Title: [294995] trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp
Revision
294995
Author
za...@apple.com
Date
2022-05-28 06:06:19 -0700 (Sat, 28 May 2022)

Log Message

Introduce the concept of frozen flex items
https://bugs.webkit.org/show_bug.cgi?id=241034

Reviewed by Antti Koivisto.

When a shrinking flex item gets too small, we exclude it from the shrinking algorithm and recompute the shrink factor. However the new shrink factor could make additional flex items too small.

* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::computeLogicalWidthForShrinkingFlexItems):

Canonical link: https://commits.webkit.org/251095@main

Modified Paths

Diff

Modified: trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp (294994 => 294995)


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-28 12:43:31 UTC (rev 294994)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-28 13:06:19 UTC (rev 294995)
@@ -217,6 +217,7 @@
         LayoutUnit minimumSize;
         LayoutUnit flexBasis;
         LogicalFlexItem& flexItem;
+        bool isFrozen { false };
     };
     Vector<ShrinkingFlexItem> shrinkingItems;
 
@@ -228,7 +229,7 @@
             auto baseSize = flexItem.rect.width();
             if (auto shrinkValue = flexItem.layoutBox->style().flexShrink()) {
                 auto flexShrink = shrinkValue * baseSize;
-                shrinkingItems.append({ flexShrink, formattingState.intrinsicWidthConstraintsForBox(*flexItem.layoutBox)->minimum, baseSize, flexItem });
+                shrinkingItems.append({ flexShrink, formattingState.intrinsicWidthConstraintsForBox(*flexItem.layoutBox)->minimum, baseSize, flexItem, { } });
                 totalShrink += flexShrink;
                 totalFlexibleSpace += baseSize;
             } else
@@ -242,15 +243,22 @@
     auto adjustShrinkBase = [&] {
         // Now that we know how much each flex item needs to be shrunk, let's check
         // if they hit their minimum content width (i.e. whether they can be sized that small).
-        for (auto& shirinkingFlex : shrinkingItems) {
-            auto flexedSize = shirinkingFlex.flexBasis - (shirinkingFlex.flexShrink * flexShrinkBase);
-            if (shirinkingFlex.minimumSize > flexedSize) {
-                totalShrink -= shirinkingFlex.flexShrink;
-                totalFlexibleSpace -= shirinkingFlex.flexBasis;
-                availableSpace -= shirinkingFlex.minimumSize;
+        while (true) {
+            auto didFreeze = false;
+            for (auto& shirinkingFlex : shrinkingItems) {
+                auto flexedSize = shirinkingFlex.flexBasis - (shirinkingFlex.flexShrink * flexShrinkBase);
+                if (!shirinkingFlex.isFrozen && shirinkingFlex.minimumSize > flexedSize) {
+                    shirinkingFlex.isFrozen = true;
+                    didFreeze = true;
+                    totalShrink -= shirinkingFlex.flexShrink;
+                    totalFlexibleSpace -= shirinkingFlex.flexBasis;
+                    availableSpace -= shirinkingFlex.minimumSize;
+                }
             }
+            if (!didFreeze)
+                break;
+            flexShrinkBase = totalShrink ? (totalFlexibleSpace - availableSpace) / totalShrink : 0.f;
         }
-        flexShrinkBase = totalShrink ? (totalFlexibleSpace - availableSpace) / totalShrink : 0.f;
     };
     adjustShrinkBase();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to