OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "chrome/browser/ui/views/accessibility/ax_tree_source_views.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "ui/views/accessibility/ax_aura_obj_cache.h" | |
10 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | |
11 | |
12 namespace views { | |
dmazzoni
2014/04/25 06:13:59
This lives in chrome/browser/ui/views now, so it s
David Tseng
2014/04/25 22:47:29
Done.
| |
13 | |
14 AXTreeSourceViews::AXTreeSourceViews() { | |
15 root_.reset(new AXRootObjWrapper(0)); | |
dmazzoni
2014/04/25 06:13:59
Could you have this assign the next id rather than
David Tseng
2014/04/25 22:47:29
Done.
| |
16 } | |
17 | |
18 AXTreeSourceViews::~AXTreeSourceViews() { | |
19 root_.reset(); | |
20 } | |
21 | |
22 AXAuraObjWrapper* AXTreeSourceViews::GetRoot() const { | |
23 return root_.get(); | |
24 } | |
25 | |
26 AXAuraObjWrapper* AXTreeSourceViews::GetFromId(int32 id) const { | |
27 if (id == root_->GetID()) | |
28 return root_.get(); | |
29 return AXAuraObjCache::GetInstance()->Get(id); | |
30 } | |
31 | |
32 int32 AXTreeSourceViews::GetId(AXAuraObjWrapper* node) const { | |
33 return node->GetID(); | |
34 } | |
35 | |
36 void AXTreeSourceViews::GetChildren(AXAuraObjWrapper* node, | |
37 std::vector<AXAuraObjWrapper*>* out_children) const { | |
38 node->GetChildren(out_children); | |
39 } | |
40 | |
41 AXAuraObjWrapper* AXTreeSourceViews::GetParent(AXAuraObjWrapper* node) const { | |
42 AXAuraObjWrapper* parent = node->GetParent(); | |
43 | |
44 if (!parent && root_->HasChild(node)) | |
45 parent = root_.get(); | |
46 return parent; | |
47 } | |
48 | |
49 bool AXTreeSourceViews::IsValid(AXAuraObjWrapper* node) const { | |
50 return node && node->GetID() != -1; | |
51 } | |
52 | |
53 bool AXTreeSourceViews::IsEqual(AXAuraObjWrapper* node1, | |
54 AXAuraObjWrapper* node2) const { | |
55 if (!node1 || !node2) | |
56 return false; | |
57 | |
58 return node1->GetID() == node2->GetID() && node1->GetID() != -1; | |
dmazzoni
2014/04/25 06:13:59
I think we use 0 for "no id" in ui/accessibility
David Tseng
2014/04/25 22:47:29
Any distinction between no id and invalid id?
| |
59 } | |
60 | |
61 AXAuraObjWrapper* AXTreeSourceViews::GetNull() const { | |
62 return NULL; | |
63 } | |
64 | |
65 void AXTreeSourceViews::SerializeNode( | |
66 AXAuraObjWrapper* node, ui::AXNodeData* out_data) const { | |
67 node->Serialize(out_data); | |
68 } | |
69 | |
70 std::string AXTreeSourceViews::ToString( | |
71 AXAuraObjWrapper* root, std::string prefix) { | |
72 ui::AXNodeData out_data; | |
73 root->Serialize(&out_data); | |
74 std::string output = prefix + out_data.ToString() + '\n'; | |
75 | |
76 std::vector<AXAuraObjWrapper*> out_children; | |
77 root->GetChildren(&out_children); | |
78 | |
79 prefix += prefix[0]; | |
80 for (size_t i = 0; i < out_children.size(); ++i) | |
81 output += ToString(out_children[i], prefix); | |
82 | |
83 return output; | |
84 } | |
85 | |
86 } // namespace views | |
OLD | NEW |