Skip to content

Truly independent web browser

LibWeb: Keep content-sized abspos flex container heights indefinite

sideshowbarker2e2af3549a27
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index 5da81276e90..faabc135ef9 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -2388,12 +2388,14 @@ impl AbsposEngine<'_> {
// https://drafts.csswg.org/css-sizing-4/#aspect-ratio-automatic
// A block size transferred through the preferred aspect ratio from a definite inline size is definite, so
// the content resolves percentages against it.
- // NB: Stretch sizing and orthogonal-flow sizing also resolve a non-replaced box's height before inside
- // layout. A provisional minimum on a content-sized box doesn't provide a percentage basis.
+ // NB: Stretch sizing and orthogonal-flow sizing also provide a definite height. A content-derived height
+ // doesn't provide a percentage basis, even if it can be calculated before inside layout.
let is_definite = if is_replaced {
!sizing.should_treat_block_size_as_auto(sized.sized_box(), available_space, constraints)
} else {
resolved_block_size.is_ok()
+ && (sizing.establishes_orthogonal_flow(sized.node)
+ || !self.sizes_to_fit_content(sized, equation, false))
};
if is_definite {
used.update_cells(|cells| cells.has_definite_block_size = true);
diff --git a/Tests/LibWeb/Text/expected/abspos-flex-content-height-percentage.txt b/Tests/LibWeb/Text/expected/abspos-flex-content-height-percentage.txt
new file mode 100644
index 00000000000..eee4a7463d2
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/abspos-flex-content-height-percentage.txt
@@ -0,0 +1,10 @@
+auto insets: parent 60, child 60
+one auto inset: parent 60, child 60
+minimum height: parent 100, child 60
+column reverse: parent 60, child 60
+nowrap: parent 60, child 60
+orthogonal flow: parent 60, child 30
+stretched: parent 300, child 150
+centered: parent 60, child 60
+explicit height: parent 100, child 50
+aspect ratio: parent 100, child 50
diff --git a/Tests/LibWeb/Text/input/abspos-flex-content-height-percentage.html b/Tests/LibWeb/Text/input/abspos-flex-content-height-percentage.html
new file mode 100644
index 00000000000..98adc270337
--- /dev/null
+++ b/Tests/LibWeb/Text/input/abspos-flex-content-height-percentage.html
@@ -0,0 +1,51 @@
+<!doctype html>
+<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#cyclic-percentage-contribution" />
+<script src="include.js"></script>
+<style>
+ .container {
+ position: relative;
+ width: 400px;
+ height: 300px;
+ }
+ .target {
+ position: absolute;
+ display: flex;
+ flex-flow: column wrap;
+ width: 200px;
+ }
+ .child {
+ flex: none;
+ min-height: 0;
+ height: 50%;
+ }
+ .content {
+ height: 60px;
+ }
+</style>
+<script>
+ test(() => {
+ for (const [name, extra] of [
+ ["auto insets", ""],
+ ["one auto inset", "top: 0"],
+ ["minimum height", "min-height: 100px"],
+ ["column reverse", "flex-direction: column-reverse"],
+ ["nowrap", "flex-wrap: nowrap"],
+ ["orthogonal flow", "writing-mode: vertical-rl"],
+ ["stretched", "top: 0; bottom: 0"],
+ ["centered", "top: 0; bottom: 0; align-self: center"],
+ ["explicit height", "height: 100px"],
+ ["aspect ratio", "aspect-ratio: 2"],
+ ]) {
+ const container = document.createElement("div");
+ container.className = "container";
+ container.innerHTML = `<div class="target" style="${extra}"><div class="child"><div class="content"></div></div></div>`;
+ document.body.append(container);
+ const target = container.querySelector(".target");
+ const child = container.querySelector(".child");
+ println(
+ `${name}: parent ${target.getBoundingClientRect().height}, child ${child.getBoundingClientRect().height}`
+ );
+ container.remove();
+ }
+ });
+</script>