Title: [294983] trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp
Revision
294983
Author
za...@apple.com
Date
2022-05-27 21:10:06 -0700 (Fri, 27 May 2022)

Log Message

Introduce base-size to the flex algorithm
https://bugs.webkit.org/show_bug.cgi?id=241001

Reviewed by Antti Koivisto.

This is in preparation for supporting flex-basis, where the flex-basis value is used as the base for flexing.

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

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

Modified Paths

Diff

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


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-28 04:05:00 UTC (rev 294982)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-28 04:10:06 UTC (rev 294983)
@@ -217,13 +217,14 @@
         // Collect flex items with non-zero flex-shrink value. flex-shrink: 0 flex items
         // don't participate in content flexing.
         for (size_t index = 0; index < logicalFlexItemList.size(); ++index) {
-            auto& logicalFlexItem = logicalFlexItemList[index];
-            if (auto flexShrink = logicalFlexItem.layoutBox->style().flexShrink()) {
+            auto& flexItem = logicalFlexItemList[index];
+            auto baseSize = flexItem.rect.width();
+            if (auto flexShrink = flexItem.layoutBox->style().flexShrink()) {
                 shrinkingItems.append(index);
-                totalShrink += flexShrink;
-                totalFlexibleSpace += logicalFlexItem.rect.width();
+                totalShrink += flexShrink * baseSize;
+                totalFlexibleSpace += baseSize;
             } else
-                availableSpace -= logicalFlexItem.rect.width();
+                availableSpace -= baseSize;
         }
         if (totalShrink)
             flexShrinkBase = (totalFlexibleSpace - availableSpace) / totalShrink;
@@ -236,12 +237,13 @@
         for (auto flexItemIndex : shrinkingItems) {
             auto& flexItem = logicalFlexItemList[flexItemIndex];
 
-            auto flexShrink = flexItem.layoutBox->style().flexShrink();
-            auto flexedSize = flexItem.rect.width() - (flexShrink * flexShrinkBase);
+            auto baseSize = flexItem.rect.width();
+            auto flexShrink = flexItem.layoutBox->style().flexShrink() * baseSize;
+            auto flexedSize = baseSize - (flexShrink * flexShrinkBase);
             auto minimumSize = formattingState.intrinsicWidthConstraintsForBox(*flexItem.layoutBox)->minimum;
             if (minimumSize >= flexedSize) {
                 totalShrink -= flexShrink;
-                totalFlexibleSpace -= flexItem.rect.width();
+                totalFlexibleSpace -= baseSize;
                 availableSpace -= minimumSize;
             }
         }
@@ -254,8 +256,9 @@
         for (auto flexItemIndex : shrinkingItems) {
             auto& flexItem = logicalFlexItemList[flexItemIndex];
 
-            auto flexShrink = flexItem.layoutBox->style().flexShrink();
-            auto flexedSize = LayoutUnit { flexItem.rect.width() - (flexShrink * flexShrinkBase) };
+            auto baseSize = flexItem.rect.width();
+            auto flexShrink = flexItem.layoutBox->style().flexShrink() * baseSize;
+            auto flexedSize = LayoutUnit { baseSize - (flexShrink * flexShrinkBase) };
             auto minimumSize = formattingState.intrinsicWidthConstraintsForBox(*flexItem.layoutBox)->minimum;
             flexItem.rect.setWidth(std::max(minimumSize, flexedSize));
         }
@@ -340,13 +343,13 @@
         for (auto& logicalFlexItem : logicalFlexItemList)
             logicalWidth += logicalFlexItem.rect.width();
         return logicalWidth;
-    };
+    }();
 
     if (!availableSpace)
         ASSERT_NOT_IMPLEMENTED_YET();
-    else if (*availableSpace > contentLogicalWidth())
+    else if (*availableSpace > contentLogicalWidth)
         computeLogicalWidthForStretchingFlexItems(logicalFlexItemList, *availableSpace);
-    else
+    else if (*availableSpace < contentLogicalWidth)
         computeLogicalWidthForShrinkingFlexItems(logicalFlexItemList, *availableSpace);
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to