summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
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/cocoa
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/cocoa')
-rw-r--r--chrome/browser/cocoa/chrome_browser_window.h10
-rw-r--r--chrome/browser/cocoa/chrome_browser_window.mm32
2 files changed, 40 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/chrome_browser_window.h b/chrome/browser/cocoa/chrome_browser_window.h
index fb14b28..9130616 100644
--- a/chrome/browser/cocoa/chrome_browser_window.h
+++ b/chrome/browser/cocoa/chrome_browser_window.h
@@ -15,6 +15,16 @@
BOOL shouldHideTitle_;
}
+// See global_keyboard_shortcuts_mac.h for details on the next two functions.
+
+// Checks if |event| is a window keyboard shortcut. If so, dispatches it to the
+// window controller's |executeCommand:| and returns |YES|.
+- (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event;
+
+// Checks if |event| is a browser keyboard shortcut. If so, dispatches it to the
+// window controller's |executeCommand:| and returns |YES|.
+- (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event;
+
// Override, so we can handle global keyboard events.
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent;
diff --git a/chrome/browser/cocoa/chrome_browser_window.mm b/chrome/browser/cocoa/chrome_browser_window.mm
index 4f2f859..a6df8d5 100644
--- a/chrome/browser/cocoa/chrome_browser_window.mm
+++ b/chrome/browser/cocoa/chrome_browser_window.mm
@@ -6,11 +6,15 @@
#include "base/logging.h"
#import "chrome/browser/cocoa/browser_window_controller.h"
+#import "chrome/browser/renderer_host/render_widget_host_view_mac.h"
#include "chrome/browser/global_keyboard_shortcuts_mac.h"
+typedef int (*KeyToCommandMapper)(bool, bool, bool, int);
+
@implementation ChromeBrowserWindow
-- (BOOL)performKeyEquivalent:(NSEvent*)event {
+- (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event fromTable:
+ (KeyToCommandMapper)commandForKeyboardShortcut {
// Extract info from |event|.
NSUInteger modifers = [event modifierFlags];
const bool cmdKey = modifers & NSCommandKeyMask;
@@ -18,7 +22,7 @@
const bool cntrlKey = modifers & NSControlKeyMask;
const int keyCode = [event keyCode];
- int cmdNum = CommandForKeyboardShortcut(cmdKey, shiftKey, cntrlKey,
+ int cmdNum = commandForKeyboardShortcut(cmdKey, shiftKey, cntrlKey,
keyCode);
BrowserWindowController* controller =
@@ -31,7 +35,31 @@
[controller executeCommand:cmdNum];
return YES;
}
+ return NO;
+}
+
+- (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event {
+ return [self handleExtraKeyboardShortcut:event
+ fromTable:CommandForWindowKeyboardShortcut];
+}
+- (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event {
+ return [self handleExtraKeyboardShortcut:event
+ fromTable:CommandForBrowserKeyboardShortcut];
+}
+
+- (BOOL)performKeyEquivalent:(NSEvent*)event {
+ // Give the web site a chance to handle the event. If it doesn't want to
+ // handle it, it will call us back with one of the |handle*| methods above.
+ NSResponder* r = [self firstResponder];
+ if ([r isKindOfClass:[RenderWidgetHostViewCocoa class]])
+ return [r performKeyEquivalent:event];
+
+ // Handle per-window shortcuts like cmd-1, but do not handle browser-level
+ // shortcuts like cmd-left (else, cmd-left would do history navigation even
+ // if e.g. the Omnibox has focus).
+ if ([self handleExtraWindowKeyboardShortcut:event])
+ return YES;
return [super performKeyEquivalent:event];
}