Chromium Code Reviews| 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/devices/x11/device_data_manager_x11.h" | 5 #include "ui/events/devices/x11/device_data_manager_x11.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
| 9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 return true; | 211 return true; |
| 212 } | 212 } |
| 213 | 213 |
| 214 bool DeviceDataManagerX11::IsXInput2Available() const { | 214 bool DeviceDataManagerX11::IsXInput2Available() const { |
| 215 return xi_opcode_ != -1; | 215 return xi_opcode_ != -1; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { | 218 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
| 219 cmt_devices_.reset(); | 219 cmt_devices_.reset(); |
| 220 touchpads_.reset(); | 220 touchpads_.reset(); |
| 221 scrollclass_devices_.reset(); | |
| 221 master_pointers_.clear(); | 222 master_pointers_.clear(); |
| 222 for (int i = 0; i < kMaxDeviceNum; ++i) { | 223 for (int i = 0; i < kMaxDeviceNum; ++i) { |
| 223 valuator_count_[i] = 0; | 224 valuator_count_[i] = 0; |
| 224 valuator_lookup_[i].clear(); | 225 valuator_lookup_[i].clear(); |
| 225 data_type_lookup_[i].clear(); | 226 data_type_lookup_[i].clear(); |
| 226 valuator_min_[i].clear(); | 227 valuator_min_[i].clear(); |
| 227 valuator_max_[i].clear(); | 228 valuator_max_[i].clear(); |
| 229 scroll_data_[i].horizontal.number = -1; | |
| 230 scroll_data_[i].horizontal.seen = false; | |
| 231 scroll_data_[i].vertical.number = -1; | |
| 232 scroll_data_[i].vertical.seen = false; | |
| 228 for (int j = 0; j < kMaxSlotNum; j++) | 233 for (int j = 0; j < kMaxSlotNum; j++) |
| 229 last_seen_valuator_[i][j].clear(); | 234 last_seen_valuator_[i][j].clear(); |
| 230 } | 235 } |
| 231 | 236 |
| 232 // Find all the touchpad devices. | 237 // Find all the touchpad devices. |
| 233 const XDeviceList& dev_list = | 238 const XDeviceList& dev_list = |
| 234 ui::DeviceListCacheX11::GetInstance()->GetXDeviceList(display); | 239 ui::DeviceListCacheX11::GetInstance()->GetXDeviceList(display); |
| 235 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); | 240 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); |
| 236 for (int i = 0; i < dev_list.count; ++i) | 241 for (int i = 0; i < dev_list.count; ++i) |
| 237 if (dev_list[i].type == xi_touchpad) | 242 if (dev_list[i].type == xi_touchpad) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 continue; | 278 continue; |
| 274 | 279 |
| 275 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); | 280 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); |
| 276 data_type_lookup_[deviceid].resize( | 281 data_type_lookup_[deviceid].resize( |
| 277 valuator_count_[deviceid], DT_LAST_ENTRY); | 282 valuator_count_[deviceid], DT_LAST_ENTRY); |
| 278 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); | 283 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); |
| 279 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); | 284 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); |
| 280 for (int j = 0; j < kMaxSlotNum; j++) | 285 for (int j = 0; j < kMaxSlotNum; j++) |
| 281 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 286 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
| 282 for (int j = 0; j < info.num_classes; ++j) { | 287 for (int j = 0; j < info.num_classes; ++j) { |
| 283 if (info.classes[j]->type != XIValuatorClass) | 288 if (info.classes[j]->type == XIValuatorClass) { |
| 284 continue; | 289 if (UpdateValuatorClassDevice( |
| 285 | 290 reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]), atoms, |
| 286 XIValuatorClassInfo* v = | 291 deviceid)) |
| 287 reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]); | 292 possible_cmt = true; |
| 288 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { | 293 } else if (info.classes[j]->type == XIScrollClass) { |
| 289 if (v->label == atoms[data_type]) { | 294 UpdateScrollClassDevice( |
| 290 valuator_lookup_[deviceid][data_type] = v->number; | 295 reinterpret_cast<XIScrollClassInfo*>(info.classes[j]), deviceid); |
| 291 data_type_lookup_[deviceid][v->number] = data_type; | |
| 292 valuator_min_[deviceid][data_type] = v->min; | |
| 293 valuator_max_[deviceid][data_type] = v->max; | |
| 294 if (IsCMTDataType(data_type)) | |
| 295 possible_cmt = true; | |
| 296 break; | |
| 297 } | |
| 298 } | 296 } |
| 299 } | 297 } |
| 300 | 298 |
| 301 if (possible_cmt && !not_cmt) | 299 if (possible_cmt && !not_cmt) |
| 302 cmt_devices_[deviceid] = true; | 300 cmt_devices_[deviceid] = true; |
| 303 } | 301 } |
| 304 } | 302 } |
| 305 | 303 |
| 306 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { | 304 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { |
| 307 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 305 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 return false; | 416 return false; |
| 419 | 417 |
| 420 XIDeviceEvent* xievent = | 418 XIDeviceEvent* xievent = |
| 421 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 419 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 422 CHECK(xievent->sourceid >= 0); | 420 CHECK(xievent->sourceid >= 0); |
| 423 if (xievent->sourceid >= kMaxDeviceNum) | 421 if (xievent->sourceid >= kMaxDeviceNum) |
| 424 return false; | 422 return false; |
| 425 return cmt_devices_[xievent->sourceid]; | 423 return cmt_devices_[xievent->sourceid]; |
| 426 } | 424 } |
| 427 | 425 |
| 426 int DeviceDataManagerX11::GetScrollClassEventDetail( | |
| 427 const base::NativeEvent& native_event) const { | |
| 428 if (native_event->type != GenericEvent) | |
| 429 return SCROLL_TYPE_NO_SCROLL; | |
| 430 | |
| 431 XIDeviceEvent* xievent = | |
| 432 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | |
| 433 if (xievent->sourceid >= kMaxDeviceNum) | |
| 434 return SCROLL_TYPE_NO_SCROLL; | |
| 435 if (!scrollclass_devices_[xievent->sourceid]) | |
| 436 return SCROLL_TYPE_NO_SCROLL; | |
| 437 int horizontal_id = scroll_data_[xievent->sourceid].horizontal.number; | |
| 438 int vertical_id = scroll_data_[xievent->sourceid].vertical.number; | |
| 439 return (XIMaskIsSet(xievent->valuators.mask, horizontal_id) | |
| 440 ? SCROLL_TYPE_HORIZONTAL | |
| 441 : 0) | | |
| 442 (XIMaskIsSet(xievent->valuators.mask, vertical_id) | |
| 443 ? SCROLL_TYPE_VERTICAL | |
| 444 : 0); | |
| 445 } | |
| 446 | |
| 447 int DeviceDataManagerX11::GetScrollClassDeviceDetail( | |
| 448 const base::NativeEvent& native_event) const { | |
| 449 XEvent& xev = *native_event; | |
| 450 if (xev.type != GenericEvent) | |
| 451 return SCROLL_TYPE_NO_SCROLL; | |
| 452 | |
| 453 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | |
| 454 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | |
| 455 return SCROLL_TYPE_NO_SCROLL; | |
| 456 const int sourceid = xiev->sourceid; | |
| 457 const ScrollInfo& device_data = scroll_data_[sourceid]; | |
| 458 return (device_data.vertical.number >= 0 ? SCROLL_TYPE_VERTICAL : 0) | | |
| 459 (device_data.horizontal.number >= 0 ? SCROLL_TYPE_HORIZONTAL : 0); | |
| 460 } | |
| 461 | |
| 428 bool DeviceDataManagerX11::IsCMTGestureEvent( | 462 bool DeviceDataManagerX11::IsCMTGestureEvent( |
| 429 const base::NativeEvent& native_event) const { | 463 const base::NativeEvent& native_event) const { |
| 430 return (IsScrollEvent(native_event) || | 464 return (IsScrollEvent(native_event) || |
| 431 IsFlingEvent(native_event) || | 465 IsFlingEvent(native_event) || |
| 432 IsCMTMetricsEvent(native_event)); | 466 IsCMTMetricsEvent(native_event)); |
| 433 } | 467 } |
| 434 | 468 |
| 435 bool DeviceDataManagerX11::HasEventData( | 469 bool DeviceDataManagerX11::HasEventData( |
| 436 const XIDeviceEvent* xiev, const DataType type) const { | 470 const XIDeviceEvent* xiev, const DataType type) const { |
| 437 CHECK(xiev->sourceid >= 0); | 471 CHECK(xiev->sourceid >= 0); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 if (data.find(DT_CMT_SCROLL_Y) != data.end()) | 544 if (data.find(DT_CMT_SCROLL_Y) != data.end()) |
| 511 *y_offset = data[DT_CMT_SCROLL_Y]; | 545 *y_offset = data[DT_CMT_SCROLL_Y]; |
| 512 if (data.find(DT_CMT_ORDINAL_X) != data.end()) | 546 if (data.find(DT_CMT_ORDINAL_X) != data.end()) |
| 513 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; | 547 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; |
| 514 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) | 548 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) |
| 515 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; | 549 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; |
| 516 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) | 550 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) |
| 517 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); | 551 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); |
| 518 } | 552 } |
| 519 | 553 |
| 554 void DeviceDataManagerX11::GetScrollClassOffsets( | |
| 555 const base::NativeEvent& native_event, | |
| 556 double* x_offset, | |
| 557 double* y_offset) { | |
| 558 DCHECK_NE(SCROLL_TYPE_NO_SCROLL, GetScrollClassDeviceDetail(native_event)); | |
| 559 XEvent& xev = *native_event; | |
| 560 if (xev.type != GenericEvent) | |
| 561 return; | |
|
sadrul
2016/01/08 17:10:21
Let's set *x_offset and *y_offset to 0 before the
Will Shackleton
2016/01/10 14:18:42
Done.
| |
| 562 | |
| 563 *x_offset = 0; | |
| 564 *y_offset = 0; | |
| 565 | |
| 566 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | |
| 567 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) | |
| 568 return; | |
| 569 const int sourceid = xiev->sourceid; | |
| 570 double* valuators = xiev->valuators.values; | |
| 571 | |
| 572 ScrollInfo* info = &scroll_data_[sourceid]; | |
| 573 | |
| 574 const int horizontal_number = info->horizontal.number; | |
| 575 const int vertical_number = info->vertical.number; | |
| 576 | |
| 577 for (int i = 0; i <= valuator_count_[sourceid]; ++i) { | |
| 578 if (!XIMaskIsSet(xiev->valuators.mask, i)) | |
| 579 continue; | |
| 580 if (i == horizontal_number) { | |
| 581 *x_offset = ExtractAndUpdateScrollOffset(&info->horizontal, *valuators); | |
| 582 } else if (i == vertical_number) { | |
| 583 *y_offset = ExtractAndUpdateScrollOffset(&info->vertical, *valuators); | |
| 584 } | |
| 585 valuators++; | |
| 586 } | |
| 587 } | |
| 588 | |
| 589 void DeviceDataManagerX11::InvalidateScrollClasses() { | |
| 590 for (int i = 0; i < kMaxDeviceNum; i++) { | |
| 591 scroll_data_[i].horizontal.seen = false; | |
| 592 scroll_data_[i].vertical.seen = false; | |
| 593 } | |
| 594 } | |
| 595 | |
| 520 void DeviceDataManagerX11::GetFlingData( | 596 void DeviceDataManagerX11::GetFlingData( |
| 521 const base::NativeEvent& native_event, | 597 const base::NativeEvent& native_event, |
| 522 float* vx, | 598 float* vx, |
| 523 float* vy, | 599 float* vy, |
| 524 float* vx_ordinal, | 600 float* vx_ordinal, |
| 525 float* vy_ordinal, | 601 float* vy_ordinal, |
| 526 bool* is_cancel) { | 602 bool* is_cancel) { |
| 527 *vx = 0; | 603 *vx = 0; |
| 528 *vy = 0; | 604 *vy = 0; |
| 529 *vx_ordinal = 0; | 605 *vx_ordinal = 0; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 766 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
| 691 for (int j = start_valuator; j <= end_valuator; ++j) { | 767 for (int j = start_valuator; j <= end_valuator; ++j) { |
| 692 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 768 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
| 693 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 769 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
| 694 valuator_min_[deviceid][j] = min_value; | 770 valuator_min_[deviceid][j] = min_value; |
| 695 valuator_max_[deviceid][j] = max_value; | 771 valuator_max_[deviceid][j] = max_value; |
| 696 valuator_count_[deviceid]++; | 772 valuator_count_[deviceid]++; |
| 697 } | 773 } |
| 698 } | 774 } |
| 699 | 775 |
| 776 bool DeviceDataManagerX11::UpdateValuatorClassDevice( | |
| 777 XIValuatorClassInfo* valuator_class_info, | |
| 778 Atom* atoms, | |
| 779 int deviceid) { | |
| 780 DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); | |
| 781 Atom* label = | |
| 782 std::find(atoms, atoms + DT_LAST_ENTRY, valuator_class_info->label); | |
| 783 if (label == atoms + DT_LAST_ENTRY) { | |
| 784 return false; | |
| 785 } | |
| 786 int data_type = label - atoms; | |
| 787 DCHECK_GE(data_type, 0); | |
| 788 DCHECK_LT(data_type, DT_LAST_ENTRY); | |
| 789 | |
| 790 valuator_lookup_[deviceid][data_type] = valuator_class_info->number; | |
| 791 data_type_lookup_[deviceid][valuator_class_info->number] = data_type; | |
| 792 valuator_min_[deviceid][data_type] = valuator_class_info->min; | |
| 793 valuator_max_[deviceid][data_type] = valuator_class_info->max; | |
| 794 return IsCMTDataType(data_type); | |
| 795 } | |
| 796 | |
| 797 void DeviceDataManagerX11::UpdateScrollClassDevice( | |
| 798 XIScrollClassInfo* scroll_class_info, | |
| 799 int deviceid) { | |
| 800 DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); | |
| 801 ScrollInfo& info = scroll_data_[deviceid]; | |
| 802 switch (scroll_class_info->scroll_type) { | |
| 803 case XIScrollTypeVertical: | |
| 804 info.vertical.number = scroll_class_info->number; | |
| 805 info.vertical.increment = scroll_class_info->increment; | |
| 806 info.vertical.position = 0; | |
| 807 info.vertical.seen = false; | |
| 808 break; | |
| 809 case XIScrollTypeHorizontal: | |
| 810 info.horizontal.number = scroll_class_info->number; | |
| 811 info.horizontal.increment = scroll_class_info->increment; | |
| 812 info.horizontal.position = 0; | |
| 813 info.horizontal.seen = false; | |
| 814 break; | |
| 815 } | |
| 816 scrollclass_devices_[deviceid] = true; | |
| 817 } | |
| 818 | |
| 819 double DeviceDataManagerX11::ExtractAndUpdateScrollOffset( | |
| 820 ScrollInfo::AxisInfo* axis, | |
| 821 double valuator) const { | |
| 822 double offset = 0; | |
| 823 if (axis->seen) | |
| 824 offset = axis->position - valuator; | |
| 825 axis->seen = true; | |
| 826 axis->position = valuator; | |
| 827 return offset / axis->increment; | |
| 828 } | |
| 829 | |
| 700 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { | 830 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { |
| 701 #if defined(OS_CHROMEOS) | 831 #if defined(OS_CHROMEOS) |
| 702 if (!base::SysInfo::IsRunningOnChromeOS()) | 832 if (!base::SysInfo::IsRunningOnChromeOS()) |
| 703 return false; | 833 return false; |
| 704 | 834 |
| 705 const std::vector<TouchscreenDevice>& touch_devices = | 835 const std::vector<TouchscreenDevice>& touch_devices = |
| 706 ui::DeviceDataManager::GetInstance()->touchscreen_devices(); | 836 ui::DeviceDataManager::GetInstance()->touchscreen_devices(); |
| 707 std::vector<TouchscreenDevice>::const_iterator it = FindDeviceWithId( | 837 std::vector<TouchscreenDevice>::const_iterator it = FindDeviceWithId( |
| 708 touch_devices.begin(), touch_devices.end(), touch_device_id); | 838 touch_devices.begin(), touch_devices.end(), touch_device_id); |
| 709 return it != touch_devices.end() && it->type == INPUT_DEVICE_INTERNAL; | 839 return it != touch_devices.end() && it->type == INPUT_DEVICE_INTERNAL; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 } else { | 917 } else { |
| 788 keyboards.erase(it); | 918 keyboards.erase(it); |
| 789 ++blocked_iter; | 919 ++blocked_iter; |
| 790 } | 920 } |
| 791 } | 921 } |
| 792 // Notify base class of updated list. | 922 // Notify base class of updated list. |
| 793 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 923 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 794 } | 924 } |
| 795 | 925 |
| 796 } // namespace ui | 926 } // namespace ui |
| OLD | NEW |