Index: webkit/plugins/ppapi/usb_key_code_conversion_win.cc |
=================================================================== |
--- webkit/plugins/ppapi/usb_key_code_conversion_win.cc (revision 0) |
+++ webkit/plugins/ppapi/usb_key_code_conversion_win.cc (revision 0) |
@@ -0,0 +1,177 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
Wez
2012/03/07 23:35:50
We probably need a comment indicating that the tab
|
+ |
+#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; |
+ |
+namespace webkit { |
+namespace ppapi { |
+ |
+namespace { |
+ |
+uint8_t win_scancode_to_usb[128] = { |
Wez
2012/03/07 23:35:50
This table should be laid out in blocks of e.g. 4
Wez
2012/03/07 23:35:50
Your table has 128 entries, but the scancode is an
|
+ // 00: unused |
+ 0x00, |
+ // 01: Escape |
+ 0x29, |
+ // 02-0b: 1! 2@ 3# 4$ 5% 6^ 7& 8* 9( 0) |
Wez
2012/03/07 23:35:50
Please put commas between the key names, to make t
|
+ 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, |
+ 0x24, 0x25, 0x26, 0x27, |
+ // 0c-0d: -_ =+ |
+ 0x2d, 0x2e, |
+ // 0e-0f: Backspace Tab |
+ 0x2a, 0x2b, |
+ // 10-19: qQ wW eE rR tT yY uU iI oO pP |
+ 0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c, |
+ 0x12, 0x13, |
+ // 1a-1d: [{ ]} Enter LeftControl |
+ 0x2f, 0x30, 0x28, 0xe0, |
+ // 1e-26: aA sS dD fF gG hH jJ kK lL |
+ 0x04, 0x16, |
+ 0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x0f, |
+ // 27-2a: ;: '" `~ LeftShift |
+ 0x33, |
+ 0x34, 0x35, 0xe1, |
+ // 2b: \| (US keyboards only) |
+ 0x31, |
+ // 2c-32: zZ xX cC vV bB nN mM |
+ 0x1d, 0x1b, 0x06, 0x19, |
+ 0x05, 0x11, 0x10, |
+ // 33-36: ,< .> /? RightShift |
+ 0x36, 0x37, 0x38, 0xe5, |
+ // 37: unused |
+ 0x00, |
+ // 38-3a: LeftAlt Space CapsLock |
+ 0xe2, 0x2c, 0x39, |
+ // 3b-44: F1 ... F10 |
+ 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, |
+ 0x3f, 0x40, 0x41, 0x42, 0x43, |
+ // 45: NumLock |
+ 0x53, |
+ // 46: ScrollLock |
+ 0x47, |
+ // 47-4a: KP_7 KP_8 KP_9 KP_- |
+ 0x5f, |
+ 0x60, 0x61, 0x56, |
+ // 4b-4e: KP_4 KP_5 KP_6 KP_+ |
+ 0x5c, 0x5d, 0x5e, 0x57, |
+ // 4f-53: KP_1 KP_2 KP_3 KP_0 KP_. |
+ 0x59, |
+ 0x5a, 0x5b, 0x62, 0x63, |
+ // 54-5a: unused |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, |
+ // 5b-5d: F13 F14 F15 |
+ 0x68, 0x69, 0x6a, |
+ // 5e-62: unused |
+ 0x00, 0x00, |
+ 0x00, 0x00, 0x00, |
+ // 63-6b: F16 ... F24 |
+ 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, |
+ 0x70, 0x71, 0x72, 0x73, |
+ // 6c-7f: unused |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
+}; |
+ |
+uint8_t win_extended_scancode_to_usb[128] = { |
+ // 00-1b: unused |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ // 1c-1d: Keypad_Enter RightControl |
+ 0x58, 0xe4, |
+ // 1e-34: unused |
+ 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, |
+ // 35: Keypad_/ |
+ 0x54, |
+ // 36: unused |
+ 0x00, |
+ // 37: PrintScreen |
+ 0x46, |
+ // 38: RightAlt |
+ 0xe6, |
+ // 39-44: unused |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, |
+ // 45-46: unused |
+ 0x00, 0x00, |
+ // 47: Home |
+ 0x4a, |
+ // 48-49: UpArrow PageUp |
+ 0x52, 0x4b, |
+ // 4a: unused |
+ 0x00, |
+ // 4b: LeftArrow |
+ 0x50, |
+ // 4c: unused |
+ 0x00, |
+ // 4d: RightArrow |
+ 0x4f, |
+ // 4e: unused |
+ 0x00, |
+ // 4f: End |
+ 0x4d, |
+ // 50-53: DownArrow PageDown Insert Delete |
+ 0x51, 0x4e, 0x49, 0x4c, |
+ // 54-5a: unused |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, |
+ // 5b-5d: LeftWin RightWin AppsMenu |
+ 0xe3, 0xe7, 0x65, |
+ // 5e-5f: Power Sleep |
+ 0x00, 0x00, |
+ // 60-7f: unused |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
+}; |
+ |
+} // anonymous namespace |
+ |
+uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) { |
+ // The |nativeKeycode| on Windows comes from the key event's lParam: |
+ // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 |
+ // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 |
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
+ // |t p c 0 0 0 0 e <--scan-code--> <--------repeat-count--------->| |
+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
+ // transition state [t]: 0 for keydown, 1 for keyup |
+ // previous key state [p] |
+ // context code [c] |
+ // extended key [e]: 1 for extended keys (like RightAlt, RightCtrl). |
+ // scan-code: The scan code from the keyboard. |
+ // repeat-count: The number of times the key is auto-repeated. |
Wez
2012/03/07 23:35:50
This is more detail than we need here; we only car
|
+ int scancode = (key_event.nativeKeyCode >> 16) & 0x00FF; |
+ if (scancode >= 128) |
+ return 0; |
+ |
+ bool extended = (key_event.nativeKeyCode & 0x1000000) != 0; |
+ uint16_t usb_id = 0; |
+ if (extended) { |
Wez
2012/03/07 23:35:50
Merge the two tables into a single 512-entry table
|
+ usb_id = win_extended_scancode_to_usb[scancode]; |
+ } else { |
+ usb_id = win_scancode_to_usb[scancode]; |
+ } |
+ VLOG(3) << "Converting scancode: " << std::hex << scancode |
+ << " extended: " << extended << " to usb: " << usb_id << std::dec; |
+ if (usb_id == 0) |
+ return 0; |
+ |
+ uint32_t usbkeycode = 0x070000 | usb_id; |
Wez
2012/03/07 23:35:50
Why are you hard-coding all keys to the keyboard p
|
+ return usbkeycode; |
+} |
+ |
+} // namespace ppapi |
+} // namespace webkit |