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