Flutter Engine
The Flutter Engine
ax_tree_observer.h
Go to the documentation of this file.
1// Copyright 2018 The Chromium 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 UI_ACCESSIBILITY_AX_TREE_OBSERVER_H_
6#define UI_ACCESSIBILITY_AX_TREE_OBSERVER_H_
7
8#include <cstdint>
9#include <string>
10#include <vector>
11
12#include "ax_enums.h"
13#include "ax_export.h"
14
15namespace ui {
16
17class AXNode;
18struct AXNodeData;
19class AXTree;
20struct AXTreeData;
21
22// Used when you want to be notified when changes happen to an AXTree.
23//
24// |OnAtomicUpdateFinished| is notified at the end of an atomic update.
25// It provides a vector of nodes that were added or changed, for final
26// postprocessing.
28 public:
30 virtual ~AXTreeObserver();
31
32 // Called before any tree modifications have occurred, notifying that a single
33 // node will change its data. Its id and data will be valid, but its links to
34 // parents and children are only valid within this callstack. Do not hold a
35 // reference to the node or any relative nodes such as ancestors or
36 // descendants described by the node data outside of this event.
37 virtual void OnNodeDataWillChange(AXTree* tree,
38 const AXNodeData& old_node_data,
39 const AXNodeData& new_node_data) {}
40
41 // Called after all tree modifications have occurred, notifying that a single
42 // node has changed its data. Its id, data, and links to parent and children
43 // will all be valid, since the tree is in a stable state after updating.
44 virtual void OnNodeDataChanged(AXTree* tree,
45 const AXNodeData& old_node_data,
46 const AXNodeData& new_node_data) {}
47
48 // Individual callbacks for every attribute of AXNodeData that can change.
49 // Called after all tree mutations have occurred, notifying that a single node
50 // changed its data. Its id, data, and links to parent and children will all
51 // be valid, since the tree is in a stable state after updating.
52 virtual void OnRoleChanged(AXTree* tree,
53 AXNode* node,
54 ax::mojom::Role old_role,
55 ax::mojom::Role new_role) {}
56 virtual void OnStateChanged(AXTree* tree,
57 AXNode* node,
59 bool new_value) {}
60 virtual void OnStringAttributeChanged(AXTree* tree,
61 AXNode* node,
63 const std::string& old_value,
64 const std::string& new_value) {}
65 virtual void OnIntAttributeChanged(AXTree* tree,
66 AXNode* node,
68 int32_t old_value,
69 int32_t new_value) {}
70 virtual void OnFloatAttributeChanged(AXTree* tree,
71 AXNode* node,
73 float old_value,
74 float new_value) {}
75 virtual void OnBoolAttributeChanged(AXTree* tree,
76 AXNode* node,
78 bool new_value) {}
80 AXTree* tree,
81 AXNode* node,
83 const std::vector<int32_t>& old_value,
84 const std::vector<int32_t>& new_value) {}
86 AXTree* tree,
87 AXNode* node,
89 const std::vector<std::string>& old_value,
90 const std::vector<std::string>& new_value) {}
91
92 // Called when tree data changes, after all nodes have been updated.
93 virtual void OnTreeDataChanged(AXTree* tree,
94 const AXTreeData& old_data,
95 const AXTreeData& new_data) {}
96
97 // Called before any tree modifications have occurred, notifying that a single
98 // node will be deleted. Its id and data will be valid, but its links to
99 // parents and children are only valid within this callstack. Do not hold
100 // a reference to node outside of the event.
101 virtual void OnNodeWillBeDeleted(AXTree* tree, AXNode* node) {}
102
103 // Same as OnNodeWillBeDeleted, but only called once for an entire subtree.
104 virtual void OnSubtreeWillBeDeleted(AXTree* tree, AXNode* node) {}
105
106 // Called just before a node is deleted for reparenting. See
107 // |OnNodeWillBeDeleted| for additional information.
108 virtual void OnNodeWillBeReparented(AXTree* tree, AXNode* node) {}
109
110 // Called just before a subtree is deleted for reparenting. See
111 // |OnSubtreeWillBeDeleted| for additional information.
112 virtual void OnSubtreeWillBeReparented(AXTree* tree, AXNode* node) {}
113
114 // Called after all tree mutations have occurred, notifying that a single node
115 // has been created. Its id, data, and links to parent and children will all
116 // be valid, since the tree is in a stable state after updating.
117 virtual void OnNodeCreated(AXTree* tree, AXNode* node) {}
118
119 // Called after all tree mutations have occurred or during tree teardown,
120 // notifying that a single node has been deleted from the tree.
121 virtual void OnNodeDeleted(AXTree* tree, int32_t node_id) {}
122
123 // Same as |OnNodeCreated|, but called for nodes that have been reparented.
124 virtual void OnNodeReparented(AXTree* tree, AXNode* node) {}
125
126 // Called after all tree mutations have occurred, notifying that a single node
127 // has updated its data or children. Its id, data, and links to parent and
128 // children will all be valid, since the tree is in a stable state after
129 // updating.
130 virtual void OnNodeChanged(AXTree* tree, AXNode* node) {}
131
137 SUBTREE_REPARENTED
138 };
139
140 struct Change {
142 this->node = node;
143 this->type = type;
144 }
147 };
148
149 // Called at the end of the update operation. Every node that was added
150 // or changed will be included in |changes|, along with an enum indicating
151 // the type of change - either (1) a node was created, (2) a node was created
152 // and it's the root of a new subtree, or (3) a node was changed. Finally,
153 // a bool indicates if the root of the tree was changed or not.
154 virtual void OnAtomicUpdateFinished(AXTree* tree,
155 bool root_changed,
156 const std::vector<Change>& changes) {}
157};
158
159} // namespace ui
160
161#endif // UI_ACCESSIBILITY_AX_TREE_OBSERVER_H_
#define AX_EXPORT
Definition: ax_export.h:29
GLenum type
virtual void OnAtomicUpdateFinished(AXTree *tree, bool root_changed, const std::vector< Change > &changes)
virtual void OnIntListAttributeChanged(AXTree *tree, AXNode *node, ax::mojom::IntListAttribute attr, const std::vector< int32_t > &old_value, const std::vector< int32_t > &new_value)
virtual void OnRoleChanged(AXTree *tree, AXNode *node, ax::mojom::Role old_role, ax::mojom::Role new_role)
virtual void OnNodeWillBeReparented(AXTree *tree, AXNode *node)
virtual void OnSubtreeWillBeReparented(AXTree *tree, AXNode *node)
virtual void OnIntAttributeChanged(AXTree *tree, AXNode *node, ax::mojom::IntAttribute attr, int32_t old_value, int32_t new_value)
virtual void OnNodeDataWillChange(AXTree *tree, const AXNodeData &old_node_data, const AXNodeData &new_node_data)
virtual void OnSubtreeWillBeDeleted(AXTree *tree, AXNode *node)
virtual void OnNodeWillBeDeleted(AXTree *tree, AXNode *node)
virtual void OnBoolAttributeChanged(AXTree *tree, AXNode *node, ax::mojom::BoolAttribute attr, bool new_value)
virtual void OnStateChanged(AXTree *tree, AXNode *node, ax::mojom::State state, bool new_value)
virtual void OnStringListAttributeChanged(AXTree *tree, AXNode *node, ax::mojom::StringListAttribute attr, const std::vector< std::string > &old_value, const std::vector< std::string > &new_value)
virtual void OnNodeDataChanged(AXTree *tree, const AXNodeData &old_node_data, const AXNodeData &new_node_data)
virtual void OnNodeReparented(AXTree *tree, AXNode *node)
virtual ~AXTreeObserver()
virtual void OnNodeDeleted(AXTree *tree, int32_t node_id)
virtual void OnStringAttributeChanged(AXTree *tree, AXNode *node, ax::mojom::StringAttribute attr, const std::string &old_value, const std::string &new_value)
virtual void OnNodeCreated(AXTree *tree, AXNode *node)
virtual void OnTreeDataChanged(AXTree *tree, const AXTreeData &old_data, const AXTreeData &new_data)
virtual void OnNodeChanged(AXTree *tree, AXNode *node)
virtual void OnFloatAttributeChanged(AXTree *tree, AXNode *node, ax::mojom::FloatAttribute attr, float old_value, float new_value)
AtkStateType state
StringListAttribute
Definition: ax_enums.h:850
StringAttribute
Definition: ax_enums.h:521
FloatAttribute
Definition: ax_enums.h:699
IntListAttribute
Definition: ax_enums.h:799
Change(AXNode *node, ChangeType type)