Index: ui/events/keycodes/platform_key_map_win.cc |
diff --git a/ui/events/keycodes/platform_key_map_win.cc b/ui/events/keycodes/platform_key_map_win.cc |
index 5c99275b905d71f72da67c6ca725fdc7960d8e13..e73ce7e885e006002b747d1be4d33c3db9572255 100644 |
--- a/ui/events/keycodes/platform_key_map_win.cc |
+++ b/ui/events/keycodes/platform_key_map_win.cc |
@@ -243,9 +243,6 @@ const struct NonPrintableKeyEntry { |
{VKEY_ALTGR, DomKey::ALT_GRAPH}, |
{VKEY_PROCESSKEY, DomKey::PROCESS}, |
// VKEY_PACKET - Used to pass Unicode char, considered as printable key. |
- |
- // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5. |
- // https://crbug.com/612694 |
{VKEY_ATTN, DomKey::ATTN}, |
{VKEY_CRSEL, DomKey::CR_SEL}, |
{VKEY_EXSEL, DomKey::EX_SEL}, |
@@ -257,7 +254,30 @@ const struct NonPrintableKeyEntry { |
{VKEY_OEM_CLEAR, DomKey::CLEAR}, |
}; |
-DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code) { |
+// Disambiguates the meaning of certain non-printable keys which have different |
+// meanings under different languages, but use the same VKEY code. |
+DomKey LanguageSpecificOemKeyboardCodeToDomKey(KeyboardCode key_code, |
+ HKL layout) { |
+ WORD language = LOWORD(layout); |
+ WORD primary_language = PRIMARYLANGID(language); |
+ if (primary_language == LANG_KOREAN) { |
+ switch (key_code) { |
+ case VKEY_HANGUL: |
+ return DomKey::HANGUL_MODE; |
+ case VKEY_HANJA: |
+ return DomKey::HANJA_MODE; |
+ default: |
+ return DomKey::NONE; |
+ } |
+ } |
+ // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5, VKEY_KANA, |
+ // VKEY_KANJI. |
+ // https://crbug.com/612694 |
+ return DomKey::NONE; |
+} |
+ |
+DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code, HKL layout) { |
+ // 1. Most |key_codes| have the same meaning regardless of |layout|. |
const NonPrintableKeyEntry* result = std::lower_bound( |
std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, |
[](const NonPrintableKeyEntry& entry, KeyboardCode needle) { |
@@ -265,7 +285,8 @@ DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code) { |
}); |
if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) |
return result->dom_key; |
- return DomKey::NONE; |
+ // 2. Look up a |layout|-specific meaning for |key_code|. |
+ return LanguageSpecificOemKeyboardCodeToDomKey(key_code, layout); |
} |
void CleanupKeyMapTls(void* data) { |
@@ -299,14 +320,10 @@ PlatformKeyMap::~PlatformKeyMap() {} |
DomKey PlatformKeyMap::DomKeyFromNativeImpl(DomCode code, |
KeyboardCode key_code, |
int flags) const { |
- DomKey key = NonPrintableKeyboardCodeToDomKey(key_code); |
+ DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_); |
if (key != DomKey::NONE) |
return key; |
- // TODO(chongz): Handle VKEY_KANA/VKEY_HANGUL, VKEY_HANJA/VKEY_KANJI based on |
- // layout. |
- // https://crbug.com/612736 |
- |
if (KeycodeConverter::DomCodeToLocation(code) == DomKeyLocation::NUMPAD) { |
// Derived the DOM Key value from |key_code| instead of |code|, to address |
// Windows Numlock/Shift interaction - see crbug.com/594552. |