Bug 1773256 - Use ProjectPoint when transforming coordinates from parent to child in BrowserParent. r=tnikkel

This patch also backs out the incorrect fix for bug 1745834
(see comment 12 on the bug for an explanation).

Differential Revision: https://phabricator.services.mozilla.com/D149321
This commit is contained in:
Botond Ballo 2022-06-15 05:29:52 +00:00
Родитель 66564fb0f0
Коммит 2c303ddd7c
6 изменённых файлов: 84 добавлений и 14 удалений

Просмотреть файл

@ -2610,9 +2610,13 @@ LayoutDeviceIntPoint BrowserParent::TransformParentToChild(
LayoutDeviceToLayoutDeviceMatrix4x4 matrix =
GetChildToParentConversionMatrix();
if (!matrix.Invert()) {
return LayoutDeviceIntPoint(0, 0);
return LayoutDeviceIntPoint();
}
return TransformPoint(aPoint, matrix);
auto transformed = UntransformBy(matrix, aPoint);
if (!transformed) {
return LayoutDeviceIntPoint();
}
return transformed.ref();
}
LayoutDevicePoint BrowserParent::TransformParentToChild(
@ -2620,9 +2624,13 @@ LayoutDevicePoint BrowserParent::TransformParentToChild(
LayoutDeviceToLayoutDeviceMatrix4x4 matrix =
GetChildToParentConversionMatrix();
if (!matrix.Invert()) {
return LayoutDevicePoint(0.0, 0.0);
return LayoutDevicePoint();
}
return TransformPoint(aPoint, matrix);
auto transformed = UntransformBy(matrix, aPoint);
if (!transformed) {
return LayoutDeviceIntPoint();
}
return transformed.ref();
}
LayoutDeviceIntPoint BrowserParent::TransformChildToParent(

Просмотреть файл

@ -0,0 +1,65 @@
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<title>Test that events are delivered with correct coordinates to an iframe inide a perspective transform</title>
<script src="apz_test_native_event_utils.js"></script>
<script src="apz_test_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
}
#outer {
margin-top: 50px;
margin-left: 50px;
perspective: 500px;
}
#inner {
transform: translate3d(0,0,-100px);
transform-style: preserve-3d;
}
iframe {
border: 0;
background-color: blue;
transform: translate3d(0,0,100px);
}
</style>
</head>
<body>
<div id="outer">
<div id="inner">
<iframe src="https://example.com/tests/gfx/layers/apz/test/mochitest/helper_hittest_iframe_perspective_child.html"></iframe>
</div>
</div>
<script type="application/javascript">
async function test() {
let clickCoordsInChild = {
offsetX: 0,
offsetY: 0
};
let childMessagePromise = new Promise(resolve => {
window.addEventListener("message", event => {
let data = JSON.parse(event.data);
if ("type" in data && data.type == "got-mouse-down") {
clickCoordsInChild = data.coords;
resolve();
}
})
});
await synthesizeNativeMouseEventWithAPZ({
type: "click",
target: outer,
offsetX: 100,
offsetY: 100
});
await childMessagePromise;
is(clickCoordsInChild.offsetX, 100, "x coordinate is correct");
is(clickCoordsInChild.offsetY, 100, "y coordinate is correct");
}
waitUntilApzStable()
.then(test)
.then(subtestDone, subtestFailed);
</script>
</body>

Просмотреть файл

@ -40,8 +40,11 @@ async function test() {
offsetY: 100
});
await childMessagePromise;
is(clickCoordsInChild.offsetX, 100, "x coordinate is correct");
is(clickCoordsInChild.offsetY, 100, "y coordinate is correct");
// Need to use fuzzy comparisons because the combination of floating-point
// matrix multiplication and rounding to integer coordinates can result in
// small discrepancies.
isfuzzy(clickCoordsInChild.offsetX, 100, 1, "x coordinate is correct");
isfuzzy(clickCoordsInChild.offsetY, 100, 1, "y coordinate is correct");
}
waitUntilApzStable()

Просмотреть файл

@ -56,6 +56,7 @@ var subtests = [
{"file": "helper_hittest_obscuration.html", "prefs": prefs},
{"file": "helper_hittest_iframe_perspective.html", "prefs": prefs},
{"file": "helper_hittest_iframe_perspective-2.html", "prefs": prefs},
{"file": "helper_hittest_iframe_perspective-3.html", "prefs": prefs},
// This test should be at the end, because it's prone to timeout.
{"file": "helper_hittest_spam.html", "prefs": prefs},
];

Просмотреть файл

@ -262,9 +262,6 @@ Maybe<gfx::Matrix4x4> StackingContextHelper::GetDeferredTransformMatrix()
// transform from all the deferred ancestors, including
// mDeferredTransformItem.
gfx::Matrix4x4 result = mDeferredTransformItem->GetTransform().GetMatrix();
if (!mDeferredTransformItem->mFrame->Combines3DTransformWithAncestors()) {
result.ProjectTo2D();
}
if (mDeferredAncestorTransform) {
result = result * *mDeferredAncestorTransform;
}

Просмотреть файл

@ -6721,11 +6721,7 @@ bool nsDisplayTransform::UpdateScrollData(
return false;
}
if (aLayerData) {
auto matrix = GetTransform().GetMatrix();
if (!mFrame->Combines3DTransformWithAncestors()) {
matrix.ProjectTo2D();
}
aLayerData->SetTransform(matrix);
aLayerData->SetTransform(GetTransform().GetMatrix());
aLayerData->SetTransformIsPerspective(true);
}
return true;