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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 @property(assign, nonatomic) id<CommandDispatcherDelegate> delegate; | 26 @property(assign, nonatomic) id<CommandDispatcherDelegate> delegate; |
27 | 27 |
28 - (instancetype)initWithOwner:(NSWindow<CommandDispatchingWindow>*)owner; | 28 - (instancetype)initWithOwner:(NSWindow<CommandDispatchingWindow>*)owner; |
29 | 29 |
30 // The main entry point for key events. The CommandDispatchingWindow should | 30 // The main entry point for key events. The CommandDispatchingWindow should |
31 // override -[NSResponder performKeyEquivalent:] and call this instead. Returns | 31 // override -[NSResponder performKeyEquivalent:] and call this instead. Returns |
32 // YES if the event is handled. | 32 // YES if the event is handled. |
33 - (BOOL)performKeyEquivalent:(NSEvent*)event; | 33 - (BOOL)performKeyEquivalent:(NSEvent*)event; |
34 | 34 |
| 35 // Validate a user interface item (e.g. an NSMenuItem), consulting |handler| for |
| 36 // -commandDispatch: item actions. |
| 37 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item |
| 38 forHandler:(id<UserInterfaceItemCommandHandler>)handler; |
| 39 |
35 // Sends a key event to -[NSApp sendEvent:]. This is used to allow default | 40 // Sends a key event to -[NSApp sendEvent:]. This is used to allow default |
36 // AppKit handling of an event that comes back from CommandDispatcherTarget, | 41 // AppKit handling of an event that comes back from CommandDispatcherTarget, |
37 // e.g. key equivalents in the menu, or window manager commands like Cmd+`. Once | 42 // e.g. key equivalents in the menu, or window manager commands like Cmd+`. Once |
38 // the event returns to the window at -preSendEvent:, handling will stop. The | 43 // the event returns to the window at -preSendEvent:, handling will stop. The |
39 // event must be of type |NSKeyDown|, |NSKeyUp|, or |NSFlagsChanged|. Returns | 44 // event must be of type |NSKeyDown|, |NSKeyUp|, or |NSFlagsChanged|. Returns |
40 // YES if the event is handled. | 45 // YES if the event is handled. |
41 - (BOOL)redispatchKeyEvent:(NSEvent*)event; | 46 - (BOOL)redispatchKeyEvent:(NSEvent*)event; |
42 | 47 |
43 // The CommandDispatchingWindow should override -[NSWindow sendEvent:] and call | 48 // The CommandDispatchingWindow should override -[NSWindow sendEvent:] and call |
44 // this before a native -sendEvent:. Ensures that a redispatched event is not | 49 // this before a native -sendEvent:. Ensures that a redispatched event is not |
45 // reposted infinitely. Returns YES if the event is handled. | 50 // reposted infinitely. Returns YES if the event is handled. |
46 - (BOOL)preSendEvent:(NSEvent*)event; | 51 - (BOOL)preSendEvent:(NSEvent*)event; |
47 | 52 |
| 53 // Dispatch a -commandDispatch: action either to |handler| or a parent window's |
| 54 // handler. |
| 55 - (void)dispatch:(id)sender |
| 56 forHandler:(id<UserInterfaceItemCommandHandler>)handler; |
| 57 - (void)dispatchUsingKeyModifiers:(id)sender |
| 58 forHandler:(id<UserInterfaceItemCommandHandler>)handler; |
| 59 |
48 @end | 60 @end |
49 | 61 |
50 // If the NSWindow's firstResponder implements CommandDispatcherTarget, it is | 62 // If the NSWindow's firstResponder implements CommandDispatcherTarget, it is |
51 // given the first opportunity to process a command. | 63 // given the first opportunity to process a command. |
52 @protocol CommandDispatcherTarget | 64 @protocol CommandDispatcherTarget |
53 | 65 |
54 // To handle an event asynchronously, return YES. If the event is ultimately not | 66 // To handle an event asynchronously, return YES. If the event is ultimately not |
55 // handled, return the event to the CommandDispatchingWindow via -[[event | 67 // handled, return the event to the CommandDispatchingWindow via -[[event |
56 // window] redispatchKeyEvent:event]. | 68 // window] redispatchKeyEvent:event]. |
57 - (BOOL)performKeyEquivalent:(NSEvent*)event; | 69 - (BOOL)performKeyEquivalent:(NSEvent*)event; |
(...skipping 30 matching lines...) Expand all Loading... |
88 -(void)setCommandHandler:(id<UserInterfaceItemCommandHandler>) commandHandler; | 100 -(void)setCommandHandler:(id<UserInterfaceItemCommandHandler>) commandHandler; |
89 | 101 |
90 // This can be implemented with -[CommandDispatcher redispatchKeyEvent:]. It's | 102 // This can be implemented with -[CommandDispatcher redispatchKeyEvent:]. It's |
91 // so that callers can simply return events to the NSWindow. | 103 // so that callers can simply return events to the NSWindow. |
92 - (BOOL)redispatchKeyEvent:(NSEvent*)event; | 104 - (BOOL)redispatchKeyEvent:(NSEvent*)event; |
93 | 105 |
94 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which | 106 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which |
95 // CommandDispatcher calls as part of its -performKeyEquivalent: flow. | 107 // CommandDispatcher calls as part of its -performKeyEquivalent: flow. |
96 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event; | 108 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event; |
97 | 109 |
| 110 // Short-circuit to the default -validateUserInterfaceItem: implementation. |
| 111 - (BOOL)defaultValidateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item; |
| 112 |
98 // AppKit will call -[NSUserInterfaceValidations validateUserInterfaceItem:] to | 113 // AppKit will call -[NSUserInterfaceValidations validateUserInterfaceItem:] to |
99 // validate UI items. Any item whose target is FirstResponder, or nil, will | 114 // validate UI items. Any item whose target is FirstResponder, or nil, will |
100 // traverse the responder chain looking for a responder that implements the | 115 // traverse the responder chain looking for a responder that implements the |
101 // item's selector. Thus NSWindow is usually the last to be checked and will | 116 // item's selector. Thus NSWindow is usually the last to be checked and will |
102 // handle any items that are not validated elsewhere in the chain. Implement the | 117 // handle any items that are not validated elsewhere in the chain. Implement the |
103 // following so that menu items with these selectors are validated by | 118 // following so that menu items with these selectors are validated by |
104 // CommandDispatchingWindow. | 119 // CommandDispatchingWindow. |
105 - (void)commandDispatch:(id)sender; | 120 - (void)commandDispatch:(id)sender; |
106 - (void)commandDispatchUsingKeyModifiers:(id)sender; | 121 - (void)commandDispatchUsingKeyModifiers:(id)sender; |
107 | 122 |
108 @end | 123 @end |
109 | 124 |
110 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_ | 125 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_ |
OLD | NEW |