OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "ui/gfx/native_widget_types.h" | 8 #include "ui/gfx/native_widget_types.h" |
9 #include "ui/views/test/widget_test.h" | 9 #include "ui/views/test/widget_test.h" |
10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 contents_view1->set_focusable(true); | 164 contents_view1->set_focusable(true); |
165 Widget widget1; | 165 Widget widget1; |
166 Widget::InitParams init_params = | 166 Widget::InitParams init_params = |
167 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 167 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
168 init_params.bounds = gfx::Rect(0, 0, 200, 200); | 168 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
169 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 169 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
170 init_params.native_widget = new DesktopNativeWidgetAura(&widget1); | 170 init_params.native_widget = new DesktopNativeWidgetAura(&widget1); |
171 widget1.Init(init_params); | 171 widget1.Init(init_params); |
172 widget1.SetContentsView(contents_view1); | 172 widget1.SetContentsView(contents_view1); |
173 widget1.Show(); | 173 widget1.Show(); |
174 aura::RootWindow* root_window1= widget1.GetNativeView()->GetRootWindow(); | 174 aura::Window* root_window1= widget1.GetNativeView()->GetRootWindow(); |
175 contents_view1->RequestFocus(); | 175 contents_view1->RequestFocus(); |
176 | 176 |
177 EXPECT_TRUE(root_window1 != NULL); | 177 EXPECT_TRUE(root_window1 != NULL); |
178 aura::client::ActivationClient* activation_client1 = | 178 aura::client::ActivationClient* activation_client1 = |
179 aura::client::GetActivationClient(root_window1); | 179 aura::client::GetActivationClient(root_window1); |
180 EXPECT_TRUE(activation_client1 != NULL); | 180 EXPECT_TRUE(activation_client1 != NULL); |
181 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); | 181 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); |
182 | 182 |
183 // Create widget 2 and expect the active window to be its window. | 183 // Create widget 2 and expect the active window to be its window. |
184 View* contents_view2 = new View; | 184 View* contents_view2 = new View; |
185 Widget widget2; | 185 Widget widget2; |
186 Widget::InitParams init_params2 = | 186 Widget::InitParams init_params2 = |
187 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 187 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
188 init_params2.bounds = gfx::Rect(0, 0, 200, 200); | 188 init_params2.bounds = gfx::Rect(0, 0, 200, 200); |
189 init_params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 189 init_params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
190 init_params2.native_widget = new DesktopNativeWidgetAura(&widget2); | 190 init_params2.native_widget = new DesktopNativeWidgetAura(&widget2); |
191 widget2.Init(init_params2); | 191 widget2.Init(init_params2); |
192 widget2.SetContentsView(contents_view2); | 192 widget2.SetContentsView(contents_view2); |
193 widget2.Show(); | 193 widget2.Show(); |
194 aura::RootWindow* root_window2 = widget2.GetNativeView()->GetRootWindow(); | 194 aura::Window* root_window2 = widget2.GetNativeView()->GetRootWindow(); |
195 contents_view2->RequestFocus(); | 195 contents_view2->RequestFocus(); |
196 ::SetActiveWindow(root_window2->GetAcceleratedWidget()); | 196 ::SetActiveWindow(root_window2->GetDispatcher()->GetAcceleratedWidget()); |
197 | 197 |
198 aura::client::ActivationClient* activation_client2 = | 198 aura::client::ActivationClient* activation_client2 = |
199 aura::client::GetActivationClient(root_window2); | 199 aura::client::GetActivationClient(root_window2); |
200 EXPECT_TRUE(activation_client2 != NULL); | 200 EXPECT_TRUE(activation_client2 != NULL); |
201 EXPECT_EQ(activation_client2->GetActiveWindow(), widget2.GetNativeView()); | 201 EXPECT_EQ(activation_client2->GetActiveWindow(), widget2.GetNativeView()); |
202 EXPECT_EQ(activation_client1->GetActiveWindow(), | 202 EXPECT_EQ(activation_client1->GetActiveWindow(), |
203 reinterpret_cast<aura::Window*>(NULL)); | 203 reinterpret_cast<aura::Window*>(NULL)); |
204 | 204 |
205 // Now set focus back to widget 1 and expect the active window to be its | 205 // Now set focus back to widget 1 and expect the active window to be its |
206 // window. | 206 // window. |
207 contents_view1->RequestFocus(); | 207 contents_view1->RequestFocus(); |
208 ::SetActiveWindow(root_window1->GetAcceleratedWidget()); | 208 ::SetActiveWindow(root_window1->GetDispatcher()->GetAcceleratedWidget()); |
209 EXPECT_EQ(activation_client2->GetActiveWindow(), | 209 EXPECT_EQ(activation_client2->GetActiveWindow(), |
210 reinterpret_cast<aura::Window*>(NULL)); | 210 reinterpret_cast<aura::Window*>(NULL)); |
211 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); | 211 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); |
212 } | 212 } |
213 #endif | 213 #endif |
214 | 214 |
215 TEST_F(WidgetTest, CaptureAutoReset) { | 215 TEST_F(WidgetTest, CaptureAutoReset) { |
216 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); | 216 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); |
217 View* container = new View; | 217 View* container = new View; |
218 toplevel->SetContentsView(container); | 218 toplevel->SetContentsView(container); |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 widget2.SetCapture(widget2.GetRootView()); | 725 widget2.SetCapture(widget2.GetRootView()); |
726 EXPECT_FALSE(widget1.HasCapture()); | 726 EXPECT_FALSE(widget1.HasCapture()); |
727 EXPECT_TRUE(widget2.HasCapture()); | 727 EXPECT_TRUE(widget2.HasCapture()); |
728 | 728 |
729 widget1.GetAndClearGotMouseEvent(); | 729 widget1.GetAndClearGotMouseEvent(); |
730 widget2.GetAndClearGotMouseEvent(); | 730 widget2.GetAndClearGotMouseEvent(); |
731 // Send a mouse event to the RootWindow associated with |widget1|. Even though | 731 // Send a mouse event to the RootWindow associated with |widget1|. Even though |
732 // |widget2| has capture, |widget1| should still get the event. | 732 // |widget2| has capture, |widget1| should still get the event. |
733 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 733 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), |
734 ui::EF_NONE); | 734 ui::EF_NONE); |
735 static_cast<aura::RootWindowHostDelegate*>( | 735 widget1.GetNativeWindow()->GetDispatcher()->AsRootWindowHostDelegate()-> |
736 widget1.GetNativeWindow()->GetRootWindow())->OnHostMouseEvent( | 736 OnHostMouseEvent(&mouse_event); |
737 &mouse_event); | |
738 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 737 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
739 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 738 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
740 } | 739 } |
741 #endif | 740 #endif |
742 | 741 |
743 } // namespace test | 742 } // namespace test |
744 } // namespace views | 743 } // namespace views |
OLD | NEW |