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

Unified Diff: content/browser/accessibility/accessibility_tree_formatter.cc

Issue 13479003: Modify AccessibilityTreeFormatter to build up an internal representation of the tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code cleanup Created 7 years, 8 months 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 side-by-side diff with in-line comments
Download patch
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 f8b4cc735230a139c6e660a862f3653d8181a2cc..781498833c2a649322ca8a000ce30f60e84df3ae 100644
--- a/content/browser/accessibility/accessibility_tree_formatter.cc
+++ b/content/browser/accessibility/accessibility_tree_formatter.cc
@@ -4,6 +4,7 @@
#include "content/browser/accessibility/accessibility_tree_formatter.h"
+#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
@@ -21,8 +22,8 @@ const char* kSkipString = "@NO_DUMP";
}
AccessibilityTreeFormatter::AccessibilityTreeFormatter(
- BrowserAccessibility* node)
- : node_(node) {
+ BrowserAccessibility* root)
+ : root_(root) {
Initialize();
}
@@ -45,26 +46,44 @@ AccessibilityTreeFormatter* AccessibilityTreeFormatter::Create(
AccessibilityTreeFormatter::~AccessibilityTreeFormatter() {
}
+void AccessibilityTreeFormatter::BuildAccessibilityTree(
+ DictionaryValue* dict) {
+ RecursiveBuildAccessibilityTree(root_, dict);
+}
+
void AccessibilityTreeFormatter::FormatAccessibilityTree(
string16* contents) {
- RecursiveFormatAccessibilityTree(node_, contents, 0);
+ DictionaryValue dict;
+ BuildAccessibilityTree(&dict);
+ RecursiveFormatAccessibilityTree(&dict, contents);
}
-void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree(
- BrowserAccessibility* node, string16* contents, int indent) {
- scoped_array<char> prefix(new char[indent + 1]);
- for (int i = 0; i < indent; ++i)
- prefix[i] = ' ';
- prefix[indent] = '\0';
+void AccessibilityTreeFormatter::RecursiveBuildAccessibilityTree(
+ BrowserAccessibility* node, DictionaryValue* dict) {
+ AddProperties(node, dict);
+ ListValue* children = new ListValue;
+ dict->Set("children", children);
dmazzoni 2013/04/08 05:46:35 Put dict field names in a constant at the top of t
aboxhall 2013/04/10 03:09:34 Done (there was actually only this one).
+ 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);
+ }
+}
- string16 line = ToString(node, prefix.get());
+void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree(
+ DictionaryValue* dict, string16* contents, int depth) {
+ string16 line = ToString(dict, string16(depth * kIndentSpaces, ' '));
dmazzoni 2013/04/08 05:46:35 Thanks - I didn't realize you could construct a st
aboxhall 2013/04/10 03:09:34 Hehe - I was thinking "surely there's a more effic
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);
+ ListValue* children;
+ dict->GetList("children", &children);
dmazzoni 2013/04/08 05:46:35 Make sure this uses the constant!
aboxhall 2013/04/10 03:09:34 Done.
aboxhall 2013/04/10 03:09:34 Done.
+ 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 +146,15 @@ bool AccessibilityTreeFormatter::MatchesFilters(
return allow;
}
-void AccessibilityTreeFormatter::StartLine() {
- line_.clear();
-}
-
-void AccessibilityTreeFormatter::Add(
- bool include_by_default, const string16& attr) {
+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

Powered by Google App Engine
This is Rietveld 408576698