Changeset 286593 in webkit


Ignore:
Timestamp:
Dec 7, 2021 2:20:24 AM (8 months ago)
Author:
svillar@igalia.com
Message:

[css-flexbox] Account for captions when flexing tables with specified sizes
https://bugs.webkit.org/show_bug.cgi?id=233814

Reviewed by Darin Adler.

Source/WebCore:

Flexing tables is complex because of the specifics of the table layout algorithms. There are
two interrelated issues that were causing some failures in flexbox WPT tests.

The first one is that tables interpret overriding sizes (flexed sizes) as the sizes of rows + captions.
However the specified height of a table only accounts for the heights of the rows, not the captions. That's
why when setting the flexed height of a table we must add up the specified height of the table and the height
of the captions. The table algorithm will properly substract the captions' size in order to compute the
available height for rows.

The second issue is that the table layout algorithm adds the size of the bottom border at the very end
of its execution after performing all the computations and it does it unconditionally. The thing is that
the flexbox code already takes into account the borders and paddings so we basically have to substract that
border when setting the height of the table, because the table layout will add it later.

  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::computeMainAxisExtentForChild):

  • rendering/RenderTable.cpp:

(WebCore::RenderTable::computeCaptionsLogicalHeight const): New method refactored from current code.
(WebCore::RenderTable::layout):

  • rendering/RenderTable.h: Expose computeCaptionsLogicalHeight.

LayoutTests:

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r286591 r286593  
     12021-12-03  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [css-flexbox] Account for captions when flexing tables with specified sizes
     4        https://bugs.webkit.org/show_bug.cgi?id=233814
     5
     6        Reviewed by Darin Adler.
     7
     8        * TestExpectations: Unskipped two tests that are now passing
     9
    1102021-12-07  Martin Robinson  <mrobinson@webkit.org>
    211
  • trunk/LayoutTests/TestExpectations

    r286591 r286593  
    42254225
    42264226# Tables as flex items.
    4227 webkit.org/b/221473 imported/w3c/web-platform-tests/css/css-flexbox/table-as-item-inflexible-in-column-1.html [ ImageOnlyFailure ]
    4228 webkit.org/b/221473 imported/w3c/web-platform-tests/css/css-flexbox/table-as-item-inflexible-in-column-2.html [ ImageOnlyFailure ]
    42294227webkit.org/b/221473 imported/w3c/web-platform-tests/css/css-flexbox/table-as-item-min-height-1.html [ ImageOnlyFailure ]
    42304228
  • trunk/Source/WebCore/ChangeLog

    r286591 r286593  
     12021-12-03  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [css-flexbox] Account for captions when flexing tables with specified sizes
     4        https://bugs.webkit.org/show_bug.cgi?id=233814
     5
     6        Reviewed by Darin Adler.
     7
     8        Flexing tables is complex because of the specifics of the table layout algorithms. There are
     9        two interrelated issues that were causing some failures in flexbox WPT tests.
     10
     11        The first one is that tables interpret overriding sizes (flexed sizes) as the sizes of rows + captions.
     12        However the specified height of a table only accounts for the heights of the rows, not the captions. That's
     13        why when setting the flexed height of a table we must add up the specified height of the table and the height
     14        of the captions. The table algorithm will properly substract the captions' size in order to compute the
     15        available height for rows.
     16
     17        The second issue is that the table layout algorithm adds the size of the bottom border at the very end
     18        of its execution after performing all the computations and it does it unconditionally. The thing is that
     19        the flexbox code already takes into account the borders and paddings so we basically have to substract that
     20        border when setting the height of the table, because the table layout will add it later.
     21
     22        * rendering/RenderFlexibleBox.cpp:
     23        (WebCore::RenderFlexibleBox::computeMainAxisExtentForChild):
     24        * rendering/RenderTable.cpp:
     25        (WebCore::RenderTable::computeCaptionsLogicalHeight const): New method refactored from current code.
     26        (WebCore::RenderTable::layout):
     27        * rendering/RenderTable.h: Expose computeCaptionsLogicalHeight.
     28
    1292021-12-07  Martin Robinson  <mrobinson@webkit.org>
    230
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r286421 r286593  
    4141#include "RenderReplaced.h"
    4242#include "RenderStyleConstants.h"
     43#include "RenderTable.h"
    4344#include "RenderView.h"
    4445#include "WritingMode.h"
     
    653654        if (!height)
    654655            return height;
    655         return height.value() + child.scrollbarLogicalHeight();
     656        // Tables interpret overriding sizes as the size of captions + rows. However the specified height of a table
     657        // only includes the size of the rows. That's why we need to add the size of the captions here so that the table
     658        // layout algorithm behaves appropiately.
     659        LayoutUnit captionsHeight;
     660        if (is<RenderTable>(child) && childMainSizeIsDefinite(child, size))
     661            captionsHeight = downcast<RenderTable>(child).sumCaptionsLogicalHeight();
     662        return *height + child.scrollbarLogicalHeight() + captionsHeight;
    656663    }
    657664
  • trunk/Source/WebCore/rendering/RenderTable.cpp

    r284093 r286593  
    420420}
    421421
     422LayoutUnit RenderTable::sumCaptionsLogicalHeight() const
     423{
     424    LayoutUnit height;
     425    for (auto& caption : m_captions)
     426        height += caption->logicalHeight() + caption->marginBefore() + caption->marginAfter();
     427    return height;
     428}
     429
    422430void RenderTable::layout()
    423431{
     
    506514            computedLogicalHeight = convertStyleLogicalHeightToComputedHeight(logicalHeightLength);
    507515
    508         if (hasOverridingLogicalHeight()) {
    509             LayoutUnit captionLogicalHeight;
    510             for (auto& caption : m_captions)
    511                 captionLogicalHeight += caption->logicalHeight() + caption->marginBefore() + caption->marginAfter();
    512             computedLogicalHeight = std::max(computedLogicalHeight, overridingLogicalHeight() - captionLogicalHeight);
    513         }
     516        if (hasOverridingLogicalHeight())
     517            computedLogicalHeight = std::max(computedLogicalHeight, overridingLogicalHeight() - borderAndPaddingAfter - sumCaptionsLogicalHeight());
    514518
    515519        Length logicalMaxHeightLength = style().logicalMaxHeight();
     
    534538            // overriding or specified height in strict mode, but this value will not be cached.
    535539            shouldCacheIntrinsicContentLogicalHeightForFlexItem = false;
    536             setLogicalHeight(hasOverridingLogicalHeight() ? overridingLogicalHeight() : logicalHeight() + computedLogicalHeight);
     540            setLogicalHeight(hasOverridingLogicalHeight() ? overridingLogicalHeight() - borderAndPaddingAfter : logicalHeight() + computedLogicalHeight);
    537541        }
    538542
  • trunk/Source/WebCore/rendering/RenderTable.h

    r278253 r286593  
    272272    void willInsertTableSection(RenderTableSection& child, RenderObject* beforeChild);
    273273
     274    LayoutUnit sumCaptionsLogicalHeight() const;
     275
    274276protected:
    275277    void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final;
Note: See TracChangeset for help on using the changeset viewer.