[LFC] Implement width computation for non-replaced block level inflow elements.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 May 2018 05:23:28 +0000 (05:23 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 May 2018 05:23:28 +0000 (05:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185641

Reviewed by Sam Weinig.

Block level inflow elements participate in block formatting context.

* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::computeWidth const):
* layout/FormattingContext.h:
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeInFlowWidth const):
* layout/blockformatting/BlockFormattingContext.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computeInFlowWidth const):
* layout/inlineformatting/InlineFormattingContext.h:

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

Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContext.cpp
Source/WebCore/layout/FormattingContext.h
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContext.h
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.h

index 81d9fda..af95b29 100644 (file)
@@ -1,3 +1,22 @@
+2018-05-14  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Implement width computation for non-replaced block level inflow elements.
+        https://bugs.webkit.org/show_bug.cgi?id=185641
+
+        Reviewed by Sam Weinig.
+
+        Block level inflow elements participate in block formatting context.
+
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::computeWidth const):
+        * layout/FormattingContext.h:
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeInFlowWidth const):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computeInFlowWidth const):
+        * layout/inlineformatting/InlineFormattingContext.h:
+
 2018-05-14  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Unreviewed, fix the iOS build after r231779
index fe1069a..0949598 100644 (file)
@@ -66,7 +66,7 @@ void FormattingContext::computeWidth(LayoutContext& layoutContext, const Box& la
         return computeOutOfFlowWidth(layoutContext, layoutBox, displayBox);
     if (layoutBox.isFloatingPositioned())
         return computeFloatingWidth(layoutBox, displayBox);
-    return computeInFlowWidth(layoutBox, displayBox);
+    return computeInFlowWidth(layoutContext, layoutBox, displayBox);
 }
 
 void FormattingContext::computeHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
index 42faeda..2424b1a 100644 (file)
@@ -73,7 +73,7 @@ protected:
 
     virtual void computeOutOfFlowWidth(LayoutContext&, const Box&, Display::Box&) const;
     virtual void computeFloatingWidth(const Box&, Display::Box&) const;
-    virtual void computeInFlowWidth(const Box&, Display::Box&) const = 0;
+    virtual void computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const = 0;
 
     virtual void computeOutOfFlowHeight(LayoutContext&, const Box&, Display::Box&) const;
     virtual void computeFloatingHeight(const Box&, Display::Box&) const;
index 0542136..4c3f41b 100644 (file)
@@ -143,8 +143,42 @@ void BlockFormattingContext::computeStaticPosition(LayoutContext& layoutContext,
     displayBox.setTopLeft(topLeft);
 }
 
-void BlockFormattingContext::computeInFlowWidth(const Box&, Display::Box&) const
+void BlockFormattingContext::computeInFlowWidth(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
 {
+    if (!layoutBox.isReplaced()) {
+        computeInFlowNonReplacedWidth(layoutContext, layoutBox, displayBox);
+        return;
+    }
+    ASSERT_NOT_REACHED();
+}
+
+void BlockFormattingContext::computeInFlowNonReplacedWidth(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
+{
+    // 10.3.3 Block-level, non-replaced elements in normal flow
+    // The following constraints must hold among the used values of the other properties:
+    // 'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
+
+    // If 'width' is set to 'auto', any other 'auto' values become '0' and 'width' follows from the resulting equality.
+    auto& style = layoutBox.style();
+    auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*layoutBox.containingBlock())->width();
+
+    LayoutUnit computedWidthValue;
+    auto width = style.logicalWidth();
+    if (width.isAuto()) {
+        auto marginLeft = displayBox.marginLeft();
+        auto marginRight = displayBox.marginRight();
+
+        auto paddingLeft = displayBox.paddingLeft();
+        auto paddingRight = displayBox.paddingRight();
+
+        auto borderLeft = displayBox.borderLeft();
+        auto borderRight = displayBox.borderRight();
+
+        computedWidthValue = containingBlockWidth - (marginLeft + borderLeft + paddingLeft + paddingRight + borderRight + marginRight);
+    } else
+        computedWidthValue = valueForLength(width, containingBlockWidth);
+
+    displayBox.setWidth(computedWidthValue);
 }
 
 void BlockFormattingContext::computeInFlowHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const
index e2ac84a..0419f6b 100644 (file)
@@ -51,7 +51,10 @@ public:
 
 private:
     void computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const override;
-    void computeInFlowWidth(const Box&, Display::Box&) const override;
+
+    void computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const override;
+    void computeInFlowNonReplacedWidth(LayoutContext&, const Box&, Display::Box&) const;
+
     void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const override;
     void computeInFlowNonReplacedHeight(LayoutContext&, const Box&, Display::Box&) const;
 
index bb8a390..b7ab203 100644 (file)
@@ -66,7 +66,7 @@ Ref<FloatingState> InlineFormattingContext::createOrFindFloatingState(LayoutCont
     return formattingState.floatingState();
 }
 
-void InlineFormattingContext::computeInFlowWidth(const Box&, Display::Box&) const
+void InlineFormattingContext::computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const
 {
 }
 
index 4437bd8..1f5a8ec 100644 (file)
@@ -48,7 +48,7 @@ public:
     Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const override;
 
 private:
-    void computeInFlowWidth(const Box&, Display::Box&) const override;
+    void computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const override;
     void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const override;
 
 };