| Index: ui/base/test/ui_controls_mac.mm
|
| diff --git a/ui/base/test/ui_controls_mac.mm b/ui/base/test/ui_controls_mac.mm
|
| index 1308de0cb4f0309db17f0b4ab74b2477704e7e6e..5689518ec399e3ffdfa0ed61a73a6e950db59f03 100644
|
| --- a/ui/base/test/ui_controls_mac.mm
|
| +++ b/ui/base/test/ui_controls_mac.mm
|
| @@ -96,13 +96,29 @@ NSEvent* SynthesizeKeyEvent(NSWindow* window,
|
| // Note that, in line with AppKit's documentation (and tracing "real" events),
|
| // -[NSEvent charactersIngoringModifiers]" are "the characters generated by
|
| // the receiving key event as if no modifier key (except for Shift)".
|
| - // So |charactersIgnoringModifiers| uses |shifted_characters|, while
|
| - // |characters| uses keyboard characters.
|
| + // So |charactersIgnoringModifiers| uses |shifted_character|.
|
| NSString* charactersIgnoringModifiers =
|
| [[[NSString alloc] initWithCharacters:&shifted_character
|
| length:1] autorelease];
|
| - NSString* characters =
|
| - [[[NSString alloc] initWithCharacters:&character length:1] autorelease];
|
| + NSString* characters;
|
| + // The following were determined empirically on OSX 10.9.
|
| + if (flags & NSControlKeyMask) {
|
| + // If Ctrl is pressed, Cocoa always puts an empty string into |characters|.
|
| + characters = [NSString string];
|
| + } else if (flags & NSCommandKeyMask) {
|
| + // If Cmd is pressed, Cocoa puts a lowercase character into |characters|,
|
| + // regardless of Shift. If, however, Alt is also pressed then shift *is*
|
| + // preserved, but re-mappings for Alt are not implemented. Although we still
|
| + // need to support Alt for things like Alt+Left/Right which don't care.
|
| + characters =
|
| + [[[NSString alloc] initWithCharacters:&character length:1] autorelease];
|
| + } else {
|
| + // If just Shift or nothing is pressed, |characters| will match
|
| + // |charactersIgnoringModifiers|. Alt puts a special character into
|
| + // |characters| (not |charactersIgnoringModifiers|), but they're not mapped
|
| + // here.
|
| + characters = charactersIgnoringModifiers;
|
| + }
|
|
|
| NSEventType type = (keyDown ? NSKeyDown : NSKeyUp);
|
|
|
| @@ -115,17 +131,16 @@ NSEvent* SynthesizeKeyEvent(NSWindow* window,
|
| // For events other than mouse moved, [event locationInWindow] is
|
| // UNDEFINED if the event is not NSMouseMoved. Thus, the (0,0)
|
| // location should be fine.
|
| - NSEvent* event =
|
| - [NSEvent keyEventWithType:type
|
| - location:NSZeroPoint
|
| - modifierFlags:flags
|
| - timestamp:TimeIntervalSinceSystemStartup()
|
| - windowNumber:[window windowNumber]
|
| - context:nil
|
| - characters:characters
|
| - charactersIgnoringModifiers:charactersIgnoringModifiers
|
| - isARepeat:NO
|
| - keyCode:(unsigned short)macKeycode];
|
| + NSEvent* event = [NSEvent keyEventWithType:type
|
| + location:NSZeroPoint
|
| + modifierFlags:flags
|
| + timestamp:TimeIntervalSinceSystemStartup()
|
| + windowNumber:[window windowNumber]
|
| + context:nil
|
| + characters:characters
|
| + charactersIgnoringModifiers:charactersIgnoringModifiers
|
| + isARepeat:NO
|
| + keyCode:(unsigned short)macKeycode];
|
|
|
| return event;
|
| }
|
|
|