Title: [233289] trunk/Source/WebCore
Revision
233289
Author
[email protected]
Date
2018-06-27 16:46:54 -0700 (Wed, 27 Jun 2018)

Log Message

[LFC] Align inFlowNonReplacedWidthAndMargin() style with the rest of the compute functions.
https://bugs.webkit.org/show_bug.cgi?id=187124

Reviewed by Antti Koivisto.

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (233288 => 233289)


--- trunk/Source/WebCore/ChangeLog	2018-06-27 23:43:13 UTC (rev 233288)
+++ trunk/Source/WebCore/ChangeLog	2018-06-27 23:46:54 UTC (rev 233289)
@@ -1,3 +1,13 @@
+2018-06-27  Zalan Bujtas  <[email protected]>
+
+        [LFC] Align inFlowNonReplacedWidthAndMargin() style with the rest of the compute functions.
+        https://bugs.webkit.org/show_bug.cgi?id=187124
+
+        Reviewed by Antti Koivisto.
+
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin):
+
 2018-06-27  Dirk Schulze  <[email protected]>
 
         -webkit-clip-path wrong offset for clipPath references

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (233288 => 233289)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2018-06-27 23:43:13 UTC (rev 233288)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2018-06-27 23:46:54 UTC (rev 233289)
@@ -138,7 +138,9 @@
     ASSERT(layoutBox.isInFlow() && !layoutBox.replaced());
 
     auto compute = [&]() {
+
         // 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
         //
@@ -159,23 +161,13 @@
         //    edges of the containing block.
 
         auto& style = layoutBox.style();
-        auto width = precomputedWidth ? Length { precomputedWidth.value(), Fixed } : style.logicalWidth();
         auto* containingBlock = layoutBox.containingBlock();
         auto containingBlockWidth = layoutContext.displayBoxForLayoutBox(*containingBlock)->contentBoxWidth();
         auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox);
 
