Chromium Code Reviews

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

Issue 9608011: Update Linux nativeKeyCode to USB keycode conversion table. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update LOG and comments Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | 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/logging.h"
7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
8 9
9 using WebKit::WebKeyboardEvent; 10 using WebKit::WebKeyboardEvent;
10 11
11 namespace webkit { 12 namespace webkit {
12 namespace ppapi { 13 namespace ppapi {
13 14
14 namespace { 15 namespace {
15 16
16 // TODO(garykac): This table covers only USB HID Boot Protocol. It should be 17 // Mapping from 8-bit xkb scancode to the USB Usage Page and Id. Each entry
17 // extended (e.g. with "media keys"), or derived automatically from the 18 // is encoded as follows:
18 // evdev USB-to-linux keycode mapping. 19 // Upper 4 bits: USB Usage Page:
19 uint16_t linux_evdev_key_code_to_usb[256] = { 20 // 0x7 : Keyboard/Keypad Page
20 // 0x00-0x0f 21 // 0xc : Consumer Page
21 0x0000, 0x0029, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023, 22 // AL = Application Launch
22 0x0024, 0x0025, 0x0026, 0x0027, 0x002d, 0x002e, 0x002a, 0x002b, 23 // Lower 12 bits: USB Usage ID
Wez 2012/03/07 23:25:18 Why are you encoding the table this way, rather th
garykac 2012/03/14 13:47:47 Changed table to use int32's. In any case, this co
23 // 0x10-0x1f 24 //
24 0x0014, 0x001a, 0x0008, 0x0015, 0x0017, 0x001c, 0x0018, 0x000c, 25 // TODO(garykac): This table covers only USB HID Boot Protocol. The keys
25 0x0012, 0x0013, 0x002f, 0x0030, 0x0028, 0x00e0, 0x0004, 0x0016, 26 // marked with '???' should be extended (e.g. with "media keys"), or derived
26 // 0x20-0x2f 27 // automatically from the USB-to-linux keycode mapping.
Wez 2012/03/07 23:25:18 The USB HID Boot Protocol is the USB-to-linux mapp
garykac 2012/03/14 13:47:47 I removed this comment since we're handling media
27 0x0007, 0x0009, 0x000a, 0x000b, 0x000d, 0x000e, 0x000f, 0x0033, 28 //
28 0x0034, 0x0035, 0x00e1, 0x0032, 0x001d, 0x001b, 0x0006, 0x0019, 29 // Note: Don't specify array size here since it will automatically zero-fill
29 // 0x30-0x3f 30 // out to the specified size if there are not enough values. This will defeat
30 0x0005, 0x0011, 0x0010, 0x0036, 0x0037, 0x0038, 0x00e5, 0x0055, 31 // our arraysize checks at the end.
31 0x00e2, 0x002c, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 32 uint16_t linux_xkb_code_to_usb[/* 256 */] = {
Wez 2012/03/07 23:25:18 nit: Don't need the Note nor the /* 256 */ - this
garykac 2012/03/14 13:47:47 Done.
32 // 0x40-0x4f 33 // 0 - 8: unused
33 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0053, 0x0047, 0x005f,
34 0x0060, 0x0061, 0x0056, 0x005c, 0x005d, 0x005e, 0x0057, 0x0059,
35 // 0x50-0x5f
36 0x005a, 0x005b, 0x0062, 0x0063, 0x0000, 0x0094, 0x0064, 0x0044,
37 0x0045, 0x0087, 0x0092, 0x0093, 0x008a, 0x0088, 0x008b, 0x008c,
38 // 0x60-0x6f
39 0x0058, 0x00e4, 0x0054, 0x0046, 0x00e6, 0x0000, 0x004a, 0x0052,
40 0x004b, 0x0050, 0x004f, 0x004d, 0x0051, 0x004e, 0x0049, 0x004c,
41 // 0x70-0x7f
42 0x0000, 0x00ef, 0x00ee, 0x00ed, 0x0066, 0x0067, 0x0000, 0x0048,
43 0x0000, 0x0085, 0x0090, 0x0091, 0x0089, 0x00e3, 0x00e7, 0x0065,
44 // 0x80-0x8f
45 0x00f3, 0x0079, 0x0076, 0x007a, 0x0077, 0x007c, 0x0074, 0x007d,
46 0x00f4, 0x007b, 0x0075, 0x0000, 0x00fb, 0x0000, 0x00f8, 0x0000,
47 // 0x90-0x9f
48 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00f0, 0x0000,
49 0x00f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00f1, 0x00f2,
50 // 0xa0-0xaf
51 0x0000, 0x00ec, 0x0000, 0x00eb, 0x00e8, 0x00ea, 0x00e9, 0x0000,
52 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00fa, 0x0000, 0x0000,
53 // 0xb0-0xbf
54 0x00f7, 0x00f5, 0x00f6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0068,
55 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x0070,
56 // 0xc0-0xcf
57 0x0071, 0x0072, 0x0073, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
58 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 34 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
59 // 0xd0-0xdf 35 0x0000,
36 // 9: Escape
37 0x7029,
38 // 10-19: 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0)
Wez 2012/03/07 23:25:18 Please put commas between the key names to make th
garykac 2012/03/14 13:47:47 Except for the ',<' key, when having a comma becom
39 0x701e, 0x701f, 0x7020, 0x7021, 0x7022, 0x7023, 0x7024, 0x7025,
40 0x7026, 0x7027,
41 // 20-21: -_ =+
42 0x702d, 0x702e,
43 // 22-23: Backspace Tab
44 0x702a, 0x702b,
45 // 24-33: qQ wW eE rR tT yY uU iI oO pP
46 0x7014, 0x701a, 0x7008, 0x7015, 0x7017, 0x701c, 0x7018, 0x700c,
47 0x7012, 0x7013,
48 // 34-35: [{ ]}
49 0x702f, 0x7030,
50 // 36: Return
51 0x7028,
52 // 37: LeftControl
53 0x70e0,
54 // 38-46: aA sS dD fF gG hH jJ kK lL
55 0x7004, 0x7016, 0x7007, 0x7009, 0x700a, 0x700b, 0x700d, 0x700e,
56 0x700f,
57 // 47-49: ;: '" `~
58 0x7033, 0x7034, 0x7035,
59 // 50: LeftShift
60 0x70e1,
61 // 51: \|
62 0x7031,
63 // 52-58: zZ xX cC vV bB nN mM
64 0x701d, 0x701b, 0x7006, 0x7019, 0x7005, 0x7011, 0x7010,
65 // 59-61: ,< .> /?
66 0x7036, 0x7037, 0x7038,
67 // 62: RightShift
68 0x70e5,
69 // 63: Keypad_*
70 0x7055,
71 // 64: LeftAlt
72 0x70e2,
73 // 65: Space
74 0x702c,
75 // 66: CapsLock
76 0x7039,
77 // 67-76: F1 F2 F3 F4 F5 F6 F7 F8 F9 F10
78 0x703a, 0x703b, 0x703c, 0x703d, 0x703e, 0x703f, 0x7040, 0x7041,
79 0x7042, 0x7043,
80 // 77: NumLock
81 0x7053,
82 // 78: ScrollLock
83 0x7047,
84 // 79-81: Keypad_7 Keypad_8 Keypad_9
85 0x705f, 0x7060, 0x7061,
86 // 82: Keypad_-
87 0x7056,
88 // 83-85: Keypad_4 Keypad_5 Keypad_6
89 0x705c, 0x705d, 0x705e,
90 // 86: Keypad_+
91 0x7057,
92 // 87-89: Keypad_1 Keypad_2 Keypad_3
93 0x7059, 0x705a, 0x705b,
94 // 90-91: Keypad_0 Keypad_.
95 0x7062, 0x7063,
96 // 92: ??? (ISO_Level3_Shift)
97 0x0000,
98 // 93: unused
99 0x0000,
100 // 94: ??? <>|| (less than, greater than, bar, broken bar)
101 // Consider USB#0064 : Non-US \ and |
102 0x0000,
103 // 95-96: F11 F12
104 0x7044, 0x7045,
105 // 97: unused
106 0x0000,
107 // 98-102: Katakana Hiragana Henkan Hiragana_Katakana Muhenkan
108 0x7092, 0x7093, 0x7094, 0x7088, 0x708b,
109 // 103: unused
110 0x0000,
111 // 104: Keypad_Enter
112 0x7058,
113 // 105: RightControl
114 0x70e4,
115 // 106: Keypad_/
116 0x7054,
117 // 107: Print/SysReq
118 // USB#0046 is PrintScreen, USB#009a is SysReq/Attention
119 0x7046,
120 // 108: RightAlt
121 0x70e6,
122 // 109: ??? (Linefeed)
123 0x0000,
124 // 110: Home
125 0x704a,
126 // 111: UpArrow
127 0x7052,
128 // 112: PageUp (Prior)
129 0x704b,
130 // 113: LeftArrow
131 0x7050,
132 // 114: RightArrow
133 0x704f,
134 // 115: End
135 0x704d,
136 // 116: DownArrow
137 0x7051,
138 // 117: PageDown (Next)
139 0x704e,
140 // 118: Insert
141 0x7049,
142 // 119: Delete (Delete Forward)
143 0x704c,
144 // 120: unused
145 0x0000,
146 // 121-123: Mute VolumeDown VolumeUp
147 0x707f, 0x7081, 0x7080,
148 // 124: PowerOff
149 0x7066,
150 // 125: Keypad_= Keypad_+-
151 0x7067, 0x00d7,
152 // 127: Pause/Break
153 0x7048,
154 // 128: ??? LaunchA
155 0x0000,
156 // 129: Keypad_Decimal (cf. 91: Keypad_. and Keypad_Delete)
157 0x70dc,
158 // 130-131: HangulToggle HanjaConversion
159 0x7090, 0x7091,
160 // 132: unused
161 0x0000,
162 // 133-134: LeftSuper/LeftWin RightSuper/RightWin
163 0x70e3, 0x70e7,
164 // 135: Menu
165 0x7065,
166 // 136: Cancel
167 0x709b,
168 // 137: Again (Redo)
169 0x7079,
170 // 138: CrSel/Props
171 0x70a3,
172 // 139: Undo
173 0x707a,
174 // 140: ??? SunFront
175 0x0000,
176 // 141: Copy
177 0x707c,
178 // 142: ??? SunOpen
179 0x0000,
180 // 143: Paste
181 0x707d,
182 // 144: Find
183 0x707e,
184 // 145: Cut
185 0x707b,
186 // 146: Help
187 0x7075,
188 // 147: ??? MenuKB (cf. 135, 193)
189 0x0000,
190 // 148: AL Calculator
191 0xc192,
192 // 149: unused
193 0x0000,
194 // 150: ??? Sleep
195 0x0000,
196 // 151: ??? WakeUp
197 0x0000,
198 // 152: ??? Explorer
199 0x0000,
200 // 153: ??? Send
201 0x0000,
202 // 154: unused
203 0x0000,
204 // 155: ??? Xfer
205 0x0000,
206 // 156: ??? Launch1
207 0x0000,
208 // 157: ??? Launch2
209 0x0000,
210 // 158: ??? WWW
211 0x0000,
212 // 159: ??? DOS
213 0x0000,
214 // 160: ??? ScreenSaver
215 0x0000,
216 // 161: unused
217 0x0000,
218 // 162: ??? RotateWindows
219 0x0000,
220 // 163: ??? Mail
221 0x0000,
222 // 164: ??? Favorites
223 0x0000,
224 // 165: ??? MyComputer
225 0x0000,
226 // 166: ??? Back
227 0x0000,
228 // 167: ??? Forward
229 0x0000,
230 // 168: unused
231 0x0000,
232 // 169-170: ??? Eject Eject (encode the same)
233 0x0000, 0x0000,
234 // 171-176: ???AudioNext AudioPlay AudioPrev AudioStop AudioRecord AudioRewind
235 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
236 // 177: ??? Phone
237 0x0000,
238 // 178: unused
239 0x0000,
240 // 179: ??? Tools
241 0x0000,
242 // 180: ??? HomePage
243 0x0000,
244 // 181: ??? Reload
245 0x0000,
246 // 182: ??? Close
247 0x0000,
248 // 183-184: unused
249 0x0000, 0x0000,
250 // 185: ??? ScrollUp
251 0x0000,
252 // 186: ??? ScrollDown
253 0x0000,
254 // 187-188: ( ) (Mapped to Keypad_( and Keypad_))
255 0x70b6, 0x70b7,
256 // 189: ??? New
257 0x0000,
258 // 190: ??? Redo
259 0x0000,
260 // 191: ??? Tools
261 0x0000,
262 // 192: ??? Launch5
263 0x0000,
264 // 193: ??? MenuKB
265 0x0000,
266 // 194-199: unused
267 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
268 // 200: ??? TouchpadToggle
269 0x0000,
270 // 201-202: unused
271 0x0000, 0x0000,
272 // 203: ??? ModeSwitch
273 0x0000,
274 // 204-207: Generates no symbol without Shift.
275 // With shift: LeftAlt LeftMeta LeftSuper LeftHyper.
276 0x0000, 0x0000, 0x0000, 0x0000,
277 // 208-209: ??? AudioPlay AudioPause
278 0x0000, 0x0000,
279 // 210-212: ??? Launch3 Launch4 LaunchB
280 0x0000, 0x0000, 0x0000,
281 // 213: ??? Suspend
282 0x0000,
283 // 214: ??? Close
284 0x0000,
285 // 215-216: ??? AudioPlay AudioForward
286 0x0000, 0x0000,
287 // 217: unused
288 0x0000,
289 // 218: ??? Print
290 0x0000,
291 // 219: unused
292 0x0000,
293 // 220: ??? WebCam
294 0x0000,
295 // 221-222: unused
296 0x0000, 0x0000,
297 // 223: ??? Mail
298 0x0000,
299 // 224: unused
300 0x0000,
301 // 225: ??? Search
302 0x0000,
303 // 226: unused
304 0x0000,
305 // 227: AL Finance
306 0xc191,
307 // 228: unused
308 0x0000,
309 // 229: ??? Shop
310 0x0000,
311 // 230: unused
312 0x0000,
313 // 231: ??? Cancel
314 0x0000,
315 // 232-233: ??? MonBrightnessDown MonBrightnessUp
316 0x0000, 0x0000,
317 // 234: ??? AudioMedia
318 0x0000,
319 // 235: ??? Display
320 0x0000,
321 // 236-238: ??? KbdLightOnOff KbdBightnessDown KdbBrightnessUp
322 0x0000, 0x0000, 0x0000,
323 // 239: ??? Send
324 0x0000,
325 // 240: ??? Reply
326 0x0000,
327 // 241: ??? MailForward
328 0x0000,
329 // 242: ??? Save
330 0x0000,
331 // 243: ??? Documents
332 0x0000,
333 // 244: ??? Battery
334 0x0000,
335 // 245: ??? Bluetooth
336 0x0000,
337 // 246: ??? WLAN
338 0x0000,
339 // 247-255: unused
60 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 340 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
61 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 341 0x0000
Wez 2012/03/07 23:25:18 This is horribly verbose and hard to read. Is the
garykac 2012/03/14 13:47:47 Compacted into 4 int32s per line.
62 // 0xe0-0xef
63 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
64 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
65 // 0xf0-0xff
66 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
67 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
68 }; 342 };
69 343
344 // Compile time check to ensure we have exactly 256 entries.
345 COMPILE_ASSERT_ARRAY_SIZE(linux_xkb_code_to_usb, uint16_t, 256);
346
70 } // anonymous namespace 347 } // anonymous namespace
71 348
72 uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { 349 uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) {
73 // TODO(garykac): This code assumes that on Linux we're receiving events via 350 // TODO(garykac): This code assumes that on Linux we're receiving events via
74 // the Xorg "evdev" driver. We should detect "XKB" or "kbd" at run-time and 351 // the XKB driver. We should detect between "XKB", "kbd" and "evdev" at
Wez 2012/03/07 23:25:18 nit: detect between -> detect
garykac 2012/03/14 13:47:47 Done.
75 // re-map accordingly, but that's not possible here, inside the sandbox. 352 // run-time and re-map accordingly, but that's not possible here, inside the
76 if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 255) 353 // sandbox.
354 uint16_t usb_id = 0;
Wez 2012/03/07 23:25:18 nit: usb_id -> usb_keycode
garykac 2012/03/14 13:47:47 Code removed.
355 if (key_event.nativeKeyCode >= 0 && key_event.nativeKeyCode < 255) {
356 usb_id = linux_xkb_code_to_usb[key_event.nativeKeyCode];
357 }
358
359 VLOG(3) << std::hex << "native: " << key_event.nativeKeyCode
360 << " usb: " << usb_id;
361 if (usb_id == 0)
77 return 0; 362 return 0;
78 363
79 uint32_t usbkeycode = 0; 364 uint32_t usb_page = usb_id & 0xF000;
80 uint16_t code = linux_evdev_key_code_to_usb[key_event.nativeKeyCode]; 365 usb_id &= 0x0FFF;
81 if (code != 0) { 366 uint32_t usb_keycode = (usb_page << 4) | usb_id;
82 // Set complete scancode to be the USB keyboard page (7) and key scancode. 367 return usb_keycode;
83 usbkeycode = 0x070000 | code;
84 }
85 return usbkeycode;
86 } 368 }
87 369
88 } // namespace ppapi 370 } // namespace ppapi
89 } // namespace webkit 371 } // namespace webkit
OLDNEW

Powered by Google App Engine