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

Unified Diff: ui/base/cocoa/command_dispatcher.h

Issue 1250403002: [Mac] Move UI item validation to UserInterfaceItemCommandHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@commandexecute
Patch Set: Split out BrowserWindowCommandHandler and only use it in browser windows. 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
Index: ui/base/cocoa/command_dispatcher.h
diff --git a/ui/base/cocoa/command_dispatcher.h b/ui/base/cocoa/command_dispatcher.h
index 8ad679af00ed3df90039e57332e870e8f88714ac..84a09b803f95543fea5b7567d15f717623326164 100644
--- a/ui/base/cocoa/command_dispatcher.h
+++ b/ui/base/cocoa/command_dispatcher.h
@@ -12,6 +12,7 @@
@protocol CommandDispatcherDelegate;
@protocol CommandDispatchingWindow;
+@protocol UserInterfaceItemCommandHandler;
// CommandDispatcher guides the processing of key events to ensure key commands
// are executed in the appropriate order. In particular, it allows a first
@@ -81,6 +82,8 @@ UI_BASE_EXPORT @interface CommandDispatcher : NSObject
// CommandDispatcher.
@protocol CommandDispatchingWindow
+@property(assign, nonatomic) id<UserInterfaceItemCommandHandler> commandHandler;
+
// This can be implemented with -[CommandDispatcher redispatchKeyEvent:]. It's
// so that callers can simply return events to the NSWindow.
- (BOOL)redispatchKeyEvent:(NSEvent*)event;
@@ -89,6 +92,39 @@ UI_BASE_EXPORT @interface CommandDispatcher : NSObject
// CommandDispatcher calls as part of its -performKeyEquivalent: flow.
- (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event;
+// AppKit will call -[NSUserInterfaceValidations validateUserInterfaceItem:] to
+// validate UI items. Any item whose target is FirstResponder, or nil, will
+// traverse the responder chain looking for a responder that implements the
+// item's selector. Thus NSWindow is usually the last to be checked and will
+// handle any items that are not validated elsewhere in the chain. Implement the
+// following so that menu items with these selectors are validated by
+// CommandDispatchingWindow.
+- (void)commandDispatch:(id)sender;
+- (void)commandDispatchUsingKeyModifiers:(id)sender;
+
+@end
+
+// Used by CommandDispatchingWindow to implement UI item validation.
+@protocol UserInterfaceItemCommandHandler
tapted 2015/09/04 02:56:24 since this is more optional, perhaps it should be
jackhou1 2015/09/04 06:13:59 Done.
+
+// Called by CommandDispatchingWindow to validate menu and toolbar items. All
+// the items we care about have been set with the -commandDispatch or
+// -commandDispatchUsingKeyModifiers selectors and a target of FirstResponder in
+// IB. If it's not one of those, it should be handled elsewhere in the responder
+// chain.
+- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item
+ window:(NSWindow*)window;
+
+// Called by CommandDispatchingWindow to execute commands. This assumes that the
+// command is supported and doesn't check, otherwise it would have been disabled
+// in the UI in validateUserInterfaceItem:.
+- (void)commandDispatch:(id)sender window:(NSWindow*)window;
+
+// Same as |-commandDispatch:|, but executes commands using a disposition
+// determined by the key flags. If the window is in the background and the
+// command key is down, ignore the command key, but process any other modifiers.
+- (void)commandDispatchUsingKeyModifiers:(id)sender window:(NSWindow*)window;
+
@end
#endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_

Powered by Google App Engine
This is Rietveld 408576698