Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 |
| OLD | NEW |