blob: e60eeaf71cec6c972d08bab5f7dc0f086c1ea262 [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_
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();
[email protected]2047ef42011-06-24 20:10:2547
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]2656a3542011-07-22 19:49:2352 // Returns default X Display.
53 static Display* GetDefaultXDisplay();
54
[email protected]4e0f45f52012-05-18 18:00:2255 protected:
56 virtual ~MessagePumpGtk();
57
[email protected]2047ef42011-06-24 20:10:2558 private:
[email protected]2047ef42011-06-24 20:10:2559 // 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
73typedef MessagePumpGtk MessagePumpForUI;
74
75} // namespace base
76
77#endif // BASE_MESSAGE_PUMP_GTK_H_