Title: [260647] trunk
Revision
260647
Author
[email protected]
Date
2020-04-24 09:22:45 -0700 (Fri, 24 Apr 2020)

Log Message

[LFC][TFC] Take first in-flow table-row baseline into account when computing cell baseline
https://bugs.webkit.org/show_bug.cgi?id=210972

Reviewed by Antti Koivisto.

Source/WebCore:

Check if the cell has a nested table and use its first row as the baseline for the cell (unless there's an IFC before).

Test: fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table.html

* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::layoutCell):
(WebCore::Layout::TableFormattingContext::computeAndDistributeExtraVerticalSpace):
* layout/tableformatting/TableFormattingContext.h:
* layout/tableformatting/TableFormattingContextGeometry.cpp:
(WebCore::Layout::TableFormattingContext::Geometry::usedBaselineForCell):
* layout/tableformatting/TableGrid.h:
(WebCore::Layout::TableGrid::Row::setBaselineOffset):
(WebCore::Layout::TableGrid::Row::baselineOffset const):

LayoutTests:

* fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table-expected.txt: Added.
* fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (260646 => 260647)


--- trunk/LayoutTests/ChangeLog	2020-04-24 16:20:35 UTC (rev 260646)
+++ trunk/LayoutTests/ChangeLog	2020-04-24 16:22:45 UTC (rev 260647)
@@ -1,3 +1,13 @@
+2020-04-24  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC] Take first in-flow table-row baseline into account when computing cell baseline
+        https://bugs.webkit.org/show_bug.cgi?id=210972
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table-expected.txt: Added.
+        * fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table.html: Added.
+
 2020-04-24  Diego Pino Garcia  <[email protected]>
 
         [GTK][WPE] Gardening, mark fast/css/resize-corner-tracking.html as flaky

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table-expected.txt (0 => 260647)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table-expected.txt	2020-04-24 16:22:45 UTC (rev 260647)
@@ -0,0 +1,25 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x79
+  RenderBlock {HTML} at (0,0) size 800x79
+    RenderBody {BODY} at (8,8) size 784x63
+      RenderTable {TABLE} at (0,0) size 29x63
+        RenderTableSection {TBODY} at (0,0) size 29x63
+          RenderTableRow {TR} at (0,2) size 29x34
+            RenderTableCell {TD} at (2,2) size 15x34 [r=0 c=0 rs=1 cs=1]
+              RenderTable {TABLE} at (1,1) size 11x19
+                RenderTableSection {TBODY} at (0,0) size 11x19
+                  RenderTableRow {TR} at (0,2) size 11x15
+                    RenderTableCell {TD} at (2,2) size 7x15 [r=0 c=0 rs=1 cs=1]
+                      RenderText {#text} at (1,1) size 5x13
+                        text run at (1,1) width 5: "#"
+              RenderBlock (anonymous) at (1,20) size 13x13
+                RenderText {#text} at (0,0) size 5x13
+                  text run at (0,0) width 5: "#"
+            RenderTableCell {TD} at (18,11) size 10x16 [r=0 c=1 rs=1 cs=1]
+              RenderText {#text} at (1,1) size 5x14
+                text run at (1,2) width 5: "#"
+          RenderTableRow {TR} at (0,38) size 29x23
+            RenderTableCell {TD} at (2,38) size 26x23 [r=1 c=0 rs=1 cs=2]
+              RenderText {#text} at (5,5) size 15x13
+                text run at (5,5) width 15: "###"

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table.html (0 => 260647)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table.html	2020-04-24 16:22:45 UTC (rev 260647)
@@ -0,0 +1,10 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+table {
+    font-size: 10px;
+}
+</style>
+<table>
+<tr><td><table><tr><td>#</td></tr></table>#</td><td>#</td></tr>
+<tr><td colspan=2 style="padding: 5px">###</td></tr>
+</table>

Modified: trunk/Source/WebCore/ChangeLog (260646 => 260647)


--- trunk/Source/WebCore/ChangeLog	2020-04-24 16:20:35 UTC (rev 260646)
+++ trunk/Source/WebCore/ChangeLog	2020-04-24 16:22:45 UTC (rev 260647)
@@ -1,3 +1,24 @@
+2020-04-24  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC] Take first in-flow table-row baseline into account when computing cell baseline
+        https://bugs.webkit.org/show_bug.cgi?id=210972
+
+        Reviewed by Antti Koivisto.
+
+        Check if the cell has a nested table and use its first row as the baseline for the cell (unless there's an IFC before).
+
+        Test: fast/layoutformattingcontext/table-basic-row-baseline-with-nested-table.html
+
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::layoutCell):
+        (WebCore::Layout::TableFormattingContext::computeAndDistributeExtraVerticalSpace):
+        * layout/tableformatting/TableFormattingContext.h:
+        * layout/tableformatting/TableFormattingContextGeometry.cpp:
+        (WebCore::Layout::TableFormattingContext::Geometry::usedBaselineForCell):
+        * layout/tableformatting/TableGrid.h:
+        (WebCore::Layout::TableGrid::Row::setBaselineOffset):
+        (WebCore::Layout::TableGrid::Row::baselineOffset const):
+
 2020-04-24  Antti Koivisto  <[email protected]>
 
         Nullptr crash in objc_msgSend under WebCore::genericFamily

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (260646 => 260647)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-24 16:20:35 UTC (rev 260646)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-24 16:22:45 UTC (rev 260647)
@@ -133,6 +133,7 @@
         // use some kind of intrinsic padding similar to RenderTableCell.
         auto verticalBorder = cellDisplayBox.verticalBorder();
         auto intrinsicVerticalPadding = std::max(0_lu, *usedCellHeight - verticalBorder - contentHeight);
+        // FIXME: Take vertical-align into account here.
         cellDisplayBox.setVerticalPadding({ intrinsicVerticalPadding / 2, intrinsicVerticalPadding / 2 });
     }
     cellDisplayBox.setContentBoxHeight(contentHeight);
@@ -451,11 +452,12 @@
     auto& columns = grid.columns().list();
     auto& rows = grid.rows();
 
-    Vector<float> rownHeights;
+    Vector<LayoutUnit> rowsHeight;
+    Vector<InlineLayoutUnit> rowsBaselineOffset;
     // 1. Collect initial row heights.
     for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
-        float maximumColumnAscent = 0;
-        float maximumColumnDescent = 0;
+        auto maximumColumnAscent = InlineLayoutUnit { };
+        auto maximumColumnDescent = InlineLayoutUnit { };
         for (size_t columnIndex = 0; columnIndex < columns.size(); ++columnIndex) {
             auto& slot = *grid.slot({ columnIndex, rowIndex });
             if (slot.isColumnSpanned())
@@ -465,27 +467,21 @@
             // The minimum height of a row (without spanning-related height distribution) is defined as the height of an hypothetical
             // linebox containing the cells originating in the row.
             auto& cellBox = slot.cell().box();
-            auto& cellDisplayBox = geometryForBox(cellBox);
-            auto cellBaselineOffset = InlineLayoutUnit { };
-            if (cellBox.establishesInlineFormattingContext()) {
-                // The baseline of a cell is defined as the baseline of the first in-flow line box in the cell,
-                // or the first in-flow table-row in the cell, whichever comes first
-                auto& firstLineBox = layoutState().establishedInlineFormattingState(cellBox).displayInlineContent()->lineBoxes[0];
-                cellBaselineOffset = firstLineBox.baselineOffset();
-            } else {
-                // If there is no such line box, the baseline is the bottom of content edge of the cell box.
-                cellBaselineOffset = cellDisplayBox.contentBoxBottom();
-            }
-            maximumColumnAscent = std::max<float>(maximumColumnAscent, cellBaselineOffset);
-            maximumColumnDescent = std::max<float>(maximumColumnDescent, cellDisplayBox.height() - cellBaselineOffset);
+            auto cellBaselineOffset = geometry().usedBaselineForCell(cellBox);
+            maximumColumnAscent = std::max(maximumColumnAscent, cellBaselineOffset);
+            maximumColumnDescent = std::max(maximumColumnDescent, geometryForBox(cellBox).height() - cellBaselineOffset);
         }
         // <tr style="height: 10px"> is considered as min height.
         auto computedRowHeight = geometry().computedContentHeight(rows.list()[rowIndex].box(), { }).valueOr(LayoutUnit { });
-        rownHeights.append(std::max(computedRowHeight.toFloat(), maximumColumnAscent + maximumColumnDescent));
+        rowsHeight.append(std::max(computedRowHeight, LayoutUnit { maximumColumnAscent + maximumColumnDescent }));
+        rowsBaselineOffset.append(maximumColumnAscent);
     }
 
-    for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex)
-        grid.rows().list()[rowIndex].setLogicalHeight(LayoutUnit { rownHeights[rowIndex] });
+    for (size_t rowIndex = 0; rowIndex < rows.size(); ++rowIndex) {
+        auto& row = grid.rows().list()[rowIndex];
+        row.setLogicalHeight(rowsHeight[rowIndex]);
+        row.setBaselineOffset(rowsBaselineOffset[rowIndex]);
+    }
 }
 
 void TableFormattingContext::setComputedGeometryForRows()

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h (260646 => 260647)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h	2020-04-24 16:20:35 UTC (rev 260646)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h	2020-04-24 16:22:45 UTC (rev 260647)
@@ -50,6 +50,7 @@
         ContentHeightAndMargin tableCellHeightAndMargin(const Box&) const;
         Optional<LayoutUnit> computedColumnWidth(const Box& columnBox) const;
         FormattingContext::IntrinsicWidthConstraints intrinsicWidthConstraintsForCell(const ContainerBox& cellBox);
+        InlineLayoutUnit usedBaselineForCell(const ContainerBox& cellBox);
 
     private:
         friend class TableFormattingContext;

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp (260646 => 260647)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp	2020-04-24 16:20:35 UTC (rev 260646)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp	2020-04-24 16:22:45 UTC (rev 260647)
@@ -30,6 +30,7 @@
 
 #include "LayoutBox.h"
 #include "LayoutContext.h"
+#include "LayoutDescendantIterator.h"
 #include "TableFormattingState.h"
 
 namespace WebCore {
@@ -84,7 +85,22 @@
     return intrinsicWidthConstraints;
 }
 
+
+InlineLayoutUnit TableFormattingContext::Geometry::usedBaselineForCell(const ContainerBox& cellBox)
+{
+    // The baseline of a cell is defined as the baseline of the first in-flow line box in the cell,
+    // or the first in-flow table-row in the cell, whichever comes first.
+    // If there is no such line box, the baseline is the bottom of content edge of the cell box.
+    for (auto& cellDescendant : descendantsOfType<ContainerBox>(cellBox)) {
+        if (cellDescendant.establishesInlineFormattingContext())
+            return layoutState().establishedInlineFormattingState(cellDescendant).displayInlineContent()->lineBoxes[0].baselineOffset();
+        if (cellDescendant.establishesTableFormattingContext())
+            return layoutState().establishedTableFormattingState(cellDescendant).tableGrid().rows().list()[0].baselineOffset();
+    }
+    return formattingContext().geometryForBox(cellBox).contentBoxBottom();
 }
+
 }
+}
 
 #endif

Modified: trunk/Source/WebCore/layout/tableformatting/TableGrid.h (260646 => 260647)


--- trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-04-24 16:20:35 UTC (rev 260646)
+++ trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-04-24 16:22:45 UTC (rev 260647)
@@ -116,11 +116,15 @@
         void setLogicalHeight(LayoutUnit logicalHeight) { m_logicalHeight = logicalHeight; }
         LayoutUnit logicalHeight() const { return m_logicalHeight; }
 
+        void setBaselineOffset(InlineLayoutUnit baselineOffset) { m_baselineOffset = baselineOffset; }
+        InlineLayoutUnit baselineOffset() const { return m_baselineOffset; }
+
         const ContainerBox& box() const { return *m_layoutBox.get(); }
 
     private:
         LayoutUnit m_logicalTop;
         LayoutUnit m_logicalHeight;
+        InlineLayoutUnit m_baselineOffset;
         WeakPtr<const ContainerBox> m_layoutBox;
     };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to