| 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 | |
| 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 // Disambiguates the meaning of certain non-printable keys which have different |
| 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|. |
| 261 const NonPrintableKeyEntry* result = std::lower_bound( | 281 const NonPrintableKeyEntry* result = std::lower_bound( |
| 262 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, | 282 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, |
| 263 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { | 283 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { |
| 264 return entry.key_code < needle; | 284 return entry.key_code < needle; |
| 265 }); | 285 }); |
| 266 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) | 286 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) |
| 267 return result->dom_key; | 287 return result->dom_key; |
| 268 return DomKey::NONE; | 288 // 2. Look up a |layout|-specific meaning for |key_code|. |
| 289 return LanguageSpecificOemKeyboardCodeToDomKey(key_code, layout); |
| 269 } | 290 } |
| 270 | 291 |
| 271 void CleanupKeyMapTls(void* data) { | 292 void CleanupKeyMapTls(void* data) { |
| 272 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); | 293 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); |
| 273 delete key_map; | 294 delete key_map; |
| 274 } | 295 } |
| 275 | 296 |
| 276 struct PlatformKeyMapInstanceTlsTraits | 297 struct PlatformKeyMapInstanceTlsTraits |
| 277 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { | 298 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { |
| 278 static base::ThreadLocalStorage::Slot* New(void* instance) { | 299 static base::ThreadLocalStorage::Slot* New(void* instance) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 292 | 313 |
| 293 PlatformKeyMap::PlatformKeyMap(HKL layout) { | 314 PlatformKeyMap::PlatformKeyMap(HKL layout) { |
| 294 UpdateLayout(layout); | 315 UpdateLayout(layout); |
| 295 } | 316 } |
| 296 | 317 |
| 297 PlatformKeyMap::~PlatformKeyMap() {} | 318 PlatformKeyMap::~PlatformKeyMap() {} |
| 298 | 319 |
| 299 DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code, | 320 DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code, |
| 300 KeyboardCode key_code, | 321 KeyboardCode key_code, |
| 301 int flags) const { | 322 int flags) const { |
| 302 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code); | 323 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_); |
| 303 if (key != DomKey::NONE) | 324 if (key != DomKey::NONE) |
| 304 return key; | 325 return key; |
| 305 | 326 |
| 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) { | 327 if (KeycodeConverter::DomCodeToLocation(code) == DomKeyLocation::NUMPAD) { |
| 311 // Derived the DOM Key value from |key_code| instead of |code|, to address | 328 // Derived the DOM Key value from |key_code| instead of |code|, to address |
| 312 // Windows Numlock/Shift interaction - see crbug.com/594552. | 329 // Windows Numlock/Shift interaction - see crbug.com/594552. |
| 313 return NumPadKeyCodeToDomKey(key_code); | 330 return NumPadKeyCodeToDomKey(key_code); |
| 314 } | 331 } |
| 315 | 332 |
| 316 const int flags_to_try[] = { | 333 const int flags_to_try[] = { |
| 317 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. | 334 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. |
| 318 // If the combination doesn't produce a printable character, the key value | 335 // 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. | 336 // 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... |
| 408 } | 425 } |
| 409 } else { | 426 } else { |
| 410 // TODO(chongz): Handle rv <= -2 and rv >= 2. | 427 // TODO(chongz): Handle rv <= -2 and rv >= 2. |
| 411 } | 428 } |
| 412 } | 429 } |
| 413 } | 430 } |
| 414 ::SetKeyboardState(keyboard_state_to_restore); | 431 ::SetKeyboardState(keyboard_state_to_restore); |
| 415 } | 432 } |
| 416 | 433 |
| 417 } // namespace ui | 434 } // namespace ui |
| OLD | NEW |