Index: chrome/browser/ui/views/accessibility/ax_tree_source_views.cc |
diff --git a/chrome/browser/ui/views/accessibility/ax_tree_source_views.cc b/chrome/browser/ui/views/accessibility/ax_tree_source_views.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..391d7f54ea8a8bffa8e3f7e5907e09e67b99197d |
--- /dev/null |
+++ b/chrome/browser/ui/views/accessibility/ax_tree_source_views.cc |
@@ -0,0 +1,86 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/views/accessibility/ax_tree_source_views.h" |
+ |
+#include <vector> |
+ |
+#include "ui/views/accessibility/ax_aura_obj_cache.h" |
+#include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
+ |
+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.
|
+ |
+AXTreeSourceViews::AXTreeSourceViews() { |
+ 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.
|
+} |
+ |
+AXTreeSourceViews::~AXTreeSourceViews() { |
+ root_.reset(); |
+} |
+ |
+AXAuraObjWrapper* AXTreeSourceViews::GetRoot() const { |
+ return root_.get(); |
+} |
+ |
+AXAuraObjWrapper* AXTreeSourceViews::GetFromId(int32 id) const { |
+ if (id == root_->GetID()) |
+ return root_.get(); |
+ return AXAuraObjCache::GetInstance()->Get(id); |
+} |
+ |
+int32 AXTreeSourceViews::GetId(AXAuraObjWrapper* node) const { |
+ return node->GetID(); |
+} |
+ |
+void AXTreeSourceViews::GetChildren(AXAuraObjWrapper* node, |
+ std::vector<AXAuraObjWrapper*>* out_children) const { |
+ node->GetChildren(out_children); |
+} |
+ |
+AXAuraObjWrapper* AXTreeSourceViews::GetParent(AXAuraObjWrapper* node) const { |
+ AXAuraObjWrapper* parent = node->GetParent(); |
+ |
+ if (!parent && root_->HasChild(node)) |
+ parent = root_.get(); |
+ return parent; |
+} |
+ |
+bool AXTreeSourceViews::IsValid(AXAuraObjWrapper* node) const { |
+ return node && node->GetID() != -1; |
+} |
+ |
+bool AXTreeSourceViews::IsEqual(AXAuraObjWrapper* node1, |
+ AXAuraObjWrapper* node2) const { |
+ if (!node1 || !node2) |
+ return false; |
+ |
+ 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?
|
+} |
+ |
+AXAuraObjWrapper* AXTreeSourceViews::GetNull() const { |
+ return NULL; |
+} |
+ |
+void AXTreeSourceViews::SerializeNode( |
+ AXAuraObjWrapper* node, ui::AXNodeData* out_data) const { |
+ node->Serialize(out_data); |
+} |
+ |
+std::string AXTreeSourceViews::ToString( |
+ AXAuraObjWrapper* root, std::string prefix) { |
+ ui::AXNodeData out_data; |
+ root->Serialize(&out_data); |
+ std::string output = prefix + out_data.ToString() + '\n'; |
+ |
+ std::vector<AXAuraObjWrapper*> out_children; |
+ root->GetChildren(&out_children); |
+ |
+ prefix += prefix[0]; |
+ for (size_t i = 0; i < out_children.size(); ++i) |
+ output += ToString(out_children[i], prefix); |
+ |
+ return output; |
+} |
+ |
+} // namespace views |