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 "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_switches.h" | 15 #include "ui/events/event_switches.h" |
| 16 #include "ui/events/keyboard_device.h" | |
| 16 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 17 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 17 #include "ui/events/x/device_list_cache_x.h" | 18 #include "ui/events/x/device_list_cache_x.h" |
| 18 #include "ui/events/x/touch_factory_x11.h" | 19 #include "ui/events/x/touch_factory_x11.h" |
| 19 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
| 20 #include "ui/gfx/point3_f.h" | 21 #include "ui/gfx/point3_f.h" |
| 21 #include "ui/gfx/x/x11_types.h" | 22 #include "ui/gfx/x/x11_types.h" |
| 22 | 23 |
| 23 // XIScrollClass was introduced in XI 2.1 so we need to define it here | 24 // XIScrollClass was introduced in XI 2.1 so we need to define it here |
| 24 // for backward-compatibility with older versions of XInput. | 25 // for backward-compatibility with older versions of XInput. |
| 25 #if !defined(XIScrollClass) | 26 #if !defined(XIScrollClass) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 | 100 |
| 100 // Constants for checking if a data type lies in the range of CMT/Touch data | 101 // Constants for checking if a data type lies in the range of CMT/Touch data |
| 101 // types. | 102 // types. |
| 102 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; | 103 const int kCMTDataTypeStart = ui::DeviceDataManagerX11::DT_CMT_SCROLL_X; |
| 103 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; | 104 const int kCMTDataTypeEnd = ui::DeviceDataManagerX11::DT_CMT_FINGER_COUNT; |
| 104 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; | 105 const int kTouchDataTypeStart = ui::DeviceDataManagerX11::DT_TOUCH_MAJOR; |
| 105 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; | 106 const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; |
| 106 | 107 |
| 107 namespace ui { | 108 namespace ui { |
| 108 | 109 |
| 110 namespace { | |
| 111 | |
| 112 bool ShouldIgnoreKeyboard( | |
| 113 ui::KeyboardDevice keyboard, | |
| 114 const std::bitset<DeviceDataManagerX11::kMaxDeviceNum>& blocked_devices) { | |
| 115 return blocked_devices.test(keyboard.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 OnTouchscreenDevicesUpdated(touchscreen_devices()); | |
| 696 OnKeyboardDevicesUpdated(keyboard_devices()); | |
| 684 } | 697 } |
| 685 | 698 |
| 686 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { | 699 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { |
| 687 blocked_devices_.set(deviceid, false); | 700 blocked_devices_.set(deviceid, false); |
| 701 OnTouchscreenDevicesUpdated(touchscreen_devices()); | |
| 702 OnKeyboardDevicesUpdated(keyboard_devices()); | |
|
flackr
2014/10/07 13:30:15
Can you add a test to ensure enable/disable correc
rsadam
2014/10/07 22:00:36
Done.
| |
| 688 } | 703 } |
| 689 | 704 |
| 690 bool DeviceDataManagerX11::IsEventBlocked( | 705 bool DeviceDataManagerX11::IsEventBlocked( |
| 691 const base::NativeEvent& native_event) { | 706 const base::NativeEvent& native_event) { |
| 692 // Only check XI2 events which have a source device id. | 707 // Only check XI2 events which have a source device id. |
| 693 if (native_event->type != GenericEvent) | 708 if (native_event->type != GenericEvent) |
| 694 return false; | 709 return false; |
| 695 | 710 |
| 696 XIDeviceEvent* xievent = | 711 XIDeviceEvent* xievent = |
| 697 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 712 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 698 // Allow any key events from blocked_keyboard_allowed_keys_. | 713 // Allow any key events from blocked_keyboard_allowed_keys_. |
| 699 if (blocked_keyboard_allowed_keys_ && | 714 if (blocked_keyboard_allowed_keys_ && |
| 700 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && | 715 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
| 701 blocked_keyboard_allowed_keys_->find( | 716 blocked_keyboard_allowed_keys_->find( |
| 702 KeyboardCodeFromXKeyEvent(native_event)) != | 717 KeyboardCodeFromXKeyEvent(native_event)) != |
| 703 blocked_keyboard_allowed_keys_->end()) { | 718 blocked_keyboard_allowed_keys_->end()) { |
| 704 return false; | 719 return false; |
| 705 } | 720 } |
| 706 | 721 |
| 707 return blocked_devices_.test(xievent->sourceid); | 722 return blocked_devices_.test(xievent->sourceid); |
| 708 } | 723 } |
| 709 | 724 |
| 725 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( | |
| 726 const std::vector<KeyboardDevice>& devices) { | |
| 727 std::vector<KeyboardDevice> keyboards(devices); | |
| 728 keyboards.erase( | |
| 729 std::remove_if(keyboards.begin(), keyboards.end(), | |
| 730 std::bind2nd( | |
| 731 std::ptr_fun(&ShouldIgnoreKeyboard), blocked_devices_)), | |
| 732 keyboards.end()); | |
| 733 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | |
| 734 } | |
| 735 | |
| 710 } // namespace ui | 736 } // namespace ui |
| OLD | NEW |