Commit 30e11c9e authored by erikchen's avatar erikchen Committed by Commit Bot

macOS: Process uppercase keyEquivalents for non-ascii characters.

The logic in NSMenuItem(ChromeAdditions) attempts to mimic Cocoa's logic for
determining whether a NSMenuItem will fire for a given NSEvent.

In keyboard layouts that produce non-ascii characters, Cocoa uses the event's
"characters" property to process keyEquivalents, and will manually apply the
shift modifier if necessary. Our logic was failing to do so. This meant that key
combinations such as [cmd + shift + t] on 2-Set Korean would attempt to match a
NSMenuItem with keyEquivalent "t" rather than a NSMenuItem with keyEquivalent
"T".

Bug: 889970
Change-Id: I81fdf11c4ffa6322d78e981cdbff6956cd8f4b79
Reviewed-on: https://chromium-review.googlesource.com/1254462Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595453}
parent 15a90436
......@@ -118,9 +118,14 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
// there, let's try a pragmatic hack.
if ([eventString characterAtIndex:0] > 0x7f &&
[[event characters] length] > 0 &&
[[event characters] characterAtIndex:0] <= 0x7f)
[[event characters] characterAtIndex:0] <= 0x7f) {
eventString = [event characters];
// Process the shift if necessary.
if (eventModifiers & NSShiftKeyMask)
eventString = [eventString uppercaseString];
}
// We intentionally leak this object.
static __attribute__((unused)) KeyboardInputSourceListener* listener =
[[KeyboardInputSourceListener alloc] init];
......
......@@ -316,6 +316,21 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) {
key = KeyEvent(0x60103, @"\x19", @"\x19", 1);
ExpectKeyFiresItem(key, MenuItem(@"\x9", NSShiftKeyMask | NSControlKeyMask),
false);
// In 2-set Korean layout, (cmd + shift + t) and (cmd + t) both produce
// multi-byte unmodified chars. For keyEquivalent purposes, we use their
// raw characters, where "shift" should be handled correctly.
key = KeyEvent(0x100108, @"t", @"\u3145", 17);
ExpectKeyFiresItem(key, MenuItem(@"t", NSCommandKeyMask),
/*compareCocoa=*/false);
ExpectKeyDoesntFireItem(key, MenuItem(@"T", NSCommandKeyMask),
/*compareCocoa=*/false);
key = KeyEvent(0x12010a, @"t", @"\u3146", 17);
ExpectKeyDoesntFireItem(key, MenuItem(@"t", NSCommandKeyMask),
/*compareCocoa=*/false);
ExpectKeyFiresItem(key, MenuItem(@"T", NSCommandKeyMask),
/*compareCocoa=*/false);
}
NSString* keyCodeToCharacter(NSUInteger keyCode,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment