Index: webkit/plugins/ppapi/usb_key_code_conversion_linux.cc |
diff --git a/webkit/plugins/ppapi/usb_key_code_conversion_linux.cc b/webkit/plugins/ppapi/usb_key_code_conversion_linux.cc |
index f10238d2d3fb56546cb3a9a22aa93213117b0e17..e80fc749a27db0e8ded579d852c487e5cd7f5750 100644 |
--- a/webkit/plugins/ppapi/usb_key_code_conversion_linux.cc |
+++ b/webkit/plugins/ppapi/usb_key_code_conversion_linux.cc |
@@ -4,6 +4,7 @@ |
#include "webkit/plugins/ppapi/usb_key_code_conversion.h" |
+#include "base/logging.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
using WebKit::WebKeyboardEvent; |
@@ -13,76 +14,357 @@ namespace ppapi { |
namespace { |
-// TODO(garykac): This table covers only USB HID Boot Protocol. It should be |
-// extended (e.g. with "media keys"), or derived automatically from the |
-// evdev USB-to-linux keycode mapping. |
-uint16_t linux_evdev_key_code_to_usb[256] = { |
- // 0x00-0x0f |
- 0x0000, 0x0029, 0x001e, 0x001f, 0x0020, 0x0021, 0x0022, 0x0023, |
- 0x0024, 0x0025, 0x0026, 0x0027, 0x002d, 0x002e, 0x002a, 0x002b, |
- // 0x10-0x1f |
- 0x0014, 0x001a, 0x0008, 0x0015, 0x0017, 0x001c, 0x0018, 0x000c, |
- 0x0012, 0x0013, 0x002f, 0x0030, 0x0028, 0x00e0, 0x0004, 0x0016, |
- // 0x20-0x2f |
- 0x0007, 0x0009, 0x000a, 0x000b, 0x000d, 0x000e, 0x000f, 0x0033, |
- 0x0034, 0x0035, 0x00e1, 0x0032, 0x001d, 0x001b, 0x0006, 0x0019, |
- // 0x30-0x3f |
- 0x0005, 0x0011, 0x0010, 0x0036, 0x0037, 0x0038, 0x00e5, 0x0055, |
- 0x00e2, 0x002c, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, |
- // 0x40-0x4f |
- 0x003f, 0x0040, 0x0041, 0x0042, 0x0043, 0x0053, 0x0047, 0x005f, |
- 0x0060, 0x0061, 0x0056, 0x005c, 0x005d, 0x005e, 0x0057, 0x0059, |
- // 0x50-0x5f |
- 0x005a, 0x005b, 0x0062, 0x0063, 0x0000, 0x0094, 0x0064, 0x0044, |
- 0x0045, 0x0087, 0x0092, 0x0093, 0x008a, 0x0088, 0x008b, 0x008c, |
- // 0x60-0x6f |
- 0x0058, 0x00e4, 0x0054, 0x0046, 0x00e6, 0x0000, 0x004a, 0x0052, |
- 0x004b, 0x0050, 0x004f, 0x004d, 0x0051, 0x004e, 0x0049, 0x004c, |
- // 0x70-0x7f |
- 0x0000, 0x00ef, 0x00ee, 0x00ed, 0x0066, 0x0067, 0x0000, 0x0048, |
- 0x0000, 0x0085, 0x0090, 0x0091, 0x0089, 0x00e3, 0x00e7, 0x0065, |
- // 0x80-0x8f |
- 0x00f3, 0x0079, 0x0076, 0x007a, 0x0077, 0x007c, 0x0074, 0x007d, |
- 0x00f4, 0x007b, 0x0075, 0x0000, 0x00fb, 0x0000, 0x00f8, 0x0000, |
- // 0x90-0x9f |
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00f0, 0x0000, |
- 0x00f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00f1, 0x00f2, |
- // 0xa0-0xaf |
- 0x0000, 0x00ec, 0x0000, 0x00eb, 0x00e8, 0x00ea, 0x00e9, 0x0000, |
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00fa, 0x0000, 0x0000, |
- // 0xb0-0xbf |
- 0x00f7, 0x00f5, 0x00f6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0068, |
- 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x0070, |
- // 0xc0-0xcf |
- 0x0071, 0x0072, 0x0073, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
- // 0xd0-0xdf |
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
- // 0xe0-0xef |
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
- // 0xf0-0xff |
+// Mapping from 8-bit xkb scancode to the USB Usage Page and Id. Each entry |
+// is encoded as follows: |
+// Upper 4 bits: USB Usage Page: |
+// 0x7 : Keyboard/Keypad Page |
+// 0xc : Consumer Page |
+// AL = Application Launch |
+// 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
|
+// |
+// TODO(garykac): This table covers only USB HID Boot Protocol. The keys |
+// marked with '???' should be extended (e.g. with "media keys"), or derived |
+// 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
|
+// |
+// Note: Don't specify array size here since it will automatically zero-fill |
+// out to the specified size if there are not enough values. This will defeat |
+// our arraysize checks at the end. |
+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.
|
+ // 0 - 8: unused |
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
+ 0x0000, |
+ // 9: Escape |
+ 0x7029, |
+ // 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
|
+ 0x701e, 0x701f, 0x7020, 0x7021, 0x7022, 0x7023, 0x7024, 0x7025, |
+ 0x7026, 0x7027, |
+ // 20-21: -_ =+ |
+ 0x702d, 0x702e, |
+ // 22-23: Backspace Tab |
+ 0x702a, 0x702b, |
+ // 24-33: qQ wW eE rR tT yY uU iI oO pP |
+ 0x7014, 0x701a, 0x7008, 0x7015, 0x7017, 0x701c, 0x7018, 0x700c, |
+ 0x7012, 0x7013, |
+ // 34-35: [{ ]} |
+ 0x702f, 0x7030, |
+ // 36: Return |
+ 0x7028, |
+ // 37: LeftControl |
+ 0x70e0, |
+ // 38-46: aA sS dD fF gG hH jJ kK lL |
+ 0x7004, 0x7016, 0x7007, 0x7009, 0x700a, 0x700b, 0x700d, 0x700e, |
+ 0x700f, |
+ // 47-49: ;: '" `~ |
+ 0x7033, 0x7034, 0x7035, |
+ // 50: LeftShift |
+ 0x70e1, |
+ // 51: \| |
+ 0x7031, |
+ // 52-58: zZ xX cC vV bB nN mM |
+ 0x701d, 0x701b, 0x7006, 0x7019, 0x7005, 0x7011, 0x7010, |
+ // 59-61: ,< .> /? |
+ 0x7036, 0x7037, 0x7038, |
+ // 62: RightShift |
+ 0x70e5, |
+ // 63: Keypad_* |
+ 0x7055, |
+ // 64: LeftAlt |
+ 0x70e2, |
+ // 65: Space |
+ 0x702c, |
+ // 66: CapsLock |
+ 0x7039, |
+ // 67-76: F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 |
+ 0x703a, 0x703b, 0x703c, 0x703d, 0x703e, 0x703f, 0x7040, 0x7041, |
+ 0x7042, 0x7043, |
+ // 77: NumLock |
+ 0x7053, |
+ // 78: ScrollLock |
+ 0x7047, |
+ // 79-81: Keypad_7 Keypad_8 Keypad_9 |
+ 0x705f, 0x7060, 0x7061, |
+ // 82: Keypad_- |
+ 0x7056, |
+ // 83-85: Keypad_4 Keypad_5 Keypad_6 |
+ 0x705c, 0x705d, 0x705e, |
+ // 86: Keypad_+ |
+ 0x7057, |
+ // 87-89: Keypad_1 Keypad_2 Keypad_3 |
+ 0x7059, 0x705a, 0x705b, |
+ // 90-91: Keypad_0 Keypad_. |
+ 0x7062, 0x7063, |
+ // 92: ??? (ISO_Level3_Shift) |
+ 0x0000, |
+ // 93: unused |
+ 0x0000, |
+ // 94: ??? <>|| (less than, greater than, bar, broken bar) |
+ // Consider USB#0064 : Non-US \ and | |
+ 0x0000, |
+ // 95-96: F11 F12 |
+ 0x7044, 0x7045, |
+ // 97: unused |
+ 0x0000, |
+ // 98-102: Katakana Hiragana Henkan Hiragana_Katakana Muhenkan |
+ 0x7092, 0x7093, 0x7094, 0x7088, 0x708b, |
+ // 103: unused |
+ 0x0000, |
+ // 104: Keypad_Enter |
+ 0x7058, |
+ // 105: RightControl |
+ 0x70e4, |
+ // 106: Keypad_/ |
+ 0x7054, |
+ // 107: Print/SysReq |
+ // USB#0046 is PrintScreen, USB#009a is SysReq/Attention |
+ 0x7046, |
+ // 108: RightAlt |
+ 0x70e6, |
+ // 109: ??? (Linefeed) |
+ 0x0000, |
+ // 110: Home |
+ 0x704a, |
+ // 111: UpArrow |
+ 0x7052, |
+ // 112: PageUp (Prior) |
+ 0x704b, |
+ // 113: LeftArrow |
+ 0x7050, |
+ // 114: RightArrow |
+ 0x704f, |
+ // 115: End |
+ 0x704d, |
+ // 116: DownArrow |
+ 0x7051, |
+ // 117: PageDown (Next) |
+ 0x704e, |
+ // 118: Insert |
+ 0x7049, |
+ // 119: Delete (Delete Forward) |
+ 0x704c, |
+ // 120: unused |
+ 0x0000, |
+ // 121-123: Mute VolumeDown VolumeUp |
+ 0x707f, 0x7081, 0x7080, |
+ // 124: PowerOff |
+ 0x7066, |
+ // 125: Keypad_= Keypad_+- |
+ 0x7067, 0x00d7, |
+ // 127: Pause/Break |
+ 0x7048, |
+ // 128: ??? LaunchA |
+ 0x0000, |
+ // 129: Keypad_Decimal (cf. 91: Keypad_. and Keypad_Delete) |
+ 0x70dc, |
+ // 130-131: HangulToggle HanjaConversion |
+ 0x7090, 0x7091, |
+ // 132: unused |
+ 0x0000, |
+ // 133-134: LeftSuper/LeftWin RightSuper/RightWin |
+ 0x70e3, 0x70e7, |
+ // 135: Menu |
+ 0x7065, |
+ // 136: Cancel |
+ 0x709b, |
+ // 137: Again (Redo) |
+ 0x7079, |
+ // 138: CrSel/Props |
+ 0x70a3, |
+ // 139: Undo |
+ 0x707a, |
+ // 140: ??? SunFront |
+ 0x0000, |
+ // 141: Copy |
+ 0x707c, |
+ // 142: ??? SunOpen |
+ 0x0000, |
+ // 143: Paste |
+ 0x707d, |
+ // 144: Find |
+ 0x707e, |
+ // 145: Cut |
+ 0x707b, |
+ // 146: Help |
+ 0x7075, |
+ // 147: ??? MenuKB (cf. 135, 193) |
+ 0x0000, |
+ // 148: AL Calculator |
+ 0xc192, |
+ // 149: unused |
+ 0x0000, |
+ // 150: ??? Sleep |
+ 0x0000, |
+ // 151: ??? WakeUp |
+ 0x0000, |
+ // 152: ??? Explorer |
+ 0x0000, |
+ // 153: ??? Send |
+ 0x0000, |
+ // 154: unused |
+ 0x0000, |
+ // 155: ??? Xfer |
+ 0x0000, |
+ // 156: ??? Launch1 |
+ 0x0000, |
+ // 157: ??? Launch2 |
+ 0x0000, |
+ // 158: ??? WWW |
+ 0x0000, |
+ // 159: ??? DOS |
+ 0x0000, |
+ // 160: ??? ScreenSaver |
+ 0x0000, |
+ // 161: unused |
+ 0x0000, |
+ // 162: ??? RotateWindows |
+ 0x0000, |
+ // 163: ??? Mail |
+ 0x0000, |
+ // 164: ??? Favorites |
+ 0x0000, |
+ // 165: ??? MyComputer |
+ 0x0000, |
+ // 166: ??? Back |
+ 0x0000, |
+ // 167: ??? Forward |
+ 0x0000, |
+ // 168: unused |
+ 0x0000, |
+ // 169-170: ??? Eject Eject (encode the same) |
+ 0x0000, 0x0000, |
+ // 171-176: ???AudioNext AudioPlay AudioPrev AudioStop AudioRecord AudioRewind |
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
+ // 177: ??? Phone |
+ 0x0000, |
+ // 178: unused |
+ 0x0000, |
+ // 179: ??? Tools |
+ 0x0000, |
+ // 180: ??? HomePage |
+ 0x0000, |
+ // 181: ??? Reload |
+ 0x0000, |
+ // 182: ??? Close |
+ 0x0000, |
+ // 183-184: unused |
+ 0x0000, 0x0000, |
+ // 185: ??? ScrollUp |
+ 0x0000, |
+ // 186: ??? ScrollDown |
+ 0x0000, |
+ // 187-188: ( ) (Mapped to Keypad_( and Keypad_)) |
+ 0x70b6, 0x70b7, |
+ // 189: ??? New |
+ 0x0000, |
+ // 190: ??? Redo |
+ 0x0000, |
+ // 191: ??? Tools |
+ 0x0000, |
+ // 192: ??? Launch5 |
+ 0x0000, |
+ // 193: ??? MenuKB |
+ 0x0000, |
+ // 194-199: unused |
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
+ // 200: ??? TouchpadToggle |
+ 0x0000, |
+ // 201-202: unused |
+ 0x0000, 0x0000, |
+ // 203: ??? ModeSwitch |
+ 0x0000, |
+ // 204-207: Generates no symbol without Shift. |
+ // With shift: LeftAlt LeftMeta LeftSuper LeftHyper. |
+ 0x0000, 0x0000, 0x0000, 0x0000, |
+ // 208-209: ??? AudioPlay AudioPause |
+ 0x0000, 0x0000, |
+ // 210-212: ??? Launch3 Launch4 LaunchB |
+ 0x0000, 0x0000, 0x0000, |
+ // 213: ??? Suspend |
+ 0x0000, |
+ // 214: ??? Close |
+ 0x0000, |
+ // 215-216: ??? AudioPlay AudioForward |
+ 0x0000, 0x0000, |
+ // 217: unused |
+ 0x0000, |
+ // 218: ??? Print |
+ 0x0000, |
+ // 219: unused |
+ 0x0000, |
+ // 220: ??? WebCam |
+ 0x0000, |
+ // 221-222: unused |
+ 0x0000, 0x0000, |
+ // 223: ??? Mail |
+ 0x0000, |
+ // 224: unused |
+ 0x0000, |
+ // 225: ??? Search |
+ 0x0000, |
+ // 226: unused |
+ 0x0000, |
+ // 227: AL Finance |
+ 0xc191, |
+ // 228: unused |
+ 0x0000, |
+ // 229: ??? Shop |
+ 0x0000, |
+ // 230: unused |
+ 0x0000, |
+ // 231: ??? Cancel |
+ 0x0000, |
+ // 232-233: ??? MonBrightnessDown MonBrightnessUp |
+ 0x0000, 0x0000, |
+ // 234: ??? AudioMedia |
+ 0x0000, |
+ // 235: ??? Display |
+ 0x0000, |
+ // 236-238: ??? KbdLightOnOff KbdBightnessDown KdbBrightnessUp |
+ 0x0000, 0x0000, 0x0000, |
+ // 239: ??? Send |
+ 0x0000, |
+ // 240: ??? Reply |
+ 0x0000, |
+ // 241: ??? MailForward |
+ 0x0000, |
+ // 242: ??? Save |
+ 0x0000, |
+ // 243: ??? Documents |
+ 0x0000, |
+ // 244: ??? Battery |
+ 0x0000, |
+ // 245: ??? Bluetooth |
+ 0x0000, |
+ // 246: ??? WLAN |
+ 0x0000, |
+ // 247-255: unused |
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, |
+ 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.
|
}; |
+// Compile time check to ensure we have exactly 256 entries. |
+COMPILE_ASSERT_ARRAY_SIZE(linux_xkb_code_to_usb, uint16_t, 256); |
+ |
} // anonymous namespace |
uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { |
// TODO(garykac): This code assumes that on Linux we're receiving events via |
- // the Xorg "evdev" driver. We should detect "XKB" or "kbd" at run-time and |
- // re-map accordingly, but that's not possible here, inside the sandbox. |
- if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 255) |
+ // 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.
|
+ // run-time and re-map accordingly, but that's not possible here, inside the |
+ // sandbox. |
+ 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.
|
+ if (key_event.nativeKeyCode >= 0 && key_event.nativeKeyCode < 255) { |
+ usb_id = linux_xkb_code_to_usb[key_event.nativeKeyCode]; |
+ } |
+ |
+ VLOG(3) << std::hex << "native: " << key_event.nativeKeyCode |
+ << " usb: " << usb_id; |
+ if (usb_id == 0) |
return 0; |
- uint32_t usbkeycode = 0; |
- uint16_t code = linux_evdev_key_code_to_usb[key_event.nativeKeyCode]; |
- if (code != 0) { |
- // Set complete scancode to be the USB keyboard page (7) and key scancode. |
- usbkeycode = 0x070000 | code; |
- } |
- return usbkeycode; |
+ uint32_t usb_page = usb_id & 0xF000; |
+ usb_id &= 0x0FFF; |
+ uint32_t usb_keycode = (usb_page << 4) | usb_id; |
+ return usb_keycode; |
} |
} // namespace ppapi |