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

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

Issue 2630213003: Return AltGraph for right-Alt keydown/keyup, under layouts which use AltGraph. (Closed)
Patch Set: Created 3 years, 11 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 <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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_); 289 DomKey key = NonPrintableKeyboardCodeToDomKey(key_code, keyboard_layout_);
290 if (key == DomKey::ALT && (flags & EF_IS_EXTENDED_KEY) && has_alt_graph_) {
garykac 2017/01/18 15:55:29 Could you add a brief comment above this line?
Wez 2017/01/18 21:36:35 Done.
291 return DomKey::ALT_GRAPH;
292 }
290 if (key != DomKey::NONE) 293 if (key != DomKey::NONE)
291 return key; 294 return key;
292 295
293 const int flags_to_try[] = { 296 const int flags_to_try[] = {
294 // Trying to match Firefox's behavior and UIEvents DomKey guidelines. 297 // Trying to match Firefox's behavior and UIEvents DomKey guidelines.
295 // If the combination doesn't produce a printable character, the key value 298 // 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. 299 // should be the key with no modifiers except for Shift and AltGr.
297 // See https://w3c.github.io/uievents/#keys-guidelines 300 // See https://w3c.github.io/uievents/#keys-guidelines
298 flags, 301 flags,
299 flags & (EF_SHIFT_DOWN | EF_ALTGR_DOWN | EF_CAPS_LOCK_ON), 302 flags & (EF_SHIFT_DOWN | EF_ALTGR_DOWN | EF_CAPS_LOCK_ON),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 if (layout == keyboard_layout_) 342 if (layout == keyboard_layout_)
340 return; 343 return;
341 344
342 BYTE keyboard_state_to_restore[256]; 345 BYTE keyboard_state_to_restore[256];
343 if (!::GetKeyboardState(keyboard_state_to_restore)) 346 if (!::GetKeyboardState(keyboard_state_to_restore))
344 return; 347 return;
345 348
346 // TODO(chongz): Optimize layout switching (see crbug.com/587147). 349 // TODO(chongz): Optimize layout switching (see crbug.com/587147).
347 keyboard_layout_ = layout; 350 keyboard_layout_ = layout;
348 printable_keycode_to_key_.clear(); 351 printable_keycode_to_key_.clear();
352 has_alt_graph_ = false;
349 353
350 // Map size for some sample keyboard layouts: 354 // Map size for some sample keyboard layouts:
351 // US: 476, French: 602, Persian: 482, Vietnamese: 1436 355 // US: 476, French: 602, Persian: 482, Vietnamese: 1436
352 printable_keycode_to_key_.reserve(1500); 356 printable_keycode_to_key_.reserve(1500);
353 357
354 for (int modifier_combination = 0; 358 for (int modifier_combination = 0;
355 modifier_combination <= kModifierFlagsCombinations; 359 modifier_combination <= kModifierFlagsCombinations;
356 ++modifier_combination) { 360 ++modifier_combination) {
357 BYTE keyboard_state[256]; 361 BYTE keyboard_state[256];
358 memset(keyboard_state, 0, sizeof(keyboard_state)); 362 memset(keyboard_state, 0, sizeof(keyboard_state));
(...skipping 19 matching lines...) Expand all
378 flags)] = 382 flags)] =
379 DomKey::DeadKeyFromCombiningCharacter(translated_chars[0]); 383 DomKey::DeadKeyFromCombiningCharacter(translated_chars[0]);
380 } else { 384 } else {
381 // TODO(chongz): Check if this will actually happen. 385 // TODO(chongz): Check if this will actually happen.
382 } 386 }
383 } else if (rv == 1) { 387 } else if (rv == 1) {
384 if (translated_chars[0] >= 0x20) { 388 if (translated_chars[0] >= 0x20) {
385 printable_keycode_to_key_[std::make_pair(static_cast<int>(key_code), 389 printable_keycode_to_key_[std::make_pair(static_cast<int>(key_code),
386 flags)] = 390 flags)] =
387 DomKey::FromCharacter(translated_chars[0]); 391 DomKey::FromCharacter(translated_chars[0]);
392
393 // Detect whether the layout makes use of AltGraph.
394 if (flags & EF_ALTGR_DOWN) {
395 has_alt_graph_ = true;
396 }
388 } else { 397 } else {
389 // Ignores legacy non-printable control characters. 398 // Ignores legacy non-printable control characters.
390 } 399 }
391 } else { 400 } else {
392 // TODO(chongz): Handle rv <= -2 and rv >= 2. 401 // TODO(chongz): Handle rv <= -2 and rv >= 2.
393 } 402 }
394 } 403 }
395 } 404 }
396 ::SetKeyboardState(keyboard_state_to_restore); 405 ::SetKeyboardState(keyboard_state_to_restore);
397 } 406 }
398 407
399 } // namespace ui 408 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/keycodes/platform_key_map_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