Title: [259981] trunk/Source/WebCore
Revision
259981
Author
[email protected]
Date
2020-04-12 09:34:57 -0700 (Sun, 12 Apr 2020)

Log Message

[LFC][TFC] Introduce dedicated SlotPosition/CellSpan structs
https://bugs.webkit.org/show_bug.cgi?id=210399

Reviewed by Antti Koivisto.

SlotPosition.column/row and CellSpan.column/row read better.

* layout/LayoutUnits.h:
(WebCore::Layout::SlotPosition::SlotPosition):
(WebCore::Layout::operator==):
(WTF::SlotPositionHash::hash):
(WTF::SlotPositionHash::equal):
(WTF::HashTraits<WebCore::Layout::SlotPosition>::emptyValue):
(WTF::HashTraits<WebCore::Layout::SlotPosition>::constructDeletedValue):
(WTF::HashTraits<WebCore::Layout::SlotPosition>::isDeletedValue):
* layout/layouttree/LayoutBox.cpp:
(WebCore::Layout::Box::setRowSpan):
(WebCore::Layout::Box::setColumnSpan):
(WebCore::Layout::Box::rowSpan const):
(WebCore::Layout::Box::columnSpan const):
* layout/layouttree/LayoutBox.h:
* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns):
* layout/tableformatting/TableGrid.cpp:
(WebCore::Layout::TableGrid::Cell::Cell):
(WebCore::Layout::TableGrid::appendCell):
* layout/tableformatting/TableGrid.h:
(WebCore::Layout::TableGrid::Cell::startColumn const):
(WebCore::Layout::TableGrid::Cell::endColumn const):
(WebCore::Layout::TableGrid::Cell::startRow const):
(WebCore::Layout::TableGrid::Cell::endRow const):
(WebCore::Layout::TableGrid::Cell::columnSpan const):
(WebCore::Layout::TableGrid::Cell::rowSpan const):
(WebCore::Layout::TableGrid::Cell::span const):
(WebCore::Layout::TableGrid::Cell::size const): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (259980 => 259981)


--- trunk/Source/WebCore/ChangeLog	2020-04-12 16:05:26 UTC (rev 259980)
+++ trunk/Source/WebCore/ChangeLog	2020-04-12 16:34:57 UTC (rev 259981)
@@ -1,5 +1,43 @@
 2020-04-12  Zalan Bujtas  <[email protected]>
 
+        [LFC][TFC] Introduce dedicated SlotPosition/CellSpan structs
+        https://bugs.webkit.org/show_bug.cgi?id=210399
+
+        Reviewed by Antti Koivisto.
+
+        SlotPosition.column/row and CellSpan.column/row read better.
+
+        * layout/LayoutUnits.h:
+        (WebCore::Layout::SlotPosition::SlotPosition):
+        (WebCore::Layout::operator==):
+        (WTF::SlotPositionHash::hash):
+        (WTF::SlotPositionHash::equal):
+        (WTF::HashTraits<WebCore::Layout::SlotPosition>::emptyValue):
+        (WTF::HashTraits<WebCore::Layout::SlotPosition>::constructDeletedValue):
+        (WTF::HashTraits<WebCore::Layout::SlotPosition>::isDeletedValue):
+        * layout/layouttree/LayoutBox.cpp:
+        (WebCore::Layout::Box::setRowSpan):
+        (WebCore::Layout::Box::setColumnSpan):
+        (WebCore::Layout::Box::rowSpan const):
+        (WebCore::Layout::Box::columnSpan const):
+        * layout/layouttree/LayoutBox.h:
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns):
+        * layout/tableformatting/TableGrid.cpp:
+        (WebCore::Layout::TableGrid::Cell::Cell):
+        (WebCore::Layout::TableGrid::appendCell):
+        * layout/tableformatting/TableGrid.h:
+        (WebCore::Layout::TableGrid::Cell::startColumn const):
+        (WebCore::Layout::TableGrid::Cell::endColumn const):
+        (WebCore::Layout::TableGrid::Cell::startRow const):
+        (WebCore::Layout::TableGrid::Cell::endRow const):
+        (WebCore::Layout::TableGrid::Cell::columnSpan const):
+        (WebCore::Layout::TableGrid::Cell::rowSpan const):
+        (WebCore::Layout::TableGrid::Cell::span const):
+        (WebCore::Layout::TableGrid::Cell::size const): Deleted.
+
+2020-04-12  Zalan Bujtas  <[email protected]>
+
         [LFC][TFC] Add table support to BlockFormattingContext::Geometry::inFlowWidthAndMargin
         https://bugs.webkit.org/show_bug.cgi?id=210400
 

