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

Side by Side Diff: ui/base/touchui/touch_factory.cc

Issue 7942004: Consolidate/cleanup event cracking code; single out GdkEvents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: File permissions and aura fix. Created 9 years, 3 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
OLDNEW
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 "views/touchui/touch_factory.h" 5 #include "ui/base/touchui/touch_factory.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <gdk/gdkx.h> 8 #include <gdk/gdkx.h>
9 #include <X11/cursorfont.h> 9 #include <X11/cursorfont.h>
10 #include <X11/extensions/XInput.h> 10 #include <X11/extensions/XInput.h>
11 #include <X11/extensions/XInput2.h> 11 #include <X11/extensions/XInput2.h>
12 #include <X11/extensions/XIproto.h> 12 #include <X11/extensions/XIproto.h>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "ui/base/x/x11_util.h" 18 #include "ui/base/x/x11_util.h"
19 19
20 namespace { 20 namespace {
21 21
22 // The X cursor is hidden if it is idle for kCursorIdleSeconds seconds. 22 // The X cursor is hidden if it is idle for kCursorIdleSeconds seconds.
23 int kCursorIdleSeconds = 5; 23 int kCursorIdleSeconds = 5;
24 24
25 // Given the TouchParam, return the correspoding XIValuatorClassInfo using 25 // Given the TouchParam, return the correspoding XIValuatorClassInfo using
26 // the X device information through Atom name matching. 26 // the X device information through Atom name matching.
27 XIValuatorClassInfo* FindTPValuator(Display* display, 27 XIValuatorClassInfo* FindTPValuator(Display* display,
28 XIDeviceInfo* info, 28 XIDeviceInfo* info,
29 views::TouchFactory::TouchParam tp) { 29 ui::TouchFactory::TouchParam tp) {
30 // Lookup table for mapping TouchParam to Atom string used in X. 30 // Lookup table for mapping TouchParam to Atom string used in X.
31 // A full set of Atom strings can be found at xserver-properties.h. 31 // A full set of Atom strings can be found at xserver-properties.h.
32 // For Slot ID, See this chromeos revision: http://git.chromium.org/gitweb/? 32 // For Slot ID, See this chromeos revision: http://git.chromium.org/gitweb/?
33 // p=chromiumos/overlays/chromiumos-overlay.git; 33 // p=chromiumos/overlays/chromiumos-overlay.git;
34 // a=commit;h=9164d0a75e48c4867e4ef4ab51f743ae231c059a 34 // a=commit;h=9164d0a75e48c4867e4ef4ab51f743ae231c059a
35 static struct { 35 static struct {
36 views::TouchFactory::TouchParam tp; 36 ui::TouchFactory::TouchParam tp;
37 const char* atom; 37 const char* atom;
38 } kTouchParamAtom[] = { 38 } kTouchParamAtom[] = {
39 { views::TouchFactory::TP_TOUCH_MAJOR, "Abs MT Touch Major" }, 39 { ui::TouchFactory::TP_TOUCH_MAJOR, "Abs MT Touch Major" },
40 { views::TouchFactory::TP_TOUCH_MINOR, "Abs MT Touch Minor" }, 40 { ui::TouchFactory::TP_TOUCH_MINOR, "Abs MT Touch Minor" },
41 { views::TouchFactory::TP_ORIENTATION, "Abs MT Orientation" }, 41 { ui::TouchFactory::TP_ORIENTATION, "Abs MT Orientation" },
42 { views::TouchFactory::TP_PRESSURE, "Abs MT Pressure" }, 42 { ui::TouchFactory::TP_PRESSURE, "Abs MT Pressure" },
43 { views::TouchFactory::TP_SLOT_ID, "Abs MT Slot ID" }, 43 { ui::TouchFactory::TP_SLOT_ID, "Abs MT Slot ID" },
44 { views::TouchFactory::TP_TRACKING_ID, "Abs MT Tracking ID" }, 44 { ui::TouchFactory::TP_TRACKING_ID, "Abs MT Tracking ID" },
45 { views::TouchFactory::TP_LAST_ENTRY, NULL }, 45 { ui::TouchFactory::TP_LAST_ENTRY, NULL },
46 }; 46 };
47 47
48 const char* atom_tp = NULL; 48 const char* atom_tp = NULL;
49 49
50 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTouchParamAtom); i++) { 50 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTouchParamAtom); i++) {
51 if (tp == kTouchParamAtom[i].tp) { 51 if (tp == kTouchParamAtom[i].tp) {
52 atom_tp = kTouchParamAtom[i].atom; 52 atom_tp = kTouchParamAtom[i].atom;
53 break; 53 break;
54 } 54 }
55 } 55 }
(...skipping 13 matching lines...) Expand all
69 } 69 }
70 70
71 return NULL; 71 return NULL;
72 } 72 }
73 73
74 // Setup XInput2 select for the GtkWidget. 74 // Setup XInput2 select for the GtkWidget.
75 gboolean GtkWidgetRealizeCallback(GSignalInvocationHint* hint, guint nparams, 75 gboolean GtkWidgetRealizeCallback(GSignalInvocationHint* hint, guint nparams,
76 const GValue* pvalues, gpointer data) { 76 const GValue* pvalues, gpointer data) {
77 GtkWidget* widget = GTK_WIDGET(g_value_get_object(pvalues)); 77 GtkWidget* widget = GTK_WIDGET(g_value_get_object(pvalues));
78 GdkWindow* window = widget->window; 78 GdkWindow* window = widget->window;
79 views::TouchFactory* factory = static_cast<views::TouchFactory*>(data); 79 ui::TouchFactory* factory = static_cast<ui::TouchFactory*>(data);
80 80
81 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_TOPLEVEL && 81 if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_TOPLEVEL &&
82 GDK_WINDOW_TYPE(window) != GDK_WINDOW_CHILD && 82 GDK_WINDOW_TYPE(window) != GDK_WINDOW_CHILD &&
83 GDK_WINDOW_TYPE(window) != GDK_WINDOW_DIALOG) 83 GDK_WINDOW_TYPE(window) != GDK_WINDOW_DIALOG)
84 return true; 84 return true;
85 85
86 factory->SetupXI2ForXWindow(GDK_WINDOW_XID(window)); 86 factory->SetupXI2ForXWindow(GDK_WINDOW_XID(window));
87 return true; 87 return true;
88 } 88 }
89 89
90 // We need to capture all the GDK windows that get created, and start 90 // We need to capture all the GDK windows that get created, and start
91 // listening for XInput2 events. So we setup a callback to the 'realize' 91 // listening for XInput2 events. So we setup a callback to the 'realize'
92 // signal for GTK+ widgets, so that whenever the signal triggers for any 92 // signal for GTK+ widgets, so that whenever the signal triggers for any
93 // GtkWidget, which means the GtkWidget should now have a GdkWindow, we can 93 // GtkWidget, which means the GtkWidget should now have a GdkWindow, we can
94 // setup XInput2 events for the GdkWindow. 94 // setup XInput2 events for the GdkWindow.
95 guint realize_signal_id = 0; 95 guint realize_signal_id = 0;
96 guint realize_hook_id = 0; 96 guint realize_hook_id = 0;
97 97
98 void SetupGtkWidgetRealizeNotifier(views::TouchFactory* factory) { 98 void SetupGtkWidgetRealizeNotifier(ui::TouchFactory* factory) {
99 gpointer klass = g_type_class_ref(GTK_TYPE_WIDGET); 99 gpointer klass = g_type_class_ref(GTK_TYPE_WIDGET);
100 100
101 g_signal_parse_name("realize", GTK_TYPE_WIDGET, 101 g_signal_parse_name("realize", GTK_TYPE_WIDGET,
102 &realize_signal_id, NULL, FALSE); 102 &realize_signal_id, NULL, FALSE);
103 realize_hook_id = g_signal_add_emission_hook(realize_signal_id, 0, 103 realize_hook_id = g_signal_add_emission_hook(realize_signal_id, 0,
104 GtkWidgetRealizeCallback, static_cast<gpointer>(factory), NULL); 104 GtkWidgetRealizeCallback, static_cast<gpointer>(factory), NULL);
105 105
106 g_type_class_unref(klass); 106 g_type_class_unref(klass);
107 } 107 }
108 108
109 void RemoveGtkWidgetRealizeNotifier() { 109 void RemoveGtkWidgetRealizeNotifier() {
110 if (realize_signal_id != 0) 110 if (realize_signal_id != 0)
111 g_signal_remove_emission_hook(realize_signal_id, realize_hook_id); 111 g_signal_remove_emission_hook(realize_signal_id, realize_hook_id);
112 realize_signal_id = 0; 112 realize_signal_id = 0;
113 realize_hook_id = 0; 113 realize_hook_id = 0;
114 } 114 }
115 115
116 } // namespace 116 } // namespace
117 117
118 namespace views { 118 namespace ui {
119 119
120 // static 120 // static
121 TouchFactory* TouchFactory::GetInstance() { 121 TouchFactory* TouchFactory::GetInstance() {
122 return Singleton<TouchFactory>::get(); 122 return Singleton<TouchFactory>::get();
123 } 123 }
124 124
125 TouchFactory::TouchFactory() 125 TouchFactory::TouchFactory()
126 : is_cursor_visible_(true), 126 : is_cursor_visible_(true),
127 keep_mouse_cursor_(false), 127 keep_mouse_cursor_(false),
128 cursor_timer_(), 128 cursor_timer_(),
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 float* min, 436 float* min,
437 float* max) { 437 float* max) {
438 if (valuator_lookup_[deviceid][tp] >= 0) { 438 if (valuator_lookup_[deviceid][tp] >= 0) {
439 *min = touch_param_min_[deviceid][tp]; 439 *min = touch_param_min_[deviceid][tp];
440 *max = touch_param_max_[deviceid][tp]; 440 *max = touch_param_max_[deviceid][tp];
441 return true; 441 return true;
442 } 442 }
443 return false; 443 return false;
444 } 444 }
445 445
446 } // namespace views 446 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698