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