| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void LayoutGrid::Grid::insert(LayoutBox& child, const GridArea& area) { | 67 void LayoutGrid::Grid::insert(LayoutBox& child, const GridArea& area) { |
| 68 DCHECK(area.rows.isTranslatedDefinite() && | 68 DCHECK(area.rows.isTranslatedDefinite() && |
| 69 area.columns.isTranslatedDefinite()); | 69 area.columns.isTranslatedDefinite()); |
| 70 ensureGridSize(area.rows.endLine(), area.columns.endLine()); | 70 ensureGridSize(area.rows.endLine(), area.columns.endLine()); |
| 71 | 71 |
| 72 for (const auto& row : area.rows) { | 72 for (const auto& row : area.rows) { |
| 73 for (const auto& column : area.columns) | 73 for (const auto& column : area.columns) |
| 74 m_grid[row][column].append(&child); | 74 m_grid[row][column].push_back(&child); |
| 75 } | 75 } |
| 76 | 76 |
| 77 setGridItemArea(child, area); | 77 setGridItemArea(child, area); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void LayoutGrid::Grid::setSmallestTracksStart(int rowStart, int columnStart) { | 80 void LayoutGrid::Grid::setSmallestTracksStart(int rowStart, int columnStart) { |
| 81 m_smallestRowStart = rowStart; | 81 m_smallestRowStart = rowStart; |
| 82 m_smallestColumnStart = columnStart; | 82 m_smallestColumnStart = columnStart; |
| 83 } | 83 } |
| 84 | 84 |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 computeUsedBreadthOfMaxLength(trackSize, track.baseSize(), maxSize)); | 901 computeUsedBreadthOfMaxLength(trackSize, track.baseSize(), maxSize)); |
| 902 track.setInfinitelyGrowable(false); | 902 track.setInfinitelyGrowable(false); |
| 903 | 903 |
| 904 if (trackSize.isFitContent()) { | 904 if (trackSize.isFitContent()) { |
| 905 GridLength gridLength = trackSize.fitContentTrackBreadth(); | 905 GridLength gridLength = trackSize.fitContentTrackBreadth(); |
| 906 if (!gridLength.hasPercentage() || hasDefiniteFreeSpace) | 906 if (!gridLength.hasPercentage() || hasDefiniteFreeSpace) |
| 907 track.setGrowthLimitCap(valueForLength(gridLength.length(), maxSize)); | 907 track.setGrowthLimitCap(valueForLength(gridLength.length(), maxSize)); |
| 908 } | 908 } |
| 909 | 909 |
| 910 if (trackSize.isContentSized()) | 910 if (trackSize.isContentSized()) |
| 911 sizingData.contentSizedTracksIndex.append(i); | 911 sizingData.contentSizedTracksIndex.push_back(i); |
| 912 if (trackSize.maxTrackBreadth().isFlex()) | 912 if (trackSize.maxTrackBreadth().isFlex()) |
| 913 flexibleSizedTracksIndex.append(i); | 913 flexibleSizedTracksIndex.push_back(i); |
| 914 } | 914 } |
| 915 | 915 |
| 916 // 2. Resolve content-based TrackSizingFunctions. | 916 // 2. Resolve content-based TrackSizingFunctions. |
| 917 if (!sizingData.contentSizedTracksIndex.isEmpty()) | 917 if (!sizingData.contentSizedTracksIndex.isEmpty()) |
| 918 resolveContentBasedTrackSizingFunctions(direction, sizingData); | 918 resolveContentBasedTrackSizingFunctions(direction, sizingData); |
| 919 | 919 |
| 920 baseSizesWithoutMaximization = growthLimitsWithoutMaximization = LayoutUnit(); | 920 baseSizesWithoutMaximization = growthLimitsWithoutMaximization = LayoutUnit(); |
| 921 | 921 |
| 922 for (auto& track : tracks) { | 922 for (auto& track : tracks) { |
| 923 ASSERT(!track.infiniteGrowthPotential()); | 923 ASSERT(!track.infiniteGrowthPotential()); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 if (leftOverSpace <= 0) | 1154 if (leftOverSpace <= 0) |
| 1155 return 0; | 1155 return 0; |
| 1156 | 1156 |
| 1157 double flexFactorSum = 0; | 1157 double flexFactorSum = 0; |
| 1158 Vector<size_t, 8> flexibleTracksIndexes; | 1158 Vector<size_t, 8> flexibleTracksIndexes; |
| 1159 for (const auto& trackIndex : tracksSpan) { | 1159 for (const auto& trackIndex : tracksSpan) { |
| 1160 GridTrackSize trackSize = gridTrackSize(direction, trackIndex, sizingData); | 1160 GridTrackSize trackSize = gridTrackSize(direction, trackIndex, sizingData); |
| 1161 if (!trackSize.maxTrackBreadth().isFlex()) { | 1161 if (!trackSize.maxTrackBreadth().isFlex()) { |
| 1162 leftOverSpace -= tracks[trackIndex].baseSize(); | 1162 leftOverSpace -= tracks[trackIndex].baseSize(); |
| 1163 } else { | 1163 } else { |
| 1164 flexibleTracksIndexes.append(trackIndex); | 1164 flexibleTracksIndexes.push_back(trackIndex); |
| 1165 flexFactorSum += trackSize.maxTrackBreadth().flex(); | 1165 flexFactorSum += trackSize.maxTrackBreadth().flex(); |
| 1166 } | 1166 } |
| 1167 } | 1167 } |
| 1168 | 1168 |
| 1169 // The function is not called if we don't have <flex> grid tracks | 1169 // The function is not called if we don't have <flex> grid tracks |
| 1170 ASSERT(!flexibleTracksIndexes.isEmpty()); | 1170 ASSERT(!flexibleTracksIndexes.isEmpty()); |
| 1171 | 1171 |
| 1172 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, | 1172 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, |
| 1173 leftOverSpace, flexibleTracksIndexes, | 1173 leftOverSpace, flexibleTracksIndexes, |
| 1174 sizingData); | 1174 sizingData); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 ? sizingData.columnTracks[trackIndex] | 1530 ? sizingData.columnTracks[trackIndex] |
| 1531 : sizingData.rowTracks[trackIndex]; | 1531 : sizingData.rowTracks[trackIndex]; |
| 1532 while (LayoutBox* gridItem = iterator.nextGridItem()) { | 1532 while (LayoutBox* gridItem = iterator.nextGridItem()) { |
| 1533 if (itemsSet.add(gridItem).isNewEntry) { | 1533 if (itemsSet.add(gridItem).isNewEntry) { |
| 1534 const GridSpan& span = grid.gridItemSpan(*gridItem, direction); | 1534 const GridSpan& span = grid.gridItemSpan(*gridItem, direction); |
| 1535 if (span.integerSpan() == 1) { | 1535 if (span.integerSpan() == 1) { |
| 1536 resolveContentBasedTrackSizingFunctionsForNonSpanningItems( | 1536 resolveContentBasedTrackSizingFunctionsForNonSpanningItems( |
| 1537 direction, span, *gridItem, track, sizingData); | 1537 direction, span, *gridItem, track, sizingData); |
| 1538 } else if (!spanningItemCrossesFlexibleSizedTracks(span, direction, | 1538 } else if (!spanningItemCrossesFlexibleSizedTracks(span, direction, |
| 1539 sizingData)) { | 1539 sizingData)) { |
| 1540 sizingData.itemsSortedByIncreasingSpan.append( | 1540 sizingData.itemsSortedByIncreasingSpan.push_back( |
| 1541 GridItemWithSpan(*gridItem, span)); | 1541 GridItemWithSpan(*gridItem, span)); |
| 1542 } | 1542 } |
| 1543 } | 1543 } |
| 1544 } | 1544 } |
| 1545 } | 1545 } |
| 1546 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), | 1546 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), |
| 1547 sizingData.itemsSortedByIncreasingSpan.end()); | 1547 sizingData.itemsSortedByIncreasingSpan.end()); |
| 1548 } | 1548 } |
| 1549 | 1549 |
| 1550 auto it = sizingData.itemsSortedByIncreasingSpan.begin(); | 1550 auto it = sizingData.itemsSortedByIncreasingSpan.begin(); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 GridTrackSize trackSize = | 1774 GridTrackSize trackSize = |
| 1775 gridTrackSize(direction, trackPosition, sizingData); | 1775 gridTrackSize(direction, trackPosition, sizingData); |
| 1776 GridTrack& track = (direction == ForColumns) | 1776 GridTrack& track = (direction == ForColumns) |
| 1777 ? sizingData.columnTracks[trackPosition] | 1777 ? sizingData.columnTracks[trackPosition] |
| 1778 : sizingData.rowTracks[trackPosition]; | 1778 : sizingData.rowTracks[trackPosition]; |
| 1779 spanningTracksSize += | 1779 spanningTracksSize += |
| 1780 trackSizeForTrackSizeComputationPhase(phase, track, ForbidInfinity); | 1780 trackSizeForTrackSizeComputationPhase(phase, track, ForbidInfinity); |
| 1781 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize)) | 1781 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize)) |
| 1782 continue; | 1782 continue; |
| 1783 | 1783 |
| 1784 sizingData.filteredTracks.append(&track); | 1784 sizingData.filteredTracks.push_back(&track); |
| 1785 | 1785 |
| 1786 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase( | 1786 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase( |
| 1787 phase, trackSize)) | 1787 phase, trackSize)) |
| 1788 sizingData.growBeyondGrowthLimitsTracks.append(&track); | 1788 sizingData.growBeyondGrowthLimitsTracks.push_back(&track); |
| 1789 } | 1789 } |
| 1790 | 1790 |
| 1791 if (sizingData.filteredTracks.isEmpty()) | 1791 if (sizingData.filteredTracks.isEmpty()) |
| 1792 continue; | 1792 continue; |
| 1793 | 1793 |
| 1794 spanningTracksSize += | 1794 spanningTracksSize += |
| 1795 guttersSize(sizingData.grid(), direction, itemSpan.startLine(), | 1795 guttersSize(sizingData.grid(), direction, itemSpan.startLine(), |
| 1796 itemSpan.integerSpan(), sizingData.sizingOperation); | 1796 itemSpan.integerSpan(), sizingData.sizingOperation); |
| 1797 | 1797 |
| 1798 LayoutUnit extraSpace = | 1798 LayoutUnit extraSpace = |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2120 area.rows.translate(abs(grid.smallestTrackStart(ForRows))); | 2120 area.rows.translate(abs(grid.smallestTrackStart(ForRows))); |
| 2121 if (!area.columns.isIndefinite()) | 2121 if (!area.columns.isIndefinite()) |
| 2122 area.columns.translate(abs(grid.smallestTrackStart(ForColumns))); | 2122 area.columns.translate(abs(grid.smallestTrackStart(ForColumns))); |
| 2123 | 2123 |
| 2124 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { | 2124 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { |
| 2125 grid.setGridItemArea(*child, area); | 2125 grid.setGridItemArea(*child, area); |
| 2126 GridSpan majorAxisPositions = | 2126 GridSpan majorAxisPositions = |
| 2127 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns | 2127 (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns |
| 2128 : area.rows; | 2128 : area.rows; |
| 2129 if (majorAxisPositions.isIndefinite()) | 2129 if (majorAxisPositions.isIndefinite()) |
| 2130 autoMajorAxisAutoGridItems.append(child); | 2130 autoMajorAxisAutoGridItems.push_back(child); |
| 2131 else | 2131 else |
| 2132 specifiedMajorAxisAutoGridItems.append(child); | 2132 specifiedMajorAxisAutoGridItems.push_back(child); |
| 2133 continue; | 2133 continue; |
| 2134 } | 2134 } |
| 2135 grid.insert(*child, area); | 2135 grid.insert(*child, area); |
| 2136 } | 2136 } |
| 2137 grid.setHasAnyOrthogonalGridItem(hasAnyOrthogonalGridItem); | 2137 grid.setHasAnyOrthogonalGridItem(hasAnyOrthogonalGridItem); |
| 2138 | 2138 |
| 2139 #if ENABLE(ASSERT) | 2139 #if ENABLE(ASSERT) |
| 2140 if (grid.hasGridItems()) { | 2140 if (grid.hasGridItems()) { |
| 2141 DCHECK_GE(grid.numTracks(ForRows), | 2141 DCHECK_GE(grid.numTracks(ForRows), |
| 2142 GridPositionsResolver::explicitGridRowCount( | 2142 GridPositionsResolver::explicitGridRowCount( |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2429 if (numPositions < 2) | 2429 if (numPositions < 2) |
| 2430 return tracks; | 2430 return tracks; |
| 2431 | 2431 |
| 2432 DCHECK(!m_grid.needsItemsPlacement()); | 2432 DCHECK(!m_grid.needsItemsPlacement()); |
| 2433 bool hasCollapsedTracks = m_grid.hasAutoRepeatEmptyTracks(direction); | 2433 bool hasCollapsedTracks = m_grid.hasAutoRepeatEmptyTracks(direction); |
| 2434 LayoutUnit gap = !hasCollapsedTracks | 2434 LayoutUnit gap = !hasCollapsedTracks |
| 2435 ? gridGapForDirection(direction, TrackSizing) | 2435 ? gridGapForDirection(direction, TrackSizing) |
| 2436 : LayoutUnit(); | 2436 : LayoutUnit(); |
| 2437 tracks.reserveCapacity(numPositions - 1); | 2437 tracks.reserveCapacity(numPositions - 1); |
| 2438 for (size_t i = 0; i < numPositions - 2; ++i) | 2438 for (size_t i = 0; i < numPositions - 2; ++i) |
| 2439 tracks.append(positions[i + 1] - positions[i] - offsetBetweenTracks - gap); | 2439 tracks.push_back(positions[i + 1] - positions[i] - offsetBetweenTracks - |
| 2440 tracks.append(positions[numPositions - 1] - positions[numPositions - 2]); | 2440 gap); |
| 2441 tracks.push_back(positions[numPositions - 1] - positions[numPositions - 2]); |
| 2441 | 2442 |
| 2442 if (!hasCollapsedTracks) | 2443 if (!hasCollapsedTracks) |
| 2443 return tracks; | 2444 return tracks; |
| 2444 | 2445 |
| 2445 size_t remainingEmptyTracks = m_grid.autoRepeatEmptyTracks(direction)->size(); | 2446 size_t remainingEmptyTracks = m_grid.autoRepeatEmptyTracks(direction)->size(); |
| 2446 size_t lastLine = tracks.size(); | 2447 size_t lastLine = tracks.size(); |
| 2447 gap = gridGapForDirection(direction, TrackSizing); | 2448 gap = gridGapForDirection(direction, TrackSizing); |
| 2448 for (size_t i = 1; i < lastLine; ++i) { | 2449 for (size_t i = 1; i < lastLine; ++i) { |
| 2449 if (m_grid.isEmptyAutoRepeatTrack(direction, i - 1)) { | 2450 if (m_grid.isEmptyAutoRepeatTrack(direction, i - 1)) { |
| 2450 --remainingEmptyTracks; | 2451 --remainingEmptyTracks; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2483 | 2484 |
| 2484 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing | 2485 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing |
| 2485 // function. | 2486 // function. |
| 2486 Vector<GridTrack>& tracks = (direction == ForColumns) | 2487 Vector<GridTrack>& tracks = (direction == ForColumns) |
| 2487 ? sizingData.columnTracks | 2488 ? sizingData.columnTracks |
| 2488 : sizingData.rowTracks; | 2489 : sizingData.rowTracks; |
| 2489 Vector<unsigned> autoSizedTracksIndex; | 2490 Vector<unsigned> autoSizedTracksIndex; |
| 2490 for (unsigned i = 0; i < tracks.size(); ++i) { | 2491 for (unsigned i = 0; i < tracks.size(); ++i) { |
| 2491 const GridTrackSize& trackSize = gridTrackSize(direction, i, sizingData); | 2492 const GridTrackSize& trackSize = gridTrackSize(direction, i, sizingData); |
| 2492 if (trackSize.hasAutoMaxTrackBreadth()) | 2493 if (trackSize.hasAutoMaxTrackBreadth()) |
| 2493 autoSizedTracksIndex.append(i); | 2494 autoSizedTracksIndex.push_back(i); |
| 2494 } | 2495 } |
| 2495 | 2496 |
| 2496 unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size(); | 2497 unsigned numberOfAutoSizedTracks = autoSizedTracksIndex.size(); |
| 2497 if (numberOfAutoSizedTracks < 1) | 2498 if (numberOfAutoSizedTracks < 1) |
| 2498 return; | 2499 return; |
| 2499 | 2500 |
| 2500 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; | 2501 LayoutUnit sizeToIncrease = availableSpace / numberOfAutoSizedTracks; |
| 2501 for (const auto& trackIndex : autoSizedTracksIndex) { | 2502 for (const auto& trackIndex : autoSizedTracksIndex) { |
| 2502 GridTrack* track = tracks.data() + trackIndex; | 2503 GridTrack* track = tracks.data() + trackIndex; |
| 2503 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; | 2504 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2575 LayoutUnit childGridAreaHeight = | 2576 LayoutUnit childGridAreaHeight = |
| 2576 isHorizontalWritingMode() ? overrideContainingBlockContentLogicalHeight | 2577 isHorizontalWritingMode() ? overrideContainingBlockContentLogicalHeight |
| 2577 : overrideContainingBlockContentLogicalWidth; | 2578 : overrideContainingBlockContentLogicalWidth; |
| 2578 LayoutUnit childGridAreaWidth = | 2579 LayoutUnit childGridAreaWidth = |
| 2579 isHorizontalWritingMode() ? overrideContainingBlockContentLogicalWidth | 2580 isHorizontalWritingMode() ? overrideContainingBlockContentLogicalWidth |
| 2580 : overrideContainingBlockContentLogicalHeight; | 2581 : overrideContainingBlockContentLogicalHeight; |
| 2581 LayoutRect gridAreaRect( | 2582 LayoutRect gridAreaRect( |
| 2582 gridAreaLogicalPosition(area), | 2583 gridAreaLogicalPosition(area), |
| 2583 LayoutSize(childGridAreaWidth, childGridAreaHeight)); | 2584 LayoutSize(childGridAreaWidth, childGridAreaHeight)); |
| 2584 if (!gridAreaRect.contains(child->frameRect())) | 2585 if (!gridAreaRect.contains(child->frameRect())) |
| 2585 m_gridItemsOverflowingGridArea.append(child); | 2586 m_gridItemsOverflowingGridArea.push_back(child); |
| 2586 } | 2587 } |
| 2587 } | 2588 } |
| 2588 | 2589 |
| 2589 void LayoutGrid::prepareChildForPositionedLayout(LayoutBox& child) { | 2590 void LayoutGrid::prepareChildForPositionedLayout(LayoutBox& child) { |
| 2590 ASSERT(child.isOutOfFlowPositioned()); | 2591 ASSERT(child.isOutOfFlowPositioned()); |
| 2591 child.containingBlock()->insertPositionedObject(&child); | 2592 child.containingBlock()->insertPositionedObject(&child); |
| 2592 | 2593 |
| 2593 PaintLayer* childLayer = child.layer(); | 2594 PaintLayer* childLayer = child.layer(); |
| 2594 childLayer->setStaticInlinePosition(borderAndPaddingStart()); | 2595 childLayer->setStaticInlinePosition(borderAndPaddingStart()); |
| 2595 childLayer->setStaticBlockPosition(borderAndPaddingBefore()); | 2596 childLayer->setStaticBlockPosition(borderAndPaddingBefore()); |
| (...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3617 if (direction == ForRows) | 3618 if (direction == ForRows) |
| 3618 return grid.numTracks(ForRows); | 3619 return grid.numTracks(ForRows); |
| 3619 | 3620 |
| 3620 return grid.numTracks(ForRows) | 3621 return grid.numTracks(ForRows) |
| 3621 ? grid.numTracks(ForColumns) | 3622 ? grid.numTracks(ForColumns) |
| 3622 : GridPositionsResolver::explicitGridColumnCount( | 3623 : GridPositionsResolver::explicitGridColumnCount( |
| 3623 styleRef(), grid.autoRepeatTracks(ForColumns)); | 3624 styleRef(), grid.autoRepeatTracks(ForColumns)); |
| 3624 } | 3625 } |
| 3625 | 3626 |
| 3626 } // namespace blink | 3627 } // namespace blink |
| OLD | NEW |