[LFC] Introduce UsedHorizontalValues::Constraints
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Sep 2019 19:56:14 +0000 (19:56 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Sep 2019 19:56:14 +0000 (19:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201919
<rdar://problem/55481927>

Reviewed by Antti Koivisto.

UsedHorizontalValues::Constraints holds the constraint values for a particular box geometry computation (currently it only has the horizontal width constraint)

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/FormattingContext.cpp:
(WebCore::Layout::FormattingContext::computeOutOfFlowHorizontalGeometry):
(WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry):
(WebCore::Layout::FormattingContext::computeBorderAndPadding):
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry const):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry const):
(WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry const):
(WebCore::Layout::FormattingContext::Geometry::floatingNonReplacedWidthAndMargin):
(WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin const):
(WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin const):
(WebCore::Layout::FormattingContext::Geometry::inFlowPositionedPositionOffset const):
(WebCore::Layout::FormattingContext::Geometry::computedPadding const):
(WebCore::Layout::FormattingContext::Geometry::computedHorizontalMargin const):
(WebCore::Layout::FormattingContext::Geometry::computedVerticalMargin const):
* layout/FormattingContextQuirks.cpp:
(WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
* layout/LayoutUnits.h:
(WebCore::Layout::UsedHorizontalValues::Constraints::Constraints):
(WebCore::Layout::UsedHorizontalValues::UsedHorizontalValues):
* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::placeInFlowPositionedChildren):
(WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition):
(WebCore::Layout::BlockFormattingContext::computeWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::computeHeightAndMargin):
* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin const):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):
* layout/blockformatting/BlockFormattingContextQuirks.cpp:
(WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight):
* layout/blockformatting/BlockMarginCollapse.cpp:
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues):
* layout/floats/FloatingContext.h:
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
(WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
(WebCore::Layout::InlineFormattingContext::computeIntrinsicWidthForFormattingRoot):
(WebCore::Layout::InlineFormattingContext::computeHeightAndMargin):
* layout/inlineformatting/InlineFormattingContextGeometry.cpp:
(WebCore::Layout::InlineFormattingContext::Geometry::inlineBlockWidthAndMargin):
* layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
(WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const):
* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns):

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/layout/FormattingContext.cpp
Source/WebCore/layout/FormattingContextGeometry.cpp
Source/WebCore/layout/FormattingContextQuirks.cpp
Source/WebCore/layout/LayoutUnits.cpp [new file with mode: 0644]
Source/WebCore/layout/LayoutUnits.h
Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp
Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp
Source/WebCore/layout/floats/FloatingContext.h
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp
Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

