Skip to content

Commit

Permalink
arc-a11y: Add role description for recursive name computation
Browse files Browse the repository at this point in the history
In order to make the behavior similar to talkback, with this change,
when we compute accessibility name from subtree, role description is
also used.

AX-Relnotes: n/a.

Bug: b:260178977
Test: AccessibilityNodeInfoDataWrapperTest
Test: PlayStore tabs are now read as "For you tab", for example.
Change-Id: Iee4e59697f15a5587dab65350fcddf237da6d0b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4654081
Reviewed-by: Jacob Francis <francisjp@google.com>
Commit-Queue: Hiroki Sato <hirokisato@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1165774}
  • Loading branch information
tossy310 authored and Chromium LUCI CQ committed Jul 5, 2023
1 parent eefb03b commit ea2318c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,18 @@ void AccessibilityNodeInfoDataWrapper::ComputeNameFromContentsInternal(
return;
}
}

// TalkBack reads role description by default even when reading properties
// of descendant nodes. Let's append them here to fill the gap.
// This is not in |text_properties_| because when focusing on the node that
// has role_description, then ChromeVox selectively reads the role
// description if needed.
std::string role_description;
if (GetProperty(AXStringProperty::ROLE_DESCRIPTION, &role_description) &&
!role_description.empty()) {
names->push_back(role_description);
// don't early return here. subtree may contain more text.
}
}

// Otherwise, continue looking for a name in this subtree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,45 @@ TEST_F(AccessibilityNodeInfoDataWrapperTest,
data.GetStringAttribute(ax::mojom::StringAttribute::kName, &name));
}

TEST_F(AccessibilityNodeInfoDataWrapperTest,
NameFromDescendants_fromRoleDescription) {
AXNodeInfoData root;
root.id = 10;
AccessibilityNodeInfoDataWrapper root_wrapper(tree_source(), &root);
SetIdToWrapper(&root_wrapper);
SetProperty(root, AXBooleanProperty::IMPORTANCE, true);
SetProperty(root, AXIntListProperty::CHILD_NODE_IDS,
std::vector<int>({1, 2}));
SetProperty(root, AXBooleanProperty::FOCUSABLE, true);
SetProperty(root, AXStringProperty::ROLE_DESCRIPTION, "rootRole");

AXNodeInfoData child1;
child1.id = 1;
AccessibilityNodeInfoDataWrapper child1_wrapper(tree_source(), &child1);
SetIdToWrapper(&child1_wrapper);
SetProperty(child1, AXBooleanProperty::IMPORTANCE, true);
SetProperty(child1, AXStringProperty::TEXT, "child1");

AXNodeInfoData child2;
child2.id = 2;
AccessibilityNodeInfoDataWrapper child2_wrapper(tree_source(), &child2);
SetIdToWrapper(&child2_wrapper);
SetProperty(child2, AXBooleanProperty::IMPORTANCE, true);
SetProperty(child2, AXStringProperty::ROLE_DESCRIPTION, "child2Role");

SetParentId(child1.id, root.id);
SetParentId(child2.id, root.id);

set_full_focus_mode(true);

ui::AXNodeData data = CallSerialize(root_wrapper);
data = CallSerialize(root_wrapper);
std::string name;
ASSERT_TRUE(
data.GetStringAttribute(ax::mojom::StringAttribute::kName, &name));
ASSERT_EQ("child1 child2Role", name); // rootRole is not used.
}

TEST_F(AccessibilityNodeInfoDataWrapperTest, NameFromTextProperties) {
AXNodeInfoData root;
root.id = 10;
Expand Down

0 comments on commit ea2318c

Please sign in to comment.