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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3fe2d744c2e29ab9eaa60b6e6087fbb7711f6f01 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) {
+ return keyboard.id == id;
+}
+
+} // namespace
+
bool DeviceDataManagerX11::IsCMTDataType(const int type) {
return (type >= kCMTDataTypeStart) && (type <= kCMTDataTypeEnd);
}
@@ -680,11 +691,34 @@ void DeviceDataManagerX11::SetDisabledKeyboardAllowedKeys(
}
void DeviceDataManagerX11::DisableDevice(unsigned int deviceid) {
+ 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.
blocked_devices_.set(deviceid, true);
+ int id = static_cast<int>(deviceid);
+ // 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,
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.
+ *it));
+ 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.
+ }
}
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);
+ OnKeyboardDevicesUpdated(devices);
+ }
}
bool DeviceDataManagerX11::IsEventBlocked(
@@ -707,4 +741,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);
+ blocked_devices_.set(id, false);
+ 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.
+ } else {
+ keyboards.erase(it);
+ ++blocked_iter;
+ }
+ }
+ // Notify base class of updated list.
+ DeviceDataManager::OnKeyboardDevicesUpdated(keyboards);
+}
+
} // namespace ui
« 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