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