Title: [295027] trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp
Revision
295027
Author
za...@apple.com
Date
2022-05-30 07:10:13 -0700 (Mon, 30 May 2022)

Log Message

Add support for justify-content: space-between
https://bugs.webkit.org/show_bug.cgi?id=241080

Reviewed by Antti Koivisto.

Distribute items evenly. The first item is flush with the start, the last is flush with the end.

* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::justifyFlexItems):
* Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp:
(WebCore::LayoutIntegration::canUseForFlexLayout):

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

Modified Paths

Diff

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


--- trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-30 14:05:27 UTC (rev 295026)
+++ trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp	2022-05-30 14:10:13 UTC (rev 295027)
@@ -459,14 +459,25 @@
 void FlexFormattingContext::justifyFlexItems(LogicalFlexItems& logicalFlexItemList, LayoutUnit availableSpace)
 {
     auto justifyContent = root().style().justifyContent();
+    // FIXME: Make this optional.
+    auto contentLogicalWidth = [&] {
+        auto logicalWidth = LayoutUnit { };
+        for (auto& logicalFlexItem : logicalFlexItemList)
+            logicalWidth += logicalFlexItem.rect.width();
+        return logicalWidth;
+    }();
 
     auto initialOffset = [&] {
-        auto contentLogicalWidth = [&] {
-            auto logicalWidth = LayoutUnit { };
-            for (auto& logicalFlexItem : logicalFlexItemList)
-                logicalWidth += logicalFlexItem.rect.width();
-            return logicalWidth;
-        };
+        switch (justifyContent.distribution()) {
+        case ContentDistribution::Default:
+            // Fall back to justifyContent.position() 
+            break;
+        case ContentDistribution::SpaceBetween:
+            return LayoutUnit { };
+        default:
+            ASSERT_NOT_IMPLEMENTED_YET();
+            break;
+        }
 
         switch (justifyContent.position()) {
         case ContentPosition::Normal:
@@ -477,20 +488,38 @@
         case ContentPosition::End:
         case ContentPosition::FlexEnd:
         case ContentPosition::Right:
-            return availableSpace - contentLogicalWidth();
+            return availableSpace - contentLogicalWidth;
         case ContentPosition::Center:
-            return availableSpace / 2 - contentLogicalWidth() / 2;
+            return availableSpace / 2 - contentLogicalWidth / 2;
         default:
             ASSERT_NOT_IMPLEMENTED_YET();
             break;
         }
+        ASSERT_NOT_REACHED();
         return LayoutUnit { };
     };
 
+    auto gapBetweenItems = [&] {
+        switch (justifyContent.distribution()) {
+        case ContentDistribution::Default:
+            return LayoutUnit { };
+        case ContentDistribution::SpaceBetween:
+            if (logicalFlexItemList.size() == 1)
+                return LayoutUnit { };
+            return (availableSpace - contentLogicalWidth) / (logicalFlexItemList.size() - 1); 
+        default:
+            ASSERT_NOT_IMPLEMENTED_YET();
+            break;
+        }
+        ASSERT_NOT_REACHED();
+        return LayoutUnit { };
+    };
+
     auto logicalLeft = initialOffset();
+    auto gap = gapBetweenItems();
     for (auto& logicalFlexItem : logicalFlexItemList) {
         logicalFlexItem.rect.setLeft(logicalLeft);
-        logicalLeft = logicalFlexItem.rect.right();
+        logicalLeft = logicalFlexItem.rect.right() + gap;
     }
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to