[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 | |
| 5 | #ifndef BASE_MESSAGE_PUMP_GTK_H_ |
| 6 | #define BASE_MESSAGE_PUMP_GTK_H_ |
| 7 | #pragma once |
| 8 | |
| 9 | #include "base/message_pump_glib.h" |
| 10 | |
| 11 | typedef union _GdkEvent GdkEvent; |
[email protected] | 2656a354 | 2011-07-22 19:49:23 | [diff] [blame] | 12 | typedef struct _XDisplay Display; |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 13 | |
| 14 | namespace base { |
| 15 | |
| 16 | // The documentation for this class is in message_pump_glib.h |
| 17 | class MessagePumpObserver { |
| 18 | public: |
| 19 | // This method is called before processing a message. |
| 20 | virtual void WillProcessEvent(GdkEvent* event) = 0; |
| 21 | |
| 22 | // This method is called after processing a message. |
| 23 | virtual void DidProcessEvent(GdkEvent* event) = 0; |
| 24 | |
| 25 | protected: |
| 26 | virtual ~MessagePumpObserver() {} |
| 27 | }; |
| 28 | |
| 29 | // The documentation for this class is in message_pump_glib.h |
| 30 | // |
| 31 | // The nested loop is exited by either posting a quit, or returning false |
| 32 | // from Dispatch. |
| 33 | class MessagePumpDispatcher { |
| 34 | public: |
| 35 | // Dispatches the event. If true is returned processing continues as |
| 36 | // normal. If false is returned, the nested loop exits immediately. |
| 37 | virtual bool Dispatch(GdkEvent* event) = 0; |
| 38 | |
| 39 | protected: |
| 40 | virtual ~MessagePumpDispatcher() {} |
| 41 | }; |
| 42 | |
| 43 | // This class implements a message-pump for dispatching GTK events. |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 44 | class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib { |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 45 | public: |
| 46 | MessagePumpGtk(); |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 47 | |
| 48 | // Dispatch an available GdkEvent. Essentially this allows a subclass to do |
| 49 | // some task before/after calling the default handler (EventDispatcher). |
| 50 | void DispatchEvents(GdkEvent* event); |
| 51 | |
[email protected] | 2656a354 | 2011-07-22 19:49:23 | [diff] [blame] | 52 | // Returns default X Display. |
| 53 | static Display* GetDefaultXDisplay(); |
| 54 | |
[email protected] | 4e0f45f5 | 2012-05-18 18:00:22 | [diff] [blame^] | 55 | protected: |
| 56 | virtual ~MessagePumpGtk(); |
| 57 | |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 58 | private: |
[email protected] | 2047ef4 | 2011-06-24 20:10:25 | [diff] [blame] | 59 | // Invoked from EventDispatcher. Notifies all observers we're about to |
| 60 | // process an event. |
| 61 | void WillProcessEvent(GdkEvent* event); |
| 62 | |
| 63 | // Invoked from EventDispatcher. Notifies all observers we processed an |
| 64 | // event. |
| 65 | void DidProcessEvent(GdkEvent* event); |
| 66 | |
| 67 | // Callback prior to gdk dispatching an event. |
| 68 | static void EventDispatcher(GdkEvent* event, void* data); |
| 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk); |
| 71 | }; |
| 72 | |
| 73 | typedef MessagePumpGtk MessagePumpForUI; |
| 74 | |
| 75 | } // namespace base |
| 76 | |
| 77 | #endif // BASE_MESSAGE_PUMP_GTK_H_ |