⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 249177 in webkit


Ignore:
Timestamp:
Aug 27, 2019, 3:21:23 PM (7 years ago)
Author:
Alan Bujtas
Message:

[LFC][TFC] Layout and position the cell boxes
https://bugs.webkit.org/show_bug.cgi?id=201192
<rdar://problem/54758638>

Reviewed by Antti Koivisto.

Add a very basic (and faily incomplete) table cell layout logic. This is mostly WIP.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • layout/FormattingContext.h:
  • layout/FormattingContextGeometry.cpp:

(WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot):
(WebCore::Layout::contentHeightForFormattingContextRoot): Deleted.

  • layout/tableformatting/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::layout const):
(WebCore::Layout::TableFormattingContext::computedTableWidth const):

  • layout/tableformatting/TableFormattingContext.h:
  • layout/tableformatting/TableFormattingContextGeometry.cpp: Copied from Source/WebCore/layout/tableformatting/TableFormattingContext.h.

(WebCore::Layout::TableFormattingContext::Geometry::tableCellHeightAndMargin):

  • layout/tableformatting/TableGrid.cpp:

(WebCore::Layout::TableGrid::Column::setLogicalLeft):
(WebCore::Layout::TableGrid::Column::logicalLeft const):

  • layout/tableformatting/TableGrid.h:

(WebCore::Layout::TableGrid::Column::logicalRight const):
(WebCore::Layout::TableGrid::Row::setLogicalTop):
(WebCore::Layout::TableGrid::Row::logicalTop const):
(WebCore::Layout::TableGrid::Row::setLogicalHeight):
(WebCore::Layout::TableGrid::Row::logicalHeight const):
(WebCore::Layout::TableGrid::Row::logicalBottom const):

