summaryrefslogtreecommitdiffstats
path: root/base/message_pump_gtk.h
blob: 80122ce8fe4b706121d201ea5c4a0de59b82d7ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_MESSAGE_PUMP_GTK_H_
#define BASE_MESSAGE_PUMP_GTK_H_
#pragma once

#include "base/message_pump_glib.h"

typedef union _GdkEvent GdkEvent;
typedef struct _XDisplay Display;

namespace base {

// The documentation for this class is in message_pump_glib.h
class MessagePumpObserver {
 public:
  // This method is called before processing a message.
  virtual void WillProcessEvent(GdkEvent* event) = 0;

  // This method is called after processing a message.
  virtual void DidProcessEvent(GdkEvent* event) = 0;

 protected:
  virtual ~MessagePumpObserver() {}
};

// The documentation for this class is in message_pump_glib.h
//
// The nested loop is exited by either posting a quit, or returning false
// from Dispatch.
class MessagePumpDispatcher {
 public:
  // Dispatches the event. If true is returned processing continues as
  // normal. If false is returned, the nested loop exits immediately.
  virtual bool Dispatch(GdkEvent* event) = 0;

 protected:
  virtual ~MessagePumpDispatcher() {}
};

// This class implements a message-pump for dispatching GTK events.
class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib {
 public:
  MessagePumpGtk();
  virtual ~MessagePumpGtk();

  // Dispatch an available GdkEvent. Essentially this allows a subclass to do
  // some task before/after calling the default handler (EventDispatcher).
  void DispatchEvents(GdkEvent* event);

  // Returns default X Display.
  static Display* GetDefaultXDisplay();

 private:
  // Overridden from MessagePumpGlib
  virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE;

  // Invoked from EventDispatcher. Notifies all observers we're about to
  // process an event.
  void WillProcessEvent(GdkEvent* event);

  // Invoked from EventDispatcher. Notifies all observers we processed an
  // event.
  void DidProcessEvent(GdkEvent* event);

  // Callback prior to gdk dispatching an event.
  static void EventDispatcher(GdkEvent* event, void* data);

  DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk);
};

typedef MessagePumpGtk MessagePumpForUI;

}  // namespace base

#endif  // BASE_MESSAGE_PUMP_GTK_H_