[LFC] Apply min/max width constraints to preferred width computation
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Feb 2019 12:54:01 +0000 (12:54 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Feb 2019 12:54:01 +0000 (12:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194739

Reviewed by Simon Fraser.

Source/WebCore:

Ensure that both min-height and max-height are taken into account while computing the preferred width.

Test: fast/block/block-only/min-max-and-preferred-width-simple.html

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

Tools:

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

LayoutTests:

* fast/block/block-only/min-max-and-preferred-width-simple-expected.html: Added.
* fast/block/block-only/min-max-and-preferred-width-simple.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/block/block-only/min-max-and-preferred-width-simple-expected.html [new file with mode: 0644]
LayoutTests/fast/block/block-only/min-max-and-preferred-width-simple.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
Tools/ChangeLog
Tools/LayoutReloaded/misc/LFC-passing-tests.txt

index e8f5c36..d2862ea 100644 (file)
@@ -1,3 +1,13 @@
+2019-02-16  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Apply min/max width constraints to preferred width computation
+        https://bugs.webkit.org/show_bug.cgi?id=194739
+
+        Reviewed by Simon Fraser.
+
+        * fast/block/block-only/min-max-and-preferred-width-simple-expected.html: Added.
+        * fast/block/block-only/min-max-and-preferred-width-simple.html: Added.
+
 2019-02-15  Dean Jackson  <dino@apple.com>
 
         Allow emulation of user gestures from Web Inspector console
diff --git a/LayoutTests/fast/block/block-only/min-max-and-preferred-width-simple-expected.html b/LayoutTests/fast/block/block-only/min-max-and-preferred-width-simple-expected.html
new file mode 100644 (file)
index 0000000..8b10f3f
--- /dev/null
@@ -0,0 +1,14 @@
+<style>
+.first {
+       width: 70px;
+       height: 30px;
+       background-color: red;
+}
+
+.second {
+       width: 70px;
+       height: 70px;
+       background-color: green;
+}
+</style>
+<div class=first></div><div class=second></div>
\ No newline at end of file
diff --git a/LayoutTests/fast/block/block-only/min-max-and-preferred-width-simple.html b/LayoutTests/fast/block/block-only/min-max-and-preferred-width-simple.html
new file mode 100644 (file)
index 0000000..86a6f00
--- /dev/null
@@ -0,0 +1,18 @@
+<style>
+.outer {
+       float: left;
+       width: auto;
+       height: 100px;
+       background-color: green;
+}
+
+.inner {
+       width: 100px;
+       height: 10px;
+       background-color: red;
+       padding: 10px;
+       max-width: 50px;
+       min-width: 30px;
+}
+</style>
+<div class=outer><div class=inner></div></div>
\ No newline at end of file
index 6625231..c045164 100644 (file)
@@ -1,3 +1,17 @@
+2019-02-16  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Apply min/max width constraints to preferred width computation
+        https://bugs.webkit.org/show_bug.cgi?id=194739
+
+        Reviewed by Simon Fraser.
+
+        Ensure that both min-height and max-height are taken into account while computing the preferred width.
+
+        Test: fast/block/block-only/min-max-and-preferred-width-simple.html
+
+        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
+        (WebCore::Layout::BlockFormattingContext::Geometry::intrinsicWidthConstraints):
+
 2019-02-15  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] Make builtin objects more lazily initialized under non-JIT mode
index 649d5c4..fe84bd8 100644 (file)
@@ -290,39 +290,41 @@ bool BlockFormattingContext::Geometry::intrinsicWidthConstraintsNeedChildrenWidt
 
 FormattingContext::IntrinsicWidthConstraints BlockFormattingContext::Geometry::intrinsicWidthConstraints(const LayoutState& layoutState, const Box& layoutBox)
 {
-    auto& style = layoutBox.style();
-    if (auto width = fixedValue(style.logicalWidth()))
-        return { *width, *width };
-
-    // Minimum/maximum width can't be depending on the containing block's width.
-    if (!style.logicalWidth().isAuto())
-        return { };
-
-    if (!is<Container>(layoutBox))
-        return { };
-
-    auto intrinsicWidthConstraints = IntrinsicWidthConstraints { };
-    for (auto& child : childrenOfType<Box>(downcast<Container>(layoutBox))) {
-        if (child.isOutOfFlowPositioned())
-            continue;
-        auto& formattingState = layoutState.formattingStateForBox(child);
-        ASSERT(formattingState.isBlockFormattingState());
-        auto childIntrinsicWidthConstraints = formattingState.intrinsicWidthConstraints(child);
-        ASSERT(childIntrinsicWidthConstraints);
-        
-        auto& style = child.style();
-        auto horizontalMarginBorderAndPadding = fixedValue(style.marginStart()).valueOr(0)
-            + LayoutUnit { style.borderLeftWidth() }
-            + fixedValue(style.paddingLeft()).valueOr(0)
-            + fixedValue(style.paddingRight()).valueOr(0)
-            + LayoutUnit { style.borderRightWidth() }
-            + fixedValue(style.marginEnd()).valueOr(0);
-
-        intrinsicWidthConstraints.minimum = std::max(intrinsicWidthConstraints.minimum, childIntrinsicWidthConstraints->minimum + horizontalMarginBorderAndPadding);
-        intrinsicWidthConstraints.maximum = std::max(intrinsicWidthConstraints.maximum, childIntrinsicWidthConstraints->maximum + horizontalMarginBorderAndPadding);
-    }
+    auto computedIntrinsicWidthConstraints = [&]() -> IntrinsicWidthConstraints {
+        auto& style = layoutBox.style();
+        if (auto width = fixedValue(style.logicalWidth()))
+            return { *width, *width };
+
+        // Minimum/maximum width can't be depending on the containing block's width.
+        if (!style.logicalWidth().isAuto())
+            return { };
+
+        if (!is<Container>(layoutBox))
+            return { };
+
+        auto intrinsicWidthConstraints = IntrinsicWidthConstraints { };
+        for (auto& child : childrenOfType<Box>(downcast<Container>(layoutBox))) {
+            if (child.isOutOfFlowPositioned())
+                continue;
+            const auto& formattingState = layoutState.formattingStateForBox(child);
+            ASSERT(formattingState.isBlockFormattingState());
+            auto childIntrinsicWidthConstraints = formattingState.intrinsicWidthConstraints(child);
+            ASSERT(childIntrinsicWidthConstraints);
+
+            auto& childStyle = child.style();
+            auto marginBorderAndPadding = fixedValue(childStyle.marginStart()).valueOr(0)
+                + LayoutUnit { childStyle.borderLeftWidth() }
+                + fixedValue(childStyle.paddingLeft()).valueOr(0)
+                + fixedValue(childStyle.paddingRight()).valueOr(0)
+                + LayoutUnit { childStyle.borderRightWidth() }
+                + fixedValue(childStyle.marginEnd()).valueOr(0);
+            intrinsicWidthConstraints.minimum = std::max(intrinsicWidthConstraints.minimum, childIntrinsicWidthConstraints->minimum + marginBorderAndPadding);
+            intrinsicWidthConstraints.maximum = std::max(intrinsicWidthConstraints.maximum, childIntrinsicWidthConstraints->maximum + marginBorderAndPadding);
+        }
+        return intrinsicWidthConstraints;
+    };
 
-    return constrainByMinMaxWidth(layoutBox, intrinsicWidthConstraints);
+    return constrainByMinMaxWidth(layoutBox, computedIntrinsicWidthConstraints());
 }
 
 }
index ea06af9..f7bf9cd 100644 (file)
@@ -1,3 +1,12 @@
+2019-02-16  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC] Apply min/max width constraints to preferred width computation
+        https://bugs.webkit.org/show_bug.cgi?id=194739
+
+        Reviewed by Simon Fraser.
+
+        * LayoutReloaded/misc/LFC-passing-tests.txt:
+
 2019-02-15  Ross Kirsling  <ross.kirsling@sony.com>
 
         [WTF] Add environment variable helpers
index d2ef4fe..286d61c 100644 (file)
@@ -97,6 +97,7 @@ fast/block/block-only/margin-left-right-sizing.html
 fast/block/block-only/margin-propagation-simple-content-height.html
 fast/block/block-only/margin-sibling-collapse-propagated.html
 fast/block/block-only/margin-simple.html
+fast/block/block-only/min-max-and-preferred-width-simple.html
 fast/block/block-only/min-max-height-percentage.html
 fast/block/block-only/negative-margin-simple.html
 fast/block/block-only/non-auto-top-bottom-height-with-auto-margins.html