Changeset 275462 in webkit


Ignore:
Timestamp:
Apr 5, 2021 5:42:08 PM (3 years ago)
Author:
Cameron McCormack
Message:

Fix max-content on tables with percentage cell widths.
https://bugs.webkit.org/show_bug.cgi?id=221165

Reviewed by Zalan Bujtas.

Source/WebCore:

When width: max-content is specified on an element, any percentages
on content inside the element that are relative to the containing block
width should be treated as auto. Percentages on table cells and columns
in tables using auto table layout are not quite relative to the
containing block width, but do have a similar influence. So when
computing the intrinsic width of a table for the purpose of determining
the max-content value to use, ignore any percentages specified on table
cells and columns.

This change makes us match Firefox and Chrome on the test case.

Test: fast/table/percent-width-max-content.html

  • rendering/AutoTableLayout.cpp:

(WebCore::AutoTableLayout::computeIntrinsicLogicalWidths):

  • rendering/AutoTableLayout.h:
  • rendering/FixedTableLayout.cpp:

(WebCore::FixedTableLayout::computeIntrinsicLogicalWidths):

  • rendering/FixedTableLayout.h:
  • rendering/RenderBox.cpp:

(WebCore::RenderBox::computeIntrinsicLogicalWidthUsing const): Call
into the new computeIntrinsicKeywordLogicalWidths function so that
tables can return different values for layout and intrinsic keyword
calculation.

  • rendering/RenderBox.h:

(WebCore::RenderBox::computeIntrinsicKeywordLogicalWidths const):
Added to support computing intrinsic keyword lengths that differ from
those returned by computeIntrinsicLogicalWidths.

  • rendering/RenderTable.cpp:

(WebCore::RenderTable::computeIntrinsicLogicalWidths const): Factored
this out to allow specifying an argument for whether the intrinsics
being computed are for layout or for instrinsic keyword calculation,
like max-content.
(WebCore::RenderTable::computeIntrinsicKeywordLogicalWidths const):
Added. This is the only override of the default implementation in
RenderBox.

  • rendering/RenderTable.h:
  • rendering/TableLayout.h:

LayoutTests:

