summaryrefslogtreecommitdiffstats
path: root/chrome/browser/global_keyboard_shortcuts_mac.mm
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-09 01:26:20 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-09 01:26:20 +0000
commit1d313b83ae291b6372a0824c57180fa1d5f36a9d (patch)
tree6ef4c7260d9bebefc40bcdf3b0ec1a3de43962ac /chrome/browser/global_keyboard_shortcuts_mac.mm
parentbe52be15450fd01fea3044267449d15560c29fe1 (diff)
downloadchromium_src-1d313b83ae291b6372a0824c57180fa1d5f36a9d.zip
chromium_src-1d313b83ae291b6372a0824c57180fa1d5f36a9d.tar.gz
chromium_src-1d313b83ae291b6372a0824c57180fa1d5f36a9d.tar.bz2
Support cmd-left/right for history.
Since cmd-left/right should not do history if the omnibox is focussed, but cmd-1-9 should work if the omnibox is focussed, we have to differentiate between window- and browser-level shortcuts. (Because performKeyEquivalent bubbles up from the window -- and if we let it bubble up to the omnibox, then the omnibox handles cmd-left/right just fine, but it swallows cmd-1 and doesn't give us a chance to intercept this. That means cmd-left doesn't work if you hit cmd-l tab, which focusses something that's neither omnibox nor tab contents. This behavior is consistent with safari and camino, and I think it's the best we can do without rewriting event dispatching. Camino does this here: http://mxr.mozilla.org/seamonkey/source/camino/src/browser/BrowserWindow.mm#128 http://mxr.mozilla.org/seamonkey/source/camino/src/browser/BrowserWrapper.mm#1031 ) BUG=12557 TEST=Focus text box on a web page. cmd-left/right should go to start/end of text. Focus webpage background. cmd-left/right \ should go history back/forward. When the omnibox is focussed, cmd-left/right should move the caret, but cmd-1-9 should still switch tabs. Note that shortcuts still don't work if a subwindow (e.g. find bar, bookmark bubble) has focus. Review URL: http://codereview.chromium.org/251069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/global_keyboard_shortcuts_mac.mm')
-rw-r--r--chrome/browser/global_keyboard_shortcuts_mac.mm41
1 files changed, 32 insertions, 9 deletions
diff --git a/chrome/browser/global_keyboard_shortcuts_mac.mm b/chrome/browser/global_keyboard_shortcuts_mac.mm
index 63982ef..d74f935 100644
--- a/chrome/browser/global_keyboard_shortcuts_mac.mm
+++ b/chrome/browser/global_keyboard_shortcuts_mac.mm
@@ -9,7 +9,8 @@
#include "base/basictypes.h"
#include "chrome/app/chrome_dll_resource.h"
-const KeyboardShortcutData* GetKeyboardShortCutTable(size_t* num_entries) {
+const KeyboardShortcutData* GetWindowKeyboardShortcutTable
+ (size_t* num_entries) {
static const KeyboardShortcutData keyboard_shortcuts[] = {
{true, true, false, kVK_ANSI_RightBracket, IDC_SELECT_NEXT_TAB},
{false, false, true, kVK_PageDown, IDC_SELECT_NEXT_TAB},
@@ -27,11 +28,6 @@ const KeyboardShortcutData* GetKeyboardShortCutTable(size_t* num_entries) {
{true, false, false, kVK_ANSI_7, IDC_SELECT_TAB_6},
{true, false, false, kVK_ANSI_8, IDC_SELECT_TAB_7},
{true, false, false, kVK_ANSI_9, IDC_SELECT_LAST_TAB},
- // TODO(pinkerton): These can't live here yet, they need to be plumbed
- // through the renderer first so it can override if in a text field.
- // http://crbug.com/12557
- // {true, false, false, kVK_LeftArrow, IDC_BACK},
- // {true, false, false, kVK_RightArrow, IDC_FORWARD},
};
*num_entries = arraysize(keyboard_shortcuts);
@@ -39,8 +35,21 @@ const KeyboardShortcutData* GetKeyboardShortCutTable(size_t* num_entries) {
return keyboard_shortcuts;
}
-int CommandForKeyboardShortcut(bool command_key, bool shift_key, bool cntrl_key,
- int vkey_code) {
+const KeyboardShortcutData* GetBrowserKeyboardShortcutTable
+ (size_t* num_entries) {
+ static const KeyboardShortcutData keyboard_shortcuts[] = {
+ {true, false, false, kVK_LeftArrow, IDC_BACK},
+ {true, false, false, kVK_RightArrow, IDC_FORWARD},
+ };
+
+ *num_entries = arraysize(keyboard_shortcuts);
+
+ return keyboard_shortcuts;
+}
+
+static int CommandForKeyboardShortcut(
+ const KeyboardShortcutData* (*get_keyboard_shortcut_table)(size_t*),
+ bool command_key, bool shift_key, bool cntrl_key, int vkey_code) {
// Scan through keycodes and see if it corresponds to one of the global
// shortcuts on file.
@@ -48,7 +57,7 @@ int CommandForKeyboardShortcut(bool command_key, bool shift_key, bool cntrl_key,
// TODO(jeremy): Change this into a hash table once we get enough
// entries in the array to make a difference.
size_t num_shortcuts = 0;
- const KeyboardShortcutData *it = GetKeyboardShortCutTable(&num_shortcuts);
+ const KeyboardShortcutData *it = get_keyboard_shortcut_table(&num_shortcuts);
for (size_t i = 0; i < num_shortcuts; ++i, ++it) {
if (it->command_key == command_key &&
it->shift_key == shift_key &&
@@ -60,3 +69,17 @@ int CommandForKeyboardShortcut(bool command_key, bool shift_key, bool cntrl_key,
return -1;
}
+
+int CommandForWindowKeyboardShortcut(
+ bool command_key, bool shift_key, bool cntrl_key, int vkey_code) {
+ return CommandForKeyboardShortcut(GetWindowKeyboardShortcutTable,
+ command_key, shift_key,
+ cntrl_key, vkey_code);
+}
+
+int CommandForBrowserKeyboardShortcut(
+ bool command_key, bool shift_key, bool cntrl_key, int vkey_code) {
+ return CommandForKeyboardShortcut(GetBrowserKeyboardShortcutTable,
+ command_key, shift_key,
+ cntrl_key, vkey_code);
+}