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

Changeset 248290 in webkit


Ignore:
Timestamp:
Aug 5, 2019, 10:20:09 PM (7 years ago)
Author:
Alan Bujtas
Message:

[LFC] Remove out-of-flow descendants from Container
https://bugs.webkit.org/show_bug.cgi?id=200430
<rdar://problem/53923980>

Reviewed by Antti Koivisto.

The out-of-flow descendant list is the last "formatting context type" bit in the layout tree.
Let's cached them in the FormattingStates instead for now.

  • layout/FormattingContext.cpp:

(WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):

  • layout/FormattingContext.h:
  • layout/FormattingState.h:

(WebCore::Layout::FormattingState::addOutOfFlowBox):
(WebCore::Layout::FormattingState::outOfFlowBoxes const):

  • layout/LayoutState.cpp:

(WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
(WebCore::Layout::LayoutState::createFormattingStateForFormattingRootIfNeeded):
(WebCore::Layout::LayoutState::run):

  • layout/LayoutState.h:
  • layout/blockformatting/BlockFormattingContext.cpp:

(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):

  • layout/layouttree/LayoutBox.h:
  • layout/layouttree/LayoutContainer.cpp:

(WebCore::Layout::Container::addOutOfFlowDescendant): Deleted.

  • layout/layouttree/LayoutContainer.h:
  • layout/layouttree/LayoutTreeBuilder.cpp:

(WebCore::Layout::TreeBuilder::createLayoutTree):

  • page/FrameViewLayoutContext.cpp:

(WebCore::layoutUsingFormattingContext):

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248289 r248290  
     12019-08-05  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Remove out-of-flow descendants from Container
     4        https://bugs.webkit.org/show_bug.cgi?id=200430
     5        <rdar://problem/53923980>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        The out-of-flow descendant list is the last "formatting context type" bit in the layout tree.
     10        Let's cached them in the FormattingStates instead for now.
     11
     12        * layout/FormattingContext.cpp:
     13        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
     14        * layout/FormattingContext.h:
     15        * layout/FormattingState.h:
     16        (WebCore::Layout::FormattingState::addOutOfFlowBox):
     17        (WebCore::Layout::FormattingState::outOfFlowBoxes const):
     18        * layout/LayoutState.cpp:
     19        (WebCore::Layout::LayoutState::layoutFormattingContextSubtree):
     20        (WebCore::Layout::LayoutState::createFormattingStateForFormattingRootIfNeeded):
     21        (WebCore::Layout::LayoutState::run):
     22        * layout/LayoutState.h:
     23        * layout/blockformatting/BlockFormattingContext.cpp:
     24        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
     25        * layout/inlineformatting/InlineFormattingContext.cpp:
     26        (WebCore::Layout::InlineFormattingContext::layoutFormattingContextRoot const):
     27        * layout/layouttree/LayoutBox.h:
     28        * layout/layouttree/LayoutContainer.cpp:
     29        (WebCore::Layout::Container::addOutOfFlowDescendant): Deleted.
     30        * layout/layouttree/LayoutContainer.h:
     31        * layout/layouttree/LayoutTreeBuilder.cpp:
     32        (WebCore::Layout::TreeBuilder::createLayoutTree):
     33        * page/FrameViewLayoutContext.cpp:
     34        (WebCore::layoutUsingFormattingContext):
     35
    1362019-08-05  Devin Rousso  <drousso@apple.com>
    237
  • trunk/Source/WebCore/layout/FormattingContext.cpp

    r247198 r248290  
    134134}
    135135
    136 void FormattingContext::layoutOutOfFlowDescendants(const Box& layoutBox) const
    137 {
    138     if (!is<Container>(layoutBox))
    139         return;
    140 
    141     auto& container = downcast<Container>(layoutBox);
    142     if (!container.hasChild())
    143         return;
    144 
    145     auto& layoutState = this->layoutState();
    146     LOG_WITH_STREAM(FormattingContextLayout, stream << "Start: layout out-of-flow descendants -> context: " << &layoutState << " root: " << &root());
    147 
    148     for (auto& outOfFlowBox : container.outOfFlowDescendants()) {
    149         auto& layoutBox = *outOfFlowBox;
    150 
    151         ASSERT(layoutBox.establishesFormattingContext());
    152 
    153         computeBorderAndPadding(layoutBox);
    154         computeOutOfFlowHorizontalGeometry(layoutBox);
    155 
    156         layoutState.createFormattingContext(layoutBox)->layout();
    157 
    158         computeOutOfFlowVerticalGeometry(layoutBox);
    159         layoutOutOfFlowDescendants(layoutBox);
    160     }
    161     LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow descendants -> context: " << &layoutState << " root: " << &root());
     136void FormattingContext::layoutOutOfFlowDescendants() const
     137{
     138    LOG_WITH_STREAM(FormattingContextLayout, stream << "Start: layout out-of-flow descendants -> context: " << &layoutState() << " root: " << &root());
     139
     140    for (auto& outOfFlowBox : formattingState().outOfFlowBoxes()) {
     141        ASSERT(outOfFlowBox->establishesFormattingContext());
     142
     143        computeBorderAndPadding(*outOfFlowBox);
     144        computeOutOfFlowHorizontalGeometry(*outOfFlowBox);
     145
     146        auto formattingContext = layoutState().createFormattingContext(*outOfFlowBox);
     147        formattingContext->layout();
     148
     149        computeOutOfFlowVerticalGeometry(*outOfFlowBox);
     150        formattingContext->layoutOutOfFlowDescendants();
     151    }
     152    LOG_WITH_STREAM(FormattingContextLayout, stream << "End: layout out-of-flow descendants -> context: " << &layoutState() << " root: " << &root());
    162153}
    163154
  • trunk/Source/WebCore/layout/FormattingContext.h

    r248262 r248290  
    5151
    5252    virtual void layout() const = 0;
    53     void layoutOutOfFlowDescendants(const Box&) const;
     53    void layoutOutOfFlowDescendants() const;
    5454
    5555    struct IntrinsicWidthConstraints {
  • trunk/Source/WebCore/layout/FormattingState.h

    r248262 r248290  
    3434#include "LayoutUnit.h"
    3535#include <wtf/IsoMalloc.h>
     36#include <wtf/WeakPtr.h>
    3637
    3738namespace WebCore {
     
    6566    LayoutState& layoutState() const { return m_layoutState; }
    6667
     68    // Since we layout the out-of-flow boxes at the end of the formatting context layout, it's okay to store them in the formatting state -as opposed to the containing block level.
     69    using OutOfFlowBoxList = Vector<WeakPtr<const Box>>;
     70    void addOutOfFlowBox(const Box& outOfFlowBox) { m_outOfFlowBoxes.append(makeWeakPtr(outOfFlowBox)); }
     71    void removeOutOfFlowBox(const Box&);
     72    const OutOfFlowBoxList& outOfFlowBoxes() const { return m_outOfFlowBoxes; }
     73
    6774protected:
    6875    enum class Type { Block, Inline, Table };
     
    7481    HashMap<const Box*, FormattingContext::IntrinsicWidthConstraints> m_intrinsicWidthConstraintsForBoxes;
    7582    Optional<FormattingContext::IntrinsicWidthConstraints> m_intrinsicWidthConstraints;
     83    // FIXME: This needs WeakListHashSet
     84    OutOfFlowBoxList m_outOfFlowBoxes;
    7685    Type m_type;
    7786};
  • trunk/Source/WebCore/layout/LayoutState.cpp

    r248263 r248290  
    3939#include "LayoutBox.h"
    4040#include "LayoutContainer.h"
     41#include "LayoutTreeBuilder.h"
     42#include "RenderView.h"
    4143#include "TableFormattingContext.h"
    4244#include "TableFormattingState.h"
     
    8183    auto formattingContext = createFormattingContext(layoutRoot);
    8284    formattingContext->layout();
    83     formattingContext->layoutOutOfFlowDescendants(layoutRoot);
     85    formattingContext->layoutOutOfFlowDescendants();
    8486}
    8587
     
    138140            // Otherwise, the formatting context inherits the floats from the parent formatting context.
    139141            // Find the formatting state in which this formatting root lives, not the one it creates and use its floating state.
    140             return std::make_unique<InlineFormattingState>(formattingStateForBox(formattingRoot).floatingState(), *this);
     142            auto& parentFormattingState = createFormattingStateForFormattingRootIfNeeded(formattingRoot.formattingContextRoot());
     143            auto& parentFloatingState = parentFormattingState.floatingState();
     144            return std::make_unique<InlineFormattingState>(parentFloatingState, *this);
    141145        }).iterator->value;
    142146    }
     
    183187}
    184188
     189void LayoutState::run(const RenderView& renderView)
     190{
     191    auto initialContainingBlock = TreeBuilder::createLayoutTree(renderView);
     192    auto layoutState = LayoutState(*initialContainingBlock);
     193    // Not efficient, but this is temporary anyway.
     194    // Collect the out-of-flow descendants at the formatting root level (as opposed to at the containing block level, though they might be the same).
     195    for (auto& descendant : descendantsOfType<Box>(*initialContainingBlock)) {
     196        if (!descendant.isOutOfFlowPositioned())
     197            continue;
     198        auto& formattingState = layoutState.createFormattingStateForFormattingRootIfNeeded(descendant.formattingContextRoot());
     199        formattingState.addOutOfFlowBox(descendant);
     200    }
     201    auto quirksMode = [&] {
     202        auto& document = renderView.document();
     203        if (document.inLimitedQuirksMode())
     204            return QuirksMode::Limited;
     205        if (document.inQuirksMode())
     206            return QuirksMode::Yes;
     207        return QuirksMode::No;
     208    };
     209    layoutState.setQuirksMode(quirksMode());
     210    layoutState.updateLayout();
     211    layoutState.verifyAndOutputMismatchingLayoutTree(renderView);
     212}
     213
    185214}
    186215}
  • trunk/Source/WebCore/layout/LayoutState.h

    r246540 r248290  
    2828#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    2929
     30#include "LayoutContainer.h"
    3031#include <wtf/HashMap.h>
    3132#include <wtf/HashSet.h>
     
    4849enum class StyleDiff;
    4950class Box;
    50 class Container;
    5151class FormattingContext;
    5252class FormattingState;
     
    6262public:
    6363    LayoutState(const Container& initialContainingBlock);
     64
     65    // FIXME: This is a temporary entry point for LFC layout.
     66    static void run(const RenderView&);
    6467
    6568    void updateLayout();
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r248262 r248290  
    173173    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Compute] -> [Height][Margin] -> for layoutBox(" << &layoutBox << ")");
    174174    computeHeightAndMargin(layoutBox);
     175    // Now that we computed the root's height, we can go back and layout the out-of-flow descedants (if any).
     176    formattingContext->layoutOutOfFlowDescendants();
    175177
    176178    // Float related final positioning.
     
    180182    } else if (layoutBox.establishesBlockFormattingContext())
    181183        computePositionToAvoidFloats(floatingContext, layoutBox);
    182 
    183     // Now that we computed the root's height, we can go back and layout the out-of-flow descedants (if any).
    184     formattingContext->layoutOutOfFlowDescendants(layoutBox);
    185184}
    186185
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r248262 r248290  
    250250    computeHeightAndMargin(root);
    251251    // Now that we computed the root's height, we can go back and layout the out-of-flow descedants (if any).
    252     formattingContext->layoutOutOfFlowDescendants(root);
     252    formattingContext->layoutOutOfFlowDescendants();
    253253}
    254254
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.h

    r248200 r248290  
    9898
    9999    const Container* containingBlock() const;
    100     virtual const Container& formattingContextRoot() const;
     100    const Container& formattingContextRoot() const;
    101101    const Container& initialContainingBlock() const;
    102102
  • trunk/Source/WebCore/layout/layouttree/LayoutContainer.cpp

    r239427 r248290  
    9292}
    9393
    94 void Container::addOutOfFlowDescendant(const Box& outOfFlowBox)
    95 {
    96     // Since we layout the out-of-flow boxes at the end of the formatting context layout,
    97     // it's okay to store them at the formatting context root level -as opposed to the containing block level.
    98     ASSERT(establishesFormattingContext());
    99     m_outOfFlowDescendants.append(makeWeakPtr(outOfFlowBox));
    100 }
    101 
    10294}
    10395}
  • trunk/Source/WebCore/layout/layouttree/LayoutContainer.h

    r248200 r248290  
    3030#include "LayoutBox.h"
    3131#include <wtf/IsoMalloc.h>
    32 #include <wtf/WeakPtr.h>
    3332
    3433namespace WebCore {
     
    5453    bool hasInFlowOrFloatingChild() const { return firstInFlowOrFloatingChild(); }
    5554
    56     const Vector<WeakPtr<const Box>>& outOfFlowDescendants() const { return m_outOfFlowDescendants; }
    57 
    5855    void setFirstChild(Box&);
    5956    void setLastChild(Box&);
    60     void addOutOfFlowDescendant(const Box&);
    6157
    6258private:
    6359    Box* m_firstChild { nullptr };
    6460    Box* m_lastChild { nullptr };
    65     Vector<WeakPtr<const Box>> m_outOfFlowDescendants;
    6661};
    6762
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

    r248200 r248290  
    7676    std::unique_ptr<Container> initialContainingBlock(new Container(WTF::nullopt, WTFMove(style)));
    7777    TreeBuilder::createSubTree(renderView, *initialContainingBlock);
    78 
    79     // Not efficient, but this is temporary anyway.
    80     // Collect the out-of-flow descendants at the formatting root level (as opposed to at the containing block level, though they might be the same).
    81     for (auto& descendant : descendantsOfType<Box>(*initialContainingBlock)) {
    82         if (!descendant.isOutOfFlowPositioned())
    83             continue;
    84         const_cast<Container&>(descendant.formattingContextRoot()).addOutOfFlowDescendant(descendant);
    85     }
    86 
    8778    return initialContainingBlock;
    8879}
  • trunk/Source/WebCore/page/FrameViewLayoutContext.cpp

    r246477 r248290  
    4040#include "ScriptDisallowedScope.h"
    4141#include "Settings.h"
    42 
    4342#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    44 #include "FormattingState.h"
    45 #include "LayoutContainer.h"
    4643#include "LayoutState.h"
    47 #include "LayoutTreeBuilder.h"
    4844#endif
    4945
     
    5955    if (!RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextEnabled())
    6056        return;
    61     auto initialContainingBlock = Layout::TreeBuilder::createLayoutTree(renderView);
    62     auto layoutState = std::make_unique<Layout::LayoutState>(*initialContainingBlock);
    63     auto quirksMode = Layout::LayoutState::QuirksMode::No;
    64     if (renderView.document().inLimitedQuirksMode())
    65         quirksMode = Layout::LayoutState::QuirksMode::Limited;
    66     else if (renderView.document().inQuirksMode())
    67         quirksMode = Layout::LayoutState::QuirksMode::Yes;
    68     layoutState->setQuirksMode(quirksMode);
    69     layoutState->updateLayout();
    70     layoutState->verifyAndOutputMismatchingLayoutTree(renderView);
     57    Layout::LayoutState::run(renderView);
    7158}
    7259#endif
Note: See TracChangeset for help on using the changeset viewer.