Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: ui/events/x/device_data_manager_x11.cc

Issue 618283003: Adds special support to the device manager for keyboards devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix blocked devices not updating. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, unsigned int id) {
115 return keyboard.id == static_cast<int>(id);
116 }
117
118 bool ShouldIgnoreKeyboard(
119 ui::KeyboardDevice keyboard,
120 const std::bitset<DeviceDataManagerX11::kMaxDeviceNum>& blocked_devices) {
121 return blocked_devices.test(keyboard.id);
122 }
123
124 } // namespace
125
109 bool DeviceDataManagerX11::IsCMTDataType(const int type) { 126 bool DeviceDataManagerX11::IsCMTDataType(const int type) {
110 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); 127 return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd);
111 } 128 }
112 129
113 bool DeviceDataManagerX11::IsTouchDataType(const int type) { 130 bool DeviceDataManagerX11::IsTouchDataType(const int type) {
114 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd); 131 return (type >= kTouchDataTypeStart) && (type <= kTouchDataTypeEnd);
115 } 132 }
116 133
117 // static 134 // static
118 void DeviceDataManagerX11::CreateInstance() { 135 void DeviceDataManagerX11::CreateInstance() {
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 691
675 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( 692 void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys(
676 scoped_ptr<std::set<KeyboardCode> > excepted_keys) { 693 scoped_ptr<std::set<KeyboardCode> > excepted_keys) {
677 DCHECK(!excepted_keys.get() || 694 DCHECK(!excepted_keys.get() ||
678 !blocked_keyboard_allowed_keys_.get()); 695 !blocked_keyboard_allowed_keys_.get());
679 blocked_keyboard_allowed_keys_ = excepted_keys.Pass(); 696 blocked_keyboard_allowed_keys_ = excepted_keys.Pass();
680 } 697 }
681 698
682 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { 699 void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) {
683 blocked_devices_.set(deviceid, true); 700 blocked_devices_.set(deviceid, true);
701 // TODO(rsadam@): Support blocking touchscreen devices.
702 std::vector<KeyboardDevice> keyboards = keyboard_devices();
703 std::vector<KeyboardDevice>::iterator it =
704 std::find_if(keyboards.begin(),
705 keyboards.end(),
flackr 2014/10/08 21:58:11 nit: Don't need to wrap this.
rsadam 2014/10/09 05:19:03 Done.
706 std::bind2nd(std::ptr_fun(&HasId), deviceid));
707 if (it != std::end(keyboards)) {
708 blocked_keyboards_.insert(std::pair<unsigned int, KeyboardDevice>(
709 deviceid,
710 *it));
711 OnKeyboardDevicesUpdated(keyboards);
712 }
684 } 713 }
685 714
686 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { 715 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) {
687 blocked_devices_.set(deviceid, false); 716 blocked_devices_.set(deviceid, false);
717 std::map<unsigned int, KeyboardDevice>::iterator it =
718 blocked_keyboards_.find(deviceid);
719 if (it != blocked_keyboards_.end()) {
720 std::vector<KeyboardDevice> devices = keyboard_devices();
721 devices.push_back(it->second);
flackr 2014/10/08 21:58:11 Hmm, what if a device changes, or is removed while
rsadam 2014/10/09 05:19:03 Handled that case with a slight variation of what
722 OnKeyboardDevicesUpdated(devices);
723 }
688 } 724 }
689 725
690 bool DeviceDataManagerX11::IsEventBlocked( 726 bool DeviceDataManagerX11::IsEventBlocked(
691 const base::NativeEvent& native_event) { 727 const base::NativeEvent& native_event) {
692 // Only check XI2 events which have a source device id. 728 // Only check XI2 events which have a source device id.
693 if (native_event->type != GenericEvent) 729 if (native_event->type != GenericEvent)
694 return false; 730 return false;
695 731
696 XIDeviceEvent* xievent = 732 XIDeviceEvent* xievent =
697 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 733 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
698 // Allow any key events from blocked_keyboard_allowed_keys_. 734 // Allow any key events from blocked_keyboard_allowed_keys_.
699 if (blocked_keyboard_allowed_keys_ && 735 if (blocked_keyboard_allowed_keys_ &&
700 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && 736 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) &&
701 blocked_keyboard_allowed_keys_->find( 737 blocked_keyboard_allowed_keys_->find(
702 KeyboardCodeFromXKeyEvent(native_event)) != 738 KeyboardCodeFromXKeyEvent(native_event)) !=
703 blocked_keyboard_allowed_keys_->end()) { 739 blocked_keyboard_allowed_keys_->end()) {
704 return false; 740 return false;
705 } 741 }
706 742
707 return blocked_devices_.test(xievent->sourceid); 743 return blocked_devices_.test(xievent->sourceid);
708 } 744 }
709 745
746 void DeviceDataManagerX11::OnKeyboardDevicesUpdated(
747 const std::vector<KeyboardDevice>& devices) {
748 std::vector<KeyboardDevice> keyboards(devices);
749 keyboards.erase(
750 std::remove_if(keyboards.begin(), keyboards.end(),
751 std::bind2nd(
752 std::ptr_fun(&ShouldIgnoreKeyboard), blocked_devices_)),
753 keyboards.end());
754 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards);
755 }
756
710 } // namespace ui 757 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698