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