| Flutter macOS Embedder |

Classes | Functions | Variables
FlutterTextInputPlugin.mm File Reference
`#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h"`
`#import <Foundation/Foundation.h>`
`#import <objc/message.h>`
`#include <algorithm>`
`#include <memory>`
`#include "flutter/fml/platform/darwin/string_range_sanitization.h"`
`#include "flutter/shell/platform/common/text_editing_delta.h"`
`#include "flutter/shell/platform/common/text_input_model.h"`
`#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h"`
`#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputSemanticsObject.h"`
`#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"`
`#import "flutter/shell/platform/darwin/macos/framework/Source/NSView+ClipsToBounds.h"`

Go to the source code of this file.

## Classes
category | NSEvent(KeyEquivalentMarker)

## Functions
typedef | NS_ENUM (NSUInteger, FlutterTextAffinity)
static flutter::TextRange | RangeFromBaseExtent (NSNumber *base, NSNumber *extent, const flutter::TextRange &range)
static NSString * | GetAutofillHint (NSDictionary *autofill)
static NSTextContentType | GetTextContentType (NSDictionary *configuration) API_AVAILABLE(macos(11.0))
static BOOL | EnableAutocompleteForTextInputConfiguration (NSDictionary *configuration)
static BOOL | EnableAutocomplete (NSDictionary *configuration)

## Variables
static NSString *const | kTextInputChannel = @"@"flutter/textinput"
static NSString *const | kSetClientMethod = @"@"TextInput.setClient"
static NSString *const | kShowMethod = @"@"TextInput.show"
static NSString *const | kHideMethod = @"@"TextInput.hide"
static NSString *const | kClearClientMethod = @"@"TextInput.clearClient"
static NSString *const | kSetEditingStateMethod = @"@"TextInput.setEditingState"
static NSString *const | kSetEditableSizeAndTransform = @"@"TextInput.setEditableSizeAndTransform"
static NSString *const | kSetCaretRect = @"@"TextInput.setCaretRect"
static NSString *const | kUpdateEditStateResponseMethod = @"@"TextInputClient.updateEditingState"
static NSString *const | kUpdateEditStateWithDeltasResponseMethod
static NSString *const | kPerformAction = @"@"TextInputClient.performAction"
static NSString *const | kPerformSelectors = @"@"TextInputClient.performSelectors"
static NSString *const | kMultilineInputType = @"@"TextInputType.multiline"
static NSString *const | kSecureTextEntry = @"@"obscureText"
static NSString *const | kTextInputAction = @"@"inputAction"
static NSString *const | kEnableDeltaModel = @"@"enableDeltaModel"
static NSString *const | kTextInputType = @"@"inputType"
static NSString *const | kTextInputTypeName = @"@"name"
static NSString *const | kSelectionBaseKey = @"@"selectionBase"
static NSString *const | kSelectionExtentKey = @"@"selectionExtent"
static NSString *const | kSelectionAffinityKey = @"@"selectionAffinity"
static NSString *const | kSelectionIsDirectionalKey = @"@"selectionIsDirectional"
static NSString *const | kComposingBaseKey = @"@"composingBase"
static NSString *const | kComposingExtentKey = @"@"composingExtent"
static NSString *const | kTextKey = @"@"text"
static NSString *const | kTransformKey = @"@"transform"
static NSString *const | kAssociatedAutofillFields = @"@"fields"
static NSString *const | kAutofillProperties = @"@"autofill"
static NSString *const | kAutofillId = @"@"uniqueIdentifier"
static NSString *const | kAutofillEditingValue = @"@"editingValue"
static NSString *const | kAutofillHints = @"@"hints"
static NSString *const | kTextAffinityDownstream = @"@"TextAffinity.downstream"
static NSString *const | kTextAffinityUpstream = @"@"TextAffinity.upstream"
static NSString *const | kInputActionNewline = @"@"TextInputAction.newline"
static char | markerKey
CATransform3D | _editableTransform
CGRect | _caretRect

## Function Documentation

## ◆ EnableAutocomplete()

static BOOL EnableAutocomplete | ( | NSDictionary * | configuration | ) |
| static

