Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: views/focus/accelerator_handler_touch.cc

Issue 6349008: Revert 71879 due to compile failure - touch: Allow grabbing/ungrabbing touch ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/menu/menu_host_gtk.cc ('k') | views/touchui/touch_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
19 #include "views/widget/root_view.h" 18 #include "views/widget/root_view.h"
20 #include "views/widget/widget_gtk.h" 19 #include "views/widget/widget_gtk.h"
21 20
22 namespace views { 21 namespace views {
23 22
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
24 namespace { 53 namespace {
25 54
26 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) { 55 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) {
27 gpointer data = NULL; 56 gpointer data = NULL;
28 gdk_window_get_user_data(gdk_window, &data); 57 gdk_window_get_user_data(gdk_window, &data);
29 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); 58 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data);
30 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { 59 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) {
31 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; 60 DLOG(WARNING) << "no GtkWidget found for that GdkWindow";
32 return NULL; 61 return NULL;
33 } 62 }
34 WidgetGtk* widget_gtk = WidgetGtk::GetViewForNative(gtk_widget); 63 WidgetGtk* widget_gtk = WidgetGtk::GetViewForNative(gtk_widget);
35 64
36 if (!widget_gtk) { 65 if (!widget_gtk) {
37 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; 66 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget";
38 return NULL; 67 return NULL;
39 } 68 }
40 return widget_gtk->GetRootView(); 69 return widget_gtk->GetRootView();
41 } 70 }
42 71
43 #if defined(HAVE_XINPUT2) 72 #if defined(HAVE_XINPUT2)
44 bool X2EventIsTouchEvent(XEvent* xev) { 73 bool X2EventIsTouchEvent(XEvent* xev) {
45 // TODO(sad): Determine if the captured event is a touch-event. 74 // TODO(sad): Determine if the captured event is a touch-event.
46 XGenericEventCookie* cookie = &xev->xcookie; 75 XGenericEventCookie* cookie = &xev->xcookie;
47 switch (cookie->evtype) { 76 switch (cookie->evtype) {
48 case XI_ButtonPress: 77 case XI_ButtonPress:
49 case XI_ButtonRelease: 78 case XI_ButtonRelease:
50 case XI_Motion: { 79 case XI_Motion: {
51 // Is the event coming from a touch device? 80 // Is the event coming from a touch device?
52 return TouchFactory::GetInstance()->IsTouchDevice( 81 return TouchFactory::IsTouchDevice(
53 static_cast<XIDeviceEvent*>(cookie->data)->sourceid); 82 static_cast<XIDeviceEvent*>(cookie->data)->sourceid);
54 } 83 }
55 default: 84 default:
56 return false; 85 return false;
57 } 86 }
58 } 87 }
59 #endif // HAVE_XINPUT2 88 #endif // HAVE_XINPUT2
60 89
61 } // namespace 90 } // namespace
62 91
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 193 }
165 #endif 194 #endif
166 } 195 }
167 } 196 }
168 197
169 return false; 198 return false;
170 } 199 }
171 200
172 #if defined(HAVE_XINPUT2) 201 #if defined(HAVE_XINPUT2)
173 void SetTouchDeviceList(std::vector<unsigned int>& devices) { 202 void SetTouchDeviceList(std::vector<unsigned int>& devices) {
174 TouchFactory::GetInstance()->SetTouchDeviceList(devices); 203 TouchFactory::SetTouchDeviceListInternal(devices);
175 } 204 }
176 #endif 205 #endif
177 206
178 AcceleratorHandler::AcceleratorHandler() {} 207 AcceleratorHandler::AcceleratorHandler() {}
179 208
180 bool AcceleratorHandler::Dispatch(GdkEvent* event) { 209 bool AcceleratorHandler::Dispatch(GdkEvent* event) {
181 gtk_main_do_event(event); 210 gtk_main_do_event(event);
182 return true; 211 return true;
183 } 212 }
184 213
185 base::MessagePumpGlibXDispatcher::DispatchStatus AcceleratorHandler::Dispatch( 214 base::MessagePumpGlibXDispatcher::DispatchStatus AcceleratorHandler::Dispatch(
186 XEvent* xev) { 215 XEvent* xev) {
187 return DispatchXEvent(xev) ? 216 return DispatchXEvent(xev) ?
188 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED : 217 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED :
189 base::MessagePumpGlibXDispatcher::EVENT_IGNORED; 218 base::MessagePumpGlibXDispatcher::EVENT_IGNORED;
190 } 219 }
191 220
192 } // namespace views 221 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/menu/menu_host_gtk.cc ('k') | views/touchui/touch_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698