Changeset 248671 in webkit


Ignore:
Timestamp:
Aug 14, 2019 8:39:23 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][TFC] Implement TableFormattingContext::computePreferredWidthForColumns
https://bugs.webkit.org/show_bug.cgi?id=200701
<rdar://problem/54287828>

Reviewed by Antti Koivisto.

Compute cells' min/max width first.

  • layout/tableformatting/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns const):

  • layout/tableformatting/TableGrid.cpp:

(WebCore::Layout::TableGrid::slot):
(WebCore::Layout::TableGrid::appendCell):

  • layout/tableformatting/TableGrid.h:

(WebCore::Layout::TableGrid::cells):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248670 r248671  
     12019-08-14  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Implement TableFormattingContext::computePreferredWidthForColumns
     4        https://bugs.webkit.org/show_bug.cgi?id=200701
     5        <rdar://problem/54287828>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Compute cells' min/max width first.
     10
     11        * layout/tableformatting/TableFormattingContext.cpp:
     12        (WebCore::Layout::TableFormattingContext::computePreferredWidthForColumns const):
     13        * layout/tableformatting/TableGrid.cpp:
     14        (WebCore::Layout::TableGrid::slot):
     15        (WebCore::Layout::TableGrid::appendCell):
     16        * layout/tableformatting/TableGrid.h:
     17        (WebCore::Layout::TableGrid::cells):
     18
    1192019-08-14  Youenn Fablet  <youenn@apple.com>
    220
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

    r248596 r248671  
    8686void TableFormattingContext::computePreferredWidthForColumns() const
    8787{
     88    auto& formattingState = this->formattingState();
     89    auto& grid = formattingState.tableGrid();
     90
     91    // 1. Calculate the minimum content width (MCW) of each cell: the formatted content may span any number of lines but may not overflow the cell box.
     92    //    If the specified 'width' (W) of the cell is greater than MCW, W is the minimum cell width. A value of 'auto' means that MCW is the minimum cell width.
     93    //    Also, calculate the "maximum" cell width of each cell: formatting the content without breaking lines other than where explicit line breaks occur.
     94    for (auto& cell : grid.cells()) {
     95        ASSERT(cell->tableCellBox.establishesFormattingContext());
     96
     97        auto intrinsicWidth = layoutState().createFormattingContext(cell->tableCellBox)->computedIntrinsicWidthConstraints();
     98        intrinsicWidth = Geometry::constrainByMinMaxWidth(cell->tableCellBox, intrinsicWidth);
     99        formattingState.setIntrinsicWidthConstraints(intrinsicWidth);
     100
     101        auto columnSpan = cell->size.width();
     102        auto slotIntrinsicWidth = FormattingContext::IntrinsicWidthConstraints { intrinsicWidth.minimum / columnSpan, intrinsicWidth.maximum / columnSpan };
     103        auto initialPosition = cell->position;
     104        for (auto i = 0; i < columnSpan; ++i)
     105            grid.slot({ initialPosition.x() + i, initialPosition.y() })->widthConstraints = slotIntrinsicWidth;
     106    }
    88107}
    89108
  • trunk/Source/WebCore/layout/tableformatting/TableGrid.cpp

    r248596 r248671  
    5252}
    5353
     54TableGrid::SlotInfo* TableGrid::slot(SlotPosition position)
     55{
     56    return m_slotMap.get(position);
     57}
     58
    5459void TableGrid::appendCell(const Box& tableCellBox)
    5560{
     
    8085            auto position = SlotPosition { initialSlotPosition.x() + row - 1, initialSlotPosition.y() + column - 1 };
    8186            ASSERT(!m_slotMap.contains(position));
    82             m_slotMap.add(position, SlotInfo { *cellInfo });
     87            m_slotMap.add(position, std::make_unique<SlotInfo>(*cellInfo));
    8388        }
    8489    }
  • trunk/Source/WebCore/layout/tableformatting/TableGrid.h

    r248596 r248671  
    4747    void removeCell(const Box&);
    4848
    49 private:
    5049    using SlotPosition = IntPoint;
    5150    using CellSize = IntSize;
    52     using SlotLogicalSize = LayoutSize;
    53 
    5451    struct CellInfo : public CanMakeWeakPtr<CellInfo> {
    5552        CellInfo(const Box& tableCellBox, SlotPosition, CellSize);
     
    5956        CellSize size;
    6057    };
     58    using CellList = WTF::ListHashSet<std::unique_ptr<CellInfo>>;
     59    CellList& cells() { return m_cellList; }
    6160
     61    using SlotLogicalSize = LayoutSize;
    6262    struct SlotInfo {
    6363        SlotInfo() = default;
     
    6565
    6666        WeakPtr<CellInfo> cell;
     67        FormattingContext::IntrinsicWidthConstraints widthConstraints;
    6768        SlotLogicalSize size;
    6869    };
     70    SlotInfo* slot(SlotPosition);
    6971
    70     using CellList = WTF::ListHashSet<std::unique_ptr<CellInfo>>;
    71     using SlotMap = WTF::HashMap<SlotPosition, SlotInfo>;
     72private:
     73    using SlotMap = WTF::HashMap<SlotPosition, std::unique_ptr<SlotInfo>>;
    7274    SlotMap m_slotMap;
    7375    CellList m_cellList;
Note: See TracChangeset for help on using the changeset viewer.