| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 | 37 |
| 38 FocusTestEventType type; | 38 FocusTestEventType type; |
| 39 int view_id; | 39 int view_id; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class SimpleTestView : public View { | 42 class SimpleTestView : public View { |
| 43 public: | 43 public: |
| 44 SimpleTestView(std::vector<FocusTestEvent>* event_list, int view_id) | 44 SimpleTestView(std::vector<FocusTestEvent>* event_list, int view_id) |
| 45 : event_list_(event_list) { | 45 : event_list_(event_list) { |
| 46 SetFocusable(true); | 46 SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 47 set_id(view_id); | 47 set_id(view_id); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void OnFocus() override { | 50 void OnFocus() override { |
| 51 event_list_->push_back(FocusTestEvent(ON_FOCUS, id())); | 51 event_list_->push_back(FocusTestEvent(ON_FOCUS, id())); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void OnBlur() override { | 54 void OnBlur() override { |
| 55 event_list_->push_back(FocusTestEvent(ON_BLUR, id())); | 55 event_list_->push_back(FocusTestEvent(ON_BLUR, id())); |
| 56 } | 56 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 event_list.clear(); | 89 event_list.clear(); |
| 90 GetFocusManager()->ClearFocus(); | 90 GetFocusManager()->ClearFocus(); |
| 91 ASSERT_EQ(1, static_cast<int>(event_list.size())); | 91 ASSERT_EQ(1, static_cast<int>(event_list.size())); |
| 92 EXPECT_EQ(ON_BLUR, event_list[0].type); | 92 EXPECT_EQ(ON_BLUR, event_list[0].type); |
| 93 EXPECT_EQ(kView2ID, event_list[0].view_id); | 93 EXPECT_EQ(kView2ID, event_list[0].view_id); |
| 94 } | 94 } |
| 95 | 95 |
| 96 TEST_F(FocusManagerTest, FocusChangeListener) { | 96 TEST_F(FocusManagerTest, FocusChangeListener) { |
| 97 View* view1 = new View(); | 97 View* view1 = new View(); |
| 98 view1->SetFocusable(true); | 98 view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 99 View* view2 = new View(); | 99 View* view2 = new View(); |
| 100 view2->SetFocusable(true); | 100 view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 101 GetContentsView()->AddChildView(view1); | 101 GetContentsView()->AddChildView(view1); |
| 102 GetContentsView()->AddChildView(view2); | 102 GetContentsView()->AddChildView(view2); |
| 103 | 103 |
| 104 TestFocusChangeListener listener; | 104 TestFocusChangeListener listener; |
| 105 AddFocusChangeListener(&listener); | 105 AddFocusChangeListener(&listener); |
| 106 | 106 |
| 107 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det
ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair | 107 // Required for VS2010: http://connect.microsoft.com/VisualStudio/feedback/det
ails/520043/error-converting-from-null-to-a-pointer-type-in-std-pair |
| 108 views::View* null_view = NULL; | 108 views::View* null_view = NULL; |
| 109 | 109 |
| 110 view1->RequestFocus(); | 110 view1->RequestFocus(); |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 DISALLOW_COPY_AND_ASSIGN(FocusInAboutToRequestFocusFromTabTraversalView); | 595 DISALLOW_COPY_AND_ASSIGN(FocusInAboutToRequestFocusFromTabTraversalView); |
| 596 }; | 596 }; |
| 597 } // namespace | 597 } // namespace |
| 598 | 598 |
| 599 // Verifies a focus change done during a call to | 599 // Verifies a focus change done during a call to |
| 600 // AboutToRequestFocusFromTabTraversal() is honored. | 600 // AboutToRequestFocusFromTabTraversal() is honored. |
| 601 TEST_F(FocusManagerTest, FocusInAboutToRequestFocusFromTabTraversal) { | 601 TEST_F(FocusManagerTest, FocusInAboutToRequestFocusFromTabTraversal) { |
| 602 // Create 3 views focuses the 3 and advances to the second. The 2nd views | 602 // Create 3 views focuses the 3 and advances to the second. The 2nd views |
| 603 // implementation of AboutToRequestFocusFromTabTraversal() focuses the first. | 603 // implementation of AboutToRequestFocusFromTabTraversal() focuses the first. |
| 604 views::View* v1 = new View; | 604 views::View* v1 = new View; |
| 605 v1->SetFocusable(true); | 605 v1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 606 GetContentsView()->AddChildView(v1); | 606 GetContentsView()->AddChildView(v1); |
| 607 | 607 |
| 608 FocusInAboutToRequestFocusFromTabTraversalView* v2 = | 608 FocusInAboutToRequestFocusFromTabTraversalView* v2 = |
| 609 new FocusInAboutToRequestFocusFromTabTraversalView; | 609 new FocusInAboutToRequestFocusFromTabTraversalView; |
| 610 v2->SetFocusable(true); | 610 v2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 611 v2->set_view_to_focus(v1); | 611 v2->set_view_to_focus(v1); |
| 612 GetContentsView()->AddChildView(v2); | 612 GetContentsView()->AddChildView(v2); |
| 613 | 613 |
| 614 views::View* v3 = new View; | 614 views::View* v3 = new View; |
| 615 v3->SetFocusable(true); | 615 v3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 616 GetContentsView()->AddChildView(v3); | 616 GetContentsView()->AddChildView(v3); |
| 617 | 617 |
| 618 v3->RequestFocus(); | 618 v3->RequestFocus(); |
| 619 GetWidget()->GetFocusManager()->AdvanceFocus(true); | 619 GetWidget()->GetFocusManager()->AdvanceFocus(true); |
| 620 EXPECT_TRUE(v1->HasFocus()); | 620 EXPECT_TRUE(v1->HasFocus()); |
| 621 } | 621 } |
| 622 | 622 |
| 623 TEST_F(FocusManagerTest, RotatePaneFocus) { | 623 TEST_F(FocusManagerTest, RotatePaneFocus) { |
| 624 views::AccessiblePaneView* pane1 = new AccessiblePaneView(); | 624 views::AccessiblePaneView* pane1 = new AccessiblePaneView(); |
| 625 GetContentsView()->AddChildView(pane1); | 625 GetContentsView()->AddChildView(pane1); |
| 626 | 626 |
| 627 views::View* v1 = new View; | 627 views::View* v1 = new View; |
| 628 v1->SetFocusable(true); | 628 v1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 629 pane1->AddChildView(v1); | 629 pane1->AddChildView(v1); |
| 630 | 630 |
| 631 views::View* v2 = new View; | 631 views::View* v2 = new View; |
| 632 v2->SetFocusable(true); | 632 v2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 633 pane1->AddChildView(v2); | 633 pane1->AddChildView(v2); |
| 634 | 634 |
| 635 views::AccessiblePaneView* pane2 = new AccessiblePaneView(); | 635 views::AccessiblePaneView* pane2 = new AccessiblePaneView(); |
| 636 GetContentsView()->AddChildView(pane2); | 636 GetContentsView()->AddChildView(pane2); |
| 637 | 637 |
| 638 views::View* v3 = new View; | 638 views::View* v3 = new View; |
| 639 v3->SetFocusable(true); | 639 v3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 640 pane2->AddChildView(v3); | 640 pane2->AddChildView(v3); |
| 641 | 641 |
| 642 views::View* v4 = new View; | 642 views::View* v4 = new View; |
| 643 v4->SetFocusable(true); | 643 v4->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 644 pane2->AddChildView(v4); | 644 pane2->AddChildView(v4); |
| 645 | 645 |
| 646 std::vector<views::View*> panes; | 646 std::vector<views::View*> panes; |
| 647 panes.push_back(pane1); | 647 panes.push_back(pane1); |
| 648 panes.push_back(pane2); | 648 panes.push_back(pane2); |
| 649 SetAccessiblePanes(panes); | 649 SetAccessiblePanes(panes); |
| 650 | 650 |
| 651 FocusManager* focus_manager = GetWidget()->GetFocusManager(); | 651 FocusManager* focus_manager = GetWidget()->GetFocusManager(); |
| 652 | 652 |
| 653 // Advance forwards. Focus should stay trapped within each pane. | 653 // Advance forwards. Focus should stay trapped within each pane. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 EXPECT_EQ(v3, focus_manager->GetFocusedView()); | 688 EXPECT_EQ(v3, focus_manager->GetFocusedView()); |
| 689 | 689 |
| 690 EXPECT_FALSE(focus_manager->RotatePaneFocus( | 690 EXPECT_FALSE(focus_manager->RotatePaneFocus( |
| 691 FocusManager::kForward, FocusManager::kNoWrap)); | 691 FocusManager::kForward, FocusManager::kNoWrap)); |
| 692 EXPECT_EQ(v3, focus_manager->GetFocusedView()); | 692 EXPECT_EQ(v3, focus_manager->GetFocusedView()); |
| 693 } | 693 } |
| 694 | 694 |
| 695 // Verifies the stored focus view tracks the focused view. | 695 // Verifies the stored focus view tracks the focused view. |
| 696 TEST_F(FocusManagerTest, ImplicitlyStoresFocus) { | 696 TEST_F(FocusManagerTest, ImplicitlyStoresFocus) { |
| 697 views::View* v1 = new View; | 697 views::View* v1 = new View; |
| 698 v1->SetFocusable(true); | 698 v1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 699 GetContentsView()->AddChildView(v1); | 699 GetContentsView()->AddChildView(v1); |
| 700 | 700 |
| 701 views::View* v2 = new View; | 701 views::View* v2 = new View; |
| 702 v2->SetFocusable(true); | 702 v2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 703 GetContentsView()->AddChildView(v2); | 703 GetContentsView()->AddChildView(v2); |
| 704 | 704 |
| 705 // Verify a focus request on |v1| implicitly updates the stored focus view. | 705 // Verify a focus request on |v1| implicitly updates the stored focus view. |
| 706 v1->RequestFocus(); | 706 v1->RequestFocus(); |
| 707 EXPECT_TRUE(v1->HasFocus()); | 707 EXPECT_TRUE(v1->HasFocus()); |
| 708 EXPECT_EQ(v1, GetWidget()->GetFocusManager()->GetStoredFocusView()); | 708 EXPECT_EQ(v1, GetWidget()->GetFocusManager()->GetStoredFocusView()); |
| 709 | 709 |
| 710 // Verify a focus request on |v2| implicitly updates the stored focus view. | 710 // Verify a focus request on |v2| implicitly updates the stored focus view. |
| 711 v2->RequestFocus(); | 711 v2->RequestFocus(); |
| 712 EXPECT_TRUE(v2->HasFocus()); | 712 EXPECT_TRUE(v2->HasFocus()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 TEST_F(FocusManagerArrowKeyTraversalTest, ArrowKeyTraversal) { | 746 TEST_F(FocusManagerArrowKeyTraversalTest, ArrowKeyTraversal) { |
| 747 FocusManager* focus_manager = GetFocusManager(); | 747 FocusManager* focus_manager = GetFocusManager(); |
| 748 const ui::KeyEvent left_key(ui::ET_KEY_PRESSED, ui::VKEY_LEFT, ui::EF_NONE); | 748 const ui::KeyEvent left_key(ui::ET_KEY_PRESSED, ui::VKEY_LEFT, ui::EF_NONE); |
| 749 const ui::KeyEvent right_key(ui::ET_KEY_PRESSED, ui::VKEY_RIGHT, ui::EF_NONE); | 749 const ui::KeyEvent right_key(ui::ET_KEY_PRESSED, ui::VKEY_RIGHT, ui::EF_NONE); |
| 750 const ui::KeyEvent up_key(ui::ET_KEY_PRESSED, ui::VKEY_UP, ui::EF_NONE); | 750 const ui::KeyEvent up_key(ui::ET_KEY_PRESSED, ui::VKEY_UP, ui::EF_NONE); |
| 751 const ui::KeyEvent down_key(ui::ET_KEY_PRESSED, ui::VKEY_DOWN, ui::EF_NONE); | 751 const ui::KeyEvent down_key(ui::ET_KEY_PRESSED, ui::VKEY_DOWN, ui::EF_NONE); |
| 752 | 752 |
| 753 std::vector<views::View*> v; | 753 std::vector<views::View*> v; |
| 754 for (size_t i = 0; i < 2; ++i) { | 754 for (size_t i = 0; i < 2; ++i) { |
| 755 views::View* view = new View; | 755 views::View* view = new View; |
| 756 view->SetFocusable(true); | 756 view->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 757 GetContentsView()->AddChildView(view); | 757 GetContentsView()->AddChildView(view); |
| 758 v.push_back(view); | 758 v.push_back(view); |
| 759 } | 759 } |
| 760 | 760 |
| 761 // Arrow key traversal is off and arrow key does not change focus. | 761 // Arrow key traversal is off and arrow key does not change focus. |
| 762 FocusManager::set_arrow_key_traversal_enabled(false); | 762 FocusManager::set_arrow_key_traversal_enabled(false); |
| 763 v[0]->RequestFocus(); | 763 v[0]->RequestFocus(); |
| 764 focus_manager->OnKeyEvent(right_key); | 764 focus_manager->OnKeyEvent(right_key); |
| 765 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); | 765 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); |
| 766 focus_manager->OnKeyEvent(left_key); | 766 focus_manager->OnKeyEvent(left_key); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 777 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); | 777 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); |
| 778 focus_manager->OnKeyEvent(left_key); | 778 focus_manager->OnKeyEvent(left_key); |
| 779 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); | 779 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); |
| 780 focus_manager->OnKeyEvent(down_key); | 780 focus_manager->OnKeyEvent(down_key); |
| 781 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); | 781 EXPECT_EQ(v[1], focus_manager->GetFocusedView()); |
| 782 focus_manager->OnKeyEvent(up_key); | 782 focus_manager->OnKeyEvent(up_key); |
| 783 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); | 783 EXPECT_EQ(v[0], focus_manager->GetFocusedView()); |
| 784 } | 784 } |
| 785 | 785 |
| 786 TEST_F(FocusManagerTest, StoreFocusedView) { | 786 TEST_F(FocusManagerTest, StoreFocusedView) { |
| 787 View view; | 787 View* view = new View; |
| 788 GetFocusManager()->SetFocusedView(&view); | 788 // Add view to the view hierarchy and make it focusable. |
| 789 GetWidget()->GetRootView()->AddChildView(view); |
| 790 view->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 791 |
| 792 GetFocusManager()->SetFocusedView(view); |
| 789 GetFocusManager()->StoreFocusedView(false); | 793 GetFocusManager()->StoreFocusedView(false); |
| 790 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); | 794 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); |
| 791 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | 795 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
| 792 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 796 EXPECT_EQ(view, GetFocusManager()->GetStoredFocusView()); |
| 793 | 797 |
| 794 // Repeat with |true|. | 798 // Repeat with |true|. |
| 795 GetFocusManager()->SetFocusedView(&view); | 799 GetFocusManager()->SetFocusedView(view); |
| 796 GetFocusManager()->StoreFocusedView(true); | 800 GetFocusManager()->StoreFocusedView(true); |
| 797 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); | 801 EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView()); |
| 798 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); | 802 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
| 799 EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView()); | 803 EXPECT_EQ(view, GetFocusManager()->GetStoredFocusView()); |
| 800 } | 804 } |
| 801 | 805 |
| 806 #if defined(OS_MACOSX) |
| 807 // Test that the correct view is restored if full keyboard access is changed. |
| 808 TEST_F(FocusManagerTest, StoreFocusedViewFullKeyboardAccess) { |
| 809 View* view1 = new View; |
| 810 View* view2 = new View; |
| 811 View* view3 = new View; |
| 812 |
| 813 // Make view1 focusable in accessibility mode, view2 not focusable and view3 |
| 814 // always focusable. |
| 815 view1->SetFocusBehavior(views::View::FocusBehavior::ACCESSIBLE_ONLY); |
| 816 view2->SetFocusBehavior(views::View::FocusBehavior::NEVER); |
| 817 view3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 818 |
| 819 // Add views to the view hierarchy |
| 820 GetWidget()->GetRootView()->AddChildView(view1); |
| 821 GetWidget()->GetRootView()->AddChildView(view2); |
| 822 GetWidget()->GetRootView()->AddChildView(view3); |
| 823 |
| 824 view1->RequestFocus(); |
| 825 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 826 GetFocusManager()->StoreFocusedView(true); |
| 827 EXPECT_EQ(nullptr, GetFocusManager()->GetFocusedView()); |
| 828 |
| 829 // Turn off full keyboard access mode and restore focused view. Since view1 is |
| 830 // no longer focusable, view3 should have focus. |
| 831 GetFocusManager()->SetKeyboardAccessible(false); |
| 832 EXPECT_FALSE(GetFocusManager()->RestoreFocusedView()); |
| 833 EXPECT_EQ(view3, GetFocusManager()->GetFocusedView()); |
| 834 |
| 835 GetFocusManager()->StoreFocusedView(false); |
| 836 EXPECT_EQ(nullptr, GetFocusManager()->GetFocusedView()); |
| 837 |
| 838 // Turn on full keyboard access mode and restore focused view. Since view3 is |
| 839 // still focusable, view3 should have focus. |
| 840 GetFocusManager()->SetKeyboardAccessible(true); |
| 841 EXPECT_TRUE(GetFocusManager()->RestoreFocusedView()); |
| 842 EXPECT_EQ(view3, GetFocusManager()->GetFocusedView()); |
| 843 } |
| 844 #endif |
| 845 |
| 802 namespace { | 846 namespace { |
| 803 | 847 |
| 804 // Trivial WidgetDelegate implementation that allows setting return value of | 848 // Trivial WidgetDelegate implementation that allows setting return value of |
| 805 // ShouldAdvanceFocusToTopLevelWidget(). | 849 // ShouldAdvanceFocusToTopLevelWidget(). |
| 806 class AdvanceFocusWidgetDelegate : public WidgetDelegate { | 850 class AdvanceFocusWidgetDelegate : public WidgetDelegate { |
| 807 public: | 851 public: |
| 808 explicit AdvanceFocusWidgetDelegate(Widget* widget) | 852 explicit AdvanceFocusWidgetDelegate(Widget* widget) |
| 809 : widget_(widget), | 853 : widget_(widget), |
| 810 should_advance_focus_to_parent_(false) {} | 854 should_advance_focus_to_parent_(false) {} |
| 811 ~AdvanceFocusWidgetDelegate() override {} | 855 ~AdvanceFocusWidgetDelegate() override {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 827 | 871 |
| 828 DISALLOW_COPY_AND_ASSIGN(AdvanceFocusWidgetDelegate); | 872 DISALLOW_COPY_AND_ASSIGN(AdvanceFocusWidgetDelegate); |
| 829 }; | 873 }; |
| 830 | 874 |
| 831 } // namespace | 875 } // namespace |
| 832 | 876 |
| 833 // Verifies focus wrapping happens in the same widget. | 877 // Verifies focus wrapping happens in the same widget. |
| 834 TEST_F(FocusManagerTest, AdvanceFocusStaysInWidget) { | 878 TEST_F(FocusManagerTest, AdvanceFocusStaysInWidget) { |
| 835 // Add |widget_view| as a child of the Widget. | 879 // Add |widget_view| as a child of the Widget. |
| 836 View* widget_view = new View; | 880 View* widget_view = new View; |
| 837 widget_view->SetFocusable(true); | 881 widget_view->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 838 widget_view->SetBounds(20, 0, 20, 20); | 882 widget_view->SetBounds(20, 0, 20, 20); |
| 839 GetContentsView()->AddChildView(widget_view); | 883 GetContentsView()->AddChildView(widget_view); |
| 840 | 884 |
| 841 // Create a widget with two views, focus the second. | 885 // Create a widget with two views, focus the second. |
| 842 std::unique_ptr<AdvanceFocusWidgetDelegate> delegate; | 886 std::unique_ptr<AdvanceFocusWidgetDelegate> delegate; |
| 843 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 887 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 844 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 888 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 845 params.child = true; | 889 params.child = true; |
| 846 params.bounds = gfx::Rect(10, 10, 100, 100); | 890 params.bounds = gfx::Rect(10, 10, 100, 100); |
| 847 params.parent = GetWidget()->GetNativeView(); | 891 params.parent = GetWidget()->GetNativeView(); |
| 848 Widget child_widget; | 892 Widget child_widget; |
| 849 delegate.reset(new AdvanceFocusWidgetDelegate(&child_widget)); | 893 delegate.reset(new AdvanceFocusWidgetDelegate(&child_widget)); |
| 850 params.delegate = delegate.get(); | 894 params.delegate = delegate.get(); |
| 851 child_widget.Init(params); | 895 child_widget.Init(params); |
| 852 View* view1 = new View; | 896 View* view1 = new View; |
| 853 view1->SetFocusable(true); | 897 view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 854 view1->SetBounds(0, 0, 20, 20); | 898 view1->SetBounds(0, 0, 20, 20); |
| 855 View* view2 = new View; | 899 View* view2 = new View; |
| 856 view2->SetFocusable(true); | 900 view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 857 view2->SetBounds(20, 0, 20, 20); | 901 view2->SetBounds(20, 0, 20, 20); |
| 858 child_widget.client_view()->AddChildView(view1); | 902 child_widget.client_view()->AddChildView(view1); |
| 859 child_widget.client_view()->AddChildView(view2); | 903 child_widget.client_view()->AddChildView(view2); |
| 860 child_widget.Show(); | 904 child_widget.Show(); |
| 861 view2->RequestFocus(); | 905 view2->RequestFocus(); |
| 862 EXPECT_EQ(view2, GetFocusManager()->GetFocusedView()); | 906 EXPECT_EQ(view2, GetFocusManager()->GetFocusedView()); |
| 863 | 907 |
| 864 // Advance focus backwards, which should focus the first. | 908 // Advance focus backwards, which should focus the first. |
| 865 GetFocusManager()->AdvanceFocus(false); | 909 GetFocusManager()->AdvanceFocus(false); |
| 866 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 910 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 867 | 911 |
| 868 // Focus forward to |view2|. | 912 // Focus forward to |view2|. |
| 869 GetFocusManager()->AdvanceFocus(true); | 913 GetFocusManager()->AdvanceFocus(true); |
| 870 EXPECT_EQ(view2, GetFocusManager()->GetFocusedView()); | 914 EXPECT_EQ(view2, GetFocusManager()->GetFocusedView()); |
| 871 | 915 |
| 872 // And forward again, wrapping back to |view1|. | 916 // And forward again, wrapping back to |view1|. |
| 873 GetFocusManager()->AdvanceFocus(true); | 917 GetFocusManager()->AdvanceFocus(true); |
| 874 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 918 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 875 | 919 |
| 876 // Allow focus to go to the parent, and focus backwards which should now move | 920 // Allow focus to go to the parent, and focus backwards which should now move |
| 877 // up |widget_view| (in the parent). | 921 // up |widget_view| (in the parent). |
| 878 delegate->set_should_advance_focus_to_parent(true); | 922 delegate->set_should_advance_focus_to_parent(true); |
| 879 GetFocusManager()->AdvanceFocus(true); | 923 GetFocusManager()->AdvanceFocus(true); |
| 880 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 924 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
| 881 } | 925 } |
| 882 | 926 |
| 883 } // namespace views | 927 } // namespace views |
| OLD | NEW |