Index: chrome/browser/cocoa/chrome_browser_window.mm |
diff --git a/chrome/browser/cocoa/chrome_browser_window.mm b/chrome/browser/cocoa/chrome_browser_window.mm |
index 4f2f8594152c5b7d8f10da566cafa19ac26d314a..a6df8d50fb6ab3463dcbab55637eed95762ce070 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]; |
pink (ping after 24hrs)
2009/10/09 14:36:51
what happens when the renderer is hung? Does that
Nico
2009/10/09 16:50:06
Yes, that will work once BrowserWindowCocoa::GetCo
|
+ 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]; |
} |