Flutter Engine
 
Loading...
Searching...
No Matches
FlutterKeyboardManager.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERKEYBOARDMANAGER_H_
6#define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERKEYBOARDMANAGER_H_
7
8#import <Cocoa/Cocoa.h>
9
12
13@protocol FlutterKeyboardManagerDelegate
14
15@required
16
17/**
18 * Dispatch events to the framework to be processed by |HardwareKeyboard|.
19 *
20 * This method typically forwards events to
21 * |FlutterEngine.sendKeyEvent:callback:userData:|.
22 */
23- (void)sendKeyEvent:(const FlutterKeyEvent&)event
24 callback:(nullable FlutterKeyEventCallback)callback
25 userData:(nullable void*)userData;
26
27/**
28 * Get a binary messenger to send channel messages with.
29 *
30 * This method is used to create the key data channel and typically
31 * forwards to |FlutterEngine.binaryMessenger|.
32 */
33- (nonnull id<FlutterBinaryMessenger>)binaryMessenger;
34
35@end
36
37/**
38 * Provides context for a keyboard event. Implemented by FlutterViewController.
39 */
40@protocol FlutterKeyboardManagerEventContext
41
42@required
43/**
44 * Get the next responder to dispatch events that the keyboard system
45 * (including text input) do not handle.
46 *
47 * If the |nextResponder| is null, then those events will be discarded.
48 */
49@property(nonatomic, readonly, nullable) NSResponder* nextResponder;
50
51/**
52 * Dispatch events that are not handled by the keyboard event handlers
53 * to the text input handler.
54 *
55 * This method typically forwards events to |TextInputPlugin.handleKeyEvent|.
56 */
57- (BOOL)onTextInputKeyEvent:(nonnull NSEvent*)event;
58
59@end
60
61/**
62 * A hub that manages how key events are dispatched to various Flutter key
63 * responders, and whether the event is propagated to the next NSResponder.
64 * Cooperates with |TextInputPlugin| to handle text
65 *
66 * A keyboard event goes through a few sections, each can choose to handled the
67 * event, and only unhandled events can move to the next section:
68 *
69 * - Pre-filtering: Events during IME are sent to the system immediately.
70 * - Keyboard: Dispatch to the embedder responder and the channel responder
71 * simultaneously. After both responders have responded (asynchronously), the
72 * event is considered handled if either responder handles.
73 * - Text input: Events are sent to |TextInputPlugin| and are handled
74 * synchronously.
75 * - Next responder: Events are sent to the next responder as specified by
76 * |viewDelegate|.
77 */
78@interface FlutterKeyboardManager : NSObject
79
80/**
81 * Create a keyboard manager.
82 *
83 * The |viewDelegate| is a weak reference, typically implemented by
84 * |FlutterViewController|.
85 */
86- (nonnull instancetype)initWithDelegate:(nonnull id<FlutterKeyboardManagerDelegate>)delegate;
87
88/**
89 * Processes a key event.
90 *
91 * Unhandled events will be dispatched to the text input system, and possibly
92 * the next responder afterwards.
93 */
94- (void)handleEvent:(nonnull NSEvent*)event
95 withContext:(nonnull id<FlutterKeyboardManagerEventContext>)eventContext;
96
97/**
98 * Returns yes if is event currently being redispatched.
99 *
100 * In some instances (i.e. emoji shortcut) the event may be redelivered by cocoa
101 * as key equivalent to FlutterTextInput, in which case it shouldn't be
102 * processed again.
103 */
104- (BOOL)isDispatchingKeyEvent:(nonnull NSEvent*)event;
105
106/**
107 * Synthesize modifier keys events.
108 *
109 * If needed, synthesize modifier keys up and down events by comparing their
110 * current pressing states with the given modifier flags.
111 */
112- (void)syncModifiersIfNeeded:(NSEventModifierFlags)modifierFlags
113 timestamp:(NSTimeInterval)timestamp;
114
115/**
116 * Returns the keyboard pressed state.
117 *
118 * Returns the keyboard pressed state. The dictionary contains one entry per
119 * pressed keys, mapping from the logical key to the physical key.
120 */
121- (nonnull NSDictionary*)getPressedState;
122
123@end
124
126
127@interface FlutterKeyboardManager (Testing)
128- (nonnull instancetype)initWithDelegate:(nonnull id<FlutterKeyboardManagerDelegate>)delegate
129 keyboardLayout:(nonnull FlutterKeyboardLayout*)keyboardLayout;
130@end
131
132#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERKEYBOARDMANAGER_H_
void(* FlutterKeyEventCallback)(bool, void *)
Definition embedder.h:1427
nonnull NSDictionary * getPressedState()
const uintptr_t id
int BOOL