Truly independent web browser
LibWeb: Resolve calc-size() with an auto basis in more layout paths
Andreas Kling5ebbb2fcf76a
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex f1fad7e291c..3b00ea84572 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -1782,6 +1782,30 @@ impl AbsposEngine<'_> {resolved_anchor_insets,);+ // NB: As in the inline axis, a calc-size() with an auto basis resolves against the block size auto gives the+ // box.+ if style.height().is_auto()+ && style.height().calc_size().is_some()+ && let Some(auto_block_size) = solution.block_size+ {+ let block_size = self.sizing().resolve_calc_size(+ node,+ SizingAxis::Block,+ style.height(),+ auto_block_size,+ constraints.percentage_basis_block_size,+ );+ solution = self.solve_non_replaced_block_once(+ node,+ available_space,+ constraints,+ static_position_rect,+ pass,+ Some(block_size),+ resolved_anchor_insets,+ );+ }+if solution.block_size.is_some() && !style.max_height().is_none() {let max_block_size = self.calculate_inner_size(node,diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rsindex 12e0d01bb9e..27a3dcccbb3 100644--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs@@ -840,7 +840,7 @@ impl<'pass> BlockFormattingContext<'pass> {// 3. If the resulting width is smaller than 'min-width', the rules above are applied again,// but this time using the value of 'min-width' as the computed value for 'width'.let min_width = style.min_width();- if !min_width.is_auto()+ if !crate::layout::sizing_context::is_plain_auto(min_width)&& let Some(value) = used_inline_size{let min_inline_size = calculate_inner_inline_size(min_width);@@ -1827,8 +1827,7 @@ impl<'pass> BlockFormattingContext<'pass> {let style = self.style(node);let box_is_html_element_in_quirks_mode = facts.document_in_quirks_mode()&& facts.is_html_html_element()- && style.height().is_auto()- && style.height().calc_size().is_none();+ && crate::layout::sizing_context::is_plain_auto(style.height());let block_size_is_definite_from_aspect_ratio = self.used(node).has_definite_inline_size()&& facts.has_preferred_aspect_ratio()&& self.sizing().box_is_sized_as_replaced_element(diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 888ba17ab66..a90b51867e0 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -65,9 +65,6 @@ pub(crate) struct SizingContext<'pass> {style_cache: Cell<Option<(Node, &'pass FfiStylePayloads)>>,}-/// Whether a size is auto without a calc-size() that changes the size auto gives.-/// NB: A replaced element's size given as calc-size() resolves to a used size that the other size follows through-/// the aspect ratio./// Whether a size is `auto` itself, rather than a calc-size() with an auto basis.pub(crate) fn is_plain_auto(size: &ComputedSize) -> bool {size.is_auto() && size.calc_size().is_none()@@ -462,7 +459,7 @@ impl<'pass> SizingContext<'pass> {preferred_block_size};// NB: A height given as calc-size() resolves to a used height that the width follows through the ratio.- let block_size_is_auto = computed_block_size.is_auto() && computed_block_size.calc_size().is_none();+ let block_size_is_auto = is_plain_auto(computed_block_size);let used_inline_size = if computed_inline_size.is_auto() {computed_inline_size.to_px(available_space.inline_size.to_px_or_zero())} else {diff --git a/Tests/LibWeb/Text/expected/css/calc-size-auto-basis-in-more-layouts.txt b/Tests/LibWeb/Text/expected/css/calc-size-auto-basis-in-more-layouts.txtnew file mode 100644index 00000000000..7ff2a28629d--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/calc-size-auto-basis-in-more-layouts.txt@@ -0,0 +1,8 @@+flex item with a clamped calc-size() height: 50px+flex item with a calc-size() min-height: 100px+percentage child of a flex item with a calc-size() height: 40px+replaced flex item with a calc-size() flex-basis: 50px+stretched flex item with a calc-size() height of an indefinite stretch: 60px+block with a calc-size() min-width: 200px+abspos with insets and a calc-size() height: 150px+abspos with a calc-size() height around its content: 60pxdiff --git a/Tests/LibWeb/Text/input/css/calc-size-auto-basis-in-more-layouts.html b/Tests/LibWeb/Text/input/css/calc-size-auto-basis-in-more-layouts.htmlnew file mode 100644index 00000000000..04f28d0980f--- /dev/null+++ b/Tests/LibWeb/Text/input/css/calc-size-auto-basis-in-more-layouts.html@@ -0,0 +1,28 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+.flex { display: flex; width: 300px; align-items: start; }+.content { width: 10px; height: 40px; }+.abspos-container { position: relative; width: 300px; height: 300px; }+</style>+<div class="flex"><div id="flex-max" style="height: calc-size(auto, size * 2); max-height: 50px"><div class="content"></div></div></div>+<div class="flex"><div id="flex-min" style="min-height: calc-size(auto, 100px)"><div class="content"></div></div></div>+<div class="flex"><div style="height: calc-size(auto, size + 10px)"><div id="flex-percentage-child" style="height: 100%"><div class="content"></div></div></div></div>+<div class="flex"><canvas id="flex-replaced" width="100" height="10" style="flex: 0 0 calc-size(max-content, size / 2); min-width: 0"></canvas></div>+<div style="display: flex"><div id="flex-stretched" style="height: calc-size(stretch, size + 10px)"><div class="content"></div></div><div style="height: 50px"></div></div>+<div id="block-min" style="width: 50px; min-width: calc-size(auto, 200px)"></div>+<div class="abspos-container"><div id="abspos-insets" style="position: absolute; top: 0; bottom: 0; height: calc-size(auto, size / 2)"></div></div>+<div class="abspos-container"><div id="abspos-content" style="position: absolute; height: calc-size(auto, size + 20px)"><div class="content"></div></div></div>+<script>+test(() => {+ const size = (id, property) => getComputedStyle(document.getElementById(id))[property];+ println(`flex item with a clamped calc-size() height: ${size("flex-max", "height")}`);+ println(`flex item with a calc-size() min-height: ${size("flex-min", "height")}`);+ println(`percentage child of a flex item with a calc-size() height: ${size("flex-percentage-child", "height")}`);+ println(`replaced flex item with a calc-size() flex-basis: ${size("flex-replaced", "width")}`);+ println(`stretched flex item with a calc-size() height of an indefinite stretch: ${size("flex-stretched", "height")}`);+ println(`block with a calc-size() min-width: ${size("block-min", "width")}`);+ println(`abspos with insets and a calc-size() height: ${size("abspos-insets", "height")}`);+ println(`abspos with a calc-size() height around its content: ${size("abspos-content", "height")}`);+});+</script>