Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1548)

Unified Diff: Source/core/rendering/RenderGrid.cpp

Issue 450093004: [CSS Grid Layout] Handle percentages of indefinite sizes in minmax() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added support for indefinite percentages in grid-auto-* Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/rendering/RenderGrid.cpp
diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp
index 4f474611800d3c8b62ce686754120dfe0f489ba7..b91e62d18ea01a2ee3cbe04caf376dc725ea2a23 100644
--- a/Source/core/rendering/RenderGrid.cpp
+++ b/Source/core/rendering/RenderGrid.cpp
@@ -418,7 +418,7 @@ void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
// 1. Initialize per Grid track variables.
for (size_t i = 0; i < tracks.size(); ++i) {
GridTrack& track = tracks[i];
- const GridTrackSize& trackSize = gridTrackSize(direction, i);
+ GridTrackSize trackSize = gridTrackSize(direction, i);
const GridLength& minTrackBreadth = trackSize.minTrackBreadth();
const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth();
@@ -472,7 +472,7 @@ void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
} else {
for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) {
const size_t trackIndex = flexibleSizedTracksIndex[i];
- const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex);
+ GridTrackSize trackSize = gridTrackSize(direction, trackIndex);
normalizedFractionBreadth = std::max(normalizedFractionBreadth, tracks[trackIndex].m_usedBreadth / trackSize.maxTrackBreadth().flex());
}
@@ -494,7 +494,7 @@ void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) {
const size_t trackIndex = flexibleSizedTracksIndex[i];
- const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex);
+ GridTrackSize trackSize = gridTrackSize(direction, trackIndex);
tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackIndex].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex());
}
@@ -549,7 +549,7 @@ double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
Vector<GridTrackForNormalization> tracksForNormalization;
for (GridSpan::iterator resolvedPosition = tracksSpan.begin(); resolvedPosition != tracksSpan.end(); ++resolvedPosition) {
- const GridTrackSize& trackSize = gridTrackSize(direction, resolvedPosition.toInt());
+ GridTrackSize trackSize = gridTrackSize(direction, resolvedPosition.toInt());
if (!trackSize.maxTrackBreadth().isFlex())
continue;
@@ -587,20 +587,19 @@ double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions;
}
-const GridTrackSize& RenderGrid::gridTrackSize(GridTrackSizingDirection direction, size_t i) const
+GridTrackSize RenderGrid::gridTrackSize(GridTrackSizingDirection direction, size_t i) const
{
- const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style()->gridTemplateColumns() : style()->gridTemplateRows();
- if (i >= trackStyles.size())
- return (direction == ForColumns) ? style()->gridAutoColumns() : style()->gridAutoRows();
-
- const GridTrackSize& trackSize = trackStyles[i];
- // If the logical width/height of the grid container is indefinite, percentage values are treated as <auto>.
- if (trackSize.isPercentage()) {
- Length logicalSize = direction == ForColumns ? style()->logicalWidth() : style()->logicalHeight();
- if (logicalSize.isIntrinsicOrAuto()) {
- DEFINE_STATIC_LOCAL(GridTrackSize, autoTrackSize, (Length(Auto)));
- return autoTrackSize;
- }
+ bool isForColumns = direction == ForColumns;
+ const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTemplateColumns() : style()->gridTemplateRows();
+ const GridTrackSize& trackSize = (i >= trackStyles.size()) ? (isForColumns ? style()->gridAutoColumns() : style()->gridAutoRows()) : trackStyles[i];
+
+ // If the logical width/height of the grid container is indefinite, percentage values are treated as <auto> (or in
+ // the case of minmax() as min-content for the first position and max-content for the second).
+ Length logicalSize = isForColumns ? style()->logicalWidth() : style()->logicalHeight();
+ if (logicalSize.isIntrinsicOrAuto()) {
Julien - ping for review 2014/09/10 01:00:17 Note that this is not the exact definition of 'ind
svillar 2014/09/10 15:03:09 Correct.
+ const GridLength& oldMinTrackBreadth = trackSize.minTrackBreadth();
+ const GridLength& oldMaxTrackBreadth = trackSize.maxTrackBreadth();
+ return GridTrackSize(oldMinTrackBreadth.isPercentage() ? Length(MinContent) : oldMinTrackBreadth, oldMaxTrackBreadth.isPercentage() ? Length(MaxContent) : oldMaxTrackBreadth);
}
return trackSize;
@@ -715,7 +714,7 @@ void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
sizingData.filteredTracks.shrink(0);
for (GridResolvedPosition trackPosition = initialTrackPosition; trackPosition <= finalTrackPosition; ++trackPosition) {
- const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition.toInt());
+ GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt());
if (!(trackSize.*filterFunction)())
continue;
@@ -793,7 +792,7 @@ void RenderGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, Vector<Grid
bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection direction, const Vector<GridTrack>& tracks)
{
for (size_t i = 0; i < tracks.size(); ++i) {
- const GridTrackSize& trackSize = gridTrackSize(direction, i);
+ GridTrackSize trackSize = gridTrackSize(direction, i);
const GridLength& minTrackBreadth = trackSize.minTrackBreadth();
if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i].m_usedBreadth)
return false;

Powered by Google App Engine
This is Rietveld 408576698