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

Side by Side 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: Sync to new CommandDispatcher design. Add UserInterfaceItemCommandHandler. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_BASE_COCOA_COMMAND_DISPATCHER_H_ 5 #ifndef UI_BASE_COCOA_COMMAND_DISPATCHER_H_
6 #define UI_BASE_COCOA_COMMAND_DISPATCHER_H_ 6 #define UI_BASE_COCOA_COMMAND_DISPATCHER_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
11 11
12 @protocol CommandDispatcherDelegate; 12 @protocol CommandDispatcherDelegate;
13 @protocol CommandDispatchingWindow; 13 @protocol CommandDispatchingWindow;
14 @protocol UserInterfaceItemCommandHandler;
14 15
15 // CommandDispatcher guides the processing of key events to ensure key commands 16 // CommandDispatcher guides the processing of key events to ensure key commands
16 // are executed in the appropriate order. In particular, it allows a first 17 // are executed in the appropriate order. In particular, it allows a first
17 // responder implementing CommandDispatcherTarget to handle an event 18 // responder implementing CommandDispatcherTarget to handle an event
18 // asynchronously and return unhandled events via -redispatchKeyEvent. An 19 // asynchronously and return unhandled events via -redispatchKeyEvent. An
19 // NSWindow can use CommandDispatcher by implementing CommandDispatchingWindow 20 // NSWindow can use CommandDispatcher by implementing CommandDispatchingWindow
20 // and overriding -[NSWindow performKeyEquivalent:] and -[NSWindow sendEvent:] 21 // and overriding -[NSWindow performKeyEquivalent:] and -[NSWindow sendEvent:]
21 // to call the respective CommandDispatcher methods. 22 // to call the respective CommandDispatcher methods.
22 @interface CommandDispatcher : NSObject 23 @interface CommandDispatcher : NSObject
23 24
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 - (BOOL)prePerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window; 72 - (BOOL)prePerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window;
72 73
73 // Called after the default -performKeyEquivalent. |window| is the 74 // Called after the default -performKeyEquivalent. |window| is the
74 // CommandDispatchingWindow that owns CommandDispatcher. 75 // CommandDispatchingWindow that owns CommandDispatcher.
75 - (BOOL)postPerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window; 76 - (BOOL)postPerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window;
76 77
77 @end 78 @end
78 79
79 // The set of methods an NSWindow subclass needs to implement to use 80 // The set of methods an NSWindow subclass needs to implement to use
80 // CommandDispatcher. 81 // CommandDispatcher.
81 @protocol CommandDispatchingWindow 82 @protocol CommandDispatchingWindow<NSUserInterfaceValidations>
tapted 2015/08/27 07:24:42 does the window need to implement this (i.e. is th
jackhou1 2015/09/03 01:12:49 Yeah it's not necessary to require this.
83
84 @property(assign, nonatomic) id<UserInterfaceItemCommandHandler> commandHandler;
tapted 2015/08/27 07:24:42 Could we just force the owner to implement this?
jackhou1 2015/09/03 01:12:49 Yeah, this is only used to set it on NativeWidgetM
82 85
83 // This can be implemented with -[CommandDispatcher redispatchKeyEvent:]. It's 86 // This can be implemented with -[CommandDispatcher redispatchKeyEvent:]. It's
84 // so that callers can simply return events to the NSWindow. 87 // so that callers can simply return events to the NSWindow.
85 - (BOOL)redispatchKeyEvent:(NSEvent*)event; 88 - (BOOL)redispatchKeyEvent:(NSEvent*)event;
86 89
87 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which 90 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which
88 // CommandDispatcher calls as part of its -performKeyEquivalent flow. 91 // CommandDispatcher calls as part of its -performKeyEquivalent flow.
89 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event; 92 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event;
90 93
94 // AppKit will call -[NSUserInterfaceValidations validateUserInterfaceItem:] to
95 // validate UI items. Any item whose target is FirstResponder, or nil, will
96 // traverse the responder chain looking for a responder that implements the
97 // item's selector. Thus NSWindow is usually the last to be checked and will
98 // handle any items that are not validated elsewhere in the chain. Implement the
99 // following so that menu items with these selectors are validated by
100 // CommandDispatchingWindow.
101 - (void)commandDispatch:(id)sender;
tapted 2015/08/28 05:04:02 What's calling these? What happens if we refactor
jackhou1 2015/09/03 01:12:49 These are hard coded in the nibs. I.e. a button mi
102 - (void)commandDispatchUsingKeyModifiers:(id)sender;
103
104 @end
105
106 // Used by CommandDispatchingWindow to implement UI item validation.
107 @protocol UserInterfaceItemCommandHandler
108
109 // Called by CommandDispatchingWindow to validate menu and toolbar items. All
110 // the items we care about have been set with the -commandDispatch or
111 // -commandDispatchUsingKeyModifiers selectors and a target of FirstResponder in
112 // IB. If it's not one of those, it should be handled elsewhere in the responder
113 // chain.
114 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item
115 window:(NSWindow*)window;
116
117 // Called by CommandDispatchingWindow to execute commands. This assumes that the
118 // command is supported and doesn't check, otherwise it would have been disabled
119 // in the UI in validateUserInterfaceItem:.
120 - (void)commandDispatch:(id)sender window:(NSWindow*)window;
121
122 // Same as |-commandDispatch:|, but executes commands using a disposition
123 // determined by the key flags. If the window is in the background and the
124 // command key is down, ignore the command key, but process any other modifiers.
125 - (void)commandDispatchUsingKeyModifiers:(id)sender window:(NSWindow*)window;
126
91 @end 127 @end
92 128
93 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_ 129 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698