Title: [277554] trunk/Source/WebCore
Revision
277554
Author
[email protected]
Date
2021-05-15 18:21:21 -0700 (Sat, 15 May 2021)

Log Message

[LFC] Move table formatting geometry to its own class
https://bugs.webkit.org/show_bug.cgi?id=225753

Reviewed by Antti Koivisto.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* layout/formattingContexts/table/TableFormattingContext.cpp:
(WebCore::Layout::TableFormattingContext::geometry const):
* layout/formattingContexts/table/TableFormattingContext.h:
(WebCore::Layout::TableFormattingContext::Geometry::Geometry): Deleted.
* layout/formattingContexts/table/TableFormattingContextGeometry.cpp: Removed.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277553 => 277554)


--- trunk/Source/WebCore/ChangeLog	2021-05-16 01:05:18 UTC (rev 277553)
+++ trunk/Source/WebCore/ChangeLog	2021-05-16 01:21:21 UTC (rev 277554)
@@ -1,3 +1,18 @@
+2021-05-15  Alan Bujtas  <[email protected]>
+
+        [LFC] Move table formatting geometry to its own class
+        https://bugs.webkit.org/show_bug.cgi?id=225753
+
+        Reviewed by Antti Koivisto.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * layout/formattingContexts/table/TableFormattingContext.cpp:
+        (WebCore::Layout::TableFormattingContext::geometry const):
+        * layout/formattingContexts/table/TableFormattingContext.h:
+        (WebCore::Layout::TableFormattingContext::Geometry::Geometry): Deleted.
+        * layout/formattingContexts/table/TableFormattingContextGeometry.cpp: Removed.
+
 2021-05-15  Chris Dumez  <[email protected]>
 
         Clean up BaseAudioContext now that legacy/prefixed WebAudio is gone

Modified: trunk/Source/WebCore/Sources.txt (277553 => 277554)


--- trunk/Source/WebCore/Sources.txt	2021-05-16 01:05:18 UTC (rev 277553)
+++ trunk/Source/WebCore/Sources.txt	2021-05-16 01:21:21 UTC (rev 277554)
@@ -1562,7 +1562,7 @@
 layout/layouttree/LayoutReplacedBox.cpp
 layout/layouttree/LayoutTreeBuilder.cpp
 layout/formattingContexts/table/TableFormattingContext.cpp
-layout/formattingContexts/table/TableFormattingContextGeometry.cpp
+layout/formattingContexts/table/TableFormattingGeometry.cpp
 layout/formattingContexts/table/TableFormattingQuirks.cpp
 layout/formattingContexts/table/TableFormattingState.cpp
 layout/formattingContexts/table/TableGrid.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (277553 => 277554)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-16 01:05:18 UTC (rev 277553)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-05-16 01:21:21 UTC (rev 277554)
@@ -1336,6 +1336,7 @@
 		4786356526507A3800C5E2E0 /* BlockFormattingGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = 4786356426507A3700C5E2E0 /* BlockFormattingGeometry.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		47C4D57D26508BCB00C7AB1F /* InlineFormattingGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = 47C4D57C26508BCA00C7AB1F /* InlineFormattingGeometry.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		47F947DB26502F2F0087968C /* BlockFormattingQuirks.h in Headers */ = {isa = PBXBuildFile; fileRef = 47F947DA26502F2F0087968C /* BlockFormattingQuirks.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		47FA97002650982B00841416 /* TableFormattingGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = 47FA96FF2650982A00841416 /* TableFormattingGeometry.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		49291E4B134172C800E753DE /* ImageRenderingMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 49291E4A134172C800E753DE /* ImageRenderingMode.h */; };
 		493E5E0912D6420500020081 /* PlatformCALayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 493E5E0812D6420500020081 /* PlatformCALayerClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4945BFD413CF809000CC3B38 /* TransformState.h in Headers */ = {isa = PBXBuildFile; fileRef = 4945BFD213CF809000CC3B38 /* TransformState.h */; };
