| 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" |
| 15 #include "ui/gfx/display_observer.h" | 17 #include "ui/gfx/display_observer.h" |
| 16 #include "ui/gfx/x/x11_atom_cache.h" | 18 #include "ui/gfx/x/x11_atom_cache.h" |
| 17 #include "ui/gfx/x/x11_types.h" | 19 #include "ui/gfx/x/x11_types.h" |
| 18 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
| 19 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 21 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 20 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 22 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| 21 | 23 |
| 22 namespace views { | 24 namespace views { |
| 23 | 25 |
| 24 const int64 kFirstDisplay = 5321829; | 26 const int64 kFirstDisplay = 5321829; |
| 25 const int64 kSecondDisplay = 928310; | 27 const int64 kSecondDisplay = 928310; |
| 26 | 28 |
| 27 // Class which waits till the X11 window associated with the widget passed into | 29 // 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 | 30 // 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 | 31 // because the _NET_ACTIVE_WINDOW property is changed after the widget is |
| 30 // activated. | 32 // activated. |
| 31 class ActivationWaiter : public base::MessagePumpDispatcher { | 33 class ActivationWaiter : public ui::PlatformEventDispatcher { |
| 32 public: | 34 public: |
| 33 explicit ActivationWaiter(views::Widget* widget) | 35 explicit ActivationWaiter(views::Widget* widget) |
| 34 : x_root_window_(DefaultRootWindow(gfx::GetXDisplay())), | 36 : x_root_window_(DefaultRootWindow(gfx::GetXDisplay())), |
| 35 widget_xid_(0), | 37 widget_xid_(0), |
| 36 active_(false) { | 38 active_(false) { |
| 37 const char* kAtomToCache[] = { | 39 const char* kAtomToCache[] = { |
| 38 "_NET_ACTIVE_WINDOW", | 40 "_NET_ACTIVE_WINDOW", |
| 39 NULL | 41 NULL |
| 40 }; | 42 }; |
| 41 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomToCache)); | 43 atom_cache_.reset(new ui::X11AtomCache(gfx::GetXDisplay(), kAtomToCache)); |
| 42 widget_xid_ = widget->GetNativeWindow()->GetHost()-> | 44 widget_xid_ = widget->GetNativeWindow()->GetHost()-> |
| 43 GetAcceleratedWidget(); | 45 GetAcceleratedWidget(); |
| 44 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); | 46 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
| 45 } | 47 } |
| 46 | 48 |
| 47 virtual ~ActivationWaiter() { | 49 virtual ~ActivationWaiter() { |
| 48 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); | 50 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
| 49 } | 51 } |
| 50 | 52 |
| 51 // Blocks till |widget_xid_| becomes active. | 53 // Blocks till |widget_xid_| becomes active. |
| 52 void Wait() { | 54 void Wait() { |
| 53 if (active_) | 55 if (active_) |
| 54 return; | 56 return; |
| 55 base::RunLoop run_loop; | 57 base::RunLoop run_loop; |
| 56 quit_closure_ = run_loop.QuitClosure(); | 58 quit_closure_ = run_loop.QuitClosure(); |
| 57 run_loop.Run(); | 59 run_loop.Run(); |
| 58 } | 60 } |
| 59 | 61 |
| 60 virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE { | 62 // ui::PlatformEventDispatcher: |
| 63 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
| 64 return event->type == PropertyNotify && |
| 65 event->xproperty.window == x_root_window_; |
| 66 } |
| 67 |
| 68 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE { |
| 61 ::Window xid; | 69 ::Window xid; |
| 62 if (event->type == PropertyNotify && | 70 CHECK_EQ(PropertyNotify, event->type); |
| 63 event->xproperty.window == x_root_window_ && | 71 CHECK_EQ(x_root_window_, event->xproperty.window); |
| 64 event->xproperty.atom == atom_cache_->GetAtom("_NET_ACTIVE_WINDOW") && | 72 |
| 73 if (event->xproperty.atom == atom_cache_->GetAtom("_NET_ACTIVE_WINDOW") && |
| 65 ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &xid) && | 74 ui::GetXIDProperty(x_root_window_, "_NET_ACTIVE_WINDOW", &xid) && |
| 66 xid == widget_xid_) { | 75 xid == widget_xid_) { |
| 67 active_ = true; | 76 active_ = true; |
| 68 if (!quit_closure_.is_null()) | 77 if (!quit_closure_.is_null()) |
| 69 quit_closure_.Run(); | 78 quit_closure_.Run(); |
| 70 } | 79 } |
| 71 return POST_DISPATCH_NONE; | 80 return ui::POST_DISPATCH_NONE; |
| 72 } | 81 } |
| 73 | 82 |
| 74 private: | 83 private: |
| 75 scoped_ptr<ui::X11AtomCache> atom_cache_; | 84 scoped_ptr<ui::X11AtomCache> atom_cache_; |
| 76 ::Window x_root_window_; | 85 ::Window x_root_window_; |
| 77 ::Window widget_xid_; | 86 ::Window widget_xid_; |
| 78 | 87 |
| 79 bool active_; | 88 bool active_; |
| 80 base::Closure quit_closure_; | 89 base::Closure quit_closure_; |
| 81 | 90 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 screen()->GetDisplayNearestWindow(window_one->GetNativeWindow()).id()); | 325 screen()->GetDisplayNearestWindow(window_one->GetNativeWindow()).id()); |
| 317 EXPECT_EQ( | 326 EXPECT_EQ( |
| 318 kSecondDisplay, | 327 kSecondDisplay, |
| 319 screen()->GetDisplayNearestWindow(window_two->GetNativeWindow()).id()); | 328 screen()->GetDisplayNearestWindow(window_two->GetNativeWindow()).id()); |
| 320 | 329 |
| 321 window_one->CloseNow(); | 330 window_one->CloseNow(); |
| 322 window_two->CloseNow(); | 331 window_two->CloseNow(); |
| 323 } | 332 } |
| 324 | 333 |
| 325 } // namespace views | 334 } // namespace views |
| OLD | NEW |