| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 test::WidgetTest::SimulateNativeActivate(GetWidget()); | 128 test::WidgetTest::SimulateNativeActivate(GetWidget()); |
| 129 | 129 |
| 130 TestWidgetFocusChangeListener widget_listener; | 130 TestWidgetFocusChangeListener widget_listener; |
| 131 AddWidgetFocusChangeListener(&widget_listener); | 131 AddWidgetFocusChangeListener(&widget_listener); |
| 132 | 132 |
| 133 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 133 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 134 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 134 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 135 params.bounds = gfx::Rect(10, 10, 100, 100); | 135 params.bounds = gfx::Rect(10, 10, 100, 100); |
| 136 params.parent = GetWidget()->GetNativeView(); | 136 params.parent = GetWidget()->GetNativeView(); |
| 137 | 137 |
| 138 scoped_ptr<Widget> widget1(new Widget); | 138 std::unique_ptr<Widget> widget1(new Widget); |
| 139 widget1->Init(params); | 139 widget1->Init(params); |
| 140 widget1->Show(); | 140 widget1->Show(); |
| 141 | 141 |
| 142 scoped_ptr<Widget> widget2(new Widget); | 142 std::unique_ptr<Widget> widget2(new Widget); |
| 143 widget2->Init(params); | 143 widget2->Init(params); |
| 144 widget2->Show(); | 144 widget2->Show(); |
| 145 | 145 |
| 146 widget_listener.ClearFocusChanges(); | 146 widget_listener.ClearFocusChanges(); |
| 147 gfx::NativeView native_view1 = widget1->GetNativeView(); | 147 gfx::NativeView native_view1 = widget1->GetNativeView(); |
| 148 test::WidgetTest::SimulateNativeActivate(widget1.get()); | 148 test::WidgetTest::SimulateNativeActivate(widget1.get()); |
| 149 ASSERT_EQ(2u, widget_listener.focus_changes().size()); | 149 ASSERT_EQ(2u, widget_listener.focus_changes().size()); |
| 150 EXPECT_EQ(nullptr, widget_listener.focus_changes()[0]); | 150 EXPECT_EQ(nullptr, widget_listener.focus_changes()[0]); |
| 151 EXPECT_EQ(native_view1, widget_listener.focus_changes()[1]); | 151 EXPECT_EQ(native_view1, widget_listener.focus_changes()[1]); |
| 152 | 152 |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 | 832 |
| 833 // Verifies focus wrapping happens in the same widget. | 833 // Verifies focus wrapping happens in the same widget. |
| 834 TEST_F(FocusManagerTest, AdvanceFocusStaysInWidget) { | 834 TEST_F(FocusManagerTest, AdvanceFocusStaysInWidget) { |
| 835 // Add |widget_view| as a child of the Widget. | 835 // Add |widget_view| as a child of the Widget. |
| 836 View* widget_view = new View; | 836 View* widget_view = new View; |
| 837 widget_view->SetFocusable(true); | 837 widget_view->SetFocusable(true); |
| 838 widget_view->SetBounds(20, 0, 20, 20); | 838 widget_view->SetBounds(20, 0, 20, 20); |
| 839 GetContentsView()->AddChildView(widget_view); | 839 GetContentsView()->AddChildView(widget_view); |
| 840 | 840 |
| 841 // Create a widget with two views, focus the second. | 841 // Create a widget with two views, focus the second. |
| 842 scoped_ptr<AdvanceFocusWidgetDelegate> delegate; | 842 std::unique_ptr<AdvanceFocusWidgetDelegate> delegate; |
| 843 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 843 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 844 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 844 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 845 params.child = true; | 845 params.child = true; |
| 846 params.bounds = gfx::Rect(10, 10, 100, 100); | 846 params.bounds = gfx::Rect(10, 10, 100, 100); |
| 847 params.parent = GetWidget()->GetNativeView(); | 847 params.parent = GetWidget()->GetNativeView(); |
| 848 Widget child_widget; | 848 Widget child_widget; |
| 849 delegate.reset(new AdvanceFocusWidgetDelegate(&child_widget)); | 849 delegate.reset(new AdvanceFocusWidgetDelegate(&child_widget)); |
| 850 params.delegate = delegate.get(); | 850 params.delegate = delegate.get(); |
| 851 child_widget.Init(params); | 851 child_widget.Init(params); |
| 852 View* view1 = new View; | 852 View* view1 = new View; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 874 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); | 874 EXPECT_EQ(view1, GetFocusManager()->GetFocusedView()); |
| 875 | 875 |
| 876 // Allow focus to go to the parent, and focus backwards which should now move | 876 // Allow focus to go to the parent, and focus backwards which should now move |
| 877 // up |widget_view| (in the parent). | 877 // up |widget_view| (in the parent). |
| 878 delegate->set_should_advance_focus_to_parent(true); | 878 delegate->set_should_advance_focus_to_parent(true); |
| 879 GetFocusManager()->AdvanceFocus(true); | 879 GetFocusManager()->AdvanceFocus(true); |
| 880 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); | 880 EXPECT_EQ(widget_view, GetFocusManager()->GetFocusedView()); |
| 881 } | 881 } |
| 882 | 882 |
| 883 } // namespace views | 883 } // namespace views |
| OLD | NEW |