Changeset 287977 in webkit


Ignore:
Timestamp:
Jan 13, 2022 6:41:12 AM (6 months ago)
Author:
Ziran Sun
Message:

[css-grid] Fix rounding of distributed free space to flexible tracks
https://bugs.webkit.org/show_bug.cgi?id=234917

LayoutTests/imported/w3c:

Reviewed by Darin Adler.

Source/WebCore:

Reviewed by Darin Adler.

When computing the growth size for flex sized tracks, the flexFraction multiplied by the flex factor can result
in a non-integer size. However, we floor the stretched size to fit in a LayoutUnit. This means that we may lose
the fractional part of the computation which can cause the entire free space not being distributed evenly. This
fix is to sum up the leftover fractional part from every flexible track to avoid this issue.

It is an import of Chromium GridNG CL at https://chromium-review.googlesource.com/c/chromium/src/+/3193674.

  • rendering/GridTrackSizingAlgorithm.cpp:

(WebCore::GridTrackSizingAlgorithm::computeFlexSizedTracksGrowth const):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/TestExpectations

    r287976 r287977  
    14151415webkit.org/b/231021 imported/w3c/web-platform-tests/css/css-grid/grid-items/percentage-margin-dynamic.html [ ImageOnlyFailure ]
    14161416webkit.org/b/231021 imported/w3c/web-platform-tests/css/css-grid/grid-items/replaced-element-015.html [ ImageOnlyFailure ]
    1417 
    1418 webkit.org/b/234879 imported/w3c/web-platform-tests/css/css-grid/layout-algorithm/flex-tracks-with-fractional-size.html [ ImageOnlyFailure ]
    14191417
    14201418imported/w3c/web-platform-tests/css/css-grid/masonry/tentative/masonry-align-content-001.html [ ImageOnlyFailure ]
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r287927 r287977  
     12022-01-13  Ziran Sun  <zsun@igalia.com>
     2
     3        [css-grid] Fix rounding of distributed free space to flexible tracks
     4        https://bugs.webkit.org/show_bug.cgi?id=234917
     5
     6        Reviewed by Darin Adler.       
     7
    182022-01-12  Sergio Villar Senin  <svillar@igalia.com>
    29
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r287974 r287977  
    19781978webkit.org/b/228153 imported/w3c/web-platform-tests/css/css-grid/abspos/grid-positioned-item-dynamic-change-002.html [ ImageOnlyFailure ]
    19791979webkit.org/b/228153 imported/w3c/web-platform-tests/css/css-grid/abspos/grid-positioned-item-dynamic-change-003.html [ ImageOnlyFailure ]
     1980webkit.org/b/235025 imported/w3c/web-platform-tests/css/css-grid/layout-algorithm/flex-tracks-with-fractional-size.html [ ImageOnlyFailure ]
    19801981webkit.org/b/228153 imported/w3c/web-platform-tests/css/css-lists/content-property/marker-text-matches-armenian.html [ ImageOnlyFailure ]
    19811982webkit.org/b/228153 imported/w3c/web-platform-tests/css/css-lists/content-property/marker-text-matches-decimal.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r287976 r287977  
     12022-01-13  Ziran Sun  <zsun@igalia.com>
     2
     3        [css-grid] Fix rounding of distributed free space to flexible tracks
     4        https://bugs.webkit.org/show_bug.cgi?id=234917
     5
     6        Reviewed by Darin Adler.
     7
     8        When computing the growth size for flex sized tracks, the flexFraction multiplied by the flex factor can result
     9        in a non-integer size. However, we floor the stretched size to fit in a LayoutUnit. This means that we may lose
     10        the fractional part of the computation which can cause the entire free space not being distributed evenly. This
     11        fix is to sum up the leftover fractional part from every flexible track to avoid this issue.
     12
     13        It is an import of Chromium GridNG CL at  https://chromium-review.googlesource.com/c/chromium/src/+/3193674.
     14
     15        * rendering/GridTrackSizingAlgorithm.cpp:
     16        (WebCore::GridTrackSizingAlgorithm::computeFlexSizedTracksGrowth const):
     17
    1182022-01-10  Sergio Villar Senin  <svillar@igalia.com>
    219
  • trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp

    r286148 r287977  
    728728    ASSERT(increments.size() == numFlexTracks);
    729729    const Vector<GridTrack>& allTracks = tracks(m_direction);
     730    // The flexFraction multiplied by the flex factor can result in a non-integer size. Since we floor the stretched size to fit in a LayoutUnit,
     731    // we may lose the fractional part of the computation which can cause the entire free space not being distributed evenly. The leftover
     732    // fractional part from every flexible track are accumulated here to avoid this issue.
     733    double leftOverSize = 0;
    730734    for (size_t i = 0; i < numFlexTracks; ++i) {
    731735        unsigned trackIndex = m_flexibleSizedTracksIndex[i];
     
    733737        ASSERT(trackSize.maxTrackBreadth().isFlex());
    734738        LayoutUnit oldBaseSize = allTracks[trackIndex].baseSize();
    735         LayoutUnit newBaseSize = std::max(oldBaseSize, LayoutUnit(flexFraction * trackSize.maxTrackBreadth().flex()));
     739        double frShare = flexFraction * trackSize.maxTrackBreadth().flex() + leftOverSize;
     740        auto stretchedSize = LayoutUnit(frShare);
     741        LayoutUnit newBaseSize = std::max(oldBaseSize, stretchedSize);
    736742        increments[i] = newBaseSize - oldBaseSize;
    737743        totalGrowth += increments[i];
     744        // In the case that stretchedSize is greater than frShare, we floor it to 0 to avoid a negative leftover.
     745        leftOverSize = std::max(frShare - stretchedSize.toDouble(), 0.0);
    738746    }
    739747}
Note: See TracChangeset for help on using the changeset viewer.