| Flutter iOS Embedder |

flutter_platform_node_delegate.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_COMMON_FLUTTER_PLATFORM_NODE_DELEGATE_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_FLUTTER_PLATFORM_NODE_DELEGATE_H_
7
8 #include "flutter/fml/mapping.h"
9 #include "flutter/shell/platform/embedder/embedder.h"
10 #include "flutter/third_party/accessibility/ax/ax_event_generator.h"
11 #include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate_base.h"
12
13 namespace flutter {
14
15 typedef ui::AXNode::AXID AccessibilityNodeId;
16
17 //------------------------------------------------------------------------------
18 /// The platform node delegate to be used in accessibility bridge. This
19 /// class is responsible for providing native accessibility object with
20 /// appropriate information, such as accessibility label/value/bounds.
21 ///
22 /// While most methods have default implementations and are ready to be used
23 /// as-is, the subclasses must override the GetNativeViewAccessible to return
24 /// native accessibility objects. To do that, subclasses should create and
25 /// maintain AXPlatformNode[s] which delegate their accessibility attributes to
26 /// this class.
27 ///
28 /// For desktop platforms, subclasses also need to override the GetBoundsRect
29 /// to apply window-to-screen transform.
30 ///
31 /// This class transforms bounds assuming the device pixel ratio is 1.0. See
32 /// the https://github.com/flutter/flutter/issues/74283 for more information.
33 class FlutterPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase {
34 public:
35 //----------------------------------------------------------------------------
36 /// The required interface to be able to own the flutter platform node
37 /// delegate.
38 class OwnerBridge {
39 public:
40 virtual ~OwnerBridge() = default;
41
42 //---------------------------------------------------------------------------
43 /// @brief Gets the rectangular bounds of the ax node relative to
44 /// global coordinate
45 ///
46 /// @param[in] node The ax node to look up.
47 /// @param[in] offscreen the bool reference to hold the result whether
48 /// the ax node is outside of its ancestors' bounds.
49 /// @param[in] clip_bounds whether to clip the result if the ax node cannot
50 /// be fully contained in its ancestors' bounds.
51 virtual gfx::RectF RelativeToGlobalBounds(const ui::AXNode* node,
52 bool& offscreen,
53 bool clip_bounds) = 0;
54
55 protected:
56 friend class FlutterPlatformNodeDelegate;
57
58 //---------------------------------------------------------------------------
59 /// @brief Dispatch accessibility action back to the Flutter framework.
60 /// These actions are generated in the native accessibility
61 /// system when users interact with the assistive technologies.
62 /// For example, a
63 /// FlutterSemanticsAction::kFlutterSemanticsActionTap is
64 /// fired when user click or touch the screen.
65 ///
66 /// @param[in] target The semantics node id of the action
67 /// target.
68 /// @param[in] action The generated flutter semantics action.
69 /// @param[in] data Additional data associated with the
70 /// action.
71 virtual void DispatchAccessibilityAction(AccessibilityNodeId target,
72 FlutterSemanticsAction action,
73 fml::MallocMapping data) = 0;
74
75 //---------------------------------------------------------------------------
76 /// @brief Get the native accessibility node with the given id.
77 ///
78 /// @param[in] id The id of the native accessibility node you
79 /// want to retrieve.
80 virtual gfx::NativeViewAccessible GetNativeAccessibleFromId(
81 AccessibilityNodeId id) = 0;
82
83 //---------------------------------------------------------------------------
84 /// @brief Get the last id of the node that received accessibility
85 /// focus.
86 virtual AccessibilityNodeId GetLastFocusedId() = 0;
87
88 //---------------------------------------------------------------------------
89 /// @brief Update the id of the node that is currently foucsed by the
90 /// native accessibility system.
91 ///
92 /// @param[in] node_id The id of the focused node.
93 virtual void SetLastFocusedId(AccessibilityNodeId node_id) = 0;
94 };
95
96 FlutterPlatformNodeDelegate();
97
98 // |ui::AXPlatformNodeDelegateBase|
99 virtual ~FlutterPlatformNodeDelegate() override;
100
101 // |ui::AXPlatformNodeDelegateBase|
102 const ui::AXUniqueId& GetUniqueId() const override { return unique_id_; }
103
104 // |ui::AXPlatformNodeDelegateBase|
105 const ui::AXNodeData& GetData() const override;
106
107 // |ui::AXPlatformNodeDelegateBase|
108 bool AccessibilityPerformAction(const ui::AXActionData& data) override;
109
110 // |ui::AXPlatformNodeDelegateBase|
111 gfx::NativeViewAccessible GetParent() override;
112
113 // |ui::AXPlatformNodeDelegateBase|
114 gfx::NativeViewAccessible GetFocus() override;
115
116 // |ui::AXPlatformNodeDelegateBase|
117 int GetChildCount() const override;
118
119 // |ui::AXPlatformNodeDelegateBase|
120 gfx::NativeViewAccessible ChildAtIndex(int index) override;
121
122 // |ui::AXPlatformNodeDelegateBase|
123 gfx::Rect GetBoundsRect(
124 const ui::AXCoordinateSystem coordinate_system,
125 const ui::AXClippingBehavior clipping_behavior,
126 ui::AXOffscreenResult* offscreen_result) const override;
127
128 // |ui::AXPlatformNodeDelegateBase|
129 gfx::NativeViewAccessible GetLowestPlatformAncestor() const override;
130
131 // |ui::AXPlatformNodeDelegateBase|
132 ui::AXNodePosition::AXPositionInstance CreateTextPositionAt(
133 int offset) const override;
134
135 //------------------------------------------------------------------------------
136 /// @brief Called only once, immediately after construction. The
137 /// constructor doesn't take any arguments because in the Windows
138 /// subclass we use a special function to construct a COM object.
139 /// Subclasses must call super.
140 virtual void Init(std::weak_ptr<OwnerBridge> bridge, ui::AXNode* node);
141
142 //------------------------------------------------------------------------------
143 /// @brief Gets the underlying ax node for this platform node delegate.
144 ui::AXNode* GetAXNode() const;
145
146 //------------------------------------------------------------------------------
147 /// @brief Gets the owner of this platform node delegate. This is useful
148 /// when you want to get the information about surrounding nodes
149 /// of this platform node delegate, e.g. the global rect of this
150 /// platform node delegate. This pointer is only safe in the
151 /// platform thread.
152 std::weak_ptr<OwnerBridge> GetOwnerBridge() const;
153
154 // Get the platform node represented by this delegate.
155 virtual ui::AXPlatformNode* GetPlatformNode() const;
156
157 // |ui::AXPlatformNodeDelegateBase|
158 virtual ui::AXPlatformNode* GetFromNodeID(int32_t id) override;
159
160 // |ui::AXPlatformNodeDelegateBase|
161 virtual ui::AXPlatformNode* GetFromTreeIDAndNodeID(
162 const ui::AXTreeID& tree_id,
163 int32_t node_id) override;
164
165 // |ui::AXPlatformNodeDelegateBase|
166 virtual const ui::AXTree::Selection GetUnignoredSelection() const override;
167
168 private:
169 ui::AXNode* ax_node_;
170 std::weak_ptr<OwnerBridge> bridge_;
171 ui::AXUniqueId unique_id_;
172 };
173
174 } // namespace flutter
175
176 #endif // FLUTTER_SHELL_PLATFORM_COMMON_FLUTTER_PLATFORM_NODE_DELEGATE_H_
flutter::FlutterPlatformNodeDelegate::GetFromTreeIDAndNodeID
virtual ui::AXPlatformNode * GetFromTreeIDAndNodeID(const ui::AXTreeID &tree_id, int32_t node_id) override
Definition: flutter_platform_node_delegate.cc:150
flutter::FlutterPlatformNodeDelegate::ChildAtIndex
gfx::NativeViewAccessible ChildAtIndex(int index) override
Definition: flutter_platform_node_delegate.cc:87
flutter::FlutterPlatformNodeDelegate::OwnerBridge::~OwnerBridge
virtual ~OwnerBridge()=default
flutter::FlutterPlatformNodeDelegate::GetUniqueId
const ui::AXUniqueId & GetUniqueId() const override
Definition: flutter_platform_node_delegate.h:102
flutter::FlutterPlatformNodeDelegate::Init
virtual void Init(std::weak_ptr< OwnerBridge > bridge, ui::AXNode *node)
Called only once, immediately after construction. The constructor doesn't take any arguments because ...
Definition: flutter_platform_node_delegate.cc:20
flutter::FlutterPlatformNodeDelegate::GetOwnerBridge
std::weak_ptr< OwnerBridge > GetOwnerBridge() const
Gets the owner of this platform node delegate. This is useful when you want to get the information ab...
Definition: flutter_platform_node_delegate.cc:115
flutter::FlutterPlatformNodeDelegate::GetFromNodeID
virtual ui::AXPlatformNode * GetFromNodeID(int32_t id) override
Definition: flutter_platform_node_delegate.cc:140
flutter::FlutterPlatformNodeDelegate::CreateTextPositionAt
ui::AXNodePosition::AXPositionInstance CreateTextPositionAt(int offset) const override
Definition: flutter_platform_node_delegate.cc:136
flutter::FlutterPlatformNodeDelegate::GetUnignoredSelection
virtual const ui::AXTree::Selection GetUnignoredSelection() const override
Definition: flutter_platform_node_delegate.cc:160
flutter::FlutterPlatformNodeDelegate::GetPlatformNode
virtual ui::AXPlatformNode * GetPlatformNode() const
Definition: flutter_platform_node_delegate.cc:119
flutter::FlutterPlatformNodeDelegate::GetData
const ui::AXNodeData & GetData() const override
Definition: flutter_platform_node_delegate.cc:60
flutter::FlutterPlatformNodeDelegate::GetBoundsRect
gfx::Rect GetBoundsRect(const ui::AXCoordinateSystem coordinate_system, const ui::AXClippingBehavior clipping_behavior, ui::AXOffscreenResult *offscreen_result) const override
Definition: flutter_platform_node_delegate.cc:94
flutter::FlutterPlatformNodeDelegate::OwnerBridge::DispatchAccessibilityAction
virtual void DispatchAccessibilityAction(AccessibilityNodeId target, FlutterSemanticsAction action, fml::MallocMapping data)=0
Dispatch accessibility action back to the Flutter framework. These actions are generated in the nativ...
flutter::FlutterPlatformNodeDelegate::~FlutterPlatformNodeDelegate
virtual ~FlutterPlatformNodeDelegate() override
flutter::AccessibilityNodeId
ui::AXNode::AXID AccessibilityNodeId
Definition: flutter_platform_node_delegate.h:15
flutter
Definition: accessibility_bridge.h:28
flutter::FlutterPlatformNodeDelegate::OwnerBridge::GetLastFocusedId
virtual AccessibilityNodeId GetLastFocusedId()=0
Get the last id of the node that received accessibility focus.
flutter::FlutterPlatformNodeDelegate::OwnerBridge::RelativeToGlobalBounds
virtual gfx::RectF RelativeToGlobalBounds(const ui::AXNode *node, bool &offscreen, bool clip_bounds)=0
Gets the rectangular bounds of the ax node relative to global coordinate.
flutter::FlutterPlatformNodeDelegate::GetAXNode
ui::AXNode * GetAXNode() const
Gets the underlying ax node for this platform node delegate.
Definition: flutter_platform_node_delegate.cc:26
flutter::FlutterPlatformNodeDelegate::GetChildCount
int GetChildCount() const override
Definition: flutter_platform_node_delegate.cc:83
flutter::FlutterPlatformNodeDelegate::GetParent
gfx::NativeViewAccessible GetParent() override
Definition: flutter_platform_node_delegate.cc:64
flutter::FlutterPlatformNodeDelegate
Definition: flutter_platform_node_delegate.h:33
flutter::FlutterPlatformNodeDelegate::GetFocus
gfx::NativeViewAccessible GetFocus() override
Definition: flutter_platform_node_delegate.cc:73
flutter::FlutterPlatformNodeDelegate::AccessibilityPerformAction
bool AccessibilityPerformAction(const ui::AXActionData &data) override
Definition: flutter_platform_node_delegate.cc:30
flutter::FlutterPlatformNodeDelegate::OwnerBridge
Definition: flutter_platform_node_delegate.h:38
flutter::FlutterPlatformNodeDelegate::OwnerBridge::GetNativeAccessibleFromId
virtual gfx::NativeViewAccessible GetNativeAccessibleFromId(AccessibilityNodeId id)=0
Get the native accessibility node with the given id.
flutter::FlutterPlatformNodeDelegate::FlutterPlatformNodeDelegate
FlutterPlatformNodeDelegate()
flutter::FlutterPlatformNodeDelegate::GetLowestPlatformAncestor
gfx::NativeViewAccessible GetLowestPlatformAncestor() const override
Definition: flutter_platform_node_delegate.cc:124
flutter::FlutterPlatformNodeDelegate::OwnerBridge::SetLastFocusedId
virtual void SetLastFocusedId(AccessibilityNodeId node_id)=0
Update the id of the node that is currently foucsed by the native accessibility system.