Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 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> |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 12 | #include <optional> |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 13 | #include <set> |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 14 | #include <string> |
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 | |
Aaron leventhal | eab7a13 | 2025-05-01 13:28:11 | [diff] [blame] | 17 | #include "base/dcheck_is_on.h" |
Aaron Leventhal | bc649ff | 2022-08-11 18:53:23 | [diff] [blame] | 18 | #include "base/debug/crash_logging.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 19 | #include "base/memory/raw_ptr.h" |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 20 | #include "base/observer_list.h" |
Addison Luh | d7d28ac | 2025-06-23 16:15:10 | [diff] [blame] | 21 | #include "third_party/abseil-cpp/absl/container/flat_hash_map.h" |
Greg Thompson | c154391 | 2025-06-24 13:22:44 | [diff] [blame] | 22 | #include "third_party/abseil-cpp/absl/container/flat_hash_set.h" |
Aaron Leventhal | 25ccd51 | 2024-12-04 00:57:48 | [diff] [blame] | 23 | #include "ui/accessibility/ax_common.h" |
James Cook | 36cab7c | 2019-10-29 23:26:40 | [diff] [blame] | 24 | #include "ui/accessibility/ax_enums.mojom-forward.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 25 | #include "ui/accessibility/ax_export.h" |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 26 | #include "ui/accessibility/ax_tree_data.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 27 | #include "ui/accessibility/ax_tree_update.h" |
| 28 | |
| 29 | namespace ui { |
| 30 | |
David Tseng | 41f13cbd | 2021-11-06 18:39:03 | [diff] [blame] | 31 | struct AXEvent; |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 32 | class AXLanguageDetectionManager; |
| 33 | class AXNode; |
| 34 | struct AXNodeData; |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 35 | class AXTableInfo; |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 36 | class AXTreeObserver; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 37 | struct AXTreeUpdateState; |
Alexander Surkov | 253235e | 2022-08-23 01:52:12 | [diff] [blame] | 38 | class AXSelection; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 39 | |
Jacques Newman | 5846e62 | 2021-01-15 02:15:59 | [diff] [blame] | 40 | // These values are persisted to logs. Entries should not be renumbered and |
| 41 | // numeric values should never be reused. |
Mark Schillaci | 99be8c9 | 2024-08-16 21:24:33 | [diff] [blame] | 42 | // |
| 43 | // LINT.IfChange(AXTreeUnserializeError) |
Jacques Newman | 5846e62 | 2021-01-15 02:15:59 | [diff] [blame] | 44 | enum class AXTreeUnserializeError { |
| 45 | // Tree has no root. |
| 46 | kNoRoot = 0, |
| 47 | // Node will not be in the tree and is not the new root. |
| 48 | kNotInTree = 1, |
| 49 | // Node is already pending for creation, cannot be the new root |
| 50 | kCreationPending = 2, |
| 51 | // Node has duplicate child. |
| 52 | kDuplicateChild = 3, |
| 53 | // Node is already pending for creation, cannot be a new child. |
| 54 | kCreationPendingForChild = 4, |
| 55 | // Node is not marked for destruction, would be reparented. |
| 56 | kReparent = 5, |
| 57 | // Nodes are left pending by the update. |
| 58 | kPendingNodes = 6, |
| 59 | // Changes left pending by the update; |
| 60 | kPendingChanges = 7, |
| 61 | // This must always be the last enum. It's okay for its value to |
| 62 | // increase, but none of the other enum values may change. |
| 63 | kMaxValue = kPendingChanges |
| 64 | }; |
Mark Schillaci | 99be8c9 | 2024-08-16 21:24:33 | [diff] [blame] | 65 | // LINT.ThenChange(/tools/metrics/histograms/metadata/accessibility/enums.xml:AccessibilityTreeUnserializeError) |
Jacques Newman | 5846e62 | 2021-01-15 02:15:59 | [diff] [blame] | 66 | |
Jacques Newman | 441afe2 | 2025-06-24 23:54:08 | [diff] [blame] | 67 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) |
Evelynn Kaplan | 6cd535ce | 2025-03-20 23:58:18 | [diff] [blame] | 68 | // To support AriaNotify on older versions of ATK, we need to use the ATK |
| 69 | // signal "Text::text-insert". This signal requires a node that is a |
| 70 | // text type, and it needs to have aria-live properties set in order for |
| 71 | // Orca to make announcements. We create 2 extra "dummy" nodes that can be |
| 72 | // used for firing these signals when there is an AriaNotify event. One node |
| 73 | // will have `aria-live: assertive` and the other will have `aria-live: |
| 74 | // polite`. |
| 75 | class ExtraAnnouncementNodes { |
| 76 | public: |
| 77 | explicit ExtraAnnouncementNodes(AXNode* root); |
| 78 | ~ExtraAnnouncementNodes(); |
| 79 | |
| 80 | AXNode& AssertiveNode() const { return *assertive_node_; } |
| 81 | AXNode& PoliteNode() const { return *polite_node_; } |
| 82 | int Count() const { |
| 83 | return (assertive_node_ ? 1 : 0) + (polite_node_ ? 1 : 0); |
| 84 | } |
| 85 | |
| 86 | static constexpr int kHighPriorityIndex = 0; |
| 87 | static constexpr int kNormalPriorityIndex = 1; |
| 88 | |
| 89 | private: |
| 90 | std::unique_ptr<AXNode> CreateNode(const std::string& live_status, |
| 91 | AXNode* root); |
| 92 | |
| 93 | std::unique_ptr<AXNode> assertive_node_; |
| 94 | std::unique_ptr<AXNode> polite_node_; |
| 95 | }; |
Jacques Newman | 441afe2 | 2025-06-24 23:54:08 | [diff] [blame] | 96 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) |
Evelynn Kaplan | 6cd535ce | 2025-03-20 23:58:18 | [diff] [blame] | 97 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 98 | // AXTree is a live, managed tree of AXNode objects that can receive |
| 99 | // updates from another AXTreeSource via AXTreeUpdates, and it can be |
| 100 | // used as a source for sending updates to another client tree. |
| 101 | // It's designed to be subclassed to implement support for native |
| 102 | // accessibility APIs on a specific platform. |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 103 | class AX_EXPORT AXTree { |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 104 | public: |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 105 | using IntReverseRelationMap = |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 106 | std::map<ax::mojom::IntAttribute, std::map<AXNodeID, std::set<AXNodeID>>>; |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 107 | using IntListReverseRelationMap = |
| 108 | std::map<ax::mojom::IntListAttribute, |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 109 | std::map<AXNodeID, std::set<AXNodeID>>>; |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 110 | |
Nektarios Paisios | 77c422a | 2021-10-19 10:37:00 | [diff] [blame] | 111 | // If called, the focused node in this tree will never be ignored, even if it |
| 112 | // has the ignored state set. For now, this boolean will be set to false for |
| 113 | // all trees except in test scenarios, in order to thoroughly test the |
| 114 | // relevant code without causing any potential regressions. Ultimately, we |
| 115 | // want to expose all focused nodes so that a user of an assistive technology |
| 116 | // will be able to interact with the application / website, even if there is |
| 117 | // an authoring error, e.g. the aria-hidden attribute has been applied to the |
| 118 | // focused element. |
| 119 | // TODO(nektar): Removed once the feature has been fully tested. |
| 120 | static void SetFocusedNodeShouldNeverBeIgnored(); |
| 121 | |
| 122 | // Determines the ignored state of a node, given information about the node |
| 123 | // and the tree. |
| 124 | static bool ComputeNodeIsIgnored(const AXTreeData* optional_tree_data, |
| 125 | const AXNodeData& node_data); |
| 126 | |
| 127 | // Determines whether a node has flipped its ignored state, given information |
| 128 | // about the previous and current state of the node / tree. |
| 129 | static bool ComputeNodeIsIgnoredChanged( |
| 130 | const AXTreeData* optional_old_tree_data, |
| 131 | const AXNodeData& old_node_data, |
| 132 | const AXTreeData* optional_new_tree_data, |
| 133 | const AXNodeData& new_node_data); |
| 134 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 135 | AXTree(); |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 136 | explicit AXTree(const AXTreeUpdate& initial_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 137 | virtual ~AXTree(); |
| 138 | |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 139 | // AXTree owns pointers so copying is non-trivial. |
| 140 | AXTree(const AXTree&) = delete; |
| 141 | AXTree& operator=(const AXTree&) = delete; |
| 142 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 143 | void AddObserver(AXTreeObserver* observer); |
| 144 | bool HasObserver(AXTreeObserver* observer); |
Nektarios Paisios | db7b5ee | 2020-02-18 21:28:11 | [diff] [blame] | 145 | void RemoveObserver(AXTreeObserver* observer); |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 146 | |
| 147 | base::ObserverList<AXTreeObserver>& observers() { return observers_; } |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 148 | |
tfarina | 6b1c1e08 | 2015-02-20 23:47:07 | [diff] [blame] | 149 | AXNode* root() const { return root_; } |
| 150 | |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 151 | const AXTreeData& data() const; |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 152 | |
Nektarios Paisios | db7b5ee | 2020-02-18 21:28:11 | [diff] [blame] | 153 | // Destroys the tree and notifies all observers. |
| 154 | void Destroy(); |
| 155 | |
Adam Ettenberger | 86af253 | 2019-09-17 20:04:46 | [diff] [blame] | 156 | // Returns the globally unique ID of this accessibility tree. |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 157 | const AXTreeID& GetAXTreeID() const; |
Adam Ettenberger | 86af253 | 2019-09-17 20:04:46 | [diff] [blame] | 158 | |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 159 | // Given a node in this accessibility tree that corresponds to a table |
| 160 | // or grid, return an object containing information about the |
| 161 | // table structure. This object is computed lazily on-demand and |
| 162 | // cached until the next time the tree is updated. Clients should |
| 163 | // not retain this pointer, they should just request it every time |
| 164 | // it's needed. |
| 165 | // |
| 166 | // Returns nullptr if the node is not a valid table. |
| 167 | AXTableInfo* GetTableInfo(const AXNode* table_node) const; |
| 168 | |
tfarina | 6b1c1e08 | 2015-02-20 23:47:07 | [diff] [blame] | 169 | // Returns the AXNode with the given |id| if it is part of this AXTree. |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 170 | AXNode* GetFromId(AXNodeID id) const; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 171 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 172 | // Returns true on success. If it returns false, it's a fatal error |
| 173 | // and this tree should be destroyed, and the source of the tree update |
| 174 | // should not be trusted any longer. |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 175 | virtual bool Unserialize(const AXTreeUpdate& update); |
| 176 | |
Nektarios Paisios | 26ac2b4 | 2021-06-02 18:24:19 | [diff] [blame] | 177 | // Used by tests to update the tree data without changing any of the nodes in |
| 178 | // the tree, notifying all tree observers in the process. |
| 179 | virtual void UpdateDataForTesting(const AXTreeData& data); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 180 | |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 181 | // Convert any rectangle from the local coordinate space of one node in |
| 182 | // the tree, to bounds in the coordinate space of the tree. |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 183 | // If set, updates |offscreen| boolean to be true if the node is offscreen |
| 184 | // relative to its rootWebArea. Callers should initialize |offscreen| |
| 185 | // to false: this method may get called multiple times in a row and |
| 186 | // |offscreen| will be propagated. |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 187 | // If |clip_bounds| is true, result bounds will be clipped. |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 188 | gfx::RectF RelativeToTreeBounds(const AXNode* node, |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 189 | gfx::RectF node_bounds, |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 190 | bool* offscreen = nullptr, |
David Tseng | 7bf30c3c | 2022-07-22 15:13:37 | [diff] [blame] | 191 | bool clip_bounds = true, |
| 192 | bool skip_container_offset = false) const; |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 193 | |
| 194 | // Get the bounds of a node in the coordinate space of the tree. |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 195 | // If set, updates |offscreen| boolean to be true if the node is offscreen |
| 196 | // relative to its rootWebArea. Callers should initialize |offscreen| |
| 197 | // to false: this method may get called multiple times in a row and |
| 198 | // |offscreen| will be propagated. |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 199 | // If |clip_bounds| is true, result bounds will be clipped. |
| 200 | gfx::RectF GetTreeBounds(const AXNode* node, |
| 201 | bool* offscreen = nullptr, |
| 202 | bool clip_bounds = true) const; |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 203 | |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 204 | // Given a node ID attribute (one where IsNodeIdIntAttribute is true), |
| 205 | // and a destination node ID, return a set of all source node IDs that |
| 206 | // have that relationship attribute between them and the destination. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 207 | std::set<AXNodeID> GetReverseRelations(ax::mojom::IntAttribute attr, |
| 208 | AXNodeID dst_id) const; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 209 | |
| 210 | // Given a node ID list attribute (one where |
| 211 | // IsNodeIdIntListAttribute is true), and a destination node ID, |
| 212 | // return a set of all source node IDs that have that relationship |
| 213 | // attribute between them and the destination. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 214 | std::set<AXNodeID> GetReverseRelations(ax::mojom::IntListAttribute attr, |
| 215 | AXNodeID dst_id) const; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 216 | |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 217 | // Given a child tree ID, return the node IDs of all nodes in the tree who |
| 218 | // have a kChildTreeId int attribute with that value. |
Nektarios Paisios | 50e579f1 | 2022-05-19 19:22:39 | [diff] [blame] | 219 | // |
| 220 | // TODO(accessibility): There should really be only one host node per child |
| 221 | // tree, so the return value should not be a set but a single node ID or |
| 222 | // `kInvalidAXNodeID`. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 223 | std::set<AXNodeID> GetNodeIdsForChildTreeId(AXTreeID child_tree_id) const; |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 224 | |
Dominic Mazzoni | 748888c | 2018-11-01 22:34:59 | [diff] [blame] | 225 | // Get all of the child tree IDs referenced by any node in this tree. |
| 226 | const std::set<AXTreeID> GetAllChildTreeIds() const; |
| 227 | |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 228 | // Map from a relation attribute to a map from a target id to source ids. |
| 229 | const IntReverseRelationMap& int_reverse_relations() { |
| 230 | return int_reverse_relations_; |
| 231 | } |
| 232 | const IntListReverseRelationMap& intlist_reverse_relations() { |
| 233 | return intlist_reverse_relations_; |
| 234 | } |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 235 | |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 236 | // Return a multi-line indented string representation, for logging. |
Aaron Leventhal | 763d46a | 2022-12-21 19:16:22 | [diff] [blame] | 237 | std::string ToString(bool verbose = true) const; |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 238 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 239 | // A string describing the error from an unsuccessful Unserialize, |
| 240 | // for testing and debugging. |
tfarina | d0bfb4b6 | 2015-02-18 17:20:32 | [diff] [blame] | 241 | const std::string& error() const { return error_; } |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 242 | |
dmazzoni | ee2eaca | 2015-03-18 18:13:07 | [diff] [blame] | 243 | int size() { return static_cast<int>(id_map_.size()); } |
| 244 | |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 245 | // Return a negative number that's suitable to use for a node ID for |
| 246 | // internal nodes created automatically by an AXTree, so as not to |
| 247 | // conflict with positive-numbered node IDs from tree sources. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 248 | AXNodeID GetNextNegativeInternalNodeId(); |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 249 | |
Akihiro Ota | f42a7d0 | 2020-06-12 19:07:56 | [diff] [blame] | 250 | // Returns the PosInSet of |node|. Looks in node_set_size_pos_in_set_info_map_ |
| 251 | // for cached value. Calls |ComputeSetSizePosInSetAndCache|if no value is |
| 252 | // present in the cache. |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 253 | std::optional<int> GetPosInSet(const AXNode& node); |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 254 | |
Akihiro Ota | f42a7d0 | 2020-06-12 19:07:56 | [diff] [blame] | 255 | // Returns the SetSize of |node|. Looks in node_set_size_pos_in_set_info_map_ |
| 256 | // for cached value. Calls |ComputeSetSizePosInSetAndCache|if no value is |
| 257 | // present in the cache. |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 258 | std::optional<int> GetSetSize(const AXNode& node); |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 259 | |
Nektarios Paisios | d3e82c6d | 2022-08-12 19:06:55 | [diff] [blame] | 260 | // Returns the part of the current selection that falls within this |
| 261 | // accessibility tree, if any. |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 262 | AXSelection GetSelection() const; |
Nektarios Paisios | d3e82c6d | 2022-08-12 19:06:55 | [diff] [blame] | 263 | |
| 264 | // Returns the part of the current selection that falls within this |
| 265 | // accessibility tree, if any, adjusting its endpoints to be within unignored |
| 266 | // nodes. (An "ignored" node is a node that is not exposed to platform APIs: |
| 267 | // See `AXNode::IsIgnored`.) |
Aaron leventhal | ebac41bf | 2025-04-17 22:40:29 | [diff] [blame] | 268 | AXSelection GetUnignoredSelection() const; |
Jacques Newman | 339afc6 | 2019-08-14 00:49:22 | [diff] [blame] | 269 | |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 270 | bool GetTreeUpdateInProgressState() const; |
Akihiro Ota | e3e420e | 2019-04-17 19:57:40 | [diff] [blame] | 271 | |
Kurt Catti-Schmidt | c8445a1 | 2019-08-07 18:52:58 | [diff] [blame] | 272 | // Returns true if the tree represents a paginated document |
Alexander Surkov | 4ab64cf | 2022-09-01 20:07:46 | [diff] [blame] | 273 | bool HasPaginationSupport() const; |
Kurt Catti-Schmidt | c8445a1 | 2019-08-07 18:52:58 | [diff] [blame] | 274 | |
Chris Hall | 697d99b | 2019-07-09 02:36:11 | [diff] [blame] | 275 | // Language detection manager, entry point to language detection features. |
| 276 | // TODO(chrishall): Should this be stored by pointer or value? |
| 277 | // When should we initialize this? |
| 278 | std::unique_ptr<AXLanguageDetectionManager> language_detection_manager; |
Chris Hall | 3420818 | 2019-03-13 02:26:18 | [diff] [blame] | 279 | |
David Tseng | 41f13cbd | 2021-11-06 18:39:03 | [diff] [blame] | 280 | // Event metadata while applying a tree update during unserialization. |
| 281 | AXEvent* event_data() const { return event_data_.get(); } |
David Tseng | b0d4366 | 2020-05-20 20:47:28 | [diff] [blame] | 282 | |
Benjamin Beaudry | 710df4d | 2023-02-08 23:47:56 | [diff] [blame] | 283 | // Notify the delegate that the tree manager for |previous_tree_id| will be |
| 284 | // removed from the AXTreeManagerMap. Because we sometimes remove the tree |
| 285 | // manager after the tree's id has been modified, we need to pass the (old) |
| 286 | // tree id associated with the manager we are removing even though it is the |
| 287 | // same tree. |
| 288 | void NotifyTreeManagerWillBeRemoved(AXTreeID previous_tree_id); |
Benjamin Beaudry | e8f23a2 | 2020-12-17 20:08:02 | [diff] [blame] | 289 | |
Stefan Zager | 3a5aabb | 2023-03-28 22:53:20 | [diff] [blame] | 290 | void NotifyChildTreeConnectionChanged(AXNode* node, AXTree* child_tree); |
| 291 | |
Jacques Newman | 441afe2 | 2025-06-24 23:54:08 | [diff] [blame] | 292 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) |
Evelynn Kaplan | 6cd535ce | 2025-03-20 23:58:18 | [diff] [blame] | 293 | void ClearExtraAnnouncementNodes(); |
| 294 | void CreateExtraAnnouncementNodes(); |
| 295 | ExtraAnnouncementNodes* extra_announcement_nodes() const { |
| 296 | return extra_announcement_nodes_.get(); |
| 297 | } |
Jacques Newman | 441afe2 | 2025-06-24 23:54:08 | [diff] [blame] | 298 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) |
Evelynn Kaplan | 6cd535ce | 2025-03-20 23:58:18 | [diff] [blame] | 299 | |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 300 | private: |
Nektarios Paisios | 8eb31fc | 2022-02-18 16:37:58 | [diff] [blame] | 301 | friend class ScopedTreeUpdateInProgressStateSetter; |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 302 | friend class AXTableInfoTest; |
| 303 | |
Nektarios Paisios | 77c422a | 2021-10-19 10:37:00 | [diff] [blame] | 304 | // Indicates if the node with the focus should never be ignored, (see |
| 305 | // `SetFocusedNodeShouldNeverBeIgnored` above). |
| 306 | static bool is_focused_node_always_unignored_; |
| 307 | |
Aaron Leventhal | f92d9971 | 2024-12-05 20:58:38 | [diff] [blame] | 308 | #if AX_FAIL_FAST_BUILD() |
Aaron Leventhal | c0bc6e9 | 2024-02-02 01:09:13 | [diff] [blame] | 309 | void CheckTreeConsistency(const AXTreeUpdate& update); |
| 310 | #endif |
| 311 | |
Aaron Leventhal | a674d63 | 2020-09-30 07:05:36 | [diff] [blame] | 312 | // Accumulate errors as there can be more than one before Chrome is crashed |
Aaron Leventhal | 6ceb588 | 2024-04-17 15:19:38 | [diff] [blame] | 313 | // via UnrecoverableAccessibilityError(); |
Aaron Leventhal | e12416e | 2022-12-23 16:08:17 | [diff] [blame] | 314 | // In an AX_FAIL_FAST_BUILD or if |is_fatal|, will assert/crash immediately. |
Aaron Leventhal | bc649ff | 2022-08-11 18:53:23 | [diff] [blame] | 315 | void RecordError(const AXTreeUpdateState& update_state, |
Aaron Leventhal | e12416e | 2022-12-23 16:08:17 | [diff] [blame] | 316 | std::string new_error, |
| 317 | bool is_fatal = false); |
Aaron Leventhal | a674d63 | 2020-09-30 07:05:36 | [diff] [blame] | 318 | |
dtseng | 5a7b3d9 | 2016-09-08 06:35:58 | [diff] [blame] | 319 | AXNode* CreateNode(AXNode* parent, |
Dominic Mazzoni | 9ccdedb2 | 2021-01-30 17:59:42 | [diff] [blame] | 320 | AXNodeID id, |
Peter Kasting | 94a07a1 | 2019-05-22 19:26:28 | [diff] [blame] | 321 | size_t index_in_parent, |
dtseng | 5a7b3d9 | 2016-09-08 06:35:58 | [diff] [blame] | 322 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 323 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 324 | // Accumulates the work that will be required to update the AXTree. |
| 325 | // This allows us to notify observers of structure changes when the |
| 326 | // tree is still in a stable and unchanged state. |
| 327 | bool ComputePendingChanges(const AXTreeUpdate& update, |
Aaron Leventhal | 051c1431 | 2023-09-01 00:17:01 | [diff] [blame] | 328 | AXTreeUpdateState* update_state); |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 329 | |
| 330 | // Populates |update_state| with information about actions that will |
| 331 | // be performed on the tree during the update, such as adding or |
| 332 | // removing nodes in the tree. Returns true on success. |
| 333 | // Nothing within this call should modify tree structure or node data. |
| 334 | bool ComputePendingChangesToNode(const AXNodeData& new_data, |
| 335 | bool is_new_root, |
Aaron Leventhal | 051c1431 | 2023-09-01 00:17:01 | [diff] [blame] | 336 | AXTreeUpdateState* update_state); |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 337 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 338 | // This is called from within Unserialize(), it returns true on success. |
dmazzoni | 67b4db2 | 2016-04-23 00:40:04 | [diff] [blame] | 339 | bool UpdateNode(const AXNodeData& src, |
| 340 | bool is_new_root, |
| 341 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 342 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 343 | // Notify the delegate that the subtree rooted at |node| will be |
| 344 | // destroyed or reparented. |
| 345 | void NotifySubtreeWillBeReparentedOrDeleted( |
| 346 | AXNode* node, |
| 347 | const AXTreeUpdateState* update_state); |
| 348 | |
| 349 | // Notify the delegate that |node| will be destroyed or reparented. |
| 350 | void NotifyNodeWillBeReparentedOrDeleted( |
Lucas Radaelli | 36b1875 | 2024-09-17 18:37:54 | [diff] [blame] | 351 | AXNode& node, |
| 352 | const AXTreeUpdateState& update_state); |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 353 | |
| 354 | // Notify the delegate that |node| and all of its descendants will be |
Victor Fei | e3cce4c | 2019-11-14 18:35:41 | [diff] [blame] | 355 | // destroyed. This function is called during AXTree teardown. |
Lucas Radaelli | 36b1875 | 2024-09-17 18:37:54 | [diff] [blame] | 356 | void RecursivelyNotifyNodeWillBeDeletedForTreeTeardown( |
| 357 | AXNode& node, |
Greg Thompson | c154391 | 2025-06-24 13:22:44 | [diff] [blame] | 358 | absl::flat_hash_set<AXNodeID>& deleted_nodes); |
Victor Fei | e3cce4c | 2019-11-14 18:35:41 | [diff] [blame] | 359 | |
| 360 | // Notify the delegate that the node marked by |node_id| has been deleted. |
| 361 | // We are passing the node id instead of ax node is because by the time this |
| 362 | // function is called, the ax node in the tree will already have been |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 363 | // destroyed. |
Dominic Mazzoni | 9ccdedb2 | 2021-01-30 17:59:42 | [diff] [blame] | 364 | void NotifyNodeHasBeenDeleted(AXNodeID node_id); |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 365 | |
| 366 | // Notify the delegate that |node| has been created or reparented. |
| 367 | void NotifyNodeHasBeenReparentedOrCreated( |
| 368 | AXNode* node, |
| 369 | const AXTreeUpdateState* update_state); |
| 370 | |
Nektarios Paisios | 77c422a | 2021-10-19 10:37:00 | [diff] [blame] | 371 | // Notify the delegate that `node` will change its data attributes, including |
| 372 | // its ignored state. |
| 373 | void NotifyNodeAttributesWillChange(AXNode* node, |
Aaron Leventhal | 06f376bf | 2022-12-01 02:15:07 | [diff] [blame] | 374 | AXTreeUpdateState& update_state, |
Nektarios Paisios | 77c422a | 2021-10-19 10:37:00 | [diff] [blame] | 375 | const AXTreeData* optional_old_tree_data, |
| 376 | const AXNodeData& old_data, |
| 377 | const AXTreeData* new_tree_data, |
| 378 | const AXNodeData& new_data); |
Adam Ettenberger | 05afcec | 2019-08-06 17:11:29 | [diff] [blame] | 379 | |
Aaron Leventhal | 06f376bf | 2022-12-01 02:15:07 | [diff] [blame] | 380 | // Notify the delegate that `node` will change its its ignored state. |
| 381 | void NotifyNodeIgnoredStateWillChange( |
| 382 | AXNode* node, |
| 383 | const AXTreeData* optional_old_tree_data, |
| 384 | const AXNodeData& old_data, |
| 385 | const AXTreeData* new_tree_data, |
| 386 | const AXNodeData& new_data); |
| 387 | |
Nektarios Paisios | 77c422a | 2021-10-19 10:37:00 | [diff] [blame] | 388 | // Notify the delegate that `node` has changed its data attributes, including |
| 389 | // its ignored state. |
| 390 | void NotifyNodeAttributesHaveBeenChanged( |
| 391 | AXNode* node, |
Aaron Leventhal | 06f376bf | 2022-12-01 02:15:07 | [diff] [blame] | 392 | AXTreeUpdateState& update_state, |
Nektarios Paisios | 77c422a | 2021-10-19 10:37:00 | [diff] [blame] | 393 | const AXTreeData* optional_old_tree_data, |
| 394 | const AXNodeData& old_data, |
| 395 | const AXTreeData* new_tree_data, |
| 396 | const AXNodeData& new_data); |
dmazzoni | 3ab5385c | 2017-03-13 18:07:03 | [diff] [blame] | 397 | |
Aaron Leventhal | 32de9b9 | 2024-03-12 15:55:38 | [diff] [blame] | 398 | // Update maps that track which relations are pointing to |node|. |
| 399 | void UpdateReverseRelations(AXNode* node, |
| 400 | const AXNodeData& new_data, |
| 401 | bool is_new_node = false); |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 402 | |
Nektarios Paisios | 8eb31fc | 2022-02-18 16:37:58 | [diff] [blame] | 403 | // Sets a flag indicating whether the tree is currently being updated or not. |
| 404 | // If the tree is being updated, then its internal pointers might be invalid |
| 405 | // and the tree should not be traversed. |
| 406 | void SetTreeUpdateInProgressState(bool set_tree_update_value); |
| 407 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 408 | // Returns true if all pending changes in the |update_state| have been |
| 409 | // handled. If this returns false, the |error_| message will be populated. |
| 410 | // It's a fatal error to have pending changes after exhausting |
| 411 | // the AXTreeUpdate. |
| 412 | bool ValidatePendingChangesComplete(const AXTreeUpdateState& update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 413 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 414 | // Modifies |update_state| so that it knows what subtree and nodes are |
| 415 | // going to be destroyed for the subtree rooted at |node|. |
Dominic Mazzoni | 9ccdedb2 | 2021-01-30 17:59:42 | [diff] [blame] | 416 | void MarkSubtreeForDestruction(AXNodeID node_id, |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 417 | AXTreeUpdateState* update_state); |
| 418 | |
| 419 | // Modifies |update_state| so that it knows what nodes are |
| 420 | // going to be destroyed for the subtree rooted at |node|. |
Dominic Mazzoni | 9ccdedb2 | 2021-01-30 17:59:42 | [diff] [blame] | 421 | void MarkNodesForDestructionRecursive(AXNodeID node_id, |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 422 | AXTreeUpdateState* update_state); |
| 423 | |
| 424 | // Validates that destroying the subtree rooted at |node| has required |
| 425 | // information in |update_state|, then calls DestroyNodeAndSubtree on it. |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 426 | void DestroySubtree(AXNode* node, AXTreeUpdateState* update_state); |
dmazzoni | a4b4891 | 2015-01-24 00:08:56 | [diff] [blame] | 427 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 428 | // Call Destroy() on |node|, and delete it from the id map, and then |
| 429 | // call recursively on all nodes in its subtree. |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 430 | void DestroyNodeAndSubtree(AXNode* node, AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 431 | |
| 432 | // Iterate over the children of |node| and for each child, destroy the |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 433 | // child and its subtree if its id is not in |new_child_ids|. |
| 434 | void DeleteOldChildren(AXNode* node, |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 435 | const std::vector<AXNodeID>& new_child_ids, |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 436 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 437 | |
| 438 | // Iterate over |new_child_ids| and populate |new_children| with |
| 439 | // pointers to child nodes, reusing existing nodes already in the tree |
| 440 | // if they exist, and creating otherwise. Reparenting is disallowed, so |
| 441 | // 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] | 442 | // error. Returns true on success, false on fatal error. |
Ali Hijazi | e63cbaf6 | 2023-12-20 19:29:35 | [diff] [blame] | 443 | bool CreateNewChildVector( |
| 444 | AXNode* node, |
| 445 | const std::vector<AXNodeID>& new_child_ids, |
| 446 | std::vector<raw_ptr<AXNode, VectorExperimental>>* new_children, |
| 447 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 448 | |
Nektarios Paisios | 77c422a | 2021-10-19 10:37:00 | [diff] [blame] | 449 | // Returns the lowest unignored ancestor of the node with the given ID. If the |
| 450 | // node is not ignored, it returns the node. |
| 451 | AXNode* GetUnignoredAncestorFromId(AXNodeID node_id) const; |
| 452 | |
Dominic Mazzoni | a1bb0d12 | 2019-09-26 20:19:59 | [diff] [blame] | 453 | // Internal implementation of RelativeToTreeBounds. It calls itself |
| 454 | // recursively but ensures that it can only do so exactly once! |
| 455 | gfx::RectF RelativeToTreeBoundsInternal(const AXNode* node, |
| 456 | gfx::RectF node_bounds, |
| 457 | bool* offscreen, |
| 458 | bool clip_bounds, |
David Tseng | 7bf30c3c | 2022-07-22 15:13:37 | [diff] [blame] | 459 | bool skip_container_offset, |
Dominic Mazzoni | a1bb0d12 | 2019-09-26 20:19:59 | [diff] [blame] | 460 | bool allow_recursion) const; |
| 461 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 462 | base::ObserverList<AXTreeObserver> observers_; |
Ali Hijazi | 2fe3e40 | 2022-08-05 16:09:31 | [diff] [blame] | 463 | raw_ptr<AXNode> root_ = nullptr; |
Addison Luh | d7d28ac | 2025-06-23 16:15:10 | [diff] [blame] | 464 | absl::flat_hash_map<AXNodeID, std::unique_ptr<AXNode>> id_map_; |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 465 | std::string error_; |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 466 | AXTreeData data_; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 467 | |
| 468 | // Map from an int attribute (if IsNodeIdIntAttribute is true) to |
| 469 | // a reverse mapping from target nodes to source nodes. |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 470 | IntReverseRelationMap int_reverse_relations_; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 471 | // Map from an int list attribute (if IsNodeIdIntListAttribute is true) to |
| 472 | // a reverse mapping from target nodes to source nodes. |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 473 | IntListReverseRelationMap intlist_reverse_relations_; |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 474 | // 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] | 475 | std::map<AXTreeID, std::set<AXNodeID>> child_tree_id_reverse_map_; |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 476 | |
| 477 | // 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] | 478 | // Invalidated every time the tree is updated. |
Addison Luh | d7d28ac | 2025-06-23 16:15:10 | [diff] [blame] | 479 | mutable absl::flat_hash_map<AXNodeID, std::unique_ptr<AXTableInfo>> |
Aaron Leventhal | 8079718 | 2020-02-25 18:50:31 | [diff] [blame] | 480 | table_info_map_; |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 481 | |
| 482 | // The next negative node ID to use for internal nodes. |
Nektarios Paisios | 527d33fb5 | 2021-02-23 19:23:28 | [diff] [blame] | 483 | AXNodeID next_negative_internal_node_id_ = -1; |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 484 | |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 485 | // Contains pos_in_set and set_size data for an AXNode. |
Stephan Hartmann | aeef688 | 2020-04-20 18:21:43 | [diff] [blame] | 486 | struct NodeSetSizePosInSetInfo { |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 487 | std::optional<int> pos_in_set; |
| 488 | std::optional<int> set_size; |
| 489 | std::optional<int> lowest_hierarchical_level; |
Stephan Hartmann | aeef688 | 2020-04-20 18:21:43 | [diff] [blame] | 490 | }; |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 491 | |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 492 | // Represents the content of an ordered set which includes the ordered set |
| 493 | // items and the ordered set container if it exists. |
| 494 | struct OrderedSetContent; |
| 495 | |
| 496 | // Maps a particular hierarchical level to a list of OrderedSetContents. |
| 497 | // Represents all ordered set items/container on a particular hierarchical |
| 498 | // level. |
| 499 | struct OrderedSetItemsMap; |
| 500 | |
| 501 | // Populates |items_map_to_be_populated| with all items associated with |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 502 | // |original_node| and within |ordered_set|. Only items whose roles match the |
| 503 | // role of the |ordered_set| will be added. |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 504 | void PopulateOrderedSetItemsMap( |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 505 | const AXNode& original_node, |
| 506 | const AXNode* ordered_set, |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 507 | OrderedSetItemsMap* items_map_to_be_populated) const; |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 508 | |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 509 | // Helper function for recursively populating ordered sets items map with |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 510 | // all items associated with |original_node| and |ordered_set|. |local_parent| |
| 511 | // tracks the recursively passed in child nodes of |ordered_set|. |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 512 | void RecursivelyPopulateOrderedSetItemsMap( |
Victor Fei | d95130c | 2020-02-03 21:42:54 | [diff] [blame] | 513 | const AXNode& original_node, |
| 514 | const AXNode* ordered_set, |
| 515 | const AXNode* local_parent, |
Arthur Sonzogni | 3eb9fd51 | 2024-02-09 12:20:43 | [diff] [blame] | 516 | std::optional<int> ordered_set_min_level, |
| 517 | std::optional<int> prev_level, |
Lei Zhang | a0614478 | 2020-03-13 09:28:47 | [diff] [blame] | 518 | OrderedSetItemsMap* items_map_to_be_populated) const; |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 519 | |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 520 | // Computes the pos_in_set and set_size values of all items in ordered_set and |
| 521 | // caches those values. Called by GetPosInSet and GetSetSize. |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 522 | void ComputeSetSizePosInSetAndCache(const AXNode& node, |
| 523 | const AXNode* ordered_set); |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 524 | |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 525 | // Helper for ComputeSetSizePosInSetAndCache. Computes and caches the |
| 526 | // pos_in_set and set_size values for a given OrderedSetContent. |
| 527 | void ComputeSetSizePosInSetAndCacheHelper( |
| 528 | const OrderedSetContent& ordered_set_content); |
| 529 | |
Akihiro Ota | b6a8a4d | 2018-12-04 01:56:39 | [diff] [blame] | 530 | // Map from node ID to OrderedSetInfo. |
| 531 | // Item-like and ordered-set-like objects will map to populated OrderedSetInfo |
| 532 | // objects. |
| 533 | // All other objects will map to default-constructed OrderedSetInfo objects. |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 534 | // Invalidated every time the tree is updated. |
Addison Luh | d7d28ac | 2025-06-23 16:15:10 | [diff] [blame] | 535 | mutable absl::flat_hash_map<AXNodeID, NodeSetSizePosInSetInfo> |
Victor Fei | 5eea952e | 2020-02-28 01:43:09 | [diff] [blame] | 536 | node_set_size_pos_in_set_info_map_; |
Chris Hall | 9b34c2c | 2018-12-04 01:45:56 | [diff] [blame] | 537 | |
Akihiro Ota | e3e420e | 2019-04-17 19:57:40 | [diff] [blame] | 538 | // Indicates if the tree is updating. |
| 539 | bool tree_update_in_progress_ = false; |
Kurt Catti-Schmidt | c8445a1 | 2019-08-07 18:52:58 | [diff] [blame] | 540 | |
| 541 | // Indicates if the tree represents a paginated document |
| 542 | bool has_pagination_support_ = false; |
David Tseng | b0d4366 | 2020-05-20 20:47:28 | [diff] [blame] | 543 | |
Aaron leventhal | eab7a13 | 2025-05-01 13:28:11 | [diff] [blame] | 544 | #if DCHECK_IS_ON() |
| 545 | bool is_destroyed_ = false; |
| 546 | int unserialize_count_ = 0; |
| 547 | #endif |
| 548 | |
David Tseng | 41f13cbd | 2021-11-06 18:39:03 | [diff] [blame] | 549 | std::unique_ptr<AXEvent> event_data_; |
Evelynn Kaplan | 6cd535ce | 2025-03-20 23:58:18 | [diff] [blame] | 550 | |
Jacques Newman | 441afe2 | 2025-06-24 23:54:08 | [diff] [blame] | 551 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) |
Evelynn Kaplan | 6cd535ce | 2025-03-20 23:58:18 | [diff] [blame] | 552 | std::unique_ptr<ExtraAnnouncementNodes> extra_announcement_nodes_ = nullptr; |
Jacques Newman | 441afe2 | 2025-06-24 23:54:08 | [diff] [blame] | 553 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 554 | }; |
| 555 | |
Nektarios Paisios | 8eb31fc | 2022-02-18 16:37:58 | [diff] [blame] | 556 | // Sets the flag that indicates whether the accessibility tree is currently |
| 557 | // being updated, and ensures that it is reset to its previous value when the |
| 558 | // instance is destructed. An accessibility tree that is being updated is |
| 559 | // unstable and should not be traversed. |
| 560 | class AX_EXPORT ScopedTreeUpdateInProgressStateSetter { |
| 561 | public: |
| 562 | explicit ScopedTreeUpdateInProgressStateSetter(AXTree& tree) |
| 563 | : tree_(&tree), |
| 564 | last_tree_update_in_progress_(tree.GetTreeUpdateInProgressState()) { |
| 565 | tree_->SetTreeUpdateInProgressState(true); |
| 566 | } |
| 567 | |
| 568 | ~ScopedTreeUpdateInProgressStateSetter() { |
| 569 | tree_->SetTreeUpdateInProgressState(last_tree_update_in_progress_); |
| 570 | } |
| 571 | |
| 572 | ScopedTreeUpdateInProgressStateSetter( |
| 573 | const ScopedTreeUpdateInProgressStateSetter&) = delete; |
| 574 | ScopedTreeUpdateInProgressStateSetter& operator=( |
| 575 | const ScopedTreeUpdateInProgressStateSetter&) = delete; |
| 576 | |
| 577 | private: |
Keishi Hattori | e175ac5 | 2022-06-07 06:24:57 | [diff] [blame] | 578 | const raw_ptr<AXTree> tree_; |
Nektarios Paisios | 8eb31fc | 2022-02-18 16:37:58 | [diff] [blame] | 579 | bool last_tree_update_in_progress_; |
| 580 | }; |
| 581 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 582 | } // namespace ui |
| 583 | |
| 584 | #endif // UI_ACCESSIBILITY_AX_TREE_H_ |