| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/x11_property_change_waiter.h" | 5 #include "ui/views/test/x11_property_change_waiter.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "ui/base/x/x11_util.h" |
| 10 #include "ui/base/x/x11_window_event_manager.h" | 11 #include "ui/base/x/x11_window_event_manager.h" |
| 11 #include "ui/events/platform/platform_event_source.h" | 12 #include "ui/events/platform/platform_event_source.h" |
| 12 #include "ui/events/platform/scoped_event_dispatcher.h" | 13 #include "ui/events/platform/scoped_event_dispatcher.h" |
| 13 #include "ui/gfx/x/x11_atom_cache.h" | |
| 14 | 14 |
| 15 namespace views { | 15 namespace views { |
| 16 | 16 |
| 17 X11PropertyChangeWaiter::X11PropertyChangeWaiter(XID window, | 17 X11PropertyChangeWaiter::X11PropertyChangeWaiter(XID window, |
| 18 const char* property) | 18 const char* property) |
| 19 : x_window_(window), property_(property), wait_(true) { | 19 : x_window_(window), property_(property), wait_(true) { |
| 20 Display* display = gfx::GetXDisplay(); | |
| 21 | |
| 22 // Ensure that we are listening to PropertyNotify events for |window|. This | 20 // Ensure that we are listening to PropertyNotify events for |window|. This |
| 23 // is not the case for windows which were not created by | 21 // is not the case for windows which were not created by |
| 24 // DesktopWindowTreeHostX11. | 22 // DesktopWindowTreeHostX11. |
| 25 x_window_events_.reset( | 23 x_window_events_.reset( |
| 26 new ui::XScopedEventSelector(x_window_, PropertyChangeMask)); | 24 new ui::XScopedEventSelector(x_window_, PropertyChangeMask)); |
| 27 | 25 |
| 28 const char* kAtomsToCache[] = { property, NULL }; | |
| 29 atom_cache_.reset(new ui::X11AtomCache(display, kAtomsToCache)); | |
| 30 | |
| 31 // Override the dispatcher so that we get events before | 26 // Override the dispatcher so that we get events before |
| 32 // DesktopWindowTreeHostX11 does. We must do this because | 27 // DesktopWindowTreeHostX11 does. We must do this because |
| 33 // DesktopWindowTreeHostX11 stops propagation. | 28 // DesktopWindowTreeHostX11 stops propagation. |
| 34 dispatcher_ = | 29 dispatcher_ = |
| 35 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(this); | 30 ui::PlatformEventSource::GetInstance()->OverrideDispatcher(this); |
| 36 } | 31 } |
| 37 | 32 |
| 38 X11PropertyChangeWaiter::~X11PropertyChangeWaiter() {} | 33 X11PropertyChangeWaiter::~X11PropertyChangeWaiter() {} |
| 39 | 34 |
| 40 void X11PropertyChangeWaiter::Wait() { | 35 void X11PropertyChangeWaiter::Wait() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 return true; | 49 return true; |
| 55 } | 50 } |
| 56 | 51 |
| 57 bool X11PropertyChangeWaiter::CanDispatchEvent(const ui::PlatformEvent& event) { | 52 bool X11PropertyChangeWaiter::CanDispatchEvent(const ui::PlatformEvent& event) { |
| 58 NOTREACHED(); | 53 NOTREACHED(); |
| 59 return true; | 54 return true; |
| 60 } | 55 } |
| 61 | 56 |
| 62 uint32_t X11PropertyChangeWaiter::DispatchEvent( | 57 uint32_t X11PropertyChangeWaiter::DispatchEvent( |
| 63 const ui::PlatformEvent& event) { | 58 const ui::PlatformEvent& event) { |
| 64 if (!wait_ || | 59 if (!wait_ || event->type != PropertyNotify || |
| 65 event->type != PropertyNotify || | |
| 66 event->xproperty.window != x_window_ || | 60 event->xproperty.window != x_window_ || |
| 67 event->xproperty.atom != atom_cache_->GetAtom(property_) || | 61 event->xproperty.atom != ui::GetAtom(property_) || |
| 68 ShouldKeepOnWaiting(event)) { | 62 ShouldKeepOnWaiting(event)) { |
| 69 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 63 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 70 } | 64 } |
| 71 | 65 |
| 72 wait_ = false; | 66 wait_ = false; |
| 73 if (!quit_closure_.is_null()) | 67 if (!quit_closure_.is_null()) |
| 74 quit_closure_.Run(); | 68 quit_closure_.Run(); |
| 75 return ui::POST_DISPATCH_PERFORM_DEFAULT; | 69 return ui::POST_DISPATCH_PERFORM_DEFAULT; |
| 76 } | 70 } |
| 77 | 71 |
| 78 } // namespace views | 72 } // namespace views |
| OLD | NEW |