Skip to content

Truly independent web browser

LibWeb: Preserve lone sticky insets on oversized boxes

sideshowbarkerb8dc7d97a487
diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/refresh.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/refresh.rs
index d5b54d33f36..3e9c24374a5 100644
--- a/Libraries/LibWeb/Rust/src/painting/visual_context/refresh.rs
+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/refresh.rs
@@ -86,8 +86,12 @@ fn resolve_sticky_insets_in_css_pixels(
Side::Top | Side::Bottom => (Side::Top, Side::Bottom, scrollport_size.height, border_box_size.height),
Side::Left | Side::Right => (Side::Left, Side::Right, scrollport_size.width, border_box_size.width),
};
- let view_extent =
- extent - insets[first as usize].unwrap_or_default() - insets[second as usize].unwrap_or_default();
+ // AD-HOC: Preserve a lone specified inset when its opposite side is auto. Although the rule above treats auto
+ // as zero, reducing that inset would detach an oversized box from the edge the page specified.
+ let (Some(first_inset), Some(second_inset)) = (insets[first as usize], insets[second as usize]) else {
+ continue;
+ };
+ let view_extent = extent - first_inset - second_inset;
if let Some(inset) = insets[end as usize].as_mut() {
*inset -= (border_extent - view_extent).max(CssPixels::default());
}
diff --git a/Tests/LibWeb/Text/expected/css/oversized-sticky-end-inset.txt b/Tests/LibWeb/Text/expected/css/oversized-sticky-end-inset.txt
new file mode 100644
index 00000000000..51eb9b58177
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/oversized-sticky-end-inset.txt
@@ -0,0 +1,21 @@
+scroll=0: top=80, bottom=340
+scroll=150: top=-70, bottom=190
+scroll=400: top=-70, bottom=190
+horizontal-tb, block, end: -70
+horizontal-tb, block, both: 10
+horizontal-tb, block, start: 10
+horizontal-tb, inline, end: -70
+horizontal-tb, inline, both: 10
+horizontal-tb, inline, start: 10
+vertical-rl, block, end: -70
+vertical-rl, block, both: 10
+vertical-rl, block, start: 10
+vertical-rl, inline, end: -70
+vertical-rl, inline, both: 10
+vertical-rl, inline, start: 10
+vertical-lr, block, end: -70
+vertical-lr, block, both: 10
+vertical-lr, block, start: 10
+vertical-lr, inline, end: -70
+vertical-lr, inline, both: 10
+vertical-lr, inline, start: 10
diff --git a/Tests/LibWeb/Text/input/css/oversized-sticky-end-inset.html b/Tests/LibWeb/Text/input/css/oversized-sticky-end-inset.html
new file mode 100644
index 00000000000..cb42221d890
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/oversized-sticky-end-inset.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<style>
+ .scroller { width: 360px; height: 200px; overflow: auto; border: 4px solid; scrollbar-width: none; }
+ .lead { height: 80px; }
+ .holder { height: 500px; }
+ .filler { height: 460px; }
+ .sticky { position: sticky; bottom: 10px; width: 180px; height: 260px; }
+ .tail { height: 300px; }
+</style>
+<div class="scroller"><div class="lead"></div><div class="holder"><div class="filler"></div><div class="sticky"></div></div><div class="tail"></div></div>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ const scroller = document.querySelector(".scroller");
+ const sticky = document.querySelector(".sticky");
+ for (const scroll of [0, 150, 400]) {
+ scroller.scrollTop = scroll;
+ const box = sticky.getBoundingClientRect();
+ const origin = scroller.getBoundingClientRect().top + scroller.clientTop;
+ println(`scroll=${scroll}: top=${box.top - origin}, bottom=${box.bottom - origin}`);
+ }
+ scroller.remove();
+ for (const mode of ["horizontal-tb", "vertical-rl", "vertical-lr"]) {
+ for (const axis of ["block", "inline"]) {
+ for (const insets of ["end", "both", "start"]) {
+ const scroller = document.createElement("div");
+ const vertical = (mode === "horizontal-tb") !== (axis === "inline");
+ const reversed = axis === "block" && mode === "vertical-rl";
+ scroller.style.cssText = `writing-mode:${mode}; ${axis}-size:200px; overflow:auto; scrollbar-width:none; border:4px solid; font-size:0`;
+ scroller.style.setProperty(axis === "block" ? "inline-size" : "block-size", "180px");
+ const container = document.createElement("div");
+ container.style.cssText = `${axis}-size:800px; display:flex; flex-direction:${axis === "block" ? "column" : "row"}`;
+ const lead = document.createElement("div");
+ lead.style.cssText = `flex:none; ${axis}-size:300px`;
+ const sticky = document.createElement("div");
+ sticky.style.cssText = `position:sticky; flex:none; ${axis}-size:260px; inset-${axis}-start:${insets === "end" ? "auto" : "10px"}; inset-${axis}-end:${insets === "start" ? "auto" : "10px"}`;
+ container.append(lead, sticky);
+ scroller.append(container);
+ document.body.append(scroller);
+ if (vertical) scroller.scrollTop = 350;
+ else scroller.scrollLeft = reversed ? -350 : 350;
+ const s = scroller.getBoundingClientRect();
+ const r = sticky.getBoundingClientRect();
+ const start = vertical ? r.top - s.top - 4 : reversed ? s.right - 4 - r.right : r.left - s.left - 4;
+ println(`${mode}, ${axis}, ${insets}: ${start}`);
+ scroller.remove();
+ }
+ }
+ }
+ });
+</script>