Title: [258137] trunk/Source/WebCore
Revision
258137
Author
za...@apple.com
Date
2020-03-09 07:36:28 -0700 (Mon, 09 Mar 2020)

Log Message

[LFC][TFC] Do no try to distribute extra space in case of shrink to fit (max preferred width).
https://bugs.webkit.org/show_bug.cgi?id=208795
<rdar://problem/60208329>

Reviewed by Antti Koivisto.

When we shrink-to-fit the table and it isn't constrained by the containing block's width, we
should use the maximum width instead of trying to distribute the space.

* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::layoutInFlowContent):
(WebCore::Layout::TableFormattingContext::layoutTableCellBox):
(WebCore::Layout::TableFormattingContext::computeAndDistributeExtraHorizontalSpace):
* layout/tableformatting/TableFormattingContext.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (258136 => 258137)


--- trunk/Source/WebCore/ChangeLog	2020-03-09 14:04:35 UTC (rev 258136)
+++ trunk/Source/WebCore/ChangeLog	2020-03-09 14:36:28 UTC (rev 258137)
@@ -1,3 +1,20 @@
+2020-03-09  Zalan Bujtas  <za...@apple.com>
+
+        [LFC][TFC] Do no try to distribute extra space in case of shrink to fit (max preferred width).
+        https://bugs.webkit.org/show_bug.cgi?id=208795
+        <rdar://problem/60208329>
+
+        Reviewed by Antti Koivisto.
+
+        When we shrink-to-fit the table and it isn't constrained by the containing block's width, we
+        should use the maximum width instead of trying to distribute the space.
+
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::layoutInFlowContent):
+        (WebCore::Layout::TableFormattingContext::layoutTableCellBox):
+        (WebCore::Layout::TableFormattingContext::computeAndDistributeExtraHorizontalSpace):
+        * layout/tableformatting/TableFormattingContext.h:
+
 2020-03-07  Darin Adler  <da...@apple.com>
 
         Begin moving off of live ranges for WebKit internals

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (258136 => 258137)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-03-09 14:04:35 UTC (rev 258136)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-03-09 14:36:28 UTC (rev 258137)
@@ -65,7 +65,7 @@
     auto& grid = formattingState().tableGrid();
     auto& columnsContext = grid.columnsContext();
 
-    computeAndDistributeExtraHorizontalSpace();
+    computeAndDistributeExtraHorizontalSpace(horizontalConstraints.logicalWidth);
     // 1. Position each column.
     // FIXME: This should also deal with collapsing borders etc.
     auto horizontalSpacing = grid.horizontalSpacing();
@@ -111,8 +111,13 @@
     cellDisplayBox.setContentBoxWidth(column.logicalWidth() - cellDisplayBox.horizontalMarginBorderAndPadding());
 
     ASSERT(cellLayoutBox.establishesBlockFormattingContext());
-    if (is<ContainerBox>(cellLayoutBox) && downcast<ContainerBox>(cellLayoutBox).hasInFlowOrFloatingChild())
-        LayoutContext::createFormattingContext(downcast<ContainerBox>(cellLayoutBox), layoutState())->layoutInFlowContent(invalidationState, Geometry::horizontalConstraintsForInFlow(cellDisplayBox), Geometry::verticalConstraintsForInFlow(cellDisplayBox));
+    if (is<ContainerBox>(cellLayoutBox) && downcast<ContainerBox>(cellLayoutBox).hasInFlowOrFloatingChild()) {
+        auto& formattingContextRoot = downcast<ContainerBox>(cellLayoutBox);
+        auto formattingContextForCellContent = LayoutContext::createFormattingContext(formattingContextRoot, layoutState());
+        auto horizontalConstraintsForCellContent = Geometry::horizontalConstraintsForInFlow(cellDisplayBox);
+        auto verticalConstraintsForCellContent = Geometry::verticalConstraintsForInFlow(cellDisplayBox);
+        formattingContextForCellContent->layoutInFlowContent(invalidationState, horizontalConstraintsForCellContent, verticalConstraintsForCellContent);
+    }
     cellDisplayBox.setVerticalMargin({ { }, { } });
     cellDisplayBox.setContentBoxHeight(geometry().tableCellHeightAndMargin(cellLayoutBox).contentHeight);
     // FIXME: Check what to do with out-of-flow content.
@@ -274,7 +279,7 @@
     }
 }
 
-void TableFormattingContext::computeAndDistributeExtraHorizontalSpace()
+void TableFormattingContext::computeAndDistributeExtraHorizontalSpace(LayoutUnit containingBlockWidth)
 {
     auto& grid = formattingState().tableGrid();
     ASSERT(grid.hasComputedWidthConstraints());
@@ -316,10 +321,7 @@
         }
     };
 
-    auto& tableBox = root();
-    auto containingBlockWidth = geometryForBox(*tableBox.containingBlock(), EscapeReason::TableNeedsAccessToTableWrapper).contentBoxWidth();
-    auto contentWidth = geometry().computedContentWidth(tableBox, containingBlockWidth);
-    if (contentWidth) {
+    if (auto contentWidth = geometry().computedContentWidth(root(), containingBlockWidth)) {
         if (*contentWidth > tableWidthConstraints.minimum)
             distributeExtraHorizontalSpace(*contentWidth - tableWidthConstraints.minimum);
         else
@@ -327,7 +329,7 @@
     } else {
         if (tableWidthConstraints.minimum > containingBlockWidth)
             useAsContentLogicalWidth(WidthConstraintsType::Minimum);
-        else if (tableWidthConstraints.maximum < containingBlockWidth)
+        else if (tableWidthConstraints.maximum <= containingBlockWidth)
             useAsContentLogicalWidth(WidthConstraintsType::Maximum);
         else
             distributeExtraHorizontalSpace(containingBlockWidth - tableWidthConstraints.minimum);

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h (258136 => 258137)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h	2020-03-09 14:04:35 UTC (rev 258136)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h	2020-03-09 14:36:28 UTC (rev 258137)
@@ -66,7 +66,7 @@
 
     void ensureTableGrid();
     void computePreferredWidthForColumns();
-    void computeAndDistributeExtraHorizontalSpace();
+    void computeAndDistributeExtraHorizontalSpace(LayoutUnit containingBlockWidth);
     enum class WidthConstraintsType { Minimum, Maximum };
     void useAsContentLogicalWidth(WidthConstraintsType);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to