Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: ui/views/cocoa/native_widget_mac_nswindow.mm

Issue 1250403002: [Mac] Move UI item validation to UserInterfaceItemCommandHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@commandexecute
Patch Set: Properly release |commandHandler|. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/ui_base.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/native_widget_mac_nswindow.mm
diff --git a/ui/views/cocoa/native_widget_mac_nswindow.mm b/ui/views/cocoa/native_widget_mac_nswindow.mm
index 1de283fb956b7dc53d180ed36ec06e1e07d4ae91..678e4d58440a13fb33614e264dc17c22c36afed9 100644
--- a/ui/views/cocoa/native_widget_mac_nswindow.mm
+++ b/ui/views/cocoa/native_widget_mac_nswindow.mm
@@ -5,6 +5,7 @@
#import "ui/views/cocoa/native_widget_mac_nswindow.h"
#include "base/mac/foundation_util.h"
+#import "ui/base/cocoa/user_interface_item_command_handler.h"
#import "ui/views/cocoa/views_nswindow_delegate.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/widget/native_widget_mac.h"
@@ -23,6 +24,7 @@
@implementation NativeWidgetMacNSWindow {
@private
base::scoped_nsobject<CommandDispatcher> commandDispatcher_;
+ base::scoped_nsprotocol<id<UserInterfaceItemCommandHandler>> commandHandler_;
}
- (instancetype)initWithContentRect:(NSRect)contentRect
@@ -160,6 +162,10 @@
// CommandDispatchingWindow implementation.
+- (void)setCommandHandler:(id<UserInterfaceItemCommandHandler>)commandHandler {
+ commandHandler_.reset([commandHandler retain]);
+}
+
- (BOOL)redispatchKeyEvent:(NSEvent*)event {
return [commandDispatcher_ redispatchKeyEvent:event];
}
@@ -168,4 +174,28 @@
return [super performKeyEquivalent:event];
}
+- (void)commandDispatch:(id)sender {
+ [commandHandler_ commandDispatch:sender window:self];
+}
+
+- (void)commandDispatchUsingKeyModifiers:(id)sender {
+ [commandHandler_ commandDispatchUsingKeyModifiers:sender window:self];
+}
+
+// NSWindow overrides (NSUserInterfaceItemValidations 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
« no previous file with comments | « ui/base/ui_base.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698