[email protected] | 4e0f45f5 | 2012-05-18 18:00:22 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 59e69e74 | 2013-06-18 20:27:52 | [diff] [blame] | 5 | #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_ |
6 | #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_ | ||||
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 7 | |
[email protected] | 59e69e74 | 2013-06-18 20:27:52 | [diff] [blame] | 8 | #include "base/message_loop/message_pump_glib.h" |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 9 | |
10 | typedef union _GdkEvent GdkEvent; | ||||
[email protected] | 2656a354 | 2011-07-22 19:49:23 | [diff] [blame] | 11 | typedef struct _XDisplay Display; |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 12 | |
13 | namespace base { | ||||
14 | |||||
15 | // The documentation for this class is in message_pump_glib.h | ||||
[email protected] | 827d38a | 2013-09-07 01:13:39 | [diff] [blame] | 16 | class MessagePumpGdkObserver { |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 17 | public: |
18 | // This method is called before processing a message. | ||||
19 | virtual void WillProcessEvent(GdkEvent* event) = 0; | ||||
20 | |||||
21 | // This method is called after processing a message. | ||||
22 | virtual void DidProcessEvent(GdkEvent* event) = 0; | ||||
23 | |||||
24 | protected: | ||||
[email protected] | 827d38a | 2013-09-07 01:13:39 | [diff] [blame] | 25 | virtual ~MessagePumpGdkObserver() {} |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 26 | }; |
27 | |||||
28 | // This class implements a message-pump for dispatching GTK events. | ||||
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 29 | class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib { |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 30 | public: |
31 | MessagePumpGtk(); | ||||
[email protected] | 54aa4f1 | 2013-07-22 22:24:13 | [diff] [blame] | 32 | virtual ~MessagePumpGtk(); |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 33 | |
34 | // Dispatch an available GdkEvent. Essentially this allows a subclass to do | ||||
35 | // some task before/after calling the default handler (EventDispatcher). | ||||
36 | void DispatchEvents(GdkEvent* event); | ||||
37 | |||||
[email protected] | 2656a354 | 2011-07-22 19:49:23 | [diff] [blame] | 38 | // Returns default X Display. |
39 | static Display* GetDefaultXDisplay(); | ||||
40 | |||||
[email protected] | 827d38a | 2013-09-07 01:13:39 | [diff] [blame] | 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 | |||||
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 48 | private: |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 49 | // Invoked from EventDispatcher. Notifies all observers we're about to |
50 | // process an event. | ||||
51 | void WillProcessEvent(GdkEvent* event); | ||||
52 | |||||
53 | // Invoked from EventDispatcher. Notifies all observers we processed an | ||||
54 | // event. | ||||
55 | void DidProcessEvent(GdkEvent* event); | ||||
56 | |||||
57 | // Callback prior to gdk dispatching an event. | ||||
58 | static void EventDispatcher(GdkEvent* event, void* data); | ||||
59 | |||||
[email protected] | 827d38a | 2013-09-07 01:13:39 | [diff] [blame] | 60 | // List of observers. |
61 | ObserverList<MessagePumpGdkObserver> observers_; | ||||
62 | |||||
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 63 | DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk); |
64 | }; | ||||
65 | |||||
66 | typedef MessagePumpGtk MessagePumpForUI; | ||||
67 | |||||
68 | } // namespace base | ||||
69 | |||||
[email protected] | 59e69e74 | 2013-06-18 20:27:52 | [diff] [blame] | 70 | #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_ |