| 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 <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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // types. | 104 // types. |
| 105 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; | 105 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; |
| 106 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; | 106 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; |
| 107 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; | 107 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; |
| 108 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; | 108 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; |
| 109 | 109 |
| 110 namespace ui { | 110 namespace ui { |
| 111 | 111 |
| 112 namespace { | 112 namespace { |
| 113 | 113 |
| 114 bool DeviceHasId(const ui::InputDevice input_device, unsigned int id) { | 114 bool DeviceHasId(const ui::InputDevice input_device, int id) { |
| 115 return input_device.id == id; | 115 return input_device.id == id; |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace | 118 } // namespace |
| 119 | 119 |
| 120 bool DeviceDataManagerX11::IsCMTDataType(const int type) { | 120 bool DeviceDataManagerX11::IsCMTDataType(const int type) { |
| 121 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); | 121 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool DeviceDataManagerX11::IsTouchDataType(const int type) { | 124 bool DeviceDataManagerX11::IsTouchDataType(const int type) { |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 563 |
| 564 EventData data; | 564 EventData data; |
| 565 GetEventRawData(*native_event, &data); | 565 GetEventRawData(*native_event, &data); |
| 566 | 566 |
| 567 if (data.find(DT_CMT_START_TIME) != data.end()) | 567 if (data.find(DT_CMT_START_TIME) != data.end()) |
| 568 *start_time = data[DT_CMT_START_TIME]; | 568 *start_time = data[DT_CMT_START_TIME]; |
| 569 if (data.find(DT_CMT_END_TIME) != data.end()) | 569 if (data.find(DT_CMT_END_TIME) != data.end()) |
| 570 *end_time = data[DT_CMT_END_TIME]; | 570 *end_time = data[DT_CMT_END_TIME]; |
| 571 } | 571 } |
| 572 | 572 |
| 573 bool DeviceDataManagerX11::NormalizeData(unsigned int deviceid, | 573 bool DeviceDataManagerX11::NormalizeData(int deviceid, |
| 574 const DataType type, | 574 const DataType type, |
| 575 double* value) { | 575 double* value) { |
| 576 double max_value; | 576 double max_value; |
| 577 double min_value; | 577 double min_value; |
| 578 if (GetDataRange(deviceid, type, &min_value, &max_value)) { | 578 if (GetDataRange(deviceid, type, &min_value, &max_value)) { |
| 579 *value = (*value - min_value) / (max_value - min_value); | 579 *value = (*value - min_value) / (max_value - min_value); |
| 580 DCHECK(*value >= 0.0 && *value <= 1.0); | 580 DCHECK(*value >= 0.0 && *value <= 1.0); |
| 581 return true; | 581 return true; |
| 582 } | 582 } |
| 583 return false; | 583 return false; |
| 584 } | 584 } |
| 585 | 585 |
| 586 bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, | 586 bool DeviceDataManagerX11::GetDataRange(int deviceid, |
| 587 const DataType type, | 587 const DataType type, |
| 588 double* min, | 588 double* min, |
| 589 double* max) { | 589 double* max) { |
| 590 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) | 590 if (deviceid >= kMaxDeviceNum) |
| 591 return false; | 591 return false; |
| 592 if (valuator_lookup_[deviceid][type] >= 0) { | 592 if (valuator_lookup_[deviceid][type] >= 0) { |
| 593 *min = valuator_min_[deviceid][type]; | 593 *min = valuator_min_[deviceid][type]; |
| 594 *max = valuator_max_[deviceid][type]; | 594 *max = valuator_max_[deviceid][type]; |
| 595 return true; | 595 return true; |
| 596 } | 596 } |
| 597 return false; | 597 return false; |
| 598 } | 598 } |
| 599 | 599 |
| 600 void DeviceDataManagerX11::SetDeviceListForTest( | 600 void DeviceDataManagerX11::SetDeviceListForTest( |
| 601 const std::vector<unsigned int>& touchscreen, | 601 const std::vector<int>& touchscreen, |
| 602 const std::vector<unsigned int>& cmt_devices) { | 602 const std::vector<int>& cmt_devices) { |
| 603 for (int i = 0; i < kMaxDeviceNum; ++i) { | 603 for (int i = 0; i < kMaxDeviceNum; ++i) { |
| 604 valuator_count_[i] = 0; | 604 valuator_count_[i] = 0; |
| 605 valuator_lookup_[i].clear(); | 605 valuator_lookup_[i].clear(); |
| 606 data_type_lookup_[i].clear(); | 606 data_type_lookup_[i].clear(); |
| 607 valuator_min_[i].clear(); | 607 valuator_min_[i].clear(); |
| 608 valuator_max_[i].clear(); | 608 valuator_max_[i].clear(); |
| 609 for (int j = 0; j < kMaxSlotNum; j++) | 609 for (int j = 0; j < kMaxSlotNum; j++) |
| 610 last_seen_valuator_[i][j].clear(); | 610 last_seen_valuator_[i][j].clear(); |
| 611 } | 611 } |
| 612 | 612 |
| 613 for (size_t i = 0; i < touchscreen.size(); i++) { | 613 for (size_t i = 0; i < touchscreen.size(); i++) { |
| 614 unsigned int deviceid = touchscreen[i]; | 614 int deviceid = touchscreen[i]; |
| 615 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, | 615 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, |
| 616 0, 1000); | 616 0, 1000); |
| 617 } | 617 } |
| 618 | 618 |
| 619 cmt_devices_.reset(); | 619 cmt_devices_.reset(); |
| 620 for (size_t i = 0; i < cmt_devices.size(); ++i) { | 620 for (size_t i = 0; i < cmt_devices.size(); ++i) { |
| 621 unsigned int deviceid = cmt_devices[i]; | 621 int deviceid = cmt_devices[i]; |
| 622 cmt_devices_[deviceid] = true; | 622 cmt_devices_[deviceid] = true; |
| 623 touchpads_[deviceid] = true; | 623 touchpads_[deviceid] = true; |
| 624 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, | 624 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, |
| 625 -1000, 1000); | 625 -1000, 1000); |
| 626 } | 626 } |
| 627 } | 627 } |
| 628 | 628 |
| 629 void DeviceDataManagerX11::SetValuatorDataForTest(XIDeviceEvent* xievent, | 629 void DeviceDataManagerX11::SetValuatorDataForTest(XIDeviceEvent* xievent, |
| 630 DataType type, | 630 DataType type, |
| 631 double value) { | 631 double value) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 658 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 658 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
| 659 for (int j = start_valuator; j <= end_valuator; ++j) { | 659 for (int j = start_valuator; j <= end_valuator; ++j) { |
| 660 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 660 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
| 661 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 661 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
| 662 valuator_min_[deviceid][j] = min_value; | 662 valuator_min_[deviceid][j] = min_value; |
| 663 valuator_max_[deviceid][j] = max_value; | 663 valuator_max_[deviceid][j] = max_value; |
| 664 valuator_count_[deviceid]++; | 664 valuator_count_[deviceid]++; |
| 665 } | 665 } |
| 666 } | 666 } |
| 667 | 667 |
| 668 bool DeviceDataManagerX11::TouchEventNeedsCalibrate( | 668 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { |
| 669 unsigned int touch_device_id) const { | |
| 670 #if defined(OS_CHROMEOS) | 669 #if defined(OS_CHROMEOS) |
| 671 if (!base::SysInfo::IsRunningOnChromeOS()) | 670 if (!base::SysInfo::IsRunningOnChromeOS()) |
| 672 return false; | 671 return false; |
| 673 | 672 |
| 674 const std::vector<TouchscreenDevice>& touch_devices = | 673 const std::vector<TouchscreenDevice>& touch_devices = |
| 675 ui::DeviceDataManager::GetInstance()->touchscreen_devices(); | 674 ui::DeviceDataManager::GetInstance()->touchscreen_devices(); |
| 676 std::vector<TouchscreenDevice>::const_iterator it = | 675 std::vector<TouchscreenDevice>::const_iterator it = |
| 677 std::find_if(touch_devices.begin(), touch_devices.end(), | 676 std::find_if(touch_devices.begin(), touch_devices.end(), |
| 678 std::bind2nd(std::ptr_fun(&DeviceHasId), touch_device_id)); | 677 std::bind2nd(std::ptr_fun(&DeviceHasId), touch_device_id)); |
| 679 return it != touch_devices.end() && it->type == INPUT_DEVICE_INTERNAL; | 678 return it != touch_devices.end() && it->type == INPUT_DEVICE_INTERNAL; |
| 680 #endif // defined(OS_CHROMEOS) | 679 #endif // defined(OS_CHROMEOS) |
| 681 return false; | 680 return false; |
| 682 } | 681 } |
| 683 | 682 |
| 684 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( | 683 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
| 685 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { | 684 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { |
| 686 DCHECK(!excepted_keys.get() || | 685 DCHECK(!excepted_keys.get() || |
| 687 !blocked_keyboard_allowed_keys_.get()); | 686 !blocked_keyboard_allowed_keys_.get()); |
| 688 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); | 687 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); |
| 689 } | 688 } |
| 690 | 689 |
| 691 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { | 690 void DeviceDataManagerX11::DisableDevice(int deviceid) { |
| 692 blocked_devices_.set(deviceid, true); | 691 blocked_devices_.set(deviceid, true); |
| 693 // TODO(rsadam@): Support blocking touchscreen devices. | 692 // TODO(rsadam@): Support blocking touchscreen devices. |
| 694 std::vector<KeyboardDevice> keyboards = keyboard_devices(); | 693 std::vector<KeyboardDevice> keyboards = keyboard_devices(); |
| 695 std::vector<KeyboardDevice>::iterator it = | 694 std::vector<KeyboardDevice>::iterator it = |
| 696 std::find_if(keyboards.begin(), | 695 std::find_if(keyboards.begin(), |
| 697 keyboards.end(), | 696 keyboards.end(), |
| 698 std::bind2nd(std::ptr_fun(&DeviceHasId), deviceid)); | 697 std::bind2nd(std::ptr_fun(&DeviceHasId), deviceid)); |
| 699 if (it != std::end(keyboards)) { | 698 if (it != std::end(keyboards)) { |
| 700 blocked_keyboards_.insert( | 699 blocked_keyboards_.insert( |
| 701 std::pair<unsigned int, KeyboardDevice>(deviceid, *it)); | 700 std::pair<int, KeyboardDevice>(deviceid, *it)); |
| 702 keyboards.erase(it); | 701 keyboards.erase(it); |
| 703 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 702 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 704 } | 703 } |
| 705 } | 704 } |
| 706 | 705 |
| 707 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { | 706 void DeviceDataManagerX11::EnableDevice(int deviceid) { |
| 708 blocked_devices_.set(deviceid, false); | 707 blocked_devices_.set(deviceid, false); |
| 709 std::map<unsigned int, KeyboardDevice>::iterator it = | 708 std::map<int, KeyboardDevice>::iterator it = |
| 710 blocked_keyboards_.find(deviceid); | 709 blocked_keyboards_.find(deviceid); |
| 711 if (it != blocked_keyboards_.end()) { | 710 if (it != blocked_keyboards_.end()) { |
| 712 std::vector<KeyboardDevice> devices = keyboard_devices(); | 711 std::vector<KeyboardDevice> devices = keyboard_devices(); |
| 713 // Add device to current list of active devices. | 712 // Add device to current list of active devices. |
| 714 devices.push_back((*it).second); | 713 devices.push_back((*it).second); |
| 715 blocked_keyboards_.erase(it); | 714 blocked_keyboards_.erase(it); |
| 716 DeviceDataManager::OnKeyboardDevicesUpdated(devices); | 715 DeviceDataManager::OnKeyboardDevicesUpdated(devices); |
| 717 } | 716 } |
| 718 } | 717 } |
| 719 | 718 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 733 blocked_keyboard_allowed_keys_->end()) { | 732 blocked_keyboard_allowed_keys_->end()) { |
| 734 return false; | 733 return false; |
| 735 } | 734 } |
| 736 | 735 |
| 737 return blocked_devices_.test(xievent->sourceid); | 736 return blocked_devices_.test(xievent->sourceid); |
| 738 } | 737 } |
| 739 | 738 |
| 740 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( | 739 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
| 741 const std::vector<KeyboardDevice>& devices) { | 740 const std::vector<KeyboardDevice>& devices) { |
| 742 std::vector<KeyboardDevice> keyboards(devices); | 741 std::vector<KeyboardDevice> keyboards(devices); |
| 743 for (std::map<unsigned int, KeyboardDevice>::iterator blocked_iter = | 742 for (std::map<int, KeyboardDevice>::iterator blocked_iter = |
| 744 blocked_keyboards_.begin(); | 743 blocked_keyboards_.begin(); |
| 745 blocked_iter != blocked_keyboards_.end();) { | 744 blocked_iter != blocked_keyboards_.end();) { |
| 746 // Check if the blocked device still exists in list of devices. | 745 // Check if the blocked device still exists in list of devices. |
| 747 std::vector<KeyboardDevice>::iterator it = std::find_if( | 746 std::vector<KeyboardDevice>::iterator it = std::find_if( |
| 748 keyboards.begin(), keyboards.end(), | 747 keyboards.begin(), keyboards.end(), |
| 749 std::bind2nd(std::ptr_fun(&DeviceHasId), (*blocked_iter).first)); | 748 std::bind2nd(std::ptr_fun(&DeviceHasId), (*blocked_iter).first)); |
| 750 // If the device no longer exists, unblock it, else filter it out from our | 749 // If the device no longer exists, unblock it, else filter it out from our |
| 751 // active list. | 750 // active list. |
| 752 if (it == keyboards.end()) { | 751 if (it == keyboards.end()) { |
| 753 blocked_devices_.set((*blocked_iter).first, false); | 752 blocked_devices_.set((*blocked_iter).first, false); |
| 754 blocked_keyboards_.erase(blocked_iter++); | 753 blocked_keyboards_.erase(blocked_iter++); |
| 755 } else { | 754 } else { |
| 756 keyboards.erase(it); | 755 keyboards.erase(it); |
| 757 ++blocked_iter; | 756 ++blocked_iter; |
| 758 } | 757 } |
| 759 } | 758 } |
| 760 // Notify base class of updated list. | 759 // Notify base class of updated list. |
| 761 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 760 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 762 } | 761 } |
| 763 | 762 |
| 764 } // namespace ui | 763 } // namespace ui |
| OLD | NEW |