Skip to content

Truly independent web browser

LibWeb: Resolve fit-content abspos sizes before auto margins

Andreas Kling77afdae84c49
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index ebd043b3b0d..01928b485b6 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -1980,6 +1980,16 @@ impl AbsposEngine<'_> {
right = solve_for_right(left, inline_size, margin_left, margin_right);
}
+ // https://drafts.csswg.org/css-position-3/#abspos-auto-size
+ // For the purpose of computing these sizes, any auto margins are treated as zero.
+ if inline_size.is_none()
+ && !computed_left.is_auto()
+ && !computed_right.is_auto()
+ && self.self_alignment_sizes_to_fit_content(sized, true)
+ {
+ inline_size = Some(shrink_to_fit(left, margin_left, margin_right, right));
+ }
+
if !computed_left.is_auto() && inline_size.is_some() && !computed_right.is_auto() {
let available_for_margins = containing_block_inline_size
- border_left
@@ -2025,14 +2035,7 @@ impl AbsposEngine<'_> {
} else if computed_left.is_auto() && inline_size.is_some() && !computed_right.is_auto() {
left = solve_for_left(inline_size, margin_left, margin_right, right);
} else if inline_size.is_none() && !computed_left.is_auto() && !computed_right.is_auto() {
- // https://drafts.csswg.org/css-position-3/#abspos-auto-size
- // NB: A box aligned within its inset-modified containing block takes its fit-content size there, while
- // normal and stretch alignment fill it.
- inline_size = Some(if self.self_alignment_sizes_to_fit_content(sized, true) {
- shrink_to_fit(left, margin_left, margin_right, right)
- } else {
- solve_for_inline_size(left, margin_left, margin_right, right)
- });
+ inline_size = Some(solve_for_inline_size(left, margin_left, margin_right, right));
} else if computed_right.is_auto() && !computed_left.is_auto() && inline_size.is_some() {
right = solve_for_right(left, inline_size, margin_left, margin_right);
}
@@ -2426,6 +2429,25 @@ 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.
+ if solution.block_size.is_none()
+ && solution.top.is_some()
+ && solution.bottom.is_some()
+ && self.self_alignment_sizes_to_fit_content(sized, false)
+ {
+ let Some(automatic) = self.automatic_block_size(
+ sized,
+ available_space,
+ constraints,
+ pass,
+ solve_for(solution.block_size, true, solution),
+ ) else {
+ return solution;
+ };
+ solution.block_size = Some(automatic);
+ }
+
if solution.top.is_none() && solution.block_size.is_none() && solution.bottom.is_none() {
solution.zero_out_auto_margins();
let Some(automatic) = self.automatic_block_size(
@@ -2494,21 +2516,6 @@ impl AbsposEngine<'_> {
solution.bottom = Some(solve_for(solution.bottom, false, solution));
} else if solution.top.is_none() && solution.block_size.is_some() && solution.bottom.is_some() {
solution.top = Some(solve_for(solution.top, false, solution));
- } else if solution.block_size.is_none()
- && solution.top.is_some()
- && solution.bottom.is_some()
- && self.self_alignment_sizes_to_fit_content(sized, false)
- {
- let Some(automatic) = self.automatic_block_size(
- sized,
- available_space,
- constraints,
- pass,
- solve_for(solution.block_size, true, solution),
- ) else {
- return solution;
- };
- solution.block_size = Some(automatic);
} else if solution.block_size.is_none() && solution.top.is_some() && solution.bottom.is_some() {
solution.block_size = Some(solve_for(solution.block_size, true, solution));
} else if solution.bottom.is_none() && solution.top.is_some() && solution.block_size.is_some() {
@@ -3116,20 +3123,15 @@ impl<'pass> AbsposEngine<'pass> {
/// within its inset-modified containing block, rather than fill it.
fn self_alignment_sizes_to_fit_content(&self, sized: sizing_context::SizedRecord<'_>, inline_axis: bool) -> bool {
let style = self.style_of(sized);
- let (value, margin_start, margin_end) = if inline_axis {
- (style.justify_self(), style.margin_left(), style.margin_right())
+ let value = if inline_axis {
+ style.justify_self()
} else {
- (
- justify_self_value_for_align_self(style.align_self()),
- style.margin_top(),
- style.margin_bottom(),
- )
+ justify_self_value_for_align_self(style.align_self())
};
!matches!(
value,
justify_self::AUTO | justify_self::NORMAL | justify_self::STRETCH | justify_self::ANCHOR_CENTER
- ) && !margin_start.is_auto()
- && !margin_end.is_auto()
+ )
}
/// Lays out and places `node`, kept with the cells `cells` for its run, with the inputs `inputs`, where its insets
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/position-absolute-fit-content-auto-margin.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/position-absolute-fit-content-auto-margin.txt
index 4528bee1100..6aaad020fe7 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-position/position-absolute-fit-content-auto-margin.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-position/position-absolute-fit-content-auto-margin.txt
@@ -2,50 +2,49 @@ Harness status: OK
Found 45 tests
-15 Pass
-30 Fail
-Fail #tests .abspos 1
-Fail #tests .abspos 2
+45 Pass
+Pass #tests .abspos 1
+Pass #tests .abspos 2
Pass #tests .abspos 3
-Fail #tests .abspos 4
-Fail #tests .abspos 5
+Pass #tests .abspos 4
+Pass #tests .abspos 5
Pass #tests .abspos 6
-Fail #tests .abspos 7
-Fail #tests .abspos 8
+Pass #tests .abspos 7
+Pass #tests .abspos 8
Pass #tests .abspos 9
-Fail #tests .abspos 10
-Fail #tests .abspos 11
+Pass #tests .abspos 10
+Pass #tests .abspos 11
Pass #tests .abspos 12
-Fail #tests .abspos 13
-Fail #tests .abspos 14
+Pass #tests .abspos 13
+Pass #tests .abspos 14
Pass #tests .abspos 15
-Fail #tests .abspos 16
-Fail #tests .abspos 17
+Pass #tests .abspos 16
+Pass #tests .abspos 17
Pass #tests .abspos 18
-Fail #tests .abspos 19
-Fail #tests .abspos 20
+Pass #tests .abspos 19
+Pass #tests .abspos 20
Pass #tests .abspos 21
-Fail #tests .abspos 22
-Fail #tests .abspos 23
+Pass #tests .abspos 22
+Pass #tests .abspos 23
Pass #tests .abspos 24
-Fail #tests .abspos 25
-Fail #tests .abspos 26
+Pass #tests .abspos 25
+Pass #tests .abspos 26
Pass #tests .abspos 27
-Fail #tests .abspos 28
-Fail #tests .abspos 29
+Pass #tests .abspos 28
+Pass #tests .abspos 29
Pass #tests .abspos 30
-Fail #tests .abspos 31
-Fail #tests .abspos 32
+Pass #tests .abspos 31
+Pass #tests .abspos 32
Pass #tests .abspos 33
-Fail #tests .abspos 34
-Fail #tests .abspos 35
+Pass #tests .abspos 34
+Pass #tests .abspos 35
Pass #tests .abspos 36
-Fail #tests .abspos 37
-Fail #tests .abspos 38
+Pass #tests .abspos 37
+Pass #tests .abspos 38
Pass #tests .abspos 39
-Fail #tests .abspos 40
-Fail #tests .abspos 41
+Pass #tests .abspos 40
+Pass #tests .abspos 41
Pass #tests .abspos 42
-Fail #tests .abspos 43
-Fail #tests .abspos 44
+Pass #tests .abspos 43
+Pass #tests .abspos 44
Pass #tests .abspos 45
\ No newline at end of file