Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: ui/events/keycodes/platform_key_map_win.cc

Issue 2128573002: [DomKey] Support Japanese (JIS) layout special keys (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wez's review 2 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // VKEY_KANA isn't generated by any modern layouts but is a listed value
215 // that third-party apps might synthesize, so we handle it anyway.
216 case VKEY_KANA:
217 case VKEY_ATTN:
218 return DomKey::KANA_MODE;
219 case VKEY_KANJI:
220 return DomKey::KANJI_MODE;
221 case VKEY_OEM_ATTN:
222 return DomKey::ALPHANUMERIC;
223 case VKEY_OEM_FINISH:
224 return DomKey::KATAKANA;
225 case VKEY_OEM_COPY:
226 return DomKey::HIRAGANA;
227 case VKEY_DBE_SBCSCHAR:
228 return DomKey::HANKAKU;
229 case VKEY_DBE_DBCSCHAR:
230 return DomKey::ZENKAKU;
231 case VKEY_OEM_BACKTAB:
232 return DomKey::ROMAJI;
233 default:
234 return DomKey::NONE;
235 }
212 } 236 }
213 // TODO(chongz): Handle Japanese keyboard layout keys 0xF0..0xF5, VKEY_KANA,
214 // VKEY_KANJI.
215 // https://crbug.com/612694
216 return DomKey::NONE; 237 return DomKey::NONE;
217 } 238 }
218 239
219 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code, HKL layout) { 240 DomKey NonPrintableKeyboardCodeToDomKey(KeyboardCode key_code, HKL layout) {
220 // 1. Most |key_codes| have the same meaning regardless of |layout|. 241 // 1. Check if |key_code| has a |layout|-specific meaning.
242 const DomKey key = LanguageSpecificOemKeyboardCodeToDomKey(key_code, layout);
243 if (key != DomKey::NONE)
244 return key;
245
246 // 2. Most |key_codes| have the same meaning regardless of |layout|.
221 const NonPrintableKeyEntry* result = std::lower_bound( 247 const NonPrintableKeyEntry* result = std::lower_bound(
222 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code, 248 std::begin(kNonPrintableKeyMap), std::end(kNonPrintableKeyMap), key_code,
223 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) { 249 [](const NonPrintableKeyEntry& entry, KeyboardCode needle) {
224 return entry.key_code < needle; 250 return entry.key_code < needle;
225 }); 251 });
226 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code) 252 if (result != std::end(kNonPrintableKeyMap) && result->key_code == key_code)
227 return result->dom_key; 253 return result->dom_key;
228 // 2. Look up a |layout|-specific meaning for |key_code|. 254
229 return LanguageSpecificOemKeyboardCodeToDomKey(key_code, layout); 255 return DomKey::NONE;
230 } 256 }
231 257
232 void CleanupKeyMapTls(void* data) { 258 void CleanupKeyMapTls(void* data) {
233 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data); 259 PlatformKeyMap* key_map = reinterpret_cast<PlatformKeyMap*>(data);
234 delete key_map; 260 delete key_map;
235 } 261 }
236 262
237 struct PlatformKeyMapInstanceTlsTraits 263 struct PlatformKeyMapInstanceTlsTraits
238 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> { 264 : public base::DefaultLazyInstanceTraits<base::ThreadLocalStorage::Slot> {
239 static base::ThreadLocalStorage::Slot* New(void* instance) { 265 static base::ThreadLocalStorage::Slot* New(void* instance) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON), 299 flags & (EF_SHIFT_DOWN | EF_CAPS_LOCK_ON),
274 EF_NONE, 300 EF_NONE,
275 }; 301 };
276 302
277 for (auto try_flags : flags_to_try) { 303 for (auto try_flags : flags_to_try) {
278 const auto& it = printable_keycode_to_key_.find( 304 const auto& it = printable_keycode_to_key_.find(
279 std::make_pair(static_cast<int>(key_code), try_flags)); 305 std::make_pair(static_cast<int>(key_code), try_flags));
280 if (it != printable_keycode_to_key_.end()) { 306 if (it != printable_keycode_to_key_.end()) {
281 key = it->second; 307 key = it->second;
282 if (key != DomKey::NONE) 308 if (key != DomKey::NONE)
283 break; 309 return key;
284 } 310 }
285 } 311 }
286 312
287 return key; 313 // Return DomKey::UNIDENTIFIED to prevent US layout fall-back.
314 return DomKey::UNIDENTIFIED;
288 } 315 }
289 316
290 // static 317 // static
291 DomKey PlatformKeyMap::DomKeyFromKeyboardCode(KeyboardCode key_code, 318 DomKey PlatformKeyMap::DomKeyFromKeyboardCode(KeyboardCode key_code,
292 int flags) { 319 int flags) {
293 // Use TLS because KeyboardLayout is per thread. 320 // Use TLS because KeyboardLayout is per thread.
294 // However currently PlatformKeyMap will only be used by the host application, 321 // However currently PlatformKeyMap will only be used by the host application,
295 // which is just one process and one thread. 322 // which is just one process and one thread.
296 base::ThreadLocalStorage::Slot* platform_key_map_tls = 323 base::ThreadLocalStorage::Slot* platform_key_map_tls =
297 g_platform_key_map_tls_lazy.Pointer(); 324 g_platform_key_map_tls_lazy.Pointer();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 389 }
363 } else { 390 } else {
364 // TODO(chongz): Handle rv <= -2 and rv >= 2. 391 // TODO(chongz): Handle rv <= -2 and rv >= 2.
365 } 392 }
366 } 393 }
367 } 394 }
368 ::SetKeyboardState(keyboard_state_to_restore); 395 ::SetKeyboardState(keyboard_state_to_restore);
369 } 396 }
370 397
371 } // namespace ui 398 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/keycodes/keyboard_codes_win.h ('k') | ui/events/keycodes/platform_key_map_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698