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" | |
8 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
9 #include "base/string_util.h" | |
10 | 8 |
11 namespace { | 9 namespace { |
12 const int kIndentSpaces = 4; | 10 const int kIndentSpaces = 4; |
13 } | 11 } |
14 | 12 |
15 DumpAccessibilityTreeHelper::DumpAccessibilityTreeHelper() { | |
16 Initialize(); | |
17 } | |
18 | |
19 DumpAccessibilityTreeHelper::~DumpAccessibilityTreeHelper() { | |
20 } | |
21 | |
22 void DumpAccessibilityTreeHelper::DumpAccessibilityTree( | 13 void DumpAccessibilityTreeHelper::DumpAccessibilityTree( |
23 BrowserAccessibility* node, string16* contents) { | 14 BrowserAccessibility* node, string16* contents) { |
24 RecursiveDumpAccessibilityTree(node, contents, 0); | 15 RecursiveDumpAccessibilityTree(node, contents, 0); |
25 } | 16 } |
26 | 17 |
27 void DumpAccessibilityTreeHelper::RecursiveDumpAccessibilityTree( | 18 void DumpAccessibilityTreeHelper::RecursiveDumpAccessibilityTree( |
28 BrowserAccessibility* node, string16* contents, int indent) { | 19 BrowserAccessibility* node, string16* contents, int indent) { |
29 scoped_array<char> prefix(new char[indent + 1]); | 20 scoped_array<char> prefix(new char[indent + 1]); |
30 for (int i = 0; i < indent; ++i) | 21 for (int i = 0; i < indent; ++i) |
31 prefix[i] = ' '; | 22 prefix[i] = ' '; |
32 prefix[indent] = '\0'; | 23 prefix[indent] = '\0'; |
33 | 24 |
34 *contents += ToString(node, prefix.get()); | 25 *contents += ToString(node, prefix.get()); |
35 for (size_t i = 0; i < node->children().size(); ++i) { | 26 for (size_t i = 0; i < node->children().size(); ++i) { |
36 RecursiveDumpAccessibilityTree(node->children()[i], contents, | 27 RecursiveDumpAccessibilityTree(node->children()[i], contents, |
37 indent + kIndentSpaces); | 28 indent + kIndentSpaces); |
38 } | 29 } |
39 } | 30 } |
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 |