[LFC][TFC] Implement TableFormattingContext::computePreferredWidthForColumns
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Aug 2019 15:39:23 +0000 (15:39 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Aug 2019 15:39:23 +0000 (15:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200701
<rdar://problem/54287828>

Reviewed by Antti Koivisto.

Compute cells' min/max width first.

* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns const):
* layout/tableformatting/TableGrid.cpp:
(WebCore::Layout::TableGrid::slot):
(WebCore::Layout::TableGrid::appendCell):
* layout/tableformatting/TableGrid.h:
(WebCore::Layout::TableGrid::cells):

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

Source/WebCore/ChangeLog
Source/WebCore/layout/tableformatting/TableFormattingContext.cpp
Source/WebCore/layout/tableformatting/TableGrid.cpp
Source/WebCore/layout/tableformatting/TableGrid.h

index 5412378..9ec0845 100644 (file)
@@ -1,3 +1,21 @@
+2019-08-14  Zalan Bujtas  <zalan@apple.com>
+
+        [LFC][TFC] Implement TableFormattingContext::computePreferredWidthForColumns
+        https://bugs.webkit.org/show_bug.cgi?id=200701
+        <rdar://problem/54287828>
+
+        Reviewed by Antti Koivisto.
+
+        Compute cells' min/max width first.
+
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns const):
+        * layout/tableformatting/TableGrid.cpp:
+        (WebCore::Layout::TableGrid::slot):
+        (WebCore::Layout::TableGrid::appendCell):
+        * layout/tableformatting/TableGrid.h:
+        (WebCore::Layout::TableGrid::cells):
+
 2019-08-14  Youenn Fablet  <youenn@apple.com>
 
         ThreadableBlobRegistry::blobSize should take a SessionID as parameter
index 3404dbf..e5a3a02 100644 (file)
@@ -85,6 +85,25 @@ void TableFormattingContext::ensureTableGrid() const
 
 void TableFormattingContext::computePreferredWidthForColumns() const
 {
+    auto& formattingState = this->formattingState();
+    auto& grid = formattingState.tableGrid();
+
+    // 1. Calculate the minimum content width (MCW) of each cell: the formatted content may span any number of lines but may not overflow the cell box.
+    //    If the specified 'width' (W) of the cell is greater than MCW, W is the minimum cell width. A value of 'auto' means that MCW is the minimum cell width.
+    //    Also, calculate the "maximum" cell width of each cell: formatting the content without breaking lines other than where explicit line breaks occur.
+    for (auto& cell : grid.cells()) {
+        ASSERT(cell->tableCellBox.establishesFormattingContext());
+
+        auto intrinsicWidth = layoutState().createFormattingContext(cell->tableCellBox)->computedIntrinsicWidthConstraints();
+        intrinsicWidth = Geometry::constrainByMinMaxWidth(cell->tableCellBox, intrinsicWidth);
+        formattingState.setIntrinsicWidthConstraints(intrinsicWidth);
+
+        auto columnSpan = cell->size.width();
+        auto slotIntrinsicWidth = FormattingContext::IntrinsicWidthConstraints { intrinsicWidth.minimum / columnSpan, intrinsicWidth.maximum / columnSpan };
+        auto initialPosition = cell->position;
+        for (auto i = 0; i < columnSpan; ++i)
+            grid.slot({ initialPosition.x() + i, initialPosition.y() })->widthConstraints = slotIntrinsicWidth;
+    }
 }
 
 void TableFormattingContext::computeTableWidth() const
index a198352..c7ae3e5 100644 (file)
@@ -51,6 +51,11 @@ TableGrid::TableGrid()
 {
 }
 
+TableGrid::SlotInfo* TableGrid::slot(SlotPosition position)
+{
+    return m_slotMap.get(position);
+}
+
 void TableGrid::appendCell(const Box& tableCellBox)
 {
     int rowSpan = tableCellBox.rowSpan();
@@ -79,7 +84,7 @@ void TableGrid::appendCell(const Box& tableCellBox)
         for (int column = 1; column <= columnSpan; ++column) {
             auto position = SlotPosition { initialSlotPosition.x() + row - 1, initialSlotPosition.y() + column - 1 };
             ASSERT(!m_slotMap.contains(position));
-            m_slotMap.add(position, SlotInfo { *cellInfo });
+            m_slotMap.add(position, std::make_unique<SlotInfo>(*cellInfo));
         }
     }
     m_cellList.add(WTFMove(cellInfo));
index 3a98c6d..bbb2736 100644 (file)
@@ -46,11 +46,8 @@ public:
     void insertCell(const Box&, const Box& before);
     void removeCell(const Box&);
 
-private:
     using SlotPosition = IntPoint;
     using CellSize = IntSize;
-    using SlotLogicalSize = LayoutSize;
-
     struct CellInfo : public CanMakeWeakPtr<CellInfo> {
         CellInfo(const Box& tableCellBox, SlotPosition, CellSize);
 
@@ -58,17 +55,22 @@ private:
         SlotPosition position;
         CellSize size;
     };
+    using CellList = WTF::ListHashSet<std::unique_ptr<CellInfo>>;
+    CellList& cells() { return m_cellList; }
 
+    using SlotLogicalSize = LayoutSize;
     struct SlotInfo {
         SlotInfo() = default;
         SlotInfo(CellInfo&);
 
         WeakPtr<CellInfo> cell;
+        FormattingContext::IntrinsicWidthConstraints widthConstraints;
         SlotLogicalSize size;
     };
+    SlotInfo* slot(SlotPosition);
 
-    using CellList = WTF::ListHashSet<std::unique_ptr<CellInfo>>;
-    using SlotMap = WTF::HashMap<SlotPosition, SlotInfo>;
+private:
+    using SlotMap = WTF::HashMap<SlotPosition, std::unique_ptr<SlotInfo>>;
     SlotMap m_slotMap;
     CellList m_cellList;
 };