OLD | NEW |
---|---|
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...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()))) | |
Manuel Rego
2016/04/19 17:22:15
We still don't have tests for this.
svillar
2016/04/20 08:24:18
Acknowledged.
| |
305 dirtyGrid(); | 306 dirtyGrid(); |
306 } | 307 } |
307 | 308 |
308 bool LayoutGrid::explicitGridDidResize(const ComputedStyle& oldStyle) const | 309 bool LayoutGrid::explicitGridDidResize(const ComputedStyle& oldStyle) const |
309 { | 310 { |
310 return oldStyle.gridTemplateColumns().size() != styleRef().gridTemplateColum ns().size() | 311 return oldStyle.gridTemplateColumns().size() != styleRef().gridTemplateColum ns().size() |
311 || oldStyle.gridTemplateRows().size() != styleRef().gridTemplateRows().s ize() | 312 || oldStyle.gridTemplateRows().size() != styleRef().gridTemplateRows().s ize() |
312 || oldStyle.namedGridAreaColumnCount() != styleRef().namedGridAreaColumn Count() | 313 || oldStyle.namedGridAreaColumnCount() != styleRef().namedGridAreaColumn Count() |
313 || oldStyle.namedGridAreaRowCount() != styleRef().namedGridAreaRowCount( ); | 314 || oldStyle.namedGridAreaRowCount() != styleRef().namedGridAreaRowCount( ) |
315 || oldStyle.gridAutoRepeatColumns().size() != styleRef().gridAutoRepeatC olumns().size() | |
316 || oldStyle.gridAutoRepeatRows().size() != styleRef().gridAutoRepeatRows ().size(); | |
Manuel Rego
2016/04/19 17:22:15
Ditto.
svillar
2016/04/20 08:24:18
Acknowledged.
| |
314 } | 317 } |
315 | 318 |
316 bool LayoutGrid::namedGridLinesDefinitionDidChange(const ComputedStyle& oldStyle ) const | 319 bool LayoutGrid::namedGridLinesDefinitionDidChange(const ComputedStyle& oldStyle ) const |
317 { | 320 { |
318 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() | 321 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() |
319 || oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); | 322 || oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); |
320 } | 323 } |
321 | 324 |
322 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi ngData) const | 325 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi ngData) const |
323 { | 326 { |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 child.setOverrideContainingBlockContentLogicalHeight(size); | 690 child.setOverrideContainingBlockContentLogicalHeight(size); |
688 } | 691 } |
689 | 692 |
690 static bool shouldClearOverrideContainingBlockContentSizeForChild(const LayoutBo x& child, GridTrackSizingDirection direction) | 693 static bool shouldClearOverrideContainingBlockContentSizeForChild(const LayoutBo x& child, GridTrackSizingDirection direction) |
691 { | 694 { |
692 if (direction == ForColumns) | 695 if (direction == ForColumns) |
693 return child.hasRelativeLogicalWidth() || child.styleRef().logicalWidth( ).isIntrinsicOrAuto(); | 696 return child.hasRelativeLogicalWidth() || child.styleRef().logicalWidth( ).isIntrinsicOrAuto(); |
694 return child.hasRelativeLogicalHeight() || child.styleRef().logicalHeight(). isIntrinsicOrAuto(); | 697 return child.hasRelativeLogicalHeight() || child.styleRef().logicalHeight(). isIntrinsicOrAuto(); |
695 } | 698 } |
696 | 699 |
700 const GridTrackSize& LayoutGrid::unresolvedGridTrackSize(GridTrackSizingDirectio n direction, size_t untranslatedIndex) const | |
Manuel Rego
2016/04/19 17:22:16
I've just realized that "untranslatedIndex" should
svillar
2016/04/20 08:24:18
Perhaps the name is not good enough but we're pass
Manuel Rego
2016/04/20 09:57:44
Yeah, so I got confused because the names are (and
| |
701 { | |
702 bool isRowAxis = direction == ForColumns; | |
703 const Vector<GridTrackSize>& trackStyles = isRowAxis ? styleRef().gridTempla teColumns() : styleRef().gridTemplateRows(); | |
704 const Vector<GridTrackSize>& autoRepeatTrackStyles = isRowAxis ? styleRef(). gridAutoRepeatColumns() : styleRef().gridAutoRepeatRows(); | |
705 const GridTrackSize& autoTrackSize = isRowAxis ? styleRef().gridAutoColumns( ) : styleRef().gridAutoRows(); | |
706 size_t insertionPoint = isRowAxis ? styleRef().gridAutoRepeatColumnsInsertio nPoint() : styleRef().gridAutoRepeatRowsInsertionPoint(); | |
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 translatedIndex = untranslatedIndex + (isRowAxis ? m_smallestColumnStart : m_smallestRowStart); | |
715 if (translatedIndex < 0 || translatedIndex >= explicitTracksCount) | |
716 return autoTrackSize; | |
717 | |
718 if (LIKELY(!repetitions) || translatedIndex < insertionPoint) | |
719 return trackStyles[translatedIndex]; | |
720 | |
721 if (translatedIndex < (insertionPoint + repetitions)) | |
722 return autoRepeatTrackStyles[0]; | |
723 | |
724 return trackStyles[translatedIndex - repetitions]; | |
725 } | |
726 | |
697 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t i) const | 727 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t i) const |
698 { | 728 { |
699 bool isForColumns = direction == ForColumns; | 729 const GridTrackSize& trackSize = unresolvedGridTrackSize(direction, i); |
700 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl ateColumns() : style()->gridTemplateRows(); | |
701 const GridTrackSize& autoTrackSize = isForColumns ? style()->gridAutoColumns () : style()->gridAutoRows(); | |
702 int translatedIndex = i + (isForColumns ? m_smallestColumnStart : m_smallest RowStart); | |
703 const GridTrackSize& trackSize = (translatedIndex < 0 || translatedIndex >= static_cast<int>(trackStyles.size())) ? autoTrackSize : trackStyles[translatedIn dex]; | |
704 | 730 |
705 GridLength minTrackBreadth = trackSize.minTrackBreadth(); | 731 GridLength minTrackBreadth = trackSize.minTrackBreadth(); |
706 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); | 732 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); |
707 | 733 |
708 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto> | 734 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto> |
709 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { | 735 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { |
710 if (!hasDefiniteLogicalSize(direction)) { | 736 if (!hasDefiniteLogicalSize(direction)) { |
711 if (minTrackBreadth.hasPercentage()) | 737 if (minTrackBreadth.hasPercentage()) |
712 minTrackBreadth = Length(Auto); | 738 minTrackBreadth = Length(Auto); |
713 if (maxTrackBreadth.hasPercentage()) | 739 if (maxTrackBreadth.hasPercentage()) |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1175 ensureGridSize(area.rows.endLine(), area.columns.endLine()); | 1201 ensureGridSize(area.rows.endLine(), area.columns.endLine()); |
1176 | 1202 |
1177 for (const auto& row : area.rows) { | 1203 for (const auto& row : area.rows) { |
1178 for (const auto& column: area.columns) | 1204 for (const auto& column: area.columns) |
1179 m_grid[row][column].append(&child); | 1205 m_grid[row][column].append(&child); |
1180 } | 1206 } |
1181 } | 1207 } |
1182 | 1208 |
1183 size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi on) const | 1209 size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi on) const |
1184 { | 1210 { |
1185 // TODO(svillar): implement the algorithm to compute the number of auto repe at tracks. | 1211 bool isRowAxis = direction == ForColumns; |
1186 return 0; | 1212 const auto& autoRepeatTracks = isRowAxis ? styleRef().gridAutoRepeatColumns( ) : styleRef().gridAutoRepeatRows(); |
1213 | |
1214 if (!autoRepeatTracks.size()) | |
1215 return 0; | |
1216 | |
1217 DCHECK_EQ(autoRepeatTracks.size(), 1); | |
1218 auto autoTrackSize = autoRepeatTracks.at(0); | |
1219 DCHECK(autoTrackSize.minTrackBreadth().isLength()); | |
1220 DCHECK(!autoTrackSize.minTrackBreadth().isContentSized()); | |
1221 | |
1222 LayoutUnit availableSize = isRowAxis ? availableLogicalWidth() : computeCont entLogicalHeight(MainOrPreferredSize, styleRef().logicalHeight(), LayoutUnit(-1) ); | |
Manuel Rego
2016/04/19 17:22:16
Couldn't you use availableLogicalHeight()?
svillar
2016/04/20 08:24:18
No because it does not return -1 for indefinite he
| |
1223 if (availableSize == -1) { | |
1224 const Length& maxLength = isRowAxis ? styleRef().logicalMaxWidth() : sty leRef().logicalMaxHeight(); | |
1225 if (!maxLength.isMaxSizeNone()) { | |
1226 LayoutUnit maxSize = isRowAxis | |
1227 ? computeLogicalWidthUsing(MaxSize, maxLength, containingBlockLo gicalWidthForContent(), containingBlock()) | |
1228 : computeContentLogicalHeight(MaxSize, maxLength, LayoutUnit(-1) ); | |
1229 if (maxSize != -1) | |
1230 availableSize = std::min(availableSize, maxSize); | |
1231 } | |
1232 } else { | |
1233 availableSize = isRowAxis | |
1234 ? constrainLogicalWidthByMinMax(availableSize, availableLogicalWidth (), containingBlock()) | |
1235 : constrainLogicalHeightByMinMax(availableSize, LayoutUnit(-1)); | |
1236 } | |
1237 | |
1238 bool needsToFulfillMinimumSize = false; | |
1239 bool indefiniteMainAndMaxSizes = availableSize == LayoutUnit(-1); | |
1240 if (indefiniteMainAndMaxSizes) { | |
1241 const Length& minSize = isRowAxis ? styleRef().logicalMinWidth() : style Ref().logicalMinHeight(); | |
1242 if (!minSize.isSpecified()) | |
1243 return 1; | |
1244 | |
1245 LayoutUnit containingBlockAvailableSize = isRowAxis ? containingBlockLog icalWidthForContent() : containingBlockLogicalHeightForContent(ExcludeMarginBord erPadding); | |
1246 availableSize = valueForLength(minSize, containingBlockAvailableSize); | |
Manuel Rego
2016/04/19 17:22:16
Why the difference to get the max vs min size.
A
svillar
2016/04/20 08:24:18
I'm mostly doing the same. I could have used compu
| |
1247 needsToFulfillMinimumSize = true; | |
1248 } | |
1249 | |
1250 bool hasDefiniteMaxTrackSizingFunction = autoTrackSize.maxTrackBreadth().isL ength() && !autoTrackSize.maxTrackBreadth().isContentSized(); | |
1251 const Length trackLength = hasDefiniteMaxTrackSizingFunction ? autoTrackSize .maxTrackBreadth().length() : autoTrackSize.minTrackBreadth().length(); | |
1252 // For the purpose of finding the number of auto-repeated tracks, the UA mus t floor the track size to a UA-specified | |
1253 // value to avoid division by zero. It is suggested that this floor be 1px. | |
1254 LayoutUnit autoRepeatTrackSize = std::max<LayoutUnit>(LayoutUnit(1), valueFo rLength(trackLength, availableSize)); | |
1255 | |
1256 // There will be always at least 1 auto-repeat track, so take it already int o account when computing the total track size | |
Manuel Rego
2016/04/19 17:22:16
Nit: Missing dot at the end.
svillar
2016/04/20 08:24:18
Acknowledged.
| |
1257 LayoutUnit tracksSize = autoRepeatTrackSize; | |
1258 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat eColumns() : styleRef().gridTemplateRows(); | |
1259 | |
1260 for (const auto& track : trackSizes) { | |
1261 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() && !track.maxTrackBreadth().isContentSized(); | |
1262 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength() && !track.minTrackBreadth().isContentSized())); | |
1263 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack Breadth().length() : track.minTrackBreadth().length(), availableSize); | |
1264 } | |
1265 | |
1266 // Add gutters as if there where only 1 auto repeat track. Gaps between auto repeat tracks will be added later when | |
1267 // computing the repetitions. | |
1268 LayoutUnit gapSize = guttersSize(direction, 2); | |
1269 tracksSize += gapSize * trackSizes.size(); | |
1270 | |
1271 LayoutUnit freeSpace = availableSize - tracksSize; | |
1272 if (freeSpace <= 0) | |
1273 return 1; | |
1274 | |
1275 size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt (); | |
1276 | |
1277 // Otherwise, if the grid container has a definite min size in the relevant axis, the | |
1278 // number of repetitions is the largest possible positive integer that fulfi lls that | |
1279 // minimum requirement. | |
1280 if (needsToFulfillMinimumSize) | |
1281 ++repetitions; | |
1282 | |
1283 return repetitions; | |
1187 } | 1284 } |
1188 | 1285 |
1189 void LayoutGrid::placeItemsOnGrid() | 1286 void LayoutGrid::placeItemsOnGrid() |
1190 { | 1287 { |
1191 if (!m_gridIsDirty) | 1288 if (!m_gridIsDirty) |
1192 return; | 1289 return; |
1193 | 1290 |
1194 ASSERT(m_gridItemArea.isEmpty()); | 1291 ASSERT(m_gridItemArea.isEmpty()); |
1195 | 1292 |
1196 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); | 1293 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); |
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2146 | 2243 |
2147 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); | 2244 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); |
2148 } | 2245 } |
2149 | 2246 |
2150 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2247 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
2151 { | 2248 { |
2152 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2249 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2153 } | 2250 } |
2154 | 2251 |
2155 } // namespace blink | 2252 } // namespace blink |
OLD | NEW |