Changeset 234084 in webkit


Ignore:
Timestamp:
Jul 21, 2018 11:47:01 AM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC] Do not use virtual methods to construct floating/formatting states.
https://bugs.webkit.org/show_bug.cgi?id=187875

Reviewed by Antti Koivisto.

LayoutContext::establishedFormattingState() does not require FormattingContext anymore only the root of the context.

  • layout/FormattingContext.cpp:

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

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

(WebCore::Layout::LayoutContext::layoutFormattingContextSubtree):
(WebCore::Layout::LayoutContext::formattingStateForBox const):
(WebCore::Layout::LayoutContext::establishedFormattingState):

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

(WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
(WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
(WebCore::Layout::BlockFormattingContext::createFormattingState const): Deleted.
(WebCore::Layout::BlockFormattingContext::createOrFindFloatingState const): Deleted.

  • layout/blockformatting/BlockFormattingContext.h:
  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::createFormattingState const): Deleted.
(WebCore::Layout::InlineFormattingContext::createOrFindFloatingState const): Deleted.

  • layout/inlineformatting/InlineFormattingContext.h:
Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r234083 r234084  
     12018-07-21  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Do not use virtual methods to construct floating/formatting states.
     4        https://bugs.webkit.org/show_bug.cgi?id=187875
     5
     6        Reviewed by Antti Koivisto.
     7
     8        LayoutContext::establishedFormattingState() does not require FormattingContext anymore only the root of the context.
     9
     10        * layout/FormattingContext.cpp:
     11        (WebCore::Layout::FormattingContext::layoutOutOfFlowDescendants const):
     12        * layout/FormattingContext.h:
     13        * layout/LayoutContext.cpp:
     14        (WebCore::Layout::LayoutContext::layoutFormattingContextSubtree):
     15        (WebCore::Layout::LayoutContext::formattingStateForBox const):
     16        (WebCore::Layout::LayoutContext::establishedFormattingState):
     17        * layout/LayoutContext.h:
     18        * layout/blockformatting/BlockFormattingContext.cpp:
     19        (WebCore::Layout::BlockFormattingContext::layoutFormattingContextRoot const):
     20        (WebCore::Layout::BlockFormattingContext::instrinsicWidthConstraints const):
     21        (WebCore::Layout::BlockFormattingContext::createFormattingState const): Deleted.
     22        (WebCore::Layout::BlockFormattingContext::createOrFindFloatingState const): Deleted.
     23        * layout/blockformatting/BlockFormattingContext.h:
     24        * layout/inlineformatting/InlineFormattingContext.cpp:
     25        (WebCore::Layout::InlineFormattingContext::createFormattingState const): Deleted.
     26        (WebCore::Layout::InlineFormattingContext::createOrFindFloatingState const): Deleted.
     27        * layout/inlineformatting/InlineFormattingContext.h:
     28
    1292018-07-21  Zalan Bujtas  <zalan@apple.com>
    230
  • trunk/Source/WebCore/layout/FormattingContext.cpp

    r233469 r234084  
    131131        ASSERT(layoutBox.establishesFormattingContext());
    132132        auto formattingContext = layoutContext.formattingContext(layoutBox);
    133         auto& establishedFormattingState = layoutContext.establishedFormattingState(layoutBox, *formattingContext);
    134133
    135134        computeBorderAndPadding(layoutContext, layoutBox, displayBox);
    136135        computeOutOfFlowHorizontalGeometry(layoutContext, layoutBox, displayBox);
    137136
    138         formattingContext->layout(layoutContext, establishedFormattingState);
     137        formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox));
    139138
    140139        computeOutOfFlowVerticalGeometry(layoutContext, layoutBox, displayBox);
  • trunk/Source/WebCore/layout/FormattingContext.h

    r233469 r234084  
    5353    virtual void layout(LayoutContext&, FormattingState&) const = 0;
    5454    void layoutOutOfFlowDescendants(LayoutContext&, const Box&) const;
    55     virtual std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&, const LayoutContext&) const = 0;
    56     virtual Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const = 0;
    5755
    5856    struct InstrinsicWidthConstraints {
  • trunk/Source/WebCore/layout/LayoutContext.cpp

    r233469 r234084  
    8282    RELEASE_ASSERT(layoutRoot.establishesFormattingContext());
    8383    auto formattingContext = this->formattingContext(layoutRoot);
    84     auto& formattingState = establishedFormattingState(layoutRoot, *formattingContext);
    85     formattingContext->layout(*this, formattingState);
     84    formattingContext->layout(*this, establishedFormattingState(layoutRoot));
    8685    formattingContext->layoutOutOfFlowDescendants(*this, layoutRoot);
    8786}
     
    120119}
    121120
    122 FormattingState& LayoutContext::establishedFormattingState(const Box& formattingContextRoot, const FormattingContext& context)
     121FormattingState& LayoutContext::establishedFormattingState(const Box& formattingRoot)
    123122{
    124     return *m_formattingStates.ensure(&formattingContextRoot, [this, &context] {
    125         return context.createFormattingState(context.createOrFindFloatingState(*this), *this);
    126     }).iterator->value;
     123    if (formattingRoot.establishesInlineFormattingContext()) {
     124        return *m_formattingStates.ensure(&formattingRoot, [&] {
     125
     126            // If the block container box that initiates this inline formatting context also establishes a block context, the floats outside of the formatting root
     127            // should not interfere with the content inside.
     128            // <div style="float: left"></div><div style="overflow: hidden"> <- is a non-intrusive float, because overflow: hidden triggers new block formatting context.</div>
     129            if (formattingRoot.establishesBlockFormattingContext())
     130                return std::make_unique<InlineFormattingState>(FloatingState::create(), *this);
     131
     132            // Otherwise, the formatting context inherits the floats from the parent formatting context.
     133            // Find the formatting state in which this formatting root lives, not the one it creates and use its floating state.
     134            return std::make_unique<InlineFormattingState>(formattingStateForBox(formattingRoot).floatingState(), *this);
     135        }).iterator->value;
     136    }
     137
     138    if (formattingRoot.establishesBlockFormattingContext()) {
     139        return *m_formattingStates.ensure(&formattingRoot, [&] {
     140
     141            // Block formatting context always establishes a new floating state.
     142            return std::make_unique<BlockFormattingState>(FloatingState::create(), *this);
     143        }).iterator->value;
     144    }
     145    CRASH();
    127146}
    128147
  • trunk/Source/WebCore/layout/LayoutContext.h

    r233469 r234084  
    7575    bool needsUpdate(const Box&) const;
    7676
     77    std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot);
     78
    7779    FormattingState& formattingStateForBox(const Box&) const;
    78     FormattingState& establishedFormattingState(const Box& formattingContextRoot, const FormattingContext&);
    79     std::unique_ptr<FormattingContext> formattingContext(const Box& formattingContextRoot);
     80    FormattingState& establishedFormattingState(const Box& formattingRoot);
    8081
    8182    Display::Box& createDisplayBox(const Box&);
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp

    r233469 r234084  
    142142    // Swich over to the new formatting context (the one that the root creates).
    143143    auto formattingContext = layoutContext.formattingContext(layoutBox);
    144     auto& establishedFormattingState = layoutContext.establishedFormattingState(layoutBox, *formattingContext);
    145     formattingContext->layout(layoutContext, establishedFormattingState);
     144    formattingContext->layout(layoutContext, layoutContext.establishedFormattingState(layoutBox));
    146145
    147146    // Come back and finalize the root's geometry.
     
    151150    // Now that we computed the root's height, we can go back and layout the out-of-flow descedants (if any).
    152151    formattingContext->layoutOutOfFlowDescendants(layoutContext, layoutBox);
    153 }
    154 
    155 std::unique_ptr<FormattingState> BlockFormattingContext::createFormattingState(Ref<FloatingState>&& floatingState, const LayoutContext& layoutContext) const
    156 {
    157     return std::make_unique<BlockFormattingState>(WTFMove(floatingState), layoutContext);
    158 }
    159 
    160 Ref<FloatingState> BlockFormattingContext::createOrFindFloatingState(LayoutContext&) const
    161 {
    162     // Block formatting context always establishes a new floating state.
    163     return FloatingState::create();
    164152}
    165153
     
    238226        queue.append(firstChild);
    239227
    240     auto& formattingStateForChildren = layoutBox.establishesFormattingContext() ? layoutContext.establishedFormattingState(layoutBox, *this) : formattingState;
     228    auto& formattingStateForChildren = layoutBox.establishesFormattingContext() ? layoutContext.establishedFormattingState(layoutBox) : formattingState;
    241229    while (!queue.isEmpty()) {
    242230        while (true) {
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r233469 r234084  
    4848
    4949    void layout(LayoutContext&, FormattingState&) const override;
    50     std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&, const LayoutContext&) const override;
    51     Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const override;
    5250
    5351private:
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r234048 r234084  
    100100}
    101101
    102 std::unique_ptr<FormattingState> InlineFormattingContext::createFormattingState(Ref<FloatingState>&& floatingState, const LayoutContext& layoutContext) const
    103 {
    104     return std::make_unique<InlineFormattingState>(WTFMove(floatingState), layoutContext);
    105 }
    106 
    107 Ref<FloatingState> InlineFormattingContext::createOrFindFloatingState(LayoutContext& layoutContext) const
    108 {
    109     // If the block container box that initiates this inline formatting context also establishes a block context, the floats outside of the formatting root
    110     // should not interfere with the content inside.
    111     // <div style="float: left"></div><div style="overflow: hidden"> <- is a non-intrusive float, because overflow: hidden triggers new block formatting context.</div>
    112     if (root().establishesBlockFormattingContext())
    113         return FloatingState::create();
    114     // Otherwise, the formatting context inherits the floats from the parent formatting context.
    115     // Find the formatting state in which this formatting root lives, not the one it creates (this) and use its floating state.
    116     auto& formattingState = layoutContext.formattingStateForBox(root());
    117     return formattingState.floatingState();
    118 }
    119 
    120102void InlineFormattingContext::computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const
    121103{
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h

    r233469 r234084  
    4545
    4646    void layout(LayoutContext&, FormattingState&) const override;
    47     std::unique_ptr<FormattingState> createFormattingState(Ref<FloatingState>&&, const LayoutContext&) const override;
    48     Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const override;
    4947
    5048private:
Note: See TracChangeset for help on using the changeset viewer.