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 KeyboardDeviceHasId(const ui::KeyboardDevice keyboard, unsigned int id) { | 114 bool DeviceHasId(const ui::InputDevice input_device, unsigned int id) { |
115 return keyboard.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) { |
125 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); | 125 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( |
669 unsigned int touch_device_id) const { | 669 unsigned int touch_device_id) const { |
670 #if defined(OS_CHROMEOS) && defined(USE_X11) | 670 #if defined(OS_CHROMEOS) |
671 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); | 671 if (!base::SysInfo::IsRunningOnChromeOS()) |
672 if (base::SysInfo::IsRunningOnChromeOS() && | 672 return false; |
673 touch_display_id == gfx::Display::InternalDisplayId()) { | 673 |
674 return true; | 674 const std::vector<TouchscreenDevice>& touch_devices = |
675 } | 675 ui::DeviceDataManager::GetInstance()->touchscreen_devices(); |
676 #endif // defined(OS_CHROMEOS) && defined(USE_X11) | 676 std::vector<TouchscreenDevice>::const_iterator it = |
| 677 std::find_if(touch_devices.begin(), touch_devices.end(), |
| 678 std::bind2nd(std::ptr_fun(&DeviceHasId), touch_device_id)); |
| 679 return it != touch_devices.end() && it->type == INPUT_DEVICE_INTERNAL; |
| 680 #endif // defined(OS_CHROMEOS) |
677 return false; | 681 return false; |
678 } | 682 } |
679 | 683 |
680 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( | 684 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
681 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { | 685 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { |
682 DCHECK(!excepted_keys.get() || | 686 DCHECK(!excepted_keys.get() || |
683 !blocked_keyboard_allowed_keys_.get()); | 687 !blocked_keyboard_allowed_keys_.get()); |
684 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); | 688 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); |
685 } | 689 } |
686 | 690 |
687 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { | 691 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { |
688 blocked_devices_.set(deviceid, true); | 692 blocked_devices_.set(deviceid, true); |
689 // TODO(rsadam@): Support blocking touchscreen devices. | 693 // TODO(rsadam@): Support blocking touchscreen devices. |
690 std::vector<KeyboardDevice> keyboards = keyboard_devices(); | 694 std::vector<KeyboardDevice> keyboards = keyboard_devices(); |
691 std::vector<KeyboardDevice>::iterator it = | 695 std::vector<KeyboardDevice>::iterator it = |
692 std::find_if(keyboards.begin(), | 696 std::find_if(keyboards.begin(), |
693 keyboards.end(), | 697 keyboards.end(), |
694 std::bind2nd(std::ptr_fun(&KeyboardDeviceHasId), deviceid)); | 698 std::bind2nd(std::ptr_fun(&DeviceHasId), deviceid)); |
695 if (it != std::end(keyboards)) { | 699 if (it != std::end(keyboards)) { |
696 blocked_keyboards_.insert( | 700 blocked_keyboards_.insert( |
697 std::pair<unsigned int, KeyboardDevice>(deviceid, *it)); | 701 std::pair<unsigned int, KeyboardDevice>(deviceid, *it)); |
698 keyboards.erase(it); | 702 keyboards.erase(it); |
699 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 703 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
700 } | 704 } |
701 } | 705 } |
702 | 706 |
703 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { | 707 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { |
704 blocked_devices_.set(deviceid, false); | 708 blocked_devices_.set(deviceid, false); |
(...skipping 28 matching lines...) Expand all Loading... |
733 return blocked_devices_.test(xievent->sourceid); | 737 return blocked_devices_.test(xievent->sourceid); |
734 } | 738 } |
735 | 739 |
736 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( | 740 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
737 const std::vector<KeyboardDevice>& devices) { | 741 const std::vector<KeyboardDevice>& devices) { |
738 std::vector<KeyboardDevice> keyboards(devices); | 742 std::vector<KeyboardDevice> keyboards(devices); |
739 for (std::map<unsigned int, KeyboardDevice>::iterator blocked_iter = | 743 for (std::map<unsigned int, KeyboardDevice>::iterator blocked_iter = |
740 blocked_keyboards_.begin(); | 744 blocked_keyboards_.begin(); |
741 blocked_iter != blocked_keyboards_.end();) { | 745 blocked_iter != blocked_keyboards_.end();) { |
742 // Check if the blocked device still exists in list of devices. | 746 // Check if the blocked device still exists in list of devices. |
743 std::vector<KeyboardDevice>::iterator it = | 747 std::vector<KeyboardDevice>::iterator it = std::find_if( |
744 std::find_if(keyboards.begin(), | 748 keyboards.begin(), keyboards.end(), |
745 keyboards.end(), | 749 std::bind2nd(std::ptr_fun(&DeviceHasId), (*blocked_iter).first)); |
746 std::bind2nd(std::ptr_fun(&KeyboardDeviceHasId), | |
747 (*blocked_iter).first)); | |
748 // If the device no longer exists, unblock it, else filter it out from our | 750 // If the device no longer exists, unblock it, else filter it out from our |
749 // active list. | 751 // active list. |
750 if (it == keyboards.end()) { | 752 if (it == keyboards.end()) { |
751 blocked_devices_.set((*blocked_iter).first, false); | 753 blocked_devices_.set((*blocked_iter).first, false); |
752 blocked_keyboards_.erase(blocked_iter++); | 754 blocked_keyboards_.erase(blocked_iter++); |
753 } else { | 755 } else { |
754 keyboards.erase(it); | 756 keyboards.erase(it); |
755 ++blocked_iter; | 757 ++blocked_iter; |
756 } | 758 } |
757 } | 759 } |
758 // Notify base class of updated list. | 760 // Notify base class of updated list. |
759 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 761 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
760 } | 762 } |
761 | 763 |
762 } // namespace ui | 764 } // namespace ui |
OLD | NEW |