Index: content/browser/accessibility/accessibility_tree_formatter.cc |
diff --git a/content/browser/accessibility/accessibility_tree_formatter.cc b/content/browser/accessibility/accessibility_tree_formatter.cc |
index 3904bc0d83bbec92675e22b5aaf50bb2a93422da..23cc04af0ff367cdc98260c89fa3e43fe709357c 100644 |
--- a/content/browser/accessibility/accessibility_tree_formatter.cc |
+++ b/content/browser/accessibility/accessibility_tree_formatter.cc |
@@ -7,6 +7,7 @@ |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/string_util.h" |
+#include "base/stringprintf.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/utf_string_conversions.h" |
#include "content/browser/accessibility/browser_accessibility_manager.h" |
@@ -18,11 +19,12 @@ namespace content { |
namespace { |
const int kIndentSpaces = 4; |
const char* kSkipString = "@NO_DUMP"; |
+const char* kChildrenDictAttr = "children"; |
} |
AccessibilityTreeFormatter::AccessibilityTreeFormatter( |
- BrowserAccessibility* node) |
- : node_(node) { |
+ BrowserAccessibility* root) |
+ : root_(root) { |
Initialize(); |
} |
@@ -45,26 +47,45 @@ AccessibilityTreeFormatter* AccessibilityTreeFormatter::Create( |
AccessibilityTreeFormatter::~AccessibilityTreeFormatter() { |
} |
+scoped_ptr<DictionaryValue> |
+AccessibilityTreeFormatter::BuildAccessibilityTree() { |
+ scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
+ RecursiveBuildAccessibilityTree(*root_, dict.get()); |
+ return dict.Pass(); |
+} |
+ |
void AccessibilityTreeFormatter::FormatAccessibilityTree( |
string16* contents) { |
- RecursiveFormatAccessibilityTree(node_, contents, 0); |
+ scoped_ptr<DictionaryValue> dict = BuildAccessibilityTree(); |
+ RecursiveFormatAccessibilityTree(*(dict.get()), contents); |
+} |
+ |
+void AccessibilityTreeFormatter::RecursiveBuildAccessibilityTree( |
+ const BrowserAccessibility& node, DictionaryValue* dict) { |
+ AddProperties(node, dict); |
+ ListValue* children = new ListValue; |
+ dict->Set(kChildrenDictAttr, children); |
+ for (size_t i = 0; i < node.children().size(); ++i) { |
+ BrowserAccessibility* child_node = node.children()[i]; |
+ DictionaryValue* child_dict = new DictionaryValue; |
+ children->Append(child_dict); |
+ RecursiveBuildAccessibilityTree(*child_node, child_dict); |
+ } |
} |
void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( |
- BrowserAccessibility* node, string16* contents, int indent) { |
- scoped_ptr<char[]> prefix(new char[indent + 1]); |
- for (int i = 0; i < indent; ++i) |
- prefix[i] = ' '; |
- prefix[indent] = '\0'; |
- |
- string16 line = ToString(node, prefix.get()); |
+ const DictionaryValue& dict, string16* contents, int depth) { |
+ string16 line = ToString(dict, string16(depth * kIndentSpaces, ' ')); |
if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos) |
return; |
*contents += line; |
- for (size_t i = 0; i < node->children().size(); ++i) { |
- RecursiveFormatAccessibilityTree(node->children()[i], contents, |
- indent + kIndentSpaces); |
+ const ListValue* children; |
+ dict.GetList(kChildrenDictAttr, &children); |
+ const DictionaryValue* child_dict; |
+ for (size_t i = 0; i < children->GetSize(); i++) { |
+ children->GetDictionary(i, &child_dict); |
+ RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1); |
} |
} |
@@ -127,23 +148,31 @@ bool AccessibilityTreeFormatter::MatchesFilters( |
return allow; |
} |
-void AccessibilityTreeFormatter::StartLine() { |
- line_.clear(); |
+string16 AccessibilityTreeFormatter::FormatCoordinates( |
+ const char* name, const char* x_name, const char* y_name, |
+ const DictionaryValue& value) { |
+ int x, y; |
+ value.GetInteger(x_name, &x); |
+ value.GetInteger(y_name, &y); |
+ std::string xy_str(base::StringPrintf("%s=(%d, %d)", name, x, y)); |
+ |
+ return UTF8ToUTF16(xy_str); |
} |
-void AccessibilityTreeFormatter::Add( |
- bool include_by_default, const string16& attr) { |
+void AccessibilityTreeFormatter::WriteAttribute( |
+ bool include_by_default, const std::string& attr, string16* line) { |
+ WriteAttribute(include_by_default, UTF8ToUTF16(attr), line); |
+} |
+ |
+void AccessibilityTreeFormatter::WriteAttribute( |
+ bool include_by_default, const string16& attr, string16* line) { |
if (attr.empty()) |
return; |
if (!MatchesFilters(attr, include_by_default)) |
return; |
- if (!line_.empty()) |
- line_ += ASCIIToUTF16(" "); |
- line_ += attr; |
-} |
- |
-string16 AccessibilityTreeFormatter::FinishLine() { |
- return line_; |
+ if (!line->empty()) |
+ *line += ASCIIToUTF16(" "); |
+ *line += attr; |
} |
} // namespace content |