Chromium Code Reviews| Index: ui/events/x/device_data_manager_x11.cc |
| diff --git a/ui/events/x/device_data_manager_x11.cc b/ui/events/x/device_data_manager_x11.cc |
| index 795cc44be7b4af79def8f0bbfce52cdd02ea6664..476476042d9d952efa0268e3ccca26acf9cb8cb5 100644 |
| --- a/ui/events/x/device_data_manager_x11.cc |
| +++ b/ui/events/x/device_data_manager_x11.cc |
| @@ -8,11 +8,14 @@ |
| #include <X11/extensions/XInput2.h> |
| #include <X11/Xlib.h> |
| +#include <utility> |
| + |
| #include "base/logging.h" |
| #include "base/memory/singleton.h" |
| #include "base/sys_info.h" |
| #include "ui/events/event_constants.h" |
| #include "ui/events/event_switches.h" |
| +#include "ui/events/keyboard_device.h" |
| #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| #include "ui/events/x/device_list_cache_x.h" |
| #include "ui/events/x/touch_factory_x11.h" |
| @@ -106,6 +109,14 @@ const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; |
| namespace ui { |
| +namespace { |
| + |
| +bool HasId(ui::KeyboardDevice keyboard, int id) { |
|
sky
2014/10/20 22:18:44
Name this better, eg KeybardDeviceHasId. Also, can
rsadam
2014/10/21 16:53:52
Done.
|
| + return keyboard.id == id; |
| +} |
| + |
| +} // namespace |
| + |
| bool DeviceDataManagerX11::IsCMTDataType(const int type) { |
| return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); |
| } |
| @@ -681,10 +692,31 @@ void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
| void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { |
| blocked_devices_.set(deviceid, true); |
| + int id = static_cast<int>(deviceid); |
|
sky
2014/10/20 22:18:44
Why the static cast here? Shouldn't the types matc
rsadam
2014/10/21 16:53:52
The input types don't match - the existing logic i
sky
2014/10/21 18:15:32
Is there a reason InputDevices needs to be int? Ca
rsadam
2014/10/21 19:37:21
Done.
|
| + // TODO(rsadam@): Support blocking touchscreen devices. |
| + std::vector<KeyboardDevice> keyboards = keyboard_devices(); |
| + std::vector<KeyboardDevice>::iterator it = |
| + std::find_if(keyboards.begin(), keyboards.end(), std::bind2nd( |
| + std::ptr_fun(&HasId), id)); |
| + if (it != std::end(keyboards)) { |
| + blocked_keyboards_.insert(std::pair<int, KeyboardDevice>(id, *it)); |
| + keyboards.erase(it); |
| + DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| + } |
| } |
| void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { |
| blocked_devices_.set(deviceid, false); |
| + int id = static_cast<int>(deviceid); |
| + std::map<int, KeyboardDevice>::iterator it = |
| + blocked_keyboards_.find(id); |
| + if (it != blocked_keyboards_.end()) { |
| + std::vector<KeyboardDevice> devices = keyboard_devices(); |
| + // Add device to current list of active devices. |
| + devices.push_back((*it).second); |
| + blocked_keyboards_.erase(it); |
| + DeviceDataManager::OnKeyboardDevicesUpdated(devices); |
| + } |
| } |
| bool DeviceDataManagerX11::IsEventBlocked( |
| @@ -707,4 +739,29 @@ bool DeviceDataManagerX11::IsEventBlocked( |
| return blocked_devices_.test(xievent->sourceid); |
| } |
| +void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
| + const std::vector<KeyboardDevice>& devices) { |
| + std::vector<KeyboardDevice> keyboards(devices); |
| + std::map<int, KeyboardDevice>::iterator blocked_iter; |
| + for (blocked_iter = blocked_keyboards_.begin(); |
| + blocked_iter != blocked_keyboards_.end();) { |
| + // Check if the blocked device still exists in list of devices. |
| + std::vector<KeyboardDevice>::iterator it = |
| + std::find_if(keyboards.begin(), keyboards.end(), std::bind2nd( |
| + std::ptr_fun(&HasId), (*blocked_iter).first)); |
| + // If the device no longer exists, unblock it, else filter it out from our |
| + // active list. |
| + if (it == keyboards.end()) { |
| + unsigned int id = static_cast<int> ((*blocked_iter).first); |
|
sky
2014/10/20 22:18:44
Same comment about cast (and you've got an extra s
rsadam
2014/10/21 16:53:52
Done.
|
| + blocked_devices_.set(id, false); |
|
sky
2014/10/20 22:18:44
Why do you need to persist this?
rsadam
2014/10/21 16:53:52
This is the case that a device is blocked and then
sky
2014/10/21 18:15:32
I you guaranteed that the same device gets the sam
rsadam
2014/10/21 19:37:21
(Replied in message above)
|
| + blocked_keyboards_.erase(blocked_iter++); |
| + } else { |
| + keyboards.erase(it); |
| + ++blocked_iter; |
| + } |
| + } |
| + // Notify base class of updated list. |
| + DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| +} |
| + |
| } // namespace ui |