OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/x/device_data_manager_x11.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 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 | 207 |
208 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { | 208 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
209 cmt_devices_.reset(); | 209 cmt_devices_.reset(); |
210 touchpads_.reset(); | 210 touchpads_.reset(); |
211 for (int i = 0; i < kMaxDeviceNum; ++i) { | 211 for (int i = 0; i < kMaxDeviceNum; ++i) { |
212 valuator_count_[i] = 0; | 212 valuator_count_[i] = 0; |
213 valuator_lookup_[i].clear(); | 213 valuator_lookup_[i].clear(); |
214 data_type_lookup_[i].clear(); | 214 data_type_lookup_[i].clear(); |
215 valuator_min_[i].clear(); | 215 valuator_min_[i].clear(); |
216 valuator_max_[i].clear(); | 216 valuator_max_[i].clear(); |
217 scroll_horizontal_number_[i] = -1; | |
218 scroll_vertical_number_[i] = -1; | |
217 for (int j = 0; j < kMaxSlotNum; j++) | 219 for (int j = 0; j < kMaxSlotNum; j++) |
218 last_seen_valuator_[i][j].clear(); | 220 last_seen_valuator_[i][j].clear(); |
219 } | 221 } |
220 | 222 |
221 // Find all the touchpad devices. | 223 // Find all the touchpad devices. |
222 XDeviceList dev_list = | 224 XDeviceList dev_list = |
223 ui::DeviceListCacheX::GetInstance()->GetXDeviceList(display); | 225 ui::DeviceListCacheX::GetInstance()->GetXDeviceList(display); |
224 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); | 226 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); |
225 for (int i = 0; i < dev_list.count; ++i) | 227 for (int i = 0; i < dev_list.count; ++i) |
226 if (dev_list[i].type == xi_touchpad) | 228 if (dev_list[i].type == xi_touchpad) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 continue; | 261 continue; |
260 | 262 |
261 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); | 263 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); |
262 data_type_lookup_[deviceid].resize( | 264 data_type_lookup_[deviceid].resize( |
263 valuator_count_[deviceid], DT_LAST_ENTRY); | 265 valuator_count_[deviceid], DT_LAST_ENTRY); |
264 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); | 266 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); |
265 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); | 267 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); |
266 for (int j = 0; j < kMaxSlotNum; j++) | 268 for (int j = 0; j < kMaxSlotNum; j++) |
267 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 269 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
268 for (int j = 0; j < info->num_classes; ++j) { | 270 for (int j = 0; j < info->num_classes; ++j) { |
269 if (info->classes[j]->type != XIValuatorClass) | 271 if (info->classes[j]->type == XIValuatorClass) { |
270 continue; | 272 XIValuatorClassInfo* v = |
271 | 273 reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]); |
272 XIValuatorClassInfo* v = | 274 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { |
273 reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]); | 275 if (v->label == atoms[data_type]) { |
274 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { | 276 valuator_lookup_[deviceid][data_type] = v->number; |
275 if (v->label == atoms[data_type]) { | 277 data_type_lookup_[deviceid][v->number] = data_type; |
276 valuator_lookup_[deviceid][data_type] = v->number; | 278 valuator_min_[deviceid][data_type] = v->min; |
277 data_type_lookup_[deviceid][v->number] = data_type; | 279 valuator_max_[deviceid][data_type] = v->max; |
278 valuator_min_[deviceid][data_type] = v->min; | 280 if (IsCMTDataType(data_type)) |
279 valuator_max_[deviceid][data_type] = v->max; | 281 possible_cmt = true; |
280 if (IsCMTDataType(data_type)) | 282 break; |
281 possible_cmt = true; | 283 } |
282 break; | |
283 } | 284 } |
285 } else if (info->classes[j]->type == XIScrollClass) { | |
286 XIScrollClassInfo* v = | |
287 reinterpret_cast<XIScrollClassInfo*>(info->classes[j]); | |
288 switch (v->scroll_type) { | |
289 case XIScrollTypeVertical: | |
290 scroll_vertical_number_[deviceid] = v->number; | |
291 scroll_vertical_increment_[deviceid] = v->increment; | |
292 scroll_vertical_position_[deviceid] = 0; | |
293 scroll_vertical_seen_[deviceid] = false; | |
294 break; | |
295 case XIScrollTypeHorizontal: | |
296 scroll_horizontal_number_[deviceid] = v->number; | |
297 scroll_horizontal_increment_[deviceid] = v->increment; | |
298 scroll_horizontal_position_[deviceid] = 0; | |
299 scroll_horizontal_seen_[deviceid] = false; | |
300 break; | |
301 } | |
302 scrollclass_devices_[deviceid] = true; | |
284 } | 303 } |
285 } | 304 } |
286 | 305 |
287 if (possible_cmt && !not_cmt) | 306 if (possible_cmt && !not_cmt) |
288 cmt_devices_[deviceid] = true; | 307 cmt_devices_[deviceid] = true; |
289 } | 308 } |
290 } | 309 } |
291 | 310 |
292 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { | 311 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { |
293 #if defined(USE_XI2_MT) | 312 #if defined(USE_XI2_MT) |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 if (native_event->type != GenericEvent) | 422 if (native_event->type != GenericEvent) |
404 return false; | 423 return false; |
405 | 424 |
406 XIDeviceEvent* xievent = | 425 XIDeviceEvent* xievent = |
407 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 426 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
408 if (xievent->sourceid >= kMaxDeviceNum) | 427 if (xievent->sourceid >= kMaxDeviceNum) |
409 return false; | 428 return false; |
410 return cmt_devices_[xievent->sourceid]; | 429 return cmt_devices_[xievent->sourceid]; |
411 } | 430 } |
412 | 431 |
432 bool DeviceDataManagerX11::IsScrollClassEvent( | |
433 const base::NativeEvent& native_event) const { | |
434 if (native_event->type != GenericEvent) | |
435 return false; | |
436 | |
437 XIDeviceEvent* xievent = | |
438 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
439 if (xievent->sourceid >= kMaxDeviceNum) | |
440 return false; | |
441 if (!scrollclass_devices_[xievent->sourceid]) | |
442 return false; | |
443 int horizontal_id = scroll_horizontal_number_[xievent->sourceid]; | |
444 int vertical_id = scroll_vertical_number_[xievent->sourceid]; | |
445 return XIMaskIsSet(xievent->valuators.mask, horizontal_id) || | |
446 XIMaskIsSet(xievent->valuators.mask, vertical_id); | |
447 } | |
448 | |
449 bool DeviceDataManagerX11::IsScrollClassVerticalDevice( | |
450 const base::NativeEvent& native_event) const { | |
451 XEvent& xev = *native_event; | |
452 if (xev.type != GenericEvent) | |
453 return false; | |
454 | |
455 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | |
456 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | |
457 return false; | |
458 const int sourceid = xiev->sourceid; | |
459 return scroll_vertical_number_[sourceid] >= 0; | |
460 } | |
461 | |
462 bool DeviceDataManagerX11::IsScrollClassHorizontalDevice( | |
463 const base::NativeEvent& native_event) const { | |
464 XEvent& xev = *native_event; | |
465 if (xev.type != GenericEvent) | |
466 return false; | |
467 | |
468 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | |
469 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | |
470 return false; | |
471 const int sourceid = xiev->sourceid; | |
472 return scroll_horizontal_number_[sourceid] >= 0; | |
473 } | |
474 | |
413 bool DeviceDataManagerX11::IsCMTGestureEvent( | 475 bool DeviceDataManagerX11::IsCMTGestureEvent( |
414 const base::NativeEvent& native_event) const { | 476 const base::NativeEvent& native_event) const { |
415 return (IsScrollEvent(native_event) || | 477 return (IsScrollEvent(native_event) || |
416 IsFlingEvent(native_event) || | 478 IsFlingEvent(native_event) || |
417 IsCMTMetricsEvent(native_event)); | 479 IsCMTMetricsEvent(native_event)); |
418 } | 480 } |
419 | 481 |
420 bool DeviceDataManagerX11::HasEventData( | 482 bool DeviceDataManagerX11::HasEventData( |
421 const XIDeviceEvent* xiev, const DataType type) const { | 483 const XIDeviceEvent* xiev, const DataType type) const { |
422 const int idx = valuator_lookup_[xiev->sourceid][type]; | 484 const int idx = valuator_lookup_[xiev->sourceid][type]; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 if (data.find(DT_CMT_SCROLL_Y) != data.end()) | 552 if (data.find(DT_CMT_SCROLL_Y) != data.end()) |
491 *y_offset = data[DT_CMT_SCROLL_Y]; | 553 *y_offset = data[DT_CMT_SCROLL_Y]; |
492 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 554 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
493 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; | 555 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; |
494 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 556 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
495 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; | 557 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; |
496 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) | 558 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) |
497 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); | 559 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); |
498 } | 560 } |
499 | 561 |
562 void DeviceDataManagerX11::GetScrollClassOffsets( | |
563 const base::NativeEvent& native_event, | |
564 double* x_offset, | |
565 double* y_offset) { | |
566 XEvent& xev = *native_event; | |
567 if (xev.type != GenericEvent) | |
568 return; | |
569 | |
570 *x_offset = 0; | |
571 *y_offset = 0; | |
572 | |
573 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | |
574 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | |
575 return; | |
576 const int sourceid = xiev->sourceid; | |
577 double* valuators = xiev->valuators.values; | |
578 | |
579 const int horizontal_number = scroll_horizontal_number_[sourceid]; | |
580 const int vertical_number = scroll_vertical_number_[sourceid]; | |
581 | |
582 for (int i = 0; i <= valuator_count_[sourceid]; ++i) { | |
583 if (XIMaskIsSet(xiev->valuators.mask, i)) { | |
584 if (i == horizontal_number) { | |
585 double value = *valuators; | |
586 double delta = 0; | |
587 | |
588 if (scroll_horizontal_seen_[sourceid]) | |
589 delta = scroll_horizontal_position_[sourceid] - value; | |
sadrul
2014/12/22 17:11:12
Does this mean the first such scroll event is igno
| |
590 | |
591 scroll_horizontal_seen_[sourceid] = true; | |
592 scroll_horizontal_position_[sourceid] = value; | |
593 *x_offset = delta; | |
594 NormalizeScrollData(sourceid, true, x_offset); | |
595 } else if (i == vertical_number) { | |
596 double value = *valuators; | |
597 double delta = 0; | |
598 if (scroll_vertical_seen_[sourceid]) | |
599 delta = scroll_vertical_position_[sourceid] - value; | |
600 | |
601 scroll_vertical_seen_[sourceid] = true; | |
602 scroll_vertical_position_[sourceid] = value; | |
603 *y_offset = delta; | |
604 NormalizeScrollData(sourceid, false, y_offset); | |
605 } | |
606 valuators++; | |
607 } | |
608 } | |
609 } | |
610 | |
611 void DeviceDataManagerX11::InvalidateScrollClasses() { | |
612 for (int i = 0; i < kMaxDeviceNum; i++) { | |
613 scroll_horizontal_seen_[i] = false; | |
614 scroll_vertical_seen_[i] = false; | |
615 } | |
616 } | |
617 | |
500 void DeviceDataManagerX11::GetFlingData( | 618 void DeviceDataManagerX11::GetFlingData( |
501 const base::NativeEvent& native_event, | 619 const base::NativeEvent& native_event, |
502 float* vx, | 620 float* vx, |
503 float* vy, | 621 float* vy, |
504 float* vx_ordinal, | 622 float* vx_ordinal, |
505 float* vy_ordinal, | 623 float* vy_ordinal, |
506 bool* is_cancel) { | 624 bool* is_cancel) { |
507 *vx = 0; | 625 *vx = 0; |
508 *vy = 0; | 626 *vy = 0; |
509 *vx_ordinal = 0; | 627 *vx_ordinal = 0; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
583 double max_value; | 701 double max_value; |
584 double min_value; | 702 double min_value; |
585 if (GetDataRange(deviceid, type, &min_value, &max_value)) { | 703 if (GetDataRange(deviceid, type, &min_value, &max_value)) { |
586 *value = (*value - min_value) / (max_value - min_value); | 704 *value = (*value - min_value) / (max_value - min_value); |
587 DCHECK(*value >= 0.0 && *value <= 1.0); | 705 DCHECK(*value >= 0.0 && *value <= 1.0); |
588 return true; | 706 return true; |
589 } | 707 } |
590 return false; | 708 return false; |
591 } | 709 } |
592 | 710 |
711 bool DeviceDataManagerX11::NormalizeScrollData(unsigned int deviceid, | |
712 bool horizontal, | |
713 double* value) { | |
714 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) | |
715 return false; | |
716 if (horizontal && scroll_horizontal_number_[deviceid] < 0) | |
717 return false; | |
718 if (!horizontal && scroll_vertical_number_[deviceid] < 0) | |
719 return false; | |
720 double increment = horizontal ? | |
721 scroll_horizontal_increment_[deviceid] : | |
722 scroll_vertical_increment_[deviceid]; | |
723 | |
724 *value /= increment; | |
725 return true; | |
726 } | |
727 | |
593 bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, | 728 bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, |
594 const DataType type, | 729 const DataType type, |
595 double* min, | 730 double* min, |
596 double* max) { | 731 double* max) { |
597 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) | 732 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) |
598 return false; | 733 return false; |
599 if (valuator_lookup_[deviceid][type] >= 0) { | 734 if (valuator_lookup_[deviceid][type] >= 0) { |
600 *min = valuator_min_[deviceid][type]; | 735 *min = valuator_min_[deviceid][type]; |
601 *max = valuator_max_[deviceid][type]; | 736 *max = valuator_max_[deviceid][type]; |
602 return true; | 737 return true; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 } else { | 895 } else { |
761 keyboards.erase(it); | 896 keyboards.erase(it); |
762 ++blocked_iter; | 897 ++blocked_iter; |
763 } | 898 } |
764 } | 899 } |
765 // Notify base class of updated list. | 900 // Notify base class of updated list. |
766 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 901 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
767 } | 902 } |
768 | 903 |
769 } // namespace ui | 904 } // namespace ui |
OLD | NEW |