[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 1 | // Copyright 2013 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_H_ |
| 6 | #define UI_ACCESSIBILITY_AX_TREE_H_ |
| 7 | |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 10 | #include <map> |
Chris Hall | 3420818 | 2019-03-13 02:26:18 | [diff] [blame] | 11 | #include <memory> |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 12 | #include <set> |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 13 | #include <string> |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 14 | #include <unordered_map> |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 16 | |
Jacques Newman | 5846e62 | 2021-01-15 02:15:59 | [diff] [blame] | 17 | #include "base/metrics/histogram_functions.h" |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 18 | #include "base/observer_list.h" |
James Cook | 36cab7c | 2019-10-29 23:26:40 | [diff] [blame] | 19 | #include "ui/accessibility/ax_enums.mojom-forward.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 20 | #include "ui/accessibility/ax_export.h" |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 21 | #include "ui/accessibility/ax_node.h" |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 22 | #include "ui/accessibility/ax_node_data.h" |
| 23 | #include "ui/accessibility/ax_tree_data.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 24 | #include "ui/accessibility/ax_tree_update.h" |
| 25 | |
| 26 | namespace ui { |
| 27 | |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 28 | class AXTableInfo; |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 29 | class AXTreeObserver; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 30 | struct AXTreeUpdateState; |
Chris Hall | 697d99b | 2019-07-09 02:36:11 | [diff] [blame] | 31 | class AXLanguageDetectionManager; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 32 | |
Jacques Newman | 5846e62 | 2021-01-15 02:15:59 | [diff] [blame] | 33 | // These values are persisted to logs. Entries should not be renumbered and |
| 34 | // numeric values should never be reused. |
| 35 | enum class AXTreeUnserializeError { |
| 36 | // Tree has no root. |
| 37 | kNoRoot = 0, |
| 38 | // Node will not be in the tree and is not the new root. |
| 39 | kNotInTree = 1, |
| 40 | // Node is already pending for creation, cannot be the new root |
| 41 | kCreationPending = 2, |
| 42 | // Node has duplicate child. |
| 43 | kDuplicateChild = 3, |
| 44 | // Node is already pending for creation, cannot be a new child. |
| 45 | kCreationPendingForChild = 4, |
| 46 | // Node is not marked for destruction, would be reparented. |
| 47 | kReparent = 5, |
| 48 | // Nodes are left pending by the update. |
| 49 | kPendingNodes = 6, |
| 50 | // Changes left pending by the update; |
| 51 | kPendingChanges = 7, |
| 52 | // This must always be the last enum. It's okay for its value to |
| 53 | // increase, but none of the other enum values may change. |
| 54 | kMaxValue = kPendingChanges |
| 55 | }; |
| 56 | |
| 57 | #define ACCESSIBILITY_TREE_UNSERIALIZE_ERROR_HISTOGRAM(enum_value) \ |
| 58 | base::UmaHistogramEnumeration( \ |
| 59 | "Accessibility.Reliability.Tree.UnserializeError", enum_value) |
| 60 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 61 | // AXTree is a live, managed tree of AXNode objects that can receive |
| 62 | // updates from another AXTreeSource via AXTreeUpdates, and it can be |
| 63 | // used as a source for sending updates to another client tree. |
| 64 | // It's designed to be subclassed to implement support for native |
| 65 | // accessibility APIs on a specific platform. |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 66 | class AX_EXPORT AXTree : public AXNode::OwnerTree { |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 67 | public: |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 68 | using IntReverseRelationMap = |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 69 | std::map<ax::mojom::IntAttribute, std::map<AXNodeID, std::set<AXNodeID>>>; |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 70 | using IntListReverseRelationMap = |
| 71 | std::map<ax::mojom::IntListAttribute, |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 72 | std::map<AXNodeID, std::set<AXNodeID>>>; |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 73 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 74 | AXTree(); |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 75 | explicit AXTree(const AXTreeUpdate& initial_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 76 | virtual ~AXTree(); |
| 77 | |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 78 | // AXTree owns pointers so copying is non-trivial. |
| 79 | AXTree(const AXTree&) = delete; |
| 80 | AXTree& operator=(const AXTree&) = delete; |
| 81 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 82 | void AddObserver(AXTreeObserver* observer); |
| 83 | bool HasObserver(AXTreeObserver* observer); |
Nektarios Paisios | db7b5ee | 2020-02-18 21:28:11 | [diff] [blame] | 84 | void RemoveObserver(AXTreeObserver* observer); |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 85 | |
| 86 | base::ObserverList<AXTreeObserver>& observers() { return observers_; } |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 87 | |
tfarina | 6b1c1e08 | 2015-02-20 23:47:07 | [diff] [blame] | 88 | AXNode* root() const { return root_; } |
| 89 | |
Joanmarie Diggs | 58b67c98 | 2020-11-13 15:33:28 | [diff] [blame] | 90 | const AXTreeData& data() const override; |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 91 | |
Nektarios Paisios | db7b5ee | 2020-02-18 21:28:11 | [diff] [blame] | 92 | // Destroys the tree and notifies all observers. |
| 93 | void Destroy(); |
| 94 | |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 95 | // AXNode::OwnerTree override. |
Adam Ettenberger | 86af253 | 2019-09-17 20:04:46 | [diff] [blame] | 96 | // Returns the globally unique ID of this accessibility tree. |
| 97 | AXTreeID GetAXTreeID() const override; |
| 98 | |
| 99 | // AXNode::OwnerTree override. |
tfarina | 6b1c1e08 | 2015-02-20 23:47:07 | [diff] [blame] | 100 | // Returns the AXNode with the given |id| if it is part of this AXTree. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 101 | AXNode* GetFromId(AXNodeID id) const override; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 102 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 103 | // Returns true on success. If it returns false, it's a fatal error |
| 104 | // and this tree should be destroyed, and the source of the tree update |
| 105 | // should not be trusted any longer. |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 106 | virtual bool Unserialize(const AXTreeUpdate& update); |
| 107 | |
| 108 | virtual void UpdateData(const AXTreeData& data); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 109 | |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 110 | // Convert any rectangle from the local coordinate space of one node in |
| 111 | // the tree, to bounds in the coordinate space of the tree. |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 112 | // If set, updates |offscreen| boolean to be true if the node is offscreen |
| 113 | // relative to its rootWebArea. Callers should initialize |offscreen| |
| 114 | // to false: this method may get called multiple times in a row and |
| 115 | // |offscreen| will be propagated. |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 116 | // If |clip_bounds| is true, result bounds will be clipped. |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 117 | gfx::RectF RelativeToTreeBounds(const AXNode* node, |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 118 | gfx::RectF node_bounds, |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 119 | bool* offscreen = nullptr, |
| 120 | bool clip_bounds = true) const; |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 121 | |
| 122 | // Get the bounds of a node in the coordinate space of the tree. |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 123 | // If set, updates |offscreen| boolean to be true if the node is offscreen |
| 124 | // relative to its rootWebArea. Callers should initialize |offscreen| |
| 125 | // to false: this method may get called multiple times in a row and |
| 126 | // |offscreen| will be propagated. |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 127 | // If |clip_bounds| is true, result bounds will be clipped. |
| 128 | gfx::RectF GetTreeBounds(const AXNode* node, |
| 129 | bool* offscreen = nullptr, |
| 130 | bool clip_bounds = true) const; |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 131 | |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 132 | // Given a node ID attribute (one where IsNodeIdIntAttribute is true), |
| 133 | // and a destination node ID, return a set of all source node IDs that |
| 134 | // have that relationship attribute between them and the destination. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 135 | std::set<AXNodeID> GetReverseRelations(ax::mojom::IntAttribute attr, |
| 136 | AXNodeID dst_id) const; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 137 | |
| 138 | // Given a node ID list attribute (one where |
| 139 | // IsNodeIdIntListAttribute is true), and a destination node ID, |
| 140 | // return a set of all source node IDs that have that relationship |
| 141 | // attribute between them and the destination. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 142 | std::set<AXNodeID> GetReverseRelations(ax::mojom::IntListAttribute attr, |
| 143 | AXNodeID dst_id) const; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 144 | |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 145 | // Given a child tree ID, return the node IDs of all nodes in the tree who |
| 146 | // have a kChildTreeId int attribute with that value. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 147 | std::set<AXNodeID> GetNodeIdsForChildTreeId(AXTreeID child_tree_id) const; |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 148 | |
Dominic Mazzoni | 748888c | 2018-11-01 22:34:59 | [diff] [blame] | 149 | // Get all of the child tree IDs referenced by any node in this tree. |
| 150 | const std::set<AXTreeID> GetAllChildTreeIds() const; |
| 151 | |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 152 | // Map from a relation attribute to a map from a target id to source ids. |
| 153 | const IntReverseRelationMap& int_reverse_relations() { |
| 154 | return int_reverse_relations_; |
| 155 | } |
| 156 | const IntListReverseRelationMap& intlist_reverse_relations() { |
| 157 | return intlist_reverse_relations_; |
| 158 | } |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 159 | |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 160 | // Return a multi-line indented string representation, for logging. |
| 161 | std::string ToString() const; |
| 162 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 163 | // A string describing the error from an unsuccessful Unserialize, |
| 164 | // for testing and debugging. |
tfarina | d0bfb4b6 | 2015-02-18 17:20:32 | [diff] [blame] | 165 | const std::string& error() const { return error_; } |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 166 | |
dmazzoni | ee2eaca | 2015-03-18 18:13:07 | [diff] [blame] | 167 | int size() { return static_cast<int>(id_map_.size()); } |
| 168 | |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 169 | // Return a negative number that's suitable to use for a node ID for |
| 170 | // internal nodes created automatically by an AXTree, so as not to |
| 171 | // conflict with positive-numbered node IDs from tree sources. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 172 | AXNodeID GetNextNegativeInternalNodeId(); |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 173 | |
Akihiro Ota | f42a7d0 | 2020-06-12 19:07:56 | [diff] [blame] | 174 | // Returns the PosInSet of |node|. Looks in node_set_size_pos_in_set_info_map_ |
| 175 | // for cached value. Calls |ComputeSetSizePosInSetAndCache|if no value is |
| 176 | // present in the cache. |
Anton Bikineev | eed0b26b | 2021-05-16 03:16:48 | [diff] [blame^] | 177 | absl::optional<int> GetPosInSet(const AXNode& node) override; |
Akihiro Ota | f42a7d0 | 2020-06-12 19:07:56 | [diff] [blame] | 178 | // Returns the SetSize of |node|. Looks in node_set_size_pos_in_set_info_map_ |
| 179 | // for cached value. Calls |ComputeSetSizePosInSetAndCache|if no value is |
| 180 | // present in the cache. |
Anton Bikineev | eed0b26b | 2021-05-16 03:16:48 | [diff] [blame^] | 181 | absl::optional<int> GetSetSize(const AXNode& node) override; |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 182 | |
Jacques Newman | 339afc6 | 2019-08-14 00:49:22 | [diff] [blame] | 183 | Selection GetUnignoredSelection() const override; |
| 184 | |
Akihiro Ota | e3e420e | 2019-04-17 19:57:40 | [diff] [blame] | 185 | bool GetTreeUpdateInProgressState() const override; |
| 186 | void SetTreeUpdateInProgressState(bool set_tree_update_value); |
| 187 | |
Kurt Catti-Schmidt | c8445a1 | 2019-08-07 18:52:58 | [diff] [blame] | 188 | // AXNode::OwnerTree override. |
| 189 | // Returns true if the tree represents a paginated document |
| 190 | bool HasPaginationSupport() const override; |
| 191 | |
Chris Hall | 697d99b | 2019-07-09 02:36:11 | [diff] [blame] | 192 | // Language detection manager, entry point to language detection features. |
| 193 | // TODO(chrishall): Should this be stored by pointer or value? |
| 194 | // When should we initialize this? |
| 195 | std::unique_ptr<AXLanguageDetectionManager> language_detection_manager; |
Chris Hall | 3420818 | 2019-03-13 02:26:18 | [diff] [blame] | 196 | |
David Tseng | b0d4366 | 2020-05-20 20:47:28 | [diff] [blame] | 197 | // A list of intents active during a tree update/unserialization. |
| 198 | const std::vector<AXEventIntent>& event_intents() const { |
| 199 | return event_intents_; |
| 200 | } |
| 201 | |
Benjamin Beaudry | e8f23a2 | 2020-12-17 20:08:02 | [diff] [blame] | 202 | // Notify the delegate that the tree manager for |previous_tree_id| will be |
| 203 | // removed from the AXTreeManagerMap. Because we sometimes remove the tree |
| 204 | // manager after the tree's id has been modified, we need to pass the (old) |
| 205 | // tree id associated with the manager we are removing even though it is the |
| 206 | // same tree. |
| 207 | void NotifyTreeManagerWillBeRemoved(AXTreeID previous_tree_id); |
| 208 | |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 209 | private: |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 210 | friend class AXTableInfoTest; |
| 211 | |
Aaron Leventhal | a674d63 | 2020-09-30 07:05:36 | [diff] [blame] | 212 | // Accumulate errors as there can be more than one before Chrome is crashed |
| 213 | // via AccessibilityFatalError(); |
| 214 | void RecordError(std::string new_error); |
| 215 | |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 216 | // AXNode::OwnerTree override. |
| 217 | // |
| 218 | // Given a node in this accessibility tree that corresponds to a table |
| 219 | // or grid, return an object containing information about the |
| 220 | // table structure. This object is computed lazily on-demand and |
| 221 | // cached until the next time the tree is updated. Clients should |
| 222 | // not retain this pointer, they should just request it every time |
| 223 | // it's needed. |
| 224 | // |
| 225 | // Returns nullptr if the node is not a valid table. |
| 226 | AXTableInfo* GetTableInfo(const AXNode* table_node) const override; |
| 227 | |
dtseng | 5a7b3d9 | 2016-09-08 06:35:58 | [diff] [blame] | 228 | AXNode* CreateNode(AXNode* parent, |
Dominic Mazzoni | 9ccdedb2 | 2021-01-30 17:59:42 | [diff] [blame] | 229 | AXNodeID id, |
Peter Kasting | 94a07a1 | 2019-05-22 19:26:28 | [diff] [blame] | 230 | size_t index_in_parent, |
dtseng | 5a7b3d9 | 2016-09-08 06:35:58 | [diff] [blame] | 231 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 232 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 233 | // Accumulates the work that will be required to update the AXTree. |
| 234 | // This allows us to notify observers of structure changes when the |
| 235 | // tree is still in a stable and unchanged state. |
| 236 | bool ComputePendingChanges(const AXTreeUpdate& update, |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 237 | AXTreeUpdateState* update_state); |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 238 | |
| 239 | // Populates |update_state| with information about actions that will |
| 240 | // be performed on the tree during the update, such as adding or |
| 241 | // removing nodes in the tree. Returns true on success. |
| 242 | // Nothing within this call should modify tree structure or node data. |
| 243 | bool ComputePendingChangesToNode(const AXNodeData& new_data, |
| 244 | bool is_new_root, |
| 245 | AXTreeUpdateState* update_state); |
| 246 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 247 | // This is called from within Unserialize(), it returns true on success. |
dmazzoni | 67b4db2 | 2016-04-23 00:40:04 | [diff] [blame] | 248 | bool UpdateNode(const AXNodeData& src, |
| 249 | bool is_new_root, |
| 250 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 251 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 252 | // Notify the delegate that the subtree rooted at |node| will be |
| 253 | // destroyed or reparented. |
| 254 | void NotifySubtreeWillBeReparentedOrDeleted( |
| 255 | AXNode* node, |
| 256 | const AXTreeUpdateState* update_state); |
| 257 | |
| 258 | // Notify the delegate that |node| will be destroyed or reparented. |
| 259 | void NotifyNodeWillBeReparentedOrDeleted( |
| 260 | AXNode* node, |
| 261 | const AXTreeUpdateState* update_state); |
| 262 | |
| 263 | // Notify the delegate that |node| and all of its descendants will be |
Victor Fei | e3cce4c | 2019-11-14 18:35:41 | [diff] [blame] | 264 | // destroyed. This function is called during AXTree teardown. |
| 265 | void RecursivelyNotifyNodeDeletedForTreeTeardown(AXNode* node); |
| 266 | |
| 267 | // Notify the delegate that the node marked by |node_id| has been deleted. |
| 268 | // We are passing the node id instead of ax node is because by the time this |
| 269 | // function is called, the ax node in the tree will already have been |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 270 | // destroyed. |
Dominic Mazzoni | 9ccdedb2 | 2021-01-30 17:59:42 | [diff] [blame] | 271 | void NotifyNodeHasBeenDeleted(AXNodeID node_id); |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 272 | |
| 273 | // Notify the delegate that |node| has been created or reparented. |
| 274 | void NotifyNodeHasBeenReparentedOrCreated( |
| 275 | AXNode* node, |
| 276 | const AXTreeUpdateState* update_state); |
| 277 | |
Adam Ettenberger | 05afcec | 2019-08-06 17:11:29 | [diff] [blame] | 278 | // Notify the delegate that a node will change its data. |
| 279 | void NotifyNodeDataWillChange(const AXNodeData& old_data, |
| 280 | const AXNodeData& new_data); |
| 281 | |
| 282 | // Notify the delegate that |node| has changed its data. |
| 283 | void NotifyNodeDataHasBeenChanged(AXNode* node, |
| 284 | const AXNodeData& old_data, |
| 285 | const AXNodeData& new_data); |
dmazzoni | 3ab5385c | 2017-03-13 18:07:03 | [diff] [blame] | 286 | |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 287 | void UpdateReverseRelations(AXNode* node, const AXNodeData& new_data); |
| 288 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 289 | // Returns true if all pending changes in the |update_state| have been |
| 290 | // handled. If this returns false, the |error_| message will be populated. |
| 291 | // It's a fatal error to have pending changes after exhausting |
| 292 | // the AXTreeUpdate. |
| 293 | bool ValidatePendingChangesComplete(const AXTreeUpdateState& update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 294 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 295 | // Modifies |update_state| so that it knows what subtree and nodes are |
| 296 | // going to be destroyed for the subtree rooted at |node|. |
Dominic Mazzoni | 9ccdedb2 | 2021-01-30 17:59:42 | [diff] [blame] | 297 | void MarkSubtreeForDestruction(AXNodeID node_id, |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 298 | AXTreeUpdateState* update_state); |
| 299 | |
| 300 | // Modifies |update_state| so that it knows what nodes are |
| 301 | // going to be destroyed for the subtree rooted at |node|. |
Dominic Mazzoni | 9ccdedb2 | 2021-01-30 17:59:42 | [diff] [blame] | 302 | void MarkNodesForDestructionRecursive(AXNodeID node_id, |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 303 | AXTreeUpdateState* update_state); |
| 304 | |
| 305 | // Validates that destroying the subtree rooted at |node| has required |
| 306 | // information in |update_state|, then calls DestroyNodeAndSubtree on it. |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 307 | void DestroySubtree(AXNode* node, AXTreeUpdateState* update_state); |
dmazzoni | a4b4891 | 2015-01-24 00:08:56 | [diff] [blame] | 308 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 309 | // Call Destroy() on |node|, and delete it from the id map, and then |
| 310 | // call recursively on all nodes in its subtree. |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 311 | void DestroyNodeAndSubtree(AXNode* node, AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 312 | |
| 313 | // Iterate over the children of |node| and for each child, destroy the |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 314 | // child and its subtree if its id is not in |new_child_ids|. |
| 315 | void DeleteOldChildren(AXNode* node, |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 316 | const std::vector<AXNodeID>& new_child_ids, |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 317 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 318 | |
| 319 | // Iterate over |new_child_ids| and populate |new_children| with |
| 320 | // pointers to child nodes, reusing existing nodes already in the tree |
| 321 | // if they exist, and creating otherwise. Reparenting is disallowed, so |
| 322 | // if the id already exists as the child of another node, that's an |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 323 | // error. Returns true on success, false on fatal error. |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 324 | bool CreateNewChildVector(AXNode* node, |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 325 | const std::vector<AXNodeID>& new_child_ids, |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 326 | std::vector<AXNode*>* new_children, |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 327 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 328 | |
Dominic Mazzoni | a1bb0d12 | 2019-09-26 20:19:59 | [diff] [blame] | 329 | // Internal implementation of RelativeToTreeBounds. It calls itself |
| 330 | // recursively but ensures that it can only do so exactly once! |
| 331 | gfx::RectF RelativeToTreeBoundsInternal(const AXNode* node, |
| 332 | gfx::RectF node_bounds, |
| 333 | bool* offscreen, |
| 334 | bool clip_bounds, |
| 335 | bool allow_recursion) const; |
| 336 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 337 | base::ObserverList<AXTreeObserver> observers_; |
Brett Wilson | 0feae3a | 2017-12-06 03:16:56 | [diff] [blame] | 338 | AXNode* root_ = nullptr; |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 339 | std::unordered_map<AXNodeID, AXNode*> id_map_; |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 340 | std::string error_; |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 341 | AXTreeData data_; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 342 | |
| 343 | // Map from an int attribute (if IsNodeIdIntAttribute is true) to |
| 344 | // a reverse mapping from target nodes to source nodes. |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 345 | IntReverseRelationMap int_reverse_relations_; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 346 | // Map from an int list attribute (if IsNodeIdIntListAttribute is true) to |
| 347 | // a reverse mapping from target nodes to source nodes. |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 348 | IntListReverseRelationMap intlist_reverse_relations_; |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 349 | // Map from child tree ID to the set of node IDs that contain that attribute. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 350 | std::map<AXTreeID, std::set<AXNodeID>> child_tree_id_reverse_map_; |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 351 | |
| 352 | // Map from node ID to cached table info, if the given node is a table. |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 353 | // Invalidated every time the tree is updated. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 354 | mutable std::unordered_map<AXNodeID, std::unique_ptr<AXTableInfo>> |
Aaron Leventhal | 8079718 | 2020-02-25 18:50:31 | [diff] [blame] | 355 | table_info_map_; |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 356 | |
| 357 | // The next negative node ID to use for internal nodes. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 358 | AXNodeID next_negative_internal_node_id_ = -1; |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 359 | |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 360 | // Contains pos_in_set and set_size data for an AXNode. |
Stephan Hartmann | aeef688 | 2020-04-20 18:21:43 | [diff] [blame] | 361 | struct NodeSetSizePosInSetInfo { |
| 362 | NodeSetSizePosInSetInfo(); |
| 363 | ~NodeSetSizePosInSetInfo(); |
| 364 | |
Anton Bikineev | eed0b26b | 2021-05-16 03:16:48 | [diff] [blame^] | 365 | absl::optional<int> pos_in_set; |
| 366 | absl::optional<int> set_size; |
| 367 | absl::optional<int> lowest_hierarchical_level; |
Stephan Hartmann | aeef688 | 2020-04-20 18:21:43 | [diff] [blame] | 368 | }; |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 369 | |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 370 | // Represents the content of an ordered set which includes the ordered set |
| 371 | // items and the ordered set container if it exists. |
| 372 | struct OrderedSetContent; |
| 373 | |
| 374 | // Maps a particular hierarchical level to a list of OrderedSetContents. |
| 375 | // Represents all ordered set items/container on a particular hierarchical |
| 376 | // level. |
| 377 | struct OrderedSetItemsMap; |
| 378 | |
| 379 | // Populates |items_map_to_be_populated| with all items associated with |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 380 | // |original_node| and within |ordered_set|. Only items whose roles match the |
| 381 | // role of the |ordered_set| will be added. |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 382 | void PopulateOrderedSetItemsMap( |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 383 | const AXNode& original_node, |
| 384 | const AXNode* ordered_set, |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 385 | OrderedSetItemsMap* items_map_to_be_populated) const; |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 386 | |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 387 | // Helper function for recursively populating ordered sets items map with |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 388 | // all items associated with |original_node| and |ordered_set|. |local_parent| |
| 389 | // tracks the recursively passed in child nodes of |ordered_set|. |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 390 | void RecursivelyPopulateOrderedSetItemsMap( |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 391 | const AXNode& original_node, |
| 392 | const AXNode* ordered_set, |
| 393 | const AXNode* local_parent, |
Anton Bikineev | eed0b26b | 2021-05-16 03:16:48 | [diff] [blame^] | 394 | absl::optional<int> ordered_set_min_level, |
| 395 | absl::optional<int> prev_level, |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 396 | OrderedSetItemsMap* items_map_to_be_populated) const; |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 397 | |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 398 | // Computes the pos_in_set and set_size values of all items in ordered_set and |
| 399 | // caches those values. Called by GetPosInSet and GetSetSize. |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 400 | void ComputeSetSizePosInSetAndCache(const AXNode& node, |
| 401 | const AXNode* ordered_set); |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 402 | |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 403 | // Helper for ComputeSetSizePosInSetAndCache. Computes and caches the |
| 404 | // pos_in_set and set_size values for a given OrderedSetContent. |
| 405 | void ComputeSetSizePosInSetAndCacheHelper( |
| 406 | const OrderedSetContent& ordered_set_content); |
| 407 | |
Akihiro Ota | b6a8a4d | 2018-12-04 01:56:39 | [diff] [blame] | 408 | // Map from node ID to OrderedSetInfo. |
| 409 | // Item-like and ordered-set-like objects will map to populated OrderedSetInfo |
| 410 | // objects. |
| 411 | // All other objects will map to default-constructed OrderedSetInfo objects. |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 412 | // Invalidated every time the tree is updated. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 413 | mutable std::unordered_map<AXNodeID, NodeSetSizePosInSetInfo> |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 414 | node_set_size_pos_in_set_info_map_; |
Chris Hall | 9b34c2c | 2018-12-04 01:45:56 | [diff] [blame] | 415 | |
Akihiro Ota | e3e420e | 2019-04-17 19:57:40 | [diff] [blame] | 416 | // Indicates if the tree is updating. |
| 417 | bool tree_update_in_progress_ = false; |
Kurt Catti-Schmidt | c8445a1 | 2019-08-07 18:52:58 | [diff] [blame] | 418 | |
| 419 | // Indicates if the tree represents a paginated document |
| 420 | bool has_pagination_support_ = false; |
David Tseng | b0d4366 | 2020-05-20 20:47:28 | [diff] [blame] | 421 | |
| 422 | std::vector<AXEventIntent> event_intents_; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | } // namespace ui |
| 426 | |
| 427 | #endif // UI_ACCESSIBILITY_AX_TREE_H_ |