Title: [294755] trunk/Source/WebCore
Revision
294755
Author
za...@apple.com
Date
2022-05-24 12:12:38 -0700 (Tue, 24 May 2022)

Log Message

Start using min/max content size for flexing
https://bugs.webkit.org/show_bug.cgi?id=240872

Reviewed by Antti Koivisto.

* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::FlexLayout::updateFormattingRootGeometryAndInvalidate):
(WebCore::LayoutIntegration::FlexLayout::updateFlexItemDimensions):
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h:
* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutUsingFlexFormattingContext):

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

Modified Paths

Diff

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


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-24 18:48:31 UTC (rev 294754)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-24 19:12:38 UTC (rev 294755)
@@ -206,6 +206,7 @@
 
 void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsForInFlowContent& constraints)
 {
+    auto& formattingState = this->formattingState();
     auto logicalFlexItemList = convertFlexItemsToLogicalSpace();
 
     auto totalGrowth = 0.f;
@@ -213,8 +214,7 @@
 
     for (auto& logicalFlexItem : logicalFlexItemList) {
         totalGrowth += logicalFlexItem.layoutBox->style().flexGrow();
-        // FIXME: Use min/max here.
-        totalFixedSpace += logicalFlexItem.rect.width();
+        totalFixedSpace += formattingState.intrinsicWidthConstraintsForBox(*logicalFlexItem.layoutBox)->minimum;
     }
 
     auto flexConstraints = downcast<ConstraintsForFlexContent>(constraints);
@@ -237,7 +237,8 @@
             // 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.
             ASSERT(availableSpace.has_value());
-            logicalFlexItem.rect.setWidth(LayoutUnit { *availableSpace * grow / totalGrowth });
+            // FIXME: This is still slighly incorrect.
+            logicalFlexItem.rect.setWidth(LayoutUnit { formattingState.intrinsicWidthConstraintsForBox(*logicalFlexItem.layoutBox)->minimum + (flexibleSpace * grow / totalGrowth) });
             // FIXME: constrain logical width on min width.
         };
         growFlexItemIfApplicable();

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


--- trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp	2022-05-24 18:48:31 UTC (rev 294754)
+++ trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp	2022-05-24 19:12:38 UTC (rev 294755)
@@ -34,6 +34,7 @@
 #include "HitTestRequest.h"
 #include "HitTestResult.h"
 #include "LayoutBoxGeometry.h"
+#include "LayoutChildIterator.h"
 #include "RenderFlexibleBox.h"
 
 namespace WebCore {
@@ -75,9 +76,9 @@
 
 void FlexLayout::updateFormattingRootGeometryAndInvalidate()
 {
-    auto& flexBoxRenderer = this->flexBoxRenderer();
+    auto updateGeometry = [&](auto& root) {
+        auto& flexBoxRenderer = this->flexBoxRenderer();
 
-    auto updateGeometry = [&](auto& root) {
         auto isLeftToRightInlineDirection = flexBoxRenderer.style().isLeftToRightDirection();
         auto writingMode = flexBoxRenderer.style().writingMode();
 
@@ -87,12 +88,16 @@
         root.setHorizontalMargin({ });
         root.setVerticalMargin({ });
     };
-    return updateGeometry(m_layoutState.ensureGeometryForBox(rootLayoutBox()));
+    updateGeometry(m_layoutState.ensureGeometryForBox(rootLayoutBox()));
+
+    for (auto& flexItem : Layout::childrenOfType<Layout::Box>(rootLayoutBox()))
+        m_flexFormattingState.clearIntrinsicWidthConstraints(flexItem);
 }
 
-void FlexLayout::updateFlexItemDimensions(const RenderBlock& flexItem)
+void FlexLayout::updateFlexItemDimensions(const RenderBlock& flexItem, LayoutUnit minimumContentSize, LayoutUnit maximumContentSize)
 {
-    auto& boxGeometry = m_layoutState.ensureGeometryForBox(m_boxTree.layoutBoxForRenderer(flexItem));
+    auto& layoutBox = m_boxTree.layoutBoxForRenderer(flexItem);
+    auto& boxGeometry = m_layoutState.ensureGeometryForBox(layoutBox);
 
     boxGeometry.setContentBoxWidth(flexItem.contentWidth());
     boxGeometry.setContentBoxHeight(flexItem.contentHeight());
@@ -100,6 +105,9 @@
     boxGeometry.setHorizontalMargin({ flexItem.marginLeft(), flexItem.marginRight() });
     boxGeometry.setBorder({ { flexItem.borderLeft(), flexItem.borderRight() }, { flexItem.borderTop(), flexItem.borderBottom() } });
     boxGeometry.setPadding(Layout::Edges { { flexItem.paddingLeft(), flexItem.paddingRight() }, { flexItem.paddingTop(), flexItem.paddingBottom() } });
+
+    // FIXME: We may need to differentiate preferred and min/max content size.
+    m_flexFormattingState.setIntrinsicWidthConstraintsForBox(layoutBox, { minimumContentSize, maximumContentSize });
 }
 
 void FlexLayout::updateStyle(const RenderBlock&, const RenderStyle&)

Modified: trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h (294754 => 294755)


--- trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h	2022-05-24 18:48:31 UTC (rev 294754)
+++ trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h	2022-05-24 19:12:38 UTC (rev 294755)
@@ -51,7 +51,7 @@
     FlexLayout(RenderFlexibleBox&);
 
     void updateFormattingRootGeometryAndInvalidate();
-    void updateFlexItemDimensions(const RenderBlock&);
+    void updateFlexItemDimensions(const RenderBlock& flexItem, LayoutUnit minimumContentSize, LayoutUnit maximumContentSize);
     void updateStyle(const RenderBlock&, const RenderStyle& oldStyle);
 
     std::pair<LayoutUnit, LayoutUnit> computeIntrinsicWidthConstraints();

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (294754 => 294755)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2022-05-24 18:48:31 UTC (rev 294754)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2022-05-24 19:12:38 UTC (rev 294755)
@@ -2356,7 +2356,8 @@
 
     for (auto& flexItem : childrenOfType<RenderBlock>(*this)) {
         flexItem.layoutIfNeeded();
-        m_flexLayout->updateFlexItemDimensions(flexItem);
+        auto minMaxContentSize = computeFlexItemMinMaxSizes(flexItem);
+        m_flexLayout->updateFlexItemDimensions(flexItem, minMaxContentSize.first, minMaxContentSize.second);
     }
     m_flexLayout->layout();
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to