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

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: Handle blocked devices being unplugged in and out + unittests. 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
« no previous file with comments | « ui/events/x/device_data_manager_x11.h ('k') | ui/events/x/device_data_manager_x11_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, int id) {
115 return keyboard.id == 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 } 684 }
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) {
694 LOG(ERROR) << "Disable the device:" << deviceid;
flackr 2014/10/10 17:49:31 Remove this, not an error.
rsadam 2014/10/14 17:32:19 Oops. Fixed.
683 blocked_devices_.set(deviceid, true); 695 blocked_devices_.set(deviceid, true);
696 int id = static_cast<int>(deviceid);
697 // TODO(rsadam@): Support blocking touchscreen devices.
698 std::vector<KeyboardDevice> keyboards = keyboard_devices();
699 std::vector<KeyboardDevice>::iterator it =
700 std::find_if(keyboards.begin(), keyboards.end(), std::bind2nd(
701 std::ptr_fun(&HasId), id));
702 if (it != std::end(keyboards)) {
703 blocked_keyboards_.insert(std::pair<int, KeyboardDevice>(
704 id,
flackr 2014/10/10 17:49:31 you can also just write blocked_keyboards_[id] = *
rsadam 2014/10/14 17:32:19 As discussed offline, would require copy construct
flackr 2014/10/14 17:41:35 Acknowledged, no need to wrap id, *it.
705 *it));
706 OnKeyboardDevicesUpdated(keyboards);
flackr 2014/10/10 17:49:30 OnKeyboardDevices assumes it is getting the full l
rsadam 2014/10/14 17:32:18 Done.
flackr 2014/10/14 17:41:35 Test?
rsadam 2014/10/14 17:55:01 Done.
707 }
684 } 708 }
685 709
686 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { 710 void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) {
687 blocked_devices_.set(deviceid, false); 711 blocked_devices_.set(deviceid, false);
712 int id = static_cast<int>(deviceid);
713 std::map<int, KeyboardDevice>::iterator it =
714 blocked_keyboards_.find(id);
715 if (it != blocked_keyboards_.end()) {
716 std::vector<KeyboardDevice> devices = keyboard_devices();
717 // Add device to current list of active devices.
718 devices.push_back((*it).second);
719 blocked_keyboards_.erase(it);
720 OnKeyboardDevicesUpdated(devices);
721 }
688 } 722 }
689 723
690 bool DeviceDataManagerX11::IsEventBlocked( 724 bool DeviceDataManagerX11::IsEventBlocked(
691 const base::NativeEvent& native_event) { 725 const base::NativeEvent& native_event) {
692 // Only check XI2 events which have a source device id. 726 // Only check XI2 events which have a source device id.
693 if (native_event->type != GenericEvent) 727 if (native_event->type != GenericEvent)
694 return false; 728 return false;
695 729
696 XIDeviceEvent* xievent = 730 XIDeviceEvent* xievent =
697 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 731 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
698 // Allow any key events from blocked_keyboard_allowed_keys_. 732 // Allow any key events from blocked_keyboard_allowed_keys_.
699 if (blocked_keyboard_allowed_keys_ && 733 if (blocked_keyboard_allowed_keys_ &&
700 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) && 734 (xievent->evtype == XI_KeyPress || xievent->evtype == XI_KeyRelease) &&
701 blocked_keyboard_allowed_keys_->find( 735 blocked_keyboard_allowed_keys_->find(
702 KeyboardCodeFromXKeyEvent(native_event)) != 736 KeyboardCodeFromXKeyEvent(native_event)) !=
703 blocked_keyboard_allowed_keys_->end()) { 737 blocked_keyboard_allowed_keys_->end()) {
704 return false; 738 return false;
705 } 739 }
706 740
707 return blocked_devices_.test(xievent->sourceid); 741 return blocked_devices_.test(xievent->sourceid);
708 } 742 }
709 743
744 void DeviceDataManagerX11::OnKeyboardDevicesUpdated(
745 const std::vector<KeyboardDevice>& devices) {
746 std::vector<KeyboardDevice> keyboards(devices);
747 std::map<int, KeyboardDevice>::iterator blocked_iter;
748 for (blocked_iter = blocked_keyboards_.begin();
749 blocked_iter != blocked_keyboards_.end();) {
750 // Check if the blocked device still exists in list of devices.
751 std::vector<KeyboardDevice>::iterator it =
752 std::find_if(keyboards.begin(), keyboards.end(), std::bind2nd(
753 std::ptr_fun(&HasId), (*blocked_iter).first));
754 // If the device no longer exists, unblock it, else filter it out from our
755 // active list.
756 if (it == keyboards.end()) {
757 unsigned int id = static_cast<int> ((*blocked_iter).first);
758 blocked_devices_.set(id, false);
759 blocked_keyboards_.erase(blocked_iter++);
flackr 2014/10/10 17:49:31 This is not correct. std::vector::erase invalidate
rsadam 2014/10/14 17:32:19 blocked_iter is a std::map::iter, and so as we dis
flackr 2014/10/14 17:41:35 Acknowledged.
760 } else {
761 keyboards.erase(it);
762 ++blocked_iter;
763 }
764 }
765 // Notify base class of updated list.
766 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards);
767 }
768
710 } // namespace ui 769 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/x/device_data_manager_x11.h ('k') | ui/events/x/device_data_manager_x11_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698