Title: [295208] trunk/Source/WebCore/layout
Revision
295208
Author
za...@apple.com
Date
2022-06-03 08:03:54 -0700 (Fri, 03 Jun 2022)

Log Message

FlexLayout should not use non-logical intrinsic widths
https://bugs.webkit.org/show_bug.cgi?id=241256

Reviewed by Antti Koivisto.

This is in preparation for using logical-intrinsic widths in flex layout.

* Source/WebCore/layout/FormattingState.h:
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::convertFlexItemsToLogicalSpace):
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
* Source/WebCore/layout/formattingContexts/flex/FlexLayout.cpp:
(WebCore::Layout::FlexLayout::FlexLayout):
(WebCore::Layout::FlexLayout::computeLogicalWidthForShrinkingFlexItems):
(WebCore::Layout::FlexLayout::computeLogicalWidthForStretchingFlexItems):
* Source/WebCore/layout/formattingContexts/flex/FlexLayout.h:
(WebCore::Layout::FlexLayout::LogicalFlexItem::minimumContentWidth const):
(WebCore::Layout::FlexLayout::LogicalFlexItem::LogicalFlexItem):
(WebCore::Layout::FlexLayout::formattingState const): Deleted.

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/layout/FormattingState.h (295207 => 295208)


--- trunk/Source/WebCore/layout/FormattingState.h	2022-06-03 14:41:53 UTC (rev 295207)
+++ trunk/Source/WebCore/layout/FormattingState.h	2022-06-03 15:03:54 UTC (rev 295208)
@@ -47,7 +47,7 @@
     void markNeedsLayout(const Box&, StyleDiff);
     bool needsLayout(const Box&);
 
-    void setIntrinsicWidthConstraintsForBox(const Box&,  IntrinsicWidthConstraints);
+    void setIntrinsicWidthConstraintsForBox(const Box&, IntrinsicWidthConstraints);
     std::optional<IntrinsicWidthConstraints> intrinsicWidthConstraintsForBox(const Box&) const;
     void clearIntrinsicWidthConstraints(const Box&);
 

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


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-06-03 14:41:53 UTC (rev 295207)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-06-03 15:03:54 UTC (rev 295208)
@@ -225,7 +225,12 @@
         auto& style = layoutBox.style();
         auto logicalWidthType = flexDirectionIsInlineAxis ? style.width().type() : style.height().type();
         auto logicalHeightType = flexDirectionIsInlineAxis ? style.height().type() : style.width().type();
-        logicalFlexItemList[index] = { flexItemList[index].marginRect, logicalWidthType, logicalHeightType, layoutBox };
+        logicalFlexItemList[index] = { flexItemList[index].marginRect
+            , logicalWidthType
+            , logicalHeightType
+            // FIXME: Convert to logical intrinsic width
+            , *formattingState.intrinsicWidthConstraintsForBox(layoutBox)
+            , layoutBox };
     }
     return logicalFlexItemList;
 }
@@ -285,7 +290,7 @@
 {
     auto flexConstraints = downcast<ConstraintsForFlexContent>(constraints);
     auto logicalFlexItems = convertFlexItemsToLogicalSpace(flexConstraints);
-    auto flexLayout = FlexLayout { formattingState(), root().style() };
+    auto flexLayout = FlexLayout { root().style() };
     flexLayout.layout(flexConstraints, logicalFlexItems);
     setFlexItemsGeometry(logicalFlexItems, flexConstraints);
 }

