[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef UI_ACCESSIBILITY_AX_TREE_H_ |
| 6 | #define UI_ACCESSIBILITY_AX_TREE_H_ |
| 7 | |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Chris Hall | 3420818 | 2019-03-13 02:26:18 | [diff] [blame] | 10 | #include <memory> |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 11 | #include <set> |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 12 | #include <unordered_map> |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 13 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 14 | #include "base/observer_list.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 15 | #include "ui/accessibility/ax_export.h" |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 16 | #include "ui/accessibility/ax_node.h" |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 17 | #include "ui/accessibility/ax_node_data.h" |
| 18 | #include "ui/accessibility/ax_tree_data.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 19 | #include "ui/accessibility/ax_tree_update.h" |
| 20 | |
| 21 | namespace ui { |
| 22 | |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 23 | class AXTableInfo; |
dmazzoni | 09e7591 | 2015-06-02 23:31:56 | [diff] [blame] | 24 | class AXTree; |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 25 | class AXTreeObserver; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 26 | struct AXTreeUpdateState; |
Chris Hall | 697d99b | 2019-07-09 02:36:11 | [diff] [blame] | 27 | class AXLanguageDetectionManager; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 28 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 29 | // AXTree is a live, managed tree of AXNode objects that can receive |
| 30 | // updates from another AXTreeSource via AXTreeUpdates, and it can be |
| 31 | // used as a source for sending updates to another client tree. |
| 32 | // It's designed to be subclassed to implement support for native |
| 33 | // accessibility APIs on a specific platform. |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 34 | class AX_EXPORT AXTree : public AXNode::OwnerTree { |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 35 | public: |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 36 | typedef std::map<ax::mojom::IntAttribute, |
| 37 | std::map<int32_t, std::set<int32_t>>> |
| 38 | IntReverseRelationMap; |
| 39 | typedef std::map<ax::mojom::IntListAttribute, |
| 40 | std::map<int32_t, std::set<int32_t>>> |
| 41 | IntListReverseRelationMap; |
| 42 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 43 | AXTree(); |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 44 | explicit AXTree(const AXTreeUpdate& initial_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 45 | virtual ~AXTree(); |
| 46 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 47 | void AddObserver(AXTreeObserver* observer); |
| 48 | bool HasObserver(AXTreeObserver* observer); |
| 49 | void RemoveObserver(const AXTreeObserver* observer); |
| 50 | |
| 51 | base::ObserverList<AXTreeObserver>& observers() { return observers_; } |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 52 | |
tfarina | 6b1c1e08 | 2015-02-20 23:47:07 | [diff] [blame] | 53 | AXNode* root() const { return root_; } |
| 54 | |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 55 | const AXTreeData& data() const { return data_; } |
| 56 | |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 57 | // AXNode::OwnerTree override. |
tfarina | 6b1c1e08 | 2015-02-20 23:47:07 | [diff] [blame] | 58 | // Returns the AXNode with the given |id| if it is part of this AXTree. |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 59 | AXNode* GetFromId(int32_t id) const override; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 60 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 61 | // Returns true on success. If it returns false, it's a fatal error |
| 62 | // and this tree should be destroyed, and the source of the tree update |
| 63 | // should not be trusted any longer. |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 64 | virtual bool Unserialize(const AXTreeUpdate& update); |
| 65 | |
| 66 | virtual void UpdateData(const AXTreeData& data); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 67 | |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 68 | // Convert any rectangle from the local coordinate space of one node in |
| 69 | // the tree, to bounds in the coordinate space of the tree. |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 70 | // If set, updates |offscreen| boolean to be true if the node is offscreen |
| 71 | // relative to its rootWebArea. Callers should initialize |offscreen| |
| 72 | // to false: this method may get called multiple times in a row and |
| 73 | // |offscreen| will be propagated. |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 74 | // If |clip_bounds| is true, result bounds will be clipped. |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 75 | gfx::RectF RelativeToTreeBounds(const AXNode* node, |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 76 | gfx::RectF node_bounds, |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 77 | bool* offscreen = nullptr, |
| 78 | bool clip_bounds = true) const; |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 79 | |
| 80 | // Get the bounds of a node in the coordinate space of the tree. |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 81 | // If set, updates |offscreen| boolean to be true if the node is offscreen |
| 82 | // relative to its rootWebArea. Callers should initialize |offscreen| |
| 83 | // to false: this method may get called multiple times in a row and |
| 84 | // |offscreen| will be propagated. |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 85 | // If |clip_bounds| is true, result bounds will be clipped. |
| 86 | gfx::RectF GetTreeBounds(const AXNode* node, |
| 87 | bool* offscreen = nullptr, |
| 88 | bool clip_bounds = true) const; |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 89 | |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 90 | // Given a node ID attribute (one where IsNodeIdIntAttribute is true), |
| 91 | // and a destination node ID, return a set of all source node IDs that |
| 92 | // have that relationship attribute between them and the destination. |
Dominic Mazzoni | dcef1b73 | 2018-01-26 17:57:04 | [diff] [blame] | 93 | std::set<int32_t> GetReverseRelations(ax::mojom::IntAttribute attr, |
Dominic Mazzoni | 94a4da6 | 2017-12-22 22:49:38 | [diff] [blame] | 94 | int32_t dst_id) const; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 95 | |
| 96 | // Given a node ID list attribute (one where |
| 97 | // IsNodeIdIntListAttribute is true), and a destination node ID, |
| 98 | // return a set of all source node IDs that have that relationship |
| 99 | // attribute between them and the destination. |
Dominic Mazzoni | dcef1b73 | 2018-01-26 17:57:04 | [diff] [blame] | 100 | std::set<int32_t> GetReverseRelations(ax::mojom::IntListAttribute attr, |
Dominic Mazzoni | 94a4da6 | 2017-12-22 22:49:38 | [diff] [blame] | 101 | int32_t dst_id) const; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 102 | |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 103 | // Given a child tree ID, return the node IDs of all nodes in the tree who |
| 104 | // have a kChildTreeId int attribute with that value. |
Dominic Mazzoni | 336bc006 | 2018-09-23 16:46:43 | [diff] [blame] | 105 | std::set<int32_t> GetNodeIdsForChildTreeId(AXTreeID child_tree_id) const; |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 106 | |
Dominic Mazzoni | 748888c | 2018-11-01 22:34:59 | [diff] [blame] | 107 | // Get all of the child tree IDs referenced by any node in this tree. |
| 108 | const std::set<AXTreeID> GetAllChildTreeIds() const; |
| 109 | |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 110 | // Map from a relation attribute to a map from a target id to source ids. |
| 111 | const IntReverseRelationMap& int_reverse_relations() { |
| 112 | return int_reverse_relations_; |
| 113 | } |
| 114 | const IntListReverseRelationMap& intlist_reverse_relations() { |
| 115 | return intlist_reverse_relations_; |
| 116 | } |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 117 | |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 118 | // Return a multi-line indented string representation, for logging. |
| 119 | std::string ToString() const; |
| 120 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 121 | // A string describing the error from an unsuccessful Unserialize, |
| 122 | // for testing and debugging. |
tfarina | d0bfb4b6 | 2015-02-18 17:20:32 | [diff] [blame] | 123 | const std::string& error() const { return error_; } |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 124 | |
dmazzoni | ee2eaca | 2015-03-18 18:13:07 | [diff] [blame] | 125 | int size() { return static_cast<int>(id_map_.size()); } |
| 126 | |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 127 | // Call this to enable support for extra Mac nodes - for each table, |
| 128 | // a table column header and a node for each column. |
| 129 | void SetEnableExtraMacNodes(bool enabled); |
| 130 | bool enable_extra_mac_nodes() const { return enable_extra_mac_nodes_; } |
| 131 | |
| 132 | // Return a negative number that's suitable to use for a node ID for |
| 133 | // internal nodes created automatically by an AXTree, so as not to |
| 134 | // conflict with positive-numbered node IDs from tree sources. |
| 135 | int32_t GetNextNegativeInternalNodeId(); |
| 136 | |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 137 | // Returns the pos_in_set of node. Looks in ordered_set_info_map_ for cached |
| 138 | // value. Calculates pos_in_set and set_size for node (and all other nodes in |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 139 | // the same ordered set) if no value is present in the cache. |
| 140 | // This function is guaranteed to be only called on nodes that can hold |
| 141 | // pos_in_set values, minimizing the size of the cache. |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 142 | int32_t GetPosInSet(const AXNode& node, const AXNode* ordered_set) override; |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 143 | // Returns the set_size of node. Looks in ordered_set_info_map_ for cached |
| 144 | // value. Calculates pos_inset_set and set_size for node (and all other nodes |
| 145 | // in the same ordered set) if no value is present in the cache. |
| 146 | // This function is guaranteed to be only called on nodes that can hold |
| 147 | // set_size values, minimizing the size of the cache. |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 148 | int32_t GetSetSize(const AXNode& node, const AXNode* ordered_set) override; |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 149 | |
Jacques Newman | 339afc6 | 2019-08-14 00:49:22 | [diff] [blame^] | 150 | Selection GetUnignoredSelection() const override; |
| 151 | |
Akihiro Ota | e3e420e | 2019-04-17 19:57:40 | [diff] [blame] | 152 | bool GetTreeUpdateInProgressState() const override; |
| 153 | void SetTreeUpdateInProgressState(bool set_tree_update_value); |
| 154 | |
Kurt Catti-Schmidt | c8445a1 | 2019-08-07 18:52:58 | [diff] [blame] | 155 | // AXNode::OwnerTree override. |
| 156 | // Returns true if the tree represents a paginated document |
| 157 | bool HasPaginationSupport() const override; |
| 158 | |
Chris Hall | 697d99b | 2019-07-09 02:36:11 | [diff] [blame] | 159 | // Language detection manager, entry point to language detection features. |
| 160 | // TODO(chrishall): Should this be stored by pointer or value? |
| 161 | // When should we initialize this? |
| 162 | std::unique_ptr<AXLanguageDetectionManager> language_detection_manager; |
Chris Hall | 3420818 | 2019-03-13 02:26:18 | [diff] [blame] | 163 | |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 164 | private: |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 165 | friend class AXTableInfoTest; |
| 166 | |
| 167 | // AXNode::OwnerTree override. |
| 168 | // |
| 169 | // Given a node in this accessibility tree that corresponds to a table |
| 170 | // or grid, return an object containing information about the |
| 171 | // table structure. This object is computed lazily on-demand and |
| 172 | // cached until the next time the tree is updated. Clients should |
| 173 | // not retain this pointer, they should just request it every time |
| 174 | // it's needed. |
| 175 | // |
| 176 | // Returns nullptr if the node is not a valid table. |
| 177 | AXTableInfo* GetTableInfo(const AXNode* table_node) const override; |
| 178 | |
dtseng | 5a7b3d9 | 2016-09-08 06:35:58 | [diff] [blame] | 179 | AXNode* CreateNode(AXNode* parent, |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 180 | AXNode::AXID id, |
Peter Kasting | 94a07a1 | 2019-05-22 19:26:28 | [diff] [blame] | 181 | size_t index_in_parent, |
dtseng | 5a7b3d9 | 2016-09-08 06:35:58 | [diff] [blame] | 182 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 183 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 184 | // Accumulates the work that will be required to update the AXTree. |
| 185 | // This allows us to notify observers of structure changes when the |
| 186 | // tree is still in a stable and unchanged state. |
| 187 | bool ComputePendingChanges(const AXTreeUpdate& update, |
| 188 | AXTreeUpdateState& update_state); |
| 189 | |
| 190 | // Populates |update_state| with information about actions that will |
| 191 | // be performed on the tree during the update, such as adding or |
| 192 | // removing nodes in the tree. Returns true on success. |
| 193 | // Nothing within this call should modify tree structure or node data. |
| 194 | bool ComputePendingChangesToNode(const AXNodeData& new_data, |
| 195 | bool is_new_root, |
| 196 | AXTreeUpdateState* update_state); |
| 197 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 198 | // This is called from within Unserialize(), it returns true on success. |
dmazzoni | 67b4db2 | 2016-04-23 00:40:04 | [diff] [blame] | 199 | bool UpdateNode(const AXNodeData& src, |
| 200 | bool is_new_root, |
| 201 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 202 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 203 | // Notify the delegate that the subtree rooted at |node| will be |
| 204 | // destroyed or reparented. |
| 205 | void NotifySubtreeWillBeReparentedOrDeleted( |
| 206 | AXNode* node, |
| 207 | const AXTreeUpdateState* update_state); |
| 208 | |
| 209 | // Notify the delegate that |node| will be destroyed or reparented. |
| 210 | void NotifyNodeWillBeReparentedOrDeleted( |
| 211 | AXNode* node, |
| 212 | const AXTreeUpdateState* update_state); |
| 213 | |
| 214 | // Notify the delegate that |node| and all of its descendants will be |
| 215 | // destroyed. |
| 216 | void RecursivelyNotifyNodeWillBeDeleted(AXNode* node); |
| 217 | |
| 218 | // Notify the delegate that |node| has been created or reparented. |
| 219 | void NotifyNodeHasBeenReparentedOrCreated( |
| 220 | AXNode* node, |
| 221 | const AXTreeUpdateState* update_state); |
| 222 | |
Adam Ettenberger | 05afcec | 2019-08-06 17:11:29 | [diff] [blame] | 223 | // Notify the delegate that a node will change its data. |
| 224 | void NotifyNodeDataWillChange(const AXNodeData& old_data, |
| 225 | const AXNodeData& new_data); |
| 226 | |
| 227 | // Notify the delegate that |node| has changed its data. |
| 228 | void NotifyNodeDataHasBeenChanged(AXNode* node, |
| 229 | const AXNodeData& old_data, |
| 230 | const AXNodeData& new_data); |
dmazzoni | 3ab5385c | 2017-03-13 18:07:03 | [diff] [blame] | 231 | |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 232 | void UpdateReverseRelations(AXNode* node, const AXNodeData& new_data); |
| 233 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 234 | // Returns true if all pending changes in the |update_state| have been |
| 235 | // handled. If this returns false, the |error_| message will be populated. |
| 236 | // It's a fatal error to have pending changes after exhausting |
| 237 | // the AXTreeUpdate. |
| 238 | bool ValidatePendingChangesComplete(const AXTreeUpdateState& update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 239 | |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 240 | // Modifies |update_state| so that it knows what subtree and nodes are |
| 241 | // going to be destroyed for the subtree rooted at |node|. |
| 242 | void MarkSubtreeForDestruction(AXNode::AXID node_id, |
| 243 | AXTreeUpdateState* update_state); |
| 244 | |
| 245 | // Modifies |update_state| so that it knows what nodes are |
| 246 | // going to be destroyed for the subtree rooted at |node|. |
| 247 | void MarkNodesForDestructionRecursive(AXNode::AXID node_id, |
| 248 | AXTreeUpdateState* update_state); |
| 249 | |
| 250 | // Validates that destroying the subtree rooted at |node| has required |
| 251 | // information in |update_state|, then calls DestroyNodeAndSubtree on it. |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 252 | void DestroySubtree(AXNode* node, AXTreeUpdateState* update_state); |
dmazzoni | a4b4891 | 2015-01-24 00:08:56 | [diff] [blame] | 253 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 254 | // Call Destroy() on |node|, and delete it from the id map, and then |
| 255 | // call recursively on all nodes in its subtree. |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 256 | void DestroyNodeAndSubtree(AXNode* node, AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 257 | |
| 258 | // Iterate over the children of |node| and for each child, destroy the |
Adam Ettenberger | d9d8d58a | 2019-08-06 16:54:08 | [diff] [blame] | 259 | // child and its subtree if its id is not in |new_child_ids|. |
| 260 | void DeleteOldChildren(AXNode* node, |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 261 | const std::vector<int32_t>& new_child_ids, |
dmazzoni | e3b7faf | 2015-06-01 17:56:36 | [diff] [blame] | 262 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 263 | |
| 264 | // Iterate over |new_child_ids| and populate |new_children| with |
| 265 | // pointers to child nodes, reusing existing nodes already in the tree |
| 266 | // if they exist, and creating otherwise. Reparenting is disallowed, so |
| 267 | // 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] | 268 | // error. Returns true on success, false on fatal error. |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 269 | bool CreateNewChildVector(AXNode* node, |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 270 | const std::vector<int32_t>& new_child_ids, |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 271 | std::vector<AXNode*>* new_children, |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 272 | AXTreeUpdateState* update_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 273 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 274 | base::ObserverList<AXTreeObserver> observers_; |
Brett Wilson | 0feae3a | 2017-12-06 03:16:56 | [diff] [blame] | 275 | AXNode* root_ = nullptr; |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 276 | std::unordered_map<int32_t, AXNode*> id_map_; |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 277 | std::string error_; |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 278 | AXTreeData data_; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 279 | |
| 280 | // Map from an int attribute (if IsNodeIdIntAttribute is true) to |
| 281 | // a reverse mapping from target nodes to source nodes. |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 282 | IntReverseRelationMap int_reverse_relations_; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 283 | // Map from an int list attribute (if IsNodeIdIntListAttribute is true) to |
| 284 | // a reverse mapping from target nodes to source nodes. |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 285 | IntListReverseRelationMap intlist_reverse_relations_; |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 286 | // Map from child tree ID to the set of node IDs that contain that attribute. |
Dominic Mazzoni | 336bc006 | 2018-09-23 16:46:43 | [diff] [blame] | 287 | std::map<AXTreeID, std::set<int32_t>> child_tree_id_reverse_map_; |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 288 | |
| 289 | // 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] | 290 | // Invalidated every time the tree is updated. |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 291 | mutable std::unordered_map<int32_t, AXTableInfo*> table_info_map_; |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 292 | |
| 293 | // The next negative node ID to use for internal nodes. |
| 294 | int32_t next_negative_internal_node_id_ = -1; |
| 295 | |
| 296 | // Whether we should create extra nodes that |
| 297 | // are only useful on macOS. Implemented using this flag to allow |
| 298 | // this code to be unit-tested on other platforms (for example, more |
| 299 | // code sanitizers run on Linux). |
| 300 | bool enable_extra_mac_nodes_ = false; |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 301 | |
| 302 | // Contains pos_in_set and set_size data for an AXNode. |
| 303 | struct OrderedSetInfo { |
| 304 | int32_t pos_in_set; |
| 305 | int32_t set_size; |
Alice Boxhall | c8ffa6c | 2019-04-09 02:39:44 | [diff] [blame] | 306 | int32_t lowest_hierarchical_level; |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 307 | OrderedSetInfo() : pos_in_set(0), set_size(0) {} |
| 308 | ~OrderedSetInfo() {} |
| 309 | }; |
| 310 | |
Akihiro Ota | b6a8a4d | 2018-12-04 01:56:39 | [diff] [blame] | 311 | // Populates items vector with all items within ordered_set. |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 312 | // Will only add items whose roles match the role of the |
| 313 | // ordered_set. |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 314 | void PopulateOrderedSetItems(const AXNode* ordered_set, |
| 315 | const AXNode* local_parent, |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 316 | std::vector<const AXNode*>& items, |
Akihiro Ota | d659eded | 2019-02-20 21:44:32 | [diff] [blame] | 317 | const AXNode& original_node) const; |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 318 | |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 319 | // Helper for GetPosInSet and GetSetSize. Computes the pos_in_set and set_size |
| 320 | // values of all items in ordered_set and caches those values. |
Akihiro Ota | 886a96d6 | 2018-12-18 00:11:48 | [diff] [blame] | 321 | void ComputeSetSizePosInSetAndCache(const AXNode& node, |
| 322 | const AXNode* ordered_set); |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 323 | |
Akihiro Ota | b6a8a4d | 2018-12-04 01:56:39 | [diff] [blame] | 324 | // Map from node ID to OrderedSetInfo. |
| 325 | // Item-like and ordered-set-like objects will map to populated OrderedSetInfo |
| 326 | // objects. |
| 327 | // All other objects will map to default-constructed OrderedSetInfo objects. |
Akihiro Ota | 413ca72 | 2018-12-03 23:29:00 | [diff] [blame] | 328 | // Invalidated every time the tree is updated. |
| 329 | mutable std::unordered_map<int32_t, OrderedSetInfo> ordered_set_info_map_; |
Chris Hall | 9b34c2c | 2018-12-04 01:45:56 | [diff] [blame] | 330 | |
| 331 | // AXTree owns pointers so copying is non-trivial. |
| 332 | DISALLOW_COPY_AND_ASSIGN(AXTree); |
Akihiro Ota | e3e420e | 2019-04-17 19:57:40 | [diff] [blame] | 333 | |
| 334 | // Indicates if the tree is updating. |
| 335 | bool tree_update_in_progress_ = false; |
Kurt Catti-Schmidt | c8445a1 | 2019-08-07 18:52:58 | [diff] [blame] | 336 | |
| 337 | // Indicates if the tree represents a paginated document |
| 338 | bool has_pagination_support_ = false; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 339 | }; |
| 340 | |
| 341 | } // namespace ui |
| 342 | |
| 343 | #endif // UI_ACCESSIBILITY_AX_TREE_H_ |