| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 GetFocusManager()->ClearFocus(); | 119 GetFocusManager()->ClearFocus(); |
| 120 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); | 120 ASSERT_EQ(1, static_cast<int>(listener.focus_changes().size())); |
| 121 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view2, null_view)); | 121 EXPECT_TRUE(listener.focus_changes()[0] == ViewPair(view2, null_view)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST_F(FocusManagerTest, WidgetFocusChangeListener) { | 124 TEST_F(FocusManagerTest, WidgetFocusChangeListener) { |
| 125 // TODO: this test ends up calling focus on the aura::Window associated with | 125 // TODO: this test ends up calling focus on the aura::Window associated with |
| 126 // the Widget and expecting that to change activation. This should work for | 126 // the Widget and expecting that to change activation. This should work for |
| 127 // aura-mus-client as well. http://crbug.com/664261. | 127 // aura-mus-client as well. http://crbug.com/664261. |
| 128 if (IsAuraMusClient()) | 128 if (IsMus()) |
| 129 return; | 129 return; |
| 130 | 130 |
| 131 // First, ensure the simulator is aware of the Widget created in SetUp() being | 131 // First, ensure the simulator is aware of the Widget created in SetUp() being |
| 132 // currently active. | 132 // currently active. |
| 133 test::WidgetTest::SimulateNativeActivate(GetWidget()); | 133 test::WidgetTest::SimulateNativeActivate(GetWidget()); |
| 134 | 134 |
| 135 TestWidgetFocusChangeListener widget_listener; | 135 TestWidgetFocusChangeListener widget_listener; |
| 136 AddWidgetFocusChangeListener(&widget_listener); | 136 AddWidgetFocusChangeListener(&widget_listener); |
| 137 | 137 |
| 138 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 138 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 Widget* widget_; | 849 Widget* widget_; |
| 850 bool should_advance_focus_to_parent_; | 850 bool should_advance_focus_to_parent_; |
| 851 | 851 |
| 852 DISALLOW_COPY_AND_ASSIGN(AdvanceFocusWidgetDelegate); | 852 DISALLOW_COPY_AND_ASSIGN(AdvanceFocusWidgetDelegate); |
| 853 }; | 853 }; |
| 854 | 854 |
| 855 } // namespace | 855 } // namespace |
| 856 | 856 |
| 857 // Verifies focus wrapping happens in the same widget. | 857 // Verifies focus wrapping happens in the same widget. |
| 858 TEST_F(FocusManagerTest, AdvanceFocusStaysInWidget) { | 858 TEST_F(FocusManagerTest, AdvanceFocusStaysInWidget) { |
| 859 // Mus doesn't support child Widgets well yet. https://crbug.com/612820 | |
| 860 if (IsMus()) | |
| 861 return; | |
| 862 // Add |widget_view| as a child of the Widget. | 859 // Add |widget_view| as a child of the Widget. |
| 863 View* widget_view = new View; | 860 View* widget_view = new View; |
| 864 widget_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 861 widget_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 865 widget_view->SetBounds(20, 0, 20, 20); | 862 widget_view->SetBounds(20, 0, 20, 20); |
| 866 GetContentsView()->AddChildView(widget_view); | 863 GetContentsView()->AddChildView(widget_view); |
| 867 | 864 |
| 868 // Create a widget with two views, focus the second. | 865 // Create a widget with two views, focus the second. |
| 869 std::unique_ptr<AdvanceFocusWidgetDelegate> delegate; | 866 std::unique_ptr<AdvanceFocusWidgetDelegate> delegate; |
| 870 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 867 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 871 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 868 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 901 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 898 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 902 | 899 |
| 903 // Allow focus to go to the parent, and focus backwards which should now move | 900 // Allow focus to go to the parent, and focus backwards which should now move |
| 904 // up |widget_view| (in the parent). | 901 // up |widget_view| (in the parent). |
| 905 delegate->set_should_advance_focus_to_parent(true); | 902 delegate->set_should_advance_focus_to_parent(true); |
| 906 GetFocusManager()->AdvanceFocus(true); | 903 GetFocusManager()->AdvanceFocus(true); |
| 907 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 904 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
| 908 } | 905 } |
| 909 | 906 |
| 910 } // namespace views | 907 } // namespace views |
| OLD | NEW |