diff options
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/link.cc | 10 | ||||
-rw-r--r-- | views/controls/tabbed_pane/native_tabbed_pane_gtk.cc | 2 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.cc | 4 | ||||
-rw-r--r-- | views/focus/focus_manager_unittest.cc | 148 | ||||
-rw-r--r-- | views/widget/root_view.cc | 15 |
5 files changed, 92 insertions, 87 deletions
diff --git a/views/controls/link.cc b/views/controls/link.cc index 6619568..75b1043 100644 --- a/views/controls/link.cc +++ b/views/controls/link.cc @@ -123,13 +123,8 @@ void Link::OnMouseReleased(const MouseEvent& e, bool canceled) { } bool Link::OnKeyPressed(const KeyEvent& e) { -#if defined(OS_WIN) bool activate = ((e.GetKeyCode() == base::VKEY_SPACE) || (e.GetKeyCode() == base::VKEY_RETURN)); -#else - bool activate = false; - NOTIMPLEMENTED(); -#endif if (!activate) return false; @@ -145,14 +140,9 @@ bool Link::OnKeyPressed(const KeyEvent& e) { } bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& e) { -#if defined(OS_WIN) // Make sure we don't process space or enter as accelerators. return (e.GetKeyCode() == base::VKEY_SPACE) || (e.GetKeyCode() == base::VKEY_RETURN); -#else - NOTIMPLEMENTED(); - return false; -#endif } void Link::SetFont(const gfx::Font& font) { diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc index 96e26df..eb8f5f2 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc @@ -136,6 +136,8 @@ void NativeTabbedPaneGtk::DoAddTabAtIndex(int index, const std::wstring& title, WidgetGtk* page_container = new WidgetGtk(WidgetGtk::TYPE_CHILD); page_container->Init(NULL, gfx::Rect()); page_container->SetContentsView(contents); + page_container->SetFocusTraversableParent(GetRootView()); + page_container->SetFocusTraversableParentView(this); page_container->Show(); if (!contents->background()) { diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index 0c72ca2..3d9471f 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -20,6 +20,10 @@ NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield) : textfield_(textfield) { if (textfield_->style() & Textfield::STYLE_MULTILINE) NOTIMPLEMENTED(); // We don't support multiline yet. + // Make |textfield| the focused view, so that when we get focused the focus + // manager sees |textfield| as the focused view (since we are just a wrapper + // view). + set_focus_view(textfield); } NativeTextfieldGtk::~NativeTextfieldGtk() { diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc index 40abff6..71f6fbd 100644 --- a/views/focus/focus_manager_unittest.cc +++ b/views/focus/focus_manager_unittest.cc @@ -41,68 +41,70 @@ #include "views/window/window_gtk.h" #endif +namespace { +const int kWindowWidth = 600; +const int kWindowHeight = 500; + +int count = 1; + +const int kTopCheckBoxID = count++; // 1 +const int kLeftContainerID = count++; +const int kAppleLabelID = count++; +const int kAppleTextfieldID = count++; +const int kOrangeLabelID = count++; // 5 +const int kOrangeTextfieldID = count++; +const int kBananaLabelID = count++; +const int kBananaTextfieldID = count++; +const int kKiwiLabelID = count++; +const int kKiwiTextfieldID = count++; // 10 +const int kFruitButtonID = count++; +const int kFruitCheckBoxID = count++; +const int kComboboxID = count++; + +const int kRightContainerID = count++; +const int kAsparagusButtonID = count++; // 15 +const int kBroccoliButtonID = count++; +const int kCauliflowerButtonID = count++; + +const int kInnerContainerID = count++; +const int kScrollViewID = count++; +const int kRosettaLinkID = count++; // 20 +const int kStupeurEtTremblementLinkID = count++; +const int kDinerGameLinkID = count++; +const int kRidiculeLinkID = count++; +const int kClosetLinkID = count++; +const int kVisitingLinkID = count++; // 25 +const int kAmelieLinkID = count++; +const int kJoyeuxNoelLinkID = count++; +const int kCampingLinkID = count++; +const int kBriceDeNiceLinkID = count++; +const int kTaxiLinkID = count++; // 30 +const int kAsterixLinkID = count++; + +const int kOKButtonID = count++; +const int kCancelButtonID = count++; +const int kHelpButtonID = count++; + + +const int kStyleContainerID = count++; // 35 +const int kBoldCheckBoxID = count++; +const int kItalicCheckBoxID = count++; +const int kUnderlinedCheckBoxID = count++; +const int kStyleHelpLinkID = count++; +const int kStyleTextEditID = count++; // 40 + +const int kSearchContainerID = count++; +const int kSearchTextfieldID = count++; +const int kSearchButtonID = count++; +const int kHelpLinkID = count++; + +const int kThumbnailContainerID = count++; // 45 +const int kThumbnailStarID = count++; +const int kThumbnailSuperStarID = count++; +} + namespace views { -static const int kWindowWidth = 600; -static const int kWindowHeight = 500; - -#if defined(OS_WIN) -static int count = 1; - -static const int kTopCheckBoxID = count++; // 1 -static const int kLeftContainerID = count++; -static const int kAppleLabelID = count++; -static const int kAppleTextfieldID = count++; -static const int kOrangeLabelID = count++; // 5 -static const int kOrangeTextfieldID = count++; -static const int kBananaLabelID = count++; -static const int kBananaTextfieldID = count++; -static const int kKiwiLabelID = count++; -static const int kKiwiTextfieldID = count++; // 10 -static const int kFruitButtonID = count++; -static const int kFruitCheckBoxID = count++; -static const int kComboboxID = count++; - -static const int kRightContainerID = count++; -static const int kAsparagusButtonID = count++; // 15 -static const int kBroccoliButtonID = count++; -static const int kCauliflowerButtonID = count++; - -static const int kInnerContainerID = count++; -static const int kScrollViewID = count++; -static const int kRosettaLinkID = count++; // 20 -static const int kStupeurEtTremblementLinkID = count++; -static const int kDinerGameLinkID = count++; -static const int kRidiculeLinkID = count++; -static const int kClosetLinkID = count++; -static const int kVisitingLinkID = count++; // 25 -static const int kAmelieLinkID = count++; -static const int kJoyeuxNoelLinkID = count++; -static const int kCampingLinkID = count++; -static const int kBriceDeNiceLinkID = count++; -static const int kTaxiLinkID = count++; // 30 -static const int kAsterixLinkID = count++; - -static const int kOKButtonID = count++; -static const int kCancelButtonID = count++; -static const int kHelpButtonID = count++; - -static const int kStyleContainerID = count++; // 35 -static const int kBoldCheckBoxID = count++; -static const int kItalicCheckBoxID = count++; -static const int kUnderlinedCheckBoxID = count++; -static const int kStyleHelpLinkID = count++; -static const int kStyleTextEditID = count++; // 40 - -static const int kSearchContainerID = count++; -static const int kSearchTextfieldID = count++; -static const int kSearchButtonID = count++; -static const int kHelpLinkID = count++; - -static const int kThumbnailContainerID = count++; // 45 -static const int kThumbnailStarID = count++; -static const int kThumbnailSuperStarID = count++; -#endif class FocusManagerTest : public testing::Test, public WindowDelegate { public: @@ -258,11 +260,9 @@ class BorderView : public NativeViewHost { widget_ = widget_win; #else WidgetGtk* widget_gtk = new WidgetGtk(WidgetGtk::TYPE_CHILD); - // TODO(jcampan): implement WidgetGtk::SetFocusTraversableParentView() - // widget_gtk->SetFocusTraversableParentView(this); + widget_gtk->Init(native_view(), gfx::Rect(0, 0, 0, 0)); + widget_gtk->SetFocusTraversableParentView(this); widget_ = widget_gtk; - widget_->Init(parent->GetRootView()->GetWidget()->GetNativeView(), - gfx::Rect(0, 0, 0, 0)); #endif widget_->SetContentsView(child_); } @@ -290,7 +290,6 @@ class DummyComboboxModel : public ComboboxModel { } }; -#if defined(OS_WIN) class FocusTraversalTest : public FocusManagerTest { public: ~FocusTraversalTest(); @@ -442,7 +441,7 @@ void FocusTraversalTest::InitContentView() { y = 10; int radio_button_height = 15; int gap_between_radio_buttons = 10; - View* radio_button = new RadioButton(L"Asparagus", 1); + RadioButton* radio_button = new RadioButton(L"Asparagus", 1); radio_button->SetID(kAsparagusButtonID); right_container->AddChildView(radio_button); radio_button->SetBounds(5, y, 70, radio_button_height); @@ -453,6 +452,7 @@ void FocusTraversalTest::InitContentView() { right_container->AddChildView(radio_button); radio_button->SetBounds(5, y, 70, radio_button_height); radio_button->SetGroup(1); + RadioButton* radio_button_to_check = radio_button; y += radio_button_height + gap_between_radio_buttons; radio_button = new RadioButton(L"Cauliflower", 1); radio_button->SetID(kCauliflowerButtonID); @@ -603,8 +603,10 @@ void FocusTraversalTest::InitContentView() { content_view_->AddChildView(contents); contents->SetBounds(250, y, 200, 50); + // We can only call RadioButton::SetChecked() on the radio-button is part of + // the view hierarchy. + radio_button_to_check->SetChecked(true); } -#endif //////////////////////////////////////////////////////////////////////////////// // The tests @@ -898,7 +900,6 @@ TEST_F(FocusManagerTest, FocusStoreRestore) { */ } -#if defined(OS_WIN) TEST_F(FocusManagerTest, ContainsView) { View* view = new View(); scoped_ptr<View> detached_view(new View()); @@ -923,7 +924,7 @@ TEST_F(FocusManagerTest, ContainsView) { TEST_F(FocusTraversalTest, NormalTraversal) { const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextfieldID, kOrangeTextfieldID, kBananaTextfieldID, kKiwiTextfieldID, - kFruitButtonID, kFruitCheckBoxID, kComboboxID, kAsparagusButtonID, + kFruitButtonID, kFruitCheckBoxID, kComboboxID, kBroccoliButtonID, kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID, kRidiculeLinkID, kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, kBriceDeNiceLinkID, @@ -939,7 +940,7 @@ TEST_F(FocusTraversalTest, NormalTraversal) { // Let's traverse the whole focus hierarchy (several times, to make sure it // loops OK). - GetFocusManager()->SetFocusedView(NULL); + GetFocusManager()->ClearFocus(); for (int i = 0; i < 3; ++i) { for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { GetFocusManager()->AdvanceFocus(false); @@ -951,7 +952,7 @@ TEST_F(FocusTraversalTest, NormalTraversal) { } // Let's traverse in reverse order. - GetFocusManager()->SetFocusedView(NULL); + GetFocusManager()->ClearFocus(); for (int i = 0; i < 3; ++i) { for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) { GetFocusManager()->AdvanceFocus(true); @@ -993,7 +994,7 @@ TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { View* focused_view; // Let's do one traversal (several times, to make sure it loops ok). - GetFocusManager()->SetFocusedView(NULL); + GetFocusManager()->ClearFocus(); for (int i = 0; i < 3; ++i) { for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { GetFocusManager()->AdvanceFocus(false); @@ -1005,7 +1006,7 @@ TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { } // Same thing in reverse. - GetFocusManager()->SetFocusedView(NULL); + GetFocusManager()->ClearFocus(); for (int i = 0; i < 3; ++i) { for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) { GetFocusManager()->AdvanceFocus(true); @@ -1016,7 +1017,6 @@ TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { } } } -#endif // Counts accelerator calls. class TestAcceleratorTarget : public AcceleratorTarget { diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index dad1964..dd2ad8a 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -617,8 +617,13 @@ View* RootView::FindNextFocusableViewImpl(View* starting_view, FocusTraversable** focus_traversable, View** focus_traversable_view) { if (check_starting_view) { - if (IsViewFocusableCandidate(starting_view, skip_group_id)) - return FindSelectedViewForGroup(starting_view); + if (IsViewFocusableCandidate(starting_view, skip_group_id)) { + View* v = FindSelectedViewForGroup(starting_view); + // The selected view might not be focusable (if it is disabled for + // example). + if (v && v->IsFocusable()) + return v; + } *focus_traversable = starting_view->GetFocusTraversable(); if (*focus_traversable) { @@ -710,7 +715,11 @@ View* RootView::FindPreviousFocusableViewImpl( // a FocusTraversable, since we do not want to go down any more. if (check_starting_view && IsViewFocusableCandidate(starting_view, skip_group_id)) { - return FindSelectedViewForGroup(starting_view); + View* v = FindSelectedViewForGroup(starting_view); + // The selected view might not be focusable (if it is disabled for + // example). + if (v && v->IsFocusable()) + return v; } // Then try the left sibling. |