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" |
13 #include "content/browser/accessibility/browser_accessibility.h" | 14 #include "content/browser/accessibility/browser_accessibility.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 class RenderViewHost; | 19 class RenderViewHost; |
19 | 20 |
20 // A utility class for formatting platform-specific accessibility information, | 21 // A utility class for formatting platform-specific accessibility information, |
21 // for use in testing, debugging, and developer tools. | 22 // for use in testing, debugging, and developer tools. |
22 // 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 |
23 // implemented. | 24 // implemented. |
24 class CONTENT_EXPORT AccessibilityTreeFormatter { | 25 class CONTENT_EXPORT AccessibilityTreeFormatter { |
25 public: | 26 public: |
26 explicit AccessibilityTreeFormatter(BrowserAccessibility* node); | 27 explicit AccessibilityTreeFormatter(BrowserAccessibility* root); |
27 virtual ~AccessibilityTreeFormatter(); | 28 virtual ~AccessibilityTreeFormatter(); |
28 | 29 |
29 static AccessibilityTreeFormatter* Create(RenderViewHost* rvh); | 30 static AccessibilityTreeFormatter* Create(RenderViewHost* rvh); |
30 | 31 |
| 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 |
31 // Dumps a BrowserAccessibility tree into a string. | 54 // Dumps a BrowserAccessibility tree into a string. |
32 void FormatAccessibilityTree(string16* contents); | 55 void FormatAccessibilityTree(string16* contents); |
33 | 56 |
34 // A single filter specification. See GetAllowString() and GetDenyString() | 57 // A single filter specification. See GetAllowString() and GetDenyString() |
35 // for more information. | 58 // for more information. |
36 struct Filter { | 59 struct Filter { |
37 enum Type { | 60 enum Type { |
38 ALLOW, | 61 ALLOW, |
39 ALLOW_EMPTY, | 62 ALLOW_EMPTY, |
40 DENY | 63 DENY |
(...skipping 28 matching lines...) Expand all Loading... |
69 // @MAC-ALLOW-EMPTY:description* | 92 // @MAC-ALLOW-EMPTY:description* |
70 // @MAC-ALLOW:roleDescription* | 93 // @MAC-ALLOW:roleDescription* |
71 // @MAC-DENY:subrole* | 94 // @MAC-DENY:subrole* |
72 // --> | 95 // --> |
73 // <p>Text</p> | 96 // <p>Text</p> |
74 static const std::string GetAllowEmptyString(); | 97 static const std::string GetAllowEmptyString(); |
75 static const std::string GetAllowString(); | 98 static const std::string GetAllowString(); |
76 static const std::string GetDenyString(); | 99 static const std::string GetDenyString(); |
77 | 100 |
78 protected: | 101 protected: |
79 void RecursiveFormatAccessibilityTree(BrowserAccessibility* node, | 102 void RecursiveFormatAccessibilityTree(const BrowserAccessibility& node, |
80 string16* contents, | 103 string16* contents, |
81 int indent); | 104 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); |
82 | 119 |
83 // Returns a platform specific representation of a BrowserAccessibility. | 120 // Returns a platform specific representation of a BrowserAccessibility. |
84 // Should be zero or more complete lines, each with |prefix| prepended | 121 // Should be zero or more complete lines, each with |prefix| prepended |
85 // (to indent each line). | 122 // (to indent each line). |
86 string16 ToString(BrowserAccessibility* node, char* prefix); | 123 string16 ToString(const DictionaryValue& node, const string16& indent); |
87 | 124 |
88 void Initialize(); | 125 void Initialize(); |
89 | 126 |
90 bool MatchesFilters(const string16& text, bool default_result) const; | 127 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(); | |
94 | 128 |
95 BrowserAccessibility* node_; | 129 // Writes the given attribute string out to |line| if it matches the filters. |
| 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. |
96 std::vector<Filter> filters_; | 140 std::vector<Filter> filters_; |
97 string16 line_; | |
98 | 141 |
99 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter); | 142 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter); |
100 }; | 143 }; |
101 | 144 |
102 } // namespace content | 145 } // namespace content |
103 | 146 |
104 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ | 147 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ |
OLD | NEW |