Skip to content
Permalink
Browse files
Flex layout may use flex box's height to stretch flex items
https://bugs.webkit.org/show_bug.cgi?id=240774

Reviewed by Antti Koivisto.

This is in preparation for being able to stretch the flex items vertically (e.g. when the flex box has fixed height)

* Source/WebCore/Headers.cmake:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/layout/formattingContexts/FormattingConstraints.h:
(WebCore::Layout::ConstraintsForInFlowContent::isConstraintsForFlexContent const):
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingConstraints.h: Added.
(WebCore::Layout::ConstraintsForFlexContent::availableVerticalSpace const):
(WebCore::Layout::ConstraintsForFlexContent::ConstraintsForFlexContent):
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.cpp:
(WebCore::Layout::FlexFormattingContext::layoutInFlowContent):
(WebCore::Layout::FlexFormattingContext::sizeAndPlaceFlexItems):
(WebCore::Layout::FlexFormattingContext::setFlexItemsGeometry):
(WebCore::Layout::FlexFormattingContext::layoutInFlowContentForIntegration):
* Source/WebCore/layout/formattingContexts/flex/FlexFormattingContext.h:
* Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::FlexLayout::layout):

Canonical link: https://commits.webkit.org/250849@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294623 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbujtas committed May 22, 2022
1 parent 03aa567 commit 99513aca469cf80b7bd8c3d50854bf87cc0b623e
Showing 7 changed files with 78 additions and 10 deletions.
@@ -978,6 +978,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
layout/formattingContexts/FormattingConstraints.h
layout/formattingContexts/FormattingContext.h

layout/formattingContexts/flex/FlexFormattingConstraints.h
layout/formattingContexts/flex/FlexFormattingState.h

