Skip to content

Commit

Permalink
[FFC][Integration] Add updateFormattingRootGeometryAndInvalidate/upda…
Browse files Browse the repository at this point in the history
…teRenderers

https://bugs.webkit.org/show_bug.cgi?id=240413

Reviewed by Antti Koivisto.

Make sure that the layout box/renderer geometries are all up-to-date.

* layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::logicalBorder):
(WebCore::LayoutIntegration::logicalPadding):
(WebCore::LayoutIntegration::FlexLayout::updateFormattingRootGeometryAndInvalidate):
(WebCore::LayoutIntegration::FlexLayout::layout):
(WebCore::LayoutIntegration::FlexLayout::updateRenderers const):
* layout/integration/flex/LayoutIntegrationFlexLayout.h:
(WebCore::LayoutIntegration::FlexLayout::flexBoxRenderer const):
(WebCore::LayoutIntegration::FlexLayout::flexBoxRenderer):
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutUsingFlexFormattingContext):

Canonical link: https://commits.webkit.org/250559@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294193 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbaradlay committed May 14, 2022
1 parent e50ad5b commit 8d506bb
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
2022-05-14 Alan Bujtas <zalan@apple.com>

[FFC][Integration] Add updateFormattingRootGeometryAndInvalidate/updateRenderers
https://bugs.webkit.org/show_bug.cgi?id=240413

Reviewed by Antti Koivisto.

Make sure that the layout box/renderer geometries are all up-to-date.

* layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
(WebCore::LayoutIntegration::logicalBorder):
(WebCore::LayoutIntegration::logicalPadding):
(WebCore::LayoutIntegration::FlexLayout::updateFormattingRootGeometryAndInvalidate):
(WebCore::LayoutIntegration::FlexLayout::layout):
(WebCore::LayoutIntegration::FlexLayout::updateRenderers const):
* layout/integration/flex/LayoutIntegrationFlexLayout.h:
(WebCore::LayoutIntegration::FlexLayout::flexBoxRenderer const):
(WebCore::LayoutIntegration::FlexLayout::flexBoxRenderer):
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutUsingFlexFormattingContext):

2022-05-14 Alan Bujtas <zalan@apple.com>

[FFC][Integration] Do not reset the effective display value for flex root
Expand Down
Expand Up @@ -45,8 +45,48 @@ FlexLayout::FlexLayout(RenderFlexibleBox& flexBoxRenderer)
{
}

// FIXME: Merge these with the other integration layout functions.
static inline Layout::Edges logicalBorder(const RenderBoxModelObject& renderer, bool isLeftToRightInlineDirection, WritingMode writingMode)
{
UNUSED_PARAM(isLeftToRightInlineDirection);
UNUSED_PARAM(writingMode);

auto borderLeft = renderer.borderLeft();
auto borderRight = renderer.borderRight();
auto borderTop = renderer.borderTop();
auto borderBottom = renderer.borderBottom();

return { { borderLeft, borderRight }, { borderTop, borderBottom } };
}

static inline Layout::Edges logicalPadding(const RenderBoxModelObject& renderer, bool isLeftToRightInlineDirection, WritingMode writingMode)
{
UNUSED_PARAM(isLeftToRightInlineDirection);
UNUSED_PARAM(writingMode);

auto paddingLeft = renderer.paddingLeft();
auto paddingRight = renderer.paddingRight();
auto paddingTop = renderer.paddingTop();
auto paddingBottom = renderer.paddingBottom();

return { { paddingLeft, paddingRight }, { paddingTop, paddingBottom } };
}

void FlexLayout::updateFormattingRootGeometryAndInvalidate()
{
auto& flexBoxRenderer = this->flexBoxRenderer();

auto updateGeometry = [&](auto& root) {
auto isLeftToRightInlineDirection = flexBoxRenderer.style().isLeftToRightDirection();
auto writingMode = flexBoxRenderer.style().writingMode();

root.setContentBoxWidth(writingMode == WritingMode::TopToBottom ? flexBoxRenderer.contentWidth() : flexBoxRenderer.contentHeight());
root.setPadding(logicalPadding(flexBoxRenderer, isLeftToRightInlineDirection, writingMode));
root.setBorder(logicalBorder(flexBoxRenderer, isLeftToRightInlineDirection, writingMode));
root.setHorizontalMargin({ });
root.setVerticalMargin({ });
};
return updateGeometry(m_layoutState.ensureGeometryForBox(rootLayoutBox()));
}

void FlexLayout::updateFlexItemDimensions(const RenderBlock& flexItem)
Expand Down Expand Up @@ -80,6 +120,19 @@ void FlexLayout::layout()
auto horizontalConstraints = Layout::HorizontalConstraints { rootGeometry.contentBoxLeft(), rootGeometry.contentBoxWidth() };

flexFormattingContext.layoutInFlowContentForIntegration({ horizontalConstraints, rootGeometry.contentBoxTop() });

updateRenderers();
}

void FlexLayout::updateRenderers() const
{
auto& boxAndRendererList = m_boxTree.boxAndRendererList();
for (auto& boxAndRenderer : boxAndRendererList) {
auto& layoutBox = boxAndRenderer.box.get();

auto& renderer = downcast<RenderBox>(*boxAndRenderer.renderer);
renderer.setLocation(Layout::BoxGeometry::borderBoxTopLeft(m_flexFormattingState.boxGeometry(layoutBox)));
}
}

void FlexLayout::paint(PaintInfo&, const LayoutPoint&)
Expand Down
Expand Up @@ -64,9 +64,14 @@ class FlexLayout : public CanMakeCheckedPtr {
LayoutUnit contentLogicalHeight() const;

private:
void updateRenderers() const;

const Layout::ContainerBox& rootLayoutBox() const { return m_boxTree.rootLayoutBox(); }
Layout::ContainerBox& rootLayoutBox() { return m_boxTree.rootLayoutBox(); }

const RenderFlexibleBox& flexBoxRenderer() const { return downcast<RenderFlexibleBox>(m_boxTree.rootRenderer()); }
RenderFlexibleBox& flexBoxRenderer() { return downcast<RenderFlexibleBox>(m_boxTree.rootRenderer()); }

BoxTree m_boxTree;
Layout::LayoutState m_layoutState;
Layout::FlexFormattingState& m_flexFormattingState;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/rendering/RenderFlexibleBox.cpp
Expand Up @@ -2347,6 +2347,8 @@ void RenderFlexibleBox::layoutUsingFlexFormattingContext()
if (!m_flexLayout)
m_flexLayout = makeUnique<LayoutIntegration::FlexLayout>(*this);

m_flexLayout->updateFormattingRootGeometryAndInvalidate();

for (auto& flexItem : childrenOfType<RenderBlock>(*this)) {
flexItem.layoutIfNeeded();
m_flexLayout->updateFlexItemDimensions(flexItem);
Expand Down

0 comments on commit 8d506bb

Please sign in to comment.