Bladeren bron

LibWeb: Use root content width as automatic width if children inline

Returning greatest_child_width() from automatic_content_width() in BFC
if root box children are inline and there are min/max-width that caused
width to be changed after IFC layout while content_width should be
always set to correct value by layout_inline_children() regardless of
layout mode.
Aliaksandr Kalenik 1 jaar geleden
bovenliggende
commit
b34b0a1cd3

+ 16 - 0
Tests/LibWeb/Layout/expected/grid/justify-start-min-width.txt

@@ -0,0 +1,16 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+  BlockContainer <html> at (0,0) content-size 800x33.46875 [BFC] children: not-inline
+    BlockContainer <body> at (8,8) content-size 784x17.46875 children: not-inline
+      Box <div#grid> at (8,8) content-size 784x17.46875 [GFC] children: not-inline
+        BlockContainer <a#box> at (8,8) content-size 288x17.46875 [BFC] children: inline
+          line 0 width: 102.75, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+            frag 0 from TextNode start: 0, length: 13, rect: [8,8 102.75x17.46875]
+              "Start Selling"
+          TextNode <#text>
+
+PaintableWithLines (Viewport<#document>) [0,0 800x600]
+  PaintableWithLines (BlockContainer<HTML>) [0,0 800x33.46875]
+    PaintableWithLines (BlockContainer<BODY>) [8,8 784x17.46875]
+      PaintableBox (Box<DIV>#grid) [8,8 784x17.46875]
+        PaintableWithLines (BlockContainer<A>#box) [8,8 288x17.46875]
+          TextPaintable (TextNode<#text>)

+ 8 - 8
Tests/LibWeb/Layout/expected/grid/min-max-content.txt

@@ -4,23 +4,23 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
       Box <div.grid-container> at (8,8) content-size 784x17.46875 [GFC] children: not-inline
       Box <div.grid-container> at (8,8) content-size 784x17.46875 [GFC] children: not-inline
         BlockContainer <(anonymous)> (not painted) [BFC] children: inline
         BlockContainer <(anonymous)> (not painted) [BFC] children: inline
           TextNode <#text>
           TextNode <#text>
-        BlockContainer <div.grid-item> at (8,8) content-size 93.765625x17.46875 [BFC] children: inline
+        BlockContainer <div.grid-item> at (8,8) content-size 0x17.46875 [BFC] children: inline
           line 0 width: 93.765625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
           line 0 width: 93.765625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
             frag 0 from TextNode start: 0, length: 11, rect: [8,8 93.765625x17.46875]
             frag 0 from TextNode start: 0, length: 11, rect: [8,8 93.765625x17.46875]
               "min-content"
               "min-content"
           TextNode <#text>
           TextNode <#text>
         BlockContainer <(anonymous)> (not painted) [BFC] children: inline
         BlockContainer <(anonymous)> (not painted) [BFC] children: inline
           TextNode <#text>
           TextNode <#text>
-        BlockContainer <div.grid-item> at (101.765625,8) content-size 98.640625x17.46875 [BFC] children: inline
+        BlockContainer <div.grid-item> at (8,8) content-size 98.640625x17.46875 [BFC] children: inline
           line 0 width: 98.640625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
           line 0 width: 98.640625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
-            frag 0 from TextNode start: 0, length: 11, rect: [101.765625,8 98.640625x17.46875]
+            frag 0 from TextNode start: 0, length: 11, rect: [8,8 98.640625x17.46875]
               "max-content"
               "max-content"
           TextNode <#text>
           TextNode <#text>
         BlockContainer <(anonymous)> (not painted) [BFC] children: inline
         BlockContainer <(anonymous)> (not painted) [BFC] children: inline
           TextNode <#text>
           TextNode <#text>
-        BlockContainer <div.grid-item> at (200.40625,8) content-size 591.59375x17.46875 [BFC] children: inline
+        BlockContainer <div.grid-item> at (106.640625,8) content-size 685.359375x17.46875 [BFC] children: inline
           line 0 width: 21.609375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
           line 0 width: 21.609375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
-            frag 0 from TextNode start: 0, length: 3, rect: [200.40625,8 21.609375x17.46875]
+            frag 0 from TextNode start: 0, length: 3, rect: [106.640625,8 21.609375x17.46875]
               "1fr"
               "1fr"
           TextNode <#text>
           TextNode <#text>
         BlockContainer <(anonymous)> (not painted) [BFC] children: inline
         BlockContainer <(anonymous)> (not painted) [BFC] children: inline
@@ -30,9 +30,9 @@ PaintableWithLines (Viewport<#document>) [0,0 800x600]
   PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
   PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
     PaintableWithLines (BlockContainer<BODY>) [8,8 784x17.46875]
     PaintableWithLines (BlockContainer<BODY>) [8,8 784x17.46875]
       PaintableBox (Box<DIV>.grid-container) [8,8 784x17.46875]
       PaintableBox (Box<DIV>.grid-container) [8,8 784x17.46875]
-        PaintableWithLines (BlockContainer<DIV>.grid-item) [8,8 93.765625x17.46875]
+        PaintableWithLines (BlockContainer<DIV>.grid-item) [8,8 0x17.46875] overflow: [8,8 93.765625x17.46875]
           TextPaintable (TextNode<#text>)
           TextPaintable (TextNode<#text>)
-        PaintableWithLines (BlockContainer<DIV>.grid-item) [101.765625,8 98.640625x17.46875]
+        PaintableWithLines (BlockContainer<DIV>.grid-item) [8,8 98.640625x17.46875]
           TextPaintable (TextNode<#text>)
           TextPaintable (TextNode<#text>)
-        PaintableWithLines (BlockContainer<DIV>.grid-item) [200.40625,8 591.59375x17.46875]
+        PaintableWithLines (BlockContainer<DIV>.grid-item) [106.640625,8 685.359375x17.46875]
           TextPaintable (TextNode<#text>)
           TextPaintable (TextNode<#text>)

+ 11 - 0
Tests/LibWeb/Layout/input/grid/justify-start-min-width.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html><html><head><style>
+#grid {
+    display: grid;
+}
+
+#box {
+    justify-self: start;
+    min-width: 18rem;
+    background-color: orange;
+}
+</style></head><body><div id="grid"><a id="box">Start Selling

+ 2 - 0
Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

@@ -40,6 +40,8 @@ BlockFormattingContext::~BlockFormattingContext()
 
 
 CSSPixels BlockFormattingContext::automatic_content_width() const
 CSSPixels BlockFormattingContext::automatic_content_width() const
 {
 {
+    if (root().children_are_inline())
+        return m_state.get(root()).content_width();
     return greatest_child_width(root());
     return greatest_child_width(root());
 }
 }