Title: [279504] trunk/Source/WebCore
Revision
279504
Author
za...@apple.com
Date
2021-07-02 08:28:05 -0700 (Fri, 02 Jul 2021)

Log Message

[LFC][TFC] TableGrid::Column holds both the computed and the used width values
https://bugs.webkit.org/show_bug.cgi?id=227488

Reviewed by Antti Koivisto.

This patch cleans up TableGrid::Column interface to ensure we don't confused
the computed and the used widths for columns.
This is also in prepartion for adding mixed width type support.

* layout/formattingContexts/table/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::setUsedGeometryForCells):
(WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
(WebCore::Layout::TableFormattingContext::computeAndDistributeExtraSpace):
* layout/formattingContexts/table/TableFormattingGeometry.cpp:
(WebCore::Layout::TableFormattingGeometry::horizontalSpaceForCellContent const):
* layout/formattingContexts/table/TableGrid.cpp:
(WebCore::Layout::TableGrid::Column::setLogicalWidth): Deleted.
(WebCore::Layout::TableGrid::Column::logicalWidth const): Deleted.
(WebCore::Layout::TableGrid::Column::setLogicalLeft): Deleted.
(WebCore::Layout::TableGrid::Column::logicalLeft const): Deleted.
* layout/formattingContexts/table/TableGrid.h:
(WebCore::Layout::TableGrid::Column::usedLogicalRight const):
(WebCore::Layout::TableGrid::Column::computedLogicalWidth const):
(WebCore::Layout::TableGrid::Columns::logicalWidth const):
(WebCore::Layout::TableGrid::Column::setComputedLogicalWidth):
(WebCore::Layout::TableGrid::Column::setUsedLogicalWidth):
(WebCore::Layout::TableGrid::Column::usedLogicalWidth const):
(WebCore::Layout::TableGrid::Column::setUsedLogicalLeft):
(WebCore::Layout::TableGrid::Column::usedLogicalLeft const):
(WebCore::Layout::TableGrid::Column::logicalRight const): Deleted.
(WebCore::Layout::TableGrid::Column::fixedWidth const): Deleted.
(WebCore::Layout::TableGrid::Column::percent const): Deleted.
(WebCore::Layout::TableGrid::Column::setFixedWidth): Deleted.
(WebCore::Layout::TableGrid::Column::setPercent): Deleted.
* layout/formattingContexts/table/TableLayout.cpp:
(WebCore::Layout::TableFormattingContext::TableLayout::distributedHorizontalSpace):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (279503 => 279504)


--- trunk/Source/WebCore/ChangeLog	2021-07-02 14:45:56 UTC (rev 279503)
+++ trunk/Source/WebCore/ChangeLog	2021-07-02 15:28:05 UTC (rev 279504)
@@ -1,3 +1,42 @@
+2021-07-02  Alan Bujtas  <za...@apple.com>
+
+        [LFC][TFC] TableGrid::Column holds both the computed and the used width values
+        https://bugs.webkit.org/show_bug.cgi?id=227488
+
+        Reviewed by Antti Koivisto.
+
+        This patch cleans up TableGrid::Column interface to ensure we don't confused
+        the computed and the used widths for columns.
+        This is also in prepartion for adding mixed width type support.
+
+        * layout/formattingContexts/table/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::setUsedGeometryForCells):
+        (WebCore::Layout::TableFormattingContext::computedPreferredWidthForColumns):
+        (WebCore::Layout::TableFormattingContext::computeAndDistributeExtraSpace):
+        * layout/formattingContexts/table/TableFormattingGeometry.cpp:
+        (WebCore::Layout::TableFormattingGeometry::horizontalSpaceForCellContent const):
+        * layout/formattingContexts/table/TableGrid.cpp:
+        (WebCore::Layout::TableGrid::Column::setLogicalWidth): Deleted.
+        (WebCore::Layout::TableGrid::Column::logicalWidth const): Deleted.
+        (WebCore::Layout::TableGrid::Column::setLogicalLeft): Deleted.
+        (WebCore::Layout::TableGrid::Column::logicalLeft const): Deleted.
+        * layout/formattingContexts/table/TableGrid.h:
+        (WebCore::Layout::TableGrid::Column::usedLogicalRight const):
+        (WebCore::Layout::TableGrid::Column::computedLogicalWidth const):
+        (WebCore::Layout::TableGrid::Columns::logicalWidth const):
+        (WebCore::Layout::TableGrid::Column::setComputedLogicalWidth):
+        (WebCore::Layout::TableGrid::Column::setUsedLogicalWidth):
+        (WebCore::Layout::TableGrid::Column::usedLogicalWidth const):
+        (WebCore::Layout::TableGrid::Column::setUsedLogicalLeft):
+        (WebCore::Layout::TableGrid::Column::usedLogicalLeft const):
+        (WebCore::Layout::TableGrid::Column::logicalRight const): Deleted.
+        (WebCore::Layout::TableGrid::Column::fixedWidth const): Deleted.
+        (WebCore::Layout::TableGrid::Column::percent const): Deleted.
+        (WebCore::Layout::TableGrid::Column::setFixedWidth): Deleted.
+        (WebCore::Layout::TableGrid::Column::setPercent): Deleted.
+        * layout/formattingContexts/table/TableLayout.cpp:
+        (WebCore::Layout::TableFormattingContext::TableLayout::distributedHorizontalSpace):
+
 2021-07-02  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, reverting r279487.

