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

Unified Diff: webkit/plugins/ppapi/usb_key_code_conversion_mac.mm

Issue 9701030: Native to USB keycode conversion for Mac (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/plugins/ppapi/usb_key_code_conversion.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/usb_key_code_conversion_mac.mm
===================================================================
--- webkit/plugins/ppapi/usb_key_code_conversion_mac.mm (revision 0)
+++ webkit/plugins/ppapi/usb_key_code_conversion_mac.mm (working copy)
@@ -0,0 +1,160 @@
+// 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.
+
+#include "webkit/plugins/ppapi/usb_key_code_conversion.h"
+
+#include "base/basictypes.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
+
+using WebKit::WebKeyboardEvent;
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+typedef struct {
+ uint32_t usb_keycode;
+ uint16_t native_keycode;
+} mac_usb_keymap;
+
+// This is extracted from the conversion table that currently lives in
+// remoting/host/usb_keycode_map.h.
+// TODO(garykac): Remove this copy and use a shared conversion table.
+const mac_usb_keymap mac_keycode_to_usb[] = {
+ {0x070004, 0x0000}, // aA
+ {0x070005, 0x000b}, // bB
+ {0x070006, 0x0008}, // cC
+ {0x070007, 0x0002}, // dD
+ {0x070008, 0x000e}, // eE
+ {0x070009, 0x0003}, // fF
+ {0x07000a, 0x0005}, // gG
+ {0x07000b, 0x0004}, // hH
+ {0x07000c, 0x0022}, // iI
+ {0x07000d, 0x0026}, // jJ
+ {0x07000e, 0x0028}, // kK
+ {0x07000f, 0x0025}, // lL
+ {0x070010, 0x002e}, // mM
+ {0x070011, 0x002d}, // nN
+ {0x070012, 0x001f}, // oO
+ {0x070013, 0x0023}, // pP
+ {0x070014, 0x000c}, // qQ
+ {0x070015, 0x000f}, // rR
+ {0x070016, 0x0001}, // sS
+ {0x070017, 0x0011}, // tT
+ {0x070018, 0x0020}, // uU
+ {0x070019, 0x0009}, // vV
+ {0x07001a, 0x000d}, // wW
+ {0x07001b, 0x0007}, // xX
+ {0x07001c, 0x0010}, // yY
+ {0x07001d, 0x0006}, // zZ
+ {0x07001e, 0x0012}, // 1!
+ {0x07001f, 0x0013}, // 2@
+ {0x070020, 0x0014}, // 3#
+ {0x070021, 0x0015}, // 4$
+ {0x070022, 0x0017}, // 5%
+ {0x070023, 0x0016}, // 6^
+ {0x070024, 0x001a}, // 7&
+ {0x070025, 0x001c}, // 8*
+ {0x070026, 0x0019}, // 9(
+ {0x070027, 0x001d}, // 0)
+ {0x070028, 0x0024}, // Return
+ {0x070029, 0x0035}, // Escape
+ {0x07002a, 0x0033}, // Backspace
+ {0x07002b, 0x0030}, // Tab
+ {0x07002c, 0x0031}, // Spacebar
+ {0x07002d, 0x001b}, // -_
+ {0x07002e, 0x0018}, // =+
+ {0x07002f, 0x0021}, // [{
+ {0x070030, 0x001e}, // }]
+ {0x070031, 0x002a}, // \| (US keyboard only)
+ {0x070032, 0x002a}, // #~ (Non-US)
+ {0x070033, 0x0029}, // ;:
+ {0x070034, 0x0027}, // '"
+ {0x070035, 0x0032}, // `~
+ {0x070036, 0x002b}, // ,<
+ {0x070037, 0x002f}, // .>
+ {0x070038, 0x002c}, // /?
+ {0x070039, 0x0039}, // CapsLock
+ {0x07003a, 0x007a}, // F1
+ {0x07003b, 0x0078}, // F2
+ {0x07003c, 0x0063}, // F3
+ {0x07003d, 0x0076}, // F4
+ {0x07003e, 0x0060}, // F5
+ {0x07003f, 0x0061}, // F6
+ {0x070040, 0x0062}, // F7
+ {0x070041, 0x0064}, // F8
+ {0x070042, 0x0065}, // F9
+ {0x070043, 0x006d}, // F10
+ {0x070044, 0x0067}, // F11
+ {0x070045, 0x006f}, // F12
+ {0x070049, 0x0072}, // Insert
+ {0x07004a, 0x0073}, // Home
+ {0x07004b, 0x0074}, // PageUp
+ {0x07004c, 0x0075}, // Delete (Forward Delete)
+ {0x07004d, 0x0077}, // End
+ {0x07004e, 0x0079}, // PageDown
+ {0x07004f, 0x007c}, // RightArrow
+ {0x070050, 0x007b}, // LeftArrow
+ {0x070051, 0x007d}, // DownArrow
+ {0x070052, 0x007e}, // UpArrow
+ {0x070053, 0x0047}, // Keypad_NumLock Clear
+ {0x070054, 0x004b}, // Keypad_/
+ {0x070055, 0x0043}, // Keypad_*
+ {0x070056, 0x004e}, // Keypad_-
+ {0x070057, 0x0045}, // Keypad_+
+ {0x070058, 0x004c}, // Keypad_Enter
+ {0x070059, 0x0053}, // Keypad_1 End
+ {0x07005a, 0x0054}, // Keypad_2 DownArrow
+ {0x07005b, 0x0055}, // Keypad_3 PageDown
+ {0x07005c, 0x0056}, // Keypad_4 LeftArrow
+ {0x07005d, 0x0057}, // Keypad_5
+ {0x07005e, 0x0058}, // Keypad_6 RightArrow
+ {0x07005f, 0x0059}, // Keypad_7 Home
+ {0x070060, 0x005b}, // Keypad_8 UpArrow
+ {0x070061, 0x005c}, // Keypad_9 PageUp
+ {0x070062, 0x0052}, // Keypad_0 Insert
+ {0x070063, 0x0041}, // Keypad_. Delete
+ {0x070067, 0x0051}, // Keypad_=
+ {0x070068, 0x0069}, // F13
+ {0x070069, 0x006b}, // F14
+ {0x07006a, 0x0071}, // F15
+ {0x07006b, 0x006a}, // F16
+ {0x07006c, 0x0040}, // F17
+ {0x07006d, 0x004f}, // F18
+ {0x07006e, 0x0050}, // F19
+ {0x07006f, 0x005a}, // F20
+ {0x07007f, 0x004a}, // Mute
+ {0x070080, 0x0048}, // VolumeUp
+ {0x070081, 0x0049}, // VolumeDown
+ {0x070085, 0x005f}, // Keypad_Comma
+ {0x070087, 0x005e}, // International1
+ {0x070088, 0x0068}, // International2
+ {0x070089, 0x005d}, // International3
+ {0x0700e0, 0x003b}, // LeftControl
dmichael (off chromium) 2012/03/14 19:36:02 There's a discontinuity here. Is that expected & c
garykac 2012/03/14 20:26:06 Yes. In that space there's a bunch of special Keyp
dmichael (off chromium) 2012/03/14 20:50:26 A short comment to that effect might help, just so
+ {0x0700e1, 0x0038}, // LeftShift
+ {0x0700e2, 0x003a}, // LeftAlt/Option
+ {0x0700e3, 0x0037}, // LeftGUI/Super/Win/Cmd
+ {0x0700e4, 0x003e}, // RightControl
+ {0x0700e5, 0x003c}, // RightShift
+ {0x0700e6, 0x003d}, // RightAlt/Option
+ {0x0700e7, 0x0036}, // RightGUI/Super/Win/Cmd
+};
+
+} // anonymous namespace
+
+uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) {
+ if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 0x7f)
+ return 0;
+
+ for (uint i = 0; i < arraysize(mac_keycode_to_usb); i++) {
+ if (mac_keycode_to_usb[i].native_keycode == key_event.nativeKeyCode)
+ return mac_keycode_to_usb[i].usb_keycode;
+ }
+
+ return 0;
+}
+
+} // namespace ppapi
+} // namespace webkit
« no previous file with comments | « webkit/plugins/ppapi/usb_key_code_conversion.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698