@@ -6422,7 +6423,7 @@
 		11C5F134200527F90001AE60 /* RenderTreeBuilderMathML.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderMathML.h; sourceTree = "<group>"; };
 		11CB2786203BA570004A1DC9 /* RenderTreeBuilderFullScreen.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderFullScreen.cpp; sourceTree = "<group>"; };
 		11CB2787203BA570004A1DC9 /* RenderTreeBuilderFullScreen.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderFullScreen.h; sourceTree = "<group>"; };
-		11D19C2E23159BAE008F24D3 /* TableFormattingContextGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableFormattingContextGeometry.cpp; sourceTree = "<group>"; };
+		11D19C2E23159BAE008F24D3 /* TableFormattingGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableFormattingGeometry.cpp; sourceTree = "<group>"; };
 		11E51635261E1A0500E69F25 /* WebXRInputSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebXRInputSpace.h; sourceTree = "<group>"; };
 		11E51637261E1A0500E69F25 /* WebXRInputSpace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebXRInputSpace.cpp; sourceTree = "<group>"; };
 		11E5163A261E1A1400E69F25 /* WebXRGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebXRGamepad.h; sourceTree = "<group>"; };
@@ -8392,6 +8393,7 @@
 		4786356426507A3700C5E2E0 /* BlockFormattingGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockFormattingGeometry.h; sourceTree = "<group>"; };
 		47C4D57C26508BCA00C7AB1F /* InlineFormattingGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineFormattingGeometry.h; sourceTree = "<group>"; };
 		47F947DA26502F2F0087968C /* BlockFormattingQuirks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockFormattingQuirks.h; sourceTree = "<group>"; };
+		47FA96FF2650982A00841416 /* TableFormattingGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableFormattingGeometry.h; sourceTree = "<group>"; };
 		49291E4A134172C800E753DE /* ImageRenderingMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageRenderingMode.h; sourceTree = "<group>"; };
 		493E5E0812D6420500020081 /* PlatformCALayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCALayerClient.h; sourceTree = "<group>"; };
 		4945BFD113CF809000CC3B38 /* TransformState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TransformState.cpp; sourceTree = "<group>"; };
@@ -22679,7 +22681,8 @@
 			children = (
 				6FC5CA9422E3599400B13E11 /* TableFormattingContext.cpp */,
 				6FC5CA9522E3599400B13E11 /* TableFormattingContext.h */,
-				11D19C2E23159BAE008F24D3 /* TableFormattingContextGeometry.cpp */,
+				11D19C2E23159BAE008F24D3 /* TableFormattingGeometry.cpp */,
+				47FA96FF2650982A00841416 /* TableFormattingGeometry.h */,
 				6FC53AEB24AF7A8E006059FE /* TableFormattingQuirks.cpp */,
 				6F49C3E626479B3B0051953D /* TableFormattingQuirks.h */,
 				6FC5CA9222E3599300B13E11 /* TableFormattingState.cpp */,
@@ -35465,6 +35468,7 @@
 				E3C04138254CB30D0021D0E6 /* SystemSoundDelegate.h in Headers */,
 				E3C0412F254CA29B0021D0E6 /* SystemSoundManager.h in Headers */,
 				5D5975B319635F1100D00878 /* SystemVersion.h in Headers */,
+				47FA97002650982B00841416 /* TableFormattingGeometry.h in Headers */,
 				6F49C3E726479B3C0051953D /* TableFormattingQuirks.h in Headers */,
 				A8CFF0510A154F09000A4234 /* TableLayout.h in Headers */,
 				6F17264F2470C60B00518C96 /* TableWrapperBlockFormattingContext.h in Headers */,

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


--- trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp	2021-05-16 01:05:18 UTC (rev 277553)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.cpp	2021-05-16 01:21:21 UTC (rev 277554)
@@ -37,6 +37,7 @@
 #include "LayoutChildIterator.h"
 #include "LayoutContext.h"
 #include "LayoutInitialContainingBlock.h"
+#include "TableFormattingGeometry.h"
 #include "TableFormattingQuirks.h"
 #include "TableFormattingState.h"
 #include <wtf/IsoMallocInlines.h>
@@ -515,6 +516,11 @@
     }
 }
 
