blob: 1a836fbd3fa08d770d0c5ba95fc6a2b793ab58a8 [file] [log] [blame]
[email protected]4b02bbca2013-11-22 08:59:031// 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
avi9c81217b2015-12-24 23:40:058#include <stdint.h>
9
Lei Zhanga06144782020-03-13 09:28:4710#include <map>
Chris Hall34208182019-03-13 02:26:1811#include <memory>
[email protected]d4e273462013-12-04 04:37:5812#include <set>
Lei Zhanga06144782020-03-13 09:28:4713#include <string>
Takuto Ikutaadf31eb2019-01-05 00:32:4814#include <unordered_map>
Lei Zhanga06144782020-03-13 09:28:4715#include <vector>
[email protected]4b02bbca2013-11-22 08:59:0316
Jacques Newman5846e622021-01-15 02:15:5917#include "base/metrics/histogram_functions.h"
Dominic Mazzoni8549eb682018-12-11 23:48:3218#include "base/observer_list.h"
James Cook36cab7c2019-10-29 23:26:4019#include "ui/accessibility/ax_enums.mojom-forward.h"
[email protected]4b02bbca2013-11-22 08:59:0320#include "ui/accessibility/ax_export.h"
Dominic Mazzoniecfb4fd2018-10-23 07:34:2021#include "ui/accessibility/ax_node.h"
dmazzoni329fd012015-10-22 20:05:3522#include "ui/accessibility/ax_node_data.h"
23#include "ui/accessibility/ax_tree_data.h"
[email protected]4b02bbca2013-11-22 08:59:0324#include "ui/accessibility/ax_tree_update.h"
25
26namespace ui {
27
Dominic Mazzoni3d9b5b92018-04-18 21:36:3828class AXTableInfo;
Dominic Mazzoni8549eb682018-12-11 23:48:3229class AXTreeObserver;
[email protected]e736e81b2014-02-24 07:15:5830struct AXTreeUpdateState;
Chris Hall697d99b2019-07-09 02:36:1131class AXLanguageDetectionManager;
[email protected]e736e81b2014-02-24 07:15:5832
Jacques Newman5846e622021-01-15 02:15:5933// These values are persisted to logs. Entries should not be renumbered and
34// numeric values should never be reused.
35enum 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]4b02bbca2013-11-22 08:59:0361// 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 Mazzoniecfb4fd2018-10-23 07:34:2066class AX_EXPORT AXTree : public AXNode::OwnerTree {
[email protected]4b02bbca2013-11-22 08:59:0367 public:
Lei Zhanga06144782020-03-13 09:28:4768 using IntReverseRelationMap =
Nektarios Paisios527d33fb52021-02-23 19:23:2869 std::map<ax::mojom::IntAttribute, std::map<AXNodeID, std::set<AXNodeID>>>;
Lei Zhanga06144782020-03-13 09:28:4770 using IntListReverseRelationMap =
71 std::map<ax::mojom::IntListAttribute,
Nektarios Paisios527d33fb52021-02-23 19:23:2872 std::map<AXNodeID, std::set<AXNodeID>>>;
David Tsengef6b480d2018-02-19 12:48:4273
[email protected]4b02bbca2013-11-22 08:59:0374 AXTree();
dmazzoni329fd012015-10-22 20:05:3575 explicit AXTree(const AXTreeUpdate& initial_state);
[email protected]4b02bbca2013-11-22 08:59:0376 virtual ~AXTree();
77
Lei Zhanga06144782020-03-13 09:28:4778 // AXTree owns pointers so copying is non-trivial.
79 AXTree(const AXTree&) = delete;
80 AXTree& operator=(const AXTree&) = delete;
81
Dominic Mazzoni8549eb682018-12-11 23:48:3282 void AddObserver(AXTreeObserver* observer);
83 bool HasObserver(AXTreeObserver* observer);
Nektarios Paisiosdb7b5ee2020-02-18 21:28:1184 void RemoveObserver(AXTreeObserver* observer);
Dominic Mazzoni8549eb682018-12-11 23:48:3285
86 base::ObserverList<AXTreeObserver>& observers() { return observers_; }
[email protected]e736e81b2014-02-24 07:15:5887
tfarina6b1c1e082015-02-20 23:47:0788 AXNode* root() const { return root_; }
89
Joanmarie Diggs58b67c982020-11-13 15:33:2890 const AXTreeData& data() const override;
dmazzoni329fd012015-10-22 20:05:3591
Nektarios Paisiosdb7b5ee2020-02-18 21:28:1192 // Destroys the tree and notifies all observers.
93 void Destroy();
94
Dominic Mazzoniecfb4fd2018-10-23 07:34:2095 // AXNode::OwnerTree override.
Adam Ettenberger86af2532019-09-17 20:04:4696 // Returns the globally unique ID of this accessibility tree.
97 AXTreeID GetAXTreeID() const override;
98
99 // AXNode::OwnerTree override.
tfarina6b1c1e082015-02-20 23:47:07100 // Returns the AXNode with the given |id| if it is part of this AXTree.
Nektarios Paisios527d33fb52021-02-23 19:23:28101 AXNode* GetFromId(AXNodeID id) const override;
[email protected]4b02bbca2013-11-22 08:59:03102
[email protected]d4e273462013-12-04 04:37:58103 // 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.
dmazzoni329fd012015-10-22 20:05:35106 virtual bool Unserialize(const AXTreeUpdate& update);
107
108 virtual void UpdateData(const AXTreeData& data);
[email protected]4b02bbca2013-11-22 08:59:03109
Dominic Mazzoni2410fc62017-06-09 22:19:18110 // 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 Dektar2c6052d2017-09-27 00:32:32112 // 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 Dektardb71ad942017-11-29 20:07:48116 // If |clip_bounds| is true, result bounds will be clipped.
Dominic Mazzoni2410fc62017-06-09 22:19:18117 gfx::RectF RelativeToTreeBounds(const AXNode* node,
Katie Dektar2c6052d2017-09-27 00:32:32118 gfx::RectF node_bounds,
Katie Dektardb71ad942017-11-29 20:07:48119 bool* offscreen = nullptr,
120 bool clip_bounds = true) const;
Dominic Mazzoni2410fc62017-06-09 22:19:18121
122 // Get the bounds of a node in the coordinate space of the tree.
Katie Dektar2c6052d2017-09-27 00:32:32123 // 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 Dektardb71ad942017-11-29 20:07:48127 // 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 Mazzoni2410fc62017-06-09 22:19:18131
Dominic Mazzoni35f2a5252017-09-26 00:56:04132 // 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 Paisios527d33fb52021-02-23 19:23:28135 std::set<AXNodeID> GetReverseRelations(ax::mojom::IntAttribute attr,
136 AXNodeID dst_id) const;
Dominic Mazzoni35f2a5252017-09-26 00:56:04137
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 Paisios527d33fb52021-02-23 19:23:28142 std::set<AXNodeID> GetReverseRelations(ax::mojom::IntListAttribute attr,
143 AXNodeID dst_id) const;
Dominic Mazzoni35f2a5252017-09-26 00:56:04144
Dominic Mazzoniaa774822018-08-29 20:33:58145 // 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 Paisios527d33fb52021-02-23 19:23:28147 std::set<AXNodeID> GetNodeIdsForChildTreeId(AXTreeID child_tree_id) const;
Dominic Mazzoniaa774822018-08-29 20:33:58148
Dominic Mazzoni748888c2018-11-01 22:34:59149 // Get all of the child tree IDs referenced by any node in this tree.
150 const std::set<AXTreeID> GetAllChildTreeIds() const;
151
David Tsengef6b480d2018-02-19 12:48:42152 // 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 Mazzoni3d9b5b92018-04-18 21:36:38159
[email protected]5eec2f52014-01-06 22:30:54160 // Return a multi-line indented string representation, for logging.
161 std::string ToString() const;
162
[email protected]d4e273462013-12-04 04:37:58163 // A string describing the error from an unsuccessful Unserialize,
164 // for testing and debugging.
tfarinad0bfb4b62015-02-18 17:20:32165 const std::string& error() const { return error_; }
[email protected]d4e273462013-12-04 04:37:58166
dmazzoniee2eaca2015-03-18 18:13:07167 int size() { return static_cast<int>(id_map_.size()); }
168
Dominic Mazzonid42e00a2018-06-27 23:14:23169 // 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 Paisios527d33fb52021-02-23 19:23:28172 AXNodeID GetNextNegativeInternalNodeId();
Dominic Mazzonid42e00a2018-06-27 23:14:23173
Akihiro Otaf42a7d02020-06-12 19:07:56174 // 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 Bikineeveed0b26b2021-05-16 03:16:48177 absl::optional<int> GetPosInSet(const AXNode& node) override;
Akihiro Otaf42a7d02020-06-12 19:07:56178 // 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 Bikineeveed0b26b2021-05-16 03:16:48181 absl::optional<int> GetSetSize(const AXNode& node) override;
Akihiro Ota413ca722018-12-03 23:29:00182
Jacques Newman339afc62019-08-14 00:49:22183 Selection GetUnignoredSelection() const override;
184
Akihiro Otae3e420e2019-04-17 19:57:40185 bool GetTreeUpdateInProgressState() const override;
186 void SetTreeUpdateInProgressState(bool set_tree_update_value);
187
Kurt Catti-Schmidtc8445a12019-08-07 18:52:58188 // AXNode::OwnerTree override.
189 // Returns true if the tree represents a paginated document
190 bool HasPaginationSupport() const override;
191
Chris Hall697d99b2019-07-09 02:36:11192 // 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 Hall34208182019-03-13 02:26:18196
David Tsengb0d43662020-05-20 20:47:28197 // 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 Beaudrye8f23a22020-12-17 20:08:02202 // 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]e736e81b2014-02-24 07:15:58209 private:
Dominic Mazzoniecfb4fd2018-10-23 07:34:20210 friend class AXTableInfoTest;
211
Aaron Leventhala674d632020-09-30 07:05:36212 // 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 Mazzoniecfb4fd2018-10-23 07:34:20216 // 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
dtseng5a7b3d92016-09-08 06:35:58228 AXNode* CreateNode(AXNode* parent,
Dominic Mazzoni9ccdedb22021-01-30 17:59:42229 AXNodeID id,
Peter Kasting94a07a12019-05-22 19:26:28230 size_t index_in_parent,
dtseng5a7b3d92016-09-08 06:35:58231 AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03232
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08233 // 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 Zhanga06144782020-03-13 09:28:47237 AXTreeUpdateState* update_state);
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08238
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]4b02bbca2013-11-22 08:59:03247 // This is called from within Unserialize(), it returns true on success.
dmazzoni67b4db22016-04-23 00:40:04248 bool UpdateNode(const AXNodeData& src,
249 bool is_new_root,
250 AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03251
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08252 // 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 Feie3cce4c2019-11-14 18:35:41264 // 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 Ettenbergerd9d8d58a2019-08-06 16:54:08270 // destroyed.
Dominic Mazzoni9ccdedb22021-01-30 17:59:42271 void NotifyNodeHasBeenDeleted(AXNodeID node_id);
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08272
273 // Notify the delegate that |node| has been created or reparented.
274 void NotifyNodeHasBeenReparentedOrCreated(
275 AXNode* node,
276 const AXTreeUpdateState* update_state);
277
Adam Ettenberger05afcec2019-08-06 17:11:29278 // 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);
dmazzoni3ab5385c2017-03-13 18:07:03286
Dominic Mazzoni35f2a5252017-09-26 00:56:04287 void UpdateReverseRelations(AXNode* node, const AXNodeData& new_data);
288
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08289 // 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]4b02bbca2013-11-22 08:59:03294
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08295 // Modifies |update_state| so that it knows what subtree and nodes are
296 // going to be destroyed for the subtree rooted at |node|.
Dominic Mazzoni9ccdedb22021-01-30 17:59:42297 void MarkSubtreeForDestruction(AXNodeID node_id,
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08298 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 Mazzoni9ccdedb22021-01-30 17:59:42302 void MarkNodesForDestructionRecursive(AXNodeID node_id,
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08303 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.
dmazzonie3b7faf2015-06-01 17:56:36307 void DestroySubtree(AXNode* node, AXTreeUpdateState* update_state);
dmazzonia4b48912015-01-24 00:08:56308
[email protected]4b02bbca2013-11-22 08:59:03309 // Call Destroy() on |node|, and delete it from the id map, and then
310 // call recursively on all nodes in its subtree.
dmazzonie3b7faf2015-06-01 17:56:36311 void DestroyNodeAndSubtree(AXNode* node, AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03312
313 // Iterate over the children of |node| and for each child, destroy the
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08314 // child and its subtree if its id is not in |new_child_ids|.
315 void DeleteOldChildren(AXNode* node,
Nektarios Paisios527d33fb52021-02-23 19:23:28316 const std::vector<AXNodeID>& new_child_ids,
dmazzonie3b7faf2015-06-01 17:56:36317 AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03318
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]e736e81b2014-02-24 07:15:58323 // error. Returns true on success, false on fatal error.
[email protected]4b02bbca2013-11-22 08:59:03324 bool CreateNewChildVector(AXNode* node,
Nektarios Paisios527d33fb52021-02-23 19:23:28325 const std::vector<AXNodeID>& new_child_ids,
[email protected]d4e273462013-12-04 04:37:58326 std::vector<AXNode*>* new_children,
[email protected]e736e81b2014-02-24 07:15:58327 AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03328
Dominic Mazzonia1bb0d122019-09-26 20:19:59329 // 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 Mazzoni8549eb682018-12-11 23:48:32337 base::ObserverList<AXTreeObserver> observers_;
Brett Wilson0feae3a2017-12-06 03:16:56338 AXNode* root_ = nullptr;
Nektarios Paisios527d33fb52021-02-23 19:23:28339 std::unordered_map<AXNodeID, AXNode*> id_map_;
[email protected]d4e273462013-12-04 04:37:58340 std::string error_;
dmazzoni329fd012015-10-22 20:05:35341 AXTreeData data_;
Dominic Mazzoni35f2a5252017-09-26 00:56:04342
343 // Map from an int attribute (if IsNodeIdIntAttribute is true) to
344 // a reverse mapping from target nodes to source nodes.
David Tsengef6b480d2018-02-19 12:48:42345 IntReverseRelationMap int_reverse_relations_;
Dominic Mazzoni35f2a5252017-09-26 00:56:04346 // Map from an int list attribute (if IsNodeIdIntListAttribute is true) to
347 // a reverse mapping from target nodes to source nodes.
David Tsengef6b480d2018-02-19 12:48:42348 IntListReverseRelationMap intlist_reverse_relations_;
Dominic Mazzoniaa774822018-08-29 20:33:58349 // Map from child tree ID to the set of node IDs that contain that attribute.
Nektarios Paisios527d33fb52021-02-23 19:23:28350 std::map<AXTreeID, std::set<AXNodeID>> child_tree_id_reverse_map_;
Dominic Mazzoni3d9b5b92018-04-18 21:36:38351
352 // Map from node ID to cached table info, if the given node is a table.
Dominic Mazzonid42e00a2018-06-27 23:14:23353 // Invalidated every time the tree is updated.
Nektarios Paisios527d33fb52021-02-23 19:23:28354 mutable std::unordered_map<AXNodeID, std::unique_ptr<AXTableInfo>>
Aaron Leventhal80797182020-02-25 18:50:31355 table_info_map_;
Dominic Mazzonid42e00a2018-06-27 23:14:23356
357 // The next negative node ID to use for internal nodes.
Nektarios Paisios527d33fb52021-02-23 19:23:28358 AXNodeID next_negative_internal_node_id_ = -1;
Dominic Mazzonid42e00a2018-06-27 23:14:23359
Akihiro Ota413ca722018-12-03 23:29:00360 // Contains pos_in_set and set_size data for an AXNode.
Stephan Hartmannaeef6882020-04-20 18:21:43361 struct NodeSetSizePosInSetInfo {
362 NodeSetSizePosInSetInfo();
363 ~NodeSetSizePosInSetInfo();
364
Anton Bikineeveed0b26b2021-05-16 03:16:48365 absl::optional<int> pos_in_set;
366 absl::optional<int> set_size;
367 absl::optional<int> lowest_hierarchical_level;
Stephan Hartmannaeef6882020-04-20 18:21:43368 };
Akihiro Ota413ca722018-12-03 23:29:00369
Victor Fei5eea952e2020-02-28 01:43:09370 // 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 Feid95130c2020-02-03 21:42:54380 // |original_node| and within |ordered_set|. Only items whose roles match the
381 // role of the |ordered_set| will be added.
Victor Fei5eea952e2020-02-28 01:43:09382 void PopulateOrderedSetItemsMap(
Victor Feid95130c2020-02-03 21:42:54383 const AXNode& original_node,
384 const AXNode* ordered_set,
Lei Zhanga06144782020-03-13 09:28:47385 OrderedSetItemsMap* items_map_to_be_populated) const;
Victor Feid95130c2020-02-03 21:42:54386
Victor Fei5eea952e2020-02-28 01:43:09387 // Helper function for recursively populating ordered sets items map with
Victor Feid95130c2020-02-03 21:42:54388 // all items associated with |original_node| and |ordered_set|. |local_parent|
389 // tracks the recursively passed in child nodes of |ordered_set|.
Victor Fei5eea952e2020-02-28 01:43:09390 void RecursivelyPopulateOrderedSetItemsMap(
Victor Feid95130c2020-02-03 21:42:54391 const AXNode& original_node,
392 const AXNode* ordered_set,
393 const AXNode* local_parent,
Anton Bikineeveed0b26b2021-05-16 03:16:48394 absl::optional<int> ordered_set_min_level,
395 absl::optional<int> prev_level,
Lei Zhanga06144782020-03-13 09:28:47396 OrderedSetItemsMap* items_map_to_be_populated) const;
Akihiro Ota886a96d62018-12-18 00:11:48397
Victor Fei5eea952e2020-02-28 01:43:09398 // 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 Ota886a96d62018-12-18 00:11:48400 void ComputeSetSizePosInSetAndCache(const AXNode& node,
401 const AXNode* ordered_set);
Akihiro Ota413ca722018-12-03 23:29:00402
Victor Fei5eea952e2020-02-28 01:43:09403 // 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 Otab6a8a4d2018-12-04 01:56:39408 // 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 Ota413ca722018-12-03 23:29:00412 // Invalidated every time the tree is updated.
Nektarios Paisios527d33fb52021-02-23 19:23:28413 mutable std::unordered_map<AXNodeID, NodeSetSizePosInSetInfo>
Victor Fei5eea952e2020-02-28 01:43:09414 node_set_size_pos_in_set_info_map_;
Chris Hall9b34c2c2018-12-04 01:45:56415
Akihiro Otae3e420e2019-04-17 19:57:40416 // Indicates if the tree is updating.
417 bool tree_update_in_progress_ = false;
Kurt Catti-Schmidtc8445a12019-08-07 18:52:58418
419 // Indicates if the tree represents a paginated document
420 bool has_pagination_support_ = false;
David Tsengb0d43662020-05-20 20:47:28421
422 std::vector<AXEventIntent> event_intents_;
[email protected]4b02bbca2013-11-22 08:59:03423};
424
425} // namespace ui
426
427#endif // UI_ACCESSIBILITY_AX_TREE_H_