Truly independent web browser
LibWeb: Ignore anonymous flow wrappers for sticky bounds
sideshowbarkerf5cc89e7aa56
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/refresh.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/refresh.rsindex c71c987ddb1..5927342ff28 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/refresh.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/refresh.rs@@ -192,7 +192,18 @@ pub(crate) fn compute_sticky_data(}let sticky_border_box_rect = paintable_geometry::absolute_border_box_rect(layout_arena, paintable);- let containing_block = layout_arena.paintable_data(paintable).containing_block;+ let mut containing_block = layout_arena.paintable_data(paintable).containing_block;+ // https://drafts.csswg.org/css2/#anonymous-block-level+ // Anonymous flow wrappers group inline content, but their bounds don't constrain sticky movement.+ while style_queries::is_anonymous(layout_arena, containing_block)+ && style_queries::display(layout_arena, containing_block).is_flow_inside()+ && !layout_arena.node_is_generated_for_pseudo_element(containing_block)+ {+ containing_block = layout_arena.paintable_data(containing_block).containing_block;+ if !layout_arena.paintable_row_is_populated(containing_block) {+ return data;+ }+ }let scroller_rect = paintable_geometry::absolute_rect(layout_arena, scroller);// NB: The box moves within the content box of its containing block, less its own margins. For the scroll// container itself, that is its scrollable overflow rectangle less its padding. This matches other engines.diff --git a/Tests/LibWeb/Text/expected/position-sticky-in-anonymous-block.txt b/Tests/LibWeb/Text/expected/position-sticky-in-anonymous-block.txtnew file mode 100644index 00000000000..47420045b34--- /dev/null+++ b/Tests/LibWeb/Text/expected/position-sticky-in-anonymous-block.txt@@ -0,0 +1,11 @@+inline: 0, 0, 0+unset: 0, 0, 0+nested inline: 0, 0, 0+inline text before and after: 20, 0, 0+sticky inline-block: 0, 0, 0+real containing block: 0, -50, -150+tall containing block: 0, 0, -70+padded containing block: 25, 0, -55+fieldset without legend: 0, 0, -70+fieldset content: 30, -20, -120+horizontal: 0, 0, 0, 0diff --git a/Tests/LibWeb/Text/input/position-sticky-in-anonymous-block.html b/Tests/LibWeb/Text/input/position-sticky-in-anonymous-block.htmlnew file mode 100644index 00000000000..62b9f35892d--- /dev/null+++ b/Tests/LibWeb/Text/input/position-sticky-in-anonymous-block.html@@ -0,0 +1,53 @@+<!DOCTYPE html>+<style>+ body { margin: 0; }+ .scroller { width: 200px; height: 100px; overflow: auto; }+ .sticky { position: sticky; top: 0; height: 20px; }+ .filler { height: 300px; }+</style>+<script src="include.js"></script>+<script>+ test(() => {+ const cases = [+ ["inline", '<div style="display: inline"><header class="sticky"></header></div>'],+ ["unset", '<div style="display: unset"><header class="sticky"></header></div>'],+ ["nested inline", '<span><span><header class="sticky"></header></span></span>'],+ ["inline text before and after", '<span style="line-height: 20px">Before<header class="sticky"></header>After</span>'],+ ["sticky inline-block", '<span><span class="sticky" style="display: inline-block; width: 20px"></span></span>'],+ ["real containing block", '<div><span><header class="sticky"></header></span></div>'],+ ["tall containing block", '<div style="height: 100px"><span><header class="sticky"></header></span><div></div></div>'],+ ["padded containing block", '<div style="height: 100px; padding: 20px; border: 5px solid"><span><header class="sticky" style="margin-bottom: 10px"></header></span><div></div></div>'],+ ["fieldset without legend", '<fieldset style="margin: 0; border: 0; padding: 0; height: 100px"><span><header class="sticky"></header></span><div></div></fieldset>'],+ ["fieldset content", '<fieldset style="margin: 0; border: 0; padding: 0; height: 100px"><legend style="padding: 0; height: 30px">Legend</legend><header class="sticky" style="top: auto; bottom: 90px"></header></fieldset>'],+ ];+ const results = [];+ for (const [name, content] of cases) {+ const scroller = document.createElement("div");+ scroller.className = "scroller";+ scroller.innerHTML = `${content}<div class="filler"></div>`;+ document.body.append(scroller);+ const sticky = scroller.querySelector(".sticky");+ const positions = [];+ for (const offset of [0, 50, 150]) {+ scroller.scrollTop = offset;+ positions.push(sticky.getBoundingClientRect().top - scroller.getBoundingClientRect().top);+ }+ results.push(`${name}: ${positions.join(", ")}`);+ scroller.remove();+ }+ const horizontal = document.createElement("div");+ horizontal.className = "scroller";+ horizontal.style.width = "100px";+ horizontal.innerHTML = '<span><header class="sticky" style="top: auto; left: 0; width: 20px"></header></span><div style="width: 300px; height: 20px"></div>';+ document.body.append(horizontal);+ const sticky = horizontal.querySelector(".sticky");+ const positions = [];+ for (const offset of [0, 50, 150, 200]) {+ horizontal.scrollLeft = offset;+ positions.push(sticky.getBoundingClientRect().left - horizontal.getBoundingClientRect().left);+ }+ results.push(`horizontal: ${positions.join(", ")}`);+ horizontal.remove();+ results.forEach(println);+ });+</script>