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_LOOP_MESSAGE_PUMP_GTK_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_ |
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_ | 6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_ |
7 | 7 |
8 #include "base/message_loop/message_pump_glib.h" | 8 #include "base/message_loop/message_pump_glib.h" |
9 | 9 |
10 typedef union _GdkEvent GdkEvent; | 10 typedef union _GdkEvent GdkEvent; |
11 typedef struct _XDisplay Display; | 11 typedef struct _XDisplay Display; |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 // The documentation for this class is in message_pump_glib.h | 15 // The documentation for this class is in message_pump_glib.h |
16 class MessagePumpObserver { | 16 class MessagePumpGdkObserver { |
17 public: | 17 public: |
18 // This method is called before processing a message. | 18 // This method is called before processing a message. |
19 virtual void WillProcessEvent(GdkEvent* event) = 0; | 19 virtual void WillProcessEvent(GdkEvent* event) = 0; |
20 | 20 |
21 // This method is called after processing a message. | 21 // This method is called after processing a message. |
22 virtual void DidProcessEvent(GdkEvent* event) = 0; | 22 virtual void DidProcessEvent(GdkEvent* event) = 0; |
23 | 23 |
24 protected: | 24 protected: |
25 virtual ~MessagePumpObserver() {} | 25 virtual ~MessagePumpGdkObserver() {} |
26 }; | |
27 | |
28 // The documentation for this class is in message_pump_glib.h | |
29 // | |
30 // The nested loop is exited by either posting a quit, or returning false | |
31 // from Dispatch. | |
32 class MessagePumpDispatcher { | |
33 public: | |
34 // Dispatches the event. If true is returned processing continues as | |
35 // normal. If false is returned, the nested loop exits immediately. | |
36 virtual bool Dispatch(GdkEvent* event) = 0; | |
37 | |
38 protected: | |
39 virtual ~MessagePumpDispatcher() {} | |
40 }; | 26 }; |
41 | 27 |
42 // This class implements a message-pump for dispatching GTK events. | 28 // This class implements a message-pump for dispatching GTK events. |
43 class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib { | 29 class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib { |
44 public: | 30 public: |
45 MessagePumpGtk(); | 31 MessagePumpGtk(); |
46 virtual ~MessagePumpGtk(); | 32 virtual ~MessagePumpGtk(); |
47 | 33 |
48 // Dispatch an available GdkEvent. Essentially this allows a subclass to do | 34 // Dispatch an available GdkEvent. Essentially this allows a subclass to do |
49 // some task before/after calling the default handler (EventDispatcher). | 35 // some task before/after calling the default handler (EventDispatcher). |
50 void DispatchEvents(GdkEvent* event); | 36 void DispatchEvents(GdkEvent* event); |
51 | 37 |
52 // Returns default X Display. | 38 // Returns default X Display. |
53 static Display* GetDefaultXDisplay(); | 39 static Display* GetDefaultXDisplay(); |
54 | 40 |
| 41 // Adds an Observer, which will start receiving notifications immediately. |
| 42 void AddObserver(MessagePumpGdkObserver* observer); |
| 43 |
| 44 // Removes an Observer. It is safe to call this method while an Observer is |
| 45 // receiving a notification callback. |
| 46 void RemoveObserver(MessagePumpGdkObserver* observer); |
| 47 |
55 private: | 48 private: |
56 // Invoked from EventDispatcher. Notifies all observers we're about to | 49 // Invoked from EventDispatcher. Notifies all observers we're about to |
57 // process an event. | 50 // process an event. |
58 void WillProcessEvent(GdkEvent* event); | 51 void WillProcessEvent(GdkEvent* event); |
59 | 52 |
60 // Invoked from EventDispatcher. Notifies all observers we processed an | 53 // Invoked from EventDispatcher. Notifies all observers we processed an |
61 // event. | 54 // event. |
62 void DidProcessEvent(GdkEvent* event); | 55 void DidProcessEvent(GdkEvent* event); |
63 | 56 |
64 // Callback prior to gdk dispatching an event. | 57 // Callback prior to gdk dispatching an event. |
65 static void EventDispatcher(GdkEvent* event, void* data); | 58 static void EventDispatcher(GdkEvent* event, void* data); |
66 | 59 |
| 60 // List of observers. |
| 61 ObserverList<MessagePumpGdkObserver> observers_; |
| 62 |
67 DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk); | 63 DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk); |
68 }; | 64 }; |
69 | 65 |
70 typedef MessagePumpGtk MessagePumpForUI; | 66 typedef MessagePumpGtk MessagePumpForUI; |
71 | 67 |
72 } // namespace base | 68 } // namespace base |
73 | 69 |
74 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_ | 70 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_ |
OLD | NEW |