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