[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 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 10 | #include <set> |
Takuto Ikuta | adf31eb | 2019-01-05 00:32:48 | [diff] [blame] | 11 | #include <unordered_map> |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 12 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 13 | #include "base/observer_list.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 14 | #include "ui/accessibility/ax_export.h" |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 15 | #include "ui/accessibility/ax_node.h" |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 16 | #include "ui/accessibility/ax_node_data.h" |
| 17 | #include "ui/accessibility/ax_tree_data.h" |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 18 | #include "ui/accessibility/ax_tree_update.h" |
| 19 | |
| 20 | namespace ui { |
| 21 | |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 22 | class AXTableInfo; |
dmazzoni | 09e7591 | 2015-06-02 23:31:56 | [diff] [blame] | 23 | class AXTree; |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 24 | class AXTreeObserver; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 25 | struct AXTreeUpdateState; |
| 26 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 27 | // AXTree is a live, managed tree of AXNode objects that can receive |
| 28 | // updates from another AXTreeSource via AXTreeUpdates, and it can be |
| 29 | // used as a source for sending updates to another client tree. |
| 30 | // It's designed to be subclassed to implement support for native |
| 31 | // accessibility APIs on a specific platform. |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 32 | class AX_EXPORT AXTree : public AXNode::OwnerTree { |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 33 | public: |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 34 | typedef std::map<ax::mojom::IntAttribute, |
| 35 | std::map<int32_t, std::set<int32_t>>> |
| 36 | IntReverseRelationMap; |
| 37 | typedef std::map<ax::mojom::IntListAttribute, |
| 38 | std::map<int32_t, std::set<int32_t>>> |
| 39 | IntListReverseRelationMap; |
| 40 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 41 | AXTree(); |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 42 | explicit AXTree(const AXTreeUpdate& initial_state); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 43 | virtual ~AXTree(); |
| 44 | |
Dominic Mazzoni | 8549eb68 | 2018-12-11 23:48:32 | [diff] [blame] | 45 | void AddObserver(AXTreeObserver* observer); |
| 46 | bool HasObserver(AXTreeObserver* observer); |
| 47 | void RemoveObserver(const AXTreeObserver* observer); |
| 48 | |
| 49 | base::ObserverList<AXTreeObserver>& observers() { return observers_; } |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 50 | |
tfarina | 6b1c1e08 | 2015-02-20 23:47:07 | [diff] [blame] | 51 | AXNode* root() const { return root_; } |
| 52 | |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 53 | const AXTreeData& data() const { return data_; } |
| 54 | |
Dominic Mazzoni | ecfb4fd | 2018-10-23 07:34:20 | [diff] [blame] | 55 | // AXNode::OwnerTree override. |
tfarina | 6b1c1e08 | 2015-02-20 23:47:07 | [diff] [blame] | 56 | // 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] | 57 | AXNode* GetFromId(int32_t id) const override; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 58 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 59 | // Returns true on success. If it returns false, it's a fatal error |
| 60 | // and this tree should be destroyed, and the source of the tree update |
| 61 | // should not be trusted any longer. |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 62 | virtual bool Unserialize(const AXTreeUpdate& update); |
| 63 | |
| 64 | virtual void UpdateData(const AXTreeData& data); |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 65 | |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 66 | // Convert any rectangle from the local coordinate space of one node in |
| 67 | // the tree, to bounds in the coordinate space of the tree. |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 68 | // If set, updates |offscreen| boolean to be true if the node is offscreen |
| 69 | // relative to its rootWebArea. Callers should initialize |offscreen| |
| 70 | // to false: this method may get called multiple times in a row and |
| 71 | // |offscreen| will be propagated. |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 72 | // If |clip_bounds| is true, result bounds will be clipped. |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 73 | gfx::RectF RelativeToTreeBounds(const AXNode* node, |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 74 | gfx::RectF node_bounds, |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 75 | bool* offscreen = nullptr, |
| 76 | bool clip_bounds = true) const; |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 77 | |
| 78 | // Get the bounds of a node in the coordinate space of the tree. |
Katie Dektar | 2c6052d | 2017-09-27 00:32:32 | [diff] [blame] | 79 | // If set, updates |offscreen| boolean to be true if the node is offscreen |
| 80 | // relative to its rootWebArea. Callers should initialize |offscreen| |
| 81 | // to false: this method may get called multiple times in a row and |
| 82 | // |offscreen| will be propagated. |
Katie Dektar | db71ad94 | 2017-11-29 20:07:48 | [diff] [blame] | 83 | // If |clip_bounds| is true, result bounds will be clipped. |
| 84 | gfx::RectF GetTreeBounds(const AXNode* node, |
| 85 | bool* offscreen = nullptr, |
| 86 | bool clip_bounds = true) const; |
Dominic Mazzoni | 2410fc6 | 2017-06-09 22:19:18 | [diff] [blame] | 87 | |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 88 | // Given a node ID attribute (one where IsNodeIdIntAttribute is true), |
| 89 | // and a destination node ID, return a set of all source node IDs that |
| 90 | // have that relationship attribute between them and the destination. |
Dominic Mazzoni | dcef1b73 | 2018-01-26 17:57:04 | [diff] [blame] | 91 | std::set<int32_t> GetReverseRelations(ax::mojom::IntAttribute attr, |
Dominic Mazzoni | 94a4da6 | 2017-12-22 22:49:38 | [diff] [blame] | 92 | int32_t dst_id) const; |
Dominic Mazzoni | 35f2a525 | 2017-09-26 00:56:04 | [diff] [blame] | 93 | |
| 94 | // Given a node ID list attribute (one where |
| 95 | // IsNodeIdIntListAttribute is true), and a destination node ID, |
| 96 | // return a set of all source node IDs that have that relationship |
| 97 | // 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::IntListAttribute 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 | |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 101 | // Given a child tree ID, return the node IDs of all nodes in the tree who |
| 102 | // have a kChildTreeId int attribute with that value. |
Dominic Mazzoni | 336bc006 | 2018-09-23 16:46:43 | [diff] [blame] | 103 | std::set<int32_t> GetNodeIdsForChildTreeId(AXTreeID child_tree_id) const; |
Dominic Mazzoni | aa77482 | 2018-08-29 20:33:58 | [diff] [blame] | 104 | |
Dominic Mazzoni | 748888c | 2018-11-01 22:34:59 | [diff] [blame] | 105 | // Get all of the child tree IDs referenced by any node in this tree. |
| 106 | const std::set<AXTreeID> GetAllChildTreeIds() const; |
| 107 | |
David Tseng | ef6b480d | 2018-02-19 12:48:42 | [diff] [blame] | 108 | // Map from a relation attribute to a map from a target id to source ids. |
| 109 | const IntReverseRelationMap& int_reverse_relations() { |
| 110 | return int_reverse_relations_; |
| 111 | } |
| 112 | const IntListReverseRelationMap& intlist_reverse_relations() { |
| 113 | return intlist_reverse_relations_; |
| 114 | } |
Dominic Mazzoni | 3d9b5b9 | 2018-04-18 21:36:38 | [diff] [blame] | 115 | |
[email protected] | 5eec2f5 | 2014-01-06 22:30:54 | [diff] [blame] | 116 | // Return a multi-line indented string representation, for logging. |
| 117 | std::string ToString() const; |
| 118 | |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 119 | // A string describing the error from an unsuccessful Unserialize, |
| 120 | // for testing and debugging. |
tfarina | d0bfb4b6 | 2015-02-18 17:20:32 | [diff] [blame] | 121 | const std::string& error() const { return error_; } |
[email protected] | d4e27346 | 2013-12-04 04:37:58 | [diff] [blame] | 122 | |
dmazzoni | ee2eaca | 2015-03-18 18:13:07 | [diff] [blame] | 123 | int size() { return static_cast<int>(id_map_.size()); } |
| 124 | |
Dominic Mazzoni | d42e00a | 2018-06-27 23:14:23 | [diff] [blame] | 125 | // Call this to enable support for extra Mac nodes - for each table, |
| 126 | // a table column header and a node for each column. |
| 127 | void SetEnableExtraMacNodes(bool enabled); |
| 128 | bool enable_extra_mac_nodes() const { return enable_extra_mac_nodes_; } |
| 129 | |
| 130 | // Return a negative number that's suitable to use for a node ID for |
| 131 | // internal nodes created automatically by an AXTree, so as not to |
| 132 | // conflict with positive-numbered node IDs from tree sources. |
|
|