| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 return m_grid.size(); | 380 return m_grid.size(); |
| 381 } | 381 } |
| 382 | 382 |
| 383 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi
ngData) const | 383 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight(const GridSizingData& sizi
ngData) const |
| 384 { | 384 { |
| 385 LayoutUnit logicalHeight; | 385 LayoutUnit logicalHeight; |
| 386 | 386 |
| 387 for (const auto& row : sizingData.rowTracks) | 387 for (const auto& row : sizingData.rowTracks) |
| 388 logicalHeight += row.baseSize(); | 388 logicalHeight += row.baseSize(); |
| 389 | 389 |
| 390 logicalHeight += guttersSize(ForRows, sizingData.rowTracks.size()); | 390 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size()); |
| 391 | 391 |
| 392 return logicalHeight; | 392 return logicalHeight; |
| 393 } | 393 } |
| 394 | 394 |
| 395 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio
n, GridSizingData& sizingData, LayoutUnit freeSpace) | 395 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio
n, GridSizingData& sizingData, LayoutUnit freeSpace) |
| 396 { | 396 { |
| 397 DCHECK(sizingData.isValidTransitionForDirection(direction)); | 397 DCHECK(sizingData.isValidTransitionForDirection(direction)); |
| 398 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct
ion, direction == ForRows ? gridRowCount() : gridColumnCount()); | 398 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct
ion, 0, direction == ForRows ? gridRowCount() : gridColumnCount()); |
| 399 sizingData.sizingOperation = TrackSizing; | 399 sizingData.sizingOperation = TrackSizing; |
| 400 | 400 |
| 401 LayoutUnit baseSizes, growthLimits; | 401 LayoutUnit baseSizes, growthLimits; |
| 402 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit
s); | 402 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit
s); |
| 403 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); | 403 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); |
| 404 sizingData.nextState(); | 404 sizingData.nextState(); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn
it availableSpaceForColumns, LayoutUnit availableSpaceForRows) | 407 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn
it availableSpaceForColumns, LayoutUnit availableSpaceForRows) |
| 408 { | 408 { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 497 |
| 498 computeOverflow(oldClientAfterEdge); | 498 computeOverflow(oldClientAfterEdge); |
| 499 } | 499 } |
| 500 | 500 |
| 501 updateLayerTransformAfterLayout(); | 501 updateLayerTransformAfterLayout(); |
| 502 updateAfterLayout(); | 502 updateAfterLayout(); |
| 503 | 503 |
| 504 clearNeedsLayout(); | 504 clearNeedsLayout(); |
| 505 } | 505 } |
| 506 | 506 |
| 507 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t sp
an) const | 507 bool LayoutGrid::hasAutoRepeatEmptyTracks(GridTrackSizingDirection direction) co
nst |
| 508 { |
| 509 return direction == ForColumns ? !!m_autoRepeatEmptyColumns : !!m_autoRepeat
EmptyRows; |
| 510 } |
| 511 |
| 512 bool LayoutGrid::isEmptyAutoRepeatTrack(GridTrackSizingDirection direction, size
_t line) const |
| 513 { |
| 514 DCHECK(hasAutoRepeatEmptyTracks(direction)); |
| 515 return direction == ForColumns ? m_autoRepeatEmptyColumns->contains(line) :
m_autoRepeatEmptyRows->contains(line); |
| 516 } |
| 517 |
| 518 LayoutUnit LayoutGrid::gridGapForDirection(GridTrackSizingDirection direction) c
onst |
| 519 { |
| 520 return valueForLength(direction == ForColumns ? styleRef().gridColumnGap() :
styleRef().gridRowGap(), LayoutUnit()); |
| 521 } |
| 522 |
| 523 LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t st
artLine, size_t span) const |
| 508 { | 524 { |
| 509 if (span <= 1) | 525 if (span <= 1) |
| 510 return LayoutUnit(); | 526 return LayoutUnit(); |
| 511 | 527 |
| 512 const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap(
) : styleRef().gridRowGap(); | 528 bool isRowAxis = direction == ForColumns; |
| 513 return valueForLength(trackGap, LayoutUnit()) * (span - 1); | 529 LayoutUnit gap = gridGapForDirection(direction); |
| 530 |
| 531 // Fast path, no collapsing tracks. |
| 532 if (!hasAutoRepeatEmptyTracks(direction)) |
| 533 return gap * (span - 1); |
| 534 |
| 535 // If there are collapsing tracks we need to be sure that gutters are proper
ly collapsed. Apart |
| 536 // from that, if we have a collapsed track in the edges of the span we're co
nsidering, we need |
| 537 // to move forward (or backwards) in order to know whether the collapsed tra
cks reach the end of |
| 538 // the grid (so the gap becomes 0) or there is a non empty track before that
. |
| 539 |
| 540 LayoutUnit gapAccumulator; |
| 541 size_t endLine = startLine + span; |
| 542 |
| 543 for (size_t line = startLine; line < endLine - 1; ++line) { |
| 544 if (!isEmptyAutoRepeatTrack(direction, line)) |
| 545 gapAccumulator += gap; |
| 546 } |
| 547 |
| 548 // If the startLine is the start line of a collapsed track we need to go bac
kwards till we reach |
| 549 // a non collapsed track. If we find a non collapsed track we need to add th
at gap. |
| 550 if (startLine && isEmptyAutoRepeatTrack(direction, startLine)) { |
| 551 size_t nonEmptyTracksBeforeStartLine = startLine; |
| 552 auto begin = isRowAxis ? m_autoRepeatEmptyColumns->begin() : m_autoRepea
tEmptyRows->begin(); |
| 553 for (auto it = begin; *it != startLine; ++it) { |
| 554 DCHECK(nonEmptyTracksBeforeStartLine); |
| 555 --nonEmptyTracksBeforeStartLine; |
| 556 } |
| 557 if (nonEmptyTracksBeforeStartLine) |
| 558 gapAccumulator += gap; |
| 559 } |
| 560 |
| 561 // If the endLine is the end line of a collapsed track we need to go forward
till we reach a non |
| 562 // collapsed track. If we find a non collapsed track we need to add that gap
. |
| 563 if (isEmptyAutoRepeatTrack(direction, endLine - 1)) { |
| 564 size_t nonEmptyTracksAfterEndLine = (isRowAxis ? gridColumnCount() : gri
dRowCount()) - endLine; |
| 565 auto currentEmptyTrack = isRowAxis ? m_autoRepeatEmptyColumns->find(endL
ine - 1) : m_autoRepeatEmptyRows->find(endLine - 1); |
| 566 auto endEmptyTrack = isRowAxis ? m_autoRepeatEmptyColumns->end() : m_aut
oRepeatEmptyRows->end(); |
| 567 // HashSet iterators do not implement operator- so we have to manually i
terate to know the number of remaining empty tracks. |
| 568 for (auto it = ++currentEmptyTrack; it != endEmptyTrack; ++it) { |
| 569 DCHECK(nonEmptyTracksAfterEndLine); |
| 570 --nonEmptyTracksAfterEndLine; |
| 571 } |
| 572 if (nonEmptyTracksAfterEndLine) |
| 573 gapAccumulator += gap; |
| 574 } |
| 575 |
| 576 return gapAccumulator; |
| 514 } | 577 } |
| 515 | 578 |
| 516 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
utUnit& maxLogicalWidth) const | 579 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
utUnit& maxLogicalWidth) const |
| 517 { | 580 { |
| 518 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); | 581 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); |
| 519 | 582 |
| 520 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 583 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
| 521 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit(); | 584 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit(); |
| 522 sizingData.sizingOperation = IntrinsicSizeComputation; | 585 sizingData.sizingOperation = IntrinsicSizeComputation; |
| 523 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL
ogicalWidth); | 586 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL
ogicalWidth); |
| 524 | 587 |
| 525 LayoutUnit totalGuttersSize = guttersSize(ForColumns, sizingData.columnTrack
s.size()); | 588 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr
acks.size()); |
| 526 minLogicalWidth += totalGuttersSize; | 589 minLogicalWidth += totalGuttersSize; |
| 527 maxLogicalWidth += totalGuttersSize; | 590 maxLogicalWidth += totalGuttersSize; |
| 528 | 591 |
| 529 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); | 592 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); |
| 530 minLogicalWidth += scrollbarWidth; | 593 minLogicalWidth += scrollbarWidth; |
| 531 maxLogicalWidth += scrollbarWidth; | 594 maxLogicalWidth += scrollbarWidth; |
| 532 } | 595 } |
| 533 | 596 |
| 534 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) | 597 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) |
| 535 { | 598 { |
| 536 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); | 599 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); |
| 537 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit(); | 600 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit(); |
| 538 sizingData.sizingOperation = IntrinsicSizeComputation; | 601 sizingData.sizingOperation = IntrinsicSizeComputation; |
| 539 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma
xContentHeight); | 602 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma
xContentHeight); |
| 540 | 603 |
| 541 LayoutUnit totalGuttersSize = guttersSize(ForRows, gridRowCount()); | 604 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount()); |
| 542 m_minContentHeight += totalGuttersSize; | 605 m_minContentHeight += totalGuttersSize; |
| 543 m_maxContentHeight += totalGuttersSize; | 606 m_maxContentHeight += totalGuttersSize; |
| 544 | 607 |
| 545 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); | 608 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); |
| 546 } | 609 } |
| 547 | 610 |
| 548 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l
ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi
ng) const | 611 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l
ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi
ng) const |
| 549 { | 612 { |
| 550 if (logicalHeightLength.isMinContent()) | 613 if (logicalHeightLength.isMinContent()) |
| 551 return m_minContentHeight; | 614 return m_minContentHeight; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 576 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction); | 639 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction); |
| 577 const LayoutUnit initialFreeSpace = freeSpace; | 640 const LayoutUnit initialFreeSpace = freeSpace; |
| 578 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra
cks : sizingData.rowTracks; | 641 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra
cks : sizingData.rowTracks; |
| 579 Vector<size_t> flexibleSizedTracksIndex; | 642 Vector<size_t> flexibleSizedTracksIndex; |
| 580 sizingData.contentSizedTracksIndex.shrink(0); | 643 sizingData.contentSizedTracksIndex.shrink(0); |
| 581 | 644 |
| 582 LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace); | 645 LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace); |
| 583 // Grid gutters were removed from freeSpace by the caller, but we must use t
hem to compute relative (i.e. percentages) sizes. | 646 // Grid gutters were removed from freeSpace by the caller, but we must use t
hem to compute relative (i.e. percentages) sizes. |
| 584 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; | 647 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; |
| 585 if (hasDefiniteFreeSpace) | 648 if (hasDefiniteFreeSpace) |
| 586 maxSize += guttersSize(direction, direction == ForRows ? gridRowCount()
: gridColumnCount()); | 649 maxSize += guttersSize(direction, 0, direction == ForRows ? gridRowCount
() : gridColumnCount()); |
| 587 | 650 |
| 588 // 1. Initialize per Grid track variables. | 651 // 1. Initialize per Grid track variables. |
| 589 for (size_t i = 0; i < tracks.size(); ++i) { | 652 for (size_t i = 0; i < tracks.size(); ++i) { |
| 590 GridTrack& track = tracks[i]; | 653 GridTrack& track = tracks[i]; |
| 591 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO
peration); | 654 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO
peration); |
| 592 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 655 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
| 593 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); | 656 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); |
| 594 | 657 |
| 595 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize
)); | 658 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize
)); |
| 596 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac
k.baseSize(), maxSize)); | 659 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac
k.baseSize(), maxSize)); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 return trackStyles[untranslatedIndex]; | 869 return trackStyles[untranslatedIndex]; |
| 807 | 870 |
| 808 if (untranslatedIndex < (insertionPoint + repetitions)) | 871 if (untranslatedIndex < (insertionPoint + repetitions)) |
| 809 return autoRepeatTrackStyles[0]; | 872 return autoRepeatTrackStyles[0]; |
| 810 | 873 |
| 811 return trackStyles[untranslatedIndex - repetitions]; | 874 return trackStyles[untranslatedIndex - repetitions]; |
| 812 } | 875 } |
| 813 | 876 |
| 814 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size
_t translatedIndex, SizingOperation sizingOperation) const | 877 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size
_t translatedIndex, SizingOperation sizingOperation) const |
| 815 { | 878 { |
| 879 // Collapse empty auto repeat tracks if auto-fit. |
| 880 if (hasAutoRepeatEmptyTracks(direction) && isEmptyAutoRepeatTrack(direction,
translatedIndex)) |
| 881 return { Length(Fixed), Length(Fixed) }; |
| 882 |
| 816 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex
); | 883 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex
); |
| 817 | 884 |
| 818 GridLength minTrackBreadth = trackSize.minTrackBreadth(); | 885 GridLength minTrackBreadth = trackSize.minTrackBreadth(); |
| 819 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); | 886 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); |
| 820 | 887 |
| 821 // If the logical width/height of the grid container is indefinite, percenta
ge values are treated as <auto>. | 888 // If the logical width/height of the grid container is indefinite, percenta
ge values are treated as <auto>. |
| 822 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { | 889 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { |
| 823 // For the inline axis this only happens when we're computing the intrin
sic sizes (AvailableSpaceIndefinite). | 890 // For the inline axis this only happens when we're computing the intrin
sic sizes (AvailableSpaceIndefinite). |
| 824 // For the block axis we check that the percentage height is resolvable
on the first in-flow child. | 891 // For the block axis we check that the percentage height is resolvable
on the first in-flow child. |
| 825 // TODO (lajava) This condition for determining whether a size is indefi
nite or not is not working correctly for orthogonal flows. | 892 // TODO (lajava) This condition for determining whether a size is indefi
nite or not is not working correctly for orthogonal flows. |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 | 1267 |
| 1201 sizingData.filteredTracks.append(&track); | 1268 sizingData.filteredTracks.append(&track); |
| 1202 | 1269 |
| 1203 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph
ase, trackSize)) | 1270 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph
ase, trackSize)) |
| 1204 sizingData.growBeyondGrowthLimitsTracks.append(&track); | 1271 sizingData.growBeyondGrowthLimitsTracks.append(&track); |
| 1205 } | 1272 } |
| 1206 | 1273 |
| 1207 if (sizingData.filteredTracks.isEmpty()) | 1274 if (sizingData.filteredTracks.isEmpty()) |
| 1208 continue; | 1275 continue; |
| 1209 | 1276 |
| 1210 spanningTracksSize += guttersSize(direction, itemSpan.integerSpan()); | 1277 spanningTracksSize += guttersSize(direction, itemSpan.startLine(), itemS
pan.integerSpan()); |
| 1211 | 1278 |
| 1212 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas
e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize; | 1279 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas
e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize; |
| 1213 extraSpace = extraSpace.clampNegativeToZero(); | 1280 extraSpace = extraSpace.clampNegativeToZero(); |
| 1214 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits
Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits
Tracks; | 1281 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits
Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits
Tracks; |
| 1215 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB
eyondGrowthLimits, sizingData, extraSpace); | 1282 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB
eyondGrowthLimits, sizingData, extraSpace); |
| 1216 } | 1283 } |
| 1217 | 1284 |
| 1218 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 1285 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 1219 GridTrack& track = tracks[trackIndex]; | 1286 GridTrack& track = tracks[trackIndex]; |
| 1220 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); | 1287 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat
eColumns() : styleRef().gridTemplateRows(); | 1430 const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplat
eColumns() : styleRef().gridTemplateRows(); |
| 1364 | 1431 |
| 1365 for (const auto& track : trackSizes) { | 1432 for (const auto& track : trackSizes) { |
| 1366 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() &&
!track.maxTrackBreadth().isContentSized(); | 1433 bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() &&
!track.maxTrackBreadth().isContentSized(); |
| 1367 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength()
&& !track.minTrackBreadth().isContentSized())); | 1434 DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength()
&& !track.minTrackBreadth().isContentSized())); |
| 1368 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack
Breadth().length() : track.minTrackBreadth().length(), availableSize); | 1435 tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrack
Breadth().length() : track.minTrackBreadth().length(), availableSize); |
| 1369 } | 1436 } |
| 1370 | 1437 |
| 1371 // Add gutters as if there where only 1 auto repeat track. Gaps between auto
repeat tracks will be added later when | 1438 // Add gutters as if there where only 1 auto repeat track. Gaps between auto
repeat tracks will be added later when |
| 1372 // computing the repetitions. | 1439 // computing the repetitions. |
| 1373 LayoutUnit gapSize = guttersSize(direction, 2); | 1440 LayoutUnit gapSize = gridGapForDirection(direction); |
| 1374 tracksSize += gapSize * trackSizes.size(); | 1441 tracksSize += gapSize * trackSizes.size(); |
| 1375 | 1442 |
| 1376 LayoutUnit freeSpace = availableSize - tracksSize; | 1443 LayoutUnit freeSpace = availableSize - tracksSize; |
| 1377 if (freeSpace <= 0) | 1444 if (freeSpace <= 0) |
| 1378 return 1; | 1445 return 1; |
| 1379 | 1446 |
| 1380 size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt
(); | 1447 size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt
(); |
| 1381 | 1448 |
| 1382 // Provided the grid container does not have a definite size or max-size in
the relevant axis, | 1449 // Provided the grid container does not have a definite size or max-size in
the relevant axis, |
| 1383 // if the min size is definite then the number of repetitions is the largest
possible positive | 1450 // if the min size is definite then the number of repetitions is the largest
possible positive |
| 1384 // integer that fulfills that minimum requirement. | 1451 // integer that fulfills that minimum requirement. |
| 1385 if (needsToFulfillMinimumSize) | 1452 if (needsToFulfillMinimumSize) |
| 1386 ++repetitions; | 1453 ++repetitions; |
| 1387 | 1454 |
| 1388 return repetitions; | 1455 return repetitions; |
| 1389 } | 1456 } |
| 1390 | 1457 |
| 1458 |
| 1459 std::unique_ptr<LayoutGrid::OrderedTrackIndexSet> LayoutGrid::computeEmptyTracks
ForAutoRepeat(GridTrackSizingDirection direction) const |
| 1460 { |
| 1461 bool isRowAxis = direction == ForColumns; |
| 1462 if ((isRowAxis && styleRef().gridAutoRepeatColumnsType() != AutoFit) |
| 1463 || (!isRowAxis && styleRef().gridAutoRepeatRowsType() != AutoFit)) |
| 1464 return nullptr; |
| 1465 |
| 1466 std::unique_ptr<OrderedTrackIndexSet> emptyTrackIndexes; |
| 1467 size_t insertionPoint = isRowAxis ? styleRef().gridAutoRepeatColumnsInsertio
nPoint() : styleRef().gridAutoRepeatRowsInsertionPoint(); |
| 1468 size_t repetitions = autoRepeatCountForDirection(direction); |
| 1469 size_t firstAutoRepeatTrack = insertionPoint + std::abs(isRowAxis ? m_smalle
stColumnStart : m_smallestRowStart); |
| 1470 size_t lastAutoRepeatTrack = firstAutoRepeatTrack + repetitions; |
| 1471 |
| 1472 if (m_gridItemArea.isEmpty()) { |
| 1473 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); |
| 1474 for (size_t trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepe
atTrack; ++trackIndex) |
| 1475 emptyTrackIndexes->add(trackIndex); |
| 1476 } else { |
| 1477 for (size_t trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepe
atTrack; ++trackIndex) { |
| 1478 GridIterator iterator(m_grid, direction, trackIndex); |
| 1479 if (!iterator.nextGridItem()) { |
| 1480 if (!emptyTrackIndexes) |
| 1481 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); |
| 1482 emptyTrackIndexes->add(trackIndex); |
| 1483 } |
| 1484 } |
| 1485 } |
| 1486 return emptyTrackIndexes; |
| 1487 } |
| 1488 |
| 1391 void LayoutGrid::placeItemsOnGrid(SizingOperation sizingOperation) | 1489 void LayoutGrid::placeItemsOnGrid(SizingOperation sizingOperation) |
| 1392 { | 1490 { |
| 1393 if (!m_gridIsDirty) | 1491 if (!m_gridIsDirty) |
| 1394 return; | 1492 return; |
| 1395 | 1493 |
| 1396 ASSERT(m_gridItemArea.isEmpty()); | 1494 ASSERT(m_gridItemArea.isEmpty()); |
| 1397 | 1495 |
| 1398 if (sizingOperation == IntrinsicSizeComputation) | 1496 if (sizingOperation == IntrinsicSizeComputation) |
| 1399 m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().isEmpty() ? 0 :
1; | 1497 m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().isEmpty() ? 0 :
1; |
| 1400 else | 1498 else |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 } | 1532 } |
| 1435 | 1533 |
| 1436 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount(*style
(), m_autoRepeatRows)); | 1534 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount(*style
(), m_autoRepeatRows)); |
| 1437 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount(
*style(), m_autoRepeatColumns)); | 1535 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount(
*style(), m_autoRepeatColumns)); |
| 1438 | 1536 |
| 1439 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 1537 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
| 1440 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 1538 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
| 1441 | 1539 |
| 1442 m_grid.shrinkToFit(); | 1540 m_grid.shrinkToFit(); |
| 1443 | 1541 |
| 1542 // Compute collapsable tracks for auto-fit. |
| 1543 m_autoRepeatEmptyColumns = computeEmptyTracksForAutoRepeat(ForColumns); |
| 1544 m_autoRepeatEmptyRows = computeEmptyTracksForAutoRepeat(ForRows); |
| 1545 |
| 1444 #if ENABLE(ASSERT) | 1546 #if ENABLE(ASSERT) |
| 1445 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { | 1547 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { |
| 1446 if (child->isOutOfFlowPositioned()) | 1548 if (child->isOutOfFlowPositioned()) |
| 1447 continue; | 1549 continue; |
| 1448 | 1550 |
| 1449 GridArea area = cachedGridArea(*child); | 1551 GridArea area = cachedGridArea(*child); |
| 1450 ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefi
nite()); | 1552 ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslatedDefi
nite()); |
| 1451 } | 1553 } |
| 1452 #endif | 1554 #endif |
| 1453 } | 1555 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 // the grid and its children are correctly laid out according to the new sty
le rules. | 1736 // the grid and its children are correctly laid out according to the new sty
le rules. |
| 1635 setNeedsLayout(LayoutInvalidationReason::GridChanged); | 1737 setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| 1636 | 1738 |
| 1637 m_grid.resize(0); | 1739 m_grid.resize(0); |
| 1638 m_gridItemArea.clear(); | 1740 m_gridItemArea.clear(); |
| 1639 m_gridItemsOverflowingGridArea.resize(0); | 1741 m_gridItemsOverflowingGridArea.resize(0); |
| 1640 m_gridItemsIndexesMap.clear(); | 1742 m_gridItemsIndexesMap.clear(); |
| 1641 m_autoRepeatColumns = 0; | 1743 m_autoRepeatColumns = 0; |
| 1642 m_autoRepeatRows = 0; | 1744 m_autoRepeatRows = 0; |
| 1643 m_gridIsDirty = true; | 1745 m_gridIsDirty = true; |
| 1746 m_autoRepeatEmptyColumns = nullptr; |
| 1747 m_autoRepeatEmptyRows = nullptr; |
| 1748 } |
| 1749 |
| 1750 Vector<LayoutUnit> LayoutGrid::trackSizesForComputedStyle(GridTrackSizingDirecti
on direction) const |
| 1751 { |
| 1752 bool isRowAxis = direction == ForColumns; |
| 1753 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
| 1754 size_t numPositions = positions.size(); |
| 1755 LayoutUnit offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offs
etBetweenRows; |
| 1756 |
| 1757 Vector<LayoutUnit> tracks; |
| 1758 if (numPositions < 2) |
| 1759 return tracks; |
| 1760 |
| 1761 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); |
| 1762 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction) : Layo
utUnit(); |
| 1763 tracks.reserveCapacity(numPositions - 1); |
| 1764 for (size_t i = 0; i < numPositions - 2; ++i) |
| 1765 tracks.append(positions[i + 1] - positions[i] - offsetBetweenTracks - ga
p); |
| 1766 tracks.append(positions[numPositions - 1] - positions[numPositions - 2]); |
| 1767 |
| 1768 if (!hasCollapsedTracks) |
| 1769 return tracks; |
| 1770 |
| 1771 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->size() :
m_autoRepeatEmptyRows->size(); |
| 1772 size_t lastLine = tracks.size(); |
| 1773 gap = gridGapForDirection(direction); |
| 1774 for (size_t i = 1; i < lastLine; ++i) { |
| 1775 if (isEmptyAutoRepeatTrack(direction, i - 1)) { |
| 1776 --remainingEmptyTracks; |
| 1777 } else { |
| 1778 // Remove the gap between consecutive non empty tracks. Remove it al
so just once for an |
| 1779 // arbitrary number of empty tracks between two non empty ones. |
| 1780 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (lastLine
- i); |
| 1781 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(direction
, i)) |
| 1782 tracks[i - 1] -= gap; |
| 1783 } |
| 1784 } |
| 1785 |
| 1786 return tracks; |
| 1644 } | 1787 } |
| 1645 | 1788 |
| 1646 static const StyleContentAlignmentData& normalValueBehavior() | 1789 static const StyleContentAlignmentData& normalValueBehavior() |
| 1647 { | 1790 { |
| 1648 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm
al, ContentDistributionStretch}; | 1791 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm
al, ContentDistributionStretch}; |
| 1649 return normalBehavior; | 1792 return normalBehavior; |
| 1650 } | 1793 } |
| 1651 | 1794 |
| 1652 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection
direction, GridSizingData& sizingData) | 1795 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection
direction, GridSizingData& sizingData) |
| 1653 { | 1796 { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 if (styleRef().isLeftToRightDirection()) | 1967 if (styleRef().isLeftToRightDirection()) |
| 1825 end = m_columnPositions[endLine] - borderLogicalLeft(); | 1968 end = m_columnPositions[endLine] - borderLogicalLeft(); |
| 1826 else | 1969 else |
| 1827 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[
endLine]) - borderLogicalRight(); | 1970 end = logicalWidth() - translateRTLCoordinate(m_columnPositions[
endLine]) - borderLogicalRight(); |
| 1828 } else { | 1971 } else { |
| 1829 end = m_rowPositions[endLine] - borderBefore(); | 1972 end = m_rowPositions[endLine] - borderBefore(); |
| 1830 } | 1973 } |
| 1831 | 1974 |
| 1832 // These vectors store line positions including gaps, but we shouldn't c
onsider them for the edges of the grid. | 1975 // These vectors store line positions including gaps, but we shouldn't c
onsider them for the edges of the grid. |
| 1833 if (endLine > 0 && endLine < lastLine) { | 1976 if (endLine > 0 && endLine < lastLine) { |
| 1834 end -= guttersSize(direction, 2); | 1977 end -= guttersSize(direction, endLine - 1, 2); |
| 1835 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; | 1978 end -= isForColumns ? m_offsetBetweenColumns : m_offsetBetweenRows; |
| 1836 } | 1979 } |
| 1837 } | 1980 } |
| 1838 | 1981 |
| 1839 breadth = end - start; | 1982 breadth = end - start; |
| 1840 offset = start; | 1983 offset = start; |
| 1841 | 1984 |
| 1842 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef(
).hasStaticInlinePosition(child.isHorizontalWritingMode())) { | 1985 if (isForColumns && !styleRef().isLeftToRightDirection() && !child.styleRef(
).hasStaticInlinePosition(child.isHorizontalWritingMode())) { |
| 1843 // If the child doesn't have a static inline position (i.e. "left" and/o
r "right" aren't "auto", | 1986 // If the child doesn't have a static inline position (i.e. "left" and/o
r "right" aren't "auto", |
| 1844 // we need to calculate the offset from the left (even if we're in RTL). | 1987 // we need to calculate the offset from the left (even if we're in RTL). |
| 1845 if (endIsAuto) { | 1988 if (endIsAuto) { |
| 1846 offset = LayoutUnit(); | 1989 offset = LayoutUnit(); |
| 1847 } else { | 1990 } else { |
| 1848 offset = translateRTLCoordinate(m_columnPositions[endLine]) - border
LogicalLeft(); | 1991 offset = translateRTLCoordinate(m_columnPositions[endLine]) - border
LogicalLeft(); |
| 1849 | 1992 |
| 1850 if (endLine > 0 && endLine < lastLine) { | 1993 if (endLine > 0 && endLine < lastLine) { |
| 1851 offset += guttersSize(direction, 2); | 1994 offset += guttersSize(direction, endLine - 1, 2); |
| 1852 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee
nRows; | 1995 offset += isForColumns ? m_offsetBetweenColumns : m_offsetBetwee
nRows; |
| 1853 } | 1996 } |
| 1854 } | 1997 } |
| 1855 } | 1998 } |
| 1856 | 1999 |
| 1857 } | 2000 } |
| 1858 | 2001 |
| 1859 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const | 2002 GridArea LayoutGrid::cachedGridArea(const LayoutBox& gridItem) const |
| 1860 { | 2003 { |
| 1861 ASSERT(m_gridItemArea.contains(&gridItem)); | 2004 ASSERT(m_gridItemArea.contains(&gridItem)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1876 bool gridAreaIsIndefinite = false; | 2019 bool gridAreaIsIndefinite = false; |
| 1877 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon
tent(ExcludeMarginBorderPadding); | 2020 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon
tent(ExcludeMarginBorderPadding); |
| 1878 for (auto trackPosition : span) { | 2021 for (auto trackPosition : span) { |
| 1879 const GridLength& maxTrackSize = gridTrackSize(ForRows, trackPosition, s
izingOperation).maxTrackBreadth(); | 2022 const GridLength& maxTrackSize = gridTrackSize(ForRows, trackPosition, s
izingOperation).maxTrackBreadth(); |
| 1880 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) | 2023 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) |
| 1881 gridAreaIsIndefinite = true; | 2024 gridAreaIsIndefinite = true; |
| 1882 else | 2025 else |
| 1883 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc
kAvailableSize); | 2026 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc
kAvailableSize); |
| 1884 } | 2027 } |
| 1885 | 2028 |
| 1886 gridAreaSize += guttersSize(ForRows, span.integerSpan()); | 2029 gridAreaSize += guttersSize(ForRows, span.startLine(), span.integerSpan()); |
| 1887 | 2030 |
| 1888 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri
dAreaSize) : gridAreaSize; | 2031 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri
dAreaSize) : gridAreaSize; |
| 1889 } | 2032 } |
| 1890 | 2033 |
| 1891 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
SizingDirection direction, const GridSizingData& sizingData) const | 2034 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack
SizingDirection direction, const GridSizingData& sizingData) const |
| 1892 { | 2035 { |
| 1893 // To determine the column track's size based on an orthogonal grid item we
need it's logical height, which | 2036 // To determine the column track's size based on an orthogonal grid item we
need it's logical height, which |
| 1894 // may depend on the row track's size. It's possible that the row tracks siz
ing logic has not been performed yet, | 2037 // may depend on the row track's size. It's possible that the row tracks siz
ing logic has not been performed yet, |
| 1895 // so we will need to do an estimation. | 2038 // so we will need to do an estimation. |
| 1896 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column
SizingFirstIteration) | 2039 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column
SizingFirstIteration) |
| 1897 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperati
on); | 2040 return assumedRowsSizeForOrthogonalChild(child, sizingData.sizingOperati
on); |
| 1898 | 2041 |
| 1899 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum
nTracks : sizingData.rowTracks; | 2042 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum
nTracks : sizingData.rowTracks; |
| 1900 const GridSpan& span = cachedGridSpan(child, direction); | 2043 const GridSpan& span = cachedGridSpan(child, direction); |
| 1901 LayoutUnit gridAreaBreadth; | 2044 LayoutUnit gridAreaBreadth; |
| 1902 for (const auto& trackPosition : span) | 2045 for (const auto& trackPosition : span) |
| 1903 gridAreaBreadth += tracks[trackPosition].baseSize(); | 2046 gridAreaBreadth += tracks[trackPosition].baseSize(); |
| 1904 | 2047 |
| 1905 gridAreaBreadth += guttersSize(direction, span.integerSpan()); | 2048 gridAreaBreadth += guttersSize(direction, span.startLine(), span.integerSpan
()); |
| 1906 | 2049 |
| 1907 return gridAreaBreadth; | 2050 return gridAreaBreadth; |
| 1908 } | 2051 } |
| 1909 | 2052 |
| 1910 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La
youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing
Data) const | 2053 LayoutUnit LayoutGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const La
youtBox& child, GridTrackSizingDirection direction, const GridSizingData& sizing
Data) const |
| 1911 { | 2054 { |
| 1912 // We need the cached value when available because Content Distribution alig
nment properties | 2055 // We need the cached value when available because Content Distribution alig
nment properties |
| 1913 // may have some influence in the final grid area breadth. | 2056 // may have some influence in the final grid area breadth. |
| 1914 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col
umnTracks : sizingData.rowTracks; | 2057 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col
umnTracks : sizingData.rowTracks; |
| 1915 const GridSpan& span = cachedGridSpan(child, direction); | 2058 const GridSpan& span = cachedGridSpan(child, direction); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1928 | 2071 |
| 1929 // The grid container's frame elements (border, padding and <content-positio
n> offset) are sensible to the | 2072 // The grid container's frame elements (border, padding and <content-positio
n> offset) are sensible to the |
| 1930 // inline-axis flow direction. However, column lines positions are 'directio
n' unaware. This simplification | 2073 // inline-axis flow direction. However, column lines positions are 'directio
n' unaware. This simplification |
| 1931 // allows us to use the same indexes to identify the columns independently o
n the inline-axis direction. | 2074 // allows us to use the same indexes to identify the columns independently o
n the inline-axis direction. |
| 1932 bool isRowAxis = direction == ForColumns; | 2075 bool isRowAxis = direction == ForColumns; |
| 1933 auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks; | 2076 auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks; |
| 1934 size_t numberOfTracks = tracks.size(); | 2077 size_t numberOfTracks = tracks.size(); |
| 1935 size_t numberOfLines = numberOfTracks + 1; | 2078 size_t numberOfLines = numberOfTracks + 1; |
| 1936 size_t lastLine = numberOfLines - 1; | 2079 size_t lastLine = numberOfLines - 1; |
| 1937 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di
rection, sizingData.freeSpaceForDirection(direction), numberOfTracks); | 2080 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di
rection, sizingData.freeSpaceForDirection(direction), numberOfTracks); |
| 1938 LayoutUnit trackGap = guttersSize(direction, 2); | |
| 1939 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; | 2081 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
| 1940 positions.resize(numberOfLines); | 2082 positions.resize(numberOfLines); |
| 1941 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn
dPaddingBefore(); | 2083 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn
dPaddingBefore(); |
| 1942 positions[0] = borderAndPadding + offset.positionOffset; | 2084 positions[0] = borderAndPadding + offset.positionOffset; |
| 1943 if (numberOfLines > 1) { | 2085 if (numberOfLines > 1) { |
| 2086 // If we have collapsed tracks we just ignore gaps here and add them lat
er as we might not |
| 2087 // compute the gap between two consecutive tracks without examining the
surrounding ones. |
| 2088 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); |
| 2089 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction) :
LayoutUnit(); |
| 1944 size_t nextToLastLine = numberOfLines - 2; | 2090 size_t nextToLastLine = numberOfLines - 2; |
| 1945 for (size_t i = 0; i < nextToLastLine; ++i) | 2091 for (size_t i = 0; i < nextToLastLine; ++i) |
| 1946 positions[i + 1] = positions[i] + offset.distributionOffset + tracks
[i].baseSize() + trackGap; | 2092 positions[i + 1] = positions[i] + offset.distributionOffset + tracks
[i].baseSize() + gap; |
| 1947 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine]
.baseSize(); | 2093 positions[lastLine] = positions[nextToLastLine] + tracks[nextToLastLine]
.baseSize(); |
| 2094 |
| 2095 // Adjust collapsed gaps. Collapsed tracks cause the surrounding gutters
to collapse (they |
| 2096 // coincide exactly) except on the edges of the grid where they become 0
. |
| 2097 if (hasCollapsedTracks) { |
| 2098 gap = gridGapForDirection(direction); |
| 2099 size_t remainingEmptyTracks = isRowAxis ? m_autoRepeatEmptyColumns->
size() : m_autoRepeatEmptyRows->size(); |
| 2100 LayoutUnit gapAccumulator; |
| 2101 for (size_t i = 1; i < lastLine; ++i) { |
| 2102 if (isEmptyAutoRepeatTrack(direction, i - 1)) { |
| 2103 --remainingEmptyTracks; |
| 2104 } else { |
| 2105 // Add gap between consecutive non empty tracks. Add it also
just once for an |
| 2106 // arbitrary number of empty tracks between two non empty on
es. |
| 2107 bool allRemainingTracksAreEmpty = remainingEmptyTracks == (l
astLine - i); |
| 2108 if (!allRemainingTracksAreEmpty || !isEmptyAutoRepeatTrack(d
irection, i)) |
| 2109 gapAccumulator += gap; |
| 2110 } |
| 2111 positions[i] += gapAccumulator; |
| 2112 } |
| 2113 positions[lastLine] += gapAccumulator; |
| 2114 } |
| 1948 } | 2115 } |
| 1949 auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBet
weenRows; | 2116 auto& offsetBetweenTracks = isRowAxis ? m_offsetBetweenColumns : m_offsetBet
weenRows; |
| 1950 offsetBetweenTracks = offset.distributionOffset; | 2117 offsetBetweenTracks = offset.distributionOffset; |
| 1951 } | 2118 } |
| 1952 | 2119 |
| 1953 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit trackBreadth, LayoutUnit childBreadth) | 2120 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay
outUnit trackBreadth, LayoutUnit childBreadth) |
| 1954 { | 2121 { |
| 1955 LayoutUnit offset = trackBreadth - childBreadth; | 2122 LayoutUnit offset = trackBreadth - childBreadth; |
| 1956 switch (overflow) { | 2123 switch (overflow) { |
| 1957 case OverflowAlignmentSafe: | 2124 case OverflowAlignmentSafe: |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2188 switch (axisPosition) { | 2355 switch (axisPosition) { |
| 2189 case GridAxisStart: | 2356 case GridAxisStart: |
| 2190 return startPosition; | 2357 return startPosition; |
| 2191 case GridAxisEnd: | 2358 case GridAxisEnd: |
| 2192 case GridAxisCenter: { | 2359 case GridAxisCenter: { |
| 2193 size_t childEndLine = rowsSpan.endLine(); | 2360 size_t childEndLine = rowsSpan.endLine(); |
| 2194 LayoutUnit endOfRow = m_rowPositions[childEndLine]; | 2361 LayoutUnit endOfRow = m_rowPositions[childEndLine]; |
| 2195 // m_rowPositions include distribution offset (because of content alignm
ent) and gutters | 2362 // m_rowPositions include distribution offset (because of content alignm
ent) and gutters |
| 2196 // so we need to subtract them to get the actual end position for a give
n row | 2363 // so we need to subtract them to get the actual end position for a give
n row |
| 2197 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). | 2364 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). |
| 2198 LayoutUnit trackGap = guttersSize(ForRows, 2); | 2365 LayoutUnit trackGap = gridGapForDirection(ForRows); |
| 2199 if (childEndLine < m_rowPositions.size() - 1) { | 2366 if (childEndLine < m_rowPositions.size() - 1) { |
| 2200 endOfRow -= trackGap; | 2367 endOfRow -= trackGap; |
| 2201 endOfRow -= m_offsetBetweenRows; | 2368 endOfRow -= m_offsetBetweenRows; |
| 2202 } | 2369 } |
| 2203 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei
ght(); | 2370 LayoutUnit childBreadth = child.logicalHeight() + child.marginLogicalHei
ght(); |
| 2204 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef
(), ItemPositionStretch).overflow(); | 2371 OverflowAlignment overflow = child.styleRef().resolvedAlignment(styleRef
(), ItemPositionStretch).overflow(); |
| 2205 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfRow - startOfRow, childBreadth); | 2372 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(over
flow, endOfRow - startOfRow, childBreadth); |
| 2206 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 2373 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
| 2207 } | 2374 } |
| 2208 } | 2375 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2223 switch (axisPosition) { | 2390 switch (axisPosition) { |
| 2224 case GridAxisStart: | 2391 case GridAxisStart: |
| 2225 return startPosition; | 2392 return startPosition; |
| 2226 case GridAxisEnd: | 2393 case GridAxisEnd: |
| 2227 case GridAxisCenter: { | 2394 case GridAxisCenter: { |
| 2228 size_t childEndLine = columnsSpan.endLine(); | 2395 size_t childEndLine = columnsSpan.endLine(); |
| 2229 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; | 2396 LayoutUnit endOfColumn = m_columnPositions[childEndLine]; |
| 2230 // m_columnPositions include distribution offset (because of content ali
gnment) and gutters | 2397 // m_columnPositions include distribution offset (because of content ali
gnment) and gutters |
| 2231 // so we need to subtract them to get the actual end position for a give
n column | 2398 // so we need to subtract them to get the actual end position for a give
n column |
| 2232 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). | 2399 // (this does not have to be done for the last track as there are no mor
e m_columnPositions after it). |
| 2233 LayoutUnit trackGap = guttersSize(ForColumns, 2); | 2400 LayoutUnit trackGap = gridGapForDirection(ForColumns); |
| 2234 if (childEndLine < m_columnPositions.size() - 1) { | 2401 if (childEndLine < m_columnPositions.size() - 1) { |
| 2235 endOfColumn -= trackGap; | 2402 endOfColumn -= trackGap; |
| 2236 endOfColumn -= m_offsetBetweenColumns; | 2403 endOfColumn -= m_offsetBetweenColumns; |
| 2237 } | 2404 } |
| 2238 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt
h(); | 2405 LayoutUnit childBreadth = child.logicalWidth() + child.marginLogicalWidt
h(); |
| 2239 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB
readth); | 2406 LayoutUnit offsetFromStartPosition = computeOverflowAlignmentOffset(chil
d.styleRef().justifySelfOverflowAlignment(), endOfColumn - startOfColumn, childB
readth); |
| 2240 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); | 2407 return startPosition + (axisPosition == GridAxisEnd ? offsetFromStartPos
ition : offsetFromStartPosition / 2); |
| 2241 } | 2408 } |
| 2242 } | 2409 } |
| 2243 | 2410 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2372 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc
ation; | 2539 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc
ation; |
| 2373 } | 2540 } |
| 2374 | 2541 |
| 2375 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const | 2542 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) const |
| 2376 { | 2543 { |
| 2377 if (!m_gridItemArea.isEmpty()) | 2544 if (!m_gridItemArea.isEmpty()) |
| 2378 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2545 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 2379 } | 2546 } |
| 2380 | 2547 |
| 2381 } // namespace blink | 2548 } // namespace blink |
| OLD | NEW |