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

Side by Side Diff: chrome/browser/chromeos/events/event_rewriter.cc

Issue 1073573002: Ozone support for device special cases in keyboard event rewriting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix crash (thanks spang) 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 unified diff | 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 »
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 "chrome/browser/chromeos/events/event_rewriter.h" 5 #include "chrome/browser/chromeos/events/event_rewriter.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/sticky_keys/sticky_keys_controller.h" 9 #include "ash/sticky_keys/sticky_keys_controller.h"
10 #include "ash/wm/window_state.h" 10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/sys_info.h" 17 #include "base/sys_info.h"
18 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" 18 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
19 #include "chrome/browser/extensions/extension_commands_global_registry.h" 19 #include "chrome/browser/extensions/extension_commands_global_registry.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chromeos/chromeos_switches.h" 22 #include "chromeos/chromeos_switches.h"
23 #include "components/user_manager/user_manager.h" 23 #include "components/user_manager/user_manager.h"
24 #include "ui/base/ime/chromeos/ime_keyboard.h" 24 #include "ui/base/ime/chromeos/ime_keyboard.h"
25 #include "ui/base/ime/chromeos/input_method_manager.h" 25 #include "ui/base/ime/chromeos/input_method_manager.h"
26 #include "ui/events/devices/device_data_manager.h"
26 #include "ui/events/event.h" 27 #include "ui/events/event.h"
27 #include "ui/events/event_utils.h" 28 #include "ui/events/event_utils.h"
28 #include "ui/events/keycodes/keyboard_code_conversion.h" 29 #include "ui/events/keycodes/keyboard_code_conversion.h"
29 #include "ui/wm/core/window_util.h" 30 #include "ui/wm/core/window_util.h"
30 31
31 #if defined(USE_X11) 32 #if defined(USE_X11)
32 #include <X11/extensions/XInput2.h> 33 #include <X11/extensions/XInput2.h>
33 #include <X11/Xatom.h>
34 #include <X11/Xlib.h> 34 #include <X11/Xlib.h>
35 35
36 #ifndef XI_PROP_PRODUCT_ID
37 #define XI_PROP_PRODUCT_ID "Device Product ID"
38 #endif
39
40 // Get rid of macros from Xlib.h that conflicts with other parts of the code. 36 // Get rid of macros from Xlib.h that conflicts with other parts of the code.
41 #undef RootWindow 37 #undef RootWindow
42 #undef Status 38 #undef Status
43 39
44 #include "ui/base/x/x11_util.h" 40 #include "ui/base/x/x11_util.h"
45 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 41 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
46 #endif 42 #endif
47 43
48 namespace chromeos { 44 namespace chromeos {
49 45
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 VLOG(1) << "Unknown keyboard '" << device_name << "' connected: " 925 VLOG(1) << "Unknown keyboard '" << device_name << "' connected: "
930 << "id=" << device_id; 926 << "id=" << device_id;
931 } 927 }
932 // Always overwrite the existing device_id since the X server may reuse a 928 // Always overwrite the existing device_id since the X server may reuse a
933 // device id for an unattached device. 929 // device id for an unattached device.
934 device_id_to_type_[device_id] = type; 930 device_id_to_type_[device_id] = type;
935 return type; 931 return type;
936 } 932 }
937 933
938 EventRewriter::DeviceType EventRewriter::KeyboardDeviceAdded(int device_id) { 934 EventRewriter::DeviceType EventRewriter::KeyboardDeviceAdded(int device_id) {
939 #if defined(USE_X11) 935 if (!ui::DeviceDataManager::HasInstance())
940 DCHECK_NE(XIAllDevices, device_id);
941 DCHECK_NE(XIAllMasterDevices, device_id);
942 if (device_id == XIAllDevices || device_id == XIAllMasterDevices) {
943 LOG(ERROR) << "Unexpected device_id passed: " << device_id;
944 return kDeviceUnknown; 936 return kDeviceUnknown;
937 const std::vector<ui::KeyboardDevice>& keyboards =
938 ui::DeviceDataManager::GetInstance()->keyboard_devices();
939 for (const auto& keyboard : keyboards) {
940 if (keyboard.id == device_id) {
941 return KeyboardDeviceAddedInternal(
942 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id);
943 }
945 } 944 }
946 945 return kDeviceUnknown;
947 Atom product_id_atom =
948 XInternAtom(gfx::GetXDisplay(), XI_PROP_PRODUCT_ID, 1);
949
950 int ndevices_return = 0;
951 XIDeviceInfo* device_info =
952 XIQueryDevice(gfx::GetXDisplay(), device_id, &ndevices_return);
953
954 // Since |device_id| is neither XIAllDevices nor XIAllMasterDevices,
955 // the number of devices found should be either 0 (not found) or 1.
956 if (!device_info) {
957 LOG(ERROR) << "XIQueryDevice: Device ID " << device_id << " is unknown.";
958 return kDeviceUnknown;
959 }
960
961 DeviceType dev_type = kDeviceUnknown;
962 DCHECK_EQ(1, ndevices_return);
963 for (int i = 0; i < ndevices_return; ++i) {
964 // Get keyboard product and vendor id.
965 int vendor_id = kUnknownVendorId;
966 int product_id = kUnknownProductId;
967 uint32* product_info = NULL;
968 Atom type;
969 int format_return;
970 unsigned long num_items_return;
971 unsigned long bytes_after_return;
972 if (XIGetProperty(gfx::GetXDisplay(),
973 device_info[i].deviceid,
974 product_id_atom,
975 0,
976 2,
977 0,
978 XA_INTEGER,
979 &type,
980 &format_return,
981 &num_items_return,
982 &bytes_after_return,
983 reinterpret_cast<unsigned char **>(&product_info)) == 0 &&
984 product_info) {
985 vendor_id = product_info[0];
986 product_id = product_info[1];
987 }
988
989 DCHECK_EQ(device_id, device_info[i].deviceid); // see the comment above.
990 DCHECK(device_info[i].name);
991 dev_type = KeyboardDeviceAddedInternal(device_info[i].deviceid,
992 device_info[i].name,
993 vendor_id,
994 product_id);
995 }
996 XIFreeDeviceInfo(device_info);
997 return dev_type;
998 #else
999 // TODO(spang): Figure out where we can get keyboard vendor/product id from in
1000 // Ozone/Freon version.
1001 return KeyboardDeviceAddedInternal(device_id,
1002 "keyboard",
1003 kUnknownVendorId,
1004 kUnknownProductId);
1005 #endif
1006 } 946 }
1007 947
1008 } // namespace chromeos 948 } // namespace chromeos
OLDNEW
« 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