| 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" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 scoped_ptr<base::DictionaryValue> dict = BuildAccessibilityTree(); | 59 scoped_ptr<base::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, base::DictionaryValue* dict) { | 64 const BrowserAccessibility& node, base::DictionaryValue* dict) { |
| 65 AddProperties(node, dict); | 65 AddProperties(node, dict); |
| 66 | 66 |
| 67 base::ListValue* children = new base::ListValue; | 67 base::ListValue* children = new base::ListValue; |
| 68 dict->Set(kChildrenDictAttr, children); | 68 dict->Set(kChildrenDictAttr, children); |
| 69 if (!IncludeChildren(node)) | |
| 70 return; | |
| 71 | 69 |
| 72 for (size_t i = 0; i < node.children().size(); ++i) { | 70 for (size_t i = 0; i < node.PlatformChildCount(); ++i) { |
| 73 BrowserAccessibility* child_node = node.children()[i]; | 71 BrowserAccessibility* child_node = node.children()[i]; |
| 74 base::DictionaryValue* child_dict = new base::DictionaryValue; | 72 base::DictionaryValue* child_dict = new base::DictionaryValue; |
| 75 children->Append(child_dict); | 73 children->Append(child_dict); |
| 76 RecursiveBuildAccessibilityTree(*child_node, child_dict); | 74 RecursiveBuildAccessibilityTree(*child_node, child_dict); |
| 77 } | 75 } |
| 78 } | 76 } |
| 79 | 77 |
| 80 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( | 78 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( |
| 81 const base::DictionaryValue& dict, string16* contents, int depth) { | 79 const base::DictionaryValue& dict, string16* contents, int depth) { |
| 82 string16 line = ToString(dict, string16(depth * kIndentSpaces, ' ')); | 80 string16 line = ToString(dict, string16(depth * kIndentSpaces, ' ')); |
| 83 if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos) | 81 if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos) |
| 84 return; | 82 return; |
| 85 | 83 |
| 86 *contents += line; | 84 *contents += line; |
| 87 const base::ListValue* children; | 85 const base::ListValue* children; |
| 88 dict.GetList(kChildrenDictAttr, &children); | 86 dict.GetList(kChildrenDictAttr, &children); |
| 89 const base::DictionaryValue* child_dict; | 87 const base::DictionaryValue* child_dict; |
| 90 for (size_t i = 0; i < children->GetSize(); i++) { | 88 for (size_t i = 0; i < children->GetSize(); i++) { |
| 91 children->GetDictionary(i, &child_dict); | 89 children->GetDictionary(i, &child_dict); |
| 92 RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1); | 90 RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1); |
| 93 } | 91 } |
| 94 } | 92 } |
| 95 | 93 |
| 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) && \ | 94 #if (!defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 104 !defined(TOOLKIT_GTK)) | 95 !defined(TOOLKIT_GTK)) |
| 105 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, | 96 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, |
| 106 base::DictionaryValue* dict) { | 97 base::DictionaryValue* dict) { |
| 107 dict->SetInteger("id", node.renderer_id()); | 98 dict->SetInteger("id", node.renderer_id()); |
| 108 } | 99 } |
| 109 | 100 |
| 110 string16 AccessibilityTreeFormatter::ToString(const base::DictionaryValue& node, | 101 string16 AccessibilityTreeFormatter::ToString(const base::DictionaryValue& node, |
| 111 const string16& indent) { | 102 const string16& indent) { |
| 112 int id_value; | 103 int id_value; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 if (attr.empty()) | 179 if (attr.empty()) |
| 189 return; | 180 return; |
| 190 if (!MatchesFilters(attr, include_by_default)) | 181 if (!MatchesFilters(attr, include_by_default)) |
| 191 return; | 182 return; |
| 192 if (!line->empty()) | 183 if (!line->empty()) |
| 193 *line += ASCIIToUTF16(" "); | 184 *line += ASCIIToUTF16(" "); |
| 194 *line += attr; | 185 *line += attr; |
| 195 } | 186 } |
| 196 | 187 |
| 197 } // namespace content | 188 } // namespace content |
| OLD | NEW |