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_keyboard_devices_.insert( |
826 std::pair<int, KeyboardDevice>(deviceid, *it)); | 825 std::pair<int, InputDevice>(deviceid, *it)); |
827 keyboards.erase(it); | 826 keyboards.erase(it); |
828 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 827 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
829 } | 828 } |
830 } | 829 } |
831 | 830 |
832 void DeviceDataManagerX11::EnableDevice(int deviceid) { | 831 void DeviceDataManagerX11::EnableDevice(int deviceid) { |
833 blocked_devices_.set(deviceid, false); | 832 blocked_devices_.set(deviceid, false); |
834 std::map<int, KeyboardDevice>::iterator it = | 833 std::map<int, InputDevice>::iterator it = |
835 blocked_keyboards_.find(deviceid); | 834 blocked_keyboard_devices_.find(deviceid); |
836 if (it != blocked_keyboards_.end()) { | 835 if (it != blocked_keyboard_devices_.end()) { |
837 std::vector<KeyboardDevice> devices = keyboard_devices(); | 836 std::vector<InputDevice> devices = keyboard_devices(); |
838 // Add device to current list of active devices. | 837 // Add device to current list of active devices. |
839 devices.push_back((*it).second); | 838 devices.push_back((*it).second); |
840 blocked_keyboards_.erase(it); | 839 blocked_keyboard_devices_.erase(it); |
841 DeviceDataManager::OnKeyboardDevicesUpdated(devices); | 840 DeviceDataManager::OnKeyboardDevicesUpdated(devices); |
842 } | 841 } |
843 } | 842 } |
844 | 843 |
845 bool DeviceDataManagerX11::IsDeviceEnabled(int device_id) const { | 844 bool DeviceDataManagerX11::IsDeviceEnabled(int device_id) const { |
846 return blocked_devices_.test(device_id); | 845 return blocked_devices_.test(device_id); |
847 } | 846 } |
848 | 847 |
849 bool DeviceDataManagerX11::IsEventBlocked(const XEvent& xev) { | 848 bool DeviceDataManagerX11::IsEventBlocked(const XEvent& xev) { |
850 // Only check XI2 events which have a source device id. | 849 // Only check XI2 events which have a source device id. |
851 if (xev.type != GenericEvent) | 850 if (xev.type != GenericEvent) |
852 return false; | 851 return false; |
853 | 852 |
854 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev.xcookie.data); | 853 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
855 // Allow any key events from blocked_keyboard_allowed_keys_. | 854 // Allow any key events from blocked_keyboard_allowed_keys_. |
856 if (blocked_keyboard_allowed_keys_ && | 855 if (blocked_keyboard_allowed_keys_ && |
857 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && | 856 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
858 blocked_keyboard_allowed_keys_->find(KeyboardCodeFromXKeyEvent(&xev)) != | 857 blocked_keyboard_allowed_keys_->find(KeyboardCodeFromXKeyEvent(&xev)) != |
859 blocked_keyboard_allowed_keys_->end()) { | 858 blocked_keyboard_allowed_keys_->end()) { |
860 return false; | 859 return false; |
861 } | 860 } |
862 | 861 |
863 return blocked_devices_.test(xievent->sourceid); | 862 return blocked_devices_.test(xievent->sourceid); |
864 } | 863 } |
865 | 864 |
866 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( | 865 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
867 const std::vector<KeyboardDevice>& devices) { | 866 const std::vector<InputDevice>& devices) { |
868 std::vector<KeyboardDevice> keyboards(devices); | 867 std::vector<InputDevice> keyboards(devices); |
869 for (std::map<int, KeyboardDevice>::iterator blocked_iter = | 868 for (std::map<int, InputDevice>::iterator blocked_iter = |
870 blocked_keyboards_.begin(); | 869 blocked_keyboard_devices_.begin(); |
871 blocked_iter != blocked_keyboards_.end();) { | 870 blocked_iter != blocked_keyboard_devices_.end();) { |
872 // Check if the blocked device still exists in list of devices. | 871 // Check if the blocked device still exists in list of devices. |
873 int device_id = blocked_iter->first; | 872 int device_id = blocked_iter->first; |
874 std::vector<KeyboardDevice>::iterator it = | 873 std::vector<InputDevice>::iterator it = |
875 FindDeviceWithId(keyboards.begin(), keyboards.end(), device_id); | 874 FindDeviceWithId(keyboards.begin(), keyboards.end(), device_id); |
876 // If the device no longer exists, unblock it, else filter it out from our | 875 // If the device no longer exists, unblock it, else filter it out from our |
877 // active list. | 876 // active list. |
878 if (it == keyboards.end()) { | 877 if (it == keyboards.end()) { |
879 blocked_devices_.set((*blocked_iter).first, false); | 878 blocked_devices_.set((*blocked_iter).first, false); |
880 blocked_keyboards_.erase(blocked_iter++); | 879 blocked_keyboard_devices_.erase(blocked_iter++); |
881 } else { | 880 } else { |
882 keyboards.erase(it); | 881 keyboards.erase(it); |
883 ++blocked_iter; | 882 ++blocked_iter; |
884 } | 883 } |
885 } | 884 } |
886 // Notify base class of updated list. | 885 // Notify base class of updated list. |
887 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 886 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
888 } | 887 } |
889 | 888 |
890 } // namespace ui | 889 } // namespace ui |
OLD | NEW |