From 2fc1cafb8af07d807663338875859e193dd66e03 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Fri, 25 Apr 2025 11:54:15 +0200 Subject: [PATCH] LibWeb: Exclude fixed positioned boxes from scrollable overflow Sometimes fixed positioned boxes would extend the viewport's scrollable overflow, which according to the spec should never happen. There are some nuances to this, such as properly determining the fixed positioning containing block for a fixed position box, but for now this prevents some pages from being overly scrollable. Fixes horizontal scrollability of https://tweakers.net. --- Libraries/LibWeb/Layout/LayoutState.cpp | 7 +++++++ ...crollable-viewport-with-position-fixed.txt | 1 + ...rollable-viewport-with-position-fixed.html | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/scrollable-viewport-with-position-fixed.txt create mode 100644 Tests/LibWeb/Text/input/scrollable-viewport-with-position-fixed.html diff --git a/Libraries/LibWeb/Layout/LayoutState.cpp b/Libraries/LibWeb/Layout/LayoutState.cpp index c73c431004e..33c825e81fc 100644 --- a/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Libraries/LibWeb/Layout/LayoutState.cpp @@ -85,6 +85,13 @@ static CSSPixelRect measure_scrollable_overflow(Box const& box) if (child.containing_block() != &box) return TraversalDecision::Continue; + // https://drafts.csswg.org/css-position/#fixed-positioning-containing-block + // [..] As a result, parts of fixed-positioned boxes that extend outside the layout viewport/page area + // cannot be scrolled to and will not print. + // FIXME: Properly establish the fixed positioning containing block for `position: fixed` + if (child.is_fixed_position()) + return TraversalDecision::Continue; + auto child_border_box = child.paintable_box()->absolute_border_box_rect(); // Border boxes with zero area do not affect the scrollable overflow area. diff --git a/Tests/LibWeb/Text/expected/scrollable-viewport-with-position-fixed.txt b/Tests/LibWeb/Text/expected/scrollable-viewport-with-position-fixed.txt new file mode 100644 index 00000000000..227cd9056be --- /dev/null +++ b/Tests/LibWeb/Text/expected/scrollable-viewport-with-position-fixed.txt @@ -0,0 +1 @@ +{"x":8,"y":8,"width":784,"height":17,"top":8,"right":792,"bottom":25,"left":8} diff --git a/Tests/LibWeb/Text/input/scrollable-viewport-with-position-fixed.html b/Tests/LibWeb/Text/input/scrollable-viewport-with-position-fixed.html new file mode 100644 index 00000000000..dc4e75cd71e --- /dev/null +++ b/Tests/LibWeb/Text/input/scrollable-viewport-with-position-fixed.html @@ -0,0 +1,21 @@ + + + +
bar
+
foo
+