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 "ui/views/widget/desktop_aura/desktop_screen_x11.h" | 5 #include "ui/views/widget/desktop_aura/desktop_screen_x11.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/aura/client/aura_constants.cc" | |
12 #include "ui/aura/test/event_generator.h" | |
11 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
16 #include "ui/base/hit_test.h" | |
14 #include "ui/base/x/x11_util.h" | 17 #include "ui/base/x/x11_util.h" |
15 #include "ui/events/platform/platform_event_dispatcher.h" | 18 #include "ui/events/platform/platform_event_dispatcher.h" |
16 #include "ui/events/platform/platform_event_source.h" | 19 #include "ui/events/platform/platform_event_source.h" |
17 #include "ui/gfx/display_observer.h" | 20 #include "ui/gfx/display_observer.h" |
18 #include "ui/gfx/x/x11_atom_cache.h" | 21 #include "ui/gfx/x/x11_atom_cache.h" |
19 #include "ui/gfx/x/x11_types.h" | 22 #include "ui/gfx/x/x11_types.h" |
20 #include "ui/views/test/views_test_base.h" | 23 #include "ui/views/test/views_test_base.h" |
21 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 24 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
22 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 25 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
23 | 26 |
27 namespace { | |
28 | |
29 // Class which allows for the designation of non-client component targets of | |
30 // hit tests. | |
31 class TestDesktopNativeWidgetAura : public views::DesktopNativeWidgetAura { | |
32 public: | |
33 explicit TestDesktopNativeWidgetAura( | |
34 views::internal::NativeWidgetDelegate* delegate) | |
35 : views::DesktopNativeWidgetAura(delegate) {} | |
36 virtual ~TestDesktopNativeWidgetAura() {} | |
37 | |
38 void set_window_component(int window_component) { | |
39 window_component_ = window_component; | |
40 } | |
41 | |
42 // DesktopNativeWidgetAura: | |
43 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { | |
44 return window_component_; | |
45 } | |
46 | |
47 private: | |
48 int window_component_; | |
49 | |
50 DISALLOW_COPY_AND_ASSIGN(TestDesktopNativeWidgetAura); | |
51 }; | |
52 | |
53 } // namespace | |
54 | |
24 namespace views { | 55 namespace views { |
25 | 56 |
26 const int64 kFirstDisplay = 5321829; | 57 const int64 kFirstDisplay = 5321829; |
27 const int64 kSecondDisplay = 928310; | 58 const int64 kSecondDisplay = 928310; |
28 | 59 |
29 // Class which waits till the X11 window associated with the widget passed into | 60 // Class which waits till the X11 window associated with the widget passed into |
30 // the constructor is activated. We cannot listen for the widget's activation | 61 // the constructor is activated. We cannot listen for the widget's activation |
31 // because the _NET_ACTIVE_WINDOW property is changed after the widget is | 62 // because the _NET_ACTIVE_WINDOW property is changed after the widget is |
32 // activated. | 63 // activated. |
33 class ActivationWaiter : public ui::PlatformEventDispatcher { | 64 class ActivationWaiter : public ui::PlatformEventDispatcher { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 std::vector<gfx::Display> removed_display_; | 149 std::vector<gfx::Display> removed_display_; |
119 | 150 |
120 DesktopScreenX11* screen() { return screen_.get(); } | 151 DesktopScreenX11* screen() { return screen_.get(); } |
121 | 152 |
122 void ResetDisplayChanges() { | 153 void ResetDisplayChanges() { |
123 changed_display_.clear(); | 154 changed_display_.clear(); |
124 added_display_.clear(); | 155 added_display_.clear(); |
125 removed_display_.clear(); | 156 removed_display_.clear(); |
126 } | 157 } |
127 | 158 |
128 Widget* BuildTopLevelDesktopWidget(const gfx::Rect& bounds) { | 159 Widget* BuildTopLevelDesktopWidget(const gfx::Rect& bounds, |
160 bool use_test_native_widget) { | |
129 Widget* toplevel = new Widget; | 161 Widget* toplevel = new Widget; |
130 Widget::InitParams toplevel_params = | 162 Widget::InitParams toplevel_params = |
131 CreateParams(Widget::InitParams::TYPE_WINDOW); | 163 CreateParams(Widget::InitParams::TYPE_WINDOW); |
132 toplevel_params.native_widget = | 164 if (use_test_native_widget) { |
133 new views::DesktopNativeWidgetAura(toplevel); | 165 toplevel_params.native_widget = |
166 new TestDesktopNativeWidgetAura(toplevel); | |
167 } else { | |
168 toplevel_params.native_widget = | |
169 new views::DesktopNativeWidgetAura(toplevel); | |
170 } | |
134 toplevel_params.bounds = bounds; | 171 toplevel_params.bounds = bounds; |
135 toplevel_params.remove_standard_frame = true; | 172 toplevel_params.remove_standard_frame = true; |
136 toplevel->Init(toplevel_params); | 173 toplevel->Init(toplevel_params); |
137 return toplevel; | 174 return toplevel; |
138 } | 175 } |
139 | 176 |
140 private: | 177 private: |
141 // Overridden from gfx::DisplayObserver: | 178 // Overridden from gfx::DisplayObserver: |
142 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { | 179 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { |
143 changed_display_.push_back(display); | 180 changed_display_.push_back(display); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 gfx::Rect(640, 0, 1024, 768))); | 305 gfx::Rect(640, 0, 1024, 768))); |
269 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); | 306 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); |
270 screen()->ProcessDisplayChange(displays); | 307 screen()->ProcessDisplayChange(displays); |
271 | 308 |
272 // The first display in the list is always the primary, even if other | 309 // The first display in the list is always the primary, even if other |
273 // displays are to the left in screen layout. | 310 // displays are to the left in screen layout. |
274 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); | 311 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); |
275 } | 312 } |
276 | 313 |
277 TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) { | 314 TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) { |
278 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10)); | 315 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10), |
279 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10)); | 316 false); |
317 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10), | |
318 false); | |
280 Widget* window_three = | 319 Widget* window_three = |
281 BuildTopLevelDesktopWidget(gfx::Rect(115, 115, 20, 20)); | 320 BuildTopLevelDesktopWidget(gfx::Rect(115, 115, 20, 20), false); |
282 | 321 |
283 window_three->Show(); | 322 window_three->Show(); |
284 window_two->Show(); | 323 window_two->Show(); |
285 window_one->Show(); | 324 window_one->Show(); |
286 | 325 |
287 // Make sure the internal state of DesktopWindowTreeHostX11 is set up | 326 // Make sure the internal state of DesktopWindowTreeHostX11 is set up |
288 // correctly. | 327 // correctly. |
289 ASSERT_EQ(3u, DesktopWindowTreeHostX11::GetAllOpenWindows().size()); | 328 ASSERT_EQ(3u, DesktopWindowTreeHostX11::GetAllOpenWindows().size()); |
290 | 329 |
291 EXPECT_EQ(window_one->GetNativeWindow(), | 330 EXPECT_EQ(window_one->GetNativeWindow(), |
(...skipping 18 matching lines...) Expand all Loading... | |
310 } | 349 } |
311 | 350 |
312 TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) { | 351 TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) { |
313 // Set up a two monitor situation. | 352 // Set up a two monitor situation. |
314 std::vector<gfx::Display> displays; | 353 std::vector<gfx::Display> displays; |
315 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | 354 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); |
316 displays.push_back(gfx::Display(kSecondDisplay, | 355 displays.push_back(gfx::Display(kSecondDisplay, |
317 gfx::Rect(640, 0, 1024, 768))); | 356 gfx::Rect(640, 0, 1024, 768))); |
318 screen()->ProcessDisplayChange(displays); | 357 screen()->ProcessDisplayChange(displays); |
319 | 358 |
320 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(10, 10, 10, 10)); | 359 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(10, 10, 10, 10), |
321 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(650, 50, 10, 10)); | 360 false); |
361 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(650, 50, 10, 10), | |
362 false); | |
322 | 363 |
323 EXPECT_EQ( | 364 EXPECT_EQ( |
324 kFirstDisplay, | 365 kFirstDisplay, |
325 screen()->GetDisplayNearestWindow(window_one->GetNativeWindow()).id()); | 366 screen()->GetDisplayNearestWindow(window_one->GetNativeWindow()).id()); |
326 EXPECT_EQ( | 367 EXPECT_EQ( |
327 kSecondDisplay, | 368 kSecondDisplay, |
328 screen()->GetDisplayNearestWindow(window_two->GetNativeWindow()).id()); | 369 screen()->GetDisplayNearestWindow(window_two->GetNativeWindow()).id()); |
329 | 370 |
330 window_one->CloseNow(); | 371 window_one->CloseNow(); |
331 window_two->CloseNow(); | 372 window_two->CloseNow(); |
332 } | 373 } |
333 | 374 |
375 // Tests that the window is maximized in response to a double click event. | |
376 TEST_F(DesktopScreenX11Test, DoubleClickHeaderMaximizes) { | |
377 Widget* widget = BuildTopLevelDesktopWidget(gfx::Rect(0, 0, 100, 100), true); | |
378 widget->Show(); | |
379 TestDesktopNativeWidgetAura* native_widget = | |
380 static_cast<TestDesktopNativeWidgetAura*>(widget->native_widget()); | |
381 native_widget->set_window_component(HTCAPTION); | |
382 | |
383 aura::Window* window = widget->GetNativeWindow(); | |
384 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
385 | |
386 // Cast to superclass as DesktopWindowTreeHostX11 hide IsMaximized | |
387 DesktopWindowTreeHost* rwh = static_cast<DesktopWindowTreeHost*>( | |
sadrul
2014/04/10 20:49:59
You shouldn't need the static_cast<>
jonross
2014/04/11 16:46:41
Done.
| |
388 DesktopWindowTreeHostX11::GetHostForXID(window->GetHost()-> | |
389 GetAcceleratedWidget())); | |
390 | |
391 aura::test::EventGenerator generator(window); | |
392 generator.ClickLeftButton(); | |
393 generator.DoubleClickLeftButton(); | |
394 RunPendingMessages(); | |
395 EXPECT_TRUE(rwh->IsMaximized()); | |
396 | |
397 widget->CloseNow(); | |
398 } | |
399 | |
400 // Tests that the window does not maximize in response to a double click event, | |
401 // if the first click was to a different target component than that of the | |
402 // second click. | |
403 TEST_F(DesktopScreenX11Test, DoubleClickTwoDifferentTargetsDoesntMaximizes) { | |
404 Widget* widget = BuildTopLevelDesktopWidget(gfx::Rect(0, 0, 100, 100), true); | |
405 widget->Show(); | |
406 TestDesktopNativeWidgetAura* native_widget = | |
407 static_cast<TestDesktopNativeWidgetAura*>(widget->native_widget()); | |
408 | |
409 aura::Window* window = widget->GetNativeWindow(); | |
410 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
411 | |
412 // Cast to superclass as DesktopWindowTreeHostX11 hide IsMaximized | |
413 DesktopWindowTreeHost* rwh = static_cast<DesktopWindowTreeHost*>( | |
sadrul
2014/04/10 20:49:59
ditto
jonross
2014/04/11 16:46:41
Done.
| |
414 DesktopWindowTreeHostX11::GetHostForXID(window->GetHost()-> | |
415 GetAcceleratedWidget())); | |
416 | |
417 aura::test::EventGenerator generator(window); | |
418 native_widget->set_window_component(HTCLIENT); | |
sadrul
2014/04/10 20:49:59
Would a test with both components being non-CLIENT
jonross
2014/04/11 16:46:41
The behaviour being tested for should not depend o
| |
419 generator.ClickLeftButton(); | |
420 native_widget->set_window_component(HTCAPTION); | |
421 generator.DoubleClickLeftButton(); | |
422 RunPendingMessages(); | |
423 EXPECT_FALSE(rwh->IsMaximized()); | |
424 | |
425 widget->CloseNow(); | |
426 } | |
427 | |
428 // Tests that the window does not maximize in response to a double click event, | |
429 // if the double click was interrupted by a right click. | |
430 TEST_F(DesktopScreenX11Test, RightClickDuringDoubleClickDoesntMaximize) { | |
431 Widget* widget = BuildTopLevelDesktopWidget(gfx::Rect(0, 0, 100, 100), true); | |
432 widget->Show(); | |
433 TestDesktopNativeWidgetAura* native_widget = | |
434 static_cast<TestDesktopNativeWidgetAura*>(widget->native_widget()); | |
435 | |
436 aura::Window* window = widget->GetNativeWindow(); | |
437 window->SetProperty(aura::client::kCanMaximizeKey, true); | |
438 | |
439 // Cast to superclass as DesktopWindowTreeHostX11 hide IsMaximized | |
440 DesktopWindowTreeHost* rwh = static_cast<DesktopWindowTreeHost*>( | |
441 DesktopWindowTreeHostX11::GetHostForXID(window->GetHost()-> | |
442 GetAcceleratedWidget())); | |
443 | |
444 aura::test::EventGenerator generator(window); | |
445 native_widget->set_window_component(HTCLIENT); | |
446 generator.ClickLeftButton(); | |
447 native_widget->set_window_component(HTCAPTION); | |
448 generator.PressRightButton(); | |
449 generator.ReleaseRightButton(); | |
450 EXPECT_FALSE(rwh->IsMaximized()); | |
451 generator.DoubleClickLeftButton(); | |
452 RunPendingMessages(); | |
453 EXPECT_FALSE(rwh->IsMaximized()); | |
454 | |
455 widget->CloseNow(); | |
456 } | |
457 | |
334 } // namespace views | 458 } // namespace views |
OLD | NEW |