| 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/dump_accessibility_tree_helper.h" | 5 #include "content/browser/accessibility/dump_accessibility_tree_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_util.h" |
| 8 | 10 |
| 9 namespace { | 11 namespace { |
| 10 const int kIndentSpaces = 4; | 12 const int kIndentSpaces = 4; |
| 11 } | 13 } |
| 12 | 14 |
| 15 DumpAccessibilityTreeHelper::DumpAccessibilityTreeHelper() { |
| 16 Initialize(); |
| 17 } |
| 18 |
| 19 DumpAccessibilityTreeHelper::~DumpAccessibilityTreeHelper() { |
| 20 } |
| 21 |
| 13 void DumpAccessibilityTreeHelper::DumpAccessibilityTree( | 22 void DumpAccessibilityTreeHelper::DumpAccessibilityTree( |
| 14 BrowserAccessibility* node, string16* contents) { | 23 BrowserAccessibility* node, string16* contents) { |
| 15 RecursiveDumpAccessibilityTree(node, contents, 0); | 24 RecursiveDumpAccessibilityTree(node, contents, 0); |
| 16 } | 25 } |
| 17 | 26 |
| 18 void DumpAccessibilityTreeHelper::RecursiveDumpAccessibilityTree( | 27 void DumpAccessibilityTreeHelper::RecursiveDumpAccessibilityTree( |
| 19 BrowserAccessibility* node, string16* contents, int indent) { | 28 BrowserAccessibility* node, string16* contents, int indent) { |
| 20 scoped_array<char> prefix(new char[indent + 1]); | 29 scoped_array<char> prefix(new char[indent + 1]); |
| 21 for (int i = 0; i < indent; ++i) | 30 for (int i = 0; i < indent; ++i) |
| 22 prefix[i] = ' '; | 31 prefix[i] = ' '; |
| 23 prefix[indent] = '\0'; | 32 prefix[indent] = '\0'; |
| 24 | 33 |
| 25 *contents += ToString(node, prefix.get()); | 34 *contents += ToString(node, prefix.get()); |
| 26 for (size_t i = 0; i < node->children().size(); ++i) { | 35 for (size_t i = 0; i < node->children().size(); ++i) { |
| 27 RecursiveDumpAccessibilityTree(node->children()[i], contents, | 36 RecursiveDumpAccessibilityTree(node->children()[i], contents, |
| 28 indent + kIndentSpaces); | 37 indent + kIndentSpaces); |
| 29 } | 38 } |
| 30 } | 39 } |
| 40 |
| 41 void DumpAccessibilityTreeHelper::SetFilters( |
| 42 const std::set<string16>& allow_filters, |
| 43 const std::set<string16>& deny_filters) { |
| 44 allow_filters_ = allow_filters; |
| 45 deny_filters_ = deny_filters; |
| 46 } |
| 47 |
| 48 bool DumpAccessibilityTreeHelper::MatchesFilters( |
| 49 const string16& text, bool default_result) { |
| 50 std::set<string16>::const_iterator iter = allow_filters_.begin(); |
| 51 for (iter = allow_filters_.begin(); iter != allow_filters_.end(); ++iter) { |
| 52 if (MatchPattern(text, *iter)) |
| 53 return true; |
| 54 } |
| 55 for (iter = deny_filters_.begin(); iter != deny_filters_.end(); ++iter) { |
| 56 if (MatchPattern(text, *iter)) |
| 57 return false; |
| 58 } |
| 59 return default_result; |
| 60 } |
| 61 |
| 62 void DumpAccessibilityTreeHelper::StartLine() { |
| 63 line_.clear(); |
| 64 } |
| 65 |
| 66 void DumpAccessibilityTreeHelper::Add( |
| 67 bool include_by_default, const string16& attr) { |
| 68 if (!MatchesFilters(attr, include_by_default)) |
| 69 return; |
| 70 if (!line_.empty()) |
| 71 line_ += ASCIIToUTF16(" "); |
| 72 line_ += attr; |
| 73 } |
| 74 |
| 75 string16 DumpAccessibilityTreeHelper::FinishLine() { |
| 76 return line_; |
| 77 } |
| OLD | NEW |