Definition at line 158 of file FlutterTextInputPlugin.mm.

158 {
159 for (NSDictionary* field in configuration[kAssociatedAutofillFields]) {
160 if (!EnableAutocompleteForTextInputConfiguration(field)) {
161 return NO;
162 }
163 }
164
165 // Check the top-level TextInputConfiguration.
166 return EnableAutocompleteForTextInputConfiguration(configuration);
167 }

References EnableAutocompleteForTextInputConfiguration(), and kAssociatedAutofillFields.

## ◆ EnableAutocompleteForTextInputConfiguration()

static BOOL EnableAutocompleteForTextInputConfiguration | ( | NSDictionary * | configuration | ) |
| static

Definition at line 130 of file FlutterTextInputPlugin.mm.

130 {
131 // Disable if obscureText is set.
132 if ([configuration[kSecureTextEntry] boolValue]) {
133 return NO;
134 }
135
136 // Disable if autofill properties are not set.
137 NSDictionary* autofill = configuration[kAutofillProperties];
138 if (autofill == nil) {
139 return NO;
140 }
141
142 // Disable if autofill properties indicate a username/password.
143 // See: https://github.com/flutter/flutter/issues/119824
144 NSString* hint = GetAutofillHint(autofill);
145 if ([hint isEqualToString:@"password"] || [hint isEqualToString:@"username"]) {
146 return NO;
147 }
148 return YES;
149 }

References GetAutofillHint(), kAutofillProperties, and kSecureTextEntry.

Referenced by EnableAutocomplete().

## ◆ GetAutofillHint()

static NSString* GetAutofillHint | ( | NSDictionary * | autofill | ) |
| static

Definition at line 97 of file FlutterTextInputPlugin.mm.

97 {
98 NSArray<NSString*>* hints = autofill[kAutofillHints];
99 return hints.count > 0 ? hints[0] : nil;
100 }

References kAutofillHints.

Referenced by EnableAutocompleteForTextInputConfiguration(), and GetTextContentType().

## ◆ GetTextContentType()

static NSTextContentType GetTextContentType | ( | NSDictionary * | configuration | ) |
| static

Definition at line 104 of file FlutterTextInputPlugin.mm.

105 {
106 // Check autofill hints.
107 NSDictionary* autofill = configuration[kAutofillProperties];
108 if (autofill) {
109 NSString* hint = GetAutofillHint(autofill);
110 if ([hint isEqualToString:@"username"]) {
111 return NSTextContentTypeUsername;
112 }
113 if ([hint isEqualToString:@"password"]) {
114 return NSTextContentTypePassword;
115 }
116 if ([hint isEqualToString:@"oneTimeCode"]) {
117 return NSTextContentTypeOneTimeCode;
118 }
119 }
120 // If no autofill hints, guess based on other attributes.
121 if ([configuration[kSecureTextEntry] boolValue]) {
122 return NSTextContentTypePassword;
123 }
124 return nil;
125 }

References GetAutofillHint(), kAutofillProperties, and kSecureTextEntry.

## ◆ NS_ENUM()

typedef NS_ENUM | ( | NSUInteger | ,
|  | FlutterTextAffinity |
| ) |  |

The affinity of the current cursor position. If the cursor is at a position representing a soft line break, the cursor may be drawn either at the end of the current line (upstream) or at the beginning of the next (downstream).

Definition at line 74 of file FlutterTextInputPlugin.mm.

74 {
75 kFlutterTextAffinityUpstream,
76 kFlutterTextAffinityDownstream
77 };

## ◆ RangeFromBaseExtent()

static flutter::TextRange RangeFromBaseExtent | ( | NSNumber * | base,
|  | NSNumber * | extent,
|  | const flutter::TextRange & | range
| ) |  |
| static

Definition at line 84 of file FlutterTextInputPlugin.mm.

86 {
87 if (base == nil || extent == nil) {
88 return range;
89 }
90 if (base.intValue == -1 && extent.intValue == -1) {
91 return flutter::TextRange(0, 0);
92 }
93 return flutter::TextRange([base unsignedLongValue], [extent unsignedLongValue]);
94 }

## Variable Documentation

