| 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 HasId(ui::KeyboardDevice keyboard, 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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 685 |
| 675 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( | 686 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
| 676 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { | 687 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { |
| 677 DCHECK(!excepted_keys.get() || | 688 DCHECK(!excepted_keys.get() || |
| 678 !blocked_keyboard_allowed_keys_.get()); | 689 !blocked_keyboard_allowed_keys_.get()); |
| 679 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); | 690 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); |
| 680 } | 691 } |
| 681 | 692 |
| 682 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { | 693 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { |
| 683 blocked_devices_.set(deviceid, true); | 694 blocked_devices_.set(deviceid, true); |
| 695 int id = static_cast<int>(deviceid); |
| 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(), keyboards.end(), std::bind2nd( |
| 700 std::ptr_fun(&HasId), id)); |
| 701 if (it != std::end(keyboards)) { |
| 702 blocked_keyboards_.insert(std::pair<int, KeyboardDevice>(id, *it)); |
| 703 keyboards.erase(it); |
| 704 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 705 } |
| 684 } | 706 } |
| 685 | 707 |
| 686 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { | 708 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { |
| 687 blocked_devices_.set(deviceid, false); | 709 blocked_devices_.set(deviceid, false); |
| 710 int id = static_cast<int>(deviceid); |
| 711 std::map<int, KeyboardDevice>::iterator it = |
| 712 blocked_keyboards_.find(id); |
| 713 if (it != blocked_keyboards_.end()) { |
| 714 std::vector<KeyboardDevice> devices = keyboard_devices(); |
| 715 // Add device to current list of active devices. |
| 716 devices.push_back((*it).second); |
| 717 blocked_keyboards_.erase(it); |
| 718 DeviceDataManager::OnKeyboardDevicesUpdated(devices); |
| 719 } |
| 688 } | 720 } |
| 689 | 721 |
| 690 bool DeviceDataManagerX11::IsEventBlocked( | 722 bool DeviceDataManagerX11::IsEventBlocked( |
| 691 const base::NativeEvent& native_event) { | 723 const base::NativeEvent& native_event) { |
| 692 // Only check XI2 events which have a source device id. | 724 // Only check XI2 events which have a source device id. |
| 693 if (native_event->type != GenericEvent) | 725 if (native_event->type != GenericEvent) |
| 694 return false; | 726 return false; |
| 695 | 727 |
| 696 XIDeviceEvent* xievent = | 728 XIDeviceEvent* xievent = |
| 697 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 729 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 698 // Allow any key events from blocked_keyboard_allowed_keys_. | 730 // Allow any key events from blocked_keyboard_allowed_keys_. |
| 699 if (blocked_keyboard_allowed_keys_ && | 731 if (blocked_keyboard_allowed_keys_ && |
| 700 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && | 732 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
| 701 blocked_keyboard_allowed_keys_->find( | 733 blocked_keyboard_allowed_keys_->find( |
| 702 KeyboardCodeFromXKeyEvent(native_event)) != | 734 KeyboardCodeFromXKeyEvent(native_event)) != |
| 703 blocked_keyboard_allowed_keys_->end()) { | 735 blocked_keyboard_allowed_keys_->end()) { |
| 704 return false; | 736 return false; |
| 705 } | 737 } |
| 706 | 738 |
| 707 return blocked_devices_.test(xievent->sourceid); | 739 return blocked_devices_.test(xievent->sourceid); |
| 708 } | 740 } |
| 709 | 741 |
| 742 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
| 743 const std::vector<KeyboardDevice>& devices) { |
| 744 std::vector<KeyboardDevice> keyboards(devices); |
| 745 std::map<int, KeyboardDevice>::iterator blocked_iter; |
| 746 for (blocked_iter = blocked_keyboards_.begin(); |
| 747 blocked_iter != blocked_keyboards_.end();) { |
| 748 // Check if the blocked device still exists in list of devices. |
| 749 std::vector<KeyboardDevice>::iterator it = |
| 750 std::find_if(keyboards.begin(), keyboards.end(), std::bind2nd( |
| 751 std::ptr_fun(&HasId), (*blocked_iter).first)); |
| 752 // If the device no longer exists, unblock it, else filter it out from our |
| 753 // active list. |
| 754 if (it == keyboards.end()) { |
| 755 unsigned int id = static_cast<int> ((*blocked_iter).first); |
| 756 blocked_devices_.set(id, false); |
| 757 blocked_keyboards_.erase(blocked_iter++); |
| 758 } else { |
| 759 keyboards.erase(it); |
| 760 ++blocked_iter; |
| 761 } |
| 762 } |
| 763 // Notify base class of updated list. |
| 764 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 765 } |
| 766 |
| 710 } // namespace ui | 767 } // namespace ui |
| OLD | NEW |