Modified: trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp (279503 => 279504)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp	2021-07-02 14:45:56 UTC (rev 279503)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp	2021-07-02 15:28:05 UTC (rev 279504)
@@ -101,7 +101,7 @@
         cellBoxGeometry.setBorder(formattingGeometry.computedCellBorder(*cell));
         cellBoxGeometry.setPadding(formattingGeometry.computedPadding(cellBox, availableHorizontalSpace));
         cellBoxGeometry.setLogicalTop(rowList[cell->startRow()].logicalTop() - sectionOffset);
-        cellBoxGeometry.setLogicalLeft(columnList[cell->startColumn()].logicalLeft());
+        cellBoxGeometry.setLogicalLeft(columnList[cell->startColumn()].usedLogicalLeft());
         cellBoxGeometry.setContentBoxWidth(formattingGeometry.horizontalSpaceForCellContent(*cell));
 
         if (cellBox.hasInFlowOrFloatingChild()) {
@@ -336,7 +336,7 @@
             return formattingGeometry.computedColumnWidth(*columnBox);
         }();
         if (fixedWidth)
-            column.setFixedWidth(*fixedWidth);
+            column.setComputedLogicalWidth({ *fixedWidth, LengthType::Fixed });
     }
 
     Vector<std::optional<float>> columnPercentList(columnList.size());
@@ -360,7 +360,9 @@
         grid.slot(cellPosition)->setWidthConstraints(*intrinsicWidth);
         if (auto fixedWidth = formattingGeometry.fixedValue(cellBox.style().logicalWidth())) {
             *fixedWidth += horizontalBorderAndPaddingWidth;
-            columnList[cellPosition.column].setFixedWidth(std::max(*fixedWidth, columnList[cellPosition.column].fixedWidth().value_or(0)));
+            auto& column = columnList[cellPosition.column];
+            if (*fixedWidth > column.computedLogicalWidth().value())
+                column.setComputedLogicalWidth({ *fixedWidth, LengthType::Fixed });
         }
         // Collect the percent values so that we can compute the maximum values per column.
         auto& cellLogicalWidth = cellBox.style().logicalWidth();
@@ -387,8 +389,8 @@
                 continue;
             }
             auto widthConstraints = slot.widthConstraints();
-            if (auto columnFixedWidth = columnList[columnIndex].fixedWidth())
-                widthConstraints.maximum = std::max(*columnFixedWidth, widthConstraints.minimum);
+            if (auto columnLogicalWidth = columnList[columnIndex].computedLogicalWidth(); columnLogicalWidth.isFixed())
+                widthConstraints.maximum = std::max(LayoutUnit { columnLogicalWidth.value() }, widthConstraints.minimum);
 
             columnIntrinsicWidths[columnIndex].minimum = std::max(widthConstraints.minimum, columnIntrinsicWidths[columnIndex].minimum);
             columnIntrinsicWidths[columnIndex].maximum = std::max(widthConstraints.maximum, columnIntrinsicWidths[columnIndex].maximum);
@@ -442,9 +444,10 @@
                 continue;
             }
             ASSERT(*percent > 0);