+TableFormattingGeometry TableFormattingContext::geometry() const
+{
+    return TableFormattingGeometry(*this, formattingState().tableGrid());
+}
+
 TableFormattingQuirks TableFormattingContext::quirks() const
 {
     return TableFormattingQuirks(*this);

Modified: trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.h (277553 => 277554)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.h	2021-05-16 01:05:18 UTC (rev 277553)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContext.h	2021-05-16 01:21:21 UTC (rev 277554)
@@ -37,6 +37,7 @@
 namespace Layout {
 
 class InvalidationState;
+class TableFormattingGeometry;
 class TableFormattingQuirks;
 
 // This class implements the layout logic for table formatting contexts.
@@ -50,23 +51,9 @@
 
     static UniqueRef<TableGrid> ensureTableGrid(const ContainerBox& tableBox);
 
-    class Geometry : public FormattingContext::Geometry {
-    public:
-        LayoutUnit cellHeigh(const ContainerBox&) const;
-        Edges computedCellBorder(const TableGrid::Cell&) const;
-        Optional<LayoutUnit> computedColumnWidth(const ContainerBox& columnBox);
-        FormattingContext::IntrinsicWidthConstraints intrinsicWidthConstraintsForCell(const TableGrid::Cell&);
-        InlineLayoutUnit usedBaselineForCell(const ContainerBox& cellBox);
+    TableFormattingGeometry geometry() const;
+    TableFormattingQuirks quirks() const;
 
-    private:
-        friend class TableFormattingContext;
-        Geometry(const TableFormattingContext&, const TableGrid&);
-
-        const TableFormattingContext& formattingContext() const { return downcast<TableFormattingContext>(FormattingContext::Geometry::formattingContext()); }
-        const TableGrid& m_grid;
-    };
-    TableFormattingContext::Geometry geometry() const { return Geometry(*this, formattingState().tableGrid()); }
-
 private:
     class TableLayout {
     public:
@@ -83,8 +70,6 @@
         const TableGrid& m_grid;
     };
 
-    TableFormattingQuirks quirks() const;
-
     TableFormattingContext::TableLayout tableLayout() const { return TableLayout(*this, formattingState().tableGrid()); }
 
     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
@@ -100,14 +85,8 @@
     TableFormattingState& formattingState() { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
 };
 
-inline TableFormattingContext::Geometry::Geometry(const TableFormattingContext& tableFormattingContext, const TableGrid& grid)
-    : FormattingContext::Geometry(tableFormattingContext)
-    , m_grid(grid)
-{
 }
-
 }
-}
 
 SPECIALIZE_TYPE_TRAITS_LAYOUT_FORMATTING_CONTEXT(TableFormattingContext, isTableFormattingContext())
 

