OLD | NEW |
---|---|
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 #include "ui/base/ui_base_export.h" | 11 #include "ui/base/ui_base_export.h" |
12 | 12 |
13 @protocol CommandDispatcherDelegate; | 13 @protocol CommandDispatcherDelegate; |
14 @protocol CommandDispatchingWindow; | 14 @protocol CommandDispatchingWindow; |
15 @protocol UserInterfaceItemCommandHandler; | |
15 | 16 |
16 // CommandDispatcher guides the processing of key events to ensure key commands | 17 // CommandDispatcher guides the processing of key events to ensure key commands |
17 // are executed in the appropriate order. In particular, it allows a first | 18 // are executed in the appropriate order. In particular, it allows a first |
18 // responder implementing CommandDispatcherTarget to handle an event | 19 // responder implementing CommandDispatcherTarget to handle an event |
19 // asynchronously and return unhandled events via -redispatchKeyEvent:. An | 20 // asynchronously and return unhandled events via -redispatchKeyEvent:. An |
20 // NSWindow can use CommandDispatcher by implementing CommandDispatchingWindow | 21 // NSWindow can use CommandDispatcher by implementing CommandDispatchingWindow |
21 // and overriding -[NSWindow performKeyEquivalent:] and -[NSWindow sendEvent:] | 22 // and overriding -[NSWindow performKeyEquivalent:] and -[NSWindow sendEvent:] |
22 // to call the respective CommandDispatcher methods. | 23 // to call the respective CommandDispatcher methods. |
23 UI_BASE_EXPORT @interface CommandDispatcher : NSObject | 24 UI_BASE_EXPORT @interface CommandDispatcher : NSObject |
24 | 25 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 // Called after the default -performKeyEquivalent:. |window| is the | 75 // Called after the default -performKeyEquivalent:. |window| is the |
75 // CommandDispatchingWindow that owns CommandDispatcher. | 76 // CommandDispatchingWindow that owns CommandDispatcher. |
76 - (BOOL)postPerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window; | 77 - (BOOL)postPerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window; |
77 | 78 |
78 @end | 79 @end |
79 | 80 |
80 // The set of methods an NSWindow subclass needs to implement to use | 81 // The set of methods an NSWindow subclass needs to implement to use |
81 // CommandDispatcher. | 82 // CommandDispatcher. |
82 @protocol CommandDispatchingWindow | 83 @protocol CommandDispatchingWindow |
83 | 84 |
85 @property(assign, nonatomic) id<UserInterfaceItemCommandHandler> commandHandler; | |
86 | |
84 // This can be implemented with -[CommandDispatcher redispatchKeyEvent:]. It's | 87 // This can be implemented with -[CommandDispatcher redispatchKeyEvent:]. It's |
85 // so that callers can simply return events to the NSWindow. | 88 // so that callers can simply return events to the NSWindow. |
86 - (BOOL)redispatchKeyEvent:(NSEvent*)event; | 89 - (BOOL)redispatchKeyEvent:(NSEvent*)event; |
87 | 90 |
88 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which | 91 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which |
89 // CommandDispatcher calls as part of its -performKeyEquivalent: flow. | 92 // CommandDispatcher calls as part of its -performKeyEquivalent: flow. |
90 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event; | 93 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event; |
91 | 94 |
95 // AppKit will call -[NSUserInterfaceValidations validateUserInterfaceItem:] to | |
96 // validate UI items. Any item whose target is FirstResponder, or nil, will | |
97 // traverse the responder chain looking for a responder that implements the | |
98 // item's selector. Thus NSWindow is usually the last to be checked and will | |
99 // handle any items that are not validated elsewhere in the chain. Implement the | |
100 // following so that menu items with these selectors are validated by | |
101 // CommandDispatchingWindow. | |
102 - (void)commandDispatch:(id)sender; | |
103 - (void)commandDispatchUsingKeyModifiers:(id)sender; | |
104 | |
105 @end | |
106 | |
107 // Used by CommandDispatchingWindow to implement UI item validation. | |
108 @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.
| |
109 | |
110 // Called by CommandDispatchingWindow to validate menu and toolbar items. All | |
111 // the items we care about have been set with the -commandDispatch or | |
112 // -commandDispatchUsingKeyModifiers selectors and a target of FirstResponder in | |
113 // IB. If it's not one of those, it should be handled elsewhere in the responder | |
114 // chain. | |
115 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item | |
116 window:(NSWindow*)window; | |
117 | |
118 // Called by CommandDispatchingWindow to execute commands. This assumes that the | |
119 // command is supported and doesn't check, otherwise it would have been disabled | |
120 // in the UI in validateUserInterfaceItem:. | |
121 - (void)commandDispatch:(id)sender window:(NSWindow*)window; | |
122 | |
123 // Same as |-commandDispatch:|, but executes commands using a disposition | |
124 // determined by the key flags. If the window is in the background and the | |
125 // command key is down, ignore the command key, but process any other modifiers. | |
126 - (void)commandDispatchUsingKeyModifiers:(id)sender window:(NSWindow*)window; | |
127 | |
92 @end | 128 @end |
93 | 129 |
94 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_ | 130 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_ |
OLD | NEW |