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_DUMP_ACCESSIBILITY_TREE_HELPER_H_ | 5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ |
6 #define CONTENT_BROWSER_ACCESSIBILITY_DUMP_ACCESSIBILITY_TREE_HELPER_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 "content/browser/accessibility/browser_accessibility.h" | 13 #include "content/browser/accessibility/browser_accessibility.h" |
| 14 #include "content/common/content_export.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 // A utility class for retrieving platform specific accessibility information. | 18 class RenderViewHost; |
| 19 |
| 20 // A utility class for formatting platform-specific accessibility information, |
| 21 // for use in testing, debugging, and developer tools. |
18 // 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 |
19 // implemented. | 23 // implemented. |
20 class DumpAccessibilityTreeHelper { | 24 class CONTENT_EXPORT AccessibilityTreeFormatter { |
21 public: | 25 public: |
22 DumpAccessibilityTreeHelper(); | 26 explicit AccessibilityTreeFormatter(BrowserAccessibility* node); |
23 virtual ~DumpAccessibilityTreeHelper(); | 27 virtual ~AccessibilityTreeFormatter(); |
| 28 |
| 29 static AccessibilityTreeFormatter* Create(RenderViewHost* rvh); |
24 | 30 |
25 // Dumps a BrowserAccessibility tree into a string. | 31 // Dumps a BrowserAccessibility tree into a string. |
26 void DumpAccessibilityTree(BrowserAccessibility* node, | 32 void FormatAccessibilityTree(string16* contents); |
27 string16* contents); | |
28 | 33 |
29 // A single filter specification. See GetAllowString() and GetDenyString() | 34 // A single filter specification. See GetAllowString() and GetDenyString() |
30 // for more information. | 35 // for more information. |
31 struct Filter { | 36 struct Filter { |
32 enum Type { | 37 enum Type { |
33 ALLOW, | 38 ALLOW, |
34 ALLOW_EMPTY, | 39 ALLOW_EMPTY, |
35 DENY | 40 DENY |
36 }; | 41 }; |
37 string16 match_str; | 42 string16 match_str; |
38 Type type; | 43 Type type; |
39 | 44 |
40 Filter(string16 match_str, Type type) | 45 Filter(string16 match_str, Type type) |
41 : match_str(match_str), type(type) {} | 46 : match_str(match_str), type(type) {} |
42 }; | 47 }; |
43 | 48 |
44 // Set regular expression filters that apply to each component of every | 49 // Set regular expression filters that apply to each component of every |
45 // line before it's output. | 50 // line before it's output. |
46 void SetFilters(const std::vector<Filter>& filters); | 51 void SetFilters(const std::vector<Filter>& filters); |
47 | 52 |
48 // Suffix of the expectation file corresponding to html file. | 53 // Suffix of the expectation file corresponding to html file. |
49 // Example: | 54 // Example: |
50 // HTML test: test-file.html | 55 // HTML test: test-file.html |
51 // Expected: test-file-expected-mac.txt. | 56 // Expected: test-file-expected-mac.txt. |
52 // Auto-generated: test-file-actual-mac.txt | 57 // Auto-generated: test-file-actual-mac.txt |
53 const base::FilePath::StringType GetActualFileSuffix() const; | 58 static const base::FilePath::StringType GetActualFileSuffix(); |
54 const base::FilePath::StringType GetExpectedFileSuffix() const; | 59 static const base::FilePath::StringType GetExpectedFileSuffix(); |
55 | 60 |
56 // A platform-specific string that indicates a given line in a file | 61 // A platform-specific string that indicates a given line in a file |
57 // is an allow-empty, allow or deny filter. Example: | 62 // is an allow-empty, allow or deny filter. Example: |
58 // Mac values: | 63 // Mac values: |
59 // GetAllowEmptyString() -> "@MAC-ALLOW-EMPTY:" | 64 // GetAllowEmptyString() -> "@MAC-ALLOW-EMPTY:" |
60 // GetAllowString() -> "@MAC-ALLOW:" | 65 // GetAllowString() -> "@MAC-ALLOW:" |
61 // GetDenyString() -> "@MAC-DENY:" | 66 // GetDenyString() -> "@MAC-DENY:" |
62 // Example html: | 67 // Example html: |
63 // <!-- | 68 // <!-- |
64 // @MAC-ALLOW-EMPTY:description* | 69 // @MAC-ALLOW-EMPTY:description* |
65 // @MAC-ALLOW:roleDescription* | 70 // @MAC-ALLOW:roleDescription* |
66 // @MAC-DENY:subrole* | 71 // @MAC-DENY:subrole* |
67 // --> | 72 // --> |
68 // <p>Text</p> | 73 // <p>Text</p> |
69 const std::string GetAllowEmptyString() const; | 74 static const std::string GetAllowEmptyString(); |
70 const std::string GetAllowString() const; | 75 static const std::string GetAllowString(); |
71 const std::string GetDenyString() const; | 76 static const std::string GetDenyString(); |
72 | 77 |
73 protected: | 78 protected: |
74 void RecursiveDumpAccessibilityTree(BrowserAccessibility* node, | 79 void RecursiveFormatAccessibilityTree(BrowserAccessibility* node, |
75 string16* contents, | 80 string16* contents, |
76 int indent); | 81 int indent); |
77 | 82 |
78 // Returns a platform specific representation of a BrowserAccessibility. | 83 // Returns a platform specific representation of a BrowserAccessibility. |
79 // Should be zero or more complete lines, each with |prefix| prepended | 84 // Should be zero or more complete lines, each with |prefix| prepended |
80 // (to indent each line). | 85 // (to indent each line). |
81 string16 ToString(BrowserAccessibility* node, char* prefix); | 86 string16 ToString(BrowserAccessibility* node, char* prefix); |
82 | 87 |
83 void Initialize(); | 88 void Initialize(); |
84 | 89 |
85 bool MatchesFilters(const string16& text, bool default_result); | 90 bool MatchesFilters(const string16& text, bool default_result) const; |
86 void StartLine(); | 91 void StartLine(); |
87 void Add(bool include_by_default, const string16& attr); | 92 void Add(bool include_by_default, const string16& attr); |
88 string16 FinishLine(); | 93 string16 FinishLine(); |
89 | 94 |
| 95 BrowserAccessibility* node_; |
90 std::vector<Filter> filters_; | 96 std::vector<Filter> filters_; |
91 string16 line_; | 97 string16 line_; |
92 | 98 |
93 DISALLOW_COPY_AND_ASSIGN(DumpAccessibilityTreeHelper); | 99 DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter); |
94 }; | 100 }; |
95 | 101 |
96 } // namespace content | 102 } // namespace content |
97 | 103 |
98 #endif // CONTENT_BROWSER_ACCESSIBILITY_DUMP_ACCESSIBILITY_TREE_HELPER_H_ | 104 #endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_ |
OLD | NEW |