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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 return m_grid.size(); | 393 return m_grid.size(); |
394 } | 394 } |
395 | 395 |
396 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi
ngData) const | 396 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi
ngData) const |
397 { | 397 { |
398 LayoutUnit logicalHeight; | 398 LayoutUnit logicalHeight; |
399 | 399 |
400 for (const auto& row : sizingData.rowTracks) | 400 for (const auto& row : sizingData.rowTracks) |
401 logicalHeight += row.baseSize(); | 401 logicalHeight += row.baseSize(); |
402 | 402 |
403 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size()); | 403 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size(), sizing
Data.sizingOperation); |
404 | 404 |
405 return logicalHeight; | 405 return logicalHeight; |
406 } | 406 } |
407 | 407 |
408 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio
n, GridSizingData& sizingData, LayoutUnit availableSpace) | 408 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio
n, GridSizingData& sizingData, LayoutUnit availableSpace) |
409 { | 409 { |
410 DCHECK(sizingData.isValidTransition(direction)); | 410 DCHECK(sizingData.isValidTransition(direction)); |
411 sizingData.setAvailableSpace(availableSpace); | 411 sizingData.setAvailableSpace(availableSpace); |
412 sizingData.freeSpace(direction) = availableSpace - guttersSize(direction, 0,
direction == ForRows ? gridRowCount() : gridColumnCount()); | 412 sizingData.freeSpace(direction) = availableSpace - guttersSize(direction, 0,
direction == ForRows ? gridRowCount() : gridColumnCount(), sizingData.sizingOpe
ration); |
413 sizingData.sizingOperation = TrackSizing; | 413 sizingData.sizingOperation = TrackSizing; |
414 | 414 |
415 LayoutUnit baseSizes, growthLimits; | 415 LayoutUnit baseSizes, growthLimits; |
416 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit
s); | 416 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit
s); |
417 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); | 417 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); |
418 sizingData.nextState(); | 418 sizingData.nextState(); |
419 } | 419 } |
420 | 420 |
421 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn
it availableSpaceForColumns, LayoutUnit availableSpaceForRows) | 421 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn
it availableSpaceForColumns, LayoutUnit availableSpaceForRows) |
422 { | 422 { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 { | 522 { |
523 return direction == ForColumns ? !!m_autoRepeatEmptyColumns : !!m_autoRepeat
EmptyRows; | 523 return direction == ForColumns ? !!m_autoRepeatEmptyColumns : !!m_autoRepeat
EmptyRows; |
524 } | 524 } |
525 | 525 |
526 bool LayoutGrid::isEmptyAutoRepeatTrack(GridTrackSizingDirection direction, size
_t line) const | 526 bool LayoutGrid::isEmptyAutoRepeatTrack(GridTrackSizingDirection direction, size
_t line) const |
527 { | 527 { |
528 DCHECK(hasAutoRepeatEmptyTracks(direction)); | 528 DCHECK(hasAutoRepeatEmptyTracks(direction)); |
529 return direction == ForColumns ? m_autoRepeatEmptyColumns->contains(line) :
m_autoRepeatEmptyRows->contains(line); | 529 return direction == ForColumns ? m_autoRepeatEmptyColumns->contains(line) :
m_autoRepeatEmptyRows->contains(line); |
530 } | 530 } |
531 | 531 |
532 LayoutUnit LayoutGrid::gridGapForDirection(GridTrackSizingDirection direction) c
onst | 532 LayoutUnit LayoutGrid::gridGapForDirection(GridTrackSizingDirection direction, S
izingOperation sizingOperation) const |
533 { | 533 { |
534 return valueForLength(direction == ForColumns ? styleRef().gridColumnGap() :
styleRef().gridRowGap(), LayoutUnit()); | 534 LayoutUnit availableSize; |
| 535 if (sizingOperation == TrackSizing) |
| 536 availableSize = direction == ForColumns ? availableLogicalWidth() : avai
lableLogicalHeightForPercentageComputation(); |
| 537 |
| 538 // TODO(rego): Maybe we could cache the computed percentage as a performance
improvement. |
| 539 return valueForLength(direction == ForColumns ? styleRef().gridColumnGap() :
styleRef().gridRowGap(), availableSize); |
535 } | 540 } |
536 | 541 |
537 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t st
artLine, size_t span) const | 542 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t st
artLine, size_t span, SizingOperation sizingOperation) const |
538 { | 543 { |
539 if (span <= 1) | 544 if (span <= 1) |
540 return LayoutUnit(); | 545 return LayoutUnit(); |
541 | 546 |
542 bool isRowAxis = direction == ForColumns; | 547 bool isRowAxis = direction == ForColumns; |
543 LayoutUnit gap = gridGapForDirection(direction); | 548 LayoutUnit gap = gridGapForDirection(direction, sizingOperation); |
544 | 549 |
545 // Fast path, no collapsing tracks. | 550 // Fast path, no collapsing tracks. |
546 if (!hasAutoRepeatEmptyTracks(direction)) | 551 if (!hasAutoRepeatEmptyTracks(direction)) |
547 return gap * (span - 1); | 552 return gap * (span - 1); |
548 | 553 |
549 // If there are collapsing tracks we need to be sure that gutters are proper
ly collapsed. Apart | 554 // If there are collapsing tracks we need to be sure that gutters are proper
ly collapsed. Apart |
550 // from that, if we have a collapsed track in the edges of the span we're co
nsidering, we need | 555 // from that, if we have a collapsed track in the edges of the span we're co
nsidering, we need |
551 // to move forward (or backwards) in order to know whether the collapsed tra
cks reach the end of | 556 // to move forward (or backwards) in order to know whether the collapsed tra
cks reach the end of |
552 // the grid (so the gap becomes 0) or there is a non empty track before that
. | 557 // the grid (so the gap becomes 0) or there is a non empty track before that
. |
553 | 558 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
utUnit& maxLogicalWidth) const | 598 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
utUnit& maxLogicalWidth) const |
594 { | 599 { |
595 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); | 600 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); |
596 | 601 |
597 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 602 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
598 sizingData.setAvailableSpace(LayoutUnit()); | 603 sizingData.setAvailableSpace(LayoutUnit()); |
599 sizingData.freeSpace(ForColumns) = LayoutUnit(); | 604 sizingData.freeSpace(ForColumns) = LayoutUnit(); |
600 sizingData.sizingOperation = IntrinsicSizeComputation; | 605 sizingData.sizingOperation = IntrinsicSizeComputation; |
601 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL
ogicalWidth); | 606 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL
ogicalWidth); |
602 | 607 |
603 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr
acks.size()); | 608 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr
acks.size(), sizingData.sizingOperation); |
604 minLogicalWidth += totalGuttersSize; | 609 minLogicalWidth += totalGuttersSize; |
605 maxLogicalWidth += totalGuttersSize; | 610 maxLogicalWidth += totalGuttersSize; |
606 | 611 |
607 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); | 612 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); |
608 minLogicalWidth += scrollbarWidth; | 613 minLogicalWidth += scrollbarWidth; |
609 maxLogicalWidth += scrollbarWidth; | 614 maxLogicalWidth += scrollbarWidth; |
610 } | 615 } |
611 | 616 |
612 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) | 617 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) |
613 { | 618 { |
614 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); | 619 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); |
615 sizingData.setAvailableSpace(LayoutUnit()); | 620 sizingData.setAvailableSpace(LayoutUnit()); |
616 sizingData.freeSpace(ForRows) = LayoutUnit(); | 621 sizingData.freeSpace(ForRows) = LayoutUnit(); |
617 sizingData.sizingOperation = IntrinsicSizeComputation; | 622 sizingData.sizingOperation = IntrinsicSizeComputation; |
618 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma
xContentHeight); | 623 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma
xContentHeight); |
619 | 624 |
620 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount()); | 625 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount(), sizing
Data.sizingOperation); |
621 m_minContentHeight += totalGuttersSize; | 626 m_minContentHeight += totalGuttersSize; |
622 m_maxContentHeight += totalGuttersSize; | 627 m_maxContentHeight += totalGuttersSize; |
623 | 628 |
624 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); | 629 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); |
625 } | 630 } |
626 | 631 |
627 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l
ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi
ng) const | 632 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l
ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi
ng) const |
628 { | 633 { |
629 if (logicalHeightLength.isMinContent()) | 634 if (logicalHeightLength.isMinContent()) |
630 return m_minContentHeight; | 635 return m_minContentHeight; |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 | 1307 |
1303 sizingData.filteredTracks.append(&track); | 1308 sizingData.filteredTracks.append(&track); |
1304 | 1309 |
1305 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph
ase, trackSize)) | 1310 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph
ase, trackSize)) |
1306 sizingData.growBeyondGrowthLimitsTracks.append(&track); | 1311 sizingData.growBeyondGrowthLimitsTracks.append(&track); |
1307 } | 1312 } |
1308 | 1313 |
1309 if (sizingData.filteredTracks.isEmpty()) | 1314 if (sizingData.filteredTracks.isEmpty()) |
1310 continue; | 1315 continue; |
1311 | 1316 |
1312 spanningTracksSize += guttersSize(direction, itemSpan.startLine(), itemS
pan.integerSpan()); | 1317 spanningTracksSize += guttersSize(direction, itemSpan.startLine(), itemS
pan.integerSpan(), sizingData.sizingOperation); |
1313 | 1318 |
1314 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas
e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize; | 1319 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas
e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize; |
1315 extraSpace = extraSpace.clampNegativeToZero(); | 1320 extraSpace = extraSpace.clampNegativeToZero(); |
1316 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits
Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits
Tracks; | 1321 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits
Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits
Tracks; |
1317 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB
eyondGrowthLimits, sizingData, extraSpace); | 1322 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB
eyondGrowthLimits, sizingData, extraSpace); |
1318 } | 1323 } |
1319 | 1324 |
1320 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 1325 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
1321 GridTrack& track = tracks[trackIndex]; | 1326 GridTrack& track = tracks[trackIndex]; |
1322 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); | 1327 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat
eColumns() : styleRef().gridTemplateRows(); | 1496 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat
eColumns() : styleRef().gridTemplateRows(); |
1492 | 1497 |
1493 for (const auto& track : trackSizes) { | 1498 for (const auto& track : trackSizes) { |
1494 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() &&
!track.maxTrackBreadth().isContentSized(); | 1499 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() &&
!track.maxTrackBreadth().isContentSized(); |
1495 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength()
&& !track.minTrackBreadth().isContentSized())); | 1500 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength()
&& !track.minTrackBreadth().isContentSized())); |
1496 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack
Breadth().length() : track.minTrackBreadth().length(), availableSize); | 1501 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack
Breadth().length() : track.minTrackBreadth().length(), availableSize); |
1497 } | 1502 } |
1498 | 1503 |
1499 // Add gutters as if there where only 1 auto repeat track. Gaps between auto
repeat tracks will be added later when | 1504 // Add gutters as if there where only 1 auto repeat track. Gaps between auto
repeat tracks will be added later when |
1500 // computing the repetitions. | 1505 // computing the repetitions. |
1501 LayoutUnit gapSize = gridGapForDirection(direction); | 1506 LayoutUnit gapSize = gridGapForDirection(direction, sizingOperation); |
1502 tracksSize += gapSize * trackSizes.size(); | 1507 tracksSize += gapSize * trackSizes.size(); |
1503 | 1508 |
1504 LayoutUnit freeSpace = availableSize - tracksSize; | 1509 LayoutUnit freeSpace = availableSize - tracksSize; |
1505 if (freeSpace <= 0) | 1510 if (freeSpace <= 0) |
1506 return autoRepeatTrackListLength; | 1511 return autoRepeatTrackListLength; |
1507 | 1512 |
1508 size_t repetitions = 1 + (freeSpace / (autoRepeatTracksSize + gapSize)).toIn
t(); | 1513 size_t repetitions = 1 + (freeSpace / (autoRepeatTracksSize + gapSize)).toIn
t(); |
1509 | 1514 |
1510 // Provided the grid container does not have a definite size or max-size in
the relevant axis, | 1515 // Provided the grid container does not have a definite size or max-size in
the relevant axis, |
1511 // if the min size is definite then the number of repetitions is the largest
possible positive | 1516 // if the min size is definite then the number of repetitions is the largest
possible positive |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 bool isRowAxis = direction == ForColumns; | 1818 bool isRowAxis = direction == ForColumns; |
1814 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; | 1819 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
1815 size_t numPositions = positions.size(); | 1820 size_t numPositions = positions.size(); |
1816 LayoutUnit offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offs
etBetweenRows; | 1821 LayoutUnit offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offs
etBetweenRows; |
1817 | 1822 |
1818 Vector<LayoutUnit> tracks; | 1823 Vector<LayoutUnit> tracks; |
1819 if (numPositions < 2) | 1824 if (numPositions < 2) |
1820 return tracks; | 1825 return tracks; |
1821 | 1826 |
1822 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); | 1827 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); |
1823 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction) : Layo
utUnit(); | 1828 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction, TrackS
izing) : LayoutUnit(); |
1824 tracks.reserveCapacity(numPositions - 1); | 1829 tracks.reserveCapacity(numPositions - 1); |
1825 for (size_t i = 0; i < numPositions - 2; ++i) | 1830 for (size_t i = 0; i < numPositions - 2; ++i) |
1826 tracks.append(positions[i + 1] - positions[i] - offsetBetweenTracks - ga
p); | 1831 tracks.append(positions[i + 1] - positions[i] - offsetBetweenTracks - ga
p); |
1827 tracks.append(positions[numPositions - 1] - positions[numPositions - 2]); | 1832 tracks.append(positions[numPositions - 1] - positions[numPositions - 2]); |
1828 | 1833 |
1829 if (!hasCollapsedTracks) | 1834 if (!hasCollapsedTracks) |
1830 return tracks; | 1835 return tracks; |
1831 | 1836 |
1832 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->size() :
m_autoRepeatEmptyRows->size(); | 1837 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->size() :
m_autoRepeatEmptyRows->size(); |
1833 size_t lastLine = tracks.size(); | 1838 size_t lastLine = tracks.size(); |
1834 gap = gridGapForDirection(direction); | 1839 gap = gridGapForDirection(direction, TrackSizing); |
1835 for (size_t i = 1; i < lastLine; ++i) { | 1840 for (size_t i = 1; i < lastLine; ++i) { |
1836 if (isEmptyAutoRepeatTrack(direction, i - 1)) { | 1841 if (isEmptyAutoRepeatTrack(direction, i - 1)) { |
1837 --remainingEmptyTracks; | 1842 --remainingEmptyTracks; |
1838 } else { | 1843 } else { |
1839 // Remove the gap between consecutive non empty tracks. Remove it al
so just once for an | 1844 // Remove the gap between consecutive non empty tracks. Remove it al
so just once for an |
1840 // arbitrary number of empty tracks between two non empty ones. | 1845 // arbitrary number of empty tracks between two non empty ones. |
1841 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (lastLine
- i); | 1846 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (lastLine
- i); |
1842 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(direction
, i)) | 1847 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(direction
, i)) |
1843 tracks[i - 1] -= gap; | 1848 tracks[i - 1] -= gap; |
1844 } | 1849 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2030 if (styleRef().isLeftToRightDirection()) | 2035 if (styleRef().isLeftToRightDirection()) |
2031 end = m_columnPositions[endLine] - borderLogicalLeft(); | 2036 end = m_columnPositions[endLine] - borderLogicalLeft(); |
2032 else | 2037 else |
2033 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[
endLine]) - borderLogicalRight(); | 2038 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[
endLine]) - borderLogicalRight(); |
2034 } else { | 2039 } else { |
2035 end = m_rowPositions[endLine] - borderBefore(); | 2040 end = m_rowPositions[endLine] - borderBefore(); |
2036 } | 2041 } |
2037 | 2042 |
2038 // These vectors store line positions including gaps, but we shouldn't c
onsider them for the edges of the grid. | 2043 // These vectors store line positions including gaps, but we shouldn't c
onsider them for the edges of the grid. |
2039 if (endLine > 0 && endLine < lastLine) { | 2044 if (endLine > 0 && endLine < lastLine) { |
2040 end -= guttersSize(direction, endLine - 1, 2); | 2045 end -= guttersSize(direction, endLine - 1, 2, TrackSizing); |
2041 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; | 2046 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; |
2042 } | 2047 } |
2043 } | 2048 } |
2044 | 2049 |
2045 breadth = std::max(end - start, LayoutUnit()); | 2050 breadth = std::max(end - start, LayoutUnit()); |
2046 offset = start; | 2051 offset = start; |
2047 | 2052 |
2048 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef(
).hasStaticInlinePosition(child.isHorizontalWritingMode())) { | 2053 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef(
).hasStaticInlinePosition(child.isHorizontalWritingMode())) { |
2049 // If the child doesn't have a static inline position (i.e. "left" and/o
r "right" aren't "auto", | 2054 // If the child doesn't have a static inline position (i.e. "left" and/o
r "right" aren't "auto", |
2050 // we need to calculate the offset from the left (even if we're in RTL). | 2055 // we need to calculate the offset from the left (even if we're in RTL). |
2051 if (endIsAuto) { | 2056 if (endIsAuto) { |
2052 offset = LayoutUnit(); | 2057 offset = LayoutUnit(); |
2053 } else { | 2058 } else { |
2054 offset = translateRTLCoordinate(m_columnPositions[endLine]) - border
LogicalLeft(); | 2059 offset = translateRTLCoordinate(m_columnPositions[endLine]) - border
LogicalLeft(); |
2055 | 2060 |
2056 if (endLine > 0 && endLine < lastLine) { | 2061 if (endLine > 0 && endLine < lastLine) { |
2057 offset += guttersSize(direction, endLine - 1, 2); | 2062 offset += guttersSize(direction, endLine - 1, 2, TrackSizing); |
2058 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee
nRows; | 2063 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee
nRows; |
2059 } | 2064 } |
2060 } | 2065 } |
2061 } | 2066 } |
2062 | 2067 |
2063 } | 2068 } |
2064 | 2069 |
2065 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const | 2070 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const |
2066 { | 2071 { |
2067 ASSERT(m_gridItemArea.contains(&gridItem)); | 2072 ASSERT(m_gridItemArea.contains(&gridItem)); |
(...skipping 14 matching lines...) Expand all Loading... |
2082 bool gridAreaIsIndefinite = false; | 2087 bool gridAreaIsIndefinite = false; |
2083 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon
tent(ExcludeMarginBorderPadding); | 2088 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon
tent(ExcludeMarginBorderPadding); |
2084 for (auto trackPosition : span) { | 2089 for (auto trackPosition : span) { |
2085 const GridLength& maxTrackSize = gridTrackSize(ForRows, trackPosition, s
izingOperation).maxTrackBreadth(); | 2090 const GridLength& maxTrackSize = gridTrackSize(ForRows, trackPosition, s
izingOperation).maxTrackBreadth(); |
2086 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) | 2091 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) |
2087 gridAreaIsIndefinite = true; | 2092 gridAreaIsIndefinite = true; |
2088 else | 2093 else |
2089 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc
kAvailableSize); | 2094 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc
kAvailableSize); |
2090 } | 2095 } |
2091 | 2096 |
2092 gridAreaSize += guttersSize(ForRows, span.startLine(), span.integerSpan()); | 2097 gridAreaSize += guttersSize(ForRows, span.startLine(), span.integerSpan(), s
izingOperation); |
2093 | 2098 |
2094 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri
dAreaSize) : gridAreaSize; | 2099 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri
dAreaSize) : gridAreaSize; |
2095 } | 2100 } |
2096 | 2101 |
2097 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
SizingDirection direction, const GridSizingData& sizingData) const | 2102 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
SizingDirection direction, const GridSizingData& sizingData) const |
2098 { | 2103 { |
2099 // To determine the column track's size based on an orthogonal grid item we
need it's logical height, which | 2104 // To determine the column track's size based on an orthogonal grid item we
need it's logical height, which |
2100 // may depend on the row track's size. It's possible that the row tracks siz
ing logic has not been performed yet, | 2105 // may depend on the row track's size. It's possible that the row tracks siz
ing logic has not been performed yet, |
2101 // so we will need to do an estimation. | 2106 // so we will need to do an estimation. |
2102 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column
SizingFirstIteration) | 2107 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column
SizingFirstIteration) |
2103 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperati
on); | 2108 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperati
on); |
2104 | 2109 |
2105 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum
nTracks : sizingData.rowTracks; | 2110 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum
nTracks : sizingData.rowTracks; |
2106 const GridSpan& span = cachedGridSpan(child, direction); | 2111 const GridSpan& span = cachedGridSpan(child, direction); |
2107 LayoutUnit gridAreaBreadth; | 2112 LayoutUnit gridAreaBreadth; |
2108 for (const auto& trackPosition : span) | 2113 for (const auto& trackPosition : span) |
2109 gridAreaBreadth += tracks[trackPosition].baseSize(); | 2114 gridAreaBreadth += tracks[trackPosition].baseSize(); |
2110 | 2115 |
2111 gridAreaBreadth += guttersSize(direction, span.startLine(), span.integerSpan
()); | 2116 gridAreaBreadth += guttersSize(direction, span.startLine(), span.integerSpan
(), sizingData.sizingOperation); |
2112 | 2117 |
2113 return gridAreaBreadth; | 2118 return gridAreaBreadth; |
2114 } | 2119 } |
2115 | 2120 |
2116 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La
youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing
Data) const | 2121 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La
youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing
Data) const |
2117 { | 2122 { |
2118 // We need the cached value when available because Content Distribution alig
nment properties | 2123 // We need the cached value when available because Content Distribution alig
nment properties |
2119 // may have some influence in the final grid area breadth. | 2124 // may have some influence in the final grid area breadth. |
2120 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col
umnTracks : sizingData.rowTracks; | 2125 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col
umnTracks : sizingData.rowTracks; |
2121 const GridSpan& span = cachedGridSpan(child, direction); | 2126 const GridSpan& span = cachedGridSpan(child, direction); |
(...skipping 20 matching lines...) Expand all Loading... |
2142 size_t lastLine = numberOfLines - 1; | 2147 size_t lastLine = numberOfLines - 1; |
2143 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di
rection, sizingData.freeSpace(direction), numberOfTracks); | 2148 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di
rection, sizingData.freeSpace(direction), numberOfTracks); |
2144 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; | 2149 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
2145 positions.resize(numberOfLines); | 2150 positions.resize(numberOfLines); |
2146 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn
dPaddingBefore(); | 2151 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn
dPaddingBefore(); |
2147 positions[0] = borderAndPadding + offset.positionOffset; | 2152 positions[0] = borderAndPadding + offset.positionOffset; |
2148 if (numberOfLines > 1) { | 2153 if (numberOfLines > 1) { |
2149 // If we have collapsed tracks we just ignore gaps here and add them lat
er as we might not | 2154 // If we have collapsed tracks we just ignore gaps here and add them lat
er as we might not |
2150 // compute the gap between two consecutive tracks without examining the
surrounding ones. | 2155 // compute the gap between two consecutive tracks without examining the
surrounding ones. |
2151 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); | 2156 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); |
2152 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction) :
LayoutUnit(); | 2157 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction, si
zingData.sizingOperation) : LayoutUnit(); |
2153 size_t nextToLastLine = numberOfLines - 2; | 2158 size_t nextToLastLine = numberOfLines - 2; |
2154 for (size_t i = 0; i < nextToLastLine; ++i) | 2159 for (size_t i = 0; i < nextToLastLine; ++i) |
2155 positions[i + 1] = positions[i] + offset.distributionOffset + tracks
[i].baseSize() + gap; | 2160 positions[i + 1] = positions[i] + offset.distributionOffset + tracks
[i].baseSize() + gap; |
2156 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine]
.baseSize(); | 2161 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine]
.baseSize(); |
2157 | 2162 |
2158 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters
to collapse (they | 2163 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters
to collapse (they |
2159 // coincide exactly) except on the edges of the grid where they become 0
. | 2164 // coincide exactly) except on the edges of the grid where they become 0
. |
2160 if (hasCollapsedTracks) { | 2165 if (hasCollapsedTracks) { |
2161 gap = gridGapForDirection(direction); | 2166 gap = gridGapForDirection(direction, sizingData.sizingOperation); |
2162 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->
size() : m_autoRepeatEmptyRows->size(); | 2167 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->
size() : m_autoRepeatEmptyRows->size(); |
2163 LayoutUnit gapAccumulator; | 2168 LayoutUnit gapAccumulator; |
2164 for (size_t i = 1; i < lastLine; ++i) { | 2169 for (size_t i = 1; i < lastLine; ++i) { |
2165 if (isEmptyAutoRepeatTrack(direction, i - 1)) { | 2170 if (isEmptyAutoRepeatTrack(direction, i - 1)) { |
2166 --remainingEmptyTracks; | 2171 --remainingEmptyTracks; |
2167 } else { | 2172 } else { |
2168 // Add gap between consecutive non empty tracks. Add it also
just once for an | 2173 // Add gap between consecutive non empty tracks. Add it also
just once for an |
2169 // arbitrary number of empty tracks between two non empty on
es. | 2174 // arbitrary number of empty tracks between two non empty on
es. |
2170 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (l
astLine - i); | 2175 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (l
astLine - i); |
2171 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(d
irection, i)) | 2176 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(d
irection, i)) |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2473 switch (axisPosition) { | 2478 switch (axisPosition) { |
2474 case GridAxisStart: | 2479 case GridAxisStart: |
2475 return startPosition; | 2480 return startPosition; |
2476 case GridAxisEnd: | 2481 case GridAxisEnd: |
2477 case GridAxisCenter: { | 2482 case GridAxisCenter: { |
2478 size_t childEndLine = rowsSpan.endLine(); | 2483 size_t childEndLine = rowsSpan.endLine(); |
2479 LayoutUnit endOfRow = m_rowPositions[childEndLine]; | 2484 LayoutUnit endOfRow = m_rowPositions[childEndLine]; |
2480 // m_rowPositions include distribution offset (because of content alignm
ent) and gutters | 2485 // m_rowPositions include distribution offset (because of content alignm
ent) and gutters |
2481 // so we need to subtract them to get the actual end position for a give
n row | 2486 // so we need to subtract them to get the actual end position for a give
n row |
2482 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). | 2487 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). |
2483 LayoutUnit trackGap = gridGapForDirection(ForRows); | 2488 LayoutUnit trackGap = gridGapForDirection(ForRows, sizingData.sizingOper
ation); |
2484 if (childEndLine < m_rowPositions.size() - 1) { | 2489 if (childEndLine < m_rowPositions.size() - 1) { |
2485 endOfRow -= trackGap; | 2490 endOfRow -= trackGap; |
2486 endOfRow -= m_offsetBetweenRows; | 2491 endOfRow -= m_offsetBetweenRows; |
2487 } | 2492 } |
2488 LayoutUnit columnAxisChildSize = isOrthogonalChild(child) ? child.logica
lWidth() + child.marginLogicalWidth() : child.logicalHeight() + child.marginLogi
calHeight(); | 2493 LayoutUnit columnAxisChildSize = isOrthogonalChild(child) ? child.logica
lWidth() + child.marginLogicalWidth() : child.logicalHeight() + child.marginLogi
calHeight(); |
2489 OverflowAlignment overflow = alignSelfForChild(child).overflow(); | 2494 OverflowAlignment overflow = alignSelfForChild(child).overflow(); |
2490 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfRow - startOfRow, columnAxisChildSize); | 2495 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfRow - startOfRow, columnAxisChildSize); |
2491 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 2496 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
2492 } | 2497 } |
2493 } | 2498 } |
(...skipping 14 matching lines...) Expand all Loading... |
2508 switch (axisPosition) { | 2513 switch (axisPosition) { |
2509 case GridAxisStart: | 2514 case GridAxisStart: |
2510 return startPosition; | 2515 return startPosition; |
2511 case GridAxisEnd: | 2516 case GridAxisEnd: |
2512 case GridAxisCenter: { | 2517 case GridAxisCenter: { |
2513 size_t childEndLine = columnsSpan.endLine(); | 2518 size_t childEndLine = columnsSpan.endLine(); |
2514 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; | 2519 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; |
2515 // m_columnPositions include distribution offset (because of content ali
gnment) and gutters | 2520 // m_columnPositions include distribution offset (because of content ali
gnment) and gutters |
2516 // so we need to subtract them to get the actual end position for a give
n column | 2521 // so we need to subtract them to get the actual end position for a give
n column |
2517 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). | 2522 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). |
2518 LayoutUnit trackGap = gridGapForDirection(ForColumns); | 2523 LayoutUnit trackGap = gridGapForDirection(ForColumns, sizingData.sizingO
peration); |
2519 if (childEndLine < m_columnPositions.size() - 1) { | 2524 if (childEndLine < m_columnPositions.size() - 1) { |
2520 endOfColumn -= trackGap; | 2525 endOfColumn -= trackGap; |
2521 endOfColumn -= m_offsetBetweenColumns; | 2526 endOfColumn -= m_offsetBetweenColumns; |
2522 } | 2527 } |
2523 LayoutUnit rowAxisChildSize = isOrthogonalChild(child) ? child.logicalHe
ight() + child.marginLogicalHeight() : child.logicalWidth() + child.marginLogica
lWidth(); | 2528 LayoutUnit rowAxisChildSize = isOrthogonalChild(child) ? child.logicalHe
ight() + child.marginLogicalHeight() : child.logicalWidth() + child.marginLogica
lWidth(); |
2524 OverflowAlignment overflow = justifySelfForChild(child).overflow(); | 2529 OverflowAlignment overflow = justifySelfForChild(child).overflow(); |
2525 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfColumn - startOfColumn, rowAxisChildSize); | 2530 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfColumn - startOfColumn, rowAxisChildSize); |
2526 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 2531 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
2527 } | 2532 } |
2528 } | 2533 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2658 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc
ation; | 2663 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc
ation; |
2659 } | 2664 } |
2660 | 2665 |
2661 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const | 2666 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const |
2662 { | 2667 { |
2663 if (!m_gridItemArea.isEmpty()) | 2668 if (!m_gridItemArea.isEmpty()) |
2664 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2669 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2665 } | 2670 } |
2666 | 2671 |
2667 } // namespace blink | 2672 } // namespace blink |
OLD | NEW |