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 using views::AXAuraObjCache; | |
13 using views::AXAuraObjWrapper; | |
14 | |
15 AXTreeSourceViews::AXTreeSourceViews() { | |
16 root_.reset( | |
17 new AXRootObjWrapper(AXAuraObjCache::GetInstance()->GetNextID())); | |
18 } | |
19 | |
20 AXTreeSourceViews::~AXTreeSourceViews() { | |
21 root_.reset(); | |
22 } | |
23 | |
24 AXAuraObjWrapper* AXTreeSourceViews::GetRoot() const { | |
25 return root_.get(); | |
26 } | |
27 | |
28 AXAuraObjWrapper* AXTreeSourceViews::GetFromId(int32 id) const { | |
29 if (id == root_->GetID()) | |
dmazzoni
2014/04/29 17:20:59
Why does the root have to be special-cased? Isn't
| |
30 return root_.get(); | |
31 return AXAuraObjCache::GetInstance()->Get(id); | |
32 } | |
33 | |
34 int32 AXTreeSourceViews::GetId(AXAuraObjWrapper* node) const { | |
35 return node->GetID(); | |
36 } | |
37 | |
38 void AXTreeSourceViews::GetChildren(AXAuraObjWrapper* node, | |
39 std::vector<AXAuraObjWrapper*>* out_children) const { | |
40 node->GetChildren(out_children); | |
41 } | |
42 | |
43 AXAuraObjWrapper* AXTreeSourceViews::GetParent(AXAuraObjWrapper* node) const { | |
44 AXAuraObjWrapper* parent = node->GetParent(); | |
45 if (!parent && root_->HasChild(node)) | |
dmazzoni
2014/04/29 17:20:59
Why can't an AXWindowWrapper return the desktop as
| |
46 parent = root_.get(); | |
47 return parent; | |
48 } | |
49 | |
50 bool AXTreeSourceViews::IsValid(AXAuraObjWrapper* node) const { | |
51 return node && node->GetID() != -1; | |
52 } | |
53 | |
54 bool AXTreeSourceViews::IsEqual(AXAuraObjWrapper* node1, | |
55 AXAuraObjWrapper* node2) const { | |
56 if (!node1 || !node2) | |
57 return false; | |
58 | |
59 return node1->GetID() == node2->GetID() && node1->GetID() != -1; | |
60 } | |
61 | |
62 AXAuraObjWrapper* AXTreeSourceViews::GetNull() const { | |
63 return NULL; | |
64 } | |
65 | |
66 void AXTreeSourceViews::SerializeNode( | |
67 AXAuraObjWrapper* node, ui::AXNodeData* out_data) const { | |
68 node->Serialize(out_data); | |
69 } | |
70 | |
71 std::string AXTreeSourceViews::ToString( | |
72 AXAuraObjWrapper* root, std::string prefix) { | |
73 ui::AXNodeData data; | |
74 root->Serialize(&data); | |
75 std::string output = prefix + data.ToString() + '\n'; | |
76 | |
77 std::vector<AXAuraObjWrapper*> children; | |
78 root->GetChildren(&children); | |
79 | |
80 prefix += prefix[0]; | |
81 for (size_t i = 0; i < children.size(); ++i) | |
82 output += ToString(children[i], prefix); | |
83 | |
84 return output; | |
85 } | |
OLD | NEW |