OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /* | 5 /* |
6 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 6 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
7 * Copyright (C) 2006-2009 Google Inc. | 7 * Copyright (C) 2006-2009 Google Inc. |
8 * | 8 * |
9 * Redistribution and use in source and binary forms, with or without | 9 * Redistribution and use in source and binary forms, with or without |
10 * modification, are permitted provided that the following conditions | 10 * modification, are permitted provided that the following conditions |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 case 62: // Right Ctrl | 110 case 62: // Right Ctrl |
111 return IsModifierKeyUp([event modifierFlags], kRightControlKeyMask, | 111 return IsModifierKeyUp([event modifierFlags], kRightControlKeyMask, |
112 kLeftControlKeyMask, NSControlKeyMask); | 112 kLeftControlKeyMask, NSControlKeyMask); |
113 | 113 |
114 case 63: // Function | 114 case 63: // Function |
115 return ([event modifierFlags] & NSFunctionKeyMask) == 0; | 115 return ([event modifierFlags] & NSFunctionKeyMask) == 0; |
116 } | 116 } |
117 return false; | 117 return false; |
118 } | 118 } |
119 | 119 |
120 inline NSString* FilterSpecialCharacter(NSString* str) { | |
121 if ([str length] != 1) | |
122 return str; | |
123 unichar c = [str characterAtIndex:0]; | |
124 NSString* result = str; | |
125 if (c == 0x7F) | |
126 // Backspace should be 8 | |
dtapuska
2015/12/11 16:20:30
I'd assume you have braces here because the code f
| |
127 result = @"\x8"; | |
128 else if (c == NSDeleteFunctionKey) | |
129 // Delete should be 0x7F | |
130 result = @"\x7F"; | |
131 else if (c >= 0xF700 && c <= 0xF7FF) | |
132 // Mac private use characters should be @"\0" (@"" won't work) | |
133 // Use the range 0xF700~0xF7FF to match | |
134 // http://www.opensource.apple.com/source/WebCore/WebCore-7601.1.55/platform /mac/KeyEventMac.mm | |
135 result = @"\0"; | |
136 return result; | |
137 } | |
138 | |
120 inline NSString* TextFromEvent(NSEvent* event) { | 139 inline NSString* TextFromEvent(NSEvent* event) { |
121 if ([event type] == NSFlagsChanged) | 140 if ([event type] == NSFlagsChanged) |
122 return @""; | 141 return @""; |
123 return [event characters]; | 142 return FilterSpecialCharacter([event characters]); |
124 } | 143 } |
125 | 144 |
126 inline NSString* UnmodifiedTextFromEvent(NSEvent* event) { | 145 inline NSString* UnmodifiedTextFromEvent(NSEvent* event) { |
127 if ([event type] == NSFlagsChanged) | 146 if ([event type] == NSFlagsChanged) |
128 return @""; | 147 return @""; |
129 return [event charactersIgnoringModifiers]; | 148 return FilterSpecialCharacter([event charactersIgnoringModifiers]); |
130 } | 149 } |
131 | 150 |
132 NSString* KeyIdentifierForKeyEvent(NSEvent* event) { | 151 NSString* KeyIdentifierForKeyEvent(NSEvent* event) { |
133 if ([event type] == NSFlagsChanged) { | 152 if ([event type] == NSFlagsChanged) { |
134 switch ([event keyCode]) { | 153 switch ([event keyCode]) { |
135 case 54: // Right Command | 154 case 54: // Right Command |
136 case 55: // Left Command | 155 case 55: // Left Command |
137 return @"Meta"; | 156 return @"Meta"; |
138 | 157 |
139 case 57: // Capslock | 158 case 57: // Capslock |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
607 | 626 |
608 // Begin Apple code, copied from KeyEventMac.mm | 627 // Begin Apple code, copied from KeyEventMac.mm |
609 | 628 |
610 // Always use 13 for Enter/Return -- we don't want to use AppKit's | 629 // Always use 13 for Enter/Return -- we don't want to use AppKit's |
611 // different character for Enter. | 630 // different character for Enter. |
612 if (result.windowsKeyCode == '\r') { | 631 if (result.windowsKeyCode == '\r') { |
613 text_str = @"\r"; | 632 text_str = @"\r"; |
614 unmodified_str = @"\r"; | 633 unmodified_str = @"\r"; |
615 } | 634 } |
616 | 635 |
617 // The adjustments below are only needed in backward compatibility mode, | |
618 // but we cannot tell what mode we are in from here. | |
619 | |
620 // Turn 0x7F into 8, because backspace needs to always be 8. | |
621 if ([text_str isEqualToString:@"\x7F"]) | |
622 text_str = @"\x8"; | |
623 if ([unmodified_str isEqualToString:@"\x7F"]) | |
624 unmodified_str = @"\x8"; | |
625 // Always use 9 for tab -- we don't want to use AppKit's different character | 636 // Always use 9 for tab -- we don't want to use AppKit's different character |
626 // for shift-tab. | 637 // for shift-tab. |
627 if (result.windowsKeyCode == 9) { | 638 if (result.windowsKeyCode == 9) { |
628 text_str = @"\x9"; | 639 text_str = @"\x9"; |
629 unmodified_str = @"\x9"; | 640 unmodified_str = @"\x9"; |
630 } | 641 } |
631 | 642 |
632 // End Apple code. | 643 // End Apple code. |
633 | 644 |
634 if ([text_str length] < blink::WebKeyboardEvent::textLengthCap && | 645 if ([text_str length] < blink::WebKeyboardEvent::textLengthCap && |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
918 break; | 929 break; |
919 default: | 930 default: |
920 NOTIMPLEMENTED(); | 931 NOTIMPLEMENTED(); |
921 result.type = blink::WebInputEvent::Undefined; | 932 result.type = blink::WebInputEvent::Undefined; |
922 } | 933 } |
923 | 934 |
924 return result; | 935 return result; |
925 } | 936 } |
926 | 937 |
927 } // namespace content | 938 } // namespace content |
OLD | NEW |