| 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" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/test/event_generator.h" | 10 #include "ui/aura/test/event_generator.h" |
| 13 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/aura/window_tree_host.h" | |
| 16 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
| 17 #include "ui/base/x/x11_util.h" | 14 #include "ui/base/x/x11_util.h" |
| 18 #include "ui/events/platform/platform_event_dispatcher.h" | |
| 19 #include "ui/events/platform/platform_event_source.h" | |
| 20 #include "ui/gfx/display_observer.h" | 15 #include "ui/gfx/display_observer.h" |
| 21 #include "ui/gfx/x/x11_atom_cache.h" | |
| 22 #include "ui/gfx/x/x11_types.h" | 16 #include "ui/gfx/x/x11_types.h" |
| 23 #include "ui/views/test/views_test_base.h" | 17 #include "ui/views/test/views_test_base.h" |
| 24 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 18 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 25 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 19 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 26 | 20 |
| 27 namespace { | 21 namespace { |
| 28 | 22 |
| 29 // Class which allows for the designation of non-client component targets of | 23 // Class which allows for the designation of non-client component targets of |
| 30 // hit tests. | 24 // hit tests. |
| 31 class TestDesktopNativeWidgetAura : public views::DesktopNativeWidgetAura { | 25 class TestDesktopNativeWidgetAura : public views::DesktopNativeWidgetAura { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 50 DISALLOW_COPY_AND_ASSIGN(TestDesktopNativeWidgetAura); | 44 DISALLOW_COPY_AND_ASSIGN(TestDesktopNativeWidgetAura); |
| 51 }; | 45 }; |
| 52 | 46 |
| 53 } // namespace | 47 } // namespace |
| 54 | 48 |
| 55 namespace views { | 49 namespace views { |
| 56 | 50 |
| 57 const int64 kFirstDisplay = 5321829; | 51 const int64 kFirstDisplay = 5321829; |
| 58 const int64 kSecondDisplay = 928310; | 52 const int64 kSecondDisplay = 928310; |
| 59 | 53 |
| 60 // Class which waits till the X11 window associated with the widget passed into | |
| 61 // the constructor is activated. We cannot listen for the widget's activation | |
| 62 // because the _NET_ACTIVE_WINDOW property is changed after the widget is | |
| 63 // activated. | |
| 64 class ActivationWaiter : public ui::PlatformEventDispatcher { | |
| 65 public: | |
| 66 explicit ActivationWaiter(views::Widget* widget) | |
| 67 : x_root_window_(DefaultRootWindow(gfx::GetXDisplay())), | |
| 68 widget_xid_(0), | |
| 69 active_(false) { | |
| 70 const char* kAtomToCache[] = { | |
| 71 "_NET_ACTIVE_WINDOW", | |
| 72 NULL | |
| 73 }; | |
| 74 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomToCache)); | |
| 75 widget_xid_ = widget->GetNativeWindow()->GetHost()-> | |
| 76 GetAcceleratedWidget(); | |
| 77 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | |
| 78 } | |
| 79 | |
| 80 virtual ~ActivationWaiter() { | |
| 81 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); | |
| 82 } | |
| 83 | |
| 84 // Blocks till |widget_xid_| becomes active. | |
| 85 void Wait() { | |
| 86 if (active_) | |
| 87 return; | |
| 88 base::RunLoop run_loop; | |
| 89 quit_closure_ = run_loop.QuitClosure(); | |
| 90 run_loop.Run(); | |
| 91 } | |
| 92 | |
| 93 // ui::PlatformEventDispatcher: | |
| 94 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { | |
| 95 return event->type == PropertyNotify && | |
| 96 event->xproperty.window == x_root_window_; | |
| 97 } | |
| 98 | |
| 99 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { | |
| 100 ::Window xid; | |
| 101 CHECK_EQ(PropertyNotify, event->type); | |
| 102 CHECK_EQ(x_root_window_, event->xproperty.window); | |
| 103 | |
| 104 if (event->xproperty.atom == atom_cache_->GetAtom("_NET_ACTIVE_WINDOW") && | |
| 105 ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &xid) && | |
| 106 xid == widget_xid_) { | |
| 107 active_ = true; | |
| 108 if (!quit_closure_.is_null()) | |
| 109 quit_closure_.Run(); | |
| 110 } | |
| 111 return ui::POST_DISPATCH_NONE; | |
| 112 } | |
| 113 | |
| 114 private: | |
| 115 scoped_ptr<ui::X11AtomCache> atom_cache_; | |
| 116 ::Window x_root_window_; | |
| 117 ::Window widget_xid_; | |
| 118 | |
| 119 bool active_; | |
| 120 base::Closure quit_closure_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(ActivationWaiter); | |
| 123 }; | |
| 124 | |
| 125 class DesktopScreenX11Test : public views::ViewsTestBase, | 54 class DesktopScreenX11Test : public views::ViewsTestBase, |
| 126 public gfx::DisplayObserver { | 55 public gfx::DisplayObserver { |
| 127 public: | 56 public: |
| 128 DesktopScreenX11Test() {} | 57 DesktopScreenX11Test() {} |
| 129 virtual ~DesktopScreenX11Test() {} | 58 virtual ~DesktopScreenX11Test() {} |
| 130 | 59 |
| 131 // Overridden from testing::Test: | 60 // Overridden from testing::Test: |
| 132 virtual void SetUp() OVERRIDE { | 61 virtual void SetUp() OVERRIDE { |
| 133 ViewsTestBase::SetUp(); | 62 ViewsTestBase::SetUp(); |
| 134 // Initialize the world to the single monitor case. | 63 // Initialize the world to the single monitor case. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 displays.push_back(gfx::Display(kFirstDisplay, | 233 displays.push_back(gfx::Display(kFirstDisplay, |
| 305 gfx::Rect(640, 0, 1024, 768))); | 234 gfx::Rect(640, 0, 1024, 768))); |
| 306 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); | 235 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); |
| 307 screen()->ProcessDisplayChange(displays); | 236 screen()->ProcessDisplayChange(displays); |
| 308 | 237 |
| 309 // The first display in the list is always the primary, even if other | 238 // The first display in the list is always the primary, even if other |
| 310 // displays are to the left in screen layout. | 239 // displays are to the left in screen layout. |
| 311 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); | 240 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); |
| 312 } | 241 } |
| 313 | 242 |
| 314 TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) { | |
| 315 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10), | |
| 316 false); | |
| 317 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10), | |
| 318 false); | |
| 319 Widget* window_three = | |
| 320 BuildTopLevelDesktopWidget(gfx::Rect(115, 115, 20, 20), false); | |
| 321 | |
| 322 window_three->Show(); | |
| 323 window_two->Show(); | |
| 324 window_one->Show(); | |
| 325 | |
| 326 // Make sure the internal state of DesktopWindowTreeHostX11 is set up | |
| 327 // correctly. | |
| 328 ASSERT_EQ(3u, DesktopWindowTreeHostX11::GetAllOpenWindows().size()); | |
| 329 | |
| 330 EXPECT_EQ(window_one->GetNativeWindow(), | |
| 331 screen()->GetWindowAtScreenPoint(gfx::Point(115, 115))); | |
| 332 EXPECT_EQ(window_two->GetNativeWindow(), | |
| 333 screen()->GetWindowAtScreenPoint(gfx::Point(155, 155))); | |
| 334 EXPECT_EQ(NULL, | |
| 335 screen()->GetWindowAtScreenPoint(gfx::Point(200, 200))); | |
| 336 | |
| 337 // Bring the third window in front. It overlaps with the first window. | |
| 338 // Hit-testing on the intersecting region should give the third window. | |
| 339 ActivationWaiter activation_waiter(window_three); | |
| 340 window_three->Activate(); | |
| 341 activation_waiter.Wait(); | |
| 342 | |
| 343 EXPECT_EQ(window_three->GetNativeWindow(), | |
| 344 screen()->GetWindowAtScreenPoint(gfx::Point(115, 115))); | |
| 345 | |
| 346 window_one->CloseNow(); | |
| 347 window_two->CloseNow(); | |
| 348 window_three->CloseNow(); | |
| 349 } | |
| 350 | |
| 351 TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) { | 243 TEST_F(DesktopScreenX11Test, GetDisplayNearestWindow) { |
| 352 // Set up a two monitor situation. | 244 // Set up a two monitor situation. |
| 353 std::vector<gfx::Display> displays; | 245 std::vector<gfx::Display> displays; |
| 354 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); | 246 displays.push_back(gfx::Display(kFirstDisplay, gfx::Rect(0, 0, 640, 480))); |
| 355 displays.push_back(gfx::Display(kSecondDisplay, | 247 displays.push_back(gfx::Display(kSecondDisplay, |
| 356 gfx::Rect(640, 0, 1024, 768))); | 248 gfx::Rect(640, 0, 1024, 768))); |
| 357 screen()->ProcessDisplayChange(displays); | 249 screen()->ProcessDisplayChange(displays); |
| 358 | 250 |
| 359 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(10, 10, 10, 10), | 251 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(10, 10, 10, 10), |
| 360 false); | 252 false); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 generator.ReleaseRightButton(); | 341 generator.ReleaseRightButton(); |
| 450 EXPECT_FALSE(rwh->IsMaximized()); | 342 EXPECT_FALSE(rwh->IsMaximized()); |
| 451 generator.DoubleClickLeftButton(); | 343 generator.DoubleClickLeftButton(); |
| 452 RunPendingMessages(); | 344 RunPendingMessages(); |
| 453 EXPECT_FALSE(rwh->IsMaximized()); | 345 EXPECT_FALSE(rwh->IsMaximized()); |
| 454 | 346 |
| 455 widget->CloseNow(); | 347 widget->CloseNow(); |
| 456 } | 348 } |
| 457 | 349 |
| 458 } // namespace views | 350 } // namespace views |
| OLD | NEW |