index 477f74b..38480ed 100644 (file)
@@ -1,3 +1,61 @@
+2019-09-18  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Introduce UsedHorizontalValues::Constraints
+        https://bugs.webkit.org/show_bug.cgi?id=201919
+        <rdar://problem/55481927>
+
+        Reviewed by Antti Koivisto.
+
+        UsedHorizontalValues::Constraints holds the constraint values for a particular box geometry computation (currently it only has the horizontal width constraint) 
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/FormattingContext.cpp:
+        (WebCore::Layout::FormattingContext::computeOutOfFlowHorizontalGeometry):
+        (WebCore::Layout::FormattingContext::computeOutOfFlowVerticalGeometry):
+        (WebCore::Layout::FormattingContext::computeBorderAndPadding):
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeometry const):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGeometry):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry const):
+        (WebCore::Layout::FormattingContext::Geometry::outOfFlowReplacedHorizontalGeometry const):
+        (WebCore::Layout::FormattingContext::Geometry::floatingNonReplacedWidthAndMargin):
+        (WebCore::Layout::FormattingContext::Geometry::floatingReplacedWidthAndMargin const):
+        (WebCore::Layout::FormattingContext::Geometry::inlineReplacedWidthAndMargin const):
+        (WebCore::Layout::FormattingContext::Geometry::inFlowPositionedPositionOffset const):
+        (WebCore::Layout::FormattingContext::Geometry::computedPadding const):
+        (WebCore::Layout::FormattingContext::Geometry::computedHorizontalMargin const):
+        (WebCore::Layout::FormattingContext::Geometry::computedVerticalMargin const):
+        * layout/FormattingContextQuirks.cpp:
+        (WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
+        * layout/LayoutUnits.h:
+        (WebCore::Layout::UsedHorizontalValues::Constraints::Constraints):
+        (WebCore::Layout::UsedHorizontalValues::UsedHorizontalValues):
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::placeInFlowPositionedChildren):
+        (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPosition):
+        (WebCore::Layout::BlockFormattingContext::computeWidthAndMargin):
+        (WebCore::Layout::BlockFormattingContext::computeHeightAndMargin):
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin const):
+        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):
+        * layout/blockformatting/BlockFormattingContextQuirks.cpp:
+        (WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight):
+        * layout/blockformatting/BlockMarginCollapse.cpp:
+        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues):
+        * layout/floats/FloatingContext.h:
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::layoutInFlowContent):
+        (WebCore::Layout::InlineFormattingContext::computedIntrinsicWidthConstraints):
+        (WebCore::Layout::InlineFormattingContext::computeIntrinsicWidthForFormattingRoot):
+        (WebCore::Layout::InlineFormattingContext::computeHeightAndMargin):
+        * layout/inlineformatting/InlineFormattingContextGeometry.cpp:
+        (WebCore::Layout::InlineFormattingContext::Geometry::inlineBlockWidthAndMargin):
+        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
+        (WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const):
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns):
+
 2019-09-18  Andy Estes  <aestes@apple.com>
 
         [Apple Pay] Tell websites why a session was cancelled
index 57e750e..94d7522 100644 (file)
@@ -1396,6 +1396,7 @@ layout/FormattingContextQuirks.cpp
 layout/FormattingState.cpp
 layout/LayoutPhase.cpp
 layout/LayoutState.cpp
+layout/LayoutUnits.cpp
 layout/Verification.cpp
 layout/blockformatting/BlockFormattingContext.cpp
 layout/blockformatting/BlockFormattingContextGeometry.cpp
index 72dc12b..ef1fd62 100644 (file)
                113409D8203E038000C66915 /* RenderTreeBuilderContinuation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderContinuation.h; sourceTree = "<group>"; };
                113D0B4F1F9FDD2B00F611BB /* FrameViewLayoutContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FrameViewLayoutContext.cpp; sourceTree = "<group>"; };
                113D0B501F9FDD2B00F611BB /* FrameViewLayoutContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FrameViewLayoutContext.h; sourceTree = "<group>"; };
+               115CA83023328B1E00FD3B08 /* LayoutUnits.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutUnits.cpp; sourceTree = "<group>"; };
                115CFA68208AF7D0001E6991 /* FormattingContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FormattingContext.h; sourceTree = "<group>"; };
                115CFA69208AF7D0001E6991 /* FormattingContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FormattingContext.cpp; sourceTree = "<group>"; };
                115CFA6C208AFAB6001E6991 /* BlockFormattingContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlockFormattingContext.h; sourceTree = "<group>"; };
                                6FEFE81D22F9D22A00114927 /* LayoutPhase.h */,
                                6F7CA3C5208C2956002F29AB /* LayoutState.cpp */,
                                6F7CA3C4208C2956002F29AB /* LayoutState.h */,
+                               115CA83023328B1E00FD3B08 /* LayoutUnits.cpp */,
                                6F73918C2106CEDD006AF262 /* LayoutUnits.h */,
                                6FE7AA2621C37B6300296DCD /* MarginTypes.h */,
                                11FF02D520BA3C810083F25B /* Verification.cpp */,
