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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 borderAndPaddingLogicalHeight() + | 277 borderAndPaddingLogicalHeight() + |
278 scrollbarLogicalHeight(); | 278 scrollbarLogicalHeight(); |
279 setLogicalHeight(trackBasedLogicalHeight); | 279 setLogicalHeight(trackBasedLogicalHeight); |
280 | 280 |
281 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); | 281 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); |
282 updateLogicalHeight(); | 282 updateLogicalHeight(); |
283 | 283 |
284 // Once grid's indefinite height is resolved, we can compute the | 284 // Once grid's indefinite height is resolved, we can compute the |
285 // available free space for Content Alignment. | 285 // available free space for Content Alignment. |
286 if (!cachedHasDefiniteLogicalHeight()) { | 286 if (!cachedHasDefiniteLogicalHeight()) { |
287 m_trackSizingAlgorithm.freeSpace(ForRows) = | 287 m_trackSizingAlgorithm.setFreeSpace( |
288 logicalHeight() - trackBasedLogicalHeight; | 288 ForRows, logicalHeight() - trackBasedLogicalHeight); |
289 } | 289 } |
290 | 290 |
291 // TODO (lajava): We need to compute baselines after step 2 so | 291 // TODO (lajava): We need to compute baselines after step 2 so |
292 // items with a relative size (percentages) can resolve it before | 292 // items with a relative size (percentages) can resolve it before |
293 // determining its baseline. However, we only set item's grid area | 293 // determining its baseline. However, we only set item's grid area |
294 // (via override sizes) as part of the content-sized tracks sizing | 294 // (via override sizes) as part of the content-sized tracks sizing |
295 // logic. Hence, items located at fixed or flexible tracks can't | 295 // logic. Hence, items located at fixed or flexible tracks can't |
296 // resolve correctly their size at this stage, which may lead to | 296 // resolve correctly their size at this stage, which may lead to |
297 // an incorrect computation of their shared context's baseline. | 297 // an incorrect computation of their shared context's baseline. |
298 computeBaselineAlignmentContext(); | 298 computeBaselineAlignmentContext(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 maxLogicalWidth += scrollbarWidth; | 429 maxLogicalWidth += scrollbarWidth; |
430 } | 430 } |
431 | 431 |
432 void LayoutGrid::computeTrackSizesForIndefiniteSize( | 432 void LayoutGrid::computeTrackSizesForIndefiniteSize( |
433 GridTrackSizingAlgorithm& algo, | 433 GridTrackSizingAlgorithm& algo, |
434 GridTrackSizingDirection direction, | 434 GridTrackSizingDirection direction, |
435 Grid& grid, | 435 Grid& grid, |
436 LayoutUnit& minIntrinsicSize, | 436 LayoutUnit& minIntrinsicSize, |
437 LayoutUnit& maxIntrinsicSize) const { | 437 LayoutUnit& maxIntrinsicSize) const { |
438 algo.setup(direction, numTracks(direction, grid), IntrinsicSizeComputation, | 438 algo.setup(direction, numTracks(direction, grid), IntrinsicSizeComputation, |
439 LayoutUnit(), LayoutUnit()); | 439 WTF::nullopt, WTF::nullopt); |
440 algo.run(); | 440 algo.run(); |
441 | 441 |
442 minIntrinsicSize = algo.minContentSize(); | 442 minIntrinsicSize = algo.minContentSize(); |
443 maxIntrinsicSize = algo.maxContentSize(); | 443 maxIntrinsicSize = algo.maxContentSize(); |
444 | 444 |
445 size_t numberOfTracks = algo.tracks(direction).size(); | 445 size_t numberOfTracks = algo.tracks(direction).size(); |
446 LayoutUnit totalGuttersSize = | 446 LayoutUnit totalGuttersSize = |
447 guttersSize(grid, direction, 0, numberOfTracks, IntrinsicSizeComputation); | 447 guttersSize(grid, direction, 0, numberOfTracks, IntrinsicSizeComputation); |
448 minIntrinsicSize += totalGuttersSize; | 448 minIntrinsicSize += totalGuttersSize; |
449 maxIntrinsicSize += totalGuttersSize; | 449 maxIntrinsicSize += totalGuttersSize; |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 } | 1039 } |
1040 | 1040 |
1041 static const StyleContentAlignmentData& contentAlignmentNormalBehavior() { | 1041 static const StyleContentAlignmentData& contentAlignmentNormalBehavior() { |
1042 static const StyleContentAlignmentData normalBehavior = { | 1042 static const StyleContentAlignmentData normalBehavior = { |
1043 ContentPositionNormal, ContentDistributionStretch}; | 1043 ContentPositionNormal, ContentDistributionStretch}; |
1044 return normalBehavior; | 1044 return normalBehavior; |
1045 } | 1045 } |
1046 | 1046 |
1047 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded( | 1047 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded( |
1048 GridTrackSizingDirection direction) { | 1048 GridTrackSizingDirection direction) { |
1049 LayoutUnit& availableSpace = m_trackSizingAlgorithm.freeSpace(direction); | 1049 Optional<LayoutUnit> freeSpace = m_trackSizingAlgorithm.freeSpace(direction); |
1050 if (availableSpace <= 0 || | 1050 if (!freeSpace || freeSpace.value() <= 0 || |
1051 (direction == ForColumns && | 1051 (direction == ForColumns && |
1052 styleRef().resolvedJustifyContentDistribution( | 1052 styleRef().resolvedJustifyContentDistribution( |
1053 contentAlignmentNormalBehavior()) != ContentDistributionStretch) || | 1053 contentAlignmentNormalBehavior()) != ContentDistributionStretch) || |
1054 (direction == ForRows && | 1054 (direction == ForRows && |
1055 styleRef().resolvedAlignContentDistribution( | 1055 styleRef().resolvedAlignContentDistribution( |
1056 contentAlignmentNormalBehavior()) != ContentDistributionStretch)) | 1056 contentAlignmentNormalBehavior()) != ContentDistributionStretch)) |
1057 return; | 1057 return; |
1058 | 1058 |
1059 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing | 1059 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing |
1060 // function. | 1060 // function. |
1061 Vector<GridTrack>& allTracks = m_trackSizingAlgorithm.tracks(direction); | 1061 Vector<GridTrack>& allTracks = m_trackSizingAlgorithm.tracks(direction); |
1062 Vector<unsigned> autoSizedTracksIndex; | 1062 Vector<unsigned> autoSizedTracksIndex; |
1063 for (unsigned i = 0; i < allTracks.size(); ++i) { | 1063 for (unsigned i = 0; i < allTracks.size(); ++i) { |
1064 const GridTrackSize& trackSize = | 1064 const GridTrackSize& trackSize = |
1065 m_trackSizingAlgorithm.gridTrackSize(direction, i, TrackSizing); | 1065 m_trackSizingAlgorithm.gridTrackSize(direction, i, TrackSizing); |
1066 if (trackSize.hasAutoMaxTrackBreadth()) | 1066 if (trackSize.hasAutoMaxTrackBreadth()) |
1067 autoSizedTracksIndex.push_back(i); | 1067 autoSizedTracksIndex.push_back(i); |
1068 } | 1068 } |
1069 | 1069 |
1070 unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size(); | 1070 unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size(); |
1071 if (numberOfAutoSizedTracks < 1) | 1071 if (numberOfAutoSizedTracks < 1) |
1072 return; | 1072 return; |
1073 | 1073 |
1074 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; | 1074 LayoutUnit sizeToIncrease = freeSpace.value() / numberOfAutoSizedTracks; |
1075 for (const auto& trackIndex : autoSizedTracksIndex) { | 1075 for (const auto& trackIndex : autoSizedTracksIndex) { |
1076 GridTrack* track = allTracks.data() + trackIndex; | 1076 GridTrack* track = allTracks.data() + trackIndex; |
1077 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; | 1077 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; |
1078 track->setBaseSize(baseSize); | 1078 track->setBaseSize(baseSize); |
1079 } | 1079 } |
1080 | 1080 m_trackSizingAlgorithm.setFreeSpace(direction, LayoutUnit()); |
1081 availableSpace = LayoutUnit(); | |
1082 } | 1081 } |
1083 | 1082 |
1084 void LayoutGrid::layoutGridItems() { | 1083 void LayoutGrid::layoutGridItems() { |
1085 populateGridPositionsForDirection(ForColumns); | 1084 populateGridPositionsForDirection(ForColumns); |
1086 populateGridPositionsForDirection(ForRows); | 1085 populateGridPositionsForDirection(ForRows); |
1087 m_gridItemsOverflowingGridArea.resize(0); | 1086 m_gridItemsOverflowingGridArea.resize(0); |
1088 | 1087 |
1089 for (LayoutBox* child = firstChildBox(); child; | 1088 for (LayoutBox* child = firstChildBox(); child; |
1090 child = child->nextSiblingBox()) { | 1089 child = child->nextSiblingBox()) { |
1091 if (child->isOutOfFlowPositioned()) { | 1090 if (child->isOutOfFlowPositioned()) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 // offset) are sensible to the inline-axis flow direction. However, column | 1337 // offset) are sensible to the inline-axis flow direction. However, column |
1339 // lines positions are 'direction' unaware. This simplification allows us to | 1338 // lines positions are 'direction' unaware. This simplification allows us to |
1340 // use the same indexes to identify the columns independently on the | 1339 // use the same indexes to identify the columns independently on the |
1341 // inline-axis direction. | 1340 // inline-axis direction. |
1342 bool isRowAxis = direction == ForColumns; | 1341 bool isRowAxis = direction == ForColumns; |
1343 auto& tracks = m_trackSizingAlgorithm.tracks(direction); | 1342 auto& tracks = m_trackSizingAlgorithm.tracks(direction); |
1344 size_t numberOfTracks = tracks.size(); | 1343 size_t numberOfTracks = tracks.size(); |
1345 size_t numberOfLines = numberOfTracks + 1; | 1344 size_t numberOfLines = numberOfTracks + 1; |
1346 size_t lastLine = numberOfLines - 1; | 1345 size_t lastLine = numberOfLines - 1; |
1347 ContentAlignmentData offset = computeContentPositionAndDistributionOffset( | 1346 ContentAlignmentData offset = computeContentPositionAndDistributionOffset( |
1348 direction, m_trackSizingAlgorithm.freeSpace(direction), numberOfTracks); | 1347 direction, m_trackSizingAlgorithm.freeSpace(direction).value(), |
| 1348 numberOfTracks); |
1349 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; | 1349 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
1350 positions.resize(numberOfLines); | 1350 positions.resize(numberOfLines); |
1351 auto borderAndPadding = | 1351 auto borderAndPadding = |
1352 isRowAxis ? borderAndPaddingLogicalLeft() : borderAndPaddingBefore(); | 1352 isRowAxis ? borderAndPaddingLogicalLeft() : borderAndPaddingBefore(); |
1353 positions[0] = borderAndPadding + offset.positionOffset; | 1353 positions[0] = borderAndPadding + offset.positionOffset; |
1354 const Grid& grid = m_trackSizingAlgorithm.grid(); | 1354 const Grid& grid = m_trackSizingAlgorithm.grid(); |
1355 if (numberOfLines > 1) { | 1355 if (numberOfLines > 1) { |
1356 // If we have collapsed tracks we just ignore gaps here and add them later | 1356 // If we have collapsed tracks we just ignore gaps here and add them later |
1357 // as we might not compute the gap between two consecutive tracks without | 1357 // as we might not compute the gap between two consecutive tracks without |
1358 // examining the surrounding ones. | 1358 // examining the surrounding ones. |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 if (direction == ForRows) | 2323 if (direction == ForRows) |
2324 return grid.numTracks(ForRows); | 2324 return grid.numTracks(ForRows); |
2325 | 2325 |
2326 return grid.numTracks(ForRows) | 2326 return grid.numTracks(ForRows) |
2327 ? grid.numTracks(ForColumns) | 2327 ? grid.numTracks(ForColumns) |
2328 : GridPositionsResolver::explicitGridColumnCount( | 2328 : GridPositionsResolver::explicitGridColumnCount( |
2329 styleRef(), grid.autoRepeatTracks(ForColumns)); | 2329 styleRef(), grid.autoRepeatTracks(ForColumns)); |
2330 } | 2330 } |
2331 | 2331 |
2332 } // namespace blink | 2332 } // namespace blink |
OLD | NEW |