Changeset 253032 in webkit


Ignore:
Timestamp:
Dec 3, 2019 2:51:46 AM (4 years ago)
Author:
Antti Koivisto
Message:

[LFC][Integration] Setup root box properties
https://bugs.webkit.org/show_bug.cgi?id=204743

Reviewed by Zalan Bujtas.

Source/WebCore:

Test: fast/layoutformattingcontext/flow-integration-basic.html

Line layout needs to know about flow borders and padding so that boxes are offset correctly.

  • CMakeLists.txt:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • layout/LayoutContext.cpp:

(WebCore::Layout::LayoutContext::layout):
(WebCore::Layout::LayoutContext::layoutWithPreparedRootGeometry):

Split setup and layout into separate functions.

  • layout/LayoutContext.h:
  • layout/LayoutState.cpp:

(WebCore::Layout::LayoutState::displayBoxForLayoutRoot):

  • layout/LayoutState.h:
  • layout/displaytree/DisplayPainter.cpp:

(WebCore::Display::paintInlineContent):
(WebCore::Display::Painter::paint):
(WebCore::Display::Painter::paintInlineFlow):

Avoid accessing tree root box properties when painting (since margins are not set up).

  • layout/integration/RenderBlockFlowLineLayout.cpp: Renamed from Source/WebCore/layout/RenderBlockFlowLineLayout.cpp.

Moved to integration subdirectory.

(WebCore::Layout::RenderBlockFlowLineLayout::layout):

Drop the content size paramater, the caller is responsible of setting up the root display box.

(WebCore::Layout::RenderBlockFlowLineLayout::prepareRootDisplayBoxForLayout):

Setup padding and borders.

(WebCore::Layout::RenderBlockFlowLineLayout::displayInlineContent const):
(WebCore::Layout::RenderBlockFlowLineLayout::rootLayoutBox const):

  • layout/integration/RenderBlockFlowLineLayout.h: Renamed from Source/WebCore/layout/RenderBlockFlowLineLayout.h.

(WebCore::Layout::RenderBlockFlowLineLayout::contentLogicalHeight const):

Use a member to pass content height.

  • layout/layouttree/LayoutTreeBuilder.h:

(WebCore::Layout::LayoutTreeContent::layoutBoxForRenderer const):

  • rendering/RenderBlockFlow.cpp:

(WebCore::RenderBlockFlow::layoutLFCLines):

LayoutTests:

  • fast/layoutformattingcontext/flow-integration-basic.html: Added.
  • platform/mac/fast/layoutformattingcontext/flow-integration-basic-expected.txt: Added.