index cec834e..e07b595 100644 (file)
@@ -70,7 +70,7 @@ void FormattingContext::computeOutOfFlowHorizontalGeometry(const Box& layoutBox)
     auto containingBlockHeight = geometryForBox(*layoutBox.containingBlock()).paddingBoxHeight();
 
     auto compute = [&](Optional<LayoutUnit> usedWidth) {
-        auto usedHorizontalValues = UsedHorizontalValues { containingBlockWidth, usedWidth, { } };
+        auto usedHorizontalValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { containingBlockWidth }, usedWidth, { } };
         auto usedVerticalValues = UsedVerticalValues { containingBlockHeight, { } };
         return geometry().outOfFlowHorizontalGeometry(layoutBox, usedHorizontalValues, usedVerticalValues);
     };
@@ -105,7 +105,7 @@ void FormattingContext::computeOutOfFlowVerticalGeometry(const Box& layoutBox)
     auto containingBlockWidth = containingBlockGeometry.paddingBoxHeight();
 
     auto usedVerticalValuesForHeight = UsedVerticalValues { containingBlockHeight, { } };
-    auto usedHorizontalValues = UsedHorizontalValues { containingBlockWidth };
+    auto usedHorizontalValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { containingBlockWidth } };
 
     auto verticalGeometry = compute(usedHorizontalValues, usedVerticalValuesForHeight);
     if (auto maxHeight = geometry().computedMaxHeight(layoutBox, containingBlockHeight)) {
@@ -133,7 +133,7 @@ void FormattingContext::computeOutOfFlowVerticalGeometry(const Box& layoutBox)
 void FormattingContext::computeBorderAndPadding(const Box& layoutBox, Optional<UsedHorizontalValues> usedHorizontalValues)
 {
     if (!usedHorizontalValues)
-        usedHorizontalValues = UsedHorizontalValues { geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() };
+        usedHorizontalValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { geometryForBox(*layoutBox.containingBlock()) } };
     auto& displayBox = formattingState().displayBox(layoutBox);
     displayBox.setBorder(geometry().computedBorder(layoutBox));
     displayBox.setPadding(geometry().computedPadding(layoutBox, *usedHorizontalValues));
index 34e381e..5c7a949 100644 (file)
@@ -300,7 +300,7 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowNonReplacedVerticalGeomet
     auto& style = layoutBox.style();
     auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
     auto containingBlockHeight = *usedVerticalValues.containingBlockHeight;
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
 
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -423,7 +423,7 @@ HorizontalGeometry FormattingContext::Geometry::outOfFlowNonReplacedHorizontalGe
     auto& formattingContext = this->formattingContext();
     auto& style = layoutBox.style();
     auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
     auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
     
     auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
@@ -557,7 +557,7 @@ VerticalGeometry FormattingContext::Geometry::outOfFlowReplacedVerticalGeometry(
     auto& style = layoutBox.style();
     auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
     auto containingBlockHeight = *usedVerticalValues.containingBlockHeight;
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
 
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -641,7 +641,7 @@ HorizontalGeometry FormattingContext::Geometry::outOfFlowReplacedHorizontalGeome
     auto& formattingContext = this->formattingContext();
     auto& style = layoutBox.style();
     auto& boxGeometry = formattingContext.geometryForBox(layoutBox);
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
     auto isLeftToRightDirection = layoutBox.containingBlock()->style().isLeftToRightDirection();
 
     auto left = computedValueIfNotAuto(style.logicalLeft(), containingBlockWidth);
@@ -769,9 +769,9 @@ WidthAndMargin FormattingContext::Geometry::floatingNonReplacedWidthAndMargin(co
     // #1
     auto usedHorizontallMargin = UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) };
     // #2
-    auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : layoutBox.style().logicalWidth(), usedHorizontalValues.containingBlockWidth);
+    auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : layoutBox.style().logicalWidth(), usedHorizontalValues.constraints.width);
     if (!width)
-        width = shrinkToFitWidth(layoutBox, usedHorizontalValues.containingBlockWidth);
+        width = shrinkToFitWidth(layoutBox, usedHorizontalValues.constraints.width);
 
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Width][Margin] -> floating non-replaced -> width(" << *width << "px) margin(" << usedHorizontallMargin.start << "px, " << usedHorizontallMargin.end << "px) -> layoutBox(" << &layoutBox << ")");
     return WidthAndMargin { *width, usedHorizontallMargin, computedHorizontalMargin };
