Forráskód Böngészése

LibWeb: Resolve cyclic % against 0 when available size is min-content

This fixes an issue where replaced elements with cyclic percentage width
would make an oversized min-content contribution to its container.
Andreas Kling 2 éve
szülő
commit
3365a1e034

+ 27 - 0
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 <html> at (1,1) content-size 798x1251.46875 [BFC] children: not-inline
+    BlockContainer <body> at (10,10) content-size 780x1233.46875 children: not-inline
+      BlockContainer <div.w.min> 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 <img> at (12,21) content-size 2x2 children: not-inline
+      BlockContainer <(anonymous)> at (10,29.46875) content-size 780x0 children: inline
+        TextNode <#text>
+      BlockContainer <div.w.max> 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 <img> at (12,31.46875) content-size 402x402 children: not-inline
+      BlockContainer <(anonymous)> at (10,435.46875) content-size 780x0 children: inline
+        TextNode <#text>
+      BlockContainer <div.h.min> 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 <img> at (12,437.46875) content-size 400x400 children: not-inline
+      BlockContainer <(anonymous)> at (10,839.46875) content-size 780x0 children: inline
+        TextNode <#text>
+      BlockContainer <div.h.max> 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 <img> at (12,841.46875) content-size 400x400 children: not-inline
+      BlockContainer <(anonymous)> at (10,1243.46875) content-size 780x0 children: inline
+        TextNode <#text>

+ 15 - 0
Tests/LibWeb/Layout/input/resolve-cyclic-percentage-against-zero-when-available-size-is-min-content.html

@@ -0,0 +1,15 @@
+<!DOCTYPE html><style>
+  * {
+    border: 1px solid red;
+  }
+  div.w.min { width: min-content; }
+  div.w.max { width: max-content; }
+  div.w > img { width: 100%; }
+  div.h.min { height: min-content; }
+  div.h.max { height: min-content; }
+  div.h > img { height: 100%; }
+</style>
+<div class="w min"><img src="400.png"></div>
+<div class="w max"><img src="400.png"></div>
+<div class="h min"><img src="400.png"></div>
+<div class="h max"><img src="400.png"></div>

+ 18 - 4
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)