Location:
trunk/Source/WebCore
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249175 r249177  
     12019-08-27  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Layout and position the cell boxes
     4        https://bugs.webkit.org/show_bug.cgi?id=201192
     5        <rdar://problem/54758638>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Add a very basic (and faily incomplete) table cell layout logic. This is mostly WIP.
     10
     11        * Sources.txt:
     12        * WebCore.xcodeproj/project.pbxproj:
     13        * layout/FormattingContext.h:
     14        * layout/FormattingContextGeometry.cpp:
     15        (WebCore::Layout::FormattingContext::Geometry::contentHeightForFormattingContextRoot):
     16        (WebCore::Layout::contentHeightForFormattingContextRoot): Deleted.
     17        * layout/tableformatting/TableFormattingContext.cpp:
     18        (WebCore::Layout::TableFormattingContext::layout const):
     19        (WebCore::Layout::TableFormattingContext::computedTableWidth const):
     20        * layout/tableformatting/TableFormattingContext.h:
     21        * layout/tableformatting/TableFormattingContextGeometry.cpp: Copied from Source/WebCore/layout/tableformatting/TableFormattingContext.h.
     22        (WebCore::Layout::TableFormattingContext::Geometry::tableCellHeightAndMargin):
     23        * layout/tableformatting/TableGrid.cpp:
     24        (WebCore::Layout::TableGrid::Column::setLogicalLeft):
     25        (WebCore::Layout::TableGrid::Column::logicalLeft const):
     26        * layout/tableformatting/TableGrid.h:
     27        (WebCore::Layout::TableGrid::Column::logicalRight const):
     28        (WebCore::Layout::TableGrid::Row::setLogicalTop):
     29        (WebCore::Layout::TableGrid::Row::logicalTop const):
     30        (WebCore::Layout::TableGrid::Row::setLogicalHeight):
     31        (WebCore::Layout::TableGrid::Row::logicalHeight const):
     32        (WebCore::Layout::TableGrid::Row::logicalBottom const):
     33
    1342019-08-27  Mark Lam  <mark.lam@apple.com>
    235
  • trunk/Source/WebCore/Sources.txt

    r249084 r249177  
    14181418layout/layouttree/LayoutTreeBuilder.cpp
    14191419layout/tableformatting/TableFormattingContext.cpp
     1420layout/tableformatting/TableFormattingContextGeometry.cpp
    14201421layout/tableformatting/TableFormattingState.cpp
    14211422layout/tableformatting/TableGrid.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r249084 r249177  
    58425842                11CB2786203BA570004A1DC9 /* RenderTreeBuilderFullScreen.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTreeBuilderFullScreen.cpp; sourceTree = "<group>"; };
    58435843                11CB2787203BA570004A1DC9 /* RenderTreeBuilderFullScreen.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RenderTreeBuilderFullScreen.h; sourceTree = "<group>"; };
     5844                11D19C2E23159BAE008F24D3 /* TableFormattingContextGeometry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TableFormattingContextGeometry.cpp; sourceTree = "<group>"; };
    58445845                11E067EB1E62461300162D16 /* SimpleLineLayoutCoverage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleLineLayoutCoverage.cpp; sourceTree = "<group>"; };
    58455846                11E067ED1E6246E500162D16 /* SimpleLineLayoutCoverage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleLineLayoutCoverage.h; sourceTree = "<group>"; };
     
    2045420455                                6FC5CA9422E3599400B13E11 /* TableFormattingContext.cpp */,
    2045520456                                6FC5CA9522E3599400B13E11 /* TableFormattingContext.h */,
     20457                                11D19C2E23159BAE008F24D3 /* TableFormattingContextGeometry.cpp */,
    2045620458                                6FC5CA9222E3599300B13E11 /* TableFormattingState.cpp */,
    2045720459                                6FC5CA9622E3599500B13E11 /* TableFormattingState.h */,
     
    3060530607                                B22279650D00BF220071B782 /* LinearGradientAttributes.h in Headers */,
    3060630608                                AB31C91E10AE1B8E000C7B92 /* LineClampValue.h in Headers */,
     30609                                E484A33E23055325009ADE6A /* LineLayoutInterfaceTextBoxes.h in Headers */,
    3060730610                                FFEFAB2A18380DA000514534 /* LineLayoutState.h in Headers */,
    3060830611                                FFDBC047183D27B700407109 /* LineWidth.h in Headers */,
     
    3192331926                                57EF5E601D20C83900171E60 /* TextCodecReplacement.h in Headers */,
    3192431927                                B2C3DA400D006C1D00EF6F26 /* TextCodecUserDefined.h in Headers */,
    31925                                 E484A33E23055325009ADE6A /* LineLayoutInterfaceTextBoxes.h in Headers */,
    3192631928                                B2C3DA420D006C1D00EF6F26 /* TextCodecUTF16.h in Headers */,
    3192731929                                9343CB8212F25E510033C5EE /* TextCodecUTF8.h in Headers */,
  • trunk/Source/WebCore/layout/FormattingContext.h

    r248834 r249177  
    113113        static FormattingContext::IntrinsicWidthConstraints constrainByMinMaxWidth(const Box&, IntrinsicWidthConstraints);
    114114
     115        static LayoutUnit contentHeightForFormattingContextRoot(const LayoutState&, const Box&);
     116
    115117    protected:
    116118        enum class HeightType { Min, Max, Normal };
  • trunk/Source/WebCore/layout/FormattingContextGeometry.cpp

    r249172 r249177  
    9090}
    9191
    92 static LayoutUnit contentHeightForFormattingContextRoot(const LayoutState& layoutState, const Box& layoutBox)
     92LayoutUnit FormattingContext::Geometry::contentHeightForFormattingContextRoot(const LayoutState& layoutState, const Box& layoutBox)
    9393{
    9494    ASSERT(isHeightAuto(layoutBox) && (layoutBox.establishesFormattingContext() || layoutBox.isDocumentBox()));
     
    127127        auto& rowList = downcast<TableFormattingState>(layoutState.establishedFormattingState(formattingRootContainer)).tableGrid().rows();
    128128        ASSERT(!rowList.isEmpty());
    129         top += rowList.first().offset;
     129        top += rowList.first().logicalTop();
    130130        auto& lastRow = rowList.last();
    131         bottom += lastRow.offset + lastRow.height;
     131        bottom += lastRow.logicalBottom();
    132132    } else
    133133        ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

    r249172 r249177  
    4646void TableFormattingContext::layout() const
    4747{
    48     ASSERT(!formattingState().tableGrid().cells().isEmpty());
     48    auto& grid = formattingState().tableGrid();
     49    auto& cellList = grid.cells();
     50    ASSERT(!cellList.isEmpty());
     51    // Layout and position each table cell (and compute row height as well).
     52    auto& layoutState = this->layoutState();
     53    auto& columnList = grid.columnsContext().columns();
     54    auto& rowList = grid.rows();
     55    for (auto& cell : cellList) {
     56        auto& cellLayoutBox = cell->tableCellBox;
     57        ASSERT(cellLayoutBox.establishesBlockFormattingContext());
     58
     59        auto& cellDisplayBox = layoutState.displayBoxForLayoutBox(cellLayoutBox);
     60        // FIXME: Add support for column and row spanning.
     61        auto cellPosition = cell->position;
     62        auto& row = rowList.at(cellPosition.y());
     63        auto& column = columnList.at(cellPosition.x());
     64        cellDisplayBox.setContentBoxWidth(column.logicalWidth());
     65        // FIXME: Do not use blanks.
     66        cellDisplayBox.setBorder({ });
     67        cellDisplayBox.setPadding({ });
     68        cellDisplayBox.setHorizontalMargin({ });
     69        cellDisplayBox.setHorizontalComputedMargin({ });
     70
     71        cellDisplayBox.setTopLeft({ column.logicalLeft(), row.logicalTop() });
     72
     73        layoutState.createFormattingContext(cellLayoutBox)->layout();
     74
     75        // FIXME: This requires a 2 pass layout.
     76        auto heightAndMargin = Geometry::tableCellHeightAndMargin(layoutState, cellLayoutBox);
     77        cellDisplayBox.setContentBoxHeight(heightAndMargin.height);
     78        cellDisplayBox.setVerticalMargin({ heightAndMargin.nonCollapsedMargin, { } });
     79
     80        row.setLogicalHeight(std::max(row.logicalHeight(), heightAndMargin.height));
     81        // FIXME: This also requires spanning support/check.
     82        if (!cellPosition.x() && cellPosition.y()) {
     83            auto& previousRow = rowList.at(cellPosition.y() - 1);
     84            row.setLogicalTop(previousRow.logicalBottom());
     85        }
     86    }
    4987}
    5088
     
    164202        }
    165203    }
    166 
     204    // FIXME: This should also deal with collapsing borders etc.
     205    LayoutUnit columnLogicalLeft;
     206    auto& columns = columnsContext.columns();
     207    for (auto& column : columns) {
     208        column.setLogicalLeft(columnLogicalLeft);
     209        columnLogicalLeft += column.logicalWidth();
     210    }
    167211    return usedWidth;
    168212}
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h

    r249172 r249177  
    4444
    4545private:
     46    class Geometry : public FormattingContext::Geometry {
     47    public:
     48        static HeightAndMargin tableCellHeightAndMargin(const LayoutState&, const Box&);
     49    };
     50
    4651    IntrinsicWidthConstraints computedIntrinsicWidthConstraints() const override;
    4752    LayoutUnit computedTableWidth() const;
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContextGeometry.cpp

    r249176 r249177  
    2424 */
    2525
    26 #pragma once
     26#include "config.h"
     27#include "TableFormattingContext.h"
    2728
    2829#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    2930
    3031#include "FormattingContext.h"
    31 #include "TableFormattingState.h"
    32 #include <wtf/IsoMalloc.h>
     32#include "LayoutBox.h"
     33#include "LayoutState.h"
    3334
    3435namespace WebCore {
    3536namespace Layout {
    3637
    37 // This class implements the layout logic for table formatting contexts.
    38 // https://www.w3.org/TR/CSS22/tables.html
    39 class TableFormattingContext : public FormattingContext {
    40     WTF_MAKE_ISO_ALLOCATED(TableFormattingContext);
    41 public:
    42     TableFormattingContext(const Box& formattingContextRoot, TableFormattingState&);
    43     void layout() const override;
     38HeightAndMargin TableFormattingContext::Geometry::tableCellHeightAndMargin(const LayoutState& layoutState, const Box& layoutBox)
     39{
     40    ASSERT(layoutBox.isInFlow());
    4441
    45 private:
    46     IntrinsicWidthConstraints computedIntrinsicWidthConstraints() const override;
    47     LayoutUnit computedTableWidth() const;
     42    auto height = computedHeightValue(layoutState, layoutBox, HeightType::Normal);
     43    if (!height)
     44        height = Geometry::contentHeightForFormattingContextRoot(layoutState, layoutBox);
    4845
    49     void ensureTableGrid() const;
    50     void computePreferredWidthForColumns() const;
    51     void distributeAvailableWidth(LayoutUnit extraHorizontalSpace) const;
    52 
    53     TableFormattingState& formattingState() const { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
    54 };
     46    // FIXME: Compute vertical margin values.
     47    return HeightAndMargin { *height, { } };
     48}
    5549
    5650}
    5751}
     52
    5853#endif
  • trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp

    r248846 r249177  
    6262    ASSERT(m_hasComputedWidth);
    6363    return m_computedLogicalWidth;
     64}
     65
     66void TableGrid::Column::setLogicalLeft(LayoutUnit computedLogicalLeft)
     67{
     68#ifndef NDEBUG
     69    m_hasComputedLeft = true;
     70#endif
     71    m_computedLogicalLeft = computedLogicalLeft;
     72}
     73
     74LayoutUnit TableGrid::Column::logicalLeft() const
     75{
     76    ASSERT(m_hasComputedLeft);
     77    return m_computedLogicalLeft;
    6478}
    6579
  • trunk/Source/WebCore/layout/tableformatting/TableGrid.h

    r249172 r249177  
    7272        LayoutUnit logicalWidth() const;
    7373
     74        void setLogicalLeft(LayoutUnit);
     75        LayoutUnit logicalLeft() const;
     76
     77        LayoutUnit logicalRight() const { return logicalLeft() + logicalWidth(); }
     78
    7479    private:
    7580        friend class ColumnsContext;
     
    7883        FormattingContext::IntrinsicWidthConstraints m_widthConstraints;
    7984        LayoutUnit m_computedLogicalWidth;
     85        LayoutUnit m_computedLogicalLeft;
    8086#ifndef NDEBUG
    8187        bool m_hasWidthConstraints { false };
    8288        bool m_hasComputedWidth { false };
     89        bool m_hasComputedLeft { false };
    8390#endif
    8491    };
     
    102109
    103110    struct Row {
    104         LayoutUnit offset;
    105         LayoutUnit height;
     111    public:
     112        void setLogicalTop(LayoutUnit logicalTop) { m_logicalTop = logicalTop; }
     113        LayoutUnit logicalTop() const { return m_logicalTop; }
     114
     115        void setLogicalHeight(LayoutUnit logicalHeight) { m_logicalHeight = logicalHeight; }
     116        LayoutUnit logicalHeight() const { return m_logicalHeight; }
     117
     118        LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
     119
     120    private:
     121        LayoutUnit m_logicalTop;
     122        LayoutUnit m_logicalHeight;
    106123    };
    107124    using RowList = WTF::Vector<Row>;
Note: See TracChangeset for help on using the changeset viewer.