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