blob: f735327e0b8b69b9baf1808f15e488e3763f717a [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 =
69 std::map<ax::mojom::IntAttribute, std::map<int32_t, std::set<int32_t>>>;
70 using IntListReverseRelationMap =
71 std::map<ax::mojom::IntListAttribute,
72 std::map<int32_t, std::set<int32_t>>>;
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.
Dominic Mazzoniecfb4fd2018-10-23 07:34:20101 AXNode* GetFromId(int32_t 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.
Dominic Mazzonidcef1b732018-01-26 17:57:04135 std::set<int32_t> GetReverseRelations(ax::mojom::IntAttribute attr,
Dominic Mazzoni94a4da62017-12-22 22:49:38136 int32_t 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.
Dominic Mazzonidcef1b732018-01-26 17:57:04142 std::set<int32_t> GetReverseRelations(ax::mojom::IntListAttribute attr,
Dominic Mazzoni94a4da62017-12-22 22:49:38143 int32_t 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.
Dominic Mazzoni336bc0062018-09-23 16:46:43147 std::set<int32_t> 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 // Call this to enable support for extra Mac nodes - for each table,
170 // a table column header and a node for each column.
171 void SetEnableExtraMacNodes(bool enabled);
172 bool enable_extra_mac_nodes() const { return enable_extra_mac_nodes_; }
173
174 // Return a negative number that's suitable to use for a node ID for
175 // internal nodes created automatically by an AXTree, so as not to
176 // conflict with positive-numbered node IDs from tree sources.
177 int32_t GetNextNegativeInternalNodeId();
178
Akihiro Otaf42a7d02020-06-12 19:07:56179 // Returns the PosInSet of |node|. Looks in node_set_size_pos_in_set_info_map_
180 // for cached value. Calls |ComputeSetSizePosInSetAndCache|if no value is
181 // present in the cache.
182 base::Optional<int> GetPosInSet(const AXNode& node) override;
183 // Returns the SetSize of |node|. Looks in node_set_size_pos_in_set_info_map_
184 // for cached value. Calls |ComputeSetSizePosInSetAndCache|if no value is
185 // present in the cache.
186 base::Optional<int> GetSetSize(const AXNode& node) override;
Akihiro Ota413ca722018-12-03 23:29:00187
Jacques Newman339afc62019-08-14 00:49:22188 Selection GetUnignoredSelection() const override;
189
Akihiro Otae3e420e2019-04-17 19:57:40190 bool GetTreeUpdateInProgressState() const override;
191 void SetTreeUpdateInProgressState(bool set_tree_update_value);
192
Kurt Catti-Schmidtc8445a12019-08-07 18:52:58193 // AXNode::OwnerTree override.
194 // Returns true if the tree represents a paginated document
195 bool HasPaginationSupport() const override;
196
Chris Hall697d99b2019-07-09 02:36:11197 // Language detection manager, entry point to language detection features.
198 // TODO(chrishall): Should this be stored by pointer or value?
199 // When should we initialize this?
200 std::unique_ptr<AXLanguageDetectionManager> language_detection_manager;
Chris Hall34208182019-03-13 02:26:18201
David Tsengb0d43662020-05-20 20:47:28202 // A list of intents active during a tree update/unserialization.
203 const std::vector<AXEventIntent>& event_intents() const {
204 return event_intents_;
205 }
206
Benjamin Beaudrye8f23a22020-12-17 20:08:02207 // Notify the delegate that the tree manager for |previous_tree_id| will be
208 // removed from the AXTreeManagerMap. Because we sometimes remove the tree
209 // manager after the tree's id has been modified, we need to pass the (old)
210 // tree id associated with the manager we are removing even though it is the
211 // same tree.
212 void NotifyTreeManagerWillBeRemoved(AXTreeID previous_tree_id);
213
[email protected]e736e81b2014-02-24 07:15:58214 private:
Dominic Mazzoniecfb4fd2018-10-23 07:34:20215 friend class AXTableInfoTest;
216
Aaron Leventhala674d632020-09-30 07:05:36217 // Accumulate errors as there can be more than one before Chrome is crashed
218 // via AccessibilityFatalError();
219 void RecordError(std::string new_error);
220
Dominic Mazzoniecfb4fd2018-10-23 07:34:20221 // AXNode::OwnerTree override.
222 //
223 // Given a node in this accessibility tree that corresponds to a table
224 // or grid, return an object containing information about the
225 // table structure. This object is computed lazily on-demand and
226 // cached until the next time the tree is updated. Clients should
227 // not retain this pointer, they should just request it every time
228 // it's needed.
229 //
230 // Returns nullptr if the node is not a valid table.
231 AXTableInfo* GetTableInfo(const AXNode* table_node) const override;
232
dtseng5a7b3d92016-09-08 06:35:58233 AXNode* CreateNode(AXNode* parent,
Dominic Mazzoni9ccdedb22021-01-30 17:59:42234 AXNodeID id,
Peter Kasting94a07a12019-05-22 19:26:28235 size_t index_in_parent,
dtseng5a7b3d92016-09-08 06:35:58236 AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03237
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08238 // Accumulates the work that will be required to update the AXTree.
239 // This allows us to notify observers of structure changes when the
240 // tree is still in a stable and unchanged state.
241 bool ComputePendingChanges(const AXTreeUpdate& update,
Lei Zhanga06144782020-03-13 09:28:47242 AXTreeUpdateState* update_state);
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08243
244 // Populates |update_state| with information about actions that will
245 // be performed on the tree during the update, such as adding or
246 // removing nodes in the tree. Returns true on success.
247 // Nothing within this call should modify tree structure or node data.
248 bool ComputePendingChangesToNode(const AXNodeData& new_data,
249 bool is_new_root,
250 AXTreeUpdateState* update_state);
251
[email protected]4b02bbca2013-11-22 08:59:03252 // This is called from within Unserialize(), it returns true on success.
dmazzoni67b4db22016-04-23 00:40:04253 bool UpdateNode(const AXNodeData& src,
254 bool is_new_root,
255 AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03256
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08257 // Notify the delegate that the subtree rooted at |node| will be
258 // destroyed or reparented.
259 void NotifySubtreeWillBeReparentedOrDeleted(
260 AXNode* node,
261 const AXTreeUpdateState* update_state);
262
263 // Notify the delegate that |node| will be destroyed or reparented.
264 void NotifyNodeWillBeReparentedOrDeleted(
265 AXNode* node,
266 const AXTreeUpdateState* update_state);
267
268 // Notify the delegate that |node| and all of its descendants will be
Victor Feie3cce4c2019-11-14 18:35:41269 // destroyed. This function is called during AXTree teardown.
270 void RecursivelyNotifyNodeDeletedForTreeTeardown(AXNode* node);
271
272 // Notify the delegate that the node marked by |node_id| has been deleted.
273 // We are passing the node id instead of ax node is because by the time this
274 // function is called, the ax node in the tree will already have been
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08275 // destroyed.
Dominic Mazzoni9ccdedb22021-01-30 17:59:42276 void NotifyNodeHasBeenDeleted(AXNodeID node_id);
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08277
278 // Notify the delegate that |node| has been created or reparented.
279 void NotifyNodeHasBeenReparentedOrCreated(
280 AXNode* node,
281 const AXTreeUpdateState* update_state);
282
Adam Ettenberger05afcec2019-08-06 17:11:29283 // Notify the delegate that a node will change its data.
284 void NotifyNodeDataWillChange(const AXNodeData& old_data,
285 const AXNodeData& new_data);
286
287 // Notify the delegate that |node| has changed its data.
288 void NotifyNodeDataHasBeenChanged(AXNode* node,
289 const AXNodeData& old_data,
290 const AXNodeData& new_data);
dmazzoni3ab5385c2017-03-13 18:07:03291
Dominic Mazzoni35f2a5252017-09-26 00:56:04292 void UpdateReverseRelations(AXNode* node, const AXNodeData& new_data);
293
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08294 // Returns true if all pending changes in the |update_state| have been
295 // handled. If this returns false, the |error_| message will be populated.
296 // It's a fatal error to have pending changes after exhausting
297 // the AXTreeUpdate.
298 bool ValidatePendingChangesComplete(const AXTreeUpdateState& update_state);
[email protected]4b02bbca2013-11-22 08:59:03299
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08300 // Modifies |update_state| so that it knows what subtree and nodes are
301 // going to be destroyed for the subtree rooted at |node|.
Dominic Mazzoni9ccdedb22021-01-30 17:59:42302 void MarkSubtreeForDestruction(AXNodeID node_id,
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08303 AXTreeUpdateState* update_state);
304
305 // Modifies |update_state| so that it knows what nodes are
306 // going to be destroyed for the subtree rooted at |node|.
Dominic Mazzoni9ccdedb22021-01-30 17:59:42307 void MarkNodesForDestructionRecursive(AXNodeID node_id,
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08308 AXTreeUpdateState* update_state);
309
310 // Validates that destroying the subtree rooted at |node| has required
311 // information in |update_state|, then calls DestroyNodeAndSubtree on it.
dmazzonie3b7faf2015-06-01 17:56:36312 void DestroySubtree(AXNode* node, AXTreeUpdateState* update_state);
dmazzonia4b48912015-01-24 00:08:56313
[email protected]4b02bbca2013-11-22 08:59:03314 // Call Destroy() on |node|, and delete it from the id map, and then
315 // call recursively on all nodes in its subtree.
dmazzonie3b7faf2015-06-01 17:56:36316 void DestroyNodeAndSubtree(AXNode* node, AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03317
318 // Iterate over the children of |node| and for each child, destroy the
Adam Ettenbergerd9d8d58a2019-08-06 16:54:08319 // child and its subtree if its id is not in |new_child_ids|.
320 void DeleteOldChildren(AXNode* node,
avi9c81217b2015-12-24 23:40:05321 const std::vector<int32_t>& new_child_ids,
dmazzonie3b7faf2015-06-01 17:56:36322 AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03323
324 // Iterate over |new_child_ids| and populate |new_children| with
325 // pointers to child nodes, reusing existing nodes already in the tree
326 // if they exist, and creating otherwise. Reparenting is disallowed, so
327 // if the id already exists as the child of another node, that's an
[email protected]e736e81b2014-02-24 07:15:58328 // error. Returns true on success, false on fatal error.
[email protected]4b02bbca2013-11-22 08:59:03329 bool CreateNewChildVector(AXNode* node,
avi9c81217b2015-12-24 23:40:05330 const std::vector<int32_t>& new_child_ids,
[email protected]d4e273462013-12-04 04:37:58331 std::vector<AXNode*>* new_children,
[email protected]e736e81b2014-02-24 07:15:58332 AXTreeUpdateState* update_state);
[email protected]4b02bbca2013-11-22 08:59:03333
Dominic Mazzonia1bb0d122019-09-26 20:19:59334 // Internal implementation of RelativeToTreeBounds. It calls itself
335 // recursively but ensures that it can only do so exactly once!
336 gfx::RectF RelativeToTreeBoundsInternal(const AXNode* node,
337 gfx::RectF node_bounds,
338 bool* offscreen,
339 bool clip_bounds,
340 bool allow_recursion) const;
341
Dominic Mazzoni8549eb682018-12-11 23:48:32342 base::ObserverList<AXTreeObserver> observers_;
Brett Wilson0feae3a2017-12-06 03:16:56343 AXNode* root_ = nullptr;
Takuto Ikutaadf31eb2019-01-05 00:32:48344 std::unordered_map<int32_t, AXNode*> id_map_;
[email protected]d4e273462013-12-04 04:37:58345 std::string error_;
dmazzoni329fd012015-10-22 20:05:35346 AXTreeData data_;
Dominic Mazzoni35f2a5252017-09-26 00:56:04347
348 // Map from an int attribute (if IsNodeIdIntAttribute is true) to
349 // a reverse mapping from target nodes to source nodes.
David Tsengef6b480d2018-02-19 12:48:42350 IntReverseRelationMap int_reverse_relations_;
Dominic Mazzoni35f2a5252017-09-26 00:56:04351 // Map from an int list attribute (if IsNodeIdIntListAttribute is true) to
352 // a reverse mapping from target nodes to source nodes.
David Tsengef6b480d2018-02-19 12:48:42353 IntListReverseRelationMap intlist_reverse_relations_;
Dominic Mazzoniaa774822018-08-29 20:33:58354 // Map from child tree ID to the set of node IDs that contain that attribute.
Dominic Mazzoni336bc0062018-09-23 16:46:43355 std::map<AXTreeID, std::set<int32_t>> child_tree_id_reverse_map_;
Dominic Mazzoni3d9b5b92018-04-18 21:36:38356
357 // Map from node ID to cached table info, if the given node is a table.
Dominic Mazzonid42e00a2018-06-27 23:14:23358 // Invalidated every time the tree is updated.
Aaron Leventhal80797182020-02-25 18:50:31359 mutable std::unordered_map<int32_t, std::unique_ptr<AXTableInfo>>
360 table_info_map_;
Dominic Mazzonid42e00a2018-06-27 23:14:23361
362 // The next negative node ID to use for internal nodes.
363 int32_t next_negative_internal_node_id_ = -1;
364
365 // Whether we should create extra nodes that
366 // are only useful on macOS. Implemented using this flag to allow
367 // this code to be unit-tested on other platforms (for example, more
368 // code sanitizers run on Linux).
369 bool enable_extra_mac_nodes_ = false;
Akihiro Ota413ca722018-12-03 23:29:00370
371 // Contains pos_in_set and set_size data for an AXNode.
Stephan Hartmannaeef6882020-04-20 18:21:43372 struct NodeSetSizePosInSetInfo {
373 NodeSetSizePosInSetInfo();
374 ~NodeSetSizePosInSetInfo();
375
Akihiro Otaf42a7d02020-06-12 19:07:56376 base::Optional<int> pos_in_set;
377 base::Optional<int> set_size;
Stephan Hartmannaeef6882020-04-20 18:21:43378 base::Optional<int> lowest_hierarchical_level;
379 };
Akihiro Ota413ca722018-12-03 23:29:00380
Victor Fei5eea952e2020-02-28 01:43:09381 // Represents the content of an ordered set which includes the ordered set
382 // items and the ordered set container if it exists.
383 struct OrderedSetContent;
384
385 // Maps a particular hierarchical level to a list of OrderedSetContents.
386 // Represents all ordered set items/container on a particular hierarchical
387 // level.
388 struct OrderedSetItemsMap;
389
390 // Populates |items_map_to_be_populated| with all items associated with
Victor Feid95130c2020-02-03 21:42:54391 // |original_node| and within |ordered_set|. Only items whose roles match the
392 // role of the |ordered_set| will be added.
Victor Fei5eea952e2020-02-28 01:43:09393 void PopulateOrderedSetItemsMap(
Victor Feid95130c2020-02-03 21:42:54394 const AXNode& original_node,
395 const AXNode* ordered_set,
Lei Zhanga06144782020-03-13 09:28:47396 OrderedSetItemsMap* items_map_to_be_populated) const;
Victor Feid95130c2020-02-03 21:42:54397
Victor Fei5eea952e2020-02-28 01:43:09398 // Helper function for recursively populating ordered sets items map with
Victor Feid95130c2020-02-03 21:42:54399 // all items associated with |original_node| and |ordered_set|. |local_parent|
400 // tracks the recursively passed in child nodes of |ordered_set|.
Victor Fei5eea952e2020-02-28 01:43:09401 void RecursivelyPopulateOrderedSetItemsMap(
Victor Feid95130c2020-02-03 21:42:54402 const AXNode& original_node,
403 const AXNode* ordered_set,
404 const AXNode* local_parent,
Victor Fei5eea952e2020-02-28 01:43:09405 base::Optional<int> ordered_set_min_level,
406 base::Optional<int> prev_level,
Lei Zhanga06144782020-03-13 09:28:47407 OrderedSetItemsMap* items_map_to_be_populated) const;
Akihiro Ota886a96d62018-12-18 00:11:48408
Victor Fei5eea952e2020-02-28 01:43:09409 // Computes the pos_in_set and set_size values of all items in ordered_set and
410 // caches those values. Called by GetPosInSet and GetSetSize.
Akihiro Ota886a96d62018-12-18 00:11:48411 void ComputeSetSizePosInSetAndCache(const AXNode& node,
412 const AXNode* ordered_set);
Akihiro Ota413ca722018-12-03 23:29:00413
Victor Fei5eea952e2020-02-28 01:43:09414 // Helper for ComputeSetSizePosInSetAndCache. Computes and caches the
415 // pos_in_set and set_size values for a given OrderedSetContent.
416 void ComputeSetSizePosInSetAndCacheHelper(
417 const OrderedSetContent& ordered_set_content);
418
Akihiro Otab6a8a4d2018-12-04 01:56:39419 // Map from node ID to OrderedSetInfo.
420 // Item-like and ordered-set-like objects will map to populated OrderedSetInfo
421 // objects.
422 // All other objects will map to default-constructed OrderedSetInfo objects.
Akihiro Ota413ca722018-12-03 23:29:00423 // Invalidated every time the tree is updated.
Victor Fei5eea952e2020-02-28 01:43:09424 mutable std::unordered_map<int32_t, NodeSetSizePosInSetInfo>
425 node_set_size_pos_in_set_info_map_;
Chris Hall9b34c2c2018-12-04 01:45:56426
Akihiro Otae3e420e2019-04-17 19:57:40427 // Indicates if the tree is updating.
428 bool tree_update_in_progress_ = false;
Kurt Catti-Schmidtc8445a12019-08-07 18:52:58429
430 // Indicates if the tree represents a paginated document
431 bool has_pagination_support_ = false;
David Tsengb0d43662020-05-20 20:47:28432
433 std::vector<AXEventIntent> event_intents_;
[email protected]4b02bbca2013-11-22 08:59:03434};
435
436} // namespace ui
437
438#endif // UI_ACCESSIBILITY_AX_TREE_H_