OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/platform/x11/device_data_manager_x11.h" | 5 #include "ui/events/devices/x11/device_data_manager_x11.h" |
6 | 6 |
7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 | 10 |
| 11 #include <utility> |
| 12 |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
13 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 16 #include "ui/events/devices/keyboard_device.h" |
| 17 #include "ui/events/devices/x11/device_list_cache_x11.h" |
| 18 #include "ui/events/devices/x11/touch_factory_x11.h" |
14 #include "ui/events/event_constants.h" | 19 #include "ui/events/event_constants.h" |
15 #include "ui/events/event_switches.h" | 20 #include "ui/events/event_switches.h" |
16 #include "ui/events/platform/x11/device_list_cache_x.h" | 21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
17 #include "ui/events/platform/x11/keyboard_code_conversion_x11.h" | |
18 #include "ui/events/platform/x11/touch_factory_x11.h" | |
19 #include "ui/gfx/display.h" | 22 #include "ui/gfx/display.h" |
20 #include "ui/gfx/point3_f.h" | 23 #include "ui/gfx/geometry/point3_f.h" |
21 #include "ui/gfx/x/x11_types.h" | 24 #include "ui/gfx/x/x11_types.h" |
22 | 25 |
23 // XIScrollClass was introduced in XI 2.1 so we need to define it here | 26 // XIScrollClass was introduced in XI 2.1 so we need to define it here |
24 // for backward-compatibility with older versions of XInput. | 27 // for backward-compatibility with older versions of XInput. |
25 #if !defined(XIScrollClass) | 28 #if !defined(XIScrollClass) |
26 #define XIScrollClass 3 | 29 #define XIScrollClass 3 |
27 #endif | 30 #endif |
28 | 31 |
29 // Multi-touch support was introduced in XI 2.2. Add XI event types here | 32 // Multi-touch support was introduced in XI 2.2. Add XI event types here |
30 // for backward-compatibility with older versions of XInput. | 33 // for backward-compatibility with older versions of XInput. |
31 #if !defined(XI_TouchBegin) | 34 #if !defined(XI_TouchBegin) |
32 #define XI_TouchBegin 18 | 35 #define XI_TouchBegin 18 |
33 #define XI_TouchUpdate 19 | 36 #define XI_TouchUpdate 19 |
34 #define XI_TouchEnd 20 | 37 #define XI_TouchEnd 20 |
35 #endif | 38 #endif |
36 | 39 |
37 // Copied from xserver-properties.h | 40 // Copied from xserver-properties.h |
38 #define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel" | 41 #define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel" |
39 #define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel" | 42 #define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel" |
40 | 43 |
41 // CMT specific timings | 44 // CMT specific timings |
42 #define AXIS_LABEL_PROP_ABS_DBL_START_TIME "Abs Dbl Start Timestamp" | 45 #define AXIS_LABEL_PROP_ABS_DBL_START_TIME "Abs Dbl Start Timestamp" |
43 #define AXIS_LABEL_PROP_ABS_DBL_END_TIME "Abs Dbl End Timestamp" | 46 #define AXIS_LABEL_PROP_ABS_DBL_END_TIME "Abs Dbl End Timestamp" |
44 | 47 |
45 // Ordinal values | 48 // Ordinal values |
46 #define AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X "Abs Dbl Ordinal X" | 49 #define AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X "Abs Dbl Ordinal X" |
47 #define AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y "Abs Dbl Ordinal Y" | 50 #define AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y "Abs Dbl Ordinal Y" |
48 | 51 |
49 // Fling properties | 52 // Fling properties |
50 #define AXIS_LABEL_PROP_ABS_DBL_FLING_VX "Abs Dbl Fling X Velocity" | 53 #define AXIS_LABEL_PROP_ABS_DBL_FLING_VX "Abs Dbl Fling X Velocity" |
51 #define AXIS_LABEL_PROP_ABS_DBL_FLING_VY "Abs Dbl Fling Y Velocity" | 54 #define AXIS_LABEL_PROP_ABS_DBL_FLING_VY "Abs Dbl Fling Y Velocity" |
52 #define AXIS_LABEL_PROP_ABS_FLING_STATE "Abs Fling State" | 55 #define AXIS_LABEL_PROP_ABS_FLING_STATE "Abs Fling State" |
53 | 56 |
54 #define AXIS_LABEL_PROP_ABS_FINGER_COUNT "Abs Finger Count" | 57 #define AXIS_LABEL_PROP_ABS_FINGER_COUNT "Abs Finger Count" |
55 | 58 |
56 // Cros metrics gesture from touchpad | 59 // Cros metrics gesture from touchpad |
57 #define AXIS_LABEL_PROP_ABS_METRICS_TYPE "Abs Metrics Type" | 60 #define AXIS_LABEL_PROP_ABS_METRICS_TYPE "Abs Metrics Type" |
58 #define AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1 "Abs Dbl Metrics Data 1" | 61 #define AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1 "Abs Dbl Metrics Data 1" |
59 #define AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2 "Abs Dbl Metrics Data 2" | 62 #define AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2 "Abs Dbl Metrics Data 2" |
60 | 63 |
61 // Touchscreen multi-touch | 64 // Touchscreen multi-touch |
62 #define AXIS_LABEL_ABS_MT_TOUCH_MAJOR "Abs MT Touch Major" | 65 #define AXIS_LABEL_ABS_MT_TOUCH_MAJOR "Abs MT Touch Major" |
63 #define AXIS_LABEL_ABS_MT_TOUCH_MINOR "Abs MT Touch Minor" | 66 #define AXIS_LABEL_ABS_MT_TOUCH_MINOR "Abs MT Touch Minor" |
64 #define AXIS_LABEL_ABS_MT_ORIENTATION "Abs MT Orientation" | 67 #define AXIS_LABEL_ABS_MT_ORIENTATION "Abs MT Orientation" |
65 #define AXIS_LABEL_ABS_MT_PRESSURE "Abs MT Pressure" | 68 #define AXIS_LABEL_ABS_MT_PRESSURE "Abs MT Pressure" |
66 #define AXIS_LABEL_ABS_MT_POSITION_X "Abs MT Position X" | 69 #define AXIS_LABEL_ABS_MT_POSITION_X "Abs MT Position X" |
67 #define AXIS_LABEL_ABS_MT_POSITION_Y "Abs MT Position Y" | 70 #define AXIS_LABEL_ABS_MT_POSITION_Y "Abs MT Position Y" |
68 #define AXIS_LABEL_ABS_MT_TRACKING_ID "Abs MT Tracking ID" | 71 #define AXIS_LABEL_ABS_MT_TRACKING_ID "Abs MT Tracking ID" |
69 #define AXIS_LABEL_TOUCH_TIMESTAMP "Touch Timestamp" | 72 #define AXIS_LABEL_TOUCH_TIMESTAMP "Touch Timestamp" |
70 | 73 |
71 // When you add new data types, please make sure the order here is aligned | 74 // When you add new data types, please make sure the order here is aligned |
72 // with the order in the DataType enum in the header file because we assume | 75 // with the order in the DataType enum in the header file because we assume |
73 // they are in sync when updating the device list (see UpdateDeviceList). | 76 // they are in sync when updating the device list (see UpdateDeviceList). |
74 const char* kCachedAtoms[] = {AXIS_LABEL_PROP_REL_HWHEEL, | 77 const char* kCachedAtoms[] = { |
75 AXIS_LABEL_PROP_REL_WHEEL, | 78 AXIS_LABEL_PROP_REL_HWHEEL, |
76 AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X, | 79 AXIS_LABEL_PROP_REL_WHEEL, |
77 AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y, | 80 AXIS_LABEL_PROP_ABS_DBL_ORDINAL_X, |
78 AXIS_LABEL_PROP_ABS_DBL_START_TIME, | 81 AXIS_LABEL_PROP_ABS_DBL_ORDINAL_Y, |
79 AXIS_LABEL_PROP_ABS_DBL_END_TIME, | 82 AXIS_LABEL_PROP_ABS_DBL_START_TIME, |
80 AXIS_LABEL_PROP_ABS_DBL_FLING_VX, | 83 AXIS_LABEL_PROP_ABS_DBL_END_TIME, |
81 AXIS_LABEL_PROP_ABS_DBL_FLING_VY, | 84 AXIS_LABEL_PROP_ABS_DBL_FLING_VX, |
82 AXIS_LABEL_PROP_ABS_FLING_STATE, | 85 AXIS_LABEL_PROP_ABS_DBL_FLING_VY, |
83 AXIS_LABEL_PROP_ABS_METRICS_TYPE, | 86 AXIS_LABEL_PROP_ABS_FLING_STATE, |
84 AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1, | 87 AXIS_LABEL_PROP_ABS_METRICS_TYPE, |
85 AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2, | 88 AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA1, |
86 AXIS_LABEL_PROP_ABS_FINGER_COUNT, | 89 AXIS_LABEL_PROP_ABS_DBL_METRICS_DATA2, |
87 AXIS_LABEL_ABS_MT_TOUCH_MAJOR, | 90 AXIS_LABEL_PROP_ABS_FINGER_COUNT, |
88 AXIS_LABEL_ABS_MT_TOUCH_MINOR, | 91 AXIS_LABEL_ABS_MT_TOUCH_MAJOR, |
89 AXIS_LABEL_ABS_MT_ORIENTATION, | 92 AXIS_LABEL_ABS_MT_TOUCH_MINOR, |
90 AXIS_LABEL_ABS_MT_PRESSURE, | 93 AXIS_LABEL_ABS_MT_ORIENTATION, |
91 AXIS_LABEL_ABS_MT_POSITION_X, | 94 AXIS_LABEL_ABS_MT_PRESSURE, |
92 AXIS_LABEL_ABS_MT_POSITION_Y, | 95 AXIS_LABEL_ABS_MT_POSITION_X, |
93 AXIS_LABEL_ABS_MT_TRACKING_ID, | 96 AXIS_LABEL_ABS_MT_POSITION_Y, |
94 AXIS_LABEL_TOUCH_TIMESTAMP, | 97 AXIS_LABEL_ABS_MT_TRACKING_ID, |
| 98 AXIS_LABEL_TOUCH_TIMESTAMP, |
95 | 99 |
96 NULL}; | 100 NULL |
| 101 }; |
97 | 102 |
98 // Constants for checking if a data type lies in the range of CMT/Touch data | 103 // Constants for checking if a data type lies in the range of CMT/Touch data |
99 // types. | 104 // types. |
100 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; | 105 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; |
101 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; | 106 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; |
102 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; | 107 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; |
103 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; | 108 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; |
104 | 109 |
105 namespace ui { | 110 namespace ui { |
106 | 111 |
| 112 namespace { |
| 113 |
| 114 bool DeviceHasId(const ui::InputDevice input_device, int id) { |
| 115 return input_device.id == id; |
| 116 } |
| 117 |
| 118 } // namespace |
| 119 |
107 bool DeviceDataManagerX11::IsCMTDataType(const int type) { | 120 bool DeviceDataManagerX11::IsCMTDataType(const int type) { |
108 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); | 121 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); |
109 } | 122 } |
110 | 123 |
111 bool DeviceDataManagerX11::IsTouchDataType(const int type) { | 124 bool DeviceDataManagerX11::IsTouchDataType(const int type) { |
112 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); | 125 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); |
113 } | 126 } |
114 | 127 |
115 // static | 128 // static |
116 void DeviceDataManagerX11::CreateInstance() { | 129 void DeviceDataManagerX11::CreateInstance() { |
(...skipping 21 matching lines...) Expand all Loading... |
138 UpdateButtonMap(); | 151 UpdateButtonMap(); |
139 } | 152 } |
140 | 153 |
141 DeviceDataManagerX11::~DeviceDataManagerX11() { | 154 DeviceDataManagerX11::~DeviceDataManagerX11() { |
142 } | 155 } |
143 | 156 |
144 bool DeviceDataManagerX11::InitializeXInputInternal() { | 157 bool DeviceDataManagerX11::InitializeXInputInternal() { |
145 // Check if XInput is available on the system. | 158 // Check if XInput is available on the system. |
146 xi_opcode_ = -1; | 159 xi_opcode_ = -1; |
147 int opcode, event, error; | 160 int opcode, event, error; |
148 if (!XQueryExtension(gfx::GetXDisplay(), "XInputExtension", &opcode, &event, | 161 if (!XQueryExtension( |
149 &error)) { | 162 gfx::GetXDisplay(), "XInputExtension", &opcode, &event, &error)) { |
150 VLOG(1) << "X Input extension not available: error=" << error; | 163 VLOG(1) << "X Input extension not available: error=" << error; |
151 return false; | 164 return false; |
152 } | 165 } |
153 | 166 |
154 // Check the XInput version. | 167 // Check the XInput version. |
155 #if defined(USE_XI2_MT) | 168 int major = 2, minor = 2; |
156 int major = 2, minor = USE_XI2_MT; | |
157 #else | |
158 int major = 2, minor = 0; | |
159 #endif | |
160 if (XIQueryVersion(gfx::GetXDisplay(), &major, &minor) == BadRequest) { | 169 if (XIQueryVersion(gfx::GetXDisplay(), &major, &minor) == BadRequest) { |
161 VLOG(1) << "XInput2 not supported in the server."; | 170 VLOG(1) << "XInput2 not supported in the server."; |
162 return false; | 171 return false; |
163 } | 172 } |
164 #if defined(USE_XI2_MT) | 173 if (major < 2 || (major == 2 && minor < 2)) { |
165 if (major < 2 || (major == 2 && minor < USE_XI2_MT)) { | |
166 DVLOG(1) << "XI version on server is " << major << "." << minor << ". " | 174 DVLOG(1) << "XI version on server is " << major << "." << minor << ". " |
167 << "But 2." << USE_XI2_MT << " is required."; | 175 << "But 2.2 is required."; |
168 return false; | 176 return false; |
169 } | 177 } |
170 #endif | |
171 | 178 |
172 xi_opcode_ = opcode; | 179 xi_opcode_ = opcode; |
173 CHECK_NE(-1, xi_opcode_); | 180 CHECK_NE(-1, xi_opcode_); |
174 | 181 |
175 // Possible XI event types for XIDeviceEvent. See the XI2 protocol | 182 // Possible XI event types for XIDeviceEvent. See the XI2 protocol |
176 // specification. | 183 // specification. |
177 xi_device_event_types_[XI_KeyPress] = true; | 184 xi_device_event_types_[XI_KeyPress] = true; |
178 xi_device_event_types_[XI_KeyRelease] = true; | 185 xi_device_event_types_[XI_KeyRelease] = true; |
179 xi_device_event_types_[XI_ButtonPress] = true; | 186 xi_device_event_types_[XI_ButtonPress] = true; |
180 xi_device_event_types_[XI_ButtonRelease] = true; | 187 xi_device_event_types_[XI_ButtonRelease] = true; |
181 xi_device_event_types_[XI_Motion] = true; | 188 xi_device_event_types_[XI_Motion] = true; |
182 // Multi-touch support was introduced in XI 2.2. | 189 // Multi-touch support was introduced in XI 2.2. |
183 if (minor >= 2) { | 190 if (minor >= 2) { |
184 xi_device_event_types_[XI_TouchBegin] = true; | 191 xi_device_event_types_[XI_TouchBegin] = true; |
185 xi_device_event_types_[XI_TouchUpdate] = true; | 192 xi_device_event_types_[XI_TouchUpdate] = true; |
186 xi_device_event_types_[XI_TouchEnd] = true; | 193 xi_device_event_types_[XI_TouchEnd] = true; |
187 } | 194 } |
188 return true; | 195 return true; |
189 } | 196 } |
190 | 197 |
191 bool DeviceDataManagerX11::IsXInput2Available() const { | 198 bool DeviceDataManagerX11::IsXInput2Available() const { |
192 return xi_opcode_ != -1; | 199 return xi_opcode_ != -1; |
193 } | 200 } |
194 | 201 |
195 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { | 202 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
196 cmt_devices_.reset(); | 203 cmt_devices_.reset(); |
197 touchpads_.reset(); | 204 touchpads_.reset(); |
| 205 master_pointers_.clear(); |
198 for (int i = 0; i < kMaxDeviceNum; ++i) { | 206 for (int i = 0; i < kMaxDeviceNum; ++i) { |
199 valuator_count_[i] = 0; | 207 valuator_count_[i] = 0; |
200 valuator_lookup_[i].clear(); | 208 valuator_lookup_[i].clear(); |
201 data_type_lookup_[i].clear(); | 209 data_type_lookup_[i].clear(); |
202 valuator_min_[i].clear(); | 210 valuator_min_[i].clear(); |
203 valuator_max_[i].clear(); | 211 valuator_max_[i].clear(); |
204 for (int j = 0; j < kMaxSlotNum; j++) | 212 for (int j = 0; j < kMaxSlotNum; j++) |
205 last_seen_valuator_[i][j].clear(); | 213 last_seen_valuator_[i][j].clear(); |
206 } | 214 } |
207 | 215 |
208 // Find all the touchpad devices. | 216 // Find all the touchpad devices. |
209 XDeviceList dev_list = | 217 const XDeviceList& dev_list = |
210 ui::DeviceListCacheX::GetInstance()->GetXDeviceList(display); | 218 ui::DeviceListCacheX11::GetInstance()->GetXDeviceList(display); |
211 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); | 219 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); |
212 for (int i = 0; i < dev_list.count; ++i) | 220 for (int i = 0; i < dev_list.count; ++i) |
213 if (dev_list[i].type == xi_touchpad) | 221 if (dev_list[i].type == xi_touchpad) |
214 touchpads_[dev_list[i].id] = true; | 222 touchpads_[dev_list[i].id] = true; |
215 | 223 |
216 if (!IsXInput2Available()) | 224 if (!IsXInput2Available()) |
217 return; | 225 return; |
218 | 226 |
219 // Update the structs with new valuator information | 227 // Update the structs with new valuator information |
220 XIDeviceList info_list = | 228 const XIDeviceList& info_list = |
221 ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(display); | 229 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); |
222 Atom atoms[DT_LAST_ENTRY]; | 230 Atom atoms[DT_LAST_ENTRY]; |
223 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) | 231 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) |
224 atoms[data_type] = atom_cache_.GetAtom(kCachedAtoms[data_type]); | 232 atoms[data_type] = atom_cache_.GetAtom(kCachedAtoms[data_type]); |
225 | 233 |
226 for (int i = 0; i < info_list.count; ++i) { | 234 for (int i = 0; i < info_list.count; ++i) { |
227 XIDeviceInfo* info = info_list.devices + i; | 235 const XIDeviceInfo& info = info_list[i]; |
| 236 |
| 237 if (info.use == XIMasterPointer) |
| 238 master_pointers_.push_back(info.deviceid); |
228 | 239 |
229 // We currently handle only slave, non-keyboard devices | 240 // We currently handle only slave, non-keyboard devices |
230 if (info->use != XISlavePointer && info->use != XIFloatingSlave) | 241 if (info.use != XISlavePointer && info.use != XIFloatingSlave) |
231 continue; | 242 continue; |
232 | 243 |
233 bool possible_cmt = false; | 244 bool possible_cmt = false; |
234 bool not_cmt = false; | 245 bool not_cmt = false; |
235 const int deviceid = info->deviceid; | 246 const int deviceid = info.deviceid; |
236 | 247 |
237 for (int j = 0; j < info->num_classes; ++j) { | 248 for (int j = 0; j < info.num_classes; ++j) { |
238 if (info->classes[j]->type == XIValuatorClass) | 249 if (info.classes[j]->type == XIValuatorClass) |
239 ++valuator_count_[deviceid]; | 250 ++valuator_count_[deviceid]; |
240 else if (info->classes[j]->type == XIScrollClass) | 251 else if (info.classes[j]->type == XIScrollClass) |
241 not_cmt = true; | 252 not_cmt = true; |
242 } | 253 } |
243 | 254 |
244 // Skip devices that don't use any valuator | 255 // Skip devices that don't use any valuator |
245 if (!valuator_count_[deviceid]) | 256 if (!valuator_count_[deviceid]) |
246 continue; | 257 continue; |
247 | 258 |
248 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); | 259 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); |
249 data_type_lookup_[deviceid].resize(valuator_count_[deviceid], | 260 data_type_lookup_[deviceid].resize( |
250 DT_LAST_ENTRY); | 261 valuator_count_[deviceid], DT_LAST_ENTRY); |
251 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); | 262 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); |
252 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); | 263 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); |
253 for (int j = 0; j < kMaxSlotNum; j++) | 264 for (int j = 0; j < kMaxSlotNum; j++) |
254 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 265 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
255 for (int j = 0; j < info->num_classes; ++j) { | 266 for (int j = 0; j < info.num_classes; ++j) { |
256 if (info->classes[j]->type != XIValuatorClass) | 267 if (info.classes[j]->type != XIValuatorClass) |
257 continue; | 268 continue; |
258 | 269 |
259 XIValuatorClassInfo* v = | 270 XIValuatorClassInfo* v = |
260 reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]); | 271 reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]); |
261 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { | 272 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { |
262 if (v->label == atoms[data_type]) { | 273 if (v->label == atoms[data_type]) { |
263 valuator_lookup_[deviceid][data_type] = v->number; | 274 valuator_lookup_[deviceid][data_type] = v->number; |
264 data_type_lookup_[deviceid][v->number] = data_type; | 275 data_type_lookup_[deviceid][v->number] = data_type; |
265 valuator_min_[deviceid][data_type] = v->min; | 276 valuator_min_[deviceid][data_type] = v->min; |
266 valuator_max_[deviceid][data_type] = v->max; | 277 valuator_max_[deviceid][data_type] = v->max; |
267 if (IsCMTDataType(data_type)) | 278 if (IsCMTDataType(data_type)) |
268 possible_cmt = true; | 279 possible_cmt = true; |
269 break; | 280 break; |
270 } | 281 } |
271 } | 282 } |
272 } | 283 } |
273 | 284 |
274 if (possible_cmt && !not_cmt) | 285 if (possible_cmt && !not_cmt) |
275 cmt_devices_[deviceid] = true; | 286 cmt_devices_[deviceid] = true; |
276 } | 287 } |
277 } | 288 } |
278 | 289 |
279 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { | 290 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { |
280 #if defined(USE_XI2_MT) | |
281 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 291 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
282 if (!factory->IsMultiTouchDevice(xiev->sourceid)) { | 292 if (!factory->IsMultiTouchDevice(xiev->sourceid)) { |
283 *slot = 0; | 293 *slot = 0; |
284 return true; | 294 return true; |
285 } | 295 } |
286 return factory->QuerySlotForTrackingID(xiev->detail, slot); | 296 return factory->QuerySlotForTrackingID(xiev->detail, slot); |
287 #else | |
288 *slot = 0; | |
289 return true; | |
290 #endif | |
291 } | 297 } |
292 | 298 |
293 void DeviceDataManagerX11::GetEventRawData(const XEvent& xev, EventData* data) { | 299 void DeviceDataManagerX11::GetEventRawData(const XEvent& xev, EventData* data) { |
294 if (xev.type != GenericEvent) | 300 if (xev.type != GenericEvent) |
295 return; | 301 return; |
296 | 302 |
297 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | 303 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
| 304 CHECK(xiev->sourceid >= 0); |
| 305 CHECK(xiev->deviceid >= 0); |
298 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | 306 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
299 return; | 307 return; |
300 data->clear(); | 308 data->clear(); |
301 const int sourceid = xiev->sourceid; | 309 const int sourceid = xiev->sourceid; |
302 double* valuators = xiev->valuators.values; | 310 double* valuators = xiev->valuators.values; |
303 for (int i = 0; i <= valuator_count_[sourceid]; ++i) { | 311 for (int i = 0; i <= valuator_count_[sourceid]; ++i) { |
304 if (XIMaskIsSet(xiev->valuators.mask, i)) { | 312 if (XIMaskIsSet(xiev->valuators.mask, i)) { |
305 int type = data_type_lookup_[sourceid][i]; | 313 int type = data_type_lookup_[sourceid][i]; |
306 if (type != DT_LAST_ENTRY) { | 314 if (type != DT_LAST_ENTRY) { |
307 (*data)[type] = *valuators; | 315 (*data)[type] = *valuators; |
308 if (IsTouchDataType(type)) { | 316 if (IsTouchDataType(type)) { |
309 int slot = -1; | 317 int slot = -1; |
310 if (GetSlotNumber(xiev, &slot) && slot >= 0 && slot < kMaxSlotNum) | 318 if (GetSlotNumber(xiev, &slot) && slot >= 0 && slot < kMaxSlotNum) |
311 last_seen_valuator_[sourceid][slot][type] = *valuators; | 319 last_seen_valuator_[sourceid][slot][type] = *valuators; |
312 } | 320 } |
313 } | 321 } |
314 valuators++; | 322 valuators++; |
315 } | 323 } |
316 } | 324 } |
317 } | 325 } |
318 | 326 |
319 bool DeviceDataManagerX11::GetEventData(const XEvent& xev, | 327 bool DeviceDataManagerX11::GetEventData(const XEvent& xev, |
320 const DataType type, | 328 const DataType type, double* value) { |
321 double* value) { | |
322 if (xev.type != GenericEvent) | 329 if (xev.type != GenericEvent) |
323 return false; | 330 return false; |
324 | 331 |
325 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | 332 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
| 333 CHECK(xiev->sourceid >= 0); |
| 334 CHECK(xiev->deviceid >= 0); |
326 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | 335 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
327 return false; | 336 return false; |
328 const int sourceid = xiev->sourceid; | 337 const int sourceid = xiev->sourceid; |
329 if (valuator_lookup_[sourceid].empty()) | 338 if (valuator_lookup_[sourceid].empty()) |
330 return false; | 339 return false; |
331 | 340 |
332 if (type == DT_TOUCH_TRACKING_ID) { | 341 if (type == DT_TOUCH_TRACKING_ID) { |
333 // With XInput2 MT, Tracking ID is provided in the detail field for touch | 342 // With XInput2 MT, Tracking ID is provided in the detail field for touch |
334 // events. | 343 // events. |
335 if (xiev->evtype == XI_TouchBegin || xiev->evtype == XI_TouchEnd || | 344 if (xiev->evtype == XI_TouchBegin || |
| 345 xiev->evtype == XI_TouchEnd || |
336 xiev->evtype == XI_TouchUpdate) { | 346 xiev->evtype == XI_TouchUpdate) { |
337 *value = xiev->detail; | 347 *value = xiev->detail; |
338 } else { | 348 } else { |
339 *value = 0; | 349 *value = 0; |
340 } | 350 } |
341 return true; | 351 return true; |
342 } | 352 } |
343 | 353 |
344 int val_index = valuator_lookup_[sourceid][type]; | 354 int val_index = valuator_lookup_[sourceid][type]; |
345 int slot = 0; | 355 int slot = 0; |
(...skipping 27 matching lines...) Expand all Loading... |
373 return xi_device_event_types_[native_event->xcookie.evtype]; | 383 return xi_device_event_types_[native_event->xcookie.evtype]; |
374 } | 384 } |
375 | 385 |
376 bool DeviceDataManagerX11::IsTouchpadXInputEvent( | 386 bool DeviceDataManagerX11::IsTouchpadXInputEvent( |
377 const base::NativeEvent& native_event) const { | 387 const base::NativeEvent& native_event) const { |
378 if (native_event->type != GenericEvent) | 388 if (native_event->type != GenericEvent) |
379 return false; | 389 return false; |
380 | 390 |
381 XIDeviceEvent* xievent = | 391 XIDeviceEvent* xievent = |
382 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 392 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 393 CHECK(xievent->sourceid >= 0); |
383 if (xievent->sourceid >= kMaxDeviceNum) | 394 if (xievent->sourceid >= kMaxDeviceNum) |
384 return false; | 395 return false; |
385 return touchpads_[xievent->sourceid]; | 396 return touchpads_[xievent->sourceid]; |
386 } | 397 } |
387 | 398 |
388 bool DeviceDataManagerX11::IsCMTDeviceEvent( | 399 bool DeviceDataManagerX11::IsCMTDeviceEvent( |
389 const base::NativeEvent& native_event) const { | 400 const base::NativeEvent& native_event) const { |
390 if (native_event->type != GenericEvent) | 401 if (native_event->type != GenericEvent) |
391 return false; | 402 return false; |
392 | 403 |
393 XIDeviceEvent* xievent = | 404 XIDeviceEvent* xievent = |
394 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 405 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 406 CHECK(xievent->sourceid >= 0); |
395 if (xievent->sourceid >= kMaxDeviceNum) | 407 if (xievent->sourceid >= kMaxDeviceNum) |
396 return false; | 408 return false; |
397 return cmt_devices_[xievent->sourceid]; | 409 return cmt_devices_[xievent->sourceid]; |
398 } | 410 } |
399 | 411 |
400 bool DeviceDataManagerX11::IsCMTGestureEvent( | 412 bool DeviceDataManagerX11::IsCMTGestureEvent( |
401 const base::NativeEvent& native_event) const { | 413 const base::NativeEvent& native_event) const { |
402 return (IsScrollEvent(native_event) || IsFlingEvent(native_event) || | 414 return (IsScrollEvent(native_event) || |
| 415 IsFlingEvent(native_event) || |
403 IsCMTMetricsEvent(native_event)); | 416 IsCMTMetricsEvent(native_event)); |
404 } | 417 } |
405 | 418 |
406 bool DeviceDataManagerX11::HasEventData(const XIDeviceEvent* xiev, | 419 bool DeviceDataManagerX11::HasEventData( |
407 const DataType type) const { | 420 const XIDeviceEvent* xiev, const DataType type) const { |
| 421 CHECK(xiev->sourceid >= 0); |
| 422 if (xiev->sourceid >= kMaxDeviceNum) |
| 423 return false; |
| 424 if (type >= valuator_lookup_[xiev->sourceid].size()) |
| 425 return false; |
408 const int idx = valuator_lookup_[xiev->sourceid][type]; | 426 const int idx = valuator_lookup_[xiev->sourceid][type]; |
409 return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); | 427 return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); |
410 } | 428 } |
411 | 429 |
412 bool DeviceDataManagerX11::IsScrollEvent( | 430 bool DeviceDataManagerX11::IsScrollEvent( |
413 const base::NativeEvent& native_event) const { | 431 const base::NativeEvent& native_event) const { |
414 if (!IsCMTDeviceEvent(native_event)) | 432 if (!IsCMTDeviceEvent(native_event)) |
415 return false; | 433 return false; |
416 | 434 |
417 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 435 XIDeviceEvent* xiev = |
| 436 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
418 return (HasEventData(xiev, DT_CMT_SCROLL_X) || | 437 return (HasEventData(xiev, DT_CMT_SCROLL_X) || |
419 HasEventData(xiev, DT_CMT_SCROLL_Y)); | 438 HasEventData(xiev, DT_CMT_SCROLL_Y)); |
420 } | 439 } |
421 | 440 |
422 bool DeviceDataManagerX11::IsFlingEvent( | 441 bool DeviceDataManagerX11::IsFlingEvent( |
423 const base::NativeEvent& native_event) const { | 442 const base::NativeEvent& native_event) const { |
424 if (!IsCMTDeviceEvent(native_event)) | 443 if (!IsCMTDeviceEvent(native_event)) |
425 return false; | 444 return false; |
426 | 445 |
427 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 446 XIDeviceEvent* xiev = |
| 447 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
428 return (HasEventData(xiev, DT_CMT_FLING_X) && | 448 return (HasEventData(xiev, DT_CMT_FLING_X) && |
429 HasEventData(xiev, DT_CMT_FLING_Y) && | 449 HasEventData(xiev, DT_CMT_FLING_Y) && |
430 HasEventData(xiev, DT_CMT_FLING_STATE)); | 450 HasEventData(xiev, DT_CMT_FLING_STATE)); |
431 } | 451 } |
432 | 452 |
433 bool DeviceDataManagerX11::IsCMTMetricsEvent( | 453 bool DeviceDataManagerX11::IsCMTMetricsEvent( |
434 const base::NativeEvent& native_event) const { | 454 const base::NativeEvent& native_event) const { |
435 if (!IsCMTDeviceEvent(native_event)) | 455 if (!IsCMTDeviceEvent(native_event)) |
436 return false; | 456 return false; |
437 | 457 |
438 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 458 XIDeviceEvent* xiev = |
| 459 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
439 return (HasEventData(xiev, DT_CMT_METRICS_TYPE) && | 460 return (HasEventData(xiev, DT_CMT_METRICS_TYPE) && |
440 HasEventData(xiev, DT_CMT_METRICS_DATA1) && | 461 HasEventData(xiev, DT_CMT_METRICS_DATA1) && |
441 HasEventData(xiev, DT_CMT_METRICS_DATA2)); | 462 HasEventData(xiev, DT_CMT_METRICS_DATA2)); |
442 } | 463 } |
443 | 464 |
444 bool DeviceDataManagerX11::HasGestureTimes( | 465 bool DeviceDataManagerX11::HasGestureTimes( |
445 const base::NativeEvent& native_event) const { | 466 const base::NativeEvent& native_event) const { |
446 if (!IsCMTDeviceEvent(native_event)) | 467 if (!IsCMTDeviceEvent(native_event)) |
447 return false; | 468 return false; |
448 | 469 |
449 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 470 XIDeviceEvent* xiev = |
| 471 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
450 return (HasEventData(xiev, DT_CMT_START_TIME) && | 472 return (HasEventData(xiev, DT_CMT_START_TIME) && |
451 HasEventData(xiev, DT_CMT_END_TIME)); | 473 HasEventData(xiev, DT_CMT_END_TIME)); |
452 } | 474 } |
453 | 475 |
454 void DeviceDataManagerX11::GetScrollOffsets( | 476 void DeviceDataManagerX11::GetScrollOffsets( |
455 const base::NativeEvent& native_event, | 477 const base::NativeEvent& native_event, |
456 float* x_offset, | 478 float* x_offset, |
457 float* y_offset, | 479 float* y_offset, |
458 float* x_offset_ordinal, | 480 float* x_offset_ordinal, |
459 float* y_offset_ordinal, | 481 float* y_offset_ordinal, |
(...skipping 12 matching lines...) Expand all Loading... |
472 if (data.find(DT_CMT_SCROLL_Y) != data.end()) | 494 if (data.find(DT_CMT_SCROLL_Y) != data.end()) |
473 *y_offset = data[DT_CMT_SCROLL_Y]; | 495 *y_offset = data[DT_CMT_SCROLL_Y]; |
474 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 496 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
475 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; | 497 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; |
476 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 498 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
477 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; | 499 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; |
478 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) | 500 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) |
479 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); | 501 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); |
480 } | 502 } |
481 | 503 |
482 void DeviceDataManagerX11::GetFlingData(const base::NativeEvent& native_event, | 504 void DeviceDataManagerX11::GetFlingData( |
483 float* vx, | 505 const base::NativeEvent& native_event, |
484 float* vy, | 506 float* vx, |
485 float* vx_ordinal, | 507 float* vy, |
486 float* vy_ordinal, | 508 float* vx_ordinal, |
487 bool* is_cancel) { | 509 float* vy_ordinal, |
| 510 bool* is_cancel) { |
488 *vx = 0; | 511 *vx = 0; |
489 *vy = 0; | 512 *vy = 0; |
490 *vx_ordinal = 0; | 513 *vx_ordinal = 0; |
491 *vy_ordinal = 0; | 514 *vy_ordinal = 0; |
492 *is_cancel = false; | 515 *is_cancel = false; |
493 | 516 |
494 EventData data; | 517 EventData data; |
495 GetEventRawData(*native_event, &data); | 518 GetEventRawData(*native_event, &data); |
496 | 519 |
497 if (data.find(DT_CMT_FLING_X) != data.end()) | 520 if (data.find(DT_CMT_FLING_X) != data.end()) |
498 *vx = data[DT_CMT_FLING_X]; | 521 *vx = data[DT_CMT_FLING_X]; |
499 if (data.find(DT_CMT_FLING_Y) != data.end()) | 522 if (data.find(DT_CMT_FLING_Y) != data.end()) |
500 *vy = data[DT_CMT_FLING_Y]; | 523 *vy = data[DT_CMT_FLING_Y]; |
501 if (data.find(DT_CMT_FLING_STATE) != data.end()) | 524 if (data.find(DT_CMT_FLING_STATE) != data.end()) |
502 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); | 525 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); |
503 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 526 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
504 *vx_ordinal = data[DT_CMT_ORDINAL_X]; | 527 *vx_ordinal = data[DT_CMT_ORDINAL_X]; |
505 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 528 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
506 *vy_ordinal = data[DT_CMT_ORDINAL_Y]; | 529 *vy_ordinal = data[DT_CMT_ORDINAL_Y]; |
507 } | 530 } |
508 | 531 |
509 void DeviceDataManagerX11::GetMetricsData(const base::NativeEvent& native_event, | 532 void DeviceDataManagerX11::GetMetricsData( |
510 GestureMetricsType* type, | 533 const base::NativeEvent& native_event, |
511 float* data1, | 534 GestureMetricsType* type, |
512 float* data2) { | 535 float* data1, |
| 536 float* data2) { |
513 *type = kGestureMetricsTypeUnknown; | 537 *type = kGestureMetricsTypeUnknown; |
514 *data1 = 0; | 538 *data1 = 0; |
515 *data2 = 0; | 539 *data2 = 0; |
516 | 540 |
517 EventData data; | 541 EventData data; |
518 GetEventRawData(*native_event, &data); | 542 GetEventRawData(*native_event, &data); |
519 | 543 |
520 if (data.find(DT_CMT_METRICS_TYPE) != data.end()) { | 544 if (data.find(DT_CMT_METRICS_TYPE) != data.end()) { |
521 int val = static_cast<int>(data[DT_CMT_METRICS_TYPE]); | 545 int val = static_cast<int>(data[DT_CMT_METRICS_TYPE]); |
522 if (val == 0) | 546 if (val == 0) |
523 *type = kGestureMetricsTypeNoisyGround; | 547 *type = kGestureMetricsTypeNoisyGround; |
524 else | 548 else |
525 *type = kGestureMetricsTypeUnknown; | 549 *type = kGestureMetricsTypeUnknown; |
526 } | 550 } |
527 if (data.find(DT_CMT_METRICS_DATA1) != data.end()) | 551 if (data.find(DT_CMT_METRICS_DATA1) != data.end()) |
528 *data1 = data[DT_CMT_METRICS_DATA1]; | 552 *data1 = data[DT_CMT_METRICS_DATA1]; |
529 if (data.find(DT_CMT_METRICS_DATA2) != data.end()) | 553 if (data.find(DT_CMT_METRICS_DATA2) != data.end()) |
530 *data2 = data[DT_CMT_METRICS_DATA2]; | 554 *data2 = data[DT_CMT_METRICS_DATA2]; |
531 } | 555 } |
532 | 556 |
533 int DeviceDataManagerX11::GetMappedButton(int button) { | 557 int DeviceDataManagerX11::GetMappedButton(int button) { |
534 return button > 0 && button <= button_map_count_ ? button_map_[button - 1] | 558 return button > 0 && button <= button_map_count_ ? button_map_[button - 1] : |
535 : button; | 559 button; |
536 } | 560 } |
537 | 561 |
538 void DeviceDataManagerX11::UpdateButtonMap() { | 562 void DeviceDataManagerX11::UpdateButtonMap() { |
539 button_map_count_ = XGetPointerMapping(gfx::GetXDisplay(), button_map_, | 563 button_map_count_ = XGetPointerMapping(gfx::GetXDisplay(), |
| 564 button_map_, |
540 arraysize(button_map_)); | 565 arraysize(button_map_)); |
541 } | 566 } |
542 | 567 |
543 void DeviceDataManagerX11::GetGestureTimes( | 568 void DeviceDataManagerX11::GetGestureTimes( |
544 const base::NativeEvent& native_event, | 569 const base::NativeEvent& native_event, |
545 double* start_time, | 570 double* start_time, |
546 double* end_time) { | 571 double* end_time) { |
547 *start_time = 0; | 572 *start_time = 0; |
548 *end_time = 0; | 573 *end_time = 0; |
549 | 574 |
550 EventData data; | 575 EventData data; |
551 GetEventRawData(*native_event, &data); | 576 GetEventRawData(*native_event, &data); |
552 | 577 |
553 if (data.find(DT_CMT_START_TIME) != data.end()) | 578 if (data.find(DT_CMT_START_TIME) != data.end()) |
554 *start_time = data[DT_CMT_START_TIME]; | 579 *start_time = data[DT_CMT_START_TIME]; |
555 if (data.find(DT_CMT_END_TIME) != data.end()) | 580 if (data.find(DT_CMT_END_TIME) != data.end()) |
556 *end_time = data[DT_CMT_END_TIME]; | 581 *end_time = data[DT_CMT_END_TIME]; |
557 } | 582 } |
558 | 583 |
559 bool DeviceDataManagerX11::NormalizeData(unsigned int deviceid, | 584 bool DeviceDataManagerX11::NormalizeData(int deviceid, |
560 const DataType type, | 585 const DataType type, |
561 double* value) { | 586 double* value) { |
562 double max_value; | 587 double max_value; |
563 double min_value; | 588 double min_value; |
564 if (GetDataRange(deviceid, type, &min_value, &max_value)) { | 589 if (GetDataRange(deviceid, type, &min_value, &max_value)) { |
565 *value = (*value - min_value) / (max_value - min_value); | 590 *value = (*value - min_value) / (max_value - min_value); |
566 DCHECK(*value >= 0.0 && *value <= 1.0); | 591 DCHECK(*value >= 0.0 && *value <= 1.0); |
567 return true; | 592 return true; |
568 } | 593 } |
569 return false; | 594 return false; |
570 } | 595 } |
571 | 596 |
572 bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, | 597 bool DeviceDataManagerX11::GetDataRange(int deviceid, |
573 const DataType type, | 598 const DataType type, |
574 double* min, | 599 double* min, |
575 double* max) { | 600 double* max) { |
576 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) | 601 CHECK(deviceid >= 0); |
| 602 if (deviceid >= kMaxDeviceNum) |
577 return false; | 603 return false; |
578 if (valuator_lookup_[deviceid][type] >= 0) { | 604 if (valuator_lookup_[deviceid][type] >= 0) { |
579 *min = valuator_min_[deviceid][type]; | 605 *min = valuator_min_[deviceid][type]; |
580 *max = valuator_max_[deviceid][type]; | 606 *max = valuator_max_[deviceid][type]; |
581 return true; | 607 return true; |
582 } | 608 } |
583 return false; | 609 return false; |
584 } | 610 } |
585 | 611 |
586 void DeviceDataManagerX11::SetDeviceListForTest( | 612 void DeviceDataManagerX11::SetDeviceListForTest( |
587 const std::vector<unsigned int>& touchscreen, | 613 const std::vector<int>& touchscreen, |
588 const std::vector<unsigned int>& cmt_devices) { | 614 const std::vector<int>& cmt_devices, |
| 615 const std::vector<int>& other_devices) { |
589 for (int i = 0; i < kMaxDeviceNum; ++i) { | 616 for (int i = 0; i < kMaxDeviceNum; ++i) { |
590 valuator_count_[i] = 0; | 617 valuator_count_[i] = 0; |
591 valuator_lookup_[i].clear(); | 618 valuator_lookup_[i].clear(); |
592 data_type_lookup_[i].clear(); | 619 data_type_lookup_[i].clear(); |
593 valuator_min_[i].clear(); | 620 valuator_min_[i].clear(); |
594 valuator_max_[i].clear(); | 621 valuator_max_[i].clear(); |
595 for (int j = 0; j < kMaxSlotNum; j++) | 622 for (int j = 0; j < kMaxSlotNum; j++) |
596 last_seen_valuator_[i][j].clear(); | 623 last_seen_valuator_[i][j].clear(); |
597 } | 624 } |
598 | 625 |
599 for (size_t i = 0; i < touchscreen.size(); i++) { | 626 for (int deviceid : touchscreen) { |
600 unsigned int deviceid = touchscreen[i]; | |
601 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, | 627 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, |
602 0, 1000); | 628 0, 1000); |
603 } | 629 } |
604 | 630 |
605 cmt_devices_.reset(); | 631 cmt_devices_.reset(); |
606 for (size_t i = 0; i < cmt_devices.size(); ++i) { | 632 for (int deviceid : cmt_devices) { |
607 unsigned int deviceid = cmt_devices[i]; | |
608 cmt_devices_[deviceid] = true; | 633 cmt_devices_[deviceid] = true; |
609 touchpads_[deviceid] = true; | 634 touchpads_[deviceid] = true; |
610 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, | 635 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, |
611 -1000, 1000); | 636 -1000, 1000); |
612 } | 637 } |
| 638 |
| 639 for (int deviceid : other_devices) { |
| 640 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, |
| 641 -1000, 1000); |
| 642 } |
613 } | 643 } |
614 | 644 |
615 void DeviceDataManagerX11::SetValuatorDataForTest(XIDeviceEvent* xievent, | 645 void DeviceDataManagerX11::SetValuatorDataForTest(XIDeviceEvent* xievent, |
616 DataType type, | 646 DataType type, |
617 double value) { | 647 double value) { |
618 int index = valuator_lookup_[xievent->deviceid][type]; | 648 int index = valuator_lookup_[xievent->deviceid][type]; |
619 CHECK(!XIMaskIsSet(xievent->valuators.mask, index)); | 649 CHECK(!XIMaskIsSet(xievent->valuators.mask, index)); |
620 CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]); | 650 CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]); |
621 XISetMask(xievent->valuators.mask, index); | 651 XISetMask(xievent->valuators.mask, index); |
622 | 652 |
(...skipping 22 matching lines...) Expand all Loading... |
645 for (int j = start_valuator; j <= end_valuator; ++j) { | 675 for (int j = start_valuator; j <= end_valuator; ++j) { |
646 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 676 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
647 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 677 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
648 valuator_min_[deviceid][j] = min_value; | 678 valuator_min_[deviceid][j] = min_value; |
649 valuator_max_[deviceid][j] = max_value; | 679 valuator_max_[deviceid][j] = max_value; |
650 valuator_count_[deviceid]++; | 680 valuator_count_[deviceid]++; |
651 } | 681 } |
652 } | 682 } |
653 | 683 |
654 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { | 684 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { |
655 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 685 #if defined(OS_CHROMEOS) |
656 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); | 686 if (!base::SysInfo::IsRunningOnChromeOS()) |
657 if (base::SysInfo::IsRunningOnChromeOS() && | 687 return false; |
658 touch_display_id == gfx::Display::InternalDisplayId()) { | 688 |
659 return true; | 689 const std::vector<TouchscreenDevice>& touch_devices = |
660 } | 690 ui::DeviceDataManager::GetInstance()->touchscreen_devices(); |
661 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 691 std::vector<TouchscreenDevice>::const_iterator it = |
| 692 std::find_if(touch_devices.begin(), touch_devices.end(), |
| 693 std::bind2nd(std::ptr_fun(&DeviceHasId), touch_device_id)); |
| 694 return it != touch_devices.end() && it->type == INPUT_DEVICE_INTERNAL; |
| 695 #endif // defined(OS_CHROMEOS) |
662 return false; | 696 return false; |
663 } | 697 } |
664 | 698 |
665 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( | 699 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
666 scoped_ptr<std::set<KeyboardCode>> excepted_keys) { | 700 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { |
667 DCHECK(!excepted_keys.get() || !blocked_keyboard_allowed_keys_.get()); | 701 DCHECK(!excepted_keys.get() || |
| 702 !blocked_keyboard_allowed_keys_.get()); |
668 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); | 703 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); |
669 } | 704 } |
670 | 705 |
671 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { | 706 void DeviceDataManagerX11::DisableDevice(int deviceid) { |
672 blocked_devices_.set(deviceid, true); | 707 blocked_devices_.set(deviceid, true); |
| 708 // TODO(rsadam@): Support blocking touchscreen devices. |
| 709 std::vector<KeyboardDevice> keyboards = keyboard_devices(); |
| 710 std::vector<KeyboardDevice>::iterator it = |
| 711 std::find_if(keyboards.begin(), |
| 712 keyboards.end(), |
| 713 std::bind2nd(std::ptr_fun(&DeviceHasId), deviceid)); |
| 714 if (it != std::end(keyboards)) { |
| 715 blocked_keyboards_.insert( |
| 716 std::pair<int, KeyboardDevice>(deviceid, *it)); |
| 717 keyboards.erase(it); |
| 718 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 719 } |
673 } | 720 } |
674 | 721 |
675 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { | 722 void DeviceDataManagerX11::EnableDevice(int deviceid) { |
676 blocked_devices_.set(deviceid, false); | 723 blocked_devices_.set(deviceid, false); |
| 724 std::map<int, KeyboardDevice>::iterator it = |
| 725 blocked_keyboards_.find(deviceid); |
| 726 if (it != blocked_keyboards_.end()) { |
| 727 std::vector<KeyboardDevice> devices = keyboard_devices(); |
| 728 // Add device to current list of active devices. |
| 729 devices.push_back((*it).second); |
| 730 blocked_keyboards_.erase(it); |
| 731 DeviceDataManager::OnKeyboardDevicesUpdated(devices); |
| 732 } |
677 } | 733 } |
678 | 734 |
679 bool DeviceDataManagerX11::IsEventBlocked( | 735 bool DeviceDataManagerX11::IsEventBlocked( |
680 const base::NativeEvent& native_event) { | 736 const base::NativeEvent& native_event) { |
681 // Only check XI2 events which have a source device id. | 737 // Only check XI2 events which have a source device id. |
682 if (native_event->type != GenericEvent) | 738 if (native_event->type != GenericEvent) |
683 return false; | 739 return false; |
684 | 740 |
685 XIDeviceEvent* xievent = | 741 XIDeviceEvent* xievent = |
686 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 742 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
687 // Allow any key events from blocked_keyboard_allowed_keys_. | 743 // Allow any key events from blocked_keyboard_allowed_keys_. |
688 if (blocked_keyboard_allowed_keys_ && | 744 if (blocked_keyboard_allowed_keys_ && |
689 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && | 745 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
690 blocked_keyboard_allowed_keys_->find(KeyboardCodeFromXKeyEvent( | 746 blocked_keyboard_allowed_keys_->find( |
691 native_event)) != blocked_keyboard_allowed_keys_->end()) { | 747 KeyboardCodeFromXKeyEvent(native_event)) != |
| 748 blocked_keyboard_allowed_keys_->end()) { |
692 return false; | 749 return false; |
693 } | 750 } |
694 | 751 |
695 return blocked_devices_.test(xievent->sourceid); | 752 return blocked_devices_.test(xievent->sourceid); |
696 } | 753 } |
697 | 754 |
| 755 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
| 756 const std::vector<KeyboardDevice>& devices) { |
| 757 std::vector<KeyboardDevice> keyboards(devices); |
| 758 for (std::map<int, KeyboardDevice>::iterator blocked_iter = |
| 759 blocked_keyboards_.begin(); |
| 760 blocked_iter != blocked_keyboards_.end();) { |
| 761 // Check if the blocked device still exists in list of devices. |
| 762 std::vector<KeyboardDevice>::iterator it = std::find_if( |
| 763 keyboards.begin(), keyboards.end(), |
| 764 std::bind2nd(std::ptr_fun(&DeviceHasId), (*blocked_iter).first)); |
| 765 // If the device no longer exists, unblock it, else filter it out from our |
| 766 // active list. |
| 767 if (it == keyboards.end()) { |
| 768 blocked_devices_.set((*blocked_iter).first, false); |
| 769 blocked_keyboards_.erase(blocked_iter++); |
| 770 } else { |
| 771 keyboards.erase(it); |
| 772 ++blocked_iter; |
| 773 } |
| 774 } |
| 775 // Notify base class of updated list. |
| 776 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 777 } |
| 778 |
698 } // namespace ui | 779 } // namespace ui |
OLD | NEW |