diff options
author | Ben Murdoch <benm@google.com> | 2010-11-25 19:40:10 +0000 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-12-03 13:52:53 +0000 |
commit | 4a5e2dc747d50c653511c68ccb2cfbfb740bd5a7 (patch) | |
tree | 938665d93a11fe7a6d0124e3c1e020d1f9d3f947 /chrome/browser/global_keyboard_shortcuts_mac.mm | |
parent | 7c627d87728a355737862918d144f98f69406954 (diff) | |
download | external_chromium-4a5e2dc747d50c653511c68ccb2cfbfb740bd5a7.zip external_chromium-4a5e2dc747d50c653511c68ccb2cfbfb740bd5a7.tar.gz external_chromium-4a5e2dc747d50c653511c68ccb2cfbfb740bd5a7.tar.bz2 |
Merge Chromium at r66597: Initial merge by git.
Change-Id: I9639f8a997f90ec219573aa22a49f5dbde78cc7b
Diffstat (limited to 'chrome/browser/global_keyboard_shortcuts_mac.mm')
-rw-r--r-- | chrome/browser/global_keyboard_shortcuts_mac.mm | 68 |
1 files changed, 53 insertions, 15 deletions
diff --git a/chrome/browser/global_keyboard_shortcuts_mac.mm b/chrome/browser/global_keyboard_shortcuts_mac.mm index 6e3f206..cc5ba64 100644 --- a/chrome/browser/global_keyboard_shortcuts_mac.mm +++ b/chrome/browser/global_keyboard_shortcuts_mac.mm @@ -31,15 +31,24 @@ const KeyboardShortcutData* GetWindowKeyboardShortcutTable {false, false, true, false, kVK_PageUp, 0, IDC_SELECT_PREVIOUS_TAB}, {false, true, true, false, kVK_Tab, 0, IDC_SELECT_PREVIOUS_TAB}, // Cmd-0..8 select the Nth tab, with cmd-9 being "last tab". - {true, false, false, false, kVK_ANSI_1, 0, IDC_SELECT_TAB_0}, - {true, false, false, false, kVK_ANSI_2, 0, IDC_SELECT_TAB_1}, - {true, false, false, false, kVK_ANSI_3, 0, IDC_SELECT_TAB_2}, - {true, false, false, false, kVK_ANSI_4, 0, IDC_SELECT_TAB_3}, - {true, false, false, false, kVK_ANSI_5, 0, IDC_SELECT_TAB_4}, - {true, false, false, false, kVK_ANSI_6, 0, IDC_SELECT_TAB_5}, - {true, false, false, false, kVK_ANSI_7, 0, IDC_SELECT_TAB_6}, - {true, false, false, false, kVK_ANSI_8, 0, IDC_SELECT_TAB_7}, - {true, false, false, false, kVK_ANSI_9, 0, IDC_SELECT_LAST_TAB}, + {true, false, false, false, kVK_ANSI_1, 0, IDC_SELECT_TAB_0}, + {true, false, false, false, kVK_ANSI_Keypad1, 0, IDC_SELECT_TAB_0}, + {true, false, false, false, kVK_ANSI_2, 0, IDC_SELECT_TAB_1}, + {true, false, false, false, kVK_ANSI_Keypad2, 0, IDC_SELECT_TAB_1}, + {true, false, false, false, kVK_ANSI_3, 0, IDC_SELECT_TAB_2}, + {true, false, false, false, kVK_ANSI_Keypad3, 0, IDC_SELECT_TAB_2}, + {true, false, false, false, kVK_ANSI_4, 0, IDC_SELECT_TAB_3}, + {true, false, false, false, kVK_ANSI_Keypad4, 0, IDC_SELECT_TAB_3}, + {true, false, false, false, kVK_ANSI_5, 0, IDC_SELECT_TAB_4}, + {true, false, false, false, kVK_ANSI_Keypad5, 0, IDC_SELECT_TAB_4}, + {true, false, false, false, kVK_ANSI_6, 0, IDC_SELECT_TAB_5}, + {true, false, false, false, kVK_ANSI_Keypad6, 0, IDC_SELECT_TAB_5}, + {true, false, false, false, kVK_ANSI_7, 0, IDC_SELECT_TAB_6}, + {true, false, false, false, kVK_ANSI_Keypad7, 0, IDC_SELECT_TAB_6}, + {true, false, false, false, kVK_ANSI_8, 0, IDC_SELECT_TAB_7}, + {true, false, false, false, kVK_ANSI_Keypad8, 0, IDC_SELECT_TAB_7}, + {true, false, false, false, kVK_ANSI_9, 0, IDC_SELECT_LAST_TAB}, + {true, false, false, false, kVK_ANSI_Keypad9, 0, IDC_SELECT_LAST_TAB}, }; *num_entries = arraysize(keyboard_shortcuts); @@ -152,8 +161,20 @@ int CommandForBrowserKeyboardShortcut( } unichar KeyCharacterForEvent(NSEvent* event) { - const NSString* eventString = [event charactersIgnoringModifiers]; - const NSString* characters = [event characters]; + NSString* eventString = [event charactersIgnoringModifiers]; + NSString* characters = [event characters]; + + // Character pairs that undergo BiDi mirrored. + // There are actually many more such pairs, but these are the ones that + // are likely to show up in keyboard shortcuts. + const struct { + unichar a; + unichar b; + } kMirroredBiDiChars[] = { + {'{', '}'}, + {'[', ']'}, + {'(', ')'}, + }; if ([eventString length] != 1) return 0; @@ -161,13 +182,30 @@ unichar KeyCharacterForEvent(NSEvent* event) { if ([characters length] != 1) return [eventString characterAtIndex:0]; + unichar noModifiersChar = [eventString characterAtIndex:0]; + unichar rawChar = [characters characterAtIndex:0]; // When both |characters| and |charactersIgnoringModifiers| are ascii, // return the first character of |characters|, if... - if (isascii([eventString characterAtIndex:0]) && - isascii([characters characterAtIndex:0])) { + if (isascii(noModifiersChar) && isascii(rawChar)) { // |characters| is an alphabet (mainly for dvorak-qwerty layout), or - if (isalpha([characters characterAtIndex:0])) - return [characters characterAtIndex:0]; + if (isalpha(rawChar)) + return rawChar; + + // http://crbug.com/42517 + // In RTL keyboard layouts, Cocoa mirrors characters in the string + // returned by [event charactersIgnoringModifiers]. In this case, return + // the raw (unmirrored) char. + // FIXME: If there is a need to add any more characters to the + // kMirroredBiDiChars table, then it's probably better to use ICU's + // u_charMirror() function to perform this test. + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kMirroredBiDiChars); ++i) { + const unichar& a = kMirroredBiDiChars[i].a; + const unichar& b = kMirroredBiDiChars[i].b; + if ((rawChar == a && noModifiersChar == b) || + (rawChar == b && noModifiersChar == a)) + return rawChar; + } + // opt/alt modifier is set (e.g. on german layout we want '{' for opt-8). if ([event modifierFlags] & NSAlternateKeyMask) return [characters characterAtIndex:0]; |