|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | | -#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyPrimaryResponder.h" |
6 | | - |
7 | 5 | #import <Cocoa/Cocoa.h> |
8 | 6 |
|
9 | | -#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyPrimaryResponder.h" |
10 | | -#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterKeySecondaryResponder.h" |
| 7 | +#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h" |
| 8 | +#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardViewDelegate.h" |
| 9 | + |
| 10 | +namespace { |
| 11 | +// Someohow this pointer type must be defined as a single type for the compiler |
| 12 | +// to compile the function pointer type (due to _Nullable). |
| 13 | +typedef NSResponder* _NSResponderPtr; |
| 14 | +} |
| 15 | + |
| 16 | +typedef _Nullable _NSResponderPtr (^NextResponderProvider)(); |
11 | 17 |
|
12 | 18 | /** |
13 | | - * A hub that manages how key events are dispatched to various Flutter key |
14 | | - * responders, and whether the event is propagated to the next NSResponder. |
15 | | - * |
16 | | - * This class manages one or more primary responders, as well as zero or more |
17 | | - * secondary responders. |
| 19 | + * Processes keyboard events and cooperate with |TextInputPlugin|. |
18 | 20 | * |
19 | | - * An event that is received by |handleEvent| is first dispatched to *all* |
20 | | - * primary responders. Each primary responder responds *asynchronously* with a |
21 | | - * boolean, indicating whether it handles the event. |
| 21 | + * A keyboard event goes through a few sections, each can choose to handled the |
| 22 | + * event, and only unhandled events can move to the next section: |
22 | 23 | * |
23 | | - * An event that is not handled by any primary responders is then passed to to |
24 | | - * the first secondary responder (in the chronological order of addition), |
25 | | - * which responds *synchronously* with a boolean, indicating whether it handles |
26 | | - * the event. If not, the event is passed to the next secondary responder, and |
27 | | - * so on. |
28 | | - * |
29 | | - * If no responders handle the event, the event is then handed over to the |
30 | | - * owner's |nextResponder| if not nil, dispatching to method |keyDown|, |
31 | | - * |keyUp|, or |flagsChanged| depending on the event's type. If the |
32 | | - * |nextResponder| is nil, then the event will be propagated no further. |
33 | | - * |
34 | | - * Preventing primary responders from receiving events is not supported, |
35 | | - * because in reality this class will only support 2 hardcoded ones (channel |
36 | | - * and embedder), where the only purpose of supporting two is to support the |
37 | | - * legacy API (channel) during the deprecation window, after which the channel |
38 | | - * responder should be removed. |
| 24 | + * - Pre-filtering: Events during IME are sent to the system immediately |
| 25 | + * (to be implemented). |
| 26 | + * - Keyboard: Dispatch to the embedder responder and the channel responder |
| 27 | + * simultaneously. After both responders have responded (asynchronously), the |
| 28 | + * event is considered handled if either responder handles. |
| 29 | + * - Text input: Events are sent to |TextInputPlugin| and are handled |
| 30 | + * synchronously. |
| 31 | + * - Next responder: Events are sent to the next responder as specified by |
| 32 | + * |viewDelegate|. |
39 | 33 | */ |
40 | 34 | @interface FlutterKeyboardManager : NSObject |
41 | 35 |
|
42 | 36 | /** |
43 | | - * Create a manager by specifying the owner. |
| 37 | + * Create a keyboard manager. |
44 | 38 | * |
45 | | - * The owner should be an object that handles the lifecycle of this instance. |
46 | | - * The |owner.nextResponder| can be nil, but if it isn't, it will be where the |
47 | | - * key events are propagated to if no responders handle the event. The owner |
48 | | - * is typically a |FlutterViewController|. |
| 39 | + * The |viewDelegate| is a weak reference, typically implemented by |
| 40 | + * |FlutterViewController|. |
49 | 41 | */ |
50 | | -- (nonnull instancetype)initWithOwner:(nonnull NSResponder*)weakOwner; |
| 42 | +- (nonnull instancetype)initWithViewDelegate:(nonnull id<FlutterKeyboardViewDelegate>)viewDelegate; |
51 | 43 |
|
52 | 44 | /** |
53 | | - * Add a primary responder, which asynchronously decides whether to handle an |
54 | | - * event. |
55 | | - */ |
56 | | -- (void)addPrimaryResponder:(nonnull id<FlutterKeyPrimaryResponder>)responder; |
57 | | - |
58 | | -/** |
59 | | - * Add a secondary responder, which synchronously decides whether to handle an |
60 | | - * event in order if no earlier responders handle. |
61 | | - */ |
62 | | -- (void)addSecondaryResponder:(nonnull id<FlutterKeySecondaryResponder>)responder; |
63 | | - |
64 | | -/** |
65 | | - * Dispatch a key event to all responders, and possibly the next |NSResponder| |
66 | | - * afterwards. |
| 45 | + * Processes a key event. |
| 46 | + * |
| 47 | + * Unhandled events will be dispatched to the text input system, and possibly |
| 48 | + * the next responder afterwards. |
67 | 49 | */ |
68 | 50 | - (void)handleEvent:(nonnull NSEvent*)event; |
69 | 51 |
|
|
0 commit comments