Title: [141163] trunk/Source/WebCore
Revision
141163
Author
jchaffr...@webkit.org
Date
2013-01-29 14:11:15 -0800 (Tue, 29 Jan 2013)

Log Message

[CSS Grid Layout] Make resolveContentBasedTrackSizingFunctionsForItems reuse distributeSpaceToTracks
https://bugs.webkit.org/show_bug.cgi?id=108110

Reviewed by Tony Chang.

This change makes us match more closely the specification by reusing distributeSpaceToTracks inside
resolveContentBasedTrackSizingFunctionsForItems. This also removes some existing code duplication.

Refactoring covered by existing tests.

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::computedUsedBreadthOfGridTracks):
Updated after distributeSpaceToTracks new arguments. Copying the tracks to a Vector<GridTrack*> is
now done here.

(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForItems):
Removed code duplication and switched to using distributeSpaceToTracks.

(WebCore::RenderGrid::distributeSpaceToTracks):
Refactored distributeSpaceToTracks to implement the distribution of any extra space above max breadth
as it was required to pass the tests (required to properly handling min-content > max). Also changed
the arguments of the function to better match the intent of the function.

* rendering/RenderGrid.h: Updated distributeSpaceToTracks's arguments.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (141162 => 141163)


--- trunk/Source/WebCore/ChangeLog	2013-01-29 21:51:25 UTC (rev 141162)
+++ trunk/Source/WebCore/ChangeLog	2013-01-29 22:11:15 UTC (rev 141163)
@@ -1,3 +1,30 @@
+2013-01-29  Julien Chaffraix  <jchaffr...@webkit.org>
+
+        [CSS Grid Layout] Make resolveContentBasedTrackSizingFunctionsForItems reuse distributeSpaceToTracks
+        https://bugs.webkit.org/show_bug.cgi?id=108110
+
+        Reviewed by Tony Chang.
+
+        This change makes us match more closely the specification by reusing distributeSpaceToTracks inside
+        resolveContentBasedTrackSizingFunctionsForItems. This also removes some existing code duplication.
+
+        Refactoring covered by existing tests.
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::computedUsedBreadthOfGridTracks):
+        Updated after distributeSpaceToTracks new arguments. Copying the tracks to a Vector<GridTrack*> is
+        now done here.
+
+        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForItems):
+        Removed code duplication and switched to using distributeSpaceToTracks.
+
+        (WebCore::RenderGrid::distributeSpaceToTracks):
+        Refactored distributeSpaceToTracks to implement the distribution of any extra space above max breadth
+        as it was required to pass the tests (required to properly handling min-content > max). Also changed
+        the arguments of the function to better match the intent of the function.
+
+        * rendering/RenderGrid.h: Updated distributeSpaceToTracks's arguments.
+
 2013-01-29  Elliott Sprehn  <espr...@chromium.org>
 
         Remove all ShadowRoots during ElementShadow destruction

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (141162 => 141163)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2013-01-29 21:51:25 UTC (rev 141162)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2013-01-29 22:11:15 UTC (rev 141163)
@@ -196,7 +196,12 @@
     if (availableLogicalSpace <= 0)
         return;
 
-    distributeSpaceToTracks(direction, tracks, availableLogicalSpace);
+    const size_t tracksSize = tracks.size();
+    Vector<GridTrack*> tracksForDistribution(tracksSize);
+    for (size_t i = 0; i < tracksSize; ++i)
+        tracksForDistribution[i] = tracks.data() + i;
+
+    distributeSpaceToTracks(tracksForDistribution, 0, &GridTrack::usedBreadth, &GridTrack::growUsedBreadth, availableLogicalSpace);
 }
 
 LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(TrackSizingDirection direction, const Length& trackLength) const
@@ -310,7 +315,6 @@
 
 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(TrackSizingDirection direction, Vector<GridTrack>& columnTracks, Vector<GridTrack>& rowTracks, size_t i, SizingFunction sizingFunction, AccumulatorGetter trackGetter, AccumulatorGrowFunction trackGrowthFunction)
 {
-    // FIXME: The specification re-uses distributeSpaceToTrack, which we should probably do.
     GridTrack& track = (direction == ForColumns) ? columnTracks[i] : rowTracks[i];
     for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
         size_t cellIndex = resolveGridPosition(direction, child);
@@ -319,33 +323,42 @@
 
         LayoutUnit contentSize = (this->*sizingFunction)(child, direction, columnTracks);
         LayoutUnit additionalBreadthSpace = contentSize - (track.*trackGetter)();
-        LayoutUnit share = additionalBreadthSpace;
-        std::min(additionalBreadthSpace, track.m_maxBreadth - (track.*trackGetter)());
-        (track.*trackGrowthFunction)(share);
+        Vector<GridTrack*> tracks;
+        tracks.append(&track);
+        // FIXME: We should pass different values for |tracksForGrowthAboveMaxBreadth|.
+        distributeSpaceToTracks(tracks, &tracks, trackGetter, trackGrowthFunction, additionalBreadthSpace);
     }
 }
 
