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

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

Issue 841263005: Use DOM- rather than Windows-based key code for non-layout cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments (sadrul) Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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/stub/stub_keyboard_layout_engine.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "ui/events/event.h" 10 #include "ui/events/event.h"
11 #include "ui/events/keycodes/dom3/dom_code.h" 11 #include "ui/events/keycodes/dom3/dom_code.h"
12 #include "ui/events/keycodes/dom3/dom_key.h" 12 #include "ui/events/keycodes/dom3/dom_key.h"
13 #include "ui/events/keycodes/keyboard_code_conversion.h" 13 #include "ui/events/keycodes/keyboard_code_conversion.h"
14 #include "ui/events/ozone/layout/layout_util.h" 14 #include "ui/events/ozone/layout/layout_util.h"
15 15
16 namespace ui { 16 namespace ui {
17 17
18 namespace {
19
20 // All of the characters have low ordinals, so we use bit 15 to flag dead keys.
21 #define DK 0x8000
22
23 const struct PrintableCodeEntry {
24 DomCode dom_code;
25 base::char16 character[4];
26 } printable_code_map[] = {
27 // Stub table based on X US international.
28 {DomCode::KEY_A, {'a', 'A', 0x00E1, 0x00C1}},
29 {DomCode::KEY_B, {'b', 'B', 'b', 'B'}},
30 {DomCode::KEY_C, {'c', 'C', 0x00A9, 0x00A2}},
31 {DomCode::KEY_D, {'d', 'D', 0x00F0, 0x00D0}},
32 {DomCode::KEY_E, {'e', 'E', 0x00E9, 0x00C9}},
33 {DomCode::KEY_F, {'f', 'F', 'f', 'F'}},
34 {DomCode::KEY_G, {'g', 'G', 'g', 'G'}},
35 {DomCode::KEY_H, {'h', 'H', 'h', 'H'}},
36 {DomCode::KEY_I, {'i', 'I', 0x00ED, 0x00CD}},
37 {DomCode::KEY_J, {'j', 'J', 'j', 'J'}},
38 {DomCode::KEY_K, {'k', 'K', 0x0153, 0x0152}},
39 {DomCode::KEY_L, {'l', 'L', 0x00F8, 0x00D8}},
40 {DomCode::KEY_M, {'m', 'M', 0x00B5, 0x00B5}},
41 {DomCode::KEY_N, {'n', 'N', 0x00F1, 0x00D1}},
42 {DomCode::KEY_O, {'o', 'O', 0x00F3, 0x00D3}},
43 {DomCode::KEY_P, {'p', 'P', 0x00F6, 0x00D6}},
44 {DomCode::KEY_Q, {'q', 'Q', 0x00E4, 0x00C4}},
45 {DomCode::KEY_R, {'r', 'R', 0x00AE, 0x00AE}},
46 {DomCode::KEY_S, {'s', 'S', 0x00DF, 0x00A7}},
47 {DomCode::KEY_T, {'t', 'T', 0x00FE, 0x00DE}},
48 {DomCode::KEY_U, {'u', 'U', 0x00FA, 0x00DA}},
49 {DomCode::KEY_V, {'v', 'V', 'v', 'V'}},
50 {DomCode::KEY_W, {'w', 'W', 0x00E5, 0x00C5}},
51 {DomCode::KEY_X, {'x', 'X', 'x', 'X'}},
52 {DomCode::KEY_Y, {'y', 'Y', 0x00FC, 0x00DC}},
53 {DomCode::KEY_Z, {'z', 'Z', 0x00E6, 0x00C6}},
54 {DomCode::DIGIT1, {'1', '!', 0x00A1, 0x00B9}},
55 {DomCode::DIGIT2, {'2', '@', 0x00B2, DK|0x030B}},
56 {DomCode::DIGIT3, {'3', '#', 0x00B3, DK|0x0304}},
57 {DomCode::DIGIT4, {'4', '$', 0x00A4, 0x00A3}},
58 {DomCode::DIGIT5, {'5', '%', 0x20AC, DK|0x0327}},
59 {DomCode::DIGIT6, {'6', '^', DK|0x0302, 0x00BC}},
60 {DomCode::DIGIT7, {'7', '&', 0x00BD, DK|0x031B}},
61 {DomCode::DIGIT8, {'8', '*', 0x00BE, DK|0x0328}},
62 {DomCode::DIGIT9, {'9', '(', 0x2018, DK|0x0306}},
63 {DomCode::DIGIT0, {'0', ')', 0x2019, DK|0x030A}},
64 {DomCode::SPACE, {' ', ' ', 0x00A0, 0x00A0}},
65 {DomCode::MINUS, {'-', '_', 0x00A5, DK|0x0323}},
66 {DomCode::EQUAL, {'=', '+', 0x00D7, 0x00F7}},
67 {DomCode::BRACKET_LEFT, {'[', '{', 0x00AB, 0x201C}},
68 {DomCode::BRACKET_RIGHT, {']', '}', 0x00BB, 0x201D}},
69 {DomCode::BACKSLASH, {'\\', '|', 0x00AC, 0x00A6}},
70 {DomCode::SEMICOLON, {';', ':', 0x00B6, 0x00B0}},
71 {DomCode::QUOTE, {'\'', '"', DK|0x0301, DK|0x0308}},
72 {DomCode::BACKQUOTE, {'`', '~', DK|0x0300, DK|0x0303}},
73 {DomCode::COMMA, {',', '<', 0x00E7, 0x00C7}},
74 {DomCode::PERIOD, {'.', '>', DK|0x0307, DK|0x030C}},
75 {DomCode::SLASH, {'/', '?', 0x00BF, DK|0x0309}},
76 {DomCode::INTL_BACKSLASH, {'\\', '|', '\\', '|'}},
77 {DomCode::INTL_YEN, {0x00A5, '|', 0x00A5, '|'}},
78 {DomCode::NUMPAD_DIVIDE, {'/', '/', '/', '/'}},
79 {DomCode::NUMPAD_MULTIPLY, {'*', '*', '*', '*'}},
80 {DomCode::NUMPAD_SUBTRACT, {'-', '-', '-', '-'}},
81 {DomCode::NUMPAD_ADD, {'+', '+', '+', '+'}},
82 {DomCode::NUMPAD1, {'1', '1', '1', '1'}},
83 {DomCode::NUMPAD2, {'2', '2', '2', '2'}},
84 {DomCode::NUMPAD3, {'3', '3', '3', '3'}},
85 {DomCode::NUMPAD4, {'4', '4', '4', '4'}},
86 {DomCode::NUMPAD5, {'5', '5', '5', '5'}},
87 {DomCode::NUMPAD6, {'6', '6', '6', '6'}},
88 {DomCode::NUMPAD7, {'7', '7', '7', '7'}},
89 {DomCode::NUMPAD8, {'8', '8', '8', '8'}},
90 {DomCode::NUMPAD9, {'9', '9', '9', '9'}},
91 {DomCode::NUMPAD0, {'0', '0', '0', '0'}},
92 {DomCode::NUMPAD_DECIMAL, {'.', '.', '.', '.'}},
93 {DomCode::NUMPAD_EQUAL, {'=', '=', '=', '='}},
94 {DomCode::NUMPAD_COMMA, {',', ',', ',', ','}},
95 {DomCode::NUMPAD_PAREN_LEFT, {'(', '(', '(', '('}},
96 {DomCode::NUMPAD_PAREN_RIGHT, {')', ')', ')', ')'}},
97 {DomCode::NUMPAD_SIGN_CHANGE, {0x00B1, 0x00B1, 0x2213, 0x2213}},
98 };
99
100 const struct NonPrintableCodeEntry {
101 DomCode dom_code;
102 DomKey dom_key;
103 base::char16 character;
104 } non_printable_code_map[] = {
105 {DomCode::ABORT, DomKey::CANCEL},
106 {DomCode::AGAIN, DomKey::AGAIN},
107 {DomCode::ALT_LEFT, DomKey::ALT},
108 {DomCode::ALT_RIGHT, DomKey::ALT},
109 {DomCode::ARROW_DOWN, DomKey::ARROW_DOWN},
110 {DomCode::ARROW_LEFT, DomKey::ARROW_LEFT},
111 {DomCode::ARROW_RIGHT, DomKey::ARROW_RIGHT},
112 {DomCode::ARROW_UP, DomKey::ARROW_UP},
113 {DomCode::BACKSPACE, DomKey::BACKSPACE, 0x0008},
114 {DomCode::BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN},
115 {DomCode::BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP},
116 // {DomCode::BRIGHTNESS_AUTO, DomKey::_}
117 // {DomCode::BRIGHTNESS_MAXIMUM, DomKey::_}
118 // {DomCode::BRIGHTNESS_MINIMIUM, DomKey::_}
119 // {DomCode::BRIGHTNESS_TOGGLE, DomKey::_}
120 {DomCode::BROWSER_BACK, DomKey::BROWSER_BACK},
121 {DomCode::BROWSER_FAVORITES, DomKey::BROWSER_FAVORITES},
122 {DomCode::BROWSER_FORWARD, DomKey::BROWSER_FORWARD},
123 {DomCode::BROWSER_HOME, DomKey::BROWSER_HOME},
124 {DomCode::BROWSER_REFRESH, DomKey::BROWSER_REFRESH},
125 {DomCode::BROWSER_SEARCH, DomKey::BROWSER_SEARCH},
126 {DomCode::BROWSER_STOP, DomKey::BROWSER_STOP},
127 {DomCode::CAPS_LOCK, DomKey::CAPS_LOCK},
128 {DomCode::CONTEXT_MENU, DomKey::CONTEXT_MENU},
129 {DomCode::CONTROL_LEFT, DomKey::CONTROL},
130 {DomCode::CONTROL_RIGHT, DomKey::CONTROL},
131 {DomCode::CONVERT, DomKey::CONVERT},
132 {DomCode::COPY, DomKey::COPY},
133 {DomCode::CUT, DomKey::CUT},
134 {DomCode::DEL, DomKey::DEL, 0x007F},
135 {DomCode::EJECT, DomKey::EJECT},
136 {DomCode::END, DomKey::END},
137 {DomCode::ENTER, DomKey::ENTER, 0x000D},
138 {DomCode::ESCAPE, DomKey::ESCAPE, 0x001B},
139 {DomCode::F1, DomKey::F1},
140 {DomCode::F2, DomKey::F2},
141 {DomCode::F3, DomKey::F3},
142 {DomCode::F4, DomKey::F4},
143 {DomCode::F5, DomKey::F5},
144 {DomCode::F6, DomKey::F6},
145 {DomCode::F7, DomKey::F7},
146 {DomCode::F8, DomKey::F8},
147 {DomCode::F9, DomKey::F9},
148 {DomCode::F10, DomKey::F10},
149 {DomCode::F11, DomKey::F11},
150 {DomCode::F12, DomKey::F12},
151 {DomCode::F13, DomKey::F13},
152 {DomCode::F14, DomKey::F14},
153 {DomCode::F15, DomKey::F15},
154 {DomCode::F16, DomKey::F16},
155 {DomCode::F17, DomKey::F17},
156 {DomCode::F18, DomKey::F18},
157 {DomCode::F19, DomKey::F19},
158 {DomCode::F20, DomKey::F20},
159 {DomCode::F21, DomKey::F21},
160 {DomCode::F22, DomKey::F22},
161 {DomCode::F23, DomKey::F23},
162 {DomCode::F24, DomKey::F24},
163 {DomCode::FIND, DomKey::FIND},
164 {DomCode::FN, DomKey::FN},
165 {DomCode::FN_LOCK, DomKey::FN_LOCK},
166 {DomCode::HELP, DomKey::HELP},
167 {DomCode::HOME, DomKey::HOME},
168 {DomCode::HYPER, DomKey::HYPER},
169 {DomCode::INSERT, DomKey::INSERT},
170 // {DomCode::INTL_RO, DomKey::_}
171 {DomCode::KANA_MODE, DomKey::KANA_MODE},
172 {DomCode::LANG1, DomKey::HANGUL_MODE},
173 {DomCode::LANG2, DomKey::HANJA_MODE},
174 {DomCode::LANG3, DomKey::KATAKANA},
175 {DomCode::LANG4, DomKey::HIRAGANA},
176 {DomCode::LANG5, DomKey::ZENKAKU_HANKAKU},
177 {DomCode::LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER},
178 {DomCode::LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR},
179 {DomCode::LAUNCH_MAIL, DomKey::LAUNCH_MAIL},
180 {DomCode::LAUNCH_SCREEN_SAVER, DomKey::LAUNCH_SCREEN_SAVER},
181 // {DomCode::LAUNCH_DOCUMENTS, DomKey::_}
182 // {DomCode::LAUNCH_FILE_BROWSER, DomKey::_}
183 // {DomCode::LAUNCH_KEYBOARD_LAYOUT, DomKey::_}
184 {DomCode::LOCK_SCREEN, DomKey::LAUNCH_SCREEN_SAVER},
185 {DomCode::MAIL_FORWARD, DomKey::MAIL_FORWARD},
186 {DomCode::MAIL_REPLY, DomKey::MAIL_REPLY},
187 {DomCode::MAIL_SEND, DomKey::MAIL_SEND},
188 {DomCode::MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE},
189 {DomCode::MEDIA_SELECT, DomKey::MEDIA_SELECT},
190 {DomCode::MEDIA_STOP, DomKey::MEDIA_STOP},
191 {DomCode::MEDIA_TRACK_NEXT, DomKey::MEDIA_TRACK_NEXT},
192 {DomCode::MEDIA_TRACK_PREVIOUS, DomKey::MEDIA_TRACK_PREVIOUS},
193 // {DomCode::MENU, DomKey::_}
194 {DomCode::NON_CONVERT, DomKey::NON_CONVERT},
195 {DomCode::NUM_LOCK, DomKey::NUM_LOCK},
196 {DomCode::NUMPAD_BACKSPACE, DomKey::BACKSPACE, 0x0008},
197 {DomCode::NUMPAD_CLEAR, DomKey::CLEAR},
198 {DomCode::NUMPAD_ENTER, DomKey::ENTER, 0x000D},
199 // {DomCode::NUMPAD_CLEAR_ENTRY, DomKey::_}
200 // {DomCode::NUMPAD_MEMORY_ADD, DomKey::_}
201 // {DomCode::NUMPAD_MEMORY_CLEAR, DomKey::_}
202 // {DomCode::NUMPAD_MEMORY_RECALL, DomKey::_}
203 // {DomCode::NUMPAD_MEMORY_STORE, DomKey::_}
204 // {DomCode::NUMPAD_MEMORY_SUBTRACT, DomKey::_}
205 {DomCode::OPEN, DomKey::OPEN},
206 {DomCode::OS_LEFT, DomKey::OS},
207 {DomCode::OS_RIGHT, DomKey::OS},
208 {DomCode::PAGE_DOWN, DomKey::PAGE_DOWN},
209 {DomCode::PAGE_UP, DomKey::PAGE_UP},
210 {DomCode::PASTE, DomKey::PASTE},
211 {DomCode::PAUSE, DomKey::PAUSE},
212 {DomCode::POWER, DomKey::POWER},
213 {DomCode::PRINT_SCREEN, DomKey::PRINT_SCREEN},
214 {DomCode::PROPS, DomKey::PROPS},
215 {DomCode::SCROLL_LOCK, DomKey::SCROLL_LOCK},
216 {DomCode::SELECT, DomKey::SELECT},
217 // {DomCode::SELECT_TASK, DomKey::_}
218 {DomCode::SHIFT_LEFT, DomKey::SHIFT},
219 {DomCode::SHIFT_RIGHT, DomKey::SHIFT},
220 {DomCode::SUPER, DomKey::SUPER},
221 {DomCode::TAB, DomKey::TAB, 0x0009},
222 {DomCode::UNDO, DomKey::UNDO},
223 // {DomCode::VOICE_COMMAND, DomKey::_}
224 {DomCode::VOLUME_DOWN, DomKey::VOLUME_DOWN},
225 {DomCode::VOLUME_MUTE, DomKey::VOLUME_MUTE},
226 {DomCode::VOLUME_UP, DomKey::VOLUME_UP},
227 {DomCode::WAKE_UP, DomKey::WAKE_UP},
228 {DomCode::ZOOM_TOGGLE, DomKey::ZOOM_TOGGLE},
229 };
230
231 } // anonymous namespace
232
233 StubKeyboardLayoutEngine::StubKeyboardLayoutEngine() { 18 StubKeyboardLayoutEngine::StubKeyboardLayoutEngine() {
234 } 19 }
235 20
236 StubKeyboardLayoutEngine::~StubKeyboardLayoutEngine() { 21 StubKeyboardLayoutEngine::~StubKeyboardLayoutEngine() {
237 } 22 }
238 23
239 bool StubKeyboardLayoutEngine::CanSetCurrentLayout() const { 24 bool StubKeyboardLayoutEngine::CanSetCurrentLayout() const {
240 return false; 25 return false;
241 } 26 }
242 27
243 bool StubKeyboardLayoutEngine::SetCurrentLayoutByName( 28 bool StubKeyboardLayoutEngine::SetCurrentLayoutByName(
244 const std::string& layout_name) { 29 const std::string& layout_name) {
245 return false; 30 return false;
246 } 31 }
247 32
248 bool StubKeyboardLayoutEngine::UsesISOLevel5Shift() const { 33 bool StubKeyboardLayoutEngine::UsesISOLevel5Shift() const {
249 return false; 34 return false;
250 } 35 }
251 36
252 bool StubKeyboardLayoutEngine::UsesAltGr() const { 37 bool StubKeyboardLayoutEngine::UsesAltGr() const {
253 return true; 38 return true;
254 } 39 }
255 40
256 bool StubKeyboardLayoutEngine::Lookup(DomCode dom_code, 41 bool StubKeyboardLayoutEngine::Lookup(DomCode dom_code,
257 int flags, 42 int flags,
258 DomKey* out_dom_key, 43 DomKey* out_dom_key,
259 base::char16* out_character, 44 base::char16* out_character,
260 KeyboardCode* out_key_code, 45 KeyboardCode* out_key_code,
261 uint32* platform_keycode) const { 46 uint32* platform_keycode) const {
262 if ((flags & EF_CONTROL_DOWN) == EF_CONTROL_DOWN) { 47 return DomCodeToUsLayoutMeaning(dom_code, flags, out_dom_key, out_character,
263 if (LookupControlCharacter(dom_code, flags, out_dom_key, out_character, 48 out_key_code);
264 out_key_code)) {
265 return true;
266 }
267 } else {
268 for (size_t i = 0; i < arraysize(printable_code_map); ++i) {
269 const PrintableCodeEntry* e = &printable_code_map[i];
270 if (e->dom_code == dom_code) {
271 int state = (((flags & EF_ALTGR_DOWN) == EF_ALTGR_DOWN) << 1) |
272 ((flags & EF_SHIFT_DOWN) == EF_SHIFT_DOWN);
273 base::char16 ch = e->character[state];
274 *out_dom_key = (ch & DK) ? DomKey::DEAD : DomKey::CHARACTER;
275 *out_character = ch;
276 if ((flags & EF_CAPS_LOCK_DOWN) == EF_CAPS_LOCK_DOWN) {
277 ch = (ch & ~DK) | 0x20;
278 if ((ch >= 'a') && (ch <= 'z'))
279 *out_character = e->character[state ^ 1];
280 }
281 *out_key_code = DomCodeToNonLocatedKeyboardCode(dom_code);
282 return true;
283 }
284 }
285 }
286
287 for (size_t i = 0; i < arraysize(non_printable_code_map); ++i) {
288 const NonPrintableCodeEntry* e = &non_printable_code_map[i];
289 if (e->dom_code == dom_code) {
290 *out_dom_key = e->dom_key;
291 *out_character = e->character;
292 *out_key_code = NonPrintableDomKeyToKeyboardCode(e->dom_key);
293 return true;
294 }
295 }
296
297 return false;
298 } 49 }
299 50
300 } // namespace ui 51 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698