| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 {VKEY_MEDIA_STOP, DomKey::MEDIA_STOP}, | 176 {VKEY_MEDIA_STOP, DomKey::MEDIA_STOP}, |
| 177 {VKEY_MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE}, | 177 {VKEY_MEDIA_PLAY_PAUSE, DomKey::MEDIA_PLAY_PAUSE}, |
| 178 {VKEY_MEDIA_LAUNCH_MAIL, DomKey::LAUNCH_MAIL}, | 178 {VKEY_MEDIA_LAUNCH_MAIL, DomKey::LAUNCH_MAIL}, |
| 179 {VKEY_MEDIA_LAUNCH_MEDIA_SELECT, DomKey::LAUNCH_MEDIA_PLAYER}, | 179 {VKEY_MEDIA_LAUNCH_MEDIA_SELECT, DomKey::LAUNCH_MEDIA_PLAYER}, |
| 180 {VKEY_MEDIA_LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER}, | 180 {VKEY_MEDIA_LAUNCH_APP1, DomKey::LAUNCH_MY_COMPUTER}, |
| 181 {VKEY_MEDIA_LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR}, | 181 {VKEY_MEDIA_LAUNCH_APP2, DomKey::LAUNCH_CALCULATOR}, |
| 182 // VKEY_OEM_1..8, 102, PLUS, COMMA, MINUS, PERIOD | 182 // VKEY_OEM_1..8, 102, PLUS, COMMA, MINUS, PERIOD |
| 183 {VKEY_ALTGR, DomKey::ALT_GRAPH}, | 183 {VKEY_ALTGR, DomKey::ALT_GRAPH}, |
| 184 {VKEY_PROCESSKEY, DomKey::PROCESS}, | 184 {VKEY_PROCESSKEY, DomKey::PROCESS}, |
| 185 // VKEY_PACKET - Used to pass Unicode char, considered as printable key. | 185 // VKEY_PACKET - Used to pass Unicode char, considered as printable key. |
| 186 | |
| 187 // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5. | |
| 188 // https://crbug.com/612694 | |
| 189 {VKEY_ATTN, DomKey::ATTN}, | 186 {VKEY_ATTN, DomKey::ATTN}, |
| 190 {VKEY_CRSEL, DomKey::CR_SEL}, | 187 {VKEY_CRSEL, DomKey::CR_SEL}, |
| 191 {VKEY_EXSEL, DomKey::EX_SEL}, | 188 {VKEY_EXSEL, DomKey::EX_SEL}, |
| 192 {VKEY_EREOF, DomKey::ERASE_EOF}, | 189 {VKEY_EREOF, DomKey::ERASE_EOF}, |
| 193 {VKEY_PLAY, DomKey::PLAY}, | 190 {VKEY_PLAY, DomKey::PLAY}, |
| 194 {VKEY_ZOOM, DomKey::ZOOM_TOGGLE}, | 191 {VKEY_ZOOM, DomKey::ZOOM_TOGGLE}, |
| 195 // TODO(chongz): Handle VKEY_NONAME, VKEY_PA1. | 192 // TODO(chongz): Handle VKEY_NONAME, VKEY_PA1. |
| 196 // https://crbug.com/616910 | 193 // https://crbug.com/616910 |
| 197 {VKEY_OEM_CLEAR, DomKey::CLEAR}, | 194 {VKEY_OEM_CLEAR, DomKey::CLEAR}, |
| 198 }; | 195 }; |
| 199 | 196 |
| 200 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code) { | 197 // Disambiguates the meaning of certain non-printable keys which have different |
| 198 // meanings under different languages, but use the same VKEY code. |
| 199 DomKey LanguageSpecificOemKeyboardCodeToDomKey(KeyboardCode key_code, |
| 200 HKL layout) { |
| 201 WORD language = LOWORD(layout); |
| 202 WORD primary_language = PRIMARYLANGID(language); |
| 203 if (primary_language == LANG_KOREAN) { |
| 204 switch (key_code) { |
| 205 case VKEY_HANGUL: |
| 206 return DomKey::HANGUL_MODE; |
| 207 case VKEY_HANJA: |
| 208 return DomKey::HANJA_MODE; |
| 209 default: |
| 210 return DomKey::NONE; |
| 211 } |
| 212 } |
| 213 // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5, VKEY_KANA, |
| 214 // VKEY_KANJI. |
| 215 // https://crbug.com/612694 |
| 216 return DomKey::NONE; |
| 217 } |
| 218 |
| 219 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code, HKL layout) { |
| 220 // 1. Most |key_codes| have the same meaning regardless of |layout|. |
| 201 const NonPrintableKeyEntry* result = std::lower_bound( | 221 const NonPrintableKeyEntry* result = std::lower_bound( |
| 202 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, | 222 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, |
| 203 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { | 223 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { |
| 204 return entry.key_code < needle; | 224 return entry.key_code < needle; |
| 205 }); | 225 }); |
| 206 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) | 226 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) |
| 207 return result->dom_key; | 227 return result->dom_key; |
| 208 return DomKey::NONE; | 228 // 2. Look up a |layout|-specific meaning for |key_code|. |
| 229 return LanguageSpecificOemKeyboardCodeToDomKey(key_code, layout); |
| 209 } | 230 } |
| 210 | 231 |
| 211 void CleanupKeyMapTls(void* data) { | 232 void CleanupKeyMapTls(void* data) { |
| 212 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); | 233 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); |
| 213 delete key_map; | 234 delete key_map; |
| 214 } | 235 } |
| 215 | 236 |
| 216 struct PlatformKeyMapInstanceTlsTraits | 237 struct PlatformKeyMapInstanceTlsTraits |
| 217 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { | 238 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { |
| 218 static base::ThreadLocalStorage::Slot* New(void* instance) { | 239 static base::ThreadLocalStorage::Slot* New(void* instance) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 231 PlatformKeyMap::PlatformKeyMap() {} | 252 PlatformKeyMap::PlatformKeyMap() {} |
| 232 | 253 |
| 233 PlatformKeyMap::PlatformKeyMap(HKL layout) { | 254 PlatformKeyMap::PlatformKeyMap(HKL layout) { |
| 234 UpdateLayout(layout); | 255 UpdateLayout(layout); |
| 235 } | 256 } |
| 236 | 257 |
| 237 PlatformKeyMap::~PlatformKeyMap() {} | 258 PlatformKeyMap::~PlatformKeyMap() {} |
| 238 | 259 |
| 239 DomKey PlatformKeyMap::DomKeyFromKeyboardCodeImpl(KeyboardCode key_code, | 260 DomKey PlatformKeyMap::DomKeyFromKeyboardCodeImpl(KeyboardCode key_code, |
| 240 int flags) const { | 261 int flags) const { |
| 241 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code); | 262 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_); |
| 242 if (key != DomKey::NONE) | 263 if (key != DomKey::NONE) |
| 243 return key; | 264 return key; |
| 244 | 265 |
| 245 // TODO(chongz): Handle VKEY_KANA/VKEY_HANGUL, VKEY_HANJA/VKEY_KANJI based on | |
| 246 // layout. | |
| 247 // https://crbug.com/612736 | |
| 248 | |
| 249 const int flags_to_try[] = { | 266 const int flags_to_try[] = { |
| 250 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. | 267 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. |
| 251 // If the combination doesn't produce a printable character, the key value | 268 // If the combination doesn't produce a printable character, the key value |
| 252 // should be the key with no modifiers except for Shift and AltGr. | 269 // should be the key with no modifiers except for Shift and AltGr. |
| 253 // See https://w3c.github.io/uievents/#keys-guidelines | 270 // See https://w3c.github.io/uievents/#keys-guidelines |
| 254 flags, | 271 flags, |
| 255 flags & (EF_SHIFT_DOWN | EF_ALTGR_DOWN | EF_CAPS_LOCK_ON), | 272 flags & (EF_SHIFT_DOWN | EF_ALTGR_DOWN | EF_CAPS_LOCK_ON), |
| 256 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), | 273 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), |
| 257 EF_NONE, | 274 EF_NONE, |
| 258 }; | 275 }; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 362 } |
| 346 } else { | 363 } else { |
| 347 // TODO(chongz): Handle rv <= -2 and rv >= 2. | 364 // TODO(chongz): Handle rv <= -2 and rv >= 2. |
| 348 } | 365 } |
| 349 } | 366 } |
| 350 } | 367 } |
| 351 ::SetKeyboardState(keyboard_state_to_restore); | 368 ::SetKeyboardState(keyboard_state_to_restore); |
| 352 } | 369 } |
| 353 | 370 |
| 354 } // namespace ui | 371 } // namespace ui |
| OLD | NEW |