OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/accessibility/ax_serializable_tree.h" | 5 #include "ui/accessibility/ax_serializable_tree.h" |
6 | 6 |
7 #include "ui/accessibility/ax_node.h" | 7 #include "ui/accessibility/ax_node.h" |
8 | 8 |
9 namespace ui { | 9 namespace ui { |
10 | 10 |
11 // This class is an implementation of the AXTreeSource interface with | 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 | 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 | 13 // of this is so that AXTreeSerializer only needs to work with the |
14 // AXTreeSource abstraction and doesn't need to actually know about | 14 // AXTreeSource abstraction and doesn't need to actually know about |
15 // AXTree directly. Another AXTreeSource is used to abstract the Blink | 15 // AXTree directly. Another AXTreeSource is used to abstract the Blink |
16 // accessibility tree. | 16 // accessibility tree. |
17 class AX_EXPORT AXTreeSourceAdapter : public AXTreeSource<AXNode> { | 17 class AX_EXPORT AXTreeSourceAdapter : public AXTreeSource<const AXNode*> { |
18 public: | 18 public: |
19 AXTreeSourceAdapter(AXTree* tree) : tree_(tree) {} | 19 AXTreeSourceAdapter(AXTree* tree) : tree_(tree) {} |
20 virtual ~AXTreeSourceAdapter() {} | 20 virtual ~AXTreeSourceAdapter() {} |
21 | 21 |
22 // AXTreeSource implementation. | 22 // AXTreeSource implementation. |
23 virtual AXNode* GetRoot() const OVERRIDE { | 23 virtual AXNode* GetRoot() const OVERRIDE { |
24 return tree_->GetRoot(); | 24 return tree_->GetRoot(); |
25 } | 25 } |
26 | 26 |
27 virtual AXNode* GetFromId(int32 id) const OVERRIDE { | 27 virtual AXNode* GetFromId(int32 id) const OVERRIDE { |
28 return tree_->GetFromId(id); | 28 return tree_->GetFromId(id); |
29 } | 29 } |
30 | 30 |
31 virtual int32 GetId(const AXNode* node) const OVERRIDE { | 31 virtual int32 GetId(const AXNode* node) const OVERRIDE { |
32 return node->id(); | 32 return node->id(); |
33 } | 33 } |
34 | 34 |
35 virtual int GetChildCount(const AXNode* node) const OVERRIDE { | 35 virtual void GetChildren( |
36 return node->child_count(); | 36 const AXNode* node, |
37 } | 37 std::vector<const AXNode*>* out_children) const OVERRIDE { |
38 | 38 for (int i = 0; i < node->child_count(); ++i) |
39 virtual AXNode* GetChildAtIndex(const AXNode* node, int index) | 39 out_children->push_back(node->ChildAtIndex(i)); |
40 const OVERRIDE { | |
41 return node->ChildAtIndex(index); | |
42 } | 40 } |
43 | 41 |
44 virtual AXNode* GetParent(const AXNode* node) const OVERRIDE { | 42 virtual AXNode* GetParent(const AXNode* node) const OVERRIDE { |
45 return node->parent(); | 43 return node->parent(); |
46 } | 44 } |
47 | 45 |
46 virtual bool IsValid(const AXNode* node) const OVERRIDE { | |
47 return node != NULL; | |
48 } | |
49 | |
50 virtual bool IsEqual(const AXNode* node1, | |
51 const AXNode* node2) const OVERRIDE { | |
52 return node1 == node2; | |
53 } | |
54 | |
55 virtual const AXNode* GetNull() const OVERRIDE { | |
David Tseng
2014/02/21 00:33:23
Is there ever an instance where GetNull wouldn't r
dmazzoni
2014/02/21 06:44:59
Yes - I had to add this so I can make AXTreeSource
| |
56 return NULL; | |
57 } | |
58 | |
48 virtual void SerializeNode( | 59 virtual void SerializeNode( |
49 const AXNode* node, AXNodeData* out_data) const OVERRIDE { | 60 const AXNode* node, AXNodeData* out_data) const OVERRIDE { |
50 *out_data = node->data(); | 61 *out_data = node->data(); |
51 } | 62 } |
52 | 63 |
53 private: | 64 private: |
54 AXTree* tree_; | 65 AXTree* tree_; |
55 }; | 66 }; |
56 | 67 |
57 AXSerializableTree::AXSerializableTree() | 68 AXSerializableTree::AXSerializableTree() |
58 : AXTree() {} | 69 : AXTree() {} |
59 | 70 |
60 AXSerializableTree::AXSerializableTree(const AXTreeUpdate& initial_state) | 71 AXSerializableTree::AXSerializableTree(const AXTreeUpdate& initial_state) |
61 : AXTree(initial_state) { | 72 : AXTree(initial_state) { |
62 } | 73 } |
63 | 74 |
64 AXSerializableTree::~AXSerializableTree() { | 75 AXSerializableTree::~AXSerializableTree() { |
65 } | 76 } |
66 | 77 |
67 AXTreeSource<AXNode>* AXSerializableTree::CreateTreeSource() { | 78 AXTreeSource<const AXNode*>* AXSerializableTree::CreateTreeSource() { |
68 return new AXTreeSourceAdapter(this); | 79 return new AXTreeSourceAdapter(this); |
69 } | 80 } |
70 | 81 |
71 } // namespace ui | 82 } // namespace ui |
OLD | NEW |