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...) 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()))) |
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(); |
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...) 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 |
697 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size
_t i) const | 700 const GridTrackSize& LayoutGrid::rawGridTrackSize(GridTrackSizingDirection direc
tion, size_t translatedIndex) const |
698 { | 701 { |
699 bool isForColumns = direction == ForColumns; | 702 bool isRowAxis = direction == ForColumns; |
700 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl
ateColumns() : style()->gridTemplateRows(); | 703 const Vector<GridTrackSize>& trackStyles = isRowAxis ? styleRef().gridTempla
teColumns() : styleRef().gridTemplateRows(); |
701 const GridTrackSize& autoTrackSize = isForColumns ? style()->gridAutoColumns
() : style()->gridAutoRows(); | 704 const Vector<GridTrackSize>& autoRepeatTrackStyles = isRowAxis ? styleRef().
gridAutoRepeatColumns() : styleRef().gridAutoRepeatRows(); |
702 int translatedIndex = i + (isForColumns ? m_smallestColumnStart : m_smallest
RowStart); | 705 const GridTrackSize& autoTrackSize = isRowAxis ? styleRef().gridAutoColumns(
) : styleRef().gridAutoRows(); |
703 const GridTrackSize& trackSize = (translatedIndex < 0 || translatedIndex >=
static_cast<int>(trackStyles.size())) ? autoTrackSize : trackStyles[translatedIn
dex]; | 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 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
); |
704 | 734 |
705 GridLength minTrackBreadth = trackSize.minTrackBreadth(); | 735 GridLength minTrackBreadth = trackSize.minTrackBreadth(); |
706 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); | 736 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); |
707 | 737 |
708 // If the logical width/height of the grid container is indefinite, percenta
ge values are treated as <auto> | 738 // If the logical width/height of the grid container is indefinite, percenta
ge values are treated as <auto> |
709 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { | 739 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { |
710 if (!hasDefiniteLogicalSize(direction)) { | 740 if (!hasDefiniteLogicalSize(direction)) { |
711 if (minTrackBreadth.hasPercentage()) | 741 if (minTrackBreadth.hasPercentage()) |
712 minTrackBreadth = Length(Auto); | 742 minTrackBreadth = Length(Auto); |
713 if (maxTrackBreadth.hasPercentage()) | 743 if (maxTrackBreadth.hasPercentage()) |
(...skipping 461 matching lines...) Loading... |
1175 ensureGridSize(area.rows.endLine(), area.columns.endLine()); | 1205 ensureGridSize(area.rows.endLine(), area.columns.endLine()); |
1176 | 1206 |
1177 for (const auto& row : area.rows) { | 1207 for (const auto& row : area.rows) { |
1178 for (const auto& column: area.columns) | 1208 for (const auto& column: area.columns) |
1179 m_grid[row][column].append(&child); | 1209 m_grid[row][column].append(&child); |
1180 } | 1210 } |
1181 } | 1211 } |
1182 | 1212 |
1183 size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi
on) const | 1213 size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi
on) const |
1184 { | 1214 { |
1185 // TODO(svillar): implement the algorithm to compute the number of auto repe
at tracks. | 1215 bool isRowAxis = direction == ForColumns; |
1186 return 0; | 1216 const auto& autoRepeatTracks = isRowAxis ? styleRef().gridAutoRepeatColumns(
) : styleRef().gridAutoRepeatRows(); |
| 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; |
1187 } | 1286 } |
1188 | 1287 |
1189 void LayoutGrid::placeItemsOnGrid() | 1288 void LayoutGrid::placeItemsOnGrid() |
1190 { | 1289 { |
1191 if (!m_gridIsDirty) | 1290 if (!m_gridIsDirty) |
1192 return; | 1291 return; |
1193 | 1292 |
1194 ASSERT(m_gridItemArea.isEmpty()); | 1293 ASSERT(m_gridItemArea.isEmpty()); |
1195 | 1294 |
1196 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); | 1295 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); |
(...skipping 949 matching lines...) Loading... |
2146 | 2245 |
2147 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData
)); | 2246 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData
)); |
2148 } | 2247 } |
2149 | 2248 |
2150 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const | 2249 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const |
2151 { | 2250 { |
2152 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2251 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2153 } | 2252 } |
2154 | 2253 |
2155 } // namespace blink | 2254 } // namespace blink |
OLD | NEW |