[LFC] Shrink-to-fit-width should be constrained by min/max width
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2019 16:32:55 +0000 (16:32 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2019 16:32:55 +0000 (16:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194653

Reviewed by Antti Koivisto.

Source/WebCore:

Use the fixed value of min-width/max-width to constrain the computed preferred width.

* layout/FormattingContext.h:
* layout/FormattingContextGeometry.cpp:
(WebCore::Layout::FormattingContext::Geometry::constrainByMinMaxWidth):
* layout/blockformatting/BlockFormattingContextGeometry.cpp:
(WebCore::Layout::BlockFormattingContext::Geometry::intrinsicWidthConstraints):
* layout/inlineformatting/InlineFormattingContext.cpp:
(WebCore::Layout::InlineFormattingContext::computeIntrinsicWidthConstraints const):

Tools:

* LayoutReloaded/misc/LFC-passing-tests.txt:

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

Source/WebCore/ChangeLog
Source/WebCore/layout/FormattingContext.h
Source/WebCore/layout/FormattingContextGeometry.cpp
Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
Tools/ChangeLog
Tools/LayoutReloaded/misc/LFC-passing-tests.txt

index d0130cd..afec57a 100644 (file)
@@ -1,3 +1,20 @@
+2019-02-14  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Shrink-to-fit-width should be constrained by min/max width
+        https://bugs.webkit.org/show_bug.cgi?id=194653
+
+        Reviewed by Antti Koivisto.
+
+        Use the fixed value of min-width/max-width to constrain the computed preferred width.
+
+        * layout/FormattingContext.h:
+        * layout/FormattingContextGeometry.cpp:
+        (WebCore::Layout::FormattingContext::Geometry::constrainByMinMaxWidth):
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::intrinsicWidthConstraints):
+        * layout/inlineformatting/InlineFormattingContext.cpp:
+        (WebCore::Layout::InlineFormattingContext::computeIntrinsicWidthConstraints const):
+
 2019-02-13  Ryosuke Niwa  <rniwa@webkit.org>
 
         Crash in DOMTimer::fired
index 209962b..1c13672 100644 (file)
@@ -104,6 +104,8 @@ protected:
         static Optional<LayoutUnit> computedMinHeight(const LayoutState&, const Box&);
         static Optional<LayoutUnit> computedMaxHeight(const LayoutState&, const Box&);
 
+        static FormattingContext::IntrinsicWidthConstraints constrainByMinMaxWidth(const Box&, IntrinsicWidthConstraints);
+
     protected:
         enum class HeightType { Min, Max, Normal };
         static Optional<LayoutUnit> computedHeightValue(const LayoutState&, const Box&, HeightType);
index 0c2d872..967cfd4 100644 (file)
@@ -1072,6 +1072,28 @@ ComputedVerticalMargin FormattingContext::Geometry::computedVerticalMargin(const
     return { computedValueIfNotAuto(style.marginBefore(), containingBlockWidth), computedValueIfNotAuto(style.marginAfter(), containingBlockWidth) };
 }
 
+FormattingContext::IntrinsicWidthConstraints FormattingContext::Geometry::constrainByMinMaxWidth(const Box& layoutBox, IntrinsicWidthConstraints intrinsicWidth)
+{
+    auto& style = layoutBox.style();
+    auto minWidth = fixedValue(style.logicalMinWidth());
+    auto maxWidth = fixedValue(style.logicalMaxWidth());
+    if (!minWidth && !maxWidth)
+        return intrinsicWidth;
+
+    if (maxWidth) {
+        intrinsicWidth.minimum = std::min(*maxWidth, intrinsicWidth.minimum);
+        intrinsicWidth.maximum = std::min(*maxWidth, intrinsicWidth.maximum);
+    }
+
+    if (minWidth) {
+        intrinsicWidth.minimum = std::max(*minWidth, intrinsicWidth.minimum);
+        intrinsicWidth.maximum = std::max(*minWidth, intrinsicWidth.maximum);
+    }
+
+    ASSERT(intrinsicWidth.minimum <= intrinsicWidth.maximum);
+    return intrinsicWidth;
+}
+
 }
 }
 #endif
