OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_BASE_COCOA_COMMAND_DISPATCHER_H_ | |
6 #define UI_BASE_COCOA_COMMAND_DISPATCHER_H_ | |
7 | |
8 #import <Cocoa/Cocoa.h> | |
9 | |
10 #import "base/mac/scoped_nsobject.h" | |
11 | |
12 @protocol CommandDispatcherDelegate; | |
13 @protocol CommandDispatchingWindow; | |
14 | |
15 // 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 // responder implementing CommandDispatcherTarget to handle an event | |
18 // asynchronously and return unhandled events via -redispatchKeyEvent. An | |
19 // NSWindow can use CommandDispatcher by implementing CommandDispatchingWindow | |
20 // and overriding -[NSWindow -performKeyEquivalent:] and -[NSWindow -sendEvent:] | |
Robert Sesek
2015/08/26 17:46:49
nit: -[NSWindow performkeyEquivalent:] (the - is a
jackhou1
2015/08/27 00:01:25
Done.
| |
21 // to call the respective CommandDispatcher methods. | |
22 @interface CommandDispatcher : NSObject { | |
23 @private | |
Robert Sesek
2015/08/26 17:46:49
These ivars can be hidden in the .mm:
@implementa
jackhou1
2015/08/27 00:01:25
Done.
| |
24 BOOL redispatchingEvent_; | |
25 BOOL eventHandled_; | |
26 NSWindow<CommandDispatchingWindow>* owner_; // Weak, owns us. | |
27 } | |
28 | |
29 @property(retain, nonatomic) id<CommandDispatcherDelegate> delegate; | |
Robert Sesek
2015/08/26 17:46:49
Delegates aren't usually retained. Maybe make a no
jackhou1
2015/08/27 00:01:25
Looking at this again, the delegate should be owne
| |
30 | |
31 - (id)initWithOwner:(NSWindow<CommandDispatchingWindow>*)owner; | |
Robert Sesek
2015/08/26 17:46:49
instancetype
jackhou1
2015/08/27 00:01:25
Done.
| |
32 | |
33 // The main entry point for key events. The CommandDispatchingWindow should | |
34 // override -[NSResponder performKeyEquivalent:] and call this instead. Returns | |
35 // YES if the event is handled. | |
36 - (BOOL)performKeyEquivalent:(NSEvent*)event; | |
37 | |
38 // Sends a key event to -[NSApp sendEvent:], but also ensures it is not short- | |
39 // circuited to the CommandDispatcherTarget. This is used to allow default | |
Robert Sesek
2015/08/26 17:46:49
" but also ensures it is not short-circuited to th
jackhou1
2015/08/27 00:01:25
Deleted that bit and added a new sentence.
| |
40 // AppKit handling of an event that comes back from CommandDispatcherTarget, | |
41 // e.g. key equivalents in the menu, or window manager commands like Cmd+`. The | |
42 // event must be of type |NSKeyDown|, |NSKeyUp|, or |NSFlagsChanged|. Returns | |
43 // YES if the event is handled. | |
44 - (BOOL)redispatchKeyEvent:(NSEvent*)event; | |
45 | |
46 // The CommandDispatchingWindow should call this before a native -sendEvent. | |
47 // Ensures that a redispatched event is not reposted infinitely. Returns YES if | |
48 // the event is handled. | |
49 - (BOOL)preSendEvent:(NSEvent*)event; | |
Robert Sesek
2015/08/26 17:46:49
Should this be ordered before -redispatchKeyEvent:
jackhou1
2015/08/27 00:01:25
This is the order that the event is handled, i.e.
| |
50 | |
51 @end | |
52 | |
53 // If the NSWindow's firstResponder implements CommandDispatcherTarget, it is | |
54 // given the first opportunity to process a command. | |
55 @protocol CommandDispatcherTarget | |
56 | |
57 // To handle an event asynchronously, return YES. If the event is ultimately not | |
58 // handled, return the event to the CommandDispatchingWindow via -[[event | |
59 // window] redispatchKeyEvent:event]. | |
60 - (BOOL)performKeyEquivalent:(NSEvent*)event; | |
61 | |
62 @end | |
63 | |
64 // Provides CommandDispatcher with the means to redirect key equivalents at | |
65 // different stages of event handling. | |
66 @protocol CommandDispatcherDelegate<NSObject> | |
67 | |
68 // Called before any other event handling, and possibly again if an unhandled | |
69 // event comes back from CommandDispatcherTarget. | |
70 - (BOOL)handledByExtensionCommand:(NSEvent*)event | |
Robert Sesek
2015/08/26 17:46:49
naming: eventHandledByExtensionCommand: ?
jackhou1
2015/08/27 00:01:25
Done.
| |
71 isRedispatch:(BOOL)isRedispatch; | |
72 | |
73 // Called before the default -performKeyEquivalent, but after the | |
74 // CommandDispatcherTarget has had a chance to intercept it. | |
75 - (BOOL)prePerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window; | |
Robert Sesek
2015/08/26 17:46:49
What |window| is this?
jackhou1
2015/08/27 00:01:25
Added comment.
| |
76 | |
77 // Called after the default -performKeyEquivalent. | |
78 - (BOOL)postPerformKeyEquivalent:(NSEvent*)event window:(NSWindow*)window; | |
79 | |
80 @end | |
81 | |
82 // The set of methods an NSWindow subclass needs to implement to use | |
83 // CommandDispatcher. | |
84 @protocol CommandDispatchingWindow | |
85 | |
86 // This can be implemented with -[CommandDispatcher -redispatchKeyEvent:]. It's | |
Robert Sesek
2015/08/26 17:46:49
nit: no - in the []
jackhou1
2015/08/27 00:01:25
Done.
| |
87 // so that callers can simply return events to the NSWindow. | |
88 - (BOOL)redispatchKeyEvent:(NSEvent*)event; | |
89 | |
90 // Short-circuit to the default -[NSResponder performKeyEquivalent:] which | |
91 // CommandDispatcher calls as part of its -performKeyEquivalent flow. | |
92 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event; | |
93 | |
94 @end | |
95 | |
96 #endif // UI_BASE_COCOA_COMMAND_DISPATCHER_H_ | |
OLD | NEW |