Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Unified Diff: ui/base/test/ui_controls_mac.mm

Issue 856313003: Mac: Refine ui_controls_mac's SynthesizeKeyEvent() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/events/keycodes/keyboard_code_conversion_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | ui/events/keycodes/keyboard_code_conversion_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698