Title: [269509] trunk/Source/WebCore
Revision
269509
Author
[email protected]
Date
2020-11-06 06:09:47 -0800 (Fri, 06 Nov 2020)

Log Message

[css-grid] Prevent FindUsedFlexFraction from iterating items twice
https://bugs.webkit.org/show_bug.cgi?id=218630

Reviewed by Javier Fernandez.

IndefiniteSizeStrategy::findUsedFlexFraction needs to iterate all grid
items that cross a flexible track. To do so it, takes the indices of the
flex tracks, and for each one it uses GridIterator to iterate the items
in that track.

Then, to avoid processing the same item multiple times, it used to check
that the item started in the current flex track, not in a previous one.

However, this was insufficient: it wasn't taking into account that an
item can be in a single flex track, but span multiple tracks in the
other axis.

Therefore, this patch changes it to use the same approach as in
GridTrackSizingAlgorithm::resolveIntrinsicTrackSizes, i.e. creates a
HashSet outside of the loop, and inserts each given grid item to it,
checking whether it's a new entry or not.

This is a port of https://crrev.com/821910 from Chromium.

* rendering/GridTrackSizingAlgorithm.cpp:
(WebCore::IndefiniteSizeStrategy::findUsedFlexFraction const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (269508 => 269509)


--- trunk/Source/WebCore/ChangeLog	2020-11-06 13:47:04 UTC (rev 269508)
+++ trunk/Source/WebCore/ChangeLog	2020-11-06 14:09:47 UTC (rev 269509)
@@ -1,3 +1,32 @@
+2020-11-06  Oriol Brufau  <[email protected]>
+
+        [css-grid] Prevent FindUsedFlexFraction from iterating items twice
+        https://bugs.webkit.org/show_bug.cgi?id=218630
+
+        Reviewed by Javier Fernandez.
+
+        IndefiniteSizeStrategy::findUsedFlexFraction needs to iterate all grid
+        items that cross a flexible track. To do so it, takes the indices of the
+        flex tracks, and for each one it uses GridIterator to iterate the items
+        in that track.
+
+        Then, to avoid processing the same item multiple times, it used to check
+        that the item started in the current flex track, not in a previous one.
+
+        However, this was insufficient: it wasn't taking into account that an
+        item can be in a single flex track, but span multiple tracks in the
+        other axis.
+
+        Therefore, this patch changes it to use the same approach as in
+        GridTrackSizingAlgorithm::resolveIntrinsicTrackSizes, i.e. creates a
+        HashSet outside of the loop, and inserts each given grid item to it,
+        checking whether it's a new entry or not.
+
+        This is a port of https://crrev.com/821910 from Chromium.
+
+        * rendering/GridTrackSizingAlgorithm.cpp:
+        (WebCore::IndefiniteSizeStrategy::findUsedFlexFraction const):
+
 2020-11-06  Chris Lord  <[email protected]>
 
         REGRESSION(r269503): [GTK][WPE] >200 tests are failing

Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (269508 => 269509)


--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp	2020-11-06 13:47:04 UTC (rev 269508)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp	2020-11-06 14:09:47 UTC (rev 269509)
@@ -972,15 +972,16 @@
     if (!grid.hasGridItems())
         return flexFraction;
 
-    for (unsigned i = 0; i < flexibleSizedTracksIndex.size(); ++i) {
-        GridIterator iterator(grid, direction, flexibleSizedTracksIndex[i]);
+    HashSet<RenderBox*> itemsSet;
+    for (const auto& trackIndex : flexibleSizedTracksIndex) {
+        GridIterator iterator(grid, direction, trackIndex);
         while (auto* gridItem = iterator.nextGridItem()) {
-            const GridSpan& span = grid.gridItemSpan(*gridItem, direction);
-
             // Do not include already processed items.
-            if (i > 0 && span.startLine() <= flexibleSizedTracksIndex[i - 1])
+            if (!itemsSet.add(gridItem).isNewEntry)
                 continue;
 
+            const GridSpan& span = grid.gridItemSpan(*gridItem, direction);
+
             // Removing gutters from the max-content contribution of the item, so they are not taken into account in FindFrUnitSize().
             LayoutUnit leftOverSpace = maxContentForChild(*gridItem) - renderGrid()->guttersSize(m_algorithm.grid(), direction, span.startLine(), span.integerSpan(), availableSpace());
             flexFraction = std::max(flexFraction, findFrUnitSize(span, leftOverSpace));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to