Modified: trunk/Source/WebCore/layout/LayoutUnits.h (259980 => 259981)


--- trunk/Source/WebCore/layout/LayoutUnits.h	2020-04-12 16:05:26 UTC (rev 259980)
+++ trunk/Source/WebCore/layout/LayoutUnits.h	2020-04-12 16:34:57 UTC (rev 259981)
@@ -31,6 +31,8 @@
 #include "LayoutPoint.h"
 #include "LayoutRect.h"
 #include "MarginTypes.h"
+#include <wtf/HashFunctions.h>
+#include <wtf/HashTraits.h>
 #include <wtf/Optional.h>
 
 namespace WebCore {
@@ -209,6 +211,48 @@
 #endif
 }
 
+struct SlotPosition {
+    SlotPosition() = default;
+    SlotPosition(size_t column, size_t row);
+
+    size_t column { 0 };
+    size_t row { 0 };
+};
+
+inline SlotPosition::SlotPosition(size_t column, size_t row)
+    : column(column)
+    , row(row)
+{
 }
+
+inline bool operator==(const SlotPosition& a, const SlotPosition& b)
+{
+    return a.column == b.column && a.row == b.row;
 }
+
+struct CellSpan {
+    size_t column { 1 };
+    size_t row { 1 };
+};
+
+}
+}
+
+namespace WTF {
+struct SlotPositionHash {
+    static unsigned hash(const WebCore::Layout::SlotPosition& slotPosition) { return pairIntHash(slotPosition.column, slotPosition.row); }
+    static bool equal(const WebCore::Layout::SlotPosition& a, const WebCore::Layout::SlotPosition& b) { return a == b; }
+    static const bool safeToCompareToEmptyOrDeleted = true;
+};
+template<> struct HashTraits<WebCore::Layout::SlotPosition> : GenericHashTraits<WebCore::Layout::SlotPosition> {
+    static WebCore::Layout::SlotPosition emptyValue() { return WebCore::Layout::SlotPosition(0, WebCore::intMinForLayoutUnit); }
+
+    static void constructDeletedValue(WebCore::Layout::SlotPosition& slot) { slot = WebCore::Layout::SlotPosition(WebCore::intMinForLayoutUnit, 0); }
+    static bool isDeletedValue(const WebCore::Layout::SlotPosition& slot) { return slot == WebCore::Layout::SlotPosition(WebCore::intMinForLayoutUnit, 0); }
+};
+template<> struct DefaultHash<WebCore::Layout::SlotPosition> {
+    typedef SlotPositionHash Hash;
+};
+}
+
 #endif

Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp (259980 => 259981)


--- trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp	2020-04-12 16:05:26 UTC (rev 259980)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp	2020-04-12 16:34:57 UTC (rev 259981)
@@ -387,28 +387,28 @@
         && !isTableColumn();
 }
 
-void Box::setRowSpan(unsigned rowSpan)
+void Box::setRowSpan(size_t rowSpan)
 {
-    ensureRareData().rowSpan = rowSpan;
+    ensureRareData().tableCellSpan.row = rowSpan;
 }
 
-void Box::setColumnSpan(unsigned columnSpan)
+void Box::setColumnSpan(size_t columnSpan)
 {
-    ensureRareData().columnSpan = columnSpan;
+    ensureRareData().tableCellSpan.column = columnSpan;
 }
 
-unsigned Box::rowSpan() const
+size_t Box::rowSpan() const
 {
     if (!hasRareData())
         return 1;
-    return rareData().rowSpan;
+    return rareData().tableCellSpan.row;
 }
 
-unsigned Box::columnSpan() const
+size_t Box::columnSpan() const
 {
     if (!hasRareData())
         return 1;
-    return rareData().columnSpan;
+    return rareData().tableCellSpan.column;
 }
 
 void Box::setColumnWidth(LayoutUnit columnWidth)

Modified: trunk/Source/WebCore/layout/layouttree/LayoutBox.h (259980 => 259981)