layout/formattingContexts/inline/display/InlineDisplayBox.h
@@ -2253,6 +2253,7 @@
6FAAE71326A2814B00E07502 /* InlineLevelBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FAAE71126A2814A00E07502 /* InlineLevelBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FAC251F281326580045683F /* LayoutIntegrationFlexLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FAC251E281326570045683F /* LayoutIntegrationFlexLayout.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FB11B5C21783FD000E2A574 /* TextUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB11B5921783FCF00E2A574 /* TextUtil.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FB17476283A8FF40067D8CA /* FlexFormattingConstraints.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB17475283A8FF40067D8CA /* FlexFormattingConstraints.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FB2400523DFF12800796458 /* InlineLineBox.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB2400323DFF12700796458 /* InlineLineBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FB47E632277425A00C7BCB0 /* LayoutIntegrationLine.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB47E612277425A00C7BCB0 /* LayoutIntegrationLine.h */; settings = {ATTRIBUTES = (Private, ); }; };
6FB5E214221F2453003989CF /* ContentChangeObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6FB5E212221F2447003989CF /* ContentChangeObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11088,6 +11089,7 @@
6FB0ED112427B6C6002737E6 /* LayoutInitialContainingBlock.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutInitialContainingBlock.cpp; sourceTree = "<group>"; };
6FB11B5921783FCF00E2A574 /* TextUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextUtil.h; sourceTree = "<group>"; };
6FB11B5B21783FCF00E2A574 /* TextUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextUtil.cpp; sourceTree = "<group>"; };
6FB17475283A8FF40067D8CA /* FlexFormattingConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlexFormattingConstraints.h; sourceTree = "<group>"; };
6FB22E30230097E300C20866 /* TableGrid.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TableGrid.h; sourceTree = "<group>"; };
6FB2400323DFF12700796458 /* InlineLineBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InlineLineBox.h; sourceTree = "<group>"; };
6FB47E612277425A00C7BCB0 /* LayoutIntegrationLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LayoutIntegrationLine.h; sourceTree = "<group>"; };
@@ -24667,6 +24669,7 @@
6FB7D2D5250FD7B5000207AA /* flex */ = {
isa = PBXGroup;
children = (
6FB17475283A8FF40067D8CA /* FlexFormattingConstraints.h */,
6FB7D2D7250FD7E5000207AA /* FlexFormattingContext.cpp */,
6FB7D2D9250FD7FC000207AA /* FlexFormattingContext.h */,
6F70DEDD251126F300F0FC78 /* FlexFormattingGeometry.cpp */,
@@ -34814,6 +34817,7 @@
72D73644278461A000398663 /* FilterResults.h in Headers */,
372C00D9129619F8005C9575 /* FindOptions.h in Headers */,
A8CFF04F0A154F09000A4234 /* FixedTableLayout.h in Headers */,
6FB17476283A8FF40067D8CA /* FlexFormattingConstraints.h in Headers */,
6FB7D2DD250FD828000207AA /* FlexFormattingContext.h in Headers */,
6FF911F726487FC8002021DF /* FlexFormattingGeometry.h in Headers */,
6FB7D2DE250FD82E000207AA /* FlexFormattingState.h in Headers */,
@@ -34890,6 +34894,7 @@
A853123D11D0471B00D4D077 /* FragmentScriptingPermission.h in Headers */,
65BF022F0974816300C43196 /* Frame.h in Headers */,
974A862314B7ADBB003FDC76 /* FrameDestructionObserver.h in Headers */,
46014ACC28333F65004C0B84 /* FrameDestructionObserverInlines.h in Headers */,
BC4A532B2560566E0028C592 /* FrameFlattening.h in Headers */,
0F11781822E3C47F008BD570 /* FrameIdentifier.h in Headers */,
656D373C0ADBA5DE00A4554D /* FrameLoader.h in Headers */,
@@ -38229,7 +38234,6 @@
E152551516FD2350003D7ADB /* WebCoreResourceHandleAsOperationQueueDelegate.h in Headers */,
A14832C7187F66C800DA63A6 /* WebCoreThread.h in Headers */,
A14832C9187F676B00DA63A6 /* WebCoreThreadInternal.h in Headers */,
46014ACC28333F65004C0B84 /* FrameDestructionObserverInlines.h in Headers */,
A14832CA187F678000DA63A6 /* WebCoreThreadMessage.h in Headers */,
A14832CC187F67C400DA63A6 /* WebCoreThreadRun.h in Headers */,
A14832CF187F684700DA63A6 /* WebCoreThreadSystemInterface.h in Headers */,
@@ -45,6 +45,7 @@ struct VerticalConstraints {
LayoutUnit logicalHeight;
};

// FIXME: Move the vertical bits to a dedicated ConstraintsForBlockContent class.
struct ConstraintsForInFlowContent {
ConstraintsForInFlowContent(HorizontalConstraints, LayoutUnit logicalTop);

@@ -53,9 +54,11 @@ struct ConstraintsForInFlowContent {

enum BaseTypeFlag : uint8_t {
GenericContent = 1 << 0,
TableContent = 1 << 1
TableContent = 1 << 1,
FlexContent = 1 << 2
};
bool isConstraintsForTableContent() const { return baseTypeFlags().contains(TableContent); }
bool isConstraintsForFlexContent() const { return baseTypeFlags().contains(FlexContent); }

protected:
ConstraintsForInFlowContent(HorizontalConstraints, LayoutUnit logicalTop, OptionSet<BaseTypeFlag>);
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if ENABLE(LAYOUT_FORMATTING_CONTEXT)

#include "FormattingConstraints.h"

namespace WebCore {
namespace Layout {

struct ConstraintsForFlexContent : public ConstraintsForInFlowContent {
ConstraintsForFlexContent(const ConstraintsForInFlowContent&, std::optional<LayoutUnit> availableVerticalSpace);

std::optional<LayoutUnit> availableVerticalSpace() const { return m_availableVerticalSpace; }

private:
std::optional<LayoutUnit> m_availableVerticalSpace;
};

inline ConstraintsForFlexContent::ConstraintsForFlexContent(const ConstraintsForInFlowContent& genericContraints, std::optional<LayoutUnit> availableVerticalSpace)
: ConstraintsForInFlowContent(genericContraints.horizontal(), genericContraints.logicalTop(), FlexContent)
, m_availableVerticalSpace(availableVerticalSpace)
{
}

}
}

SPECIALIZE_TYPE_TRAITS_LAYOUT_FORMATTING_CONSTRAINTS(ConstraintsForFlexContent, isConstraintsForFlexContent())

#endif
@@ -52,7 +52,7 @@ FlexFormattingContext::FlexFormattingContext(const ContainerBox& formattingConte
void FlexFormattingContext::layoutInFlowContent(const ConstraintsForInFlowContent& constraints)
{
computeIntrinsicWidthConstraintsForFlexItems();
sizeAndPlaceFlexItems(constraints);
sizeAndPlaceFlexItems(downcast<ConstraintsForFlexContent>(constraints));
}

LayoutUnit FlexFormattingContext::usedContentHeight() const
@@ -66,7 +66,7 @@ IntrinsicWidthConstraints FlexFormattingContext::computedIntrinsicWidthConstrain
return { };
}

void FlexFormattingContext::sizeAndPlaceFlexItems(const ConstraintsForInFlowContent& constraints)
void FlexFormattingContext::sizeAndPlaceFlexItems(const ConstraintsForFlexContent& constraints)
{
auto& formattingState = this->formattingState();
auto& formattingGeometry = this->formattingGeometry();
@@ -168,7 +168,7 @@ FlexFormattingContext::LogicalFlexItems FlexFormattingContext::convertFlexItemsT
return logicalFlexItemList;
}

void FlexFormattingContext::setFlexItemsGeometry(const LogicalFlexItems& logicalFlexItemList, const ConstraintsForInFlowContent& constraints)
void FlexFormattingContext::setFlexItemsGeometry(const LogicalFlexItems& logicalFlexItemList, const ConstraintsForFlexContent& constraints)
{
auto& formattingState = this->formattingState();
auto logicalWidth = logicalFlexItemList.last().rect.right() - logicalFlexItemList.first().rect.left();
@@ -238,7 +238,7 @@ void FlexFormattingContext::layoutInFlowContentForIntegration(const ConstraintsF
};
growFlexItemIfApplicable();
}
setFlexItemsGeometry(logicalFlexItemList, constraints);
setFlexItemsGeometry(logicalFlexItemList, downcast<ConstraintsForFlexContent>(constraints));
}

IntrinsicWidthConstraints FlexFormattingContext::computedIntrinsicWidthConstraintsForIntegration()
@@ -27,6 +27,7 @@

#if ENABLE(LAYOUT_FORMATTING_CONTEXT)

#include "FlexFormattingConstraints.h"
#include "FlexFormattingGeometry.h"
#include "FlexFormattingState.h"
#include "FlexRect.h"
@@ -53,7 +54,7 @@ class FlexFormattingContext final : public FormattingContext {
IntrinsicWidthConstraints computedIntrinsicWidthConstraintsForIntegration();

private:
void sizeAndPlaceFlexItems(const ConstraintsForInFlowContent&);
void sizeAndPlaceFlexItems(const ConstraintsForFlexContent&);
void computeIntrinsicWidthConstraintsForFlexItems();

struct LogicalFlexItem {
@@ -63,7 +64,7 @@ class FlexFormattingContext final : public FormattingContext {
};
using LogicalFlexItems = Vector<LogicalFlexItem>;
LogicalFlexItems convertFlexItemsToLogicalSpace();
void setFlexItemsGeometry(const LogicalFlexItems&, const ConstraintsForInFlowContent&);
void setFlexItemsGeometry(const LogicalFlexItems&, const ConstraintsForFlexContent&);

const FlexFormattingState& formattingState() const { return downcast<FlexFormattingState>(FormattingContext::formattingState()); }
FlexFormattingState& formattingState() { return downcast<FlexFormattingState>(FormattingContext::formattingState()); }
@@ -28,6 +28,7 @@

#if ENABLE(LAYOUT_FORMATTING_CONTEXT)

#include "FlexFormattingConstraints.h"
#include "FlexFormattingContext.h"
#include "HitTestLocation.h"
#include "HitTestRequest.h"
@@ -116,10 +117,13 @@ std::pair<LayoutUnit, LayoutUnit> FlexLayout::computeIntrinsicWidthConstraints()
void FlexLayout::layout()
{
auto& rootGeometry = m_layoutState.geometryForBox(rootLayoutBox());
auto flexFormattingContext = Layout::FlexFormattingContext { rootLayoutBox(), m_flexFormattingState };
auto horizontalConstraints = Layout::HorizontalConstraints { rootGeometry.contentBoxLeft(), rootGeometry.contentBoxWidth() };
auto rootBoxLogicalHeight = rootLayoutBox().style().logicalHeight();
auto availableVerticalSpace = std::optional<LayoutUnit> { rootBoxLogicalHeight.isFixed() ? std::make_optional(rootBoxLogicalHeight.value()) : std::nullopt };
auto constraints = Layout::ConstraintsForFlexContent { { horizontalConstraints, rootGeometry.contentBoxTop() }, availableVerticalSpace };

flexFormattingContext.layoutInFlowContentForIntegration({ horizontalConstraints, rootGeometry.contentBoxTop() });
auto flexFormattingContext = Layout::FlexFormattingContext { rootLayoutBox(), m_flexFormattingState };
flexFormattingContext.layoutInFlowContentForIntegration(constraints);

updateRenderers();
}

0 comments on commit 99513ac

Please sign in to comment.