Fix max-content on tables with percentage cell widths.

  • fast/table/percent-width-max-content-expected.html: Added.
  • fast/table/percent-width-max-content.html: Added.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r275456 r275462  
     12021-04-05  Cameron McCormack  <heycam@apple.com>
     2
     3        Fix max-content on tables with percentage cell widths.
     4        https://bugs.webkit.org/show_bug.cgi?id=221165
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Fix max-content on tables with percentage cell widths.
     9
     10        * fast/table/percent-width-max-content-expected.html: Added.
     11        * fast/table/percent-width-max-content.html: Added.
     12
    1132021-04-05  Devin Rousso  <drousso@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r275459 r275462  
     12021-04-05  Cameron McCormack  <heycam@apple.com>
     2
     3        Fix max-content on tables with percentage cell widths.
     4        https://bugs.webkit.org/show_bug.cgi?id=221165
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        When `width: max-content` is specified on an element, any percentages
     9        on content inside the element that are relative to the containing block
     10        width should be treated as auto.  Percentages on table cells and columns
     11        in tables using auto table layout are not quite relative to the
     12        containing block width, but do have a similar influence.  So when
     13        computing the intrinsic width of a table for the purpose of determining
     14        the max-content value to use, ignore any percentages specified on table
     15        cells and columns.
     16
     17        This change makes us match Firefox and Chrome on the test case.
     18
     19        Test: fast/table/percent-width-max-content.html
     20
     21        * rendering/AutoTableLayout.cpp:
     22        (WebCore::AutoTableLayout::computeIntrinsicLogicalWidths):
     23        * rendering/AutoTableLayout.h:
     24        * rendering/FixedTableLayout.cpp:
     25        (WebCore::FixedTableLayout::computeIntrinsicLogicalWidths):
     26        * rendering/FixedTableLayout.h:
     27        * rendering/RenderBox.cpp:
     28        (WebCore::RenderBox::computeIntrinsicLogicalWidthUsing const): Call
     29        into the new computeIntrinsicKeywordLogicalWidths function so that
     30        tables can return different values for layout and intrinsic keyword
     31        calculation.
     32        * rendering/RenderBox.h:
     33        (WebCore::RenderBox::computeIntrinsicKeywordLogicalWidths const):
     34        Added to support computing intrinsic keyword lengths that differ from
     35        those returned by computeIntrinsicLogicalWidths.
     36        * rendering/RenderTable.cpp:
     37        (WebCore::RenderTable::computeIntrinsicLogicalWidths const): Factored
     38        this out to allow specifying an argument for whether the intrinsics
     39        being computed are for layout or for instrinsic keyword calculation,
     40        like max-content.
     41        (WebCore::RenderTable::computeIntrinsicKeywordLogicalWidths const):
     42        Added.  This is the only override of the default implementation in
     43        RenderBox.
     44        * rendering/RenderTable.h:
     45        * rendering/TableLayout.h:
     46
    1472021-04-05  Myles C. Maxfield  <mmaxfield@apple.com>
    248
  • trunk/Source/WebCore/rendering/AutoTableLayout.cpp

    r272805 r275462  
    238238}
    239239
    240 void AutoTableLayout::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth)
     240void AutoTableLayout::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth, TableIntrinsics intrinsics)
    241241{
    242242    fullRecalc();
     
    247247    float maxPercent = 0;
    248248    float maxNonPercent = 0;
    249     bool scaleColumnsForSelf = shouldScaleColumnsForSelf(m_table);
     249    bool scaleColumnsForSelf = shouldScaleColumnsForSelf(m_table) && intrinsics == TableIntrinsics::ForLayout;
    250250
    251251    // We substitute 0 percent by (epsilon / percentScaleFactor) percent in two places below to avoid division by zero.
  • trunk/Source/WebCore/rendering/AutoTableLayout.h

    r233148 r275462  
    3636    virtual ~AutoTableLayout();
    3737
    38     void computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth) override;
     38    void computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth, TableIntrinsics) override;
    3939    LayoutUnit scaledWidthFromPercentColumns() const override { return m_scaledWidthFromPercentColumns; }
    4040    void applyPreferredLogicalWidthQuirks(LayoutUnit& minWidth, LayoutUnit& maxWidth) const override;
  • trunk/Source/WebCore/rendering/FixedTableLayout.cpp

    r272805 r275462  
    170170}
    171171
    172 void FixedTableLayout::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth)
     172void FixedTableLayout::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth, TableIntrinsics)
    173173{
    174174    minWidth = maxWidth = calcWidthArray();
  • trunk/Source/WebCore/rendering/FixedTableLayout.h

    r208668 r275462  
    3434    explicit FixedTableLayout(RenderTable*);
    3535
    36     void computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth) override;
     36    void computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth, TableIntrinsics) override;
    3737    void applyPreferredLogicalWidthQuirks(LayoutUnit& minWidth, LayoutUnit& maxWidth) const override;
    3838    void layout() override;
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r275430 r275462  
    26182618        minLogicalWidth = maxLogicalWidth = computeLogicalWidthFromAspectRatio();
    26192619    else
    2620         computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth);
     2620        computeIntrinsicKeywordLogicalWidths(minLogicalWidth, maxLogicalWidth);
    26212621
    26222622    if (logicalWidthLength.isMinContent() || logicalWidthLength.isMinIntrinsic())
  • trunk/Source/WebCore/rendering/RenderBox.h

    r275413 r275462  
    752752
    753753    virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
     754    virtual void computeIntrinsicKeywordLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
     755    {
     756        computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth);
     757    }
    754758
    755759    // This function calculates the minimum and maximum preferred widths for an object.
  • trunk/Source/WebCore/rendering/RenderTable.cpp

    r275413 r275462  
    803803}
    804804
    805 void RenderTable::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth) const
     805void RenderTable::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth, TableIntrinsics intrinsics) const
    806806{
    807807    recalcSectionsIfNeeded();
     
    811811    const_cast<RenderTable*>(this)->recalcBordersInRowDirection();
    812812    // FIXME: Restructure the table layout code so that we can make this method const.
    813     const_cast<RenderTable*>(this)->m_tableLayout->computeIntrinsicLogicalWidths(minWidth, maxWidth);
     813    const_cast<RenderTable*>(this)->m_tableLayout->computeIntrinsicLogicalWidths(minWidth, maxWidth, intrinsics);
    814814
    815815    // FIXME: We should include captions widths here like we do in computePreferredLogicalWidths.
     816}
     817
     818void RenderTable::computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth) const
     819{
     820    computeIntrinsicLogicalWidths(minWidth, maxWidth, TableIntrinsics::ForLayout);
     821}
     822
     823void RenderTable::computeIntrinsicKeywordLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth) const
     824{
     825    computeIntrinsicLogicalWidths(minWidth, maxWidth, TableIntrinsics::ForKeyword);
    816826}
    817827
  • trunk/Source/WebCore/rendering/RenderTable.h

    r275413 r275462  
    4141
    4242enum SkipEmptySectionsValue { DoNotSkipEmptySections, SkipEmptySections };
     43enum class TableIntrinsics : uint8_t { ForLayout, ForKeyword };
    4344
    4445class RenderTable : public RenderBlock {
     
    289290    void paintMask(PaintInfo&, const LayoutPoint&) final;
    290291    void layout() final;
     292    void computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth, TableIntrinsics) const;
    291293    void computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth) const final;
     294    void computeIntrinsicKeywordLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth) const final;
    292295    void computePreferredLogicalWidths() override;
    293296    bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override;
  • trunk/Source/WebCore/rendering/TableLayout.h

    r253987 r275462  
    2929class RenderTable;
    3030
     31enum class TableIntrinsics : uint8_t;
     32
    3133DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(TableLayout);
    3234class TableLayout {
     
    4143    virtual ~TableLayout() = default;
    4244
    43     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth) = 0;
     45    virtual void computeIntrinsicLogicalWidths(LayoutUnit& minWidth, LayoutUnit& maxWidth, TableIntrinsics) = 0;
    4446    virtual LayoutUnit scaledWidthFromPercentColumns() const { return 0_lu; }
    4547    virtual void applyPreferredLogicalWidthQuirks(LayoutUnit& minWidth, LayoutUnit& maxWidth) const = 0;
Note: See TracChangeset for help on using the changeset viewer.