Flutter Engine
The Flutter Engine
ax_platform_node_delegate_base.h
Go to the documentation of this file.
1// Copyright 2014 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_PLATFORM_AX_PLATFORM_NODE_DELEGATE_BASE_H_
6#define UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_DELEGATE_BASE_H_
7
8#include <cstdint>
9#include <memory>
10#include <set>
11#include <string>
12#include <vector>
13
15
16namespace ui {
17
18// Base implementation of AXPlatformNodeDelegate where all functions
19// return a default value. Useful for classes that want to implement
20// AXPlatformNodeDelegate but don't need to override much of its
21// behavior.
23 public:
26
27 // Get the accessibility data that should be exposed for this node.
28 // Virtually all of the information is obtained from this structure
29 // (role, state, name, cursor position, etc.) - the rest of this interface
30 // is mostly to implement support for walking the accessibility tree.
31 const AXNodeData& GetData() const override;
32
33 // Get the accessibility tree data for this node.
34 const AXTreeData& GetTreeData() const override;
35
36 std::u16string GetInnerText() const override;
37 const AXTree::Selection GetUnignoredSelection() const override;
38
39 // Creates a text position rooted at this object.
40 AXNodePosition::AXPositionInstance CreateTextPositionAt(
41 int offset) const override;
42
43 // See comments in AXPlatformNodeDelegate.
44 gfx::NativeViewAccessible GetNSWindow() override;
45
46 // Get the node for this delegate, which may be an AXPlatformNode or it may
47 // be a native accessible object implemented by another class.
48 gfx::NativeViewAccessible GetNativeViewAccessible() override;
49
50 // Get the parent of the node, which may be an AXPlatformNode or it may
51 // be a native accessible object implemented by another class.
52 gfx::NativeViewAccessible GetParent() override;
53
54 // If this object is exposed to the platform's accessibility layer, returns
55 // this object. Otherwise, returns the platform leaf or lowest unignored
56 // ancestor under which this object is found.
57 //
58 // (An ignored node means that the node should not be exposed to platform
59 // APIs: See `IsIgnored`.)
60 gfx::NativeViewAccessible GetLowestPlatformAncestor() const override;
61
62 // Get the index in parent. Typically this is the AXNode's index_in_parent_.
63 int GetIndexInParent() override;
64
65 // Get the number of children of this node.
66 int GetChildCount() const override;
67
68 // Get the child of a node given a 0-based index.
69 gfx::NativeViewAccessible ChildAtIndex(int index) override;
70
71 // Returns true if it has a modal dialog.
72 bool HasModalDialog() const override;
73
74 gfx::NativeViewAccessible GetFirstChild() override;
75 gfx::NativeViewAccessible GetLastChild() override;
76 gfx::NativeViewAccessible GetNextSibling() override;
77 gfx::NativeViewAccessible GetPreviousSibling() override;
78
79 bool IsChildOfLeaf() const override;
80 bool IsChildOfPlainTextField() const override;
81 bool IsLeaf() const override;
82 bool IsToplevelBrowserWindow() override;
83 gfx::NativeViewAccessible GetClosestPlatformObject() const override;
84
86 public:
89 ~ChildIteratorBase() override = default;
90 bool operator==(const ChildIterator& rhs) const override;
91 bool operator!=(const ChildIterator& rhs) const override;
92 void operator++() override;
93 void operator++(int) override;
94 void operator--() override;
95 void operator--(int) override;
96 gfx::NativeViewAccessible GetNativeViewAccessible() const override;
97 int GetIndexInParent() const override;
98 AXPlatformNodeDelegate& operator*() const override;
99 AXPlatformNodeDelegate* operator->() const override;
100
101 private:
102 int index_;
104 };
105 std::unique_ptr<AXPlatformNodeDelegate::ChildIterator> ChildrenBegin()
106 override;
107 std::unique_ptr<AXPlatformNodeDelegate::ChildIterator> ChildrenEnd() override;
108
109 std::string GetName() const override;
110 std::u16string GetHypertext() const override;
111 bool SetHypertextSelection(int start_offset, int end_offset) override;
112 TextAttributeMap ComputeTextAttributeMap(
113 const TextAttributeList& default_attributes) const override;
114 std::string GetInheritedFontFamilyName() const override;
115
116 gfx::Rect GetBoundsRect(const AXCoordinateSystem coordinate_system,
117 const AXClippingBehavior clipping_behavior,
118 AXOffscreenResult* offscreen_result) const override;
119
120 gfx::Rect GetHypertextRangeBoundsRect(
121 const int start_offset,
122 const int end_offset,
123 const AXCoordinateSystem coordinate_system,
124 const AXClippingBehavior clipping_behavior,
125 AXOffscreenResult* offscreen_result) const override;
126
127 gfx::Rect GetInnerTextRangeBoundsRect(
128 const int start_offset,
129 const int end_offset,
130 const AXCoordinateSystem coordinate_system,
131 const AXClippingBehavior clipping_behavior,
132 AXOffscreenResult* offscreen_result) const override;
133
134 // Derivative utils for AXPlatformNodeDelegate::GetBoundsRect
135 gfx::Rect GetClippedScreenBoundsRect(
136 AXOffscreenResult* offscreen_result = nullptr) const override;
137 gfx::Rect GetUnclippedScreenBoundsRect(
138 AXOffscreenResult* offscreen_result = nullptr) const;
139
140 // Do a *synchronous* hit test of the given location in global screen physical
141 // pixel coordinates, and the node within this node's subtree (inclusive)
142 // that's hit, if any.
143 //
144 // If the result is anything other than this object or NULL, it will be
145 // hit tested again recursively - that allows hit testing to work across
146 // implementation classes. It's okay to take advantage of this and return
147 // only an immediate child and not the deepest descendant.
148 //
149 // This function is mainly used by accessibility debugging software.
150 // Platforms with touch accessibility use a different asynchronous interface.
151 gfx::NativeViewAccessible HitTestSync(
152 int screen_physical_pixel_x,
153 int screen_physical_pixel_y) const override;
154
155 // Return the node within this node's subtree (inclusive) that currently
156 // has focus.
157 gfx::NativeViewAccessible GetFocus() override;
158
159 // Get whether this node is offscreen.
160 bool IsOffscreen() const override;
161
162 // Get whether this node is a minimized window.
163 bool IsMinimized() const override;
164 bool IsText() const override;
165
166 // Get whether this node is in web content.
167 bool IsWebContent() const override;
168
169 // Returns true if the caret or selection is visible on this object.
170 bool HasVisibleCaretOrSelection() const override;
171
172 // Get another node from this same tree.
173 AXPlatformNode* GetFromNodeID(int32_t id) override;
174
175 // Get a node from a different tree using a tree ID and node ID.
176 // Note that this is only guaranteed to work if the other tree is of the
177 // same type, i.e. it won't work between web and views or vice-versa.
178 AXPlatformNode* GetFromTreeIDAndNodeID(const ui::AXTreeID& ax_tree_id,
179 int32_t id) override;
180
181 // Given a node ID attribute (one where IsNodeIdIntAttribute is true), return
182 // a target nodes for which this delegate's node has that relationship
183 // attribute or NULL if there is no such relationship.
184 AXPlatformNode* GetTargetNodeForRelation(
185 ax::mojom::IntAttribute attr) override;
186
187 // Given a node ID attribute (one where IsNodeIdIntListAttribute is true),
188 // return a vector of all target nodes for which this delegate's node has that
189 // relationship attribute.
190 std::vector<AXPlatformNode*> GetTargetNodesForRelation(
191 ax::mojom::IntListAttribute attr) override;
192
193 // Given a node ID attribute (one where IsNodeIdIntAttribute is true), return
194 // a set of all source nodes that have that relationship attribute between
195 // them and this delegate's node.
196 std::set<AXPlatformNode*> GetReverseRelations(
197 ax::mojom::IntAttribute attr) override;
198
199 // Given a node ID list attribute (one where IsNodeIdIntListAttribute is
200 // true) return a set of all source nodes that have that relationship
201 // attribute between them and this delegate's node.
202 std::set<AXPlatformNode*> GetReverseRelations(
203 ax::mojom::IntListAttribute attr) override;
204
205 std::u16string GetAuthorUniqueId() const override;
206
207 const AXUniqueId& GetUniqueId() const override;
208
209 std::optional<int> FindTextBoundary(
211 int offset,
212 ax::mojom::MoveDirection direction,
213 ax::mojom::TextAffinity affinity) const override;
214
215 const std::vector<gfx::NativeViewAccessible> GetUIADescendants()
216 const override;
217
218 std::string GetLanguage() const override;
219
220 //
221 // Tables. All of these should be called on a node that's a table-like
222 // role, otherwise they return nullopt.
223 //
224 bool IsTable() const override;
225 std::optional<int> GetTableColCount() const override;
226 std::optional<int> GetTableRowCount() const override;
227 std::optional<int> GetTableAriaColCount() const override;
228 std::optional<int> GetTableAriaRowCount() const override;
229 std::optional<int> GetTableCellCount() const override;
230 std::optional<bool> GetTableHasColumnOrRowHeaderNode() const override;
231 std::vector<int32_t> GetColHeaderNodeIds() const override;
232 std::vector<int32_t> GetColHeaderNodeIds(int col_index) const override;
233 std::vector<int32_t> GetRowHeaderNodeIds() const override;
234 std::vector<int32_t> GetRowHeaderNodeIds(int row_index) const override;
235 AXPlatformNode* GetTableCaption() const override;
236
237 // Table row-like nodes.
238 bool IsTableRow() const override;
239 std::optional<int> GetTableRowRowIndex() const override;
240
241 // Table cell-like nodes.
242 bool IsTableCellOrHeader() const override;
243 std::optional<int> GetTableCellIndex() const override;
244 std::optional<int> GetTableCellColIndex() const override;
245 std::optional<int> GetTableCellRowIndex() const override;
246 std::optional<int> GetTableCellColSpan() const override;
247 std::optional<int> GetTableCellRowSpan() const override;
248 std::optional<int> GetTableCellAriaColIndex() const override;
249 std::optional<int> GetTableCellAriaRowIndex() const override;
250 std::optional<int32_t> GetCellId(int row_index, int col_index) const override;
251 std::optional<int32_t> CellIndexToId(int cell_index) const override;
252
253 // Helper methods to check if a cell is an ARIA-1.1+ 'cell' or 'gridcell'
254 bool IsCellOrHeaderOfARIATable() const override;
255 bool IsCellOrHeaderOfARIAGrid() const override;
256
257 // Ordered-set-like and item-like nodes.
258 bool IsOrderedSetItem() const override;
259 bool IsOrderedSet() const override;
260 std::optional<int> GetPosInSet() const override;
261 std::optional<int> GetSetSize() const override;
262
263 //
264 // Events.
265 //
266
267 // Return the platform-native GUI object that should be used as a target
268 // for accessibility events.
269 gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override;
270
271 //
272 // Actions.
273 //
274
275 // Perform an accessibility action, switching on the ax::mojom::Action
276 // provided in |data|.
277 bool AccessibilityPerformAction(const AXActionData& data) override;
278
279 //
280 // Localized strings.
281 //
282
283 std::u16string GetLocalizedStringForImageAnnotationStatus(
284 ax::mojom::ImageAnnotationStatus status) const override;
285 std::u16string GetLocalizedRoleDescriptionForUnlabeledImage() const override;
286 std::u16string GetLocalizedStringForLandmarkType() const override;
287 std::u16string GetLocalizedStringForRoleDescription() const override;
288 std::u16string GetStyleNameAttributeAsLocalizedString() const override;
289
290 //
291 // Testing.
292 //
293
294 // Accessibility objects can have the "hot tracked" state set when
295 // the mouse is hovering over them, but this makes tests flaky because
296 // the test behaves differently when the mouse happens to be over an
297 // element. The default value should be falses if not in testing mode.
298 bool ShouldIgnoreHoveredStateForTesting() override;
299
300 protected:
301 std::string SubtreeToStringHelper(size_t level) override;
302
303 // Given a list of node ids, return the nodes in this delegate's tree to
304 // which they correspond.
305 std::set<ui::AXPlatformNode*> GetNodesForNodeIds(
306 const std::set<int32_t>& ids);
307
308 AXPlatformNodeDelegate* GetParentDelegate();
309
310 private:
312};
313
314} // namespace ui
315
316#endif // UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_DELEGATE_BASE_H_
#define AX_EXPORT
Definition: ax_export.h:29
Definition: rect.h:36
std::unique_ptr< AXPosition< AXNodePosition, AXNode > > AXPositionInstance
Definition: ax_position.h:163
ImageAnnotationStatus
Definition: ax_enums.h:1170
IntListAttribute
Definition: ax_enums.h:799
UnimplementedNativeViewAccessible * NativeViewAccessible
constexpr Color operator*(T value, const Color &c)
Definition: color.h:911
bool operator==(const AXEventIntent &a, const AXEventIntent &b)
bool IsTableRow(ax::mojom::Role role)
std::vector< TextAttribute > TextAttributeList
std::map< int, TextAttributeList > TextAttributeMap
bool operator!=(const AXEventIntent &a, const AXEventIntent &b)
bool IsText(ax::mojom::Role role)
SeparatedVector2 offset
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
#define BASE_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:8