Home | History | Annotate | Download | only in message_loop
      1 // Copyright (c) 2012 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_LOOP_MESSAGE_PUMP_GTK_H_
      6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_
      7 
      8 #include "base/message_loop/message_pump_glib.h"
      9 
     10 typedef union _GdkEvent GdkEvent;
     11 typedef struct _XDisplay Display;
     12 
     13 namespace base {
     14 
     15 // The documentation for this class is in message_pump_glib.h
     16 class MessagePumpGdkObserver {
     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 ~MessagePumpGdkObserver() {}
     26 };
     27 
     28 // This class implements a message-pump for dispatching GTK events.
     29 class BASE_EXPORT MessagePumpGtk : public MessagePumpGlib {
     30  public:
     31   MessagePumpGtk();
     32   virtual ~MessagePumpGtk();
     33 
     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 
     38   // Returns default X Display.
     39   static Display* GetDefaultXDisplay();
     40 
     41   // 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 
     48  private:
     49   // 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 
     60   // List of observers.
     61   ObserverList<MessagePumpGdkObserver> observers_;
     62 
     63   DISALLOW_COPY_AND_ASSIGN(MessagePumpGtk);
     64 };
     65 
     66 typedef MessagePumpGtk MessagePumpForUI;
     67 
     68 }  // namespace base
     69 
     70 #endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_
     71