Title: [262951] trunk
Revision
262951
Author
za...@apple.com
Date
2020-06-12 08:55:03 -0700 (Fri, 12 Jun 2020)

Log Message

[LFC][TFC] Add support for min/max-width
https://bugs.webkit.org/show_bug.cgi?id=213111

Reviewed by Antti Koivisto.

Source/WebCore:

Apply min/max-width to constrain the available width for the table content.

Test: fast/layoutformattingcontext/table-min-max-width-simple.html

* layout/blockformatting/BlockFormattingContext.cpp:
(WebCore::Layout::BlockFormattingContext::computeWidthAndMargin):
(WebCore::Layout::BlockFormattingContext::computedWidthAndMargin):
* layout/blockformatting/BlockFormattingContext.h:
* layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp:
(WebCore::Layout::TableWrapperBlockFormattingContext::computeWidthAndMarginForTableBox):

LayoutTests:

* fast/layoutformattingcontext/table-min-max-width-simple-expected.html: Added.
* fast/layoutformattingcontext/table-min-max-width-simple.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (262950 => 262951)


--- trunk/LayoutTests/ChangeLog	2020-06-12 15:48:54 UTC (rev 262950)
+++ trunk/LayoutTests/ChangeLog	2020-06-12 15:55:03 UTC (rev 262951)
@@ -1,3 +1,13 @@
+2020-06-12  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][TFC] Add support for min/max-width
+        https://bugs.webkit.org/show_bug.cgi?id=213111
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/table-min-max-width-simple-expected.html: Added.
+        * fast/layoutformattingcontext/table-min-max-width-simple.html: Added.
+
 2020-06-12  Antti Koivisto  <an...@apple.com>
 
         Relative font size values (em) within CSS animations compound

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-min-max-width-simple-expected.html (0 => 262951)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-min-max-width-simple-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-min-max-width-simple-expected.html	2020-06-12 15:55:03 UTC (rev 262951)
@@ -0,0 +1,19 @@
+<!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+div {
+    padding: 2px;
+}
+</style>
+<div>text<br>
+content</div>
+<div>text content</div>
+<div>text<br>
+content</div>
+<div>text content</div>
+<div>text content</div>
+<div>text content</div>
+<div>text content</div>
+<div>text content</div>
+<div>text content</div>
+<div>text<br>
+content</div>

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-min-max-width-simple.html (0 => 262951)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-min-max-width-simple.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-min-max-width-simple.html	2020-06-12 15:55:03 UTC (rev 262951)
@@ -0,0 +1,15 @@
+<!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+td {
+   padding: 0px; }
+</style>
+<table style="width: 10px;"><tr><td>text content</td></tr></table>
+<table style="width: 500px;"><tr><td>text content</td></tr></table>
+<table style="max-width: 10px;"><tr><td>text content</td></tr></table>
+<table style="max-width: 500px;"><tr><td>text content</td></tr></table>
+<table style="min-width: 10px;"><tr><td>text content</td></tr></table>
+<table style="min-width: 500px;"><tr><td>text content</td></tr></table>
+<table style="min-width: 500px; max-width: 10px;"><tr><td>text content</td></tr></table>
+<table style="min-width: 10px; max-width: 500px;"><tr><td>text content</td></tr></table>
+<table style="width: 200px; min-width: 10px; max-width: 500px;"><tr><td>text content</td></tr></table>
+<table style="width: 5px; min-width: 10px; max-width: 500px;"><tr><td>text content</td></tr></table>

Modified: trunk/Source/WebCore/ChangeLog (262950 => 262951)


