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"
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"
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
{
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
) {
219 // Special Key Values
220 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special
221 case DomKey::UNIDENTIFIED
:
224 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier
227 case DomKey::ALT_GRAPH
:
229 case DomKey::CAPS_LOCK
:
231 case DomKey::CONTROL
:
233 case DomKey::NUM_LOCK
:
237 case DomKey::SCROLL_LOCK
:
242 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-whitespace
245 case DomKey::SEPARATOR
:
246 return VKEY_SEPARATOR
;
250 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-navigation
251 case DomKey::ARROW_DOWN
:
253 case DomKey::ARROW_LEFT
:
255 case DomKey::ARROW_RIGHT
:
257 case DomKey::ARROW_UP
:
263 case DomKey::PAGE_DOWN
:
265 case DomKey::PAGE_UP
:
268 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-editing
269 case DomKey::BACKSPACE
:
277 case DomKey::ERASE_EOF
:
284 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-ui
289 case DomKey::CONTEXT_MENU
:
293 case DomKey::EXECUTE
:
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
;
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
:
319 case DomKey::CONVERT
:
321 case DomKey::FINAL_MODE
:
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
:
332 case DomKey::HANJA_MODE
:
334 case DomKey::JUNJA_MODE
:
336 // Keys specific to Japanese keyboards
337 case DomKey::HANKAKU
:
338 return VKEY_DBE_SBCSCHAR
;
339 case DomKey::KANA_MODE
:
341 case DomKey::KANJI_MODE
:
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
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
;
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
;
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
;
426 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-browser
427 case DomKey::BROWSER_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
:
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
;
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
) {
491 // Determine the located VKEY corresponding to a non-located VKEY.
492 KeyboardCode
LocatedKeyboardCode(KeyboardCode key_code
, DomCode dom_code
) {
495 return IsRightSideDomCode(dom_code
) ? VKEY_RSHIFT
: VKEY_LSHIFT
;
497 return IsRightSideDomCode(dom_code
) ? VKEY_RCONTROL
: VKEY_LCONTROL
;
499 return IsRightSideDomCode(dom_code
) ? VKEY_RMENU
: VKEY_LMENU
;
501 return IsRightSideDomCode(dom_code
) ? VKEY_RWIN
: VKEY_LWIN
;
503 return (dom_code
== DomCode::NUMPAD0
) ? VKEY_NUMPAD0
: VKEY_0
;
505 return (dom_code
== DomCode::NUMPAD1
) ? VKEY_NUMPAD1
: VKEY_1
;
507 return (dom_code
== DomCode::NUMPAD2
) ? VKEY_NUMPAD2
: VKEY_2
;
509 return (dom_code
== DomCode::NUMPAD3
) ? VKEY_NUMPAD3
: VKEY_3
;
511 return (dom_code
== DomCode::NUMPAD4
) ? VKEY_NUMPAD4
: VKEY_4
;
513 return (dom_code
== DomCode::NUMPAD5
) ? VKEY_NUMPAD5
: VKEY_5
;
515 return (dom_code
== DomCode::NUMPAD6
) ? VKEY_NUMPAD6
: VKEY_6
;
517 return (dom_code
== DomCode::NUMPAD7
) ? VKEY_NUMPAD7
: VKEY_7
;
519 return (dom_code
== DomCode::NUMPAD8
) ? VKEY_NUMPAD8
: VKEY_8
;
521 return (dom_code
== DomCode::NUMPAD9
) ? VKEY_NUMPAD9
: VKEY_9
;
527 bool LookupControlCharacter(DomCode dom_code
,
530 base::char16
* character
,
531 KeyboardCode
* key_code
) {
532 if ((flags
& EF_CONTROL_DOWN
) == 0)
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
);
543 *dom_key
= DomKey::BACKSPACE
;
545 *dom_key
= DomKey::TAB
;
547 *dom_key
= DomKey::ENTER
;
549 *dom_key
= DomKey::CHARACTER
;
555 case DomCode::DIGIT2
:
558 *dom_key
= DomKey::CHARACTER
;
564 *dom_key
= DomKey::CHARACTER
;
565 *key_code
= VKEY_RETURN
;
567 case DomCode::BRACKET_LEFT
:
570 *dom_key
= DomKey::ESCAPE
;
571 *key_code
= VKEY_OEM_4
;
573 case DomCode::BACKSLASH
:
576 *dom_key
= DomKey::CHARACTER
;
577 *key_code
= VKEY_OEM_5
;
579 case DomCode::BRACKET_RIGHT
:
582 *dom_key
= DomKey::CHARACTER
;
583 *key_code
= VKEY_OEM_6
;
585 case DomCode::DIGIT6
:
588 *dom_key
= DomKey::CHARACTER
;
594 *dom_key
= DomKey::CHARACTER
;
595 *key_code
= VKEY_OEM_MINUS
;
602 int ModifierDomKeyToEventFlag(DomKey key
) {
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
;
617 return EF_COMMAND_DOWN
;
619 return EF_SHIFT_DOWN
;
630 // DomKey::SCROLL_LOCK
632 // DomKey::SYMBOL_LOCK