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

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

Issue 954943003: [KeyboardEvent] Use DOM |code| rather than Windows-based key code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing VKEY in windows for brightness and power Created 5 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
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
15 // This table maps a subset of |KeyboardCode| (VKEYs) to DomKey and character. 17 // This table maps a DomCode to a printable character, assuming US layout.
16 // Only values not otherwise handled by GetMeaningFromKeyCode() are here. 18 // All of the characters have low ordinals, so we use bit 15 to flag dead keys.
17 const struct KeyboardCodeToMeaning { 19 const base::char16 kDeadKeyFlag = 0x8000;
20 const struct PrintableCodeEntry {
21 DomCode dom_code;
22 base::char16 character[4]; // normal, shift, altgr, shiftaltgr
23 } kPrintableCodeMap[] = {
24 {DomCode::KEY_A, {'a', 'A', 0x00E1, 0x00C1}},
25 {DomCode::KEY_B, {'b', 'B', 'b', 'B'}},
26 {DomCode::KEY_C, {'c', 'C', 0x00A9, 0x00A2}},
27 {DomCode::KEY_D, {'d', 'D', 0x00F0, 0x00D0}},
28 {DomCode::KEY_E, {'e', 'E', 0x00E9, 0x00C9}},
29 {DomCode::KEY_F, {'f', 'F', 'f', 'F'}},
30 {DomCode::KEY_G, {'g', 'G', 'g', 'G'}},
31 {DomCode::KEY_H, {'h', 'H', 'h', 'H'}},
32 {DomCode::KEY_I, {'i', 'I', 0x00ED, 0x00CD}},
33 {DomCode::KEY_J, {'j', 'J', 'j', 'J'}},
34 {DomCode::KEY_K, {'k', 'K', 0x0153, 0x0152}},
35 {DomCode::KEY_L, {'l', 'L', 0x00F8, 0x00D8}},
36 {DomCode::KEY_M, {'m', 'M', 0x00B5, 0x00B5}},
37 {DomCode::KEY_N, {'n', 'N', 0x00F1, 0x00D1}},
38 {DomCode::KEY_O, {'o', 'O', 0x00F3, 0x00D3}},
39 {DomCode::KEY_P, {'p', 'P', 0x00F6, 0x00D6}},
40 {DomCode::KEY_Q, {'q', 'Q', 0x00E4, 0x00C4}},
41 {DomCode::KEY_R, {'r', 'R', 0x00AE, 0x00AE}},
42 {DomCode::KEY_S, {'s', 'S', 0x00DF, 0x00A7}},
43 {DomCode::KEY_T, {'t', 'T', 0x00FE, 0x00DE}},
44 {DomCode::KEY_U, {'u', 'U', 0x00FA, 0x00DA}},
45 {DomCode::KEY_V, {'v', 'V', 'v', 'V'}},
46 {DomCode::KEY_W, {'w', 'W', 0x00E5, 0x00C5}},
47 {DomCode::KEY_X, {'x', 'X', 'x', 'X'}},
48 {DomCode::KEY_Y, {'y', 'Y', 0x00FC, 0x00DC}},
49 {DomCode::KEY_Z, {'z', 'Z', 0x00E6, 0x00C6}},
50 {DomCode::DIGIT1, {'1', '!', 0x00A1, 0x00B9}},
51 {DomCode::DIGIT2, {'2', '@', 0x00B2, kDeadKeyFlag | 0x030B}},
52 {DomCode::DIGIT3, {'3', '#', 0x00B3, kDeadKeyFlag | 0x0304}},
53 {DomCode::DIGIT4, {'4', '$', 0x00A4, 0x00A3}},
54 {DomCode::DIGIT5, {'5', '%', 0x20AC, kDeadKeyFlag | 0x0327}},
55 {DomCode::DIGIT6, {'6', '^', kDeadKeyFlag | 0x0302, 0x00BC}},
56 {DomCode::DIGIT7, {'7', '&', 0x00BD, kDeadKeyFlag | 0x031B}},
57 {DomCode::DIGIT8, {'8', '*', 0x00BE, kDeadKeyFlag | 0x0328}},
58 {DomCode::DIGIT9, {'9', '(', 0x2018, kDeadKeyFlag | 0x0306}},
59 {DomCode::DIGIT0, {'0', ')', 0x2019, kDeadKeyFlag | 0x030A}},
60 {DomCode::SPACE, {' ', ' ', 0x00A0, 0x00A0}},
61 {DomCode::MINUS, {'-', '_', 0x00A5, kDeadKeyFlag | 0x0323}},
62 {DomCode::EQUAL, {'=', '+', 0x00D7, 0x00F7}},
63 {DomCode::BRACKET_LEFT, {'[', '{', 0x00AB, 0x201C}},
64 {DomCode::BRACKET_RIGHT, {']', '}', 0x00BB, 0x201D}},
65 {DomCode::BACKSLASH, {'\\', '|', 0x00AC, 0x00A6}},
66 {DomCode::SEMICOLON, {';', ':', 0x00B6, 0x00B0}},
67 {DomCode::QUOTE,
68 {'\'', '"', kDeadKeyFlag | 0x0301, kDeadKeyFlag | 0x0308}},
69 {DomCode::BACKQUOTE,
70 {'`', '~', kDeadKeyFlag | 0x0300, kDeadKeyFlag | 0x0303}},
71 {DomCode::COMMA, {',', '<', 0x00E7, 0x00C7}},
72 {DomCode::PERIOD,{'.', '>', kDeadKeyFlag | 0x0307, kDeadKeyFlag | 0x030C}},
73 {DomCode::SLASH, {'/', '?', 0x00BF, kDeadKeyFlag | 0x0309}},
74 {DomCode::INTL_BACKSLASH, {'\\', '|', '\\', '|'}},
75 {DomCode::INTL_YEN, {0x00A5, '|', 0x00A5, '|'}},
76 {DomCode::NUMPAD_DIVIDE, {'/', '/', '/', '/'}},
77 {DomCode::NUMPAD_MULTIPLY, {'*', '*', '*', '*'}},
78 {DomCode::NUMPAD_SUBTRACT, {'-', '-', '-', '-'}},
79 {DomCode::NUMPAD_ADD, {'+', '+', '+', '+'}},
80 {DomCode::NUMPAD1, {'1', '1', '1', '1'}},
81 {DomCode::NUMPAD2, {'2', '2', '2', '2'}},
82 {DomCode::NUMPAD3, {'3', '3', '3', '3'}},
83 {DomCode::NUMPAD4, {'4', '4', '4', '4'}},
84 {DomCode::NUMPAD5, {'5', '5', '5', '5'}},
85 {DomCode::NUMPAD6, {'6', '6', '6', '6'}},
86 {DomCode::NUMPAD7, {'7', '7', '7', '7'}},
87 {DomCode::NUMPAD8, {'8', '8', '8', '8'}},
88 {DomCode::NUMPAD9, {'9', '9', '9', '9'}},
89 {DomCode::NUMPAD0, {'0', '0', '0', '0'}},
90 {DomCode::NUMPAD_DECIMAL, {'.', '.', '.', '.'}},
91 {DomCode::NUMPAD_EQUAL, {'=', '=', '=', '='}},
92 {DomCode::NUMPAD_COMMA, {',', ',', ',', ','}},
93 {DomCode::NUMPAD_PAREN_LEFT, {'(', '(', '(', '('}},
94 {DomCode::NUMPAD_PAREN_RIGHT, {')', ')', ')', ')'}},
95 {DomCode::NUMPAD_SIGN_CHANGE, {0x00B1, 0x00B1, 0x2213, 0x2213}},
96 };
97
98 // This table maps a DomCode to a DomKey, assuming US keyboard layout.
99 const struct NonPrintableCodeEntry {
100 DomCode dom_code;
101 DomKey dom_key;
102 base::char16 character;
103 } kNonPrintableCodeMap[] = {
104 {DomCode::ABORT, DomKey::CANCEL},
105 {DomCode::AGAIN, DomKey::AGAIN},
106 {DomCode::ALT_LEFT, DomKey::ALT},
107 {DomCode::ALT_RIGHT, DomKey::ALT},
108 {DomCode::ARROW_DOWN, DomKey::ARROW_DOWN},
109 {DomCode::ARROW_LEFT, DomKey::ARROW_LEFT},
110 {DomCode::ARROW_RIGHT, DomKey::ARROW_RIGHT},
111 {DomCode::ARROW_UP, DomKey::ARROW_UP},
112 {DomCode::BACKSPACE, DomKey::BACKSPACE, 0x0008},
113 {DomCode::BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN},
114 {DomCode::BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP},
115 // {DomCode::BRIGHTNESS_AUTO, DomKey::_}
116 // {DomCode::BRIGHTNESS_MAXIMUM, DomKey::_}
117 // {DomCode::BRIGHTNESS_MINIMIUM, DomKey::_}
118 // {DomCode::BRIGHTNESS_TOGGLE, DomKey::_}
119 {DomCode::BROWSER_BACK, DomKey::BROWSER_BACK},
120 {DomCode::BROWSER_FAVORITES, DomKey::BROWSER_FAVORITES},
121 {DomCode::BROWSER_FORWARD, DomKey::BROWSER_FORWARD},
122 {DomCode::BROWSER_HOME, DomKey::BROWSER_HOME},
123 {DomCode::BROWSER_REFRESH, DomKey::BROWSER_REFRESH},
124 {DomCode::BROWSER_SEARCH, DomKey::BROWSER_SEARCH},
125 {DomCode::BROWSER_STOP, DomKey::BROWSER_STOP},
126 {DomCode::CAPS_LOCK, DomKey::CAPS_LOCK},
127 {DomCode::CONTEXT_MENU, DomKey::CONTEXT_MENU},
128 {DomCode::CONTROL_LEFT, DomKey::CONTROL},
129 {DomCode::CONTROL_RIGHT, DomKey::CONTROL},
130 {DomCode::CONVERT, DomKey::CONVERT},
131 {DomCode::COPY, DomKey::COPY},
132 {DomCode::CUT, DomKey::CUT},
133 {DomCode::DEL, DomKey::DEL, 0x007F},
134 {DomCode::EJECT, DomKey::EJECT},
135 {DomCode::END, DomKey::END},
136 {DomCode::ENTER, DomKey::ENTER, 0x000D},
137 {DomCode::ESCAPE, DomKey::ESCAPE, 0x001B},
138 {DomCode::F1, DomKey::F1},
139 {DomCode::F2, DomKey::F2},
140 {DomCode::F3, DomKey::F3},
141 {DomCode::F4, DomKey::F4},
142 {DomCode::F5, DomKey::F5},
143 {DomCode::F6, DomKey::F6},
144 {DomCode::F7, DomKey::F7},
145 {DomCode::F8, DomKey::F8},
146 {DomCode::F9, DomKey::F9},
147 {DomCode::F10, DomKey::F10},
148 {DomCode::F11, DomKey::F11},
149 {DomCode::F12, DomKey::F12},
150 {DomCode::F13, DomKey::F13},
151 {DomCode::F14, DomKey::F14},
152 {DomCode::F15, DomKey::F15},
153 {DomCode::F16, DomKey::F16},
154 {DomCode::F17, DomKey::F17},
155 {DomCode::F18, DomKey::F18},
156 {DomCode::F19, DomKey::F19},
157 {DomCode::F20, DomKey::F20},
158 {DomCode::F21, DomKey::F21},
159 {DomCode::F22, DomKey::F22},
160 {DomCode::F23, DomKey::F23},
161 {DomCode::F24, DomKey::F24},
162 {DomCode::FIND, DomKey::FIND},
163 {DomCode::FN, DomKey::FN},
164 {DomCode::FN_LOCK, DomKey::FN_LOCK},
165 {DomCode::HELP, DomKey::HELP},
166 {DomCode::HOME, DomKey::HOME},
167 {DomCode::HYPER, DomKey::HYPER},
168 {DomCode::INSERT, DomKey::INSERT},
169 // {DomCode::INTL_RO, DomKey::_}
170 {DomCode::KANA_MODE, DomKey::KANA_MODE},
171 {DomCode::LANG1, DomKey::HANGUL_MODE},
172 {DomCode::LANG2, DomKey::HANJA_MODE},
173 {DomCode::LANG3, DomKey::KATAKANA},
174 {DomCode::LANG4, DomKey::HIRAGANA},
175 {DomCode::LANG5, DomKey::ZENKAKU_HANKAKU},
176 {DomCode::LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER},
177 {DomCode::LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR},
178 {DomCode::LAUNCH_MAIL, DomKey::LAUNCH_MAIL},
179 {DomCode::LAUNCH_SCREEN_SAVER, DomKey::LAUNCH_SCREEN_SAVER},
180 // {DomCode::LAUNCH_DOCUMENTS, DomKey::_}
181 // {DomCode::LAUNCH_FILE_BROWSER, DomKey::_}
182 // {DomCode::LAUNCH_KEYBOARD_LAYOUT, DomKey::_}
183 {DomCode::LOCK_SCREEN, DomKey::LAUNCH_SCREEN_SAVER},
184 {DomCode::MAIL_FORWARD, DomKey::MAIL_FORWARD},
185 {DomCode::MAIL_REPLY, DomKey::MAIL_REPLY},
186 {DomCode::MAIL_SEND, DomKey::MAIL_SEND},
187 {DomCode::MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE},
188 {DomCode::MEDIA_SELECT, DomKey::MEDIA_SELECT},
189 {DomCode::MEDIA_STOP, DomKey::MEDIA_STOP},
190 {DomCode::MEDIA_TRACK_NEXT, DomKey::MEDIA_TRACK_NEXT},
191 {DomCode::MEDIA_TRACK_PREVIOUS, DomKey::MEDIA_TRACK_PREVIOUS},
192 // {DomCode::MENU, DomKey::_}
193 {DomCode::NON_CONVERT, DomKey::NON_CONVERT},
194 {DomCode::NUM_LOCK, DomKey::NUM_LOCK},
195 {DomCode::NUMPAD_BACKSPACE, DomKey::BACKSPACE, 0x0008},
196 {DomCode::NUMPAD_CLEAR, DomKey::CLEAR},
197 {DomCode::NUMPAD_ENTER, DomKey::ENTER, 0x000D},
198 // {DomCode::NUMPAD_CLEAR_ENTRY, DomKey::_}
199 // {DomCode::NUMPAD_MEMORY_ADD, DomKey::_}
200 // {DomCode::NUMPAD_MEMORY_CLEAR, DomKey::_}
201 // {DomCode::NUMPAD_MEMORY_RECALL, DomKey::_}
202 // {DomCode::NUMPAD_MEMORY_STORE, DomKey::_}
203 // {DomCode::NUMPAD_MEMORY_SUBTRACT, DomKey::_}
204 {DomCode::OPEN, DomKey::OPEN},
205 {DomCode::OS_LEFT, DomKey::OS},
206 {DomCode::OS_RIGHT, DomKey::OS},
207 {DomCode::PAGE_DOWN, DomKey::PAGE_DOWN},
208 {DomCode::PAGE_UP, DomKey::PAGE_UP},
209 {DomCode::PASTE, DomKey::PASTE},
210 {DomCode::PAUSE, DomKey::PAUSE},
211 {DomCode::POWER, DomKey::POWER},
212 {DomCode::PRINT_SCREEN, DomKey::PRINT_SCREEN},
213 {DomCode::PROPS, DomKey::PROPS},
214 {DomCode::SCROLL_LOCK, DomKey::SCROLL_LOCK},
215 {DomCode::SELECT, DomKey::SELECT},
216 // {DomCode::SELECT_TASK, DomKey::_}
217 {DomCode::SHIFT_LEFT, DomKey::SHIFT},
218 {DomCode::SHIFT_RIGHT, DomKey::SHIFT},
219 {DomCode::SUPER, DomKey::SUPER},
220 {DomCode::TAB, DomKey::TAB, 0x0009},
221 {DomCode::UNDO, DomKey::UNDO},
222 // {DomCode::VOICE_COMMAND, DomKey::_}
223 {DomCode::VOLUME_DOWN, DomKey::VOLUME_DOWN},
224 {DomCode::VOLUME_MUTE, DomKey::VOLUME_MUTE},
225 {DomCode::VOLUME_UP, DomKey::VOLUME_UP},
226 {DomCode::WAKE_UP, DomKey::WAKE_UP},
227 {DomCode::ZOOM_TOGGLE, DomKey::ZOOM_TOGGLE},
228 };
229
230 // This table maps a DomKey to a non-located KeyboardCode.
231 const struct DomKeyToKeyboardCodeEntry {
232 DomKey dom_key;
18 KeyboardCode key_code; 233 KeyboardCode key_code;
19 DomKey key; 234 } kDomKeyToKeyboardCodeMap[] = {
20 base::char16 plain_character; 235 // No value.
21 base::char16 shift_character; 236 {DomKey::NONE, VKEY_UNKNOWN},
22 } kKeyboardCodeToMeaning[] = { 237 // Special Key Values
23 {VKEY_BACK, DomKey::BACKSPACE, '\b', 0}, 238 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special
24 {VKEY_TAB, DomKey::TAB, '\t', 0}, 239 {DomKey::UNIDENTIFIED, VKEY_UNKNOWN},
25 {VKEY_RETURN, DomKey::ENTER, '\r', 0}, 240 // Modifier Keys
26 {VKEY_ESCAPE, DomKey::ESCAPE, 0x1B, 0}, 241 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier
27 {VKEY_SPACE, DomKey::CHARACTER, ' ', 0}, 242 {DomKey::ALT, VKEY_MENU},
28 {VKEY_MULTIPLY, DomKey::CHARACTER, '*', 0}, 243 {DomKey::ALT_GRAPH, VKEY_ALTGR},
29 {VKEY_ADD, DomKey::CHARACTER, '+', 0}, 244 {DomKey::CAPS_LOCK, VKEY_CAPITAL},
30 {VKEY_SEPARATOR, DomKey::CHARACTER, ',', 0}, 245 {DomKey::CONTROL, VKEY_CONTROL},
31 {VKEY_SUBTRACT, DomKey::CHARACTER, '-', 0}, 246 {DomKey::NUM_LOCK, VKEY_NUMLOCK},
32 {VKEY_DECIMAL, DomKey::CHARACTER, '.', 0}, 247 {DomKey::OS, VKEY_LWIN},
33 {VKEY_DIVIDE, DomKey::CHARACTER, '/', 0}, 248 {DomKey::SCROLL_LOCK, VKEY_SCROLL},
34 {VKEY_OEM_1, DomKey::CHARACTER, ';', ':'}, 249 {DomKey::SHIFT, VKEY_SHIFT},
35 {VKEY_OEM_PLUS, DomKey::CHARACTER, '=', '+'}, 250 // Whitespace Keys
36 {VKEY_OEM_COMMA, DomKey::CHARACTER, ',', '<'}, 251 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-whitespace
37 {VKEY_OEM_MINUS, DomKey::CHARACTER, '-', '_'}, 252 {DomKey::ENTER, VKEY_RETURN},
38 {VKEY_OEM_PERIOD, DomKey::CHARACTER, '.', '>'}, 253 {DomKey::SEPARATOR, VKEY_SEPARATOR},
39 {VKEY_OEM_2, DomKey::CHARACTER, '/', '?'}, 254 {DomKey::TAB, VKEY_TAB},
40 {VKEY_OEM_3, DomKey::CHARACTER, '`', '~'}, 255 // Navigation Keys
41 {VKEY_OEM_4, DomKey::CHARACTER, '[', '{'}, 256 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-navigation
42 {VKEY_OEM_5, DomKey::CHARACTER, '\\', '|'}, 257 {DomKey::ARROW_DOWN, VKEY_DOWN},
43 {VKEY_OEM_6, DomKey::CHARACTER, ']', '}'}, 258 {DomKey::ARROW_LEFT, VKEY_LEFT},
44 {VKEY_OEM_7, DomKey::CHARACTER, '\'', '"'}, 259 {DomKey::ARROW_RIGHT, VKEY_RIGHT},
45 {VKEY_OEM_102, DomKey::CHARACTER, '<', '>'}, 260 {DomKey::ARROW_UP, VKEY_UP},
46 {VKEY_CLEAR, DomKey::CLEAR, 0, 0}, 261 {DomKey::END, VKEY_END},
47 {VKEY_SHIFT, DomKey::SHIFT, 0, 0}, 262 {DomKey::HOME, VKEY_HOME},
48 {VKEY_CONTROL, DomKey::CONTROL, 0, 0}, 263 {DomKey::PAGE_DOWN, VKEY_NEXT},
49 {VKEY_MENU, DomKey::ALT, 0, 0}, 264 {DomKey::PAGE_UP, VKEY_PRIOR},
50 {VKEY_PAUSE, DomKey::PAUSE, 0, 0}, 265 // Editing Keys
51 {VKEY_CAPITAL, DomKey::CAPS_LOCK, 0, 0}, 266 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-editing
52 // Windows conflates 'KanaMode' and 'HangulMode'. 267 {DomKey::BACKSPACE, VKEY_BACK},
53 {VKEY_KANA, DomKey::KANA_MODE, 0, 0}, 268 {DomKey::CLEAR, VKEY_CLEAR},
54 {VKEY_JUNJA, DomKey::JUNJA_MODE, 0, 0}, 269 {DomKey::CR_SEL, VKEY_CRSEL},
55 {VKEY_FINAL, DomKey::FINAL_MODE, 0, 0}, 270 {DomKey::DEL, VKEY_DELETE},
56 // Windows conflates 'HanjaMode' and 'KanjiMode'. 271 {DomKey::ERASE_EOF, VKEY_EREOF},
57 {VKEY_HANJA, DomKey::HANJA_MODE, 0, 0}, 272 {DomKey::EX_SEL, VKEY_EXSEL},
58 {VKEY_CONVERT, DomKey::CONVERT, 0, 0}, 273 {DomKey::INSERT, VKEY_INSERT},
59 {VKEY_NONCONVERT, DomKey::NON_CONVERT, 0, 0}, 274 // UI Keys
60 {VKEY_ACCEPT, DomKey::ACCEPT, 0, 0}, 275 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-ui
61 {VKEY_MODECHANGE, DomKey::MODE_CHANGE, 0, 0}, 276 {DomKey::ACCEPT, VKEY_ACCEPT},
62 {VKEY_PRIOR, DomKey::PAGE_UP, 0, 0}, 277 {DomKey::ATTN, VKEY_ATTN},
63 {VKEY_NEXT, DomKey::PAGE_DOWN, 0, 0}, 278 {DomKey::CONTEXT_MENU, VKEY_APPS},
64 {VKEY_END, DomKey::END, 0, 0}, 279 {DomKey::ESCAPE, VKEY_ESCAPE},
65 {VKEY_HOME, DomKey::HOME, 0, 0}, 280 {DomKey::EXECUTE, VKEY_EXECUTE},
66 {VKEY_LEFT, DomKey::ARROW_LEFT, 0, 0}, 281 {DomKey::HELP, VKEY_HELP},
67 {VKEY_UP, DomKey::ARROW_UP, 0, 0}, 282 {DomKey::PAUSE, VKEY_PAUSE},
68 {VKEY_RIGHT, DomKey::ARROW_RIGHT, 0, 0}, 283 {DomKey::PLAY, VKEY_PLAY},
69 {VKEY_DOWN, DomKey::ARROW_DOWN, 0, 0}, 284 {DomKey::SELECT, VKEY_SELECT},
70 {VKEY_SELECT, DomKey::SELECT, 0, 0}, 285 // Device Keys
71 {VKEY_PRINT, DomKey::PRINT, 0, 0}, 286 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device
72 {VKEY_EXECUTE, DomKey::EXECUTE, 0, 0}, 287 {DomKey::BRIGHTNESS_DOWN, VKEY_BRIGHTNESS_DOWN},
73 {VKEY_SNAPSHOT, DomKey::PRINT_SCREEN, 0, 0}, 288 {DomKey::BRIGHTNESS_UP, VKEY_BRIGHTNESS_UP},
74 {VKEY_INSERT, DomKey::INSERT, 0, 0}, 289 {DomKey::POWER, VKEY_POWER},
75 {VKEY_DELETE, DomKey::DEL, 0, 0}, 290 {DomKey::PRINT_SCREEN, VKEY_SNAPSHOT},
76 {VKEY_HELP, DomKey::HELP, 0, 0}, 291 // IME and Composition Keys
77 {VKEY_LWIN, DomKey::OS, 0, 0}, 292 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition
78 {VKEY_RWIN, DomKey::OS, 0, 0},
79 {VKEY_APPS, DomKey::MEDIA_APPS, 0, 0},
80 {VKEY_NUMLOCK, DomKey::NUM_LOCK, 0, 0},
81 {VKEY_SCROLL, DomKey::SCROLL_LOCK, 0, 0},
82 {VKEY_LSHIFT, DomKey::SHIFT, 0, 0},
83 {VKEY_RSHIFT, DomKey::SHIFT, 0, 0},
84 {VKEY_LCONTROL, DomKey::CONTROL, 0, 0},
85 {VKEY_RCONTROL, DomKey::CONTROL, 0, 0},
86 {VKEY_LMENU, DomKey::ALT, 0, 0},
87 {VKEY_RMENU, DomKey::ALT, 0, 0},
88 {VKEY_BROWSER_BACK, DomKey::BROWSER_BACK, 0, 0},
89 {VKEY_BROWSER_FORWARD, DomKey::BROWSER_FORWARD, 0, 0},
90 {VKEY_BROWSER_REFRESH, DomKey::BROWSER_REFRESH, 0, 0},
91 {VKEY_BROWSER_STOP, DomKey::BROWSER_STOP, 0, 0},
92 {VKEY_BROWSER_SEARCH, DomKey::BROWSER_SEARCH, 0, 0},
93 {VKEY_BROWSER_FAVORITES, DomKey::BROWSER_FAVORITES, 0, 0},
94 {VKEY_BROWSER_HOME, DomKey::BROWSER_HOME, 0, 0},
95 {VKEY_VOLUME_MUTE, DomKey::VOLUME_MUTE, 0, 0},
96 {VKEY_VOLUME_DOWN, DomKey::VOLUME_DOWN, 0, 0},
97 {VKEY_VOLUME_UP, DomKey::VOLUME_UP, 0, 0},
98 {VKEY_MEDIA_NEXT_TRACK, DomKey::MEDIA_TRACK_NEXT, 0, 0},
99 {VKEY_MEDIA_PREV_TRACK, DomKey::MEDIA_TRACK_PREVIOUS, 0, 0},
100 {VKEY_MEDIA_STOP, DomKey::MEDIA_STOP, 0, 0},
101 {VKEY_MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE, 0, 0},
102 {VKEY_MEDIA_LAUNCH_MAIL, DomKey::LAUNCH_MAIL, 0, 0},
103 {VKEY_MEDIA_LAUNCH_MEDIA_SELECT, DomKey::LAUNCH_MEDIA_PLAYER, 0, 0},
104 {VKEY_MEDIA_LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER, 0, 0},
105 {VKEY_MEDIA_LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR, 0, 0},
106 {VKEY_OEM_8, DomKey::SUPER, 0, 0}, // ISO Level 5 Shift in ChromeOS
107 {VKEY_PROCESSKEY, DomKey::PROCESS, 0, 0},
108 {VKEY_DBE_SBCSCHAR, DomKey::HANKAKU, 0, 0},
109 {VKEY_DBE_DBCSCHAR, DomKey::ZENKAKU, 0, 0},
110 {VKEY_ATTN, DomKey::ATTN, 0, 0},
111 {VKEY_CRSEL, DomKey::CR_SEL, 0, 0},
112 {VKEY_EXSEL, DomKey::EX_SEL, 0, 0},
113 {VKEY_EREOF, DomKey::ERASE_EOF, 0, 0},
114 {VKEY_PLAY, DomKey::MEDIA_PLAY, 0, 0},
115 {VKEY_ZOOM, DomKey::ZOOM_TOGGLE, 0, 0},
116 {VKEY_OEM_CLEAR, DomKey::CLEAR, 0, 0},
117 {VKEY_ALTGR, DomKey::ALT_GRAPH, 0, 0},
118 #if defined(OS_POSIX) 293 #if defined(OS_POSIX)
119 {VKEY_POWER, DomKey::POWER, 0, 0}, 294 {DomKey::COMPOSE, VKEY_COMPOSE},
120 {VKEY_BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN, 0, 0},
121 {VKEY_BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP, 0, 0},
122 {VKEY_COMPOSE, DomKey::COMPOSE, 0, 0},
123 {VKEY_OEM_103, DomKey::MEDIA_REWIND, 0, 0},
124 {VKEY_OEM_104, DomKey::MEDIA_FAST_FORWARD, 0, 0},
125 #endif 295 #endif
296 {DomKey::CONVERT, VKEY_CONVERT},
297 {DomKey::FINAL_MODE, VKEY_FINAL},
298 {DomKey::MODE_CHANGE, VKEY_MODECHANGE},
299 {DomKey::NON_CONVERT, VKEY_NONCONVERT},
300 {DomKey::PROCESS, VKEY_PROCESSKEY},
301 // Keys specific to Korean keyboards
302 {DomKey::HANGUL_MODE, VKEY_HANGUL},
303 {DomKey::HANJA_MODE, VKEY_HANJA},
304 {DomKey::JUNJA_MODE, VKEY_JUNJA},
305 // Keys specific to Japanese keyboards
306 {DomKey::HANKAKU, VKEY_DBE_SBCSCHAR},
307 {DomKey::KANA_MODE, VKEY_KANA},
308 {DomKey::KANJI_MODE, VKEY_KANJI},
309 {DomKey::ZENKAKU, VKEY_DBE_DBCSCHAR},
310 {DomKey::ZENKAKU_HANKAKU, VKEY_DBE_DBCSCHAR},
311 // General-Purpose Function Keys
312 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-function
313 {DomKey::F1, VKEY_F1},
314 {DomKey::F2, VKEY_F2},
315 {DomKey::F3, VKEY_F3},
316 {DomKey::F4, VKEY_F4},
317 {DomKey::F5, VKEY_F5},
318 {DomKey::F6, VKEY_F6},
319 {DomKey::F7, VKEY_F7},
320 {DomKey::F8, VKEY_F8},
321 {DomKey::F9, VKEY_F9},
322 {DomKey::F10, VKEY_F10},
323 {DomKey::F11, VKEY_F11},
324 {DomKey::F12, VKEY_F12},
325 {DomKey::F13, VKEY_F13},
326 {DomKey::F14, VKEY_F14},
327 {DomKey::F15, VKEY_F15},
328 {DomKey::F16, VKEY_F16},
329 {DomKey::F17, VKEY_F17},
330 {DomKey::F18, VKEY_F18},
331 {DomKey::F19, VKEY_F19},
332 {DomKey::F20, VKEY_F20},
333 {DomKey::F21, VKEY_F21},
334 {DomKey::F22, VKEY_F22},
335 {DomKey::F23, VKEY_F23},
336 {DomKey::F24, VKEY_F24},
337 // Multimedia Keys
338 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-multimedia
339 {DomKey::MEDIA_PLAY_PAUSE, VKEY_MEDIA_PLAY_PAUSE},
340 {DomKey::MEDIA_SELECT, VKEY_MEDIA_LAUNCH_MEDIA_SELECT},
341 {DomKey::MEDIA_STOP, VKEY_MEDIA_STOP},
342 {DomKey::MEDIA_TRACK_NEXT, VKEY_MEDIA_NEXT_TRACK},
343 {DomKey::MEDIA_TRACK_PREVIOUS, VKEY_MEDIA_PREV_TRACK},
344 {DomKey::PRINT, VKEY_PRINT},
345 {DomKey::VOLUME_DOWN, VKEY_VOLUME_DOWN},
346 {DomKey::VOLUME_MUTE, VKEY_VOLUME_MUTE},
347 {DomKey::VOLUME_UP, VKEY_VOLUME_UP},
348 // Application Keys
349 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-apps
350 {DomKey::LAUNCH_CALCULATOR, VKEY_MEDIA_LAUNCH_APP2},
351 {DomKey::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL},
352 {DomKey::LAUNCH_MY_COMPUTER, VKEY_MEDIA_LAUNCH_APP1},
353 // Browser Keys
354 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-browser
355 {DomKey::BROWSER_BACK, VKEY_BROWSER_BACK},
356 {DomKey::BROWSER_FAVORITES, VKEY_BROWSER_FAVORITES},
357 {DomKey::BROWSER_FORWARD, VKEY_BROWSER_FORWARD},
358 {DomKey::BROWSER_HOME, VKEY_BROWSER_HOME},
359 {DomKey::BROWSER_REFRESH, VKEY_BROWSER_REFRESH},
360 {DomKey::BROWSER_SEARCH, VKEY_BROWSER_SEARCH},
361 {DomKey::BROWSER_STOP, VKEY_BROWSER_STOP},
362 // Media Controller Keys
363 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller
364 {DomKey::ZOOM_TOGGLE, VKEY_ZOOM},
365 };
366
367 // This table, used by DomCodeToKeyboardCode() and KeyboardCodeToDomCode(),
368 // maps between DOM Level 3 .code values and legacy Windows-based VKEY values,
369 // where the VKEYs are interpreted positionally (located).
370 const struct DomCodeToKeyboardCodeEntry {
371 DomCode dom_code;
372 KeyboardCode key_code;
373 } kDomCodeToKeyboardCodeMap[] = {
374 // Entries are ordered by numeric value of the DomCode enum,
375 // which is the USB physical key code.
376 // DomCode::HYPER 0x000010 Hyper
377 // DomCode::SUPER 0x000011 Super
378 // DomCode::FN 0x000012 Fn
379 // DomCode::FN_LOCK 0x000013 FLock
380 // DomCode::SUSPEND 0x000014 Suspend
381 // DomCode::RESUME 0x000015 Resume
382 // DomCode::TURBO 0x000016 Turbo
383 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep
384 // DomCode::WAKE_UP 0x010083 WakeUp
385 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA
386 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB
387 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC
388 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD
389 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE
390 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF
391 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG
392 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH
393 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI
394 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ
395 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK
396 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL
397 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM
398 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN
399 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO
400 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP
401 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ
402 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR
403 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS
404 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT
405 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU
406 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV
407 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW
408 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX
409 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY
410 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ
411 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1
412 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2
413 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3
414 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4
415 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5
416 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6
417 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7
418 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8
419 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9
420 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0
421 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter
422 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape
423 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace
424 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab
425 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space
426 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus
427 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal
428 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft
429 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight
430 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash
431 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash
432 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon
433 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote
434 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote
435 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma
436 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period
437 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash
438 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock
439 {DomCode::F1, VKEY_F1}, // 0x07003A F1
440 {DomCode::F2, VKEY_F2}, // 0x07003B F2
441 {DomCode::F3, VKEY_F3}, // 0x07003C F3
442 {DomCode::F4, VKEY_F4}, // 0x07003D F4
443 {DomCode::F5, VKEY_F5}, // 0x07003E F5
444 {DomCode::F6, VKEY_F6}, // 0x07003F F6
445 {DomCode::F7, VKEY_F7}, // 0x070040 F7
446 {DomCode::F8, VKEY_F8}, // 0x070041 F8
447 {DomCode::F9, VKEY_F9}, // 0x070042 F9
448 {DomCode::F10, VKEY_F10}, // 0x070043 F10
449 {DomCode::F11, VKEY_F11}, // 0x070044 F11
450 {DomCode::F12, VKEY_F12}, // 0x070045 F12
451 {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen
452 {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock
453 {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause
454 {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert
455 {DomCode::HOME, VKEY_HOME}, // 0x07004A Home
456 {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp
457 {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete
458 {DomCode::END, VKEY_END}, // 0x07004D End
459 {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown
460 {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight
461 {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft
462 {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown
463 {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp
464 {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock
465 {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide
466 {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply
467 {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract
468 {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd
469 {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter
470 {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1
471 {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2
472 {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3
473 {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4
474 {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5
475 {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6
476 {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7
477 {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8
478 {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9
479 {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0
480 {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal
481 {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash
482 {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu
483 {DomCode::POWER, VKEY_POWER}, // 0x070066 Power
484 // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual
485 // DomCode::OPEN 0x070074 Open
486 {DomCode::HELP, VKEY_HELP}, // 0x070075 Help
487 {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select
488 // DomCode::AGAIN 0x070079 Again
489 // DomCode::UNDO 0x07007A Undo
490 // DomCode::CUT 0x07007B Cut
491 // DomCode::COPY 0x07007C Copy
492 // DomCode::PASTE 0x07007D Paste
493 // DomCode::FIND 0x07007E Find
494 {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute
495 {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp
496 {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown
497 {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma
498 {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo
499 {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode
500 {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen
501 {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert
502 {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert
503 {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1
504 {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2
505 // DomCode::LANG3 0x070092 Lang3
506 // DomCode::LANG4 0x070093 Lang4
507 // DomCode::LANG5 0x070094 Lang5
508 // DomCode::ABORT 0x07009B Abort
509 // DomCode::PROPS 0x0700A3 Props
510 // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft
511 // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight
512 {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace
513 // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore
514 // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall
515 // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear
516 // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd
517 // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4
518 // NumpadMemorySubtract
519 {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear
520 {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry
521 {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft
522 {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft
523 {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft
524 {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft
525 {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight
526 {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight
527 {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight
528 {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight
529 {DomCode::MEDIA_TRACK_NEXT,
530 VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext
531 {DomCode::MEDIA_TRACK_PREVIOUS,
532 VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious
533 {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop
534 // DomCode::EJECT 0x0C00B8 Eject
535 {DomCode::MEDIA_PLAY_PAUSE,
536 VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause
537 {DomCode::MEDIA_SELECT,
538 VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect
539 {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail
540 {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2
541 {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1
542 {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch
543 {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome
544 {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack
545 {DomCode::BROWSER_FORWARD,
546 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward
547 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop
548 {DomCode::BROWSER_REFRESH,
549 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh
550 {DomCode::BROWSER_FAVORITES,
551 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites
552 };
553
554 const struct CharacterToDomKey {
555 base::char16 character;
556 DomKey dom_key;
557 } kCharacterToDomKey[] = {
558 {0x08, DomKey::BACKSPACE},
559 {0x09, DomKey::TAB},
560 {0x0A, DomKey::ENTER},
561 {0x0D, DomKey::ENTER},
562 {0x1B, DomKey::ESCAPE},
563 };
564
565 const struct DomCodeToCtrlCharacter {
566 DomCode dom_code;
567 DomKey dom_key;
568 base::char16 character;
569 KeyboardCode key_code;
570 } kDomCodeToCtrlCharacterCtrl[] = {
571 {DomCode::KEY_H, DomKey::BACKSPACE, 0, VKEY_BACK},
572 {DomCode::KEY_I, DomKey::TAB, 0, VKEY_TAB},
573 {DomCode::KEY_M, DomKey::ENTER, 0, VKEY_RETURN},
574 };
575
576 DomCodeToCtrlCharacter kDomCodeToCtrlCharacterShiftDown[] = {
577 {DomCode::DIGIT2, DomKey::CHARACTER, 0, VKEY_1},
578 {DomCode::DIGIT6, DomKey::CHARACTER, 0x1E, VKEY_6},
579 {DomCode::MINUS, DomKey::CHARACTER, 0x1F, VKEY_OEM_MINUS},
580 };
581
582 DomCodeToCtrlCharacter kDomCodeToCtrlCharacterOther[] = {
583 {DomCode::ENTER, DomKey::CHARACTER, 0x0A, VKEY_RETURN},
584 {DomCode::BRACKET_LEFT, DomKey::ESCAPE, 0x1B, VKEY_OEM_4},
585 {DomCode::BACKSLASH, DomKey::CHARACTER, 0x1C, VKEY_OEM_5},
586 {DomCode::BRACKET_RIGHT, DomKey::CHARACTER, 0x1D, VKEY_OEM_6},
126 }; 587 };
127 588
128 bool IsRightSideDomCode(DomCode code) { 589 bool IsRightSideDomCode(DomCode code) {
129 return (code == DomCode::SHIFT_RIGHT) || (code == DomCode::CONTROL_RIGHT) || 590 return (code == DomCode::SHIFT_RIGHT) || (code == DomCode::CONTROL_RIGHT) ||
130 (code == DomCode::ALT_RIGHT) || (code == DomCode::OS_RIGHT); 591 (code == DomCode::ALT_RIGHT) || (code == DomCode::OS_RIGHT);
131 } 592 }
132 593
594 bool IsModifierDomCode(DomCode code) {
595 return (code == DomCode::CONTROL_LEFT) || (code == DomCode::CONTROL_RIGHT) ||
596 (code == DomCode::SHIFT_LEFT) || (code == DomCode::SHIFT_RIGHT) ||
597 (code == DomCode::ALT_LEFT) || (code == DomCode::ALT_RIGHT) ||
598 (code == DomCode::OS_LEFT) || (code == DomCode::OS_RIGHT);
599 }
600
133 } // anonymous namespace 601 } // anonymous namespace
134 602
135 base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, int flags) { 603 base::char16 DomCodeToCharacter(DomCode dom_code, int flags) {
136 ui::DomKey dom_key;
137 base::char16 character; 604 base::char16 character;
138 if (GetMeaningFromKeyCode(key_code, flags, &dom_key, &character)) 605 DomKey key;
606 KeyboardCode key_code;
607 if (DomCodeToMeaning(dom_code, flags, &key, &character, &key_code))
139 return character; 608 return character;
140 return 0; 609 return 0;
141 } 610 }
142 611
143 bool GetMeaningFromKeyCode(KeyboardCode key_code, 612 bool DomCodeToMeaning(DomCode dom_code,
144 int flags, 613 int flags,
145 DomKey* dom_key, 614 DomKey* out_dom_key,
146 base::char16* character) { 615 base::char16* out_character,
147 const bool ctrl = (flags & EF_CONTROL_DOWN) != 0; 616 KeyboardCode* out_key_code) {
148 const bool shift = (flags & EF_SHIFT_DOWN) != 0; 617 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) {
149 const bool upper = shift ^ ((flags & EF_CAPS_LOCK_DOWN) != 0); 618 if (DomCodeToControlCharacter(dom_code, flags, out_dom_key, out_character,
150 619 out_key_code)) {
151 // Control characters.
152 if (ctrl) {
153 // Following Windows behavior to map ctrl-a ~ ctrl-z to \x01 ~ \x1A.
154 if (key_code >= VKEY_A && key_code <= VKEY_Z) {
155 *character = static_cast<uint16>(key_code - VKEY_A + 1);
156 switch (key_code) {
157 case VKEY_H:
158 *dom_key = DomKey::BACKSPACE;
159 break;
160 case VKEY_I:
161 *dom_key = DomKey::TAB;
162 break;
163 case VKEY_J:
164 case VKEY_M:
165 *dom_key = DomKey::ENTER;
166 break;
167 default:
168 *dom_key = DomKey::CHARACTER;
169 break;
170 }
171 return true; 620 return true;
172 } 621 }
173 // Other control characters. 622 if (!IsModifierDomCode(dom_code)) {
174 if (shift) { 623 *out_dom_key = DomKey::UNIDENTIFIED;
175 // The following graphics characters require the shift key to input. 624 *out_character = 0;
176 switch (key_code) { 625 *out_key_code = VKEY_UNKNOWN;
177 // ctrl-@ maps to \x00 (Null byte) 626 return true;
178 case VKEY_2: 627 }
179 *dom_key = DomKey::CHARACTER; 628 } else {
180 *character = 0; 629 for (const auto& it : kPrintableCodeMap) {
181 return true; 630 if (it.dom_code == dom_code) {
182 // ctrl-^ maps to \x1E (Record separator, Information separator two) 631 int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) |
183 case VKEY_6: 632 ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN);
184 *dom_key = DomKey::CHARACTER; 633 base::char16 ch = it.character[state];
185 *character = 0x1E; 634 *out_dom_key = (ch & kDeadKeyFlag) ? DomKey::DEAD : DomKey::CHARACTER;
186 return true; 635 *out_character = ch;
187 // ctrl-_ maps to \x1F (Unit separator, Information separator one) 636 if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) {
188 case VKEY_OEM_MINUS: 637 ch = (ch & ~kDeadKeyFlag) | 0x20;
189 *dom_key = DomKey::CHARACTER; 638 if ((ch >= 'a') && (ch <= 'z'))
190 *character = 0x1F; 639 *out_character = it.character[state ^ 1];
191 return true; 640 }
192 // Returns 0 for all other keys to avoid inputting unexpected chars. 641 *out_key_code =
193 default: 642 LocatedToNonLocatedKeyboardCode(DomCodeToKeyboardCode(dom_code));
194 *dom_key = DomKey::UNIDENTIFIED; 643 return true;
195 *character = 0;
196 return false;
197 }
198 } else {
199 switch (key_code) {
200 // ctrl-[ maps to \x1B (Escape)
201 case VKEY_OEM_4:
202 *dom_key = DomKey::ESCAPE;
203 *character = 0x1B;
204 return true;
205 // ctrl-\ maps to \x1C (File separator, Information separator four)
206 case VKEY_OEM_5:
207 *dom_key = DomKey::CHARACTER;
208 *character = 0x1C;
209 return true;
210 // ctrl-] maps to \x1D (Group separator, Information separator three)
211 case VKEY_OEM_6:
212 *dom_key = DomKey::CHARACTER;
213 *character = 0x1D;
214 return true;
215 // ctrl-Enter maps to \x0A (Line feed)
216 case VKEY_RETURN:
217 *dom_key = DomKey::CHARACTER;
218 *character = 0x0A;
219 return true;
220 // Returns 0 for all other keys to avoid inputting unexpected chars.
221 default:
222 *dom_key = DomKey::UNIDENTIFIED;
223 *character = 0;
224 return false;
225 } 644 }
226 } 645 }
227 } 646 }
647 for (const auto& it : kNonPrintableCodeMap) {
648 if (it.dom_code == dom_code) {
649 *out_dom_key = it.dom_key;
650 *out_character = it.character;
651 *out_key_code = NonPrintableDomKeyToKeyboardCode(it.dom_key);
652 return true;
653 }
654 }
655 return false;
656 }
228 657
229 // ASCII alphanumeric characters. 658 bool DomCodeToControlCharacter(DomCode dom_code,
230 if (key_code >= VKEY_A && key_code <= VKEY_Z) { 659 int flags,
660 DomKey* dom_key,
661 base::char16* character,
662 KeyboardCode* key_code) {
663 if ((flags & EF_CONTROL_DOWN) == 0)
664 return false;
665
666 int code = static_cast<int>(dom_code);
667 const int kKeyA = static_cast<int>(DomCode::KEY_A);
668
669 // Control-A - Control-Z map to 0x01 - 0x1A.
670 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) {
231 *dom_key = DomKey::CHARACTER; 671 *dom_key = DomKey::CHARACTER;
232 *character = static_cast<uint16>(key_code - VKEY_A + (upper ? 'A' : 'a')); 672 *key_code = static_cast<KeyboardCode>(code - kKeyA + VKEY_A);
233 return true; 673 *character = static_cast<base::char16>(code - kKeyA + 1);
234 } 674 for (const auto& it: kDomCodeToCtrlCharacterCtrl) {
235 if (key_code >= VKEY_0 && key_code <= VKEY_9) { 675 if (it.dom_code == dom_code) {
236 *dom_key = DomKey::CHARACTER; 676 *dom_key = it.dom_key;
237 *character = 677 *key_code = it.key_code;
238 shift ? ")!@#$%^&*("[key_code - VKEY_0] : static_cast<uint16>(key_code); 678 }
239 return true; 679 }
240 }
241 if (key_code >= VKEY_NUMPAD0 && key_code <= VKEY_NUMPAD9) {
242 *dom_key = DomKey::CHARACTER;
243 *character = static_cast<uint16>(key_code - VKEY_NUMPAD0 + '0');
244 return true; 680 return true;
245 } 681 }
246 682
247 // Function keys. 683 if (flags & EF_SHIFT_DOWN) {
248 if (key_code >= VKEY_F1 && key_code <= VKEY_F24) { 684 for (const auto& it: kDomCodeToCtrlCharacterShiftDown) {
249 *dom_key = 685 if (it.dom_code == dom_code) {
250 static_cast<DomKey>(key_code - VKEY_F1 + static_cast<int>(DomKey::F1)); 686 *dom_key = it.dom_key;
251 *character = 0; 687 *key_code = it.key_code;
252 return true; 688 *character = it.character;
689 return true;
690 }
691 }
692 return false;
253 } 693 }
254 694
255 // Other keys. 695 for (const auto& it: kDomCodeToCtrlCharacterOther) {
256 for (size_t i = 0; i < arraysize(kKeyboardCodeToMeaning); ++i) { 696 if (it.dom_code == dom_code) {
257 if (kKeyboardCodeToMeaning[i].key_code == key_code) { 697 *dom_key = it.dom_key;
258 const KeyboardCodeToMeaning* p = &kKeyboardCodeToMeaning[i]; 698 *key_code = it.key_code;
259 *dom_key = p->key; 699 *character = it.character;
260 *character = (shift && p->shift_character) ? p->shift_character
261 : p->plain_character;
262 return true; 700 return true;
263 } 701 }
264 } 702 }
265 *dom_key = DomKey::UNIDENTIFIED;
266 *character = 0;
267 return false; 703 return false;
268 } 704 }
269 705
706 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|.
707 // The returned VKEY is non-positional (e.g. VKEY_SHIFT).
708 KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) {
709 for (const auto& it : kDomKeyToKeyboardCodeMap) {
710 if (it.dom_key == dom_key)
711 return it.key_code;
712 }
713 return VKEY_UNKNOWN;
714 }
715
716 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
717 // The returned VKEY is located (e.g. VKEY_LSHIFT).
718 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) {
719 const DomCodeToKeyboardCodeEntry* end =
720 kDomCodeToKeyboardCodeMap + arraysize(kDomCodeToKeyboardCodeMap);
721 const DomCodeToKeyboardCodeEntry* found =
722 std::lower_bound(kDomCodeToKeyboardCodeMap, end, dom_code,
723 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) {
724 return static_cast<int>(a.dom_code) < static_cast<int>(b);
725 });
726 if ((found != end) && (found->dom_code == dom_code))
727 return found->key_code;
728 return VKEY_UNKNOWN;
729 }
730
731 // Returns a DOM Level 3 |code| from a Windows-based VKEY value.
732 // This assumes a US layout and should only be used when |code| cannot be
733 // determined from a physical scan code.
734 DomCode KeyboardCodeToDomCode(KeyboardCode key_code) {
735 key_code = NonLocatedToLocatedKeyboardCode(key_code, DomCode::NONE);
736 for (const auto& it : kDomCodeToKeyboardCodeMap) {
737 if (it.key_code == key_code)
738 return it.dom_code;
739 }
740 return DomCode::NONE;
741 }
742
743 // Returns the DomKey value associated with an ASCII/Unicode character.
744 DomKey CharacterToDomKey(base::char16 character) {
745 for (const auto& it: kCharacterToDomKey) {
746 if (it.character == character)
747 return it.dom_key;
748 }
749 return DomKey::CHARACTER;
750 }
751
752 // Returns the ui::EventFlags value associated with a modifier key.
753 int ModifierDomKeyToEventFlag(DomKey key) {
754 switch (key) {
755 case DomKey::ALT:
756 return EF_ALT_DOWN;
757 case DomKey::ALT_GRAPH:
758 return EF_ALTGR_DOWN;
759 case DomKey::CAPS_LOCK:
760 return EF_CAPS_LOCK_DOWN;
761 case DomKey::CONTROL:
762 return EF_CONTROL_DOWN;
763 case DomKey::HYPER:
764 return EF_MOD3_DOWN;
765 case DomKey::META:
766 return EF_ALT_DOWN;
767 case DomKey::OS:
768 return EF_COMMAND_DOWN;
769 case DomKey::SHIFT:
770 return EF_SHIFT_DOWN;
771 case DomKey::SUPER:
772 return EF_MOD3_DOWN;
773 default:
774 return EF_NONE;
775 }
776 // Not represented:
777 // DomKey::ACCEL
778 // DomKey::FN
779 // DomKey::FN_LOCK
780 // DomKey::NUM_LOCK
781 // DomKey::SCROLL_LOCK
782 // DomKey::SYMBOL
783 // DomKey::SYMBOL_LOCK
784 }
785
270 // Determine the non-located VKEY corresponding to a located VKEY. 786 // Determine the non-located VKEY corresponding to a located VKEY.
271 KeyboardCode LocatedToNonLocatedKeyboardCode(KeyboardCode key_code) { 787 KeyboardCode LocatedToNonLocatedKeyboardCode(KeyboardCode key_code) {
272 switch (key_code) { 788 switch (key_code) {
273 case VKEY_RWIN: 789 case VKEY_RWIN:
274 return VKEY_LWIN; 790 return VKEY_LWIN;
275 case VKEY_LSHIFT: 791 case VKEY_LSHIFT:
276 case VKEY_RSHIFT: 792 case VKEY_RSHIFT:
277 return VKEY_SHIFT; 793 return VKEY_SHIFT;
278 case VKEY_LCONTROL: 794 case VKEY_LCONTROL:
279 case VKEY_RCONTROL: 795 case VKEY_RCONTROL:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 case VKEY_8: 853 case VKEY_8:
338 return (dom_code == DomCode::NUMPAD8) ? VKEY_NUMPAD8 : VKEY_8; 854 return (dom_code == DomCode::NUMPAD8) ? VKEY_NUMPAD8 : VKEY_8;
339 case VKEY_9: 855 case VKEY_9:
340 return (dom_code == DomCode::NUMPAD9) ? VKEY_NUMPAD9 : VKEY_9; 856 return (dom_code == DomCode::NUMPAD9) ? VKEY_NUMPAD9 : VKEY_9;
341 default: 857 default:
342 return key_code; 858 return key_code;
343 } 859 }
344 } 860 }
345 861
346 } // namespace ui 862 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/keycodes/keyboard_code_conversion.h ('k') | ui/events/keycodes/keyboard_code_conversion_x.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698