OLD | NEW |
(Empty) | |
| 1 // 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 #include "base/message_pump_gtk.h" |
| 6 |
| 7 #include <gtk/gtk.h> |
| 8 |
| 9 namespace base { |
| 10 |
| 11 MessagePumpGtk::MessagePumpGtk() : MessagePumpGlib() { |
| 12 gdk_event_handler_set(&EventDispatcher, this, NULL); |
| 13 } |
| 14 |
| 15 MessagePumpGtk::~MessagePumpGtk() { |
| 16 gdk_event_handler_set(reinterpret_cast<GdkEventFunc>(gtk_main_do_event), |
| 17 this, NULL); |
| 18 } |
| 19 |
| 20 void MessagePumpGtk::DispatchEvents(GdkEvent* event) { |
| 21 WillProcessEvent(event); |
| 22 |
| 23 MessagePumpDispatcher* dispatcher = GetDispatcher(); |
| 24 if (!dispatcher) |
| 25 gtk_main_do_event(event); |
| 26 else if (!dispatcher->Dispatch(event)) |
| 27 Quit(); |
| 28 |
| 29 DidProcessEvent(event); |
| 30 } |
| 31 |
| 32 bool MessagePumpGtk::RunOnce(GMainContext* context, bool block) { |
| 33 // g_main_context_iteration returns true if events have been dispatched. |
| 34 return g_main_context_iteration(context, block); |
| 35 } |
| 36 |
| 37 void MessagePumpGtk::WillProcessEvent(GdkEvent* event) { |
| 38 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), WillProcessEvent(event)); |
| 39 } |
| 40 |
| 41 void MessagePumpGtk::DidProcessEvent(GdkEvent* event) { |
| 42 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(event)); |
| 43 } |
| 44 |
| 45 // static |
| 46 void MessagePumpGtk::EventDispatcher(GdkEvent* event, gpointer data) { |
| 47 MessagePumpGtk* message_pump = reinterpret_cast<MessagePumpGtk*>(data); |
| 48 message_pump->DispatchEvents(event); |
| 49 } |
| 50 |
| 51 } // namespace base |
| 52 |
OLD | NEW |