Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: content/browser/accessibility/accessibility_tree_formatter.cc

Issue 811213002: Revert of Add DumpAccessibilityEvents test framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dump_acc_events_1
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "content/browser/accessibility/browser_accessibility_manager.h" 13 #include "content/browser/accessibility/browser_accessibility_manager.h"
14 #include "content/browser/renderer_host/render_widget_host_view_base.h" 14 #include "content/browser/renderer_host/render_widget_host_view_base.h"
15 #include "content/browser/web_contents/web_contents_impl.h" 15 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 17
18 namespace content { 18 namespace content {
19 namespace { 19 namespace {
20 const int kIndentSpaces = 4; 20 const int kIndentSpaces = 4;
21 const char* kSkipString = "@NO_DUMP"; 21 const char* kSkipString = "@NO_DUMP";
22 const char* kChildrenDictAttr = "children"; 22 const char* kChildrenDictAttr = "children";
23 } 23 }
24 24
25 AccessibilityTreeFormatter::AccessibilityTreeFormatter( 25 AccessibilityTreeFormatter::AccessibilityTreeFormatter(
26 BrowserAccessibility* root) 26 BrowserAccessibility* root)
27 : root_(root), 27 : root_(root) {
28 show_ids_(false) {
29 Initialize(); 28 Initialize();
30 } 29 }
31 30
32 // static 31 // static
33 AccessibilityTreeFormatter* AccessibilityTreeFormatter::Create( 32 AccessibilityTreeFormatter* AccessibilityTreeFormatter::Create(
34 WebContents* web_contents) { 33 WebContents* web_contents) {
35 BrowserAccessibilityManager* manager = 34 BrowserAccessibilityManager* manager =
36 static_cast<WebContentsImpl*>(web_contents)-> 35 static_cast<WebContentsImpl*>(web_contents)->
37 GetRootBrowserAccessibilityManager(); 36 GetRootBrowserAccessibilityManager();
38 if (!manager) 37 if (!manager)
(...skipping 30 matching lines...) Expand all
69 for (size_t i = 0; i < node.PlatformChildCount(); ++i) { 68 for (size_t i = 0; i < node.PlatformChildCount(); ++i) {
70 BrowserAccessibility* child_node = node.PlatformGetChild(i); 69 BrowserAccessibility* child_node = node.PlatformGetChild(i);
71 base::DictionaryValue* child_dict = new base::DictionaryValue; 70 base::DictionaryValue* child_dict = new base::DictionaryValue;
72 children->Append(child_dict); 71 children->Append(child_dict);
73 RecursiveBuildAccessibilityTree(*child_node, child_dict); 72 RecursiveBuildAccessibilityTree(*child_node, child_dict);
74 } 73 }
75 } 74 }
76 75
77 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree( 76 void AccessibilityTreeFormatter::RecursiveFormatAccessibilityTree(
78 const base::DictionaryValue& dict, base::string16* contents, int depth) { 77 const base::DictionaryValue& dict, base::string16* contents, int depth) {
79 base::string16 indent = base::string16(depth * kIndentSpaces, ' '); 78 base::string16 line =
80 base::string16 line = indent + ToString(dict); 79 ToString(dict, base::string16(depth * kIndentSpaces, ' '));
81 if (line.find(base::ASCIIToUTF16(kSkipString)) != base::string16::npos) 80 if (line.find(base::ASCIIToUTF16(kSkipString)) != base::string16::npos)
82 return; 81 return;
83 82
84 *contents += line + base::ASCIIToUTF16("\n"); 83 *contents += line;
85 const base::ListValue* children; 84 const base::ListValue* children;
86 dict.GetList(kChildrenDictAttr, &children); 85 dict.GetList(kChildrenDictAttr, &children);
87 const base::DictionaryValue* child_dict; 86 const base::DictionaryValue* child_dict;
88 for (size_t i = 0; i < children->GetSize(); i++) { 87 for (size_t i = 0; i < children->GetSize(); i++) {
89 children->GetDictionary(i, &child_dict); 88 children->GetDictionary(i, &child_dict);
90 RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1); 89 RecursiveFormatAccessibilityTree(*child_dict, contents, depth + 1);
91 } 90 }
92 } 91 }
93 92
94 #if (!defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_ANDROID)) 93 #if (!defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_ANDROID))
95 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node, 94 void AccessibilityTreeFormatter::AddProperties(const BrowserAccessibility& node,
96 base::DictionaryValue* dict) { 95 base::DictionaryValue* dict) {
97 dict->SetInteger("id", node.GetId()); 96 dict->SetInteger("id", node.GetId());
98 } 97 }
99 98
100 base::string16 AccessibilityTreeFormatter::ToString( 99 base::string16 AccessibilityTreeFormatter::ToString(
101 const base::DictionaryValue& node) { 100 const base::DictionaryValue& node,
101 const base::string16& indent) {
102 int id_value; 102 int id_value;
103 node.GetInteger("id", &id_value); 103 node.GetInteger("id", &id_value);
104 return base::IntToString16(id_value); 104 return indent + base::IntToString16(id_value) +
105 base::ASCIIToUTF16("\n");
105 } 106 }
106 107
107 void AccessibilityTreeFormatter::Initialize() {} 108 void AccessibilityTreeFormatter::Initialize() {}
108 109
109 // static 110 // static
110 const base::FilePath::StringType 111 const base::FilePath::StringType
111 AccessibilityTreeFormatter::GetActualFileSuffix() { 112 AccessibilityTreeFormatter::GetActualFileSuffix() {
112 return base::FilePath::StringType(); 113 return base::FilePath::StringType();
113 } 114 }
114 115
(...skipping 17 matching lines...) Expand all
132 const std::string AccessibilityTreeFormatter::GetDenyString() { 133 const std::string AccessibilityTreeFormatter::GetDenyString() {
133 return std::string(); 134 return std::string();
134 } 135 }
135 #endif 136 #endif
136 137
137 void AccessibilityTreeFormatter::SetFilters( 138 void AccessibilityTreeFormatter::SetFilters(
138 const std::vector<Filter>& filters) { 139 const std::vector<Filter>& filters) {
139 filters_ = filters; 140 filters_ = filters;
140 } 141 }
141 142
142 // static
143 bool AccessibilityTreeFormatter::MatchesFilters( 143 bool AccessibilityTreeFormatter::MatchesFilters(
144 const std::vector<Filter>& filters, 144 const base::string16& text, bool default_result) const {
145 const base::string16& text, 145 std::vector<Filter>::const_iterator iter = filters_.begin();
146 bool default_result) {
147 std::vector<Filter>::const_iterator iter = filters.begin();
148 bool allow = default_result; 146 bool allow = default_result;
149 for (iter = filters.begin(); iter != filters.end(); ++iter) { 147 for (iter = filters_.begin(); iter != filters_.end(); ++iter) {
150 if (MatchPattern(text, iter->match_str)) { 148 if (MatchPattern(text, iter->match_str)) {
151 if (iter->type == Filter::ALLOW_EMPTY) 149 if (iter->type == Filter::ALLOW_EMPTY)
152 allow = true; 150 allow = true;
153 else if (iter->type == Filter::ALLOW) 151 else if (iter->type == Filter::ALLOW)
154 allow = (!MatchPattern(text, base::UTF8ToUTF16("*=''"))); 152 allow = (!MatchPattern(text, base::UTF8ToUTF16("*=''")));
155 else 153 else
156 allow = false; 154 allow = false;
157 } 155 }
158 } 156 }
159 return allow; 157 return allow;
160 } 158 }
161 159
162 bool AccessibilityTreeFormatter::MatchesFilters(
163 const base::string16& text, bool default_result) const {
164 return MatchesFilters(filters_, text, default_result);
165 }
166
167 base::string16 AccessibilityTreeFormatter::FormatCoordinates( 160 base::string16 AccessibilityTreeFormatter::FormatCoordinates(
168 const char* name, const char* x_name, const char* y_name, 161 const char* name, const char* x_name, const char* y_name,
169 const base::DictionaryValue& value) { 162 const base::DictionaryValue& value) {
170 int x, y; 163 int x, y;
171 value.GetInteger(x_name, &x); 164 value.GetInteger(x_name, &x);
172 value.GetInteger(y_name, &y); 165 value.GetInteger(y_name, &y);
173 std::string xy_str(base::StringPrintf("%s=(%d, %d)", name, x, y)); 166 std::string xy_str(base::StringPrintf("%s=(%d, %d)", name, x, y));
174 167
175 return base::UTF8ToUTF16(xy_str); 168 return base::UTF8ToUTF16(xy_str);
176 } 169 }
177 170
178 void AccessibilityTreeFormatter::WriteAttribute( 171 void AccessibilityTreeFormatter::WriteAttribute(
179 bool include_by_default, const std::string& attr, base::string16* line) { 172 bool include_by_default, const std::string& attr, base::string16* line) {
180 WriteAttribute(include_by_default, base::UTF8ToUTF16(attr), line); 173 WriteAttribute(include_by_default, base::UTF8ToUTF16(attr), line);
181 } 174 }
182 175
183 void AccessibilityTreeFormatter::WriteAttribute( 176 void AccessibilityTreeFormatter::WriteAttribute(
184 bool include_by_default, const base::string16& attr, base::string16* line) { 177 bool include_by_default, const base::string16& attr, base::string16* line) {
185 if (attr.empty()) 178 if (attr.empty())
186 return; 179 return;
187 if (!MatchesFilters(attr, include_by_default)) 180 if (!MatchesFilters(attr, include_by_default))
188 return; 181 return;
189 if (!line->empty()) 182 if (!line->empty())
190 *line += base::ASCIIToUTF16(" "); 183 *line += base::ASCIIToUTF16(" ");
191 *line += attr; 184 *line += attr;
192 } 185 }
193 186
194 } // namespace content 187 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698