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(), |
| 98 OnMessagePumpDestroying()); |
97 g_source_destroy(x_source_); | 99 g_source_destroy(x_source_); |
98 g_source_unref(x_source_); | 100 g_source_unref(x_source_); |
99 XCloseDisplay(g_xdisplay); | 101 XCloseDisplay(g_xdisplay); |
100 g_xdisplay = NULL; | 102 g_xdisplay = NULL; |
101 } | 103 } |
102 | 104 |
103 // static | 105 // static |
104 Display* MessagePumpX::GetDefaultXDisplay() { | 106 Display* MessagePumpX::GetDefaultXDisplay() { |
105 if (!g_xdisplay) | 107 if (!g_xdisplay) |
106 g_xdisplay = XOpenDisplay(NULL); | 108 g_xdisplay = XOpenDisplay(NULL); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 XEvent xev; | 178 XEvent xev; |
177 XNextEvent(display, &xev); | 179 XNextEvent(display, &xev); |
178 if (ProcessXEvent(dispatcher, &xev)) | 180 if (ProcessXEvent(dispatcher, &xev)) |
179 return true; | 181 return true; |
180 } | 182 } |
181 | 183 |
182 return g_main_context_iteration(context, block); | 184 return g_main_context_iteration(context, block); |
183 } | 185 } |
184 | 186 |
185 bool MessagePumpX::WillProcessXEvent(XEvent* xevent) { | 187 bool MessagePumpX::WillProcessXEvent(XEvent* xevent) { |
| 188 if (!observers().might_have_observers()) |
| 189 return false; |
186 ObserverListBase<MessagePumpObserver>::Iterator it(observers()); | 190 ObserverListBase<MessagePumpObserver>::Iterator it(observers()); |
187 MessagePumpObserver* obs; | 191 MessagePumpObserver* obs; |
188 while ((obs = it.GetNext()) != NULL) { | 192 while ((obs = it.GetNext()) != NULL) { |
189 if (obs->WillProcessEvent(xevent)) | 193 if (obs->WillProcessEvent(xevent)) |
190 return true; | 194 return true; |
191 } | 195 } |
192 return false; | 196 return false; |
193 } | 197 } |
194 | 198 |
195 void MessagePumpX::DidProcessXEvent(XEvent* xevent) { | 199 void MessagePumpX::DidProcessXEvent(XEvent* xevent) { |
196 ObserverListBase<MessagePumpObserver>::Iterator it(observers()); | 200 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent)); |
197 MessagePumpObserver* obs; | |
198 while ((obs = it.GetNext()) != NULL) { | |
199 obs->DidProcessEvent(xevent); | |
200 } | |
201 } | 201 } |
202 | 202 |
203 } // namespace base | 203 } // namespace base |
OLD | NEW |