From 8fb49fe5072fdc220c5b122df6cb569d67fd9c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Wed, 23 Sep 2026 13:42:36 +0200 Subject: [PATCH] Match Chrome's root scroll size and clamp x too Only the root scroller's scrollWidth and scrollHeight are floored at the viewport; html and body keep the document's own height, as in Chrome. The document's width is body's widest child, and scrollX clamps against it. --- src/browser/Frame.zig | 11 ++- src/browser/tests/element/position.html | 4 +- src/browser/tests/mcp_actions.html | 2 +- src/browser/tests/window_scroll.html | 10 +-- src/browser/webapi/Element.zig | 94 ++++++++++++++++++------- src/browser/webapi/Window.zig | 18 +++-- 6 files changed, 96 insertions(+), 43 deletions(-) diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig index 8c1d7bcad..d8f8f8d5e 100644 --- a/src/browser/Frame.zig +++ b/src/browser/Frame.zig @@ -155,9 +155,14 @@ _focus_fixup_pending: bool = false, _style_manager: StyleManager, -// Element.documentHeight, valid while the style version and viewport height -// it was computed for hold. -_document_height: ?struct { version: usize, viewport: u32, value: f64 } = null, +// Element.documentExtent, valid while the style version and viewport it was +// computed for hold. +_document_extent: ?struct { + version: usize, + viewport_width: u32, + viewport_height: u32, + extent: Element.DocumentExtent, +} = null, _script_manager: ScriptManager, _http_owner: HttpClient.Owner, diff --git a/src/browser/tests/element/position.html b/src/browser/tests/element/position.html index eeeace6bc..8b696c269 100644 --- a/src/browser/tests/element/position.html +++ b/src/browser/tests/element/position.html @@ -343,11 +343,11 @@ // per cell, which a document-sized box turned into ~5M walks. testing.expectEqual(document.body.clientHeight, document.body.scrollHeight); testing.expectEqual(window.innerHeight, document.documentElement.clientHeight); + // What the viewport scrolls over: the document, or the viewport itself testing.expectEqual( - document.documentElement.offsetHeight, + Math.max(document.documentElement.offsetHeight, document.documentElement.clientHeight), document.documentElement.scrollHeight, ); - testing.expectTrue(document.documentElement.scrollHeight >= document.documentElement.clientHeight); } diff --git a/src/browser/tests/mcp_actions.html b/src/browser/tests/mcp_actions.html index 75bda144f..c407bffa6 100644 --- a/src/browser/tests/mcp_actions.html +++ b/src/browser/tests/mcp_actions.html @@ -71,6 +71,6 @@ document.getElementById('rad').addEventListener('change', function() { window.radChanged = true; }); -
+
diff --git a/src/browser/tests/window_scroll.html b/src/browser/tests/window_scroll.html index dda8a1d51..89c1fa498 100644 --- a/src/browser/tests/window_scroll.html +++ b/src/browser/tests/window_scroll.html @@ -2,7 +2,7 @@ -
+