Skip to content

Truly independent web browser

LibWeb: Keep a content-sized abspos height indefinite until layout

sideshowbarker3022f63e461d
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index e5688583ed7..5da81276e90 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -2388,12 +2388,12 @@ 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: A box that establishes an orthogonal flow is sized in this axis before its contents are laid out,
- // which they are at that size.
+ // 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.
let is_definite = if is_replaced {
!sizing.should_treat_block_size_as_auto(sized.sized_box(), available_space, constraints)
} else {
- block_size.is_some() && sizing.establishes_orthogonal_flow(sized.node)
+ resolved_block_size.is_ok()
};
if is_definite {
used.update_cells(|cells| cells.has_definite_block_size = true);
@@ -2508,12 +2508,6 @@ impl<'pass> AbsposEngine<'pass> {
if !style.inset_left().is_auto() && !style.inset_right().is_auto() {
used.update_cells(|cells| cells.has_definite_inline_size = true);
}
- if !style.inset_top().is_auto()
- && !style.inset_bottom().is_auto()
- && (style.height().is_auto() || !style.height().is_intrinsic_sizing_constraint())
- {
- used.update_cells(|cells| cells.has_definite_block_size = true);
- }
}
if !self.facts(node).creates_block_formatting_context() {
let block_size_resolved_from_aspect_ratio = style.height().is_auto()
diff --git a/Tests/LibWeb/Text/expected/abspos-anchor-percent-height.txt b/Tests/LibWeb/Text/expected/abspos-anchor-percent-height.txt
new file mode 100644
index 00000000000..1d9e56162a0
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/abspos-anchor-percent-height.txt
@@ -0,0 +1,20 @@
+normal, 100%: parent 300, child 300
+normal, 50%: parent 300, child 150
+stretch, 100%: parent 300, child 300
+stretch, 50%: parent 300, child 150
+center, 100%: parent 60, child 60
+center, 50%: parent 60, child 60
+anchor-center, 100%: parent 60, child 60
+anchor-center, 50%: parent 60, child 60
+missing anchor, 100%: parent 60, child 60
+missing anchor, 50%: parent 60, child 60
+minimum height, 100%: parent 120, child 60
+minimum height, 50%: parent 120, child 60
+zero height, 100%: parent 0, child 0
+zero height, 50%: parent 0, child 0
+explicit height, 100%: parent 100, child 100
+explicit height, 50%: parent 100, child 50
+aspect ratio, 100%: parent 100, child 100
+aspect ratio, 50%: parent 100, child 50
+one auto inset, 100%: parent 60, child 60
+one auto inset, 50%: parent 60, child 60
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/abspos/stretch-intrinsic-size-htb-htb.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/abspos/stretch-intrinsic-size-htb-htb.txt
new file mode 100644
index 00000000000..989ab518f1c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/abspos/stretch-intrinsic-size-htb-htb.txt
@@ -0,0 +1,18 @@
+Harness status: OK
+
+Found 12 tests
+
+7 Pass
+5 Fail
+Pass .item 1
+Pass .item 2
+Pass .item 3
+Pass .item 4
+Pass .item 5
+Pass .item 6
+Fail .item 7
+Fail .item 8
+Pass .item 9
+Fail .item 10
+Fail .item 11
+Fail .item 12
\ No newline at end of file
diff --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.txt
index e4951b11462..4da17207030 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,10 +2,10 @@ Harness status: OK
Found 12 tests
-7 Pass
-5 Fail
+8 Pass
+4 Fail
Pass .item 1
-Fail .item 2
+Pass .item 2
Pass .item 3
Pass .item 4
Pass .item 5
diff --git a/Tests/LibWeb/Text/input/abspos-anchor-percent-height.html b/Tests/LibWeb/Text/input/abspos-anchor-percent-height.html
new file mode 100644
index 00000000000..ea4f5844aa9
--- /dev/null
+++ b/Tests/LibWeb/Text/input/abspos-anchor-percent-height.html
@@ -0,0 +1,57 @@
+<!doctype html>
+<link rel="help" href="https://drafts.csswg.org/css-position-3/#abspos-auto-size">
+<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;
+ }
+ .anchor {
+ anchor-name: --anchor;
+ width: 20px;
+ height: 20px;
+ margin-top: 100px;
+ }
+ .target {
+ position: absolute;
+ position-anchor: --anchor;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ width: 200px;
+ }
+ .content {
+ height: 60px;
+ }
+</style>
+<script>
+ test(() => {
+ for (const [name, extra] of [
+ ["normal", ""],
+ ["stretch", "align-self: stretch"],
+ ["center", "align-self: center"],
+ ["anchor-center", "align-self: anchor-center"],
+ ["missing anchor", "align-self: anchor-center; position-anchor: --missing"],
+ ["minimum height", "align-self: anchor-center; min-height: 120px"],
+ ["zero height", "align-self: anchor-center; height: 0"],
+ ["explicit height", "align-self: anchor-center; height: 100px"],
+ ["aspect ratio", "align-self: anchor-center; aspect-ratio: 2"],
+ ["one auto inset", "align-self: anchor-center; bottom: auto"],
+ ]) {
+ for (const percentage of [100, 50]) {
+ const container = document.createElement("div");
+ container.className = "container";
+ container.innerHTML = `<div class="anchor"></div><div class="target" style="${extra}"><div class="child" style="height: ${percentage}%"><div class="content"></div></div></div>`;
+ document.body.append(container);
+ const target = container.querySelector(".target");
+ const child = container.querySelector(".child");
+ println(
+ `${name}, ${percentage}%: parent ${target.getBoundingClientRect().height}, child ${child.getBoundingClientRect().height}`
+ );
+ container.remove();
+ }
+ }
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-align/abspos/stretch-intrinsic-size-htb-htb.html b/Tests/LibWeb/Text/input/wpt-import/css/css-align/abspos/stretch-intrinsic-size-htb-htb.html
new file mode 100644
index 00000000000..6beb61244d4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-align/abspos/stretch-intrinsic-size-htb-htb.html
@@ -0,0 +1,100 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/css-align-3/#align-abspos">
+<link rel="help" href="https://drafts.csswg.org/css-align-3/#justify-abspos">
+<style>
+body {
+ margin: 0;
+}
+
+.container {
+ writing-mode: horizontal-tb;
+ display: inline-block;
+ position: relative;
+ margin: 20px;
+ border: solid 4px;
+ width: 60px;
+ height: 60px;
+}
+
+.item {
+ writing-mode: horizontal-tb;
+ position: absolute;
+ background: green;
+ inset: 5px 10px 5px 10px;
+}
+
+.child::before {
+ aspect-ratio: 1/1;
+ min-width: 20px;
+ min-height: 20px;
+ width: 100%;
+ height: 100%;
+ content: '';
+ display: block;
+}
+
+.ar {
+ aspect-ratio: 1/1;
+ min-width: 20px;
+ min-height: 20px;
+}
+</style>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../resources/check-layout-th.js"></script>
+
+<body onload="checkLayout('.item')">
+
+<body>
+
+<div class="container">
+ <div class="item child" style="justify-self: start; align-self: start;" data-expected-width="20" data-expected-height="20"></div>
+</div>
+
+<div class="container">
+ <div class="item child" style="justify-self: stretch; align-self: start;" data-expected-width="40" data-expected-height="40"></div>
+</div>
+
+<div class="container">
+ <div class="item child" style="justify-self: start; align-self: stretch;" data-expected-width="50" data-expected-height="50"></div>
+</div>
+
+<div class="container">
+ <div class="item child" style="justify-self: stretch; align-self: stretch;" data-expected-width="40" data-expected-height="50"></div>
+</div>
+
+<br>
+
+<div class="container">
+ <div class="item ar" style="justify-self: start; align-self: start;" data-expected-width="20" data-expected-height="20"></div>
+</div>
+
+<div class="container">
+ <div class="item ar" style="justify-self: stretch; align-self: start;" data-expected-width="40" data-expected-height="40"></div>
+</div>
+
+<div class="container">
+ <div class="item ar" style="justify-self: start; align-self: stretch;" data-expected-width="50" data-expected-height="50"></div>
+</div>
+
+<div class="container">
+ <div class="item ar" style="justify-self: stretch; align-self: stretch;" data-expected-width="40" data-expected-height="50"></div>
+</div>
+
+<br>
+
+<div class="container">
+ <canvas width="10" height="10" class="item" style="justify-self: start; align-self: start;" data-expected-width="10" data-expected-height="10"></canvas>
+</div>
+
+<div class="container">
+ <canvas width="10" height="10" class="item" style="justify-self: stretch; align-self: start;" data-expected-width="40" data-expected-height="40"></canvas>
+</div>
+
+<div class="container">
+ <canvas width="10" height="10" class="item" style="justify-self: start; align-self: stretch;" data-expected-width="50" data-expected-height="50"></canvas>
+</div>
+
+<div class="container">
+ <canvas width="10" height="10" class="item" style="justify-self: stretch; align-self: stretch;" data-expected-width="40" data-expected-height="50"></canvas>
+</div>