| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/accessibility/accessibility_tree_formatter.h" | 5 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 void AccessibilityTreeFormatter::FormatAccessibilityTree( | 57 void AccessibilityTreeFormatter::FormatAccessibilityTree( |
| 58 string16* contents) { | 58 string16* contents) { |
| 59 scoped_ptr<DictionaryValue> dict = BuildAccessibilityTree(); | 59 scoped_ptr<DictionaryValue> dict = BuildAccessibilityTree(); |
| 60 RecursiveFormatAccessibilityTree(*(dict.get()), contents); | 60 RecursiveFormatAccessibilityTree(*(dict.get()), contents); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void AccessibilityTreeFormatter::RecursiveBuildAccessibilityTree( | 63 void AccessibilityTreeFormatter::RecursiveBuildAccessibilityTree( |
| 64 const BrowserAccessibility& node, DictionaryValue* dict) { | 64 const BrowserAccessibility& node, DictionaryValue* dict) { |
| 65 AddProperties(node, dict); | 65 AddProperties(node, dict); |
| 66 |
| 66 ListValue* children = new ListValue; | 67 ListValue* children = new ListValue; |
| 67 dict->Set(kChildrenDictAttr, children); | 68 dict->Set(kChildrenDictAttr, children); |
| 69 if (!IncludeChildren(node)) |
| 70 return; |
| 71 |
| 68 for (size_t i = 0; i < node.children().size(); ++i) { | 72 for (size_t i = 0; i < node.children().size(); ++i) { |
| 69 BrowserAccessibility* child_node = node.children()[i]; | 73 BrowserAccessibility* child_node = node.children()[i]; |
| 70 DictionaryValue* child_dict = new DictionaryValue; | 74 DictionaryValue* child_dict = new DictionaryValue; |
| 71 children->Append(child_dict); | 75 children->Append(child_dict); |
| 72 RecursiveBuildAccessibilityTree(*child_node, child_dict); | 76 RecursiveBuildAccessibilityTree(*child_node, child_dict); |
| 73 } | 77 } |
| 74 } | 78 } |
| 75 | 79 |
| 76 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( | 80 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( |
| 77 const DictionaryValue& dict, string16* contents, int depth) { | 81 const DictionaryValue& dict, string16* contents, int depth) { |
| 78 string16 line = ToString(dict, string16(depth * kIndentSpaces, ' ')); | 82 string16 line = ToString(dict, string16(depth * kIndentSpaces, ' ')); |
| 79 if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos) | 83 if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos) |
| 80 return; | 84 return; |
| 81 | 85 |
| 82 *contents += line; | 86 *contents += line; |
| 83 const ListValue* children; | 87 const ListValue* children; |
| 84 dict.GetList(kChildrenDictAttr, &children); | 88 dict.GetList(kChildrenDictAttr, &children); |
| 85 const DictionaryValue* child_dict; | 89 const DictionaryValue* child_dict; |
| 86 for (size_t i = 0; i < children->GetSize(); i++) { | 90 for (size_t i = 0; i < children->GetSize(); i++) { |
| 87 children->GetDictionary(i, &child_dict); | 91 children->GetDictionary(i, &child_dict); |
| 88 RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1); | 92 RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1); |
| 89 } | 93 } |
| 90 } | 94 } |
| 91 | 95 |
| 92 #if (!defined(OS_WIN) && !defined(OS_MACOSX)) | 96 #if !defined(OS_ANDROID) |
| 97 bool AccessibilityTreeFormatter::IncludeChildren( |
| 98 const BrowserAccessibility& node) { |
| 99 return true; |
| 100 } |
| 101 #endif |
| 102 |
| 103 #if (!defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_ANDROID)) |
| 93 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, | 104 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, |
| 94 DictionaryValue* dict) { | 105 DictionaryValue* dict) { |
| 95 dict->SetInteger("id", node.renderer_id()); | 106 dict->SetInteger("id", node.renderer_id()); |
| 96 } | 107 } |
| 97 | 108 |
| 98 string16 AccessibilityTreeFormatter::ToString(const DictionaryValue& node, | 109 string16 AccessibilityTreeFormatter::ToString(const DictionaryValue& node, |
| 99 const string16& indent) { | 110 const string16& indent) { |
| 100 int id_value; | 111 int id_value; |
| 101 node.GetInteger("id", &id_value); | 112 node.GetInteger("id", &id_value); |
| 102 return indent + base::IntToString16(id_value) + | 113 return indent + base::IntToString16(id_value) + |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 if (attr.empty()) | 187 if (attr.empty()) |
| 177 return; | 188 return; |
| 178 if (!MatchesFilters(attr, include_by_default)) | 189 if (!MatchesFilters(attr, include_by_default)) |
| 179 return; | 190 return; |
| 180 if (!line->empty()) | 191 if (!line->empty()) |
| 181 *line += ASCIIToUTF16(" "); | 192 *line += ASCIIToUTF16(" "); |
| 182 *line += attr; | 193 *line += attr; |
| 183 } | 194 } |
| 184 | 195 |
| 185 } // namespace content | 196 } // namespace content |
| OLD | NEW |