Flutter macOS Embedder
FlutterTextInputPlugin.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_FLUTTERTEXTINPUTPLUGIN_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
7 
8 #import <Cocoa/Cocoa.h>
9 
12 
13 @class FlutterTextField;
14 
15 /**
16  * A plugin to handle text input.
17  *
18  * Responsible for bridging the native macOS text input system with the Flutter framework text
19  * editing classes, via system channels.
20  *
21  * This is not an FlutterPlugin since it needs access to FlutterViewController internals, so needs
22  * to be managed differently.
23  *
24  * When accessibility is on, accessibility bridge creates a NSTextField, i.e. FlutterTextField,
25  * for every text field in the Flutter. This plugin acts as a field editor for those NSTextField[s].
26  */
27 @interface FlutterTextInputPlugin : NSTextView
28 
29 /**
30  * The NSTextField that currently has this plugin as its field editor.
31  *
32  * Must be nil if accessibility is off.
33  */
34 @property(nonatomic, weak) FlutterTextField* client;
35 
36 /**
37  * Initializes a text input plugin that coordinates key event handling with |viewController|.
38  */
39 - (instancetype)initWithViewController:(FlutterViewController*)viewController;
40 
41 /**
42  * Whether this plugin is the first responder of this NSWindow.
43  *
44  * When accessibility is on, this plugin is set as the first responder to act as the field
45  * editor for FlutterTextFields.
46  *
47  * Returns false if accessibility is off.
48  */
49 - (BOOL)isFirstResponder;
50 
51 /**
52  * Handles key down events received from the view controller, responding YES if
53  * the event was handled.
54  *
55  * Note, the Apple docs suggest that clients should override essentially all the
56  * mouse and keyboard event-handling methods of NSResponder. However, experimentation
57  * indicates that only key events are processed by the native layer; Flutter processes
58  * mouse events. Additionally, processing both keyUp and keyDown results in duplicate
59  * processing of the same keys.
60  */
61 - (BOOL)handleKeyEvent:(NSEvent*)event;
62 
63 @end
64 
65 // Private methods made visible for testing
67 - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
68 - (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actualRange;
69 - (NSDictionary*)editingState;
70 @property(nonatomic) NSTextInputContext* textInputContext;
71 @property(readwrite, nonatomic) NSString* customRunLoopMode;
72 @end
73 
74 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
-[FlutterTextInputPlugin(TestMethods) editingState]
NSDictionary * editingState()
FlutterTextInputPlugin(TestMethods)
Definition: FlutterTextInputPlugin.h:66
FlutterTextInputPlugin(TestMethods)::customRunLoopMode
NSString * customRunLoopMode
Definition: FlutterTextInputPlugin.h:71
FlutterViewController
Definition: FlutterViewController.h:65
FlutterTextInputPlugin::client
FlutterTextField * client
Definition: FlutterTextInputPlugin.h:34
FlutterMethodCall
Definition: FlutterCodecs.h:220
FlutterBinaryMessenger.h
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:27
FlutterTextInputPlugin(TestMethods)::textInputContext
NSTextInputContext * textInputContext
Definition: FlutterTextInputPlugin.h:70
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
-[FlutterTextInputPlugin isFirstResponder]
BOOL isFirstResponder()
Definition: FlutterTextInputPlugin.mm:373
FlutterTextField
Definition: FlutterTextInputSemanticsObject.h:81
FlutterViewController.h