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

Side by Side Diff: webkit/plugins/ppapi/usb_key_code_conversion_linux.cc

Issue 12320014: Switch Pepper Linux to use shared USB<->native key conversion table. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix missed kInvalidKeycode. Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/plugins/ppapi/usb_key_code_conversion.h" 5 #include "webkit/plugins/ppapi/usb_key_code_conversion.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
10 9
11 using WebKit::WebKeyboardEvent; 10 using WebKit::WebKeyboardEvent;
12 11
13 namespace webkit { 12 namespace webkit {
14 namespace ppapi { 13 namespace ppapi {
15 14
16 namespace { 15 namespace {
17 16
18 // Mapping from 8-bit xkb scancode to 32-bit USB Usage Page and Id. 17 #define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb}
19 // 18 #include "ui/base/keycodes/usb_keycode_map.h"
20 // TODO(garykac): This table covers only USB HID Boot Protocol. The keys 19 #undef USB_KEYMAP
21 // marked with '???' should be extended (e.g. with "media keys"), or derived
22 // automatically from the USB-to-linux keycode mapping.
23 uint32_t linux_xkb_code_to_usb[] = {
24 // 00-04: unused
25 0x000000, 0x000000, 0x000000, 0x000000,
26 // 04-07: unused
27 0x000000, 0x000000, 0x000000, 0x000000,
28 // 08-0b: unused Escape 1! 2@
29 0x000000, 0x070029, 0x07001e, 0x07001f,
30 // 0c-0f: 3# 4$ 5% 6^
31 0x070020, 0x070021, 0x070022, 0x070023,
32 // 10-13: 7& 8* 9( 0)
33 0x070024, 0x070025, 0x070026, 0x070027,
34 // 14-17: -_ =+ Backspace Tab
35 0x07002d, 0x07002e, 0x07002a, 0x07002b,
36 // 18-1b: qQ wW eE rR
37 0x070014, 0x07001a, 0x070008, 0x070015,
38 // 1c-1f: tT yY uU iI
39 0x070017, 0x07001c, 0x070018, 0x07000c,
40 // 20-23: oO pP [{ ]}
41 0x070012, 0x070013, 0x07002f, 0x070030,
42 // 24-27: Return LeftControl aA sS
43 0x070028, 0x0700e0, 0x070004, 0x070016,
44 // 28-2b: dD fF gG hH
45 0x070007, 0x070009, 0x07000a, 0x07000b,
46 // 2c-2f: jJ kK lL ;:
47 0x07000d, 0x07000e, 0x07000f, 0x070033,
48 // 30-33: '" `~ LeftShift \|
49 0x070034, 0x070035, 0x0700e1, 0x070031,
50 // 34-37: zZ xX cC vV
51 0x07001d, 0x07001b, 0x070006, 0x070019,
52 // 38-3b: bB nN mM ,<
53 0x070005, 0x070011, 0x070010, 0x070036,
54 // 3c-3f: .> /? RightShift Keypad_*
55 0x070037, 0x070038, 0x0700e5, 0x070055,
56 // 40-43: LeftAlt Space CapsLock F1
57 0x0700e2, 0x07002c, 0x070039, 0x07003a,
58 // 44-47: F2 F3 F4 F5
59 0x07003b, 0x07003c, 0x07003d, 0x07003e,
60 // 48-4b: F6 F7 F8 F9
61 0x07003f, 0x070040, 0x070041, 0x070042,
62 // 4c-4f: F10 NumLock ScrollLock Keypad_7
63 0x070043, 0x070053, 0x070047, 0x07005f,
64 // 50-53: Keypad_8 Keypad_9 Keypad_- Keypad_4
65 0x070060, 0x070061, 0x070056, 0x07005c,
66 // 54-57: Keypad_5 Keypad_6 Keypad_+ Keypad_1
67 0x07005d, 0x07005e, 0x070057, 0x070059,
68 // 58-5b: Keypad_2 Keypad_3 Keypad_0 Keypad_.
69 0x07005a, 0x07005b, 0x070062, 0x070063,
70 // 5c-5f: ISO_Level3_Shift unused <>|| F11
71 0x000000, 0x000000, 0x070064, 0x070044,
72 // 60-63: F12 unused Katakana Hiragana
73 0x070045, 0x000000, 0x070092, 0x070093,
74 // 64-67: Henkan Hiragana_Katakana Muhenkan unused
75 0x070094, 0x070088, 0x07008b, 0x000000,
76 // 68-6b: Keypad_Enter RightControl Keypad_/ Print/SysReq
77 // For 6b, USB#0046 is PrintScreen, USB#009a is SysReq/Attention
78 0x070058, 0x0700e4, 0x070054, 0x070046,
79 // 6c-6f: RightAlt Linefeed Home UpArrow
80 0x0700e6, 0x000000, 0x07004a, 0x070052,
81 // 70-73: PageUp/Prior LeftArrow RightArrow End
82 0x07004b, 0x070050, 0x07004f, 0x07004d,
83 // 74-77: DownArrow PageDown/Next Insert Delete/ForwardDelete
84 0x070051, 0x07004e, 0x070049, 0x07004c,
85 // 78-7b: unused Mute VolumeDown VolumeUp
86 0x000000, 0x07007f, 0x070081, 0x070080,
87 // 7c-7f: PowerOff Keypad_= Keypad_+- Pause/Break
88 0x070066, 0x070067, 0x0700d7, 0x070048,
89 // 80-83: LaunchA Keypad_Decimal HangulToggle HanjaConversion
90 // For 81, cf. 5b: Keypad_.
91 0x000000, 0x0700dc, 0x070090, 0x070091,
92 // 84-87: unused LeftSuper/LeftWin RightSuper/RightWin Menu
93 0x000000, 0x0700e3, 0x0700e7, 0x070065,
94 // 88-8b: Cancel Again/Redo CrSel/Props Undo
95 0x07009b, 0x070079, 0x0700a3, 0x07007a,
96 // 8c-8f: SunFront Copy SunOpen Paste
97 0x000000, 0x07007c, 0x000000, 0x07007d,
98 // 90-93: Find Cut Help MenuKB
99 // For 93, cf. 87 (Menu) and c1 (MenuKB)
100 0x07007e, 0x07007b, 0x070075, 0x000000,
101 // 94-97: AL_Calculator unused Sleep WakeUp
102 0x0c0192, 0x000000, 0x000000, 0x000000,
103 // 98-9b: Explorer Send unused Xfer
104 0x000000, 0x000000, 0x000000, 0x000000,
105 // 9c-9f: Launch1 Launch2 WWW DOS
106 0x000000, 0x000000, 0x000000, 0x000000,
107 // a0-a3: ScreenSaver unused RotateWindows Mail
108 0x000000, 0x000000, 0x000000, 0x000000,
109 // a4-a7: Favorites MyComputer Back Forward
110 0x000000, 0x000000, 0x000000, 0x000000,
111 // a8-ab: unused Eject Eject AudioNext
112 0x000000, 0x000000, 0x000000, 0x000000,
113 // ac-af: AudioPlay AudioPrev AudioStop AudioRecord
114 0x000000, 0x000000, 0x000000, 0x000000,
115 // b0-b3: AudioRewind Phone unused Tools
116 0x000000, 0x000000, 0x000000, 0x000000,
117 // b4-b7: HomePage Reload Close unused
118 0x000000, 0x000000, 0x000000, 0x000000,
119 // b8-bb: unused ScrollUp ScrollDown (
120 // For bb, mapped to Keypad_(
121 0x000000, 0x000000, 0x000000, 0x0700b6,
122 // bc-bf: ) New Redo Tools
123 // For bc, mapped to Keypad_)
124 0x0700b7, 0x000000, 0x000000, 0x000000,
125 // c0-c3: Launch5 MenuKB unused unused
126 0x000000, 0x000000, 0x000000, 0x000000,
127 // c4-c7: unused
128 0x000000, 0x000000, 0x000000, 0x000000,
129 // c8-cb: TouchpadToggle unused unused ModeSwitch
130 0x000000, 0x000000, 0x000000, 0x000000,
131 // cc-cf: Generates no symbol without Shift.
132 // With shift: LeftAlt LeftMeta LeftSuper LeftHyper.
133 0x000000, 0x000000, 0x000000, 0x000000,
134 // d0-d3: AudioPlay AudioPause Launch3 Launch4
135 0x000000, 0x000000, 0x000000, 0x000000,
136 // d4-d7: LaunchB Suspend Close AudioPlay
137 0x000000, 0x000000, 0x000000, 0x000000,
138 // d8-db: AudioForward unused Print unused
139 0x000000, 0x000000, 0x000000, 0x000000,
140 // dc-df: WebCam unused unused Mail
141 0x000000, 0x000000, 0x000000, 0x000000,
142 // e0-e3: unused Search unused AL_Finance
143 0x000000, 0x000000, 0x000000, 0x0c0191,
144 // e4-e7: unused Shop unused Cancel
145 0x000000, 0x000000, 0x000000, 0x000000,
146 // e8-eb: MonBrightnessDown MonBrightnessUp AudioMedia Display
147 0x000000, 0x000000, 0x000000, 0x000000,
148 // ec-ef: KbdLightOnOff KbdBightnessDown KdbBrightnessUp Send
149 0x000000, 0x000000, 0x000000, 0x000000,
150 // f0-f3: Reply MailForward Save Documents
151 0x000000, 0x000000, 0x000000, 0x000000,
152 // f4-f7: Battery Bluetooth WLAN unused
153 0x000000, 0x000000, 0x000000, 0x000000,
154 // f8-fb: unused
155 0x000000, 0x000000, 0x000000, 0x000000,
156 // fc-ff: unused
157 0x000000, 0x000000, 0x000000, 0x000000
158 };
159 20
160 COMPILE_ASSERT(arraysize(linux_xkb_code_to_usb) == 256, 21 } // anonymous namespace
161 linux_xkb_code_to_usb_table_incorrect_size);
162
163 } // anonymous namespace
164 22
165 uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { 23 uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) {
166 // TODO(garykac): This code assumes that on Linux we're receiving events via 24 // TODO(garykac): This code assumes that on Linux we're receiving events via
167 // the XKB driver. We should detect between "XKB", "kbd" and "evdev" at 25 // the XKB driver. We should detect between "XKB", "kbd" and "evdev" at
168 // run-time and re-map accordingly, but that's not possible here, inside the 26 // run-time and re-map accordingly, but that's not possible here, inside the
169 // sandbox. 27 // sandbox.
170 if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 255) { 28 return NativeKeycodeToUsbKeycode(key_event.nativeKeyCode);
171 return 0;
172 }
173 return linux_xkb_code_to_usb[key_event.nativeKeyCode];
174 } 29 }
175 30
176 } // namespace ppapi 31 } // namespace ppapi
177 } // namespace webkit 32 } // namespace webkit
OLDNEW
« no previous file with comments | « ui/base/keycodes/usb_keycode_map_unittest.cc ('k') | webkit/plugins/ppapi/usb_key_code_conversion_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698