Files
ladybird/Tests/LibWeb/Text/input/scroll-with-pinch-zoom-applied.html
Aliaksandr Kalenik f63674e92d LibWeb: Fix scroll regression when pinch-to-zoom is applied
When scrolling with a visual viewport offset (from pinch-to-zoom),
scroll_viewport_by_delta() was passing m_viewport_scroll_offset + delta
to perform_a_scroll_of_the_viewport(). However, that function calculates
the scroll delta as `position - page_top()`, where page_top() includes
the visual viewport offset. This caused the effective scroll delta to be
reduced by the visual offset amount.

Fix by using the current page position (which includes the visual
offset) as the base for the delta calculation.

Regression from 0a57e1e8ac.
2026-01-23 17:52:50 +01:00

57 lines
1.7 KiB
HTML

<!DOCTYPE html>
<style>
body {
margin: 0;
overflow: scroll;
}
.spacer {
height: 3000px;
background: linear-gradient(to bottom, red, blue);
}
</style>
<div class="spacer"></div>
<script src="include.js"></script>
<script>
asyncTest(done => {
const vv = window.visualViewport;
const scrollDelta = 100;
println(`Initial: pageTop=${vv.pageTop}, scale=${vv.scale}`);
// First, zoom in
vv.addEventListener("resize", function onResize() {
vv.removeEventListener("resize", onResize);
println(`After zoom: pageTop=${vv.pageTop}, scale=${vv.scale}, offsetTop=${vv.offsetTop}`);
const pageTopBefore = vv.pageTop;
// Scroll down
internals.wheel(100, 100, 0, scrollDelta);
// Poll for changes since scroll events may not fire for visual viewport panning
requestAnimationFrame(() => {
const pageTopAfter = vv.pageTop;
const scrolled = pageTopAfter - pageTopBefore;
println(`pageTop changed by: ${scrolled}`);
// The scroll amount should be approximately equal to the requested delta
// Allow small tolerance for floating point
if (Math.abs(scrolled - scrollDelta) < 1) {
println("PASS");
} else {
println(`FAIL: Expected scroll of ${scrollDelta}, got ${scrolled}`);
}
done();
});
});
requestAnimationFrame(() => {
// Zoom in (scale increases with positive delta)
internals.pinch(100, 100, 0.5);
});
});
</script>