Deleted: trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContextGeometry.cpp (277553 => 277554)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContextGeometry.cpp	2021-05-16 01:05:18 UTC (rev 277553)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContextGeometry.cpp	2021-05-16 01:21:21 UTC (rev 277554)
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "TableFormattingContext.h"
-
-#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-
-#include "InlineFormattingState.h"
-#include "LayoutBoxGeometry.h"
-#include "LayoutContext.h"
-#include "LayoutDescendantIterator.h"
-#include "LayoutInitialContainingBlock.h"
-#include "TableFormattingState.h"
-
-namespace WebCore {
-namespace Layout {
-
-LayoutUnit TableFormattingContext::Geometry::cellHeigh(const ContainerBox& cellBox) const
-{
-    ASSERT(cellBox.isInFlow());
-    auto contentHeight = LayoutUnit { };
-    if (formattingContext().quirks().shouldIgnoreChildContentVerticalMargin(cellBox)) {
-        ASSERT(cellBox.firstInFlowChild());
-        auto formattingContext = this->formattingContext();
-        auto& firstInFlowChild = *cellBox.firstInFlowChild();
-        auto& lastInFlowChild = *cellBox.lastInFlowChild();
-        auto& firstInFlowChildGeometry = formattingContext.geometryForBox(firstInFlowChild, EscapeReason::TableQuirkNeedsGeometryFromEstablishedFormattingContext);
-        auto& lastInFlowChildGeometry = formattingContext.geometryForBox(lastInFlowChild, EscapeReason::TableQuirkNeedsGeometryFromEstablishedFormattingContext);
-
-        auto top = firstInFlowChild.style().hasMarginBeforeQuirk() ? BoxGeometry::borderBoxRect(firstInFlowChildGeometry).top() : BoxGeometry::marginBoxRect(firstInFlowChildGeometry).top();
-        auto bottom = lastInFlowChild.style().hasMarginAfterQuirk() ? BoxGeometry::borderBoxRect(lastInFlowChildGeometry).bottom() : BoxGeometry::marginBoxRect(lastInFlowChildGeometry).bottom();
-        contentHeight = bottom - top;
-    } else
-        contentHeight = contentHeightForFormattingContextRoot(cellBox);
-    return std::max(computedHeight(cellBox).valueOr(0_lu), contentHeight);
-}
-
-Edges TableFormattingContext::Geometry::computedCellBorder(const TableGrid::Cell& cell) const
-{
-    auto& cellBox = cell.box();
-    auto border = computedBorder(cellBox);
-    auto collapsedBorder = m_grid.collapsedBorder();
-    if (!collapsedBorder)
-        return border;
-
-    // We might want to cache these collapsed borders on the grid.
-    auto cellPosition = cell.position();
-    // Collapsed border left from table and adjacent cells.
-    if (!cellPosition.column)
-        border.horizontal.left = collapsedBorder->horizontal.left / 2;
-    else {
-        auto adjacentBorderRight = computedBorder(m_grid.slot({ cellPosition.column - 1, cellPosition.row })->cell().box()).horizontal.right;
-        border.horizontal.left = std::max(border.horizontal.left, adjacentBorderRight) / 2;
-    }
-    // Collapsed border right from table and adjacent cells.
-    if (cellPosition.column == m_grid.columns().size() - 1)
-        border.horizontal.right = collapsedBorder->horizontal.right / 2;
-    else {
-        auto adjacentBorderLeft = computedBorder(m_grid.slot({ cellPosition.column + 1, cellPosition.row })->cell().box()).horizontal.left;
-        border.horizontal.right = std::max(border.horizontal.right, adjacentBorderLeft) / 2;
-    }
-    // Collapsed border top from table, row and adjacent cells.
-    auto& rows = m_grid.rows().list();
-    if (!cellPosition.row)
-        border.vertical.top = collapsedBorder->vertical.top / 2;
-    else {
-        auto adjacentBorderBottom = computedBorder(m_grid.slot({ cellPosition.column, cellPosition.row - 1 })->cell().box()).vertical.bottom;
-        auto adjacentRowBottom = computedBorder(rows[cellPosition.row - 1].box()).vertical.bottom;
-        auto adjacentCollapsedBorder = std::max(adjacentBorderBottom, adjacentRowBottom);
-        border.vertical.top = std::max(border.vertical.top, adjacentCollapsedBorder) / 2;
-    }
-    // Collapsed border bottom from table, row and adjacent cells.
-    if (cellPosition.row == m_grid.rows().size() - 1)
-        border.vertical.bottom = collapsedBorder->vertical.bottom / 2;
-    else {
-        auto adjacentBorderTop = computedBorder(m_grid.slot({ cellPosition.column, cellPosition.row + 1 })->cell().box()).vertical.top;
-        auto adjacentRowTop = computedBorder(rows[cellPosition.row + 1].box()).vertical.top;
-        auto adjacentCollapsedBorder = std::max(adjacentBorderTop, adjacentRowTop);
-        border.vertical.bottom = std::max(border.vertical.bottom, adjacentCollapsedBorder) / 2;
-    }
-    return border;
-}
-
-Optional<LayoutUnit> TableFormattingContext::Geometry::computedColumnWidth(const ContainerBox& columnBox)
-{
-    // Check both style and <col>'s width attribute.
-    // FIXME: Figure out what to do with calculated values, like <col style="width: 10%">.
-    if (auto computedWidthValue = computedWidth(columnBox, { }))
-        return computedWidthValue;
-    return columnBox.columnWidth();
-}
-
-FormattingContext::IntrinsicWidthConstraints TableFormattingContext::Geometry::intrinsicWidthConstraintsForCell(const TableGrid::Cell& cell)
-{
-    auto& cellBox = cell.box();
-    auto& style = cellBox.style();
-
-    auto computedIntrinsicWidthConstraints = [&]() -> FormattingContext::IntrinsicWidthConstraints {
-        // Even fixed width cells expand to their minimum content width
-        // <td style="width: 10px">test_content</td> will size to max(minimum content width, computed width).
-        auto intrinsicWidthConstraints = FormattingContext::IntrinsicWidthConstraints { };
-        if (cellBox.hasChild())
-            intrinsicWidthConstraints = LayoutContext::createFormattingContext(cellBox, layoutState())->computedIntrinsicWidthConstraints();
-        if (auto fixedWidth = fixedValue(style.logicalWidth()))
-            return { std::max(intrinsicWidthConstraints.minimum, *fixedWidth), std::max(intrinsicWidthConstraints.minimum, *fixedWidth) };
-        return intrinsicWidthConstraints;
-    };
-    // FIXME Check for box-sizing: border-box;
-    auto intrinsicWidthConstraints = constrainByMinMaxWidth(cellBox, computedIntrinsicWidthConstraints());
-    // Expand with border
-    intrinsicWidthConstraints.expand(computedCellBorder(cell).width());
-    // padding
-    intrinsicWidthConstraints.expand(fixedValue(style.paddingLeft()).valueOr(0) + fixedValue(style.paddingRight()).valueOr(0));
-    // and margin
-    intrinsicWidthConstraints.expand(fixedValue(style.marginStart()).valueOr(0) + fixedValue(style.marginEnd()).valueOr(0));
-    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.
-    if (cellBox.establishesInlineFormattingContext())
-        return layoutState().establishedInlineFormattingState(cellBox).lines()[0].baseline();
-    for (auto& cellDescendant : descendantsOfType<ContainerBox>(cellBox)) {
-        if (cellDescendant.establishesInlineFormattingContext()) {
-            auto& inlineFormattingStateForCell = layoutState().establishedInlineFormattingState(cellDescendant);
-            if (!inlineFormattingStateForCell.lines().isEmpty())
-                return inlineFormattingStateForCell.lines()[0].baseline();
-        }
-        if (cellDescendant.establishesTableFormattingContext())
-            return layoutState().establishedTableFormattingState(cellDescendant).tableGrid().rows().list()[0].baseline();
-    }
-    return formattingContext().geometryForBox(cellBox).contentBoxBottom();
-}
-
-}
-}
-
-#endif