Location:
trunk
Files:
7 added
13 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r253031 r253032  
     12019-12-03  Antti Koivisto  <antti@apple.com>
     2
     3        [LFC][Integration] Setup root box properties
     4        https://bugs.webkit.org/show_bug.cgi?id=204743
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        * fast/layoutformattingcontext/flow-integration-basic.html: Added.
     9        * platform/mac/fast/layoutformattingcontext/flow-integration-basic-expected.txt: Added.
     10
    1112019-12-03  Zan Dobersek  <zdobersek@igalia.com>
    212
  • trunk/Source/WebCore/CMakeLists.txt

    r252226 r253032  
    106106    "${WEBCORE_DIR}/layout/inlineformatting"
    107107    "${WEBCORE_DIR}/layout/inlineformatting/text"
     108    "${WEBCORE_DIR}/layout/integration"
    108109    "${WEBCORE_DIR}/layout/layouttree"
    109110    "${WEBCORE_DIR}/loader"
  • trunk/Source/WebCore/ChangeLog

    r253031 r253032  
     12019-12-03  Antti Koivisto  <antti@apple.com>
     2
     3        [LFC][Integration] Setup root box properties
     4        https://bugs.webkit.org/show_bug.cgi?id=204743
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Test: fast/layoutformattingcontext/flow-integration-basic.html
     9
     10        Line layout needs to know about flow borders and padding so that boxes are offset correctly.
     11
     12        * CMakeLists.txt:
     13        * Sources.txt:
     14        * WebCore.xcodeproj/project.pbxproj:
     15        * layout/LayoutContext.cpp:
     16        (WebCore::Layout::LayoutContext::layout):
     17        (WebCore::Layout::LayoutContext::layoutWithPreparedRootGeometry):
     18
     19        Split setup and layout into separate functions.
     20
     21        * layout/LayoutContext.h:
     22        * layout/LayoutState.cpp:
     23        (WebCore::Layout::LayoutState::displayBoxForLayoutRoot):
     24        * layout/LayoutState.h:
     25        * layout/displaytree/DisplayPainter.cpp:
     26        (WebCore::Display::paintInlineContent):
     27        (WebCore::Display::Painter::paint):
     28        (WebCore::Display::Painter::paintInlineFlow):
     29
     30        Avoid accessing tree root box properties when painting (since margins are not set up).
     31
     32        * layout/integration/RenderBlockFlowLineLayout.cpp: Renamed from Source/WebCore/layout/RenderBlockFlowLineLayout.cpp.
     33
     34        Moved to integration subdirectory.
     35
     36        (WebCore::Layout::RenderBlockFlowLineLayout::layout):
     37
     38        Drop the content size paramater, the caller is responsible of setting up the root display box.
     39
     40        (WebCore::Layout::RenderBlockFlowLineLayout::prepareRootDisplayBoxForLayout):
     41
     42        Setup padding and borders.
     43
     44        (WebCore::Layout::RenderBlockFlowLineLayout::displayInlineContent const):
     45        (WebCore::Layout::RenderBlockFlowLineLayout::rootLayoutBox const):
     46        * layout/integration/RenderBlockFlowLineLayout.h: Renamed from Source/WebCore/layout/RenderBlockFlowLineLayout.h.
     47        (WebCore::Layout::RenderBlockFlowLineLayout::contentLogicalHeight const):
     48
     49        Use a member to pass content height.
     50
     51        * layout/layouttree/LayoutTreeBuilder.h:
     52        (WebCore::Layout::LayoutTreeContent::layoutBoxForRenderer const):
     53        * rendering/RenderBlockFlow.cpp:
     54        (WebCore::RenderBlockFlow::layoutLFCLines):
     55
    1562019-12-03  Zan Dobersek  <zdobersek@igalia.com>
    257
  • trunk/Source/WebCore/Sources.txt

    r252966 r253032  
    14231423layout/LayoutState.cpp
    14241424layout/LayoutUnits.cpp
    1425 layout/RenderBlockFlowLineLayout.cpp
    14261425layout/Verification.cpp
    14271426layout/blockformatting/BlockFormattingContext.cpp
     
    14461445layout/inlineformatting/LineLayoutContext.cpp
    14471446layout/inlineformatting/text/TextUtil.cpp
     1447layout/integration/RenderBlockFlowLineLayout.cpp
    14481448layout/invalidation/InvalidationContext.cpp
    14491449layout/invalidation/InvalidationState.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r253025 r253032  
    1663016630                                6FCFC055212DACC2007695D2 /* floats */,
    1663116631                                115CFA9A208BC140001E6991 /* inlineformatting */,
     16632                                E4FB4B1E2395356F003C336A /* integration */,
    1663216633                                6F95DE4A237B883000E517E1 /* invalidation */,
    1663316634                                115CFA90208B9441001E6991 /* layouttree */,
     
    1664816649                                6F73918C2106CEDD006AF262 /* LayoutUnits.h */,
    1664916650                                6FE7AA2621C37B6300296DCD /* MarginTypes.h */,
    16650                                 E4ABABDE2360893D00FA4345 /* RenderBlockFlowLineLayout.cpp */,
    16651                                 E4ABABDB236088FD00FA4345 /* RenderBlockFlowLineLayout.h */,
    1665216651                                11FF02D520BA3C810083F25B /* Verification.cpp */,
    1665316652                        );
     
    1669216691                        isa = PBXGroup;
    1669316692                        children = (
     16693                                E435505223953457004829C0 /* integration */,
    1669416694                                6FE7DDDD20EC6E8B008B5B4E /* text */,
    1669516695                                6F7CA3C9208C2B2E002F29AB /* InlineFormattingContext.cpp */,
     
    2702227022                        sourceTree = "<group>";
    2702327023                };
     27024                E435505223953457004829C0 /* integration */ = {
     27025                        isa = PBXGroup;
     27026                        children = (
     27027                        );
     27028                        path = integration;
     27029                        sourceTree = "<group>";
     27030                };
    2702427031                E46E97860DAAD61B0071E894 /* animation */ = {
    2702527032                        isa = PBXGroup;
     
    2714327150                        );
    2714427151                        path = updating;
     27152                        sourceTree = "<group>";
     27153                };
     27154                E4FB4B1E2395356F003C336A /* integration */ = {
     27155                        isa = PBXGroup;
     27156                        children = (
     27157                                E4ABABDE2360893D00FA4345 /* RenderBlockFlowLineLayout.cpp */,
     27158                                E4ABABDB236088FD00FA4345 /* RenderBlockFlowLineLayout.h */,
     27159                        );
     27160                        path = integration;
    2714527161                        sourceTree = "<group>";
    2714627162                };
  • trunk/Source/WebCore/layout/LayoutContext.cpp

    r252912 r253032  
    5959void LayoutContext::layout(const LayoutSize& rootContentBoxSize, InvalidationState& invalidationState)
    6060{
    61     PhaseScope scope(Phase::Type::Layout);
    6261    // Set the geometry on the root.
    6362    // Note that we never layout the root box. It has to have an already computed geometry (in case of ICB, it's the view geometry).
    6463    // ICB establishes the initial BFC, but it does not live in a formatting context and while a non-ICB root(subtree layout) has to have a formatting context,
    6564    // we could not lay it out even if we wanted to since it's outside of this LayoutContext.
    66     auto& displayBox = layoutState().displayBoxForLayoutBox(layoutState().root());
     65    auto& displayBox = layoutState().displayBoxForRootLayoutBox();
    6766    displayBox.setHorizontalMargin({ });
    6867    displayBox.setHorizontalComputedMargin({ });
     
    7473    displayBox.setContentBoxWidth(rootContentBoxSize.width());
    7574
     75    layoutWithPreparedRootGeometry(invalidationState);
     76}
     77
     78void LayoutContext::layoutWithPreparedRootGeometry(InvalidationState& invalidationState)
     79{
     80    PhaseScope scope(Phase::Type::Layout);
     81
    7682    auto& formattingContextRootsForLayout = invalidationState.formattingContextRoots();
    7783    // When invalidation is empty, we assume constraint mutation and start running layout on the context root. Layout logic should be able to figure out the damage.
     
    8288        layoutFormattingContextSubtree(formattingContextRoot, invalidationState);
    8389}
     90
    8491
    8592void LayoutContext::layoutFormattingContextSubtree(const Container& formattingContextRoot, InvalidationState& invalidationState)
  • trunk/Source/WebCore/layout/LayoutContext.h

    r252534 r253032  
    5353public:
    5454    LayoutContext(LayoutState&);
     55
    5556    void layout(const LayoutSize& rootContentBoxSize, InvalidationState&);
     57    void layoutWithPreparedRootGeometry(InvalidationState&);
    5658
    5759    static std::unique_ptr<FormattingContext> createFormattingContext(const Container& formattingContextRoot, LayoutState&);
  • trunk/Source/WebCore/layout/LayoutState.cpp

    r252534 r253032  
    5757
    5858LayoutState::~LayoutState() = default;
     59
     60Display::Box& LayoutState::displayBoxForRootLayoutBox()
     61{
     62    return displayBoxForLayoutBox(m_layoutTreeContent->rootLayoutBox());
     63}
    5964
    6065Display::Box& LayoutState::displayBoxForLayoutBox(const Box& layoutBox)
  • trunk/Source/WebCore/layout/LayoutState.h

    r252534 r253032  
    6363#endif
    6464
     65    Display::Box& displayBoxForRootLayoutBox();
    6566    Display::Box& displayBoxForLayoutBox(const Box& layoutBox);
    6667    const Display::Box& displayBoxForLayoutBox(const Box& layoutBox) const;
  • trunk/Source/WebCore/layout/displaytree/DisplayPainter.cpp

    r252979 r253032  
    111111}
    112112
    113 static void paintInlineContent(GraphicsContext& context, const Box& rootAbsoluteDisplayBox, const Layout::InlineFormattingState& formattingState)
     113static void paintInlineContent(GraphicsContext& context, LayoutPoint absoluteOffset, const Layout::InlineFormattingState& formattingState)
    114114{
    115115    auto* displayInlineContent = formattingState.displayInlineContent();
     
    127127            context.setFillColor(style.color());
    128128
    129             auto logicalLeft = rootAbsoluteDisplayBox.left() + run.logicalLeft();
     129            auto logicalLeft = absoluteOffset.x() + run.logicalLeft();
    130130            // FIXME: Add non-baseline align painting
    131131            auto& lineBox = displayInlineContent->lineBoxForRun(run);
    132             auto baselineOffset = rootAbsoluteDisplayBox.top() + lineBox.logicalTop() + lineBox.baselineOffset();
     132            auto baselineOffset = absoluteOffset.y() + lineBox.logicalTop() + lineBox.baselineOffset();
    133133            if (auto expansionContext = textContext->expansion())
    134134                context.drawText(style.fontCascade(), TextRun { textContext->content(), logicalLeft, expansionContext->horizontalExpansion, expansionContext->behavior }, { logicalLeft, baselineOffset });
     
    136136                context.drawText(style.fontCascade(), TextRun { textContext->content(), logicalLeft }, { logicalLeft, baselineOffset });
    137137        } else if (auto* cachedImage = run.image()) {
    138             auto runAbsoluteRect = FloatRect { rootAbsoluteDisplayBox.left() + run.logicalLeft(), rootAbsoluteDisplayBox.top() + run.logicalTop(), run.logicalWidth(), run.logicalHeight() };
     138            auto runAbsoluteRect = FloatRect { absoluteOffset.x() + run.logicalLeft(), absoluteOffset.y() + run.logicalTop(), run.logicalWidth(), run.logicalHeight() };
    139139            context.drawImage(*cachedImage->image(), runAbsoluteRect);
    140140        }
     
    195195        if (layoutBox.establishesInlineFormattingContext()) {
    196196            auto& container = downcast<Layout::Container>(layoutBox);
    197             paintInlineContent(context, absoluteDisplayBox, downcast<Layout::InlineFormattingState>(layoutState.establishedFormattingState(container)));
     197            paintInlineContent(context, absoluteDisplayBox.topLeft(), downcast<Layout::InlineFormattingState>(layoutState.establishedFormattingState(container)));
    198198            continue;
    199199        }
     
    207207    ASSERT(layoutRoot.establishesInlineFormattingContext());
    208208
    209     auto& displayBox = layoutState.displayBoxForLayoutBox(layoutRoot);
    210 
    211     paintInlineContent(context, displayBox, downcast<Layout::InlineFormattingState>(layoutState.establishedFormattingState(layoutRoot)));
     209    paintInlineContent(context, { }, downcast<Layout::InlineFormattingState>(layoutState.establishedFormattingState(layoutRoot)));
    212210}
    213211
  • trunk/Source/WebCore/layout/integration/RenderBlockFlowLineLayout.cpp

    r253031 r253032  
    7575        m_layoutState = makeUnique<LayoutState>(*m_treeContent);
    7676
    77     auto& rootContainer = m_layoutState->root();
     77    prepareRootGeometryForLayout();
     78
    7879    auto layoutContext = LayoutContext { *m_layoutState };
    7980    auto invalidationState = InvalidationState { };
    80     layoutContext.layout(m_flow.contentSize(), invalidationState);
    8181
    82     auto& lineBoxes = downcast<InlineFormattingState>(m_layoutState->establishedFormattingState(rootContainer)).displayInlineContent()->lineBoxes;
    83     auto height = lineBoxes.last().logicalBottom();
     82    layoutContext.layoutWithPreparedRootGeometry(invalidationState);
    8483
    85     auto& displayBox = m_layoutState->displayBoxForLayoutBox(rootContainer);
    86     displayBox.setContentBoxHeight(height);
     84    auto& lineBoxes = downcast<InlineFormattingState>(m_layoutState->establishedFormattingState(rootLayoutBox())).displayInlineContent()->lineBoxes;
     85    m_contentLogicalHeight = lineBoxes.last().logicalBottom() - lineBoxes.first().logicalTop();
    8786}
    8887
    89 LayoutUnit RenderBlockFlowLineLayout::contentBoxHeight() const
     88void RenderBlockFlowLineLayout::prepareRootGeometryForLayout()
    9089{
    91     return m_layoutState ? m_layoutState->displayBoxForLayoutBox(m_layoutState->root()).contentBoxHeight() : 0_lu;
     90    auto& displayBox = m_layoutState->displayBoxForRootLayoutBox();
     91
     92    // Don't set marging properties or height. These should not be be accessed by inline layout.
     93    displayBox.setBorder(Layout::Edges { { m_flow.borderStart(), m_flow.borderEnd() }, { m_flow.borderBefore(), m_flow.borderAfter() } });
     94    displayBox.setPadding(Layout::Edges { { m_flow.paddingStart(), m_flow.paddingEnd() }, { m_flow.paddingBefore(), m_flow.paddingAfter() } });
     95    displayBox.setContentBoxWidth(m_flow.contentSize().width());
    9296}
    9397
    9498const Display::InlineContent* RenderBlockFlowLineLayout::displayInlineContent() const
    9599{
    96     return downcast<InlineFormattingState>(m_layoutState->establishedFormattingState(m_treeContent->rootLayoutBox())).displayInlineContent();
     100    return downcast<InlineFormattingState>(m_layoutState->establishedFormattingState(rootLayoutBox())).displayInlineContent();
    97101}
    98102
     
    150154}
    151155
     156const Container& RenderBlockFlowLineLayout::rootLayoutBox() const
     157{
     158    return m_treeContent->rootLayoutBox();
     159}
     160
    152161}
    153162}
  • trunk/Source/WebCore/layout/integration/RenderBlockFlowLineLayout.h

    r253031 r253032  
    5656
    5757    void layout();
    58     LayoutUnit contentBoxHeight() const;
     58
     59    LayoutUnit contentLogicalHeight() const { return m_contentLogicalHeight; }
    5960    const Display::InlineContent* displayInlineContent() const;
    6061
     
    6566
    6667private:
     68    const Container& rootLayoutBox() const;
     69    void prepareRootGeometryForLayout();
     70
    6771    const RenderBlockFlow& m_flow;
    68     std::unique_ptr<LayoutTreeContent> m_treeContent;
     72    std::unique_ptr<const LayoutTreeContent> m_treeContent;
    6973    std::unique_ptr<LayoutState> m_layoutState;
     74    LayoutUnit m_contentLogicalHeight;
    7075};
    7176
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

    r252979 r253032  
    455455        auto& layoutRoot = layoutState.root();
    456456        auto invalidationState = InvalidationState { };
     457
    457458        LayoutContext(layoutState).layout(renderView.size(), invalidationState);
    458459        showLayoutTree(layoutRoot, &layoutState);
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h

    r252893 r253032  
    5858    void addBox(std::unique_ptr<Box> box) { m_boxes.add(WTFMove(box)); }
    5959
    60     using RenderObjectToLayoutBoxMap = HashMap<const RenderObject*, Box*>;
    6160    Box* layoutBoxForRenderer(const RenderObject& renderer) { return m_renderObjectToLayoutBox.get(&renderer); }
     61    const Box* layoutBoxForRenderer(const RenderObject& renderer) const { return m_renderObjectToLayoutBox.get(&renderer); }
     62   
    6263    void addLayoutBoxForRenderer(const RenderObject& renderer, Box& layoutBox) { m_renderObjectToLayoutBox.add(&renderer, &layoutBox); }
    6364
     
    6667    std::unique_ptr<Container> m_rootLayoutBox;
    6768    HashSet<std::unique_ptr<Box>> m_boxes;
    68     RenderObjectToLayoutBoxMap m_renderObjectToLayoutBox;
     69
     70    HashMap<const RenderObject*, Box*> m_renderObjectToLayoutBox;
    6971};
    7072
  • trunk/Source/WebCore/rendering/RenderBlockFlow.cpp

    r252907 r253032  
    36813681    lfcLineLayout.layout();
    36823682
    3683     LayoutUnit lineLayoutHeight = lfcLineLayout.contentBoxHeight();
    3684     LayoutUnit lineLayoutTop = borderAndPaddingBefore();
    3685     repaintLogicalTop = lineLayoutTop;
    3686     repaintLogicalBottom = repaintLogicalTop + lineLayoutHeight + borderAndPaddingAfter();
    3687     setLogicalHeight(lineLayoutTop + lineLayoutHeight + borderAndPaddingAfter());
     3683    auto contentHeight = lfcLineLayout.contentLogicalHeight();
     3684    auto contentTop = borderAndPaddingBefore();
     3685    auto contentBottom = contentTop + contentHeight;
     3686    auto totalHeight = contentBottom + borderAndPaddingAfter();
     3687
     3688    repaintLogicalTop = contentTop;
     3689    repaintLogicalBottom = contentBottom;
     3690
     3691    setLogicalHeight(totalHeight);
    36883692}
    36893693#endif
Note: See TracChangeset for help on using the changeset viewer.