OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/x/device_data_manager.h" | 5 #include "ui/events/x/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 "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
15 #include "ui/events/event_switches.h" | 15 #include "ui/events/event_switches.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 AXIS_LABEL_ABS_MT_ORIENTATION, | 87 AXIS_LABEL_ABS_MT_ORIENTATION, |
88 AXIS_LABEL_ABS_MT_PRESSURE, | 88 AXIS_LABEL_ABS_MT_PRESSURE, |
89 AXIS_LABEL_ABS_MT_TRACKING_ID, | 89 AXIS_LABEL_ABS_MT_TRACKING_ID, |
90 AXIS_LABEL_TOUCH_TIMESTAMP, | 90 AXIS_LABEL_TOUCH_TIMESTAMP, |
91 | 91 |
92 NULL | 92 NULL |
93 }; | 93 }; |
94 | 94 |
95 // Constants for checking if a data type lies in the range of CMT/Touch data | 95 // Constants for checking if a data type lies in the range of CMT/Touch data |
96 // types. | 96 // types. |
97 const int kCMTDataTypeStart = ui::DeviceDataManager::DT_CMT_SCROLL_X; | 97 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; |
98 const int kCMTDataTypeEnd = ui::DeviceDataManager::DT_CMT_FINGER_COUNT; | 98 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; |
99 const int kTouchDataTypeStart = ui::DeviceDataManager::DT_TOUCH_MAJOR; | 99 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; |
100 const int kTouchDataTypeEnd = ui::DeviceDataManager::DT_TOUCH_RAW_TIMESTAMP; | 100 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; |
101 | 101 |
102 namespace ui { | 102 namespace ui { |
103 | 103 |
104 bool DeviceDataManager::IsCMTDataType(const int type) { | 104 bool DeviceDataManagerX11::IsCMTDataType(const int type) { |
105 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); | 105 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); |
106 } | 106 } |
107 | 107 |
108 bool DeviceDataManager::IsTouchDataType(const int type) { | 108 bool DeviceDataManagerX11::IsTouchDataType(const int type) { |
109 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); | 109 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); |
110 } | 110 } |
111 | 111 |
112 DeviceDataManager* DeviceDataManager::GetInstance() { | 112 // static |
113 return Singleton<DeviceDataManager>::get(); | 113 DeviceDataManagerX11* DeviceDataManagerX11::GetInstance() { |
| 114 return static_cast<DeviceDataManagerX11*>(DeviceDataManager::GetInstance()); |
114 } | 115 } |
115 | 116 |
116 DeviceDataManager::DeviceDataManager() | 117 DeviceDataManagerX11::DeviceDataManagerX11() |
117 : xi_opcode_(-1), | 118 : xi_opcode_(-1), |
118 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), | 119 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), |
119 button_map_count_(0) { | 120 button_map_count_(0) { |
120 CHECK(gfx::GetXDisplay()); | 121 CHECK(gfx::GetXDisplay()); |
121 InitializeXInputInternal(); | 122 InitializeXInputInternal(); |
122 | 123 |
123 // Make sure the sizes of enum and kCachedAtoms are aligned. | 124 // Make sure the sizes of enum and kCachedAtoms are aligned. |
124 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); | 125 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); |
125 UpdateDeviceList(gfx::GetXDisplay()); | 126 UpdateDeviceList(gfx::GetXDisplay()); |
126 UpdateButtonMap(); | 127 UpdateButtonMap(); |
127 for (int i = 0; i < kMaxDeviceNum; i++) | |
128 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | |
129 } | 128 } |
130 | 129 |
131 DeviceDataManager::~DeviceDataManager() { | 130 DeviceDataManagerX11::~DeviceDataManagerX11() { |
132 } | 131 } |
133 | 132 |
134 bool DeviceDataManager::InitializeXInputInternal() { | 133 bool DeviceDataManagerX11::InitializeXInputInternal() { |
135 // Check if XInput is available on the system. | 134 // Check if XInput is available on the system. |
136 xi_opcode_ = -1; | 135 xi_opcode_ = -1; |
137 int opcode, event, error; | 136 int opcode, event, error; |
138 if (!XQueryExtension( | 137 if (!XQueryExtension( |
139 gfx::GetXDisplay(), "XInputExtension", &opcode, &event, &error)) { | 138 gfx::GetXDisplay(), "XInputExtension", &opcode, &event, &error)) { |
140 VLOG(1) << "X Input extension not available: error=" << error; | 139 VLOG(1) << "X Input extension not available: error=" << error; |
141 return false; | 140 return false; |
142 } | 141 } |
143 | 142 |
144 // Check the XInput version. | 143 // Check the XInput version. |
(...skipping 26 matching lines...) Expand all Loading... |
171 xi_device_event_types_[XI_Motion] = true; | 170 xi_device_event_types_[XI_Motion] = true; |
172 // Multi-touch support was introduced in XI 2.2. | 171 // Multi-touch support was introduced in XI 2.2. |
173 if (minor >= 2) { | 172 if (minor >= 2) { |
174 xi_device_event_types_[XI_TouchBegin] = true; | 173 xi_device_event_types_[XI_TouchBegin] = true; |
175 xi_device_event_types_[XI_TouchUpdate] = true; | 174 xi_device_event_types_[XI_TouchUpdate] = true; |
176 xi_device_event_types_[XI_TouchEnd] = true; | 175 xi_device_event_types_[XI_TouchEnd] = true; |
177 } | 176 } |
178 return true; | 177 return true; |
179 } | 178 } |
180 | 179 |
181 bool DeviceDataManager::IsXInput2Available() const { | 180 bool DeviceDataManagerX11::IsXInput2Available() const { |
182 return xi_opcode_ != -1; | 181 return xi_opcode_ != -1; |
183 } | 182 } |
184 | 183 |
185 void DeviceDataManager::UpdateDeviceList(Display* display) { | 184 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
186 cmt_devices_.reset(); | 185 cmt_devices_.reset(); |
187 touchpads_.reset(); | 186 touchpads_.reset(); |
188 for (int i = 0; i < kMaxDeviceNum; ++i) { | 187 for (int i = 0; i < kMaxDeviceNum; ++i) { |
189 valuator_count_[i] = 0; | 188 valuator_count_[i] = 0; |
190 valuator_lookup_[i].clear(); | 189 valuator_lookup_[i].clear(); |
191 data_type_lookup_[i].clear(); | 190 data_type_lookup_[i].clear(); |
192 valuator_min_[i].clear(); | 191 valuator_min_[i].clear(); |
193 valuator_max_[i].clear(); | 192 valuator_max_[i].clear(); |
194 for (int j = 0; j < kMaxSlotNum; j++) | 193 for (int j = 0; j < kMaxSlotNum; j++) |
195 last_seen_valuator_[i][j].clear(); | 194 last_seen_valuator_[i][j].clear(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 break; | 258 break; |
260 } | 259 } |
261 } | 260 } |
262 } | 261 } |
263 | 262 |
264 if (possible_cmt && !not_cmt) | 263 if (possible_cmt && !not_cmt) |
265 cmt_devices_[deviceid] = true; | 264 cmt_devices_[deviceid] = true; |
266 } | 265 } |
267 } | 266 } |
268 | 267 |
269 bool DeviceDataManager::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { | 268 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { |
270 #if defined(USE_XI2_MT) | 269 #if defined(USE_XI2_MT) |
271 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 270 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
272 if (!factory->IsMultiTouchDevice(xiev->sourceid)) { | 271 if (!factory->IsMultiTouchDevice(xiev->sourceid)) { |
273 *slot = 0; | 272 *slot = 0; |
274 return true; | 273 return true; |
275 } | 274 } |
276 return factory->QuerySlotForTrackingID(xiev->detail, slot); | 275 return factory->QuerySlotForTrackingID(xiev->detail, slot); |
277 #else | 276 #else |
278 *slot = 0; | 277 *slot = 0; |
279 return true; | 278 return true; |
280 #endif | 279 #endif |
281 } | 280 } |
282 | 281 |
283 void DeviceDataManager::GetEventRawData(const XEvent& xev, EventData* data) { | 282 void DeviceDataManagerX11::GetEventRawData(const XEvent& xev, EventData* data) { |
284 if (xev.type != GenericEvent) | 283 if (xev.type != GenericEvent) |
285 return; | 284 return; |
286 | 285 |
287 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | 286 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
288 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | 287 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
289 return; | 288 return; |
290 data->clear(); | 289 data->clear(); |
291 const int sourceid = xiev->sourceid; | 290 const int sourceid = xiev->sourceid; |
292 double* valuators = xiev->valuators.values; | 291 double* valuators = xiev->valuators.values; |
293 for (int i = 0; i <= valuator_count_[sourceid]; ++i) { | 292 for (int i = 0; i <= valuator_count_[sourceid]; ++i) { |
294 if (XIMaskIsSet(xiev->valuators.mask, i)) { | 293 if (XIMaskIsSet(xiev->valuators.mask, i)) { |
295 int type = data_type_lookup_[sourceid][i]; | 294 int type = data_type_lookup_[sourceid][i]; |
296 if (type != DT_LAST_ENTRY) { | 295 if (type != DT_LAST_ENTRY) { |
297 (*data)[type] = *valuators; | 296 (*data)[type] = *valuators; |
298 if (IsTouchDataType(type)) { | 297 if (IsTouchDataType(type)) { |
299 int slot = -1; | 298 int slot = -1; |
300 if (GetSlotNumber(xiev, &slot) && slot >= 0 && slot < kMaxSlotNum) | 299 if (GetSlotNumber(xiev, &slot) && slot >= 0 && slot < kMaxSlotNum) |
301 last_seen_valuator_[sourceid][slot][type] = *valuators; | 300 last_seen_valuator_[sourceid][slot][type] = *valuators; |
302 } | 301 } |
303 } | 302 } |
304 valuators++; | 303 valuators++; |
305 } | 304 } |
306 } | 305 } |
307 } | 306 } |
308 | 307 |
309 bool DeviceDataManager::GetEventData(const XEvent& xev, | 308 bool DeviceDataManagerX11::GetEventData(const XEvent& xev, |
310 const DataType type, double* value) { | 309 const DataType type, double* value) { |
311 if (xev.type != GenericEvent) | 310 if (xev.type != GenericEvent) |
312 return false; | 311 return false; |
313 | 312 |
314 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | 313 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
315 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | 314 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
316 return false; | 315 return false; |
317 const int sourceid = xiev->sourceid; | 316 const int sourceid = xiev->sourceid; |
318 if (valuator_lookup_[sourceid].empty()) | 317 if (valuator_lookup_[sourceid].empty()) |
319 return false; | 318 return false; |
(...skipping 28 matching lines...) Expand all Loading... |
348 return true; | 347 return true; |
349 } else if (IsTouchDataType(type)) { | 348 } else if (IsTouchDataType(type)) { |
350 if (GetSlotNumber(xiev, &slot) && slot >= 0 && slot < kMaxSlotNum) | 349 if (GetSlotNumber(xiev, &slot) && slot >= 0 && slot < kMaxSlotNum) |
351 *value = last_seen_valuator_[sourceid][slot][type]; | 350 *value = last_seen_valuator_[sourceid][slot][type]; |
352 } | 351 } |
353 } | 352 } |
354 | 353 |
355 return false; | 354 return false; |
356 } | 355 } |
357 | 356 |
358 bool DeviceDataManager::IsXIDeviceEvent( | 357 bool DeviceDataManagerX11::IsXIDeviceEvent( |
359 const base::NativeEvent& native_event) const { | 358 const base::NativeEvent& native_event) const { |
360 if (native_event->type != GenericEvent || | 359 if (native_event->type != GenericEvent || |
361 native_event->xcookie.extension != xi_opcode_) | 360 native_event->xcookie.extension != xi_opcode_) |
362 return false; | 361 return false; |
363 return xi_device_event_types_[native_event->xcookie.evtype]; | 362 return xi_device_event_types_[native_event->xcookie.evtype]; |
364 } | 363 } |
365 | 364 |
366 bool DeviceDataManager::IsTouchpadXInputEvent( | 365 bool DeviceDataManagerX11::IsTouchpadXInputEvent( |
367 const base::NativeEvent& native_event) const { | 366 const base::NativeEvent& native_event) const { |
368 if (native_event->type != GenericEvent) | 367 if (native_event->type != GenericEvent) |
369 return false; | 368 return false; |
370 | 369 |
371 XIDeviceEvent* xievent = | 370 XIDeviceEvent* xievent = |
372 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 371 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
373 if (xievent->sourceid >= kMaxDeviceNum) | 372 if (xievent->sourceid >= kMaxDeviceNum) |
374 return false; | 373 return false; |
375 return touchpads_[xievent->sourceid]; | 374 return touchpads_[xievent->sourceid]; |
376 } | 375 } |
377 | 376 |
378 bool DeviceDataManager::IsCMTDeviceEvent( | 377 bool DeviceDataManagerX11::IsCMTDeviceEvent( |
379 const base::NativeEvent& native_event) const { | 378 const base::NativeEvent& native_event) const { |
380 if (native_event->type != GenericEvent) | 379 if (native_event->type != GenericEvent) |
381 return false; | 380 return false; |
382 | 381 |
383 XIDeviceEvent* xievent = | 382 XIDeviceEvent* xievent = |
384 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 383 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
385 if (xievent->sourceid >= kMaxDeviceNum) | 384 if (xievent->sourceid >= kMaxDeviceNum) |
386 return false; | 385 return false; |
387 return cmt_devices_[xievent->sourceid]; | 386 return cmt_devices_[xievent->sourceid]; |
388 } | 387 } |
389 | 388 |
390 bool DeviceDataManager::IsCMTGestureEvent( | 389 bool DeviceDataManagerX11::IsCMTGestureEvent( |
391 const base::NativeEvent& native_event) const { | 390 const base::NativeEvent& native_event) const { |
392 return (IsScrollEvent(native_event) || | 391 return (IsScrollEvent(native_event) || |
393 IsFlingEvent(native_event) || | 392 IsFlingEvent(native_event) || |
394 IsCMTMetricsEvent(native_event)); | 393 IsCMTMetricsEvent(native_event)); |
395 } | 394 } |
396 | 395 |
397 bool DeviceDataManager::HasEventData( | 396 bool DeviceDataManagerX11::HasEventData( |
398 const XIDeviceEvent* xiev, const DataType type) const { | 397 const XIDeviceEvent* xiev, const DataType type) const { |
399 const int idx = valuator_lookup_[xiev->sourceid][type]; | 398 const int idx = valuator_lookup_[xiev->sourceid][type]; |
400 return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); | 399 return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); |
401 } | 400 } |
402 | 401 |
403 bool DeviceDataManager::IsScrollEvent( | 402 bool DeviceDataManagerX11::IsScrollEvent( |
404 const base::NativeEvent& native_event) const { | 403 const base::NativeEvent& native_event) const { |
405 if (!IsCMTDeviceEvent(native_event)) | 404 if (!IsCMTDeviceEvent(native_event)) |
406 return false; | 405 return false; |
407 | 406 |
408 XIDeviceEvent* xiev = | 407 XIDeviceEvent* xiev = |
409 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 408 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
410 return (HasEventData(xiev, DT_CMT_SCROLL_X) || | 409 return (HasEventData(xiev, DT_CMT_SCROLL_X) || |
411 HasEventData(xiev, DT_CMT_SCROLL_Y)); | 410 HasEventData(xiev, DT_CMT_SCROLL_Y)); |
412 } | 411 } |
413 | 412 |
414 bool DeviceDataManager::IsFlingEvent( | 413 bool DeviceDataManagerX11::IsFlingEvent( |
415 const base::NativeEvent& native_event) const { | 414 const base::NativeEvent& native_event) const { |
416 if (!IsCMTDeviceEvent(native_event)) | 415 if (!IsCMTDeviceEvent(native_event)) |
417 return false; | 416 return false; |
418 | 417 |
419 XIDeviceEvent* xiev = | 418 XIDeviceEvent* xiev = |
420 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 419 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
421 return (HasEventData(xiev, DT_CMT_FLING_X) && | 420 return (HasEventData(xiev, DT_CMT_FLING_X) && |
422 HasEventData(xiev, DT_CMT_FLING_Y) && | 421 HasEventData(xiev, DT_CMT_FLING_Y) && |
423 HasEventData(xiev, DT_CMT_FLING_STATE)); | 422 HasEventData(xiev, DT_CMT_FLING_STATE)); |
424 } | 423 } |
425 | 424 |
426 bool DeviceDataManager::IsCMTMetricsEvent( | 425 bool DeviceDataManagerX11::IsCMTMetricsEvent( |
427 const base::NativeEvent& native_event) const { | 426 const base::NativeEvent& native_event) const { |
428 if (!IsCMTDeviceEvent(native_event)) | 427 if (!IsCMTDeviceEvent(native_event)) |
429 return false; | 428 return false; |
430 | 429 |
431 XIDeviceEvent* xiev = | 430 XIDeviceEvent* xiev = |
432 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 431 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
433 return (HasEventData(xiev, DT_CMT_METRICS_TYPE) && | 432 return (HasEventData(xiev, DT_CMT_METRICS_TYPE) && |
434 HasEventData(xiev, DT_CMT_METRICS_DATA1) && | 433 HasEventData(xiev, DT_CMT_METRICS_DATA1) && |
435 HasEventData(xiev, DT_CMT_METRICS_DATA2)); | 434 HasEventData(xiev, DT_CMT_METRICS_DATA2)); |
436 } | 435 } |
437 | 436 |
438 bool DeviceDataManager::HasGestureTimes( | 437 bool DeviceDataManagerX11::HasGestureTimes( |
439 const base::NativeEvent& native_event) const { | 438 const base::NativeEvent& native_event) const { |
440 if (!IsCMTDeviceEvent(native_event)) | 439 if (!IsCMTDeviceEvent(native_event)) |
441 return false; | 440 return false; |
442 | 441 |
443 XIDeviceEvent* xiev = | 442 XIDeviceEvent* xiev = |
444 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 443 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
445 return (HasEventData(xiev, DT_CMT_START_TIME) && | 444 return (HasEventData(xiev, DT_CMT_START_TIME) && |
446 HasEventData(xiev, DT_CMT_END_TIME)); | 445 HasEventData(xiev, DT_CMT_END_TIME)); |
447 } | 446 } |
448 | 447 |
449 void DeviceDataManager::GetScrollOffsets(const base::NativeEvent& native_event, | 448 void DeviceDataManagerX11::GetScrollOffsets( |
450 float* x_offset, float* y_offset, | 449 const base::NativeEvent& native_event, |
451 float* x_offset_ordinal, | 450 float* x_offset, |
452 float* y_offset_ordinal, | 451 float* y_offset, |
453 int* finger_count) { | 452 float* x_offset_ordinal, |
| 453 float* y_offset_ordinal, |
| 454 int* finger_count) { |
454 *x_offset = 0; | 455 *x_offset = 0; |
455 *y_offset = 0; | 456 *y_offset = 0; |
456 *x_offset_ordinal = 0; | 457 *x_offset_ordinal = 0; |
457 *y_offset_ordinal = 0; | 458 *y_offset_ordinal = 0; |
458 *finger_count = 2; | 459 *finger_count = 2; |
459 | 460 |
460 EventData data; | 461 EventData data; |
461 GetEventRawData(*native_event, &data); | 462 GetEventRawData(*native_event, &data); |
462 | 463 |
463 if (data.find(DT_CMT_SCROLL_X) != data.end()) | 464 if (data.find(DT_CMT_SCROLL_X) != data.end()) |
464 *x_offset = data[DT_CMT_SCROLL_X]; | 465 *x_offset = data[DT_CMT_SCROLL_X]; |
465 if (data.find(DT_CMT_SCROLL_Y) != data.end()) | 466 if (data.find(DT_CMT_SCROLL_Y) != data.end()) |
466 *y_offset = data[DT_CMT_SCROLL_Y]; | 467 *y_offset = data[DT_CMT_SCROLL_Y]; |
467 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 468 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
468 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; | 469 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; |
469 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 470 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
470 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; | 471 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; |
471 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) | 472 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) |
472 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); | 473 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); |
473 } | 474 } |
474 | 475 |
475 void DeviceDataManager::GetFlingData(const base::NativeEvent& native_event, | 476 void DeviceDataManagerX11::GetFlingData( |
476 float* vx, float* vy, | 477 const base::NativeEvent& native_event, |
477 float* vx_ordinal, float* vy_ordinal, | 478 float* vx, |
478 bool* is_cancel) { | 479 float* vy, |
| 480 float* vx_ordinal, |
| 481 float* vy_ordinal, |
| 482 bool* is_cancel) { |
479 *vx = 0; | 483 *vx = 0; |
480 *vy = 0; | 484 *vy = 0; |
481 *vx_ordinal = 0; | 485 *vx_ordinal = 0; |
482 *vy_ordinal = 0; | 486 *vy_ordinal = 0; |
483 *is_cancel = false; | 487 *is_cancel = false; |
484 | 488 |
485 EventData data; | 489 EventData data; |
486 GetEventRawData(*native_event, &data); | 490 GetEventRawData(*native_event, &data); |
487 | 491 |
488 if (data.find(DT_CMT_FLING_X) != data.end()) | 492 if (data.find(DT_CMT_FLING_X) != data.end()) |
489 *vx = data[DT_CMT_FLING_X]; | 493 *vx = data[DT_CMT_FLING_X]; |
490 if (data.find(DT_CMT_FLING_Y) != data.end()) | 494 if (data.find(DT_CMT_FLING_Y) != data.end()) |
491 *vy = data[DT_CMT_FLING_Y]; | 495 *vy = data[DT_CMT_FLING_Y]; |
492 if (data.find(DT_CMT_FLING_STATE) != data.end()) | 496 if (data.find(DT_CMT_FLING_STATE) != data.end()) |
493 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); | 497 *is_cancel = !!static_cast<unsigned int>(data[DT_CMT_FLING_STATE]); |
494 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 498 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
495 *vx_ordinal = data[DT_CMT_ORDINAL_X]; | 499 *vx_ordinal = data[DT_CMT_ORDINAL_X]; |
496 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 500 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
497 *vy_ordinal = data[DT_CMT_ORDINAL_Y]; | 501 *vy_ordinal = data[DT_CMT_ORDINAL_Y]; |
498 } | 502 } |
499 | 503 |
500 void DeviceDataManager::GetMetricsData(const base::NativeEvent& native_event, | 504 void DeviceDataManagerX11::GetMetricsData( |
501 GestureMetricsType* type, | 505 const base::NativeEvent& native_event, |
502 float* data1, float* data2) { | 506 GestureMetricsType* type, |
| 507 float* data1, |
| 508 float* data2) { |
503 *type = kGestureMetricsTypeUnknown; | 509 *type = kGestureMetricsTypeUnknown; |
504 *data1 = 0; | 510 *data1 = 0; |
505 *data2 = 0; | 511 *data2 = 0; |
506 | 512 |
507 EventData data; | 513 EventData data; |
508 GetEventRawData(*native_event, &data); | 514 GetEventRawData(*native_event, &data); |
509 | 515 |
510 if (data.find(DT_CMT_METRICS_TYPE) != data.end()) { | 516 if (data.find(DT_CMT_METRICS_TYPE) != data.end()) { |
511 int val = static_cast<int>(data[DT_CMT_METRICS_TYPE]); | 517 int val = static_cast<int>(data[DT_CMT_METRICS_TYPE]); |
512 if (val == 0) | 518 if (val == 0) |
513 *type = kGestureMetricsTypeNoisyGround; | 519 *type = kGestureMetricsTypeNoisyGround; |
514 else | 520 else |
515 *type = kGestureMetricsTypeUnknown; | 521 *type = kGestureMetricsTypeUnknown; |
516 } | 522 } |
517 if (data.find(DT_CMT_METRICS_DATA1) != data.end()) | 523 if (data.find(DT_CMT_METRICS_DATA1) != data.end()) |
518 *data1 = data[DT_CMT_METRICS_DATA1]; | 524 *data1 = data[DT_CMT_METRICS_DATA1]; |
519 if (data.find(DT_CMT_METRICS_DATA2) != data.end()) | 525 if (data.find(DT_CMT_METRICS_DATA2) != data.end()) |
520 *data2 = data[DT_CMT_METRICS_DATA2]; | 526 *data2 = data[DT_CMT_METRICS_DATA2]; |
521 } | 527 } |
522 | 528 |
523 int DeviceDataManager::GetMappedButton(int button) { | 529 int DeviceDataManagerX11::GetMappedButton(int button) { |
524 return button > 0 && button <= button_map_count_ ? button_map_[button - 1] : | 530 return button > 0 && button <= button_map_count_ ? button_map_[button - 1] : |
525 button; | 531 button; |
526 } | 532 } |
527 | 533 |
528 void DeviceDataManager::UpdateButtonMap() { | 534 void DeviceDataManagerX11::UpdateButtonMap() { |
529 button_map_count_ = XGetPointerMapping(gfx::GetXDisplay(), | 535 button_map_count_ = XGetPointerMapping(gfx::GetXDisplay(), |
530 button_map_, | 536 button_map_, |
531 arraysize(button_map_)); | 537 arraysize(button_map_)); |
532 } | 538 } |
533 | 539 |
534 void DeviceDataManager::GetGestureTimes(const base::NativeEvent& native_event, | 540 void DeviceDataManagerX11::GetGestureTimes( |
535 double* start_time, | 541 const base::NativeEvent& native_event, |
536 double* end_time) { | 542 double* start_time, |
| 543 double* end_time) { |
537 *start_time = 0; | 544 *start_time = 0; |
538 *end_time = 0; | 545 *end_time = 0; |
539 | 546 |
540 EventData data; | 547 EventData data; |
541 GetEventRawData(*native_event, &data); | 548 GetEventRawData(*native_event, &data); |
542 | 549 |
543 if (data.find(DT_CMT_START_TIME) != data.end()) | 550 if (data.find(DT_CMT_START_TIME) != data.end()) |
544 *start_time = data[DT_CMT_START_TIME]; | 551 *start_time = data[DT_CMT_START_TIME]; |
545 if (data.find(DT_CMT_END_TIME) != data.end()) | 552 if (data.find(DT_CMT_END_TIME) != data.end()) |
546 *end_time = data[DT_CMT_END_TIME]; | 553 *end_time = data[DT_CMT_END_TIME]; |
547 } | 554 } |
548 | 555 |
549 bool DeviceDataManager::NormalizeData(unsigned int deviceid, | 556 bool DeviceDataManagerX11::NormalizeData(unsigned int deviceid, |
550 const DataType type, | 557 const DataType type, |
551 double* value) { | 558 double* value) { |
552 double max_value; | 559 double max_value; |
553 double min_value; | 560 double min_value; |
554 if (GetDataRange(deviceid, type, &min_value, &max_value)) { | 561 if (GetDataRange(deviceid, type, &min_value, &max_value)) { |
555 *value = (*value - min_value) / (max_value - min_value); | 562 *value = (*value - min_value) / (max_value - min_value); |
556 DCHECK(*value >= 0.0 && *value <= 1.0); | 563 DCHECK(*value >= 0.0 && *value <= 1.0); |
557 return true; | 564 return true; |
558 } | 565 } |
559 return false; | 566 return false; |
560 } | 567 } |
561 | 568 |
562 bool DeviceDataManager::GetDataRange(unsigned int deviceid, | 569 bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, |
563 const DataType type, | 570 const DataType type, |
564 double* min, double* max) { | 571 double* min, |
| 572 double* max) { |
565 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) | 573 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) |
566 return false; | 574 return false; |
567 if (valuator_lookup_[deviceid][type] >= 0) { | 575 if (valuator_lookup_[deviceid][type] >= 0) { |
568 *min = valuator_min_[deviceid][type]; | 576 *min = valuator_min_[deviceid][type]; |
569 *max = valuator_max_[deviceid][type]; | 577 *max = valuator_max_[deviceid][type]; |
570 return true; | 578 return true; |
571 } | 579 } |
572 return false; | 580 return false; |
573 } | 581 } |
574 | 582 |
575 void DeviceDataManager::SetDeviceListForTest( | 583 void DeviceDataManagerX11::SetDeviceListForTest( |
576 const std::vector<unsigned int>& touchscreen, | 584 const std::vector<unsigned int>& touchscreen, |
577 const std::vector<unsigned int>& cmt_devices) { | 585 const std::vector<unsigned int>& cmt_devices) { |
578 for (int i = 0; i < kMaxDeviceNum; ++i) { | 586 for (int i = 0; i < kMaxDeviceNum; ++i) { |
579 valuator_count_[i] = 0; | 587 valuator_count_[i] = 0; |
580 valuator_lookup_[i].clear(); | 588 valuator_lookup_[i].clear(); |
581 data_type_lookup_[i].clear(); | 589 data_type_lookup_[i].clear(); |
582 valuator_min_[i].clear(); | 590 valuator_min_[i].clear(); |
583 valuator_max_[i].clear(); | 591 valuator_max_[i].clear(); |
584 for (int j = 0; j < kMaxSlotNum; j++) | 592 for (int j = 0; j < kMaxSlotNum; j++) |
585 last_seen_valuator_[i][j].clear(); | 593 last_seen_valuator_[i][j].clear(); |
586 } | 594 } |
587 | 595 |
588 for (size_t i = 0; i < touchscreen.size(); i++) { | 596 for (size_t i = 0; i < touchscreen.size(); i++) { |
589 unsigned int deviceid = touchscreen[i]; | 597 unsigned int deviceid = touchscreen[i]; |
590 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, | 598 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, |
591 0, 1000); | 599 0, 1000); |
592 } | 600 } |
593 | 601 |
594 cmt_devices_.reset(); | 602 cmt_devices_.reset(); |
595 for (size_t i = 0; i < cmt_devices.size(); ++i) { | 603 for (size_t i = 0; i < cmt_devices.size(); ++i) { |
596 unsigned int deviceid = cmt_devices[i]; | 604 unsigned int deviceid = cmt_devices[i]; |
597 cmt_devices_[deviceid] = true; | 605 cmt_devices_[deviceid] = true; |
598 touchpads_[deviceid] = true; | 606 touchpads_[deviceid] = true; |
599 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, | 607 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, |
600 -1000, 1000); | 608 -1000, 1000); |
601 } | 609 } |
602 } | 610 } |
603 | 611 |
604 void DeviceDataManager::SetValuatorDataForTest(XIDeviceEvent* xievent, | 612 void DeviceDataManagerX11::SetValuatorDataForTest(XIDeviceEvent* xievent, |
605 DataType type, | 613 DataType type, |
606 double value) { | 614 double value) { |
607 int index = valuator_lookup_[xievent->deviceid][type]; | 615 int index = valuator_lookup_[xievent->deviceid][type]; |
608 CHECK(!XIMaskIsSet(xievent->valuators.mask, index)); | 616 CHECK(!XIMaskIsSet(xievent->valuators.mask, index)); |
609 CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]); | 617 CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]); |
610 XISetMask(xievent->valuators.mask, index); | 618 XISetMask(xievent->valuators.mask, index); |
611 | 619 |
612 double* valuators = xievent->valuators.values; | 620 double* valuators = xievent->valuators.values; |
613 for (int i = 0; i < index; ++i) { | 621 for (int i = 0; i < index; ++i) { |
614 if (XIMaskIsSet(xievent->valuators.mask, i)) | 622 if (XIMaskIsSet(xievent->valuators.mask, i)) |
615 valuators++; | 623 valuators++; |
616 } | 624 } |
617 for (int i = DT_LAST_ENTRY - 1; i > valuators - xievent->valuators.values; | 625 for (int i = DT_LAST_ENTRY - 1; i > valuators - xievent->valuators.values; |
618 --i) | 626 --i) |
619 xievent->valuators.values[i] = xievent->valuators.values[i - 1]; | 627 xievent->valuators.values[i] = xievent->valuators.values[i - 1]; |
620 *valuators = value; | 628 *valuators = value; |
621 } | 629 } |
622 | 630 |
623 void DeviceDataManager::InitializeValuatorsForTest(int deviceid, | 631 void DeviceDataManagerX11::InitializeValuatorsForTest(int deviceid, |
624 int start_valuator, | 632 int start_valuator, |
625 int end_valuator, | 633 int end_valuator, |
626 double min_value, | 634 double min_value, |
627 double max_value) { | 635 double max_value) { |
628 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); | 636 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); |
629 data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY); | 637 data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY); |
630 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); | 638 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); |
631 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); | 639 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); |
632 for (int j = 0; j < kMaxSlotNum; j++) | 640 for (int j = 0; j < kMaxSlotNum; j++) |
633 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 641 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
634 for (int j = start_valuator; j <= end_valuator; ++j) { | 642 for (int j = start_valuator; j <= end_valuator; ++j) { |
635 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 643 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
636 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 644 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
637 valuator_min_[deviceid][j] = min_value; | 645 valuator_min_[deviceid][j] = min_value; |
638 valuator_max_[deviceid][j] = max_value; | 646 valuator_max_[deviceid][j] = max_value; |
639 valuator_count_[deviceid]++; | 647 valuator_count_[deviceid]++; |
640 } | 648 } |
641 } | 649 } |
642 | 650 |
643 bool DeviceDataManager::TouchEventNeedsCalibrate(int touch_device_id) const { | 651 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { |
644 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 652 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
645 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); | 653 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); |
646 if (base::SysInfo::IsRunningOnChromeOS() && | 654 if (base::SysInfo::IsRunningOnChromeOS() && |
647 touch_display_id == gfx::Display::InternalDisplayId()) { | 655 touch_display_id == gfx::Display::InternalDisplayId()) { |
648 return true; | 656 return true; |
649 } | 657 } |
650 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 658 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
651 return false; | 659 return false; |
652 } | 660 } |
653 | 661 |
654 void DeviceDataManager::ClearTouchTransformerRecord() { | |
655 for (int i = 0; i < kMaxDeviceNum; i++) { | |
656 touch_device_transformer_map_[i] = gfx::Transform(); | |
657 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | |
658 } | |
659 } | |
660 | |
661 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { | |
662 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); | |
663 } | |
664 | |
665 void DeviceDataManager::UpdateTouchInfoForDisplay( | |
666 int64 display_id, | |
667 int touch_device_id, | |
668 const gfx::Transform& touch_transformer) { | |
669 if (IsTouchDeviceIdValid(touch_device_id)) { | |
670 touch_device_to_display_map_[touch_device_id] = display_id; | |
671 touch_device_transformer_map_[touch_device_id] = touch_transformer; | |
672 } | |
673 } | |
674 | |
675 void DeviceDataManager::ApplyTouchTransformer(int touch_device_id, | |
676 float* x, float* y) { | |
677 if (IsTouchDeviceIdValid(touch_device_id)) { | |
678 gfx::Point3F point(*x, *y, 0.0); | |
679 const gfx::Transform& trans = | |
680 touch_device_transformer_map_[touch_device_id]; | |
681 trans.TransformPoint(&point); | |
682 *x = point.x(); | |
683 *y = point.y(); | |
684 } | |
685 } | |
686 | |
687 int64 DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { | |
688 if (IsTouchDeviceIdValid(touch_device_id)) | |
689 return touch_device_to_display_map_[touch_device_id]; | |
690 return gfx::Display::kInvalidDisplayID; | |
691 } | |
692 | |
693 } // namespace ui | 662 } // namespace ui |
OLD | NEW |