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