Chromium Code Reviews

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 1920953002: Revert of [css-grid] Implement auto-repeat computation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 283 matching lines...)
294 if (!oldStyle) 294 if (!oldStyle)
295 return; 295 return;
296 296
297 // FIXME: The following checks could be narrowed down if we kept track of wh ich type of grid items we have: 297 // FIXME: The following checks could be narrowed down if we kept track of wh ich type of grid items we have:
298 // - explicit grid size changes impact negative explicitely positioned and a uto-placed grid items. 298 // - explicit grid size changes impact negative explicitely positioned and a uto-placed grid items.
299 // - named grid lines only impact grid items with named grid lines. 299 // - named grid lines only impact grid items with named grid lines.
300 // - auto-flow changes only impacts auto-placed children. 300 // - auto-flow changes only impacts auto-placed children.
301 301
302 if (explicitGridDidResize(*oldStyle) 302 if (explicitGridDidResize(*oldStyle)
303 || namedGridLinesDefinitionDidChange(*oldStyle) 303 || namedGridLinesDefinitionDidChange(*oldStyle)
304 || oldStyle->getGridAutoFlow() != styleRef().getGridAutoFlow() 304 || oldStyle->getGridAutoFlow() != styleRef().getGridAutoFlow())
305 || (diff.needsLayout() && (styleRef().gridAutoRepeatColumns().size() || styleRef().gridAutoRepeatRows().size())))
306 dirtyGrid(); 305 dirtyGrid();
307 } 306 }
308 307
309 bool LayoutGrid::explicitGridDidResize(const ComputedStyle& oldStyle) const 308 bool LayoutGrid::explicitGridDidResize(const ComputedStyle& oldStyle) const
310 { 309 {
311 return oldStyle.gridTemplateColumns().size() != styleRef().gridTemplateColum ns().size() 310 return oldStyle.gridTemplateColumns().size() != styleRef().gridTemplateColum ns().size()
312 || oldStyle.gridTemplateRows().size() != styleRef().gridTemplateRows().s ize() 311 || oldStyle.gridTemplateRows().size() != styleRef().gridTemplateRows().s ize()
313 || oldStyle.namedGridAreaColumnCount() != styleRef().namedGridAreaColumn Count() 312 || oldStyle.namedGridAreaColumnCount() != styleRef().namedGridAreaColumn Count()
314 || oldStyle.namedGridAreaRowCount() != styleRef().namedGridAreaRowCount( ) 313 || oldStyle.namedGridAreaRowCount() != styleRef().namedGridAreaRowCount( );
315 || oldStyle.gridAutoRepeatColumns().size() != styleRef().gridAutoRepeatC olumns().size()
316 || oldStyle.gridAutoRepeatRows().size() != styleRef().gridAutoRepeatRows ().size();
317 } 314 }
318 315
319 bool LayoutGrid::namedGridLinesDefinitionDidChange(const ComputedStyle& oldStyle ) const 316 bool LayoutGrid::namedGridLinesDefinitionDidChange(const ComputedStyle& oldStyle ) const
320 { 317 {
321 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() 318 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines()
322 || oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); 319 || oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines();
323 } 320 }
324 321
325 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi ngData) const 322 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi ngData) const
326 { 323 {
(...skipping 363 matching lines...)
690 child.setOverrideContainingBlockContentLogicalHeight(size); 687 child.setOverrideContainingBlockContentLogicalHeight(size);
691 } 688 }
692 689
693 static bool shouldClearOverrideContainingBlockContentSizeForChild(const LayoutBo x& child, GridTrackSizingDirection direction) 690 static bool shouldClearOverrideContainingBlockContentSizeForChild(const LayoutBo x& child, GridTrackSizingDirection direction)
694 { 691 {
695 if (direction == ForColumns) 692 if (direction == ForColumns)
696 return child.hasRelativeLogicalWidth() || child.styleRef().logicalWidth( ).isIntrinsicOrAuto(); 693 return child.hasRelativeLogicalWidth() || child.styleRef().logicalWidth( ).isIntrinsicOrAuto();
697 return child.hasRelativeLogicalHeight() || child.styleRef().logicalHeight(). isIntrinsicOrAuto(); 694 return child.hasRelativeLogicalHeight() || child.styleRef().logicalHeight(). isIntrinsicOrAuto();
698 } 695 }
699 696
700 const GridTrackSize& LayoutGrid::rawGridTrackSize(GridTrackSizingDirection direc tion, size_t translatedIndex) const 697 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t i) const
701 { 698 {
702 bool isRowAxis = direction == ForColumns; 699 bool isForColumns = direction == ForColumns;
703 const Vector<GridTrackSize>& trackStyles = isRowAxis ? styleRef().gridTempla teColumns() : styleRef().gridTemplateRows(); 700 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl ateColumns() : style()->gridTemplateRows();
704 const Vector<GridTrackSize>& autoRepeatTrackStyles = isRowAxis ? styleRef(). gridAutoRepeatColumns() : styleRef().gridAutoRepeatRows(); 701 const GridTrackSize& autoTrackSize = isForColumns ? style()->gridAutoColumns () : style()->gridAutoRows();
705 const GridTrackSize& autoTrackSize = isRowAxis ? styleRef().gridAutoColumns( ) : styleRef().gridAutoRows(); 702 int translatedIndex = i + (isForColumns ? m_smallestColumnStart : m_smallest RowStart);
706 size_t insertionPoint = isRowAxis ? styleRef().gridAutoRepeatColumnsInsertio nPoint() : styleRef().gridAutoRepeatRowsInsertionPoint(); 703 const GridTrackSize& trackSize = (translatedIndex < 0 || translatedIndex >= static_cast<int>(trackStyles.size())) ? autoTrackSize : trackStyles[translatedIn dex];
707 size_t repetitions = autoRepeatCountForDirection(direction);
708
709 // We should not use GridPositionsResolver::explicitGridXXXCount() for this because the
710 // explicit grid might be larger than the number of tracks in grid-template- rows|columns (if
711 // grid-template-areas is specified for example).
712 size_t explicitTracksCount = trackStyles.size() + repetitions;
713
714 int untranslatedIndexAsInt = translatedIndex + (isRowAxis ? m_smallestColumn Start : m_smallestRowStart);
715 if (untranslatedIndexAsInt < 0)
716 return autoTrackSize;
717
718 size_t untranslatedIndex = static_cast<size_t>(untranslatedIndexAsInt);
719 if (untranslatedIndex >= explicitTracksCount)
720 return autoTrackSize;
721
722 if (LIKELY(!repetitions) || untranslatedIndex < insertionPoint)
723 return trackStyles[untranslatedIndex];
724
725 if (untranslatedIndex < (insertionPoint + repetitions))
726 return autoRepeatTrackStyles[0];
727
728 return trackStyles[untranslatedIndex - repetitions];
729 }
730
731 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t translatedIndex) const
732 {
733 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex );
734 704
735 GridLength minTrackBreadth = trackSize.minTrackBreadth(); 705 GridLength minTrackBreadth = trackSize.minTrackBreadth();
736 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); 706 GridLength maxTrackBreadth = trackSize.maxTrackBreadth();
737 707
738 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto> 708 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>
739 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { 709 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) {
740 if (!hasDefiniteLogicalSize(direction)) { 710 if (!hasDefiniteLogicalSize(direction)) {
741 if (minTrackBreadth.hasPercentage()) 711 if (minTrackBreadth.hasPercentage())
742 minTrackBreadth = Length(Auto); 712 minTrackBreadth = Length(Auto);
743 if (maxTrackBreadth.hasPercentage()) 713 if (maxTrackBreadth.hasPercentage())
(...skipping 461 matching lines...)
1205 ensureGridSize(area.rows.endLine(), area.columns.endLine()); 1175 ensureGridSize(area.rows.endLine(), area.columns.endLine());
1206 1176
1207 for (const auto& row : area.rows) { 1177 for (const auto& row : area.rows) {
1208 for (const auto& column: area.columns) 1178 for (const auto& column: area.columns)
1209 m_grid[row][column].append(&child); 1179 m_grid[row][column].append(&child);
1210 } 1180 }
1211 } 1181 }
1212 1182
1213 size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi on) const 1183 size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi on) const
1214 { 1184 {
1215 bool isRowAxis = direction == ForColumns; 1185 // TODO(svillar): implement the algorithm to compute the number of auto repe at tracks.
1216 const auto& autoRepeatTracks = isRowAxis ? styleRef().gridAutoRepeatColumns( ) : styleRef().gridAutoRepeatRows(); 1186 return 0;
1217
1218 if (!autoRepeatTracks.size())
1219 return 0;
1220
1221 DCHECK_EQ(autoRepeatTracks.size(), static_cast<size_t>(1));
1222 auto autoTrackSize = autoRepeatTracks.at(0);
1223 DCHECK(autoTrackSize.minTrackBreadth().isLength());
1224 DCHECK(!autoTrackSize.minTrackBreadth().isContentSized());
1225
1226 LayoutUnit availableSize = isRowAxis ? availableLogicalWidth() : computeCont entLogicalHeight(MainOrPreferredSize, styleRef().logicalHeight(), LayoutUnit(-1) );
1227 if (availableSize == -1) {
1228 const Length& maxLength = isRowAxis ? styleRef().logicalMaxWidth() : sty leRef().logicalMaxHeight();
1229 if (!maxLength.isMaxSizeNone()) {
1230 availableSize = isRowAxis
1231 ? computeLogicalWidthUsing(MaxSize, maxLength, containingBlockLo gicalWidthForContent(), containingBlock())
1232 : computeContentLogicalHeight(MaxSize, maxLength, LayoutUnit(-1) );
1233 }
1234 } else {
1235 availableSize = isRowAxis
1236 ? constrainLogicalWidthByMinMax(availableSize, availableLogicalWidth (), containingBlock())
1237 : constrainLogicalHeightByMinMax(availableSize, LayoutUnit(-1));
1238 }
1239
1240 bool needsToFulfillMinimumSize = false;
1241 bool indefiniteMainAndMaxSizes = availableSize == LayoutUnit(-1);
1242 if (indefiniteMainAndMaxSizes) {
1243 const Length& minSize = isRowAxis ? styleRef().logicalMinWidth() : style Ref().logicalMinHeight();
1244 if (!minSize.isSpecified())
1245 return 1;
1246
1247 LayoutUnit containingBlockAvailableSize = isRowAxis ? containingBlockLog icalWidthForContent() : containingBlockLogicalHeightForContent(ExcludeMarginBord erPadding);
1248 availableSize = valueForLength(minSize, containingBlockAvailableSize);
1249 needsToFulfillMinimumSize = true;
1250 }
1251
1252 bool hasDefiniteMaxTrackSizingFunction = autoTrackSize.maxTrackBreadth().isL ength() && !autoTrackSize.maxTrackBreadth().isContentSized();
1253 const Length trackLength = hasDefiniteMaxTrackSizingFunction ? autoTrackSize .maxTrackBreadth().length() : autoTrackSize.minTrackBreadth().length();
1254 // For the purpose of finding the number of auto-repeated tracks, the UA mus t floor the track size to a UA-specified
1255 // value to avoid division by zero. It is suggested that this floor be 1px.
1256 LayoutUnit autoRepeatTrackSize = std::max<LayoutUnit>(LayoutUnit(1), valueFo rLength(trackLength, availableSize));
1257
1258 // There will be always at least 1 auto-repeat track, so take it already int o account when computing the total track size.
1259 LayoutUnit tracksSize = autoRepeatTrackSize;
1260 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat eColumns() : styleRef().gridTemplateRows();
1261
1262 for (const auto& track : trackSizes) {
1263 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() && !track.maxTrackBreadth().isContentSized();
1264 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength() && !track.minTrackBreadth().isContentSized()));
1265 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack Breadth().length() : track.minTrackBreadth().length(), availableSize);
1266 }
1267
1268 // Add gutters as if there where only 1 auto repeat track. Gaps between auto repeat tracks will be added later when
1269 // computing the repetitions.
1270 LayoutUnit gapSize = guttersSize(direction, 2);
1271 tracksSize += gapSize * trackSizes.size();
1272
1273 LayoutUnit freeSpace = availableSize - tracksSize;
1274 if (freeSpace <= 0)
1275 return 1;
1276
1277 size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt ();
1278
1279 // Provided the grid container does not have a definite size or max-size in the relevant axis,
1280 // if the min size is definite then the number of repetitions is the largest possible positive
1281 // integer that fulfills that minimum requirement.
1282 if (needsToFulfillMinimumSize)
1283 ++repetitions;
1284
1285 return repetitions;
1286 } 1187 }
1287 1188
1288 void LayoutGrid::placeItemsOnGrid() 1189 void LayoutGrid::placeItemsOnGrid()
1289 { 1190 {
1290 if (!m_gridIsDirty) 1191 if (!m_gridIsDirty)
1291 return; 1192 return;
1292 1193
1293 ASSERT(m_gridItemArea.isEmpty()); 1194 ASSERT(m_gridItemArea.isEmpty());
1294 1195
1295 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); 1196 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns);
(...skipping 949 matching lines...)
2245 2146
2246 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); 2147 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData ));
2247 } 2148 }
2248 2149
2249 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2150 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2250 { 2151 {
2251 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2152 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2252 } 2153 }
2253 2154
2254 } // namespace blink 2155 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine