| 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> |
| 11 | 11 |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/singleton.h" | 18 #include "base/memory/singleton.h" |
| 19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
| 22 #include "ui/events/devices/keyboard_device.h" | |
| 23 #include "ui/events/devices/x11/device_list_cache_x11.h" | 22 #include "ui/events/devices/x11/device_list_cache_x11.h" |
| 24 #include "ui/events/devices/x11/touch_factory_x11.h" | 23 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 25 #include "ui/events/event_constants.h" | 24 #include "ui/events/event_constants.h" |
| 26 #include "ui/events/event_switches.h" | 25 #include "ui/events/event_switches.h" |
| 27 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 26 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 28 #include "ui/gfx/geometry/point3_f.h" | 27 #include "ui/gfx/geometry/point3_f.h" |
| 29 #include "ui/gfx/x/x11_types.h" | 28 #include "ui/gfx/x/x11_types.h" |
| 30 | 29 |
| 31 // XIScrollClass was introduced in XI 2.1 so we need to define it here | 30 // XIScrollClass was introduced in XI 2.1 so we need to define it here |
| 32 // for backward-compatibility with older versions of XInput. | 31 // for backward-compatibility with older versions of XInput. |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( | 810 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
| 812 std::unique_ptr<std::set<KeyboardCode>> excepted_keys) { | 811 std::unique_ptr<std::set<KeyboardCode>> excepted_keys) { |
| 813 DCHECK(!excepted_keys.get() || | 812 DCHECK(!excepted_keys.get() || |
| 814 !blocked_keyboard_allowed_keys_.get()); | 813 !blocked_keyboard_allowed_keys_.get()); |
| 815 blocked_keyboard_allowed_keys_ = std::move(excepted_keys); | 814 blocked_keyboard_allowed_keys_ = std::move(excepted_keys); |
| 816 } | 815 } |
| 817 | 816 |
| 818 void DeviceDataManagerX11::DisableDevice(int deviceid) { | 817 void DeviceDataManagerX11::DisableDevice(int deviceid) { |
| 819 blocked_devices_.set(deviceid, true); | 818 blocked_devices_.set(deviceid, true); |
| 820 // TODO(rsadam@): Support blocking touchscreen devices. | 819 // TODO(rsadam@): Support blocking touchscreen devices. |
| 821 std::vector<KeyboardDevice> keyboards = keyboard_devices(); | 820 std::vector<InputDevice> keyboards = keyboard_devices(); |
| 822 std::vector<KeyboardDevice>::iterator it = | 821 std::vector<InputDevice>::iterator it = |
| 823 FindDeviceWithId(keyboards.begin(), keyboards.end(), deviceid); | 822 FindDeviceWithId(keyboards.begin(), keyboards.end(), deviceid); |
| 824 if (it != std::end(keyboards)) { | 823 if (it != std::end(keyboards)) { |
| 825 blocked_keyboards_.insert( | 824 blocked_keyboards_.insert(std::pair<int, InputDevice>(deviceid, *it)); |
| 826 std::pair<int, KeyboardDevice>(deviceid, *it)); | |
| 827 keyboards.erase(it); | 825 keyboards.erase(it); |
| 828 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 826 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 829 } | 827 } |
| 830 } | 828 } |
| 831 | 829 |
| 832 void DeviceDataManagerX11::EnableDevice(int deviceid) { | 830 void DeviceDataManagerX11::EnableDevice(int deviceid) { |
| 833 blocked_devices_.set(deviceid, false); | 831 blocked_devices_.set(deviceid, false); |
| 834 std::map<int, KeyboardDevice>::iterator it = | 832 std::map<int, InputDevice>::iterator it = blocked_keyboards_.find(deviceid); |
| 835 blocked_keyboards_.find(deviceid); | |
| 836 if (it != blocked_keyboards_.end()) { | 833 if (it != blocked_keyboards_.end()) { |
| 837 std::vector<KeyboardDevice> devices = keyboard_devices(); | 834 std::vector<InputDevice> devices = keyboard_devices(); |
| 838 // Add device to current list of active devices. | 835 // Add device to current list of active devices. |
| 839 devices.push_back((*it).second); | 836 devices.push_back((*it).second); |
| 840 blocked_keyboards_.erase(it); | 837 blocked_keyboards_.erase(it); |
| 841 DeviceDataManager::OnKeyboardDevicesUpdated(devices); | 838 DeviceDataManager::OnKeyboardDevicesUpdated(devices); |
| 842 } | 839 } |
| 843 } | 840 } |
| 844 | 841 |
| 845 bool DeviceDataManagerX11::IsDeviceEnabled(int device_id) const { | 842 bool DeviceDataManagerX11::IsDeviceEnabled(int device_id) const { |
| 846 return blocked_devices_.test(device_id); | 843 return blocked_devices_.test(device_id); |
| 847 } | 844 } |
| 848 | 845 |
| 849 bool DeviceDataManagerX11::IsEventBlocked(const XEvent& xev) { | 846 bool DeviceDataManagerX11::IsEventBlocked(const XEvent& xev) { |
| 850 // Only check XI2 events which have a source device id. | 847 // Only check XI2 events which have a source device id. |
| 851 if (xev.type != GenericEvent) | 848 if (xev.type != GenericEvent) |
| 852 return false; | 849 return false; |
| 853 | 850 |
| 854 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev.xcookie.data); | 851 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
| 855 // Allow any key events from blocked_keyboard_allowed_keys_. | 852 // Allow any key events from blocked_keyboard_allowed_keys_. |
| 856 if (blocked_keyboard_allowed_keys_ && | 853 if (blocked_keyboard_allowed_keys_ && |
| 857 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && | 854 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
| 858 blocked_keyboard_allowed_keys_->find(KeyboardCodeFromXKeyEvent(&xev)) != | 855 blocked_keyboard_allowed_keys_->find(KeyboardCodeFromXKeyEvent(&xev)) != |
| 859 blocked_keyboard_allowed_keys_->end()) { | 856 blocked_keyboard_allowed_keys_->end()) { |
| 860 return false; | 857 return false; |
| 861 } | 858 } |
| 862 | 859 |
| 863 return blocked_devices_.test(xievent->sourceid); | 860 return blocked_devices_.test(xievent->sourceid); |
| 864 } | 861 } |
| 865 | 862 |
| 866 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( | 863 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
| 867 const std::vector<KeyboardDevice>& devices) { | 864 const std::vector<InputDevice>& devices) { |
| 868 std::vector<KeyboardDevice> keyboards(devices); | 865 std::vector<InputDevice> keyboards(devices); |
| 869 for (std::map<int, KeyboardDevice>::iterator blocked_iter = | 866 for (std::map<int, InputDevice>::iterator blocked_iter = |
| 870 blocked_keyboards_.begin(); | 867 blocked_keyboards_.begin(); |
| 871 blocked_iter != blocked_keyboards_.end();) { | 868 blocked_iter != blocked_keyboards_.end();) { |
| 872 // Check if the blocked device still exists in list of devices. | 869 // Check if the blocked device still exists in list of devices. |
| 873 int device_id = blocked_iter->first; | 870 int device_id = blocked_iter->first; |
| 874 std::vector<KeyboardDevice>::iterator it = | 871 std::vector<InputDevice>::iterator it = |
| 875 FindDeviceWithId(keyboards.begin(), keyboards.end(), device_id); | 872 FindDeviceWithId(keyboards.begin(), keyboards.end(), device_id); |
| 876 // If the device no longer exists, unblock it, else filter it out from our | 873 // If the device no longer exists, unblock it, else filter it out from our |
| 877 // active list. | 874 // active list. |
| 878 if (it == keyboards.end()) { | 875 if (it == keyboards.end()) { |
| 879 blocked_devices_.set((*blocked_iter).first, false); | 876 blocked_devices_.set((*blocked_iter).first, false); |
| 880 blocked_keyboards_.erase(blocked_iter++); | 877 blocked_keyboards_.erase(blocked_iter++); |
| 881 } else { | 878 } else { |
| 882 keyboards.erase(it); | 879 keyboards.erase(it); |
| 883 ++blocked_iter; | 880 ++blocked_iter; |
| 884 } | 881 } |
| 885 } | 882 } |
| 886 // Notify base class of updated list. | 883 // Notify base class of updated list. |
| 887 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 884 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| 888 } | 885 } |
| 889 | 886 |
| 890 } // namespace ui | 887 } // namespace ui |
| OLD | NEW |