Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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 * 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 * In case of popup windows, this will be the view controller of the closest
55 * window in hierarchy above that can receive keyboard input.
56 */
57@property(nonatomic, readonly, weak) FlutterViewController* currentViewController;
58
59/**
60 * Initializes a text input plugin that coordinates key event handling with |viewController|.
61 */
62- (instancetype)initWithDelegate:(id<FlutterTextInputPluginDelegate>)delegate;
63
64/**
65 * Whether this plugin is the first responder of this NSWindow.
66 *
67 * When accessibility is on, this plugin is set as the first responder to act as the field
68 * editor for FlutterTextFields.
69 *
70 * Returns false if accessibility is off.
71 */
73
74/**
75 * Handles key down events received from the view controller, responding YES if
76 * the event was handled.
77 *
78 * Note, the Apple docs suggest that clients should override essentially all the
79 * mouse and keyboard event-handling methods of NSResponder. However, experimentation
80 * indicates that only key events are processed by the native layer; Flutter processes
81 * mouse events. Additionally, processing both keyUp and keyDown results in duplicate
82 * processing of the same keys.
83 */
84- (BOOL)handleKeyEvent:(NSEvent*)event;
85
86@end
87
88// Private methods made visible for testing
89@interface FlutterTextInputPlugin (TestMethods)
90- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
91- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actualRange;
92- (NSDictionary*)editingState;
93@property(nonatomic) NSTextInputContext* textInputContext;
94@property(readwrite, nonatomic) NSString* customRunLoopMode;
95@end
96
97#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
void(^ FlutterResult)(id _Nullable result)
FlutterViewController * currentViewController
int64_t FlutterViewIdentifier
int BOOL