--- trunk/Source/WebCore/ChangeLog	2020-06-12 15:48:54 UTC (rev 262950)
+++ trunk/Source/WebCore/ChangeLog	2020-06-12 15:55:03 UTC (rev 262951)
@@ -1,3 +1,21 @@
+2020-06-12  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][TFC] Add support for min/max-width
+        https://bugs.webkit.org/show_bug.cgi?id=213111
+
+        Reviewed by Antti Koivisto.
+
+        Apply min/max-width to constrain the available width for the table content. 
+
+        Test: fast/layoutformattingcontext/table-min-max-width-simple.html
+
+        * layout/blockformatting/BlockFormattingContext.cpp:
+        (WebCore::Layout::BlockFormattingContext::computeWidthAndMargin):
+        (WebCore::Layout::BlockFormattingContext::computedWidthAndMargin):
+        * layout/blockformatting/BlockFormattingContext.h:
+        * layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp:
+        (WebCore::Layout::TableWrapperBlockFormattingContext::computeWidthAndMarginForTableBox):
+
 2020-06-12  Antti Koivisto  <an...@apple.com>
 
         Relative font size values (em) within CSS animations compound

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp (262950 => 262951)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2020-06-12 15:48:54 UTC (rev 262950)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp	2020-06-12 15:55:03 UTC (rev 262951)
@@ -320,39 +320,14 @@
 
 void BlockFormattingContext::computeWidthAndMargin(const FloatingContext& floatingContext, const Box& layoutBox, const ConstraintsPair& constraintsPair)
 {
-    auto& horizontalConstraints = constraintsPair.containingBlock.horizontal; 
-    auto compute = [&](Optional<LayoutUnit> usedWidth) -> ContentWidthAndMargin {
-        if (layoutBox.isFloatingPositioned())
-            return geometry().floatingWidthAndMargin(layoutBox, horizontalConstraints, { usedWidth, { } });
-
-        if (layoutBox.isFloatAvoider()) {
-            auto availableWidth = horizontalConstraints.logicalWidth;
-            if (layoutBox.style().logicalWidth().isAuto())
-                availableWidth = usedAvailableWidthForFloatAvoider(floatingContext, layoutBox, constraintsPair).valueOr(availableWidth);
-            return geometry().inFlowWidthAndMargin(layoutBox, { horizontalConstraints.logicalLeft, availableWidth }, { usedWidth, { } });
-        }
-
-        if (layoutBox.isInFlow())
-            return geometry().inFlowWidthAndMargin(layoutBox, horizontalConstraints, { usedWidth, { } });
-
-        ASSERT_NOT_REACHED();
-        return { };
-    };
-
-    auto contentWidthAndMargin = compute({ });
-
-    auto availableWidth = horizontalConstraints.logicalWidth;
-    if (auto maxWidth = geometry().computedMaxWidth(layoutBox, availableWidth)) {
-        auto maxWidthAndMargin = compute(maxWidth);
-        if (contentWidthAndMargin.contentWidth > maxWidthAndMargin.contentWidth)
-            contentWidthAndMargin = maxWidthAndMargin;
+    auto adjustedConstraints = constraintsPair;
+    if (layoutBox.isFloatAvoider() && layoutBox.style().logicalWidth().isAuto()) {
+        // Float avoiders' available width might be shrunk by existing floats in the context.
+        if (auto availableWidthForFloatAvoider = usedAvailableWidthForFloatAvoider(floatingContext, layoutBox, constraintsPair))
+            adjustedConstraints.containingBlock.horizontal.logicalWidth = *availableWidthForFloatAvoider;
     }
 
-    auto minWidth = geometry().computedMinWidth(layoutBox, availableWidth).valueOr(0);
-    auto minWidthAndMargin = compute(minWidth);
-    if (contentWidthAndMargin.contentWidth < minWidthAndMargin.contentWidth)
-        contentWidthAndMargin = minWidthAndMargin;
-
+    auto contentWidthAndMargin = geometry().computedWidthAndMargin(layoutBox, adjustedConstraints);
     auto& displayBox = formattingState().displayBox(layoutBox);
     displayBox.setContentBoxWidth(contentWidthAndMargin.contentWidth);
     displayBox.setHorizontalMargin(contentWidthAndMargin.usedMargin);

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h (262950 => 262951)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2020-06-12 15:48:54 UTC (rev 262950)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h	2020-06-12 15:55:03 UTC (rev 262951)
@@ -52,8 +52,8 @@
 
 protected:
     struct ConstraintsPair {
-        const ConstraintsForInFlowContent formattingContextRoot;
-        const ConstraintsForInFlowContent containingBlock;
+        ConstraintsForInFlowContent formattingContextRoot;
+        ConstraintsForInFlowContent containingBlock;
     };
     void placeInFlowPositionedChildren(const ContainerBox&, const HorizontalConstraints&);
 
@@ -69,6 +69,7 @@
     void precomputeVerticalPositionForBoxAndAncestors(const Box&, const ConstraintsPair&);
 
     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
+
     LayoutUnit verticalPositionWithMargin(const Box&, const UsedVerticalMargin&, const VerticalConstraints&) const;
 
     // This class implements positioning and sizing for boxes participating in a block formatting context.
@@ -85,6 +86,8 @@
 
         IntrinsicWidthConstraints intrinsicWidthConstraints(const Box&);
 
+        ContentWidthAndMargin computedWidthAndMargin(const Box&, const ConstraintsPair&);
+
     private:
         ContentHeightAndMargin inFlowNonReplacedHeightAndMargin(const Box&, const HorizontalConstraints&, const OverrideVerticalValues&);
         ContentWidthAndMargin inFlowNonReplacedWidthAndMargin(const Box&, const HorizontalConstraints&, const OverrideHorizontalValues&);

Modified: trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp (262950 => 262951)


--- trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2020-06-12 15:48:54 UTC (rev 262950)
+++ trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp	2020-06-12 15:55:03 UTC (rev 262951)
@@ -283,6 +283,36 @@
     return inFlowReplacedWidthAndMargin(downcast<ReplacedBox>(layoutBox), horizontalConstraints, overrideHorizontalValues);
 }
 
+ContentWidthAndMargin BlockFormattingContext::Geometry::computedWidthAndMargin(const Box& layoutBox, const ConstraintsPair& constraintsPair)
+{
+    auto& horizontalConstraints = constraintsPair.containingBlock.horizontal;
+    auto compute = [&](Optional<LayoutUnit> usedWidth) {
+        if (layoutBox.isFloatingPositioned())
+            return floatingWidthAndMargin(layoutBox, horizontalConstraints, { usedWidth, { } });
+
+        if (layoutBox.isInFlow())
+            return inFlowWidthAndMargin(layoutBox, horizontalConstraints, { usedWidth, { } });
+
+        ASSERT_NOT_REACHED();
+        return ContentWidthAndMargin { };
+    };
+
+    auto contentWidthAndMargin = compute({ });
+
+    auto availableWidth = horizontalConstraints.logicalWidth;
+    if (auto maxWidth = computedMaxWidth(layoutBox, availableWidth)) {
+        auto maxWidthAndMargin = compute(maxWidth);
+        if (contentWidthAndMargin.contentWidth > maxWidthAndMargin.contentWidth)
+            contentWidthAndMargin = maxWidthAndMargin;
+    }
+
+    auto minWidth = computedMinWidth(layoutBox, availableWidth).valueOr(0);
+    auto minWidthAndMargin = compute(minWidth);
+    if (contentWidthAndMargin.contentWidth < minWidthAndMargin.contentWidth)
+        contentWidthAndMargin = minWidthAndMargin;
+    return contentWidthAndMargin;
+}
+
 FormattingContext::IntrinsicWidthConstraints BlockFormattingContext::Geometry::intrinsicWidthConstraints(const Box& layoutBox)
 {
     auto fixedMarginBorderAndPadding = [&](auto& layoutBox) {

Modified: trunk/Source/WebCore/layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp (262950 => 262951)


--- trunk/Source/WebCore/layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp	2020-06-12 15:48:54 UTC (rev 262950)
+++ trunk/Source/WebCore/layout/blockformatting/tablewrapper/TableWrapperBlockFormattingContext.cpp	2020-06-12 15:55:03 UTC (rev 262951)
@@ -145,11 +145,12 @@
 {
     ASSERT(tableBox.isTableBox());
     if (!tableBox.hasChild()) {
-        auto contentWidthAndMargin = geometry().inFlowWidthAndMargin(tableBox, horizontalConstraints, { });
+        auto constraintsPair = ConstraintsPair { { horizontalConstraints, { } }, { horizontalConstraints, { } } };
+        auto computedWidthAndMargin = geometry().computedWidthAndMargin(tableBox, constraintsPair);
         auto& displayBox = formattingState().displayBox(tableBox);
-        displayBox.setContentBoxWidth(contentWidthAndMargin.contentWidth);
-        displayBox.setHorizontalMargin(contentWidthAndMargin.usedMargin);
-        displayBox.setHorizontalComputedMargin(contentWidthAndMargin.computedMargin);
+        displayBox.setContentBoxWidth(computedWidthAndMargin.contentWidth);
+        displayBox.setHorizontalMargin(computedWidthAndMargin.usedMargin);
+        displayBox.setHorizontalComputedMargin(computedWidthAndMargin.computedMargin);
         return;
     }
 
@@ -159,19 +160,35 @@
     auto intrinsicWidthConstraints = IntrinsicWidthConstraints { };
     if (auto precomputedIntrinsicWidthConstraints = formattingStateForTableBox.intrinsicWidthConstraints())
         intrinsicWidthConstraints = *precomputedIntrinsicWidthConstraints;
-    else
+    else {
         intrinsicWidthConstraints = LayoutContext::createFormattingContext(tableBox, layoutState())->computedIntrinsicWidthConstraints();
-    auto computedTableWidth = geometry().computedWidth(tableBox, horizontalConstraints.logicalWidth);
-    auto usedWidth = computedTableWidth;
-    if (computedTableWidth && intrinsicWidthConstraints.minimum > computedTableWidth) {
-        // Table content needs more space than the table has.
-        usedWidth = intrinsicWidthConstraints.minimum;
-    } else if (!computedTableWidth) {
-        // Use the generic shrink-to-fit-width logic.
-        usedWidth = std::min(std::max(intrinsicWidthConstraints.minimum, horizontalConstraints.logicalWidth), intrinsicWidthConstraints.maximum);
+        formattingStateForTableBox.setIntrinsicWidthConstraints(intrinsicWidthConstraints);
     }
-    auto contentWidthAndMargin = geometry().inFlowWidthAndMargin(tableBox, horizontalConstraints, OverrideHorizontalValues { usedWidth, { } });
 
+    auto geometry = this->geometry();
+    auto computedWidth = geometry.computedWidth(tableBox, horizontalConstraints.logicalWidth);
+    auto computedMaxWidth = geometry.computedMaxWidth(tableBox, horizontalConstraints.logicalWidth);
+    auto computedMinWidth = geometry.computedMinWidth(tableBox, horizontalConstraints.logicalWidth);
+    // Use the generic shrink-to-fit-width logic as the initial width for the table.
+    auto usedWidth = std::min(std::max(intrinsicWidthConstraints.minimum, horizontalConstraints.logicalWidth), intrinsicWidthConstraints.maximum);
+    if (computedWidth || computedMinWidth || computedMaxWidth) {
+        if (computedWidth) {
+            // Normalize the computed width value first.
+            if (computedMaxWidth && *computedWidth > *computedMaxWidth)
+                computedWidth = computedMaxWidth;
+            if (computedMinWidth && *computedWidth < *computedMinWidth)
+                computedWidth = computedMinWidth;
+            usedWidth = *computedWidth < intrinsicWidthConstraints.minimum ? intrinsicWidthConstraints.minimum : *computedWidth;
+        }
+
+        if (computedMaxWidth && *computedMaxWidth < usedWidth)
+            usedWidth = intrinsicWidthConstraints.minimum;
+        if (computedMinWidth && *computedMinWidth > usedWidth)
+            usedWidth = *computedMinWidth;
+    }
+
+    auto contentWidthAndMargin = geometry.inFlowWidthAndMargin(tableBox, horizontalConstraints, OverrideHorizontalValues { usedWidth, { } });
+
     auto& displayBox = formattingState().displayBox(tableBox);
     displayBox.setContentBoxWidth(contentWidthAndMargin.contentWidth);
     displayBox.setHorizontalMargin(contentWidthAndMargin.usedMargin);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to