Log Message
[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: 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:
Modified Paths
- trunk/LayoutTests/imported/w3c/ChangeLog
- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp
- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h
- trunk/Source/WebCore/rendering/RenderGrid.cpp
- trunk/Source/WebCore/rendering/RenderGrid.h
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (221930 => 221931)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-09-12 19:17:35 UTC (rev 221930)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2017-09-12 19:19:45 UTC (rev 221931)
@@ -1,5 +1,16 @@
2017-09-12 Manuel Rego Casasnovas <[email protected]>
+ [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 <[email protected]>
+
[css-grid] Use transferred size over content size for automatic minimum size
https://bugs.webkit.org/show_bug.cgi?id=176688
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html (221930 => 221931)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html 2017-09-12 19:17:35 UTC (rev 221930)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid-1/grid-items/grid-minimum-size-grid-items-021.html 2017-09-12 19:19:45 UTC (rev 221931)
@@ -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");
Modified: trunk/Source/WebCore/ChangeLog (221930 => 221931)
--- trunk/Source/WebCore/ChangeLog 2017-09-12 19:17:35 UTC (rev 221930)
+++ trunk/Source/WebCore/ChangeLog 2017-09-12 19:19:45 UTC (rev 221931)
@@ -1,3 +1,44 @@
+2017-09-12 Manuel Rego Casasnovas <[email protected]>
+
+ [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 <[email protected]>
Switch MediaPlayerPrivateAVFoundation to release logging
Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (221930 => 221931)
--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2017-09-12 19:17:35 UTC (rev 221930)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2017-09-12 19:19:45 UTC (rev 221931)
@@ -970,6 +970,7 @@
{
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 @@
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::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 @@
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 @@
m_contentSizedTracksIndex.shrink(0);
m_flexibleSizedTracksIndex.shrink(0);
+ m_autoSizedTracksIndex.shrink(0);
setFreeSpace(direction, freeSpace);
tracks(direction).resize(numTracks);
@@ -1150,11 +1179,11 @@
// 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 @@
m_rows.shrink(0);
m_contentSizedTracksIndex.shrink(0);
m_flexibleSizedTracksIndex.shrink(0);
+ m_autoSizedTracksIndex.shrink(0);
setAvailableSpace(ForRows, std::nullopt);
setAvailableSpace(ForColumns, std::nullopt);
}
Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h (221930 => 221931)
--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h 2017-09-12 19:17:35 UTC (rev 221930)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h 2017-09-12 19:19:45 UTC (rev 221931)
@@ -153,6 +153,7 @@
void initializeTrackSizes();
void resolveIntrinsicTrackSizes();
void stretchFlexibleTracks(std::optional<LayoutUnit> freeSpace);
+ void stretchAutoTracks();
// State machine.
void advanceNextState();
@@ -171,6 +172,7 @@
Vector<GridTrack> m_rows;
Vector<unsigned> m_contentSizedTracksIndex;
Vector<unsigned> m_flexibleSizedTracksIndex;
+ Vector<unsigned> m_autoSizedTracksIndex;
GridTrackSizingDirection m_direction;
SizingOperation m_sizingOperation;
Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (221930 => 221931)
--- trunk/Source/WebCore/rendering/RenderGrid.cpp 2017-09-12 19:17:35 UTC (rev 221930)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp 2017-09-12 19:19:45 UTC (rev 221931)
@@ -305,9 +305,6 @@
setLogicalHeight(std::max(logicalHeight(), minHeightForEmptyLine));
}
- applyStretchAlignmentToTracksIfNeeded(ForColumns);
- applyStretchAlignmentToTracksIfNeeded(ForRows);
-
layoutGridItems();
m_trackSizingAlgorithm.reset();
@@ -880,42 +877,12 @@
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);
Modified: trunk/Source/WebCore/rendering/RenderGrid.h (221930 => 221931)
--- trunk/Source/WebCore/rendering/RenderGrid.h 2017-09-12 19:17:35 UTC (rev 221930)
+++ trunk/Source/WebCore/rendering/RenderGrid.h 2017-09-12 19:19:45 UTC (rev 221931)
@@ -65,6 +65,8 @@
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 @@
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;
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