@@ -798,8 +798,8 @@ WidthAndMargin FormattingContext::Geometry::floatingReplacedWidthAndMargin(const
     auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
 
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Height][Margin] -> floating replaced -> redirected to inline replaced");
-    return inlineReplacedWidthAndMargin(layoutBox, UsedHorizontalValues { usedHorizontalValues.containingBlockWidth,
-        usedHorizontalValues.width, UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) } });
+    usedHorizontalValues.margin = UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) };
+    return inlineReplacedWidthAndMargin(layoutBox, usedHorizontalValues);
 }
 
 VerticalGeometry FormattingContext::Geometry::outOfFlowVerticalGeometry(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues, UsedVerticalValues usedVerticalValues) const
@@ -908,7 +908,7 @@ WidthAndMargin FormattingContext::Geometry::inlineReplacedWidthAndMargin(const B
     //    If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead.
 
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
     auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutBox, usedHorizontalValues);
 
     auto usedMarginStart = [&] {
@@ -969,7 +969,7 @@ LayoutSize FormattingContext::Geometry::inFlowPositionedPositionOffset(const Box
     // 3. If neither is 'auto', 'bottom' is ignored (i.e., the used value of 'bottom' will be minus the value of 'top').
 
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
 
     auto top = computedValueIfNotAuto(style.logicalTop(), containingBlockWidth);
     auto bottom = computedValueIfNotAuto(style.logicalBottom(), containingBlockWidth);
@@ -1046,7 +1046,7 @@ Optional<Edges> FormattingContext::Geometry::computedPadding(const Box& layoutBo
         return WTF::nullopt;
 
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Padding] -> layoutBox: " << &layoutBox);
     return Edges {
         { valueForLength(style.paddingLeft(), containingBlockWidth), valueForLength(style.paddingRight(), containingBlockWidth) },
@@ -1057,14 +1057,14 @@ Optional<Edges> FormattingContext::Geometry::computedPadding(const Box& layoutBo
 ComputedHorizontalMargin FormattingContext::Geometry::computedHorizontalMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
     return { computedValueIfNotAuto(style.marginStart(), containingBlockWidth), computedValueIfNotAuto(style.marginEnd(), containingBlockWidth) };
 }
 
 ComputedVerticalMargin FormattingContext::Geometry::computedVerticalMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues) const
 {
     auto& style = layoutBox.style();
-    auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+    auto containingBlockWidth = usedHorizontalValues.constraints.width;
     return { computedValueIfNotAuto(style.marginBefore(), containingBlockWidth), computedValueIfNotAuto(style.marginAfter(), containingBlockWidth) };
 }
 
index 4828d00..da679fe 100644 (file)
@@ -52,7 +52,7 @@ LayoutUnit FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFix
         if (containingBlock->isBodyBox() || containingBlock->isDocumentBox()) {
             auto& boxGeometry = formattingContext.geometryForBox(*containingBlock, FormattingContext::EscapeType::AccessAncestorFormattingContext);
 
-            auto usedValues = UsedHorizontalValues { formattingContext.geometryForBox(*containingBlock->containingBlock(), FormattingContext::EscapeType::AccessAncestorFormattingContext).contentBoxWidth() };
+            auto usedValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { formattingContext.geometryForBox(*containingBlock->containingBlock(), FormattingContext::EscapeType::AccessAncestorFormattingContext) } };
             auto verticalMargin = formattingContext.geometry().computedVerticalMargin(*containingBlock, usedValues);
             auto verticalPadding = boxGeometry.paddingTop().valueOr(0) + boxGeometry.paddingBottom().valueOr(0);
             auto verticalBorder = boxGeometry.borderTop() + boxGeometry.borderBottom();
diff --git a/Source/WebCore/layout/LayoutUnits.cpp b/Source/WebCore/layout/LayoutUnits.cpp
new file mode 100644 (file)
index 0000000..504c338
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LayoutUnits.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "DisplayBox.h"
+
+namespace WebCore {
+namespace Layout {
+
+UsedHorizontalValues::Constraints::Constraints(const Display::Box& containingBlockGeometry)
+    : width(containingBlockGeometry.contentBoxWidth())
+{
+}
+
+}
+}
+#endif
index b5c53a2..29237ac 100644 (file)
 #include <wtf/Optional.h>
 
 namespace WebCore {
+
+namespace Display {
+class Box;
+}
+
 namespace Layout {
 
 struct Position {
@@ -138,19 +143,29 @@ struct VerticalGeometry {
 };
 
 struct UsedHorizontalValues {
-    explicit UsedHorizontalValues(LayoutUnit containingBlockWidth)
-        : containingBlockWidth(containingBlockWidth)
+    struct Constraints {
+        explicit Constraints(const Display::Box& containingBlockGeometry);
+        explicit Constraints(LayoutUnit horizontalConstraint)
+            : width(horizontalConstraint)
         {
         }
 
-    explicit UsedHorizontalValues(LayoutUnit containingBlockWidth, Optional<LayoutUnit> width, Optional<UsedHorizontalMargin> margin)
-        : containingBlockWidth(containingBlockWidth)
+        LayoutUnit width;
+    };
+
+    explicit UsedHorizontalValues(Constraints constraints)
+        : constraints(constraints)
+    {
+    }
+
+    explicit UsedHorizontalValues(Constraints constraints, Optional<LayoutUnit> width, Optional<UsedHorizontalMargin> margin)
+        : constraints(constraints)
         , width(width)
         , margin(margin)
-        {
-        }
+    {
+    }
 
-    LayoutUnit containingBlockWidth;
+    Constraints constraints;
     Optional<LayoutUnit> width;
     Optional<UsedHorizontalMargin> margin;
 };
index 2f24ef4..fac0fbc 100644 (file)
@@ -33,6 +33,7 @@
 #include "FloatingContext.h"
 #include "FloatingState.h"
 #include "LayoutBox.h"
+#include "LayoutChildIterator.h"
 #include "LayoutContainer.h"
 #include "LayoutState.h"
 #include "Logging.h"
@@ -193,7 +194,7 @@ void BlockFormattingContext::placeInFlowPositionedChildren(const Box& layoutBox)
             continue;
 
         auto computeInFlowPositionedPosition = [&] {
-            auto usedHorizontalValues = UsedHorizontalValues { geometryForBox(*childBox.containingBlock()).contentBoxWidth() };
+            auto usedHorizontalValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { geometryForBox(*childBox.containingBlock()) } };
             auto positionOffset = geometry().inFlowPositionedPositionOffset(childBox, usedHorizontalValues);
 
             auto& displayBox = formattingState().displayBox(childBox);
@@ -231,7 +232,7 @@ void BlockFormattingContext::computeStaticPosition(const FloatingContext& floati
 
 void BlockFormattingContext::computeEstimatedVerticalPosition(const Box& layoutBox)
 {
-    auto usedHorizontalValues = UsedHorizontalValues { geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() };
+    auto usedHorizontalValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { geometryForBox(*layoutBox.containingBlock()) } };
     auto computedVerticalMargin = geometry().computedVerticalMargin(layoutBox, usedHorizontalValues);
     auto usedNonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
     auto estimatedMarginBefore = marginCollapse().estimatedMarginBefore(layoutBox, usedNonCollapsedMargin);
@@ -356,7 +357,7 @@ void BlockFormattingContext::computeWidthAndMargin(const Box& layoutBox, Optiona
         availableWidth = geometryForBox(*layoutBox.containingBlock()).contentBoxWidth();
 
     auto compute = [&](Optional<LayoutUnit> usedWidth) -> WidthAndMargin {
-        auto usedValues = UsedHorizontalValues { availableWidth, usedWidth, { } };
+        auto usedValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { availableWidth }, usedWidth, { } };
         if (layoutBox.isInFlow())
             return geometry().inFlowWidthAndMargin(layoutBox, usedValues);
 
@@ -390,7 +391,7 @@ void BlockFormattingContext::computeHeightAndMargin(const Box& layoutBox)
 {
     auto compute = [&](auto usedVerticalValues) -> HeightAndMargin {
 
-        auto usedHorizontalValues = UsedHorizontalValues { geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() };
+        auto usedHorizontalValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { geometryForBox(*layoutBox.containingBlock()) } };
         if (layoutBox.isInFlow())
             return geometry().inFlowHeightAndMargin(layoutBox, usedHorizontalValues, usedVerticalValues);
 
index 22a9c8a..e8bf6f9 100644 (file)
@@ -136,7 +136,7 @@ WidthAndMargin BlockFormattingContext::Geometry::inFlowNonReplacedWidthAndMargin
         //    edges of the containing block.
 
         auto& style = layoutBox.style();
-        auto containingBlockWidth = usedHorizontalValues.containingBlockWidth;
+        auto containingBlockWidth = usedHorizontalValues.constraints.width;
         auto& boxGeometry = formattingContext().geometryForBox(layoutBox);
 
         auto width = computedValueIfNotAuto(usedHorizontalValues.width ? Length { usedHorizontalValues.width.value(), Fixed } : style.logicalWidth(), containingBlockWidth);
@@ -278,7 +278,7 @@ HeightAndMargin BlockFormattingContext::Geometry::inFlowHeightAndMargin(const Bo
     return heightAndMargin;
 }
 
-WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedValues)
+WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(const Box& layoutBox, UsedHorizontalValues usedHorizontalValues)
 {
     ASSERT(layoutBox.isInFlow());
 
@@ -286,11 +286,11 @@ WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(const Box&
         if (layoutBox.establishesTableFormattingContext()) {
             // This is a special table "fit-content size" behavior handling. Not in the spec though.
             // Table returns its final width as min/max. Use this final width value to computed horizontal margins etc.
-            usedValues.width = shrinkToFitWidth(layoutBox, usedValues.containingBlockWidth);
+            usedHorizontalValues.width = shrinkToFitWidth(layoutBox, usedHorizontalValues.constraints.width);
         }
-        return inFlowNonReplacedWidthAndMargin(layoutBox, usedValues);
+        return inFlowNonReplacedWidthAndMargin(layoutBox, usedHorizontalValues);
     }
-    return inFlowReplacedWidthAndMargin(layoutBox, usedValues);
+    return inFlowReplacedWidthAndMargin(layoutBox, usedHorizontalValues);
 }
 
 FormattingContext::IntrinsicWidthConstraints BlockFormattingContext::Geometry::intrinsicWidthConstraints(const Box& layoutBox)
index 4c1e15b..32495f8 100644 (file)
@@ -69,8 +69,8 @@ HeightAndMargin BlockFormattingContext::Quirks::stretchedInFlowHeight(const Box&
     auto& documentBox = layoutBox.isDocumentBox() ? layoutBox : *layoutBox.parent();
     auto& documentBoxGeometry = formattingContext.geometryForBox(documentBox);
 
-    auto& initialContainingBlocGeometry = formattingContext.geometryForBox(initialContainingBlock(layoutBox));
-    auto strechedHeight = initialContainingBlocGeometry.contentBoxHeight();
+    auto& initialContainingBlockGeometry = formattingContext.geometryForBox(initialContainingBlock(layoutBox));
+    auto strechedHeight = initialContainingBlockGeometry.contentBoxHeight();
     strechedHeight -= documentBoxGeometry.verticalBorder() + documentBoxGeometry.verticalPadding().valueOr(0);
 
     LayoutUnit totalVerticalMargin;
@@ -82,7 +82,7 @@ HeightAndMargin BlockFormattingContext::Quirks::stretchedInFlowHeight(const Box&
         // Here is the quirky part for body box:
         // Stretch the body using the initial containing block's height and shrink it with document box's margin/border/padding.
         // This looks extremely odd when html has non-auto height.
-        auto documentBoxVerticalMargin = formattingContext.geometry().computedVerticalMargin(documentBox, UsedHorizontalValues { initialContainingBlocGeometry.contentBoxWidth() });
+        auto documentBoxVerticalMargin = formattingContext.geometry().computedVerticalMargin(documentBox, UsedHorizontalValues { UsedHorizontalValues::Constraints { initialContainingBlockGeometry } });
         strechedHeight -= (documentBoxVerticalMargin.before.valueOr(0) + documentBoxVerticalMargin.after.valueOr(0));
 
         auto& bodyBoxGeometry = formattingContext.geometryForBox(layoutBox);
index ba88b54..ed9b225 100644 (file)
@@ -519,7 +519,7 @@ PositiveAndNegativeVerticalMargin::Values BlockFormattingContext::MarginCollapse
         return marginType == MarginType::Before ? positiveAndNegativeVerticalMargin.before : positiveAndNegativeVerticalMargin.after; 
     }
     // This is the estimate path. We don't yet have positive/negative margin computed.
-    auto usedValues = UsedHorizontalValues { formattingContext().geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() };
+    auto usedValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { formattingContext().geometryForBox(*layoutBox.containingBlock()) } };
     auto computedVerticalMargin = formattingContext().geometry().computedVerticalMargin(layoutBox, usedValues);
     auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) }; 
 
index e496739..283d874 100644 (file)
@@ -30,7 +30,6 @@
 #include "FloatingState.h"
 #include "FormattingContext.h"
 #include "LayoutContainer.h"
-#include "LayoutUnits.h"
 #include <wtf/IsoMalloc.h>
 
 namespace WebCore {
index 91deaa5..7c1ce09 100644 (file)
@@ -68,8 +68,7 @@ void InlineFormattingContext::layoutInFlowContent()
         return;
 
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
-    auto availableWidth = geometryForBox(root()).contentBoxWidth();
-    auto usedValues = UsedHorizontalValues { availableWidth };
+    auto usedValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { geometryForBox(root()) } };
     auto* layoutBox = root().firstInFlowOrFloatingChild();
     // Compute width/height for non-text content and margin/border/padding for inline containers.
     while (layoutBox) {
@@ -91,7 +90,7 @@ void InlineFormattingContext::layoutInFlowContent()
     formattingState().inlineRuns().clear();
 
     collectInlineContent();
-    InlineLayout(*this).layout(formattingState().inlineItems(), availableWidth);
+    InlineLayout(*this).layout(formattingState().inlineItems(), usedValues.constraints.width);
     LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root() << ")");
 }
 
@@ -107,7 +106,7 @@ FormattingContext::IntrinsicWidthConstraints InlineFormattingContext::computedIn
     }
 
     Vector<const Box*> formattingContextRootList;
-    auto usedValues = UsedHorizontalValues { LayoutUnit { } };
+    auto usedValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { LayoutUnit { } } };
     auto* layoutBox = root().firstInFlowOrFloatingChild();
     while (layoutBox) {
         if (layoutBox->establishesFormattingContext()) {
@@ -168,7 +167,7 @@ void InlineFormattingContext::computeIntrinsicWidthForFormattingRoot(const Box&
 {
     ASSERT(formattingRoot.establishesFormattingContext());
 
-    auto usedValues = UsedHorizontalValues { LayoutUnit { } };
+    auto usedValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { LayoutUnit { } } };
     computeBorderAndPadding(formattingRoot, usedValues);
     computeHorizontalMargin(formattingRoot, usedValues);
 
@@ -211,7 +210,7 @@ void InlineFormattingContext::computeWidthAndMargin(const Box& layoutBox, UsedHo
 void InlineFormattingContext::computeHeightAndMargin(const Box& layoutBox)
 {
     HeightAndMargin heightAndMargin;
-    auto usedHorizontalValues = UsedHorizontalValues { geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() };
+    auto usedHorizontalValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { geometryForBox(*layoutBox.containingBlock()) } };
     if (layoutBox.isFloatingPositioned())
         heightAndMargin = geometry().floatingHeightAndMargin(layoutBox, usedHorizontalValues, { });
     else if (layoutBox.isInlineBlockBox())
index 0d1ac75..4675cc2 100644 (file)
@@ -53,9 +53,9 @@ WidthAndMargin InlineFormattingContext::Geometry::inlineBlockWidthAndMargin(cons
     // If 'width' is 'auto', the used value is the shrink-to-fit width as for floating elements.
     // A computed value of 'auto' for 'margin-left' or 'margin-right' becomes a used value of '0'.
     // #1
-    auto width = computedValueIfNotAuto(formattingContextRoot.style().logicalWidth(), usedHorizontalValues.containingBlockWidth);
+    auto width = computedValueIfNotAuto(formattingContextRoot.style().logicalWidth(), usedHorizontalValues.constraints.width);
     if (!width)
-        width = shrinkToFitWidth(formattingContextRoot, usedHorizontalValues.containingBlockWidth);
+        width = shrinkToFitWidth(formattingContextRoot, usedHorizontalValues.constraints.width);
 
     // #2
     auto computedHorizontalMargin = Geometry::computedHorizontalMargin(formattingContextRoot, usedHorizontalValues);
index 883f748..aecbbf0 100644 (file)
@@ -404,11 +404,12 @@ void InlineFormattingContext::InlineLayout::createDisplayRuns(const Line::Conten
             continue;
         }
 
+        auto usedHorizontalValues = UsedHorizontalValues { UsedHorizontalValues::Constraints { formattingContext.geometryForBox(*layoutBox.containingBlock()) } };
         // Inline level box (replaced or inline-block)
         if (lineRun->isBox()) {
             auto topLeft = logicalRect.topLeft();
             if (layoutBox.isInFlowPositioned())
-                topLeft += geometry.inFlowPositionedPositionOffset(layoutBox, UsedHorizontalValues { formattingContext.geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() });
+                topLeft += geometry.inFlowPositionedPositionOffset(layoutBox, usedHorizontalValues);
             displayBox.setTopLeft(topLeft);
             lineBoxRect.expandHorizontally(logicalRect.width());
             formattingState.addInlineRun(makeUnique<Display::Run>(logicalRect));
@@ -425,7 +426,7 @@ void InlineFormattingContext::InlineLayout::createDisplayRuns(const Line::Conten
         // Inline level container end (</span>)
         if (lineRun->isContainerEnd()) {
             if (layoutBox.isInFlowPositioned()) {
-                auto inflowOffset = geometry.inFlowPositionedPositionOffset(layoutBox, UsedHorizontalValues { formattingContext.geometryForBox(*layoutBox.containingBlock()).contentBoxWidth() });
+                auto inflowOffset = geometry.inFlowPositionedPositionOffset(layoutBox, usedHorizontalValues);
                 displayBox.moveHorizontally(inflowOffset.width());
                 displayBox.moveVertically(inflowOffset.height());
             }
index 71f5c2d..d913816 100644 (file)
@@ -199,7 +199,7 @@ void TableFormattingContext::computePreferredWidthForColumns()
                 intrinsicWidth = layoutState().createFormattingContext(downcast<Container>(tableCellBox))->computedIntrinsicWidthConstraints();
             intrinsicWidth = geometry().constrainByMinMaxWidth(tableCellBox, *intrinsicWidth);
             auto border = geometry().computedBorder(tableCellBox);
-            auto padding = *geometry().computedPadding(tableCellBox, UsedHorizontalValues({ }));
+            auto padding = *geometry().computedPadding(tableCellBox, UsedHorizontalValues { UsedHorizontalValues::Constraints { LayoutUnit { } } });
 
             intrinsicWidth->expand(border.horizontal.width() + padding.horizontal.width());
             formattingState.setIntrinsicWidthConstraintsForBox(tableCellBox, *intrinsicWidth);