Title: [231786] trunk/Source/WebCore
Revision
231786
Author
za...@apple.com
Date
2018-05-14 22:23:28 -0700 (Mon, 14 May 2018)

Log Message

[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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (231785 => 231786)


--- trunk/Source/WebCore/ChangeLog	2018-05-15 03:09:19 UTC (rev 231785)
+++ trunk/Source/WebCore/ChangeLog	2018-05-15 05:23:28 UTC (rev 231786)
@@ -1,3 +1,22 @@
+2018-05-14  Zalan Bujtas  <za...@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_hs...@apple.com>
 
         Unreviewed, fix the iOS build after r231779

Modified: trunk/Source/WebCore/layout/FormattingContext.cpp (231785 => 231786)


--- trunk/Source/WebCore/layout/FormattingContext.cpp	2018-05-15 03:09:19 UTC (rev 231785)
+++ trunk/Source/WebCore/layout/FormattingContext.cpp	2018-05-15 05:23:28 UTC (rev 231786)
@@ -66,7 +66,7 @@
         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

Modified: trunk/Source/WebCore/layout/FormattingContext.h (231785 => 231786)


--- trunk/Source/WebCore/layout/FormattingContext.h	2018-05-15 03:09:19 UTC (rev 231785)
+++ trunk/Source/WebCore/layout/FormattingContext.h	2018-05-15 05:23:28 UTC (rev 231786)
@@ -73,7 +73,7 @@
 
     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;

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (231785 => 231786)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2018-05-15 03:09:19 UTC (rev 231785)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2018-05-15 05:23:28 UTC (rev 231786)
@@ -143,10 +143,44 @@
     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
 {
     if (!layoutBox.isReplaced()) {

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (231785 => 231786)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2018-05-15 03:09:19 UTC (rev 231785)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2018-05-15 05:23:28 UTC (rev 231786)
@@ -51,7 +51,10 @@
 
 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;
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp (231785 => 231786)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2018-05-15 03:09:19 UTC (rev 231785)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp	2018-05-15 05:23:28 UTC (rev 231786)
@@ -66,7 +66,7 @@
     return formattingState.floatingState();
 }
 
-void InlineFormattingContext::computeInFlowWidth(const Box&, Display::Box&) const
+void InlineFormattingContext::computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const
 {
 }
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (231785 => 231786)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2018-05-15 03:09:19 UTC (rev 231785)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2018-05-15 05:23:28 UTC (rev 231786)
@@ -48,7 +48,7 @@
     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;
 
 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to