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

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

Issue 12335101: Move some accessibility methods, enums and interfaces into the content/public API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix virtual method with no implementation, non-explicit single argument constructor Created 7 years, 10 months 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/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/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "content/browser/accessibility/browser_accessibility_manager.h"
12 #include "content/port/browser/render_widget_host_view_port.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h"
11 15
12 namespace content { 16 namespace content {
13 namespace { 17 namespace {
14 const int kIndentSpaces = 4; 18 const int kIndentSpaces = 4;
15 const char* kSkipString = "@NO_DUMP"; 19 const char* kSkipString = "@NO_DUMP";
16 } 20 }
17 21
18 DumpAccessibilityTreeHelper::DumpAccessibilityTreeHelper() { 22 DumpAccessibilityTreeHelper::DumpAccessibilityTreeHelper(
23 BrowserAccessibility* node)
24 : node_(node) {
19 Initialize(); 25 Initialize();
20 } 26 }
21 27
28 // static
29 AccessibilityTreeFormatter* AccessibilityTreeFormatter::From(
30 RenderViewHost* rvh) {
31 RenderWidgetHostViewPort* host_view = static_cast<RenderWidgetHostViewPort*>(
32 WebContents::FromRenderViewHost(rvh)->GetRenderWidgetHostView());
33
34 content::BrowserAccessibilityManager* manager =
35 host_view->GetBrowserAccessibilityManager();
36 if (!manager)
37 return NULL;
38
39 content::BrowserAccessibility* root = manager->GetRoot();
40 return new DumpAccessibilityTreeHelper(root);
41 }
42
43
22 DumpAccessibilityTreeHelper::~DumpAccessibilityTreeHelper() { 44 DumpAccessibilityTreeHelper::~DumpAccessibilityTreeHelper() {
23 } 45 }
24 46
25 void DumpAccessibilityTreeHelper::DumpAccessibilityTree( 47 void DumpAccessibilityTreeHelper::FormatAccessibilityTree(string16* contents) {
26 BrowserAccessibility* node, string16* contents) { 48 RecursiveDumpAccessibilityTree(node_, contents, 0);
27 RecursiveDumpAccessibilityTree(node, contents, 0);
28 } 49 }
29 50
30 void DumpAccessibilityTreeHelper::RecursiveDumpAccessibilityTree( 51 void DumpAccessibilityTreeHelper::RecursiveDumpAccessibilityTree(
31 BrowserAccessibility* node, string16* contents, int indent) { 52 BrowserAccessibility* node, string16* contents, int indent) {
32 scoped_array<char> prefix(new char[indent + 1]); 53 scoped_array<char> prefix(new char[indent + 1]);
33 for (int i = 0; i < indent; ++i) 54 for (int i = 0; i < indent; ++i)
34 prefix[i] = ' '; 55 prefix[i] = ' ';
35 prefix[indent] = '\0'; 56 prefix[indent] = '\0';
36 57
37 string16 line = ToString(node, prefix.get()); 58 string16 line = ToString(node, prefix.get());
38 if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos) 59 if (line.find(ASCIIToUTF16(kSkipString)) != string16::npos)
39 return; 60 return;
40 61
41 *contents += line; 62 *contents += line;
42 for (size_t i = 0; i < node->children().size(); ++i) { 63 for (size_t i = 0; i < node->children().size(); ++i) {
43 RecursiveDumpAccessibilityTree(node->children()[i], contents, 64 RecursiveDumpAccessibilityTree(node->children()[i], contents,
44 indent + kIndentSpaces); 65 indent + kIndentSpaces);
45 } 66 }
46 } 67 }
47 68
48 void DumpAccessibilityTreeHelper::SetFilters( 69 void DumpAccessibilityTreeHelper::SetFilters(
49 const std::vector<Filter>& filters) { 70 const std::vector<Filter>& filters) {
50 filters_ = filters; 71 filters_ = filters;
51 } 72 }
52 73
53 bool DumpAccessibilityTreeHelper::MatchesFilters( 74 bool DumpAccessibilityTreeHelper::MatchesFilters(
54 const string16& text, bool default_result) { 75 const string16& text, bool default_result) const {
55 std::vector<Filter>::const_iterator iter = filters_.begin(); 76 std::vector<Filter>::const_iterator iter = filters_.begin();
56 bool allow = default_result; 77 bool allow = default_result;
57 for (iter = filters_.begin(); iter != filters_.end(); ++iter) { 78 for (iter = filters_.begin(); iter != filters_.end(); ++iter) {
58 if (MatchPattern(text, iter->match_str)) { 79 if (MatchPattern(text, iter->match_str)) {
59 if (iter->type == Filter::ALLOW_EMPTY) 80 if (iter->type == Filter::ALLOW_EMPTY)
60 allow = true; 81 allow = true;
61 else if (iter->type == Filter::ALLOW) 82 else if (iter->type == Filter::ALLOW)
62 allow = (!MatchPattern(text, UTF8ToUTF16("*=''"))); 83 allow = (!MatchPattern(text, UTF8ToUTF16("*=''")));
63 else 84 else
64 allow = false; 85 allow = false;
(...skipping 15 matching lines...) Expand all
80 if (!line_.empty()) 101 if (!line_.empty())
81 line_ += ASCIIToUTF16(" "); 102 line_ += ASCIIToUTF16(" ");
82 line_ += attr; 103 line_ += attr;
83 } 104 }
84 105
85 string16 DumpAccessibilityTreeHelper::FinishLine() { 106 string16 DumpAccessibilityTreeHelper::FinishLine() {
86 return line_; 107 return line_;
87 } 108 }
88 109
89 } // namespace content 110 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698