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 <bitset> | 7 #include <bitset> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #if defined(HAVE_XINPUT2) | 9 #if defined(HAVE_XINPUT2) |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
11 #else | 11 #else |
12 #include <X11/Xlib.h> | 12 #include <X11/Xlib.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include "views/accelerator.h" | 15 #include "views/accelerator.h" |
16 #include "views/event.h" | 16 #include "views/event.h" |
17 #include "views/focus/focus_manager.h" | 17 #include "views/focus/focus_manager.h" |
| 18 #include "views/touchui/touch_factory.h" |
18 #include "views/widget/root_view.h" | 19 #include "views/widget/root_view.h" |
19 #include "views/widget/widget_gtk.h" | 20 #include "views/widget/widget_gtk.h" |
20 | 21 |
21 namespace views { | 22 namespace views { |
22 | 23 |
23 #if defined(HAVE_XINPUT2) | |
24 // Functions related to determining touch devices. | |
25 class TouchFactory { | |
26 public: | |
27 // Keep a list of touch devices so that it is possible to determine if a | |
28 // pointer event is a touch-event or a mouse-event. | |
29 static void SetTouchDeviceListInternal( | |
30 const std::vector<unsigned int>& devices) { | |
31 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | |
32 iter != devices.end(); ++iter) { | |
33 DCHECK(*iter < touch_devices.size()); | |
34 touch_devices[*iter] = true; | |
35 } | |
36 } | |
37 | |
38 // Is the device a touch-device? | |
39 static bool IsTouchDevice(unsigned int deviceid) { | |
40 return deviceid < touch_devices.size() ? touch_devices[deviceid] : false; | |
41 } | |
42 | |
43 private: | |
44 // A quick lookup table for determining if a device is a touch device. | |
45 static std::bitset<128> touch_devices; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(TouchFactory); | |
48 }; | |
49 | |
50 std::bitset<128> TouchFactory::touch_devices; | |
51 #endif | |
52 | |
53 namespace { | 24 namespace { |
54 | 25 |
55 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) { | 26 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) { |
56 gpointer data = NULL; | 27 gpointer data = NULL; |
57 gdk_window_get_user_data(gdk_window, &data); | 28 gdk_window_get_user_data(gdk_window, &data); |
58 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); | 29 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); |
59 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { | 30 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { |
60 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; | 31 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; |
61 return NULL; | 32 return NULL; |
62 } | 33 } |
63 WidgetGtk* widget_gtk = WidgetGtk::GetViewForNative(gtk_widget); | 34 WidgetGtk* widget_gtk = WidgetGtk::GetViewForNative(gtk_widget); |
64 | 35 |
65 if (!widget_gtk) { | 36 if (!widget_gtk) { |
66 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; | 37 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; |
67 return NULL; | 38 return NULL; |
68 } | 39 } |
69 return widget_gtk->GetRootView(); | 40 return widget_gtk->GetRootView(); |
70 } | 41 } |
71 | 42 |
72 #if defined(HAVE_XINPUT2) | 43 #if defined(HAVE_XINPUT2) |
73 bool X2EventIsTouchEvent(XEvent* xev) { | 44 bool X2EventIsTouchEvent(XEvent* xev) { |
74 // TODO(sad): Determine if the captured event is a touch-event. | 45 // TODO(sad): Determine if the captured event is a touch-event. |
75 XGenericEventCookie* cookie = &xev->xcookie; | 46 XGenericEventCookie* cookie = &xev->xcookie; |
76 switch (cookie->evtype) { | 47 switch (cookie->evtype) { |
77 case XI_ButtonPress: | 48 case XI_ButtonPress: |
78 case XI_ButtonRelease: | 49 case XI_ButtonRelease: |
79 case XI_Motion: { | 50 case XI_Motion: { |
80 // Is the event coming from a touch device? | 51 // Is the event coming from a touch device? |
81 return TouchFactory::IsTouchDevice( | 52 return TouchFactory::GetInstance()->IsTouchDevice( |
82 static_cast<XIDeviceEvent*>(cookie->data)->sourceid); | 53 static_cast<XIDeviceEvent*>(cookie->data)->sourceid); |
83 } | 54 } |
84 default: | 55 default: |
85 return false; | 56 return false; |
86 } | 57 } |
87 } | 58 } |
88 #endif // HAVE_XINPUT2 | 59 #endif // HAVE_XINPUT2 |
89 | 60 |
90 } // namespace | 61 } // namespace |
91 | 62 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 164 } |
194 #endif | 165 #endif |
195 } | 166 } |
196 } | 167 } |
197 | 168 |
198 return false; | 169 return false; |
199 } | 170 } |
200 | 171 |
201 #if defined(HAVE_XINPUT2) | 172 #if defined(HAVE_XINPUT2) |
202 void SetTouchDeviceList(std::vector<unsigned int>& devices) { | 173 void SetTouchDeviceList(std::vector<unsigned int>& devices) { |
203 TouchFactory::SetTouchDeviceListInternal(devices); | 174 TouchFactory::GetInstance()->SetTouchDeviceList(devices); |
204 } | 175 } |
205 #endif | 176 #endif |
206 | 177 |
207 AcceleratorHandler::AcceleratorHandler() {} | 178 AcceleratorHandler::AcceleratorHandler() {} |
208 | 179 |
209 bool AcceleratorHandler::Dispatch(GdkEvent* event) { | 180 bool AcceleratorHandler::Dispatch(GdkEvent* event) { |
210 gtk_main_do_event(event); | 181 gtk_main_do_event(event); |
211 return true; | 182 return true; |
212 } | 183 } |
213 | 184 |
214 base::MessagePumpGlibXDispatcher::DispatchStatus AcceleratorHandler::Dispatch( | 185 base::MessagePumpGlibXDispatcher::DispatchStatus AcceleratorHandler::Dispatch( |
215 XEvent* xev) { | 186 XEvent* xev) { |
216 return DispatchXEvent(xev) ? | 187 return DispatchXEvent(xev) ? |
217 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED : | 188 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED : |
218 base::MessagePumpGlibXDispatcher::EVENT_IGNORED; | 189 base::MessagePumpGlibXDispatcher::EVENT_IGNORED; |
219 } | 190 } |
220 | 191 |
221 } // namespace views | 192 } // namespace views |
OLD | NEW |