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

Unified Diff: Source/core/layout/LayoutGrid.cpp

Issue 1317643005: [css-grid] Fix track sizing algo w/ size restrictions and intrinsic sizes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Simplified code Created 5 years, 3 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/layout/LayoutGrid.cpp
diff --git a/Source/core/layout/LayoutGrid.cpp b/Source/core/layout/LayoutGrid.cpp
index 2de38a480b67dc7c3a5bede6d2eb962a899aec5a..ba38a92665bb356fb14c029dfc5ad8b08f6eb1e9 100644
--- a/Source/core/layout/LayoutGrid.cpp
+++ b/Source/core/layout/LayoutGrid.cpp
@@ -391,9 +391,67 @@ void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
maxLogicalWidth += scrollbarWidth;
}
-bool LayoutGrid::gridElementIsShrinkToFit()
+static bool heightSizedUnderMinContentConstraint(const ComputedStyle& style)
cbiesinger 2015/09/30 15:49:35 I'm somewhat skeptical about this design -- does t
{
- return isFloatingOrOutOfFlowPositioned();
+ return style.logicalMinHeight().isMinContent() || style.logicalHeight().isMinContent() || style.logicalMaxHeight().isMinContent();
+}
+
+static bool heightSizedUnderMaxContentConstraint(const ComputedStyle& style)
+{
+ return style.logicalMinHeight().isMaxContent() || style.logicalHeight().isMaxContent() || style.logicalMaxHeight().isMaxContent();
+}
+
+LayoutUnit LayoutGrid::spaceToDistributeForMaximizeTracks(GridTrackSizingDirection direction, bool hasDefiniteAvailableSpace, const LayoutUnit &tracksBreadth, const LayoutUnit& freeSpace) const
+{
+ if (direction == ForColumns)
+ return freeSpace;
+
+ // Under max-content the freeSpace is infinity unless we have a max-height restriction.
+ if (heightSizedUnderMaxContentConstraint(styleRef())) {
+ if (!styleRef().logicalMaxHeight().isMaxSizeNone())
+ return std::max<LayoutUnit>(0, computeLogicalHeightUsing(MaxSize, styleRef().logicalMaxHeight(), contentLogicalHeight()) - tracksBreadth);
+
+ return infinity;
+ }
+
+ // Under min-content the freeSpace is 0 unless we have a min-height restriction.
+ if (heightSizedUnderMinContentConstraint(styleRef())) {
+ const Length& logicalMinSize = styleRef().logicalMinHeight();
+ if (!logicalMinSize.isZero() || logicalMinSize.isIntrinsic())
+ return std::max<LayoutUnit>(0, computeLogicalHeightUsing(MinSize, styleRef().logicalMinHeight(), contentLogicalHeight()) - tracksBreadth);
+
+ return 0;
+ }
+
+ if (!hasDefiniteAvailableSpace)
+ return infinity;
+
+ return freeSpace;
+}
+
+void LayoutGrid::maximizeTracks(Vector<GridTrack>& tracks, GridSizingData& sizingData, LayoutUnit& spaceToDistribute)
+{
+ if (spaceToDistribute == infinity) {
+ for (auto& track : tracks)
+ track.setBaseSize(track.growthLimit());
+ return;
+ }
+
+ ASSERT(spaceToDistribute >= 0);
+ if (spaceToDistribute == 0)
+ return;
+
+ size_t tracksSize = tracks.size();
+ Vector<GridTrack*> tracksForDistribution(tracksSize);
+ for (size_t i = 0; i < tracksSize; ++i) {
+ tracksForDistribution[i] = tracks.data() + i;
+ tracksForDistribution[i]->setPlannedSize(tracksForDistribution[i]->baseSize());
+ }
+
+ distributeSpaceToTracks<MaximizeTracks>(tracksForDistribution, nullptr, sizingData, spaceToDistribute);
+
+ for (auto* track : tracksForDistribution)
+ track->setBaseSize(track->plannedSize());
}
void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection direction, GridSizingData& sizingData, LayoutUnit& freeSpace)
@@ -429,35 +487,23 @@ void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
freeSpace -= track.baseSize();
}
- const bool hasUndefinedRemainingSpace = (direction == ForRows) ? style()->logicalHeight().isAuto() : gridElementIsShrinkToFit();
-
- if (!hasUndefinedRemainingSpace && freeSpace <= 0)
+ // For columns we already have the right available space because the intrinsic sizes
+ // were previously computed by computeIntrinsicLogicalWidths().
+ const bool hasDefiniteAvailableSpace = (direction == ForRows) ? hasDefiniteLogicalHeight() : true;
+ if (hasDefiniteAvailableSpace && freeSpace <= 0)
return;
// 3. Grow all Grid tracks in GridTracks from their baseSize up to their growthLimit value until freeSpace is exhausted.
- const size_t tracksSize = tracks.size();
- if (!hasUndefinedRemainingSpace) {
- Vector<GridTrack*> tracksForDistribution(tracksSize);
- for (size_t i = 0; i < tracksSize; ++i) {
- tracksForDistribution[i] = tracks.data() + i;
- tracksForDistribution[i]->setPlannedSize(tracksForDistribution[i]->baseSize());
- }
-
- distributeSpaceToTracks<MaximizeTracks>(tracksForDistribution, nullptr, sizingData, freeSpace);
-
- for (auto* track : tracksForDistribution)
- track->setBaseSize(track->plannedSize());
- } else {
- for (auto& track : tracks)
- track.setBaseSize(track.growthLimit());
- }
+ LayoutUnit tracksBreadth = initialFreeSpace - freeSpace;
+ LayoutUnit spaceToDistribute = spaceToDistributeForMaximizeTracks(direction, hasDefiniteAvailableSpace, tracksBreadth, freeSpace);
+ maximizeTracks(tracks, sizingData, spaceToDistribute);
if (flexibleSizedTracksIndex.isEmpty())
return;
// 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction.
double normalizedFractionBreadth = 0;
- if (!hasUndefinedRemainingSpace) {
+ if (hasDefiniteAvailableSpace) {
normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, GridSpan(0, tracks.size() - 1), direction, initialFreeSpace);
} else {
for (const auto& trackIndex : flexibleSizedTracksIndex) {

Powered by Google App Engine
This is Rietveld 408576698