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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/usb_key_code_conversion.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/ppapi/usb_key_code_conversion.h"
6
7 #include "base/basictypes.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
9
10 using WebKit::WebKeyboardEvent;
11
12 namespace webkit {
13 namespace ppapi {
14
15 namespace {
16
17 typedef struct {
18 uint32_t usb_keycode;
19 uint16_t native_keycode;
20 } mac_usb_keymap;
21
22 // This is extracted from the conversion table that currently lives in
23 // remoting/host/usb_keycode_map.h.
24 // TODO(garykac): Remove this copy and use a shared conversion table.
25 const mac_usb_keymap mac_keycode_to_usb[] = {
26 {0x070004, 0x0000}, // aA
27 {0x070005, 0x000b}, // bB
28 {0x070006, 0x0008}, // cC
29 {0x070007, 0x0002}, // dD
30 {0x070008, 0x000e}, // eE
31 {0x070009, 0x0003}, // fF
32 {0x07000a, 0x0005}, // gG
33 {0x07000b, 0x0004}, // hH
34 {0x07000c, 0x0022}, // iI
35 {0x07000d, 0x0026}, // jJ
36 {0x07000e, 0x0028}, // kK
37 {0x07000f, 0x0025}, // lL
38 {0x070010, 0x002e}, // mM
39 {0x070011, 0x002d}, // nN
40 {0x070012, 0x001f}, // oO
41 {0x070013, 0x0023}, // pP
42 {0x070014, 0x000c}, // qQ
43 {0x070015, 0x000f}, // rR
44 {0x070016, 0x0001}, // sS
45 {0x070017, 0x0011}, // tT
46 {0x070018, 0x0020}, // uU
47 {0x070019, 0x0009}, // vV
48 {0x07001a, 0x000d}, // wW
49 {0x07001b, 0x0007}, // xX
50 {0x07001c, 0x0010}, // yY
51 {0x07001d, 0x0006}, // zZ
52 {0x07001e, 0x0012}, // 1!
53 {0x07001f, 0x0013}, // 2@
54 {0x070020, 0x0014}, // 3#
55 {0x070021, 0x0015}, // 4$
56 {0x070022, 0x0017}, // 5%
57 {0x070023, 0x0016}, // 6^
58 {0x070024, 0x001a}, // 7&
59 {0x070025, 0x001c}, // 8*
60 {0x070026, 0x0019}, // 9(
61 {0x070027, 0x001d}, // 0)
62 {0x070028, 0x0024}, // Return
63 {0x070029, 0x0035}, // Escape
64 {0x07002a, 0x0033}, // Backspace
65 {0x07002b, 0x0030}, // Tab
66 {0x07002c, 0x0031}, // Spacebar
67 {0x07002d, 0x001b}, // -_
68 {0x07002e, 0x0018}, // =+
69 {0x07002f, 0x0021}, // [{
70 {0x070030, 0x001e}, // }]
71 {0x070031, 0x002a}, // \| (US keyboard only)
72 {0x070032, 0x002a}, // #~ (Non-US)
73 {0x070033, 0x0029}, // ;:
74 {0x070034, 0x0027}, // '"
75 {0x070035, 0x0032}, // `~
76 {0x070036, 0x002b}, // ,<
77 {0x070037, 0x002f}, // .>
78 {0x070038, 0x002c}, // /?
79 {0x070039, 0x0039}, // CapsLock
80 {0x07003a, 0x007a}, // F1
81 {0x07003b, 0x0078}, // F2
82 {0x07003c, 0x0063}, // F3
83 {0x07003d, 0x0076}, // F4
84 {0x07003e, 0x0060}, // F5
85 {0x07003f, 0x0061}, // F6
86 {0x070040, 0x0062}, // F7
87 {0x070041, 0x0064}, // F8
88 {0x070042, 0x0065}, // F9
89 {0x070043, 0x006d}, // F10
90 {0x070044, 0x0067}, // F11
91 {0x070045, 0x006f}, // F12
92 {0x070049, 0x0072}, // Insert
93 {0x07004a, 0x0073}, // Home
94 {0x07004b, 0x0074}, // PageUp
95 {0x07004c, 0x0075}, // Delete (Forward Delete)
96 {0x07004d, 0x0077}, // End
97 {0x07004e, 0x0079}, // PageDown
98 {0x07004f, 0x007c}, // RightArrow
99 {0x070050, 0x007b}, // LeftArrow
100 {0x070051, 0x007d}, // DownArrow
101 {0x070052, 0x007e}, // UpArrow
102 {0x070053, 0x0047}, // Keypad_NumLock Clear
103 {0x070054, 0x004b}, // Keypad_/
104 {0x070055, 0x0043}, // Keypad_*
105 {0x070056, 0x004e}, // Keypad_-
106 {0x070057, 0x0045}, // Keypad_+
107 {0x070058, 0x004c}, // Keypad_Enter
108 {0x070059, 0x0053}, // Keypad_1 End
109 {0x07005a, 0x0054}, // Keypad_2 DownArrow
110 {0x07005b, 0x0055}, // Keypad_3 PageDown
111 {0x07005c, 0x0056}, // Keypad_4 LeftArrow
112 {0x07005d, 0x0057}, // Keypad_5
113 {0x07005e, 0x0058}, // Keypad_6 RightArrow
114 {0x07005f, 0x0059}, // Keypad_7 Home
115 {0x070060, 0x005b}, // Keypad_8 UpArrow
116 {0x070061, 0x005c}, // Keypad_9 PageUp
117 {0x070062, 0x0052}, // Keypad_0 Insert
118 {0x070063, 0x0041}, // Keypad_. Delete
119 {0x070067, 0x0051}, // Keypad_=
120 {0x070068, 0x0069}, // F13
121 {0x070069, 0x006b}, // F14
122 {0x07006a, 0x0071}, // F15
123 {0x07006b, 0x006a}, // F16
124 {0x07006c, 0x0040}, // F17
125 {0x07006d, 0x004f}, // F18
126 {0x07006e, 0x0050}, // F19
127 {0x07006f, 0x005a}, // F20
128 {0x07007f, 0x004a}, // Mute
129 {0x070080, 0x0048}, // VolumeUp
130 {0x070081, 0x0049}, // VolumeDown
131 {0x070085, 0x005f}, // Keypad_Comma
132 {0x070087, 0x005e}, // International1
133 {0x070088, 0x0068}, // International2
134 {0x070089, 0x005d}, // International3
135 {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
136 {0x0700e1, 0x0038}, // LeftShift
137 {0x0700e2, 0x003a}, // LeftAlt/Option
138 {0x0700e3, 0x0037}, // LeftGUI/Super/Win/Cmd
139 {0x0700e4, 0x003e}, // RightControl
140 {0x0700e5, 0x003c}, // RightShift
141 {0x0700e6, 0x003d}, // RightAlt/Option
142 {0x0700e7, 0x0036}, // RightGUI/Super/Win/Cmd
143 };
144
145 } // anonymous namespace
146
147 uint32_t UsbKeyCodeForKeyboardEvent(const WebKeyboardEvent& key_event) {
148 if (key_event.nativeKeyCode < 0 || key_event.nativeKeyCode > 0x7f)
149 return 0;
150
151 for (uint i = 0; i < arraysize(mac_keycode_to_usb); i++) {
152 if (mac_keycode_to_usb[i].native_keycode == key_event.nativeKeyCode)
153 return mac_keycode_to_usb[i].usb_keycode;
154 }
155
156 return 0;
157 }
158
159 } // namespace ppapi
160 } // namespace webkit
OLDNEW
« 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