Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: ui/accessibility/ax_serializable_tree.cc

Issue 90853002: Make tree serialization more robust and add more unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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<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 {
24 return tree_->GetRoot();
25 }
26
23 virtual AXNode* GetFromId(int32 id) const OVERRIDE { 27 virtual AXNode* GetFromId(int32 id) const OVERRIDE {
24 return tree_->GetFromId(id); 28 return tree_->GetFromId(id);
25 } 29 }
26 30
27 virtual int32 GetId(const AXNode* node) const OVERRIDE { 31 virtual int32 GetId(const AXNode* node) const OVERRIDE {
28 return node->id(); 32 return node->id();
29 } 33 }
30 34
31 virtual int GetChildCount(const AXNode* node) const OVERRIDE { 35 virtual int GetChildCount(const AXNode* node) const OVERRIDE {
32 return node->child_count(); 36 return node->child_count();
33 } 37 }
34 38
35 virtual AXNode* GetChildAtIndex(const AXNode* node, int index) 39 virtual AXNode* GetChildAtIndex(const AXNode* node, int index)
36 const OVERRIDE { 40 const OVERRIDE {
37 return node->ChildAtIndex(index); 41 return node->ChildAtIndex(index);
38 } 42 }
39 43
40 virtual int32 GetParentId(const AXNode* node) const OVERRIDE { 44 virtual AXNode* GetParent(const AXNode* node) const OVERRIDE {
41 if (node->parent()) 45 return node->parent();
42 return node->parent()->id();
43 else
44 return 0;
45 } 46 }
46 47
47 virtual void SerializeNode( 48 virtual void SerializeNode(
48 const AXNode* node, AXNodeData* out_data) const OVERRIDE { 49 const AXNode* node, AXNodeData* out_data) const OVERRIDE {
49 *out_data = node->data(); 50 *out_data = node->data();
50 } 51 }
51 52
52 private: 53 private:
53 AXTree* tree_; 54 AXTree* tree_;
54 }; 55 };
55 56
56 AXSerializableTree::AXSerializableTree() 57 AXSerializableTree::AXSerializableTree()
57 : AXTree() {} 58 : AXTree() {}
58 59
59 AXSerializableTree::AXSerializableTree(const AXTreeUpdate& initial_state) 60 AXSerializableTree::AXSerializableTree(const AXTreeUpdate& initial_state)
60 : AXTree(initial_state) { 61 : AXTree(initial_state) {
61 } 62 }
62 63
63 AXSerializableTree::~AXSerializableTree() { 64 AXSerializableTree::~AXSerializableTree() {
64 } 65 }
65 66
66 AXTreeSource<AXNode>* AXSerializableTree::CreateTreeSource() { 67 AXTreeSource<AXNode>* AXSerializableTree::CreateTreeSource() {
67 return new AXTreeSourceAdapter(this); 68 return new AXTreeSourceAdapter(this);
68 } 69 }
69 70
70 } // namespace ui 71 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698