Skip to content

Commit e84d497

Browse files
authored
Fix hit testing logic in fuchsia a11y (flutter#19029)
1 parent f7d241f commit e84d497

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

shell/platform/fuchsia/flutter/accessibility_bridge.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,13 @@ std::optional<int32_t> AccessibilityBridge::GetHitNode(int32_t node_id,
384384
!node.screen_rect.contains(x, y)) {
385385
return {};
386386
}
387-
auto hit = node_id;
388387
for (int32_t child_id : node.children_in_hit_test_order) {
389-
hit = GetHitNode(child_id, x, y).value_or(hit);
388+
auto candidate = GetHitNode(child_id, x, y);
389+
if (candidate) {
390+
return candidate;
391+
}
390392
}
391-
return hit;
393+
return node_id;
392394
}
393395

394396
// |fuchsia::accessibility::semantics::SemanticListener|

shell/platform/fuchsia/flutter/accessibility_bridge_unittest.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,41 @@ TEST_F(AccessibilityBridgeTest, HitTest) {
515515
EXPECT_EQ(hit_node_id, 4u);
516516
}
517517

518+
TEST_F(AccessibilityBridgeTest, HitTestOverlapping) {
519+
// Tests that the first node in hit test order wins, even if a later node
520+
// would be able to recieve the hit.
521+
flutter::SemanticsNode node0;
522+
node0.id = 0;
523+
node0.rect.setLTRB(0, 0, 100, 100);
524+
525+
flutter::SemanticsNode node1;
526+
node1.id = 1;
527+
node1.rect.setLTRB(0, 0, 100, 100);
528+
529+
flutter::SemanticsNode node2;
530+
node2.id = 2;
531+
node2.rect.setLTRB(25, 10, 45, 20);
532+
533+
node0.childrenInTraversalOrder = {1, 2};
534+
node0.childrenInHitTestOrder = {2, 1};
535+
536+
accessibility_bridge_->AddSemanticsNodeUpdate({
537+
{0, node0},
538+
{1, node1},
539+
{2, node2},
540+
});
541+
RunLoopUntilIdle();
542+
543+
uint32_t hit_node_id;
544+
auto callback = [&hit_node_id](fuchsia::accessibility::semantics::Hit hit) {
545+
EXPECT_TRUE(hit.has_node_id());
546+
hit_node_id = hit.node_id();
547+
};
548+
549+
accessibility_bridge_->HitTest({30, 15}, callback);
550+
EXPECT_EQ(hit_node_id, 2u);
551+
}
552+
518553
TEST_F(AccessibilityBridgeTest, Actions) {
519554
flutter::SemanticsNode node0;
520555
node0.id = 0;

0 commit comments

Comments
 (0)