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/window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
14 #include "ui/base/x/x11_util.h" | 14 #include "ui/base/x/x11_util.h" |
| 15 #include "ui/events/platform/platform_event_dispatcher.h" |
| 16 #include "ui/events/platform/platform_event_source.h" |
| 17 #include "ui/events/platform/x11/x11_event_source.h" |
15 #include "ui/gfx/display_observer.h" | 18 #include "ui/gfx/display_observer.h" |
16 #include "ui/gfx/x/x11_atom_cache.h" | 19 #include "ui/gfx/x/x11_atom_cache.h" |
17 #include "ui/gfx/x/x11_types.h" | 20 #include "ui/gfx/x/x11_types.h" |
18 #include "ui/views/test/views_test_base.h" | 21 #include "ui/views/test/views_test_base.h" |
19 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 22 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
20 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 23 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
21 | 24 |
22 namespace views { | 25 namespace views { |
23 | 26 |
24 const int64 kFirstDisplay = 5321829; | 27 const int64 kFirstDisplay = 5321829; |
25 const int64 kSecondDisplay = 928310; | 28 const int64 kSecondDisplay = 928310; |
26 | 29 |
27 // Class which waits till the X11 window associated with the widget passed into | 30 // Class which waits till the X11 window associated with the widget passed into |
28 // the constructor is activated. We cannot listen for the widget's activation | 31 // the constructor is activated. We cannot listen for the widget's activation |
29 // because the _NET_ACTIVE_WINDOW property is changed after the widget is | 32 // because the _NET_ACTIVE_WINDOW property is changed after the widget is |
30 // activated. | 33 // activated. |
31 class ActivationWaiter : public base::MessagePumpDispatcher { | 34 class ActivationWaiter : public ui::PlatformEventDispatcher { |
32 public: | 35 public: |
33 explicit ActivationWaiter(views::Widget* widget) | 36 explicit ActivationWaiter(views::Widget* widget) |
34 : x_root_window_(DefaultRootWindow(gfx::GetXDisplay())), | 37 : x_root_window_(DefaultRootWindow(gfx::GetXDisplay())), |
35 widget_xid_(0), | 38 widget_xid_(0), |
36 active_(false) { | 39 active_(false) { |
37 const char* kAtomToCache[] = { | 40 const char* kAtomToCache[] = { |
38 "_NET_ACTIVE_WINDOW", | 41 "_NET_ACTIVE_WINDOW", |
39 NULL | 42 NULL |
40 }; | 43 }; |
41 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomToCache)); | 44 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomToCache)); |
42 widget_xid_ = widget->GetNativeWindow()->GetHost()-> | 45 widget_xid_ = widget->GetNativeWindow()->GetHost()-> |
43 GetAcceleratedWidget(); | 46 GetAcceleratedWidget(); |
44 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); | 47 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
45 } | 48 } |
46 | 49 |
47 virtual ~ActivationWaiter() { | 50 virtual ~ActivationWaiter() { |
48 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); | 51 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
49 } | 52 } |
50 | 53 |
51 // Blocks till |widget_xid_| becomes active. | 54 // Blocks till |widget_xid_| becomes active. |
52 void Wait() { | 55 void Wait() { |
53 if (active_) | 56 if (active_) |
54 return; | 57 return; |
55 base::RunLoop run_loop; | 58 base::RunLoop run_loop; |
56 quit_closure_ = run_loop.QuitClosure(); | 59 quit_closure_ = run_loop.QuitClosure(); |
57 run_loop.Run(); | 60 run_loop.Run(); |
58 } | 61 } |
59 | 62 |
60 virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE { | 63 // ui::PlatformEventDispatcher: |
| 64 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
| 65 return event->type == PropertyNotify && |
| 66 event->xproperty.window == x_root_window_; |
| 67 } |
| 68 |
| 69 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
61 ::Window xid; | 70 ::Window xid; |
62 if (event->type == PropertyNotify && | 71 CHECK_EQ(PropertyNotify, event->type); |
63 event->xproperty.window == x_root_window_ && | 72 CHECK_EQ(x_root_window_, event->xproperty.window); |
64 event->xproperty.atom == atom_cache_->GetAtom("_NET_ACTIVE_WINDOW") && | 73 |
| 74 if (event->xproperty.atom == atom_cache_->GetAtom("_NET_ACTIVE_WINDOW") && |
65 ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &xid) && | 75 ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &xid) && |
66 xid == widget_xid_) { | 76 xid == widget_xid_) { |
67 active_ = true; | 77 active_ = true; |
68 if (!quit_closure_.is_null()) | 78 if (!quit_closure_.is_null()) |
69 quit_closure_.Run(); | 79 quit_closure_.Run(); |
70 } | 80 } |
71 return POST_DISPATCH_NONE; | 81 return ui::POST_DISPATCH_NONE; |
72 } | 82 } |
73 | 83 |
74 private: | 84 private: |
75 scoped_ptr<ui::X11AtomCache> atom_cache_; | 85 scoped_ptr<ui::X11AtomCache> atom_cache_; |
76 ::Window x_root_window_; | 86 ::Window x_root_window_; |
77 ::Window widget_xid_; | 87 ::Window widget_xid_; |
78 | 88 |
79 bool active_; | 89 bool active_; |
80 base::Closure quit_closure_; | 90 base::Closure quit_closure_; |
81 | 91 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 gfx::Rect(640, 0, 1024, 768))); | 269 gfx::Rect(640, 0, 1024, 768))); |
260 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); | 270 displays.push_back(gfx::Display(kSecondDisplay, gfx::Rect(0, 0, 640, 480))); |
261 screen()->ProcessDisplayChange(displays); | 271 screen()->ProcessDisplayChange(displays); |
262 | 272 |
263 // The first display in the list is always the primary, even if other | 273 // The first display in the list is always the primary, even if other |
264 // displays are to the left in screen layout. | 274 // displays are to the left in screen layout. |
265 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); | 275 EXPECT_EQ(kFirstDisplay, screen()->GetPrimaryDisplay().id()); |
266 } | 276 } |
267 | 277 |
268 TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) { | 278 TEST_F(DesktopScreenX11Test, GetWindowAtScreenPoint) { |
| 279 ui::X11EventSource x11_source(gfx::GetXDisplay()); |
269 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10)); | 280 Widget* window_one = BuildTopLevelDesktopWidget(gfx::Rect(110, 110, 10, 10)); |
270 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10)); | 281 Widget* window_two = BuildTopLevelDesktopWidget(gfx::Rect(150, 150, 10, 10)); |
271 Widget* window_three = | 282 Widget* window_three = |
272 BuildTopLevelDesktopWidget(gfx::Rect(115, 115, 20, 20)); | 283 BuildTopLevelDesktopWidget(gfx::Rect(115, 115, 20, 20)); |
273 | 284 |
274 window_three->Show(); | 285 window_three->Show(); |
275 window_two->Show(); | 286 window_two->Show(); |
276 window_one->Show(); | 287 window_one->Show(); |
277 | 288 |
278 // Make sure the internal state of DesktopWindowTreeHostX11 is set up | 289 // Make sure the internal state of DesktopWindowTreeHostX11 is set up |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 screen()->GetDisplayNearestWindow(window_one->GetNativeWindow()).id()); | 327 screen()->GetDisplayNearestWindow(window_one->GetNativeWindow()).id()); |
317 EXPECT_EQ( | 328 EXPECT_EQ( |
318 kSecondDisplay, | 329 kSecondDisplay, |
319 screen()->GetDisplayNearestWindow(window_two->GetNativeWindow()).id()); | 330 screen()->GetDisplayNearestWindow(window_two->GetNativeWindow()).id()); |
320 | 331 |
321 window_one->CloseNow(); | 332 window_one->CloseNow(); |
322 window_two->CloseNow(); | 333 window_two->CloseNow(); |
323 } | 334 } |
324 | 335 |
325 } // namespace views | 336 } // namespace views |
OLD | NEW |