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

Side by Side Diff: ui/events/keycodes/keyboard_code_conversion.cc

Issue 841263005: Use DOM- rather than Windows-based key code for non-layout cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/events/keycodes/keyboard_code_conversion.h" 5 #include "ui/events/keycodes/keyboard_code_conversion.h"
6 6
7 #include <algorithm>
8
7 #include "ui/events/event_constants.h" 9 #include "ui/events/event_constants.h"
8 #include "ui/events/keycodes/dom3/dom_code.h" 10 #include "ui/events/keycodes/dom3/dom_code.h"
9 #include "ui/events/keycodes/dom3/dom_key.h" 11 #include "ui/events/keycodes/dom3/dom_key.h"
10 12
11 namespace ui { 13 namespace ui {
12 14
13 namespace { 15 namespace {
14 16
17 // This table maps a DomCode to a printable character, assuming US layout.
18 // All of the characters have low ordinals, so we use bit 15 to flag dead keys.
19 #define DK 0x8000
Wez 2015/01/17 02:06:47 Use a const char16 for this instead of a macro?
kpschoedel 2015/04/10 18:32:33 Removed entirely.
20 const struct PrintableCodeEntry {
21 DomCode dom_code;
22 base::char16 character[4];
23 } kPrintableCodeMap[] = {
Wez 2015/01/17 02:06:47 Suggest moving this into a separate file e.g. dom_
kpschoedel 2015/02/18 17:14:01 Done.
24 // Stub table based on X US international.
25 {DomCode::KEY_A, {'a', 'A', 0x00E1, 0x00C1}},
26 {DomCode::KEY_B, {'b', 'B', 'b', 'B'}},
27 {DomCode::KEY_C, {'c', 'C', 0x00A9, 0x00A2}},
28 {DomCode::KEY_D, {'d', 'D', 0x00F0, 0x00D0}},
29 {DomCode::KEY_E, {'e', 'E', 0x00E9, 0x00C9}},
30 {DomCode::KEY_F, {'f', 'F', 'f', 'F'}},
31 {DomCode::KEY_G, {'g', 'G', 'g', 'G'}},
32 {DomCode::KEY_H, {'h', 'H', 'h', 'H'}},
33 {DomCode::KEY_I, {'i', 'I', 0x00ED, 0x00CD}},
34 {DomCode::KEY_J, {'j', 'J', 'j', 'J'}},
35 {DomCode::KEY_K, {'k', 'K', 0x0153, 0x0152}},
36 {DomCode::KEY_L, {'l', 'L', 0x00F8, 0x00D8}},
37 {DomCode::KEY_M, {'m', 'M', 0x00B5, 0x00B5}},
38 {DomCode::KEY_N, {'n', 'N', 0x00F1, 0x00D1}},
39 {DomCode::KEY_O, {'o', 'O', 0x00F3, 0x00D3}},
40 {DomCode::KEY_P, {'p', 'P', 0x00F6, 0x00D6}},
41 {DomCode::KEY_Q, {'q', 'Q', 0x00E4, 0x00C4}},
42 {DomCode::KEY_R, {'r', 'R', 0x00AE, 0x00AE}},
43 {DomCode::KEY_S, {'s', 'S', 0x00DF, 0x00A7}},
44 {DomCode::KEY_T, {'t', 'T', 0x00FE, 0x00DE}},
45 {DomCode::KEY_U, {'u', 'U', 0x00FA, 0x00DA}},
46 {DomCode::KEY_V, {'v', 'V', 'v', 'V'}},
47 {DomCode::KEY_W, {'w', 'W', 0x00E5, 0x00C5}},
48 {DomCode::KEY_X, {'x', 'X', 'x', 'X'}},
49 {DomCode::KEY_Y, {'y', 'Y', 0x00FC, 0x00DC}},
50 {DomCode::KEY_Z, {'z', 'Z', 0x00E6, 0x00C6}},
51 {DomCode::DIGIT1, {'1', '!', 0x00A1, 0x00B9}},
52 {DomCode::DIGIT2, {'2', '@', 0x00B2, DK | 0x030B}},
53 {DomCode::DIGIT3, {'3', '#', 0x00B3, DK | 0x0304}},
54 {DomCode::DIGIT4, {'4', '$', 0x00A4, 0x00A3}},
55 {DomCode::DIGIT5, {'5', '%', 0x20AC, DK | 0x0327}},
56 {DomCode::DIGIT6, {'6', '^', DK | 0x0302, 0x00BC}},
57 {DomCode::DIGIT7, {'7', '&', 0x00BD, DK | 0x031B}},
58 {DomCode::DIGIT8, {'8', '*', 0x00BE, DK | 0x0328}},
59 {DomCode::DIGIT9, {'9', '(', 0x2018, DK | 0x0306}},
60 {DomCode::DIGIT0, {'0', ')', 0x2019, DK | 0x030A}},
61 {DomCode::SPACE, {' ', ' ', 0x00A0, 0x00A0}},
62 {DomCode::MINUS, {'-', '_', 0x00A5, DK | 0x0323}},
63 {DomCode::EQUAL, {'=', '+', 0x00D7, 0x00F7}},
64 {DomCode::BRACKET_LEFT, {'[', '{', 0x00AB, 0x201C}},
65 {DomCode::BRACKET_RIGHT, {']', '}', 0x00BB, 0x201D}},
66 {DomCode::BACKSLASH, {'\\', '|', 0x00AC, 0x00A6}},
67 {DomCode::SEMICOLON, {';', ':', 0x00B6, 0x00B0}},
68 {DomCode::QUOTE, {'\'', '"', DK | 0x0301, DK | 0x0308}},
69 {DomCode::BACKQUOTE, {'`', '~', DK | 0x0300, DK | 0x0303}},
70 {DomCode::COMMA, {',', '<', 0x00E7, 0x00C7}},
71 {DomCode::PERIOD, {'.', '>', DK | 0x0307, DK | 0x030C}},
72 {DomCode::SLASH, {'/', '?', 0x00BF, DK | 0x0309}},
73 {DomCode::INTL_BACKSLASH, {'\\', '|', '\\', '|'}},
74 {DomCode::INTL_YEN, {0x00A5, '|', 0x00A5, '|'}},
75 {DomCode::NUMPAD_DIVIDE, {'/', '/', '/', '/'}},
76 {DomCode::NUMPAD_MULTIPLY, {'*', '*', '*', '*'}},
77 {DomCode::NUMPAD_SUBTRACT, {'-', '-', '-', '-'}},
78 {DomCode::NUMPAD_ADD, {'+', '+', '+', '+'}},
79 {DomCode::NUMPAD1, {'1', '1', '1', '1'}},
80 {DomCode::NUMPAD2, {'2', '2', '2', '2'}},
81 {DomCode::NUMPAD3, {'3', '3', '3', '3'}},
82 {DomCode::NUMPAD4, {'4', '4', '4', '4'}},
83 {DomCode::NUMPAD5, {'5', '5', '5', '5'}},
84 {DomCode::NUMPAD6, {'6', '6', '6', '6'}},
85 {DomCode::NUMPAD7, {'7', '7', '7', '7'}},
86 {DomCode::NUMPAD8, {'8', '8', '8', '8'}},
87 {DomCode::NUMPAD9, {'9', '9', '9', '9'}},
88 {DomCode::NUMPAD0, {'0', '0', '0', '0'}},
89 {DomCode::NUMPAD_DECIMAL, {'.', '.', '.', '.'}},
90 {DomCode::NUMPAD_EQUAL, {'=', '=', '=', '='}},
91 {DomCode::NUMPAD_COMMA, {',', ',', ',', ','}},
92 {DomCode::NUMPAD_PAREN_LEFT, {'(', '(', '(', '('}},
93 {DomCode::NUMPAD_PAREN_RIGHT, {')', ')', ')', ')'}},
94 {DomCode::NUMPAD_SIGN_CHANGE, {0x00B1, 0x00B1, 0x2213, 0x2213}},
95 };
96
97 // This table maps a DomCode to a DomKey, assuming US keyboard layout.
98 const struct NonPrintableCodeEntry {
99 DomCode dom_code;
100 DomKey dom_key;
101 base::char16 character;
102 } kNonPrintableCodeMap[] = {
103 {DomCode::ABORT, DomKey::CANCEL},
104 {DomCode::AGAIN, DomKey::AGAIN},
105 {DomCode::ALT_LEFT, DomKey::ALT},
106 {DomCode::ALT_RIGHT, DomKey::ALT},
107 {DomCode::ARROW_DOWN, DomKey::ARROW_DOWN},
108 {DomCode::ARROW_LEFT, DomKey::ARROW_LEFT},
109 {DomCode::ARROW_RIGHT, DomKey::ARROW_RIGHT},
110 {DomCode::ARROW_UP, DomKey::ARROW_UP},
111 {DomCode::BACKSPACE, DomKey::BACKSPACE, 0x0008},
112 {DomCode::BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN},
113 {DomCode::BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP},
114 // {DomCode::BRIGHTNESS_AUTO, DomKey::_}
115 // {DomCode::BRIGHTNESS_MAXIMUM, DomKey::_}
116 // {DomCode::BRIGHTNESS_MINIMIUM, DomKey::_}
117 // {DomCode::BRIGHTNESS_TOGGLE, DomKey::_}
118 {DomCode::BROWSER_BACK, DomKey::BROWSER_BACK},
119 {DomCode::BROWSER_FAVORITES, DomKey::BROWSER_FAVORITES},
120 {DomCode::BROWSER_FORWARD, DomKey::BROWSER_FORWARD},
121 {DomCode::BROWSER_HOME, DomKey::BROWSER_HOME},
122 {DomCode::BROWSER_REFRESH, DomKey::BROWSER_REFRESH},
123 {DomCode::BROWSER_SEARCH, DomKey::BROWSER_SEARCH},
124 {DomCode::BROWSER_STOP, DomKey::BROWSER_STOP},
125 {DomCode::CAPS_LOCK, DomKey::CAPS_LOCK},
126 {DomCode::CONTEXT_MENU, DomKey::CONTEXT_MENU},
127 {DomCode::CONTROL_LEFT, DomKey::CONTROL},
128 {DomCode::CONTROL_RIGHT, DomKey::CONTROL},
129 {DomCode::CONVERT, DomKey::CONVERT},
130 {DomCode::COPY, DomKey::COPY},
131 {DomCode::CUT, DomKey::CUT},
132 {DomCode::DEL, DomKey::DEL, 0x007F},
133 {DomCode::EJECT, DomKey::EJECT},
134 {DomCode::END, DomKey::END},
135 {DomCode::ENTER, DomKey::ENTER, 0x000D},
136 {DomCode::ESCAPE, DomKey::ESCAPE, 0x001B},
137 {DomCode::F1, DomKey::F1},
138 {DomCode::F2, DomKey::F2},
139 {DomCode::F3, DomKey::F3},
140 {DomCode::F4, DomKey::F4},
141 {DomCode::F5, DomKey::F5},
142 {DomCode::F6, DomKey::F6},
143 {DomCode::F7, DomKey::F7},
144 {DomCode::F8, DomKey::F8},
145 {DomCode::F9, DomKey::F9},
146 {DomCode::F10, DomKey::F10},
147 {DomCode::F11, DomKey::F11},
148 {DomCode::F12, DomKey::F12},
149 {DomCode::F13, DomKey::F13},
150 {DomCode::F14, DomKey::F14},
151 {DomCode::F15, DomKey::F15},
152 {DomCode::F16, DomKey::F16},
153 {DomCode::F17, DomKey::F17},
154 {DomCode::F18, DomKey::F18},
155 {DomCode::F19, DomKey::F19},
156 {DomCode::F20, DomKey::F20},
157 {DomCode::F21, DomKey::F21},
158 {DomCode::F22, DomKey::F22},
159 {DomCode::F23, DomKey::F23},
160 {DomCode::F24, DomKey::F24},
161 {DomCode::FIND, DomKey::FIND},
162 {DomCode::FN, DomKey::FN},
163 {DomCode::FN_LOCK, DomKey::FN_LOCK},
164 {DomCode::HELP, DomKey::HELP},
165 {DomCode::HOME, DomKey::HOME},
166 {DomCode::HYPER, DomKey::HYPER},
167 {DomCode::INSERT, DomKey::INSERT},
168 // {DomCode::INTL_RO, DomKey::_}
169 {DomCode::KANA_MODE, DomKey::KANA_MODE},
170 {DomCode::LANG1, DomKey::HANGUL_MODE},
171 {DomCode::LANG2, DomKey::HANJA_MODE},
172 {DomCode::LANG3, DomKey::KATAKANA},
173 {DomCode::LANG4, DomKey::HIRAGANA},
174 {DomCode::LANG5, DomKey::ZENKAKU_HANKAKU},
175 {DomCode::LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER},
176 {DomCode::LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR},
177 {DomCode::LAUNCH_MAIL, DomKey::LAUNCH_MAIL},
178 {DomCode::LAUNCH_SCREEN_SAVER, DomKey::LAUNCH_SCREEN_SAVER},
179 // {DomCode::LAUNCH_DOCUMENTS, DomKey::_}
180 // {DomCode::LAUNCH_FILE_BROWSER, DomKey::_}
181 // {DomCode::LAUNCH_KEYBOARD_LAYOUT, DomKey::_}
182 {DomCode::LOCK_SCREEN, DomKey::LAUNCH_SCREEN_SAVER},
183 {DomCode::MAIL_FORWARD, DomKey::MAIL_FORWARD},
184 {DomCode::MAIL_REPLY, DomKey::MAIL_REPLY},
185 {DomCode::MAIL_SEND, DomKey::MAIL_SEND},
186 {DomCode::MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE},
187 {DomCode::MEDIA_SELECT, DomKey::MEDIA_SELECT},
188 {DomCode::MEDIA_STOP, DomKey::MEDIA_STOP},
189 {DomCode::MEDIA_TRACK_NEXT, DomKey::MEDIA_TRACK_NEXT},
190 {DomCode::MEDIA_TRACK_PREVIOUS, DomKey::MEDIA_TRACK_PREVIOUS},
191 // {DomCode::MENU, DomKey::_}
192 {DomCode::NON_CONVERT, DomKey::NON_CONVERT},
193 {DomCode::NUM_LOCK, DomKey::NUM_LOCK},
194 {DomCode::NUMPAD_BACKSPACE, DomKey::BACKSPACE, 0x0008},
195 {DomCode::NUMPAD_CLEAR, DomKey::CLEAR},
196 {DomCode::NUMPAD_ENTER, DomKey::ENTER, 0x000D},
197 // {DomCode::NUMPAD_CLEAR_ENTRY, DomKey::_}
198 // {DomCode::NUMPAD_MEMORY_ADD, DomKey::_}
199 // {DomCode::NUMPAD_MEMORY_CLEAR, DomKey::_}
200 // {DomCode::NUMPAD_MEMORY_RECALL, DomKey::_}
201 // {DomCode::NUMPAD_MEMORY_STORE, DomKey::_}
202 // {DomCode::NUMPAD_MEMORY_SUBTRACT, DomKey::_}
203 {DomCode::OPEN, DomKey::OPEN},
204 {DomCode::OS_LEFT, DomKey::OS},
205 {DomCode::OS_RIGHT, DomKey::OS},
206 {DomCode::PAGE_DOWN, DomKey::PAGE_DOWN},
207 {DomCode::PAGE_UP, DomKey::PAGE_UP},
208 {DomCode::PASTE, DomKey::PASTE},
209 {DomCode::PAUSE, DomKey::PAUSE},
210 {DomCode::POWER, DomKey::POWER},
211 {DomCode::PRINT_SCREEN, DomKey::PRINT_SCREEN},
212 {DomCode::PROPS, DomKey::PROPS},
213 {DomCode::SCROLL_LOCK, DomKey::SCROLL_LOCK},
214 {DomCode::SELECT, DomKey::SELECT},
215 // {DomCode::SELECT_TASK, DomKey::_}
216 {DomCode::SHIFT_LEFT, DomKey::SHIFT},
217 {DomCode::SHIFT_RIGHT, DomKey::SHIFT},
218 {DomCode::SUPER, DomKey::SUPER},
219 {DomCode::TAB, DomKey::TAB, 0x0009},
220 {DomCode::UNDO, DomKey::UNDO},
221 // {DomCode::VOICE_COMMAND, DomKey::_}
222 {DomCode::VOLUME_DOWN, DomKey::VOLUME_DOWN},
223 {DomCode::VOLUME_MUTE, DomKey::VOLUME_MUTE},
224 {DomCode::VOLUME_UP, DomKey::VOLUME_UP},
225 {DomCode::WAKE_UP, DomKey::WAKE_UP},
226 {DomCode::ZOOM_TOGGLE, DomKey::ZOOM_TOGGLE},
227 };
228
229 // This table maps a DomKey to a non-located KeyboardCode.
230 const struct DomKeyToKeyboardCodeEntry {
231 DomKey dom_key;
232 KeyboardCode key_code;
233 } kDomKeyToKeyboardCodeMap[] = {
234 // No value.
235 {DomKey::NONE, VKEY_UNKNOWN},
236 // Special Key Values
237 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special
238 {DomKey::UNIDENTIFIED, VKEY_UNKNOWN},
239 // Modifier Keys
240 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier
241 {DomKey::ALT, VKEY_MENU},
242 {DomKey::ALT_GRAPH, VKEY_ALTGR},
243 {DomKey::CAPS_LOCK, VKEY_CAPITAL},
244 {DomKey::CONTROL, VKEY_CONTROL},
245 {DomKey::NUM_LOCK, VKEY_NUMLOCK},
246 {DomKey::OS, VKEY_LWIN},
247 {DomKey::SCROLL_LOCK, VKEY_SCROLL},
248 {DomKey::SHIFT, VKEY_SHIFT},
249 // Whitespace Keys
250 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-whitespace
251 {DomKey::ENTER, VKEY_RETURN},
252 {DomKey::SEPARATOR, VKEY_SEPARATOR},
253 {DomKey::TAB, VKEY_TAB},
254 // Navigation Keys
255 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-navigation
256 {DomKey::ARROW_DOWN, VKEY_DOWN},
257 {DomKey::ARROW_LEFT, VKEY_LEFT},
258 {DomKey::ARROW_RIGHT, VKEY_RIGHT},
259 {DomKey::ARROW_UP, VKEY_UP},
260 {DomKey::END, VKEY_END},
261 {DomKey::HOME, VKEY_HOME},
262 {DomKey::PAGE_DOWN, VKEY_NEXT},
263 {DomKey::PAGE_UP, VKEY_PRIOR},
264 // Editing Keys
265 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-editing
266 {DomKey::BACKSPACE, VKEY_BACK},
267 {DomKey::CLEAR, VKEY_CLEAR},
268 {DomKey::CR_SEL, VKEY_CRSEL},
269 {DomKey::DEL, VKEY_DELETE},
270 {DomKey::ERASE_EOF, VKEY_EREOF},
271 {DomKey::EX_SEL, VKEY_EXSEL},
272 {DomKey::INSERT, VKEY_INSERT},
273 // UI Keys
274 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-ui
275 {DomKey::ACCEPT, VKEY_ACCEPT},
276 {DomKey::ATTN, VKEY_ATTN},
277 {DomKey::CONTEXT_MENU, VKEY_APPS},
278 {DomKey::ESCAPE, VKEY_ESCAPE},
279 {DomKey::EXECUTE, VKEY_EXECUTE},
280 {DomKey::HELP, VKEY_HELP},
281 {DomKey::PAUSE, VKEY_PAUSE},
282 {DomKey::PLAY, VKEY_PLAY},
283 {DomKey::SELECT, VKEY_SELECT},
284 // Device Keys
285 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device
286 {DomKey::BRIGHTNESS_DOWN, VKEY_BRIGHTNESS_DOWN},
287 {DomKey::BRIGHTNESS_UP, VKEY_BRIGHTNESS_UP},
288 {DomKey::POWER, VKEY_POWER},
289 {DomKey::PRINT_SCREEN, VKEY_SNAPSHOT},
290 // IME and Composition Keys
291 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition
292 #if defined(OS_POSIX)
293 {DomKey::COMPOSE, VKEY_COMPOSE},
294 #endif
295 {DomKey::CONVERT, VKEY_CONVERT},
296 {DomKey::FINAL_MODE, VKEY_FINAL},
297 {DomKey::MODE_CHANGE, VKEY_MODECHANGE},
298 {DomKey::NON_CONVERT, VKEY_NONCONVERT},
299 {DomKey::PROCESS, VKEY_PROCESSKEY},
300 // Keys specific to Korean keyboards
301 {DomKey::HANGUL_MODE, VKEY_HANGUL},
302 {DomKey::HANJA_MODE, VKEY_HANJA},
303 {DomKey::JUNJA_MODE, VKEY_JUNJA},
304 // Keys specific to Japanese keyboards
305 {DomKey::HANKAKU, VKEY_DBE_SBCSCHAR},
306 {DomKey::KANA_MODE, VKEY_KANA},
307 {DomKey::KANJI_MODE, VKEY_KANJI},
308 {DomKey::ZENKAKU, VKEY_DBE_DBCSCHAR},
309 {DomKey::ZENKAKU_HANKAKU, VKEY_DBE_DBCSCHAR},
310 // General-Purpose Function Keys
311 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-function
312 {DomKey::F1, VKEY_F1},
313 {DomKey::F2, VKEY_F2},
314 {DomKey::F3, VKEY_F3},
315 {DomKey::F4, VKEY_F4},
316 {DomKey::F5, VKEY_F5},
317 {DomKey::F6, VKEY_F6},
318 {DomKey::F7, VKEY_F7},
319 {DomKey::F8, VKEY_F8},
320 {DomKey::F9, VKEY_F9},
321 {DomKey::F10, VKEY_F10},
322 {DomKey::F11, VKEY_F11},
323 {DomKey::F12, VKEY_F12},
324 {DomKey::F13, VKEY_F13},
325 {DomKey::F14, VKEY_F14},
326 {DomKey::F15, VKEY_F15},
327 {DomKey::F16, VKEY_F16},
328 {DomKey::F17, VKEY_F17},
329 {DomKey::F18, VKEY_F18},
330 {DomKey::F19, VKEY_F19},
331 {DomKey::F20, VKEY_F20},
332 {DomKey::F21, VKEY_F21},
333 {DomKey::F22, VKEY_F22},
334 {DomKey::F23, VKEY_F23},
335 {DomKey::F24, VKEY_F24},
336 // Multimedia Keys
337 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-multimedia
338 {DomKey::MEDIA_PLAY_PAUSE, VKEY_MEDIA_PLAY_PAUSE},
339 {DomKey::MEDIA_SELECT, VKEY_MEDIA_LAUNCH_MEDIA_SELECT},
340 {DomKey::MEDIA_STOP, VKEY_MEDIA_STOP},
341 {DomKey::MEDIA_TRACK_NEXT, VKEY_MEDIA_NEXT_TRACK},
342 {DomKey::MEDIA_TRACK_PREVIOUS, VKEY_MEDIA_PREV_TRACK},
343 {DomKey::PRINT, VKEY_PRINT},
344 {DomKey::VOLUME_DOWN, VKEY_VOLUME_DOWN},
345 {DomKey::VOLUME_MUTE, VKEY_VOLUME_MUTE},
346 {DomKey::VOLUME_UP, VKEY_VOLUME_UP},
347 // Application Keys
348 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-apps
349 {DomKey::LAUNCH_CALCULATOR, VKEY_MEDIA_LAUNCH_APP2},
350 {DomKey::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL},
351 {DomKey::LAUNCH_MY_COMPUTER, VKEY_MEDIA_LAUNCH_APP1},
352 // Browser Keys
353 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-browser
354 {DomKey::BROWSER_BACK, VKEY_BACK},
355 {DomKey::BROWSER_FAVORITES, VKEY_BROWSER_FAVORITES},
356 {DomKey::BROWSER_FORWARD, VKEY_BROWSER_FORWARD},
357 {DomKey::BROWSER_HOME, VKEY_BROWSER_HOME},
358 {DomKey::BROWSER_REFRESH, VKEY_BROWSER_REFRESH},
359 {DomKey::BROWSER_SEARCH, VKEY_BROWSER_SEARCH},
360 {DomKey::BROWSER_STOP, VKEY_BROWSER_STOP},
361 // Media Controller Keys
362 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller
363 {DomKey::ZOOM_TOGGLE, VKEY_ZOOM},
364 };
365
366 // This table, used by DomCodeToKeyboardCode() and KeyboardCodeToDomCode(),
367 // maps between DOM Level 3 .code values and legacy Windows-based VKEY values,
368 // where the VKEYs are interpreted positionally (located).
Wez 2015/01/17 02:06:47 This also assumes a US English layout. What is th
kpschoedel 2015/02/18 17:14:01 This appears to have been done originally, quite a
Wez 2015/02/19 23:16:08 Yeah, I'm not sure what the rationale in the IME a
369 const struct DomCodeToKeyboardCodeEntry {
370 DomCode dom_code;
371 KeyboardCode key_code;
372 } dom_code_to_keyboard_code[] = {
373 // Entries are ordered by numeric value of the DomCode enum,
374 // which is the USB physical key code.
375 // DomCode::HYPER 0x000010 Hyper
376 // DomCode::SUPER 0x000011 Super
377 // DomCode::FN 0x000012 Fn
378 // DomCode::FN_LOCK 0x000013 FLock
379 // DomCode::SUSPEND 0x000014 Suspend
380 // DomCode::RESUME 0x000015 Resume
381 // DomCode::TURBO 0x000016 Turbo
382 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep
383 // DomCode::WAKE_UP 0x010083 WakeUp
384 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA
385 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB
386 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC
387 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD
388 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE
389 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF
390 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG
391 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH
392 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI
393 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ
394 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK
395 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL
396 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM
397 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN
398 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO
399 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP
400 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ
401 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR
402 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS
403 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT
404 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU
405 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV
406 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW
407 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX
408 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY
409 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ
410 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1
411 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2
412 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3
413 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4
414 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5
415 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6
416 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7
417 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8
418 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9
419 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0
420 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter
421 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape
422 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace
423 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab
424 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space
425 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus
426 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal
427 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft
428 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight
429 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash
430 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash
431 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon
432 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote
433 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote
434 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma
435 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period
436 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash
437 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock
438 {DomCode::F1, VKEY_F1}, // 0x07003A F1
439 {DomCode::F2, VKEY_F2}, // 0x07003B F2
440 {DomCode::F3, VKEY_F3}, // 0x07003C F3
441 {DomCode::F4, VKEY_F4}, // 0x07003D F4
442 {DomCode::F5, VKEY_F5}, // 0x07003E F5
443 {DomCode::F6, VKEY_F6}, // 0x07003F F6
444 {DomCode::F7, VKEY_F7}, // 0x070040 F7
445 {DomCode::F8, VKEY_F8}, // 0x070041 F8
446 {DomCode::F9, VKEY_F9}, // 0x070042 F9
447 {DomCode::F10, VKEY_F10}, // 0x070043 F10
448 {DomCode::F11, VKEY_F11}, // 0x070044 F11
449 {DomCode::F12, VKEY_F12}, // 0x070045 F12
450 {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen
451 {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock
452 {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause
453 {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert
454 {DomCode::HOME, VKEY_HOME}, // 0x07004A Home
455 {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp
456 {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete
457 {DomCode::END, VKEY_END}, // 0x07004D End
458 {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown
459 {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight
460 {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft
461 {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown
462 {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp
463 {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock
464 {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide
465 {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply
466 {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract
467 {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd
468 {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter
469 {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1
470 {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2
471 {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3
472 {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4
473 {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5
474 {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6
475 {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7
476 {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8
477 {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9
478 {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0
479 {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal
480 {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash
481 {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu
482 {DomCode::POWER, VKEY_POWER}, // 0x070066 Power
483 // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual
484 // DomCode::OPEN 0x070074 Open
485 {DomCode::HELP, VKEY_HELP}, // 0x070075 Help
486 {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select
487 // DomCode::AGAIN 0x070079 Again
488 // DomCode::UNDO 0x07007A Undo
489 // DomCode::CUT 0x07007B Cut
490 // DomCode::COPY 0x07007C Copy
491 // DomCode::PASTE 0x07007D Paste
492 // DomCode::FIND 0x07007E Find
493 {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute
494 {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp
495 {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown
496 {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma
497 {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo
498 {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode
499 {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen
500 {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert
501 {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert
502 {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1
503 {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2
504 // DomCode::LANG3 0x070092 Lang3
505 // DomCode::LANG4 0x070093 Lang4
506 // DomCode::LANG5 0x070094 Lang5
507 // DomCode::ABORT 0x07009B Abort
508 // DomCode::PROPS 0x0700A3 Props
509 // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft
510 // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight
511 {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace
512 // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore
513 // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall
514 // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear
515 // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd
516 // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4
517 // NumpadMemorySubtract
518 {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear
519 {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry
520 {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft
521 {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft
522 {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft
523 {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft
524 {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight
525 {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight
526 {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight
527 {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight
528 {DomCode::MEDIA_TRACK_NEXT,
529 VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext
530 {DomCode::MEDIA_TRACK_PREVIOUS,
531 VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious
532 {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop
533 // DomCode::EJECT 0x0C00B8 Eject
534 {DomCode::MEDIA_PLAY_PAUSE,
535 VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause
536 {DomCode::MEDIA_SELECT,
537 VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect
538 {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail
539 {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2
540 {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1
541 {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch
542 {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome
543 {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack
544 {DomCode::BROWSER_FORWARD,
545 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward
546 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop
547 {DomCode::BROWSER_REFRESH,
548 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh
549 {DomCode::BROWSER_FAVORITES,
550 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites
551 };
552
15 // This table maps a subset of |KeyboardCode| (VKEYs) to DomKey and character. 553 // This table maps a subset of |KeyboardCode| (VKEYs) to DomKey and character.
16 // Only values not otherwise handled by GetMeaningFromKeyCode() are here. 554 // Only values not otherwise handled by GetMeaningFromKeyCode() are here.
17 const struct KeyboardCodeToMeaning { 555 const struct KeyboardCodeToMeaning {
18 KeyboardCode key_code; 556 KeyboardCode key_code;
19 DomKey key; 557 DomKey key;
20 base::char16 plain_character; 558 base::char16 plain_character;
21 base::char16 shift_character; 559 base::char16 shift_character;
22 } kKeyboardCodeToMeaning[] = { 560 } kKeyboardCodeToMeaning[] = {
23 {VKEY_BACK, DomKey::BACKSPACE, '\b', 0}, 561 {VKEY_BACK, DomKey::BACKSPACE, '\b', 0},
24 {VKEY_TAB, DomKey::TAB, '\t', 0}, 562 {VKEY_TAB, DomKey::TAB, '\t', 0},
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 {VKEY_OEM_103, DomKey::MEDIA_REWIND, 0, 0}, 661 {VKEY_OEM_103, DomKey::MEDIA_REWIND, 0, 0},
124 {VKEY_OEM_104, DomKey::MEDIA_FAST_FORWARD, 0, 0}, 662 {VKEY_OEM_104, DomKey::MEDIA_FAST_FORWARD, 0, 0},
125 #endif 663 #endif
126 }; 664 };
127 665
128 bool IsRightSideDomCode(DomCode code) { 666 bool IsRightSideDomCode(DomCode code) {
129 return (code == DomCode::SHIFT_RIGHT) || (code == DomCode::CONTROL_RIGHT) || 667 return (code == DomCode::SHIFT_RIGHT) || (code == DomCode::CONTROL_RIGHT) ||
130 (code == DomCode::ALT_RIGHT) || (code == DomCode::OS_RIGHT); 668 (code == DomCode::ALT_RIGHT) || (code == DomCode::OS_RIGHT);
131 } 669 }
132 670
671 bool IsModifierDomCode(DomCode code) {
672 return (code == DomCode::CONTROL_LEFT) || (code == DomCode::CONTROL_RIGHT) ||
673 (code == DomCode::SHIFT_LEFT) || (code == DomCode::SHIFT_RIGHT) ||
674 (code == DomCode::ALT_LEFT) || (code == DomCode::ALT_RIGHT) ||
675 (code == DomCode::OS_LEFT) || (code == DomCode::OS_RIGHT);
676 }
677
133 } // anonymous namespace 678 } // anonymous namespace
134 679
135 base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, int flags) { 680 base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, int flags) {
136 ui::DomKey dom_key; 681 ui::DomKey dom_key;
137 base::char16 character; 682 base::char16 character;
138 if (GetMeaningFromKeyCode(key_code, flags, &dom_key, &character)) 683 if (GetMeaningFromKeyCode(key_code, flags, &dom_key, &character))
139 return character; 684 return character;
140 return 0; 685 return 0;
141 } 686 }
142 687
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 *character = (shift && p->shift_character) ? p->shift_character 805 *character = (shift && p->shift_character) ? p->shift_character
261 : p->plain_character; 806 : p->plain_character;
262 return true; 807 return true;
263 } 808 }
264 } 809 }
265 *dom_key = DomKey::UNIDENTIFIED; 810 *dom_key = DomKey::UNIDENTIFIED;
266 *character = 0; 811 *character = 0;
267 return false; 812 return false;
268 } 813 }
269 814
815 bool DomCodeToMeaning(DomCode dom_code,
816 int flags,
817 DomKey* out_dom_key,
818 base::char16* out_character,
819 KeyboardCode* out_key_code) {
820 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) {
821 if (DomCodeToControlCharacter(dom_code, flags, out_dom_key, out_character,
822 out_key_code)) {
823 return true;
824 }
825 if (!IsModifierDomCode(dom_code)) {
826 *out_dom_key = DomKey::UNIDENTIFIED;
827 *out_character = 0;
828 *out_key_code = VKEY_UNKNOWN;
829 return true;
830 }
831 } else {
832 for (const auto& it : kPrintableCodeMap) {
833 if (it.dom_code == dom_code) {
834 int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) |
835 ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN);
836 base::char16 ch = it.character[state];
837 *out_dom_key = (ch & DK) ? DomKey::DEAD : DomKey::CHARACTER;
838 *out_character = ch;
839 if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) {
840 ch = (ch & ~DK) | 0x20;
841 if ((ch >= 'a') && (ch <= 'z'))
842 *out_character = it.character[state ^ 1];
843 }
844 *out_key_code = DomCodeToNonLocatedKeyboardCode(dom_code);
845 return true;
846 }
847 }
848 }
849 for (const auto& it : kNonPrintableCodeMap) {
850 if (it.dom_code == dom_code) {
851 *out_dom_key = it.dom_key;
852 *out_character = it.character;
853 *out_key_code = NonPrintableDomKeyToKeyboardCode(it.dom_key);
854 return true;
855 }
856 }
857 return false;
858 }
859
860 bool DomCodeToControlCharacter(DomCode dom_code,
861 int flags,
862 DomKey* dom_key,
863 base::char16* character,
864 KeyboardCode* key_code) {
865 if ((flags & EF_CONTROL_DOWN) == 0)
866 return false;
867
868 int code = static_cast<int>(dom_code);
869 const int kKeyA = static_cast<int>(DomCode::KEY_A);
870 // Control-A - Control-Z map to 0x01 - 0x1A.
871 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) {
872 *character = static_cast<base::char16>(code - kKeyA + 1);
873 switch (dom_code) {
874 case DomCode::KEY_H:
875 *dom_key = DomKey::BACKSPACE;
876 *key_code = VKEY_BACK;
877 break;
878 case DomCode::KEY_I:
879 *dom_key = DomKey::TAB;
880 *key_code = VKEY_TAB;
881 break;
882 case DomCode::KEY_M:
883 *dom_key = DomKey::ENTER;
884 *key_code = VKEY_RETURN;
885 break;
886 default:
887 *dom_key = DomKey::CHARACTER;
888 *key_code = static_cast<KeyboardCode>(code - kKeyA + VKEY_A);
889 break;
890 }
891 return true;
892 }
893
894 if (flags & EF_SHIFT_DOWN) {
895 switch (dom_code) {
896 case DomCode::DIGIT2:
897 // NUL
898 *character = 0;
899 *dom_key = DomKey::CHARACTER;
900 *key_code = VKEY_2;
901 return true;
902 case DomCode::DIGIT6:
903 // RS
904 *character = 0x1E;
905 *dom_key = DomKey::CHARACTER;
906 *key_code = VKEY_6;
907 return true;
908 case DomCode::MINUS:
909 // US
910 *character = 0x1F;
911 *dom_key = DomKey::CHARACTER;
912 *key_code = VKEY_OEM_MINUS;
913 return true;
914 default:
915 return false;
916 }
917 }
918
919 switch (dom_code) {
920 case DomCode::ENTER:
921 // NL
922 *character = 0x0A;
923 *dom_key = DomKey::CHARACTER;
924 *key_code = VKEY_RETURN;
925 return true;
926 case DomCode::BRACKET_LEFT:
927 // ESC
928 *character = 0x1B;
929 *dom_key = DomKey::ESCAPE;
930 *key_code = VKEY_OEM_4;
931 return true;
932 case DomCode::BACKSLASH:
933 // FS
934 *character = 0x1C;
935 *dom_key = DomKey::CHARACTER;
936 *key_code = VKEY_OEM_5;
937 return true;
938 case DomCode::BRACKET_RIGHT:
939 // GS
940 *character = 0x1D;
941 *dom_key = DomKey::CHARACTER;
942 *key_code = VKEY_OEM_6;
943 return true;
944 default:
945 return false;
946 }
947 }
948
949 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|.
950 // The returned VKEY is non-positional (e.g. VKEY_SHIFT).
951 KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) {
952 for (const auto& it : kDomKeyToKeyboardCodeMap) {
953 if (it.dom_key == dom_key)
954 return it.key_code;
955 }
956 return VKEY_UNKNOWN;
957 }
958
959 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
960 // The returned VKEY is located (e.g. VKEY_LSHIFT).
961 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) {
962 const DomCodeToKeyboardCodeEntry* end =
963 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code);
964 const DomCodeToKeyboardCodeEntry* found =
965 std::lower_bound(dom_code_to_keyboard_code, end, dom_code,
966 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) {
967 return static_cast<int>(a.dom_code) < static_cast<int>(b);
968 });
969 if ((found != end) && (found->dom_code == dom_code))
970 return found->key_code;
971 return VKEY_UNKNOWN;
972 }
973
974 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
975 // The returned VKEY is non-located (e.g. VKEY_SHIFT).
976 KeyboardCode DomCodeToNonLocatedKeyboardCode(DomCode dom_code) {
977 return LocatedToNonLocatedKeyboardCode(DomCodeToKeyboardCode(dom_code));
978 }
979
980 // Returns a DOM Level 3 |code| from a Windows-based VKEY value.
981 // This assumes a US layout and should only be used when |code| cannot be
982 // determined from a physical scan code.
Wez 2015/01/17 02:06:47 This comment is in the header; no need for it here
Wez 2015/02/19 23:16:08 Ping.
kpschoedel 2015/04/10 18:32:33 Done.
983 DomCode KeyboardCodeToDomCode(KeyboardCode key_code) {
Wez 2015/01/17 02:06:47 nit: Move this to appear in the same order relativ
Wez 2015/02/19 23:16:08 Ping.
kpschoedel 2015/04/10 18:32:33 Done.
984 key_code = NonLocatedToLocatedKeyboardCode(key_code, DomCode::NONE);
985 for (const auto& it : dom_code_to_keyboard_code) {
986 if (it.key_code == key_code)
987 return it.dom_code;
988 }
989 return DomCode::NONE;
990 }
991
270 // Determine the non-located VKEY corresponding to a located VKEY. 992 // Determine the non-located VKEY corresponding to a located VKEY.
271 KeyboardCode LocatedToNonLocatedKeyboardCode(KeyboardCode key_code) { 993 KeyboardCode LocatedToNonLocatedKeyboardCode(KeyboardCode key_code) {
272 switch (key_code) { 994 switch (key_code) {
273 case VKEY_RWIN: 995 case VKEY_RWIN:
274 return VKEY_LWIN; 996 return VKEY_LWIN;
275 case VKEY_LSHIFT: 997 case VKEY_LSHIFT:
276 case VKEY_RSHIFT: 998 case VKEY_RSHIFT:
277 return VKEY_SHIFT; 999 return VKEY_SHIFT;
278 case VKEY_LCONTROL: 1000 case VKEY_LCONTROL:
279 case VKEY_RCONTROL: 1001 case VKEY_RCONTROL:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 case VKEY_8: 1059 case VKEY_8:
338 return (dom_code == DomCode::NUMPAD8) ? VKEY_NUMPAD8 : VKEY_8; 1060 return (dom_code == DomCode::NUMPAD8) ? VKEY_NUMPAD8 : VKEY_8;
339 case VKEY_9: 1061 case VKEY_9:
340 return (dom_code == DomCode::NUMPAD9) ? VKEY_NUMPAD9 : VKEY_9; 1062 return (dom_code == DomCode::NUMPAD9) ? VKEY_NUMPAD9 : VKEY_9;
341 default: 1063 default:
342 return key_code; 1064 return key_code;
343 } 1065 }
344 } 1066 }
345 1067
346 } // namespace ui 1068 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698