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

Changeset 249172 in webkit


Ignore:
Timestamp:
Aug 27, 2019, 2:24:40 PM (7 years ago)
Author:
Alan Bujtas
Message:

[LFC][TFC] Align table formatting context code with the existing layout logic.
https://bugs.webkit.org/show_bug.cgi?id=201168
<rdar://problem/54732633>

Reviewed by Antti Koivisto.

Let's make the TFC go through the exisint shrink-to-fit computation. Tables behave slightly different from
other shrink-to-fit boxes as they are streched to their minimum width(MIN) even when 'width' is non-auto and computed to less than MIN.

  • layout/FormattingContextGeometry.cpp:

(WebCore::Layout::contentHeightForFormattingContextRoot):

  • layout/blockformatting/BlockFormattingContext.h:
  • layout/blockformatting/BlockFormattingContextGeometry.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):

  • layout/tableformatting/TableFormattingContext.cpp:

(WebCore::Layout::TableFormattingContext::layout const):
(WebCore::Layout::TableFormattingContext::computedIntrinsicWidthConstraints const):
(WebCore::Layout::TableFormattingContext::computedTableWidth const):
(WebCore::Layout::TableFormattingContext::computeTableWidth const): Deleted.
(WebCore::Layout::TableFormattingContext::computeTableHeight const): Deleted.
(WebCore::Layout::TableFormattingContext::distributeAvailableHeight const): Deleted.

  • layout/tableformatting/TableFormattingContext.h:
  • layout/tableformatting/TableGrid.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249170 r249172  
     12019-08-27  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][TFC] Align table formatting context code with the existing layout logic.
     4        https://bugs.webkit.org/show_bug.cgi?id=201168
     5        <rdar://problem/54732633>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Let's make the TFC go through the exisint shrink-to-fit computation. Tables behave slightly different from
     10        other shrink-to-fit boxes as they are streched to their minimum width(MIN) even when 'width' is non-auto and computed to less than MIN.
     11
     12        * layout/FormattingContextGeometry.cpp:
     13        (WebCore::Layout::contentHeightForFormattingContextRoot):
     14        * layout/blockformatting/BlockFormattingContext.h:
     15        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     16        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowWidthAndMargin):
     17        * layout/tableformatting/TableFormattingContext.cpp:
     18        (WebCore::Layout::TableFormattingContext::layout const):
     19        (WebCore::Layout::TableFormattingContext::computedIntrinsicWidthConstraints const):
     20        (WebCore::Layout::TableFormattingContext::computedTableWidth const):
     21        (WebCore::Layout::TableFormattingContext::computeTableWidth const): Deleted.
     22        (WebCore::Layout::TableFormattingContext::computeTableHeight const): Deleted.
     23        (WebCore::Layout::TableFormattingContext::distributeAvailableHeight const): Deleted.
     24        * layout/tableformatting/TableFormattingContext.h:
     25        * layout/tableformatting/TableGrid.h:
     26
    1272019-08-27  Simon Fraser  <simon.fraser@apple.com>
    228
  • trunk/Source/WebCore/layout/FormattingContextGeometry.cpp

    r248262 r249172  
    3232#include "FormattingState.h"
    3333#include "InlineFormattingState.h"
     34#include "TableFormattingState.h"
     35#include "TableGrid.h"
    3436
    3537namespace WebCore {
     
    102104    // into account, e.g., floats inside absolutely positioned descendants or other floats are not.
    103105    if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowOrFloatingChild())
    104         return 0;
     106        return { };
    105107
    106108    auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
     
    122124            bottom = lastDisplayBox.rectWithMargin().bottom();
    123125        }
    124     }
     126    } else if (formattingRootContainer.establishesTableFormattingContext()) {
     127        auto& rowList = downcast<TableFormattingState>(layoutState.establishedFormattingState(formattingRootContainer)).tableGrid().rows();
     128        ASSERT(!rowList.isEmpty());
     129        top += rowList.first().offset;
     130        auto& lastRow = rowList.last();
     131        bottom += lastRow.offset + lastRow.height;
     132    } else
     133        ASSERT_NOT_REACHED();
    125134
    126135    auto* formattingContextRoot = &layoutBox;
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r248262 r249172  
    7777    public:
    7878        static HeightAndMargin inFlowHeightAndMargin(const LayoutState&, const Box&, UsedVerticalValues);
    79         static WidthAndMargin inFlowWidthAndMargin(const LayoutState&, const Box&, UsedHorizontalValues);
     79        static WidthAndMargin inFlowWidthAndMargin(LayoutState&, const Box&, UsedHorizontalValues);
    8080
    8181        static Point staticPosition(const LayoutState&, const Box&);
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r248262 r249172  
    277277}
    278278
    279 WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(const LayoutState& layoutState, const Box& layoutBox, UsedHorizontalValues usedValues)
     279WidthAndMargin BlockFormattingContext::Geometry::inFlowWidthAndMargin(LayoutState& layoutState, const Box& layoutBox, UsedHorizontalValues usedValues)
    280280{
    281281    ASSERT(layoutBox.isInFlow());
    282282
    283     if (!layoutBox.replaced())
     283    if (!layoutBox.replaced()) {
     284        if (layoutBox.establishesTableFormattingContext()) {
     285            // This is a special table "fit-content size" behavior handling. Not in the spec though.
     286            // Table returns its final width as min/max. Use this final width value to computed horizontal margins etc.
     287            usedValues.width = Geometry::shrinkToFitWidth(layoutState, layoutBox, usedValues);
     288        }
    284289        return inFlowNonReplacedWidthAndMargin(layoutState, layoutBox, usedValues);
     290    }
    285291    return inFlowReplacedWidthAndMargin(layoutState, layoutBox, usedValues);
    286292}
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.cpp

    r248834 r249172  
    3838WTF_MAKE_ISO_ALLOCATED_IMPL(TableFormattingContext);
    3939
     40// https://www.w3.org/TR/css-tables-3/#table-layout-algorithm
    4041TableFormattingContext::TableFormattingContext(const Box& formattingContextRoot, TableFormattingState& formattingState)
    4142    : FormattingContext(formattingContextRoot, formattingState)
     
    4546void TableFormattingContext::layout() const
    4647{
    47     // https://www.w3.org/TR/css-tables-3/#table-layout-algorithm
    48     // To layout a table, user agents must apply the following actions:
     48    ASSERT(!formattingState().tableGrid().cells().isEmpty());
     49}
     50
     51FormattingContext::IntrinsicWidthConstraints TableFormattingContext::computedIntrinsicWidthConstraints() const
     52{
     53    // Tables have a slighty different concept of shrink to fit. It's really only different with non-auto "width" values, where
     54    // a generic shrink-to fit block level box like a float box would be just sized to the computed value of "width", tables
     55    // can actually be streched way over.
    4956
    5057    // 1. Ensure each cell slot is occupied by at least one cell.
     
    5360    computePreferredWidthForColumns();
    5461    // 3. Compute the width of the table.
    55     computeTableWidth();
    56     // 4. Compute the height of the table.
    57     computeTableHeight();
    58     // 5. Distribute the height of the table among rows.
    59     distributeAvailableHeight();
    60 }
    61 
    62 FormattingContext::IntrinsicWidthConstraints TableFormattingContext::computedIntrinsicWidthConstraints() const
    63 {
    64     return { };
     62    auto width = computedTableWidth();
     63    // This is the actual computed table width that we want to present as min/max width.
     64    return { width, width };
    6565}
    6666
     
    121121}
    122122
    123 void TableFormattingContext::computeTableWidth() const
     123LayoutUnit TableFormattingContext::computedTableWidth() const
    124124{
    125125    // Column and caption widths influence the final table width as follows:
     
    165165    }
    166166
    167     auto& tableDisplayBox = layoutState().displayBoxForLayoutBox(tableWrapperBox);
    168     tableDisplayBox.setContentBoxWidth(usedWidth);
     167    return usedWidth;
    169168}
    170169
     
    180179}
    181180
    182 void TableFormattingContext::computeTableHeight() const
    183 {
    184 }
    185 
    186 void TableFormattingContext::distributeAvailableHeight() const
    187 {
    188 }
    189 
    190181}
    191182}
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h

    r248834 r249172  
    4545private:
    4646    IntrinsicWidthConstraints computedIntrinsicWidthConstraints() const override;
     47    LayoutUnit computedTableWidth() const;
    4748
    4849    void ensureTableGrid() const;
    4950    void computePreferredWidthForColumns() const;
    50     void computeTableWidth() const;
    5151    void distributeAvailableWidth(LayoutUnit extraHorizontalSpace) const;
    52     void computeTableHeight() const;
    53     void distributeAvailableHeight() const;
    5452
    5553    TableFormattingState& formattingState() const { return downcast<TableFormattingState>(FormattingContext::formattingState()); }
  • trunk/Source/WebCore/layout/tableformatting/TableGrid.h

    r248834 r249172  
    102102
    103103    struct Row {
     104        LayoutUnit offset;
    104105        LayoutUnit height;
    105106    };
Note: See TracChangeset for help on using the changeset viewer.