Flutter Engine
The Flutter Engine
test_ax_node_wrapper.h
Go to the documentation of this file.
1// Copyright 2015 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_TEST_AX_NODE_WRAPPER_H_
6#define UI_ACCESSIBILITY_PLATFORM_TEST_AX_NODE_WRAPPER_H_
7
8#include <set>
9#include <string>
10#include <vector>
11
12#include "ax/ax_node.h"
13#include "ax/ax_tree.h"
15#include "ax_platform_node.h"
17#include "base/auto_reset.h"
18
19#if defined(OS_WIN)
20namespace gfx {
21const AcceleratedWidget kMockAcceleratedWidget = reinterpret_cast<HWND>(-1);
22}
23#endif
24
25namespace ui {
26
27// For testing, a TestAXNodeWrapper wraps an AXNode, implements
28// AXPlatformNodeDelegate, and owns an AXPlatformNode.
30 public:
31 // Create TestAXNodeWrapper instances on-demand from an AXTree and AXNode.
32 static TestAXNodeWrapper* GetOrCreate(AXTree* tree, AXNode* node);
33
34 // Set a global coordinate offset for testing.
36
37 // Get the last node which ShowContextMenu was called from for testing.
39
40 // Get the last node which AccessibilityPerformAction default action was
41 // called from for testing.
43
44 // Set the last node which AccessibilityPerformAction default action was
45 // called for testing.
46 static void SetNodeFromLastDefaultAction(AXNode* node);
47
48 // Set a global scale factor for testing.
49 static std::unique_ptr<base::AutoReset<float>> SetScaleFactor(float value);
50
51 // Set a global indicating that AXPlatformNodeDelegates are for web content.
52 static void SetGlobalIsWebContent(bool is_web_content);
53
54 // When a hit test is called on |src_node_id|, return |dst_node_id| as
55 // the result.
56 static void SetHitTestResult(AXNode::AXID src_node_id,
57 AXNode::AXID dst_node_id);
58
59 // Remove all hit test overrides added by SetHitTestResult.
60 static void ClearHitTestResults();
61
62 ~TestAXNodeWrapper() override;
63
64 AXPlatformNode* ax_platform_node() const { return platform_node_; }
65 void set_minimized(bool minimized) { minimized_ = minimized; }
66
67 // Test helpers.
68 void BuildAllWrappers(AXTree* tree, AXNode* node);
70
71 // AXPlatformNodeDelegate.
72 const AXNodeData& GetData() const override;
73 const AXTreeData& GetTreeData() const override;
74 const AXTree::Selection GetUnignoredSelection() const override;
76 int offset) const override;
79 int GetChildCount() const override;
80 gfx::NativeViewAccessible ChildAtIndex(int index) override;
81 gfx::Rect GetBoundsRect(const AXCoordinateSystem coordinate_system,
82 const AXClippingBehavior clipping_behavior,
83 AXOffscreenResult* offscreen_result) const override;
85 const int start_offset,
86 const int end_offset,
87 const AXCoordinateSystem coordinate_system,
88 const AXClippingBehavior clipping_behavior,
89 AXOffscreenResult* offscreen_result) const override;
91 const int start_offset,
92 const int end_offset,
93 const AXCoordinateSystem coordinate_system,
94 const AXClippingBehavior clipping_behavior,
95 AXOffscreenResult* offscreen_result) const override;
97 int screen_physical_pixel_x,
98 int screen_physical_pixel_y) const override;
100 bool IsMinimized() const override;
101 bool IsWebContent() const override;
102 AXPlatformNode* GetFromNodeID(int32_t id) override;
104 int32_t id) override;
105 int GetIndexInParent() override;
106 bool IsTable() const override;
107 std::optional<int> GetTableRowCount() const override;
108 std::optional<int> GetTableColCount() const override;
109 std::optional<int> GetTableAriaColCount() const override;
110 std::optional<int> GetTableAriaRowCount() const override;
111 std::optional<int> GetTableCellCount() const override;
112 std::optional<bool> GetTableHasColumnOrRowHeaderNode() const override;
113 std::vector<int32_t> GetColHeaderNodeIds() const override;
114 std::vector<int32_t> GetColHeaderNodeIds(int col_index) const override;
115 std::vector<int32_t> GetRowHeaderNodeIds() const override;
116 std::vector<int32_t> GetRowHeaderNodeIds(int row_index) const override;
117 bool IsTableRow() const override;
118 std::optional<int> GetTableRowRowIndex() const override;
119 bool IsTableCellOrHeader() const override;
120 std::optional<int> GetTableCellIndex() const override;
121 std::optional<int> GetTableCellColIndex() const override;
122 std::optional<int> GetTableCellRowIndex() const override;
123 std::optional<int> GetTableCellColSpan() const override;
124 std::optional<int> GetTableCellRowSpan() const override;
125 std::optional<int> GetTableCellAriaColIndex() const override;
126 std::optional<int> GetTableCellAriaRowIndex() const override;
127 std::optional<int32_t> GetCellId(int row_index, int col_index) const override;
128 std::optional<int32_t> CellIndexToId(int cell_index) const override;
129 bool IsCellOrHeaderOfARIATable() const override;
130 bool IsCellOrHeaderOfARIAGrid() const override;
131 gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override;
132 bool AccessibilityPerformAction(const AXActionData& data) override;
133 std::u16string GetLocalizedRoleDescriptionForUnlabeledImage() const override;
134 std::u16string GetLocalizedStringForLandmarkType() const override;
135 std::u16string GetLocalizedStringForRoleDescription() const override;
137 ax::mojom::ImageAnnotationStatus status) const override;
138 std::u16string GetStyleNameAttributeAsLocalizedString() const override;
140 const ui::AXUniqueId& GetUniqueId() const override;
141 bool HasVisibleCaretOrSelection() const override;
142 std::set<AXPlatformNode*> GetReverseRelations(
143 ax::mojom::IntAttribute attr) override;
144 std::set<AXPlatformNode*> GetReverseRelations(
145 ax::mojom::IntListAttribute attr) override;
146 bool IsOrderedSetItem() const override;
147 bool IsOrderedSet() const override;
148 std::optional<int> GetPosInSet() const override;
149 std::optional<int> GetSetSize() const override;
150 const std::vector<gfx::NativeViewAccessible> GetUIADescendants()
151 const override;
152 gfx::RectF GetLocation() const;
153 int InternalChildCount() const;
154 TestAXNodeWrapper* InternalGetChild(int index) const;
155
156 private:
157 TestAXNodeWrapper(AXTree* tree, AXNode* node);
158 void ReplaceIntAttribute(int32_t node_id,
159 ax::mojom::IntAttribute attribute,
160 int32_t value);
161 void ReplaceFloatAttribute(ax::mojom::FloatAttribute attribute, float value);
162 void ReplaceBoolAttribute(ax::mojom::BoolAttribute attribute, bool value);
163 void ReplaceStringAttribute(ax::mojom::StringAttribute attribute,
164 std::string value);
165 void ReplaceTreeDataTextSelection(int32_t anchor_node_id,
166 int32_t anchor_offset,
167 int32_t focus_node_id,
168 int32_t focus_offset);
169
170 TestAXNodeWrapper* HitTestSyncInternal(int x, int y);
171 void UIADescendants(
172 const AXNode* node,
173 std::vector<gfx::NativeViewAccessible>* descendants) const;
174 static bool ShouldHideChildrenForUIA(const AXNode* node);
175
176 // Return the bounds of inline text in this node's coordinate system (which is
177 // relative to its container node specified in AXRelativeBounds).
178 gfx::RectF GetInlineTextRect(const int start_offset,
179 const int end_offset) const;
180
181 // Determine the offscreen status of a particular element given its bounds..
182 AXOffscreenResult DetermineOffscreenResult(gfx::RectF bounds) const;
183
184 AXTree* tree_;
185 AXNode* node_;
186 ui::AXUniqueId unique_id_;
187 AXPlatformNode* platform_node_;
188 gfx::AcceleratedWidget native_event_target_;
189 bool minimized_ = false;
190};
191
192} // namespace ui
193
194#endif // UI_ACCESSIBILITY_PLATFORM_TEST_AX_NODE_WRAPPER_H_
Definition: rect.h:36
int32_t AXID
Definition: ax_node.h:36
std::unique_ptr< AXPosition< AXNodePosition, AXNode > > AXPositionInstance
Definition: ax_position.h:163
const std::vector< gfx::NativeViewAccessible > GetUIADescendants() const override
bool AccessibilityPerformAction(const AXActionData &data) override
gfx::NativeViewAccessible GetParent() override
std::optional< int > GetTableCellColIndex() const override
const AXTreeData & GetTreeData() const override
bool IsMinimized() const override
const AXNodeData & GetData() const override
std::optional< int > GetTableRowCount() const override
std::optional< int > GetTableCellCount() const override
std::optional< int > GetSetSize() const override
bool IsWebContent() const override
gfx::NativeViewAccessible GetNativeViewAccessible() override
void set_minimized(bool minimized)
const AXTree::Selection GetUnignoredSelection() const override
std::u16string GetStyleNameAttributeAsLocalizedString() const override
std::optional< int > GetTableCellColSpan() const override
gfx::NativeViewAccessible HitTestSync(int screen_physical_pixel_x, int screen_physical_pixel_y) const override
std::u16string GetLocalizedStringForImageAnnotationStatus(ax::mojom::ImageAnnotationStatus status) const override
bool IsTable() const override
gfx::RectF GetLocation() const
std::vector< int32_t > GetRowHeaderNodeIds() const override
bool IsOrderedSetItem() const override
static void SetGlobalIsWebContent(bool is_web_content)
std::optional< int > GetTableCellAriaColIndex() const override
gfx::Rect GetHypertextRangeBoundsRect(const int start_offset, const int end_offset, const AXCoordinateSystem coordinate_system, const AXClippingBehavior clipping_behavior, AXOffscreenResult *offscreen_result) const override
static TestAXNodeWrapper * GetOrCreate(AXTree *tree, AXNode *node)
AXPlatformNode * GetFromNodeID(int32_t id) override
int GetChildCount() const override
std::optional< bool > GetTableHasColumnOrRowHeaderNode() const override
bool IsCellOrHeaderOfARIAGrid() const override
bool IsOrderedSet() const override
std::optional< int > GetTableCellRowIndex() const override
std::optional< int > GetPosInSet() const override
AXPlatformNode * GetFromTreeIDAndNodeID(const ui::AXTreeID &ax_tree_id, int32_t id) override
std::optional< int > GetTableCellRowSpan() const override
AXPlatformNode * ax_platform_node() const
std::optional< int > GetTableAriaColCount() const override
std::optional< int > GetTableColCount() const override
std::u16string GetLocalizedStringForRoleDescription() const override
std::u16string GetLocalizedRoleDescriptionForUnlabeledImage() const override
bool IsCellOrHeaderOfARIATable() const override
gfx::NativeViewAccessible GetFocus() override
bool IsTableCellOrHeader() const override
static void SetNodeFromLastDefaultAction(AXNode *node)
std::set< AXPlatformNode * > GetReverseRelations(ax::mojom::IntAttribute attr) override
const ui::AXUniqueId & GetUniqueId() const override
gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override
std::vector< int32_t > GetColHeaderNodeIds() const override
std::u16string GetLocalizedStringForLandmarkType() const override
std::optional< int32_t > GetCellId(int row_index, int col_index) const override
bool HasVisibleCaretOrSelection() const override
gfx::Rect GetBoundsRect(const AXCoordinateSystem coordinate_system, const AXClippingBehavior clipping_behavior, AXOffscreenResult *offscreen_result) const override
static const AXNode * GetNodeFromLastShowContextMenu()
bool IsTableRow() const override
std::optional< int > GetTableAriaRowCount() const override
TestAXNodeWrapper * InternalGetChild(int index) const
gfx::Rect GetInnerTextRangeBoundsRect(const int start_offset, const int end_offset, const AXCoordinateSystem coordinate_system, const AXClippingBehavior clipping_behavior, AXOffscreenResult *offscreen_result) const override
AXNodePosition::AXPositionInstance CreateTextPositionAt(int offset) const override
std::optional< int > GetTableCellIndex() const override
std::optional< int > GetTableRowRowIndex() const override
static void SetGlobalCoordinateOffset(const gfx::Vector2d &offset)
static const AXNode * GetNodeFromLastDefaultAction()
static std::unique_ptr< base::AutoReset< float > > SetScaleFactor(float value)
static void SetHitTestResult(AXNode::AXID src_node_id, AXNode::AXID dst_node_id)
bool ShouldIgnoreHoveredStateForTesting() override
std::optional< int32_t > CellIndexToId(int cell_index) const override
gfx::NativeViewAccessible ChildAtIndex(int index) override
std::optional< int > GetTableCellAriaRowIndex() const override
void BuildAllWrappers(AXTree *tree, AXNode *node)
uint8_t value
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
StringAttribute
Definition: ax_enums.h:521
FloatAttribute
Definition: ax_enums.h:699
ImageAnnotationStatus
Definition: ax_enums.h:1170
IntListAttribute
Definition: ax_enums.h:799
Definition: insets.cc:10
UnimplementedNativeViewAccessible * NativeViewAccessible
SeparatedVector2 offset
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63