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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 | 675 |
| 675 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( | 676 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
| 676 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { | 677 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { |
| 677 DCHECK(!excepted_keys.get() || | 678 DCHECK(!excepted_keys.get() || |
| 678 !blocked_keyboard_allowed_keys_.get()); | 679 !blocked_keyboard_allowed_keys_.get()); |
| 679 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); | 680 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); |
| 680 } | 681 } |
| 681 | 682 |
| 682 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { | 683 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { |
| 683 blocked_devices_.set(deviceid, true); | 684 blocked_devices_.set(deviceid, true); |
| 685 OnTouchscreenDevicesUpdated(touchscreen_devices()); | |
| 686 OnKeyboardDevicesUpdated(keyboard_devices()); | |
| 684 } | 687 } |
| 685 | 688 |
| 686 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { | 689 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { |
| 687 blocked_devices_.set(deviceid, false); | 690 blocked_devices_.set(deviceid, false); |
| 691 OnTouchscreenDevicesUpdated(touchscreen_devices()); | |
| 692 OnKeyboardDevicesUpdated(keyboard_devices()); | |
| 688 } | 693 } |
| 689 | 694 |
| 690 bool DeviceDataManagerX11::IsEventBlocked( | 695 bool DeviceDataManagerX11::IsEventBlocked( |
| 691 const base::NativeEvent& native_event) { | 696 const base::NativeEvent& native_event) { |
| 692 // Only check XI2 events which have a source device id. | 697 // Only check XI2 events which have a source device id. |
| 693 if (native_event->type != GenericEvent) | 698 if (native_event->type != GenericEvent) |
| 694 return false; | 699 return false; |
| 695 | 700 |
| 696 XIDeviceEvent* xievent = | 701 XIDeviceEvent* xievent = |
| 697 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 702 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| 698 // Allow any key events from blocked_keyboard_allowed_keys_. | 703 // Allow any key events from blocked_keyboard_allowed_keys_. |
| 699 if (blocked_keyboard_allowed_keys_ && | 704 if (blocked_keyboard_allowed_keys_ && |
| 700 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && | 705 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && |
| 701 blocked_keyboard_allowed_keys_->find( | 706 blocked_keyboard_allowed_keys_->find( |
| 702 KeyboardCodeFromXKeyEvent(native_event)) != | 707 KeyboardCodeFromXKeyEvent(native_event)) != |
| 703 blocked_keyboard_allowed_keys_->end()) { | 708 blocked_keyboard_allowed_keys_->end()) { |
| 704 return false; | 709 return false; |
| 705 } | 710 } |
| 706 | 711 |
| 707 return blocked_devices_.test(xievent->sourceid); | 712 return blocked_devices_.test(xievent->sourceid); |
| 708 } | 713 } |
| 709 | 714 |
| 715 bool DeviceDataManagerX11::ShouldIgnoreKeyboard( | |
| 716 const ui::KeyboardDevice keyboard, DeviceDataManagerX11* manager) { | |
|
pkotwicz
2014/10/05 18:53:02
As a general rule we either pass in a const refere
rsadam
2014/10/06 15:40:17
Done.
| |
| 717 return manager->blocked_devices_.test(keyboard.id); | |
| 718 } | |
| 719 | |
| 720 void DeviceDataManagerX11::OnKeyboardDevicesUpdated( | |
| 721 const std::vector<KeyboardDevice>& devices) { | |
| 722 std::vector<KeyboardDevice> keyboards(devices); | |
| 723 keyboards.erase( | |
| 724 std::remove_if(keyboards.begin(), keyboards.end(), | |
| 725 std::bind2nd( | |
| 726 std::ptr_fun(&DeviceDataManagerX11::ShouldIgnoreKeyboard), | |
| 727 this)), | |
| 728 keyboards.end()); | |
| 729 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | |
| 730 } | |
| 731 | |
| 710 } // namespace ui | 732 } // namespace ui |
| OLD | NEW |