Flutter Engine
FlutterTextInputPlugin Class Reference

#import <FlutterTextInputPlugin.h>

Inheritance diagram for FlutterTextInputPlugin:
<FlutterKeySecondaryResponder> <FlutterKeySecondaryResponder>

Instance Methods

(void) - handleMethodCall:result:
 
(UIView< UITextInput > *) - textInputView
 
(instancetype) - initWithViewController:
 
(BOOL- isFirstResponder
 
(NSRect) - firstRectForCharacterRange:actualRange:
 
- Instance Methods inherited from <FlutterKeySecondaryResponder>
(BOOL- handlePress:
 
(BOOL- handleKeyEvent:
 

Properties

id< FlutterTextInputDelegate > textInputDelegate
 
FlutterTextFieldclient
 

Detailed Description

A plugin to handle text input.

Responsible for bridging the native macOS text input system with the Flutter framework text editing classes, via system channels.

This is not an FlutterPlugin since it needs access to FlutterViewController internals, so needs to be managed differently.

When accessibility is on, accessibility bridge creates a NSTextField, i.e. FlutterTextField, for every text field in the Flutter. This plugin acts as a field editor for those NSTextField[s].

Definition at line 15 of file FlutterTextInputPlugin.h.

Method Documentation

◆ firstRectForCharacterRange:actualRange:()

- (NSRect) firstRectForCharacterRange: (NSRange)  range
actualRange: (NSRangePointer)  actualRange 

◆ handleMethodCall:result:()

- (void) handleMethodCall: (FlutterMethodCall*)  call
result: (FlutterResult result 

Provided by category FlutterTextInputPlugin(TestMethods).

Definition at line 1648 of file FlutterTextInputPlugin.mm.

References API_AVAILABLE, args, FlutterMethodCall::arguments, autofillIdFromDictionary(), autofillTypeOf(), FlutterMethodNotImplemented, kAssociatedAutofillFields, kClearClientMethod, kFinishAutofillContextMethod, kHideMethod, kInvalidFirstRect, kSetClientMethod, kSetEditableSizeAndTransformMethod, kSetEditingStateMethod, kSetMarkedTextRectMethod, kShowMethod, FlutterMethodCall::method, result, state, FlutterTextInputView::textInputDelegate, and view.

Referenced by FlutterEngine::destroyContext, and FlutterInputPluginTestObjc::testEmptyCompositionRange.

1649  NSString* method = call.method;
1650  id args = call.arguments;
1651  if ([method isEqualToString:kShowMethod]) {
1652  [self showTextInput];
1653  result(nil);
1654  } else if ([method isEqualToString:kHideMethod]) {
1655  [self hideTextInput];
1656  result(nil);
1657  } else if ([method isEqualToString:kSetClientMethod]) {
1658  [self setTextInputClient:[args[0] intValue] withConfiguration:args[1]];
1659  result(nil);
1660  } else if ([method isEqualToString:kSetEditingStateMethod]) {
1661  [self setTextInputEditingState:args];
1662  result(nil);
1663  } else if ([method isEqualToString:kClearClientMethod]) {
1664  [self clearTextInputClient];
1665  result(nil);
1666  } else if ([method isEqualToString:kSetEditableSizeAndTransformMethod]) {
1667  [self setEditableSizeAndTransform:args];
1668  result(nil);
1669  } else if ([method isEqualToString:kSetMarkedTextRectMethod]) {
1670  [self updateMarkedRect:args];
1671  result(nil);
1672  } else if ([method isEqualToString:kFinishAutofillContextMethod]) {
1673  [self triggerAutofillSave:[args boolValue]];
1674  result(nil);
1675  } else {
1677  }
1678 }
G_BEGIN_DECLS FlValue * args
static NSString *const kSetEditingStateMethod
static NSString *const kShowMethod
GAsyncResult * result
static NSString *const kClearClientMethod
static NSString *const kSetClientMethod
static NSString *const kSetMarkedTextRectMethod
void(^ FlutterResult)(id _Nullable result)
static NSString *const kSetEditableSizeAndTransformMethod
static NSString *const kHideMethod
static NSString *const kFinishAutofillContextMethod
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented

◆ initWithViewController:()

- (instancetype) initWithViewController: (FlutterViewController*)  viewController

Initializes a text input plugin that coordinates key event handling with |viewController|.

Definition at line 171 of file FlutterTextInputPlugin.mm.

References _caretRect, _channel, _editableTransform, _flutterViewController, FALSE, and FlutterMethodChannel::methodChannelWithName:binaryMessenger:codec:.

171  :(FlutterViewController*)viewController {
172  // The view needs a non-zero frame.
173  self = [super initWithFrame:NSMakeRect(0, 0, 1, 1)];
174  if (self != nil) {
175  _flutterViewController = viewController;
177  binaryMessenger:viewController.engine.binaryMessenger
178  codec:[FlutterJSONMethodCodec sharedInstance]];
179  _shown = FALSE;
180  // NSTextView does not support _weak reference, so this class has to
181  // use __unsafe_unretained and manage the reference by itself.
182  //
183  // Since the dealloc removes the handler, the pointer should
184  // be valid if the handler is ever called.
185  __unsafe_unretained FlutterTextInputPlugin* unsafeSelf = self;
186  [_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
187  [unsafeSelf handleMethodCall:call result:result];
188  }];
189  _textInputContext = [[NSTextInputContext alloc] initWithClient:self];
190  _previouslyPressedFlags = 0;
191 
192  _flutterViewController = viewController;
193 
194  // Initialize with the zero matrix which is not
195  // an affine transform.
196  _editableTransform = CATransform3D();
197  _caretRect = CGRectNull;
198  }
199  return self;
200 }
FlutterMethodChannel * _channel
instancetype methodChannelWithName:binaryMessenger:codec:(NSString *name, [binaryMessenger] NSObject< FlutterBinaryMessenger > *messenger, [codec] NSObject< FlutterMethodCodec > *codec)
CATransform3D _editableTransform
CGRect _caretRect
fml::scoped_nsobject< UIViewController > _flutterViewController
return FALSE

◆ isFirstResponder()

- (BOOL) isFirstResponder

Whether this plugin is the first responder of this NSWindow.

When accessibility is on, this plugin is set as the first responder to act as the field editor for FlutterTextFields.

Returns false if accessibility is off.

Definition at line 202 of file FlutterTextInputPlugin.mm.

References _caretRect, _editableTransform, FlutterMethodCall::arguments, flutter::TextRange::base(), event, FALSE, FlutterMethodNotImplemented, id, kClearClientMethod, kComposingBaseKey, kComposingExtentKey, kHideMethod, kMultilineInputType, kSelectionAffinityKey, kSelectionBaseKey, kSelectionExtentKey, kSelectionIsDirectionalKey, kSetCaretRect, kSetClientMethod, kSetEditableSizeAndTransform, kSetEditingStateMethod, kShowMethod, kTextAffinityDownstream, kTextAffinityUpstream, kTextKey, FlutterMethodCall::method, RangeFromBaseExtent(), result, flutter::TextRange::start(), state, text, flutter::transform, and TRUE.

202  {
203  if (!self.flutterViewController.viewLoaded) {
204  return false;
205  }
206  return [self.flutterViewController.view.window firstResponder] == self;
207 }

◆ textInputView()

- (UIView< UITextInput > *) textInputView

The UITextInput implementation used to control text entry.

This is used by AccessibilityBridge to forward interactions with iOS' accessibility system.

Definition at line 1644 of file FlutterTextInputPlugin.mm.

1644  {
1645  return _activeView;
1646 }

Property Documentation

◆ client

- (FlutterTextField*) client
readwritenonatomicweak

The NSTextField that currently has this plugin as its field editor.

Must be nil if accessibility is off.

Definition at line 32 of file FlutterTextInputPlugin.h.

Referenced by FlutterTextField::updateString:withSelection:.

◆ textInputDelegate

- (id<FlutterTextInputDelegate>) textInputDelegate
readwritenonatomicassign

Definition at line 17 of file FlutterTextInputPlugin.h.


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