Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: mojo/services/native_viewport/native_viewport_x11.cc

Issue 219743002: x11: Move X event handling out of the message-pump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r261267 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "mojo/services/native_viewport/native_viewport.h" 5 #include "mojo/services/native_viewport/native_viewport.h"
6 6
7 #include <X11/Xlib.h> 7 #include <X11/Xlib.h>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/message_loop/message_pump_x11.h" 10 #include "ui/events/platform/platform_event_dispatcher.h"
11 #include "ui/events/platform/platform_event_source.h"
11 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
12 #include "ui/gfx/x/x11_types.h" 13 #include "ui/gfx/x/x11_types.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace services { 16 namespace services {
16 17
17 class NativeViewportX11 : public NativeViewport, 18 class NativeViewportX11 : public NativeViewport,
18 public base::MessagePumpDispatcher { 19 public ui::PlatformEventDispatcher {
19 public: 20 public:
20 NativeViewportX11(NativeViewportDelegate* delegate) 21 NativeViewportX11(NativeViewportDelegate* delegate)
21 : delegate_(delegate) { 22 : delegate_(delegate) {
22 } 23 }
23 24
24 virtual ~NativeViewportX11() { 25 virtual ~NativeViewportX11() {
25 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); 26 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
26 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(window_);
27 27
28 XDestroyWindow(gfx::GetXDisplay(), window_); 28 XDestroyWindow(gfx::GetXDisplay(), window_);
29 } 29 }
30 30
31 private: 31 private:
32 // Overridden from NativeViewport: 32 // Overridden from NativeViewport:
33 virtual void Init(const gfx::Rect& bounds) OVERRIDE { 33 virtual void Init(const gfx::Rect& bounds) OVERRIDE {
34 XDisplay* display = gfx::GetXDisplay(); 34 XDisplay* display = gfx::GetXDisplay();
35 35
36 XSetWindowAttributes swa; 36 XSetWindowAttributes swa;
37 memset(&swa, 0, sizeof(swa)); 37 memset(&swa, 0, sizeof(swa));
38 swa.override_redirect = False; 38 swa.override_redirect = False;
39 39
40 bounds_ = bounds; 40 bounds_ = bounds;
41 window_ = XCreateWindow( 41 window_ = XCreateWindow(
42 display, 42 display,
43 DefaultRootWindow(display), 43 DefaultRootWindow(display),
44 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), 44 bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(),
45 0, // border width 45 0, // border width
46 CopyFromParent, // depth 46 CopyFromParent, // depth
47 InputOutput, 47 InputOutput,
48 CopyFromParent, // visual 48 CopyFromParent, // visual
49 CWBackPixmap | CWOverrideRedirect, 49 CWBackPixmap | CWOverrideRedirect,
50 &swa); 50 &swa);
51 51
52 atom_wm_protocols_ = XInternAtom(display, "WM_PROTOCOLS", 1); 52 atom_wm_protocols_ = XInternAtom(display, "WM_PROTOCOLS", 1);
53 atom_wm_delete_window_ = XInternAtom(display, "WM_DELETE_WINDOW", 1); 53 atom_wm_delete_window_ = XInternAtom(display, "WM_DELETE_WINDOW", 1);
54 XSetWMProtocols(display, window_, &atom_wm_delete_window_, 1); 54 XSetWMProtocols(display, window_, &atom_wm_delete_window_, 1);
55 55
56 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, window_); 56 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
57 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this);
58 57
59 delegate_->OnAcceleratedWidgetAvailable(window_); 58 delegate_->OnAcceleratedWidgetAvailable(window_);
60 } 59 }
61 60
62 virtual void Show() OVERRIDE { 61 virtual void Show() OVERRIDE {
63 XDisplay* display = gfx::GetXDisplay(); 62 XDisplay* display = gfx::GetXDisplay();
64 XMapWindow(display, window_); 63 XMapWindow(display, window_);
65 XFlush(display); 64 XFlush(display);
66 } 65 }
67 66
(...skipping 15 matching lines...) Expand all
83 } 82 }
84 83
85 virtual void SetCapture() OVERRIDE { 84 virtual void SetCapture() OVERRIDE {
86 NOTIMPLEMENTED(); 85 NOTIMPLEMENTED();
87 } 86 }
88 87
89 virtual void ReleaseCapture() OVERRIDE { 88 virtual void ReleaseCapture() OVERRIDE {
90 NOTIMPLEMENTED(); 89 NOTIMPLEMENTED();
91 } 90 }
92 91
93 // Overridden from base::MessagePumpDispatcher: 92 // ui::PlatformEventDispatcher:
94 virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE { 93 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
95 switch (event->type) { 94 return event->type == ClientMessage &&
96 case ClientMessage: { 95 event->xclient.message_type == atom_wm_protocols_;
97 if (event->xclient.message_type == atom_wm_protocols_) { 96 }
98 Atom protocol = static_cast<Atom>(event->xclient.data.l[0]); 97
99 if (protocol == atom_wm_delete_window_) 98 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
100 delegate_->OnDestroyed(); 99 Atom protocol = static_cast<Atom>(event->xclient.data.l[0]);
101 } 100 if (protocol == atom_wm_delete_window_)
102 break; 101 delegate_->OnDestroyed();
103 } 102 return ui::POST_DISPATCH_NONE;
104 }
105 return POST_DISPATCH_NONE;
106 } 103 }
107 104
108 NativeViewportDelegate* delegate_; 105 NativeViewportDelegate* delegate_;
109 gfx::Rect bounds_; 106 gfx::Rect bounds_;
110 XID window_; 107 XID window_;
111 Atom atom_wm_protocols_; 108 Atom atom_wm_protocols_;
112 Atom atom_wm_delete_window_; 109 Atom atom_wm_delete_window_;
113 110
114 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); 111 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11);
115 }; 112 };
116 113
117 // static 114 // static
118 scoped_ptr<NativeViewport> NativeViewport::Create( 115 scoped_ptr<NativeViewport> NativeViewport::Create(
119 shell::Context* context, 116 shell::Context* context,
120 NativeViewportDelegate* delegate) { 117 NativeViewportDelegate* delegate) {
121 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); 118 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass();
122 } 119 }
123 120
124 } // namespace services 121 } // namespace services
125 } // namespace mojo 122 } // namespace mojo
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc ('k') | ui/aura/window_tree_host_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698