Truly independent web browser
LibWeb: Use inset-derived heights for abspos intrinsic widths
sideshowbarkerf4802ff4aec8
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 2b6b4927d03..37c0afbd650 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -1951,6 +1951,55 @@ impl AbsposEngine<'_> {equation.stretch_fit_size()}+ fn stretch_block_size_for_intrinsic_inline_sizing(+ &self,+ sized: OutOfFlowBox<'_>,+ inputs: &abspos_inputs::AbsposLayoutInputs,+ available_space: AvailableSpace,+ constraints: ContainingBlockConstraints,+ ) -> Option<CssPixels> {+ let style = self.style_of(sized);+ if !style.height().is_auto() || self.sizing().establishes_orthogonal_flow(sized.node) {+ return None;+ }+ let equation = self.axis_equation(+ sized,+ inputs,+ SizingAxis::Block,+ available_space.block_size.to_px_or_zero(),+ available_space.inline_size.to_px_or_zero(),+ self.auto_margin_overflow(inputs.containing_block, SizingAxis::Block),+ );+ if self.sizes_to_fit_content(sized, equation, false) {+ return None;+ }+ // https://drafts.csswg.org/css-sizing-3/#definite+ // The stretch-fit block size is definite without laying out the contents. Descendant percentages resolve+ // against it during intrinsic inline sizing, with only definite minimum and maximum sizes applied.+ let mut block_size = equation.stretch_fit_size();+ if style.height().calc_size().is_some() {+ block_size = self.sizing().resolve_calc_size(+ sized.sized_box(),+ SizingAxis::Block,+ style.height(),+ block_size,+ constraints.percentage_basis_block_size,+ );+ }+ let inner_size = |size: &ComputedSize| {+ self.calculate_inner_size(sized, SizingAxis::Block, size, available_space, constraints, inputs)+ };+ if !style.max_height().is_none() && !style.max_height().is_intrinsic_sizing_constraint() {+ block_size = block_size.min(inner_size(style.max_height()));+ }+ if !crate::layout::sizing_context::is_plain_auto(style.min_height())+ && !style.min_height().is_intrinsic_sizing_constraint()+ {+ block_size = block_size.max(inner_size(style.min_height()));+ }+ Some(block_size)+ }+/// The content inline size of a non-replaced box: its specified size, or the size that auto gives it in the space/// between its insets and margins, adjusted by calc-size() and its limits.fn non_replaced_inline_size(@@ -1991,11 +2040,31 @@ impl AbsposEngine<'_> {// https://drafts.csswg.org/css-position-3/#abspos-auto-size// For the purpose of computing these sizes, any auto margins are treated as zero.let available = Self::shrink_to_fit_available_size(inputs, SizingAxis::Inline, equation);- let preferred = sizing.calculate_max_content_inline_size(sized.sized_box(), constraints);+ let block_size =+ self.stretch_block_size_for_intrinsic_inline_sizing(sized, inputs, available_space, constraints);+ let preferred = block_size.map_or_else(+ || sizing.calculate_max_content_inline_size(sized.sized_box(), constraints),+ |block_size| {+ sizing.calculate_max_content_inline_size_at_definite_block_size(+ sized.sized_box(),+ constraints,+ block_size,+ )+ },+ );if preferred <= available {preferred} else {- let preferred_minimum = sizing.calculate_min_content_inline_size(sized.sized_box(), constraints);+ let preferred_minimum = block_size.map_or_else(+ || sizing.calculate_min_content_inline_size(sized.sized_box(), constraints),+ |block_size| {+ sizing.calculate_min_content_inline_size_at_definite_block_size(+ sized.sized_box(),+ constraints,+ block_size,+ )+ },+ );preferred_minimum.max(available).min(preferred)}};diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-005.htmlnew file mode 100644index 00000000000..bcb7b525fa9--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-005.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#intrinsic-sizes">+<meta name="assert" content="Checks that a replaced element, with an aspect ratio, converts a percent height into an intrinsic width." />+<link rel="match" href="../../../../expected/wpt-import/css/css-sizing/../reference/ref-filled-green-100px-square-only.html">+<style>+#container { position: relative; height: 100px; }+#abs { position: absolute; top: 0; bottom: 0; background: green; }+canvas { height: 100%; }+</style>+<p>Test passes if there is a filled green square.</p>+<div id=container>+ <div id=abs>+ <canvas width=10 height=10></canvas>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-007.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-007.htmlnew file mode 100644index 00000000000..8f5e0974275--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-007.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#intrinsic-sizes">+<meta name="assert" content="Checks that a replaced element, with an aspect ratio, converts a percent height into an intrinsic width." />+<link rel="match" href="../../../../expected/wpt-import/css/css-sizing/../reference/ref-filled-green-100px-square-only.html">+<style>+#container { position: relative; height: 200px; }+#abs { position: absolute; top: 0; bottom: 100px; background: green; }+canvas { height: 100%; }+</style>+<p>Test passes if there is a filled green square.</p>+<div id=container>+ <div id=abs>+ <canvas width=10 height=10></canvas>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-008.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-008.htmlnew file mode 100644index 00000000000..de7a49d87fa--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-008.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#intrinsic-sizes">+<meta name="assert" content="Checks that a replaced element, with an aspect ratio, converts a percent height into an intrinsic width." />+<link rel="match" href="../../../../expected/wpt-import/css/css-sizing/../reference/ref-filled-green-100px-square-only.html">+<style>+#container { position: relative; width: 200px; height: 200px; }+#abs { writing-mode: vertical-lr; position: absolute; left: 0; right: 100px; background: green; }+canvas { width: 100%; }+</style>+<p>Test passes if there is a filled green square.</p>+<div id=container>+ <div id=abs>+ <canvas width=10 height=10></canvas>+ </div>+</div>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-005.htmlnew file mode 100644index 00000000000..1bd79fba363--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-005.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#intrinsic">+<link rel="match" href="../../../../expected/wpt-import/css/css-sizing/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="This test checks that a dynamic change in the height of an element calculates the intrinsic min/max size correctly when a replaced element is present."/>+<p>Test passes if there is a filled green square.</p>+<div style="position: relative; width: 100px; height: 100px;">+ <div id="target" style="position: absolute; top:0; background: green;">+ <canvas width="1" height="1" style="height: 100%;"></canvas>+ </div>+</div>+<script>+ document.body.offsetTop;+ document.getElementById('target').style.bottom = '0px';+</script>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-007.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-007.htmlnew file mode 100644index 00000000000..ffebc02d470--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-007.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#intrinsic">+<link rel="match" href="../../../../expected/wpt-import/css/css-sizing/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="This test checks that a dynamic change in the height of an element calculates the intrinsic min/max size correctly when a replaced element is present."/>+<p>Test passes if there is a filled green square.</p>+<div style="position: relative; width: 100px; height: 200px;">+ <div id="target" style="position: absolute; top:0; bottom: 0; background: green;">+ <canvas width="1" height="1" style="height: 100%;"></canvas>+ </div>+</div>+<script>+ document.body.offsetTop;+ document.getElementById('target').style.bottom = '100px';+</script>diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-008.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-008.htmlnew file mode 100644index 00000000000..e7dddf61395--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-sizing/intrinsic-percent-replaced-dynamic-008.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#intrinsic">+<link rel="match" href="../../../../expected/wpt-import/css/css-sizing/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="This test checks that a dynamic change in the height of an element calculates the intrinsic min/max size correctly when a replaced element is present."/>+<p>Test passes if there is a filled green square.</p>+<div style="position: relative; width: 200px; height: 200px;">+ <div id="target" style="writing-mode: vertical-lr; position: absolute; left: 0; right: 0; background: green;">+ <canvas width="1" height="1" style="width: 100%;"></canvas>+ </div>+</div>+<script>+ document.body.offsetTop;+ document.getElementById('target').style.right = '100px';+</script>diff --git a/Tests/LibWeb/Text/expected/abspos-inset-height-intrinsic-width.txt b/Tests/LibWeb/Text/expected/abspos-inset-height-intrinsic-width.txtnew file mode 100644index 00000000000..dda657fa929--- /dev/null+++ b/Tests/LibWeb/Text/expected/abspos-inset-height-intrinsic-width.txt@@ -0,0 +1,48 @@+block horizontal-tb: box 200x100, image 200x100+block vertical-rl: box 100x50, image 100x50+block vertical-lr: box 100x50, image 100x50+block rtl: box 200x100, image 200x100+block explicit height: box 200x100, image 200x100+block insets: box 120x60, image 120x60+block box model: box 140x80, image 120x60+block percentage margins: box 122x61, image 122x61+block max height: box 120x60, image 120x60+block min height: box 280x140, image 280x140+block percentage max height: box 100x50, image 100x50+block minimum wins: box 240x120, image 240x120+block border-box limit: box 100x60, image 80x40+block intrinsic maximum: box 200x100, image 200x100+block max width: box 100x100, image 200x100+block min width: box 300x100, image 200x100+block narrow container: box 200x100, image 200x100+block auto height: box 400x200, image 400x200+block content height: box 400x200, image 400x200+block before resize: box 200x100, image 200x100+block after resize: box 300x150, image 300x150+block changed inset: box 100x50, image 100x50+block removed inset: box 400x200, image 400x200+block restored inset: box 300x150, image 300x150+flex horizontal-tb: box 200x100, image 200x100+flex vertical-rl: box 100x50, image 100x50+flex vertical-lr: box 100x50, image 100x50+flex rtl: box 200x100, image 200x100+flex explicit height: box 200x100, image 200x100+flex insets: box 120x60, image 120x60+flex box model: box 140x80, image 120x60+flex percentage margins: box 122x61, image 122x61+flex max height: box 120x60, image 120x60+flex min height: box 280x140, image 280x140+flex percentage max height: box 100x50, image 100x50+flex minimum wins: box 240x120, image 240x120+flex border-box limit: box 100x60, image 80x40+flex intrinsic maximum: box 200x100, image 200x100+flex max width: box 100x100, image 200x100+flex min width: box 300x100, image 200x100+flex narrow container: box 200x100, image 200x100+flex auto height: box 400x200, image 400x200+flex content height: box 400x200, image 400x200+flex before resize: box 200x100, image 200x100+flex after resize: box 300x150, image 300x150+flex changed inset: box 100x50, image 100x50+flex removed inset: box 400x200, image 400x200+flex restored inset: box 300x150, image 300x150diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/abspos/stretch-intrinsic-size-vrl-vrl.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/abspos/stretch-intrinsic-size-vrl-vrl.txtindex 9ae4d2d8b23..e4951b11462 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/abspos/stretch-intrinsic-size-vrl-vrl.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/abspos/stretch-intrinsic-size-vrl-vrl.txt@@ -2,15 +2,15 @@ Harness status: OKFound 12 tests-5 Pass-7 Fail+7 Pass+5 FailPass .item 1Fail .item 2-Fail .item 3+Pass .item 3Pass .item 4Pass .item 5Pass .item 6-Fail .item 7+Pass .item 7Fail .item 8Pass .item 9Fail .item 10diff --git a/Tests/LibWeb/Text/input/abspos-inset-height-intrinsic-width.html b/Tests/LibWeb/Text/input/abspos-inset-height-intrinsic-width.htmlnew file mode 100644index 00000000000..eed98314348--- /dev/null+++ b/Tests/LibWeb/Text/input/abspos-inset-height-intrinsic-width.html@@ -0,0 +1,95 @@+<!doctype html>+<script src="include.js"></script>+<style>+ .container {+ position: relative;+ inline-size: 390px;+ block-size: 100px;+ }+ .absolute {+ position: absolute;+ inset-block: 0;+ inset-inline-start: 0;+ line-height: 0;+ }+ .child {+ display: block;+ block-size: 100%;+ }+ img {+ block-size: 100%;+ }+</style>+<script>+ promiseTest(async () => {+ const image = new Image();+ image.src =+ "data:image/svg+xml," ++ encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="400" height="200"></svg>');+ await image.decode();+ function add(style = "", containerStyle = "") {+ const container = document.createElement("div");+ container.className = "container";+ container.style.cssText = containerStyle;+ const box = document.createElement("div");+ box.className = "absolute";+ box.style.cssText = style;+ const child = document.createElement("a");+ child.className = "child";+ child.append(image.cloneNode());+ box.append(child);+ container.append(box);+ document.body.append(container);+ return [container, box];+ }+ function report(name, container, box) {+ const size = element => {+ const rect = element.getBoundingClientRect();+ return `${Math.round(rect.width)}x${Math.round(rect.height)}`;+ };+ println(`${name}: box ${size(box)}, image ${size(box.querySelector("img"))}`);+ }+ for (const display of ["block", "flex"]) {+ for (const mode of ["horizontal-tb", "vertical-rl", "vertical-lr"]) {+ report(`${display} ${mode}`, ...add(`display: ${display}`, `writing-mode: ${mode}`));+ }+ report(`${display} rtl`, ...add(`display: ${display}`, "direction: rtl"));+ report(`${display} explicit height`, ...add(`display: ${display}; block-size: 100px`));+ report(`${display} insets`, ...add(`display: ${display}; inset-block: 10px 30px`));+ report(+ `${display} box model`,+ ...add(`display: ${display}; padding: 5px; border: 5px solid; margin: 10px`)+ );+ report(`${display} percentage margins`, ...add(`display: ${display}; margin-block: 5%`));+ report(`${display} max height`, ...add(`display: ${display}; max-block-size: 60px`));+ report(`${display} min height`, ...add(`display: ${display}; min-block-size: 140px`));+ report(`${display} percentage max height`, ...add(`display: ${display}; max-block-size: 50%`));+ report(+ `${display} minimum wins`,+ ...add(`display: ${display}; min-block-size: 120px; max-block-size: 60px`)+ );+ report(+ `${display} border-box limit`,+ ...add(+ `display: ${display}; padding: 5px; border: 5px solid; box-sizing: border-box; max-block-size: 60px`+ )+ );+ report(`${display} intrinsic maximum`, ...add(`display: ${display}; max-block-size: max-content`));+ report(`${display} max width`, ...add(`display: ${display}; max-inline-size: 100px`));+ report(`${display} min width`, ...add(`display: ${display}; min-inline-size: 300px`));+ report(`${display} narrow container`, ...add(`display: ${display}`, "inline-size: 100px"));+ report(`${display} auto height`, ...add(`display: ${display}; inset-block-end: auto`));+ report(`${display} content height`, ...add(`display: ${display}; block-size: max-content`));+ const [container, box] = add(`display: ${display}`);+ report(`${display} before resize`, container, box);+ container.style.blockSize = "150px";+ report(`${display} after resize`, container, box);+ box.style.insetBlockEnd = "100px";+ report(`${display} changed inset`, container, box);+ box.style.insetBlockEnd = "auto";+ report(`${display} removed inset`, container, box);+ box.style.insetBlockEnd = "0";+ report(`${display} restored inset`, container, box);+ }+ });+</script>