5#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputSemanticsObject.h"
7#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
8#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h"
9#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
11#include "flutter/third_party/accessibility/ax/ax_action_data.h"
12#include "flutter/third_party/accessibility/gfx/geometry/rect_conversions.h"
13#include "flutter/third_party/accessibility/gfx/mac/coordinate_conversion.h"
15#pragma mark - FlutterTextFieldCell
28- (instancetype)initWithTextField:(NSTextField*)textField fieldEditor:(NSTextView*)editor;
38- (instancetype)initWithTextField:(NSTextField*)textField fieldEditor:(NSTextView*)editor {
39 self = [
super initTextCell:textField.stringValue];
42 [
self setControlView:textField];
47 self.selectable = YES;
54- (NSTextView*)fieldEditorForView:(NSView*)controlView {
60#pragma mark - FlutterTextField
69- (instancetype)initWithPlatformNode:(
flutter::FlutterTextPlatformNode*)node
71 self = [
super initWithFrame:NSZeroRect];
80- (void)updateString:(NSString*)string withSelection:(NSRange)selection {
82 @"Can't update FlutterTextField when it is not the first responder");
83 if (![[
self stringValue] isEqualToString:
string]) {
84 [
self setStringValue:string];
86 if (!NSEqualRanges(
_plugin.selectedRange, selection)) {
87 [_plugin setSelectedRange:selection];
97 return _node->GetFrame();
100#pragma mark - NSAccessibilityProtocol
102- (void)setAccessibilityFocused:(
BOOL)isFocused {
106 [
super setAccessibilityFocused:isFocused];
109 _node->GetDelegate()->AccessibilityPerformAction(
data);
112- (void)startEditing {
124 [
self selectText:self];
125 NSAssert(
self.currentEditor ==
_plugin,
@"Failed to set current editor");
133 NSAssert((
start >= 0 &&
end >= 0) || (
start == -1 &&
end == -1),
@"selection is invalid");
140 selection = NSMakeRange([
self stringValue].
length, 0);
142 [
self updateString:textValue withSelection:selection];
145- (void)setPlatformNode:(
flutter::FlutterTextPlatformNode*)node {
149#pragma mark - NSObject
164 view_controller_ = view_controller;
167 fieldEditor:view_controller.textInputPlugin];
168 appkit_text_field_.bezeled = NO;
169 appkit_text_field_.drawsBackground = NO;
170 appkit_text_field_.bordered = NO;
171 appkit_text_field_.focusRingType = NSFocusRingTypeNone;
176 EnsureDetachedFromView();
180 if (EnsureAttachedToView()) {
181 return appkit_text_field_;
187 if (!view_controller_.viewLoaded) {
201 ns_local_bounds.origin.y = -ns_local_bounds.origin.y - ns_local_bounds.size.height;
202 NSRect ns_view_bounds = [
view_controller_.flutterView convertRectFromBacking:ns_local_bounds];
203 return [
view_controller_.flutterView convertRect:ns_view_bounds toView:nil];
206bool FlutterTextPlatformNode::EnsureAttachedToView() {
207 if (!view_controller_.viewLoaded) {
210 if ([appkit_text_field_ isDescendantOf:view_controller_.
view]) {
213 [view_controller_.view addSubview:appkit_text_field_
214 positioned:NSWindowBelow
215 relativeTo:view_controller_.flutterView];
219void FlutterTextPlatformNode::EnsureDetachedFromView() {
220 [appkit_text_field_ removeFromSuperview];
FlutterTextInputPlugin * _plugin
The ax platform node for a text field.
FlutterTextPlatformNode(FlutterPlatformNodeDelegate *delegate, __weak FlutterViewController *view_controller)
Creates a FlutterTextPlatformNode that uses a FlutterTextField as its NativeViewAccessible.
~FlutterTextPlatformNode() override
NSRect GetFrame()
Gets the frame of this platform node relative to the view of FlutterViewController....
gfx::NativeViewAccessible GetNativeViewAccessible() override
FlutterView * view() const
void setPlatformNode:(flutter::FlutterTextPlatformNode *node)
FlutterTextField * client
Optional< SkRect > bounds
UnimplementedNativeViewAccessible * NativeViewAccessible
std::shared_ptr< const fml::Mapping > data