Title: [294463] trunk/Source/WebCore/layout
Revision
294463
Author
za...@apple.com
Date
2022-05-18 20:05:09 -0700 (Wed, 18 May 2022)

Log Message

Add support for simple 'flex-grow'
https://bugs.webkit.org/show_bug.cgi?id=240561

Reviewed by Antti Koivisto.

This is a basic "flex grow" implementation ignoring min/max values.

* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::setFlexItemsGeometry):
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::FlexLayout::updateRenderers const):

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

Modified Paths

Diff

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


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-19 02:29:12 UTC (rev 294462)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-19 03:05:09 UTC (rev 294463)
@@ -197,6 +197,10 @@
             break;
         }
         flexItemGeometry.setLogicalTopLeft(topLeft);
+        if (direction == FlexDirection::Row || direction == FlexDirection::RowReverse)
+            flexItemGeometry.setContentBoxWidth(logicalFlexItem.rect.width() - flexItemGeometry.horizontalMarginBorderAndPadding());
+        else
+            flexItemGeometry.setContentBoxHeight(logicalFlexItem.rect.width() - flexItemGeometry.verticalMarginBorderAndPadding());
     }
 }
 
@@ -204,12 +208,35 @@
 {
     auto logicalFlexItemList = convertFlexItemsToLogicalSpace();
 
+    auto totalGrowth = 0.f;
+    auto totalFixedWidth = LayoutUnit { };
+
+    for (auto& logicalFlexItem : logicalFlexItemList) {
+        totalGrowth += logicalFlexItem.layoutBox->style().flexGrow();
+        // FIXME: Use min/max here.
+        totalFixedWidth += logicalFlexItem.rect.width();
+    }
+
     auto logicalLeft = LayoutUnit { };
     auto logicalTop = LayoutUnit { };
+    auto availableWidth = constraints.horizontal().logicalWidth;
+    auto flexibleWidth = availableWidth - totalFixedWidth;
 
     for (auto& logicalFlexItem : logicalFlexItemList) {
         logicalFlexItem.rect.setTopLeft({ logicalLeft, logicalTop });
         logicalLeft = logicalFlexItem.rect.right();
+        auto growFlexItemIfApplicable = [&] {
+            if (flexibleWidth <= 0)
+                return;
+            auto grow = logicalFlexItem.layoutBox->style().flexGrow();
+            if (!grow)
+                return;
+            // This value specifies the flex grow factor, which determines how much the flex item will grow relative to the
+            // rest of the flex items in the flex container when positive free space is distributed.
+            logicalFlexItem.rect.setWidth(LayoutUnit { availableWidth * grow / totalGrowth });
+            // FIXME: constrain logical width on min width.
+        };
+        growFlexItemIfApplicable();
     }
     setFlexItemsGeometry(logicalFlexItemList, constraints);
 }

Modified: trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp (294462 => 294463)


--- trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp	2022-05-19 02:29:12 UTC (rev 294462)
+++ trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp	2022-05-19 03:05:09 UTC (rev 294463)
@@ -131,7 +131,10 @@
         auto& layoutBox = boxAndRenderer.box.get();
 
         auto& renderer = downcast<RenderBox>(*boxAndRenderer.renderer);
-        renderer.setLocation(Layout::BoxGeometry::borderBoxTopLeft(m_flexFormattingState.boxGeometry(layoutBox)));
+        auto& flexItemGeometry = m_flexFormattingState.boxGeometry(layoutBox);
+        auto borderBox = Layout::BoxGeometry::borderBoxRect(flexItemGeometry);
+        renderer.setLocation(borderBox.topLeft());
+        renderer.setWidth(borderBox.width());
     }
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to