OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/message_pump_gtk.h" | 5 #include "base/message_pump_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <gdk/gdkx.h> | 8 #include <gdk/gdkx.h> |
9 | 9 |
| 10 #include "base/profiler/scoped_profile.h" |
| 11 #include "base/debug/trace_event.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 const char* EventToTypeString(const GdkEvent* event) { |
| 16 switch (event->type) { |
| 17 case GDK_NOTHING: return "GDK_NOTHING"; |
| 18 case GDK_DELETE: return "GDK_DELETE"; |
| 19 case GDK_DESTROY: return "GDK_DESTROY"; |
| 20 case GDK_EXPOSE: return "GDK_EXPOSE"; |
| 21 case GDK_MOTION_NOTIFY: return "GDK_MOTION_NOTIFY"; |
| 22 case GDK_BUTTON_PRESS: return "GDK_BUTTON_PRESS"; |
| 23 case GDK_2BUTTON_PRESS: return "GDK_2BUTTON_PRESS"; |
| 24 case GDK_3BUTTON_PRESS: return "GDK_3BUTTON_PRESS"; |
| 25 case GDK_BUTTON_RELEASE: return "GDK_BUTTON_RELEASE"; |
| 26 case GDK_KEY_PRESS: return "GDK_KEY_PRESS"; |
| 27 case GDK_KEY_RELEASE: return "GDK_KEY_RELEASE"; |
| 28 case GDK_ENTER_NOTIFY: return "GDK_ENTER_NOTIFY"; |
| 29 case GDK_LEAVE_NOTIFY: return "GDK_LEAVE_NOTIFY"; |
| 30 case GDK_FOCUS_CHANGE: return "GDK_FOCUS_CHANGE"; |
| 31 case GDK_CONFIGURE: return "GDK_CONFIGURE"; |
| 32 case GDK_MAP: return "GDK_MAP"; |
| 33 case GDK_UNMAP: return "GDK_UNMAP"; |
| 34 case GDK_PROPERTY_NOTIFY: return "GDK_PROPERTY_NOTIFY"; |
| 35 case GDK_SELECTION_CLEAR: return "GDK_SELECTION_CLEAR"; |
| 36 case GDK_SELECTION_REQUEST: return "GDK_SELECTION_REQUEST"; |
| 37 case GDK_SELECTION_NOTIFY: return "GDK_SELECTION_NOTIFY"; |
| 38 case GDK_PROXIMITY_IN: return "GDK_PROXIMITY_IN"; |
| 39 case GDK_PROXIMITY_OUT: return "GDK_PROXIMITY_OUT"; |
| 40 case GDK_DRAG_ENTER: return "GDK_DRAG_ENTER"; |
| 41 case GDK_DRAG_LEAVE: return "GDK_DRAG_LEAVE"; |
| 42 case GDK_DRAG_MOTION: return "GDK_DRAG_MOTION"; |
| 43 case GDK_DRAG_STATUS: return "GDK_DRAG_STATUS"; |
| 44 case GDK_DROP_START: return "GDK_DROP_START"; |
| 45 case GDK_DROP_FINISHED: return "GDK_DROP_FINISHED"; |
| 46 case GDK_CLIENT_EVENT: return "GDK_CLIENT_EVENT"; |
| 47 case GDK_VISIBILITY_NOTIFY: return "GDK_VISIBILITY_NOTIFY"; |
| 48 case GDK_NO_EXPOSE: return "GDK_NO_EXPOSE"; |
| 49 case GDK_SCROLL: return "GDK_SCROLL"; |
| 50 case GDK_WINDOW_STATE: return "GDK_WINDOW_STATE"; |
| 51 case GDK_SETTING: return "GDK_SETTING"; |
| 52 case GDK_OWNER_CHANGE: return "GDK_OWNER_CHANGE"; |
| 53 case GDK_GRAB_BROKEN: return "GDK_GRAB_BROKEN"; |
| 54 case GDK_DAMAGE: return "GDK_DAMAGE"; |
| 55 default: |
| 56 return "Unknown Gdk Event"; |
| 57 } |
| 58 } |
| 59 |
| 60 } |
| 61 |
10 namespace base { | 62 namespace base { |
11 | 63 |
12 MessagePumpGtk::MessagePumpGtk() : MessagePumpGlib() { | 64 MessagePumpGtk::MessagePumpGtk() : MessagePumpGlib() { |
13 gdk_event_handler_set(&EventDispatcher, this, NULL); | 65 gdk_event_handler_set(&EventDispatcher, this, NULL); |
14 } | 66 } |
15 | 67 |
16 MessagePumpGtk::~MessagePumpGtk() { | 68 MessagePumpGtk::~MessagePumpGtk() { |
17 gdk_event_handler_set(reinterpret_cast<GdkEventFunc>(gtk_main_do_event), | 69 gdk_event_handler_set(reinterpret_cast<GdkEventFunc>(gtk_main_do_event), |
18 this, NULL); | 70 this, NULL); |
19 } | 71 } |
20 | 72 |
21 void MessagePumpGtk::DispatchEvents(GdkEvent* event) { | 73 void MessagePumpGtk::DispatchEvents(GdkEvent* event) { |
| 74 UNSHIPPED_TRACE_EVENT1("task", "MessagePumpGtk::DispatchEvents", |
| 75 "type", EventToTypeString(event)); |
| 76 |
22 WillProcessEvent(event); | 77 WillProcessEvent(event); |
23 | 78 |
24 MessagePumpDispatcher* dispatcher = GetDispatcher(); | 79 MessagePumpDispatcher* dispatcher = GetDispatcher(); |
25 if (!dispatcher) | 80 if (!dispatcher) |
26 gtk_main_do_event(event); | 81 gtk_main_do_event(event); |
27 else if (!dispatcher->Dispatch(event)) | 82 else if (!dispatcher->Dispatch(event)) |
28 Quit(); | 83 Quit(); |
29 | 84 |
30 DidProcessEvent(event); | 85 DidProcessEvent(event); |
31 } | 86 } |
(...skipping 17 matching lines...) Expand all Loading... |
49 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(event)); | 104 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(event)); |
50 } | 105 } |
51 | 106 |
52 // static | 107 // static |
53 void MessagePumpGtk::EventDispatcher(GdkEvent* event, gpointer data) { | 108 void MessagePumpGtk::EventDispatcher(GdkEvent* event, gpointer data) { |
54 MessagePumpGtk* message_pump = reinterpret_cast<MessagePumpGtk*>(data); | 109 MessagePumpGtk* message_pump = reinterpret_cast<MessagePumpGtk*>(data); |
55 message_pump->DispatchEvents(event); | 110 message_pump->DispatchEvents(event); |
56 } | 111 } |
57 | 112 |
58 } // namespace base | 113 } // namespace base |
OLD | NEW |