diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 2ab284b9e150..7ca30bbe459f 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -5474,10 +5474,23 @@ GetIntegerDeltaForEvent(NSEvent* aEvent) handled = mTextInputHandler->HandleKeyDownEvent(theEvent); } - // We always allow keyboard events to propagate to keyDown: but if they are not - // handled we give special Application menu items a chance to act. + // We always allow keyboard events to propagate to keyDown: but if they are + // not handled we give menu items a chance to act. This allows for handling of + // custom shortcuts. Note that existing shortcuts cannot be reassigned yet and + // will have been handled by keyDown: before we get here. + if (!handled && mGeckoChild) { + nsCocoaWindow* widget = mGeckoChild->GetXULWindowWidget(); + if (widget) { + nsMenuBarX* mb = widget->GetMenuBar(); + if (mb) { + // Check if main menu wants to handle the event. + handled = mb->PerformKeyEquivalent(theEvent); + } + } + } if (!handled && sApplicationMenu) { - [sApplicationMenu performKeyEquivalent:theEvent]; + // Check if application menu wants to handle the event. + handled = [sApplicationMenu performKeyEquivalent:theEvent]; } NS_OBJC_END_TRY_ABORT_BLOCK; diff --git a/widget/cocoa/nsMenuBarX.h b/widget/cocoa/nsMenuBarX.h index f976ce4a665c..ea20b1285709 100644 --- a/widget/cocoa/nsMenuBarX.h +++ b/widget/cocoa/nsMenuBarX.h @@ -47,6 +47,7 @@ protected: @interface GeckoNSMenu : NSMenu { } +- (BOOL)performSuperKeyEquivalent:(NSEvent*)theEvent; @end // Objective-C class used as action target for menu items @@ -119,6 +120,7 @@ public: static void ResetNativeApplicationMenu(); void SetNeedsRebuild(); void ApplicationMenuOpened(); + bool PerformKeyEquivalent(NSEvent* theEvent); protected: void ConstructNativeMenus(); diff --git a/widget/cocoa/nsMenuBarX.mm b/widget/cocoa/nsMenuBarX.mm index e4f8c748f2e5..97fe4c1a7425 100644 --- a/widget/cocoa/nsMenuBarX.mm +++ b/widget/cocoa/nsMenuBarX.mm @@ -527,6 +527,11 @@ void nsMenuBarX::ApplicationMenuOpened() } } +bool nsMenuBarX::PerformKeyEquivalent(NSEvent* theEvent) +{ + return [mNativeMenu performSuperKeyEquivalent:theEvent]; +} + // Hide the item in the menu by setting the 'hidden' attribute. Returns it in |outHiddenNode| so // the caller can hang onto it if they so choose. It is acceptable to pass nsull // for |outHiddenNode| if the caller doesn't care about the hidden node. @@ -876,6 +881,11 @@ static BOOL gMenuItemsExecuteCommands = YES; return NO; } +- (BOOL)performSuperKeyEquivalent:(NSEvent*)theEvent +{ + return [super performKeyEquivalent:theEvent]; +} + @end //