-            columnList[columnIndex].setPercent(std::min(remainingPercent, *percent));
-            percentMaximumWidth = std::max(percentMaximumWidth, LayoutUnit { columnIntrinsicWidths[columnIndex].maximum * 100.0f / *columnList[columnIndex].percent() });
-            remainingPercent -= *columnList[columnIndex].percent();
+            percent = std::min(*percent, remainingPercent);
+            columnList[columnIndex].setComputedLogicalWidth({ *percent, LengthType::Percent });
+            percentMaximumWidth = std::max(percentMaximumWidth, LayoutUnit { columnIntrinsicWidths[columnIndex].maximum * 100.0f / *percent });
+            remainingPercent -= *percent;
         }
 
         ASSERT(remainingPercent >= 0.f);
@@ -472,8 +475,8 @@
     auto columnLogicalLeft = grid.horizontalSpacing();
     for (size_t columnIndex = 0; columnIndex < columns.size(); ++columnIndex) {
         auto& column = columns[columnIndex];
-        column.setLogicalLeft(columnLogicalLeft);
-        column.setLogicalWidth(distributedHorizontalSpaces[columnIndex]);
+        column.setUsedLogicalLeft(columnLogicalLeft);
+        column.setUsedLogicalWidth(distributedHorizontalSpaces[columnIndex]);
         columnLogicalLeft += distributedHorizontalSpaces[columnIndex] + grid.horizontalSpacing();
     }
 

Modified: trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.cpp (279503 => 279504)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.cpp	2021-07-02 14:45:56 UTC (rev 279503)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.cpp	2021-07-02 15:28:05 UTC (rev 279504)
@@ -152,7 +152,7 @@
     auto& columnList = grid.columns().list();
     auto logicalWidth = LayoutUnit { };
     for (auto columnIndex = cell.startColumn(); columnIndex < cell.endColumn(); ++columnIndex)
-        logicalWidth += columnList.at(columnIndex).logicalWidth();
+        logicalWidth += columnList.at(columnIndex).usedLogicalWidth();
     // No column spacing when spanning.
     logicalWidth += (cell.columnSpan() - 1) * grid.horizontalSpacing();
     auto& cellBoxGeometry = formattingContext().geometryForBox(cell.box());

Modified: trunk/Source/WebCore/layout/formattingContexts/table/TableGrid.cpp (279503 => 279504)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableGrid.cpp	2021-07-02 14:45:56 UTC (rev 279503)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableGrid.cpp	2021-07-02 15:28:05 UTC (rev 279504)
@@ -40,34 +40,6 @@
 {
 }
 
-void TableGrid::Column::setLogicalWidth(LayoutUnit computedLogicalWidth)
-{
-#if ASSERT_ENABLED
-    m_hasComputedWidth = true;
-#endif
-    m_computedLogicalWidth = computedLogicalWidth;
-}
-
-LayoutUnit TableGrid::Column::logicalWidth() const
-{
-    ASSERT(m_hasComputedWidth);
-    return m_computedLogicalWidth;
-}
-
-void TableGrid::Column::setLogicalLeft(LayoutUnit computedLogicalLeft)
-{
-#if ASSERT_ENABLED
-    m_hasComputedLeft = true;
-#endif
-    m_computedLogicalLeft = computedLogicalLeft;
-}
-
-LayoutUnit TableGrid::Column::logicalLeft() const
-{
-    ASSERT(m_hasComputedLeft);
-    return m_computedLogicalLeft;
-}
-
 void TableGrid::Columns::addColumn(const ContainerBox& columnBox)
 {
     m_columnList.append({ &columnBox });

Modified: trunk/Source/WebCore/layout/formattingContexts/table/TableGrid.h (279503 => 279504)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableGrid.h	2021-07-02 14:45:56 UTC (rev 279503)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableGrid.h	2021-07-02 15:28:05 UTC (rev 279504)
@@ -67,30 +67,26 @@
     public:
         Column(const ContainerBox*);
 
-        void setLogicalLeft(LayoutUnit);
-        LayoutUnit logicalLeft() const;
-        LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
-        void setLogicalWidth(LayoutUnit);
-        LayoutUnit logicalWidth() const;
+        void setUsedLogicalLeft(LayoutUnit);
+        LayoutUnit usedLogicalLeft() const;
+        LayoutUnit usedLogicalRight() const { return usedLogicalLeft() + usedLogicalWidth(); }
+        void setUsedLogicalWidth(LayoutUnit);
+        LayoutUnit usedLogicalWidth() const;
 
-        void setFixedWidth(LayoutUnit fixedValue);
-        std::optional<LayoutUnit> fixedWidth() const { return m_fixedWidth; }
+        void setComputedLogicalWidth(Length&&);
+        const Length& computedLogicalWidth() const { return m_computedLogicalWidth; }
 
-        void setPercent(float);
-        std::optional<float> percent() const { return m_percent; }
-
         const ContainerBox* box() const { return m_layoutBox.get(); }
 
     private:
-        LayoutUnit m_computedLogicalWidth;
-        LayoutUnit m_computedLogicalLeft;
-        std::optional<LayoutUnit> m_fixedWidth;
-        std::optional<float> m_percent;
+        LayoutUnit m_usedLogicalWidth;
+        LayoutUnit m_usedLogicalLeft;
+        Length m_computedLogicalWidth;
         WeakPtr<const ContainerBox> m_layoutBox;
 
 #if ASSERT_ENABLED
-        bool m_hasComputedWidth { false };
-        bool m_hasComputedLeft { false };
+        bool m_hasUsedWidth { false };
+        bool m_hasUsedLeft { false };
 #endif
     };
 
