Title: [260708] trunk
Revision
260708
Author
[email protected]
Date
2020-04-25 12:13:18 -0700 (Sat, 25 Apr 2020)

Log Message

[LFC][TFC] Add vertical-align: baseline support
https://bugs.webkit.org/show_bug.cgi?id=211024

Reviewed by Antti Koivisto.

Source/WebCore:

Adjust the padding with the baseline offset when the cell is baseline aligned (as opposed to the initial value of 'middle').

Test: fast/layoutformattingcontext/table-basic-row-vertical-align-baseline.html

* layout/tableformatting/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::setUsedGeometryForCells):
(WebCore::Layout::TableFormattingContext::computeAndDistributeExtraVerticalSpace):
* layout/tableformatting/TableGrid.h:
(WebCore::Layout::TableGrid::Cell::setBaselineOffset):
(WebCore::Layout::TableGrid::Cell::baselineOffset const):

LayoutTests:

* fast/layoutformattingcontext/table-basic-row-vertical-align-baseline-expected.txt: Added.
* fast/layoutformattingcontext/table-basic-row-vertical-align-baseline.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (260707 => 260708)


--- trunk/LayoutTests/ChangeLog	2020-04-25 18:01:55 UTC (rev 260707)
+++ trunk/LayoutTests/ChangeLog	2020-04-25 19:13:18 UTC (rev 260708)
@@ -1,3 +1,13 @@
+2020-04-25  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC] Add vertical-align: baseline support
+        https://bugs.webkit.org/show_bug.cgi?id=211024
+
+        Reviewed by Antti Koivisto.
+
+        * fast/layoutformattingcontext/table-basic-row-vertical-align-baseline-expected.txt: Added.
+        * fast/layoutformattingcontext/table-basic-row-vertical-align-baseline.html: Added.
+
 2020-04-25  Antoine Quint  <[email protected]>
 
         [Web Animations] KeyframeEffect should ensure its target remains alive

Added: trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-vertical-align-baseline-expected.txt (0 => 260708)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-vertical-align-baseline-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-vertical-align-baseline-expected.txt	2020-04-25 19:13:18 UTC (rev 260708)
@@ -0,0 +1,19 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x100
+  RenderBlock {HTML} at (0,0) size 800x100
+    RenderBody {BODY} at (8,8) size 784x84
+      RenderTable {TABLE} at (0,0) size 60x84
+        RenderTableSection {TBODY} at (0,0) size 60x84
+          RenderTableRow {TR} at (0,2) size 60x55
+            RenderTableCell {TD} at (2,2) size 47x55 [r=0 c=0 rs=1 cs=1]
+              RenderText {#text} at (1,41) size 5x13
+                text run at (1,41) width 5: "#"
+              RenderImage {IMG} at (6,1) size 40x50
+            RenderTableCell {TD} at (51,42) size 7x15 [r=0 c=1 rs=1 cs=1]
+              RenderText {#text} at (1,1) size 5x13
+                text run at (1,1) width 5: "#"
+          RenderTableRow {TR} at (0,59) size 60x23
+            RenderTableCell {TD} at (2,59) size 56x23 [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-vertical-align-baseline.html (0 => 260708)


--- trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-vertical-align-baseline.html	                        (rev 0)
+++ trunk/LayoutTests/fast/layoutformattingcontext/table-basic-row-vertical-align-baseline.html	2020-04-25 19:13:18 UTC (rev 260708)
@@ -0,0 +1,13 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:LayoutFormattingContextEnabled=true internal:LayoutFormattingContextIntegrationEnabled=false ] -->
+<style>
+table {
+    font-size: 10px;
+}
+td {
+    vertical-align: baseline;
+}
+</style>
+<table>
+<tr><td>#<img height=50px width=40px src=""
+<tr><td colspan=2 style="padding: 5px">###</td></tr>
+</table>

Modified: trunk/Source/WebCore/ChangeLog (260707 => 260708)


--- trunk/Source/WebCore/ChangeLog	2020-04-25 18:01:55 UTC (rev 260707)
+++ trunk/Source/WebCore/ChangeLog	2020-04-25 19:13:18 UTC (rev 260708)
@@ -1,3 +1,21 @@
+2020-04-25  Zalan Bujtas  <[email protected]>
+
+        [LFC][TFC] Add vertical-align: baseline support
+        https://bugs.webkit.org/show_bug.cgi?id=211024
+
+        Reviewed by Antti Koivisto.
+
+        Adjust the padding with the baseline offset when the cell is baseline aligned (as opposed to the initial value of 'middle').
+
+        Test: fast/layoutformattingcontext/table-basic-row-vertical-align-baseline.html
+
+        * layout/tableformatting/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::setUsedGeometryForCells):
+        (WebCore::Layout::TableFormattingContext::computeAndDistributeExtraVerticalSpace):
+        * layout/tableformatting/TableGrid.h:
+        (WebCore::Layout::TableGrid::Cell::setBaselineOffset):
+        (WebCore::Layout::TableGrid::Cell::baselineOffset const):
+
 2020-04-25  Darin Adler  <[email protected]>
 
         Move URL to use StringView when returning substrings of the URL

Modified: trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp (260707 => 260708)


--- trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-25 18:01:55 UTC (rev 260707)
+++ trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp	2020-04-25 19:13:18 UTC (rev 260708)
@@ -68,18 +68,39 @@
     auto& rowList = grid.rows().list();
     // Final table cell layout. At this point all percentage values can be resolved.
     for (auto& cell : grid.cells()) {
-        auto& cellDisplayBox = formattingState().displayBox(cell->box());
+        auto& cellBox = cell->box();
+        auto& cellDisplayBox = formattingState().displayBox(cellBox);
         cellDisplayBox.setTop(rowList[cell->startRow()].logicalTop());
         cellDisplayBox.setLeft(columnList[cell->startColumn()].logicalLeft());
         auto rowHeight = rowList[cell->startRow()].logicalHeight();
         layoutCell(*cell, availableHorizontalSpace, rowHeight);
+        
         // FIXME: Find out if it is ok to use the regular padding here to align the content box inside a tall cell or we need to 
         // use some kind of intrinsic padding similar to RenderTableCell.
-        auto verticalBorder = cellDisplayBox.verticalBorder();
-        auto contentHeight = cellDisplayBox.contentBoxHeight();
-        auto intrinsicVerticalPadding = std::max(0_lu, rowHeight - verticalBorder - contentHeight);
-        // FIXME: Take vertical-align into account here.
-        cellDisplayBox.setVerticalPadding({ intrinsicVerticalPadding / 2, intrinsicVerticalPadding / 2 });
+        auto paddingTop = cellDisplayBox.paddingTop().valueOr(LayoutUnit { });
+        auto paddingBottom = cellDisplayBox.paddingBottom().valueOr(LayoutUnit { });
+        auto intrinsicPaddingTop = LayoutUnit { };
+        auto intrinsicPaddingBottom = LayoutUnit { };
+
+        switch (cellBox.style().verticalAlign()) {
+        case VerticalAlign::Middle: {
+            auto intrinsicVerticalPadding = std::max(0_lu, rowHeight - cellDisplayBox.verticalMarginBorderAndPadding() - cellDisplayBox.contentBoxHeight()); 
+            intrinsicPaddingTop = intrinsicVerticalPadding / 2;
+            intrinsicPaddingBottom = intrinsicVerticalPadding / 2;
+            break;
+        }
+        case VerticalAlign::Baseline: {
+            auto rowBaselineOffset = LayoutUnit { rowList[cell->startRow()].baselineOffset() };
+            auto cellBaselineOffset = LayoutUnit { cell->baselineOffset() };
+            intrinsicPaddingTop = std::max(0_lu, rowBaselineOffset - cellBaselineOffset - cellDisplayBox.borderTop());
+            intrinsicPaddingBottom = std::max(0_lu, rowHeight - cellDisplayBox.verticalMarginBorderAndPadding() - intrinsicPaddingTop - cellDisplayBox.contentBoxHeight());
+            break;
+        }
+        default:
+            ASSERT_NOT_IMPLEMENTED_YET();
+            break;
+        }
+        cellDisplayBox.setVerticalPadding({ paddingTop + intrinsicPaddingTop, paddingBottom + intrinsicPaddingBottom });
     }
 }
 
