Chromium Code Reviews| 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 #ifndef BASE_MESSAGE_PUMP_X_H | 5 #ifndef BASE_MESSAGE_PUMP_X_H |
| 6 #define BASE_MESSAGE_PUMP_X_H | 6 #define BASE_MESSAGE_PUMP_X_H |
| 7 | 7 |
| 8 #include "base/message_pump.h" | 8 #include "base/message_pump.h" |
| 9 #include "base/message_pump_glib.h" | 9 #include "base/message_pump_glib.h" |
| 10 | 10 |
| 11 #include <bitset> | 11 #include <bitset> |
| 12 | 12 |
| 13 #include <glib.h> | 13 #include <glib.h> |
| 14 | 14 |
| 15 #if defined(TOOLKIT_USES_GTK) | 15 #if defined(TOOLKIT_USES_GTK) |
| 16 #include <gtk/gtk.h> | 16 #include <gtk/gtk.h> |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 typedef union _XEvent XEvent; | 19 typedef union _XEvent XEvent; |
| 20 typedef struct _XDisplay Display; | 20 typedef struct _XDisplay Display; |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 | 23 |
| 24 typedef XEvent* NativeEvent; | |
| 25 | |
| 26 enum EventStatus { | |
| 27 EVENT_CONTINUE, // The event should be dispatched as normal. | |
| 28 EVENT_HANDLED // The event should not be processed any farther. | |
| 29 }; | |
| 30 | |
| 24 // The documentation for this class is in message_pump_glib.h | 31 // The documentation for this class is in message_pump_glib.h |
| 25 class BASE_EXPORT MessagePumpObserver { | 32 class BASE_EXPORT MessagePumpObserver { |
|
darin (slow to review)
2011/09/23 20:58:46
it seems like you should factor this out into a se
oshima
2011/09/23 21:12:59
Yes, will do. So are you ok to have NativeEvent in
| |
| 26 public: | 33 public: |
| 27 enum EventStatus { | |
| 28 EVENT_CONTINUE, // The event should be dispatched as normal. | |
| 29 EVENT_HANDLED // The event should not be processed any farther. | |
| 30 }; | |
| 31 | |
| 32 // This method is called before processing an XEvent. If the method returns | 34 // This method is called before processing an XEvent. If the method returns |
| 33 // EVENT_HANDLED, it indicates the event has already been handled, so the | 35 // EVENT_HANDLED, it indicates the event has already been handled, so the |
| 34 // event is not processed any farther. If the method returns EVENT_CONTINUE, | 36 // event is not processed any farther. If the method returns EVENT_CONTINUE, |
| 35 // the event dispatching proceeds as normal. | 37 // the event dispatching proceeds as normal. |
| 36 virtual EventStatus WillProcessXEvent(XEvent* xevent); | 38 virtual EventStatus WillProcessEvent(const NativeEvent& xevent) = 0; |
| 39 | |
| 40 // This method is called after processing a message. | |
| 41 virtual void DidProcessEvent(const NativeEvent& event) = 0; | |
| 37 | 42 |
| 38 protected: | 43 protected: |
| 39 virtual ~MessagePumpObserver() {} | 44 virtual ~MessagePumpObserver() {} |
| 40 }; | 45 }; |
| 41 | 46 |
| 42 // The documentation for this class is in message_pump_glib.h | 47 // The documentation for this class is in message_pump_glib.h |
| 43 // | 48 // |
| 44 // The nested loop is exited by either posting a quit, or returning EVENT_QUIT | 49 // The nested loop is exited by either posting a quit, or returning EVENT_QUIT |
| 45 // from Dispatch. | 50 // from Dispatch. |
| 46 class MessagePumpDispatcher { | 51 class MessagePumpDispatcher { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 bool ShouldCaptureXEvent(XEvent* event); | 95 bool ShouldCaptureXEvent(XEvent* event); |
| 91 | 96 |
| 92 // Dispatches the XEvent and returns true if we should exit the current loop | 97 // Dispatches the XEvent and returns true if we should exit the current loop |
| 93 // of message processing. | 98 // of message processing. |
| 94 bool ProcessXEvent(XEvent* event); | 99 bool ProcessXEvent(XEvent* event); |
| 95 | 100 |
| 96 // Sends the event to the observers. If an observer returns true, then it does | 101 // Sends the event to the observers. If an observer returns true, then it does |
| 97 // not send the event to any other observers and returns true. Returns false | 102 // not send the event to any other observers and returns true. Returns false |
| 98 // if no observer returns true. | 103 // if no observer returns true. |
| 99 bool WillProcessXEvent(XEvent* xevent); | 104 bool WillProcessXEvent(XEvent* xevent); |
| 105 void DidProcessXEvent(XEvent* xevent); | |
| 100 #if defined(TOOLKIT_USES_GTK) | 106 #if defined(TOOLKIT_USES_GTK) |
| 101 // Some XEvent's can't be directly read from X event queue and will go | 107 // Some XEvent's can't be directly read from X event queue and will go |
| 102 // through GDK's dispatching process and may get discarded. This function | 108 // through GDK's dispatching process and may get discarded. This function |
| 103 // sets up a filter to intercept those XEvent's we are interested in | 109 // sets up a filter to intercept those XEvent's we are interested in |
| 104 // and dispatches them so that they won't get lost. | 110 // and dispatches them so that they won't get lost. |
| 105 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, | 111 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, |
| 106 GdkEvent* gevent, | 112 GdkEvent* gevent, |
| 107 gpointer data); | 113 gpointer data); |
| 108 | 114 |
| 109 static void EventDispatcherX(GdkEvent* event, gpointer data); | 115 static void EventDispatcherX(GdkEvent* event, gpointer data); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 GSource* x_source_; | 157 GSource* x_source_; |
| 152 | 158 |
| 153 DISALLOW_COPY_AND_ASSIGN(MessagePumpX); | 159 DISALLOW_COPY_AND_ASSIGN(MessagePumpX); |
| 154 }; | 160 }; |
| 155 | 161 |
| 156 typedef MessagePumpX MessagePumpForUI; | 162 typedef MessagePumpX MessagePumpForUI; |
| 157 | 163 |
| 158 } // namespace base | 164 } // namespace base |
| 159 | 165 |
| 160 #endif // BASE_MESSAGE_PUMP_X_H | 166 #endif // BASE_MESSAGE_PUMP_X_H |
| OLD | NEW |