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

Unified Diff: chrome/browser/chromeos/events/event_rewriter.cc

Issue 1097393011: Revert of Ozone support for device special cases in keyboard event rewriting. (patchset #6 id:12000… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 | « ash/virtual_keyboard_controller_unittest.cc ('k') | ui/events/devices/input_device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/events/event_rewriter.cc
diff --git a/chrome/browser/chromeos/events/event_rewriter.cc b/chrome/browser/chromeos/events/event_rewriter.cc
index e35bdae02167a4ab76b4199fbcddabd19912adb7..b0b8531d9c45aa7a163dd4718b60bf83e0102d2d 100644
--- a/chrome/browser/chromeos/events/event_rewriter.cc
+++ b/chrome/browser/chromeos/events/event_rewriter.cc
@@ -23,7 +23,6 @@
#include "components/user_manager/user_manager.h"
#include "ui/base/ime/chromeos/ime_keyboard.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
-#include "ui/events/devices/device_data_manager.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
@@ -31,8 +30,13 @@
#if defined(USE_X11)
#include <X11/extensions/XInput2.h>
+#include <X11/Xatom.h>
#include <X11/Xlib.h>
+#ifndef XI_PROP_PRODUCT_ID
+#define XI_PROP_PRODUCT_ID "Device Product ID"
+#endif
+
// Get rid of macros from Xlib.h that conflicts with other parts of the code.
#undef RootWindow
#undef Status
@@ -932,17 +936,73 @@ EventRewriter::DeviceType EventRewriter::KeyboardDeviceAddedInternal(
}
EventRewriter::DeviceType EventRewriter::KeyboardDeviceAdded(int device_id) {
- if (!ui::DeviceDataManager::HasInstance())
+#if defined(USE_X11)
+ DCHECK_NE(XIAllDevices, device_id);
+ DCHECK_NE(XIAllMasterDevices, device_id);
+ if (device_id == XIAllDevices || device_id == XIAllMasterDevices) {
+ LOG(ERROR) << "Unexpected device_id passed: " << device_id;
+ return kDeviceUnknown;
+ }
+
+ Atom product_id_atom =
+ XInternAtom(gfx::GetXDisplay(), XI_PROP_PRODUCT_ID, 1);
+
+ int ndevices_return = 0;
+ XIDeviceInfo* device_info =
+ XIQueryDevice(gfx::GetXDisplay(), device_id, &ndevices_return);
+
+ // Since |device_id| is neither XIAllDevices nor XIAllMasterDevices,
+ // the number of devices found should be either 0 (not found) or 1.
+ if (!device_info) {
+ LOG(ERROR) << "XIQueryDevice: Device ID " << device_id << " is unknown.";
return kDeviceUnknown;
- const std::vector<ui::KeyboardDevice>& keyboards =
- ui::DeviceDataManager::GetInstance()->keyboard_devices();
- for (const auto& keyboard : keyboards) {
- if (keyboard.id == device_id) {
- return KeyboardDeviceAddedInternal(
- keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id);
- }
}
- return kDeviceUnknown;
+
+ DeviceType dev_type = kDeviceUnknown;
+ DCHECK_EQ(1, ndevices_return);
+ for (int i = 0; i < ndevices_return; ++i) {
+ // Get keyboard product and vendor id.
+ int vendor_id = kUnknownVendorId;
+ int product_id = kUnknownProductId;
+ uint32* product_info = NULL;
+ Atom type;
+ int format_return;
+ unsigned long num_items_return;
+ unsigned long bytes_after_return;
+ if (XIGetProperty(gfx::GetXDisplay(),
+ device_info[i].deviceid,
+ product_id_atom,
+ 0,
+ 2,
+ 0,
+ XA_INTEGER,
+ &type,
+ &format_return,
+ &num_items_return,
+ &bytes_after_return,
+ reinterpret_cast<unsigned char **>(&product_info)) == 0 &&
+ product_info) {
+ vendor_id = product_info[0];
+ product_id = product_info[1];
+ }
+
+ DCHECK_EQ(device_id, device_info[i].deviceid); // see the comment above.
+ DCHECK(device_info[i].name);
+ dev_type = KeyboardDeviceAddedInternal(device_info[i].deviceid,
+ device_info[i].name,
+ vendor_id,
+ product_id);
+ }
+ XIFreeDeviceInfo(device_info);
+ return dev_type;
+#else
+ // TODO(spang): Figure out where we can get keyboard vendor/product id from in
+ // Ozone/Freon version.
+ return KeyboardDeviceAddedInternal(device_id,
+ "keyboard",
+ kUnknownVendorId,
+ kUnknownProductId);
+#endif
}
} // namespace chromeos
« no previous file with comments | « ash/virtual_keyboard_controller_unittest.cc ('k') | ui/events/devices/input_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698