| Flutter macOS Embedder |

FlutterTextInputPlugin.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import <Cocoa/Cocoa.h>
6
7 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
8 #import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h"
9
10 @class FlutterTextField;
11
12 @interface NSView (ClipsToBounds)
13 // This property is available since macOS 10.9 but only declared in macOS 14 SDK.
14 @property BOOL clipsToBounds API_AVAILABLE(macos(10.9));
15 @end
16
17 /**
18 * A plugin to handle text input.
19 *
20 * Responsible for bridging the native macOS text input system with the Flutter framework text
21 * editing classes, via system channels.
22 *
23 * This is not an FlutterPlugin since it needs access to FlutterViewController internals, so needs
24 * to be managed differently.
25 *
26 * When accessibility is on, accessibility bridge creates a NSTextField, i.e. FlutterTextField,
27 * for every text field in the Flutter. This plugin acts as a field editor for those NSTextField[s].
28 */
29 @interface FlutterTextInputPlugin : NSTextView
30
31 /**
32 * The NSTextField that currently has this plugin as its field editor.
33 *
34 * Must be nil if accessibility is off.
35 */
36 @property(nonatomic, weak) FlutterTextField* client;
37
38 /**
39 * Initializes a text input plugin that coordinates key event handling with |viewController|.
40 */
41 - (instancetype)initWithViewController:(FlutterViewController*)viewController;
42
43 /**
44 * Whether this plugin is the first responder of this NSWindow.
45 *
46 * When accessibility is on, this plugin is set as the first responder to act as the field
47 * editor for FlutterTextFields.
48 *
49 * Returns false if accessibility is off.
50 */
51 - (BOOL)isFirstResponder;
52
53 /**
54 * Handles key down events received from the view controller, responding YES if
55 * the event was handled.
56 *
57 * Note, the Apple docs suggest that clients should override essentially all the
58 * mouse and keyboard event-handling methods of NSResponder. However, experimentation
59 * indicates that only key events are processed by the native layer; Flutter processes
60 * mouse events. Additionally, processing both keyUp and keyDown results in duplicate
61 * processing of the same keys.
62 */
63 - (BOOL)handleKeyEvent:(NSEvent*)event;
64
65 @end
66
67 // Private methods made visible for testing
68 @interface FlutterTextInputPlugin (TestMethods)
69 - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
70 - (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actualRange;
71 - (NSDictionary*)editingState;
72 @property(nonatomic) NSTextInputContext* textInputContext;
73 @property(readwrite, nonatomic) NSString* customRunLoopMode;
74 @end
FlutterTextInputPlugin(TestMethods)
Definition: FlutterTextInputPlugin.h:68
FlutterViewController
Definition: FlutterViewController.h:62
FlutterMethodCall
Definition: FlutterCodecs.h:220
FlutterBinaryMessenger.h
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:29
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:196
NSView(ClipsToBounds)
Definition: FlutterTextInputPlugin.h:12
FlutterTextField
Definition: FlutterTextInputSemanticsObject.h:78
FlutterViewController.h