| 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 |
| 15 #if defined(TOOLKIT_USES_GTK) |
| 14 #include <gtk/gtk.h> | 16 #include <gtk/gtk.h> |
| 17 #endif |
| 15 | 18 |
| 16 typedef union _XEvent XEvent; | 19 typedef union _XEvent XEvent; |
| 17 typedef struct _XDisplay Display; | 20 typedef struct _XDisplay Display; |
| 18 | 21 |
| 19 namespace base { | 22 namespace base { |
| 20 | 23 |
| 21 // The documentation for this class is in message_pump_glib.h | 24 // The documentation for this class is in message_pump_glib.h |
| 22 class BASE_EXPORT MessagePumpObserver { | 25 class BASE_EXPORT MessagePumpObserver { |
| 23 public: | 26 public: |
| 24 enum EventStatus { | 27 enum EventStatus { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 protected: | 60 protected: |
| 58 virtual ~MessagePumpDispatcher() {} | 61 virtual ~MessagePumpDispatcher() {} |
| 59 }; | 62 }; |
| 60 | 63 |
| 61 // This class implements a message-pump for dispatching X events. | 64 // This class implements a message-pump for dispatching X events. |
| 62 class BASE_EXPORT MessagePumpX : public MessagePumpGlib { | 65 class BASE_EXPORT MessagePumpX : public MessagePumpGlib { |
| 63 public: | 66 public: |
| 64 MessagePumpX(); | 67 MessagePumpX(); |
| 65 virtual ~MessagePumpX(); | 68 virtual ~MessagePumpX(); |
| 66 | 69 |
| 67 // Indicates whether a GDK event was injected by chrome (when |true|) or if it | |
| 68 // was captured and being processed by GDK (when |false|). | |
| 69 bool IsDispatchingEvent(void) { return dispatching_event_; } | |
| 70 | |
| 71 // Overridden from MessagePumpGlib: | 70 // Overridden from MessagePumpGlib: |
| 72 virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE; | 71 virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE; |
| 73 | 72 |
| 73 #if defined(TOOLKIT_USES_GTK) |
| 74 // Disables Gtk/Gdk event pumping. This will be used when | 74 // Disables Gtk/Gdk event pumping. This will be used when |
| 75 // NativeWidgetX is enabled. | 75 // NativeWidgetX is enabled. |
| 76 static void DisableGtkMessagePump(); | 76 static void DisableGtkMessagePump(); |
| 77 #endif |
| 77 | 78 |
| 78 // Returns default X Display. | 79 // Returns default X Display. |
| 79 static Display* GetDefaultXDisplay(); | 80 static Display* GetDefaultXDisplay(); |
| 80 | 81 |
| 81 // Returns true if the system supports XINPUT2. | 82 // Returns true if the system supports XINPUT2. |
| 82 static bool HasXInput2(); | 83 static bool HasXInput2(); |
| 83 | 84 |
| 84 private: | 85 private: |
| 85 // Some XEvent's can't be directly read from X event queue and will go | 86 // Initializes the glib event source for X. |
| 86 // through GDK's dispatching process and may get discarded. This function | 87 void InitXSource(); |
| 87 // sets up a filter to intercept those XEvent's we are interested in | |
| 88 // and dispatches them so that they won't get lost. | |
| 89 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, | |
| 90 GdkEvent* gevent, | |
| 91 gpointer data); | |
| 92 | |
| 93 static void EventDispatcherX(GdkEvent* event, gpointer data); | |
| 94 | 88 |
| 95 // Decides whether we are interested in processing this XEvent. | 89 // Decides whether we are interested in processing this XEvent. |
| 96 bool ShouldCaptureXEvent(XEvent* event); | 90 bool ShouldCaptureXEvent(XEvent* event); |
| 97 | 91 |
| 98 // Dispatches the XEvent and returns true if we should exit the current loop | 92 // Dispatches the XEvent and returns true if we should exit the current loop |
| 99 // of message processing. | 93 // of message processing. |
| 100 bool ProcessXEvent(XEvent* event); | 94 bool ProcessXEvent(XEvent* event); |
| 101 | 95 |
| 102 // Sends the event to the observers. If an observer returns true, then it does | 96 // Sends the event to the observers. If an observer returns true, then it does |
| 103 // not send the event to any other observers and returns true. Returns false | 97 // not send the event to any other observers and returns true. Returns false |
| 104 // if no observer returns true. | 98 // if no observer returns true. |
| 105 bool WillProcessXEvent(XEvent* xevent); | 99 bool WillProcessXEvent(XEvent* xevent); |
| 100 #if defined(TOOLKIT_USES_GTK) |
| 101 // 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 |
| 103 // sets up a filter to intercept those XEvent's we are interested in |
| 104 // and dispatches them so that they won't get lost. |
| 105 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, |
| 106 GdkEvent* gevent, |
| 107 gpointer data); |
| 108 |
| 109 static void EventDispatcherX(GdkEvent* event, gpointer data); |
| 110 |
| 111 // Indicates whether a GDK event was injected by chrome (when |true|) or if it |
| 112 // was captured and being processed by GDK (when |false|). |
| 113 bool IsDispatchingEvent(void) { return dispatching_event_; } |
| 106 | 114 |
| 107 // Update the lookup table and flag the events that should be captured and | 115 // Update the lookup table and flag the events that should be captured and |
| 108 // processed so that GDK doesn't get to them. | 116 // processed so that GDK doesn't get to them. |
| 109 void InitializeEventsToCapture(void); | 117 void InitializeEventsToCapture(void); |
| 110 | 118 |
| 111 // The event source for X events (used only when GTK event processing is | |
| 112 // disabled). | |
| 113 GSource* x_source_; | |
| 114 | |
| 115 // The event source for GDK events. | 119 // The event source for GDK events. |
| 116 GSource* gdksource_; | 120 GSource* gdksource_; |
| 117 | 121 |
| 118 // The default GDK event dispatcher. This is stored so that it can be restored | 122 // The default GDK event dispatcher. This is stored so that it can be restored |
| 119 // when necessary during nested event dispatching. | 123 // when necessary during nested event dispatching. |
| 120 gboolean (*gdkdispatcher_)(GSource*, GSourceFunc, void*); | 124 gboolean (*gdkdispatcher_)(GSource*, GSourceFunc, void*); |
| 121 | 125 |
| 122 // Indicates whether a GDK event was injected by chrome (when |true|) or if it | 126 // Indicates whether a GDK event was injected by chrome (when |true|) or if it |
| 123 // was captured and being processed by GDK (when |false|). | 127 // was captured and being processed by GDK (when |false|). |
| 124 bool dispatching_event_; | 128 bool dispatching_event_; |
| 125 | 129 |
| 126 #if ! GTK_CHECK_VERSION(2,18,0) | 130 #if ! GTK_CHECK_VERSION(2,18,0) |
| 127 // GDK_EVENT_LAST was introduced in GTK+ 2.18.0. For earlier versions, we pick a | 131 // GDK_EVENT_LAST was introduced in GTK+ 2.18.0. For earlier versions, we pick a |
| 128 // large enough value (the value of GDK_EVENT_LAST in 2.18.0) so that it works | 132 // large enough value (the value of GDK_EVENT_LAST in 2.18.0) so that it works |
| 129 // for all versions. | 133 // for all versions. |
| 130 #define GDK_EVENT_LAST 37 | 134 #define GDK_EVENT_LAST 37 |
| 131 #endif | 135 #endif |
| 132 | 136 |
| 133 // Ideally we would #include X.h for LASTEvent, but it brings in a lot of stupid | 137 // Ideally we would #include X.h for LASTEvent, but it brings in a lot of stupid |
| 134 // stuff (like Time, CurrentTime etc.) that messes up a lot of things. So define | 138 // stuff (like Time, CurrentTime etc.) that messes up a lot of things. So define |
| 135 // XLASTEvent here to a large enough value so that it works. | 139 // XLASTEvent here to a large enough value so that it works. |
| 136 #define XLASTEvent 40 | 140 #define XLASTEvent 40 |
| 137 | 141 |
| 138 // We do not want to process all the events ourselves. So we use a lookup | 142 // We do not want to process all the events ourselves. So we use a lookup |
| 139 // table to quickly check if a particular event should be handled by us or if | 143 // table to quickly check if a particular event should be handled by us or if |
| 140 // it should be passed on to the default GDK handler. | 144 // it should be passed on to the default GDK handler. |
| 141 std::bitset<XLASTEvent> capture_x_events_; | 145 std::bitset<XLASTEvent> capture_x_events_; |
| 142 std::bitset<GDK_EVENT_LAST> capture_gdk_events_; | 146 std::bitset<GDK_EVENT_LAST> capture_gdk_events_; |
| 147 #endif // defined(TOOLKIT_USES_GTK) |
| 148 |
| 149 // The event source for X events (used only when GTK event processing is |
| 150 // disabled). |
| 151 GSource* x_source_; |
| 143 | 152 |
| 144 DISALLOW_COPY_AND_ASSIGN(MessagePumpX); | 153 DISALLOW_COPY_AND_ASSIGN(MessagePumpX); |
| 145 }; | 154 }; |
| 146 | 155 |
| 147 typedef MessagePumpX MessagePumpForUI; | 156 typedef MessagePumpX MessagePumpForUI; |
| 148 | 157 |
| 149 } // namespace base | 158 } // namespace base |
| 150 | 159 |
| 151 #endif // BASE_MESSAGE_PUMP_X_H | 160 #endif // BASE_MESSAGE_PUMP_X_H |
| OLD | NEW |