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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "content/browser/accessibility/browser_accessibility_manager.h" | 13 #include "content/browser/accessibility/browser_accessibility_manager.h" |
14 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 14 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 namespace { | 19 namespace { |
20 const int kIndentSpaces = 4; | 20 const char kIndentSymbol = '+'; |
| 21 const int kIndentSymbolCount = 2; |
21 const char* kSkipString = "@NO_DUMP"; | 22 const char* kSkipString = "@NO_DUMP"; |
22 const char* kChildrenDictAttr = "children"; | 23 const char* kChildrenDictAttr = "children"; |
23 } | 24 } |
24 | 25 |
25 AccessibilityTreeFormatter::AccessibilityTreeFormatter( | 26 AccessibilityTreeFormatter::AccessibilityTreeFormatter( |
26 BrowserAccessibility* root) | 27 BrowserAccessibility* root) |
27 : root_(root), | 28 : root_(root), |
28 show_ids_(false) { | 29 show_ids_(false) { |
29 Initialize(); | 30 Initialize(); |
30 } | 31 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 for (size_t i = 0; i < node.PlatformChildCount(); ++i) { | 70 for (size_t i = 0; i < node.PlatformChildCount(); ++i) { |
70 BrowserAccessibility* child_node = node.PlatformGetChild(i); | 71 BrowserAccessibility* child_node = node.PlatformGetChild(i); |
71 base::DictionaryValue* child_dict = new base::DictionaryValue; | 72 base::DictionaryValue* child_dict = new base::DictionaryValue; |
72 children->Append(child_dict); | 73 children->Append(child_dict); |
73 RecursiveBuildAccessibilityTree(*child_node, child_dict); | 74 RecursiveBuildAccessibilityTree(*child_node, child_dict); |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( | 78 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( |
78 const base::DictionaryValue& dict, base::string16* contents, int depth) { | 79 const base::DictionaryValue& dict, base::string16* contents, int depth) { |
79 base::string16 indent = base::string16(depth * kIndentSpaces, ' '); | 80 base::string16 indent = base::string16(depth * kIndentSymbolCount, |
| 81 kIndentSymbol); |
80 base::string16 line = indent + ToString(dict); | 82 base::string16 line = indent + ToString(dict); |
81 if (line.find(base::ASCIIToUTF16(kSkipString)) != base::string16::npos) | 83 if (line.find(base::ASCIIToUTF16(kSkipString)) != base::string16::npos) |
82 return; | 84 return; |
83 | 85 |
84 *contents += line + base::ASCIIToUTF16("\n"); | 86 *contents += line + base::ASCIIToUTF16("\n"); |
85 const base::ListValue* children; | 87 const base::ListValue* children; |
86 dict.GetList(kChildrenDictAttr, &children); | 88 dict.GetList(kChildrenDictAttr, &children); |
87 const base::DictionaryValue* child_dict; | 89 const base::DictionaryValue* child_dict; |
88 for (size_t i = 0; i < children->GetSize(); i++) { | 90 for (size_t i = 0; i < children->GetSize(); i++) { |
89 children->GetDictionary(i, &child_dict); | 91 children->GetDictionary(i, &child_dict); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 if (attr.empty()) | 187 if (attr.empty()) |
186 return; | 188 return; |
187 if (!MatchesFilters(attr, include_by_default)) | 189 if (!MatchesFilters(attr, include_by_default)) |
188 return; | 190 return; |
189 if (!line->empty()) | 191 if (!line->empty()) |
190 *line += base::ASCIIToUTF16(" "); | 192 *line += base::ASCIIToUTF16(" "); |
191 *line += attr; | 193 *line += attr; |
192 } | 194 } |
193 | 195 |
194 } // namespace content | 196 } // namespace content |
OLD | NEW |