⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 238431 in webkit


Ignore:
Timestamp:
Nov 21, 2018, 3:25:13 PM (8 years ago)
Author:
Alan Bujtas
Message:

[LFC] LayoutState should always be initialized with the initial containing block.
https://bugs.webkit.org/show_bug.cgi?id=191896

Reviewed by Antti Koivisto.

There should always be only one LayoutState per layout tree (it does not mean that layout always starts at the ICB).
The ICB is a special formatting context root because it does not have a parent formatting context. All the other formatting contexts
first need to be laid out (partially at least e.g margin) in their parent formatting context.
Having a non-null parent formatting context as root could lead to undefined behaviour.

  • layout/LayoutFormattingState.cpp:

(WebCore::Layout::LayoutState::LayoutState):
(WebCore::Layout::LayoutState::initializeRoot): Deleted.

  • layout/LayoutFormattingState.h:
  • layout/Verification.cpp:

(WebCore::Layout::LayoutState::verifyAndOutputMismatchingLayoutTree const):

  • page/FrameViewLayoutContext.cpp:

(WebCore::layoutUsingFormattingContext):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r238430 r238431  
     12018-11-21  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] LayoutState should always be initialized with the initial containing block.
     4        https://bugs.webkit.org/show_bug.cgi?id=191896
     5
     6        Reviewed by Antti Koivisto.
     7
     8        There should always be only one LayoutState per layout tree (it does not mean that layout always starts at the ICB).
     9        The ICB is a special formatting context root because it does not have a parent formatting context. All the other formatting contexts
     10        first need to be laid out (partially at least e.g margin) in their parent formatting context.
     11        Having a non-null parent formatting context as root could lead to undefined behaviour.
     12
     13        * layout/LayoutFormattingState.cpp:
     14        (WebCore::Layout::LayoutState::LayoutState):
     15        (WebCore::Layout::LayoutState::initializeRoot): Deleted.
     16        * layout/LayoutFormattingState.h:
     17        * layout/Verification.cpp:
     18        (WebCore::Layout::LayoutState::verifyAndOutputMismatchingLayoutTree const):
     19        * page/FrameViewLayoutContext.cpp:
     20        (WebCore::layoutUsingFormattingContext):
     21
    1222018-11-21  Zalan Bujtas  <zalan@apple.com>
    223
  • trunk/Source/WebCore/layout/LayoutFormattingState.cpp

    r237634 r238431  
    4646WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutState);
    4747
    48 LayoutState::LayoutState()
     48LayoutState::LayoutState(const Container& initialContainingBlock, const LayoutSize& containerSize)
     49    : m_initialContainingBlock(makeWeakPtr(initialContainingBlock))
    4950{
    50 }
     51    // LayoutState is always initiated with the ICB.
     52    ASSERT(!initialContainingBlock.parent());
     53    ASSERT(initialContainingBlock.establishesBlockFormattingContext());
    5154
    52 void LayoutState::initializeRoot(const Container& root, const LayoutSize& containerSize)
    53 {
    54     ASSERT(root.establishesFormattingContext());
    55 
    56     m_root = makeWeakPtr(root);
    57     auto& displayBox = displayBoxForLayoutBox(root);
    58 
    59     // FIXME: m_root could very well be a formatting context root with ancestors and resolvable border and padding (as opposed to the topmost root)
     55    auto& displayBox = displayBoxForLayoutBox(initialContainingBlock);
    6056    displayBox.setHorizontalMargin({ });
    6157    displayBox.setHorizontalNonComputedMargin({ });
     
    6460    displayBox.setBorder({ });
    6561    displayBox.setPadding({ });
     62    displayBox.setTopLeft({ });
    6663    displayBox.setContentBoxHeight(containerSize.height());
    6764    displayBox.setContentBoxWidth(containerSize.width());
    68     displayBox.setTopLeft({ });
    6965
    70     m_formattingContextRootListForLayout.add(&root);
     66    m_formattingContextRootListForLayout.add(&initialContainingBlock);
    7167}
    7268
  • trunk/Source/WebCore/layout/LayoutFormattingState.h

    r237633 r238431  
    5050class FormattingState;
    5151
    52 // LayoutState is the entry point for layout. It takes a (formatting root)container which acts as the root of the layout context.
     52// LayoutState is the entry point for layout. It takes the initial containing block which acts as the root of the layout context.
    5353// LayoutState::layout() generates the display tree for the root container's subtree (it does not run layout on the root though).
    54 // Note, while the root container is suppposed to be the entry point for the initial layout, it does not necessarily need to be the entry point of any
     54// Note, while the initial containing block is entry point for the initial layout, it does not necessarily need to be the entry point of any
    5555// subsequent layouts (subtree layout). A non-initial, subtree layout could be initiated on multiple formatting contexts.
    5656// Each formatting context has an entry point for layout, which potenitally means multiple entry points per layout frame.
     
    5959    WTF_MAKE_ISO_ALLOCATED(LayoutState);
    6060public:
    61     LayoutState();
     61    LayoutState(const Container& initialContainingBlock, const LayoutSize&);
    6262
    63     void initializeRoot(const Container&, const LayoutSize&);
    6463    void updateLayout();
    6564    void styleChanged(const Box&, StyleDiff);
     
    8786
    8887private:
     88    const Container& initialContainingBlock() const { return *m_initialContainingBlock; }
    8989    void layoutFormattingContextSubtree(const Box&);
    9090
    91     WeakPtr<const Container> m_root;
     91    WeakPtr<const Container> m_initialContainingBlock;
    9292    HashSet<const Container*> m_formattingContextRootListForLayout;
    9393    HashMap<const Box*, std::unique_ptr<FormattingState>> m_formattingStates;
  • trunk/Source/WebCore/layout/Verification.cpp

    r238415 r238431  
    322322{
    323323    TextStream stream;
    324     auto mismatchingGeometry = verifyAndOutputSubtree(stream, *this, renderView, *m_root.get());
     324    auto mismatchingGeometry = verifyAndOutputSubtree(stream, *this, renderView, initialContainingBlock());
    325325    if (!mismatchingGeometry)
    326326        return;
    327327#if ENABLE(TREE_DEBUGGING)
    328328    showRenderTree(&renderView);
    329     showLayoutTree(*m_root.get(), this);
     329    showLayoutTree(initialContainingBlock(), this);
    330330#endif
    331331    WTFLogAlways("%s", stream.release().utf8().data());
  • trunk/Source/WebCore/page/FrameViewLayoutContext.cpp

    r237631 r238431  
    5757{
    5858    auto initialContainingBlock = Layout::TreeBuilder::createLayoutTree(renderView);
    59     auto layoutState = std::make_unique<Layout::LayoutState>();
    60     layoutState->initializeRoot(*initialContainingBlock, renderView.size());
     59    auto layoutState = std::make_unique<Layout::LayoutState>(*initialContainingBlock, renderView.size());
    6160    layoutState->setInQuirksMode(renderView.document().inQuirksMode());
    6261    layoutState->updateLayout();
Note: See TracChangeset for help on using the changeset viewer.