Skip to content
Permalink
Browse files
[css-grid] Stretching auto tracks should be done as part of the track…
… sizing algorithm

https://bugs.webkit.org/show_bug.cgi?id=176783

Reviewed by Sergio Villar Senin.

LayoutTests/imported/w3c:

Import changes on the test related to the new behavior.

* web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html:

Source/WebCore:

CSS WG has agreed to modify the track sizing algorithm to include
a new step: https://drafts.csswg.org/css-grid/#algo-stretch
We used to do the stretch of the "auto" tracks at the end of
the track sizing algorithm, however this change integrates it
into the algorithm itself as the last step.
See: w3c/csswg-drafts#1150

The patch moves the method
RenderGrid::applyStretchAlignmentToTracksIfNeeded() to
GridTrackSizingAlgorithm::stretchAutoTracks().
And then modifies the grid track sizing algorithm to execute
the new step.

This patch uses the WPT test updated to check the new behavior.

* rendering/GridTrackSizingAlgorithm.cpp:
(WebCore::GridTrackSizingAlgorithm::initializeTrackSizes): Initialize
the list of auto tracks.
(WebCore::GridTrackSizingAlgorithm::stretchFlexibleTracks): Add
early return if there are not flexible tracks.
(WebCore::GridTrackSizingAlgorithm::stretchAutoTracks): Code moved from
RenderGrid::applyStretchAlignmentToTracksIfNeeded().
(WebCore::GridTrackSizingAlgorithm::setup): Reset list of auto tracks.
(WebCore::GridTrackSizingAlgorithm::run): Add new step
stretchAutoTracks().
(WebCore::GridTrackSizingAlgorithm::reset): Reset auto tracks.
* rendering/GridTrackSizingAlgorithm.h: Add m_autoSizedTracksIndex.
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutBlock): Avoid applying stretch here.
(WebCore::RenderGrid::contentAlignmentNormalBehaviorGrid): Make public.
(WebCore::RenderGrid::applyStretchAlignmentToTracksIfNeeded): Moved to
GridTrackSizingAlgorithm::stretchAutoTracks().
* rendering/RenderGrid.h:


Canonical link: https://commits.webkit.org/193271@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221931 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
mrego committed Sep 12, 2017
1 parent c0ab7e5 commit 3882da927cbaef0cde63585d5f1112185c527ccf
Showing 7 changed files with 94 additions and 43 deletions.
@@ -1,3 +1,14 @@
2017-09-12 Manuel Rego Casasnovas <rego@igalia.com>

[css-grid] Stretching auto tracks should be done as part of the track sizing algorithm
https://bugs.webkit.org/show_bug.cgi?id=176783

Reviewed by Sergio Villar Senin.

Import changes on the test related to the new behavior.

* web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html:

2017-09-12 Manuel Rego Casasnovas <rego@igalia.com>

[css-grid] Use transferred size over content size for automatic minimum size
@@ -68,14 +68,14 @@
function runTests() {
checkGridSizeTracksAndImageSize("grid-1", "img-1", "200px", "200px", "200px", "200px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-2", "img-2", "10px", "10px", "200px", "200px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-3", "img-3", "200px", "50px", "200px", "50px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-4", "img-4", "200px", "10px", "200px", "50px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-3", "img-3", "200px", "200px", "200px", "200px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-4", "img-4", "200px", "10px", "200px", "200px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-5", "img-5", "200px", "50px", "50px", "50px", "50px", "50px");
checkGridSizeTracksAndImageSize("grid-6", "img-6", "200px", "10px", "50px", "50px", "50px", "50px");
checkGridSizeTracksAndImageSize("grid-7", "img-7", "200px", "225px", "200px", "200px 25px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-8", "img-8", "10px", "10px", "200px", "200px 25px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-9", "img-9", "200px", "125px", "200px", "100px 25px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-10", "img-10", "200px", "10px", "200px", "100px 25px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-9", "img-9", "200px", "225px", "200px", "200px 25px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-10", "img-10", "200px", "10px", "200px", "200px 25px", "200px", "200px");
checkGridSizeTracksAndImageSize("grid-11", "img-11", "200px", "125px", "100px", "100px 25px", "100px", "100px");
checkGridSizeTracksAndImageSize("grid-12", "img-12", "200px", "10px", "100px", "100px 25px", "100px", "100px");
checkGridSizeTracksAndImageSize("grid-13", "img-13", "200px", "200px", "200px", "200px", "200px", "200px");
@@ -1,3 +1,44 @@
2017-09-12 Manuel Rego Casasnovas <rego@igalia.com>

[css-grid] Stretching auto tracks should be done as part of the track sizing algorithm
https://bugs.webkit.org/show_bug.cgi?id=176783

Reviewed by Sergio Villar Senin.

CSS WG has agreed to modify the track sizing algorithm to include
a new step: https://drafts.csswg.org/css-grid/#algo-stretch
We used to do the stretch of the "auto" tracks at the end of
the track sizing algorithm, however this change integrates it
into the algorithm itself as the last step.
See: https://github.com/w3c/csswg-drafts/issues/1150

The patch moves the method
RenderGrid::applyStretchAlignmentToTracksIfNeeded() to
GridTrackSizingAlgorithm::stretchAutoTracks().
And then modifies the grid track sizing algorithm to execute
the new step.

This patch uses the WPT test updated to check the new behavior.

* rendering/GridTrackSizingAlgorithm.cpp:
(WebCore::GridTrackSizingAlgorithm::initializeTrackSizes): Initialize
the list of auto tracks.
(WebCore::GridTrackSizingAlgorithm::stretchFlexibleTracks): Add
early return if there are not flexible tracks.
(WebCore::GridTrackSizingAlgorithm::stretchAutoTracks): Code moved from
RenderGrid::applyStretchAlignmentToTracksIfNeeded().
(WebCore::GridTrackSizingAlgorithm::setup): Reset list of auto tracks.
(WebCore::GridTrackSizingAlgorithm::run): Add new step
stretchAutoTracks().
(WebCore::GridTrackSizingAlgorithm::reset): Reset auto tracks.
* rendering/GridTrackSizingAlgorithm.h: Add m_autoSizedTracksIndex.
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutBlock): Avoid applying stretch here.
(WebCore::RenderGrid::contentAlignmentNormalBehaviorGrid): Make public.
(WebCore::RenderGrid::applyStretchAlignmentToTracksIfNeeded): Moved to
GridTrackSizingAlgorithm::stretchAutoTracks().
* rendering/RenderGrid.h:

2017-09-12 Eric Carlson <eric.carlson@apple.com>

Switch MediaPlayerPrivateAVFoundation to release logging
@@ -970,6 +970,7 @@ void GridTrackSizingAlgorithm::initializeTrackSizes()
{
ASSERT(m_contentSizedTracksIndex.isEmpty());
ASSERT(m_flexibleSizedTracksIndex.isEmpty());
ASSERT(m_autoSizedTracksIndex.isEmpty());

Vector<GridTrack>& allTracks = tracks(m_direction);
const bool hasDefiniteFreeSpace = !!availableSpace();
@@ -992,6 +993,8 @@ void GridTrackSizingAlgorithm::initializeTrackSizes()
m_contentSizedTracksIndex.append(i);
if (trackSize.maxTrackBreadth().isFlex())
m_flexibleSizedTracksIndex.append(i);
if (trackSize.hasAutoMaxTrackBreadth())
m_autoSizedTracksIndex.append(i);
}
}

@@ -1039,6 +1042,9 @@ void GridTrackSizingAlgorithm::resolveIntrinsicTrackSizes()

void GridTrackSizingAlgorithm::stretchFlexibleTracks(std::optional<LayoutUnit> freeSpace)
{
if (m_flexibleSizedTracksIndex.isEmpty())
return;

double flexFraction = m_strategy->findUsedFlexFraction(m_flexibleSizedTracksIndex, m_direction, freeSpace);

LayoutUnit totalGrowth;
@@ -1063,6 +1069,28 @@ void GridTrackSizingAlgorithm::stretchFlexibleTracks(std::optional<LayoutUnit> f
m_maxContentSize += totalGrowth;
}

void GridTrackSizingAlgorithm::stretchAutoTracks()
{
if (m_autoSizedTracksIndex.isEmpty())
return;

auto currentFreeSpace = freeSpace(m_direction);
if (!currentFreeSpace
|| currentFreeSpace.value() <= 0
|| (m_direction == ForColumns && m_renderGrid->style().resolvedJustifyContentDistribution(m_renderGrid->contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch)
|| (m_direction == ForRows && m_renderGrid->style().resolvedAlignContentDistribution(m_renderGrid->contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch))
return;

Vector<GridTrack>& allTracks = tracks(m_direction);
unsigned numberOfAutoSizedTracks = m_autoSizedTracksIndex.size();
LayoutUnit sizeToIncrease = currentFreeSpace.value() / numberOfAutoSizedTracks;
for (const auto& trackIndex : m_autoSizedTracksIndex) {
auto& track = allTracks[trackIndex];
track.setBaseSize(track.baseSize() + sizeToIncrease);
}
setFreeSpace(m_direction, LayoutUnit());
}

void GridTrackSizingAlgorithm::advanceNextState()
{
switch (m_sizingState) {
@@ -1117,6 +1145,7 @@ void GridTrackSizingAlgorithm::setup(GridTrackSizingDirection direction, unsigne

m_contentSizedTracksIndex.shrink(0);
m_flexibleSizedTracksIndex.shrink(0);
m_autoSizedTracksIndex.shrink(0);

setFreeSpace(direction, freeSpace);
tracks(direction).resize(numTracks);
@@ -1150,11 +1179,11 @@ void GridTrackSizingAlgorithm::run()
// Step 3.
m_strategy->maximizeTracks(tracks(m_direction), m_direction == ForColumns ? m_freeSpaceColumns : m_freeSpaceRows);

if (m_flexibleSizedTracksIndex.isEmpty())
return;

// Step 4.
stretchFlexibleTracks(initialFreeSpace);

// Step 5.
stretchAutoTracks();
}

void GridTrackSizingAlgorithm::reset()
@@ -1164,6 +1193,7 @@ void GridTrackSizingAlgorithm::reset()
m_rows.shrink(0);
m_contentSizedTracksIndex.shrink(0);
m_flexibleSizedTracksIndex.shrink(0);
m_autoSizedTracksIndex.shrink(0);
setAvailableSpace(ForRows, std::nullopt);
setAvailableSpace(ForColumns, std::nullopt);
}
@@ -153,6 +153,7 @@ class GridTrackSizingAlgorithm final {
void initializeTrackSizes();
void resolveIntrinsicTrackSizes();
void stretchFlexibleTracks(std::optional<LayoutUnit> freeSpace);
void stretchAutoTracks();

// State machine.
void advanceNextState();
@@ -171,6 +172,7 @@ class GridTrackSizingAlgorithm final {
Vector<GridTrack> m_rows;
Vector<unsigned> m_contentSizedTracksIndex;
Vector<unsigned> m_flexibleSizedTracksIndex;
Vector<unsigned> m_autoSizedTracksIndex;

GridTrackSizingDirection m_direction;
SizingOperation m_sizingOperation;
@@ -305,9 +305,6 @@ void RenderGrid::layoutBlock(bool relayoutChildren, LayoutUnit)
setLogicalHeight(std::max(logicalHeight(), minHeightForEmptyLine));
}

applyStretchAlignmentToTracksIfNeeded(ForColumns);
applyStretchAlignmentToTracksIfNeeded(ForRows);

layoutGridItems();
m_trackSizingAlgorithm.reset();

@@ -880,42 +877,12 @@ Vector<LayoutUnit> RenderGrid::trackSizesForComputedStyle(GridTrackSizingDirecti
return tracks;
}

static const StyleContentAlignmentData& contentAlignmentNormalBehaviorGrid()
const StyleContentAlignmentData& RenderGrid::contentAlignmentNormalBehaviorGrid()
{
static const StyleContentAlignmentData normalBehavior = {ContentPositionNormal, ContentDistributionStretch};
return normalBehavior;
}

void RenderGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction)
{
std::optional<LayoutUnit> freeSpace = m_trackSizingAlgorithm.freeSpace(direction);
if (!freeSpace
|| freeSpace.value() <= 0
|| (direction == ForColumns && style().resolvedJustifyContentDistribution(contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch)
|| (direction == ForRows && style().resolvedAlignContentDistribution(contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch))
return;

// Spec defines auto-sized tracks as the ones with an 'auto' max-sizing function.
Vector<GridTrack>& allTracks = m_trackSizingAlgorithm.tracks(direction);
Vector<unsigned> autoSizedTracksIndex;
for (unsigned i = 0; i < allTracks.size(); ++i) {
const GridTrackSize& trackSize = m_trackSizingAlgorithm.gridTrackSize(direction, i);
if (trackSize.hasAutoMaxTrackBreadth())
autoSizedTracksIndex.append(i);
}

unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size();
if (numberOfAutoSizedTracks < 1)
return;

LayoutUnit sizeToIncrease = freeSpace.value() / numberOfAutoSizedTracks;
for (const auto& trackIndex : autoSizedTracksIndex) {
auto& track = allTracks[trackIndex];
track.setBaseSize(track.baseSize() + sizeToIncrease);
}
m_trackSizingAlgorithm.setFreeSpace(direction, LayoutUnit());
}

void RenderGrid::layoutGridItems()
{
populateGridPositionsForDirection(ForColumns);
@@ -65,6 +65,8 @@ class RenderGrid final : public RenderBlock {
bool isOrthogonalChild(const RenderBox&) const;
LayoutUnit guttersSize(const Grid&, GridTrackSizingDirection, unsigned startLine, unsigned span, std::optional<LayoutUnit> availableSize) const;

static const StyleContentAlignmentData& contentAlignmentNormalBehaviorGrid();

protected:
ItemPosition selfAlignmentNormalBehavior(const RenderBox* child = nullptr) const override
{
@@ -132,8 +134,6 @@ class RenderGrid final : public RenderBlock {

LayoutUnit gridAreaBreadthForChildIncludingAlignmentOffsets(const RenderBox&, GridTrackSizingDirection) const;

void applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection);

void paintChildren(PaintInfo& forSelf, const LayoutPoint& paintOffset, PaintInfo& forChild, bool usePrintRect) override;
LayoutUnit marginLogicalSizeForChild(GridTrackSizingDirection, const RenderBox&) const;
LayoutUnit computeMarginLogicalSizeForChild(GridTrackSizingDirection, const RenderBox&) const;

0 comments on commit 3882da9

Please sign in to comment.