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/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 |
| 11 #include <utility> | |
| 12 | |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 13 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
| 14 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_switches.h" | 17 #include "ui/events/event_switches.h" |
| 18 #include "ui/events/keyboard_device.h" | |
| 16 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 19 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 17 #include "ui/events/x/device_list_cache_x.h" | 20 #include "ui/events/x/device_list_cache_x.h" |
| 18 #include "ui/events/x/touch_factory_x11.h" | 21 #include "ui/events/x/touch_factory_x11.h" |
| 19 #include "ui/gfx/display.h" | 22 #include "ui/gfx/display.h" |
| 20 #include "ui/gfx/point3_f.h" | 23 #include "ui/gfx/point3_f.h" |
| 21 #include "ui/gfx/x/x11_types.h" | 24 #include "ui/gfx/x/x11_types.h" |
| 22 | 25 |
| 23 // XIScrollClass was introduced in XI 2.1 so we need to define it here | 26 // XIScrollClass was introduced in XI 2.1 so we need to define it here |
| 24 // for backward-compatibility with older versions of XInput. | 27 // for backward-compatibility with older versions of XInput. |
| 25 #if !defined(XIScrollClass) | 28 #if !defined(XIScrollClass) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 | 102 |
| 100 // Constants for checking if a data type lies in the range of CMT/Touch data | 103 // Constants for checking if a data type lies in the range of CMT/Touch data |
| 101 // types. | 104 // types. |
| 102 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; | 105 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; |
| 103 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; | 106 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; |
| 104 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; | 107 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; |
| 105 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; | 108 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; |
| 106 | 109 |
| 107 namespace ui { | 110 namespace ui { |
| 108 | 111 |
| 112 namespace { | |
| 113 | |
| 114 bool KeyboardDeviceHasId(const ui::KeyboardDevice keyboard, unsigned int id) { | |
| 115 return keyboard.id == id; | |
| 116 } | |
| 117 | |
| 118 } // namespace | |
| 119 | |
| 109 bool DeviceDataManagerX11::IsCMTDataType(const int type) { | 120 bool DeviceDataManagerX11::IsCMTDataType(const int type) { |
| 110 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); | 121 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); |
| 111 } | 122 } |
| 112 | 123 |
| 113 bool DeviceDataManagerX11::IsTouchDataType(const int type) { | 124 bool DeviceDataManagerX11::IsTouchDataType(const int type) { |
| 114 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); | 125 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); |
| 115 } | 126 } |
| 116 | 127 |
| 117 // static | 128 // static |
| 118 void DeviceDataManagerX11::CreateInstance() { | 129 void DeviceDataManagerX11::CreateInstance() { |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 665 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
| 655 for (int j = start_valuator; j <= end_valuator; ++j) { | 666 for (int j = start_valuator; j <= end_valuator; ++j) { |
| 656 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 667 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
| 657 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 668 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
| 658 valuator_min_[deviceid][j] = min_value; | 669 valuator_min_[deviceid][j] = min_value; |
| 659 valuator_max_[deviceid][j] = max_value; | 670 valuator_max_[deviceid][j] = max_value; |
| 660 valuator_count_[deviceid]++; | 671 valuator_count_[deviceid]++; |
| 661 } | 672 } |
| 662 } | 673 } |
| 663 | 674 |
| 664 bool DeviceDataManagerX11::TouchEventNeedsCalibrate(int touch_device_id) const { | 675 bool DeviceDataManagerX11::TouchEventNeedsCalibrate( |
| 676 unsigned int touch_device_id) const { | |
| 665 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 677 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
| 666 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); | 678 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); |
| 667 if (base::SysInfo::IsRunningOnChromeOS() && | 679 if (base::SysInfo::IsRunningOnChromeOS() && |
| 668 touch_display_id == gfx::Display::InternalDisplayId()) { | 680 touch_display_id == gfx::Display::InternalDisplayId()) { |
| 669 return true; | 681 return true; |
| 670 } | 682 } |
| 671 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 683 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
| 672 return false; | 684 return false; |
| 673 } | 685 } |
| 674 | 686 |
| 675 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( | 687 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
| 676 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { | 688 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { |
| 677 DCHECK(!excepted_keys.get() || | 689 DCHECK(!excepted_keys.get() || |
| 678 !blocked_keyboard_allowed_keys_.get()); | 690 !blocked_keyboard_allowed_keys_.get()); |
| 679 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); | 691 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); |
| 680 } | 692 } |
| 681 | 693 |
| 682 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { | 694 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { |
| 683 blocked_devices_.set(deviceid, true); | 695 blocked_devices_.set(deviceid, true); |
| 696 // TODO(rsadam@): Support blocking touchscreen devices. | |
| 697 std::vector<KeyboardDevice> keyboards = keyboard_devices(); | |
| 698 std::vector<KeyboardDevice>::iterator it = | |
| 699 std::find_if(keyboards.begin(), | |
| 700 keyboards.end(), | |
| 701 std::bind2nd(std::ptr_fun(&KeyboardDeviceHasId), deviceid)); | |
| 702 if (it != std::end(keyboards)) { | |
| 703 blocked_keyboards_.insert( | |
| 704 std::pair<unsigned int, KeyboardDevice>(deviceid, *it)); | |
| 705 keyboards.erase(it); | |
| 706 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | |
| 707 } | |
| 684 } | 708 } |
| 685 | 709 |
| 686 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { | 710 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { |
| 687 blocked_devices_.set(deviceid, false); | 711 blocked_devices_.set(deviceid, false); |
| 712 std::map<unsigned int, KeyboardDevice>::iterator it = | |
| 713 blocked_keyboards_.find(deviceid); | |
| 714 if (it != blocked_keyboards_.end()) { | |
| 715 std::vector<KeyboardDevice> devices = keyboard_devices(); | |
| 716 // Add device to current list of active devices. | |
| 717 devices.push_back((*it).second); | |
| 718 blocked_keyboards_.erase(it); | |
| 719 DeviceDataManager::OnKeyboardDevicesUpdated(devices); | |
| 720 } | |
| 688 } | 721 } |
| 689 | 722 |
| 690 bool DeviceDataManagerX11::IsEventBlocked( | 723 bool DeviceDataManagerX11::IsEventBlocked( |
| 691 const base::NativeEvent& native_event) { | 724 const base::NativeEvent& native_event) { |
| 692 // Only check XI2 events which have a source device id. | 725 // Only check XI2 events which have a source device id. |
| 693 if (native_event->type != GenericEvent) | 726 if (native_event->type != GenericEvent) |
| 694 return false; | 727 return false; |
| 695 | 728 |
| 696 XIDeviceEvent* xievent = | 729 XIDeviceEvent* xievent = |
| 697 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 730 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 698 // Allow any key events from blocked_keyboard_allowed_keys_. | 731 // Allow any key events from blocked_keyboard_allowed_keys_. |
| 699 if (blocked_keyboard_allowed_keys_ && | 732 if (blocked_keyboard_allowed_keys_ && |
| 700 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && | 733 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
| 701 blocked_keyboard_allowed_keys_->find( | 734 blocked_keyboard_allowed_keys_->find( |
| 702 KeyboardCodeFromXKeyEvent(native_event)) != | 735 KeyboardCodeFromXKeyEvent(native_event)) != |
| 703 blocked_keyboard_allowed_keys_->end()) { | 736 blocked_keyboard_allowed_keys_->end()) { |
| 704 return false; | 737 return false; |
| 705 } | 738 } |
| 706 | 739 |
| 707 return blocked_devices_.test(xievent->sourceid); | 740 return blocked_devices_.test(xievent->sourceid); |
| 708 } | 741 } |
| 709 | 742 |
| 743 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( | |
| 744 const std::vector<KeyboardDevice>& devices) { | |
| 745 std::vector<KeyboardDevice> keyboards(devices); | |
| 746 std::map<unsigned int, KeyboardDevice>::iterator blocked_iter; | |
|
sky
2014/10/22 15:07:18
nit: move into for loop.
rsadam
2014/10/22 16:21:16
Done.
| |
| 747 for (blocked_iter = blocked_keyboards_.begin(); | |
| 748 blocked_iter != blocked_keyboards_.end();) { | |
| 749 // Check if the blocked device still exists in list of devices. | |
| 750 std::vector<KeyboardDevice>::iterator it = | |
| 751 std::find_if(keyboards.begin(), | |
| 752 keyboards.end(), | |
| 753 std::bind2nd(std::ptr_fun(&KeyboardDeviceHasId), | |
| 754 (*blocked_iter).first)); | |
| 755 // If the device no longer exists, unblock it, else filter it out from our | |
| 756 // active list. | |
| 757 if (it == keyboards.end()) { | |
| 758 blocked_devices_.set((*blocked_iter).first, false); | |
| 759 blocked_keyboards_.erase(blocked_iter++); | |
| 760 } else { | |
| 761 keyboards.erase(it); | |
| 762 ++blocked_iter; | |
| 763 } | |
| 764 } | |
| 765 // Notify base class of updated list. | |
| 766 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | |
| 767 } | |
| 768 | |
| 710 } // namespace ui | 769 } // namespace ui |
| OLD | NEW |