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 25 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 static const int infinity = -1; | 39 static const int infinity = -1; |
| 40 | 40 |
| 41 class GridItemWithSpan; | 41 class GridItemWithSpan; |
| 42 | 42 |
| 43 class GridTrack { | 43 class GridTrack { |
| 44 public: | 44 public: |
| 45 GridTrack() | 45 GridTrack() |
| 46 : m_plannedIncrease(0) | 46 : m_baseSize(0) |
| 47 , m_increaseDuringDistribution(0) | |
| 48 , m_baseSize(0) | |
| 49 , m_growthLimit(0) | 47 , m_growthLimit(0) |
| 48 , m_plannedSize(0) | |
| 49 , m_sizeDuringDistribution(0) | |
| 50 , m_infinitelyGrowable(false) | |
| 50 { | 51 { |
| 51 } | 52 } |
| 52 | 53 |
| 53 const LayoutUnit& baseSize() const | 54 const LayoutUnit& baseSize() const |
| 54 { | 55 { |
| 55 ASSERT(isGrowthLimitBiggerThanBaseSize()); | 56 ASSERT(isGrowthLimitBiggerThanBaseSize()); |
| 56 return m_baseSize; | 57 return m_baseSize; |
| 57 } | 58 } |
| 58 | 59 |
| 59 const LayoutUnit& growthLimit() const | 60 const LayoutUnit& growthLimit() const |
| 60 { | 61 { |
| 61 ASSERT(isGrowthLimitBiggerThanBaseSize()); | 62 ASSERT(isGrowthLimitBiggerThanBaseSize()); |
| 62 return m_growthLimit; | 63 return m_growthLimit; |
| 63 } | 64 } |
| 64 | 65 |
| 65 void setBaseSize(LayoutUnit baseSize) | 66 void setBaseSize(LayoutUnit baseSize) |
| 66 { | 67 { |
| 67 m_baseSize = baseSize; | 68 m_baseSize = baseSize; |
| 68 ensureGrowthLimitIsBiggerThanBaseSize(); | 69 ensureGrowthLimitIsBiggerThanBaseSize(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void setGrowthLimit(LayoutUnit growthLimit) | 72 void setGrowthLimit(LayoutUnit growthLimit) |
| 72 { | 73 { |
| 73 m_growthLimit = growthLimit; | 74 m_growthLimit = growthLimit; |
| 74 ensureGrowthLimitIsBiggerThanBaseSize(); | 75 ensureGrowthLimitIsBiggerThanBaseSize(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void growBaseSize(LayoutUnit growth) | |
| 78 { | |
| 79 ASSERT(growth >= 0); | |
| 80 m_baseSize += growth; | |
| 81 ensureGrowthLimitIsBiggerThanBaseSize(); | |
| 82 } | |
| 83 | |
| 84 void growGrowthLimit(LayoutUnit growth) | |
| 85 { | |
| 86 ASSERT(growth >= 0); | |
| 87 if (m_growthLimit == infinity) | |
| 88 m_growthLimit = m_baseSize + growth; | |
| 89 else | |
| 90 m_growthLimit += growth; | |
| 91 | |
| 92 ASSERT(m_growthLimit >= m_baseSize); | |
| 93 } | |
| 94 | |
| 95 bool growthLimitIsInfinite() const | 78 bool growthLimitIsInfinite() const |
| 96 { | 79 { |
| 97 return m_growthLimit == infinity; | 80 return m_growthLimit == infinity; |
| 98 } | 81 } |
| 99 | 82 |
| 100 const LayoutUnit& growthLimitIfNotInfinite() const | 83 bool infiniteGrowthPotential() const |
|
Manuel Rego
2015/06/26 11:09:48
Suggestion: maybe call it isInfiniteGrowthPotentia
svillar
2015/06/29 07:08:27
If you don't mind I'd like to keep the name as it
Manuel Rego
2015/06/29 07:46:42
Ok, fair enough.
| |
| 101 { | 84 { |
| 102 ASSERT(isGrowthLimitBiggerThanBaseSize()); | 85 return growthLimitIsInfinite() || m_infinitelyGrowable; |
| 103 return (m_growthLimit == infinity) ? m_baseSize : m_growthLimit; | |
| 104 } | 86 } |
| 105 | 87 |
| 106 LayoutUnit m_plannedIncrease; | 88 const LayoutUnit& plannedSize() const { return m_plannedSize; } |
| 107 LayoutUnit m_increaseDuringDistribution; | 89 |
| 90 void setPlannedSize(const LayoutUnit& plannedSize) | |
| 91 { | |
| 92 ASSERT(plannedSize >= 0 || plannedSize == infinity); | |
| 93 m_plannedSize = plannedSize; | |
| 94 } | |
| 95 | |
| 96 const LayoutUnit& sizeDuringDistribution() { return m_sizeDuringDistribution ; } | |
| 97 | |
| 98 void setSizeDuringDistribution(const LayoutUnit& sizeDuringDistribution) | |
| 99 { | |
| 100 ASSERT(sizeDuringDistribution >= 0); | |
| 101 m_sizeDuringDistribution = sizeDuringDistribution; | |
| 102 } | |
| 103 | |
| 104 void growSizeDuringDistribution(const LayoutUnit& sizeDuringDistribution) | |
| 105 { | |
| 106 ASSERT(sizeDuringDistribution >= 0); | |
| 107 m_sizeDuringDistribution += sizeDuringDistribution; | |
| 108 } | |
| 109 | |
| 110 bool infinitelyGrowable() const { return m_infinitelyGrowable; } | |
| 111 void setInfinitelyGrowable(bool infinitelyGrowable) { m_infinitelyGrowable = infinitelyGrowable; } | |
| 108 | 112 |
| 109 private: | 113 private: |
| 110 bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite( ) || m_growthLimit >= m_baseSize; } | 114 bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite( ) || m_growthLimit >= m_baseSize; } |
| 111 | 115 |
| 112 void ensureGrowthLimitIsBiggerThanBaseSize() | 116 void ensureGrowthLimitIsBiggerThanBaseSize() |
| 113 { | 117 { |
| 114 if (m_growthLimit != infinity && m_growthLimit < m_baseSize) | 118 if (m_growthLimit != infinity && m_growthLimit < m_baseSize) |
| 115 m_growthLimit = m_baseSize; | 119 m_growthLimit = m_baseSize; |
| 116 } | 120 } |
| 117 | 121 |
| 118 LayoutUnit m_baseSize; | 122 LayoutUnit m_baseSize; |
| 119 LayoutUnit m_growthLimit; | 123 LayoutUnit m_growthLimit; |
| 124 LayoutUnit m_plannedSize; | |
| 125 LayoutUnit m_sizeDuringDistribution; | |
| 126 bool m_infinitelyGrowable; | |
| 120 }; | 127 }; |
| 121 | 128 |
| 122 struct GridTrackForNormalization { | 129 struct GridTrackForNormalization { |
| 123 GridTrackForNormalization(const GridTrack& track, double flex) | 130 GridTrackForNormalization(const GridTrack& track, double flex) |
| 124 : m_track(&track) | 131 : m_track(&track) |
| 125 , m_flex(flex) | 132 , m_flex(flex) |
| 126 , m_normalizedFlexValue(track.baseSize() / flex) | 133 , m_normalizedFlexValue(track.baseSize() / flex) |
| 127 { | 134 { |
| 128 } | 135 } |
| 129 | 136 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 | 417 |
| 411 // 1. Initialize per Grid track variables. | 418 // 1. Initialize per Grid track variables. |
| 412 for (size_t i = 0; i < tracks.size(); ++i) { | 419 for (size_t i = 0; i < tracks.size(); ++i) { |
| 413 GridTrack& track = tracks[i]; | 420 GridTrack& track = tracks[i]; |
| 414 GridTrackSize trackSize = gridTrackSize(direction, i); | 421 GridTrackSize trackSize = gridTrackSize(direction, i); |
| 415 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 422 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
| 416 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); | 423 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); |
| 417 | 424 |
| 418 track.setBaseSize(computeUsedBreadthOfMinLength(direction, minTrackBread th)); | 425 track.setBaseSize(computeUsedBreadthOfMinLength(direction, minTrackBread th)); |
| 419 track.setGrowthLimit(computeUsedBreadthOfMaxLength(direction, maxTrackBr eadth, track.baseSize())); | 426 track.setGrowthLimit(computeUsedBreadthOfMaxLength(direction, maxTrackBr eadth, track.baseSize())); |
| 427 track.setInfinitelyGrowable(false); | |
|
Manuel Rego
2015/06/26 11:09:47
Do we really need this?
I thoguht this was false b
svillar
2015/06/29 07:08:27
It's false by default but note that this algorithm
| |
| 420 | 428 |
| 421 if (trackSize.isContentSized()) | 429 if (trackSize.isContentSized()) |
| 422 sizingData.contentSizedTracksIndex.append(i); | 430 sizingData.contentSizedTracksIndex.append(i); |
| 423 if (trackSize.maxTrackBreadth().isFlex()) | 431 if (trackSize.maxTrackBreadth().isFlex()) |
| 424 flexibleSizedTracksIndex.append(i); | 432 flexibleSizedTracksIndex.append(i); |
| 425 } | 433 } |
| 426 | 434 |
| 427 // 2. Resolve content-based TrackSizingFunctions. | 435 // 2. Resolve content-based TrackSizingFunctions. |
| 428 if (!sizingData.contentSizedTracksIndex.isEmpty()) | 436 if (!sizingData.contentSizedTracksIndex.isEmpty()) |
| 429 resolveContentBasedTrackSizingFunctions(direction, sizingData); | 437 resolveContentBasedTrackSizingFunctions(direction, sizingData); |
| 430 | 438 |
| 431 for (const auto& track: tracks) { | 439 for (const auto& track: tracks) { |
| 432 ASSERT(!track.growthLimitIsInfinite()); | 440 ASSERT(!track.infiniteGrowthPotential()); |
| 433 freeSpace -= track.baseSize(); | 441 freeSpace -= track.baseSize(); |
| 434 } | 442 } |
| 435 | 443 |
| 436 const bool hasUndefinedRemainingSpace = (direction == ForRows) ? style()->lo gicalHeight().isAuto() : gridElementIsShrinkToFit(); | 444 const bool hasUndefinedRemainingSpace = (direction == ForRows) ? style()->lo gicalHeight().isAuto() : gridElementIsShrinkToFit(); |
| 437 | 445 |
| 438 if (!hasUndefinedRemainingSpace && freeSpace <= 0) | 446 if (!hasUndefinedRemainingSpace && freeSpace <= 0) |
| 439 return; | 447 return; |
| 440 | 448 |
| 441 // 3. Grow all Grid tracks in GridTracks from their baseSize up to their gro wthLimit value until freeSpace is exhausted. | 449 // 3. Grow all Grid tracks in GridTracks from their baseSize up to their gro wthLimit value until freeSpace is exhausted. |
| 442 // Any 'auto-sized' (content based) track will be 'stretched' over their Max Breadth if required | 450 // Any 'auto-sized' (content based) track will be 'stretched' over their Max Breadth if required |
| 443 // and there is space available, except if there are flexible track, which w ill occupy the whole | 451 // and there is space available, except if there are flexible track, which w ill occupy the whole |
| 444 // available space. | 452 // available space. |
| 445 bool needToStretch = flexibleSizedTracksIndex.isEmpty() && !sizingData.conte ntSizedTracksIndex.isEmpty() | 453 bool needToStretch = flexibleSizedTracksIndex.isEmpty() && !sizingData.conte ntSizedTracksIndex.isEmpty() |
| 446 && ((direction == ForColumns && style()->justifyContentDistribution() == ContentDistributionStretch) | 454 && ((direction == ForColumns && style()->justifyContentDistribution() == ContentDistributionStretch) |
| 447 || (direction == ForRows && style()->alignContentDistribution() == C ontentDistributionStretch)); | 455 || (direction == ForRows && style()->alignContentDistribution() == C ontentDistributionStretch)); |
| 448 const size_t tracksSize = tracks.size(); | 456 const size_t tracksSize = tracks.size(); |
| 449 if (!hasUndefinedRemainingSpace) { | 457 if (!hasUndefinedRemainingSpace) { |
| 450 Vector<GridTrack*> tracksForDistribution(tracksSize); | 458 Vector<GridTrack*> tracksForDistribution(tracksSize); |
| 451 for (size_t i = 0; i < tracksSize; ++i) { | 459 for (size_t i = 0; i < tracksSize; ++i) { |
| 452 tracksForDistribution[i] = tracks.data() + i; | 460 tracksForDistribution[i] = tracks.data() + i; |
| 453 tracksForDistribution[i]->m_plannedIncrease = 0; | 461 tracksForDistribution[i]->setPlannedSize(tracksForDistribution[i]->b aseSize()); |
| 454 } | 462 } |
| 455 | 463 |
| 456 Vector<GridTrack*> tracksToStretch(sizingData.contentSizedTracksIndex.si ze()); | 464 Vector<GridTrack*> tracksToStretch(sizingData.contentSizedTracksIndex.si ze()); |
| 457 if (needToStretch) { | 465 if (needToStretch) { |
| 458 unsigned i = 0; | 466 unsigned i = 0; |
| 459 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 467 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 460 tracksToStretch[i++] = tracks.data() + trackIndex; | 468 tracksToStretch[i++] = tracks.data() + trackIndex; |
| 461 } | 469 } |
| 462 } | 470 } |
| 463 | 471 |
| 464 distributeSpaceToTracks<MaximizeTracks>(tracksForDistribution, needToStr etch ? &tracksToStretch : nullptr, sizingData, freeSpace); | 472 distributeSpaceToTracks<MaximizeTracks>(tracksForDistribution, needToStr etch ? &tracksToStretch : nullptr, sizingData, freeSpace); |
| 465 | 473 |
| 466 for (auto* track : tracksForDistribution) | 474 for (auto* track : tracksForDistribution) |
| 467 track->growBaseSize(track->m_plannedIncrease); | 475 track->setBaseSize(track->plannedSize()); |
| 468 } else { | 476 } else { |
| 469 for (auto& track : tracks) | 477 for (auto& track : tracks) |
| 470 track.setBaseSize(track.growthLimit()); | 478 track.setBaseSize(track.growthLimit()); |
| 471 } | 479 } |
| 472 | 480 |
| 473 if (flexibleSizedTracksIndex.isEmpty()) | 481 if (flexibleSizedTracksIndex.isEmpty()) |
| 474 return; | 482 return; |
| 475 | 483 |
| 476 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. | 484 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. |
| 477 double normalizedFractionBreadth = 0; | 485 double normalizedFractionBreadth = 0; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr idItem, direction, columnTracks))); | 799 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr idItem, direction, columnTracks))); |
| 792 } | 800 } |
| 793 | 801 |
| 794 static const LayoutUnit& trackSizeForTrackSizeComputationPhase(TrackSizeComputat ionPhase phase, const GridTrack& track, TrackSizeRestriction restriction) | 802 static const LayoutUnit& trackSizeForTrackSizeComputationPhase(TrackSizeComputat ionPhase phase, const GridTrack& track, TrackSizeRestriction restriction) |
| 795 { | 803 { |
| 796 switch (phase) { | 804 switch (phase) { |
| 797 case ResolveIntrinsicMinimums: | 805 case ResolveIntrinsicMinimums: |
| 798 case ResolveMaxContentMinimums: | 806 case ResolveMaxContentMinimums: |
| 799 case MaximizeTracks: | 807 case MaximizeTracks: |
| 800 return track.baseSize(); | 808 return track.baseSize(); |
| 801 break; | |
| 802 case ResolveIntrinsicMaximums: | 809 case ResolveIntrinsicMaximums: |
| 803 case ResolveMaxContentMaximums: | 810 case ResolveMaxContentMaximums: |
| 804 return restriction == AllowInfinity ? track.growthLimit() : track.growth LimitIfNotInfinite(); | 811 const LayoutUnit& growthLimit = track.growthLimit(); |
| 805 break; | 812 if (restriction == AllowInfinity) |
| 813 return growthLimit; | |
| 814 return growthLimit == infinity ? track.baseSize() : growthLimit; | |
|
svillar
2015/06/12 16:07:07
This is not strictly required BTW but the growthLi
| |
| 806 } | 815 } |
| 807 | 816 |
| 808 ASSERT_NOT_REACHED(); | 817 ASSERT_NOT_REACHED(); |
| 809 return track.baseSize(); | 818 return track.baseSize(); |
| 810 } | 819 } |
| 811 | 820 |
| 812 static bool shouldProcessTrackForTrackSizeComputationPhase(TrackSizeComputationP hase phase, const GridTrackSize& trackSize) | 821 static bool shouldProcessTrackForTrackSizeComputationPhase(TrackSizeComputationP hase phase, const GridTrackSize& trackSize) |
| 813 { | 822 { |
| 814 switch (phase) { | 823 switch (phase) { |
| 815 case ResolveIntrinsicMinimums: | 824 case ResolveIntrinsicMinimums: |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 841 return true; | 850 return true; |
| 842 case MaximizeTracks: | 851 case MaximizeTracks: |
| 843 ASSERT_NOT_REACHED(); | 852 ASSERT_NOT_REACHED(); |
| 844 return false; | 853 return false; |
| 845 } | 854 } |
| 846 | 855 |
| 847 ASSERT_NOT_REACHED(); | 856 ASSERT_NOT_REACHED(); |
| 848 return false; | 857 return false; |
| 849 } | 858 } |
| 850 | 859 |
| 860 static void markAsInfinitelyGrowableForTrackSizeComputationPhase(TrackSizeComput ationPhase phase, GridTrack& track) | |
| 861 { | |
| 862 switch (phase) { | |
| 863 case ResolveIntrinsicMinimums: | |
| 864 case ResolveMaxContentMinimums: | |
| 865 return; | |
| 866 case ResolveIntrinsicMaximums: | |
| 867 if (trackSizeForTrackSizeComputationPhase(phase, track, AllowInfinity) = = infinity && track.plannedSize() != infinity) | |
| 868 track.setInfinitelyGrowable(true); | |
| 869 return; | |
| 870 case ResolveMaxContentMaximums: | |
| 871 if (track.infinitelyGrowable()) | |
| 872 track.setInfinitelyGrowable(false); | |
| 873 return; | |
| 874 case MaximizeTracks: | |
| 875 ASSERT_NOT_REACHED(); | |
| 876 return; | |
| 877 } | |
| 878 | |
| 879 ASSERT_NOT_REACHED(); | |
| 880 } | |
| 881 | |
|
svillar
2015/06/12 16:07:07
This is the implementation of step 2.3 from: http:
Manuel Rego
2015/06/26 11:09:47
I think you mean 2.2 here (otherwise I don't get i
svillar
2015/06/29 07:08:27
Sure 2.2 you're right.
| |
| 851 static void updateTrackSizeForTrackSizeComputationPhase(TrackSizeComputationPhas e phase, GridTrack& track) | 882 static void updateTrackSizeForTrackSizeComputationPhase(TrackSizeComputationPhas e phase, GridTrack& track) |
| 852 { | 883 { |
| 853 switch (phase) { | 884 switch (phase) { |
| 854 case ResolveIntrinsicMinimums: | 885 case ResolveIntrinsicMinimums: |
| 855 case ResolveMaxContentMinimums: | 886 case ResolveMaxContentMinimums: |
| 856 track.growBaseSize(track.m_plannedIncrease); | 887 track.setBaseSize(track.plannedSize()); |
| 857 return; | 888 return; |
| 858 case ResolveIntrinsicMaximums: | 889 case ResolveIntrinsicMaximums: |
| 859 case ResolveMaxContentMaximums: | 890 case ResolveMaxContentMaximums: |
| 860 track.growGrowthLimit(track.m_plannedIncrease); | 891 track.setGrowthLimit(track.plannedSize()); |
| 861 return; | 892 return; |
| 862 case MaximizeTracks: | 893 case MaximizeTracks: |
| 863 ASSERT_NOT_REACHED(); | 894 ASSERT_NOT_REACHED(); |
| 864 return; | 895 return; |
| 865 } | 896 } |
| 866 | 897 |
| 867 ASSERT_NOT_REACHED(); | 898 ASSERT_NOT_REACHED(); |
| 868 } | 899 } |
| 869 | 900 |
| 870 LayoutUnit LayoutGrid::currentItemSizeForTrackSizeComputationPhase(TrackSizeComp utationPhase phase, LayoutBox& gridItem, GridTrackSizingDirection direction, Vec tor<GridTrack>& columnTracks) | 901 LayoutUnit LayoutGrid::currentItemSizeForTrackSizeComputationPhase(TrackSizeComp utationPhase phase, LayoutBox& gridItem, GridTrackSizingDirection direction, Vec tor<GridTrack>& columnTracks) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 882 } | 913 } |
| 883 | 914 |
| 884 ASSERT_NOT_REACHED(); | 915 ASSERT_NOT_REACHED(); |
| 885 return 0; | 916 return 0; |
| 886 } | 917 } |
| 887 | 918 |
| 888 template <TrackSizeComputationPhase phase> | 919 template <TrackSizeComputationPhase phase> |
| 889 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing Direction direction, GridSizingData& sizingData, const GridItemsSpanGroupRange& gridItemsWithSpan) | 920 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing Direction direction, GridSizingData& sizingData, const GridItemsSpanGroupRange& gridItemsWithSpan) |
| 890 { | 921 { |
| 891 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; | 922 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; |
| 892 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) | 923 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 893 tracks[trackIndex].m_plannedIncrease = 0; | 924 GridTrack& track = tracks[trackIndex]; |
| 925 track.setPlannedSize(trackSizeForTrackSizeComputationPhase(phase, track, AllowInfinity)); | |
| 926 } | |
| 894 | 927 |
| 895 for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEn d; ++it) { | 928 for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEn d; ++it) { |
| 896 GridItemWithSpan& gridItemWithSpan = *it; | 929 GridItemWithSpan& gridItemWithSpan = *it; |
| 897 ASSERT(gridItemWithSpan.span() > 1); | 930 ASSERT(gridItemWithSpan.span() > 1); |
| 898 const GridCoordinate coordinate = gridItemWithSpan.coordinate(); | 931 const GridCoordinate coordinate = gridItemWithSpan.coordinate(); |
| 899 const GridSpan& itemSpan = (direction == ForColumns) ? coordinate.column s : coordinate.rows; | 932 const GridSpan& itemSpan = (direction == ForColumns) ? coordinate.column s : coordinate.rows; |
| 900 | 933 |
| 901 sizingData.growBeyondGrowthLimitsTracks.shrink(0); | 934 sizingData.growBeyondGrowthLimitsTracks.shrink(0); |
| 902 sizingData.filteredTracks.shrink(0); | 935 sizingData.filteredTracks.shrink(0); |
| 903 LayoutUnit spanningTracksSize; | 936 LayoutUnit spanningTracksSize; |
| 904 for (const auto& trackPosition : itemSpan) { | 937 for (const auto& trackPosition : itemSpan) { |
| 905 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toI nt()); | 938 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toI nt()); |
| 906 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackPosition.toInt()] : sizingData.rowTracks[trackPosition.toInt()]; | 939 GridTrack& track = (direction == ForColumns) ? sizingData.columnTrac ks[trackPosition.toInt()] : sizingData.rowTracks[trackPosition.toInt()]; |
| 907 spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, t rack, ForbidInfinity); | 940 spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, t rack, ForbidInfinity); |
| 908 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize )) | 941 if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize )) |
| 909 continue; | 942 continue; |
| 910 | 943 |
| 911 sizingData.filteredTracks.append(&track); | 944 sizingData.filteredTracks.append(&track); |
| 912 | 945 |
| 913 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) | 946 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) |
| 914 sizingData.growBeyondGrowthLimitsTracks.append(&track); | 947 sizingData.growBeyondGrowthLimitsTracks.append(&track); |
| 915 } | 948 } |
| 916 | 949 |
| 917 if (sizingData.filteredTracks.isEmpty()) | 950 if (sizingData.filteredTracks.isEmpty()) |
| 918 continue; | 951 continue; |
| 919 | 952 |
| 920 // Specs mandate to floor extraSpace to 0. Instead we directly avoid the function call in those cases as it will be | |
| 921 // a noop in terms of track sizing. | |
| 922 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData.columnTracks) - spanningTr acksSize; | 953 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData.columnTracks) - spanningTr acksSize; |
| 923 if (extraSpace > 0) { | 954 extraSpace = std::max<LayoutUnit>(extraSpace, 0); |
| 924 Vector<GridTrack*>* tracksToGrowBeyondGrowthLimits = sizingData.grow BeyondGrowthLimitsTracks.isEmpty() ? &sizingData.filteredTracks : &sizingData.gr owBeyondGrowthLimitsTracks; | 955 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks; |
| 925 distributeSpaceToTracks<phase>(sizingData.filteredTracks, tracksToGr owBeyondGrowthLimits, sizingData, extraSpace); | 956 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace); |
| 926 } | |
| 927 } | 957 } |
| 928 | 958 |
| 929 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { | 959 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { |
| 930 GridTrack& track = tracks[trackIndex]; | 960 GridTrack& track = tracks[trackIndex]; |
| 931 if (track.m_plannedIncrease) | 961 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); |
| 932 updateTrackSizeForTrackSizeComputationPhase(phase, track); | 962 updateTrackSizeForTrackSizeComputationPhase(phase, track); |
| 933 } | 963 } |
| 934 } | 964 } |
| 935 | 965 |
| 936 static bool sortByGridTrackGrowthPotential(const GridTrack* track1, const GridTr ack* track2) | 966 static bool sortByGridTrackGrowthPotential(const GridTrack* track1, const GridTr ack* track2) |
| 937 { | 967 { |
| 938 // This check ensures that we respect the irreflexivity property of the stri ct weak ordering required by std::sort | 968 // This check ensures that we respect the irreflexivity property of the stri ct weak ordering required by std::sort |
| 939 // (forall x: NOT x < x). | 969 // (forall x: NOT x < x). |
| 940 if (track1->growthLimitIsInfinite() && track2->growthLimitIsInfinite()) | 970 if (track1->infiniteGrowthPotential() && track2->infiniteGrowthPotential()) |
| 941 return false; | 971 return false; |
| 942 | 972 |
| 943 if (track1->growthLimitIsInfinite() || track2->growthLimitIsInfinite()) | 973 if (track1->infiniteGrowthPotential() || track2->infiniteGrowthPotential()) |
| 944 return track2->growthLimitIsInfinite(); | 974 return track2->infiniteGrowthPotential(); |
| 945 | 975 |
| 946 return (track1->growthLimit() - track1->baseSize()) < (track2->growthLimit() - track2->baseSize()); | 976 return (track1->growthLimit() - track1->baseSize()) < (track2->growthLimit() - track2->baseSize()); |
| 947 } | 977 } |
| 948 | 978 |
| 949 template <TrackSizeComputationPhase phase> | 979 template <TrackSizeComputationPhase phase> |
| 950 void LayoutGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, const Vecto r<GridTrack*>* growBeyondGrowthLimitsTracks, GridSizingData& sizingData, LayoutU nit& availableLogicalSpace) | 980 void LayoutGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, const Vecto r<GridTrack*>* growBeyondGrowthLimitsTracks, GridSizingData& sizingData, LayoutU nit& availableLogicalSpace) |
| 951 { | 981 { |
| 952 ASSERT(availableLogicalSpace > 0); | 982 ASSERT(availableLogicalSpace >= 0); |
| 953 std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential); | |
| 954 | 983 |
| 955 size_t tracksSize = tracks.size(); | 984 for (auto* track : tracks) |
|
Manuel Rego
2015/06/26 11:09:48
A pitty that we need an extra loop here. :/
svillar
2015/06/29 07:08:27
Yes, but this is the best place to do it. Otherwis
| |
| 956 for (size_t i = 0; i < tracksSize; ++i) { | 985 track->setSizeDuringDistribution(trackSizeForTrackSizeComputationPhase(p hase, *track, ForbidInfinity)); |
| 957 GridTrack& track = *tracks[i]; | 986 |
| 958 LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tracksS ize - i); | 987 if (availableLogicalSpace > 0) { |
| 959 const LayoutUnit& trackBreadth = trackSizeForTrackSizeComputationPhase(p hase, track, ForbidInfinity); | 988 std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential); |
| 960 LayoutUnit growthShare = track.growthLimitIsInfinite() ? availableLogica lSpaceShare : std::min(availableLogicalSpaceShare, track.growthLimit() - trackBr eadth); | 989 |
| 961 ASSERT_WITH_MESSAGE(growthShare >= 0, "We must never shrink any grid tra ck or else we can't guarantee we abide by our min-sizing function."); | 990 size_t tracksSize = tracks.size(); |
| 962 track.m_increaseDuringDistribution = growthShare; | 991 for (size_t i = 0; i < tracksSize; ++i) { |
| 963 availableLogicalSpace -= growthShare; | 992 GridTrack& track = *tracks[i]; |
|
Manuel Rego
2015/06/26 11:09:48
Couldn't we use a range-based loop here as well?
svillar
2015/06/29 07:08:27
It was considered in previous patches, but note th
Manuel Rego
2015/06/29 07:46:42
Yes, I didn't realize about that.
| |
| 993 LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tra cksSize - i); | |
| 994 const LayoutUnit& trackBreadth = trackSizeForTrackSizeComputationPha se(phase, track, ForbidInfinity); | |
| 995 LayoutUnit growthShare = track.infiniteGrowthPotential() ? available LogicalSpaceShare : std::min(availableLogicalSpaceShare, track.growthLimit() - t rackBreadth); | |
| 996 ASSERT_WITH_MESSAGE(growthShare >= 0, "We must never shrink any grid track or else we can't guarantee we abide by our min-sizing function."); | |
| 997 track.growSizeDuringDistribution(growthShare); | |
| 998 availableLogicalSpace -= growthShare; | |
| 999 } | |
| 964 } | 1000 } |
| 965 | 1001 |
| 966 if (availableLogicalSpace > 0 && growBeyondGrowthLimitsTracks) { | 1002 if (availableLogicalSpace > 0 && growBeyondGrowthLimitsTracks) { |
| 967 size_t tracksGrowingAboveMaxBreadthSize = growBeyondGrowthLimitsTracks-> size(); | 1003 size_t tracksGrowingAboveMaxBreadthSize = growBeyondGrowthLimitsTracks-> size(); |
| 968 for (size_t i = 0; i < tracksGrowingAboveMaxBreadthSize; ++i) { | 1004 for (size_t i = 0; i < tracksGrowingAboveMaxBreadthSize; ++i) { |
| 969 GridTrack* track = growBeyondGrowthLimitsTracks->at(i); | 1005 GridTrack* track = growBeyondGrowthLimitsTracks->at(i); |
| 970 LayoutUnit growthShare = availableLogicalSpace / (tracksGrowingAbove MaxBreadthSize - i); | 1006 LayoutUnit growthShare = availableLogicalSpace / (tracksGrowingAbove MaxBreadthSize - i); |
| 971 track->m_increaseDuringDistribution += growthShare; | 1007 track->growSizeDuringDistribution(growthShare); |
| 972 availableLogicalSpace -= growthShare; | 1008 availableLogicalSpace -= growthShare; |
| 973 } | 1009 } |
| 974 } | 1010 } |
| 975 | 1011 |
| 976 for (auto* track : tracks) | 1012 for (auto* track : tracks) |
| 977 track->m_plannedIncrease = std::max(track->m_plannedIncrease, track->m_i ncreaseDuringDistribution); | 1013 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( ))); |
| 978 } | 1014 } |
| 979 | 1015 |
| 980 #if ENABLE(ASSERT) | 1016 #if ENABLE(ASSERT) |
| 981 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, const Vector<GridTrack>& tracks) | 1017 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, const Vector<GridTrack>& tracks) |
| 982 { | 1018 { |
| 983 for (size_t i = 0; i < tracks.size(); ++i) { | 1019 for (size_t i = 0; i < tracks.size(); ++i) { |
| 984 GridTrackSize trackSize = gridTrackSize(direction, i); | 1020 GridTrackSize trackSize = gridTrackSize(direction, i); |
| 985 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 1021 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
| 986 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i ].baseSize()) | 1022 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i ].baseSize()) |
| 987 return false; | 1023 return false; |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1855 | 1891 |
| 1856 return LayoutPoint(columnPosition, rowPositionForChild(child)); | 1892 return LayoutPoint(columnPosition, rowPositionForChild(child)); |
| 1857 } | 1893 } |
| 1858 | 1894 |
| 1859 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) | 1895 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) |
| 1860 { | 1896 { |
| 1861 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 1897 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 1862 } | 1898 } |
| 1863 | 1899 |
| 1864 } // namespace blink | 1900 } // namespace blink |
| OLD | NEW |