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" | 5 #include "views/focus/accelerator_handler.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #if defined(HAVE_XINPUT2) |
| 9 #include <X11/extensions/XInput2.h> |
| 10 #else |
8 #include <X11/Xlib.h> | 11 #include <X11/Xlib.h> |
| 12 #endif |
9 | 13 |
10 #include "views/accelerator.h" | 14 #include "views/accelerator.h" |
11 #include "views/event.h" | 15 #include "views/event.h" |
12 #include "views/focus/focus_manager.h" | 16 #include "views/focus/focus_manager.h" |
13 #include "views/widget/root_view.h" | 17 #include "views/widget/root_view.h" |
14 #include "views/widget/widget_gtk.h" | 18 #include "views/widget/widget_gtk.h" |
15 | 19 |
16 namespace views { | 20 namespace views { |
17 | 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) { | 24 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) { |
21 gpointer data = NULL; | 25 gpointer data = NULL; |
22 gdk_window_get_user_data(gdk_window, &data); | 26 gdk_window_get_user_data(gdk_window, &data); |
23 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); | 27 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); |
24 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { | 28 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { |
25 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; | 29 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; |
26 return NULL; | 30 return NULL; |
27 } | 31 } |
28 WidgetGtk* widget_gtk = WidgetGtk::GetViewForNative(gtk_widget); | 32 WidgetGtk* widget_gtk = WidgetGtk::GetViewForNative(gtk_widget); |
29 | 33 |
30 if (!widget_gtk) { | 34 if (!widget_gtk) { |
31 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; | 35 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; |
32 return NULL; | 36 return NULL; |
33 } | 37 } |
34 return widget_gtk->GetRootView(); | 38 return widget_gtk->GetRootView(); |
35 } | 39 } |
36 | 40 |
| 41 #if defined(HAVE_XINPUT2) |
| 42 bool X2EventIsTouchEvent(XEvent* xev) { |
| 43 // TODO(sad): Determine if the captured event is a touch-event. |
| 44 return false; |
| 45 } |
| 46 #endif // HAVE_XINPUT2 |
| 47 |
37 } // namespace | 48 } // namespace |
38 | 49 |
| 50 #if defined(HAVE_XINPUT2) |
| 51 bool DispatchX2Event(RootView* root, XEvent* xev) { |
| 52 if (X2EventIsTouchEvent(xev)) { |
| 53 // TODO(sad): Create a TouchEvent, and send it off to |root|. If the event |
| 54 // is processed by |root|, then return. Otherwise let it fall through so it |
| 55 // can be used (if desired) as a mouse event. |
| 56 |
| 57 // TouchEvent touch(xev); |
| 58 // if (root->OnTouchEvent(touch)) |
| 59 // return true; |
| 60 } |
| 61 |
| 62 XGenericEventCookie* cookie = &xev->xcookie; |
| 63 |
| 64 switch (cookie->evtype) { |
| 65 case XI_KeyPress: |
| 66 case XI_KeyRelease: { |
| 67 // TODO(sad): We don't capture XInput2 events from keyboard yet. |
| 68 break; |
| 69 } |
| 70 case XI_ButtonPress: |
| 71 case XI_ButtonRelease: { |
| 72 MouseEvent mouseev(xev); |
| 73 if (cookie->evtype == XI_ButtonPress) { |
| 74 return root->OnMousePressed(mouseev); |
| 75 } else { |
| 76 root->OnMouseReleased(mouseev, false); |
| 77 return true; |
| 78 } |
| 79 } |
| 80 |
| 81 case XI_Motion: { |
| 82 MouseEvent mouseev(xev); |
| 83 if (mouseev.GetType() == Event::ET_MOUSE_DRAGGED) { |
| 84 return root->OnMouseDragged(mouseev); |
| 85 } else { |
| 86 root->OnMouseMoved(mouseev); |
| 87 return true; |
| 88 } |
| 89 break; |
| 90 } |
| 91 } |
| 92 |
| 93 return false; |
| 94 } |
| 95 |
| 96 #endif // HAVE_XINPUT2 |
| 97 |
39 bool DispatchXEvent(XEvent* xev) { | 98 bool DispatchXEvent(XEvent* xev) { |
40 GdkDisplay* gdisp = gdk_display_get_default(); | 99 GdkDisplay* gdisp = gdk_display_get_default(); |
41 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xev->xany.window); | 100 XID xwindow = xev->xany.window; |
| 101 |
| 102 #if defined(HAVE_XINPUT2) |
| 103 if (xev->type == GenericEvent) { |
| 104 if (XGetEventData(xev->xgeneric.display, &xev->xcookie)) { |
| 105 XGenericEventCookie* cookie = &xev->xcookie; |
| 106 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); |
| 107 xwindow = xiev->event; |
| 108 } else { |
| 109 DLOG(WARNING) << "Error fetching XGenericEventCookie for event."; |
| 110 return false; |
| 111 } |
| 112 } |
| 113 #endif |
| 114 |
| 115 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); |
42 | 116 |
43 if (RootView* root = FindRootViewForGdkWindow(gwind)) { | 117 if (RootView* root = FindRootViewForGdkWindow(gwind)) { |
44 switch (xev->type) { | 118 switch (xev->type) { |
45 case KeyPress: | 119 case KeyPress: |
46 case KeyRelease: { | 120 case KeyRelease: { |
47 KeyEvent keyev(xev); | 121 KeyEvent keyev(xev); |
48 | 122 |
49 // If it's a keypress, check to see if it triggers an accelerator. | 123 // If it's a keypress, check to see if it triggers an accelerator. |
50 if (xev->type == KeyPress) { | 124 if (xev->type == KeyPress) { |
51 FocusManager* focus_manager = root->GetFocusManager(); | 125 FocusManager* focus_manager = root->GetFocusManager(); |
(...skipping 18 matching lines...) Expand all Loading... |
70 | 144 |
71 case MotionNotify: { | 145 case MotionNotify: { |
72 MouseEvent mouseev(xev); | 146 MouseEvent mouseev(xev); |
73 if (mouseev.GetType() == Event::ET_MOUSE_DRAGGED) { | 147 if (mouseev.GetType() == Event::ET_MOUSE_DRAGGED) { |
74 return root->OnMouseDragged(mouseev); | 148 return root->OnMouseDragged(mouseev); |
75 } else { | 149 } else { |
76 root->OnMouseMoved(mouseev); | 150 root->OnMouseMoved(mouseev); |
77 return true; | 151 return true; |
78 } | 152 } |
79 } | 153 } |
| 154 |
| 155 #if defined(HAVE_XINPUT2) |
| 156 case GenericEvent: { |
| 157 bool ret = DispatchX2Event(root, xev); |
| 158 XFreeEventData(xev->xgeneric.display, &xev->xcookie); |
| 159 return ret; |
| 160 } |
| 161 #endif |
80 } | 162 } |
81 } | 163 } |
82 | 164 |
83 return false; | 165 return false; |
84 } | 166 } |
85 | 167 |
86 AcceleratorHandler::AcceleratorHandler() {} | 168 AcceleratorHandler::AcceleratorHandler() {} |
87 | 169 |
88 bool AcceleratorHandler::Dispatch(GdkEvent* event) { | 170 bool AcceleratorHandler::Dispatch(GdkEvent* event) { |
89 gtk_main_do_event(event); | 171 gtk_main_do_event(event); |
90 return true; | 172 return true; |
91 } | 173 } |
92 | 174 |
93 bool AcceleratorHandler::Dispatch(XEvent* xev) { | 175 bool AcceleratorHandler::Dispatch(XEvent* xev) { |
94 return DispatchXEvent(xev); | 176 return DispatchXEvent(xev); |
95 } | 177 } |
96 | 178 |
97 } // namespace views | 179 } // namespace views |
OLD | NEW |