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