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/18 21:31:42
We don't have a test for this.
BTW, why you need
svillar
2016/04/19 08:09:36
ACK
| |
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/18 21:31:41
We don't have a test for this either.
svillar
2016/04/19 08:09:36
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, int i) const | |
Manuel Rego
2016/04/18 21:31:42
We could find a better name than "i" for the varia
svillar
2016/04/19 08:09:36
Acknowledged.
| |
701 { | |
702 bool isForColumns = direction == ForColumns; | |
Manuel Rego
2016/04/18 21:31:42
Probably better use "isRowAxis" as in most of the
svillar
2016/04/19 08:09:35
Acknowledged.
| |
703 const Vector<GridTrackSize>& trackStyles = isForColumns ? styleRef().gridTem plateColumns() : styleRef().gridTemplateRows(); | |
704 const Vector<GridTrackSize>& autoRepeatTrackStyles = isForColumns ? styleRef ().gridAutoRepeatColumns() : styleRef().gridAutoRepeatRows(); | |
705 const GridTrackSize& autoTrackSize = isForColumns ? styleRef().gridAutoColum ns() : styleRef().gridAutoRows(); | |
706 size_t insertionPoint = isForColumns ? styleRef().gridAutoRepeatColumnsInser tionPoint() : 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). | |
Manuel Rego
2016/04/18 21:31:42
But explicitGridXXXCount() now already manages
the
svillar
2016/04/19 08:09:35
It's perfectly up to date :). So the thing is that
Manuel Rego
2016/04/19 11:37:30
Yeah I read the comment wrong, I got it now. Thank
| |
712 size_t explicitTracksCount = trackStyles.size() + repetitions; | |
713 | |
714 if (i < 0 || i >= explicitTracksCount) | |
715 return autoTrackSize; | |
716 | |
717 if (LIKELY(!repetitions) || i < insertionPoint) | |
Manuel Rego
2016/04/18 21:31:42
Wow, first time I see LIKELY in a patch. :-)
svillar
2016/04/19 08:09:36
Not sure if this is a complain or what :). There a
Manuel Rego
2016/04/19 11:37:30
Just a funny comment, sorry. :-)
| |
718 return trackStyles[i]; | |
719 | |
720 if (i < (insertionPoint + repetitions)) | |
721 return autoRepeatTrackStyles[0]; | |
722 | |
723 return trackStyles[i - repetitions]; | |
724 } | |
725 | |
697 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t i) const | 726 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t i) const |
698 { | 727 { |
699 bool isForColumns = direction == ForColumns; | 728 int translatedIndex = i + (direction == ForColumns ? m_smallestColumnStart : m_smallestRowStart); |
Manuel Rego
2016/04/18 21:31:42
You could do this inside unresolvedGridTrackSize()
svillar
2016/04/19 08:09:36
Acknowledged.
| |
700 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl ateColumns() : style()->gridTemplateRows(); | 729 const GridTrackSize& trackSize = unresolvedGridTrackSize(direction, translat edIndex); |
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() && !autoTrackSize.minTrack Breadth().isContentSized()); | |
Manuel Rego
2016/04/18 21:31:42
Usually it's preferred to split this in 2 lines,
t
svillar
2016/04/19 08:09:35
Acknowledged.
| |
1220 | |
1221 const Length& minSize = isRowAxis ? styleRef().logicalMinWidth() : styleRef( ).logicalMinHeight(); | |
Manuel Rego
2016/04/18 21:31:42
This should be moved below where it's first used.
svillar
2016/04/19 08:09:36
Acknowledged.
| |
1222 LayoutUnit availableSize = isRowAxis ? availableLogicalWidth() : computeCont entLogicalHeight(MainOrPreferredSize, styleRef().logicalHeight(), LayoutUnit(-1) ); | |
1223 | |
1224 bool needsToFulfillMinimumSize = false; | |
Manuel Rego
2016/04/18 21:31:42
Ditto.
svillar
2016/04/19 08:09:36
Acknowledged.
| |
1225 if (availableSize == -1) { | |
1226 const Length& maxLength = isRowAxis ? styleRef().logicalMaxWidth() : sty leRef().logicalMaxHeight(); | |
1227 if (!maxLength.isMaxSizeNone()) { | |
1228 LayoutUnit maxSize = isRowAxis | |
1229 ? computeLogicalWidthUsing(MaxSize, maxLength, containingBlockLo gicalWidthForContent(), containingBlock()) | |
1230 : computeContentLogicalHeight(MaxSize, maxLength, LayoutUnit(-1) ); | |
1231 if (maxSize != -1) | |
1232 availableSize = availableSize != -1 ? std::min(availableSize, ma xSize) : maxSize; | |
Manuel Rego
2016/04/18 21:31:42
"availableSize" should be -1 if we are in this par
svillar
2016/04/19 08:09:36
Acknowledged.
| |
1233 } | |
1234 } else { | |
1235 availableSize = isRowAxis | |
1236 ? constrainLogicalWidthByMinMax(availableSize, containingBlockLogica lWidthForContent(), containingBlock()) | |
1237 : constrainLogicalHeightByMinMax(availableSize, LayoutUnit(-1)); | |
1238 } | |
1239 | |
1240 bool indefiniteMainAndMaxSizes = availableSize == LayoutUnit(-1); | |
1241 if (indefiniteMainAndMaxSizes) { | |
1242 if (!minSize.isSpecified()) | |
1243 return 1; | |
1244 | |
1245 LayoutUnit containingBlockAvailableSize = isRowAxis ? containingBlockLog icalWidthForContent() : containingBlockLogicalHeightForContent(ExcludeMarginBord erPadding); | |
1246 availableSize = valueForLength(minSize, containingBlockAvailableSize); | |
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 | |
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 (); | |
Manuel Rego
2016/04/18 21:31:42
I'm not sure if I get this, if you've for example
svillar
2016/04/19 08:09:36
You're missing the freeSpace computation just a co
Manuel Rego
2016/04/19 11:37:30
Thanks again.
| |
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; | |
Manuel Rego
2016/04/18 21:31:42
Again, I don't get why in this case we've to incre
svillar
2016/04/19 08:09:36
Because in the above code we compute the maximum n
Manuel Rego
2016/04/19 11:37:30
And thanks again, I was not getting it.
| |
1282 | |
1283 return std::min<size_t>(repetitions, kGridMaxTracks); | |
Manuel Rego
2016/04/18 21:31:42
I guess the limit for kGridMaxTracks should be
rep
svillar
2016/04/19 08:09:36
Yeah good catch.
| |
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 |