Modified: trunk/Source/WebCore/layout/formattingContexts/flex/FlexLayout.cpp (295207 => 295208)


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexLayout.cpp	2022-06-03 14:41:53 UTC (rev 295207)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexLayout.cpp	2022-06-03 15:03:54 UTC (rev 295208)
@@ -34,9 +34,8 @@
 namespace WebCore {
 namespace Layout {
 
-FlexLayout::FlexLayout(const FlexFormattingState& formattingState, const RenderStyle& flexBoxStyle)
-    : m_formattingState(formattingState)
-    , m_flexBoxStyle(flexBoxStyle)
+FlexLayout::FlexLayout(const RenderStyle& flexBoxStyle)
+    : m_flexBoxStyle(flexBoxStyle)
 {
 }
 
@@ -80,8 +79,6 @@
 
 void FlexLayout::computeLogicalWidthForShrinkingFlexItems(LogicalFlexItems& flexItems, LayoutUnit availableSpace)
 {
-    auto& formattingState = this->formattingState();
-
     auto totalShrink = 0.f;
     auto totalFlexibleSpace = LayoutUnit { };
     auto flexShrinkBase = 0.f;
@@ -103,7 +100,7 @@
             auto baseSize = style.flexBasis().isFixed() ? LayoutUnit { style.flexBasis().value() } : flexItem.width();
             if (auto shrinkValue = style.flexShrink()) {
                 auto flexShrink = shrinkValue * baseSize;
-                shrinkingItems.append({ flexShrink, formattingState.intrinsicWidthConstraintsForBox(flexItem.layoutBox())->minimum, baseSize, flexItem, { } });
+                shrinkingItems.append({ flexShrink, flexItem.minimumContentWidth(), baseSize, flexItem, { } });
                 totalShrink += flexShrink;
                 totalFlexibleSpace += baseSize;
             } else
@@ -148,8 +145,6 @@
 
 void FlexLayout::computeLogicalWidthForStretchingFlexItems(LogicalFlexItems& flexItems, LayoutUnit availableSpace)
 {
-    auto& formattingState = this->formattingState();
-
     auto totalFlexibleSpace = LayoutUnit { };
     auto totalGrowth = 0.f;
     auto flexGrowBase = 0.f;
@@ -170,7 +165,7 @@
             auto baseSize = style.flexBasis().isFixed() ? LayoutUnit { style.flexBasis().value() } : flexItem.width();
             if (auto growValue = style.flexGrow()) {
                 auto flexGrow = growValue * baseSize;
-                stretchingItems.append({ flexGrow, formattingState.intrinsicWidthConstraintsForBox(flexItem.layoutBox())->minimum, baseSize, flexItem, { } });
+                stretchingItems.append({ flexGrow, flexItem.minimumContentWidth(), baseSize, flexItem, { } });
                 totalGrowth += flexGrow;
                 totalFlexibleSpace += baseSize;
             } else

Modified: trunk/Source/WebCore/layout/formattingContexts/flex/FlexLayout.h (295207 => 295208)


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexLayout.h	2022-06-03 14:41:53 UTC (rev 295207)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexLayout.h	2022-06-03 15:03:54 UTC (rev 295208)
@@ -38,11 +38,11 @@
 // https://www.w3.org/TR/css-flexbox-1/
 class FlexLayout {
 public:
-    FlexLayout(const FlexFormattingState&, const RenderStyle& flexBoxStyle);
+    FlexLayout(const RenderStyle& flexBoxStyle);
 
     struct LogicalFlexItem {
     public:
-        LogicalFlexItem(const FlexRect&, LengthType widthType, LengthType heightType, const ContainerBox&);
+        LogicalFlexItem(const FlexRect&, LengthType widthType, LengthType heightType, IntrinsicWidthConstraints, const ContainerBox&);
         LogicalFlexItem() = default;
 
         void setTop(LayoutUnit top) { m_marginRect.value.setTop(top); }
@@ -61,6 +61,8 @@
 
         bool isHeightAuto() const { return m_marginRect.heightType == LengthType::Auto; }
 
+        LayoutUnit minimumContentWidth() const { return m_intrinsicWidthConstraints.minimum; }
+
         const RenderStyle& style() const { return m_layoutBox->style(); }
         const ContainerBox& layoutBox() const { return *m_layoutBox; }
 
@@ -71,6 +73,7 @@
             LengthType heightType { LengthType::Auto };
         };
         MarginRect m_marginRect { };
+        IntrinsicWidthConstraints m_intrinsicWidthConstraints { };
         CheckedPtr<const ContainerBox> m_layoutBox;        
     };
     using LogicalFlexItems = Vector<LogicalFlexItem>;    
@@ -86,15 +89,14 @@
     LayoutUnit computeAvailableLogicalVerticalSpace(LogicalFlexItems&, const ConstraintsForFlexContent&) const;
     LayoutUnit computeAvailableLogicalHorizontalSpace(LogicalFlexItems&, const ConstraintsForFlexContent&) const;
 
-    const FlexFormattingState& formattingState() const { return m_formattingState; }
     const RenderStyle& flexBoxStyle() const { return m_flexBoxStyle; }
 
-    const FlexFormattingState& m_formattingState;
     const RenderStyle& m_flexBoxStyle;
 };
 
-inline FlexLayout::LogicalFlexItem::LogicalFlexItem(const FlexRect& marginRect, LengthType widthType, LengthType heightType, const ContainerBox& layoutBox)
+inline FlexLayout::LogicalFlexItem::LogicalFlexItem(const FlexRect& marginRect, LengthType widthType, LengthType heightType, IntrinsicWidthConstraints intrinsicWidthConstraints, const ContainerBox& layoutBox)
     : m_marginRect({ marginRect, widthType, heightType })
+    , m_intrinsicWidthConstraints(intrinsicWidthConstraints)
     , m_layoutBox(layoutBox)
 {
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to