Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9cc4b4f

Browse files
committed
Includes roles for links, checkboxes, and radio buttons in semantics
updates.
1 parent 92cd74e commit 9cc4b4f

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

shell/platform/fuchsia/flutter/accessibility_bridge.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ fuchsia::accessibility::semantics::Role AccessibilityBridge::GetNodeRole(
160160
return fuchsia::accessibility::semantics::Role::TEXT_FIELD;
161161
}
162162

163+
if (node.HasFlag(flutter::SemanticsFlags::kIsLink)) {
164+
return fuchsia::accessibility::semantics::Role::LINK;
165+
}
166+
163167
if (node.HasFlag(flutter::SemanticsFlags::kIsSlider)) {
164168
return fuchsia::accessibility::semantics::Role::SLIDER;
165169
}
@@ -170,6 +174,7 @@ fuchsia::accessibility::semantics::Role AccessibilityBridge::GetNodeRole(
170174
if (node.HasFlag(flutter::SemanticsFlags::kIsImage)) {
171175
return fuchsia::accessibility::semantics::Role::IMAGE;
172176
}
177+
173178
// If a flutter node supports the kIncrease or kDecrease actions, it can be
174179
// treated as a slider control by assistive technology. This is important
175180
// because users have special gestures to deal with sliders, and Fuchsia API
@@ -178,6 +183,18 @@ fuchsia::accessibility::semantics::Role AccessibilityBridge::GetNodeRole(
178183
node.HasAction(flutter::SemanticsAction::kDecrease)) {
179184
return fuchsia::accessibility::semantics::Role::SLIDER;
180185
}
186+
187+
// If a flutter node has a checked state, then we assume it is either a
188+
// checkbox or a radio button. We distinguish between checkboxes and
189+
// radio buttons based on membership in a mutually exclusive group.
190+
if (!node.HasFlag(flutter::SemanticsFlags::kHasCheckedState)) {
191+
if (node.HasFlag(flutter::SemanticsFlags::kIsInMutuallyExclusiveGroup)) {
192+
return fuchsia::accessibility::semantics::Role::RADIO_BUTTON;
193+
} else {
194+
return fuchsia::accessibility::semantics::Role::CHECK_BOX;
195+
}
196+
}
197+
181198
return fuchsia::accessibility::semantics::Role::UNKNOWN;
182199
}
183200

shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,29 @@ TEST_F(AccessibilityBridgeTest, UpdatesNodeRoles) {
141141
node4.flags |= static_cast<int>(flutter::SemanticsFlags::kIsSlider);
142142
updates.emplace(4, node4);
143143

144+
flutter::SemanticsNode node5;
145+
node5.childrenInTraversalOrder = {};
146+
node5.childrenInHitTestOrder = {};
147+
node5.id = 5;
148+
node5.flags |= static_cast<int>(flutter::SemanticsFlags::kIsLink);
149+
updates.emplace(5, node5);
150+
151+
flutter::SemanticsNode node6;
152+
node6.childrenInTraversalOrder = {};
153+
node6.childrenInHitTestOrder = {};
154+
node6.id = 6;
155+
node6.flags |= static_cast<int>(flutter::SemanticsFlags::kHasCheckedState);
156+
node6.flags |=
157+
static_cast<int>(flutter::SemanticsFlags::kIsInMutuallyExclusiveGroup);
158+
updates.emplace(6, node6);
159+
160+
flutter::SemanticsNode node7;
161+
node7.childrenInTraversalOrder = {};
162+
node7.childrenInHitTestOrder = {};
163+
node7.id = 7;
164+
node7.flags |= static_cast<int>(flutter::SemanticsFlags::kHasCheckedState);
165+
updates.emplace(7, node7);
166+
144167
accessibility_bridge_->AddSemanticsNodeUpdate(std::move(updates), 1.f);
145168
RunLoopUntilIdle();
146169

@@ -150,12 +173,15 @@ TEST_F(AccessibilityBridgeTest, UpdatesNodeRoles) {
150173
{1u, fuchsia::accessibility::semantics::Role::HEADER},
151174
{2u, fuchsia::accessibility::semantics::Role::IMAGE},
152175
{3u, fuchsia::accessibility::semantics::Role::TEXT_FIELD},
153-
{4u, fuchsia::accessibility::semantics::Role::SLIDER}};
176+
{4u, fuchsia::accessibility::semantics::Role::SLIDER},
177+
{5u, fuchsia::accessibility::semantics::Role::LINK},
178+
{6u, fuchsia::accessibility::semantics::Role::RADIO_BUTTON},
179+
{7u, fuchsia::accessibility::semantics::Role::CHECK_BOX}};
154180

155181
EXPECT_EQ(0, semantics_manager_.DeleteCount());
156182
EXPECT_EQ(1, semantics_manager_.UpdateCount());
157183
EXPECT_EQ(1, semantics_manager_.CommitCount());
158-
EXPECT_EQ(5U, semantics_manager_.LastUpdatedNodes().size());
184+
EXPECT_EQ(8u, semantics_manager_.LastUpdatedNodes().size());
159185
for (const auto& node : semantics_manager_.LastUpdatedNodes()) {
160186
ExpectNodeHasRole(node, roles_by_node_id);
161187
}

0 commit comments

Comments
 (0)