blob: 9244c7f75c2f976316b6b12587fe3604a6c05df8 [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.
dmazzoni329fd012015-10-22 20:05:3526 AXTreeData GetTreeData() const override { return tree_->data(); }
27
tfarina6b1c1e082015-02-20 23:47:0728 AXNode* GetRoot() const override { return tree_->root(); }
[email protected]d4e273462013-12-04 04:37:5829
avi9c81217b2015-12-24 23:40:0530 AXNode* GetFromId(int32_t id) const override { return tree_->GetFromId(id); }
[email protected]4b02bbca2013-11-22 08:59:0331
avi9c81217b2015-12-24 23:40:0532 int32_t GetId(const AXNode* node) const override { return node->id(); }
[email protected]4b02bbca2013-11-22 08:59:0333
dcheng08038792014-10-21 10:53:2634 void GetChildren(const AXNode* node,
35 std::vector<const AXNode*>* out_children) const override {
[email protected]e736e81b2014-02-24 07:15:5836 for (int i = 0; i < node->child_count(); ++i)
37 out_children->push_back(node->ChildAtIndex(i));
[email protected]4b02bbca2013-11-22 08:59:0338 }
39
dcheng08038792014-10-21 10:53:2640 AXNode* GetParent(const AXNode* node) const override {
[email protected]d4e273462013-12-04 04:37:5841 return node->parent();
[email protected]4b02bbca2013-11-22 08:59:0342 }
43
dcheng08038792014-10-21 10:53:2644 bool IsValid(const AXNode* node) const override { return node != NULL; }
[email protected]e736e81b2014-02-24 07:15:5845
dcheng08038792014-10-21 10:53:2646 bool IsEqual(const AXNode* node1, const AXNode* node2) const override {
[email protected]e736e81b2014-02-24 07:15:5847 return node1 == node2;
48 }
49
dcheng08038792014-10-21 10:53:2650 const AXNode* GetNull() const override { return NULL; }
[email protected]e736e81b2014-02-24 07:15:5851
dcheng08038792014-10-21 10:53:2652 void SerializeNode(const AXNode* node, AXNodeData* out_data) const override {
[email protected]4b02bbca2013-11-22 08:59:0353 *out_data = node->data();
54 }
55
56 private:
57 AXTree* tree_;
58};
59
60AXSerializableTree::AXSerializableTree()
61 : AXTree() {}
62
dmazzoniac6cdd02015-08-04 21:07:0663AXSerializableTree::AXSerializableTree(
dmazzoni329fd012015-10-22 20:05:3564 const AXTreeUpdate& initial_state)
[email protected]4b02bbca2013-11-22 08:59:0365 : AXTree(initial_state) {
66}
67
68AXSerializableTree::~AXSerializableTree() {
69}
70
dmazzoni329fd012015-10-22 20:05:3571AXTreeSource<const AXNode*, AXNodeData, AXTreeData>*
dmazzoniac6cdd02015-08-04 21:07:0672AXSerializableTree::CreateTreeSource() {
[email protected]4b02bbca2013-11-22 08:59:0373 return new AXTreeSourceAdapter(this);
74}
75
76} // namespace ui