Changeset 293293 in webkit


Ignore:
Timestamp:
Apr 23, 2022 1:25:12 PM (2 years ago)
Author:
Alan Bujtas
Message:

[FFC][Integration] Construct and update the layout tree for the flex items
https://bugs.webkit.org/show_bug.cgi?id=239684

Reviewed by Antti Koivisto.

This patch implements the usual flow of preparing a subtree for integration layout.

  1. Take the direct children of a RenderFlexibleBox (flex items) and construct Layout::ContainerBox objects.
  2. Run layout on the direct children (RenderBlocks) first and update the associated Layout::ContainerBoxes' geometries.
  3. Call LayoutIntegration::FlexLayout::layout (not yet implemented) to run flex layout on the flex items.
  • layout/integration/LayoutIntegrationBoxTree.cpp:

(WebCore::LayoutIntegration::BoxTree::buildTreeForFlexContent):

  • layout/integration/LayoutIntegrationBoxTree.h:
  • layout/integration/flex/LayoutIntegrationFlexLayout.cpp:

(WebCore::LayoutIntegration::FlexLayout::FlexLayout):
(WebCore::LayoutIntegration::FlexLayout::updateFlexItemDimensions):

  • layout/integration/flex/LayoutIntegrationFlexLayout.h:
  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::layoutUsingFlexFormattingContext):

  • rendering/RenderFlexibleBox.h:
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r293291 r293293  
     12022-04-23  Alan Bujtas  <zalan@apple.com>
     2
     3        [FFC][Integration] Construct and update the layout tree for the flex items
     4        https://bugs.webkit.org/show_bug.cgi?id=239684
     5
     6        Reviewed by Antti Koivisto.
     7
     8        This patch implements the usual flow of preparing a subtree for integration layout.
     9
     10        1. Take the direct children of a RenderFlexibleBox (flex items) and construct Layout::ContainerBox objects.
     11        2. Run layout on the direct children (RenderBlocks) first and update the associated Layout::ContainerBoxes' geometries.
     12        3. Call LayoutIntegration::FlexLayout::layout (not yet implemented) to run flex layout on the flex items.
     13
     14        * layout/integration/LayoutIntegrationBoxTree.cpp:
     15        (WebCore::LayoutIntegration::BoxTree::buildTreeForFlexContent):
     16        * layout/integration/LayoutIntegrationBoxTree.h:
     17        * layout/integration/flex/LayoutIntegrationFlexLayout.cpp:
     18        (WebCore::LayoutIntegration::FlexLayout::FlexLayout):
     19        (WebCore::LayoutIntegration::FlexLayout::updateFlexItemDimensions):
     20        * layout/integration/flex/LayoutIntegrationFlexLayout.h:
     21        * rendering/RenderFlexibleBox.cpp:
     22        (WebCore::RenderFlexibleBox::layoutUsingFlexFormattingContext):
     23        * rendering/RenderFlexibleBox.h:
     24
    1252022-04-23  Andres Gonzalez  <andresg_22@apple.com>
    226
  • trunk/Source/WebCore/Headers.cmake

    r293285 r293293  
    971971    inspector/agents/InspectorPageAgent.h
    972972
     973    layout/LayoutState.h
    973974    layout/LayoutUnits.h
    974975    layout/MarginTypes.h
     
    976977    layout/formattingContexts/inline/display/InlineDisplayBox.h
    977978    layout/formattingContexts/inline/InlineRect.h
     979
     980    layout/integration/LayoutIntegrationBoxTree.h
    978981
    979982    layout/integration/flex/LayoutIntegrationFlexLayout.h
     
    992995    layout/layouttree/LayoutContainerBox.h
    993996    layout/layouttree/LayoutBox.h
     997    layout/layouttree/LayoutInitialContainingBlock.h
    994998
    995999    loader/CanvasActivityRecord.h
  • trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.cpp

    r293222 r293293  
    3838#include "RenderChildIterator.h"
    3939#include "RenderDetailsMarker.h"
     40#include "RenderFlexibleBox.h"
    4041#include "RenderImage.h"
    4142#include "RenderLineBreak.h"
     
    8889    if (is<RenderBlockFlow>(rootRenderer))
    8990        buildTreeForInlineContent();
     91    else if (is<RenderFlexibleBox>(rootRenderer))
     92        buildTreeForFlexContent();
    9093    else
    9194        ASSERT_NOT_IMPLEMENTED_YET();
     
    171174        auto childBox = createChildBox(childRenderer);
    172175        appendChild(makeUniqueRefFromNonNullUniquePtr(WTFMove(childBox)), childRenderer);
     176    }
     177}
     178
     179void BoxTree::buildTreeForFlexContent()
     180{
     181    for (auto& flexItemRenderer : childrenOfType<RenderObject>(m_rootRenderer)) {
     182        auto style = RenderStyle::clone(flexItemRenderer.style());
     183        auto flexItem = makeUnique<Layout::ContainerBox>(Layout::Box::ElementAttributes { Layout::Box::ElementType::IntegrationBlockContainer }, WTFMove(style));
     184        appendChild(makeUniqueRefFromNonNullUniquePtr(WTFMove(flexItem)), flexItemRenderer);
    173185    }
    174186}
  • trunk/Source/WebCore/layout/integration/LayoutIntegrationBoxTree.h

    r293222 r293293  
    7272private:
    7373    void buildTreeForInlineContent();
     74    void buildTreeForFlexContent();
    7475    void appendChild(UniqueRef<Layout::Box>, RenderObject&);
    7576
  • trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.cpp

    r293251 r293293  
    3232#include "HitTestRequest.h"
    3333#include "HitTestResult.h"
     34#include "LayoutBoxGeometry.h"
    3435#include "RenderFlexibleBox.h"
    3536
     
    3940FlexLayout::FlexLayout(RenderFlexibleBox& flexBoxRenderer)
    4041    : m_boxTree(flexBoxRenderer)
     42    , m_layoutState(flexBoxRenderer.document(), m_boxTree.rootLayoutBox())
    4143{
    4244}
     
    4648}
    4749
    48 void FlexLayout::updateFlexItemDimensions(const RenderBlock&)
     50void FlexLayout::updateFlexItemDimensions(const RenderBlock& flexItem)
    4951{
     52    auto& boxGeometry = m_layoutState.ensureGeometryForBox(m_boxTree.layoutBoxForRenderer(flexItem));
     53
     54    boxGeometry.setContentBoxWidth(flexItem.contentWidth());
     55    boxGeometry.setContentBoxHeight(flexItem.contentHeight());
     56    boxGeometry.setVerticalMargin({ flexItem.marginTop(), flexItem.marginBottom() });
     57    boxGeometry.setHorizontalMargin({ flexItem.marginLeft(), flexItem.marginRight() });
     58    boxGeometry.setBorder({ { flexItem.borderLeft(), flexItem.borderRight() }, { flexItem.borderTop(), flexItem.borderBottom() } });
     59    boxGeometry.setPadding(Layout::Edges { { flexItem.paddingLeft(), flexItem.paddingRight() }, { flexItem.paddingTop(), flexItem.paddingBottom() } });
    5060}
    5161
  • trunk/Source/WebCore/layout/integration/flex/LayoutIntegrationFlexLayout.h

    r293251 r293293  
    2929
    3030#include "LayoutIntegrationBoxTree.h"
     31#include "LayoutState.h"
    3132#include "RenderObjectEnums.h"
    3233#include <wtf/CheckedPtr.h>
     
    6465private:
    6566    BoxTree m_boxTree;
     67    Layout::LayoutState m_layoutState;
    6668};
    6769
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r293233 r293293  
    23452345void RenderFlexibleBox::layoutUsingFlexFormattingContext()
    23462346{
     2347    if (!m_flexLayout)
     2348        m_flexLayout = makeUnique<LayoutIntegration::FlexLayout>(*this);
     2349
     2350    for (auto& flexItem : childrenOfType<RenderBlock>(*this)) {
     2351        flexItem.layoutIfNeeded();
     2352        m_flexLayout->updateFlexItemDimensions(flexItem);
     2353    }
     2354    m_flexLayout->layout();
    23472355}
    23482356#endif
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.h

    r293233 r293293  
    3131#pragma once
    3232
     33#include "LayoutIntegrationFlexLayout.h"
    3334#include "OrderIterator.h"
    3435#include "RenderBlock.h"
     
    235236    bool m_inLayout { false };
    236237    bool m_shouldResetChildLogicalHeightBeforeLayout { false };
     238#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
     239    std::unique_ptr<LayoutIntegration::FlexLayout> m_flexLayout;
     240#endif
    237241};
    238242
Note: See TracChangeset for help on using the changeset viewer.