@@ -490,10 +511,11 @@
             layoutCell(slot.cell(), availableHorizontalSpace);
             // 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 cellBaselineOffset = geometry().usedBaselineForCell(cellBox);
-            maximumColumnAscent = std::max(maximumColumnAscent, cellBaselineOffset);
-            maximumColumnDescent = std::max(maximumColumnDescent, geometryForBox(cellBox).height() - cellBaselineOffset);
+            auto& cell = slot.cell();
+            auto& cellBox = cell.box();
+            cell.setBaselineOffset(geometry().usedBaselineForCell(cellBox));
+            maximumColumnAscent = std::max(maximumColumnAscent, cell.baselineOffset());
+            maximumColumnDescent = std::max(maximumColumnDescent, geometryForBox(cellBox).height() - cell.baselineOffset());
         }
         // <tr style="height: 10px"> is considered as min height.
         auto computedRowHeight = geometry().computedContentHeight(rows.list()[rowIndex].box(), { }).valueOr(LayoutUnit { });

Modified: trunk/Source/WebCore/layout/tableformatting/TableGrid.h (260707 => 260708)


--- trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-04-25 18:01:55 UTC (rev 260707)
+++ trunk/Source/WebCore/layout/tableformatting/TableGrid.h	2020-04-25 19:13:18 UTC (rev 260708)
@@ -160,6 +160,9 @@
         SlotPosition position() const { return m_position; }
         CellSpan span() const { return m_span; }
 
+        void setBaselineOffset(InlineLayoutUnit baselineOffset) { m_baselineOffset = baselineOffset; }
+        InlineLayoutUnit baselineOffset() const { return m_baselineOffset; }
+
         bool isFixedWidth() const;
 
         const ContainerBox& box() const { return *m_layoutBox.get(); }
@@ -168,6 +171,7 @@
         WeakPtr<const ContainerBox> m_layoutBox;
         SlotPosition m_position;
         CellSpan m_span;
+        InlineLayoutUnit m_baselineOffset;
     };
 
     class Slot {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to