| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/platform_window/x11/x11_window_ozone.h" | 5 #include "ui/platform_window/x11/x11_window_ozone.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| 11 #include "ui/events/ozone/events_ozone.h" | 11 #include "ui/events/ozone/events_ozone.h" |
| 12 #include "ui/events/platform/x11/x11_event_source.h" | 12 #include "ui/events/platform/x11/x11_event_source.h" |
| 13 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
| 14 #include "ui/platform_window/x11/x11_cursor_ozone.h" | 14 #include "ui/platform_window/x11/x11_cursor_ozone.h" |
| 15 #include "ui/platform_window/x11/x11_window_manager_ozone.h" | 15 #include "ui/platform_window/x11/x11_window_manager_ozone.h" |
| 16 | 16 |
| 17 namespace ui { | 17 namespace ui { |
| 18 | 18 |
| 19 X11WindowOzone::X11WindowOzone(X11EventSourceLibevent* event_source, | 19 X11WindowOzone::X11WindowOzone(X11WindowManagerOzone* window_manager, |
| 20 X11WindowManagerOzone* window_manager, | |
| 21 PlatformWindowDelegate* delegate, | 20 PlatformWindowDelegate* delegate, |
| 22 const gfx::Rect& bounds) | 21 const gfx::Rect& bounds) |
| 23 : X11WindowBase(delegate, bounds), | 22 : X11WindowBase(delegate, bounds), window_manager_(window_manager) { |
| 24 event_source_(event_source), | |
| 25 window_manager_(window_manager) { | |
| 26 DCHECK(event_source_); | |
| 27 DCHECK(window_manager); | 23 DCHECK(window_manager); |
| 28 event_source_->AddPlatformEventDispatcher(this); | 24 auto* event_source = X11EventSourceLibevent::GetInstance(); |
| 29 event_source_->AddXEventDispatcher(this); | 25 if (event_source) { |
| 26 event_source->AddPlatformEventDispatcher(this); |
| 27 event_source->AddXEventDispatcher(this); |
| 28 } |
| 30 } | 29 } |
| 31 | 30 |
| 32 X11WindowOzone::~X11WindowOzone() { | 31 X11WindowOzone::~X11WindowOzone() { |
| 33 event_source_->RemovePlatformEventDispatcher(this); | 32 X11WindowOzone::PrepareForShutdown(); |
| 34 event_source_->RemoveXEventDispatcher(this); | 33 } |
| 34 |
| 35 void X11WindowOzone::PrepareForShutdown() { |
| 36 auto* event_source = X11EventSourceLibevent::GetInstance(); |
| 37 if (event_source) { |
| 38 event_source->RemovePlatformEventDispatcher(this); |
| 39 event_source->RemoveXEventDispatcher(this); |
| 40 } |
| 35 } | 41 } |
| 36 | 42 |
| 37 void X11WindowOzone::SetCapture() { | 43 void X11WindowOzone::SetCapture() { |
| 38 window_manager_->GrabEvents(xwindow()); | 44 window_manager_->GrabEvents(xwindow()); |
| 39 } | 45 } |
| 40 | 46 |
| 41 void X11WindowOzone::ReleaseCapture() { | 47 void X11WindowOzone::ReleaseCapture() { |
| 42 window_manager_->UngrabEvents(xwindow()); | 48 window_manager_->UngrabEvents(xwindow()); |
| 43 } | 49 } |
| 44 | 50 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 uint32_t X11WindowOzone::DispatchEvent(const PlatformEvent& platform_event) { | 84 uint32_t X11WindowOzone::DispatchEvent(const PlatformEvent& platform_event) { |
| 79 // This is unfortunately needed otherwise events that depend on global state | 85 // This is unfortunately needed otherwise events that depend on global state |
| 80 // (eg. double click) are broken. | 86 // (eg. double click) are broken. |
| 81 DispatchEventFromNativeUiEvent( | 87 DispatchEventFromNativeUiEvent( |
| 82 platform_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, | 88 platform_event, base::Bind(&PlatformWindowDelegate::DispatchEvent, |
| 83 base::Unretained(delegate()))); | 89 base::Unretained(delegate()))); |
| 84 return POST_DISPATCH_STOP_PROPAGATION; | 90 return POST_DISPATCH_STOP_PROPAGATION; |
| 85 } | 91 } |
| 86 | 92 |
| 87 } // namespace ui | 93 } // namespace ui |
| OLD | NEW |