-void RenderGrid::distributeSpaceToTracks(TrackSizingDirection, Vector<GridTrack>& tracks, LayoutUnit availableLogicalSpace)
+void RenderGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, Vector<GridTrack*>* tracksForGrowthAboveMaxBreadth, AccumulatorGetter trackGetter, AccumulatorGrowFunction trackGrowthFunction, LayoutUnit& availableLogicalSpace)
 {
-    const size_t tracksSize = tracks.size();
-    Vector<GridTrack*> sortedTracks(tracksSize);
-    for (size_t i = 0; i < tracksSize; ++i)
-        sortedTracks[i] = tracks.data() + i;
+    std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential);
 
-    std::sort(sortedTracks.begin(), sortedTracks.end(), sortByGridTrackGrowthPotential);
-
+    size_t tracksSize = tracks.size();
     for (size_t i = 0; i < tracksSize; ++i) {
-        GridTrack& track = *sortedTracks[i];
+        GridTrack& track = *tracks[i];
         LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tracksSize - i);
         // We never shrink the used breadth by clamping the difference between max and used breadth. The spec uses
-        // 2 extra-variables and 2 extra iterations over the tracks to achieve that (because distributeSpaceToTracks
-        // is shared with other methods). If we start sharing the method, we should probably remove this clamping.
-        LayoutUnit growthShare = std::min(availableLogicalSpaceShare, std::max(LayoutUnit(0), track.m_maxBreadth - track.m_usedBreadth));
-        track.m_usedBreadth += growthShare;
+        // 2 extra-variables and 2 extra iterations to ensure that we always grow our tracks (thus never going below
+        // min-track). If we decide to follow it to the letter, we should remove this clamping.
+        LayoutUnit growthShare = std::min(availableLogicalSpaceShare, std::max(LayoutUnit(0), track.m_maxBreadth - (track.*trackGetter)()));
+        (track.*trackGrowthFunction)(growthShare);
         availableLogicalSpace -= growthShare;
     }
 
-    // FIXME: We don't implement the last 2 steps of the algorithm as we don't implement content based sizing.
+    if (availableLogicalSpace <= 0)
+        return;
+
+    if (!tracksForGrowthAboveMaxBreadth)
+        return;
+
+    tracksSize = tracksForGrowthAboveMaxBreadth->size();
+    for (size_t i = 0; i < tracksSize; ++i) {
+        GridTrack& track = *tracksForGrowthAboveMaxBreadth->at(i);
+        LayoutUnit growthShare = availableLogicalSpace / (tracksSize - i);
+        (track.*trackGrowthFunction)(growthShare);
+        availableLogicalSpace -= growthShare;
+    }
 }
 
 #ifndef NDEBUG

Modified: trunk/Source/WebCore/rendering/RenderGrid.h (141162 => 141163)


--- trunk/Source/WebCore/rendering/RenderGrid.h	2013-01-29 21:51:25 UTC (rev 141162)
+++ trunk/Source/WebCore/rendering/RenderGrid.h	2013-01-29 22:11:15 UTC (rev 141163)
@@ -54,13 +54,13 @@
     LayoutUnit computeUsedBreadthOfMaxLength(TrackSizingDirection, const Length&) const;
     LayoutUnit computeUsedBreadthOfSpecifiedLength(TrackSizingDirection, const Length&) const;
     void resolveContentBasedTrackSizingFunctions(TrackSizingDirection, Vector<GridTrack>& columnTracks, Vector<GridTrack>& rowTracks, LayoutUnit& availableLogicalSpace);
-    void distributeSpaceToTracks(TrackSizingDirection, Vector<GridTrack>&, LayoutUnit availableLogicalSpace);
     void layoutGridItems();
 
     typedef LayoutUnit (RenderGrid::* SizingFunction)(RenderBox*, TrackSizingDirection, Vector<GridTrack>&);
     typedef LayoutUnit (GridTrack::* AccumulatorGetter)() const;
     typedef void (GridTrack::* AccumulatorGrowFunction)(LayoutUnit);
     void resolveContentBasedTrackSizingFunctionsForItems(TrackSizingDirection, Vector<GridTrack>& columnTracks, Vector<GridTrack>& rowTracks, size_t, SizingFunction, AccumulatorGetter, AccumulatorGrowFunction);
+    void distributeSpaceToTracks(Vector<GridTrack*>&, Vector<GridTrack*>* tracksForGrowthAboveMaxBreadth, AccumulatorGetter, AccumulatorGrowFunction, LayoutUnit& availableLogicalSpace);
 
     LayoutUnit minContentForChild(RenderBox*, TrackSizingDirection, Vector<GridTrack>& columnTracks);
     LayoutUnit maxContentForChild(RenderBox*, TrackSizingDirection, Vector<GridTrack>& columnTracks);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to