| Flutter macOS Embedder |

Instance Methods | Properties | List of all members
FlutterTextInputPlugin Class Reference

`#import <FlutterTextInputPlugin.h>`

Inheritance diagram for FlutterTextInputPlugin:

## Instance Methods
(instancetype) | - initWithDelegate:
(BOOL) | - isFirstResponder
(BOOL) | - handleKeyEvent:
(void) | - handleMethodCall:result:
(NSRect) | - firstRectForCharacterRange:actualRange:
(NSDictionary *) | - editingState

## Properties
FlutterTextField * | client
FlutterViewController * | currentViewController
NSTextInputContext * | textInputContext
NSString * | customRunLoopMode

## 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 41 of file FlutterTextInputPlugin.h.

## Method Documentation

## ◆ editingState

- (NSDictionary*) editingState |  |  |

Provided by category FlutterTextInputPlugin(TestMethods).

## ◆ firstRectForCharacterRange:actualRange:

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

Provided by category FlutterTextInputPlugin(TestMethods).

## ◆ handleKeyEvent:

- (BOOL) handleKeyEvent: |  | (NSEvent*) | event |

Handles key down events received from the view controller, responding YES if the event was handled.

Note, the Apple docs suggest that clients should override essentially all the mouse and keyboard event-handling methods of NSResponder. However, experimentation indicates that only key events are processed by the native layer; Flutter processes mouse events. Additionally, processing both keyUp and keyDown results in duplicate processing of the same keys.

Definition at line 341 of file FlutterTextInputPlugin.mm.

621 :(NSEvent*)event {
622 if (event.type == NSEventTypeKeyUp ||
623 (event.type == NSEventTypeFlagsChanged && event.modifierFlags < _previouslyPressedFlags)) {
624 return NO;
625 }
626 _previouslyPressedFlags = event.modifierFlags;
627 if (!_shown) {
628 return NO;
629 }
630
631 _eventProducedOutput = NO;
632 BOOL res = [_textInputContext handleEvent:event];
633 // NSTextInputContext#handleEvent returns YES if the context handles the event. One of the reasons
634 // the event is handled is because it's a key equivalent. But a key equivalent might produce a
635 // text command (indicated by calling doCommandBySelector) or might not (for example, Cmd+Q). In
636 // the latter case, this command somehow has not been executed yet and Flutter must dispatch it to
637 // the next responder. See https://github.com/flutter/flutter/issues/106354 .
638 // The event is also not redispatched if there is IME composition active, because it might be
639 // handled by the IME. See https://github.com/flutter/flutter/issues/134699
640
641 // both NSEventModifierFlagNumericPad and NSEventModifierFlagFunction are set for arrow keys.
642 bool is_navigation = event.modifierFlags & NSEventModifierFlagFunction &&
643 event.modifierFlags & NSEventModifierFlagNumericPad;
644 bool is_navigation_in_ime = is_navigation && self.hasMarkedText;
645
646 if (event.isKeyEquivalent && !is_navigation_in_ime && !_eventProducedOutput) {
647 return NO;
648 }
649 return res;
650 }

References FlutterMethodChannel::methodChannelWithName:binaryMessenger:codec:.

## ◆ handleMethodCall:result:

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

Provided by category FlutterTextInputPlugin(TestMethods).

Referenced by flutter::testing::TEST().

## ◆ initWithDelegate:

- (instancetype) initWithDelegate: |  | (id<FlutterTextInputPluginDelegate>) | delegate |

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

Definition at line 341 of file FlutterTextInputPlugin.mm.

349 :(id<FlutterTextInputPluginDelegate>)delegate {
350 // The view needs an empty frame otherwise it is visible on dark background.
351 // https://github.com/flutter/flutter/issues/118504
352 self = [super initWithFrame:NSZeroRect];
353 self.clipsToBounds = YES;
354 if (self != nil) {
355 _delegate = delegate;
356 _channel = [FlutterMethodChannel methodChannelWithName:kTextInputChannel
357 binaryMessenger:_delegate.binaryMessenger
358 codec:[FlutterJSONMethodCodec sharedInstance]];
359 _shown = FALSE;
360 // NSTextView does not support _weak reference, so this class has to
361 // use __unsafe_unretained and manage the reference by itself.
362 //
363 // Since the dealloc removes the handler, the pointer should
364 // be valid if the handler is ever called.
365 __unsafe_unretained FlutterTextInputPlugin* unsafeSelf = self;
366 [_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
367 [unsafeSelf handleMethodCall:call result:result];
368 }];
369 _textInputContext = [[NSTextInputContext alloc] initWithClient:unsafeSelf];
370 _previouslyPressedFlags = 0;
371
372 // Initialize with the zero matrix which is not
373 // an affine transform.
374 _editableTransform = CATransform3D();
375 _caretRect = CGRectNull;
376 }
377 return self;
378 }
FlutterJSONMethodCodec
Definition: FlutterCodecs.h:455
FlutterMethodChannel
Definition: FlutterChannels.h:221
+[FlutterMethodChannel methodChannelWithName:binaryMessenger:codec:]
instancetype methodChannelWithName:binaryMessenger:codec:(NSString *name,[binaryMessenger] NSObject< FlutterBinaryMessenger > *messenger,[codec] NSObject< FlutterMethodCodec > *codec)
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:42

## ◆ 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 341 of file FlutterTextInputPlugin.mm.

380 {
381 if (!_currentViewController.viewLoaded) {
382 return false;
383 }
384 return [_currentViewController.view.window firstResponder] == self;
385 }

## 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 48 of file FlutterTextInputPlugin.h.

## ◆ currentViewController

- (FlutterViewController*) currentViewController
| readnonatomicweak

Returns the view controller text input plugin is currently attached to, nil if not attached to any view controller.

Definition at line 54 of file FlutterTextInputPlugin.h.

## ◆ customRunLoopMode

- (NSString*) customRunLoopMode
| readwritenonatomicassign

Provided by category FlutterTextInputPlugin(TestMethods).

Definition at line 91 of file FlutterTextInputPlugin.h.

## ◆ textInputContext

- (NSTextInputContext*) textInputContext
| readwritenonatomicassign

Provided by category FlutterTextInputPlugin(TestMethods).

Definition at line 90 of file FlutterTextInputPlugin.h.

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

- shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h
- shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.mm