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