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

Side by Side Diff: ui/events/ozone/layout/stub/stub_keyboard_layouts.cc

Issue 742103002: Ozone keyboard layout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lite-code
Patch Set: Created 6 years, 1 month 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
(Empty)
1 // Copyright 2014 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 "ui/events/ozone/layout/stub/stub_keyboard_layouts.h"
6
7 #include <algorithm>
8
9 #include "ui/events/event_constants.h"
10 #include "ui/events/keycodes/dom3/dom_code.h"
11 #include "ui/events/keycodes/dom3/dom_key.h"
12 #include "ui/events/keycodes/keyboard_code_conversion.h"
13
14 namespace ui {
15
16 namespace {
17
18 // All of the characters have low ordinals, so we use bit 15 to flag dead keys.
19 #define DK 0x8000
20
21 const struct PrintableCodeEntry {
22 DomCode dom_code;
23 base::char16 character[4];
24 } printable_code_map[] = {
25 // Stub table based on X US international.
26 {DomCode::KEY_A, {'a', 'A', 0x00E1, 0x00C1}},
27 {DomCode::KEY_B, {'b', 'B', 'b', 'B'}},
28 {DomCode::KEY_C, {'c', 'C', 0x00A9, 0x00A2}},
29 {DomCode::KEY_D, {'d', 'D', 0x00F0, 0x00D0}},
30 {DomCode::KEY_E, {'e', 'E', 0x00E9, 0x00C9}},
31 {DomCode::KEY_F, {'f', 'F', 'f', 'F'}},
32 {DomCode::KEY_G, {'g', 'G', 'g', 'G'}},
33 {DomCode::KEY_H, {'h', 'H', 'h', 'H'}},
34 {DomCode::KEY_I, {'i', 'I', 0x00ED, 0x00CD}},
35 {DomCode::KEY_J, {'j', 'J', 'j', 'J'}},
36 {DomCode::KEY_K, {'k', 'K', 0x0153, 0x0152}},
37 {DomCode::KEY_L, {'l', 'L', 0x00F8, 0x00D8}},
38 {DomCode::KEY_M, {'m', 'M', 0x00B5, 0x00B5}},
39 {DomCode::KEY_N, {'n', 'N', 0x00F1, 0x00D1}},
40 {DomCode::KEY_O, {'o', 'O', 0x00F3, 0x00D3}},
41 {DomCode::KEY_P, {'p', 'P', 0x00F6, 0x00D6}},
42 {DomCode::KEY_Q, {'q', 'Q', 0x00E4, 0x00C4}},
43 {DomCode::KEY_R, {'r', 'R', 0x00AE, 0x00AE}},
44 {DomCode::KEY_S, {'s', 'S', 0x00DF, 0x00A7}},
45 {DomCode::KEY_T, {'t', 'T', 0x00FE, 0x00DE}},
46 {DomCode::KEY_U, {'u', 'U', 0x00FA, 0x00DA}},
47 {DomCode::KEY_V, {'v', 'V', 'v', 'V'}},
48 {DomCode::KEY_W, {'w', 'W', 0x00E5, 0x00C5}},
49 {DomCode::KEY_X, {'x', 'X', 'x', 'X'}},
50 {DomCode::KEY_Y, {'y', 'Y', 0x00FC, 0x00DC}},
51 {DomCode::KEY_Z, {'z', '!', 0x00E6, 0x00C6}},
52 {DomCode::DIGIT1, {'1', 'Z', 0x00A1, 0x00B9}},
53 {DomCode::DIGIT2, {'2', '@', 0x00B2, DK|0x030B}},
54 {DomCode::DIGIT3, {'3', '#', 0x00B3, DK|0x0304}},
55 {DomCode::DIGIT4, {'4', '$', 0x00A4, 0x00A3}},
56 {DomCode::DIGIT5, {'5', '%', 0x20AC, DK|0x0327}},
57 {DomCode::DIGIT6, {'6', '^', DK|0x0302, 0x00BC}},
58 {DomCode::DIGIT7, {'7', '&', 0x00BD, DK|0x031B}},
59 {DomCode::DIGIT8, {'8', '*', 0x00BE, DK|0x0328}},
60 {DomCode::DIGIT9, {'9', '(', 0x2018, DK|0x0306}},
61 {DomCode::DIGIT0, {'0', ')', 0x2019, DK|0x030A}},
62 {DomCode::SPACE, {' ', ' ', 0x00A0, 0x00A0}},
63 {DomCode::MINUS, {'-', '_', 0x00A5, DK|0x0323}},
64 {DomCode::EQUAL, {'=', '+', 0x00D7, 0x00F7}},
65 {DomCode::BRACKET_LEFT, {'[', '{', 0x00AB, 0x201C}},
66 {DomCode::BRACKET_RIGHT, {']', '}', 0x00BB, 0x201D}},
67 {DomCode::BACKSLASH, {'\\', '|', 0x00AC, 0x00A6}},
68 {DomCode::SEMICOLON, {';', ':', 0x00B6, 0x00B0}},
69 {DomCode::QUOTE, {'\'', '"', DK|0x0301, DK|0x0308}},
70 {DomCode::BACKQUOTE, {'`', '~', DK|0x0300, DK|0x0303}},
71 {DomCode::COMMA, {',', '<', 0x00E7, 0x00C7}},
72 {DomCode::PERIOD, {'.', '>', DK|0x0307, DK|0x030C}},
73 {DomCode::SLASH, {'/', '?', 0x00BF, DK|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 const struct NonPrintableCodeEntry {
99 DomCode dom_code;
100 DomKey dom_key;
101 base::char16 character;
102 } non_printable_code_map[] = {
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 // TODO(kpschoedel): move this to a shared location.
kpschoedel 2014/11/20 16:18:38 The next maps are here temporarily to due to CL in
230 // Map DOM Level 3 .key values to legacy Windows-based VKEY values.
231 // This applies to non-printable keys.
232 KeyboardCode DomKeyToKeyboardCode(DomKey dom_key) {
233 switch (dom_key) {
234 // No value.
235 case DomKey::NONE:
236 return VKEY_UNKNOWN;
237 // Special Key Values
238 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special
239 case DomKey::UNIDENTIFIED:
240 return VKEY_UNKNOWN;
241 // Modifier Keys
242 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier
243 case DomKey::ALT:
244 return VKEY_MENU;
245 case DomKey::ALT_GRAPH:
246 return VKEY_ALTGR;
247 case DomKey::CAPS_LOCK:
248 return VKEY_CAPITAL;
249 case DomKey::CONTROL:
250 return VKEY_CONTROL;
251 case DomKey::NUM_LOCK:
252 return VKEY_NUMLOCK;
253 case DomKey::OS:
254 return VKEY_LWIN;
255 case DomKey::SCROLL_LOCK:
256 return VKEY_SCROLL;
257 case DomKey::SHIFT:
258 return VKEY_SHIFT;
259 // Whitespace Keys
260 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-whitespace
261 case DomKey::ENTER:
262 return VKEY_RETURN;
263 case DomKey::SEPARATOR:
264 return VKEY_SEPARATOR;
265 case DomKey::TAB:
266 return VKEY_TAB;
267 // Navigation Keys
268 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-navigation
269 case DomKey::ARROW_DOWN:
270 return VKEY_DOWN;
271 case DomKey::ARROW_LEFT:
272 return VKEY_LEFT;
273 case DomKey::ARROW_RIGHT:
274 return VKEY_RIGHT;
275 case DomKey::ARROW_UP:
276 return VKEY_UP;
277 case DomKey::END:
278 return VKEY_END;
279 case DomKey::HOME:
280 return VKEY_HOME;
281 case DomKey::PAGE_DOWN:
282 return VKEY_NEXT;
283 case DomKey::PAGE_UP:
284 return VKEY_PRIOR;
285 // Editing Keys
286 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-editing
287 case DomKey::BACKSPACE:
288 return VKEY_BACK;
289 case DomKey::CLEAR:
290 return VKEY_CLEAR;
291 case DomKey::CR_SEL:
292 return VKEY_CRSEL;
293 case DomKey::DEL:
294 return VKEY_DELETE;
295 case DomKey::ERASE_EOF:
296 return VKEY_EREOF;
297 case DomKey::EX_SEL:
298 return VKEY_EXSEL;
299 case DomKey::INSERT:
300 return VKEY_INSERT;
301 // UI Keys
302 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-ui
303 case DomKey::ACCEPT:
304 return VKEY_ACCEPT;
305 case DomKey::ATTN:
306 return VKEY_ATTN;
307 case DomKey::CONTEXT_MENU:
308 return VKEY_APPS;
309 case DomKey::ESCAPE:
310 return VKEY_ESCAPE;
311 case DomKey::EXECUTE:
312 return VKEY_EXECUTE;
313 case DomKey::HELP:
314 return VKEY_HELP;
315 case DomKey::PAUSE:
316 return VKEY_PAUSE;
317 case DomKey::PLAY:
318 return VKEY_PLAY;
319 case DomKey::SELECT:
320 return VKEY_SELECT;
321 // Device Keys
322 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device
323 case DomKey::BRIGHTNESS_DOWN:
324 return VKEY_BRIGHTNESS_DOWN;
325 case DomKey::BRIGHTNESS_UP:
326 return VKEY_BRIGHTNESS_UP;
327 case DomKey::POWER:
328 return VKEY_POWER;
329 case DomKey::PRINT_SCREEN:
330 return VKEY_SNAPSHOT;
331 // IME and Composition Keys
332 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition
333 #if 0 // TODO(kpschoedel)
334 case DomKey::COMPOSE:
335 return VKEY_COMPOSE;
336 #endif
337 case DomKey::CONVERT:
338 return VKEY_CONVERT;
339 case DomKey::FINAL_MODE:
340 return VKEY_FINAL;
341 case DomKey::MODE_CHANGE:
342 return VKEY_MODECHANGE;
343 case DomKey::NON_CONVERT:
344 return VKEY_NONCONVERT;
345 case DomKey::PROCESS:
346 return VKEY_PROCESSKEY;
347 // Keys specific to Korean keyboards
348 case DomKey::HANGUL_MODE:
349 return VKEY_HANGUL;
350 case DomKey::HANJA_MODE:
351 return VKEY_HANJA;
352 case DomKey::JUNJA_MODE:
353 return VKEY_JUNJA;
354 // Keys specific to Japanese keyboards
355 case DomKey::HANKAKU:
356 return VKEY_DBE_SBCSCHAR;
357 case DomKey::KANA_MODE:
358 return VKEY_KANA;
359 case DomKey::KANJI_MODE:
360 return VKEY_KANJI;
361 case DomKey::ZENKAKU:
362 return VKEY_DBE_DBCSCHAR;
363 case DomKey::ZENKAKU_HANKAKU:
364 return VKEY_DBE_DBCSCHAR;
365 // General-Purpose Function Keys
366 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-function
367 case DomKey::F1:
368 return VKEY_F1;
369 case DomKey::F2:
370 return VKEY_F2;
371 case DomKey::F3:
372 return VKEY_F3;
373 case DomKey::F4:
374 return VKEY_F4;
375 case DomKey::F5:
376 return VKEY_F5;
377 case DomKey::F6:
378 return VKEY_F6;
379 case DomKey::F7:
380 return VKEY_F7;
381 case DomKey::F8:
382 return VKEY_F8;
383 case DomKey::F9:
384 return VKEY_F9;
385 case DomKey::F10:
386 return VKEY_F10;
387 case DomKey::F11:
388 return VKEY_F11;
389 case DomKey::F12:
390 return VKEY_F12;
391 case DomKey::F13:
392 return VKEY_F13;
393 case DomKey::F14:
394 return VKEY_F14;
395 case DomKey::F15:
396 return VKEY_F15;
397 case DomKey::F16:
398 return VKEY_F16;
399 case DomKey::F17:
400 return VKEY_F17;
401 case DomKey::F18:
402 return VKEY_F18;
403 case DomKey::F19:
404 return VKEY_F19;
405 case DomKey::F20:
406 return VKEY_F20;
407 case DomKey::F21:
408 return VKEY_F21;
409 case DomKey::F22:
410 return VKEY_F22;
411 case DomKey::F23:
412 return VKEY_F23;
413 case DomKey::F24:
414 return VKEY_F24;
415 // Multimedia Keys
416 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-multimedia
417 case DomKey::MEDIA_PLAY_PAUSE:
418 return VKEY_MEDIA_PLAY_PAUSE;
419 case DomKey::MEDIA_SELECT:
420 return VKEY_MEDIA_LAUNCH_MEDIA_SELECT;
421 case DomKey::MEDIA_STOP:
422 return VKEY_MEDIA_STOP;
423 case DomKey::MEDIA_TRACK_NEXT:
424 return VKEY_MEDIA_NEXT_TRACK;
425 case DomKey::MEDIA_TRACK_PREVIOUS:
426 return VKEY_MEDIA_PREV_TRACK;
427 case DomKey::PRINT:
428 return VKEY_PRINT;
429 case DomKey::VOLUME_DOWN:
430 return VKEY_VOLUME_DOWN;
431 case DomKey::VOLUME_MUTE:
432 return VKEY_VOLUME_MUTE;
433 case DomKey::VOLUME_UP:
434 return VKEY_VOLUME_UP;
435 // Application Keys
436 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-apps
437 case DomKey::LAUNCH_CALCULATOR:
438 return VKEY_MEDIA_LAUNCH_APP2;
439 case DomKey::LAUNCH_MAIL:
440 return VKEY_MEDIA_LAUNCH_MAIL;
441 case DomKey::LAUNCH_MY_COMPUTER:
442 return VKEY_MEDIA_LAUNCH_APP1;
443 // Browser Keys
444 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-browser
445 case DomKey::BROWSER_BACK:
446 return VKEY_BACK;
447 case DomKey::BROWSER_FAVORITES:
448 return VKEY_BROWSER_FAVORITES;
449 case DomKey::BROWSER_FORWARD:
450 return VKEY_BROWSER_FORWARD;
451 case DomKey::BROWSER_HOME:
452 return VKEY_BROWSER_HOME;
453 case DomKey::BROWSER_REFRESH:
454 return VKEY_BROWSER_REFRESH;
455 case DomKey::BROWSER_SEARCH:
456 return VKEY_BROWSER_SEARCH;
457 case DomKey::BROWSER_STOP:
458 return VKEY_BROWSER_STOP;
459 // Media Controller Keys
460 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller
461 case DomKey::ZOOM_TOGGLE:
462 return VKEY_ZOOM;
463 // No value.
464 default:
465 return VKEY_UNKNOWN;
466 }
467 }
468
469 // TODO(kpschoedel): move this to a shared location.
470 // This table maps DOM Level 3 .code values to legacy Windows-based VKEY
471 // values, where the VKEYs are interpreted positionally.
472 const struct DomCodeToKeyboardCodeEntry {
473 DomCode dom_code;
474 KeyboardCode key_code;
475 } dom_code_to_keyboard_code[] = {
476 // Entries are ordered by numeric value of the DomCode enum,
477 // which is the USB physical key code.
478 // DomCode::HYPER 0x000010 Hyper
479 // DomCode::SUPER 0x000011 Super
480 // DomCode::FN 0x000012 Fn
481 // DomCode::FN_LOCK 0x000013 FLock
482 // DomCode::SUSPEND 0x000014 Suspend
483 // DomCode::RESUME 0x000015 Resume
484 // DomCode::TURBO 0x000016 Turbo
485 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep
486 // DomCode::WAKE_UP 0x010083 WakeUp
487 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA
488 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB
489 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC
490 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD
491 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE
492 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF
493 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG
494 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH
495 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI
496 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ
497 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK
498 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL
499 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM
500 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN
501 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO
502 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP
503 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ
504 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR
505 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS
506 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT
507 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU
508 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV
509 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW
510 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX
511 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY
512 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ
513 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1
514 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2
515 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3
516 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4
517 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5
518 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6
519 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7
520 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8
521 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9
522 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0
523 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter
524 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape
525 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace
526 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab
527 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space
528 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus
529 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal
530 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft
531 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight
532 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash
533 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash
534 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon
535 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote
536 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote
537 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma
538 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period
539 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash
540 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock
541 {DomCode::F1, VKEY_F1}, // 0x07003A F1
542 {DomCode::F2, VKEY_F2}, // 0x07003B F2
543 {DomCode::F3, VKEY_F3}, // 0x07003C F3
544 {DomCode::F4, VKEY_F4}, // 0x07003D F4
545 {DomCode::F5, VKEY_F5}, // 0x07003E F5
546 {DomCode::F6, VKEY_F6}, // 0x07003F F6
547 {DomCode::F7, VKEY_F7}, // 0x070040 F7
548 {DomCode::F8, VKEY_F8}, // 0x070041 F8
549 {DomCode::F9, VKEY_F9}, // 0x070042 F9
550 {DomCode::F10, VKEY_F10}, // 0x070043 F10
551 {DomCode::F11, VKEY_F11}, // 0x070044 F11
552 {DomCode::F12, VKEY_F12}, // 0x070045 F12
553 {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen
554 {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock
555 {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause
556 {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert
557 {DomCode::HOME, VKEY_HOME}, // 0x07004A Home
558 {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp
559 {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete
560 {DomCode::END, VKEY_END}, // 0x07004D End
561 {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown
562 {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight
563 {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft
564 {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown
565 {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp
566 {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock
567 {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide
568 {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply
569 {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract
570 {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd
571 {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter
572 {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1
573 {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2
574 {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3
575 {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4
576 {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5
577 {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6
578 {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7
579 {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8
580 {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9
581 {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0
582 {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal
583 {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash
584 {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu
585 {DomCode::POWER, VKEY_POWER}, // 0x070066 Power
586 // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual
587 // DomCode::OPEN 0x070074 Open
588 {DomCode::HELP, VKEY_HELP}, // 0x070075 Help
589 {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select
590 // DomCode::AGAIN 0x070079 Again
591 // DomCode::UNDO 0x07007A Undo
592 // DomCode::CUT 0x07007B Cut
593 // DomCode::COPY 0x07007C Copy
594 // DomCode::PASTE 0x07007D Paste
595 // DomCode::FIND 0x07007E Find
596 {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute
597 {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp
598 {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown
599 {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma
600 {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo
601 {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode
602 {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen
603 {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert
604 {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert
605 {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1
606 {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2
607 // DomCode::LANG3 0x070092 Lang3
608 // DomCode::LANG4 0x070093 Lang4
609 // DomCode::LANG5 0x070094 Lang5
610 // DomCode::ABORT 0x07009B Abort
611 // DomCode::PROPS 0x0700A3 Props
612 // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft
613 // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight
614 {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace
615 // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore
616 // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall
617 // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear
618 // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd
619 // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4
620 // NumpadMemorySubtract
621 {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear
622 {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry
623 {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft
624 {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft
625 {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft
626 {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft
627 {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight
628 {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight
629 {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight
630 {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight
631 {DomCode::MEDIA_TRACK_NEXT,
632 VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext
633 {DomCode::MEDIA_TRACK_PREVIOUS,
634 VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious
635 {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop
636 // DomCode::EJECT 0x0C00B8 Eject
637 {DomCode::MEDIA_PLAY_PAUSE,
638 VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause
639 {DomCode::MEDIA_SELECT,
640 VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect
641 {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail
642 {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2
643 {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1
644 {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch
645 {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome
646 {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack
647 {DomCode::BROWSER_FORWARD,
648 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward
649 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop
650 {DomCode::BROWSER_REFRESH,
651 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh
652 {DomCode::BROWSER_FAVORITES,
653 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites
654 };
655
656 // TODO(kpschoedel): move this to a shared location.
657 // Map DOM Level 3 .code values to legacy Windows-based VKEY values,
658 // where the VKEYs are interpreted positionally.
659 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) {
660 const DomCodeToKeyboardCodeEntry* end =
661 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code);
662 const DomCodeToKeyboardCodeEntry* found =
663 std::lower_bound(dom_code_to_keyboard_code, end, dom_code,
664 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) {
665 return static_cast<int>(a.dom_code) < static_cast<int>(b);
666 });
667 if ((found != end) && (found->dom_code == dom_code))
668 return found->key_code;
669 return VKEY_UNKNOWN;
670 }
671
672
673 } // anonymous namespace
674
675 StubKeyboardLayouts::StubKeyboardLayouts() {
676 }
677
678 StubKeyboardLayouts::~StubKeyboardLayouts() {
679 }
680
681 bool StubKeyboardLayouts::CanSetCurrentLayout() {
682 return false;
683 }
684
685 bool StubKeyboardLayouts::SetCurrentLayoutByName(
686 const std::string& layout_name) {
687 return false;
688 }
689
690 bool StubKeyboardLayouts::UsesISOLevel5Shift() {
691 return false;
692 }
693
694 bool StubKeyboardLayouts::UsesAltGr() {
695 return true;
696 }
697
698 bool StubKeyboardLayouts::Lookup(DomCode dom_code,
699 int flags,
700 DomKey* dom_key,
701 base::char16* character,
702 KeyboardCode* key_code) {
703 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) {
704 *key_code = DomCodeToKeyboardCode(dom_code);
705 *character = GetCharacterFromKeyCode(*key_code, flags);
706 switch (*character) {
707 case 0x00:
708 if (dom_code == DomCode::DIGIT2) {
709 // Control-@.
710 *dom_key = DomKey::CHARACTER;
711 return true;
712 }
713 *dom_key = DomKey::UNIDENTIFIED;
714 return false;
715 case 0x08:
716 *dom_key = DomKey::BACKSPACE;
717 return true;
718 case 0x09:
719 *dom_key = DomKey::TAB;
720 return true;
721 case 0x0D:
722 *dom_key = DomKey::ENTER;
723 return true;
724 case 0x1B:
725 *dom_key = DomKey::ESCAPE;
726 return true;
727 case 0x7F:
728 *dom_key = DomKey::DEL;
729 return true;
730 default:
731 *dom_key = DomKey::CHARACTER;
732 return true;
733 break;
734 }
735 }
736 for (size_t i = 0; i < arraysize(printable_code_map); ++i) {
737 if (printable_code_map[i].dom_code == dom_code) {
738 int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) |
739 ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN);
740 base::char16 ch = printable_code_map[i].character[state];
741 *dom_key = (ch & DK) ? DomKey::DEAD : DomKey::CHARACTER;
742 *character = ch;
743 if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) {
744 ch = (ch & ~DK) | 0x20;
745 if ((ch >= 'a') && (ch <= 'z'))
746 *character = printable_code_map[i].character[state ^ 1];
747 }
748 *key_code = DomCodeToKeyboardCode(dom_code);
749 return true;
750 }
751 }
752 for (size_t i = 0; i < arraysize(non_printable_code_map); ++i) {
753 if (non_printable_code_map[i].dom_code == dom_code) {
754 *dom_key = non_printable_code_map[i].dom_key;
755 *character = non_printable_code_map[i].character;
756 *key_code = DomKeyToKeyboardCode(*dom_key);
757 return true;
758 }
759 }
760 *dom_key = DomKey::UNIDENTIFIED;
761 *character = 0;
762 *key_code = VKEY_UNKNOWN;
763 return false;
764 }
765
766 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698