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..4f9473e73d0172ea6ccd8d5ca2e3a4c942b531de 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,20 @@ const int kTouchDataTypeEnd = ui::DeviceDataManagerX11::DT_TOUCH_RAW_TIMESTAMP; |
| namespace ui { |
| +namespace { |
| + |
| +bool HasId(ui::KeyboardDevice keyboard, unsigned int id) { |
| + return keyboard.id == static_cast<int>(id); |
| +} |
| + |
| +bool ShouldIgnoreKeyboard( |
| + ui::KeyboardDevice keyboard, |
| + const std::bitset<DeviceDataManagerX11::kMaxDeviceNum>& blocked_devices) { |
| + return blocked_devices.test(keyboard.id); |
| +} |
| + |
| +} // namespace |
| + |
| bool DeviceDataManagerX11::IsCMTDataType(const int type) { |
| return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd); |
| } |
| @@ -681,10 +698,29 @@ void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys( |
| void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) { |
| blocked_devices_.set(deviceid, true); |
| + // TODO(rsadam@): Support blocking touchscreen devices. |
| + std::vector<KeyboardDevice> keyboards = keyboard_devices(); |
| + std::vector<KeyboardDevice>::iterator it = |
| + std::find_if(keyboards.begin(), |
| + keyboards.end(), |
|
flackr
2014/10/08 21:58:11
nit: Don't need to wrap this.
rsadam
2014/10/09 05:19:03
Done.
|
| + std::bind2nd(std::ptr_fun(&HasId), deviceid)); |
| + if (it != std::end(keyboards)) { |
| + blocked_keyboards_.insert(std::pair<unsigned int, KeyboardDevice>( |
| + deviceid, |
| + *it)); |
| + OnKeyboardDevicesUpdated(keyboards); |
| + } |
| } |
| void DeviceDataManagerX11::EnableDevice(unsigned int deviceid) { |
| blocked_devices_.set(deviceid, false); |
| + std::map<unsigned int, KeyboardDevice>::iterator it = |
| + blocked_keyboards_.find(deviceid); |
| + if (it != blocked_keyboards_.end()) { |
| + std::vector<KeyboardDevice> devices = keyboard_devices(); |
| + 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
|
| + OnKeyboardDevicesUpdated(devices); |
| + } |
| } |
| bool DeviceDataManagerX11::IsEventBlocked( |
| @@ -707,4 +743,15 @@ bool DeviceDataManagerX11::IsEventBlocked( |
| return blocked_devices_.test(xievent->sourceid); |
| } |
| +void DeviceDataManagerX11::OnKeyboardDevicesUpdated( |
| + const std::vector<KeyboardDevice>& devices) { |
| + std::vector<KeyboardDevice> keyboards(devices); |
| + keyboards.erase( |
| + std::remove_if(keyboards.begin(), keyboards.end(), |
| + std::bind2nd( |
| + std::ptr_fun(&ShouldIgnoreKeyboard), blocked_devices_)), |
| + keyboards.end()); |
| + DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
| +} |
| + |
| } // namespace ui |