Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: base/message_pump_x.h

Issue 7250001: Refactor the glib message-pump, and use it as the base for a gtk message pump and an X message pump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_GLIB_X_H 5 #ifndef BASE_MESSAGE_PUMP_X_H
6 #define BASE_MESSAGE_PUMP_GLIB_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 #include <gtk/gtk.h> 14 #include <gtk/gtk.h>
15 #include <X11/X.h>
16 15
17 typedef union _XEvent XEvent; 16 typedef union _XEvent XEvent;
18 17
19 namespace base { 18 namespace base {
20 19
21 class MessagePumpGlibX : public MessagePumpForUI { 20 // The documentation for this class is in message_pump_glib.h
21 class MessagePumpDispatcher {
22 public: 22 public:
23 MessagePumpGlibX(); 23 virtual ~MessagePumpDispatcher() {}
sky 2011/06/24 15:27:12 If the pump doesn't own the dispatcher, make this
sadrul 2011/06/24 17:14:01 Done.
24 virtual ~MessagePumpGlibX(); 24
25 enum DispatchStatus {
26 EVENT_IGNORED, // The event was not processed.
27 EVENT_PROCESSED, // The event has been processed.
28 EVENT_QUIT // The event was processed and the message-loop should
29 // terminate.
30 };
31
32 // Dispatches the event. EVENT_IGNORED is returned if the event was ignored
33 // (i.e. not processed). EVENT_PROCESSED is returned if the event was
34 // processed. The nested loop exits immediately if EVENT_QUIT is returned.
35 virtual DispatchStatus DispatchX(XEvent* xevent) = 0;
sky 2011/06/24 15:27:12 nit: DispatchX sounds pretty vague. How about Disp
sadrul 2011/06/24 17:14:01 I have changed it to Dispatch. (it used to be Disp
36 };
37
38 // The documentation for this class is in message_pump_glib.h
39 class BASE_API MessagePumpObserver {
40 public:
41 virtual ~MessagePumpObserver() {}
42
43 // This method is called before processing an XEvent. If the method returns
44 // true, it indicates the event has already been handled, so the event is not
45 // processed any farther. If the method returns false, the event dispatching
46 // proceeds as normal.
47 virtual bool WillProcessXEvent(XEvent* xevent);
sky 2011/06/24 15:27:12 For clarity consider making this return an enum. I
sadrul 2011/06/24 17:14:01 Sounds like a good idea. I have done it here. The
48 };
49
50 // This class implements a message-pump for dispatching X events.
51 class MessagePumpX : public MessagePumpGlib {
52 public:
53 MessagePumpX();
54 virtual ~MessagePumpX();
25 55
26 // Indicates whether a GDK event was injected by chrome (when |true|) or if it 56 // Indicates whether a GDK event was injected by chrome (when |true|) or if it
27 // was captured and being processed by GDK (when |false|). 57 // was captured and being processed by GDK (when |false|).
28 bool IsDispatchingEvent(void) { return dispatching_event_; } 58 bool IsDispatchingEvent(void) { return dispatching_event_; }
29 59
30 // Overridden from MessagePumpForUI: 60 // Overridden from MessagePumpGlib:
31 virtual bool RunOnce(GMainContext* context, bool block); 61 virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE;
32 62
33 private: 63 private:
34 // Some XEvent's can't be directly read from X event queue and will go 64 // Some XEvent's can't be directly read from X event queue and will go
35 // through GDK's dispatching process and may get discarded. This function 65 // through GDK's dispatching process and may get discarded. This function
36 // sets up a filter to intercept those XEvent's we are interested in 66 // sets up a filter to intercept those XEvent's we are interested in
37 // and dispatches them so that they won't get lost. 67 // and dispatches them so that they won't get lost.
38 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, 68 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent,
39 GdkEvent* gevent, 69 GdkEvent* gevent,
40 gpointer data); 70 gpointer data);
41 71
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // was captured and being processed by GDK (when |false|). 106 // was captured and being processed by GDK (when |false|).
77 bool dispatching_event_; 107 bool dispatching_event_;
78 108
79 #if ! GTK_CHECK_VERSION(2,18,0) 109 #if ! GTK_CHECK_VERSION(2,18,0)
80 // GDK_EVENT_LAST was introduced in GTK+ 2.18.0. For earlier versions, we pick a 110 // GDK_EVENT_LAST was introduced in GTK+ 2.18.0. For earlier versions, we pick a
81 // large enough value (the value of GDK_EVENT_LAST in 2.18.0) so that it works 111 // large enough value (the value of GDK_EVENT_LAST in 2.18.0) so that it works
82 // for all versions. 112 // for all versions.
83 #define GDK_EVENT_LAST 37 113 #define GDK_EVENT_LAST 37
84 #endif 114 #endif
85 115
116 // Ideally we would #include X.h for LASTEvent, but it brings in a lot of stupid
117 // stuff (like Time, CurrentTime etc.) that messes up a lot of things. So define
118 // XLASTEvent here to a large enough value so that it works.
119 #define XLASTEvent 40
120
86 // We do not want to process all the events ourselves. So we use a lookup 121 // We do not want to process all the events ourselves. So we use a lookup
87 // table to quickly check if a particular event should be handled by us or if 122 // table to quickly check if a particular event should be handled by us or if
88 // it should be passed on to the default GDK handler. 123 // it should be passed on to the default GDK handler.
89 std::bitset<LASTEvent> capture_x_events_; 124 std::bitset<XLASTEvent> capture_x_events_;
90 std::bitset<GDK_EVENT_LAST> capture_gdk_events_; 125 std::bitset<GDK_EVENT_LAST> capture_gdk_events_;
91 126
92 DISALLOW_COPY_AND_ASSIGN(MessagePumpGlibX); 127 DISALLOW_COPY_AND_ASSIGN(MessagePumpX);
93 }; 128 };
94 129
130 typedef MessagePumpX MessagePumpForUI;
131
95 } // namespace base 132 } // namespace base
96 133
97 #endif // BASE_MESSAGE_PUMP_GLIB_X_H 134 #endif // BASE_MESSAGE_PUMP_X_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698