| OLD | NEW |
| 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 Loading... |
| 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 |
| 246 {VKEY_ATTN, DomKey::ATTN}, | 249 {VKEY_ATTN, DomKey::ATTN}, |
| 247 {VKEY_CRSEL, DomKey::CR_SEL}, | 250 {VKEY_CRSEL, DomKey::CR_SEL}, |
| 248 {VKEY_EXSEL, DomKey::EX_SEL}, | 251 {VKEY_EXSEL, DomKey::EX_SEL}, |
| 249 {VKEY_EREOF, DomKey::ERASE_EOF}, | 252 {VKEY_EREOF, DomKey::ERASE_EOF}, |
| 250 {VKEY_PLAY, DomKey::PLAY}, | 253 {VKEY_PLAY, DomKey::PLAY}, |
| 251 {VKEY_ZOOM, DomKey::ZOOM_TOGGLE}, | 254 {VKEY_ZOOM, DomKey::ZOOM_TOGGLE}, |
| 252 // TODO(chongz): Handle VKEY_NONAME, VKEY_PA1. | 255 // TODO(chongz): Handle VKEY_NONAME, VKEY_PA1. |
| 253 // https://crbug.com/616910 | 256 // https://crbug.com/616910 |
| 254 {VKEY_OEM_CLEAR, DomKey::CLEAR}, | 257 {VKEY_OEM_CLEAR, DomKey::CLEAR}, |
| 255 }; | 258 }; |
| 256 | 259 |
| 257 // Disambiguates the meaning of certain non-printable keys which have different | 260 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code) { |
| 258 // meanings under different languages, but use the same VKEY code. | |
| 259 DomKey LanguageSpecificOemKeyboardCodeToDomKey(KeyboardCode key_code, | |
| 260 HKL layout) { | |
| 261 WORD language = LOWORD(layout); | |
| 262 WORD primary_language = PRIMARYLANGID(language); | |
| 263 if (primary_language == LANG_KOREAN) { | |
| 264 switch (key_code) { | |
| 265 case VKEY_HANGUL: | |
| 266 return DomKey::HANGUL_MODE; | |
| 267 case VKEY_HANJA: | |
| 268 return DomKey::HANJA_MODE; | |
| 269 default: | |
| 270 return DomKey::NONE; | |
| 271 } | |
| 272 } | |
| 273 // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5, VKEY_KANA, | |
| 274 // VKEY_KANJI. | |
| 275 // https://crbug.com/612694 | |
| 276 return DomKey::NONE; | |
| 277 } | |
| 278 | |
| 279 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code, HKL layout) { | |
| 280 // 1. Most |key_codes| have the same meaning regardless of |layout|. | |
| 281 const NonPrintableKeyEntry* result = std::lower_bound( | 261 const NonPrintableKeyEntry* result = std::lower_bound( |
| 282 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, | 262 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, |
| 283 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { | 263 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { |
| 284 return entry.key_code < needle; | 264 return entry.key_code < needle; |
| 285 }); | 265 }); |
| 286 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) | 266 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) |
| 287 return result->dom_key; | 267 return result->dom_key; |
| 288 // 2. Look up a |layout|-specific meaning for |key_code|. | 268 return DomKey::NONE; |
| 289 return LanguageSpecificOemKeyboardCodeToDomKey(key_code, layout); | |
| 290 } | 269 } |
| 291 | 270 |
| 292 void CleanupKeyMapTls(void* data) { | 271 void CleanupKeyMapTls(void* data) { |
| 293 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); | 272 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); |
| 294 delete key_map; | 273 delete key_map; |
| 295 } | 274 } |
| 296 | 275 |
| 297 struct PlatformKeyMapInstanceTlsTraits | 276 struct PlatformKeyMapInstanceTlsTraits |
| 298 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { | 277 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { |
| 299 static base::ThreadLocalStorage::Slot* New(void* instance) { | 278 static base::ThreadLocalStorage::Slot* New(void* instance) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 313 | 292 |
| 314 PlatformKeyMap::PlatformKeyMap(HKL layout) { | 293 PlatformKeyMap::PlatformKeyMap(HKL layout) { |
| 315 UpdateLayout(layout); | 294 UpdateLayout(layout); |
| 316 } | 295 } |
| 317 | 296 |
| 318 PlatformKeyMap::~PlatformKeyMap() {} | 297 PlatformKeyMap::~PlatformKeyMap() {} |
| 319 | 298 |
| 320 DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code, | 299 DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code, |
| 321 KeyboardCode key_code, | 300 KeyboardCode key_code, |
| 322 int flags) const { | 301 int flags) const { |
| 323 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_); | 302 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code); |
| 324 if (key != DomKey::NONE) | 303 if (key != DomKey::NONE) |
| 325 return key; | 304 return key; |
| 326 | 305 |
| 306 // TODO(chongz): Handle VKEY_KANA/VKEY_HANGUL, VKEY_HANJA/VKEY_KANJI based on |
| 307 // layout. |
| 308 // https://crbug.com/612736 |
| 309 |
| 327 if (KeycodeConverter::DomCodeToLocation(code) == DomKeyLocation::NUMPAD) { | 310 if (KeycodeConverter::DomCodeToLocation(code) == DomKeyLocation::NUMPAD) { |
| 328 // Derived the DOM Key value from |key_code| instead of |code|, to address | 311 // Derived the DOM Key value from |key_code| instead of |code|, to address |
| 329 // Windows Numlock/Shift interaction - see crbug.com/594552. | 312 // Windows Numlock/Shift interaction - see crbug.com/594552. |
| 330 return NumPadKeyCodeToDomKey(key_code); | 313 return NumPadKeyCodeToDomKey(key_code); |
| 331 } | 314 } |
| 332 | 315 |
| 333 const int flags_to_try[] = { | 316 const int flags_to_try[] = { |
| 334 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. | 317 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. |
| 335 // If the combination doesn't produce a printable character, the key value | 318 // If the combination doesn't produce a printable character, the key value |
| 336 // should be the key with no modifiers except for Shift and AltGr. | 319 // should be the key with no modifiers except for Shift and AltGr. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } | 408 } |
| 426 } else { | 409 } else { |
| 427 // TODO(chongz): Handle rv <= -2 and rv >= 2. | 410 // TODO(chongz): Handle rv <= -2 and rv >= 2. |
| 428 } | 411 } |
| 429 } | 412 } |
| 430 } | 413 } |
| 431 ::SetKeyboardState(keyboard_state_to_restore); | 414 ::SetKeyboardState(keyboard_state_to_restore); |
| 432 } | 415 } |
| 433 | 416 |
| 434 } // namespace ui | 417 } // namespace ui |
| OLD | NEW |