Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ax_node_data.h
Go to the documentation of this file.
1// Copyright 2013 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 UI_ACCESSIBILITY_AX_NODE_DATA_H_
6#define UI_ACCESSIBILITY_AX_NODE_DATA_H_
7
8#include <cstdint>
9#include <map>
10#include <memory>
11#include <string>
12#include <utility>
13#include <vector>
14
15#include "ax_base_export.h"
16#include "ax_enums.h"
17#include "ax_node_text_styles.h"
18#include "ax_relative_bounds.h"
19
20namespace ui {
21
22// Return true if |attr| should be interpreted as the id of another node
23// in the same tree.
25
26// Return true if |attr| should be interpreted as a list of ids of
27// nodes in the same tree.
29
30// A compact representation of the accessibility information for a
31// single accessible object, in a form that can be serialized and sent from
32// one process to another.
34 // Defines the type used for AXNode IDs.
35 using AXID = int32_t;
36
37 AXNodeData();
38 virtual ~AXNodeData();
39
40 AXNodeData(const AXNodeData& other);
41 AXNodeData(AXNodeData&& other);
42 AXNodeData& operator=(AXNodeData other);
43
44 // Accessing accessibility attributes:
45 //
46 // There are dozens of possible attributes for an accessibility node,
47 // but only a few tend to apply to any one object, so we store them
48 // in sparse arrays of <attribute id, attribute value> pairs, organized
49 // by type (bool, int, float, string, int list).
50 //
51 // There are three accessors for each type of attribute: one that returns
52 // true if the attribute is present and false if not, one that takes a
53 // pointer argument and returns true if the attribute is present (if you
54 // need to distinguish between the default value and a missing attribute),
55 // and another that returns the default value for that type if the
56 // attribute is not present. In addition, strings can be returned as
57 // either std::string or std::u16string, for convenience.
58
59 bool HasBoolAttribute(ax::mojom::BoolAttribute attribute) const;
60 bool GetBoolAttribute(ax::mojom::BoolAttribute attribute) const;
61 bool GetBoolAttribute(ax::mojom::BoolAttribute attribute, bool* value) const;
62
63 bool HasFloatAttribute(ax::mojom::FloatAttribute attribute) const;
64 float GetFloatAttribute(ax::mojom::FloatAttribute attribute) const;
65 bool GetFloatAttribute(ax::mojom::FloatAttribute attribute,
66 float* value) const;
67
68 bool HasIntAttribute(ax::mojom::IntAttribute attribute) const;
69 int GetIntAttribute(ax::mojom::IntAttribute attribute) const;
70 bool GetIntAttribute(ax::mojom::IntAttribute attribute, int* value) const;
71
72 bool HasStringAttribute(ax::mojom::StringAttribute attribute) const;
73 const std::string& GetStringAttribute(
74 ax::mojom::StringAttribute attribute) const;
75 bool GetStringAttribute(ax::mojom::StringAttribute attribute,
76 std::string* value) const;
77
78 bool GetString16Attribute(ax::mojom::StringAttribute attribute,
79 std::u16string* value) const;
80 std::u16string GetString16Attribute(
81 ax::mojom::StringAttribute attribute) const;
82
83 bool HasIntListAttribute(ax::mojom::IntListAttribute attribute) const;
84 const std::vector<int32_t>& GetIntListAttribute(
85 ax::mojom::IntListAttribute attribute) const;
86 bool GetIntListAttribute(ax::mojom::IntListAttribute attribute,
87 std::vector<int32_t>* value) const;
88
89 bool HasStringListAttribute(ax::mojom::StringListAttribute attribute) const;
90 const std::vector<std::string>& GetStringListAttribute(
91 ax::mojom::StringListAttribute attribute) const;
92 bool GetStringListAttribute(ax::mojom::StringListAttribute attribute,
93 std::vector<std::string>* value) const;
94 bool GetHtmlAttribute(const char* attribute, std::u16string* value) const;
95 bool GetHtmlAttribute(const char* attribute, std::string* value) const;
96
97 //
98 // Setting accessibility attributes.
99 //
100 // Replaces an attribute if present. This is safer than crashing via a
101 // BASE_DCHECK or doing nothing, because most likely replacing is what the
102 // caller would have wanted or what existing code already assumes.
103 //
104
105 void AddStringAttribute(ax::mojom::StringAttribute attribute,
106 const std::string& value);
107 void AddIntAttribute(ax::mojom::IntAttribute attribute, int32_t value);
108 void AddFloatAttribute(ax::mojom::FloatAttribute attribute, float value);
109 void AddBoolAttribute(ax::mojom::BoolAttribute attribute, bool value);
110 void AddIntListAttribute(ax::mojom::IntListAttribute attribute,
111 const std::vector<int32_t>& value);
112 void AddStringListAttribute(ax::mojom::StringListAttribute attribute,
113 const std::vector<std::string>& value);
114
115 //
116 // Removing accessibility attributes.
117 //
118
119 void RemoveStringAttribute(ax::mojom::StringAttribute attribute);
120 void RemoveIntAttribute(ax::mojom::IntAttribute attribute);
121 void RemoveFloatAttribute(ax::mojom::FloatAttribute attribute);
122 void RemoveBoolAttribute(ax::mojom::BoolAttribute attribute);
123 void RemoveIntListAttribute(ax::mojom::IntListAttribute attribute);
124 void RemoveStringListAttribute(ax::mojom::StringListAttribute attribute);
125
126 //
127 // Text styles.
128 //
129 AXNodeTextStyles GetTextStyles() const;
130
131 //
132 // Convenience functions.
133 //
134
135 // Adds the name attribute or replaces it if already present. Also sets the
136 // NameFrom attribute if not already set.
137 void SetName(const std::string& name);
138 void SetName(const std::u16string& name);
139
140 // Allows nameless objects to pass accessibility checks.
141 void SetNameExplicitlyEmpty();
142
143 // Adds the description attribute or replaces it if already present.
144 void SetDescription(const std::string& description);
145 void SetDescription(const std::u16string& description);
146
147 // Adds the value attribute or replaces it if already present.
148 void SetValue(const std::string& value);
149 void SetValue(const std::u16string& value);
150
151 // Adds the tooltip attribute or replaces it if already present.
152 void SetTooltip(const std::string& value);
153 void SetTooltip(const std::u16string& value);
154
155 // Returns true if the given enum bit is 1.
156 bool HasState(ax::mojom::State state) const;
157 bool HasAction(ax::mojom::Action action) const;
158 bool HasTextStyle(ax::mojom::TextStyle text_style) const;
159 // aria-dropeffect is deprecated in WAI-ARIA 1.1.
160 bool HasDropeffect(ax::mojom::Dropeffect dropeffect) const;
161
162 // Set or remove bits in the given enum's corresponding bitfield.
163 void AddState(ax::mojom::State state);
164 void RemoveState(ax::mojom::State state);
165 void AddAction(ax::mojom::Action action);
166 void AddTextStyle(ax::mojom::TextStyle text_style);
167 // aria-dropeffect is deprecated in WAI-ARIA 1.1.
168 void AddDropeffect(ax::mojom::Dropeffect dropeffect);
169
170 // Helper functions to get or set some common int attributes with some
171 // specific enum types. To remove an attribute, set it to None.
172 //
173 // Please keep in alphabetic order.
174 ax::mojom::CheckedState GetCheckedState() const;
175 void SetCheckedState(ax::mojom::CheckedState checked_state);
176 bool HasCheckedState() const;
177 ax::mojom::DefaultActionVerb GetDefaultActionVerb() const;
178 void SetDefaultActionVerb(ax::mojom::DefaultActionVerb default_action_verb);
179 ax::mojom::HasPopup GetHasPopup() const;
180 void SetHasPopup(ax::mojom::HasPopup has_popup);
181 ax::mojom::InvalidState GetInvalidState() const;
182 void SetInvalidState(ax::mojom::InvalidState invalid_state);
183 ax::mojom::NameFrom GetNameFrom() const;
184 void SetNameFrom(ax::mojom::NameFrom name_from);
185 ax::mojom::DescriptionFrom GetDescriptionFrom() const;
186 void SetDescriptionFrom(ax::mojom::DescriptionFrom description_from);
187 ax::mojom::TextPosition GetTextPosition() const;
188 void SetTextPosition(ax::mojom::TextPosition text_position);
189 ax::mojom::Restriction GetRestriction() const;
190 void SetRestriction(ax::mojom::Restriction restriction);
191 ax::mojom::ListStyle GetListStyle() const;
192 void SetListStyle(ax::mojom::ListStyle list_style);
193 ax::mojom::TextAlign GetTextAlign() const;
194 void SetTextAlign(ax::mojom::TextAlign text_align);
195 ax::mojom::WritingDirection GetTextDirection() const;
196 void SetTextDirection(ax::mojom::WritingDirection text_direction);
197 ax::mojom::ImageAnnotationStatus GetImageAnnotationStatus() const;
198 void SetImageAnnotationStatus(ax::mojom::ImageAnnotationStatus status);
199
200 // Helper to determine if the data belongs to a node that gains focus when
201 // clicked, such as a text field or a native HTML list box.
202 bool IsActivatable() const;
203
204 // Helper to determine if the data belongs to a node that is a native button
205 // or ARIA role="button" in a pressed state.
206 bool IsButtonPressed() const;
207
208 // Helper to determine if the data belongs to a node that can respond to
209 // clicks.
210 bool IsClickable() const;
211
212 // Helper to determine if the object is selectable.
213 bool IsSelectable() const;
214
215 // Helper to determine if the data has the ignored state or ignored role.
216 bool IsIgnored() const;
217
218 // Helper to determine if the data has the invisible state.
219 bool IsInvisible() const;
220
221 // Helper to determine if the data has the ignored state, the invisible state
222 // or the ignored role.
223 bool IsInvisibleOrIgnored() const;
224
225 // Helper to determine if the data belongs to a node that is invocable.
226 bool IsInvocable() const;
227
228 // Helper to determine if the data belongs to a node that is a menu button.
229 bool IsMenuButton() const;
230
231 // This data belongs to a text field. This is any widget in which the user
232 // should be able to enter and edit text.
233 //
234 // Examples include <input type="text">, <input type="password">, <textarea>,
235 // <div contenteditable="true">, <div role="textbox">, <div role="searchbox">
236 // and <div role="combobox">. Note that when an ARIA role that indicates that
237 // the widget is editable is used, such as "role=textbox", the element doesn't
238 // need to be contenteditable for this method to return true, as in theory
239 // JavaScript could be used to implement editing functionality. In practice,
240 // this situation should be rare.
241 bool IsTextField() const;
242
243 // This data belongs to a text field that is used for entering passwords.
244 bool IsPasswordField() const;
245
246 // This data belongs to a text field that doesn't accept rich text content,
247 // such as text with special formatting or styling.
248 bool IsPlainTextField() const;
249
250 // This data belongs to a text field that accepts rich text content, such as
251 // text with special formatting or styling.
252 bool IsRichTextField() const;
253
254 // Helper to determine if |GetRestriction| is either ReadOnly or Disabled.
255 // By default, all nodes that can't be edited are readonly.
256 bool IsReadOnlyOrDisabled() const;
257
258 // Helper to determine if the data belongs to a node that supports
259 // range-based value.
260 bool IsRangeValueSupported() const;
261
262 // Helper to determine if the data belongs to a node that supports
263 // expand/collapse.
264 bool SupportsExpandCollapse() const;
265
266 // Return a string representation of this data, for debugging.
267 virtual std::string ToString() const;
268
269 // Return a string representation of |aria-dropeffect| values, for testing
270 // and debugging.
271 // aria-dropeffect is deprecated in WAI-ARIA 1.1.
272 std::string DropeffectBitfieldToString() const;
273
274 // As much as possible this should behave as a simple, serializable,
275 // copyable struct.
276 int32_t id = -1;
278 uint32_t state;
279 uint64_t actions;
280 std::vector<std::pair<ax::mojom::StringAttribute, std::string>>
282 std::vector<std::pair<ax::mojom::IntAttribute, int32_t>> int_attributes;
283 std::vector<std::pair<ax::mojom::FloatAttribute, float>> float_attributes;
284 std::vector<std::pair<ax::mojom::BoolAttribute, bool>> bool_attributes;
285 std::vector<std::pair<ax::mojom::IntListAttribute, std::vector<int32_t>>>
287 std::vector<
288 std::pair<ax::mojom::StringListAttribute, std::vector<std::string>>>
290 std::vector<std::pair<std::string, std::string>> html_attributes;
291 std::vector<int32_t> child_ids;
292
294};
295
296} // namespace ui
297
298#endif // UI_ACCESSIBILITY_AX_NODE_DATA_H_
#define AX_BASE_EXPORT
AtkStateType state
const char * name
Definition fuchsia.cc:50
StringListAttribute
Definition ax_enums.h:850
ImageAnnotationStatus
Definition ax_enums.h:1170
DefaultActionVerb
Definition ax_enums.h:489
bool IsNodeIdIntAttribute(ax::mojom::IntAttribute attr)
bool IsRangeValueSupported(const ax::mojom::Role role)
const char * ToString(ax::mojom::Event event)
bool SupportsExpandCollapse(const ax::mojom::Role role)
bool IsNodeIdIntListAttribute(ax::mojom::IntListAttribute attr)
bool IsClickable(const ax::mojom::Role role)
AXRelativeBounds relative_bounds
std::vector< std::pair< ax::mojom::FloatAttribute, float > > float_attributes
virtual ~AXNodeData()
std::vector< int32_t > child_ids
std::vector< std::pair< ax::mojom::IntAttribute, int32_t > > int_attributes
std::vector< std::pair< ax::mojom::IntListAttribute, std::vector< int32_t > > > intlist_attributes
std::vector< std::pair< ax::mojom::StringAttribute, std::string > > string_attributes
std::vector< std::pair< std::string, std::string > > html_attributes
std::vector< std::pair< ax::mojom::StringListAttribute, std::vector< std::string > > > stringlist_attributes
ax::mojom::Role role
std::vector< std::pair< ax::mojom::BoolAttribute, bool > > bool_attributes