| 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/platform_window/x11/x11_window.h" | 5 #include "ui/platform_window/x11/x11_window.h" |
| 6 | 6 |
| 7 #include <X11/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
| 8 #include <X11/Xatom.h> | 8 #include <X11/Xatom.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 X11Window::X11Window(PlatformWindowDelegate* delegate) | 43 X11Window::X11Window(PlatformWindowDelegate* delegate) |
| 44 : delegate_(delegate), | 44 : delegate_(delegate), |
| 45 xdisplay_(gfx::GetXDisplay()), | 45 xdisplay_(gfx::GetXDisplay()), |
| 46 xwindow_(None), | 46 xwindow_(None), |
| 47 xroot_window_(DefaultRootWindow(xdisplay_)), | 47 xroot_window_(DefaultRootWindow(xdisplay_)), |
| 48 atom_cache_(xdisplay_, kAtomsToCache), | 48 atom_cache_(xdisplay_, kAtomsToCache), |
| 49 window_mapped_(false) { | 49 window_mapped_(false), |
| 50 destroyed_(false) { |
| 50 CHECK(delegate_); | 51 CHECK(delegate_); |
| 51 TouchFactory::SetTouchDeviceListFromCommandLine(); | 52 TouchFactory::SetTouchDeviceListFromCommandLine(); |
| 52 } | 53 } |
| 53 | 54 |
| 54 X11Window::~X11Window() { | 55 X11Window::~X11Window() { |
| 55 Destroy(); | 56 Destroy(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void X11Window::Destroy() { | 59 void X11Window::Destroy() { |
| 59 delegate_->OnClosed(); | 60 if (destroyed_) |
| 60 if (xwindow_ == None) | |
| 61 return; | 61 return; |
| 62 | 62 |
| 63 // Stop processing events. | 63 destroyed_ = true; |
| 64 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); | 64 |
| 65 XDestroyWindow(xdisplay_, xwindow_); | 65 if (xwindow_ != None) { |
| 66 xwindow_ = None; | 66 // Stop processing events. |
| 67 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
| 68 XDestroyWindow(xdisplay_, xwindow_); |
| 69 xwindow_ = None; |
| 70 } |
| 71 |
| 72 delegate_->OnClosed(); |
| 73 // |this| could be deleted now. |
| 67 } | 74 } |
| 68 | 75 |
| 69 void X11Window::ProcessXInput2Event(XEvent* xev) { | 76 void X11Window::ProcessXInput2Event(XEvent* xev) { |
| 70 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) | 77 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) |
| 71 return; | 78 return; |
| 72 EventType event_type = EventTypeFromNative(xev); | 79 EventType event_type = EventTypeFromNative(xev); |
| 73 switch (event_type) { | 80 switch (event_type) { |
| 74 case ET_KEY_PRESSED: | 81 case ET_KEY_PRESSED: |
| 75 case ET_KEY_RELEASED: { | 82 case ET_KEY_RELEASED: { |
| 76 KeyEvent key_event(xev); | 83 KeyEvent key_event(xev); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 362 |
| 356 case GenericEvent: { | 363 case GenericEvent: { |
| 357 ProcessXInput2Event(xev); | 364 ProcessXInput2Event(xev); |
| 358 break; | 365 break; |
| 359 } | 366 } |
| 360 } | 367 } |
| 361 return POST_DISPATCH_STOP_PROPAGATION; | 368 return POST_DISPATCH_STOP_PROPAGATION; |
| 362 } | 369 } |
| 363 | 370 |
| 364 } // namespace ui | 371 } // namespace ui |
| OLD | NEW |