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 // through GDK's dispatching process and may get discarded. This function | |
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 | |
95 // Decides whether we are interested in processing this XEvent. | 86 // Decides whether we are interested in processing this XEvent. |
96 bool ShouldCaptureXEvent(XEvent* event); | 87 bool ShouldCaptureXEvent(XEvent* event); |
97 | 88 |
98 // Dispatches the XEvent and returns true if we should exit the current loop | 89 // Dispatches the XEvent and returns true if we should exit the current loop |
99 // of message processing. | 90 // of message processing. |
100 bool ProcessXEvent(XEvent* event); | 91 bool ProcessXEvent(XEvent* event); |
101 | 92 |
102 // Sends the event to the observers. If an observer returns true, then it does | 93 // 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 | 94 // not send the event to any other observers and returns true. Returns false |
104 // if no observer returns true. | 95 // if no observer returns true. |
105 bool WillProcessXEvent(XEvent* xevent); | 96 bool WillProcessXEvent(XEvent* xevent); |
| 97 #if defined(TOOLKIT_USES_GTK) |
| 98 // Some XEvent's can't be directly read from X event queue and will go |
| 99 // through GDK's dispatching process and may get discarded. This function |
| 100 // sets up a filter to intercept those XEvent's we are interested in |
| 101 // and dispatches them so that they won't get lost. |
| 102 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, |
| 103 GdkEvent* gevent, |
| 104 gpointer data); |
| 105 |
| 106 static void EventDispatcherX(GdkEvent* event, gpointer data); |
| 107 |
| 108 // Indicates whether a GDK event was injected by chrome (when |true|) or if it |
| 109 // was captured and being processed by GDK (when |false|). |
| 110 bool IsDispatchingEvent(void) { return dispatching_event_; } |
106 | 111 |
107 // Update the lookup table and flag the events that should be captured and | 112 // Update the lookup table and flag the events that should be captured and |
108 // processed so that GDK doesn't get to them. | 113 // processed so that GDK doesn't get to them. |
109 void InitializeEventsToCapture(void); | 114 void InitializeEventsToCapture(void); |
110 | 115 |
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. | 116 // The event source for GDK events. |
116 GSource* gdksource_; | 117 GSource* gdksource_; |
117 | 118 |
118 // The default GDK event dispatcher. This is stored so that it can be restored | 119 // The default GDK event dispatcher. This is stored so that it can be restored |
119 // when necessary during nested event dispatching. | 120 // when necessary during nested event dispatching. |
120 gboolean (*gdkdispatcher_)(GSource*, GSourceFunc, void*); | 121 gboolean (*gdkdispatcher_)(GSource*, GSourceFunc, void*); |
121 | 122 |
122 // Indicates whether a GDK event was injected by chrome (when |true|) or if it | 123 // Indicates whether a GDK event was injected by chrome (when |true|) or if it |
123 // was captured and being processed by GDK (when |false|). | 124 // was captured and being processed by GDK (when |false|). |
124 bool dispatching_event_; | 125 bool dispatching_event_; |
125 | 126 |
126 #if ! GTK_CHECK_VERSION(2,18,0) | 127 #if ! GTK_CHECK_VERSION(2,18,0) |
127 // GDK_EVENT_LAST was introduced in GTK+ 2.18.0. For earlier versions, we pick a | 128 // 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 | 129 // large enough value (the value of GDK_EVENT_LAST in 2.18.0) so that it works |
129 // for all versions. | 130 // for all versions. |
130 #define GDK_EVENT_LAST 37 | 131 #define GDK_EVENT_LAST 37 |
131 #endif | 132 #endif |
132 | 133 |
133 // Ideally we would #include X.h for LASTEvent, but it brings in a lot of stupid | 134 // 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 | 135 // 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. | 136 // XLASTEvent here to a large enough value so that it works. |
136 #define XLASTEvent 40 | 137 #define XLASTEvent 40 |
137 | 138 |
138 // We do not want to process all the events ourselves. So we use a lookup | 139 // 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 | 140 // 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. | 141 // it should be passed on to the default GDK handler. |
141 std::bitset<XLASTEvent> capture_x_events_; | 142 std::bitset<XLASTEvent> capture_x_events_; |
142 std::bitset<GDK_EVENT_LAST> capture_gdk_events_; | 143 std::bitset<GDK_EVENT_LAST> capture_gdk_events_; |
| 144 #endif // defined(TOOLKIT_USES_GTK) |
| 145 |
| 146 // The event source for X events (used only when GTK event processing is |
| 147 // disabled). |
| 148 GSource* x_source_; |
143 | 149 |
144 DISALLOW_COPY_AND_ASSIGN(MessagePumpX); | 150 DISALLOW_COPY_AND_ASSIGN(MessagePumpX); |
145 }; | 151 }; |
146 | 152 |
147 typedef MessagePumpX MessagePumpForUI; | 153 typedef MessagePumpX MessagePumpForUI; |
148 | 154 |
149 } // namespace base | 155 } // namespace base |
150 | 156 |
151 #endif // BASE_MESSAGE_PUMP_X_H | 157 #endif // BASE_MESSAGE_PUMP_X_H |
OLD | NEW |