Fix hit testing logic in fuchsia a11y (flutter/engine#19029)
This commit is contained in:
@@ -384,11 +384,13 @@ std::optional<int32_t> AccessibilityBridge::GetHitNode(int32_t node_id,
|
||||
!node.screen_rect.contains(x, y)) {
|
||||
return {};
|
||||
}
|
||||
auto hit = node_id;
|
||||
for (int32_t child_id : node.children_in_hit_test_order) {
|
||||
hit = GetHitNode(child_id, x, y).value_or(hit);
|
||||
auto candidate = GetHitNode(child_id, x, y);
|
||||
if (candidate) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return hit;
|
||||
return node_id;
|
||||
}
|
||||
|
||||
// |fuchsia::accessibility::semantics::SemanticListener|
|
||||
|
||||
@@ -515,6 +515,41 @@ TEST_F(AccessibilityBridgeTest, HitTest) {
|
||||
EXPECT_EQ(hit_node_id, 4u);
|
||||
}
|
||||
|
||||
TEST_F(AccessibilityBridgeTest, HitTestOverlapping) {
|
||||
// Tests that the first node in hit test order wins, even if a later node
|
||||
// would be able to recieve the hit.
|
||||
flutter::SemanticsNode node0;
|
||||
node0.id = 0;
|
||||
node0.rect.setLTRB(0, 0, 100, 100);
|
||||
|
||||
flutter::SemanticsNode node1;
|
||||
node1.id = 1;
|
||||
node1.rect.setLTRB(0, 0, 100, 100);
|
||||
|
||||
flutter::SemanticsNode node2;
|
||||
node2.id = 2;
|
||||
node2.rect.setLTRB(25, 10, 45, 20);
|
||||
|
||||
node0.childrenInTraversalOrder = {1, 2};
|
||||
node0.childrenInHitTestOrder = {2, 1};
|
||||
|
||||
accessibility_bridge_->AddSemanticsNodeUpdate({
|
||||
{0, node0},
|
||||
{1, node1},
|
||||
{2, node2},
|
||||
});
|
||||
RunLoopUntilIdle();
|
||||
|
||||
uint32_t hit_node_id;
|
||||
auto callback = [&hit_node_id](fuchsia::accessibility::semantics::Hit hit) {
|
||||
EXPECT_TRUE(hit.has_node_id());
|
||||
hit_node_id = hit.node_id();
|
||||
};
|
||||
|
||||
accessibility_bridge_->HitTest({30, 15}, callback);
|
||||
EXPECT_EQ(hit_node_id, 2u);
|
||||
}
|
||||
|
||||
TEST_F(AccessibilityBridgeTest, Actions) {
|
||||
flutter::SemanticsNode node0;
|
||||
node0.id = 0;
|
||||
|
||||
Reference in New Issue
Block a user