blob: 80122ce8fe4b706121d201ea5c4a0de59b82d7ec [file] [log] [blame]
[email protected]2047ef42011-06-24 20:10:251// Copyright (c) 2011 The Chromium Authors. All rights reserved.
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
11typedef union _GdkEvent GdkEvent;
[email protected]2656a3542011-07-22 19:49:2312typedef struct _XDisplay Display;
[email protected]2047ef42011-06-24 20:10:2513
14namespace base {
15
16// The documentation for this class is in message_pump_glib.h
17class 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.
33class 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]0bea7252011-08-05 15:34:0044class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib {
[email protected]2047ef42011-06-24 20:10:2545 public:
46 MessagePumpGtk();
47 virtual ~MessagePumpGtk();
48
49 // Dispatch an available GdkEvent. Essentially this allows a subclass to do
50 // some task before/after calling the default handler (EventDispatcher).
51 void DispatchEvents(GdkEvent* event);
52
[email protected]2656a3542011-07-22 19:49:2353 // Returns default X Display.
54 static Display* GetDefaultXDisplay();
55
[email protected]2047ef42011-06-24 20:10:2556 private:
57 // Overridden from MessagePumpGlib
58 virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE;
59
60 // Invoked from EventDispatcher. Notifies all observers we're about to
61 // process an event.
62 void WillProcessEvent(GdkEvent* event);
63
64 // Invoked from EventDispatcher. Notifies all observers we processed an
65 // event.
66 void DidProcessEvent(GdkEvent* event);
67
68 // Callback prior to gdk dispatching an event.
69 static void EventDispatcher(GdkEvent* event, void* data);
70
71 DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk);
72};
73
74typedef MessagePumpGtk MessagePumpForUI;
75
76} // namespace base
77
78#endif // BASE_MESSAGE_PUMP_GTK_H_