Chromium Code Reviews| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 WORD primary_language = PRIMARYLANGID(language); | 202 WORD primary_language = PRIMARYLANGID(language); |
| 203 if (primary_language == LANG_KOREAN) { | 203 if (primary_language == LANG_KOREAN) { |
| 204 switch (key_code) { | 204 switch (key_code) { |
| 205 case VKEY_HANGUL: | 205 case VKEY_HANGUL: |
| 206 return DomKey::HANGUL_MODE; | 206 return DomKey::HANGUL_MODE; |
| 207 case VKEY_HANJA: | 207 case VKEY_HANJA: |
| 208 return DomKey::HANJA_MODE; | 208 return DomKey::HANJA_MODE; |
| 209 default: | 209 default: |
| 210 return DomKey::NONE; | 210 return DomKey::NONE; |
| 211 } | 211 } |
| 212 } else if (primary_language == LANG_JAPANESE) { | |
| 213 switch (key_code) { | |
| 214 case VKEY_KANA: | |
| 215 return DomKey::KANA_MODE; | |
|
chongz
2016/07/06 22:50:34
|VKEY_KANA| is not used with modern Japanese keybo
Wez
2016/07/07 18:25:51
When you say "modern keyboard" do you mean modern
chongz
2016/07/07 22:18:09
Actually FireFox says so but I cannot find more in
Wez
2016/07/08 23:34:06
That's really unfortunate. It sounds like the Fire
| |
| 216 case VKEY_KANJI: | |
| 217 return DomKey::KANJI_MODE; | |
| 218 case VKEY_OEM_ATTN: | |
| 219 return DomKey::ALPHANUMERIC; | |
| 220 case VKEY_OEM_FINISH: | |
| 221 return DomKey::KATAKANA; | |
| 222 case VKEY_OEM_COPY: | |
| 223 return DomKey::HIRAGANA; | |
| 224 case VKEY_DBE_SBCSCHAR: | |
| 225 return DomKey::HANKAKU; | |
| 226 case VKEY_DBE_DBCSCHAR: | |
| 227 return DomKey::ZENKAKU; | |
| 228 case VKEY_OEM_BACKTAB: | |
| 229 return DomKey::ROMAJI; | |
| 230 case VKEY_ATTN: | |
| 231 return DomKey::KANA_MODE; | |
|
chongz
2016/07/06 22:50:34
On other layouts |VKEY_ATTN| will be mapped to |Do
| |
| 232 default: | |
| 233 return DomKey::NONE; | |
| 234 } | |
| 212 } | 235 } |
| 213 // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5, VKEY_KANA, | |
| 214 // VKEY_KANJI. | |
| 215 // https://crbug.com/612694 | |
| 216 return DomKey::NONE; | 236 return DomKey::NONE; |
| 217 } | 237 } |
| 218 | 238 |
| 219 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code, HKL layout) { | 239 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code, HKL layout) { |
| 220 // 1. Most |key_codes| have the same meaning regardless of |layout|. | 240 // 1. Check if |key_code| has a |layout|-specific meaning. |
| 241 const DomKey key = LanguageSpecificOemKeyboardCodeToDomKey(key_code, layout); | |
| 242 if (key != DomKey::NONE) | |
| 243 return key; | |
|
chongz
2016/07/06 22:50:34
Do language mapping first so JIS could map |VKEY_A
Wez
2016/07/07 18:25:51
Acknowledged.
| |
| 244 | |
| 245 // 2. Most |key_codes| have the same meaning regardless of |layout|. | |
| 221 const NonPrintableKeyEntry* result = std::lower_bound( | 246 const NonPrintableKeyEntry* result = std::lower_bound( |
| 222 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, | 247 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, |
| 223 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { | 248 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { |
| 224 return entry.key_code < needle; | 249 return entry.key_code < needle; |
| 225 }); | 250 }); |
| 226 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) | 251 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) |
| 227 return result->dom_key; | 252 return result->dom_key; |
| 228 // 2. Look up a |layout|-specific meaning for |key_code|. | 253 |
| 229 return LanguageSpecificOemKeyboardCodeToDomKey(key_code, layout); | 254 return DomKey::NONE; |
| 230 } | 255 } |
| 231 | 256 |
| 232 void CleanupKeyMapTls(void* data) { | 257 void CleanupKeyMapTls(void* data) { |
| 233 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); | 258 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); |
| 234 delete key_map; | 259 delete key_map; |
| 235 } | 260 } |
| 236 | 261 |
| 237 struct PlatformKeyMapInstanceTlsTraits | 262 struct PlatformKeyMapInstanceTlsTraits |
| 238 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { | 263 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { |
| 239 static base::ThreadLocalStorage::Slot* New(void* instance) { | 264 static base::ThreadLocalStorage::Slot* New(void* instance) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), | 298 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), |
| 274 EF_NONE, | 299 EF_NONE, |
| 275 }; | 300 }; |
| 276 | 301 |
| 277 for (auto try_flags : flags_to_try) { | 302 for (auto try_flags : flags_to_try) { |
| 278 const auto& it = printable_keycode_to_key_.find( | 303 const auto& it = printable_keycode_to_key_.find( |
| 279 std::make_pair(static_cast<int>(key_code), try_flags)); | 304 std::make_pair(static_cast<int>(key_code), try_flags)); |
| 280 if (it != printable_keycode_to_key_.end()) { | 305 if (it != printable_keycode_to_key_.end()) { |
| 281 key = it->second; | 306 key = it->second; |
| 282 if (key != DomKey::NONE) | 307 if (key != DomKey::NONE) |
| 283 break; | 308 return key; |
| 284 } | 309 } |
| 285 } | 310 } |
| 286 | 311 |
| 287 return key; | 312 // Return DomKey::UNIDENTIFIED to prevent US layout fall-back. |
| 313 return DomKey::UNIDENTIFIED; | |
|
chongz
2016/07/06 22:50:34
|KeyEvent::ApplyLayout()| will do the fall-back ma
Wez
2016/07/07 18:25:51
Acknowledged.
| |
| 288 } | 314 } |
| 289 | 315 |
| 290 // static | 316 // static |
| 291 DomKey PlatformKeyMap::DomKeyFromKeyboardCode(KeyboardCode key_code, | 317 DomKey PlatformKeyMap::DomKeyFromKeyboardCode(KeyboardCode key_code, |
| 292 int flags) { | 318 int flags) { |
| 293 // Use TLS because KeyboardLayout is per thread. | 319 // Use TLS because KeyboardLayout is per thread. |
| 294 // However currently PlatformKeyMap will only be used by the host application, | 320 // However currently PlatformKeyMap will only be used by the host application, |
| 295 // which is just one process and one thread. | 321 // which is just one process and one thread. |
| 296 base::ThreadLocalStorage::Slot* platform_key_map_tls = | 322 base::ThreadLocalStorage::Slot* platform_key_map_tls = |
| 297 g_platform_key_map_tls_lazy.Pointer(); | 323 g_platform_key_map_tls_lazy.Pointer(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 } | 388 } |
| 363 } else { | 389 } else { |
| 364 // TODO(chongz): Handle rv <= -2 and rv >= 2. | 390 // TODO(chongz): Handle rv <= -2 and rv >= 2. |
| 365 } | 391 } |
| 366 } | 392 } |
| 367 } | 393 } |
| 368 ::SetKeyboardState(keyboard_state_to_restore); | 394 ::SetKeyboardState(keyboard_state_to_restore); |
| 369 } | 395 } |
| 370 | 396 |
| 371 } // namespace ui | 397 } // namespace ui |
| OLD | NEW |