[LFC] Merge width and margin computation for block-level, replaced elements in normal...
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Jun 2018 14:05:47 +0000 (14:05 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Jun 2018 14:05:47 +0000 (14:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186270

Reviewed by Sam Weinig.

https://www.w3.org/TR/CSS22/visudet.html#block-replaced-width
10.3.4 Block-level, replaced elements in normal flow

The used value of 'width' is determined as for inline replaced elements.
Then the rules for non-replaced block-level elements are applied to determine the margins.

* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232507 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/blockformatting/BlockFormattingContext.h
Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

index ba786dd..fa786a4 100644 (file)
@@ -1,3 +1,21 @@
+2018-06-05  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Merge width and margin computation for block-level, replaced elements in normal flow
+        https://bugs.webkit.org/show_bug.cgi?id=186270
+
+        Reviewed by Sam Weinig.
+
+        https://www.w3.org/TR/CSS22/visudet.html#block-replaced-width
+        10.3.4 Block-level, replaced elements in normal flow
+
+        The used value of 'width' is determined as for inline replaced elements.
+        Then the rules for non-replaced block-level elements are applied to determine the margins.
+
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):
+
 2018-06-04  Enrique Ocaña González  <eocanha@igalia.com>
 
         [GStreamer][MSE] MediaPlayerPrivateGStreamerMSE.h includes and forward declares PlaybackPipeline
index 9bbadcc..48a01a5 100644 (file)
@@ -70,7 +70,7 @@ private:
 
     private:
         static LayoutUnit inFlowNonReplacedHeight(LayoutContext&, const Box&);
-        static FormattingContext::Geometry::WidthAndMargin inFlowNonReplacedWidthAndMargin(LayoutContext&, const Box&);
+        static FormattingContext::Geometry::WidthAndMargin inFlowNonReplacedWidthAndMargin(LayoutContext&, const Box&, std::optional<LayoutUnit> precomputedWidth = std::nullopt);
     };
     
     // This class implements margin collapsing for block formatting context.
index 4b5ff26..552829b 100644 (file)
@@ -113,7 +113,8 @@ LayoutUnit BlockFormattingContext::Geometry::inFlowNonReplacedHeight(LayoutConte
     return std::max(computedHeight, initialContainingBlockHeight);
 }
 
-FormattingContext::Geometry::WidthAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox)
+FormattingContext::Geometry::WidthAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin(LayoutContext& layoutContext, const Box& layoutBox,
+    std::optional<LayoutUnit> precomputedWidth)
 {
     ASSERT(layoutBox.isInFlow() && !layoutBox.replaced());
 
@@ -139,7 +140,7 @@ FormattingContext::Geometry::WidthAndMargin BlockFormattingContext::Geometry::in
         //    edges of the containing block.
 
         auto& style = layoutBox.style();
-        auto width = style.logicalWidth();
+        auto width = precomputedWidth ? Length { precomputedWidth.value(), Fixed } : style.logicalWidth();
         auto* containingBlock = layoutBox.containingBlock();
         auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*containingBlock)->width();
         auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox);
@@ -319,8 +320,16 @@ FormattingContext::Geometry::WidthAndMargin BlockFormattingContext::Geometry::in
     if (!layoutBox.replaced())
         return inFlowNonReplacedWidthAndMargin(layoutContext, layoutBox);
     // 10.3.4 Block-level, replaced elements in normal flow
-    // The used value of 'width' is determined as for inline replaced elements
-    return FormattingContext::Geometry::inlineReplacedWidthAndMargin(layoutContext, layoutBox);
+    //
+    // 1. The used value of 'width' is determined as for inline replaced elements.
+    // 2. Then the rules for non-replaced block-level elements are applied to determine the margins.
+
+    // #1
+    auto inlineReplacedWidthAndMargin = FormattingContext::Geometry::inlineReplacedWidthAndMargin(layoutContext, layoutBox);
+    // #2
+    auto inlineReplacedWidthAndBlockNonReplacedMargin = Geometry::inFlowNonReplacedWidthAndMargin(layoutContext, layoutBox, inlineReplacedWidthAndMargin.width);
+    ASSERT(inlineReplacedWidthAndMargin.width == inlineReplacedWidthAndBlockNonReplacedMargin.width);
+    return inlineReplacedWidthAndBlockNonReplacedMargin;
 }
 
 }