| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 PlatformKeyMap::PlatformKeyMap() {} | 279 PlatformKeyMap::PlatformKeyMap() {} |
| 280 | 280 |
| 281 PlatformKeyMap::PlatformKeyMap(HKL layout) { | 281 PlatformKeyMap::PlatformKeyMap(HKL layout) { |
| 282 UpdateLayout(layout); | 282 UpdateLayout(layout); |
| 283 } | 283 } |
| 284 | 284 |
| 285 PlatformKeyMap::~PlatformKeyMap() {} | 285 PlatformKeyMap::~PlatformKeyMap() {} |
| 286 | 286 |
| 287 DomKey PlatformKeyMap::DomKeyFromKeyboardCodeImpl(KeyboardCode key_code, | 287 DomKey PlatformKeyMap::DomKeyFromKeyboardCodeImpl(KeyboardCode key_code, |
| 288 int flags) const { | 288 int flags) const { |
| 289 // Windows expresses right-Alt as VKEY_MENU with the extended flag set. |
| 290 // This key should generate AltGraph under layouts which use that modifier. |
| 291 if (key_code == VKEY_MENU && (flags & EF_IS_EXTENDED_KEY) && has_alt_graph_) { |
| 292 return DomKey::ALT_GRAPH; |
| 293 } |
| 294 |
| 289 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_); | 295 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_); |
| 290 if (key != DomKey::NONE) | 296 if (key != DomKey::NONE) |
| 291 return key; | 297 return key; |
| 292 | 298 |
| 293 const int flags_to_try[] = { | 299 const int flags_to_try[] = { |
| 294 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. | 300 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. |
| 295 // If the combination doesn't produce a printable character, the key value | 301 // If the combination doesn't produce a printable character, the key value |
| 296 // should be the key with no modifiers except for Shift and AltGr. | 302 // should be the key with no modifiers except for Shift and AltGr. |
| 297 // See https://w3c.github.io/uievents/#keys-guidelines | 303 // See https://w3c.github.io/uievents/#keys-guidelines |
| 298 flags, | 304 flags, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 if (layout == keyboard_layout_) | 345 if (layout == keyboard_layout_) |
| 340 return; | 346 return; |
| 341 | 347 |
| 342 BYTE keyboard_state_to_restore[256]; | 348 BYTE keyboard_state_to_restore[256]; |
| 343 if (!::GetKeyboardState(keyboard_state_to_restore)) | 349 if (!::GetKeyboardState(keyboard_state_to_restore)) |
| 344 return; | 350 return; |
| 345 | 351 |
| 346 // TODO(chongz): Optimize layout switching (see crbug.com/587147). | 352 // TODO(chongz): Optimize layout switching (see crbug.com/587147). |
| 347 keyboard_layout_ = layout; | 353 keyboard_layout_ = layout; |
| 348 printable_keycode_to_key_.clear(); | 354 printable_keycode_to_key_.clear(); |
| 355 has_alt_graph_ = false; |
| 349 | 356 |
| 350 // Map size for some sample keyboard layouts: | 357 // Map size for some sample keyboard layouts: |
| 351 // US: 476, French: 602, Persian: 482, Vietnamese: 1436 | 358 // US: 476, French: 602, Persian: 482, Vietnamese: 1436 |
| 352 printable_keycode_to_key_.reserve(1500); | 359 printable_keycode_to_key_.reserve(1500); |
| 353 | 360 |
| 354 for (int modifier_combination = 0; | 361 for (int modifier_combination = 0; |
| 355 modifier_combination <= kModifierFlagsCombinations; | 362 modifier_combination <= kModifierFlagsCombinations; |
| 356 ++modifier_combination) { | 363 ++modifier_combination) { |
| 357 BYTE keyboard_state[256]; | 364 BYTE keyboard_state[256]; |
| 358 memset(keyboard_state, 0, sizeof(keyboard_state)); | 365 memset(keyboard_state, 0, sizeof(keyboard_state)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 378 flags)] = | 385 flags)] = |
| 379 DomKey::DeadKeyFromCombiningCharacter(translated_chars[0]); | 386 DomKey::DeadKeyFromCombiningCharacter(translated_chars[0]); |
| 380 } else { | 387 } else { |
| 381 // TODO(chongz): Check if this will actually happen. | 388 // TODO(chongz): Check if this will actually happen. |
| 382 } | 389 } |
| 383 } else if (rv == 1) { | 390 } else if (rv == 1) { |
| 384 if (translated_chars[0] >= 0x20) { | 391 if (translated_chars[0] >= 0x20) { |
| 385 printable_keycode_to_key_[std::make_pair(static_cast<int>(key_code), | 392 printable_keycode_to_key_[std::make_pair(static_cast<int>(key_code), |
| 386 flags)] = | 393 flags)] = |
| 387 DomKey::FromCharacter(translated_chars[0]); | 394 DomKey::FromCharacter(translated_chars[0]); |
| 395 |
| 396 // Detect whether the layout makes use of AltGraph. |
| 397 if (flags & EF_ALTGR_DOWN) { |
| 398 has_alt_graph_ = true; |
| 399 } |
| 388 } else { | 400 } else { |
| 389 // Ignores legacy non-printable control characters. | 401 // Ignores legacy non-printable control characters. |
| 390 } | 402 } |
| 391 } else { | 403 } else { |
| 392 // TODO(chongz): Handle rv <= -2 and rv >= 2. | 404 // TODO(chongz): Handle rv <= -2 and rv >= 2. |
| 393 } | 405 } |
| 394 } | 406 } |
| 395 } | 407 } |
| 396 ::SetKeyboardState(keyboard_state_to_restore); | 408 ::SetKeyboardState(keyboard_state_to_restore); |
| 397 } | 409 } |
| 398 | 410 |
| 399 } // namespace ui | 411 } // namespace ui |
| OLD | NEW |