diff --git a/Tests/LibWeb/Layout/expected/resolve-cyclic-percentage-against-zero-when-available-size-is-min-content.txt b/Tests/LibWeb/Layout/expected/resolve-cyclic-percentage-against-zero-when-available-size-is-min-content.txt
new file mode 100644
index 00000000000..13cb4a9dc9b
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/resolve-cyclic-percentage-against-zero-when-available-size-is-min-content.txt
@@ -0,0 +1,27 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+ BlockContainer at (1,1) content-size 798x1251.46875 [BFC] children: not-inline
+ BlockContainer
at (10,10) content-size 780x1233.46875 children: not-inline
+ BlockContainer at (11,11) content-size 2x17.46875 children: inline
+ line 0 width: 4, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from ImageBox start: 0, length: 0, rect: [12,21 2x2]
+ ImageBox
at (12,21) content-size 2x2 children: not-inline
+ BlockContainer <(anonymous)> at (10,29.46875) content-size 780x0 children: inline
+ TextNode <#text>
+ BlockContainer at (11,30.46875) content-size 402x404 children: inline
+ line 0 width: 404, height: 404, bottom: 404, baseline: 404
+ frag 0 from ImageBox start: 0, length: 0, rect: [12,31.46875 402x402]
+ ImageBox
at (12,31.46875) content-size 402x402 children: not-inline
+ BlockContainer <(anonymous)> at (10,435.46875) content-size 780x0 children: inline
+ TextNode <#text>
+ BlockContainer at (11,436.46875) content-size 778x402 children: inline
+ line 0 width: 402, height: 402, bottom: 402, baseline: 402
+ frag 0 from ImageBox start: 0, length: 0, rect: [12,437.46875 400x400]
+ ImageBox
at (12,437.46875) content-size 400x400 children: not-inline
+ BlockContainer <(anonymous)> at (10,839.46875) content-size 780x0 children: inline
+ TextNode <#text>
+ BlockContainer at (11,840.46875) content-size 778x402 children: inline
+ line 0 width: 402, height: 402, bottom: 402, baseline: 402
+ frag 0 from ImageBox start: 0, length: 0, rect: [12,841.46875 400x400]
+ ImageBox
at (12,841.46875) content-size 400x400 children: not-inline
+ BlockContainer <(anonymous)> at (10,1243.46875) content-size 780x0 children: inline
+ TextNode <#text>
diff --git a/Tests/LibWeb/Layout/input/resolve-cyclic-percentage-against-zero-when-available-size-is-min-content.html b/Tests/LibWeb/Layout/input/resolve-cyclic-percentage-against-zero-when-available-size-is-min-content.html
new file mode 100644
index 00000000000..772dd00f712
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/resolve-cyclic-percentage-against-zero-when-available-size-is-min-content.html
@@ -0,0 +1,15 @@
+
+
+
+
+
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
index 8964035c2b5..16834726952 100644
--- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp
@@ -1463,14 +1463,28 @@ CSSPixels FormattingContext::calculate_stretch_fit_height(Box const& box, Availa
bool FormattingContext::should_treat_width_as_auto(Box const& box, AvailableSpace const& available_space)
{
- return box.computed_values().width().is_auto()
- || (box.computed_values().width().contains_percentage() && !available_space.width.is_definite());
+ if (box.computed_values().width().is_auto())
+ return true;
+ if (box.computed_values().width().contains_percentage()) {
+ if (available_space.width.is_max_content())
+ return true;
+ if (available_space.width.is_indefinite())
+ return true;
+ }
+ return false;
}
bool FormattingContext::should_treat_height_as_auto(Box const& box, AvailableSpace const& available_space)
{
- return box.computed_values().height().is_auto()
- || (box.computed_values().height().contains_percentage() && !available_space.height.is_definite());
+ if (box.computed_values().height().is_auto())
+ return true;
+ if (box.computed_values().height().contains_percentage()) {
+ if (available_space.height.is_max_content())
+ return true;
+ if (available_space.height.is_indefinite())
+ return true;
+ }
+ return false;
}
bool FormattingContext::can_skip_is_anonymous_text_run(Box& box)