blob: 66be06f7937852d6cf2b03e930c11f40cc79e718 [file] [log] [blame]
[email protected]4b02bbca2013-11-22 08:59:031// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_ACCESSIBILITY_AX_TREE_H_
6#define UI_ACCESSIBILITY_AX_TREE_H_
7
avi9c81217b2015-12-24 23:40:058#include <stdint.h>
9
[email protected]d4e273462013-12-04 04:37:5810#include <set>
Takuto Ikutaadf31eb2019-01-05 00:32:4811#include <unordered_map>
[email protected]4b02bbca2013-11-22 08:59:0312
Dominic Mazzoni8549eb682018-12-11 23:48:3213#include "base/observer_list.h"
[email protected]4b02bbca2013-11-22 08:59:0314#include "ui/accessibility/ax_export.h"
Dominic Mazzoniecfb4fd2018-10-23 07:34:2015#include "ui/accessibility/ax_node.h"
dmazzoni329fd012015-10-22 20:05:3516#include "ui/accessibility/ax_node_data.h"
17#include "ui/accessibility/ax_tree_data.h"
[email protected]4b02bbca2013-11-22 08:59:0318#include "ui/accessibility/ax_tree_update.h"
19
20namespace ui {
21
Dominic Mazzoni3d9b5b92018-04-18 21:36:3822class AXTableInfo;
dmazzoni09e75912015-06-02 23:31:5623class AXTree;
Dominic Mazzoni8549eb682018-12-11 23:48:3224class AXTreeObserver;
[email protected]e736e81b2014-02-24 07:15:5825struct AXTreeUpdateState;
26
[email protected]4b02bbca2013-11-22 08:59:0327// 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 Mazzoniecfb4fd2018-10-23 07:34:2032class AX_EXPORT AXTree : public AXNode::OwnerTree {
[email protected]4b02bbca2013-11-22 08:59:0333 public:
David Tsengef6b480d2018-02-19 12:48:4234 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]4b02bbca2013-11-22 08:59:0341 AXTree();
dmazzoni329fd012015-10-22 20:05:3542 explicit AXTree(const AXTreeUpdate& initial_state);
[email protected]4b02bbca2013-11-22 08:59:0343 virtual ~AXTree();
44
Dominic Mazzoni8549eb682018-12-11 23:48:3245 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]e736e81b2014-02-24 07:15:5850
tfarina6b1c1e082015-02-20 23:47:0751 AXNode* root() const { return root_; }
52
dmazzoni329fd012015-10-22 20:05:3553 const AXTreeData& data() const { return data_; }
54
Dominic Mazzoniecfb4fd2018-10-23 07:34:2055 // AXNode::OwnerTree override.
tfarina6b1c1e082015-02-20 23:47:0756 // Returns the AXNode with the given |id| if it is part of this AXTree.
Dominic Mazzoniecfb4fd2018-10-23 07:34:2057 AXNode* GetFromId(int32_t id) const override;
[email protected]4b02bbca2013-11-22 08:59:0358
[email protected]d4e273462013-12-04 04:37:5859 // 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.
dmazzoni329fd012015-10-22 20:05:3562 virtual bool Unserialize(const AXTreeUpdate& update);
63
64 virtual void UpdateData(const AXTreeData& data);
[email protected]4b02bbca2013-11-22 08:59:0365
Dominic Mazzoni2410fc62017-06-09 22:19:1866 // 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 Dektar2c6052d2017-09-27 00:32:3268 // 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 Dektardb71ad942017-11-29 20:07:4872 // If |clip_bounds| is true, result bounds will be clipped.
Dominic Mazzoni2410fc62017-06-09 22:19:1873 gfx::RectF RelativeToTreeBounds(const AXNode* node,
Katie Dektar2c6052d2017-09-27 00:32:3274 gfx::RectF node_bounds,
Katie Dektardb71ad942017-11-29 20:07:4875 bool* offscreen = nullptr,
76 bool clip_bounds = true) const;
Dominic Mazzoni2410fc62017-06-09 22:19:1877
78 // Get the bounds of a node in the coordinate space of the tree.
Katie Dektar2c6052d2017-09-27 00:32:3279 // 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 Dektardb71ad942017-11-29 20:07:4883 // 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 Mazzoni2410fc62017-06-09 22:19:1887
Dominic Mazzoni35f2a5252017-09-26 00:56:0488 // 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 Mazzonidcef1b732018-01-26 17:57:0491 std::set<int32_t> GetReverseRelations(ax::mojom::IntAttribute attr,
Dominic Mazzoni94a4da62017-12-22 22:49:3892 int32_t dst_id) const;
Dominic Mazzoni35f2a5252017-09-26 00:56:0493
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 Mazzonidcef1b732018-01-26 17:57:0498 std::set<int32_t> GetReverseRelations(ax::mojom::IntListAttribute attr,
Dominic Mazzoni94a4da62017-12-22 22:49:3899 int32_t dst_id) const;
Dominic Mazzoni35f2a5252017-09-26 00:56:04100
Dominic Mazzoniaa774822018-08-29 20:33:58101 // 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 Mazzoni336bc0062018-09-23 16:46:43103 std::set<int32_t> GetNodeIdsForChildTreeId(AXTreeID child_tree_id) const;
Dominic Mazzoniaa774822018-08-29 20:33:58104
Dominic Mazzoni748888c2018-11-01 22:34:59105 // Get all of the child tree IDs referenced by any node in this tree.
106 const std::set<AXTreeID> GetAllChildTreeIds() const;
107
David Tsengef6b480d2018-02-19 12:48:42108 // 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 Mazzoni3d9b5b92018-04-18 21:36:38115
[email protected]5eec2f52014-01-06 22:30:54116 // Return a multi-line indented string representation, for logging.
117 std::string ToString() const;
118
[email protected]d4e273462013-12-04 04:37:58119 // A string describing the error from an unsuccessful Unserialize,
120 // for testing and debugging.
tfarinad0bfb4b62015-02-18 17:20:32121 const std::string& error() const { return error_; }
[email protected]d4e273462013-12-04 04:37:58122
dmazzoniee2eaca2015-03-18 18:13:07123 int size() { return static_cast<int>(id_map_.size()); }
124
Dominic Mazzonid42e00a2018-06-27 23:14:23125 // 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.