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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 | 781 |
| 782 characters = [event charactersIgnoringModifiers]; | 782 characters = [event charactersIgnoringModifiers]; |
| 783 if ([characters length] > 0) | 783 if ([characters length] > 0) |
| 784 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); | 784 code = KeyboardCodeFromCharCode([characters characterAtIndex:0]); |
| 785 if (code) | 785 if (code) |
| 786 return code; | 786 return code; |
| 787 } | 787 } |
| 788 return KeyboardCodeFromKeyCode([event keyCode]); | 788 return KeyboardCodeFromKeyCode([event keyCode]); |
| 789 } | 789 } |
| 790 | 790 |
| 791 int ISOKeyboardKeyCodeMap(int nativeKeyCode) { | |
| 792 // OS X will swap 'Backquote' and 'IntlBackslash' if it's an ISO keyboard. | |
| 793 // https://crbug.com/600607 | |
| 794 switch (nativeKeyCode) { | |
| 795 case kVK_ISO_Section: | |
| 796 return kVK_ANSI_Grave; | |
| 797 case kVK_ANSI_Grave: | |
| 798 return kVK_ISO_Section; | |
| 799 default: | |
| 800 return nativeKeyCode; | |
| 801 } | |
| 802 } | |
| 803 | |
| 791 DomCode DomCodeFromNSEvent(NSEvent* event) { | 804 DomCode DomCodeFromNSEvent(NSEvent* event) { |
| 805 if (KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) { | |
|
chongz
2016/05/02 21:33:25
I'm not sure how to test this code, it seems magic
garykac
2016/05/02 22:03:23
For which keyboards does this return kKeyboardISO?
chongz
2016/05/02 22:31:12
It returns |kKeyboardISO| for
1. Apple's ISO Fr C
| |
| 806 return ui::KeycodeConverter::NativeKeycodeToDomCode( | |
| 807 ISOKeyboardKeyCodeMap([event keyCode])); | |
| 808 } | |
| 809 | |
| 792 return ui::KeycodeConverter::NativeKeycodeToDomCode([event keyCode]); | 810 return ui::KeycodeConverter::NativeKeycodeToDomCode([event keyCode]); |
| 793 } | 811 } |
| 794 | 812 |
| 795 DomKey DomKeyFromNSEvent(NSEvent* event) { | 813 DomKey DomKeyFromNSEvent(NSEvent* event) { |
| 796 // Apply the lookup based on the character first since that has the | 814 // Apply the lookup based on the character first since that has the |
| 797 // Keyboard layout and modifiers already applied; whereas the keyCode | 815 // Keyboard layout and modifiers already applied; whereas the keyCode |
| 798 // doesn't. | 816 // doesn't. |
| 799 if ([event type] == NSKeyDown || [event type] == NSKeyUp) { | 817 if ([event type] == NSKeyDown || [event type] == NSKeyUp) { |
| 800 // Cannot use [event characters] to check whether it's a dead key, because | 818 // Cannot use [event characters] to check whether it's a dead key, because |
| 801 // KeyUp event has the character form of the dead key in [event characters]. | 819 // KeyUp event has the character form of the dead key in [event characters]. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 &unused_is_dead_key); | 853 &unused_is_dead_key); |
| 836 } | 854 } |
| 837 if (!std::iscntrl(dom_key_char)) | 855 if (!std::iscntrl(dom_key_char)) |
| 838 return DomKeyFromCharCode(dom_key_char); | 856 return DomKeyFromCharCode(dom_key_char); |
| 839 } | 857 } |
| 840 } | 858 } |
| 841 return DomKeyFromKeyCode([event keyCode]); | 859 return DomKeyFromKeyCode([event keyCode]); |
| 842 } | 860 } |
| 843 | 861 |
| 844 } // namespace ui | 862 } // namespace ui |
| OLD | NEW |