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/string16.h" | 11 #include "base/string16.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | |
14 #include "content/browser/accessibility/browser_accessibility.h" | 13 #include "content/browser/accessibility/browser_accessibility.h" |
15 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
16 | 15 |
17 namespace content { | 16 namespace content { |
18 | 17 |
19 class RenderViewHost; | 18 class RenderViewHost; |
20 | 19 |
21 // A utility class for formatting platform-specific accessibility information, | 20 // A utility class for formatting platform-specific accessibility information, |
22 // for use in testing, debugging, and developer tools. | 21 // for use in testing, debugging, and developer tools. |
23 // This is extended by a subclass for each platform where accessibility is | 22 // This is extended by a subclass for each platform where accessibility is |
24 // implemented. | 23 // implemented. |
25 class CONTENT_EXPORT AccessibilityTreeFormatter { | 24 class CONTENT_EXPORT AccessibilityTreeFormatter { |
26 public: | 25 public: |
27 explicit AccessibilityTreeFormatter(BrowserAccessibility* root); | 26 explicit AccessibilityTreeFormatter(BrowserAccessibility* node); |
28 virtual ~AccessibilityTreeFormatter(); | 27 virtual ~AccessibilityTreeFormatter(); |
29 | 28 |
30 static AccessibilityTreeFormatter* Create(RenderViewHost* rvh); | 29 static AccessibilityTreeFormatter* Create(RenderViewHost* rvh); |
31 | 30 |
32 // Populates the given DictionaryValue with the accessibility tree. | |
33 // 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. | |
35 // { | |
36 // "AXName": "node", /* actual attributes will vary by platform */ | |
37 // "position": { /* some attributes may be dictionaries */ | |
38 // "x": 0, | |
39 // "y": 0 | |
40 // }, | |
41 // /* ... more attributes of |node| */ | |
42 // "children": [ { /* list of children created recursively */ | |
43 // "AXName": "child node 1", | |
44 // /* ... more attributes */ | |
45 // "children": [ ] | |
46 // }, { | |
47 // "AXName": "child name 2", | |
48 // /* ... more attributes */ | |
49 // "children": [ ] | |
50 // } ] | |
51 // } | |
52 scoped_ptr<DictionaryValue> BuildAccessibilityTree(); | |
53 | |
54 // Dumps a BrowserAccessibility tree into a string. | 31 // Dumps a BrowserAccessibility tree into a string. |
55 void FormatAccessibilityTree(string16* contents); | 32 void FormatAccessibilityTree(string16* contents); |
56 | 33 |
57 // A single filter specification. See GetAllowString() and GetDenyString() | 34 // A single filter specification. See GetAllowString() and GetDenyString() |
58 // for more information. | 35 // for more information. |
59 struct Filter { | 36 struct Filter { |
60 enum Type { | 37 enum Type { |
61 ALLOW, | 38 ALLOW, |
62 ALLOW_EMPTY, | 39 ALLOW_EMPTY, |
63 DENY | 40 DENY |
(...skipping 28 matching lines...) Expand all Loading... |
92 // @MAC-ALLOW-EMPTY:description* | 69 // @MAC-ALLOW-EMPTY:description* |
93 // @MAC-ALLOW:roleDescription* | 70 // @MAC-ALLOW:roleDescription* |
94 // @MAC-DENY:subrole* | 71 // @MAC-DENY:subrole* |
95 // --> | 72 // --> |
96 // <p>Text</p> | 73 // <p>Text</p> |
97 static const std::string GetAllowEmptyString(); | 74 static const std::string GetAllowEmptyString(); |
98 static const std::string GetAllowString(); | 75 static const std::string GetAllowString(); |
99 static const std::string GetDenyString(); | 76 static const std::string GetDenyString(); |
100 | 77 |
101 protected: | 78 protected: |
102 void RecursiveFormatAccessibilityTree(const BrowserAccessibility& node, | 79 void RecursiveFormatAccessibilityTree(BrowserAccessibility* node, |
103 string16* contents, | 80 string16* contents, |
104 int indent); | 81 int indent); |
105 void RecursiveBuildAccessibilityTree(const BrowserAccessibility& node, | |
106 DictionaryValue* tree_node); | |
107 void RecursiveFormatAccessibilityTree(const DictionaryValue& tree_node, | |
108 string16* contents, | |
109 int depth = 0); | |
110 | |
111 // Overridden by each platform to add the required attributes for each node | |
112 // into the given dict. | |
113 void AddProperties(const BrowserAccessibility& node, DictionaryValue* dict); | |
114 | |
115 string16 FormatCoordinates(const char* name, | |
116 const char* x_name, | |
117 const char* y_name, | |
118 const DictionaryValue& value); | |
119 | 82 |
120 // Returns a platform specific representation of a BrowserAccessibility. | 83 // Returns a platform specific representation of a BrowserAccessibility. |
121 // Should be zero or more complete lines, each with |prefix| prepended | 84 // Should be zero or more complete lines, each with |prefix| prepended |
122 // (to indent each line). | 85 // (to indent each line). |
123 string16 ToString(const DictionaryValue& node, const string16& indent); | 86 string16 ToString(BrowserAccessibility* node, char* prefix); |
124 | 87 |
125 void Initialize(); | 88 void Initialize(); |
126 | 89 |
127 bool MatchesFilters(const string16& text, bool default_result) const; | 90 bool MatchesFilters(const string16& text, bool default_result) const; |
| 91 void StartLine(); |
| 92 void Add(bool include_by_default, const string16& attr); |
| 93 string16 FinishLine(); |
128 | 94 |
129 // Writes the given attribute string out to |line| if it matches the filters. | 95 BrowserAccessibility* node_; |
130 void WriteAttribute(bool include_by_default, | |
131 const string16& attr, | |
132 string16* line); | |
133 void WriteAttribute(bool include_by_default, | |
134 const std::string& attr, | |
135 string16* line); | |
136 | |
137 BrowserAccessibility* root_; | |
138 | |
139 // Filters used when formatting the accessibility tree as text. | |
140 std::vector<Filter> filters_; | 96 std::vector<Filter> filters_; |
| 97 string16 line_; |
141 | 98 |
142 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter); | 99 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter); |
143 }; | 100 }; |
144 | 101 |
145 } // namespace content | 102 } // namespace content |
146 | 103 |
147 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ | 104 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ |
OLD | NEW |