5 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_ACCESSIBILITY_BRIDGE_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_ACCESSIBILITY_BRIDGE_H_
8 #include <unordered_map>
10 #include "flutter/fml/mapping.h"
11 #include "flutter/shell/platform/embedder/embedder.h"
13 #include "flutter/third_party/accessibility/ax/ax_event_generator.h"
14 #include "flutter/third_party/accessibility/ax/ax_tree.h"
15 #include "flutter/third_party/accessibility/ax/ax_tree_observer.h"
16 #include "flutter/third_party/accessibility/ax/platform/ax_platform_node_delegate.h"
17 #include "flutter/third_party/accessibility/ax/platform/ax_platform_tree_manager.h"
41 :
public std::enable_shared_from_this<AccessibilityBridge>,
43 public ui::AXPlatformTreeManager,
44 private ui::AXTreeObserver {
68 const FlutterSemanticsCustomAction2&
action);
88 std::weak_ptr<FlutterPlatformNodeDelegate>
108 const ui::AXNode::AXID node_id)
const override;
111 ui::AXNode*
GetNodeFromTree(
const ui::AXNode::AXID node_id)
const override;
126 ui::AXTree*
GetTree()
const override;
130 const ui::AXNode::AXID node_id)
const override;
134 const ui::AXNode& node)
const override;
137 ui::AXPlatformNodeDelegate*
RootDelegate()
const override;
149 ui::AXEventGenerator::TargetedEvent targeted_event) = 0;
157 virtual std::shared_ptr<FlutterPlatformNodeDelegate>
164 FlutterSemanticsFlags* flags;
165 FlutterSemanticsAction actions;
166 int32_t text_selection_base;
167 int32_t text_selection_extent;
168 int32_t scroll_child_count;
169 int32_t scroll_index;
170 double scroll_position;
171 double scroll_extent_max;
172 double scroll_extent_min;
176 std::string increased_value;
177 std::string decreased_value;
179 FlutterTextDirection text_direction;
181 FlutterTransformation transform;
182 std::vector<int32_t> children_in_traversal_order;
183 std::vector<int32_t> custom_accessibility_actions;
189 FlutterSemanticsAction override_action;
192 } SemanticsCustomAction;
195 std::shared_ptr<FlutterPlatformNodeDelegate>>
197 std::unique_ptr<ui::AXTree> tree_;
198 ui::AXEventGenerator event_generator_;
199 std::unordered_map<int32_t, SemanticsNode> pending_semantics_node_updates_;
200 std::unordered_map<int32_t, SemanticsCustomAction>
201 pending_semantics_custom_action_updates_;
204 void InitAXTree(
const ui::AXTreeUpdate& initial_state);
208 std::optional<ui::AXTreeUpdate> CreateRemoveReparentedNodesUpdate();
210 void GetSubTreeList(
const SemanticsNode& target,
211 std::vector<SemanticsNode>& result);
212 void ConvertFlutterUpdate(
const SemanticsNode& node,
213 ui::AXTreeUpdate& tree_update);
214 void SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
215 const SemanticsNode& node);
216 void SetStateFromFlutterUpdate(ui::AXNodeData& node_data,
217 const SemanticsNode& node);
218 void SetActionsFromFlutterUpdate(ui::AXNodeData& node_data,
219 const SemanticsNode& node);
220 void SetBooleanAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
221 const SemanticsNode& node);
222 void SetIntAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
223 const SemanticsNode& node);
224 void SetIntListAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
225 const SemanticsNode& node);
226 void SetStringListAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
227 const SemanticsNode& node);
228 void SetNameFromFlutterUpdate(ui::AXNodeData& node_data,
229 const SemanticsNode& node);
230 void SetValueFromFlutterUpdate(ui::AXNodeData& node_data,
231 const SemanticsNode& node);
232 void SetTooltipFromFlutterUpdate(ui::AXNodeData& node_data,
233 const SemanticsNode& node);
234 void SetTreeData(
const SemanticsNode& node, ui::AXTreeUpdate& tree_update);
235 SemanticsNode FromFlutterSemanticsNode(
236 const FlutterSemanticsNode2& flutter_node);
237 SemanticsCustomAction FromFlutterSemanticsCustomAction(
238 const FlutterSemanticsCustomAction2& flutter_custom_action);
241 void OnNodeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node)
override;
244 void OnSubtreeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node)
override;
247 void OnNodeCreated(ui::AXTree* tree, ui::AXNode* node)
override;
253 void OnNodeReparented(ui::AXTree* tree, ui::AXNode* node)
override;
256 void OnRoleChanged(ui::AXTree* tree,
258 ax::mojom::Role old_role,
259 ax::mojom::Role new_role)
override;
262 void OnNodeDataChanged(ui::AXTree* tree,
263 const ui::AXNodeData& old_node_data,
264 const ui::AXNodeData& new_node_data)
override;
267 void OnAtomicUpdateFinished(
270 const std::vector<ui::AXTreeObserver::Change>& changes)
override;
279 gfx::NativeViewAccessible GetNativeAccessibleFromId(
283 gfx::RectF RelativeToGlobalBounds(
const ui::AXNode* node,
285 bool clip_bounds)
override;
ui::AXTree * GetTree() const override
ui::AXPlatformNodeDelegate * RootDelegate() const override
std::weak_ptr< FlutterPlatformNodeDelegate > GetFlutterPlatformNodeDelegateFromID(AccessibilityNodeId id) const
Get the flutter platform node delegate with the given id from this accessibility bridge....
virtual std::shared_ptr< FlutterPlatformNodeDelegate > CreateFlutterPlatformNodeDelegate()=0
Creates a platform specific FlutterPlatformNodeDelegate. Ownership passes to the caller....
void AddFlutterSemanticsNodeUpdate(const FlutterSemanticsNode2 &node)
Adds a semantics node update to the pending semantics update. Calling this method alone will NOT upda...
void AddFlutterSemanticsCustomActionUpdate(const FlutterSemanticsCustomAction2 &action)
Adds a custom semantics action update to the pending semantics update. Calling this method alone will...
ui::AXPlatformNode * GetPlatformNodeFromTree(const ui::AXNode::AXID node_id) const override
const ui::AXTreeData & GetAXTreeData() const
Get the ax tree data from this accessibility bridge. The tree data contains information such as the i...
ui::AXTreeID GetParentTreeID() const override
ui::AXNode * GetRootAsAXNode() const override
virtual ~AccessibilityBridge()
ui::AXNode * GetParentNodeFromParentTreeAsAXNode() const override
AccessibilityBridge()
Creates a new instance of a accessibility bridge.
virtual void OnAccessibilityEvent(ui::AXEventGenerator::TargetedEvent targeted_event)=0
Handle accessibility events generated due to accessibility tree changes. These events are needed to b...
ui::AXTreeID GetTreeID() const override
const std::vector< ui::AXEventGenerator::TargetedEvent > GetPendingEvents() const
Gets all pending accessibility events generated during semantics updates. This is useful when decidin...
void CommitUpdates()
Flushes the pending updates and applies them to this accessibility bridge. Calling this with no pendi...
ui::AXNode * GetNodeFromTree(const ui::AXTreeID tree_id, const ui::AXNode::AXID node_id) const override
ui::AXNode::AXID AccessibilityNodeId