1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_
#define CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_
#include <vector>
#include "base/files/file_path.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "content/browser/accessibility/browser_accessibility.h"
#include "content/common/content_export.h"
namespace content {
class WebContents;
// A utility class for formatting platform-specific accessibility information,
// for use in testing, debugging, and developer tools.
// This is extended by a subclass for each platform where accessibility is
// implemented.
class CONTENT_EXPORT AccessibilityTreeFormatter {
public:
explicit AccessibilityTreeFormatter(BrowserAccessibility* root);
virtual ~AccessibilityTreeFormatter();
// A single filter specification. See GetAllowString() and GetDenyString()
// for more information.
struct Filter {
enum Type {
ALLOW,
ALLOW_EMPTY,
DENY
};
base::string16 match_str;
Type type;
Filter(base::string16 match_str, Type type)
: match_str(match_str), type(type) {}
};
static AccessibilityTreeFormatter* Create(WebContents* wc);
static bool MatchesFilters(
const std::vector<Filter>& filters,
const base::string16& text,
bool default_result);
// Populates the given DictionaryValue with the accessibility tree.
// The dictionary contains a key/value pair for each attribute of the node,
// plus a "children" attribute containing a list of all child nodes.
// {
// "AXName": "node", /* actual attributes will vary by platform */
// "position": { /* some attributes may be dictionaries */
// "x": 0,
// "y": 0
// },
// /* ... more attributes of |node| */
// "children": [ { /* list of children created recursively */
// "AXName": "child node 1",
// /* ... more attributes */
// "children": [ ]
// }, {
// "AXName": "child name 2",
// /* ... more attributes */
// "children": [ ]
// } ]
// }
scoped_ptr<base::DictionaryValue> BuildAccessibilityTree();
// Dumps a BrowserAccessibility tree into a string.
void FormatAccessibilityTree(base::string16* contents);
// Set regular expression filters that apply to each component of every
// line before it's output.
void SetFilters(const std::vector<Filter>& filters);
// If true, the internal accessibility id of each node will be included
// in its output.
void set_show_ids(bool show_ids) { show_ids_ = show_ids; }
// Suffix of the expectation file corresponding to html file.
// Example:
// HTML test: test-file.html
// Expected: test-file-expected-mac.txt.
// Auto-generated: test-file-actual-mac.txt
static const base::FilePath::StringType GetActualFileSuffix();
static const base::FilePath::StringType GetExpectedFileSuffix();
// A platform-specific string that indicates a given line in a file
// is an allow-empty, allow or deny filter. Example:
// Mac values:
// GetAllowEmptyString() -> "@MAC-ALLOW-EMPTY:"
// GetAllowString() -> "@MAC-ALLOW:"
// GetDenyString() -> "@MAC-DENY:"
// Example html:
// <!--
// @MAC-ALLOW-EMPTY:description*
// @MAC-ALLOW:roleDescription*
// @MAC-DENY:subrole*
// -->
// <p>Text</p>
static const std::string GetAllowEmptyString();
static const std::string GetAllowString();
static const std::string GetDenyString();
protected:
void RecursiveFormatAccessibilityTree(const BrowserAccessibility& node,
base::string16* contents,
int indent);
void RecursiveBuildAccessibilityTree(const BrowserAccessibility& node,
base::DictionaryValue* tree_node);
void RecursiveFormatAccessibilityTree(const base::DictionaryValue& tree_node,
base::string16* contents,
int depth = 0);
// Overridden by each platform to add the required attributes for each node
// into the given dict.
void AddProperties(const BrowserAccessibility& node,
base::DictionaryValue* dict);
base::string16 FormatCoordinates(const char* name,
const char* x_name,
const char* y_name,
const base::DictionaryValue& value);
// Returns a platform specific representation of a BrowserAccessibility.
base::string16 ToString(const base::DictionaryValue& node);
void Initialize();
bool MatchesFilters(const base::string16& text, bool default_result) const;
// Writes the given attribute string out to |line| if it matches the filters.
void WriteAttribute(bool include_by_default,
const base::string16& attr,
base::string16* line);
void WriteAttribute(bool include_by_default,
const std::string& attr,
base::string16* line);
BrowserAccessibility* root_;
// Filters used when formatting the accessibility tree as text.
std::vector<Filter> filters_;
// Whether or not node ids should be included in the dump.
bool show_ids_;
DISALLOW_COPY_AND_ASSIGN(AccessibilityTreeFormatter);
};
} // namespace content
#endif // CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_H_
|