@@ -104,7 +100,7 @@
         void addColumn(const ContainerBox&);
         void addAnonymousColumn();
 
-        LayoutUnit logicalWidth() const { return m_columnList.last().logicalRight() - m_columnList.first().logicalLeft(); }
+        LayoutUnit logicalWidth() const { return m_columnList.last().usedLogicalRight() - m_columnList.first().usedLogicalLeft(); }
 
     private:
         ColumnList m_columnList;
@@ -234,20 +230,41 @@
     std::optional<Edges> m_collapsedBorder;
 };
 
+inline void TableGrid::Column::setComputedLogicalWidth(Length&& computedLogicalWidth)
+{
+    ASSERT(computedLogicalWidth.type() == LengthType::Fixed || computedLogicalWidth.type() == LengthType::Percent || computedLogicalWidth.type() == LengthType::Relative);
+    m_computedLogicalWidth = WTFMove(computedLogicalWidth);
+}
 
-inline void TableGrid::Column::setFixedWidth(LayoutUnit fixedValue)
+inline void TableGrid::Column::setUsedLogicalWidth(LayoutUnit usedLogicalWidth)
 {
-    ASSERT(!m_percent);
-    m_fixedWidth = fixedValue;
+#if ASSERT_ENABLED
+    m_hasUsedWidth = true;
+#endif
+    m_usedLogicalWidth = usedLogicalWidth;
 }
 
-inline void TableGrid::Column::setPercent(float percent)
+inline LayoutUnit TableGrid::Column::usedLogicalWidth() const
 {
-    ASSERT(!m_fixedWidth);
-    m_percent = percent;
+    ASSERT(m_hasUsedWidth);
+    return m_usedLogicalWidth;
 }
 
+inline void TableGrid::Column::setUsedLogicalLeft(LayoutUnit usedLogicalLeft)
+{
+#if ASSERT_ENABLED
+    m_hasUsedLeft = true;
+#endif
+    m_usedLogicalLeft = usedLogicalLeft;
 }
+
+inline LayoutUnit TableGrid::Column::usedLogicalLeft() const
+{
+    ASSERT(m_hasUsedLeft);
+    return m_usedLogicalLeft;
 }
 
+}
+}
+
 #endif

Modified: trunk/Source/WebCore/layout/formattingContexts/table/TableLayout.cpp (279503 => 279504)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableLayout.cpp	2021-07-02 14:45:56 UTC (rev 279503)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableLayout.cpp	2021-07-02 15:28:05 UTC (rev 279504)
@@ -294,12 +294,22 @@
         auto& column = m_grid.columns().list()[columnIndex];
         auto columnWidth = std::optional<float> { };
         auto type = GridSpace::Type::Auto;
-        if (auto fixedWidth = column.fixedWidth()) {
-            columnWidth = *fixedWidth;
+
+        auto& computedLogicalWidth = column.computedLogicalWidth();
+        switch (computedLogicalWidth.type()) {
+        case LengthType::Fixed:
+            columnWidth = computedLogicalWidth.value();
             type = GridSpace::Type::Fixed;
-        } else if (auto percent = column.percent()) {
-            columnWidth = *percent * availableHorizontalSpace / 100.0f;
+            break;
+        case LengthType::Percent:
+            columnWidth = computedLogicalWidth.value() * availableHorizontalSpace / 100.0f;
             type = GridSpace::Type::Percent;
+            break;
+        case LengthType::Relative:
+            ASSERT_NOT_IMPLEMENTED_YET();
+            break;
+        default:
+            break;
         }
 
         float minimumContentWidth = slot.widthConstraints().minimum;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to