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;
184 int32_t heading_level;
190 FlutterSemanticsAction override_action;
193 } SemanticsCustomAction;
196 std::shared_ptr<FlutterPlatformNodeDelegate>>
198 std::unique_ptr<ui::AXTree> tree_;
199 ui::AXEventGenerator event_generator_;
200 std::unordered_map<int32_t, SemanticsNode> pending_semantics_node_updates_;
201 std::unordered_map<int32_t, SemanticsCustomAction>
202 pending_semantics_custom_action_updates_;
205 void InitAXTree(
const ui::AXTreeUpdate& initial_state);
209 std::optional<ui::AXTreeUpdate> CreateRemoveReparentedNodesUpdate();
211 void GetSubTreeList(
const SemanticsNode& target,
212 std::vector<SemanticsNode>& result);
213 void ConvertFlutterUpdate(
const SemanticsNode& node,
214 ui::AXTreeUpdate& tree_update);
215 void SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
216 const SemanticsNode& node);
217 void SetStateFromFlutterUpdate(ui::AXNodeData& node_data,
218 const SemanticsNode& node);
219 void SetActionsFromFlutterUpdate(ui::AXNodeData& node_data,
220 const SemanticsNode& node);
221 void SetBooleanAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
222 const SemanticsNode& node);
223 void SetIntAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
224 const SemanticsNode& node);
225 void SetIntListAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
226 const SemanticsNode& node);
227 void SetStringListAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
228 const SemanticsNode& node);
229 void SetNameFromFlutterUpdate(ui::AXNodeData& node_data,
230 const SemanticsNode& node);
231 void SetValueFromFlutterUpdate(ui::AXNodeData& node_data,
232 const SemanticsNode& node);
233 void SetTooltipFromFlutterUpdate(ui::AXNodeData& node_data,
234 const SemanticsNode& node);
235 void SetTreeData(
const SemanticsNode& node, ui::AXTreeUpdate& tree_update);
236 SemanticsNode FromFlutterSemanticsNode(
237 const FlutterSemanticsNode2& flutter_node);
238 SemanticsCustomAction FromFlutterSemanticsCustomAction(
239 const FlutterSemanticsCustomAction2& flutter_custom_action);
242 void OnNodeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node)
override;
245 void OnSubtreeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node)
override;
248 void OnNodeCreated(ui::AXTree* tree, ui::AXNode* node)
override;
254 void OnNodeReparented(ui::AXTree* tree, ui::AXNode* node)
override;
257 void OnRoleChanged(ui::AXTree* tree,
259 ax::mojom::Role old_role,
260 ax::mojom::Role new_role)
override;
263 void OnNodeDataChanged(ui::AXTree* tree,
264 const ui::AXNodeData& old_node_data,
265 const ui::AXNodeData& new_node_data)
override;
268 void OnAtomicUpdateFinished(
271 const std::vector<ui::AXTreeObserver::Change>& changes)
override;
280 gfx::NativeViewAccessible GetNativeAccessibleFromId(
284 gfx::RectF RelativeToGlobalBounds(
const ui::AXNode* node,
286 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