## ◆ _caretRect

CGRect _caretRect

Current position of caret in local (editable) coordinates.

Definition at line 339 of file FlutterTextInputPlugin.mm.

Referenced by FlutterTextInputPlugin::initWithViewController:.

## ◆ _editableTransform

CATransform3D _editableTransform

Initial value:
{
std::unique_ptr<flutter::TextInputModel> _activeModel

Transform for current the editable. Used to determine position of accent selection menu.

Definition at line 325 of file FlutterTextInputPlugin.mm.

Referenced by FlutterTextInputPlugin::initWithViewController:.

## ◆ kAssociatedAutofillFields

NSString* const kAssociatedAutofillFields = @"@"fields"
| static

Definition at line 53 of file FlutterTextInputPlugin.mm.

Referenced by EnableAutocomplete().

## ◆ kAutofillEditingValue

NSString* const kAutofillEditingValue = @"@"editingValue"
| static

Definition at line 58 of file FlutterTextInputPlugin.mm.

## ◆ kAutofillHints

NSString* const kAutofillHints = @"@"hints"
| static

Definition at line 59 of file FlutterTextInputPlugin.mm.

Referenced by GetAutofillHint().

## ◆ kAutofillId

NSString* const kAutofillId = @"@"uniqueIdentifier"
| static

Definition at line 57 of file FlutterTextInputPlugin.mm.

## ◆ kAutofillProperties

NSString* const kAutofillProperties = @"@"autofill"
| static

Definition at line 56 of file FlutterTextInputPlugin.mm.

Referenced by EnableAutocompleteForTextInputConfiguration(), and GetTextContentType().

## ◆ kClearClientMethod

NSString* const kClearClientMethod = @"@"TextInput.clearClient"
| static

Definition at line 28 of file FlutterTextInputPlugin.mm.

## ◆ kComposingBaseKey

NSString* const kComposingBaseKey = @"@"composingBase"
| static

Definition at line 49 of file FlutterTextInputPlugin.mm.

## ◆ kComposingExtentKey

NSString* const kComposingExtentKey = @"@"composingExtent"
| static

Definition at line 50 of file FlutterTextInputPlugin.mm.

## ◆ kEnableDeltaModel

NSString* const kEnableDeltaModel = @"@"enableDeltaModel"
| static

Definition at line 42 of file FlutterTextInputPlugin.mm.

## ◆ kHideMethod

NSString* const kHideMethod = @"@"TextInput.hide"
| static

Definition at line 27 of file FlutterTextInputPlugin.mm.

## ◆ kInputActionNewline

NSString* const kInputActionNewline = @"@"TextInputAction.newline"
| static

Definition at line 66 of file FlutterTextInputPlugin.mm.

## ◆ kMultilineInputType

NSString* const kMultilineInputType = @"@"TextInputType.multiline"
| static

Definition at line 37 of file FlutterTextInputPlugin.mm.

## ◆ kPerformAction

NSString* const kPerformAction = @"@"TextInputClient.performAction"
| static

Definition at line 35 of file FlutterTextInputPlugin.mm.

## ◆ kPerformSelectors

NSString* const kPerformSelectors = @"@"TextInputClient.performSelectors"
| static

Definition at line 36 of file FlutterTextInputPlugin.mm.

## ◆ kSecureTextEntry

NSString* const kSecureTextEntry = @"@"obscureText"
| static

Definition at line 40 of file FlutterTextInputPlugin.mm.

Referenced by EnableAutocompleteForTextInputConfiguration(), and GetTextContentType().

## ◆ kSelectionAffinityKey

NSString* const kSelectionAffinityKey = @"@"selectionAffinity"
| static

Definition at line 47 of file FlutterTextInputPlugin.mm.

## ◆ kSelectionBaseKey

NSString* const kSelectionBaseKey = @"@"selectionBase"
| static

Definition at line 45 of file FlutterTextInputPlugin.mm.

## ◆ kSelectionExtentKey

NSString* const kSelectionExtentKey = @"@"selectionExtent"
| static

Definition at line 46 of file FlutterTextInputPlugin.mm.

## ◆ kSelectionIsDirectionalKey

NSString* const kSelectionIsDirectionalKey = @"@"selectionIsDirectional"
| static

Definition at line 48 of file FlutterTextInputPlugin.mm.

## ◆ kSetCaretRect

NSString* const kSetCaretRect = @"@"TextInput.setCaretRect"
| static

Definition at line 31 of file FlutterTextInputPlugin.mm.

## ◆ kSetClientMethod

NSString* const kSetClientMethod = @"@"TextInput.setClient"
| static

Definition at line 25 of file FlutterTextInputPlugin.mm.

## ◆ kSetEditableSizeAndTransform

NSString* const kSetEditableSizeAndTransform = @"@"TextInput.setEditableSizeAndTransform"
| static

Definition at line 30 of file FlutterTextInputPlugin.mm.

## ◆ kSetEditingStateMethod

NSString* const kSetEditingStateMethod = @"@"TextInput.setEditingState"
| static

Definition at line 29 of file FlutterTextInputPlugin.mm.

## ◆ kShowMethod

NSString* const kShowMethod = @"@"TextInput.show"
| static

Definition at line 26 of file FlutterTextInputPlugin.mm.

## ◆ kTextAffinityDownstream

NSString* const kTextAffinityDownstream = @"@"TextAffinity.downstream"
| static

Definition at line 62 of file FlutterTextInputPlugin.mm.

## ◆ kTextAffinityUpstream

NSString* const kTextAffinityUpstream = @"@"TextAffinity.upstream"
| static

Definition at line 63 of file FlutterTextInputPlugin.mm.

## ◆ kTextInputAction

NSString* const kTextInputAction = @"@"inputAction"
| static

Definition at line 41 of file FlutterTextInputPlugin.mm.

## ◆ kTextInputChannel

NSString* const kTextInputChannel = @"@"flutter/textinput"
| static

Definition at line 21 of file FlutterTextInputPlugin.mm.

## ◆ kTextInputType

NSString* const kTextInputType = @"@"inputType"
| static

Definition at line 43 of file FlutterTextInputPlugin.mm.

## ◆ kTextInputTypeName

NSString* const kTextInputTypeName = @"@"name"
| static

Definition at line 44 of file FlutterTextInputPlugin.mm.

## ◆ kTextKey

NSString* const kTextKey = @"@"text"
| static

Definition at line 51 of file FlutterTextInputPlugin.mm.

## ◆ kTransformKey

NSString* const kTransformKey = @"@"transform"
| static

Definition at line 52 of file FlutterTextInputPlugin.mm.

## ◆ kUpdateEditStateResponseMethod

NSString* const kUpdateEditStateResponseMethod = @"@"TextInputClient.updateEditingState"
| static

Definition at line 32 of file FlutterTextInputPlugin.mm.

## ◆ kUpdateEditStateWithDeltasResponseMethod

NSString* const kUpdateEditStateWithDeltasResponseMethod
| static

Initial value:
=
@"@"TextInputClient.updateEditingStateWithDeltas"

Definition at line 33 of file FlutterTextInputPlugin.mm.

## ◆ markerKey

char markerKey
| static

Definition at line 188 of file FlutterTextInputPlugin.mm.

Referenced by NSEvent(KeyEquivalentMarker)::markAsKeyEquivalent.

EnableAutocompleteForTextInputConfiguration
static BOOL EnableAutocompleteForTextInputConfiguration(NSDictionary *configuration)
Definition: FlutterTextInputPlugin.mm:130
kAutofillProperties
static NSString *const kAutofillProperties
Definition: FlutterTextInputPlugin.mm:56
kSecureTextEntry
static NSString *const kSecureTextEntry
Definition: FlutterTextInputPlugin.mm:40
kAssociatedAutofillFields
static NSString *const kAssociatedAutofillFields
Definition: FlutterTextInputPlugin.mm:53
flutter::TextRange
Definition: text_range.h:19
GetAutofillHint
static NSString * GetAutofillHint(NSDictionary *autofill)
Definition: FlutterTextInputPlugin.mm:97
kAutofillHints
static NSString *const kAutofillHints
Definition: FlutterTextInputPlugin.mm:59