OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/message_pump_x.h" | 5 #include "base/message_pump_x.h" |
6 | 6 |
7 #include <X11/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 namespace base { | 88 namespace base { |
89 | 89 |
90 MessagePumpX::MessagePumpX() : MessagePumpGlib(), | 90 MessagePumpX::MessagePumpX() : MessagePumpGlib(), |
91 x_source_(NULL) { | 91 x_source_(NULL) { |
92 InitializeXInput2(); | 92 InitializeXInput2(); |
93 InitXSource(); | 93 InitXSource(); |
94 } | 94 } |
95 | 95 |
96 MessagePumpX::~MessagePumpX() { | 96 MessagePumpX::~MessagePumpX() { |
| 97 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DestroyMessagePump()); |
97 g_source_destroy(x_source_); | 98 g_source_destroy(x_source_); |
98 g_source_unref(x_source_); | 99 g_source_unref(x_source_); |
99 XCloseDisplay(g_xdisplay); | 100 XCloseDisplay(g_xdisplay); |
100 g_xdisplay = NULL; | 101 g_xdisplay = NULL; |
101 } | 102 } |
102 | 103 |
103 // static | 104 // static |
104 Display* MessagePumpX::GetDefaultXDisplay() { | 105 Display* MessagePumpX::GetDefaultXDisplay() { |
105 if (!g_xdisplay) | 106 if (!g_xdisplay) |
106 g_xdisplay = XOpenDisplay(NULL); | 107 g_xdisplay = XOpenDisplay(NULL); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 XEvent xev; | 177 XEvent xev; |
177 XNextEvent(display, &xev); | 178 XNextEvent(display, &xev); |
178 if (ProcessXEvent(dispatcher, &xev)) | 179 if (ProcessXEvent(dispatcher, &xev)) |
179 return true; | 180 return true; |
180 } | 181 } |
181 | 182 |
182 return g_main_context_iteration(context, block); | 183 return g_main_context_iteration(context, block); |
183 } | 184 } |
184 | 185 |
185 bool MessagePumpX::WillProcessXEvent(XEvent* xevent) { | 186 bool MessagePumpX::WillProcessXEvent(XEvent* xevent) { |
| 187 if (!observers().might_have_observers()) |
| 188 return false; |
186 ObserverListBase<MessagePumpObserver>::Iterator it(observers()); | 189 ObserverListBase<MessagePumpObserver>::Iterator it(observers()); |
187 MessagePumpObserver* obs; | 190 MessagePumpObserver* obs; |
188 while ((obs = it.GetNext()) != NULL) { | 191 while ((obs = it.GetNext()) != NULL) { |
189 if (obs->WillProcessEvent(xevent)) | 192 if (obs->WillProcessEvent(xevent)) |
190 return true; | 193 return true; |
191 } | 194 } |
192 return false; | 195 return false; |
193 } | 196 } |
194 | 197 |
195 void MessagePumpX::DidProcessXEvent(XEvent* xevent) { | 198 void MessagePumpX::DidProcessXEvent(XEvent* xevent) { |
196 ObserverListBase<MessagePumpObserver>::Iterator it(observers()); | 199 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent)); |
197 MessagePumpObserver* obs; | |
198 while ((obs = it.GetNext()) != NULL) { | |
199 obs->DidProcessEvent(xevent); | |
200 } | |
201 } | 200 } |
202 | 201 |
203 } // namespace base | 202 } // namespace base |
OLD | NEW |