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

Side by Side Diff: base/message_pump_aurax11.h

Issue 16897006: Move message_pump to base/message_loop. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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
« no previous file with comments | « base/message_pump_android.cc ('k') | base/message_pump_aurax11.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_AURAX11_H
6 #define BASE_MESSAGE_PUMP_AURAX11_H
7
8 #include <bitset>
9 #include <map>
10
11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_pump.h"
13 #include "base/message_pump_glib.h"
14 #include "base/message_pump_dispatcher.h"
15 #include "base/message_pump_observer.h"
16 #include "base/observer_list.h"
17
18 // It would be nice to include the X11 headers here so that we use Window
19 // instead of its typedef of unsigned long, but we can't because everything in
20 // chrome includes us through base/message_loop.h, and X11's crappy #define
21 // heavy headers muck up half of chrome.
22
23 typedef struct _GPollFD GPollFD;
24 typedef struct _GSource GSource;
25 typedef struct _XDisplay Display;
26
27 namespace base {
28
29 // This class implements a message-pump for dispatching X events.
30 //
31 // If there's a current dispatcher given through RunWithDispatcher(), that
32 // dispatcher receives events. Otherwise, we route to messages to dispatchers
33 // who have subscribed to messages from a specific X11 window.
34 class BASE_EXPORT MessagePumpAuraX11 : public MessagePumpGlib,
35 public MessagePumpDispatcher {
36 public:
37 MessagePumpAuraX11();
38
39 // Returns default X Display.
40 static Display* GetDefaultXDisplay();
41
42 // Returns true if the system supports XINPUT2.
43 static bool HasXInput2();
44
45 // Returns the UI message pump.
46 static MessagePumpAuraX11* Current();
47
48 // Adds/Removes |dispatcher| for the |xid|. This will route all messages from
49 // the window |xid| to |dispatcher.
50 void AddDispatcherForWindow(MessagePumpDispatcher* dispatcher,
51 unsigned long xid);
52 void RemoveDispatcherForWindow(unsigned long xid);
53
54 // Adds/Removes |dispatcher| to receive all events sent to the X root
55 // window. A root window can have multiple dispatchers, and events on root
56 // windows will be dispatched to all.
57 void AddDispatcherForRootWindow(MessagePumpDispatcher* dispatcher);
58 void RemoveDispatcherForRootWindow(MessagePumpDispatcher* dispatcher);
59
60 // Internal function. Called by the glib source dispatch function. Processes
61 // all available X events.
62 bool DispatchXEvents();
63
64 // Blocks on the X11 event queue until we receive notification from the
65 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are
66 // pulled out from the queue and dispatched out of order.
67 //
68 // For those that know X11, this is really a wrapper around XWindowEvent
69 // which still makes sure the preempted event is dispatched instead of
70 // dropped on the floor. This method exists because mapping a window is
71 // asynchronous (and we receive an XEvent when mapped), while there are also
72 // functions which require a mapped window.
73 void BlockUntilWindowMapped(unsigned long xid);
74
75 protected:
76 virtual ~MessagePumpAuraX11();
77
78 private:
79 typedef std::map<unsigned long, MessagePumpDispatcher*> DispatchersMap;
80
81 // Initializes the glib event source for X.
82 void InitXSource();
83
84 // Dispatches the XEvent and returns true if we should exit the current loop
85 // of message processing.
86 bool ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event);
87
88 // Sends the event to the observers. If an observer returns true, then it does
89 // not send the event to any other observers and returns true. Returns false
90 // if no observer returns true.
91 bool WillProcessXEvent(XEvent* xevent);
92 void DidProcessXEvent(XEvent* xevent);
93
94 // Returns the Dispatcher based on the event's target window.
95 MessagePumpDispatcher* GetDispatcherForXEvent(
96 const base::NativeEvent& xev) const;
97
98 // Overridden from MessagePumpDispatcher:
99 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
100
101 // The event source for X events.
102 GSource* x_source_;
103
104 // The poll attached to |x_source_|.
105 scoped_ptr<GPollFD> x_poll_;
106
107 DispatchersMap dispatchers_;
108
109 // Dispatch calls can cause addition of new dispatchers as we iterate
110 // through them. Use ObserverList to ensure the iterator remains valid across
111 // additions.
112 ObserverList<MessagePumpDispatcher> root_window_dispatchers_;
113
114 unsigned long x_root_window_;
115
116 DISALLOW_COPY_AND_ASSIGN(MessagePumpAuraX11);
117 };
118
119 typedef MessagePumpAuraX11 MessagePumpForUI;
120
121 } // namespace base
122
123 #endif // BASE_MESSAGE_PUMP_AURAX11_H
OLDNEW
« no previous file with comments | « base/message_pump_android.cc ('k') | base/message_pump_aurax11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698