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

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

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

Powered by Google App Engine
This is Rietveld 408576698