base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / ozone / layout / layout_util.cc
blob2583485d3e06e349b86f74d9781e4a9381e1af38
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.
5 #include "ui/events/ozone/layout/layout_util.h"
7 #include <algorithm>
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"
13 namespace ui {
15 namespace {
17 bool IsRightSideDomCode(DomCode code) {
18 return (code == DomCode::SHIFT_RIGHT) || (code == DomCode::CONTROL_RIGHT) ||
19 (code == DomCode::ALT_RIGHT) || (code == DomCode::OS_RIGHT);
22 // This table, used by DomKeyToKeyboardCode(), maps DOM Level 3 .code
23 // values to legacy Windows-based VKEY values, where the VKEYs are
24 // interpreted positionally.
25 const struct DomCodeToKeyboardCodeEntry {
26 DomCode dom_code;
27 KeyboardCode key_code;
28 } dom_code_to_keyboard_code[] = {
29 // Entries are ordered by numeric value of the DomCode enum,
30 // which is the USB physical key code.
31 // DomCode::HYPER 0x000010 Hyper
32 // DomCode::SUPER 0x000011 Super
33 // DomCode::FN 0x000012 Fn
34 // DomCode::FN_LOCK 0x000013 FLock
35 // DomCode::SUSPEND 0x000014 Suspend
36 // DomCode::RESUME 0x000015 Resume
37 // DomCode::TURBO 0x000016 Turbo
38 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep
39 // DomCode::WAKE_UP 0x010083 WakeUp
40 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA
41 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB
42 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC
43 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD
44 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE
45 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF
46 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG
47 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH
48 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI
49 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ
50 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK
51 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL
52 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM
53 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN
54 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO
55 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP
56 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ
57 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR
58 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS
59 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT
60 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU
61 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV
62 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW
63 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX
64 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY
65 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ
66 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1
67 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2
68 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3
69 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4
70 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5
71 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6
72 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7
73 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8
74 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9
75 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0
76 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter
77 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape
78 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace
79 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab
80 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space
81 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus
82 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal
83 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft
84 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight
85 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash
86 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash
87 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon
88 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote
89 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote
90 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma
91 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period
92 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash
93 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock
94 {DomCode::F1, VKEY_F1}, // 0x07003A F1
95 {DomCode::F2, VKEY_F2}, // 0x07003B F2
96 {DomCode::F3, VKEY_F3}, // 0x07003C F3
97 {DomCode::F4, VKEY_F4}, // 0x07003D F4
98 {DomCode::F5, VKEY_F5}, // 0x07003E F5
99 {DomCode::F6, VKEY_F6}, // 0x07003F F6
100 {DomCode::F7, VKEY_F7}, // 0x070040 F7
101 {DomCode::F8, VKEY_F8}, // 0x070041 F8
102 {DomCode::F9, VKEY_F9}, // 0x070042 F9
103 {DomCode::F10, VKEY_F10}, // 0x070043 F10
104 {DomCode::F11, VKEY_F11}, // 0x070044 F11
105 {DomCode::F12, VKEY_F12}, // 0x070045 F12
106 {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen
107 {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock
108 {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause
109 {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert
110 {DomCode::HOME, VKEY_HOME}, // 0x07004A Home
111 {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp
112 {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete
113 {DomCode::END, VKEY_END}, // 0x07004D End
114 {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown
115 {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight
116 {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft
117 {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown
118 {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp
119 {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock
120 {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide
121 {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply
122 {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract
123 {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd
124 {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter
125 {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1
126 {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2
127 {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3
128 {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4
129 {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5
130 {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6
131 {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7
132 {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8
133 {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9
134 {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0
135 {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal
136 {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash
137 {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu
138 {DomCode::POWER, VKEY_POWER}, // 0x070066 Power
139 // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual
140 // DomCode::OPEN 0x070074 Open
141 {DomCode::HELP, VKEY_HELP}, // 0x070075 Help
142 {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select
143 // DomCode::AGAIN 0x070079 Again
144 // DomCode::UNDO 0x07007A Undo
145 // DomCode::CUT 0x07007B Cut
146 // DomCode::COPY 0x07007C Copy
147 // DomCode::PASTE 0x07007D Paste
148 // DomCode::FIND 0x07007E Find
149 {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute
150 {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp
151 {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown
152 {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma
153 {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo
154 {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode
155 {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen
156 {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert
157 {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert
158 {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1
159 {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2
160 // DomCode::LANG3 0x070092 Lang3
161 // DomCode::LANG4 0x070093 Lang4
162 // DomCode::LANG5 0x070094 Lang5
163 // DomCode::ABORT 0x07009B Abort
164 // DomCode::PROPS 0x0700A3 Props
165 // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft
166 // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight
167 {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace
168 // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore
169 // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall
170 // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear
171 // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd
172 // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4
173 // NumpadMemorySubtract
174 {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear
175 {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry
176 {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft
177 {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft
178 {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft
179 {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft
180 {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight
181 {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight
182 {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight
183 {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight
184 {DomCode::MEDIA_TRACK_NEXT,
185 VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext
186 {DomCode::MEDIA_TRACK_PREVIOUS,
187 VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious
188 {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop
189 // DomCode::EJECT 0x0C00B8 Eject
190 {DomCode::MEDIA_PLAY_PAUSE,
191 VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause
192 {DomCode::MEDIA_SELECT,
193 VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect
194 {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail
195 {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2
196 {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1
197 {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch
198 {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome
199 {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack
200 {DomCode::BROWSER_FORWARD,
201 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward
202 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop
203 {DomCode::BROWSER_REFRESH,
204 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh
205 {DomCode::BROWSER_FAVORITES,
206 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites
209 } // anonymous namespace
211 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|.
212 // The returned VKEY is non-positional (e.g. VKEY_SHIFT).
213 KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) {
214 switch (dom_key) {
215 // No value.
216 case DomKey::NONE:
217 return VKEY_UNKNOWN;
218 // Character values.
219 // Special Key Values
220 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special
221 case DomKey::UNIDENTIFIED:
222 return VKEY_UNKNOWN;
223 // Modifier Keys
224 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier
225 case DomKey::ALT:
226 return VKEY_MENU;
227 case DomKey::ALT_GRAPH:
228 return VKEY_ALTGR;
229 case DomKey::CAPS_LOCK:
230 return VKEY_CAPITAL;
231 case DomKey::CONTROL:
232 return VKEY_CONTROL;
233 case DomKey::NUM_LOCK:
234 return VKEY_NUMLOCK;
235 case DomKey::OS:
236 return VKEY_LWIN;
237 case DomKey::SCROLL_LOCK:
238 return VKEY_SCROLL;
239 case DomKey::SHIFT:
240 return VKEY_SHIFT;
241 // Whitespace Keys
242 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-whitespace
243 case DomKey::ENTER:
244 return VKEY_RETURN;
245 case DomKey::SEPARATOR:
246 return VKEY_SEPARATOR;
247 case DomKey::TAB:
248 return VKEY_TAB;
249 // Navigation Keys
250 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-navigation
251 case DomKey::ARROW_DOWN:
252 return VKEY_DOWN;
253 case DomKey::ARROW_LEFT:
254 return VKEY_LEFT;
255 case DomKey::ARROW_RIGHT:
256 return VKEY_RIGHT;
257 case DomKey::ARROW_UP:
258 return VKEY_UP;
259 case DomKey::END:
260 return VKEY_END;
261 case DomKey::HOME:
262 return VKEY_HOME;
263 case DomKey::PAGE_DOWN:
264 return VKEY_NEXT;
265 case DomKey::PAGE_UP:
266 return VKEY_PRIOR;
267 // Editing Keys
268 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-editing
269 case DomKey::BACKSPACE:
270 return VKEY_BACK;
271 case DomKey::CLEAR:
272 return VKEY_CLEAR;
273 case DomKey::CR_SEL:
274 return VKEY_CRSEL;
275 case DomKey::DEL:
276 return VKEY_DELETE;
277 case DomKey::ERASE_EOF:
278 return VKEY_EREOF;
279 case DomKey::EX_SEL:
280 return VKEY_EXSEL;
281 case DomKey::INSERT:
282 return VKEY_INSERT;
283 // UI Keys
284 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-ui
285 case DomKey::ACCEPT:
286 return VKEY_ACCEPT;
287 case DomKey::ATTN:
288 return VKEY_ATTN;
289 case DomKey::CONTEXT_MENU:
290 return VKEY_APPS;
291 case DomKey::ESCAPE:
292 return VKEY_ESCAPE;
293 case DomKey::EXECUTE:
294 return VKEY_EXECUTE;
295 case DomKey::HELP:
296 return VKEY_HELP;
297 case DomKey::PAUSE:
298 return VKEY_PAUSE;
299 case DomKey::PLAY:
300 return VKEY_PLAY;
301 case DomKey::SELECT:
302 return VKEY_SELECT;
303 // Device Keys
304 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device
305 case DomKey::BRIGHTNESS_DOWN:
306 return VKEY_BRIGHTNESS_DOWN;
307 case DomKey::BRIGHTNESS_UP:
308 return VKEY_BRIGHTNESS_UP;
309 case DomKey::POWER:
310 return VKEY_POWER;
311 case DomKey::PRINT_SCREEN:
312 return VKEY_SNAPSHOT;
313 // IME and Composition Keys
314 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition
315 #if 0 // TODO(kpschoedel)
316 case DomKey::COMPOSE:
317 return VKEY_COMPOSE;
318 #endif
319 case DomKey::CONVERT:
320 return VKEY_CONVERT;
321 case DomKey::FINAL_MODE:
322 return VKEY_FINAL;
323 case DomKey::MODE_CHANGE:
324 return VKEY_MODECHANGE;
325 case DomKey::NON_CONVERT:
326 return VKEY_NONCONVERT;
327 case DomKey::PROCESS:
328 return VKEY_PROCESSKEY;
329 // Keys specific to Korean keyboards
330 case DomKey::HANGUL_MODE:
331 return VKEY_HANGUL;
332 case DomKey::HANJA_MODE:
333 return VKEY_HANJA;
334 case DomKey::JUNJA_MODE:
335 return VKEY_JUNJA;
336 // Keys specific to Japanese keyboards
337 case DomKey::HANKAKU:
338 return VKEY_DBE_SBCSCHAR;
339 case DomKey::KANA_MODE:
340 return VKEY_KANA;
341 case DomKey::KANJI_MODE:
342 return VKEY_KANJI;
343 case DomKey::ZENKAKU:
344 return VKEY_DBE_DBCSCHAR;
345 case DomKey::ZENKAKU_HANKAKU:
346 return VKEY_DBE_DBCSCHAR;
347 // General-Purpose Function Keys
348 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-function
349 case DomKey::F1:
350 return VKEY_F1;
351 case DomKey::F2:
352 return VKEY_F2;
353 case DomKey::F3:
354 return VKEY_F3;
355 case DomKey::F4:
356 return VKEY_F4;
357 case DomKey::F5:
358 return VKEY_F5;
359 case DomKey::F6:
360 return VKEY_F6;
361 case DomKey::F7:
362 return VKEY_F7;
363 case DomKey::F8:
364 return VKEY_F8;
365 case DomKey::F9:
366 return VKEY_F9;
367 case DomKey::F10:
368 return VKEY_F10;
369 case DomKey::F11:
370 return VKEY_F11;
371 case DomKey::F12:
372 return VKEY_F12;
373 case DomKey::F13:
374 return VKEY_F13;
375 case DomKey::F14:
376 return VKEY_F14;
377 case DomKey::F15:
378 return VKEY_F15;
379 case DomKey::F16:
380 return VKEY_F16;
381 case DomKey::F17:
382 return VKEY_F17;
383 case DomKey::F18:
384 return VKEY_F18;
385 case DomKey::F19:
386 return VKEY_F19;
387 case DomKey::F20:
388 return VKEY_F20;
389 case DomKey::F21:
390 return VKEY_F21;
391 case DomKey::F22:
392 return VKEY_F22;
393 case DomKey::F23:
394 return VKEY_F23;
395 case DomKey::F24:
396 return VKEY_F24;
397 // Multimedia Keys
398 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-multimedia
399 case DomKey::MEDIA_PLAY_PAUSE:
400 return VKEY_MEDIA_PLAY_PAUSE;
401 case DomKey::MEDIA_SELECT:
402 return VKEY_MEDIA_LAUNCH_MEDIA_SELECT;
403 case DomKey::MEDIA_STOP:
404 return VKEY_MEDIA_STOP;
405 case DomKey::MEDIA_TRACK_NEXT:
406 return VKEY_MEDIA_NEXT_TRACK;
407 case DomKey::MEDIA_TRACK_PREVIOUS:
408 return VKEY_MEDIA_PREV_TRACK;
409 case DomKey::PRINT:
410 return VKEY_PRINT;
411 case DomKey::VOLUME_DOWN:
412 return VKEY_VOLUME_DOWN;
413 case DomKey::VOLUME_MUTE:
414 return VKEY_VOLUME_MUTE;
415 case DomKey::VOLUME_UP:
416 return VKEY_VOLUME_UP;
417 // Application Keys
418 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-apps
419 case DomKey::LAUNCH_CALCULATOR:
420 return VKEY_MEDIA_LAUNCH_APP2;
421 case DomKey::LAUNCH_MAIL:
422 return VKEY_MEDIA_LAUNCH_MAIL;
423 case DomKey::LAUNCH_MY_COMPUTER:
424 return VKEY_MEDIA_LAUNCH_APP1;
425 // Browser Keys
426 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-browser
427 case DomKey::BROWSER_BACK:
428 return VKEY_BACK;
429 case DomKey::BROWSER_FAVORITES:
430 return VKEY_BROWSER_FAVORITES;
431 case DomKey::BROWSER_FORWARD:
432 return VKEY_BROWSER_FORWARD;
433 case DomKey::BROWSER_HOME:
434 return VKEY_BROWSER_HOME;
435 case DomKey::BROWSER_REFRESH:
436 return VKEY_BROWSER_REFRESH;
437 case DomKey::BROWSER_SEARCH:
438 return VKEY_BROWSER_SEARCH;
439 case DomKey::BROWSER_STOP:
440 return VKEY_BROWSER_STOP;
441 // Media Controller Keys
442 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller
443 case DomKey::ZOOM_TOGGLE:
444 return VKEY_ZOOM;
445 // No value.
446 default:
447 return VKEY_UNKNOWN;
451 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
452 // The returned VKEY is located (e.g. VKEY_LSHIFT).
453 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) {
454 const DomCodeToKeyboardCodeEntry* end =
455 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code);
456 const DomCodeToKeyboardCodeEntry* found =
457 std::lower_bound(dom_code_to_keyboard_code, end, dom_code,
458 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) {
459 return static_cast<int>(a.dom_code) < static_cast<int>(b);
461 if ((found != end) && (found->dom_code == dom_code))
462 return found->key_code;
463 return VKEY_UNKNOWN;
466 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
467 // The returned VKEY is non-located (e.g. VKEY_SHIFT).
468 KeyboardCode DomCodeToNonLocatedKeyboardCode(DomCode dom_code) {
469 return NonLocatedKeyboardCode(DomCodeToKeyboardCode(dom_code));
472 // Determine the non-located VKEY corresponding to a located VKEY.
473 KeyboardCode NonLocatedKeyboardCode(KeyboardCode key_code) {
474 switch (key_code) {
475 case VKEY_RWIN:
476 return VKEY_LWIN;
477 case VKEY_LSHIFT:
478 case VKEY_RSHIFT:
479 return VKEY_SHIFT;
480 case VKEY_LCONTROL:
481 case VKEY_RCONTROL:
482 return VKEY_CONTROL;
483 case VKEY_LMENU:
484 case VKEY_RMENU:
485 return VKEY_MENU;
486 default:
487 return key_code;
491 // Determine the located VKEY corresponding to a non-located VKEY.
492 KeyboardCode LocatedKeyboardCode(KeyboardCode key_code, DomCode dom_code) {
493 switch (key_code) {
494 case VKEY_SHIFT:
495 return IsRightSideDomCode(dom_code) ? VKEY_RSHIFT : VKEY_LSHIFT;
496 case VKEY_CONTROL:
497 return IsRightSideDomCode(dom_code) ? VKEY_RCONTROL : VKEY_LCONTROL;
498 case VKEY_MENU:
499 return IsRightSideDomCode(dom_code) ? VKEY_RMENU : VKEY_LMENU;
500 case VKEY_LWIN:
501 return IsRightSideDomCode(dom_code) ? VKEY_RWIN : VKEY_LWIN;
502 case VKEY_0:
503 return (dom_code == DomCode::NUMPAD0) ? VKEY_NUMPAD0 : VKEY_0;
504 case VKEY_1:
505 return (dom_code == DomCode::NUMPAD1) ? VKEY_NUMPAD1 : VKEY_1;
506 case VKEY_2:
507 return (dom_code == DomCode::NUMPAD2) ? VKEY_NUMPAD2 : VKEY_2;
508 case VKEY_3:
509 return (dom_code == DomCode::NUMPAD3) ? VKEY_NUMPAD3 : VKEY_3;
510 case VKEY_4:
511 return (dom_code == DomCode::NUMPAD4) ? VKEY_NUMPAD4 : VKEY_4;
512 case VKEY_5:
513 return (dom_code == DomCode::NUMPAD5) ? VKEY_NUMPAD5 : VKEY_5;
514 case VKEY_6:
515 return (dom_code == DomCode::NUMPAD6) ? VKEY_NUMPAD6 : VKEY_6;
516 case VKEY_7:
517 return (dom_code == DomCode::NUMPAD7) ? VKEY_NUMPAD7 : VKEY_7;
518 case VKEY_8:
519 return (dom_code == DomCode::NUMPAD8) ? VKEY_NUMPAD8 : VKEY_8;
520 case VKEY_9:
521 return (dom_code == DomCode::NUMPAD9) ? VKEY_NUMPAD9 : VKEY_9;
522 default:
523 return key_code;
527 bool LookupControlCharacter(DomCode dom_code,
528 int flags,
529 DomKey* dom_key,
530 base::char16* character,
531 KeyboardCode* key_code) {
532 if ((flags & EF_CONTROL_DOWN) == 0)
533 return false;
535 int code = static_cast<int>(dom_code);
536 const int kKeyA = static_cast<int>(DomCode::KEY_A);
537 // Control-A - Control-Z map to 0x01 - 0x1A.
538 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) {
539 *character = static_cast<base::char16>(code - kKeyA + 1);
540 *key_code = static_cast<KeyboardCode>(code - kKeyA + VKEY_A);
541 switch (dom_code) {
542 case DomCode::KEY_H:
543 *dom_key = DomKey::BACKSPACE;
544 case DomCode::KEY_I:
545 *dom_key = DomKey::TAB;
546 case DomCode::KEY_M:
547 *dom_key = DomKey::ENTER;
548 default:
549 *dom_key = DomKey::CHARACTER;
551 return true;
554 switch (dom_code) {
555 case DomCode::DIGIT2:
556 // NUL
557 *character = 0;
558 *dom_key = DomKey::CHARACTER;
559 *key_code = VKEY_2;
560 return true;
561 case DomCode::ENTER:
562 // NL
563 *character = 0x0A;
564 *dom_key = DomKey::CHARACTER;
565 *key_code = VKEY_RETURN;
566 return true;
567 case DomCode::BRACKET_LEFT:
568 // ESC
569 *character = 0x1B;
570 *dom_key = DomKey::ESCAPE;
571 *key_code = VKEY_OEM_4;
572 return true;
573 case DomCode::BACKSLASH:
574 // FS
575 *character = 0x1C;
576 *dom_key = DomKey::CHARACTER;
577 *key_code = VKEY_OEM_5;
578 return true;
579 case DomCode::BRACKET_RIGHT:
580 // GS
581 *character = 0x1D;
582 *dom_key = DomKey::CHARACTER;
583 *key_code = VKEY_OEM_6;
584 return true;
585 case DomCode::DIGIT6:
586 // RS
587 *character = 0x1E;
588 *dom_key = DomKey::CHARACTER;
589 *key_code = VKEY_6;
590 return true;
591 case DomCode::MINUS:
592 // US
593 *character = 0x1F;
594 *dom_key = DomKey::CHARACTER;
595 *key_code = VKEY_OEM_MINUS;
596 return true;
597 default:
598 return false;
602 int ModifierDomKeyToEventFlag(DomKey key) {
603 switch (key) {
604 case DomKey::ALT:
605 return EF_ALT_DOWN;
606 case DomKey::ALT_GRAPH:
607 return EF_ALTGR_DOWN;
608 case DomKey::CAPS_LOCK:
609 return EF_CAPS_LOCK_DOWN;
610 case DomKey::CONTROL:
611 return EF_CONTROL_DOWN;
612 case DomKey::HYPER:
613 return EF_MOD3_DOWN;
614 case DomKey::META:
615 return EF_ALT_DOWN;
616 case DomKey::OS:
617 return EF_COMMAND_DOWN;
618 case DomKey::SHIFT:
619 return EF_SHIFT_DOWN;
620 case DomKey::SUPER:
621 return EF_MOD3_DOWN;
622 default:
623 return EF_NONE;
625 // Not represented:
626 // DomKey::ACCEL
627 // DomKey::FN
628 // DomKey::FN_LOCK
629 // DomKey::NUM_LOCK
630 // DomKey::SCROLL_LOCK
631 // DomKey::SYMBOL
632 // DomKey::SYMBOL_LOCK
635 } // namespace ui