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