| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_MESSAGE_PUMP_GLIB_X_H | |
| 6 #define BASE_MESSAGE_PUMP_GLIB_X_H | |
| 7 | |
| 8 #include "base/message_pump.h" | |
| 9 #include "base/message_pump_glib.h" | |
| 10 | |
| 11 #include <bitset> | |
| 12 | |
| 13 #include <glib.h> | |
| 14 #include <gtk/gtk.h> | |
| 15 #include <X11/X.h> | |
| 16 | |
| 17 typedef union _XEvent XEvent; | |
| 18 | |
| 19 namespace base { | |
| 20 | |
| 21 class MessagePumpGlibX : public MessagePumpForUI { | |
| 22 public: | |
| 23 MessagePumpGlibX(); | |
| 24 virtual ~MessagePumpGlibX(); | |
| 25 | |
| 26 // Indicates whether a GDK event was injected by chrome (when |true|) or if it | |
| 27 // was captured and being processed by GDK (when |false|). | |
| 28 bool IsDispatchingEvent(void) { return dispatching_event_; } | |
| 29 | |
| 30 // Overridden from MessagePumpForUI: | |
| 31 virtual bool RunOnce(GMainContext* context, bool block); | |
| 32 | |
| 33 private: | |
| 34 // 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 | |
| 36 // sets up a filter to intercept those XEvent's we are interested in | |
| 37 // and dispatches them so that they won't get lost. | |
| 38 static GdkFilterReturn GdkEventFilter(GdkXEvent* gxevent, | |
| 39 GdkEvent* gevent, | |
| 40 gpointer data); | |
| 41 | |
| 42 static void EventDispatcherX(GdkEvent* event, gpointer data); | |
| 43 | |
| 44 // Decides whether we are interested in processing this XEvent. | |
| 45 bool ShouldCaptureXEvent(XEvent* event); | |
| 46 | |
| 47 // Dispatches the XEvent and returns true if we should exit the current loop | |
| 48 // of message processing. | |
| 49 bool ProcessXEvent(XEvent* event); | |
| 50 | |
| 51 // Sends the event to the observers. If an observer returns true, then it does | |
| 52 // not send the event to any other observers and returns true. Returns false | |
| 53 // if no observer returns true. | |
| 54 bool WillProcessXEvent(XEvent* xevent); | |
| 55 | |
| 56 // Update the lookup table and flag the events that should be captured and | |
| 57 // processed so that GDK doesn't get to them. | |
| 58 void InitializeEventsToCapture(void); | |
| 59 | |
| 60 #if defined(HAVE_XINPUT2) | |
| 61 // Initialize X2 input. | |
| 62 void InitializeXInput2(void); | |
| 63 | |
| 64 // The opcode used for checking events. | |
| 65 int xiopcode_; | |
| 66 #endif | |
| 67 | |
| 68 // The event source for GDK events. | |
| 69 GSource* gdksource_; | |
| 70 | |
| 71 // The default GDK event dispatcher. This is stored so that it can be restored | |
| 72 // when necessary during nested event dispatching. | |
| 73 gboolean (*gdkdispatcher_)(GSource*, GSourceFunc, void*); | |
| 74 | |
| 75 // Indicates whether a GDK event was injected by chrome (when |true|) or if it | |
| 76 // was captured and being processed by GDK (when |false|). | |
| 77 bool dispatching_event_; | |
| 78 | |
| 79 #if ! GTK_CHECK_VERSION(2,18,0) | |
| 80 // 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 | |
| 82 // for all versions. | |
| 83 #define GDK_EVENT_LAST 37 | |
| 84 #endif | |
| 85 | |
| 86 // 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 | |
| 88 // it should be passed on to the default GDK handler. | |
| 89 std::bitset<LASTEvent> capture_x_events_; | |
| 90 std::bitset<GDK_EVENT_LAST> capture_gdk_events_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(MessagePumpGlibX); | |
| 93 }; | |
| 94 | |
| 95 } // namespace base | |
| 96 | |
| 97 #endif // BASE_MESSAGE_PUMP_GLIB_X_H | |
| OLD | NEW |