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 |
| 561 *x_offset = 0; |
| 562 *y_offset = 0; |
| 563 |
| 564 if (xev.type != GenericEvent) |
| 565 return; |
| 566 |
| 567 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
| 568 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum) |
| 569 return; |
| 570 const int sourceid = xiev->sourceid; |
| 571 double* valuators = xiev->valuators.values; |
| 572 |
| 573 ScrollInfo* info = &scroll_data_[sourceid]; |
| 574 |
| 575 const int horizontal_number = info->horizontal.number; |
| 576 const int vertical_number = info->vertical.number; |
| 577 |
| 578 for (int i = 0; i <= valuator_count_[sourceid]; ++i) { |
| 579 if (!XIMaskIsSet(xiev->valuators.mask, i)) |
| 580 continue; |
| 581 if (i == horizontal_number) { |
| 582 *x_offset = ExtractAndUpdateScrollOffset(&info->horizontal, *valuators); |
| 583 } else if (i == vertical_number) { |
| 584 *y_offset = ExtractAndUpdateScrollOffset(&info->vertical, *valuators); |
| 585 } |
| 586 valuators++; |
| 587 } |
| 588 } |
| 589 |
| 590 void DeviceDataManagerX11::InvalidateScrollClasses() { |
| 591 for (int i = 0; i < kMaxDeviceNum; i++) { |
| 592 scroll_data_[i].horizontal.seen = false; |
| 593 scroll_data_[i].vertical.seen = false; |
| 594 } |
| 595 } |
| 596 |
520 void DeviceDataManagerX11::GetFlingData( | 597 void DeviceDataManagerX11::GetFlingData( |
521 const base::NativeEvent& native_event, | 598 const base::NativeEvent& native_event, |
522 float* vx, | 599 float* vx, |
523 float* vy, | 600 float* vy, |
524 float* vx_ordinal, | 601 float* vx_ordinal, |
525 float* vy_ordinal, | 602 float* vy_ordinal, |
526 bool* is_cancel) { | 603 bool* is_cancel) { |
527 *vx = 0; | 604 *vx = 0; |
528 *vy = 0; | 605 *vy = 0; |
529 *vx_ordinal = 0; | 606 *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); | 767 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
691 for (int j = start_valuator; j <= end_valuator; ++j) { | 768 for (int j = start_valuator; j <= end_valuator; ++j) { |
692 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 769 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
693 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 770 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
694 valuator_min_[deviceid][j] = min_value; | 771 valuator_min_[deviceid][j] = min_value; |
695 valuator_max_[deviceid][j] = max_value; | 772 valuator_max_[deviceid][j] = max_value; |
696 valuator_count_[deviceid]++; | 773 valuator_count_[deviceid]++; |
697 } | 774 } |
698 } | 775 } |
699 | 776 |
| 777 bool DeviceDataManagerX11::UpdateValuatorClassDevice( |
| 778 XIValuatorClassInfo* valuator_class_info, |
| 779 Atom* atoms, |
| 780 int deviceid) { |
| 781 DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); |
| 782 Atom* label = |
| 783 std::find(atoms, atoms + DT_LAST_ENTRY, valuator_class_info->label); |
| 784 if (label == atoms + DT_LAST_ENTRY) { |
| 785 return false; |
| 786 } |
| 787 int data_type = label - atoms; |
| 788 DCHECK_GE(data_type, 0); |
| 789 DCHECK_LT(data_type, DT_LAST_ENTRY); |
| 790 |
| 791 valuator_lookup_[deviceid][data_type] = valuator_class_info->number; |
| 792 data_type_lookup_[deviceid][valuator_class_info->number] = data_type; |
| 793 valuator_min_[deviceid][data_type] = valuator_class_info->min; |
| 794 valuator_max_[deviceid][data_type] = valuator_class_info->max; |
| 795 return IsCMTDataType(data_type); |
| 796 } |
| 797 |
| 798 void DeviceDataManagerX11::UpdateScrollClassDevice( |
| 799 XIScrollClassInfo* scroll_class_info, |
| 800 int deviceid) { |
| 801 DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); |
| 802 ScrollInfo& info = scroll_data_[deviceid]; |
| 803 switch (scroll_class_info->scroll_type) { |
| 804 case XIScrollTypeVertical: |
| 805 info.vertical.number = scroll_class_info->number; |
| 806 info.vertical.increment = scroll_class_info->increment; |
| 807 info.vertical.position = 0; |
| 808 info.vertical.seen = false; |
| 809 break; |
| 810 case XIScrollTypeHorizontal: |
| 811 info.horizontal.number = scroll_class_info->number; |
| 812 info.horizontal.increment = scroll_class_info->increment; |
| 813 info.horizontal.position = 0; |
| 814 info.horizontal.seen = false; |
| 815 break; |
| 816 } |
| 817 scrollclass_devices_[deviceid] = true; |
| 818 } |
| 819 |
| 820 double DeviceDataManagerX11::ExtractAndUpdateScrollOffset( |
| 821 ScrollInfo::AxisInfo* axis, |
| 822 double valuator) const { |
| 823 double offset = 0; |
| 824 if (axis->seen) |
| 825 offset = axis->position - valuator; |
| 826 axis->seen = true; |
| 827 axis->position = valuator; |
| 828 return offset / axis->increment; |
| 829 } |
| 830 |
700 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { | 831 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { |
701 #if defined(OS_CHROMEOS) | 832 #if defined(OS_CHROMEOS) |
702 if (!base::SysInfo::IsRunningOnChromeOS()) | 833 if (!base::SysInfo::IsRunningOnChromeOS()) |
703 return false; | 834 return false; |
704 | 835 |
705 const std::vector<TouchscreenDevice>& touch_devices = | 836 const std::vector<TouchscreenDevice>& touch_devices = |
706 ui::DeviceDataManager::GetInstance()->touchscreen_devices(); | 837 ui::DeviceDataManager::GetInstance()->touchscreen_devices(); |
707 std::vector<TouchscreenDevice>::const_iterator it = FindDeviceWithId( | 838 std::vector<TouchscreenDevice>::const_iterator it = FindDeviceWithId( |
708 touch_devices.begin(), touch_devices.end(), touch_device_id); | 839 touch_devices.begin(), touch_devices.end(), touch_device_id); |
709 return it != touch_devices.end() && it->type == INPUT_DEVICE_INTERNAL; | 840 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 { | 918 } else { |
788 keyboards.erase(it); | 919 keyboards.erase(it); |
789 ++blocked_iter; | 920 ++blocked_iter; |
790 } | 921 } |
791 } | 922 } |
792 // Notify base class of updated list. | 923 // Notify base class of updated list. |
793 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 924 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
794 } | 925 } |
795 | 926 |
796 } // namespace ui | 927 } // namespace ui |
OLD | NEW |