blob: ba5cff146835442bd47d5cf6c177a0875c4bc7eb [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
5#ifndef BASE_MESSAGE_PUMP_GTK_H_
6#define BASE_MESSAGE_PUMP_GTK_H_
[email protected]2047ef42011-06-24 20:10:257
8#include "base/message_pump_glib.h"
9
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
16class MessagePumpObserver {
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:
25 virtual ~MessagePumpObserver() {}
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.
32class 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};
41
42// This class implements a message-pump for dispatching GTK events.
[email protected]0bea7252011-08-05 15:34:0043class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib {
[email protected]2047ef42011-06-24 20:10:2544 public:
45 MessagePumpGtk();
[email protected]2047ef42011-06-24 20:10:2546
47 // Dispatch an available GdkEvent. Essentially this allows a subclass to do
48 // some task before/after calling the default handler (EventDispatcher).
49 void DispatchEvents(GdkEvent* event);
50
[email protected]2656a3542011-07-22 19:49:2351 // Returns default X Display.
52 static Display* GetDefaultXDisplay();
53
[email protected]4e0f45f52012-05-18 18:00:2254 protected:
55 virtual ~MessagePumpGtk();
56
[email protected]2047ef42011-06-24 20:10:2557 private:
[email protected]2047ef42011-06-24 20:10:2558 // Invoked from EventDispatcher. Notifies all observers we're about to
59 // process an event.
60 void WillProcessEvent(GdkEvent* event);
61
62 // Invoked from EventDispatcher. Notifies all observers we processed an
63 // event.
64 void DidProcessEvent(GdkEvent* event);
65
66 // Callback prior to gdk dispatching an event.
67 static void EventDispatcher(GdkEvent* event, void* data);
68
69 DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk);
70};
71
72typedef MessagePumpGtk MessagePumpForUI;
73
74} // namespace base
75
76#endif // BASE_MESSAGE_PUMP_GTK_H_