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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/message_pump_x.h
diff --git a/base/message_pump_glib_x.h b/base/message_pump_x.h
similarity index 60%
rename from base/message_pump_glib_x.h
rename to base/message_pump_x.h
index ed29e6a777e2c1cb5643b13df08aed741e249cd8..348d799368843e359e4a57eb9d21af824fb7c4f1 100644
--- a/base/message_pump_glib_x.h
+++ b/base/message_pump_x.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_MESSAGE_PUMP_GLIB_X_H
-#define BASE_MESSAGE_PUMP_GLIB_X_H
+#ifndef BASE_MESSAGE_PUMP_X_H
+#define BASE_MESSAGE_PUMP_X_H
oshima 2011/06/24 05:55:15 We will need glib even after we remove gtk (for ib
sadrul 2011/06/24 06:35:32 I changed the name because GlibX seems a bit too v
#include "base/message_pump.h"
#include "base/message_pump_glib.h"
@@ -12,23 +12,53 @@
#include <glib.h>
#include <gtk/gtk.h>
-#include <X11/X.h>
typedef union _XEvent XEvent;
namespace base {
-class MessagePumpGlibX : public MessagePumpForUI {
+// The documentation for this class is in message_pump_glib.h
+class MessagePumpDispatcher {
public:
- MessagePumpGlibX();
- virtual ~MessagePumpGlibX();
+ virtual ~MessagePumpDispatcher() {}
+
+ enum DispatchStatus {
+ EVENT_IGNORED, // The event was not processed.
+ EVENT_PROCESSED, // The event has been processed.
+ EVENT_QUIT // The event was processed and the message-loop should
+ // terminate.
+ };
+
+ // Dispatches the event. EVENT_IGNORED is returned if the event was ignored
+ // (i.e. not processed). EVENT_PROCESSED is returned if the event was
+ // processed. The nested loop exits immediately if EVENT_QUIT is returned.
+ virtual DispatchStatus DispatchX(XEvent* xevent) = 0;
+};
+
+// The documentation for this class is in message_pump_glib.h
+class BASE_API MessagePumpObserver {
+ public:
+ virtual ~MessagePumpObserver() {}
+
+ // This method is called before processing an XEvent. If the method returns
+ // true, it indicates the event has already been handled, so the event is not
+ // processed any farther. If the method returns false, the event dispatching
+ // proceeds as normal.
+ virtual bool WillProcessXEvent(XEvent* xevent);
+};
+
+// This class implements a message-pump for dispatching X events.
+class MessagePumpX : public MessagePumpGlib {
+ public:
+ MessagePumpX();
+ virtual ~MessagePumpX();
// Indicates whether a GDK event was injected by chrome (when |true|) or if it
// was captured and being processed by GDK (when |false|).
bool IsDispatchingEvent(void) { return dispatching_event_; }
- // Overridden from MessagePumpForUI:
- virtual bool RunOnce(GMainContext* context, bool block);
+ // Overridden from MessagePumpGlib:
+ virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE;
private:
// Some XEvent's can't be directly read from X event queue and will go
@@ -83,15 +113,22 @@ class MessagePumpGlibX : public MessagePumpForUI {
#define GDK_EVENT_LAST 37
#endif
+// Ideally we would #include X.h for LASTEvent, but it brings in a lot of stupid
+// shit (like Time, CurrentTime etc.) that messes up a lot of things. So define
+// XLASTEvent here to a large enough value so that it works.
+#define XLASTEvent 40
oshima 2011/06/24 05:55:15 can you add compile time check if this value is go
sadrul 2011/06/24 06:35:32 Sounds like a good idea. Done!
+
// We do not want to process all the events ourselves. So we use a lookup
// table to quickly check if a particular event should be handled by us or if
// it should be passed on to the default GDK handler.
- std::bitset<LASTEvent> capture_x_events_;
+ std::bitset<XLASTEvent> capture_x_events_;
std::bitset<GDK_EVENT_LAST> capture_gdk_events_;
- DISALLOW_COPY_AND_ASSIGN(MessagePumpGlibX);
+ DISALLOW_COPY_AND_ASSIGN(MessagePumpX);
};
+typedef MessagePumpX MessagePumpForUI;
+
} // namespace base
-#endif // BASE_MESSAGE_PUMP_GLIB_X_H
+#endif // BASE_MESSAGE_PUMP_X_H
« base/message_pump_glib.h ('K') | « base/message_pump_gtk.cc ('k') | base/message_pump_x.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698