Flutter Engine
The Flutter Engine
Instance Methods | List of all members
FlutterTextField Class Reference

#import <FlutterTextInputSemanticsObject.h>

Inheritance diagram for FlutterTextField:
FlutterTextFieldMock

Instance Methods

(instancetype) - initWithPlatformNode:fieldEditor:
 
(void) - updateString:withSelection:
 
(void) - startEditing
 
(NSRect) - frame [implementation]
 
(void) - setAccessibilityFocused: [implementation]
 
(void) - setPlatformNode: [implementation]
 
(void) - dealloc [implementation]
 

Detailed Description

An NSTextField implementation that represents the NativeViewAccessible for the FlutterTextPlatformNode

The NSAccessibility protocol does not provide full support for text editing. This appkit text field is used to get around this problem. The FlutterTextPlatformNode creates a hidden FlutterTextField, since VoiceOver only provides text editing announcements for NSTextField subclasses.

All of the text editing events in this native text field are redirected to the FlutterTextInputPlugin.

Definition at line 81 of file FlutterTextInputSemanticsObject.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 64 of file FlutterTextInputSemanticsObject.mm.

151 {
152 if (_plugin.client == self) {
153 _plugin.client = nil;
154 }
155}
FlutterTextInputPlugin * _plugin

◆ frame

- (NSRect) frame
implementation

Definition at line 64 of file FlutterTextInputSemanticsObject.mm.

93 {
94 if (!_node) {
95 return NSZeroRect;
96 }
97 return _node->GetFrame();
98}

◆ initWithPlatformNode:fieldEditor:

- (instancetype) initWithPlatformNode: (flutter::FlutterTextPlatformNode*)  node
fieldEditor: (FlutterTextInputPlugin*)  plugin 

Initializes a FlutterTextField that uses the FlutterTextInputPlugin as its field editor. The text field redirects all of the text editing events to the FlutterTextInputPlugin.

Definition at line 64 of file FlutterTextInputSemanticsObject.mm.

70 fieldEditor:(FlutterTextInputPlugin*)plugin {
71 self = [super initWithFrame:NSZeroRect];
72 if (self) {
73 _node = node;
74 _plugin = plugin;
75 [self setCell:[[FlutterTextFieldCell alloc] initWithTextField:self fieldEditor:plugin]];
76 }
77 return self;
78}
The ax platform node for a text field.

◆ setAccessibilityFocused:

- (void) setAccessibilityFocused: (BOOL isFocused
implementation

Definition at line 64 of file FlutterTextInputSemanticsObject.mm.

102 :(BOOL)isFocused {
103 if (!_node) {
104 return;
105 }
106 [super setAccessibilityFocused:isFocused];
109 _node->GetDelegate()->AccessibilityPerformAction(data);
110}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
int BOOL
Definition: windows_types.h:37

◆ setPlatformNode:

- (void) setPlatformNode: (flutter::FlutterTextPlatformNode*)  node
implementation

Provided by category FlutterTextField(Testing).

Definition at line 64 of file FlutterTextInputSemanticsObject.mm.

146 _node = node;
147}

◆ startEditing

- (void) startEditing

Makes the field editor (plugin) current editor for this TextField, meaning that the text field will start getting editing events.

Definition at line 64 of file FlutterTextInputSemanticsObject.mm.

112 {
113 if (!_plugin) {
114 return;
115 }
116 if (self.currentEditor == _plugin) {
117 return;
118 }
119 if (!_node) {
120 return;
121 }
122 // Selecting text seems to be the only way to make the field editor
123 // current editor.
124 [self selectText:self];
125 NSAssert(self.currentEditor == _plugin, @"Failed to set current editor");
126
127 _plugin.client = self;
128
129 // Restore previous selection.
130 NSString* textValue = @(_node->GetStringAttribute(ax::mojom::StringAttribute::kValue).data());
131 int start = _node->GetIntAttribute(ax::mojom::IntAttribute::kTextSelStart);
132 int end = _node->GetIntAttribute(ax::mojom::IntAttribute::kTextSelEnd);
133 NSAssert((start >= 0 && end >= 0) || (start == -1 && end == -1), @"selection is invalid");
134 NSRange selection;
135 if (start >= 0 && end >= 0) {
136 selection = NSMakeRange(MIN(start, end), ABS(end - start));
137 } else {
138 // The native behavior is to place the cursor at the end of the string if
139 // there is no selection.
140 selection = NSMakeRange([self stringValue].length, 0);
141 }
142 [self updateString:textValue withSelection:selection];
143}
glong glong end
size_t length

◆ updateString:withSelection:

- (void) updateString: (NSString*)  string
withSelection: (NSRange)  selection 

Updates the string value and the selection of this text field.

Calling this method is necessary for macOS to get notified about string and selection changes.

Reimplemented in FlutterTextFieldMock.

Definition at line 64 of file FlutterTextInputSemanticsObject.mm.

80 :(NSString*)string withSelection:(NSRange)selection {
81 NSAssert(_plugin.client == self,
82 @"Can't update FlutterTextField when it is not the first responder");
83 if (![[self stringValue] isEqualToString:string]) {
84 [self setStringValue:string];
85 }
86 if (!NSEqualRanges(_plugin.selectedRange, selection)) {
87 [_plugin setSelectedRange:selection];
88 }
89}

The documentation for this class was generated from the following files: