blob: 17446e32396d4cc22c8563a417e009ae700f2f54 [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#include "ui/accessibility/ax_serializable_tree.h"
6
avi9c81217b2015-12-24 23:40:057#include <stdint.h>
8
[email protected]4b02bbca2013-11-22 08:59:039#include "ui/accessibility/ax_node.h"
10
11namespace ui {
12
13// This class is an implementation of the AXTreeSource interface with
14// AXNode as the node type, that just delegates to an AXTree. The purpose
15// of this is so that AXTreeSerializer only needs to work with the
16// AXTreeSource abstraction and doesn't need to actually know about
17// AXTree directly. Another AXTreeSource is used to abstract the Blink
18// accessibility tree.
dmazzoniac6cdd02015-08-04 21:07:0619class AX_EXPORT AXTreeSourceAdapter
dmazzoni329fd012015-10-22 20:05:3520 : public AXTreeSource<const AXNode*, AXNodeData, AXTreeData> {
[email protected]4b02bbca2013-11-22 08:59:0321 public:
22 AXTreeSourceAdapter(AXTree* tree) : tree_(tree) {}
dcheng08038792014-10-21 10:53:2623 ~AXTreeSourceAdapter() override {}
[email protected]4b02bbca2013-11-22 08:59:0324
25 // AXTreeSource implementation.
dmazzonia6bc51332016-06-17 03:42:4626 bool GetTreeData(AXTreeData* data) const override {
27 *data = tree_->data();
28 return true;
29 }
dmazzoni329fd012015-10-22 20:05:3530
tfarina6b1c1e082015-02-20 23:47:0731 AXNode* GetRoot() const override { return tree_->root(); }
[email protected]d4e273462013-12-04 04:37:5832
avi9c81217b2015-12-24 23:40:0533 AXNode* GetFromId(int32_t id) const override { return tree_->GetFromId(id); }
[email protected]4b02bbca2013-11-22 08:59:0334
avi9c81217b2015-12-24 23:40:0535 int32_t GetId(const AXNode* node) const override { return node->id(); }
[email protected]4b02bbca2013-11-22 08:59:0336
dcheng08038792014-10-21 10:53:2637 void GetChildren(const AXNode* node,
38 std::vector<const AXNode*>* out_children) const override {
[email protected]e736e81b2014-02-24 07:15:5839 for (int i = 0; i < node->child_count(); ++i)
40 out_children->push_back(node->ChildAtIndex(i));
[email protected]4b02bbca2013-11-22 08:59:0341 }
42
dcheng08038792014-10-21 10:53:2643 AXNode* GetParent(const AXNode* node) const override {
[email protected]d4e273462013-12-04 04:37:5844 return node->parent();
[email protected]4b02bbca2013-11-22 08:59:0345 }
46
dcheng08038792014-10-21 10:53:2647 bool IsValid(const AXNode* node) const override { return node != NULL; }
[email protected]e736e81b2014-02-24 07:15:5848
dcheng08038792014-10-21 10:53:2649 bool IsEqual(const AXNode* node1, const AXNode* node2) const override {
[email protected]e736e81b2014-02-24 07:15:5850 return node1 == node2;
51 }
52
dcheng08038792014-10-21 10:53:2653 const AXNode* GetNull() const override { return NULL; }
[email protected]e736e81b2014-02-24 07:15:5854
dcheng08038792014-10-21 10:53:2655 void SerializeNode(const AXNode* node, AXNodeData* out_data) const override {
[email protected]4b02bbca2013-11-22 08:59:0356 *out_data = node->data();
57 }
58
59 private:
60 AXTree* tree_;
61};
62
63AXSerializableTree::AXSerializableTree()
64 : AXTree() {}
65
dmazzoniac6cdd02015-08-04 21:07:0666AXSerializableTree::AXSerializableTree(
dmazzoni329fd012015-10-22 20:05:3567 const AXTreeUpdate& initial_state)
[email protected]4b02bbca2013-11-22 08:59:0368 : AXTree(initial_state) {
69}
70
71AXSerializableTree::~AXSerializableTree() {
72}
73
dmazzoni329fd012015-10-22 20:05:3574AXTreeSource<const AXNode*, AXNodeData, AXTreeData>*
dmazzoniac6cdd02015-08-04 21:07:0675AXSerializableTree::CreateTreeSource() {
[email protected]4b02bbca2013-11-22 08:59:0376 return new AXTreeSourceAdapter(this);
77}
78
79} // namespace ui