| 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 * The `UITextInput` implementation used to control text entry.
51 *
52 * This is used by `AccessibilityBridge` to forward interactions with iOS'
53 * accessibility system.
54 */
55 - (UIView<UITextInput>*)textInputView;
56
57 /**
58 * These are used by the UIIndirectScribbleInteractionDelegate methods to handle focusing on the
59 * correct element.
60 */
61 - (void)setUpIndirectScribbleInteraction:(id<FlutterViewResponder>)viewResponder;
62 - (void)resetViewResponder;
63
64 @end
65
66 /** An indexed position in the buffer of a Flutter text editing widget. */
67 @interface FlutterTextPosition : UITextPosition
68
69 @property(nonatomic, readonly) NSUInteger index;
70 @property(nonatomic, readonly) UITextStorageDirection affinity;
71
72 + (instancetype)positionWithIndex:(NSUInteger)index;
73 + (instancetype)positionWithIndex:(NSUInteger)index affinity:(UITextStorageDirection)affinity;
74 - (instancetype)initWithIndex:(NSUInteger)index affinity:(UITextStorageDirection)affinity;
75
76 @end
77
78 /** A range of text in the buffer of a Flutter text editing widget. */
79 @interface FlutterTextRange : UITextRange <NSCopying>
80
81 @property(nonatomic, readonly) NSRange range;
82
83 + (instancetype)rangeWithNSRange:(NSRange)range;
84
85 @end
86
87 /** A tokenizer used by `FlutterTextInputView` to customize string parsing. */
88 @interface FlutterTokenizer : UITextInputStringTokenizer
89 @end
90
91 @interface FlutterTextSelectionRect : UITextSelectionRect
92
93 @property(nonatomic, assign) CGRect rect;
94 @property(nonatomic) NSUInteger position;
95 @property(nonatomic, assign) NSWritingDirection writingDirection;
96 @property(nonatomic) BOOL containsStart;
97 @property(nonatomic) BOOL containsEnd;
98 @property(nonatomic) BOOL isVertical;
99
100 + (instancetype)selectionRectWithRectAndInfo:(CGRect)rect
101 position:(NSUInteger)position
102 writingDirection:(NSWritingDirection)writingDirection
103 containsStart:(BOOL)containsStart
104 containsEnd:(BOOL)containsEnd
105 isVertical:(BOOL)isVertical;
106
107 + (instancetype)selectionRectWithRect:(CGRect)rect position:(NSUInteger)position;
108
109 + (instancetype)selectionRectWithRect:(CGRect)rect
110 position:(NSUInteger)position
111 writingDirection:(NSWritingDirection)writingDirection;
112
113 - (instancetype)initWithRectAndInfo:(CGRect)rect
114 position:(NSUInteger)position
115 writingDirection:(NSWritingDirection)writingDirection
116 containsStart:(BOOL)containsStart
117 containsEnd:(BOOL)containsEnd
118 isVertical:(BOOL)isVertical;
119
120 - (instancetype)init NS_UNAVAILABLE;
121
122 - (BOOL)isRTL;
123 @end
124
125 API_AVAILABLE(ios(13.0)) @interface FlutterTextPlaceholder : UITextPlaceholder
126 @end
127
128 #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
129 FLUTTER_DARWIN_EXPORT
130 #endif
131 @interface FlutterTextInputView : UIView <UITextInput, UIScribbleInteractionDelegate>
132
133 // UITextInput
134 @property(nonatomic, readonly) NSMutableString* text;
135 @property(readwrite, copy) UITextRange* selectedTextRange;
136 @property(nonatomic, strong) UITextRange* markedTextRange;
137 @property(nonatomic, copy) NSDictionary* markedTextStyle;
138 @property(nonatomic, weak) id<UITextInputDelegate> inputDelegate;
139 @property(nonatomic, strong) NSMutableArray* pendingDeltas;
140
141 // UITextInputTraits
142 @property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
143 @property(nonatomic) UITextAutocorrectionType autocorrectionType;
144 @property(nonatomic) UITextSpellCheckingType spellCheckingType;
145 @property(nonatomic) BOOL enablesReturnKeyAutomatically;
146 @property(nonatomic) UIKeyboardAppearance keyboardAppearance;
147 @property(nonatomic) UIKeyboardType keyboardType;
148 @property(nonatomic) UIReturnKeyType returnKeyType;
149 @property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry;
150 @property(nonatomic, getter=isEnableDeltaModel) BOOL enableDeltaModel;
151 @property(nonatomic) UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0));
152 @property(nonatomic) UITextSmartDashesType smartDashesType API_AVAILABLE(ios(11.0));
153 @property(nonatomic, copy) UITextContentType textContentType API_AVAILABLE(ios(10.0));
154
155 @property(nonatomic, weak) UIAccessibilityElement* backingTextInputAccessibilityObject;
156
157 // Scribble Support
158 @property(nonatomic, weak) id<FlutterViewResponder> viewResponder;
159 @property(nonatomic) FlutterScribbleFocusStatus scribbleFocusStatus;
160 @property(nonatomic, strong) NSArray<FlutterTextSelectionRect*>* selectionRects;
161 - (void)resetScribbleInteractionStatusIfEnding;
162 - (BOOL)isScribbleAvailable;
163
164 - (instancetype)init NS_UNAVAILABLE;
165 + (instancetype)new NS_UNAVAILABLE;
166 - (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
167 - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
168 - (instancetype)initWithOwner:(FlutterTextInputPlugin*)textInputPlugin NS_DESIGNATED_INITIALIZER;
169
170 // TODO(louisehsu): These are being exposed to support Share in FlutterPlatformPlugin
171 // Consider moving that feature into FlutterTextInputPlugin to avoid exposing extra methods
172 - (CGRect)localRectFromFrameworkTransform:(CGRect)incomingRect;
173 - (CGRect)caretRectForPosition:(UITextPosition*)position;
174 @end
175
176 @interface UIView (FindFirstResponder)
177 @property(nonatomic, readonly) id flutterFirstResponder;
178 @end
179
180 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
caretRectForPosition
CGRect caretRectForPosition
Definition: FlutterTextInputPlugin.h:173
selectionRects
NSArray< FlutterTextSelectionRect * > * selectionRects
Definition: FlutterTextInputPlugin.h:160
keyboardType
UIKeyboardType keyboardType
Definition: FlutterTextInputPlugin.h:147
returnKeyType
UIReturnKeyType returnKeyType
Definition: FlutterTextInputPlugin.h:148
FlutterTextInputDelegate-p
Definition: FlutterTextInputDelegate.h:37
FlutterTextInputPlugin::indirectScribbleDelegate
id< FlutterIndirectScribbleDelegate > indirectScribbleDelegate
Definition: FlutterTextInputPlugin.h:37
backingTextInputAccessibilityObject
UIAccessibilityElement * backingTextInputAccessibilityObject
Definition: FlutterTextInputPlugin.h:155
keyboardAppearance
UIKeyboardAppearance keyboardAppearance
Definition: FlutterTextInputPlugin.h:146
isScribbleAvailable
BOOL isScribbleAvailable
Definition: FlutterTextInputPlugin.h:162
FlutterTextInputDelegate.h
API_AVAILABLE
UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0))
FlutterTokenizer
Definition: FlutterTextInputPlugin.h:88
FlutterChannels.h
secureTextEntry
BOOL secureTextEntry
Definition: FlutterTextInputPlugin.h:149
resetScribbleInteractionStatusIfEnding
void resetScribbleInteractionStatusIfEnding
Definition: FlutterTextInputPlugin.h:161
FlutterTextRange
Definition: FlutterTextInputPlugin.h:79
autocapitalizationType
UITextAutocapitalizationType autocapitalizationType
Definition: FlutterTextInputPlugin.h:142
initWithFrame
instancetype initWithFrame
Definition: FlutterTextInputPlugin.h:167
FlutterTextPlaceholder
Definition: FlutterTextInputPlugin.mm:728
autocorrectionType
UITextAutocorrectionType autocorrectionType
Definition: FlutterTextInputPlugin.h:143
-[FlutterTextInputPlugin textInputView]
UIView< UITextInput > * textInputView()
Definition: FlutterTextInputPlugin.mm:2347
initWithOwner
instancetype initWithOwner
Definition: FlutterTextInputPlugin.h:168
enablesReturnKeyAutomatically
BOOL enablesReturnKeyAutomatically
Definition: FlutterTextInputPlugin.h:145
viewController
FlutterViewController * viewController
Definition: FlutterTextInputPluginTest.mm:92
-[FlutterTextInputPlugin resetViewResponder]
void resetViewResponder()
Definition: FlutterTextInputPlugin.mm:2981
FlutterTextInputView
Definition: FlutterTextInputPlugin.mm:801
UIView(FindFirstResponder)
Definition: FlutterTextInputPlugin.h:176
FlutterTextInputPlugin::scribbleElements
NSMutableDictionary< UIScribbleElementIdentifier, NSValue * > * scribbleElements
Definition: FlutterTextInputPlugin.h:39
enableDeltaModel
BOOL enableDeltaModel
Definition: FlutterTextInputPlugin.h:150
FlutterViewResponder.h
selectedTextRange
API_AVAILABLE(ios(13.0)) @interface FlutterTextPlaceholder UITextRange * selectedTextRange
Definition: FlutterTextInputPlugin.h:125
FlutterMethodCall
Definition: FlutterCodecs.h:220
pendingDeltas
NSMutableArray * pendingDeltas
Definition: FlutterTextInputPlugin.h:139
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:33
localRectFromFrameworkTransform
CGRect localRectFromFrameworkTransform
Definition: FlutterTextInputPlugin.h:172
FlutterTextPosition::affinity
UITextStorageDirection affinity
Definition: FlutterTextInputPlugin.h:70
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
FlutterIndirectScribbleDelegate.h
initWithCoder
instancetype initWithCoder
Definition: FlutterTextInputPlugin.h:166
inputDelegate
id< UITextInputDelegate > inputDelegate
Definition: FlutterTextInputPlugin.h:138
viewResponder
id< FlutterViewResponder > viewResponder
Definition: FlutterTextInputPlugin.h:158
scribbleFocusStatus
FlutterScribbleFocusStatus scribbleFocusStatus
Definition: FlutterTextInputPlugin.h:159
NS_UNAVAILABLE
instancetype init NS_UNAVAILABLE
Definition: FlutterTextInputPlugin.h:164
FlutterTextPosition
Definition: FlutterTextInputPlugin.h:67
FlutterViewResponder-p
Definition: FlutterViewResponder.h:11
FLUTTER_DARWIN_EXPORT
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
text_editing_delta.h
FlutterTextPosition::index
NSUInteger index
Definition: FlutterTextInputPlugin.h:69
FlutterKeySecondaryResponder.h
markedTextStyle
NSDictionary * markedTextStyle
Definition: FlutterTextInputPlugin.h:137
FlutterTextSelectionRect
Definition: FlutterTextInputPlugin.h:91
NS_ENUM
typedef NS_ENUM(NSInteger, FlutterScribbleFocusStatus)
Definition: FlutterTextInputPlugin.h:17
spellCheckingType
UITextSpellCheckingType spellCheckingType
Definition: FlutterTextInputPlugin.h:144
markedTextRange
UITextRange * markedTextRange
Definition: FlutterTextInputPlugin.h:136