Commit 2fc6dc8c authored by erikchen's avatar erikchen Committed by Commit Bot

macOS: Treat cmd + '+' as cmd + '1' on Czech keyboard layouts.

This results in more intuitive behavior of Chrome with respect to tab switching
shortcuts.

Bug: 889424
Change-Id: I1ccba5141a3ddbfd2391d2d40e0d5884b50a382f
Reviewed-on: https://chromium-review.googlesource.com/1259244Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596288}
parent d467a6a9
...@@ -19,5 +19,6 @@ ...@@ -19,5 +19,6 @@
// Used by tests to set internal state without having to change global input // Used by tests to set internal state without having to change global input
// source. // source.
void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty); void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty);
void SetIsInputSourceCzechForTesting(bool is_czech);
#endif // CHROME_BROWSER_UI_COCOA_NSMENUITEM_ADDITIONS_H_ #endif // CHROME_BROWSER_UI_COCOA_NSMENUITEM_ADDITIONS_H_
...@@ -12,12 +12,17 @@ ...@@ -12,12 +12,17 @@
namespace { namespace {
bool g_is_input_source_dvorak_qwerty = false; bool g_is_input_source_dvorak_qwerty = false;
bool g_is_input_source_czech = false;
} // namespace } // namespace
void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) { void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
g_is_input_source_dvorak_qwerty = is_dvorak_qwerty; g_is_input_source_dvorak_qwerty = is_dvorak_qwerty;
} }
void SetIsInputSourceCzechForTesting(bool is_czech) {
g_is_input_source_czech = is_czech;
}
@interface KeyboardInputSourceListener : NSObject @interface KeyboardInputSourceListener : NSObject
@end @end
...@@ -47,6 +52,9 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) { ...@@ -47,6 +52,9 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
inputSource.get(), kTISPropertyInputSourceID); inputSource.get(), kTISPropertyInputSourceID);
g_is_input_source_dvorak_qwerty = g_is_input_source_dvorak_qwerty =
[inputSourceID isEqualToString:@"com.apple.keylayout.DVORAK-QWERTYCMD"]; [inputSourceID isEqualToString:@"com.apple.keylayout.DVORAK-QWERTYCMD"];
g_is_input_source_czech =
[inputSourceID rangeOfString:@"com.apple.keylayout.Czech"].location !=
NSNotFound;
} }
- (void)inputSourceDidChange:(NSNotification*)notification { - (void)inputSourceDidChange:(NSNotification*)notification {
...@@ -165,6 +173,17 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) { ...@@ -165,6 +173,17 @@ void SetIsInputSourceDvorakQwertyForTesting(bool is_dvorak_qwerty) {
NSAlternateKeyMask | NSAlternateKeyMask |
NSShiftKeyMask; NSShiftKeyMask;
// On Czech keyboards, we want to interpret cmd + '+' as cmd + '1'.
// htts://crbug.com/889424. We don't need special handling for other numeric
// keys because they produce non-ASCII characters, and we already have logic
// that ignores non-ASCII characters in favor of modified characters.
if (g_is_input_source_czech) {
if (eventModifiers == NSCommandKeyMask &&
[eventString isEqualToString:@"+"]) {
eventString = @"1";
}
}
return [eventString isEqualToString:[self keyEquivalent]] return [eventString isEqualToString:[self keyEquivalent]]
&& eventModifiers == [self keyEquivalentModifierMask]; && eventModifiers == [self keyEquivalentModifierMask];
} }
......
...@@ -331,6 +331,17 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) { ...@@ -331,6 +331,17 @@ TEST(NSMenuItemAdditionsTest, TestFiresForKeyEvent) {
/*compareCocoa=*/false); /*compareCocoa=*/false);
ExpectKeyFiresItem(key, MenuItem(@"T", NSCommandKeyMask), ExpectKeyFiresItem(key, MenuItem(@"T", NSCommandKeyMask),
/*compareCocoa=*/false); /*compareCocoa=*/false);
// On Czech layout, cmd + '+' should instead trigger cmd + '1'.
key = KeyEvent(0x100108, @"1", @"+", 18);
ExpectKeyDoesntFireItem(key, MenuItem(@"1", NSCommandKeyMask),
/*compareCocoa=*/false);
SetIsInputSourceCzechForTesting(true);
ExpectKeyFiresItem(key, MenuItem(@"1", NSCommandKeyMask),
/*compareCocoa=*/false);
SetIsInputSourceCzechForTesting(false);
ExpectKeyDoesntFireItem(key, MenuItem(@"1", NSCommandKeyMask),
/*compareCocoa=*/false);
} }
NSString* keyCodeToCharacter(NSUInteger keyCode, 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