• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ui/accessibility/ax_serializable_tree.h"
6 
7 #include "ui/accessibility/ax_node.h"
8 
9 namespace ui {
10 
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 : public AXTreeSource<const AXNode*> {
18  public:
AXTreeSourceAdapter(AXTree * tree)19   AXTreeSourceAdapter(AXTree* tree) : tree_(tree) {}
~AXTreeSourceAdapter()20   virtual ~AXTreeSourceAdapter() {}
21 
22   // AXTreeSource implementation.
GetRoot() const23   virtual AXNode* GetRoot() const OVERRIDE {
24     return tree_->GetRoot();
25   }
26 
GetFromId(int32 id) const27   virtual AXNode* GetFromId(int32 id) const OVERRIDE {
28     return tree_->GetFromId(id);
29   }
30 
GetId(const AXNode * node) const31   virtual int32 GetId(const AXNode* node) const OVERRIDE {
32     return node->id();
33   }
34 
GetChildren(const AXNode * node,std::vector<const AXNode * > * out_children) const35   virtual void GetChildren(
36       const AXNode* node,
37       std::vector<const AXNode*>* out_children) const OVERRIDE {
38     for (int i = 0; i < node->child_count(); ++i)
39       out_children->push_back(node->ChildAtIndex(i));
40   }
41 
GetParent(const AXNode * node) const42   virtual AXNode* GetParent(const AXNode* node) const OVERRIDE {
43     return node->parent();
44   }
45 
IsValid(const AXNode * node) const46   virtual bool IsValid(const AXNode* node) const OVERRIDE {
47     return node != NULL;
48   }
49 
IsEqual(const AXNode * node1,const AXNode * node2) const50   virtual bool IsEqual(const AXNode* node1,
51                        const AXNode* node2) const OVERRIDE {
52     return node1 == node2;
53   }
54 
GetNull() const55   virtual const AXNode* GetNull() const OVERRIDE {
56     return NULL;
57   }
58 
SerializeNode(const AXNode * node,AXNodeData * out_data) const59   virtual void SerializeNode(
60       const AXNode* node, AXNodeData* out_data) const OVERRIDE {
61     *out_data = node->data();
62   }
63 
64  private:
65   AXTree* tree_;
66 };
67 
AXSerializableTree()68 AXSerializableTree::AXSerializableTree()
69     : AXTree() {}
70 
AXSerializableTree(const AXTreeUpdate & initial_state)71 AXSerializableTree::AXSerializableTree(const AXTreeUpdate& initial_state)
72     : AXTree(initial_state) {
73 }
74 
~AXSerializableTree()75 AXSerializableTree::~AXSerializableTree() {
76 }
77 
CreateTreeSource()78 AXTreeSource<const AXNode*>* AXSerializableTree::CreateTreeSource() {
79   return new AXTreeSourceAdapter(this);
80 }
81 
82 }  // namespace ui
83