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 | |
127 result = @"\x8"; | |
128 } else if (c >= 0xF700 && c <= 0xF7FF) { | |
129 // Mac private use characters should be @"\0" (@"" won't work) | |
130 // NSDeleteFunctionKey will also go into here | |
131 // Use the range 0xF700~0xF7FF to match | |
132 // http://www.opensource.apple.com/source/WebCore/WebCore-7601.1.55/platform
/mac/KeyEventMac.mm | |
133 result = @"\0"; | |
134 } | |
135 return result; | |
136 } | |
137 | |
138 inline NSString* TextFromEvent(NSEvent* event) { | 120 inline NSString* TextFromEvent(NSEvent* event) { |
139 if ([event type] == NSFlagsChanged) | 121 if ([event type] == NSFlagsChanged) |
140 return @""; | 122 return @""; |
141 return FilterSpecialCharacter([event characters]); | 123 return [event characters]; |
142 } | 124 } |
143 | 125 |
144 inline NSString* UnmodifiedTextFromEvent(NSEvent* event) { | 126 inline NSString* UnmodifiedTextFromEvent(NSEvent* event) { |
145 if ([event type] == NSFlagsChanged) | 127 if ([event type] == NSFlagsChanged) |
146 return @""; | 128 return @""; |
147 return FilterSpecialCharacter([event charactersIgnoringModifiers]); | 129 return [event charactersIgnoringModifiers]; |
148 } | 130 } |
149 | 131 |
150 NSString* KeyIdentifierForKeyEvent(NSEvent* event) { | 132 NSString* KeyIdentifierForKeyEvent(NSEvent* event) { |
151 if ([event type] == NSFlagsChanged) { | 133 if ([event type] == NSFlagsChanged) { |
152 switch ([event keyCode]) { | 134 switch ([event keyCode]) { |
153 case 54: // Right Command | 135 case 54: // Right Command |
154 case 55: // Left Command | 136 case 55: // Left Command |
155 return @"Meta"; | 137 return @"Meta"; |
156 | 138 |
157 case 57: // Capslock | 139 case 57: // Capslock |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 607 |
626 // Begin Apple code, copied from KeyEventMac.mm | 608 // Begin Apple code, copied from KeyEventMac.mm |
627 | 609 |
628 // Always use 13 for Enter/Return -- we don't want to use AppKit's | 610 // Always use 13 for Enter/Return -- we don't want to use AppKit's |
629 // different character for Enter. | 611 // different character for Enter. |
630 if (result.windowsKeyCode == '\r') { | 612 if (result.windowsKeyCode == '\r') { |
631 text_str = @"\r"; | 613 text_str = @"\r"; |
632 unmodified_str = @"\r"; | 614 unmodified_str = @"\r"; |
633 } | 615 } |
634 | 616 |
| 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"; |
635 // Always use 9 for tab -- we don't want to use AppKit's different character | 625 // Always use 9 for tab -- we don't want to use AppKit's different character |
636 // for shift-tab. | 626 // for shift-tab. |
637 if (result.windowsKeyCode == 9) { | 627 if (result.windowsKeyCode == 9) { |
638 text_str = @"\x9"; | 628 text_str = @"\x9"; |
639 unmodified_str = @"\x9"; | 629 unmodified_str = @"\x9"; |
640 } | 630 } |
641 | 631 |
642 // End Apple code. | 632 // End Apple code. |
643 | 633 |
644 if ([text_str length] < blink::WebKeyboardEvent::textLengthCap && | 634 if ([text_str length] < blink::WebKeyboardEvent::textLengthCap && |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 break; | 918 break; |
929 default: | 919 default: |
930 NOTIMPLEMENTED(); | 920 NOTIMPLEMENTED(); |
931 result.type = blink::WebInputEvent::Undefined; | 921 result.type = blink::WebInputEvent::Undefined; |
932 } | 922 } |
933 | 923 |
934 return result; | 924 return result; |
935 } | 925 } |
936 | 926 |
937 } // namespace content | 927 } // namespace content |
OLD | NEW |