-        LayoutUnit computedWidthValue;
-        std::optional<LayoutUnit> computedMarginLeftValue;
-        std::optional<LayoutUnit> computedMarginRightValue;
-
-        auto marginLeft = style.marginLeft();
-        if (!marginLeft.isAuto())
-            computedMarginLeftValue = valueForLength(marginLeft, containingBlockWidth);
-
-        auto marginRight = style.marginRight();
-        if (!marginRight.isAuto())
-            computedMarginRightValue = valueForLength(marginRight, containingBlockWidth);
-
+        auto width = FormattingContext::Geometry::computedValueIfNotAuto(precomputedWidth ? Length { precomputedWidth.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
+        auto marginLeft = FormattingContext::Geometry::computedValueIfNotAuto(style.marginLeft(), containingBlockWidth);
+        auto marginRight = FormattingContext::Geometry::computedValueIfNotAuto(style.marginRight(), containingBlockWidth);
         auto borderLeft = displayBox.borderLeft();
         auto borderRight = displayBox.borderRight();
         auto paddingLeft = displayBox.paddingLeft();
@@ -182,53 +174,48 @@
         auto paddingRight = displayBox.paddingRight();
 
         // #1
-        if (!width.isAuto()) {
-            computedWidthValue = valueForLength(width, containingBlockWidth);
-            auto horizontalSpaceForMargin = containingBlockWidth - (computedMarginLeftValue.value_or(0) + borderLeft + paddingLeft 
-                + computedWidthValue + paddingRight + borderRight + computedMarginRightValue.value_or(0));
-
+        if (width) {
+            auto horizontalSpaceForMargin = containingBlockWidth - (marginLeft.value_or(0) + borderLeft + paddingLeft + *width + paddingRight + borderRight + marginRight.value_or(0));
             if (horizontalSpaceForMargin < 0) {
-                if (!computedMarginLeftValue)
-                    computedMarginLeftValue = LayoutUnit(0);
-                if (!computedMarginRightValue)
-                    computedMarginRightValue = LayoutUnit(0);
+                marginLeft = marginLeft.value_or(0);
+                marginRight = marginRight.value_or(0);
             }
         }
 
         // #2
-        if (!width.isAuto() && !marginLeft.isAuto() && !marginRight.isAuto()) {
-            ASSERT(computedMarginLeftValue);
-            ASSERT(computedMarginRightValue);
-
+        if (width && marginLeft && marginRight) {
             if (containingBlock->style().isLeftToRightDirection())
-                computedMarginRightValue = containingBlockWidth - (*computedMarginLeftValue + borderLeft + paddingLeft  + computedWidthValue + paddingRight + borderRight);
+                marginRight = containingBlockWidth - (*marginLeft + borderLeft + paddingLeft  + *width + paddingRight + borderRight);
             else
-                computedMarginLeftValue = containingBlockWidth - (borderLeft + paddingLeft  + computedWidthValue + paddingRight + borderRight + *computedMarginRightValue);
+                marginLeft = containingBlockWidth - (borderLeft + paddingLeft + *width + paddingRight + borderRight + *marginRight);
         }
 
         // #3
-        if (!computedMarginLeftValue && !marginRight.isAuto() && !width.isAuto()) {
-            ASSERT(computedMarginRightValue);
-            computedMarginLeftValue = containingBlockWidth - (borderLeft + paddingLeft  + computedWidthValue + paddingRight + borderRight + *computedMarginRightValue);
-        } else if (!computedMarginRightValue && !marginLeft.isAuto() && !width.isAuto()) {
-            ASSERT(computedMarginLeftValue);
-            computedMarginRightValue = containingBlockWidth - (*computedMarginLeftValue + borderLeft + paddingLeft  + computedWidthValue + paddingRight + borderRight);
-        }
+        if (!marginLeft && width && marginRight)
+            marginLeft = containingBlockWidth - (borderLeft + paddingLeft  + *width + paddingRight + borderRight + *marginRight);
+        else if (marginLeft && !width && marginRight)
+            width = containingBlockWidth - (*marginLeft + borderLeft + paddingLeft + paddingRight + borderRight + *marginRight);
+        else if (marginLeft && width && !marginRight)
+            marginRight = containingBlockWidth - (*marginLeft + borderLeft + paddingLeft + *width + paddingRight + borderRight);
 
         // #4
-        if (width.isAuto())
-            computedWidthValue = containingBlockWidth - (computedMarginLeftValue.value_or(0) + borderLeft + paddingLeft + paddingRight + borderRight + computedMarginRightValue.value_or(0));
+        if (!width) {
+            marginLeft = marginLeft.value_or(0);
+            marginRight = marginRight.value_or(0);
+            width = containingBlockWidth - (*marginLeft + borderLeft + paddingLeft + paddingRight + borderRight + *marginRight);
+        }
 
         // #5
-        if (!computedMarginLeftValue && !computedMarginRightValue) {
-            auto horizontalSpaceForMargin = containingBlockWidth - (borderLeft + paddingLeft  + computedWidthValue + paddingRight + borderRight);
-            computedMarginLeftValue = computedMarginRightValue = horizontalSpaceForMargin / 2;
+        if (!marginLeft && !marginRight) {
+            auto horizontalSpaceForMargin = containingBlockWidth - (borderLeft + paddingLeft  + *width + paddingRight + borderRight);
+            marginLeft = marginRight = horizontalSpaceForMargin / 2;
         }
 
-        ASSERT(computedMarginLeftValue);
-        ASSERT(computedMarginRightValue);
+        ASSERT(width);
+        ASSERT(marginLeft);
+        ASSERT(marginRight);
 
-        return FormattingContext::Geometry::WidthAndMargin { computedWidthValue, { *computedMarginLeftValue, *computedMarginRightValue } };
+        return FormattingContext::Geometry::WidthAndMargin { *width, { *marginLeft, *marginRight } };
     };
 
     auto widthAndMargin = compute();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to