Accounts for inverse pixel ratio transform in screen rects. (flutter/engine#27427)

This commit is contained in:
Alexander Brusher
2021-07-20 13:09:42 -07:00
committed by GitHub
parent c18b4008c0
commit 014a087925
2 changed files with 48 additions and 1 deletions

View File

@@ -692,7 +692,19 @@ void AccessibilityBridge::RequestAnnounce(const std::string message) {
void AccessibilityBridge::UpdateScreenRects() {
std::unordered_set<int32_t> visited_nodes;
UpdateScreenRects(kRootNodeId, SkM44{}, &visited_nodes);
// The embedder applies a special pixel ratio transform to the root of the
// view, and the accessibility bridge applies the inverse of this transform
// to the root node. However, this transform is not persisted in the flutter
// representation of the root node, so we need to account for it explicitly
// here.
float inverse_view_pixel_ratio = 1.f / last_seen_view_pixel_ratio_;
SkM44 inverse_view_pixel_ratio_transform;
inverse_view_pixel_ratio_transform.setScale(inverse_view_pixel_ratio,
inverse_view_pixel_ratio, 1.f);
UpdateScreenRects(kRootNodeId, inverse_view_pixel_ratio_transform,
&visited_nodes);
}
void AccessibilityBridge::UpdateScreenRects(

View File

@@ -842,6 +842,41 @@ TEST_F(AccessibilityBridgeTest, HitTest) {
EXPECT_EQ(hit_node_id, 4u);
}
TEST_F(AccessibilityBridgeTest, HitTestWithPixelRatio) {
flutter::SemanticsNode node0;
node0.id = 0;
node0.rect.setLTRB(0, 0, 100, 100);
node0.flags |= static_cast<int32_t>(flutter::SemanticsFlags::kIsFocusable);
flutter::SemanticsNode node1;
node1.id = 1;
node1.rect.setLTRB(10, 10, 20, 20);
// Setting platform view id ensures this node is considered focusable.
node1.platformViewId = 1u;
node0.childrenInTraversalOrder = {1};
node0.childrenInHitTestOrder = {1};
accessibility_bridge_->AddSemanticsNodeUpdate(
{
{0, node0},
{1, node1},
},
// Pick a very small pixel ratio so that a point within the bounds of
// the node's root-space coordinates will be well outside the "screen"
// bounds of the node.
.1f);
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({15, 15}, callback);
EXPECT_EQ(hit_node_id, 0u);
}
TEST_F(AccessibilityBridgeTest, HitTestUnfocusableChild) {
flutter::SemanticsNode node0;
node0.id = 0;