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

Side by Side Diff: ui/events/ozone/layout/layout_util.cc

Issue 778503002: XKB implementation of Ozone key layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@x430194-layout
Patch Set: fix boneheaded license paste Created 6 years 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 2014 The Chromium Authors. All rights reserved. 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 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/ozone/layout/stub/stub_keyboard_layout_engine.h" 5 #include "ui/events/ozone/layout/layout_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string16.h" 9 #include "ui/events/event_constants.h"
10 #include "ui/events/event.h"
11 #include "ui/events/keycodes/dom3/dom_code.h" 10 #include "ui/events/keycodes/dom3/dom_code.h"
12 #include "ui/events/keycodes/dom3/dom_key.h" 11 #include "ui/events/keycodes/dom3/dom_key.h"
13 #include "ui/events/keycodes/keyboard_code_conversion.h"
14 12
15 namespace ui { 13 namespace ui {
16 14
17 namespace { 15 namespace {
18 16
19 // All of the characters have low ordinals, so we use bit 15 to flag dead keys. 17 // This table, used by DomKeyToKeyboardCode(), maps DOM Level 3 .code
20 #define DK 0x8000 18 // values to legacy Windows-based VKEY values, where the VKEYs are
21 19 // interpreted positionally.
22 const struct PrintableCodeEntry { 20 const struct DomCodeToKeyboardCodeEntry {
23 DomCode dom_code; 21 DomCode dom_code;
24 base::char16 character[4]; 22 KeyboardCode key_code;
25 } printable_code_map[] = { 23 } dom_code_to_keyboard_code[] = {
26 // Stub table based on X US international. 24 // Entries are ordered by numeric value of the DomCode enum,
27 {DomCode::KEY_A, {'a', 'A', 0x00E1, 0x00C1}}, 25 // which is the USB physical key code.
28 {DomCode::KEY_B, {'b', 'B', 'b', 'B'}}, 26 // DomCode::HYPER 0x000010 Hyper
29 {DomCode::KEY_C, {'c', 'C', 0x00A9, 0x00A2}}, 27 // DomCode::SUPER 0x000011 Super
30 {DomCode::KEY_D, {'d', 'D', 0x00F0, 0x00D0}}, 28 // DomCode::FN 0x000012 Fn
31 {DomCode::KEY_E, {'e', 'E', 0x00E9, 0x00C9}}, 29 // DomCode::FN_LOCK 0x000013 FLock
32 {DomCode::KEY_F, {'f', 'F', 'f', 'F'}}, 30 // DomCode::SUSPEND 0x000014 Suspend
33 {DomCode::KEY_G, {'g', 'G', 'g', 'G'}}, 31 // DomCode::RESUME 0x000015 Resume
34 {DomCode::KEY_H, {'h', 'H', 'h', 'H'}}, 32 // DomCode::TURBO 0x000016 Turbo
35 {DomCode::KEY_I, {'i', 'I', 0x00ED, 0x00CD}}, 33 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep
36 {DomCode::KEY_J, {'j', 'J', 'j', 'J'}}, 34 // DomCode::WAKE_UP 0x010083 WakeUp
37 {DomCode::KEY_K, {'k', 'K', 0x0153, 0x0152}}, 35 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA
38 {DomCode::KEY_L, {'l', 'L', 0x00F8, 0x00D8}}, 36 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB
39 {DomCode::KEY_M, {'m', 'M', 0x00B5, 0x00B5}}, 37 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC
40 {DomCode::KEY_N, {'n', 'N', 0x00F1, 0x00D1}}, 38 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD
41 {DomCode::KEY_O, {'o', 'O', 0x00F3, 0x00D3}}, 39 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE
42 {DomCode::KEY_P, {'p', 'P', 0x00F6, 0x00D6}}, 40 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF
43 {DomCode::KEY_Q, {'q', 'Q', 0x00E4, 0x00C4}}, 41 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG
44 {DomCode::KEY_R, {'r', 'R', 0x00AE, 0x00AE}}, 42 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH
45 {DomCode::KEY_S, {'s', 'S', 0x00DF, 0x00A7}}, 43 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI
46 {DomCode::KEY_T, {'t', 'T', 0x00FE, 0x00DE}}, 44 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ
47 {DomCode::KEY_U, {'u', 'U', 0x00FA, 0x00DA}}, 45 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK
48 {DomCode::KEY_V, {'v', 'V', 'v', 'V'}}, 46 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL
49 {DomCode::KEY_W, {'w', 'W', 0x00E5, 0x00C5}}, 47 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM
50 {DomCode::KEY_X, {'x', 'X', 'x', 'X'}}, 48 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN
51 {DomCode::KEY_Y, {'y', 'Y', 0x00FC, 0x00DC}}, 49 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO
52 {DomCode::KEY_Z, {'z', 'Z', 0x00E6, 0x00C6}}, 50 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP
53 {DomCode::DIGIT1, {'1', '!', 0x00A1, 0x00B9}}, 51 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ
54 {DomCode::DIGIT2, {'2', '@', 0x00B2, DK|0x030B}}, 52 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR
55 {DomCode::DIGIT3, {'3', '#', 0x00B3, DK|0x0304}}, 53 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS
56 {DomCode::DIGIT4, {'4', '$', 0x00A4, 0x00A3}}, 54 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT
57 {DomCode::DIGIT5, {'5', '%', 0x20AC, DK|0x0327}}, 55 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU
58 {DomCode::DIGIT6, {'6', '^', DK|0x0302, 0x00BC}}, 56 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV
59 {DomCode::DIGIT7, {'7', '&', 0x00BD, DK|0x031B}}, 57 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW
60 {DomCode::DIGIT8, {'8', '*', 0x00BE, DK|0x0328}}, 58 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX
61 {DomCode::DIGIT9, {'9', '(', 0x2018, DK|0x0306}}, 59 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY
62 {DomCode::DIGIT0, {'0', ')', 0x2019, DK|0x030A}}, 60 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ
63 {DomCode::SPACE, {' ', ' ', 0x00A0, 0x00A0}}, 61 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1
64 {DomCode::MINUS, {'-', '_', 0x00A5, DK|0x0323}}, 62 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2
65 {DomCode::EQUAL, {'=', '+', 0x00D7, 0x00F7}}, 63 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3
66 {DomCode::BRACKET_LEFT, {'[', '{', 0x00AB, 0x201C}}, 64 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4
67 {DomCode::BRACKET_RIGHT, {']', '}', 0x00BB, 0x201D}}, 65 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5
68 {DomCode::BACKSLASH, {'\\', '|', 0x00AC, 0x00A6}}, 66 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6
69 {DomCode::SEMICOLON, {';', ':', 0x00B6, 0x00B0}}, 67 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7
70 {DomCode::QUOTE, {'\'', '"', DK|0x0301, DK|0x0308}}, 68 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8
71 {DomCode::BACKQUOTE, {'`', '~', DK|0x0300, DK|0x0303}}, 69 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9
72 {DomCode::COMMA, {',', '<', 0x00E7, 0x00C7}}, 70 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0
73 {DomCode::PERIOD, {'.', '>', DK|0x0307, DK|0x030C}}, 71 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter
74 {DomCode::SLASH, {'/', '?', 0x00BF, DK|0x0309}}, 72 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape
75 {DomCode::INTL_BACKSLASH, {'\\', '|', '\\', '|'}}, 73 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace
76 {DomCode::INTL_YEN, {0x00A5, '|', 0x00A5, '|'}}, 74 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab
77 {DomCode::NUMPAD_DIVIDE, {'/', '/', '/', '/'}}, 75 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space
78 {DomCode::NUMPAD_MULTIPLY, {'*', '*', '*', '*'}}, 76 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus
79 {DomCode::NUMPAD_SUBTRACT, {'-', '-', '-', '-'}}, 77 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal
80 {DomCode::NUMPAD_ADD, {'+', '+', '+', '+'}}, 78 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft
81 {DomCode::NUMPAD1, {'1', '1', '1', '1'}}, 79 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight
82 {DomCode::NUMPAD2, {'2', '2', '2', '2'}}, 80 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash
83 {DomCode::NUMPAD3, {'3', '3', '3', '3'}}, 81 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash
84 {DomCode::NUMPAD4, {'4', '4', '4', '4'}}, 82 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon
85 {DomCode::NUMPAD5, {'5', '5', '5', '5'}}, 83 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote
86 {DomCode::NUMPAD6, {'6', '6', '6', '6'}}, 84 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote
87 {DomCode::NUMPAD7, {'7', '7', '7', '7'}}, 85 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma
88 {DomCode::NUMPAD8, {'8', '8', '8', '8'}}, 86 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period
89 {DomCode::NUMPAD9, {'9', '9', '9', '9'}}, 87 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash
90 {DomCode::NUMPAD0, {'0', '0', '0', '0'}}, 88 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock
91 {DomCode::NUMPAD_DECIMAL, {'.', '.', '.', '.'}}, 89 {DomCode::F1, VKEY_F1}, // 0x07003A F1
92 {DomCode::NUMPAD_EQUAL, {'=', '=', '=', '='}}, 90 {DomCode::F2, VKEY_F2}, // 0x07003B F2
93 {DomCode::NUMPAD_COMMA, {',', ',', ',', ','}}, 91 {DomCode::F3, VKEY_F3}, // 0x07003C F3
94 {DomCode::NUMPAD_PAREN_LEFT, {'(', '(', '(', '('}}, 92 {DomCode::F4, VKEY_F4}, // 0x07003D F4
95 {DomCode::NUMPAD_PAREN_RIGHT, {')', ')', ')', ')'}}, 93 {DomCode::F5, VKEY_F5}, // 0x07003E F5
96 {DomCode::NUMPAD_SIGN_CHANGE, {0x00B1, 0x00B1, 0x2213, 0x2213}}, 94 {DomCode::F6, VKEY_F6}, // 0x07003F F6
95 {DomCode::F7, VKEY_F7}, // 0x070040 F7
96 {DomCode::F8, VKEY_F8}, // 0x070041 F8
97 {DomCode::F9, VKEY_F9}, // 0x070042 F9
98 {DomCode::F10, VKEY_F10}, // 0x070043 F10
99 {DomCode::F11, VKEY_F11}, // 0x070044 F11
100 {DomCode::F12, VKEY_F12}, // 0x070045 F12
101 {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen
102 {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock
103 {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause
104 {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert
105 {DomCode::HOME, VKEY_HOME}, // 0x07004A Home
106 {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp
107 {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete
108 {DomCode::END, VKEY_END}, // 0x07004D End
109 {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown
110 {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight
111 {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft
112 {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown
113 {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp
114 {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock
115 {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide
116 {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply
117 {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract
118 {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd
119 {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter
120 {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1
121 {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2
122 {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3
123 {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4
124 {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5
125 {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6
126 {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7
127 {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8
128 {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9
129 {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0
130 {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal
131 {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash
132 {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu
133 {DomCode::POWER, VKEY_POWER}, // 0x070066 Power
134 // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual
135 // DomCode::OPEN 0x070074 Open
136 {DomCode::HELP, VKEY_HELP}, // 0x070075 Help
137 {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select
138 // DomCode::AGAIN 0x070079 Again
139 // DomCode::UNDO 0x07007A Undo
140 // DomCode::CUT 0x07007B Cut
141 // DomCode::COPY 0x07007C Copy
142 // DomCode::PASTE 0x07007D Paste
143 // DomCode::FIND 0x07007E Find
144 {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute
145 {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp
146 {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown
147 {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma
148 {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo
149 {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode
150 {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen
151 {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert
152 {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert
153 {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1
154 {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2
155 // DomCode::LANG3 0x070092 Lang3
156 // DomCode::LANG4 0x070093 Lang4
157 // DomCode::LANG5 0x070094 Lang5
158 // DomCode::ABORT 0x07009B Abort
159 // DomCode::PROPS 0x0700A3 Props
160 // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft
161 // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight
162 {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace
163 // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore
164 // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall
165 // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear
166 // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd
167 // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4
168 // NumpadMemorySubtract
169 {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear
170 {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry
171 {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft
172 {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft
173 {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft
174 {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft
175 {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight
176 {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight
177 {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight
178 {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight
179 {DomCode::MEDIA_TRACK_NEXT,
180 VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext
181 {DomCode::MEDIA_TRACK_PREVIOUS,
182 VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious
183 {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop
184 // DomCode::EJECT 0x0C00B8 Eject
185 {DomCode::MEDIA_PLAY_PAUSE,
186 VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause
187 {DomCode::MEDIA_SELECT,
188 VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect
189 {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail
190 {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2
191 {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1
192 {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch
193 {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome
194 {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack
195 {DomCode::BROWSER_FORWARD,
196 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward
197 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop
198 {DomCode::BROWSER_REFRESH,
199 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh
200 {DomCode::BROWSER_FAVORITES,
201 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites
97 }; 202 };
98 203
99 const struct NonPrintableCodeEntry { 204 } // anonymous namespace
100 DomCode dom_code; 205
101 DomKey dom_key; 206 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
102 base::char16 character; 207 // The returned VKEY is positional (e.g. VKEY_LSHIFT).
103 } non_printable_code_map[] = { 208 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) {
104 {DomCode::ABORT, DomKey::CANCEL}, 209 const DomCodeToKeyboardCodeEntry* end =
105 {DomCode::AGAIN, DomKey::AGAIN}, 210 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code);
106 {DomCode::ALT_LEFT, DomKey::ALT}, 211 const DomCodeToKeyboardCodeEntry* found =
107 {DomCode::ALT_RIGHT, DomKey::ALT}, 212 std::lower_bound(dom_code_to_keyboard_code, end, dom_code,
108 {DomCode::ARROW_DOWN, DomKey::ARROW_DOWN}, 213 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) {
109 {DomCode::ARROW_LEFT, DomKey::ARROW_LEFT}, 214 return static_cast<int>(a.dom_code) < static_cast<int>(b);
110 {DomCode::ARROW_RIGHT, DomKey::ARROW_RIGHT}, 215 });
111 {DomCode::ARROW_UP, DomKey::ARROW_UP}, 216 if ((found != end) && (found->dom_code == dom_code))
112 {DomCode::BACKSPACE, DomKey::BACKSPACE, 0x0008}, 217 return found->key_code;
113 {DomCode::BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN}, 218 return VKEY_UNKNOWN;
114 {DomCode::BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP}, 219 }
115 // {DomCode::BRIGHTNESS_AUTO, DomKey::_} 220
116 // {DomCode::BRIGHTNESS_MAXIMUM, DomKey::_} 221 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|.
117 // {DomCode::BRIGHTNESS_MINIMIUM, DomKey::_} 222 // The returned VKEY is non-positional (e.g. VKEY_SHIFT).
118 // {DomCode::BRIGHTNESS_TOGGLE, DomKey::_} 223 KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) {
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 // TODO(kpschoedel): move this to a shared location.
231 // Map DOM Level 3 .key values to legacy Windows-based VKEY values.
232 // This applies to non-printable keys.
233 KeyboardCode DomKeyToKeyboardCode(DomKey dom_key) {
234 switch (dom_key) { 224 switch (dom_key) {
235 // No value. 225 // No value.
236 case DomKey::NONE: 226 case DomKey::NONE:
237 return VKEY_UNKNOWN; 227 return VKEY_UNKNOWN;
228 // Character values.
238 // Special Key Values 229 // Special Key Values
239 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special 230 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special
240 case DomKey::UNIDENTIFIED: 231 case DomKey::UNIDENTIFIED:
241 return VKEY_UNKNOWN; 232 return VKEY_UNKNOWN;
242 // Modifier Keys 233 // Modifier Keys
243 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier 234 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-modifier
244 case DomKey::ALT: 235 case DomKey::ALT:
245 return VKEY_MENU; 236 return VKEY_MENU;
246 case DomKey::ALT_GRAPH: 237 case DomKey::ALT_GRAPH:
247 return VKEY_ALTGR; 238 return VKEY_ALTGR;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // Device Keys 313 // Device Keys
323 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device 314 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-device
324 case DomKey::BRIGHTNESS_DOWN: 315 case DomKey::BRIGHTNESS_DOWN:
325 return VKEY_BRIGHTNESS_DOWN; 316 return VKEY_BRIGHTNESS_DOWN;
326 case DomKey::BRIGHTNESS_UP: 317 case DomKey::BRIGHTNESS_UP:
327 return VKEY_BRIGHTNESS_UP; 318 return VKEY_BRIGHTNESS_UP;
328 case DomKey::POWER: 319 case DomKey::POWER:
329 return VKEY_POWER; 320 return VKEY_POWER;
330 case DomKey::PRINT_SCREEN: 321 case DomKey::PRINT_SCREEN:
331 return VKEY_SNAPSHOT; 322 return VKEY_SNAPSHOT;
332 // IME and Composition Keys 323 // IME and Composition Keys
333 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition 324 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-composition
334 #if 0 // TODO(kpschoedel) 325 #if 0 // TODO(kpschoedel)
335 case DomKey::COMPOSE: 326 case DomKey::COMPOSE:
336 return VKEY_COMPOSE; 327 return VKEY_COMPOSE;
337 #endif 328 #endif
338 case DomKey::CONVERT: 329 case DomKey::CONVERT:
339 return VKEY_CONVERT; 330 return VKEY_CONVERT;
340 case DomKey::FINAL_MODE: 331 case DomKey::FINAL_MODE:
341 return VKEY_FINAL; 332 return VKEY_FINAL;
342 case DomKey::MODE_CHANGE: 333 case DomKey::MODE_CHANGE:
343 return VKEY_MODECHANGE; 334 return VKEY_MODECHANGE;
344 case DomKey::NON_CONVERT: 335 case DomKey::NON_CONVERT:
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 // Media Controller Keys 451 // Media Controller Keys
461 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller 452 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller
462 case DomKey::ZOOM_TOGGLE: 453 case DomKey::ZOOM_TOGGLE:
463 return VKEY_ZOOM; 454 return VKEY_ZOOM;
464 // No value. 455 // No value.
465 default: 456 default:
466 return VKEY_UNKNOWN; 457 return VKEY_UNKNOWN;
467 } 458 }
468 } 459 }
469 460
470 // TODO(kpschoedel): move this to a shared location. 461 // Determine the non-located VKEY corresponding to a located VKEY.
471 // This table maps DOM Level 3 .code values to legacy Windows-based VKEY 462 ui::KeyboardCode DeLocateKeyboardCode(ui::KeyboardCode key_code) {
472 // values, where the VKEYs are interpreted positionally. 463 switch (key_code) {
473 const struct DomCodeToKeyboardCodeEntry { 464 case VKEY_RWIN:
474 DomCode dom_code; 465 return VKEY_LWIN;
475 KeyboardCode key_code; 466 case VKEY_LSHIFT:
476 } dom_code_to_keyboard_code[] = { 467 case VKEY_RSHIFT:
477 // Entries are ordered by numeric value of the DomCode enum, 468 return VKEY_SHIFT;
478 // which is the USB physical key code. 469 case VKEY_LCONTROL:
479 // DomCode::HYPER 0x000010 Hyper 470 case VKEY_RCONTROL:
480 // DomCode::SUPER 0x000011 Super 471 return VKEY_CONTROL;
481 // DomCode::FN 0x000012 Fn 472 case VKEY_LMENU:
482 // DomCode::FN_LOCK 0x000013 FLock 473 case VKEY_RMENU:
483 // DomCode::SUSPEND 0x000014 Suspend 474 return VKEY_MENU;
484 // DomCode::RESUME 0x000015 Resume 475 default:
485 // DomCode::TURBO 0x000016 Turbo 476 return key_code;
486 {DomCode::SLEEP, VKEY_SLEEP}, // 0x010082 Sleep 477 }
487 // DomCode::WAKE_UP 0x010083 WakeUp
488 {DomCode::KEY_A, VKEY_A}, // 0x070004 KeyA
489 {DomCode::KEY_B, VKEY_B}, // 0x070005 KeyB
490 {DomCode::KEY_C, VKEY_C}, // 0x070006 KeyC
491 {DomCode::KEY_D, VKEY_D}, // 0x070007 KeyD
492 {DomCode::KEY_E, VKEY_E}, // 0x070008 KeyE
493 {DomCode::KEY_F, VKEY_F}, // 0x070009 KeyF
494 {DomCode::KEY_G, VKEY_G}, // 0x07000A KeyG
495 {DomCode::KEY_H, VKEY_H}, // 0x07000B KeyH
496 {DomCode::KEY_I, VKEY_I}, // 0x07000C KeyI
497 {DomCode::KEY_J, VKEY_J}, // 0x07000D KeyJ
498 {DomCode::KEY_K, VKEY_K}, // 0x07000E KeyK
499 {DomCode::KEY_L, VKEY_L}, // 0x07000F KeyL
500 {DomCode::KEY_M, VKEY_M}, // 0x070010 KeyM
501 {DomCode::KEY_N, VKEY_N}, // 0x070011 KeyN
502 {DomCode::KEY_O, VKEY_O}, // 0x070012 KeyO
503 {DomCode::KEY_P, VKEY_P}, // 0x070013 KeyP
504 {DomCode::KEY_Q, VKEY_Q}, // 0x070014 KeyQ
505 {DomCode::KEY_R, VKEY_R}, // 0x070015 KeyR
506 {DomCode::KEY_S, VKEY_S}, // 0x070016 KeyS
507 {DomCode::KEY_T, VKEY_T}, // 0x070017 KeyT
508 {DomCode::KEY_U, VKEY_U}, // 0x070018 KeyU
509 {DomCode::KEY_V, VKEY_V}, // 0x070019 KeyV
510 {DomCode::KEY_W, VKEY_W}, // 0x07001A KeyW
511 {DomCode::KEY_X, VKEY_X}, // 0x07001B KeyX
512 {DomCode::KEY_Y, VKEY_Y}, // 0x07001C KeyY
513 {DomCode::KEY_Z, VKEY_Z}, // 0x07001D KeyZ
514 {DomCode::DIGIT1, VKEY_1}, // 0x07001E Digit1
515 {DomCode::DIGIT2, VKEY_2}, // 0x07001F Digit2
516 {DomCode::DIGIT3, VKEY_3}, // 0x070020 Digit3
517 {DomCode::DIGIT4, VKEY_4}, // 0x070021 Digit4
518 {DomCode::DIGIT5, VKEY_5}, // 0x070022 Digit5
519 {DomCode::DIGIT6, VKEY_6}, // 0x070023 Digit6
520 {DomCode::DIGIT7, VKEY_7}, // 0x070024 Digit7
521 {DomCode::DIGIT8, VKEY_8}, // 0x070025 Digit8
522 {DomCode::DIGIT9, VKEY_9}, // 0x070026 Digit9
523 {DomCode::DIGIT0, VKEY_0}, // 0x070027 Digit0
524 {DomCode::ENTER, VKEY_RETURN}, // 0x070028 Enter
525 {DomCode::ESCAPE, VKEY_ESCAPE}, // 0x070029 Escape
526 {DomCode::BACKSPACE, VKEY_BACK}, // 0x07002A Backspace
527 {DomCode::TAB, VKEY_TAB}, // 0x07002B Tab
528 {DomCode::SPACE, VKEY_SPACE}, // 0x07002C Space
529 {DomCode::MINUS, VKEY_OEM_MINUS}, // 0x07002D Minus
530 {DomCode::EQUAL, VKEY_OEM_PLUS}, // 0x07002E Equal
531 {DomCode::BRACKET_LEFT, VKEY_OEM_4}, // 0x07002F BracketLeft
532 {DomCode::BRACKET_RIGHT, VKEY_OEM_6}, // 0x070030 BracketRight
533 {DomCode::BACKSLASH, VKEY_OEM_5}, // 0x070031 Backslash
534 // DomCode::INTL_HASH, VKEY_OEM_5 // 0x070032 IntlHash
535 {DomCode::SEMICOLON, VKEY_OEM_1}, // 0x070033 Semicolon
536 {DomCode::QUOTE, VKEY_OEM_7}, // 0x070034 Quote
537 {DomCode::BACKQUOTE, VKEY_OEM_3}, // 0x070035 Backquote
538 {DomCode::COMMA, VKEY_OEM_COMMA}, // 0x070036 Comma
539 {DomCode::PERIOD, VKEY_OEM_PERIOD}, // 0x070037 Period
540 {DomCode::SLASH, VKEY_OEM_2}, // 0x070038 Slash
541 {DomCode::CAPS_LOCK, VKEY_CAPITAL}, // 0x070039 CapsLock
542 {DomCode::F1, VKEY_F1}, // 0x07003A F1
543 {DomCode::F2, VKEY_F2}, // 0x07003B F2
544 {DomCode::F3, VKEY_F3}, // 0x07003C F3
545 {DomCode::F4, VKEY_F4}, // 0x07003D F4
546 {DomCode::F5, VKEY_F5}, // 0x07003E F5
547 {DomCode::F6, VKEY_F6}, // 0x07003F F6
548 {DomCode::F7, VKEY_F7}, // 0x070040 F7
549 {DomCode::F8, VKEY_F8}, // 0x070041 F8
550 {DomCode::F9, VKEY_F9}, // 0x070042 F9
551 {DomCode::F10, VKEY_F10}, // 0x070043 F10
552 {DomCode::F11, VKEY_F11}, // 0x070044 F11
553 {DomCode::F12, VKEY_F12}, // 0x070045 F12
554 {DomCode::PRINT_SCREEN, VKEY_SNAPSHOT}, // 0x070046 PrintScreen
555 {DomCode::SCROLL_LOCK, VKEY_SCROLL}, // 0x070047 ScrollLock
556 {DomCode::PAUSE, VKEY_PAUSE}, // 0x070048 Pause
557 {DomCode::INSERT, VKEY_INSERT}, // 0x070049 Insert
558 {DomCode::HOME, VKEY_HOME}, // 0x07004A Home
559 {DomCode::PAGE_UP, VKEY_PRIOR}, // 0x07004B PageUp
560 {DomCode::DEL, VKEY_DELETE}, // 0x07004C Delete
561 {DomCode::END, VKEY_END}, // 0x07004D End
562 {DomCode::PAGE_DOWN, VKEY_NEXT}, // 0x07004E PageDown
563 {DomCode::ARROW_RIGHT, VKEY_RIGHT}, // 0x07004F ArrowRight
564 {DomCode::ARROW_LEFT, VKEY_LEFT}, // 0x070050 ArrowLeft
565 {DomCode::ARROW_DOWN, VKEY_DOWN}, // 0x070051 ArrowDown
566 {DomCode::ARROW_UP, VKEY_UP}, // 0x070052 ArrowUp
567 {DomCode::NUM_LOCK, VKEY_NUMLOCK}, // 0x070053 NumLock
568 {DomCode::NUMPAD_DIVIDE, VKEY_DIVIDE}, // 0x070054 NumpadDivide
569 {DomCode::NUMPAD_MULTIPLY, VKEY_MULTIPLY}, // 0x070055 NumpadMultiply
570 {DomCode::NUMPAD_SUBTRACT, VKEY_SUBTRACT}, // 0x070056 NumpadSubtract
571 {DomCode::NUMPAD_ADD, VKEY_ADD}, // 0x070057 NumpadAdd
572 {DomCode::NUMPAD_ENTER, VKEY_RETURN}, // 0x070058 NumpadEnter
573 {DomCode::NUMPAD1, VKEY_NUMPAD1}, // 0x070059 Numpad1
574 {DomCode::NUMPAD2, VKEY_NUMPAD2}, // 0x07005A Numpad2
575 {DomCode::NUMPAD3, VKEY_NUMPAD3}, // 0x07005B Numpad3
576 {DomCode::NUMPAD4, VKEY_NUMPAD4}, // 0x07005C Numpad4
577 {DomCode::NUMPAD5, VKEY_NUMPAD5}, // 0x07005D Numpad5
578 {DomCode::NUMPAD6, VKEY_NUMPAD6}, // 0x07005E Numpad6
579 {DomCode::NUMPAD7, VKEY_NUMPAD7}, // 0x07005F Numpad7
580 {DomCode::NUMPAD8, VKEY_NUMPAD8}, // 0x070060 Numpad8
581 {DomCode::NUMPAD9, VKEY_NUMPAD9}, // 0x070061 Numpad9
582 {DomCode::NUMPAD0, VKEY_NUMPAD0}, // 0x070062 Numpad0
583 {DomCode::NUMPAD_DECIMAL, VKEY_DECIMAL}, // 0x070063 NumpadDecimal
584 {DomCode::INTL_BACKSLASH, VKEY_OEM_102}, // 0x070064 IntlBackslash
585 {DomCode::CONTEXT_MENU, VKEY_APPS}, // 0x070065 ContextMenu
586 {DomCode::POWER, VKEY_POWER}, // 0x070066 Power
587 // DomCode::NUMPAD_EQUAL 0x070067 NumpadEqual
588 // DomCode::OPEN 0x070074 Open
589 {DomCode::HELP, VKEY_HELP}, // 0x070075 Help
590 {DomCode::SELECT, VKEY_SELECT}, // 0x070077 Select
591 // DomCode::AGAIN 0x070079 Again
592 // DomCode::UNDO 0x07007A Undo
593 // DomCode::CUT 0x07007B Cut
594 // DomCode::COPY 0x07007C Copy
595 // DomCode::PASTE 0x07007D Paste
596 // DomCode::FIND 0x07007E Find
597 {DomCode::VOLUME_MUTE, VKEY_VOLUME_MUTE}, // 0x07007F VolumeMute
598 {DomCode::VOLUME_UP, VKEY_VOLUME_UP}, // 0x070080 VolumeUp
599 {DomCode::VOLUME_DOWN, VKEY_VOLUME_DOWN}, // 0x070081 VolumeDown
600 {DomCode::NUMPAD_COMMA, VKEY_OEM_COMMA}, // 0x070085 NumpadComma
601 {DomCode::INTL_RO, VKEY_OEM_102}, // 0x070087 IntlRo
602 {DomCode::KANA_MODE, VKEY_KANA}, // 0x070088 KanaMode
603 {DomCode::INTL_YEN, VKEY_OEM_5}, // 0x070089 IntlYen
604 {DomCode::CONVERT, VKEY_CONVERT}, // 0x07008A Convert
605 {DomCode::NON_CONVERT, VKEY_NONCONVERT}, // 0x07008B NonConvert
606 {DomCode::LANG1, VKEY_KANA}, // 0x070090 Lang1
607 {DomCode::LANG2, VKEY_KANJI}, // 0x070091 Lang2
608 // DomCode::LANG3 0x070092 Lang3
609 // DomCode::LANG4 0x070093 Lang4
610 // DomCode::LANG5 0x070094 Lang5
611 // DomCode::ABORT 0x07009B Abort
612 // DomCode::PROPS 0x0700A3 Props
613 // DomCode::NUMPAD_PAREN_LEFT 0x0700B6 NumpadParenLeft
614 // DomCode::NUMPAD_PAREN_RIGHT 0x0700B7 NumpadParenRight
615 {DomCode::NUMPAD_BACKSPACE, VKEY_BACK}, // 0x0700BB NumpadBackspace
616 // DomCode::NUMPAD_MEMORY_STORE 0x0700D0 NumpadMemoryStore
617 // DomCode::NUMPAD_MEMORY_RECALL 0x0700D1 NumpadMemoryRecall
618 // DomCode::NUMPAD_MEMORY_CLEAR 0x0700D2 NumpadMemoryClear
619 // DomCode::NUMPAD_MEMORY_ADD 0x0700D3 NumpadMemoryAdd
620 // DomCode::NUMPAD_MEMORY_SUBTRACT 0x0700D4
621 // NumpadMemorySubtract
622 {DomCode::NUMPAD_CLEAR, VKEY_CLEAR}, // 0x0700D8 NumpadClear
623 {DomCode::NUMPAD_CLEAR_ENTRY, VKEY_CLEAR}, // 0x0700D9 NumpadClearEntry
624 {DomCode::CONTROL_LEFT, VKEY_LCONTROL}, // 0x0700E0 ControlLeft
625 {DomCode::SHIFT_LEFT, VKEY_LSHIFT}, // 0x0700E1 ShiftLeft
626 {DomCode::ALT_LEFT, VKEY_LMENU}, // 0x0700E2 AltLeft
627 {DomCode::OS_LEFT, VKEY_LWIN}, // 0x0700E3 OSLeft
628 {DomCode::CONTROL_RIGHT, VKEY_RCONTROL}, // 0x0700E4 ControlRight
629 {DomCode::SHIFT_RIGHT, VKEY_RSHIFT}, // 0x0700E5 ShiftRight
630 {DomCode::ALT_RIGHT, VKEY_RMENU}, // 0x0700E6 AltRight
631 {DomCode::OS_RIGHT, VKEY_RWIN}, // 0x0700E7 OSRight
632 {DomCode::MEDIA_TRACK_NEXT,
633 VKEY_MEDIA_NEXT_TRACK}, // 0x0C00B5 MediaTrackNext
634 {DomCode::MEDIA_TRACK_PREVIOUS,
635 VKEY_MEDIA_PREV_TRACK}, // 0x0C00B6 MediaTrackPrevious
636 {DomCode::MEDIA_STOP, VKEY_MEDIA_STOP}, // 0x0C00B7 MediaStop
637 // DomCode::EJECT 0x0C00B8 Eject
638 {DomCode::MEDIA_PLAY_PAUSE,
639 VKEY_MEDIA_PLAY_PAUSE}, // 0x0C00CD MediaPlayPause
640 {DomCode::MEDIA_SELECT,
641 VKEY_MEDIA_LAUNCH_MEDIA_SELECT}, // 0x0C0183 MediaSelect
642 {DomCode::LAUNCH_MAIL, VKEY_MEDIA_LAUNCH_MAIL}, // 0x0C018A LaunchMail
643 {DomCode::LAUNCH_APP2, VKEY_MEDIA_LAUNCH_APP2}, // 0x0C0192 LaunchApp2
644 {DomCode::LAUNCH_APP1, VKEY_MEDIA_LAUNCH_APP1}, // 0x0C0194 LaunchApp1
645 {DomCode::BROWSER_SEARCH, VKEY_BROWSER_SEARCH}, // 0x0C0221 BrowserSearch
646 {DomCode::BROWSER_HOME, VKEY_BROWSER_HOME}, // 0x0C0223 BrowserHome
647 {DomCode::BROWSER_BACK, VKEY_BROWSER_BACK}, // 0x0C0224 BrowserBack
648 {DomCode::BROWSER_FORWARD,
649 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward
650 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop
651 {DomCode::BROWSER_REFRESH,
652 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh
653 {DomCode::BROWSER_FAVORITES,
654 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites
655 };
656
657 // TODO(kpschoedel): move this to a shared location.
658 // Map DOM Level 3 .code values to legacy Windows-based VKEY values,
659 // where the VKEYs are interpreted positionally.
660 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) {
661 const DomCodeToKeyboardCodeEntry* end =
662 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code);
663 const DomCodeToKeyboardCodeEntry* found =
664 std::lower_bound(dom_code_to_keyboard_code, end, dom_code,
665 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) {
666 return static_cast<int>(a.dom_code) < static_cast<int>(b);
667 });
668 if ((found != end) && (found->dom_code == dom_code))
669 return found->key_code;
670 return VKEY_UNKNOWN;
671 } 478 }
672 479
673 // TODO(kpschoedel): move this to a shared location. 480 bool LookupControlCharacter(DomCode dom_code,
674 bool ControlCharacter(DomCode dom_code, 481 int flags,
675 DomKey* dom_key, 482 DomKey* dom_key,
676 base::char16* character) { 483 base::char16* character,
484 KeyboardCode* key_code) {
485 if ((flags & EF_CONTROL_DOWN) == 0)
486 return false;
487
677 int code = static_cast<int>(dom_code); 488 int code = static_cast<int>(dom_code);
678 const int kKeyA = static_cast<int>(DomCode::KEY_A); 489 const int kKeyA = static_cast<int>(DomCode::KEY_A);
679 // Control-A - Control-Z map to 0x01 - 0x1A. 490 // Control-A - Control-Z map to 0x01 - 0x1A.
680 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) { 491 if (code >= kKeyA && code <= static_cast<int>(DomCode::KEY_Z)) {
681 *character = static_cast<base::char16>(code - kKeyA + 1); 492 *character = static_cast<base::char16>(code - kKeyA + 1);
493 *key_code = static_cast<KeyboardCode>(code - kKeyA + VKEY_A);
682 switch (dom_code) { 494 switch (dom_code) {
683 case DomCode::KEY_H: 495 case DomCode::KEY_H:
684 *dom_key = DomKey::BACKSPACE; 496 *dom_key = DomKey::BACKSPACE;
685 case DomCode::KEY_I: 497 case DomCode::KEY_I:
686 *dom_key = DomKey::TAB; 498 *dom_key = DomKey::TAB;
687 case DomCode::KEY_M: 499 case DomCode::KEY_M:
688 *dom_key = DomKey::ENTER; 500 *dom_key = DomKey::ENTER;
689 default: 501 default:
690 *dom_key = DomKey::CHARACTER; 502 *dom_key = DomKey::CHARACTER;
691 } 503 }
692 return true; 504 return true;
693 } 505 }
506
694 switch (dom_code) { 507 switch (dom_code) {
695 case DomCode::DIGIT2: 508 case DomCode::DIGIT2:
696 // NUL 509 // NUL
697 *character = 0; 510 *character = 0;
698 *dom_key = DomKey::CHARACTER; 511 *dom_key = DomKey::CHARACTER;
512 *key_code = VKEY_2;
699 return true; 513 return true;
700 case DomCode::ENTER: 514 case DomCode::ENTER:
701 // NL 515 // NL
702 *character = 0x0A; 516 *character = 0x0A;
703 *dom_key = DomKey::CHARACTER; 517 *dom_key = DomKey::CHARACTER;
518 *key_code = VKEY_RETURN;
704 return true; 519 return true;
705 case DomCode::BRACKET_LEFT: 520 case DomCode::BRACKET_LEFT:
706 // ESC 521 // ESC
707 *character = 0x1B; 522 *character = 0x1B;
708 *dom_key = DomKey::ESCAPE; 523 *dom_key = DomKey::ESCAPE;
524 *key_code = VKEY_OEM_4;
709 return true; 525 return true;
710 case DomCode::BACKSLASH: 526 case DomCode::BACKSLASH:
711 // FS 527 // FS
712 *character = 0x1C; 528 *character = 0x1C;
713 *dom_key = DomKey::CHARACTER; 529 *dom_key = DomKey::CHARACTER;
530 *key_code = VKEY_OEM_5;
714 return true; 531 return true;
715 case DomCode::BRACKET_RIGHT: 532 case DomCode::BRACKET_RIGHT:
716 // GS 533 // GS
717 *character = 0x1D; 534 *character = 0x1D;
718 *dom_key = DomKey::CHARACTER; 535 *dom_key = DomKey::CHARACTER;
536 *key_code = VKEY_OEM_6;
719 return true; 537 return true;
720 case DomCode::DIGIT6: 538 case DomCode::DIGIT6:
721 // RS 539 // RS
722 *character = 0x1E; 540 *character = 0x1E;
723 *dom_key = DomKey::CHARACTER; 541 *dom_key = DomKey::CHARACTER;
542 *key_code = VKEY_6;
724 return true; 543 return true;
725 case DomCode::MINUS: 544 case DomCode::MINUS:
726 // US 545 // US
727 *character = 0x1F; 546 *character = 0x1F;
728 *dom_key = DomKey::CHARACTER; 547 *dom_key = DomKey::CHARACTER;
548 *key_code = VKEY_OEM_MINUS;
729 return true; 549 return true;
730 default: 550 default:
731 return false; 551 return false;
732 } 552 }
733 } 553 }
734 554
735 } // anonymous namespace
736
737 StubKeyboardLayoutEngine::StubKeyboardLayoutEngine() {
738 }
739
740 StubKeyboardLayoutEngine::~StubKeyboardLayoutEngine() {
741 }
742
743 bool StubKeyboardLayoutEngine::CanSetCurrentLayout() const {
744 return false;
745 }
746
747 bool StubKeyboardLayoutEngine::SetCurrentLayoutByName(
748 const std::string& layout_name) {
749 return false;
750 }
751
752 bool StubKeyboardLayoutEngine::UsesISOLevel5Shift() const {
753 return false;
754 }
755
756 bool StubKeyboardLayoutEngine::UsesAltGr() const {
757 return true;
758 }
759
760 bool StubKeyboardLayoutEngine::Lookup(DomCode dom_code,
761 int flags,
762 DomKey* out_dom_key,
763 base::char16* out_character,
764 KeyboardCode* out_key_code) const {
765 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) {
766 if (ControlCharacter(dom_code, out_dom_key, out_character)) {
767 *out_key_code = DomCodeToKeyboardCode(dom_code);
768 return true;
769 }
770 } else {
771 for (size_t i = 0; i < arraysize(printable_code_map); ++i) {
772 const PrintableCodeEntry* e = &printable_code_map[i];
773 if (e->dom_code == dom_code) {
774 int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) |
775 ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN);
776 base::char16 ch = e->character[state];
777 *out_dom_key = (ch & DK) ? DomKey::DEAD : DomKey::CHARACTER;
778 *out_character = ch;
779 if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) {
780 ch = (ch & ~DK) | 0x20;
781 if ((ch >= 'a') && (ch <= 'z'))
782 *out_character = e->character[state ^ 1];
783 }
784 *out_key_code = DomCodeToKeyboardCode(dom_code);
785 return true;
786 }
787 }
788 }
789
790 for (size_t i = 0; i < arraysize(non_printable_code_map); ++i) {
791 const NonPrintableCodeEntry* e = &non_printable_code_map[i];
792 if (e->dom_code == dom_code) {
793 *out_dom_key = e->dom_key;
794 *out_character = e->character;
795 *out_key_code = DomKeyToKeyboardCode(e->dom_key);
796 return true;
797 }
798 }
799
800 return false;
801 }
802
803 } // namespace ui 555 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/layout/layout_util.h ('k') | ui/events/ozone/layout/stub/stub_keyboard_layout_engine.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698