[cros] Don't succeed if user has default profile picturewq
[chromium-blink-merge.git] / base / message_pump_x.h
blob231100d3c381781d8b8fa0f0593d4c273d44fac7
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.
5 #ifndef BASE_MESSAGE_PUMP_X_H
6 #define BASE_MESSAGE_PUMP_X_H
8 #include "base/message_pump.h"
9 #include "base/message_pump_glib.h"
10 #include "base/message_pump_observer.h"
12 #include <bitset>
14 #include <glib.h>
16 #if defined(TOOLKIT_USES_GTK)
17 #include <gtk/gtk.h>
18 #endif
20 typedef struct _XDisplay Display;
22 namespace base {
24 // The documentation for this class is in message_pump_glib.h
26 // The nested loop is exited by either posting a quit, or returning EVENT_QUIT
27 // from Dispatch.
28 class MessagePumpDispatcher {
29 public:
30 enum DispatchStatus {
31 EVENT_IGNORED, // The event was not processed.
32 EVENT_PROCESSED, // The event has been processed.
33 EVENT_QUIT // The event was processed and the message-loop should
34 // terminate.
37 // Dispatches the event. EVENT_IGNORED is returned if the event was ignored
38 // (i.e. not processed). EVENT_PROCESSED is returned if the event was
39 // processed. The nested loop exits immediately if EVENT_QUIT is returned.
40 virtual DispatchStatus Dispatch(XEvent* xevent) = 0;
42 protected:
43 virtual ~MessagePumpDispatcher() {}
46 // This class implements a message-pump for dispatching X events.
47 class BASE_EXPORT MessagePumpX : public MessagePumpGlib {
48 public:
49 MessagePumpX();
50 virtual ~MessagePumpX();
52 // Overridden from MessagePumpGlib:
53 virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE;
55 // Returns default X Display.
56 static Display* GetDefaultXDisplay();
58 // Returns true if the system supports XINPUT2.
59 static bool HasXInput2();
61 private:
62 // Initializes the glib event source for X.
63 void InitXSource();
65 // Decides whether we are interested in processing this XEvent.
66 bool ShouldCaptureXEvent(XEvent* event);
68 // Dispatches the XEvent and returns true if we should exit the current loop
69 // of message processing.
70 bool ProcessXEvent(XEvent* event);
72 // 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
74 // if no observer returns true.
75 bool WillProcessXEvent(XEvent* xevent);
76 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);
86 static void EventDispatcherX(GdkEvent* event, gpointer data);
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_; }
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);
96 // The event source for GDK events.
97 GSource* gdksource_;
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*);
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_;
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
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
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)
126 // The event source for X events (used only when GTK event processing is
127 // disabled).
128 GSource* x_source_;
130 DISALLOW_COPY_AND_ASSIGN(MessagePumpX);
133 typedef MessagePumpX MessagePumpForUI;
135 } // namespace base
137 #endif // BASE_MESSAGE_PUMP_X_H