OLD | NEW |
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" |
| 8 #include "base/logging.h" |
7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
8 | 10 |
9 using WebKit::WebKeyboardEvent; | 11 using WebKit::WebKeyboardEvent; |
10 | 12 |
11 namespace webkit { | 13 namespace webkit { |
12 namespace ppapi { | 14 namespace ppapi { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // TODO(garykac): This table covers only USB HID Boot Protocol. It should be | 18 // Mapping from 8-bit xkb scancode to 32-bit USB Usage Page and Id. |
17 // extended (e.g. with "media keys"), or derived automatically from the | 19 // |
18 // evdev USB-to-linux keycode mapping. | 20 // TODO(garykac): This table covers only USB HID Boot Protocol. The keys |
19 uint16_t linux_evdev_key_code_to_usb[256] = { | 21 // marked with '???' should be extended (e.g. with "media keys"), or derived |
20 // 0x00-0x0f | 22 // automatically from the USB-to-linux keycode mapping. |
21 0x0000, 0x0029, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023, | 23 uint32_t linux_xkb_code_to_usb[] = { |
22 0x0024, 0x0025, 0x0026, 0x0027, 0x002d, 0x002e, 0x002a, 0x002b, | 24 // 00-04: unused |
23 // 0x10-0x1f | 25 0x000000, 0x000000, 0x000000, 0x000000, |
24 0x0014, 0x001a, 0x0008, 0x0015, 0x0017, 0x001c, 0x0018, 0x000c, | 26 // 04-07: unused |
25 0x0012, 0x0013, 0x002f, 0x0030, 0x0028, 0x00e0, 0x0004, 0x0016, | 27 0x000000, 0x000000, 0x000000, 0x000000, |
26 // 0x20-0x2f | 28 // 08-0b: unused Escape 1! 2@ |
27 0x0007, 0x0009, 0x000a, 0x000b, 0x000d, 0x000e, 0x000f, 0x0033, | 29 0x000000, 0x070029, 0x07001e, 0x07001f, |
28 0x0034, 0x0035, 0x00e1, 0x0032, 0x001d, 0x001b, 0x0006, 0x0019, | 30 // 0c-0f: 3# 4$ 5% 6^ |
29 // 0x30-0x3f | 31 0x070020, 0x070021, 0x070022, 0x070023, |
30 0x0005, 0x0011, 0x0010, 0x0036, 0x0037, 0x0038, 0x00e5, 0x0055, | 32 // 10-13: 7& 8* 9( 0) |
31 0x00e2, 0x002c, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, | 33 0x070024, 0x070025, 0x070026, 0x070027, |
32 // 0x40-0x4f | 34 // 14-17: -_ =+ Backspace Tab |
33 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0053, 0x0047, 0x005f, | 35 0x07002d, 0x07002e, 0x07002a, 0x07002b, |
34 0x0060, 0x0061, 0x0056, 0x005c, 0x005d, 0x005e, 0x0057, 0x0059, | 36 // 18-1b: qQ wW eE rR |
35 // 0x50-0x5f | 37 0x070014, 0x07001a, 0x070008, 0x070015, |
36 0x005a, 0x005b, 0x0062, 0x0063, 0x0000, 0x0094, 0x0064, 0x0044, | 38 // 1c-1f: tT yY uU iI |
37 0x0045, 0x0087, 0x0092, 0x0093, 0x008a, 0x0088, 0x008b, 0x008c, | 39 0x070017, 0x07001c, 0x070018, 0x07000c, |
38 // 0x60-0x6f | 40 // 20-23: oO pP [{ ]} |
39 0x0058, 0x00e4, 0x0054, 0x0046, 0x00e6, 0x0000, 0x004a, 0x0052, | 41 0x070012, 0x070013, 0x07002f, 0x070030, |
40 0x004b, 0x0050, 0x004f, 0x004d, 0x0051, 0x004e, 0x0049, 0x004c, | 42 // 24-27: Return LeftControl aA sS |
41 // 0x70-0x7f | 43 0x070028, 0x0700e0, 0x070004, 0x070016, |
42 0x0000, 0x00ef, 0x00ee, 0x00ed, 0x0066, 0x0067, 0x0000, 0x0048, | 44 // 28-2b: dD fF gG hH |
43 0x0000, 0x0085, 0x0090, 0x0091, 0x0089, 0x00e3, 0x00e7, 0x0065, | 45 0x070007, 0x070009, 0x07000a, 0x07000b, |
44 // 0x80-0x8f | 46 // 2c-2f: jJ kK lL ;: |
45 0x00f3, 0x0079, 0x0076, 0x007a, 0x0077, 0x007c, 0x0074, 0x007d, | 47 0x07000d, 0x07000e, 0x07000f, 0x070033, |
46 0x00f4, 0x007b, 0x0075, 0x0000, 0x00fb, 0x0000, 0x00f8, 0x0000, | 48 // 30-33: '" `~ LeftShift \| |
47 // 0x90-0x9f | 49 0x070034, 0x070035, 0x0700e1, 0x070031, |
48 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00f0, 0x0000, | 50 // 34-37: zZ xX cC vV |
49 0x00f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00f1, 0x00f2, | 51 0x07001d, 0x07001b, 0x070006, 0x070019, |
50 // 0xa0-0xaf | 52 // 38-3b: bB nN mM ,< |
51 0x0000, 0x00ec, 0x0000, 0x00eb, 0x00e8, 0x00ea, 0x00e9, 0x0000, | 53 0x070005, 0x070011, 0x070010, 0x070036, |
52 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00fa, 0x0000, 0x0000, | 54 // 3c-3f: .> /? RightShift Keypad_* |
53 // 0xb0-0xbf | 55 0x070037, 0x070038, 0x0700e5, 0x070055, |
54 0x00f7, 0x00f5, 0x00f6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0068, | 56 // 40-43: LeftAlt Space CapsLock F1 |
55 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x0070, | 57 0x0700e2, 0x07002c, 0x070039, 0x07003a, |
56 // 0xc0-0xcf | 58 // 44-47: F2 F3 F4 F5 |
57 0x0071, 0x0072, 0x0073, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 59 0x07003b, 0x07003c, 0x07003d, 0x07003e, |
58 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 60 // 48-4b: F6 F7 F8 F9 |
59 // 0xd0-0xdf | 61 0x07003f, 0x070040, 0x070041, 0x070042, |
60 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 62 // 4c-4f: F10 NumLock ScrollLock Keypad_7 |
61 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 63 0x070043, 0x070053, 0x070047, 0x07005f, |
62 // 0xe0-0xef | 64 // 50-53: Keypad_8 Keypad_9 Keypad_- Keypad_4 |
63 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 65 0x070060, 0x070061, 0x070056, 0x07005c, |
64 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 66 // 54-57: Keypad_5 Keypad_6 Keypad_+ Keypad_1 |
65 // 0xf0-0xff | 67 0x07005d, 0x07005e, 0x070057, 0x070059, |
66 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 68 // 58-5b: Keypad_2 Keypad_3 Keypad_0 Keypad_. |
67 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, | 69 0x07005a, 0x07005b, 0x070062, 0x070063, |
| 70 // 5c-5f: ISO_Level3_Shift unused <>|| F11 |
| 71 // For 5e, consider USB#0064 : Non-US \ and | |
| 72 0x000000, 0x000000, 0x000000, 0x070044, |
| 73 // 60-63: F12 unused Katakana Hiragana |
| 74 0x070045, 0x000000, 0x070092, 0x070093, |
| 75 // 64-67: Henkan Hiragana_Katakana Muhenkan unused |
| 76 0x070094, 0x070088, 0x07008b, 0x000000, |
| 77 // 68-6b: Keypad_Enter RightControl Keypad_/ Print/SysReq |
| 78 // For 6b, USB#0046 is PrintScreen, USB#009a is SysReq/Attention |
| 79 0x070058, 0x0700e4, 0x070054, 0x070046, |
| 80 // 6c-6f: RightAlt Linefeed Home UpArrow |
| 81 0x0700e6, 0x000000, 0x07004a, 0x070052, |
| 82 // 70-73: PageUp/Prior LeftArrow RightArrow End |
| 83 0x07004b, 0x070050, 0x07004f, 0x07004d, |
| 84 // 74-77: DownArrow PageDown/Next Insert Delete/ForwardDelete |
| 85 0x070051, 0x07004e, 0x070049, 0x07004c, |
| 86 // 78-7b: unused Mute VolumeDown VolumeUp |
| 87 0x000000, 0x07007f, 0x070081, 0x070080, |
| 88 // 7c-7f: PowerOff Keypad_= Keypad_+- Pause/Break |
| 89 0x070066, 0x070067, 0x0700d7, 0x070048, |
| 90 // 80-83: LaunchA Keypad_Decimal HangulToggle HanjaConversion |
| 91 // For 81, cf. 5b: Keypad_. |
| 92 0x000000, 0x0700dc, 0x070090, 0x070091, |
| 93 // 84-87: unused LeftSuper/LeftWin RightSuper/RightWin Menu |
| 94 0x000000, 0x0700e3, 0x0700e7, 0x070065, |
| 95 // 88-8b: Cancel Again/Redo CrSel/Props Undo |
| 96 0x07009b, 0x070079, 0x0700a3, 0x07007a, |
| 97 // 8c-8f: SunFront Copy SunOpen Paste |
| 98 0x000000, 0x07007c, 0x000000, 0x07007d, |
| 99 // 90-93: Find Cut Help MenuKB |
| 100 // For 93, cf. 87 (Menu) and c1 (MenuKB) |
| 101 0x07007e, 0x07007b, 0x070075, 0x000000, |
| 102 // 94-97: AL_Calculator unused Sleep WakeUp |
| 103 0x0c0192, 0x000000, 0x000000, 0x000000, |
| 104 // 98-9b: Explorer Send unused Xfer |
| 105 0x000000, 0x000000, 0x000000, 0x000000, |
| 106 // 9c-9f: Launch1 Launch2 WWW DOS |
| 107 0x000000, 0x000000, 0x000000, 0x000000, |
| 108 // a0-a3: ScreenSaver unused RotateWindows Mail |
| 109 0x000000, 0x000000, 0x000000, 0x000000, |
| 110 // a4-a7: Favorites MyComputer Back Forward |
| 111 0x000000, 0x000000, 0x000000, 0x000000, |
| 112 // a8-ab: unused Eject Eject AudioNext |
| 113 0x000000, 0x000000, 0x000000, 0x000000, |
| 114 // ac-af: AudioPlay AudioPrev AudioStop AudioRecord |
| 115 0x000000, 0x000000, 0x000000, 0x000000, |
| 116 // b0-b3: AudioRewind Phone unused Tools |
| 117 0x000000, 0x000000, 0x000000, 0x000000, |
| 118 // b4-b7: HomePage Reload Close unused |
| 119 0x000000, 0x000000, 0x000000, 0x000000, |
| 120 // b8-bb: unused ScrollUp ScrollDown ( |
| 121 // For bb, mapped to Keypad_( |
| 122 0x000000, 0x000000, 0x000000, 0x0700b6, |
| 123 // bc-bf: ) New Redo Tools |
| 124 // For bc, mapped to Keypad_) |
| 125 0x0700b7, 0x000000, 0x000000, 0x000000, |
| 126 // c0-c3: Launch5 MenuKB unused unused |
| 127 0x000000, 0x000000, 0x000000, 0x000000, |
| 128 // c4-c7: unused |
| 129 0x000000, 0x000000, 0x000000, 0x000000, |
| 130 // c8-cb: TouchpadToggle unused unused ModeSwitch |
| 131 0x000000, 0x000000, 0x000000, 0x000000, |
| 132 // cc-cf: Generates no symbol without Shift. |
| 133 // With shift: LeftAlt LeftMeta LeftSuper LeftHyper. |
| 134 0x000000, 0x000000, 0x000000, 0x000000, |
| 135 // d0-d3: AudioPlay AudioPause Launch3 Launch4 |
| 136 0x000000, 0x000000, 0x000000, 0x000000, |
| 137 // d4-d7: LaunchB Suspend Close AudioPlay |
| 138 0x000000, 0x000000, 0x000000, 0x000000, |
| 139 // d8-db: AudioForward unused Print unused |
| 140 0x000000, 0x000000, 0x000000, 0x000000, |
| 141 // dc-df: WebCam unused unused Mail |
| 142 0x000000, 0x000000, 0x000000, 0x000000, |
| 143 // e0-e3: unused Search unused AL_Finance |
| 144 0x000000, 0x000000, 0x000000, 0x0c0191, |
| 145 // e4-e7: unused Shop unused Cancel |
| 146 0x000000, 0x000000, 0x000000, 0x000000, |
| 147 // e8-eb: MonBrightnessDown MonBrightnessUp AudioMedia Display |
| 148 0x000000, 0x000000, 0x000000, 0x000000, |
| 149 // ec-ef: KbdLightOnOff KbdBightnessDown KdbBrightnessUp Send |
| 150 0x000000, 0x000000, 0x000000, 0x000000, |
| 151 // f0-f3: Reply MailForward Save Documents |
| 152 0x000000, 0x000000, 0x000000, 0x000000, |
| 153 // f4-f7: Battery Bluetooth WLAN unused |
| 154 0x000000, 0x000000, 0x000000, 0x000000, |
| 155 // f8-fb: unused |
| 156 0x000000, 0x000000, 0x000000, 0x000000, |
| 157 // fc-ff: unused |
| 158 0x000000, 0x000000, 0x000000, 0x000000 |
68 }; | 159 }; |
69 | 160 |
| 161 COMPILE_ASSERT(arraysize(linux_xkb_code_to_usb) == 256, |
| 162 linux_xkb_code_to_usb_table_incorrect_size); |
| 163 |
70 } // anonymous namespace | 164 } // anonymous namespace |
71 | 165 |
72 uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { | 166 uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { |
73 // TODO(garykac): This code assumes that on Linux we're receiving events via | 167 // 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 | 168 // the XKB driver. We should detect between "XKB", "kbd" and "evdev" at |
75 // re-map accordingly, but that's not possible here, inside the sandbox. | 169 // run-time and re-map accordingly, but that's not possible here, inside the |
76 if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 255) | 170 // sandbox. |
| 171 if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 255) { |
77 return 0; | 172 return 0; |
78 | |
79 uint32_t usbkeycode = 0; | |
80 uint16_t code = linux_evdev_key_code_to_usb[key_event.nativeKeyCode]; | |
81 if (code != 0) { | |
82 // Set complete scancode to be the USB keyboard page (7) and key scancode. | |
83 usbkeycode = 0x070000 | code; | |
84 } | 173 } |
85 return usbkeycode; | 174 return linux_xkb_code_to_usb[key_event.nativeKeyCode]; |
86 } | 175 } |
87 | 176 |
88 } // namespace ppapi | 177 } // namespace ppapi |
89 } // namespace webkit | 178 } // namespace webkit |
OLD | NEW |