Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 class GridItemWithSpan; | 43 class GridItemWithSpan; |
| 44 | 44 |
| 45 class GridTrack { | 45 class GridTrack { |
| 46 public: | 46 public: |
| 47 GridTrack() | 47 GridTrack() |
| 48 : m_infinitelyGrowable(false) | 48 : m_infinitelyGrowable(false) |
| 49 { | 49 { |
| 50 } | 50 } |
| 51 | 51 |
| 52 const LayoutUnit& baseSize() const | 52 LayoutUnit baseSize() const |
| 53 { | 53 { |
| 54 ASSERT(isGrowthLimitBiggerThanBaseSize()); | 54 DCHECK(isGrowthLimitBiggerThanBaseSize()); |
| 55 return m_baseSize; | 55 return m_baseSize; |
| 56 } | 56 } |
| 57 | 57 |
| 58 const LayoutUnit& growthLimit() const | 58 LayoutUnit growthLimit() const |
| 59 { | 59 { |
| 60 ASSERT(isGrowthLimitBiggerThanBaseSize()); | 60 DCHECK(isGrowthLimitBiggerThanBaseSize()); |
| 61 DCHECK(!m_growthLimitCap || m_growthLimitCap.value() >= m_growthLimit || m_baseSize >= m_growthLimitCap.value()); | |
| 61 return m_growthLimit; | 62 return m_growthLimit; |
| 62 } | 63 } |
| 63 | 64 |
| 64 void setBaseSize(LayoutUnit baseSize) | 65 void setBaseSize(LayoutUnit baseSize) |
| 65 { | 66 { |
| 66 m_baseSize = baseSize; | 67 m_baseSize = baseSize; |
| 67 ensureGrowthLimitIsBiggerThanBaseSize(); | 68 ensureGrowthLimitIsBiggerThanBaseSize(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void setGrowthLimit(LayoutUnit growthLimit) | 71 void setGrowthLimit(LayoutUnit growthLimit) |
| 71 { | 72 { |
| 72 m_growthLimit = growthLimit; | 73 m_growthLimit = growthLimit == infinity ? growthLimit : std::min(growthL imit, m_growthLimitCap.value_or(growthLimit)); |
| 73 ensureGrowthLimitIsBiggerThanBaseSize(); | 74 ensureGrowthLimitIsBiggerThanBaseSize(); |
| 74 } | 75 } |
| 75 | 76 |
| 76 bool growthLimitIsInfinite() const | 77 bool infiniteGrowthPotential() const { return growthLimitIsInfinite() || m_i nfinitelyGrowable; } |
| 77 { | |
| 78 return m_growthLimit == infinity; | |
| 79 } | |
| 80 | 78 |
| 81 bool infiniteGrowthPotential() const | 79 LayoutUnit plannedSize() const { return m_plannedSize; } |
| 82 { | |
| 83 return growthLimitIsInfinite() || m_infinitelyGrowable; | |
| 84 } | |
| 85 | |
| 86 const LayoutUnit& plannedSize() const { return m_plannedSize; } | |
| 87 | 80 |
| 88 void setPlannedSize(const LayoutUnit& plannedSize) | 81 void setPlannedSize(const LayoutUnit& plannedSize) |
| 89 { | 82 { |
| 90 ASSERT(plannedSize >= 0 || plannedSize == infinity); | 83 ASSERT(plannedSize >= 0 || plannedSize == infinity); |
| 91 m_plannedSize = plannedSize; | 84 m_plannedSize = plannedSize; |
| 92 } | 85 } |
| 93 | 86 |
| 94 const LayoutUnit& sizeDuringDistribution() { return m_sizeDuringDistribution ; } | 87 LayoutUnit sizeDuringDistribution() const { return m_sizeDuringDistribution; } |
| 95 | 88 |
| 96 void setSizeDuringDistribution(const LayoutUnit& sizeDuringDistribution) | 89 void setSizeDuringDistribution(const LayoutUnit& sizeDuringDistribution) |
| 97 { | 90 { |
| 98 ASSERT(sizeDuringDistribution >= 0); | 91 DCHECK_GE(sizeDuringDistribution, 0); |
| 92 DCHECK(growthLimitIsInfinite() || growthLimit() >= sizeDuringDistributio n); | |
| 99 m_sizeDuringDistribution = sizeDuringDistribution; | 93 m_sizeDuringDistribution = sizeDuringDistribution; |
| 100 } | 94 } |
| 101 | 95 |
| 102 void growSizeDuringDistribution(const LayoutUnit& sizeDuringDistribution) | 96 void growSizeDuringDistribution(const LayoutUnit& sizeDuringDistribution) |
| 103 { | 97 { |
| 104 ASSERT(sizeDuringDistribution >= 0); | 98 DCHECK_GE(sizeDuringDistribution, 0); |
| 105 m_sizeDuringDistribution += sizeDuringDistribution; | 99 m_sizeDuringDistribution += sizeDuringDistribution; |
| 106 } | 100 } |
| 107 | 101 |
| 108 bool infinitelyGrowable() const { return m_infinitelyGrowable; } | 102 bool infinitelyGrowable() const { return m_infinitelyGrowable; } |
| 109 void setInfinitelyGrowable(bool infinitelyGrowable) { m_infinitelyGrowable = infinitelyGrowable; } | 103 void setInfinitelyGrowable(bool infinitelyGrowable) { m_infinitelyGrowable = infinitelyGrowable; } |
| 110 | 104 |
| 105 void setGrowthLimitCap(Optional<LayoutUnit> growthLimitCap) | |
| 106 { | |
| 107 DCHECK(!growthLimitCap || *growthLimitCap >= 0); | |
|
Manuel Rego
2016/08/31 07:24:29
Why you don't use growthLimitCap.value() here?
svillar
2016/08/31 09:50:04
I can use it indeed, they're equivalent in any cas
| |
| 108 m_growthLimitCap = growthLimitCap; | |
| 109 } | |
| 110 | |
| 111 Optional<LayoutUnit> growthLimitCap() const { return m_growthLimitCap; } | |
| 112 | |
| 111 private: | 113 private: |
| 114 bool growthLimitIsInfinite() const { return m_growthLimit == infinity; } | |
| 112 bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite( ) || m_growthLimit >= m_baseSize; } | 115 bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite( ) || m_growthLimit >= m_baseSize; } |
| 113 | 116 |
| 114 void ensureGrowthLimitIsBiggerThanBaseSize() | 117 void ensureGrowthLimitIsBiggerThanBaseSize() |
| 115 { | 118 { |
| 116 if (m_growthLimit != infinity && m_growthLimit < m_baseSize) | 119 if (m_growthLimit != infinity && m_growthLimit < m_baseSize) |
| 117 m_growthLimit = m_baseSize; | 120 m_growthLimit = m_baseSize; |
| 118 } | 121 } |
| 119 | 122 |
| 120 LayoutUnit m_baseSize; | 123 LayoutUnit m_baseSize; |
| 121 LayoutUnit m_growthLimit; | 124 LayoutUnit m_growthLimit; |
| 122 LayoutUnit m_plannedSize; | 125 LayoutUnit m_plannedSize; |
| 123 LayoutUnit m_sizeDuringDistribution; | 126 LayoutUnit m_sizeDuringDistribution; |
| 127 Optional<LayoutUnit> m_growthLimitCap; | |
| 124 bool m_infinitelyGrowable; | 128 bool m_infinitelyGrowable; |
| 125 }; | 129 }; |
| 126 | 130 |
| 127 struct ContentAlignmentData { | 131 struct ContentAlignmentData { |
| 128 STACK_ALLOCATED(); | 132 STACK_ALLOCATED(); |
| 129 public: | 133 public: |
| 130 ContentAlignmentData() {}; | 134 ContentAlignmentData() {}; |
| 131 ContentAlignmentData(LayoutUnit position, LayoutUnit distribution) | 135 ContentAlignmentData(LayoutUnit position, LayoutUnit distribution) |
| 132 : positionOffset(position) | 136 : positionOffset(position) |
| 133 , distributionOffset(distribution) | 137 , distributionOffset(distribution) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 | 247 |
| 244 Vector<GridTrack> columnTracks; | 248 Vector<GridTrack> columnTracks; |
| 245 Vector<GridTrack> rowTracks; | 249 Vector<GridTrack> rowTracks; |
| 246 Vector<size_t> contentSizedTracksIndex; | 250 Vector<size_t> contentSizedTracksIndex; |
| 247 | 251 |
| 248 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. | 252 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. |
| 249 Vector<GridTrack*> filteredTracks; | 253 Vector<GridTrack*> filteredTracks; |
| 250 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; | 254 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; |
| 251 Vector<GridTrack*> growBeyondGrowthLimitsTracks; | 255 Vector<GridTrack*> growBeyondGrowthLimitsTracks; |
| 252 | 256 |
| 253 LayoutUnit& freeSpaceForDirection(GridTrackSizingDirection direction) { retu rn direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; } | 257 LayoutUnit& freeSpace(GridTrackSizingDirection direction) { return direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; } |
| 258 | |
| 259 LayoutUnit availableSpace() const { return m_availableSpace; } | |
| 260 void setAvailableSpace(LayoutUnit availableSpace) { m_availableSpace = avail ableSpace; } | |
| 254 | 261 |
| 255 SizingOperation sizingOperation { TrackSizing }; | 262 SizingOperation sizingOperation { TrackSizing }; |
| 256 enum SizingState { ColumnSizingFirstIteration, RowSizingFirstIteration, Colu mnSizingSecondIteration, RowSizingSecondIteration}; | 263 enum SizingState { ColumnSizingFirstIteration, RowSizingFirstIteration, Colu mnSizingSecondIteration, RowSizingSecondIteration}; |
| 257 SizingState sizingState { ColumnSizingFirstIteration }; | 264 SizingState sizingState { ColumnSizingFirstIteration }; |
| 258 void nextState() | 265 void nextState() |
| 259 { | 266 { |
| 260 switch (sizingState) { | 267 switch (sizingState) { |
| 261 case ColumnSizingFirstIteration: | 268 case ColumnSizingFirstIteration: |
| 262 sizingState = RowSizingFirstIteration; | 269 sizingState = RowSizingFirstIteration; |
| 263 return; | 270 return; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 283 case RowSizingFirstIteration: | 290 case RowSizingFirstIteration: |
| 284 case RowSizingSecondIteration: | 291 case RowSizingSecondIteration: |
| 285 return direction == ForRows; | 292 return direction == ForRows; |
| 286 } | 293 } |
| 287 NOTREACHED(); | 294 NOTREACHED(); |
| 288 return false; | 295 return false; |
| 289 } | 296 } |
| 290 private: | 297 private: |
| 291 LayoutUnit freeSpaceForColumns { }; | 298 LayoutUnit freeSpaceForColumns { }; |
| 292 LayoutUnit freeSpaceForRows { }; | 299 LayoutUnit freeSpaceForRows { }; |
| 300 // No need to store one per direction as it will be only used for computatio ns during each axis | |
| 301 // track sizing. It's cached here because we need it to compute relative siz es. | |
| 302 LayoutUnit m_availableSpace; | |
| 293 }; | 303 }; |
| 294 | 304 |
| 295 struct GridItemsSpanGroupRange { | 305 struct GridItemsSpanGroupRange { |
| 296 Vector<GridItemWithSpan>::iterator rangeStart; | 306 Vector<GridItemWithSpan>::iterator rangeStart; |
| 297 Vector<GridItemWithSpan>::iterator rangeEnd; | 307 Vector<GridItemWithSpan>::iterator rangeEnd; |
| 298 }; | 308 }; |
| 299 | 309 |
| 300 LayoutGrid::LayoutGrid(Element* element) | 310 LayoutGrid::LayoutGrid(Element* element) |
| 301 : LayoutBlock(element) | 311 : LayoutBlock(element) |
| 302 , m_gridIsDirty(true) | 312 , m_gridIsDirty(true) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 LayoutUnit logicalHeight; | 391 LayoutUnit logicalHeight; |
| 382 | 392 |
| 383 for (const auto& row : sizingData.rowTracks) | 393 for (const auto& row : sizingData.rowTracks) |
| 384 logicalHeight += row.baseSize(); | 394 logicalHeight += row.baseSize(); |
| 385 | 395 |
| 386 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size()); | 396 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size()); |
| 387 | 397 |
| 388 return logicalHeight; | 398 return logicalHeight; |
| 389 } | 399 } |
| 390 | 400 |
| 391 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace) | 401 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit availableSpace) |
| 392 { | 402 { |
| 393 DCHECK(sizingData.isValidTransition(direction)); | 403 DCHECK(sizingData.isValidTransition(direction)); |
| 394 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct ion, 0, direction == ForRows ? gridRowCount() : gridColumnCount()); | 404 sizingData.setAvailableSpace(availableSpace); |
| 405 sizingData.freeSpace(direction) = availableSpace - guttersSize(direction, 0, direction == ForRows ? gridRowCount() : gridColumnCount()); | |
| 395 sizingData.sizingOperation = TrackSizing; | 406 sizingData.sizingOperation = TrackSizing; |
| 396 | 407 |
| 397 LayoutUnit baseSizes, growthLimits; | 408 LayoutUnit baseSizes, growthLimits; |
| 398 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s); | 409 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s); |
| 399 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); | 410 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); |
| 400 sizingData.nextState(); | 411 sizingData.nextState(); |
| 401 } | 412 } |
| 402 | 413 |
| 403 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn it availableSpaceForColumns, LayoutUnit availableSpaceForRows) | 414 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn it availableSpaceForColumns, LayoutUnit availableSpaceForRows) |
| 404 { | 415 { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 } | 581 } |
| 571 | 582 |
| 572 return gapAccumulator; | 583 return gapAccumulator; |
| 573 } | 584 } |
| 574 | 585 |
| 575 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const | 586 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const |
| 576 { | 587 { |
| 577 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); | 588 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); |
| 578 | 589 |
| 579 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 590 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
| 580 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit(); | 591 sizingData.setAvailableSpace(LayoutUnit()); |
| 592 sizingData.freeSpace(ForColumns) = LayoutUnit(); | |
| 581 sizingData.sizingOperation = IntrinsicSizeComputation; | 593 sizingData.sizingOperation = IntrinsicSizeComputation; |
| 582 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL ogicalWidth); | 594 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL ogicalWidth); |
| 583 | 595 |
| 584 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr acks.size()); | 596 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr acks.size()); |
| 585 minLogicalWidth += totalGuttersSize; | 597 minLogicalWidth += totalGuttersSize; |
| 586 maxLogicalWidth += totalGuttersSize; | 598 maxLogicalWidth += totalGuttersSize; |
| 587 | 599 |
| 588 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); | 600 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); |
| 589 minLogicalWidth += scrollbarWidth; | 601 minLogicalWidth += scrollbarWidth; |
| 590 maxLogicalWidth += scrollbarWidth; | 602 maxLogicalWidth += scrollbarWidth; |
| 591 } | 603 } |
| 592 | 604 |
| 593 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) | 605 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) |
| 594 { | 606 { |
| 595 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); | 607 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); |
| 596 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit(); | 608 sizingData.setAvailableSpace(LayoutUnit()); |
| 609 sizingData.freeSpace(ForRows) = LayoutUnit(); | |
| 597 sizingData.sizingOperation = IntrinsicSizeComputation; | 610 sizingData.sizingOperation = IntrinsicSizeComputation; |
| 598 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight); | 611 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight); |
| 599 | 612 |
| 600 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount()); | 613 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount()); |
| 601 m_minContentHeight += totalGuttersSize; | 614 m_minContentHeight += totalGuttersSize; |
| 602 m_maxContentHeight += totalGuttersSize; | 615 m_maxContentHeight += totalGuttersSize; |
| 603 | 616 |
| 604 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); | 617 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); |
| 605 } | 618 } |
| 606 | 619 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 625 return LayoutUnit(); | 638 return LayoutUnit(); |
| 626 } | 639 } |
| 627 | 640 |
| 628 static inline double normalizedFlexFraction(const GridTrack& track, double flexF actor) | 641 static inline double normalizedFlexFraction(const GridTrack& track, double flexF actor) |
| 629 { | 642 { |
| 630 return track.baseSize() / std::max<double>(1, flexFactor); | 643 return track.baseSize() / std::max<double>(1, flexFactor); |
| 631 } | 644 } |
| 632 | 645 |
| 633 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& baseSizesWithoutMaximization, Layout Unit& growthLimitsWithoutMaximization) const | 646 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& baseSizesWithoutMaximization, Layout Unit& growthLimitsWithoutMaximization) const |
| 634 { | 647 { |
| 635 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction); | 648 LayoutUnit& freeSpace = sizingData.freeSpace(direction); |
| 636 const LayoutUnit initialFreeSpace = freeSpace; | 649 const LayoutUnit initialFreeSpace = freeSpace; |
| 637 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; | 650 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; |
| 638 Vector<size_t> flexibleSizedTracksIndex; | 651 Vector<size_t> flexibleSizedTracksIndex; |
| 639 sizingData.contentSizedTracksIndex.shrink(0); | 652 sizingData.contentSizedTracksIndex.shrink(0); |
| 640 | 653 |
| 641 LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace); | |
| 642 // Grid gutters were removed from freeSpace by the caller, but we must use t hem to compute relative (i.e. percentages) sizes. | 654 // Grid gutters were removed from freeSpace by the caller, but we must use t hem to compute relative (i.e. percentages) sizes. |
| 655 LayoutUnit maxSize = std::max(LayoutUnit(), sizingData.availableSpace()); | |
|
eae
2016/08/29 18:19:40
LayoutUnit maxSize = sizingData.availableSpace().c
svillar
2016/08/29 20:01:55
Acknowledged.
| |
| 643 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; | 656 bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing; |
| 644 if (hasDefiniteFreeSpace) | |
| 645 maxSize += guttersSize(direction, 0, direction == ForRows ? gridRowCount () : gridColumnCount()); | |
| 646 | 657 |
| 647 // 1. Initialize per Grid track variables. | 658 // 1. Initialize per Grid track variables. |
| 648 for (size_t i = 0; i < tracks.size(); ++i) { | 659 for (size_t i = 0; i < tracks.size(); ++i) { |
| 649 GridTrack& track = tracks[i]; | 660 GridTrack& track = tracks[i]; |
| 650 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); | 661 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); |
| 651 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | |
| 652 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); | |
| 653 | 662 |
| 654 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize )); | 663 track.setBaseSize(computeUsedBreadthOfMinLength(trackSize, maxSize)); |
| 655 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac k.baseSize(), maxSize)); | 664 track.setGrowthLimit(computeUsedBreadthOfMaxLength(trackSize, track.base Size(), maxSize)); |
| 656 track.setInfinitelyGrowable(false); | 665 track.setInfinitelyGrowable(false); |
| 657 | 666 |
| 667 if (trackSize.isFitContent()) { | |
| 668 GridLength gridLength = trackSize.length(); | |
| 669 if (!gridLength.hasPercentage() || hasDefiniteFreeSpace) | |
|
eae
2016/08/29 18:19:40
Where is percentage lengths handled?
svillar
2016/08/29 20:01:55
Precisely here. We only consider percentage length
| |
| 670 track.setGrowthLimitCap(valueForLength(gridLength.length(), maxS ize)); | |
| 671 } | |
| 672 | |
| 658 if (trackSize.isContentSized()) | 673 if (trackSize.isContentSized()) |
| 659 sizingData.contentSizedTracksIndex.append(i); | 674 sizingData.contentSizedTracksIndex.append(i); |
| 660 if (trackSize.maxTrackBreadth().isFlex()) | 675 if (trackSize.maxTrackBreadth().isFlex()) |
| 661 flexibleSizedTracksIndex.append(i); | 676 flexibleSizedTracksIndex.append(i); |
| 662 } | 677 } |
| 663 | 678 |
| 664 // 2. Resolve content-based TrackSizingFunctions. | 679 // 2. Resolve content-based TrackSizingFunctions. |
| 665 if (!sizingData.contentSizedTracksIndex.isEmpty()) | 680 if (!sizingData.contentSizedTracksIndex.isEmpty()) |
| 666 resolveContentBasedTrackSizingFunctions(direction, sizingData); | 681 resolveContentBasedTrackSizingFunctions(direction, sizingData); |
| 667 | 682 |
| 668 baseSizesWithoutMaximization = growthLimitsWithoutMaximization = LayoutUnit( ); | 683 baseSizesWithoutMaximization = growthLimitsWithoutMaximization = LayoutUnit( ); |
| 669 | 684 |
| 670 for (const auto& track: tracks) { | 685 for (auto& track: tracks) { |
| 671 ASSERT(!track.infiniteGrowthPotential()); | 686 ASSERT(!track.infiniteGrowthPotential()); |
| 672 baseSizesWithoutMaximization += track.baseSize(); | 687 baseSizesWithoutMaximization += track.baseSize(); |
| 673 growthLimitsWithoutMaximization += track.growthLimit(); | 688 growthLimitsWithoutMaximization += track.growthLimit(); |
| 689 // The growth limit caps must be cleared now in order to properly sort t racks by growth | |
| 690 // potential on an eventual "Maximize Tracks". | |
| 691 track.setGrowthLimitCap(WTF::nullopt); | |
|
Manuel Rego
2016/08/31 07:24:29
So I guess in one phase we ignore the limit for so
svillar
2016/08/31 09:50:04
While computing the sizes of content sized tracks
| |
| 674 } | 692 } |
| 675 freeSpace = initialFreeSpace - baseSizesWithoutMaximization; | 693 freeSpace = initialFreeSpace - baseSizesWithoutMaximization; |
| 676 | 694 |
| 677 if (hasDefiniteFreeSpace && freeSpace <= 0) | 695 if (hasDefiniteFreeSpace && freeSpace <= 0) |
| 678 return; | 696 return; |
| 679 | 697 |
| 680 // 3. Grow all Grid tracks in GridTracks from their baseSize up to their gro wthLimit value until freeSpace is exhausted. | 698 // 3. Grow all Grid tracks in GridTracks from their baseSize up to their gro wthLimit value until freeSpace is exhausted. |
| 681 const size_t tracksSize = tracks.size(); | 699 const size_t tracksSize = tracks.size(); |
| 682 if (hasDefiniteFreeSpace) { | 700 if (hasDefiniteFreeSpace) { |
| 683 Vector<GridTrack*> tracksForDistribution(tracksSize); | 701 Vector<GridTrack*> tracksForDistribution(tracksSize); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 if (LayoutUnit increment = baseSize - oldBaseSize) { | 748 if (LayoutUnit increment = baseSize - oldBaseSize) { |
| 731 tracks[trackIndex].setBaseSize(baseSize); | 749 tracks[trackIndex].setBaseSize(baseSize); |
| 732 freeSpace -= increment; | 750 freeSpace -= increment; |
| 733 | 751 |
| 734 baseSizesWithoutMaximization += increment; | 752 baseSizesWithoutMaximization += increment; |
| 735 growthLimitsWithoutMaximization += increment; | 753 growthLimitsWithoutMaximization += increment; |
| 736 } | 754 } |
| 737 } | 755 } |
| 738 } | 756 } |
| 739 | 757 |
| 740 LayoutUnit LayoutGrid::computeUsedBreadthOfMinLength(const GridLength& gridLengt h, LayoutUnit maxSize) const | 758 LayoutUnit LayoutGrid::computeUsedBreadthOfMinLength(const GridTrackSize& trackS ize, LayoutUnit maxSize) const |
| 741 { | 759 { |
| 760 const GridLength& gridLength = trackSize.minTrackBreadth(); | |
| 742 if (gridLength.isFlex()) | 761 if (gridLength.isFlex()) |
| 743 return LayoutUnit(); | 762 return LayoutUnit(); |
| 744 | 763 |
| 745 const Length& trackLength = gridLength.length(); | 764 const Length& trackLength = gridLength.length(); |
| 746 if (trackLength.isSpecified()) | 765 if (trackLength.isSpecified()) |
| 747 return valueForLength(trackLength, maxSize); | 766 return valueForLength(trackLength, maxSize); |
| 748 | 767 |
| 749 ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isM axContent()); | 768 ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isM axContent()); |
| 750 return LayoutUnit(); | 769 return LayoutUnit(); |
| 751 } | 770 } |
| 752 | 771 |
| 753 LayoutUnit LayoutGrid::computeUsedBreadthOfMaxLength(const GridLength& gridLengt h, LayoutUnit usedBreadth, LayoutUnit maxSize) const | 772 LayoutUnit LayoutGrid::computeUsedBreadthOfMaxLength(const GridTrackSize& trackS ize, LayoutUnit usedBreadth, LayoutUnit maxSize) const |
| 754 { | 773 { |
| 774 const GridLength& gridLength = trackSize.maxTrackBreadth(); | |
| 755 if (gridLength.isFlex()) | 775 if (gridLength.isFlex()) |
| 756 return usedBreadth; | 776 return usedBreadth; |
| 757 | 777 |
| 758 const Length& trackLength = gridLength.length(); | 778 const Length& trackLength = gridLength.length(); |
| 759 if (trackLength.isSpecified()) | 779 if (trackLength.isSpecified()) |
| 760 return valueForLength(trackLength, maxSize); | 780 return valueForLength(trackLength, maxSize); |
| 761 | 781 |
| 762 ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isM axContent()); | 782 ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isM axContent()); |
| 763 return LayoutUnit(infinity); | 783 return LayoutUnit(infinity); |
| 764 } | 784 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 return autoRepeatTrackStyles[autoRepeatLocalIndex % autoRepeatTrackStyle s.size()]; | 894 return autoRepeatTrackStyles[autoRepeatLocalIndex % autoRepeatTrackStyle s.size()]; |
| 875 } | 895 } |
| 876 | 896 |
| 877 return trackStyles[untranslatedIndex - autoRepeatTracksCount]; | 897 return trackStyles[untranslatedIndex - autoRepeatTracksCount]; |
| 878 } | 898 } |
| 879 | 899 |
| 880 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t translatedIndex, SizingOperation sizingOperation) const | 900 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t translatedIndex, SizingOperation sizingOperation) const |
| 881 { | 901 { |
| 882 // Collapse empty auto repeat tracks if auto-fit. | 902 // Collapse empty auto repeat tracks if auto-fit. |
| 883 if (hasAutoRepeatEmptyTracks(direction) && isEmptyAutoRepeatTrack(direction, translatedIndex)) | 903 if (hasAutoRepeatEmptyTracks(direction) && isEmptyAutoRepeatTrack(direction, translatedIndex)) |
| 884 return { Length(Fixed), Length(Fixed) }; | 904 return { Length(Fixed), LengthTrackSizing }; |
| 885 | 905 |
| 886 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex ); | 906 const GridTrackSize& trackSize = rawGridTrackSize(direction, translatedIndex ); |
| 907 if (trackSize.isFitContent()) | |
| 908 return trackSize; | |
| 887 | 909 |
| 888 GridLength minTrackBreadth = trackSize.minTrackBreadth(); | 910 GridLength minTrackBreadth = trackSize.minTrackBreadth(); |
| 889 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); | 911 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); |
| 890 | |
| 891 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>. | 912 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>. |
| 892 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { | 913 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { |
| 893 // For the inline axis this only happens when we're computing the intrin sic sizes (AvailableSpaceIndefinite). | 914 // For the inline axis this only happens when we're computing the intrin sic sizes (AvailableSpaceIndefinite). |
| 894 // For the block axis we check that the percentage height is resolvable on the first in-flow child. | 915 // For the block axis we check that the percentage height is resolvable on the first in-flow child. |
| 895 // TODO (lajava) This condition for determining whether a size is indefi nite or not is not working correctly for orthogonal flows. | 916 // TODO (lajava) This condition for determining whether a size is indefi nite or not is not working correctly for orthogonal flows. |
| 896 if ((sizingOperation == IntrinsicSizeComputation) || (direction == ForRo ws && firstInFlowChildBox() && !firstInFlowChildBox()->percentageLogicalHeightIs Resolvable())) { | 917 if ((sizingOperation == IntrinsicSizeComputation) || (direction == ForRo ws && firstInFlowChildBox() && !firstInFlowChildBox()->percentageLogicalHeightIs Resolvable())) { |
| 897 if (minTrackBreadth.hasPercentage()) | 918 if (minTrackBreadth.hasPercentage()) |
| 898 minTrackBreadth = Length(Auto); | 919 minTrackBreadth = Length(Auto); |
| 899 if (maxTrackBreadth.hasPercentage()) | 920 if (maxTrackBreadth.hasPercentage()) |
| 900 maxTrackBreadth = Length(Auto); | 921 maxTrackBreadth = Length(Auto); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1089 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMinimums >(direction, sizingData, spanGroupRange); | 1110 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMinimums >(direction, sizingData, spanGroupRange); |
| 1090 resolveContentBasedTrackSizingFunctionsForItems<ResolveContentBasedMinim ums>(direction, sizingData, spanGroupRange); | 1111 resolveContentBasedTrackSizingFunctionsForItems<ResolveContentBasedMinim ums>(direction, sizingData, spanGroupRange); |
| 1091 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMinimum s>(direction, sizingData, spanGroupRange); | 1112 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMinimum s>(direction, sizingData, spanGroupRange); |
| 1092 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMaximums >(direction, sizingData, spanGroupRange); | 1113 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMaximums >(direction, sizingData, spanGroupRange); |
| 1093 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMaximum s>(direction, sizingData, spanGroupRange); | 1114 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMaximum s>(direction, sizingData, spanGroupRange); |
| 1094 it = spanGroupRange.rangeEnd; | 1115 it = spanGroupRange.rangeEnd; |
| 1095 } | 1116 } |
| 1096 | 1117 |
| 1097 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 1118 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 1098 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; | 1119 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; |
| 1099 if (track.growthLimitIsInfinite()) | 1120 if (track.growthLimit() == infinity) |
|
Manuel Rego
2016/08/31 07:24:29
Why this change?
svillar
2016/08/31 09:50:04
Because growthLimitIsInfinite() is private now. I
| |
| 1100 track.setGrowthLimit(track.baseSize()); | 1121 track.setGrowthLimit(track.baseSize()); |
| 1101 } | 1122 } |
| 1102 } | 1123 } |
| 1103 | 1124 |
| 1104 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT rack& track, GridSizingData& sizingData) const | 1125 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT rack& track, GridSizingData& sizingData) const |
| 1105 { | 1126 { |
| 1106 const size_t trackPosition = span.startLine(); | 1127 const size_t trackPosition = span.startLine(); |
| 1107 GridTrackSize trackSize = gridTrackSize(direction, trackPosition, sizingData .sizingOperation); | 1128 GridTrackSize trackSize = gridTrackSize(direction, trackPosition, sizingData .sizingOperation); |
| 1108 | 1129 |
| 1109 if (trackSize.hasMinContentMinTrackBreadth()) | 1130 if (trackSize.hasMinContentMinTrackBreadth()) |
| 1110 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, sizingData))); | 1131 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, sizingData))); |
| 1111 else if (trackSize.hasMaxContentMinTrackBreadth()) | 1132 else if (trackSize.hasMaxContentMinTrackBreadth()) |
| 1112 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, sizingData))); | 1133 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, sizingData))); |
| 1113 else if (trackSize.hasAutoMinTrackBreadth()) | 1134 else if (trackSize.hasAutoMinTrackBreadth()) |
| 1114 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, sizingData))); | 1135 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, sizingData))); |
| 1115 | 1136 |
| 1116 if (trackSize.hasMinContentMaxTrackBreadth()) | 1137 if (trackSize.hasMinContentMaxTrackBreadth()) { |
| 1117 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, sizingData))); | 1138 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, sizingData))); |
| 1118 else if (trackSize.hasMaxContentOrAutoMaxTrackBreadth()) | 1139 } else if (trackSize.hasMaxContentOrAutoMaxTrackBreadth()) { |
| 1119 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr idItem, direction, sizingData))); | 1140 LayoutUnit growthLimit = maxContentForChild(gridItem, direction, sizingD ata); |
| 1141 if (trackSize.isFitContent()) | |
| 1142 growthLimit = std::min(growthLimit, valueForLength(trackSize.length( ).length(), sizingData.availableSpace())); | |
| 1143 track.setGrowthLimit(std::max(track.growthLimit(), growthLimit)); | |
| 1144 } | |
| 1120 } | 1145 } |
| 1121 | 1146 |
| 1122 static const LayoutUnit& trackSizeForTrackSizeComputationPhase(TrackSizeComputat ionPhase phase, const GridTrack& track, TrackSizeRestriction restriction) | 1147 static LayoutUnit trackSizeForTrackSizeComputationPhase(TrackSizeComputationPhas e phase, const GridTrack& track, TrackSizeRestriction restriction) |
| 1123 { | 1148 { |
| 1124 switch (phase) { | 1149 switch (phase) { |
| 1125 case ResolveIntrinsicMinimums: | 1150 case ResolveIntrinsicMinimums: |
| 1126 case ResolveContentBasedMinimums: | 1151 case ResolveContentBasedMinimums: |
| 1127 case ResolveMaxContentMinimums: | 1152 case ResolveMaxContentMinimums: |
| 1128 case MaximizeTracks: | 1153 case MaximizeTracks: |
| 1129 return track.baseSize(); | 1154 return track.baseSize(); |
| 1130 case ResolveIntrinsicMaximums: | 1155 case ResolveIntrinsicMaximums: |
| 1131 case ResolveMaxContentMaximums: | 1156 case ResolveMaxContentMaximums: |
| 1132 const LayoutUnit& growthLimit = track.growthLimit(); | 1157 const LayoutUnit& growthLimit = track.growthLimit(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1289 GridTrack& track = tracks[trackIndex]; | 1314 GridTrack& track = tracks[trackIndex]; |
| 1290 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); | 1315 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); |
| 1291 updateTrackSizeForTrackSizeComputationPhase(phase, track); | 1316 updateTrackSizeForTrackSizeComputationPhase(phase, track); |
| 1292 } | 1317 } |
| 1293 } | 1318 } |
| 1294 | 1319 |
| 1295 static bool sortByGridTrackGrowthPotential(const GridTrack* track1, const GridTr ack* track2) | 1320 static bool sortByGridTrackGrowthPotential(const GridTrack* track1, const GridTr ack* track2) |
| 1296 { | 1321 { |
| 1297 // This check ensures that we respect the irreflexivity property of the stri ct weak ordering required by std::sort | 1322 // This check ensures that we respect the irreflexivity property of the stri ct weak ordering required by std::sort |
| 1298 // (forall x: NOT x < x). | 1323 // (forall x: NOT x < x). |
| 1299 if (track1->infiniteGrowthPotential() && track2->infiniteGrowthPotential()) | 1324 bool track1HasInfiniteGrowthPotentialWithoutCap = track1->infiniteGrowthPote ntial() && !track1->growthLimitCap(); |
| 1325 bool track2HasInfiniteGrowthPotentialWithoutCap = track2->infiniteGrowthPote ntial() && !track2->growthLimitCap(); | |
| 1326 | |
| 1327 if (track1HasInfiniteGrowthPotentialWithoutCap && track2HasInfiniteGrowthPot entialWithoutCap) | |
| 1300 return false; | 1328 return false; |
| 1301 | 1329 |
| 1302 if (track1->infiniteGrowthPotential() || track2->infiniteGrowthPotential()) | 1330 if (track1HasInfiniteGrowthPotentialWithoutCap || track2HasInfiniteGrowthPot entialWithoutCap) |
| 1303 return track2->infiniteGrowthPotential(); | 1331 return track2HasInfiniteGrowthPotentialWithoutCap; |
| 1304 | 1332 |
| 1305 return (track1->growthLimit() - track1->baseSize()) < (track2->growthLimit() - track2->baseSize()); | 1333 LayoutUnit track1Limit = track1->growthLimitCap().value_or(track1->growthLim it()); |
| 1334 LayoutUnit track2Limit = track2->growthLimitCap().value_or(track2->growthLim it()); | |
| 1335 return (track1Limit - track1->baseSize()) < (track2Limit - track2->baseSize( )); | |
| 1336 } | |
| 1337 | |
| 1338 static void clampGrowthShareIfNeeded(TrackSizeComputationPhase phase, const Grid Track& track, LayoutUnit& growthShare) | |
| 1339 { | |
| 1340 if (phase != ResolveMaxContentMaximums || !track.growthLimitCap()) | |
| 1341 return; | |
| 1342 | |
| 1343 LayoutUnit distanceToCap = track.growthLimitCap().value() - track.sizeDuring Distribution(); | |
|
Manuel Rego
2016/08/31 07:24:29
Nit: "distanceToCap"? Maybe better "sizeToCap".
| |
| 1344 if (distanceToCap <= 0) | |
| 1345 return; | |
| 1346 | |
| 1347 growthShare = std::min(growthShare, distanceToCap); | |
| 1306 } | 1348 } |
| 1307 | 1349 |
| 1308 template <TrackSizeComputationPhase phase> | 1350 template <TrackSizeComputationPhase phase> |
| 1309 void LayoutGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, const Vecto r<GridTrack*>* growBeyondGrowthLimitsTracks, GridSizingData& sizingData, LayoutU nit& availableLogicalSpace) const | 1351 void LayoutGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, Vector<Grid Track*>* growBeyondGrowthLimitsTracks, GridSizingData& sizingData, LayoutUnit& a vailableLogicalSpace) const |
| 1310 { | 1352 { |
| 1311 ASSERT(availableLogicalSpace >= 0); | 1353 ASSERT(availableLogicalSpace >= 0); |
| 1312 | 1354 |
| 1313 for (auto* track : tracks) | 1355 for (auto* track : tracks) |
| 1314 track->setSizeDuringDistribution(trackSizeForTrackSizeComputationPhase(p hase, *track, ForbidInfinity)); | 1356 track->setSizeDuringDistribution(trackSizeForTrackSizeComputationPhase(p hase, *track, ForbidInfinity)); |
| 1315 | 1357 |
| 1316 if (availableLogicalSpace > 0) { | 1358 if (availableLogicalSpace > 0) { |
| 1317 std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential); | 1359 std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential); |
| 1318 | 1360 |
| 1319 size_t tracksSize = tracks.size(); | 1361 size_t tracksSize = tracks.size(); |
| 1320 for (size_t i = 0; i < tracksSize; ++i) { | 1362 for (size_t i = 0; i < tracksSize; ++i) { |
| 1321 GridTrack& track = *tracks[i]; | 1363 GridTrack& track = *tracks[i]; |
| 1322 LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tra cksSize - i); | 1364 LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tra cksSize - i); |
| 1323 const LayoutUnit& trackBreadth = trackSizeForTrackSizeComputationPha se(phase, track, ForbidInfinity); | 1365 const LayoutUnit& trackBreadth = trackSizeForTrackSizeComputationPha se(phase, track, ForbidInfinity); |
| 1324 LayoutUnit growthShare = track.infiniteGrowthPotential() ? available LogicalSpaceShare : std::min(availableLogicalSpaceShare, track.growthLimit() - t rackBreadth); | 1366 LayoutUnit growthShare = track.infiniteGrowthPotential() ? available LogicalSpaceShare : std::min(availableLogicalSpaceShare, track.growthLimit() - t rackBreadth); |
| 1367 clampGrowthShareIfNeeded(phase, track, growthShare); | |
| 1325 DCHECK_GE(growthShare, 0) << "We must never shrink any grid track or else we can't guarantee we abide by our min-sizing function."; | 1368 DCHECK_GE(growthShare, 0) << "We must never shrink any grid track or else we can't guarantee we abide by our min-sizing function."; |
| 1326 track.growSizeDuringDistribution(growthShare); | 1369 track.growSizeDuringDistribution(growthShare); |
| 1327 availableLogicalSpace -= growthShare; | 1370 availableLogicalSpace -= growthShare; |
| 1328 } | 1371 } |
| 1329 } | 1372 } |
| 1330 | 1373 |
| 1331 if (availableLogicalSpace > 0 && growBeyondGrowthLimitsTracks) { | 1374 if (availableLogicalSpace > 0 && growBeyondGrowthLimitsTracks) { |
| 1375 // We need to sort them because there might be tracks with growth limit caps (like the ones | |
| 1376 // with fit-content()) which cannot indefinitely grow over the limits. | |
| 1377 if (phase == ResolveMaxContentMaximums) | |
| 1378 std::sort(growBeyondGrowthLimitsTracks->begin(), growBeyondGrowthLim itsTracks->end(), sortByGridTrackGrowthPotential); | |
| 1379 | |
| 1332 size_t tracksGrowingAboveMaxBreadthSize = growBeyondGrowthLimitsTracks-> size(); | 1380 size_t tracksGrowingAboveMaxBreadthSize = growBeyondGrowthLimitsTracks-> size(); |
| 1333 for (size_t i = 0; i < tracksGrowingAboveMaxBreadthSize; ++i) { | 1381 for (size_t i = 0; i < tracksGrowingAboveMaxBreadthSize; ++i) { |
| 1334 GridTrack* track = growBeyondGrowthLimitsTracks->at(i); | 1382 GridTrack* track = growBeyondGrowthLimitsTracks->at(i); |
| 1335 LayoutUnit growthShare = availableLogicalSpace / (tracksGrowingAbove MaxBreadthSize - i); | 1383 LayoutUnit growthShare = availableLogicalSpace / (tracksGrowingAbove MaxBreadthSize - i); |
| 1384 clampGrowthShareIfNeeded(phase, *track, growthShare); | |
| 1385 DCHECK_GE(growthShare, 0) << "We must never shrink any grid track or else we can't guarantee we abide by our min-sizing function."; | |
| 1336 track->growSizeDuringDistribution(growthShare); | 1386 track->growSizeDuringDistribution(growthShare); |
| 1337 availableLogicalSpace -= growthShare; | 1387 availableLogicalSpace -= growthShare; |
| 1338 } | 1388 } |
| 1339 } | 1389 } |
| 1340 | 1390 |
| 1341 for (auto* track : tracks) | 1391 for (auto* track : tracks) |
| 1342 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( ))); | 1392 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( ))); |
| 1343 } | 1393 } |
| 1344 | 1394 |
| 1345 #if ENABLE(ASSERT) | 1395 #if ENABLE(ASSERT) |
| 1346 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, GridSizingData& sizingData) | 1396 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, GridSizingData& sizingData) |
| 1347 { | 1397 { |
| 1348 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; | 1398 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; |
| 1349 LayoutUnit& maxSize = sizingData.freeSpaceForDirection(direction); | 1399 LayoutUnit& maxSize = sizingData.freeSpace(direction); |
| 1350 for (size_t i = 0; i < tracks.size(); ++i) { | 1400 for (size_t i = 0; i < tracks.size(); ++i) { |
| 1351 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); | 1401 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); |
| 1352 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 1402 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > tracks[i].baseSi ze()) |
| 1353 if (computeUsedBreadthOfMinLength(minTrackBreadth, maxSize) > tracks[i]. baseSize()) | |
| 1354 return false; | 1403 return false; |
| 1355 } | 1404 } |
| 1356 return true; | 1405 return true; |
| 1357 } | 1406 } |
| 1358 #endif | 1407 #endif |
| 1359 | 1408 |
| 1360 void LayoutGrid::ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize) | 1409 void LayoutGrid::ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize) |
| 1361 { | 1410 { |
| 1362 const size_t oldRowSize = gridRowCount(); | 1411 const size_t oldRowSize = gridRowCount(); |
| 1363 if (maximumRowSize > oldRowSize) { | 1412 if (maximumRowSize > oldRowSize) { |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1792 } | 1841 } |
| 1793 | 1842 |
| 1794 static const StyleContentAlignmentData& contentAlignmentNormalBehavior() | 1843 static const StyleContentAlignmentData& contentAlignmentNormalBehavior() |
| 1795 { | 1844 { |
| 1796 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch}; | 1845 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch}; |
| 1797 return normalBehavior; | 1846 return normalBehavior; |
| 1798 } | 1847 } |
| 1799 | 1848 |
| 1800 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData) | 1849 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData) |
| 1801 { | 1850 { |
| 1802 LayoutUnit& availableSpace = sizingData.freeSpaceForDirection(direction); | 1851 LayoutUnit& availableSpace = sizingData.freeSpace(direction); |
| 1803 if (availableSpace <= 0 | 1852 if (availableSpace <= 0 |
| 1804 || (direction == ForColumns && styleRef().resolvedJustifyContentDistribu tion(contentAlignmentNormalBehavior()) != ContentDistributionStretch) | 1853 || (direction == ForColumns && styleRef().resolvedJustifyContentDistribu tion(contentAlignmentNormalBehavior()) != ContentDistributionStretch) |
| 1805 || (direction == ForRows && styleRef().resolvedAlignContentDistribution( contentAlignmentNormalBehavior()) != ContentDistributionStretch)) | 1854 || (direction == ForRows && styleRef().resolvedAlignContentDistribution( contentAlignmentNormalBehavior()) != ContentDistributionStretch)) |
| 1806 return; | 1855 return; |
| 1807 | 1856 |
| 1808 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing func tion. | 1857 // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing func tion. |
| 1809 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; | 1858 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; |
| 1810 Vector<unsigned> autoSizedTracksIndex; | 1859 Vector<unsigned> autoSizedTracksIndex; |
| 1811 for (unsigned i = 0; i < tracks.size(); ++i) { | 1860 for (unsigned i = 0; i < tracks.size(); ++i) { |
| 1812 const GridTrackSize& trackSize = gridTrackSize(direction, i); | 1861 const GridTrackSize& trackSize = gridTrackSize(direction, i); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2077 // except the last one, which is the only one considered as a final grid lin e of a track. | 2126 // except the last one, which is the only one considered as a final grid lin e of a track. |
| 2078 | 2127 |
| 2079 // The grid container's frame elements (border, padding and <content-positio n> offset) are sensible to the | 2128 // The grid container's frame elements (border, padding and <content-positio n> offset) are sensible to the |
| 2080 // inline-axis flow direction. However, column lines positions are 'directio n' unaware. This simplification | 2129 // inline-axis flow direction. However, column lines positions are 'directio n' unaware. This simplification |
| 2081 // allows us to use the same indexes to identify the columns independently o n the inline-axis direction. | 2130 // allows us to use the same indexes to identify the columns independently o n the inline-axis direction. |
| 2082 bool isRowAxis = direction == ForColumns; | 2131 bool isRowAxis = direction == ForColumns; |
| 2083 auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks; | 2132 auto& tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks; |
| 2084 size_t numberOfTracks = tracks.size(); | 2133 size_t numberOfTracks = tracks.size(); |
| 2085 size_t numberOfLines = numberOfTracks + 1; | 2134 size_t numberOfLines = numberOfTracks + 1; |
| 2086 size_t lastLine = numberOfLines - 1; | 2135 size_t lastLine = numberOfLines - 1; |
| 2087 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di rection, sizingData.freeSpaceForDirection(direction), numberOfTracks); | 2136 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(di rection, sizingData.freeSpace(direction), numberOfTracks); |
| 2088 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; | 2137 auto& positions = isRowAxis ? m_columnPositions : m_rowPositions; |
| 2089 positions.resize(numberOfLines); | 2138 positions.resize(numberOfLines); |
| 2090 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn dPaddingBefore(); | 2139 auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAn dPaddingBefore(); |
| 2091 positions[0] = borderAndPadding + offset.positionOffset; | 2140 positions[0] = borderAndPadding + offset.positionOffset; |
| 2092 if (numberOfLines > 1) { | 2141 if (numberOfLines > 1) { |
| 2093 // If we have collapsed tracks we just ignore gaps here and add them lat er as we might not | 2142 // If we have collapsed tracks we just ignore gaps here and add them lat er as we might not |
| 2094 // compute the gap between two consecutive tracks without examining the surrounding ones. | 2143 // compute the gap between two consecutive tracks without examining the surrounding ones. |
| 2095 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); | 2144 bool hasCollapsedTracks = hasAutoRepeatEmptyTracks(direction); |
| 2096 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction) : LayoutUnit(); | 2145 LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction) : LayoutUnit(); |
| 2097 size_t nextToLastLine = numberOfLines - 2; | 2146 size_t nextToLastLine = numberOfLines - 2; |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2602 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; | 2651 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; |
| 2603 } | 2652 } |
| 2604 | 2653 |
| 2605 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2654 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
| 2606 { | 2655 { |
| 2607 if (!m_gridItemArea.isEmpty()) | 2656 if (!m_gridItemArea.isEmpty()) |
| 2608 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2657 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 2609 } | 2658 } |
| 2610 | 2659 |
| 2611 } // namespace blink | 2660 } // namespace blink |
| OLD | NEW |