Truly independent web browser
LibWeb: Shrink-wrap aspect-ratio boxes with intrinsic block sizes
sideshowbarker6d53ed298e43
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 7d3cc6ba26b..81987b7c06b 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -1273,6 +1273,16 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {return true;}if facts.has_preferred_aspect_ratio() || facts.has_auto_content_box_size() {+ // An intrinsic block size depends on content layout, so it can't determine an automatic inline size+ // through the aspect ratio. Non-replaced boxes use their normal inline sizing rules in that case.+ if !facts.is_replaced_box()+ && self.should_treat_inline_size_as_auto(sized, available_space)+ && self+ .preferred_block_size(node, constraints)+ .is_intrinsic_sizing_constraint()+ {+ return false;+ }// From CSS2:// If height and width both have computed values of auto and the element has an intrinsic ratio but no intrinsic height or width,// then the used value of width is undefined in CSS 2.diff --git a/Tests/LibWeb/Text/expected/css/aspect-ratio-auto-width-intrinsic-height.txt b/Tests/LibWeb/Text/expected/css/aspect-ratio-auto-width-intrinsic-height.txtnew file mode 100644index 00000000000..b7e387176e5--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/aspect-ratio-auto-width-intrinsic-height.txt@@ -0,0 +1,10 @@+auto/min-content: border 60x64; computed 28pxx32px+auto/auto: border 60x64; computed 28pxx32px+fit-content/min-content: border 60x64; computed 28pxx32px+auto/max-content: border 60x64; computed 28pxx32px+auto/fit-content: border 60x64; computed 28pxx32px+min-content/min-content: border 60x64; computed 28pxx32px+auto/min-content no ratio: border 60x64; computed 28pxx32px+auto/32px: border 64x64; computed 32pxx32px+auto/min-content no padding: border 28x32; computed 28pxx32px+auto/min-content border-box: border 60x64; computed 60pxx64pxdiff --git a/Tests/LibWeb/Text/input/css/aspect-ratio-auto-width-intrinsic-height.html b/Tests/LibWeb/Text/input/css/aspect-ratio-auto-width-intrinsic-height.htmlnew file mode 100644index 00000000000..4a319998a4b--- /dev/null+++ b/Tests/LibWeb/Text/input/css/aspect-ratio-auto-width-intrinsic-height.html@@ -0,0 +1,39 @@+<!doctype html>+<meta charset="utf-8">+<style>+ .container { width: 300px; }+ .box { display: inline-block; padding: 16px; aspect-ratio: 1; }+ .child { width: 28px; height: 32px; }+</style>+<script src="../include.js"></script>+<script>+test(() => {+ const cases = [+ ["auto/min-content", "width:auto; height:min-content"],+ ["auto/auto", "width:auto; height:auto"],+ ["fit-content/min-content", "width:fit-content; height:min-content"],+ ["auto/max-content", "width:auto; height:max-content"],+ ["auto/fit-content", "width:auto; height:fit-content"],+ ["min-content/min-content", "width:min-content; height:min-content"],+ ["auto/min-content no ratio", "width:auto; height:min-content; aspect-ratio:auto"],+ ["auto/32px", "width:auto; height:32px"],+ ["auto/min-content no padding", "width:auto; height:min-content; padding:0"],+ ["auto/min-content border-box", "width:auto; height:min-content; box-sizing:border-box"],+ ];+ for (const [label, style] of cases) {+ const container = document.createElement("div");+ container.className = "container";+ const box = document.createElement("div");+ box.className = "box";+ box.style.cssText = style;+ const child = document.createElement("div");+ child.className = "child";+ box.append(child);+ container.append(box);+ document.body.append(container);+ const rect = box.getBoundingClientRect();+ const computed = getComputedStyle(box);+ println(`${label}: border ${rect.width}x${rect.height}; computed ${computed.width}x${computed.height}`);+ }+});+</script>