Copied: trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.cpp (from rev 277553, trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingContextGeometry.cpp) (0 => 277554)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.cpp	                        (rev 0)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.cpp	2021-05-16 01:21:21 UTC (rev 277554)
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TableFormattingGeometry.h"
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "InlineFormattingState.h"
+#include "LayoutBoxGeometry.h"
+#include "LayoutContext.h"
+#include "LayoutDescendantIterator.h"
+#include "LayoutInitialContainingBlock.h"
+#include "TableFormattingState.h"
+
+namespace WebCore {
+namespace Layout {
+
+TableFormattingGeometry::TableFormattingGeometry(const TableFormattingContext& tableFormattingContext, const TableGrid& grid)
+    : FormattingContext::Geometry(tableFormattingContext)
+    , m_grid(grid)
+{
+}
+
+LayoutUnit TableFormattingGeometry::cellHeigh(const ContainerBox& cellBox) const
+{
+    ASSERT(cellBox.isInFlow());
+    auto contentHeight = LayoutUnit { };
+    if (formattingContext().quirks().shouldIgnoreChildContentVerticalMargin(cellBox)) {
+        ASSERT(cellBox.firstInFlowChild());
+        auto formattingContext = this->formattingContext();
+        auto& firstInFlowChild = *cellBox.firstInFlowChild();
+        auto& lastInFlowChild = *cellBox.lastInFlowChild();
+        auto& firstInFlowChildGeometry = formattingContext.geometryForBox(firstInFlowChild, FormattingContext::EscapeReason::TableQuirkNeedsGeometryFromEstablishedFormattingContext);
+        auto& lastInFlowChildGeometry = formattingContext.geometryForBox(lastInFlowChild, FormattingContext::EscapeReason::TableQuirkNeedsGeometryFromEstablishedFormattingContext);
+
+        auto top = firstInFlowChild.style().hasMarginBeforeQuirk() ? BoxGeometry::borderBoxRect(firstInFlowChildGeometry).top() : BoxGeometry::marginBoxRect(firstInFlowChildGeometry).top();
+        auto bottom = lastInFlowChild.style().hasMarginAfterQuirk() ? BoxGeometry::borderBoxRect(lastInFlowChildGeometry).bottom() : BoxGeometry::marginBoxRect(lastInFlowChildGeometry).bottom();
+        contentHeight = bottom - top;
+    } else
+        contentHeight = contentHeightForFormattingContextRoot(cellBox);
+    return std::max(computedHeight(cellBox).valueOr(0_lu), contentHeight);
+}
+
+Edges TableFormattingGeometry::computedCellBorder(const TableGrid::Cell& cell) const
+{
+    auto& cellBox = cell.box();
+    auto border = computedBorder(cellBox);
+    auto collapsedBorder = m_grid.collapsedBorder();
+    if (!collapsedBorder)
+        return border;
+
+    // We might want to cache these collapsed borders on the grid.
+    auto cellPosition = cell.position();
+    // Collapsed border left from table and adjacent cells.
+    if (!cellPosition.column)
+        border.horizontal.left = collapsedBorder->horizontal.left / 2;
+    else {
+        auto adjacentBorderRight = computedBorder(m_grid.slot({ cellPosition.column - 1, cellPosition.row })->cell().box()).horizontal.right;
+        border.horizontal.left = std::max(border.horizontal.left, adjacentBorderRight) / 2;
+    }
+    // Collapsed border right from table and adjacent cells.
+    if (cellPosition.column == m_grid.columns().size() - 1)
+        border.horizontal.right = collapsedBorder->horizontal.right / 2;
+    else {
+        auto adjacentBorderLeft = computedBorder(m_grid.slot({ cellPosition.column + 1, cellPosition.row })->cell().box()).horizontal.left;
+        border.horizontal.right = std::max(border.horizontal.right, adjacentBorderLeft) / 2;
+    }
+    // Collapsed border top from table, row and adjacent cells.
+    auto& rows = m_grid.rows().list();
+    if (!cellPosition.row)
+        border.vertical.top = collapsedBorder->vertical.top / 2;
+    else {
+        auto adjacentBorderBottom = computedBorder(m_grid.slot({ cellPosition.column, cellPosition.row - 1 })->cell().box()).vertical.bottom;
+        auto adjacentRowBottom = computedBorder(rows[cellPosition.row - 1].box()).vertical.bottom;
+        auto adjacentCollapsedBorder = std::max(adjacentBorderBottom, adjacentRowBottom);
+        border.vertical.top = std::max(border.vertical.top, adjacentCollapsedBorder) / 2;
+    }
+    // Collapsed border bottom from table, row and adjacent cells.
+    if (cellPosition.row == m_grid.rows().size() - 1)
+        border.vertical.bottom = collapsedBorder->vertical.bottom / 2;
+    else {
+        auto adjacentBorderTop = computedBorder(m_grid.slot({ cellPosition.column, cellPosition.row + 1 })->cell().box()).vertical.top;
+        auto adjacentRowTop = computedBorder(rows[cellPosition.row + 1].box()).vertical.top;
+        auto adjacentCollapsedBorder = std::max(adjacentBorderTop, adjacentRowTop);
+        border.vertical.bottom = std::max(border.vertical.bottom, adjacentCollapsedBorder) / 2;
+    }
+    return border;
+}
+
+Optional<LayoutUnit> TableFormattingGeometry::computedColumnWidth(const ContainerBox& columnBox)
+{
+    // Check both style and <col>'s width attribute.
+    // FIXME: Figure out what to do with calculated values, like <col style="width: 10%">.
+    if (auto computedWidthValue = computedWidth(columnBox, { }))
+        return computedWidthValue;
+    return columnBox.columnWidth();
+}
+
+FormattingContext::IntrinsicWidthConstraints TableFormattingGeometry::intrinsicWidthConstraintsForCell(const TableGrid::Cell& cell)
+{
+    auto& cellBox = cell.box();
+    auto& style = cellBox.style();
+
+    auto computedIntrinsicWidthConstraints = [&]() -> FormattingContext::IntrinsicWidthConstraints {
+        // Even fixed width cells expand to their minimum content width
+        // <td style="width: 10px">test_content</td> will size to max(minimum content width, computed width).
+        auto intrinsicWidthConstraints = FormattingContext::IntrinsicWidthConstraints { };
+        if (cellBox.hasChild())
+            intrinsicWidthConstraints = LayoutContext::createFormattingContext(cellBox, layoutState())->computedIntrinsicWidthConstraints();
+        if (auto fixedWidth = fixedValue(style.logicalWidth()))
+            return { std::max(intrinsicWidthConstraints.minimum, *fixedWidth), std::max(intrinsicWidthConstraints.minimum, *fixedWidth) };
+        return intrinsicWidthConstraints;
+    };
+    // FIXME Check for box-sizing: border-box;
+    auto intrinsicWidthConstraints = constrainByMinMaxWidth(cellBox, computedIntrinsicWidthConstraints());
+    // Expand with border
+    intrinsicWidthConstraints.expand(computedCellBorder(cell).width());
+    // padding
+    intrinsicWidthConstraints.expand(fixedValue(style.paddingLeft()).valueOr(0) + fixedValue(style.paddingRight()).valueOr(0));
+    // and margin
+    intrinsicWidthConstraints.expand(fixedValue(style.marginStart()).valueOr(0) + fixedValue(style.marginEnd()).valueOr(0));
+    return intrinsicWidthConstraints;
+}
+
+
+InlineLayoutUnit TableFormattingGeometry::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.
+    if (cellBox.establishesInlineFormattingContext())
+        return layoutState().establishedInlineFormattingState(cellBox).lines()[0].baseline();
+    for (auto& cellDescendant : descendantsOfType<ContainerBox>(cellBox)) {
+        if (cellDescendant.establishesInlineFormattingContext()) {
+            auto& inlineFormattingStateForCell = layoutState().establishedInlineFormattingState(cellDescendant);
+            if (!inlineFormattingStateForCell.lines().isEmpty())
+                return inlineFormattingStateForCell.lines()[0].baseline();
+        }
+        if (cellDescendant.establishesTableFormattingContext())
+            return layoutState().establishedTableFormattingState(cellDescendant).tableGrid().rows().list()[0].baseline();
+    }
+    return formattingContext().geometryForBox(cellBox).contentBoxBottom();
+}
+
+}
+}
+
+#endif

Added: trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.h (0 => 277554)


--- trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.h	                        (rev 0)
+++ trunk/Source/WebCore/layout/formattingContexts/table/TableFormattingGeometry.h	2021-05-16 01:21:21 UTC (rev 277554)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+
+#include "FormattingContext.h"
+
+namespace WebCore {
+namespace Layout {
+
+class TableFormattingGeometry : public FormattingContext::Geometry {
+public:
+    LayoutUnit cellHeigh(const ContainerBox&) const;
+    Edges computedCellBorder(const TableGrid::Cell&) const;
+    Optional<LayoutUnit> computedColumnWidth(const ContainerBox& columnBox);
+    FormattingContext::IntrinsicWidthConstraints intrinsicWidthConstraintsForCell(const TableGrid::Cell&);
+    InlineLayoutUnit usedBaselineForCell(const ContainerBox& cellBox);
+
+private:
+    friend class TableFormattingContext;
+    TableFormattingGeometry(const TableFormattingContext&, const TableGrid&);
+
+    const TableFormattingContext& formattingContext() const { return downcast<TableFormattingContext>(FormattingContext::Geometry::formattingContext()); }
+    const TableGrid& m_grid;
+};
+
+}
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to