Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ui / accessibility / ax_serializable_tree.cc
blob9c13fd085de47d42b899d514c601983739db6d42
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.
5 #include "ui/accessibility/ax_serializable_tree.h"
7 #include "ui/accessibility/ax_node.h"
9 namespace ui {
11 // This class is an implementation of the AXTreeSource interface with
12 // AXNode as the node type, that just delegates to an AXTree. The purpose
13 // of this is so that AXTreeSerializer only needs to work with the
14 // AXTreeSource abstraction and doesn't need to actually know about
15 // AXTree directly. Another AXTreeSource is used to abstract the Blink
16 // accessibility tree.
17 class AX_EXPORT AXTreeSourceAdapter
18 : public AXTreeSource<const AXNode*, AXNodeData> {
19 public:
20 AXTreeSourceAdapter(AXTree* tree) : tree_(tree) {}
21 ~AXTreeSourceAdapter() override {}
23 // AXTreeSource implementation.
24 AXNode* GetRoot() const override { return tree_->root(); }
26 AXNode* GetFromId(int32 id) const override { return tree_->GetFromId(id); }
28 int32 GetId(const AXNode* node) const override { return node->id(); }
30 void GetChildren(const AXNode* node,
31 std::vector<const AXNode*>* out_children) const override {
32 for (int i = 0; i < node->child_count(); ++i)
33 out_children->push_back(node->ChildAtIndex(i));
36 AXNode* GetParent(const AXNode* node) const override {
37 return node->parent();
40 bool IsValid(const AXNode* node) const override { return node != NULL; }
42 bool IsEqual(const AXNode* node1, const AXNode* node2) const override {
43 return node1 == node2;
46 const AXNode* GetNull() const override { return NULL; }
48 void SerializeNode(const AXNode* node, AXNodeData* out_data) const override {
49 *out_data = node->data();
52 private:
53 AXTree* tree_;
56 AXSerializableTree::AXSerializableTree()
57 : AXTree() {}
59 AXSerializableTree::AXSerializableTree(
60 const AXTreeUpdate<AXNodeData>& initial_state)
61 : AXTree(initial_state) {
64 AXSerializableTree::~AXSerializableTree() {
67 AXTreeSource<const AXNode*, AXNodeData>*
68 AXSerializableTree::CreateTreeSource() {
69 return new AXTreeSourceAdapter(this);
72 } // namespace ui