| OLD | NEW |
| 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 "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ui/base/models/combobox_model.h" | 10 #include "ui/base/models/combobox_model.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 set_focusable(false); | 137 SetFocusable(false); |
| 138 } | 138 } |
| 139 | 139 |
| 140 virtual ~BorderView() {} | 140 virtual ~BorderView() {} |
| 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 virtual FocusTraversable* GetFocusTraversable() OVERRIDE { | 146 virtual 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 Loading... |
| 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->set_focusable(true); | 546 contents->SetFocusable(true); |
| 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_NATIVE_TEXTBUTTON); | 550 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); |
| 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_NATIVE_TEXTBUTTON); | 555 button->SetStyle(Button::STYLE_NATIVE_TEXTBUTTON); |
| 556 contents->AddChildView(button); | 556 contents->AddChildView(button); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 // Now test the right container, but this time with accessibility mode. | 749 // Now test the right container, but this time with accessibility mode. |
| 750 // Make some links not focusable, but mark one of them as | 750 // Make some links not focusable, but mark one of them as |
| 751 // "accessibility focusable", so it should show up in the traversal. | 751 // "accessibility focusable", so it should show up in the traversal. |
| 752 const int kRightTraversalIDs[] = { | 752 const int kRightTraversalIDs[] = { |
| 753 kBroccoliButtonID, kDinerGameLinkID, kRidiculeLinkID, | 753 kBroccoliButtonID, kDinerGameLinkID, kRidiculeLinkID, |
| 754 kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, | 754 kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, |
| 755 kCampingLinkID, kBriceDeNiceLinkID, kTaxiLinkID, kAsterixLinkID }; | 755 kCampingLinkID, kBriceDeNiceLinkID, kTaxiLinkID, kAsterixLinkID }; |
| 756 | 756 |
| 757 FocusSearch focus_search_right(right_container_, true, true); | 757 FocusSearch focus_search_right(right_container_, true, true); |
| 758 right_container_->EnablePaneFocus(&focus_search_right); | 758 right_container_->EnablePaneFocus(&focus_search_right); |
| 759 FindViewByID(kRosettaLinkID)->set_focusable(false); | 759 FindViewByID(kRosettaLinkID)->SetFocusable(false); |
| 760 FindViewByID(kStupeurEtTremblementLinkID)->set_focusable(false); | 760 FindViewByID(kStupeurEtTremblementLinkID)->SetFocusable(false); |
| 761 FindViewByID(kDinerGameLinkID)->set_accessibility_focusable(true); | 761 FindViewByID(kDinerGameLinkID)->SetAccessibilityFocusable(true); |
| 762 FindViewByID(kDinerGameLinkID)->set_focusable(false); | 762 FindViewByID(kDinerGameLinkID)->SetFocusable(false); |
| 763 FindViewByID(kAsterixLinkID)->RequestFocus(); | 763 FindViewByID(kAsterixLinkID)->RequestFocus(); |
| 764 | 764 |
| 765 // Traverse the focus hierarchy within the pane several times. | 765 // Traverse the focus hierarchy within the pane several times. |
| 766 for (int i = 0; i < 3; ++i) { | 766 for (int i = 0; i < 3; ++i) { |
| 767 for (size_t j = 0; j < arraysize(kRightTraversalIDs); j++) { | 767 for (size_t j = 0; j < arraysize(kRightTraversalIDs); j++) { |
| 768 GetFocusManager()->AdvanceFocus(false); | 768 GetFocusManager()->AdvanceFocus(false); |
| 769 View* focused_view = GetFocusManager()->GetFocusedView(); | 769 View* focused_view = GetFocusManager()->GetFocusedView(); |
| 770 EXPECT_TRUE(focused_view != NULL); | 770 EXPECT_TRUE(focused_view != NULL); |
| 771 if (focused_view) | 771 if (focused_view) |
| 772 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); | 772 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); |
| 773 } | 773 } |
| 774 } | 774 } |
| 775 | 775 |
| 776 // Traverse in reverse order. | 776 // Traverse in reverse order. |
| 777 FindViewByID(kBroccoliButtonID)->RequestFocus(); | 777 FindViewByID(kBroccoliButtonID)->RequestFocus(); |
| 778 for (int i = 0; i < 3; ++i) { | 778 for (int i = 0; i < 3; ++i) { |
| 779 for (int j = arraysize(kRightTraversalIDs) - 1; j >= 0; --j) { | 779 for (int j = arraysize(kRightTraversalIDs) - 1; j >= 0; --j) { |
| 780 GetFocusManager()->AdvanceFocus(true); | 780 GetFocusManager()->AdvanceFocus(true); |
| 781 View* focused_view = GetFocusManager()->GetFocusedView(); | 781 View* focused_view = GetFocusManager()->GetFocusedView(); |
| 782 EXPECT_TRUE(focused_view != NULL); | 782 EXPECT_TRUE(focused_view != NULL); |
| 783 if (focused_view) | 783 if (focused_view) |
| 784 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); | 784 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 } | 787 } |
| 788 | 788 |
| 789 } // namespace views | 789 } // namespace views |
| OLD | NEW |