Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_AURAX11_H | 5 #ifndef BASE_MESSAGE_PUMP_AURAX11_H |
| 6 #define BASE_MESSAGE_PUMP_AURAX11_H | 6 #define BASE_MESSAGE_PUMP_AURAX11_H |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_pump.h" | 9 #include "base/message_pump.h" |
| 10 #include "base/message_pump_glib.h" | 10 #include "base/message_pump_glib.h" |
| 11 #include "base/message_pump_dispatcher.h" | 11 #include "base/message_pump_dispatcher.h" |
| 12 #include "base/message_pump_observer.h" | 12 #include "base/message_pump_observer.h" |
| 13 | 13 |
| 14 #include <bitset> | 14 #include <bitset> |
| 15 #include <map> | |
| 16 #include <vector> | |
| 15 | 17 |
| 16 // It would be nice to include the X11 headers here so that we use Window | 18 // It would be nice to include the X11 headers here so that we use Window |
| 17 // instead of its typedef of unsigned long, but we can't because everything in | 19 // instead of its typedef of unsigned long, but we can't because everything in |
| 18 // chrome includes us through base/message_loop.h, and X11's crappy #define | 20 // chrome includes us through base/message_loop.h, and X11's crappy #define |
| 19 // heavy headers muck up half of chrome. | 21 // heavy headers muck up half of chrome. |
| 20 | 22 |
| 21 typedef struct _GPollFD GPollFD; | 23 typedef struct _GPollFD GPollFD; |
| 22 typedef struct _GSource GSource; | 24 typedef struct _GSource GSource; |
| 23 typedef struct _XDisplay Display; | 25 typedef struct _XDisplay Display; |
| 24 | 26 |
| 25 namespace base { | 27 namespace base { |
| 26 | 28 |
| 27 // This class implements a message-pump for dispatching X events. | 29 // This class implements a message-pump for dispatching X events. |
| 28 class BASE_EXPORT MessagePumpAuraX11 : public MessagePumpGlib { | 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 { | |
| 29 public: | 36 public: |
| 30 MessagePumpAuraX11(); | 37 MessagePumpAuraX11(); |
| 31 | 38 |
| 32 // Returns default X Display. | 39 // Returns default X Display. |
| 33 static Display* GetDefaultXDisplay(); | 40 static Display* GetDefaultXDisplay(); |
| 34 | 41 |
| 35 // Returns true if the system supports XINPUT2. | 42 // Returns true if the system supports XINPUT2. |
| 36 static bool HasXInput2(); | 43 static bool HasXInput2(); |
| 37 | 44 |
| 38 // Sets the default dispatcher to process native events. | |
| 39 static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher); | |
| 40 | |
| 41 // Returns the UI message pump. | 45 // Returns the UI message pump. |
| 42 static MessagePumpAuraX11* Current(); | 46 static MessagePumpAuraX11* Current(); |
| 43 | 47 |
| 48 // Adds/Removes |dispatcher| for the |x_window|. | |
| 49 void AddDispatcherForWindow(MessagePumpDispatcher* dispatcher, | |
| 50 unsigned long x_window); | |
|
sadrul
2012/08/29 16:01:25
Use XID?
| |
| 51 void RemoveDispatcherForWindow(unsigned long x_window); | |
| 52 | |
| 53 // Adds/Removes |dispatcher| to receive all events sent to the X | |
| 54 // root window. | |
| 55 void AddDispatcherForRootWindow(MessagePumpDispatcher* dispatcher); | |
| 56 void RemoveDispatcherForRootWindow(MessagePumpDispatcher* dispatcher); | |
|
sadrul
2012/08/29 16:01:25
It makes sense to explicitly state in the comments
| |
| 57 | |
| 44 // Internal function. Called by the glib source dispatch function. Processes | 58 // Internal function. Called by the glib source dispatch function. Processes |
| 45 // all available X events. | 59 // all available X events. |
| 46 bool DispatchXEvents(); | 60 bool DispatchXEvents(); |
| 47 | 61 |
| 48 // Blocks on the X11 event queue until we receive notification from the | 62 // Blocks on the X11 event queue until we receive notification from the |
| 49 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are | 63 // xserver that |w| has been mapped; StructureNotifyMask events on |w| are |
| 50 // pulled out from the queue and dispatched out of order. | 64 // pulled out from the queue and dispatched out of order. |
| 51 // | 65 // |
| 52 // For those that know X11, this is really a wrapper around XWindowEvent | 66 // For those that know X11, this is really a wrapper around XWindowEvent |
| 53 // which still makes sure the preempted event is dispatched instead of | 67 // which still makes sure the preempted event is dispatched instead of |
| 54 // dropped on the floor. This method exists because mapping a window is | 68 // dropped on the floor. This method exists because mapping a window is |
| 55 // asynchronous (and we receive an XEvent when mapped), while there are also | 69 // asynchronous (and we receive an XEvent when mapped), while there are also |
| 56 // functions which require a mapped window. | 70 // functions which require a mapped window. |
| 57 void BlockUntilWindowMapped(unsigned long window); | 71 void BlockUntilWindowMapped(unsigned long x_window); |
| 58 | 72 |
| 59 protected: | 73 protected: |
| 60 virtual ~MessagePumpAuraX11(); | 74 virtual ~MessagePumpAuraX11(); |
| 61 | 75 |
| 62 private: | 76 private: |
| 77 typedef std::map<unsigned long, MessagePumpDispatcher*> DispatchersMap; | |
| 78 typedef std::vector<MessagePumpDispatcher*> Dispatchers; | |
| 79 | |
| 63 // Initializes the glib event source for X. | 80 // Initializes the glib event source for X. |
| 64 void InitXSource(); | 81 void InitXSource(); |
| 65 | 82 |
| 66 // Dispatches the XEvent and returns true if we should exit the current loop | 83 // Dispatches the XEvent and returns true if we should exit the current loop |
| 67 // of message processing. | 84 // of message processing. |
| 68 bool ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event); | 85 bool ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event); |
| 69 | 86 |
| 70 // Sends the event to the observers. If an observer returns true, then it does | 87 // Sends the event to the observers. If an observer returns true, then it does |
| 71 // not send the event to any other observers and returns true. Returns false | 88 // not send the event to any other observers and returns true. Returns false |
| 72 // if no observer returns true. | 89 // if no observer returns true. |
| 73 bool WillProcessXEvent(XEvent* xevent); | 90 bool WillProcessXEvent(XEvent* xevent); |
| 74 void DidProcessXEvent(XEvent* xevent); | 91 void DidProcessXEvent(XEvent* xevent); |
| 75 | 92 |
| 93 // Returns the Dispatcher based on the event's target window. | |
| 94 MessagePumpDispatcher* GetDispatcherForXEvent( | |
| 95 const base::NativeEvent& xev) const; | |
| 96 | |
| 97 // Overridden from MessagePumpDispatcher: | |
| 98 virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE; | |
| 99 | |
| 76 // The event source for X events. | 100 // The event source for X events. |
| 77 GSource* x_source_; | 101 GSource* x_source_; |
| 78 | 102 |
| 79 // The poll attached to |x_source_|. | 103 // The poll attached to |x_source_|. |
| 80 scoped_ptr<GPollFD> x_poll_; | 104 scoped_ptr<GPollFD> x_poll_; |
| 81 | 105 |
| 106 DispatchersMap dispatchers_; | |
| 107 Dispatchers root_window_dispatchers_; | |
| 108 | |
| 109 unsigned long x_root_window_; | |
| 110 | |
| 82 DISALLOW_COPY_AND_ASSIGN(MessagePumpAuraX11); | 111 DISALLOW_COPY_AND_ASSIGN(MessagePumpAuraX11); |
| 83 }; | 112 }; |
| 84 | 113 |
| 85 typedef MessagePumpAuraX11 MessagePumpForUI; | 114 typedef MessagePumpAuraX11 MessagePumpForUI; |
| 86 | 115 |
| 87 } // namespace base | 116 } // namespace base |
| 88 | 117 |
| 89 #endif // BASE_MESSAGE_PUMP_AURAX11_H | 118 #endif // BASE_MESSAGE_PUMP_AURAX11_H |
| OLD | NEW |