--- trunk/Source/WebCore/layout/layouttree/LayoutBox.h	2020-04-12 16:05:26 UTC (rev 259980)
+++ trunk/Source/WebCore/layout/layouttree/LayoutBox.h	2020-04-12 16:34:57 UTC (rev 259981)
@@ -27,6 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "LayoutUnits.h"
 #include "RenderStyle.h"
 #include <wtf/IsoMalloc.h>
 #include <wtf/WeakPtr.h>
@@ -150,11 +151,11 @@
     const RenderStyle& style() const { return m_style; }
 
     // FIXME: Find a better place for random DOM things.
-    void setRowSpan(unsigned);
-    unsigned rowSpan() const;
+    void setRowSpan(size_t);
+    size_t rowSpan() const;
 
-    void setColumnSpan(unsigned);
-    unsigned columnSpan() const;
+    void setColumnSpan(size_t);
+    size_t columnSpan() const;
 
     void setColumnWidth(LayoutUnit);
     Optional<LayoutUnit> columnWidth() const;
@@ -178,8 +179,7 @@
     public:
         BoxRareData() = default;
 
-        unsigned rowSpan { 1 };
-        unsigned columnSpan { 1 };
+        CellSpan tableCellSpan;
         Optional<LayoutUnit> columnWidth;
     };
 

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (259980 => 259981)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-12 16:05:26 UTC (rev 259980)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-12 16:34:57 UTC (rev 259981)
@@ -259,21 +259,21 @@
             formattingState.setIntrinsicWidthConstraintsForBox(cellBox, *intrinsicWidth);
         }
 
-        auto columnSpan = cell->size().width();
+        auto columnSpan = cell->span().column;
         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;
+        for (size_t i = 0; i < columnSpan; ++i)
+            grid.slot({ initialPosition.column + i, initialPosition.row })->widthConstraints = slotIntrinsicWidth;
     }
     // 2. For each column, determine a maximum and minimum column width from the cells that span only that column.
     //    The minimum is that required by the cell with the largest minimum cell width (or the column 'width', whichever is larger).
     //    The maximum is that required by the cell with the largest maximum cell width (or the column 'width', whichever is larger).
     auto& columnList = grid.columns().list();
