[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_SOURCE_H_ |
| 6 | #define UI_ACCESSIBILITY_AX_TREE_SOURCE_H_ |
| 7 | |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 12 | namespace ui { |
| 13 | |
| 14 | // An AXTreeSource is an abstract interface for a serializable |
| 15 | // accessibility tree. The tree may be in some other format or |
| 16 | // may be computed dynamically, but maintains the properties that |
| 17 | // it's a strict tree, it has a unique id for each node, and all |
| 18 | // of the accessibility information about a node can be serialized |
| 19 | // as an AXNodeData. This is the primary interface to use when |
| 20 | // an accessibility tree will be sent over an IPC before being |
| 21 | // consumed. |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 22 | template<typename AXNodeSource, typename AXNodeData, typename AXTreeData> |
[email protected] | 949df1c | 2014-04-03 15:25:30 | [diff] [blame] | 23 | class AXTreeSource { |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 24 | public: |
| 25 | virtual ~AXTreeSource() {} |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 26 | |
dmazzoni | a6bc5133 | 2016-06-17 03:42:46 | [diff] [blame] | 27 | // Get the tree data and returns true if there is any data to copy. |
| 28 | virtual bool GetTreeData(AXTreeData* data) const = 0; |
dmazzoni | 329fd01 | 2015-10-22 20:05:35 | [diff] [blame] | 29 | |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 30 | // Get the root of the tree. |
| 31 | virtual AXNodeSource GetRoot() const = 0; |
| 32 | |
| 33 | // Get a node by its id. If no node by that id exists in the tree, return a |
| 34 | // null node, i.e. one that will return false if you call IsValid on it. |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 35 | virtual AXNodeSource GetFromId(int32_t id) const = 0; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 36 | |
| 37 | // Return the id of a node. All ids must be positive integers. |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 38 | virtual int32_t GetId(AXNodeSource node) const = 0; |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 39 | |
| 40 | // Append all children of |node| to |out_children|. |
| 41 | virtual void GetChildren(AXNodeSource node, |
| 42 | std::vector<AXNodeSource>* out_children) const = 0; |
| 43 | |
| 44 | // Get the parent of |node|. |
| 45 | virtual AXNodeSource GetParent(AXNodeSource node) const = 0; |
| 46 | |
| 47 | // Returns true if |node| is valid, and false if it's a null pointer or a |
| 48 | // node object representing the null pointer. |
| 49 | virtual bool IsValid(AXNodeSource node) const = 0; |
| 50 | |
| 51 | // Returns true if two nodes are equal. |
| 52 | virtual bool IsEqual(AXNodeSource node1, |
| 53 | AXNodeSource node2) const = 0; |
| 54 | |
| 55 | // Return a AXNodeSource representing null. |
| 56 | virtual AXNodeSource GetNull() const = 0; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 57 | |
| 58 | // Serialize one node in the tree. |
[email protected] | e736e81b | 2014-02-24 07:15:58 | [diff] [blame] | 59 | virtual void SerializeNode(AXNodeSource node, AXNodeData* out_data) const = 0; |
[email protected] | 4b02bbca | 2013-11-22 08:59:03 | [diff] [blame] | 60 | |
| 61 | protected: |
| 62 | AXTreeSource() {} |
| 63 | }; |
| 64 | |
| 65 | } // namespace ui |
| 66 | |
| 67 | #endif // UI_ACCESSIBILITY_AX_TREE_SOURCE_H_ |