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

Side by Side Diff: ui/events/keycodes/keyboard_code_conversion_mac.mm

Issue 1706683002: [Mac] Produce correct DomKey when Ctrl/Shift/Command is down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test case for Ctrl+Shift+foo Created 4 years, 10 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
« no previous file with comments | « content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" 5 #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #import <Carbon/Carbon.h> 9 #import <Carbon/Carbon.h>
10 10
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 DomCode DomCodeFromNSEvent(NSEvent* event) { 739 DomCode DomCodeFromNSEvent(NSEvent* event) {
740 return ui::KeycodeConverter::NativeKeycodeToDomCode([event keyCode]); 740 return ui::KeycodeConverter::NativeKeycodeToDomCode([event keyCode]);
741 } 741 }
742 742
743 DomKey DomKeyFromNSEvent(NSEvent* event) { 743 DomKey DomKeyFromNSEvent(NSEvent* event) {
744 // Apply the lookup based on the character first since that has the 744 // Apply the lookup based on the character first since that has the
745 // Keyboard layout and modifers already applied; whereas the keyCode 745 // Keyboard layout and modifers already applied; whereas the keyCode
746 // doesn't. 746 // doesn't.
747 if ([event type] == NSKeyDown || [event type] == NSKeyUp) { 747 if ([event type] == NSKeyDown || [event type] == NSKeyUp) {
748 NSString* characters = [event characters]; 748 NSString* characters = [event characters];
749 if ([characters length] > 0) 749 if ([characters length] > 0) {
750 return DomKeyFromCharCode([characters characterAtIndex:0]); 750 unichar dom_key_char =
751 [characters characterAtIndex:[characters length] - 1];
chongz 2016/02/17 22:54:05 Use last character because e.g. On French keyboard
752 if ([event modifierFlags] != 0 && std::iscntrl(dom_key_char)) {
753 // According to spec if the key combination produces a non-printable
754 // character, the key value should be the character without modifiers.
755 // See https://w3c.github.io/uievents/#keys-guidelines
756 NSString* unmodified_characters = [event charactersIgnoringModifiers];
757 if ([unmodified_characters length] > 0) {
758 unichar unmodified_char = [unmodified_characters
759 characterAtIndex:[unmodified_characters length] - 1];
760 dom_key_char = unmodified_char;
761 }
762 }
763 return DomKeyFromCharCode(dom_key_char);
764 }
751 } 765 }
752 return DomKeyFromKeyCode([event keyCode]); 766 return DomKeyFromKeyCode([event keyCode]);
753 } 767 }
754 768
755 } // namespace ui 769 } // namespace ui
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698