-    int numberOfRows = grid.rows().size();
-    int numberOfColumns = columnList.size();
-    for (int columnIndex = 0; columnIndex < numberOfColumns; ++columnIndex) {
+    auto numberOfRows = grid.rows().size();
+    auto numberOfColumns = columnList.size();
+    for (size_t columnIndex = 0; columnIndex < numberOfColumns; ++columnIndex) {
         auto columnIntrinsicWidths = FormattingContext::IntrinsicWidthConstraints { };
-        for (int rowIndex = 0; rowIndex < numberOfRows; ++rowIndex) {
+        for (size_t rowIndex = 0; rowIndex < numberOfRows; ++rowIndex) {
             auto* slot = grid.slot({ columnIndex, rowIndex });
             columnIntrinsicWidths.minimum = std::max(slot->widthConstraints.minimum, columnIntrinsicWidths.minimum);
             columnIntrinsicWidths.maximum = std::max(slot->widthConstraints.maximum, columnIntrinsicWidths.maximum);

Modified: trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp (259980 => 259981)


--- trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp	2020-04-12 16:05:26 UTC (rev 259980)
+++ trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp	2020-04-12 16:34:57 UTC (rev 259981)
@@ -108,10 +108,10 @@
 {
 }
 
-TableGrid::Cell::Cell(const Box& cellBox, SlotPosition position, CellSize size)
+TableGrid::Cell::Cell(const Box& cellBox, SlotPosition position, CellSpan span)
     : m_layoutBox(makeWeakPtr(cellBox))
     , m_position(position)
-    , m_size(size)
+    , m_span(span)
 {
 }
 
@@ -131,8 +131,8 @@
 
 void TableGrid::appendCell(const Box& cellBox)
 {
-    int rowSpan = cellBox.rowSpan();
-    int columnSpan = cellBox.columnSpan();
+    auto rowSpan = cellBox.rowSpan();
+    auto columnSpan = cellBox.columnSpan();
     auto isInNewRow = !cellBox.previousSibling();
     auto initialSlotPosition = SlotPosition { };
 
@@ -141,28 +141,28 @@
         auto lastSlotPosition = lastCell->position();
         // First table cell in this row?
         if (isInNewRow)
-            initialSlotPosition = SlotPosition { 0, lastSlotPosition.y() + 1 };
+            initialSlotPosition = SlotPosition { 0, lastSlotPosition.row + 1 };
         else
-            initialSlotPosition = SlotPosition { lastSlotPosition.x() + 1, lastSlotPosition.y() };
+            initialSlotPosition = SlotPosition { lastSlotPosition.column + 1, lastSlotPosition.row };
 
         // Pick the next available slot by avoiding row and column spanners.
         while (true) {
             if (!m_slotMap.contains(initialSlotPosition))
                 break;
-            initialSlotPosition.move(1, 0);
+            ++initialSlotPosition.column;
         }
     }
-    auto cell = makeUnique<Cell>(cellBox, initialSlotPosition, CellSize { columnSpan, rowSpan });
+    auto cell = makeUnique<Cell>(cellBox, initialSlotPosition, CellSpan { columnSpan, rowSpan });
     // Row and column spanners create additional slots.
-    for (int row = 1; row <= rowSpan; ++row) {
-        for (int column = 1; column <= columnSpan; ++column) {
-            auto position = SlotPosition { initialSlotPosition.x() + column - 1, initialSlotPosition.y() + row - 1 };
+    for (size_t row = 1; row <= rowSpan; ++row) {
+        for (size_t column = 1; column <= columnSpan; ++column) {
+            auto position = SlotPosition { initialSlotPosition.column + column - 1, initialSlotPosition.row + row - 1 };
             ASSERT(!m_slotMap.contains(position));
             m_slotMap.add(position, makeUnique<Slot>(*cell));
         }
     }
     // Initialize columns/rows if needed.
-    auto missingNumberOfColumns = std::max<int>(0, initialSlotPosition.x() + columnSpan - m_columns.size()); 
+    auto missingNumberOfColumns = std::max<int>(0, initialSlotPosition.column + columnSpan - m_columns.size());
     for (auto column = 0; column < missingNumberOfColumns; ++column)
         m_columns.addAnonymousColumn();
 

Modified: trunk/Source/WebCore/layout/tableformatting/TableGrid.h (259980 => 259981)


--- trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-04-12 16:05:26 UTC (rev 259980)
+++ trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-04-12 16:34:57 UTC (rev 259981)
@@ -28,7 +28,7 @@
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
 #include "FormattingContext.h"
-#include "IntPointHash.h"
+#include "LayoutUnits.h"
 #include <wtf/HashMap.h>
 #include <wtf/IsoMalloc.h>
 #include <wtf/IsoMallocInlines.h>
@@ -138,25 +138,23 @@
         RowList m_rowList;
     };
 
-    using SlotPosition = IntPoint;
-    using CellSize = IntSize;
     // Cell represents a <td> or <th>. It can span multiple slots in the grid.
     class Cell : public CanMakeWeakPtr<Cell> {
         WTF_MAKE_ISO_ALLOCATED_INLINE(Cell);
     public:
-        Cell(const Box&, SlotPosition, CellSize);
+        Cell(const Box&, SlotPosition, CellSpan);
 
-        size_t startColumn() const { return m_position.x(); }
-        size_t endColumn() const { return m_position.x() + m_size.width(); }
+        size_t startColumn() const { return m_position.column; }
+        size_t endColumn() const { return m_position.column + m_span.column; }
 
-        size_t startRow() const { return m_position.y(); }
-        size_t endRow() const { return m_position.y() + m_size.height(); }
+        size_t startRow() const { return m_position.row; }
+        size_t endRow() const { return m_position.row + m_span.row; }
 
-        size_t columnSpan() const { return m_size.width(); }
-        size_t rowSpan() const { return m_size.height(); }
+        size_t columnSpan() const { return m_span.column; }
+        size_t rowSpan() const { return m_span.row; }
 
         SlotPosition position() const { return m_position; }
-        CellSize size() const { return m_size; }
+        CellSpan span() const { return m_span; }
 
         const Box& box() const { return *m_layoutBox.get(); }
 
@@ -163,7 +161,7 @@
     private:
         WeakPtr<const Box> m_layoutBox;
         SlotPosition m_position;
-        CellSize m_size;
+        CellSpan m_span;
     };
 
     struct Slot {
@@ -201,4 +199,5 @@
 
 }
 }
+
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to