Chromium Code Reviews| 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)) | 69 if (node.IsLeaf()) |
|
David Tseng
2013/10/17 22:56:29
Btw, isLeaf worries me because it's often possible
dmazzoni
2013/10/21 17:26:57
My intent is that this is only used to really mean
| |
| 70 return; | 70 return; |
| 71 | 71 |
| 72 for (size_t i = 0; i < node.children().size(); ++i) { | 72 for (size_t i = 0; i < node.children().size(); ++i) { |
| 73 BrowserAccessibility* child_node = node.children()[i]; | 73 BrowserAccessibility* child_node = node.children()[i]; |
| 74 base::DictionaryValue* child_dict = new base::DictionaryValue; | 74 base::DictionaryValue* child_dict = new base::DictionaryValue; |
| 75 children->Append(child_dict); | 75 children->Append(child_dict); |
| 76 RecursiveBuildAccessibilityTree(*child_node, child_dict); | 76 RecursiveBuildAccessibilityTree(*child_node, child_dict); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( | 80 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( |
| 81 const base::DictionaryValue& dict, string16* contents, int depth) { | 81 const base::DictionaryValue& dict, string16* contents, int depth) { |
| 82 string16 line = ToString(dict, string16(depth * kIndentSpaces, ' ')); | 82 string16 line = ToString(dict, string16(depth * kIndentSpaces, ' ')); |
| 83 if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos) | 83 if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 *contents += line; | 86 *contents += line; |
| 87 const base::ListValue* children; | 87 const base::ListValue* children; |
| 88 dict.GetList(kChildrenDictAttr, &children); | 88 dict.GetList(kChildrenDictAttr, &children); |
| 89 const base::DictionaryValue* child_dict; | 89 const base::DictionaryValue* child_dict; |
| 90 for (size_t i = 0; i < children->GetSize(); i++) { | 90 for (size_t i = 0; i < children->GetSize(); i++) { |
| 91 children->GetDictionary(i, &child_dict); | 91 children->GetDictionary(i, &child_dict); |
| 92 RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1); | 92 RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 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) && \ | 96 #if (!defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 104 !defined(TOOLKIT_GTK)) | 97 !defined(TOOLKIT_GTK)) |
| 105 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, | 98 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, |
| 106 base::DictionaryValue* dict) { | 99 base::DictionaryValue* dict) { |
| 107 dict->SetInteger("id", node.renderer_id()); | 100 dict->SetInteger("id", node.renderer_id()); |
| 108 } | 101 } |
| 109 | 102 |
| 110 string16 AccessibilityTreeFormatter::ToString(const base::DictionaryValue& node, | 103 string16 AccessibilityTreeFormatter::ToString(const base::DictionaryValue& node, |
| 111 const string16& indent) { | 104 const string16& indent) { |
| 112 int id_value; | 105 int id_value; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 if (attr.empty()) | 181 if (attr.empty()) |
| 189 return; | 182 return; |
| 190 if (!MatchesFilters(attr, include_by_default)) | 183 if (!MatchesFilters(attr, include_by_default)) |
| 191 return; | 184 return; |
| 192 if (!line->empty()) | 185 if (!line->empty()) |
| 193 *line += ASCIIToUTF16(" "); | 186 *line += ASCIIToUTF16(" "); |
| 194 *line += attr; | 187 *line += attr; |
| 195 } | 188 } |
| 196 | 189 |
| 197 } // namespace content | 190 } // namespace content |
| OLD | NEW |