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

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

Powered by Google App Engine
This is Rietveld 408576698