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
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_ACCESSIBILITY_PLATFORM_INSPECT_AX_TREE_FORMATTER_H_
#define UI_ACCESSIBILITY_PLATFORM_INSPECT_AX_TREE_FORMATTER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/component_export.h"
#include "base/values.h"
#include "ui/accessibility/platform/inspect/ax_inspect.h"
#include "ui/gfx/native_widget_types.h"
namespace ui {
class AXNode;
class AXScriptInstruction;
class AXTreeID;
class AXPlatformNodeDelegate;
class AXInspectScenario;
// 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 COMPONENT_EXPORT(AX_PLATFORM) AXTreeFormatter {
public:
using AXTreeSelector = ui::AXTreeSelector;
using AXPropertyFilter = ui::AXPropertyFilter;
using AXNodeFilter = ui::AXNodeFilter;
virtual ~AXTreeFormatter() = default;
// Returns true if the given text matches |allow| property filters, or false
// if matches |deny| filter. Returns default value if doesn't match any
// property filters.
static bool MatchesPropertyFilters(
const std::vector<AXPropertyFilter>& property_filters,
const std::string& text,
bool default_result);
// Check if the given dictionary matches any of the supplied AXNodeFilter(s).
static bool MatchesNodeFilters(const std::vector<AXNodeFilter>& node_filters,
const base::Value::Dict& dict);
// Formats a given web content accessible tree.
// |root| must be non-null and must be in web content.
virtual std::string Format(AXPlatformNodeDelegate* root) const = 0;
// Formats an accessible tree identified by the given selector.
virtual std::string Format(const AXTreeSelector&) const = 0;
// Formats a given web node (i.e. without children).
virtual std::string FormatNode(AXPlatformNodeDelegate* node) const = 0;
// Formats an accessible element specified by the given selector.
virtual std::string FormatNode(const AXTreeSelector&) const = 0;
// Similar to BuildTree, but generates a dictionary just for the current
// web node (i.e. without children).
virtual base::Value::Dict BuildNode(AXPlatformNodeDelegate* node) const = 0;
virtual base::Value::Dict BuildNodeForSelector(
const AXTreeSelector&) const = 0;
// Build an accessibility tree for any window or pattern supplied by
// the selector object.
//
// Returns a dictionary value with the accessibility tree populated.
// The dictionary contains a key/value pair for each attribute of a 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": [ ]
// } ]
// }
virtual base::Value::Dict BuildTreeForSelector(
const AXTreeSelector&) const = 0;
// Build an accessibility tree for an application with |node| as the root.
virtual base::Value::Dict BuildTreeForNode(AXNode* node) const = 0;
// Returns a string representing the internal tree represented by |tree_id|.
virtual std::string DumpInternalAccessibilityTree(
AXTreeID tree_id,
const std::vector<AXPropertyFilter>& property_filters) = 0;
// Dumps accessibility tree.
virtual std::string FormatTree(const base::Value::Dict& tree_node) const = 0;
// Evaluates script instructions for the window returned by the selector.
virtual std::string EvaluateScript(
const AXTreeSelector& selector,
const AXInspectScenario& scenario) const = 0;
// Evaluates script instructions between the given indices.
virtual std::string EvaluateScript(
AXPlatformNodeDelegate* root,
const std::vector<AXScriptInstruction>& instructions,
size_t start_index,
size_t end_index) const = 0;
// Property filter predefined sets.
enum PropertyFilterSet {
// Empty set.
kFiltersEmptySet,
// Default filters set, defined by a formatter.
kFiltersDefaultSet,
};
// Set regular expression filters that apply to each property of every node
// before it's output. If a default filter set is given, then filters defined
// by the set are preappended to the given property filters.
virtual void SetPropertyFilters(
const std::vector<AXPropertyFilter>& property_filters,
PropertyFilterSet default_filters_set = kFiltersEmptySet) = 0;
// Set regular expression filters that apply to every node before output.
virtual void SetNodeFilters(
const std::vector<AXNodeFilter>& node_filters) = 0;
// If true, the internal accessibility id of each node will be included
// in its output.
virtual void set_show_ids(bool show_ids) = 0;
};
} // namespace ui
#endif // UI_ACCESSIBILITY_PLATFORM_INSPECT_AX_TREE_FORMATTER_H_
|