23std::map<AXNode::AXID, TestAXNodeWrapper*> g_node_id_to_wrapper_map;
29float g_scale_factor = 1.0;
36std::map<AXTree*, AXNode*> g_focused_node_in_tree;
39AXNode* g_node_from_last_show_context_menu;
43AXNode* g_node_from_last_default_action;
46bool g_is_web_content =
false;
50std::map<AXNode::AXID, AXNode::AXID> g_hit_test_result;
54class TestAXTreeObserver :
public AXTreeObserver {
56 void OnNodeDeleted(AXTree* tree, int32_t node_id)
override {
57 const auto& iter = g_node_id_to_wrapper_map.find(node_id);
58 if (iter != g_node_id_to_wrapper_map.end()) {
59 TestAXNodeWrapper* wrapper = iter->second;
60 const auto& focus_iter = g_focused_node_in_tree.find(tree);
61 if (focus_iter != g_focused_node_in_tree.end() &&
62 focus_iter->second->id() == node_id) {
63 g_focused_node_in_tree.erase(tree);
66 g_node_id_to_wrapper_map.erase(node_id);
71TestAXTreeObserver g_ax_tree_observer;
82 auto iter = g_node_id_to_wrapper_map.find(node->
id());
83 if (iter != g_node_id_to_wrapper_map.end())
86 g_node_id_to_wrapper_map[node->
id()] = wrapper;
97 return g_node_from_last_show_context_menu;
102 return g_node_from_last_default_action;
107 g_node_from_last_default_action = node;
113 return std::make_unique<base::AutoReset<float>>(&g_scale_factor,
value);
118 g_is_web_content = is_web_content;
124 g_hit_test_result[src_node_id] = dst_node_id;
129 g_hit_test_result.clear();
137 return node_->
data();
141 return tree_->
data();
162 return parent_wrapper
182 switch (coordinate_system) {
194 if (offscreen_result) {
195 *offscreen_result = DetermineOffscreenResult(
bounds);
208 const int start_offset,
209 const int end_offset,
213 switch (coordinate_system) {
224 bounds = GetInlineTextRect(start_offset, end_offset);
228 if (child !=
nullptr &&
230 bounds = child->GetInlineTextRect(start_offset, end_offset);
239 if (offscreen_result) {
240 *offscreen_result = DetermineOffscreenResult(
bounds);
253 const int start_offset,
254 const int end_offset,
258 switch (coordinate_system) {
277 if (g_hit_test_result.find(node_->
id()) != g_hit_test_result.end()) {
278 int result_id = g_hit_test_result[node_->
id()];
294 TestAXNodeWrapper*
result = child->HitTestSyncInternal(
x,
y);
303 int screen_physical_pixel_x,
304 int screen_physical_pixel_y)
const {
307 screen_physical_pixel_x / g_scale_factor,
308 screen_physical_pixel_y / g_scale_factor);
314 auto focused = g_focused_node_in_tree.find(tree_);
315 if (focused != g_focused_node_in_tree.end() &&
316 focused->second->IsDescendantOf(node_)) {
329 return g_is_web_content;
334 for (
auto* child : node->
children()) {
341 native_event_target_ = gfx::kNullAcceleratedWidget;
348 const auto iter = g_node_id_to_wrapper_map.find(
id);
349 if (iter != g_node_id_to_wrapper_map.end())
350 return iter->second->ax_platform_node();
368void TestAXNodeWrapper::ReplaceIntAttribute(int32_t node_id,
379 std::vector<std::pair<ax::mojom::IntAttribute, int32_t>>& attributes =
382 auto it = std::remove_if(
383 attributes.begin(), attributes.end(),
384 [attribute](
auto& pair) { return pair.first == attribute; });
385 attributes.erase(it, attributes.end());
391void TestAXNodeWrapper::ReplaceFloatAttribute(
394 AXNodeData new_data =
GetData();
395 std::vector<std::pair<ax::mojom::FloatAttribute, float>>& attributes =
396 new_data.float_attributes;
398 auto it = std::remove_if(
399 attributes.begin(), attributes.end(),
400 [attribute](
auto& pair) { return pair.first == attribute; });
401 attributes.erase(it, attributes.end());
403 new_data.AddFloatAttribute(attribute,
value);
409 AXNodeData new_data =
GetData();
410 std::vector<std::pair<ax::mojom::BoolAttribute, bool>>& attributes =
411 new_data.bool_attributes;
413 auto it = std::remove_if(
414 attributes.begin(), attributes.end(),
415 [attribute](
auto& pair) { return pair.first == attribute; });
416 attributes.erase(it, attributes.end());
418 new_data.AddBoolAttribute(attribute,
value);
422void TestAXNodeWrapper::ReplaceStringAttribute(
425 AXNodeData new_data =
GetData();
426 std::vector<std::pair<ax::mojom::StringAttribute, std::string>>& attributes =
427 new_data.string_attributes;
429 auto it = std::remove_if(
430 attributes.begin(), attributes.end(),
431 [attribute](
auto& pair) { return pair.first == attribute; });
432 attributes.erase(it, attributes.end());
434 new_data.AddStringAttribute(attribute,
value);
438void TestAXNodeWrapper::ReplaceTreeDataTextSelection(int32_t anchor_node_id,
439 int32_t anchor_offset,
440 int32_t focus_node_id,
441 int32_t focus_offset) {
446 new_tree_data.sel_anchor_object_id = anchor_node_id;
447 new_tree_data.sel_anchor_offset = anchor_offset;
448 new_tree_data.sel_focus_object_id = focus_node_id;
449 new_tree_data.sel_focus_offset = focus_offset;
488 int col_index)
const {
497 int row_index)
const {
542 int col_index)
const {
549gfx::AcceleratedWidget
551 return native_event_target_;
571 switch (
data.action) {
606 if (
GetData().HasBoolAttribute(
626 else if (
GetData().GetCheckedState() ==
643 std::stof(
data.value));
650 ReplaceIntAttribute(
data.anchor_node_id,
653 ReplaceIntAttribute(
data.focus_node_id,
656 ReplaceTreeDataTextSelection(
data.anchor_node_id,
data.anchor_offset,
657 data.focus_node_id,
data.focus_offset);
662 g_focused_node_in_tree[tree_] = node_;
678 g_node_from_last_show_context_menu = node_;
738 std::string input_type;
741 if (input_type ==
"datetime-local") {
743 }
else if (input_type ==
"week") {
790 std::string input_type;
793 if (input_type ==
"email") {
795 }
else if (input_type ==
"tel") {
797 }
else if (input_type ==
"url") {
817 "To get missing image descriptions, open the context menu.");
822 "Appears to contain adult content. No description available.");
831 return std::u16string();
835 return std::u16string();
840 AXNode* current_node = node_;
841 while (current_node) {
844 current_node = current_node->
parent();
846 return std::u16string();
890TestAXNodeWrapper::TestAXNodeWrapper(
AXTree* tree,
AXNode* node)
893 native_event_target_ = gfx::kMockAcceleratedWidget;
895 native_event_target_ = gfx::kNullAcceleratedWidget;
932void TestAXNodeWrapper::UIADescendants(
934 std::vector<gfx::NativeViewAccessible>* descendants)
const {
935 if (ShouldHideChildrenForUIA(node))
944 UIADescendants(it.get(), descendants);
948const std::vector<gfx::NativeViewAccessible>
950 std::vector<gfx::NativeViewAccessible> descendants;
951 UIADescendants(node_, &descendants);
957bool TestAXNodeWrapper::ShouldHideChildrenForUIA(
const AXNode* node) {
975gfx::RectF TestAXNodeWrapper::GetInlineTextRect(
const int start_offset,
976 const int end_offset)
const {
977 BASE_DCHECK(start_offset >= 0 && end_offset >= 0 &&
978 start_offset <= end_offset);
989 int start_pixel_offset =
990 start_offset > 0 ? character_offsets[start_offset - 1] : location.
x();
991 int end_pixel_offset =
992 end_offset > 0 ? character_offsets[end_offset - 1] : location.
x();
995 end_pixel_offset - start_pixel_offset, location.
height());
1006 if (!tree_ || !tree_->
root())
1009 const AXNodeData& root_web_area_node_data = tree_->
root()->
data();
1011 root_web_area_node_data.relative_bounds.bounds;
1020 if (!root_web_area_bounds.
IsEmpty()) {
1021 bounds.Intersect(root_web_area_bounds);
static sk_sp< Effect > Create()
Vector2dF OffsetFromOrigin() const
constexpr float y() const
constexpr float height() const
constexpr float x() const
std::optional< int > GetSetSize()
size_t GetUnignoredChildCount() const
std::vector< AXNode::AXID > GetTableColHeaderNodeIds() const
std::vector< AXNode::AXID > GetTableCellRowHeaderNodeIds() const
UnignoredChildIterator UnignoredChildrenEnd() const
bool IsCellOrHeaderOfARIATable() const
bool IsOrderedSetItem() const
std::optional< int > GetTableCellIndex() const
void SetData(const AXNodeData &src)
std::optional< int > GetTableCellRowIndex() const
size_t GetUnignoredIndexInParent() const
bool IsCellOrHeaderOfARIAGrid() const
bool IsTableCellOrHeader() const
std::optional< int > GetTableCellAriaColIndex() const
std::vector< AXNode::AXID > GetTableRowHeaderNodeIds(int row_index) const
std::optional< int > GetTableRowCount() const
std::optional< bool > GetTableHasColumnOrRowHeaderNode() const
AXNode * GetUnignoredParent() const
std::optional< int > GetTableRowRowIndex() const
AXNode * GetUnignoredChildAtIndex(size_t index) const
std::optional< int > GetTableCellAriaRowIndex() const
std::optional< int > GetTableAriaColCount() const
std::optional< int > GetTableColCount() const
const std::vector< AXNode * > & children() const
std::optional< int > GetTableCellColSpan() const
UnignoredChildIterator UnignoredChildrenBegin() const
std::optional< int > GetTableCellRowSpan() const
std::optional< int > GetTableCellCount() const
bool IsOrderedSet() const
std::optional< int > GetTableCellColIndex() const
bool IsDescendantOf(const AXNode *ancestor) const
AXNode * GetTableCellFromIndex(int index) const
std::optional< int > GetPosInSet()
AXNode * GetTableCellFromCoords(int row_index, int col_index) const
const AXNodeData & data() const
std::optional< int > GetTableAriaRowCount() const
std::unique_ptr< AXPosition< AXNodePosition, AXNode > > AXPositionInstance
static AXPositionInstance CreateTextPosition(AXTreeID tree_id, AXNode::AXID anchor_id, int text_offset, ax::mojom::TextAffinity affinity)
const AXTreeData & data() const
std::set< int32_t > GetReverseRelations(ax::mojom::IntAttribute attr, int32_t dst_id) const
AXNode * GetFromId(int32_t id) const override
void AddObserver(AXTreeObserver *observer)
Selection GetUnignoredSelection() const override
virtual void UpdateData(const AXTreeData &data)
bool HasObserver(AXTreeObserver *observer)
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
int InternalChildCount() const
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
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
static void ClearHitTestResults()
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)
void ResetNativeEventTarget()
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
~TestAXNodeWrapper() 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
int GetIndexInParent() 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)
Optional< SkRect > bounds
@ kSilentlyEligibleForAnnotation
@ kAnnotationProcessFailed
@ kIneligibleForAnnotation
@ kWillNotAnnotateDueToScheme
std::u16string ASCIIToUTF16(std::string src)
constexpr const T & ClampToRange(const T &value, const T &min, const T &max)
bool Contains(const Container &container, const Value &value)
Rect ToEnclosingRect(const RectF &r)
UnimplementedNativeViewAccessible * NativeViewAccessible
bool IsNodeIdIntAttribute(ax::mojom::IntAttribute attr)
bool SupportsSelected(const ax::mojom::Role role)
bool IsRangeValueSupported(const ax::mojom::Role role)
bool HasPresentationalChildren(const ax::mojom::Role role)
bool IsNodeIdIntListAttribute(ax::mojom::IntListAttribute attr)
AXRelativeBounds relative_bounds
bool IsPlainTextField() const
void AddIntAttribute(ax::mojom::IntAttribute attribute, int32_t value)
std::vector< std::pair< ax::mojom::IntAttribute, int32_t > > int_attributes
bool GetBoolAttribute(ax::mojom::BoolAttribute attribute) const
const std::vector< int32_t > & GetIntListAttribute(ax::mojom::IntListAttribute attribute) const
int GetIntAttribute(ax::mojom::IntAttribute attribute) const
std::shared_ptr< const fml::Mapping > data
#define BASE_DCHECK(condition)
#define BASE_UNREACHABLE()
#define BASE_CHECK(condition)