blob: b3c3b8c7415d603d19c8dd25c510b31df91b0fbe [file] [log] [blame]
[email protected]4e0f45f52012-05-18 18:00:221// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]2047ef42011-06-24 20:10:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]59e69e742013-06-18 20:27:525#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_
6#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_
[email protected]2047ef42011-06-24 20:10:257
[email protected]59e69e742013-06-18 20:27:528#include "base/message_loop/message_pump_glib.h"
[email protected]2047ef42011-06-24 20:10:259
10typedef union _GdkEvent GdkEvent;
[email protected]2656a3542011-07-22 19:49:2311typedef struct _XDisplay Display;
[email protected]2047ef42011-06-24 20:10:2512
13namespace base {
14
15// The documentation for this class is in message_pump_glib.h
[email protected]827d38a2013-09-07 01:13:3916class MessagePumpGdkObserver {
[email protected]2047ef42011-06-24 20:10:2517 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]827d38a2013-09-07 01:13:3925 virtual ~MessagePumpGdkObserver() {}
[email protected]2047ef42011-06-24 20:10:2526};
27
28// This class implements a message-pump for dispatching GTK events.
[email protected]0bea7252011-08-05 15:34:0029class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib {
[email protected]2047ef42011-06-24 20:10:2530 public:
31 MessagePumpGtk();
[email protected]54aa4f12013-07-22 22:24:1332 virtual ~MessagePumpGtk();
[email protected]2047ef42011-06-24 20:10:2533
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]2656a3542011-07-22 19:49:2338 // Returns default X Display.
39 static Display* GetDefaultXDisplay();
40
[email protected]827d38a2013-09-07 01:13:3941 // 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]2047ef42011-06-24 20:10:2548 private:
[email protected]2047ef42011-06-24 20:10:2549 // 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]827d38a2013-09-07 01:13:3960 // List of observers.
61 ObserverList<MessagePumpGdkObserver> observers_;
62
[email protected]2047ef42011-06-24 20:10:2563 DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk);
64};
65
66typedef MessagePumpGtk MessagePumpForUI;
67
68} // namespace base
69
[email protected]59e69e742013-06-18 20:27:5270#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_