Index: chrome/browser/ui/cocoa/chrome_event_processing_window.mm |
diff --git a/chrome/browser/ui/cocoa/chrome_event_processing_window.mm b/chrome/browser/ui/cocoa/chrome_event_processing_window.mm |
index b7b437d923f67200e1a961bb126a05312fb709a3..6c9e275d56264149f1f2445281f8c0a6e1a6a6d2 100644 |
--- a/chrome/browser/ui/cocoa/chrome_event_processing_window.mm |
+++ b/chrome/browser/ui/cocoa/chrome_event_processing_window.mm |
@@ -6,12 +6,14 @@ |
#include "base/logging.h" |
#import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h" |
+#import "ui/base/cocoa/user_interface_item_command_handler.h" |
@implementation ChromeEventProcessingWindow { |
@private |
base::scoped_nsobject<CommandDispatcher> commandDispatcher_; |
base::scoped_nsobject<ChromeCommandDispatcherDelegate> |
commandDispatcherDelegate_; |
+ base::scoped_nsprotocol<id<UserInterfaceItemCommandHandler>> commandHandler_; |
} |
- (instancetype)initWithContentRect:(NSRect)contentRect |
@@ -37,6 +39,10 @@ |
// CommandDispatchingWindow implementation. |
+- (void)setCommandHandler:(id<UserInterfaceItemCommandHandler>)commandHandler { |
+ commandHandler_.reset([commandHandler retain]); |
+} |
+ |
- (BOOL)redispatchKeyEvent:(NSEvent*)event { |
return [commandDispatcher_ redispatchKeyEvent:event]; |
} |
@@ -45,6 +51,14 @@ |
return [super performKeyEquivalent:event]; |
} |
+- (void)commandDispatch:(id)sender { |
+ [commandHandler_ commandDispatch:sender window:self]; |
+} |
+ |
+- (void)commandDispatchUsingKeyModifiers:(id)sender { |
+ [commandHandler_ commandDispatchUsingKeyModifiers:sender window:self]; |
+} |
+ |
// NSWindow overrides. |
- (BOOL)performKeyEquivalent:(NSEvent*)event { |
@@ -56,4 +70,20 @@ |
[super sendEvent:event]; |
} |
+// NSWindow overrides (NSUserInterfaceValidations implementation). |
+ |
+- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
+ // Since this class implements these selectors, |super| will always say they |
+ // are enabled. Only use [super] to validate other selectors. If there is no |
+ // command handler, defer to AppController. |
+ if ([item action] == @selector(commandDispatch:) || |
+ [item action] == @selector(commandDispatchUsingKeyModifiers:)) { |
+ return commandHandler_ |
+ ? [commandHandler_ validateUserInterfaceItem:item window:self] |
+ : [[NSApp delegate] validateUserInterfaceItem:item]; |
+ } |
+ |
+ return [super validateUserInterfaceItem:item]; |
+} |
+ |
@end // ChromeEventProcessingWindow |