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 #ifndef CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ | 5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ |
6 #define CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ | 6 #define CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "content/browser/accessibility/browser_accessibility.h" | 14 #include "content/browser/accessibility/browser_accessibility.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 class WebContents; | 19 class WebContents; |
20 | 20 |
21 // A utility class for formatting platform-specific accessibility information, | 21 // A utility class for formatting platform-specific accessibility information, |
22 // for use in testing, debugging, and developer tools. | 22 // for use in testing, debugging, and developer tools. |
23 // This is extended by a subclass for each platform where accessibility is | 23 // This is extended by a subclass for each platform where accessibility is |
24 // implemented. | 24 // implemented. |
25 class CONTENT_EXPORT AccessibilityTreeFormatter { | 25 class CONTENT_EXPORT AccessibilityTreeFormatter { |
26 public: | 26 public: |
27 explicit AccessibilityTreeFormatter(BrowserAccessibility* root); | 27 explicit AccessibilityTreeFormatter(BrowserAccessibility* root); |
28 virtual ~AccessibilityTreeFormatter(); | 28 virtual ~AccessibilityTreeFormatter(); |
29 | 29 |
| 30 // A single filter specification. See GetAllowString() and GetDenyString() |
| 31 // for more information. |
| 32 struct Filter { |
| 33 enum Type { |
| 34 ALLOW, |
| 35 ALLOW_EMPTY, |
| 36 DENY |
| 37 }; |
| 38 base::string16 match_str; |
| 39 Type type; |
| 40 |
| 41 Filter(base::string16 match_str, Type type) |
| 42 : match_str(match_str), type(type) {} |
| 43 }; |
| 44 |
30 static AccessibilityTreeFormatter* Create(WebContents* wc); | 45 static AccessibilityTreeFormatter* Create(WebContents* wc); |
31 | 46 |
| 47 static bool MatchesFilters( |
| 48 const std::vector<Filter>& filters, |
| 49 const base::string16& text, |
| 50 bool default_result); |
| 51 |
32 // Populates the given DictionaryValue with the accessibility tree. | 52 // Populates the given DictionaryValue with the accessibility tree. |
33 // The dictionary contains a key/value pair for each attribute of the node, | 53 // The dictionary contains a key/value pair for each attribute of the node, |
34 // plus a "children" attribute containing a list of all child nodes. | 54 // plus a "children" attribute containing a list of all child nodes. |
35 // { | 55 // { |
36 // "AXName": "node", /* actual attributes will vary by platform */ | 56 // "AXName": "node", /* actual attributes will vary by platform */ |
37 // "position": { /* some attributes may be dictionaries */ | 57 // "position": { /* some attributes may be dictionaries */ |
38 // "x": 0, | 58 // "x": 0, |
39 // "y": 0 | 59 // "y": 0 |
40 // }, | 60 // }, |
41 // /* ... more attributes of |node| */ | 61 // /* ... more attributes of |node| */ |
42 // "children": [ { /* list of children created recursively */ | 62 // "children": [ { /* list of children created recursively */ |
43 // "AXName": "child node 1", | 63 // "AXName": "child node 1", |
44 // /* ... more attributes */ | 64 // /* ... more attributes */ |
45 // "children": [ ] | 65 // "children": [ ] |
46 // }, { | 66 // }, { |
47 // "AXName": "child name 2", | 67 // "AXName": "child name 2", |
48 // /* ... more attributes */ | 68 // /* ... more attributes */ |
49 // "children": [ ] | 69 // "children": [ ] |
50 // } ] | 70 // } ] |
51 // } | 71 // } |
52 scoped_ptr<base::DictionaryValue> BuildAccessibilityTree(); | 72 scoped_ptr<base::DictionaryValue> BuildAccessibilityTree(); |
53 | 73 |
54 // Dumps a BrowserAccessibility tree into a string. | 74 // Dumps a BrowserAccessibility tree into a string. |
55 void FormatAccessibilityTree(base::string16* contents); | 75 void FormatAccessibilityTree(base::string16* contents); |
56 | 76 |
57 // A single filter specification. See GetAllowString() and GetDenyString() | |
58 // for more information. | |
59 struct Filter { | |
60 enum Type { | |
61 ALLOW, | |
62 ALLOW_EMPTY, | |
63 DENY | |
64 }; | |
65 base::string16 match_str; | |
66 Type type; | |
67 | |
68 Filter(base::string16 match_str, Type type) | |
69 : match_str(match_str), type(type) {} | |
70 }; | |
71 | |
72 // Set regular expression filters that apply to each component of every | 77 // Set regular expression filters that apply to each component of every |
73 // line before it's output. | 78 // line before it's output. |
74 void SetFilters(const std::vector<Filter>& filters); | 79 void SetFilters(const std::vector<Filter>& filters); |
75 | 80 |
| 81 // If true, the internal accessibility id of each node will be included |
| 82 // in its output. |
| 83 void set_show_ids(bool show_ids) { show_ids_ = show_ids; } |
| 84 |
76 // Suffix of the expectation file corresponding to html file. | 85 // Suffix of the expectation file corresponding to html file. |
77 // Example: | 86 // Example: |
78 // HTML test: test-file.html | 87 // HTML test: test-file.html |
79 // Expected: test-file-expected-mac.txt. | 88 // Expected: test-file-expected-mac.txt. |
80 // Auto-generated: test-file-actual-mac.txt | 89 // Auto-generated: test-file-actual-mac.txt |
81 static const base::FilePath::StringType GetActualFileSuffix(); | 90 static const base::FilePath::StringType GetActualFileSuffix(); |
82 static const base::FilePath::StringType GetExpectedFileSuffix(); | 91 static const base::FilePath::StringType GetExpectedFileSuffix(); |
83 | 92 |
84 // A platform-specific string that indicates a given line in a file | 93 // A platform-specific string that indicates a given line in a file |
85 // is an allow-empty, allow or deny filter. Example: | 94 // is an allow-empty, allow or deny filter. Example: |
(...skipping 26 matching lines...) Expand all Loading... |
112 // into the given dict. | 121 // into the given dict. |
113 void AddProperties(const BrowserAccessibility& node, | 122 void AddProperties(const BrowserAccessibility& node, |
114 base::DictionaryValue* dict); | 123 base::DictionaryValue* dict); |
115 | 124 |
116 base::string16 FormatCoordinates(const char* name, | 125 base::string16 FormatCoordinates(const char* name, |
117 const char* x_name, | 126 const char* x_name, |
118 const char* y_name, | 127 const char* y_name, |
119 const base::DictionaryValue& value); | 128 const base::DictionaryValue& value); |
120 | 129 |
121 // Returns a platform specific representation of a BrowserAccessibility. | 130 // Returns a platform specific representation of a BrowserAccessibility. |
122 // Should be zero or more complete lines, each with |prefix| prepended | 131 base::string16 ToString(const base::DictionaryValue& node); |
123 // (to indent each line). | |
124 base::string16 ToString(const base::DictionaryValue& node, | |
125 const base::string16& indent); | |
126 | 132 |
127 void Initialize(); | 133 void Initialize(); |
128 | 134 |
129 bool MatchesFilters(const base::string16& text, bool default_result) const; | 135 bool MatchesFilters(const base::string16& text, bool default_result) const; |
130 | 136 |
131 // Writes the given attribute string out to |line| if it matches the filters. | 137 // Writes the given attribute string out to |line| if it matches the filters. |
132 void WriteAttribute(bool include_by_default, | 138 void WriteAttribute(bool include_by_default, |
133 const base::string16& attr, | 139 const base::string16& attr, |
134 base::string16* line); | 140 base::string16* line); |
135 void WriteAttribute(bool include_by_default, | 141 void WriteAttribute(bool include_by_default, |
136 const std::string& attr, | 142 const std::string& attr, |
137 base::string16* line); | 143 base::string16* line); |
138 | 144 |
139 BrowserAccessibility* root_; | 145 BrowserAccessibility* root_; |
140 | 146 |
141 // Filters used when formatting the accessibility tree as text. | 147 // Filters used when formatting the accessibility tree as text. |
142 std::vector<Filter> filters_; | 148 std::vector<Filter> filters_; |
143 | 149 |
| 150 // Whether or not node ids should be included in the dump. |
| 151 bool show_ids_; |
| 152 |
144 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter); | 153 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter); |
145 }; | 154 }; |
146 | 155 |
147 } // namespace content | 156 } // namespace content |
148 | 157 |
149 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ | 158 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ |
OLD | NEW |