OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/focus/accelerator_handler.h" |
| 6 |
5 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <X11/Xlib.h> |
6 | 9 |
7 #include "views/accelerator.h" | 10 #include "views/accelerator.h" |
8 #include "views/focus/accelerator_handler.h" | 11 #include "views/event.h" |
9 #include "views/focus/focus_manager.h" | 12 #include "views/focus/focus_manager.h" |
10 #include "views/touchui/touch_event_dispatcher_gtk.h" | 13 #include "views/widget/root_view.h" |
11 #include "views/widget/widget_gtk.h" | 14 #include "views/widget/widget_gtk.h" |
12 | 15 |
13 namespace views { | 16 namespace views { |
14 | 17 |
| 18 namespace { |
| 19 |
| 20 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) { |
| 21 gpointer data = NULL; |
| 22 gdk_window_get_user_data(gdk_window, &data); |
| 23 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); |
| 24 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { |
| 25 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; |
| 26 return NULL; |
| 27 } |
| 28 WidgetGtk* widget_gtk = WidgetGtk::GetViewForNative(gtk_widget); |
| 29 |
| 30 if (!widget_gtk) { |
| 31 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; |
| 32 return NULL; |
| 33 } |
| 34 return widget_gtk->GetRootView(); |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 39 bool DispatchXEvent(XEvent* xev) { |
| 40 GdkDisplay* gdisp = gdk_display_get_default(); |
| 41 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xev->xany.window); |
| 42 |
| 43 if (RootView* root = FindRootViewForGdkWindow(gwind)) { |
| 44 switch (xev->type) { |
| 45 case KeyPress: |
| 46 case KeyRelease: { |
| 47 KeyEvent keyev(xev); |
| 48 |
| 49 // If it's a keypress, check to see if it triggers an accelerator. |
| 50 if (xev->type == KeyPress) { |
| 51 FocusManager* focus_manager = root->GetFocusManager(); |
| 52 if (focus_manager && !focus_manager->OnKeyEvent(keyev)) |
| 53 return true; |
| 54 } |
| 55 |
| 56 return root->ProcessKeyEvent(keyev); |
| 57 } |
| 58 |
| 59 case ButtonPress: |
| 60 case ButtonRelease: { |
| 61 MouseEvent mouseev(xev); |
| 62 if (xev->type == ButtonPress) { |
| 63 return root->OnMousePressed(mouseev); |
| 64 } else { |
| 65 root->OnMouseReleased(mouseev, false); |
| 66 return true; // Assume the event has been processed to make sure we |
| 67 // don't process it twice. |
| 68 } |
| 69 } |
| 70 |
| 71 case MotionNotify: { |
| 72 MouseEvent mouseev(xev); |
| 73 if (mouseev.GetType() == Event::ET_MOUSE_DRAGGED) { |
| 74 return root->OnMouseDragged(mouseev); |
| 75 } else { |
| 76 root->OnMouseMoved(mouseev); |
| 77 return true; |
| 78 } |
| 79 } |
| 80 } |
| 81 } |
| 82 |
| 83 return false; |
| 84 } |
| 85 |
15 AcceleratorHandler::AcceleratorHandler() {} | 86 AcceleratorHandler::AcceleratorHandler() {} |
16 | 87 |
17 bool AcceleratorHandler::Dispatch(GdkEvent* event) { | 88 bool AcceleratorHandler::Dispatch(GdkEvent* event) { |
18 // The logic for handling keyboard accelerators has been moved into | 89 gtk_main_do_event(event); |
19 // WidgetGtk::OnKeyEvent handler (views/widget/widget_gtk.cc). | |
20 | |
21 // TODO(wyck): Hijack TouchUI events at other calls to gtk_main_do_event. | |
22 // There are more places where we call gtk_main_do_event. | |
23 // In particular: the message pump itself, and the menu controller, | |
24 // as well as native_menu_gtk. | |
25 // This function contains the most important one important one, though. | |
26 if (!DispatchEventForTouchUIGtk(event)) | |
27 gtk_main_do_event(event); | |
28 | |
29 return true; | 90 return true; |
30 } | 91 } |
31 | 92 |
| 93 bool AcceleratorHandler::Dispatch(XEvent* xev) { |
| 94 return DispatchXEvent(xev); |
| 95 } |
| 96 |
32 } // namespace views | 97 } // namespace views |
OLD | NEW |