index 148542b..649d5c4 100644 (file)
@@ -301,9 +301,7 @@ FormattingContext::IntrinsicWidthConstraints BlockFormattingContext::Geometry::i
     if (!is<Container>(layoutBox))
         return { };
 
-    LayoutUnit minimumIntrinsicWidth;
-    LayoutUnit maximumIntrinsicWidth;
-
+    auto intrinsicWidthConstraints = IntrinsicWidthConstraints { };
     for (auto& child : childrenOfType<Box>(downcast<Container>(layoutBox))) {
         if (child.isOutOfFlowPositioned())
             continue;
@@ -320,11 +318,11 @@ FormattingContext::IntrinsicWidthConstraints BlockFormattingContext::Geometry::i
             + LayoutUnit { style.borderRightWidth() }
             + fixedValue(style.marginEnd()).valueOr(0);
 
-        minimumIntrinsicWidth = std::max(minimumIntrinsicWidth, childIntrinsicWidthConstraints->minimum + horizontalMarginBorderAndPadding); 
-        maximumIntrinsicWidth = std::max(maximumIntrinsicWidth, childIntrinsicWidthConstraints->maximum + horizontalMarginBorderAndPadding); 
+        intrinsicWidthConstraints.minimum = std::max(intrinsicWidthConstraints.minimum, childIntrinsicWidthConstraints->minimum + horizontalMarginBorderAndPadding);
+        intrinsicWidthConstraints.maximum = std::max(intrinsicWidthConstraints.maximum, childIntrinsicWidthConstraints->maximum + horizontalMarginBorderAndPadding);
     }
 
-    return { minimumIntrinsicWidth, maximumIntrinsicWidth };
+    return constrainByMinMaxWidth(layoutBox, intrinsicWidthConstraints);
 }
 
 }
index fb982b3..e3c1536 100644 (file)
@@ -150,7 +150,7 @@ void InlineFormattingContext::computeIntrinsicWidthConstraints() const
         return maxContentLogicalRight;
     };
 
-    auto intrinsicWidthConstraints = FormattingContext::IntrinsicWidthConstraints { maximumLineWidth(0), maximumLineWidth(LayoutUnit::max()) };
+    auto intrinsicWidthConstraints = Geometry::constrainByMinMaxWidth(root, { maximumLineWidth(0), maximumLineWidth(LayoutUnit::max()) });
     layoutState.formattingStateForBox(root).setIntrinsicWidthConstraints(root, intrinsicWidthConstraints);
 }
 
index e7c8dd8..bf1fc0c 100644 (file)
@@ -1,3 +1,12 @@
+2019-02-14  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Shrink-to-fit-width should be constrained by min/max width
+        https://bugs.webkit.org/show_bug.cgi?id=194653
+
+        Reviewed by Antti Koivisto.
+
+        * LayoutReloaded/misc/LFC-passing-tests.txt:
+
 2019-02-13  Ryosuke Niwa  <rniwa@webkit.org>
 
         Crash in WKBundleFrameGetParentFrame when called inside didRemoveFrameFromHierarchy
index 8a95f9e..a5d5924 100644 (file)
@@ -813,7 +813,11 @@ css2.1/20110323/float-non-replaced-width-003.htm
 css2.1/20110323/float-non-replaced-width-004.htm
 css2.1/20110323/float-non-replaced-width-005.htm
 css2.1/20110323/float-non-replaced-width-006.htm
+css2.1/20110323/float-non-replaced-width-007.htm
+css2.1/20110323/float-non-replaced-width-008.htm
+css2.1/20110323/float-non-replaced-width-009.htm
 css2.1/20110323/float-non-replaced-width-010.htm
+css2.1/20110323/float-non-replaced-width-011.htm
 css2.1/20110323/float-non-replaced-width-012.htm
 css2.1/20110323/float-replaced-height-001.htm
 css2.1/20110323/float-replaced-height-004.htm