Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: ui/views/focus/focus_traversal_unittest.cc

Issue 1898633004: Views: Add new SetFocusBehavior method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/focus/focus_manager_unittest.cc ('k') | ui/views/test/widget_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/focus/focus_manager.h" 5 #include "ui/views/focus/focus_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 FocusSearch* focus_search_; 127 FocusSearch* focus_search_;
128 }; 128 };
129 129
130 // BorderView is a view containing a native window with its own view hierarchy. 130 // BorderView is a view containing a native window with its own view hierarchy.
131 // It is interesting to test focus traversal from a view hierarchy to an inner 131 // It is interesting to test focus traversal from a view hierarchy to an inner
132 // view hierarchy. 132 // view hierarchy.
133 class BorderView : public NativeViewHost { 133 class BorderView : public NativeViewHost {
134 public: 134 public:
135 explicit BorderView(View* child) : child_(child), widget_(NULL) { 135 explicit BorderView(View* child) : child_(child), widget_(NULL) {
136 DCHECK(child); 136 DCHECK(child);
137 SetFocusable(false); 137 SetFocusBehavior(FocusBehavior::NEVER);
138 } 138 }
139 139
140 ~BorderView() override {} 140 ~BorderView() override {}
141 141
142 virtual internal::RootView* GetContentsRootView() { 142 virtual internal::RootView* GetContentsRootView() {
143 return static_cast<internal::RootView*>(widget_->GetRootView()); 143 return static_cast<internal::RootView*>(widget_->GetRootView());
144 } 144 }
145 145
146 FocusTraversable* GetFocusTraversable() override { 146 FocusTraversable* GetFocusTraversable() override {
147 return static_cast<internal::RootView*>(widget_->GetRootView()); 147 return static_cast<internal::RootView*>(widget_->GetRootView());
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 536
537 search_border_view_ = new BorderView(contents); 537 search_border_view_ = new BorderView(contents);
538 search_border_view_->set_id(kSearchContainerID); 538 search_border_view_->set_id(kSearchContainerID);
539 539
540 GetContentsView()->AddChildView(search_border_view_); 540 GetContentsView()->AddChildView(search_border_view_);
541 search_border_view_->SetBounds(300, y, 240, 50); 541 search_border_view_->SetBounds(300, y, 240, 50);
542 542
543 y += 60; 543 y += 60;
544 544
545 contents = new View(); 545 contents = new View();
546 contents->SetFocusable(true); 546 contents->SetFocusBehavior(View::FocusBehavior::ALWAYS);
547 contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE)); 547 contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE));
548 contents->set_id(kThumbnailContainerID); 548 contents->set_id(kThumbnailContainerID);
549 button = new LabelButton(NULL, ASCIIToUTF16("Star")); 549 button = new LabelButton(NULL, ASCIIToUTF16("Star"));
550 button->SetStyle(Button::STYLE_BUTTON); 550 button->SetStyle(Button::STYLE_BUTTON);
551 contents->AddChildView(button); 551 contents->AddChildView(button);
552 button->SetBounds(5, 5, 50, 30); 552 button->SetBounds(5, 5, 50, 30);
553 button->set_id(kThumbnailStarID); 553 button->set_id(kThumbnailStarID);
554 button = new LabelButton(NULL, ASCIIToUTF16("SuperStar")); 554 button = new LabelButton(NULL, ASCIIToUTF16("SuperStar"));
555 button->SetStyle(Button::STYLE_BUTTON); 555 button->SetStyle(Button::STYLE_BUTTON);
556 contents->AddChildView(button); 556 contents->AddChildView(button);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 // Now test the right container, but this time with accessibility mode. 740 // Now test the right container, but this time with accessibility mode.
741 // Make some links not focusable, but mark one of them as 741 // Make some links not focusable, but mark one of them as
742 // "accessibility focusable", so it should show up in the traversal. 742 // "accessibility focusable", so it should show up in the traversal.
743 const int kRightTraversalIDs[] = { 743 const int kRightTraversalIDs[] = {
744 kBroccoliButtonID, kDinerGameLinkID, kRidiculeLinkID, 744 kBroccoliButtonID, kDinerGameLinkID, kRidiculeLinkID,
745 kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, 745 kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID,
746 kCampingLinkID, kBriceDeNiceLinkID, kTaxiLinkID, kAsterixLinkID }; 746 kCampingLinkID, kBriceDeNiceLinkID, kTaxiLinkID, kAsterixLinkID };
747 747
748 FocusSearch focus_search_right(right_container_, true, true); 748 FocusSearch focus_search_right(right_container_, true, true);
749 right_container_->EnablePaneFocus(&focus_search_right); 749 right_container_->EnablePaneFocus(&focus_search_right);
750 FindViewByID(kRosettaLinkID)->SetFocusable(false); 750 FindViewByID(kRosettaLinkID)->SetFocusBehavior(View::FocusBehavior::NEVER);
751 FindViewByID(kStupeurEtTremblementLinkID)->SetFocusable(false); 751 FindViewByID(kStupeurEtTremblementLinkID)
752 FindViewByID(kDinerGameLinkID)->SetAccessibilityFocusable(true); 752 ->SetFocusBehavior(View::FocusBehavior::NEVER);
753 FindViewByID(kDinerGameLinkID)->SetFocusable(false); 753 FindViewByID(kDinerGameLinkID)
754 ->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY);
754 FindViewByID(kAsterixLinkID)->RequestFocus(); 755 FindViewByID(kAsterixLinkID)->RequestFocus();
755 756
756 // Traverse the focus hierarchy within the pane several times. 757 // Traverse the focus hierarchy within the pane several times.
757 for (int i = 0; i < 3; ++i) { 758 for (int i = 0; i < 3; ++i) {
758 for (size_t j = 0; j < arraysize(kRightTraversalIDs); j++) { 759 for (size_t j = 0; j < arraysize(kRightTraversalIDs); j++) {
759 GetFocusManager()->AdvanceFocus(false); 760 GetFocusManager()->AdvanceFocus(false);
760 View* focused_view = GetFocusManager()->GetFocusedView(); 761 View* focused_view = GetFocusManager()->GetFocusedView();
761 EXPECT_TRUE(focused_view != NULL); 762 EXPECT_TRUE(focused_view != NULL);
762 if (focused_view) 763 if (focused_view)
763 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); 764 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 GetFocusManager()->AdvanceFocus(false); 847 GetFocusManager()->AdvanceFocus(false);
847 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 848 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
848 849
849 // Advance backwards from the root node. 850 // Advance backwards from the root node.
850 GetFocusManager()->ClearFocus(); 851 GetFocusManager()->ClearFocus();
851 GetFocusManager()->AdvanceFocus(true); 852 GetFocusManager()->AdvanceFocus(true);
852 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 853 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
853 } 854 }
854 855
855 } // namespace views 856 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/focus/focus_manager_unittest.cc ('k') | ui/views/test/widget_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698