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

Side by Side Diff: ui/events/x/device_data_manager_x11.cc

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

Powered by Google App Engine
This is Rietveld 408576698