| Flutter iOS 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_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
7
8 #import <UIKit/UIKit.h>
9
10 #import "flutter/shell/platform/common/text_editing_delta.h"
11 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
12 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterIndirectScribbleDelegate.h"
13 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterKeySecondaryResponder.h"
14 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h"
15 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h"
16
17 typedef NS_ENUM(NSInteger, FlutterScribbleFocusStatus) {
18 // NOLINTBEGIN(readability-identifier-naming)
19 FlutterScribbleFocusStatusUnfocused,
20 FlutterScribbleFocusStatusFocusing,
21 FlutterScribbleFocusStatusFocused,
22 // NOLINTEND(readability-identifier-naming)
23 };
24
25 typedef NS_ENUM(NSInteger, FlutterScribbleInteractionStatus) {
26 // NOLINTBEGIN(readability-identifier-naming)
27 FlutterScribbleInteractionStatusNone,
28 FlutterScribbleInteractionStatusStarted,
29 FlutterScribbleInteractionStatusEnding,
30 // NOLINTEND(readability-identifier-naming)
31 };
32
33 @interface FlutterTextInputPlugin
34 : NSObject <FlutterKeySecondaryResponder, UIIndirectScribbleInteractionDelegate>
35
36 @property(nonatomic, weak) UIViewController* viewController;
37 @property(nonatomic, weak) id<FlutterIndirectScribbleDelegate> indirectScribbleDelegate;
38 @property(nonatomic, strong)
39 NSMutableDictionary<UIScribbleElementIdentifier, NSValue*>* scribbleElements;
40
41 - (instancetype)init NS_UNAVAILABLE;
42 + (instancetype)new NS_UNAVAILABLE;
43
44 - (instancetype)initWithDelegate:(id<FlutterTextInputDelegate>)textInputDelegate
45 NS_DESIGNATED_INITIALIZER;
46
47 - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
48
49 /**
50 * Reset the text input plugin to prepare for a hot restart.
51 *
52 * This hides the software keyboard and text editing context menu.
53 */
54 - (void)reset;
55
56 /**
57 * The `UITextInput` implementation used to control text entry.
58 *
59 * This is used by `AccessibilityBridge` to forward interactions with iOS'
60 * accessibility system.
61 */
62 - (UIView<UITextInput>*)textInputView;
63
64 /**
65 * These are used by the UIIndirectScribbleInteractionDelegate methods to handle focusing on the
66 * correct element.
67 */
68 - (void)setUpIndirectScribbleInteraction:(id<FlutterViewResponder>)viewResponder;
69 - (void)resetViewResponder;
70 - (BOOL)showEditMenu:(NSDictionary*)args API_AVAILABLE(ios(16.0));
71 - (void)hideEditMenu API_AVAILABLE(ios(16.0));
72
73 @end
74
75 /** An indexed position in the buffer of a Flutter text editing widget. */
76 @interface FlutterTextPosition : UITextPosition
77
78 @property(nonatomic, readonly) NSUInteger index;
79 @property(nonatomic, readonly) UITextStorageDirection affinity;
80
81 + (instancetype)positionWithIndex:(NSUInteger)index;
82 + (instancetype)positionWithIndex:(NSUInteger)index affinity:(UITextStorageDirection)affinity;
83 - (instancetype)initWithIndex:(NSUInteger)index affinity:(UITextStorageDirection)affinity;
84
85 @end
86
87 /** A range of text in the buffer of a Flutter text editing widget. */
88 @interface FlutterTextRange : UITextRange <NSCopying>
89
90 @property(nonatomic, readonly) NSRange range;
91
92 + (instancetype)rangeWithNSRange:(NSRange)range;
93
94 @end
95
96 /** A tokenizer used by `FlutterTextInputView` to customize string parsing. */
97 @interface FlutterTokenizer : UITextInputStringTokenizer
98 @end
99
100 @interface FlutterTextSelectionRect : UITextSelectionRect
101
102 @property(nonatomic, assign) CGRect rect;
103 @property(nonatomic) NSUInteger position;
104 @property(nonatomic, assign) NSWritingDirection writingDirection;
105 @property(nonatomic) BOOL containsStart;
106 @property(nonatomic) BOOL containsEnd;
107 @property(nonatomic) BOOL isVertical;
108
109 + (instancetype)selectionRectWithRectAndInfo:(CGRect)rect
110 position:(NSUInteger)position
111 writingDirection:(NSWritingDirection)writingDirection
112 containsStart:(BOOL)containsStart
113 containsEnd:(BOOL)containsEnd
114 isVertical:(BOOL)isVertical;
115
116 + (instancetype)selectionRectWithRect:(CGRect)rect position:(NSUInteger)position;
117
118 + (instancetype)selectionRectWithRect:(CGRect)rect
119 position:(NSUInteger)position
120 writingDirection:(NSWritingDirection)writingDirection;
121
122 - (instancetype)initWithRectAndInfo:(CGRect)rect
123 position:(NSUInteger)position
124 writingDirection:(NSWritingDirection)writingDirection
125 containsStart:(BOOL)containsStart
126 containsEnd:(BOOL)containsEnd
127 isVertical:(BOOL)isVertical;
128
129 - (instancetype)init NS_UNAVAILABLE;
130
131 - (BOOL)isRTL;
132 @end
133
134 API_AVAILABLE(ios(13.0)) @interface FlutterTextPlaceholder : UITextPlaceholder
135 @end
136
137 #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
138 FLUTTER_DARWIN_EXPORT
139 #endif
140 @interface FlutterTextInputView
141 : UIView <UITextInput, UIScribbleInteractionDelegate, UIEditMenuInteractionDelegate>
142
143 // UITextInput
144 @property(nonatomic, readonly) NSMutableString* text;
145 @property(readwrite, copy) UITextRange* selectedTextRange;
146 @property(nonatomic, strong) UITextRange* markedTextRange;
147 @property(nonatomic, copy) NSDictionary* markedTextStyle;
148 @property(nonatomic, weak) id<UITextInputDelegate> inputDelegate;
149 @property(nonatomic, strong) NSMutableArray* pendingDeltas;
150
151 // UITextInputTraits
152 @property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
153 @property(nonatomic) UITextAutocorrectionType autocorrectionType;
154 @property(nonatomic) UITextSpellCheckingType spellCheckingType;
155 @property(nonatomic) BOOL enablesReturnKeyAutomatically;
156 @property(nonatomic) UIKeyboardAppearance keyboardAppearance;
157 @property(nonatomic) UIKeyboardType keyboardType;
158 @property(nonatomic) UIReturnKeyType returnKeyType;
159 @property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry;
160 @property(nonatomic, getter=isEnableDeltaModel) BOOL enableDeltaModel;
161 @property(nonatomic) UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0));
162 @property(nonatomic) UITextSmartDashesType smartDashesType API_AVAILABLE(ios(11.0));
163 @property(nonatomic, copy) UITextContentType textContentType API_AVAILABLE(ios(10.0));
164
165 @property(nonatomic, weak) UIAccessibilityElement* backingTextInputAccessibilityObject;
166
167 // Scribble Support
168 @property(nonatomic, weak) id<FlutterViewResponder> viewResponder;
169 @property(nonatomic) FlutterScribbleFocusStatus scribbleFocusStatus;
170 @property(nonatomic, strong) NSArray<FlutterTextSelectionRect*>* selectionRects;
171
172 @property(nonatomic, strong) UIEditMenuInteraction* editMenuInteraction API_AVAILABLE(ios(16.0));
173 - (void)resetScribbleInteractionStatusIfEnding;
174 - (BOOL)isScribbleAvailable;
175
176 - (instancetype)init NS_UNAVAILABLE;
177 + (instancetype)new NS_UNAVAILABLE;
178 - (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
179 - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
180 - (instancetype)initWithOwner:(FlutterTextInputPlugin*)textInputPlugin NS_DESIGNATED_INITIALIZER;
181
182 // TODO(louisehsu): These are being exposed to support Share in FlutterPlatformPlugin
183 // Consider moving that feature into FlutterTextInputPlugin to avoid exposing extra methods
184 - (CGRect)localRectFromFrameworkTransform:(CGRect)incomingRect;
185 - (CGRect)caretRectForPosition:(UITextPosition*)position;
186 @end
187
188 @interface UIView (FindFirstResponder)
189 @property(nonatomic, readonly) id flutterFirstResponder;
190 @end
191
192 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
FlutterChannels.h
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
FlutterIndirectScribbleDelegate.h
FlutterKeySecondaryResponder.h
FLUTTER_DARWIN_EXPORT
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
FlutterTextInputDelegate.h
enablesReturnKeyAutomatically
BOOL enablesReturnKeyAutomatically
Definition: FlutterTextInputPlugin.h:155
backingTextInputAccessibilityObject
UIAccessibilityElement * backingTextInputAccessibilityObject
Definition: FlutterTextInputPlugin.h:165
markedTextStyle
NSDictionary * markedTextStyle
Definition: FlutterTextInputPlugin.h:147
selectionRects
NSArray< FlutterTextSelectionRect * > * selectionRects
Definition: FlutterTextInputPlugin.h:170
secureTextEntry
BOOL secureTextEntry
Definition: FlutterTextInputPlugin.h:159
pendingDeltas
NSMutableArray * pendingDeltas
Definition: FlutterTextInputPlugin.h:149
isScribbleAvailable
BOOL isScribbleAvailable
Definition: FlutterTextInputPlugin.h:174
localRectFromFrameworkTransform
CGRect localRectFromFrameworkTransform
Definition: FlutterTextInputPlugin.h:184
resetScribbleInteractionStatusIfEnding
void resetScribbleInteractionStatusIfEnding
Definition: FlutterTextInputPlugin.h:173
NS_ENUM
typedef NS_ENUM(NSInteger, FlutterScribbleFocusStatus)
Definition: FlutterTextInputPlugin.h:17
keyboardType
UIKeyboardType keyboardType
Definition: FlutterTextInputPlugin.h:157
markedTextRange
UITextRange * markedTextRange
Definition: FlutterTextInputPlugin.h:146
inputDelegate
id< UITextInputDelegate > inputDelegate
Definition: FlutterTextInputPlugin.h:148
NS_UNAVAILABLE
instancetype init NS_UNAVAILABLE
Definition: FlutterTextInputPlugin.h:176
autocorrectionType
UITextAutocorrectionType autocorrectionType
Definition: FlutterTextInputPlugin.h:153
initWithFrame
instancetype initWithFrame
Definition: FlutterTextInputPlugin.h:179
scribbleFocusStatus
FlutterScribbleFocusStatus scribbleFocusStatus
Definition: FlutterTextInputPlugin.h:169
spellCheckingType
UITextSpellCheckingType spellCheckingType
Definition: FlutterTextInputPlugin.h:154
selectedTextRange
API_AVAILABLE(ios(13.0)) @interface FlutterTextPlaceholder UITextRange * selectedTextRange
Definition: FlutterTextInputPlugin.h:134
initWithOwner
instancetype initWithOwner
Definition: FlutterTextInputPlugin.h:180
viewResponder
id< FlutterViewResponder > viewResponder
Definition: FlutterTextInputPlugin.h:168
API_AVAILABLE
UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0))
enableDeltaModel
BOOL enableDeltaModel
Definition: FlutterTextInputPlugin.h:160
initWithCoder
instancetype initWithCoder
Definition: FlutterTextInputPlugin.h:178
autocapitalizationType
UITextAutocapitalizationType autocapitalizationType
Definition: FlutterTextInputPlugin.h:152
returnKeyType
UIReturnKeyType returnKeyType
Definition: FlutterTextInputPlugin.h:158
caretRectForPosition
CGRect caretRectForPosition
Definition: FlutterTextInputPlugin.h:185
keyboardAppearance
UIKeyboardAppearance keyboardAppearance
Definition: FlutterTextInputPlugin.h:156
viewController
FlutterViewController * viewController
Definition: FlutterTextInputPluginTest.mm:139
FlutterViewResponder.h
UIView(FindFirstResponder)
Definition: FlutterTextInputPlugin.h:188
FlutterTextInputView
Definition: FlutterTextInputPlugin.mm:812
FlutterTextPlaceholder
Definition: FlutterTextInputPlugin.mm:737
FlutterMethodCall
Definition: FlutterCodecs.h:221
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:34
-[FlutterTextInputPlugin textInputView]
UIView< UITextInput > * textInputView()
Definition: FlutterTextInputPlugin.mm:2531
FlutterTextInputPlugin::scribbleElements
NSMutableDictionary< UIScribbleElementIdentifier, NSValue * > * scribbleElements
Definition: FlutterTextInputPlugin.h:39
-[FlutterTextInputPlugin resetViewResponder]
void resetViewResponder()
Definition: FlutterTextInputPlugin.mm:3194
FlutterTextInputPlugin::indirectScribbleDelegate
id< FlutterIndirectScribbleDelegate > indirectScribbleDelegate
Definition: FlutterTextInputPlugin.h:37
-[FlutterTextInputPlugin reset]
void reset()
Definition: FlutterTextInputPlugin.mm:2535
FlutterTextPosition
Definition: FlutterTextInputPlugin.h:77
FlutterTextPosition::index
NSUInteger index
Definition: FlutterTextInputPlugin.h:78
FlutterTextPosition::affinity
UITextStorageDirection affinity
Definition: FlutterTextInputPlugin.h:79
FlutterTextRange
Definition: FlutterTextInputPlugin.h:88
FlutterTextSelectionRect
Definition: FlutterTextInputPlugin.h:101
FlutterTokenizer
Definition: FlutterTextInputPlugin.h:98
FlutterTextInputDelegate-p
Definition: FlutterTextInputDelegate.h:37
FlutterViewResponder-p
Definition: FlutterViewResponder.h:15
text_editing_delta.h