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

Side by Side Diff: ui/events/keycodes/platform_key_map_win.cc

Issue 2046193002: [DomKey] Expose Korean special keys on Korean keyboard layout only (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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/keycodes/platform_key_map_win.h" 5 #include "ui/events/keycodes/platform_key_map_win.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 {VKEY_MEDIA_STOP, DomKey::MEDIA_STOP}, 236 {VKEY_MEDIA_STOP, DomKey::MEDIA_STOP},
237 {VKEY_MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE}, 237 {VKEY_MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE},
238 {VKEY_MEDIA_LAUNCH_MAIL, DomKey::LAUNCH_MAIL}, 238 {VKEY_MEDIA_LAUNCH_MAIL, DomKey::LAUNCH_MAIL},
239 {VKEY_MEDIA_LAUNCH_MEDIA_SELECT, DomKey::LAUNCH_MEDIA_PLAYER}, 239 {VKEY_MEDIA_LAUNCH_MEDIA_SELECT, DomKey::LAUNCH_MEDIA_PLAYER},
240 {VKEY_MEDIA_LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER}, 240 {VKEY_MEDIA_LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER},
241 {VKEY_MEDIA_LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR}, 241 {VKEY_MEDIA_LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR},
242 // VKEY_OEM_1..8, 102, PLUS, COMMA, MINUS, PERIOD 242 // VKEY_OEM_1..8, 102, PLUS, COMMA, MINUS, PERIOD
243 {VKEY_ALTGR, DomKey::ALT_GRAPH}, 243 {VKEY_ALTGR, DomKey::ALT_GRAPH},
244 {VKEY_PROCESSKEY, DomKey::PROCESS}, 244 {VKEY_PROCESSKEY, DomKey::PROCESS},
245 // VKEY_PACKET - Used to pass Unicode char, considered as printable key. 245 // VKEY_PACKET - Used to pass Unicode char, considered as printable key.
246
247 // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5.
248 // https://crbug.com/612694
249 {VKEY_ATTN, DomKey::ATTN}, 246 {VKEY_ATTN, DomKey::ATTN},
250 {VKEY_CRSEL, DomKey::CR_SEL}, 247 {VKEY_CRSEL, DomKey::CR_SEL},
251 {VKEY_EXSEL, DomKey::EX_SEL}, 248 {VKEY_EXSEL, DomKey::EX_SEL},
252 {VKEY_EREOF, DomKey::ERASE_EOF}, 249 {VKEY_EREOF, DomKey::ERASE_EOF},
253 {VKEY_PLAY, DomKey::PLAY}, 250 {VKEY_PLAY, DomKey::PLAY},
254 {VKEY_ZOOM, DomKey::ZOOM_TOGGLE}, 251 {VKEY_ZOOM, DomKey::ZOOM_TOGGLE},
255 // TODO(chongz): Handle VKEY_NONAME, VKEY_PA1. 252 // TODO(chongz): Handle VKEY_NONAME, VKEY_PA1.
256 // https://crbug.com/616910 253 // https://crbug.com/616910
257 {VKEY_OEM_CLEAR, DomKey::CLEAR}, 254 {VKEY_OEM_CLEAR, DomKey::CLEAR},
258 }; 255 };
259 256
260 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code) { 257 DomKey LangSpecificNonPrintableKeyboardCodeToDomKey(KeyboardCode key_code,
258 HKL layout) {
Wez 2016/06/10 22:55:09 nit: I'd suggest calling this LanguageSpecificOemK
chongz 2016/06/14 20:41:47 Done.
259 WORD langID = LOWORD(layout);
Wez 2016/06/10 22:55:09 nit: langID->language_id, or just |language|
chongz 2016/06/14 20:41:47 Done.
260 WORD primaryLangID = PRIMARYLANGID(langID);
Wez 2016/06/10 22:55:09 nit: primary_language_id or just |primary_language
chongz 2016/06/14 20:41:47 Done.
261 // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5.
262 // https://crbug.com/612694
Wez 2016/06/10 22:55:09 nit: I'd suggest putting this comment after the Ko
chongz 2016/06/14 20:41:47 Done.
263 if (primaryLangID == LANG_KOREAN) {
264 switch (key_code) {
265 case VKEY_HANGUL: // Same as VKEY_KANA.
266 return DomKey::HANGUL_MODE;
267 case VKEY_HANJA: // Same as VKEY_KANJI.
Wez 2016/06/10 22:55:09 Do these comments make sense in the context of Kor
chongz 2016/06/14 20:41:47 Done.
268 return DomKey::HANJA_MODE;
269 default:
270 return DomKey::NONE;
271 }
272 }
273 return DomKey::NONE;
274 }
275
276 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code, HKL layout) {
277 // 1. Look up general key map.
Wez 2016/06/10 22:55:09 nit: Suggest "Most |key_codes| have the same meani
chongz 2016/06/14 20:41:47 Done.
261 const NonPrintableKeyEntry* result = std::lower_bound( 278 const NonPrintableKeyEntry* result = std::lower_bound(
262 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, 279 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code,
263 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { 280 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) {
264 return entry.key_code < needle; 281 return entry.key_code < needle;
265 }); 282 });
266 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) 283 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code)
267 return result->dom_key; 284 return result->dom_key;
268 return DomKey::NONE; 285 // 2. Look up language specific key map.
286 return LangSpecificNonPrintableKeyboardCodeToDomKey(key_code, layout);
269 } 287 }
270 288
271 void CleanupKeyMapTls(void* data) { 289 void CleanupKeyMapTls(void* data) {
272 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); 290 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data);
273 delete key_map; 291 delete key_map;
274 } 292 }
275 293
276 struct PlatformKeyMapInstanceTlsTraits 294 struct PlatformKeyMapInstanceTlsTraits
277 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { 295 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> {
278 static base::ThreadLocalStorage::Slot* New(void* instance) { 296 static base::ThreadLocalStorage::Slot* New(void* instance) {
(...skipping 13 matching lines...) Expand all
292 310
293 PlatformKeyMap::PlatformKeyMap(HKL layout) { 311 PlatformKeyMap::PlatformKeyMap(HKL layout) {
294 UpdateLayout(layout); 312 UpdateLayout(layout);
295 } 313 }
296 314
297 PlatformKeyMap::~PlatformKeyMap() {} 315 PlatformKeyMap::~PlatformKeyMap() {}
298 316
299 DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code, 317 DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code,
300 KeyboardCode key_code, 318 KeyboardCode key_code,
301 int flags) const { 319 int flags) const {
302 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code); 320 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_);
303 if (key != DomKey::NONE) 321 if (key != DomKey::NONE)
304 return key; 322 return key;
305 323
306 // TODO(chongz): Handle VKEY_KANA/VKEY_HANGUL, VKEY_HANJA/VKEY_KANJI based on
307 // layout.
308 // https://crbug.com/612736
309
310 if (KeycodeConverter::DomCodeToLocation(code) == DomKeyLocation::NUMPAD) { 324 if (KeycodeConverter::DomCodeToLocation(code) == DomKeyLocation::NUMPAD) {
311 // Derived the DOM Key value from |key_code| instead of |code|, to address 325 // Derived the DOM Key value from |key_code| instead of |code|, to address
312 // Windows Numlock/Shift interaction - see crbug.com/594552. 326 // Windows Numlock/Shift interaction - see crbug.com/594552.
313 return NumPadKeyCodeToDomKey(key_code); 327 return NumPadKeyCodeToDomKey(key_code);
314 } 328 }
315 329
316 const int flags_to_try[] = { 330 const int flags_to_try[] = {
317 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. 331 // Trying to match Firefox's behavior and UIEvents DomKey guidelines.
318 // If the combination doesn't produce a printable character, the key value 332 // If the combination doesn't produce a printable character, the key value
319 // should be the key with no modifiers except for Shift and AltGr. 333 // should be the key with no modifiers except for Shift and AltGr.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 } 422 }
409 } else { 423 } else {
410 // TODO(chongz): Handle rv <= -2 and rv >= 2. 424 // TODO(chongz): Handle rv <= -2 and rv >= 2.
411 } 425 }
412 } 426 }
413 } 427 }
414 ::SetKeyboardState(keyboard_state_to_restore); 428 ::SetKeyboardState(keyboard_state_to_restore);
415 } 429 }
416 430
417 } // namespace ui 431 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698