| Flutter macOS Embedder |

FlutterTextInputSemanticsObject.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/macos/framework/Source/FlutterPlatformNodeDelegateMac.h"
8
9 #include "flutter/fml/macros.h"
10 #include "flutter/third_party/accessibility/ax/platform/ax_platform_node_base.h"
11
12 @class FlutterTextField;
13 @class FlutterTextInputPlugin;
14
15 namespace flutter {
16
17 //------------------------------------------------------------------------------
18 /// The ax platform node for a text field.
19 class FlutterTextPlatformNode : public ui::AXPlatformNodeBase {
20 public:
21 //---------------------------------------------------------------------------
22 /// @brief Creates a FlutterTextPlatformNode that uses a
23 /// FlutterTextField as its NativeViewAccessible.
24 /// @param[in] delegate The delegate that provides accessibility
25 /// data.
26 /// @param[in] view_controller The view_controller that is used for querying
27 /// the information about FlutterView and
28 /// FlutterTextInputPlugin.
29 explicit FlutterTextPlatformNode(FlutterPlatformNodeDelegate* delegate,
30 __weak FlutterViewController* view_controller);
31 ~FlutterTextPlatformNode() override;
32
33 //------------------------------------------------------------------------------
34 /// @brief Gets the frame of this platform node relative to the view of
35 /// FlutterViewController. This is used by the FlutterTextField to get its
36 /// frame rect because the FlutterTextField is a subview of the
37 /// FlutterViewController.view.
38 NSRect GetFrame();
39
40 // |ui::AXPlatformNodeBase|
41 gfx::NativeViewAccessible GetNativeViewAccessible() override;
42
43 private:
44 FlutterTextField* appkit_text_field_;
45 __weak FlutterViewController* view_controller_;
46
47 //------------------------------------------------------------------------------
48 /// @brief Ensures the FlutterTextField is attached to the FlutterView. This
49 /// method returns true if the text field is succesfully attached. If
50 /// this method returns false, that means the FlutterTextField could not
51 /// be attached to the FlutterView. This can happen when the FlutterEngine
52 /// does not have a FlutterViewController or the FlutterView is not loaded
53 /// yet.
54 bool EnsureAttachedToView();
55
56 //------------------------------------------------------------------------------
57 /// @brief Detaches the FlutterTextField from the FlutterView if it is not
58 /// already detached.
59 void EnsureDetachedFromView();
60
61 FML_DISALLOW_COPY_AND_ASSIGN(FlutterTextPlatformNode);
62 };
63
64 } // namespace flutter
65
66 /**
67 * An NSTextField implementation that represents the NativeViewAccessible for the
68 * FlutterTextPlatformNode
69 *
70 * The NSAccessibility protocol does not provide full support for text editing. This
71 * appkit text field is used to get around this problem. The FlutterTextPlatformNode
72 * creates a hidden FlutterTextField, since VoiceOver only provides text editing
73 * announcements for NSTextField subclasses.
74 *
75 * All of the text editing events in this native text field are redirected to the
76 * FlutterTextInputPlugin.
77 */
78 @interface FlutterTextField : NSTextField
79
80 /**
81 * Initializes a FlutterTextField that uses the FlutterTextInputPlugin as its field editor.
82 * The text field redirects all of the text editing events to the FlutterTextInputPlugin.
83 */
84 - (instancetype)initWithPlatformNode:(flutter::FlutterTextPlatformNode*)node
85 fieldEditor:(FlutterTextInputPlugin*)plugin;
86
87 /**
88 * Updates the string value and the selection of this text field.
89 *
90 * Calling this method is necessary for macOS to get notified about string and selection
91 * changes.
92 */
93 - (void)updateString:(NSString*)string withSelection:(NSRange)selection;
94
95 /**
96 * Makes the field editor (plugin) current editor for this TextField, meaning
97 * that the text field will start getting editing events.
98 */
99 - (void)startEditing;
100
101 @end
FlutterViewController
Definition: FlutterViewController.h:62
flutter::FlutterTextPlatformNode::FlutterTextPlatformNode
FlutterTextPlatformNode(FlutterPlatformNodeDelegate *delegate, __weak FlutterViewController *view_controller)
Creates a FlutterTextPlatformNode that uses a FlutterTextField as its NativeViewAccessible.
Definition: FlutterTextInputSemanticsObject.mm:161
flutter::FlutterTextPlatformNode
The ax platform node for a text field.
Definition: FlutterTextInputSemanticsObject.h:19
flutter::FlutterTextPlatformNode::GetNativeViewAccessible
gfx::NativeViewAccessible GetNativeViewAccessible() override
Definition: FlutterTextInputSemanticsObject.mm:179
FlutterPlatformNodeDelegateMac.h
flutter
Definition: AccessibilityBridgeMac.h:16
-[FlutterTextField startEditing]
void startEditing()
Definition: FlutterTextInputSemanticsObject.mm:112
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:24
flutter::FlutterTextPlatformNode::~FlutterTextPlatformNode
~FlutterTextPlatformNode() override
Definition: FlutterTextInputSemanticsObject.mm:174
flutter::FlutterPlatformNodeDelegate
Definition: flutter_platform_node_delegate.h:33
FlutterTextField
Definition: FlutterTextInputSemanticsObject.h:78
flutter::FlutterTextPlatformNode::GetFrame
NSRect GetFrame()
Gets the frame of this platform node relative to the view of FlutterViewController....
Definition: FlutterTextInputSemanticsObject.mm:186