Changeset 295027 in webkit


Ignore:
Timestamp:
May 30, 2022 7:10:13 AM (2 years ago)
Author:
Alan Bujtas
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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp

    r295017 r295027  
    460460{
    461461    auto justifyContent = root().style().justifyContent();
     462    // FIXME: Make this optional.
     463    auto contentLogicalWidth = [&] {
     464        auto logicalWidth = LayoutUnit { };
     465        for (auto& logicalFlexItem : logicalFlexItemList)
     466            logicalWidth += logicalFlexItem.rect.width();
     467        return logicalWidth;
     468    }();
    462469
    463470    auto initialOffset = [&] {
    464         auto contentLogicalWidth = [&] {
    465             auto logicalWidth = LayoutUnit { };
    466             for (auto& logicalFlexItem : logicalFlexItemList)
    467                 logicalWidth += logicalFlexItem.rect.width();
    468             return logicalWidth;
    469         };
     471        switch (justifyContent.distribution()) {
     472        case ContentDistribution::Default:
     473            // Fall back to justifyContent.position()
     474            break;
     475        case ContentDistribution::SpaceBetween:
     476            return LayoutUnit { };
     477        default:
     478            ASSERT_NOT_IMPLEMENTED_YET();
     479            break;
     480        }
    470481
    471482        switch (justifyContent.position()) {
     
    478489        case ContentPosition::FlexEnd:
    479490        case ContentPosition::Right:
    480             return availableSpace - contentLogicalWidth();
     491            return availableSpace - contentLogicalWidth;
    481492        case ContentPosition::Center:
    482             return availableSpace / 2 - contentLogicalWidth() / 2;
     493            return availableSpace / 2 - contentLogicalWidth / 2;
    483494        default:
    484495            ASSERT_NOT_IMPLEMENTED_YET();
    485496            break;
    486497        }
     498        ASSERT_NOT_REACHED();
    487499        return LayoutUnit { };
    488500    };
    489501
     502    auto gapBetweenItems = [&] {
     503        switch (justifyContent.distribution()) {
     504        case ContentDistribution::Default:
     505            return LayoutUnit { };
     506        case ContentDistribution::SpaceBetween:
     507            if (logicalFlexItemList.size() == 1)
     508                return LayoutUnit { };
     509            return (availableSpace - contentLogicalWidth) / (logicalFlexItemList.size() - 1);
     510        default:
     511            ASSERT_NOT_IMPLEMENTED_YET();
     512            break;
     513        }
     514        ASSERT_NOT_REACHED();
     515        return LayoutUnit { };
     516    };
     517
    490518    auto logicalLeft = initialOffset();
     519    auto gap = gapBetweenItems();
    491520    for (auto& logicalFlexItem : logicalFlexItemList) {
    492521        logicalFlexItem.rect.setLeft(logicalLeft);
    493         logicalLeft = logicalFlexItem.rect.right();
     522        logicalLeft = logicalFlexItem.rect.right() + gap;
    494523    }
    495524}
Note: See TracChangeset for help on using the changeset viewer.