Changeset 249349 in webkit


Ignore:
Timestamp:
Aug 30, 2019 3:45:49 PM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC] Pass FormattingContext to Geometry/Quirks/BlockMarginCollapsing classes
https://bugs.webkit.org/show_bug.cgi?id=201355
<rdar://problem/54895959>

Reviewed by Antti Koivisto.

This is in preparation for enforcing LFC to not call outside of the formatting context.
LayoutState::displayBoxForLayoutBox calls will be forced to go through the FormattingContext class to
check LFC escaping.

  • layout/FormattingContext.h:

(WebCore::Layout::FormattingContext::isBlockFormattingContext const):
(WebCore::Layout::FormattingContext::isInlineFormattingContext const):
(WebCore::Layout::FormattingContext::isTableFormattingContext const):
(WebCore::Layout::FormattingContext::Geometry::layoutState const):
(WebCore::Layout::FormattingContext::Geometry::layoutState):
(WebCore::Layout::FormattingContext::Geometry::formattingContext const):
(WebCore::Layout::FormattingContext::geometry const):
(WebCore::Layout::FormattingContext::Quirks::layoutState const):
(WebCore::Layout::FormattingContext::Quirks::layoutState):
(WebCore::Layout::FormattingContext::Quirks::formattingContext const):
(WebCore::Layout::FormattingContext::quirks const):
(WebCore::Layout::FormattingContext::Geometry::Geometry):
(WebCore::Layout::FormattingContext::Quirks::Quirks):

  • layout/FormattingContextGeometry.cpp:

(WebCore::Layout::FormattingContext::Geometry::computedHeightValue const):

  • layout/FormattingContextQuirks.cpp:

(WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):

  • layout/blockformatting/BlockFormattingContext.h:

(WebCore::Layout::BlockFormattingContext::Geometry::formattingContext const):
(WebCore::Layout::BlockFormattingContext::geometry const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::layoutState):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::layoutState const):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::formattingContext const):
(WebCore::Layout::BlockFormattingContext::marginCollapse const):
(WebCore::Layout::BlockFormattingContext::Quirks::formattingContext const):
(WebCore::Layout::BlockFormattingContext::quirks const):
(WebCore::Layout::BlockFormattingContext::Geometry::Geometry):
(WebCore::Layout::BlockFormattingContext::Quirks::Quirks):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::MarginCollapse):

  • layout/blockformatting/BlockFormattingContextGeometry.cpp:

(WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
(WebCore::Layout::BlockFormattingContext::Geometry::inFlowHeightAndMargin):

  • layout/blockformatting/BlockFormattingContextQuirks.cpp:

(WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight):

  • layout/blockformatting/BlockMarginCollapse.cpp:

(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore):
(WebCore::Layout::BlockFormattingContext::MarginCollapse::estimatedMarginBefore):

  • layout/inlineformatting/InlineFormattingContext.h:

(WebCore::Layout::InlineFormattingContext::InlineLayout::layoutState const):
(WebCore::Layout::InlineFormattingContext::InlineLayout::formattingContext const):
(WebCore::Layout::InlineFormattingContext::InlineLayout::formattingRoot const):
(WebCore::Layout::InlineFormattingContext::Quirks::formattingContext const):
(WebCore::Layout::InlineFormattingContext::quirks const):
(WebCore::Layout::InlineFormattingContext::Geometry::formattingContext const):
(WebCore::Layout::InlineFormattingContext::geometry const):
(WebCore::Layout::InlineFormattingContext::Geometry::Geometry):
(WebCore::Layout::InlineFormattingContext::Quirks::Quirks):

  • layout/inlineformatting/InlineFormattingContextLineLayout.cpp:

(WebCore::Layout::LineLayout::LineLayout):
(WebCore::Layout::InlineFormattingContext::InlineLayout::InlineLayout):
(WebCore::Layout::InlineFormattingContext::InlineLayout::layout const):
(WebCore::Layout::InlineFormattingContext::InlineLayout::computedIntrinsicWidth const):
(WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const):

  • layout/inlineformatting/InlineLine.cpp:

(WebCore::Layout::Line::Line):
(WebCore::Layout::Line::isVisuallyEmpty const):
(WebCore::Layout::Line::close):
(WebCore::Layout::Line::appendNonReplacedInlineBox):
(WebCore::Layout::Line::adjustBaselineAndLineHeight):
(WebCore::Layout::Line::inlineItemContentHeight const):
(WebCore::Layout::Line::layoutState const):
(WebCore::Layout::Line::formattingContext const):

  • layout/inlineformatting/InlineLine.h:
  • layout/tableformatting/TableFormattingContext.h:

(WebCore::Layout::TableFormattingContext::Geometry::formattingContext const):
(WebCore::Layout::TableFormattingContext::geometry const):
(WebCore::Layout::TableFormattingContext::Geometry::Geometry):

  • page/FrameViewLayoutContext.cpp:

(WebCore::layoutUsingFormattingContext):

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r249344 r249349  
     12019-08-30  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC] Pass FormattingContext to Geometry/Quirks/BlockMarginCollapsing classes
     4        https://bugs.webkit.org/show_bug.cgi?id=201355
     5        <rdar://problem/54895959>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This is in preparation for enforcing LFC to not call outside of the formatting context.
     10        LayoutState::displayBoxForLayoutBox calls will be forced to go through the FormattingContext class to
     11        check LFC escaping.
     12
     13
     14        * layout/FormattingContext.h:
     15        (WebCore::Layout::FormattingContext::isBlockFormattingContext const):
     16        (WebCore::Layout::FormattingContext::isInlineFormattingContext const):
     17        (WebCore::Layout::FormattingContext::isTableFormattingContext const):
     18        (WebCore::Layout::FormattingContext::Geometry::layoutState const):
     19        (WebCore::Layout::FormattingContext::Geometry::layoutState):
     20        (WebCore::Layout::FormattingContext::Geometry::formattingContext const):
     21        (WebCore::Layout::FormattingContext::geometry const):
     22        (WebCore::Layout::FormattingContext::Quirks::layoutState const):
     23        (WebCore::Layout::FormattingContext::Quirks::layoutState):
     24        (WebCore::Layout::FormattingContext::Quirks::formattingContext const):
     25        (WebCore::Layout::FormattingContext::quirks const):
     26        (WebCore::Layout::FormattingContext::Geometry::Geometry):
     27        (WebCore::Layout::FormattingContext::Quirks::Quirks):
     28        * layout/FormattingContextGeometry.cpp:
     29        (WebCore::Layout::FormattingContext::Geometry::computedHeightValue const):
     30        * layout/FormattingContextQuirks.cpp:
     31        (WebCore::Layout::FormattingContext::Quirks::heightValueOfNearestContainingBlockWithFixedHeight):
     32        * layout/blockformatting/BlockFormattingContext.h:
     33        (WebCore::Layout::BlockFormattingContext::Geometry::formattingContext const):
     34        (WebCore::Layout::BlockFormattingContext::geometry const):
     35        (WebCore::Layout::BlockFormattingContext::MarginCollapse::layoutState):
     36        (WebCore::Layout::BlockFormattingContext::MarginCollapse::layoutState const):
     37        (WebCore::Layout::BlockFormattingContext::MarginCollapse::formattingContext const):
     38        (WebCore::Layout::BlockFormattingContext::marginCollapse const):
     39        (WebCore::Layout::BlockFormattingContext::Quirks::formattingContext const):
     40        (WebCore::Layout::BlockFormattingContext::quirks const):
     41        (WebCore::Layout::BlockFormattingContext::Geometry::Geometry):
     42        (WebCore::Layout::BlockFormattingContext::Quirks::Quirks):
     43        (WebCore::Layout::BlockFormattingContext::MarginCollapse::MarginCollapse):
     44        * layout/blockformatting/BlockFormattingContextGeometry.cpp:
     45        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin):
     46        (WebCore::Layout::BlockFormattingContext::Geometry::inFlowHeightAndMargin):
     47        * layout/blockformatting/BlockFormattingContextQuirks.cpp:
     48        (WebCore::Layout::BlockFormattingContext::Quirks::stretchedInFlowHeight):
     49        * layout/blockformatting/BlockMarginCollapse.cpp:
     50        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeValues):
     51        (WebCore::Layout::BlockFormattingContext::MarginCollapse::positiveNegativeMarginBefore):
     52        (WebCore::Layout::BlockFormattingContext::MarginCollapse::estimatedMarginBefore):
     53        * layout/inlineformatting/InlineFormattingContext.h:
     54        (WebCore::Layout::InlineFormattingContext::InlineLayout::layoutState const):
     55        (WebCore::Layout::InlineFormattingContext::InlineLayout::formattingContext const):
     56        (WebCore::Layout::InlineFormattingContext::InlineLayout::formattingRoot const):
     57        (WebCore::Layout::InlineFormattingContext::Quirks::formattingContext const):
     58        (WebCore::Layout::InlineFormattingContext::quirks const):
     59        (WebCore::Layout::InlineFormattingContext::Geometry::formattingContext const):
     60        (WebCore::Layout::InlineFormattingContext::geometry const):
     61        (WebCore::Layout::InlineFormattingContext::Geometry::Geometry):
     62        (WebCore::Layout::InlineFormattingContext::Quirks::Quirks):
     63        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
     64        (WebCore::Layout::LineLayout::LineLayout):
     65        (WebCore::Layout::InlineFormattingContext::InlineLayout::InlineLayout):
     66        (WebCore::Layout::InlineFormattingContext::InlineLayout::layout const):
     67        (WebCore::Layout::InlineFormattingContext::InlineLayout::computedIntrinsicWidth const):
     68        (WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const):
     69        * layout/inlineformatting/InlineLine.cpp:
     70        (WebCore::Layout::Line::Line):
     71        (WebCore::Layout::Line::isVisuallyEmpty const):
     72        (WebCore::Layout::Line::close):
     73        (WebCore::Layout::Line::appendNonReplacedInlineBox):
     74        (WebCore::Layout::Line::adjustBaselineAndLineHeight):
     75        (WebCore::Layout::Line::inlineItemContentHeight const):
     76        (WebCore::Layout::Line::layoutState const):
     77        (WebCore::Layout::Line::formattingContext const):
     78        * layout/inlineformatting/InlineLine.h:
     79        * layout/tableformatting/TableFormattingContext.h:
     80        (WebCore::Layout::TableFormattingContext::Geometry::formattingContext const):
     81        (WebCore::Layout::TableFormattingContext::geometry const):
     82        (WebCore::Layout::TableFormattingContext::Geometry::Geometry):
     83        * page/FrameViewLayoutContext.cpp:
     84        (WebCore::layoutUsingFormattingContext):
     85
    1862019-08-30  Ryan Haddad  <ryanhaddad@apple.com>
    287
  • trunk/Source/WebCore/layout/FormattingContext.h

    r249331 r249349  
    2929
    3030#include "DisplayBox.h"
     31#include "LayoutBox.h"
    3132#include <wtf/IsoMalloc.h>
    3233#include <wtf/WeakPtr.h>
     
    3940namespace Layout {
    4041
    41 class Box;
    4242class Container;
    4343class FormattingState;
     
    6969    static Point mapPointToDescendent(const LayoutState&, Point, const Container& from, const Container& to);
    7070
     71    bool isBlockFormattingContext() const { return root().establishesBlockFormattingContext(); }
     72    bool isInlineFormattingContext() const { return root().establishesInlineFormattingContext(); }
     73    bool isTableFormattingContext() const { return root().establishesTableFormattingContext(); }
     74
    7175protected:
    7276    using LayoutQueue = Vector<const Box*>;
     
    8589    class Geometry {
    8690    public:
    87         Geometry(LayoutState&);
     91        Geometry(const FormattingContext&);
    8892
    8993        VerticalGeometry outOfFlowVerticalGeometry(const Box&, UsedVerticalValues) const;
     
    121125        Optional<LayoutUnit> computedHeightValue(const Box&, HeightType) const;
    122126
    123         const LayoutState& layoutState() const { return m_layoutState; }
    124         LayoutState& layoutState() { return m_layoutState; }
     127        const LayoutState& layoutState() const { return m_formattingContext.layoutState(); }
     128        LayoutState& layoutState() { return m_formattingContext.layoutState(); }
     129        const FormattingContext& formattingContext() const { return m_formattingContext; }
    125130
    126131    private:
     
    139144        LayoutUnit staticHorizontalPositionForOutOfFlowPositioned(const Box&) const;
    140145
    141         LayoutState& m_layoutState;
     146        const FormattingContext& m_formattingContext;
    142147    };
    143     FormattingContext::Geometry geometry() const { return Geometry(layoutState()); }
     148    FormattingContext::Geometry geometry() const { return Geometry(*this); }
    144149
    145150    class Quirks {
    146151    public:
    147         Quirks(LayoutState&);
     152        Quirks(const FormattingContext&);
    148153
    149154        LayoutUnit heightValueOfNearestContainingBlockWithFixedHeight(const Box&);
    150155
    151156    protected:
    152         const LayoutState& layoutState() const { return m_layoutState; }
    153         LayoutState& layoutState() { return m_layoutState; }
    154 
    155         LayoutState& m_layoutState;
     157        const LayoutState& layoutState() const { return m_formattingContext.layoutState(); }
     158        LayoutState& layoutState() { return m_formattingContext.layoutState(); }
     159        const FormattingContext& formattingContext() const { return m_formattingContext; }
     160
     161        const FormattingContext& m_formattingContext;
    156162    };
    157     FormattingContext::Quirks quirks() const { return Quirks(layoutState()); }
     163    FormattingContext::Quirks quirks() const { return Quirks(*this); }
    158164
    159165private:
     
    165171};
    166172
    167 inline FormattingContext::Geometry::Geometry(LayoutState& layoutState)
    168     : m_layoutState(layoutState)
    169 {
    170 }
    171 
    172 inline FormattingContext::Quirks::Quirks(LayoutState& layoutState)
    173     : m_layoutState(layoutState)
     173inline FormattingContext::Geometry::Geometry(const FormattingContext& formattingContext)
     174    : m_formattingContext(formattingContext)
     175{
     176}
     177
     178inline FormattingContext::Quirks::Quirks(const FormattingContext& formattingContext)
     179    : m_formattingContext(formattingContext)
    174180{
    175181}
     
    190196}
    191197}
     198
     199#define SPECIALIZE_TYPE_TRAITS_LAYOUT_FORMATTING_CONTEXT(ToValueTypeName, predicate) \
     200SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Layout::ToValueTypeName) \
     201    static bool isType(const WebCore::Layout::FormattingContext& formattingContext) { return formattingContext.predicate; } \
     202SPECIALIZE_TYPE_TRAITS_END()
     203
    192204#endif
  • trunk/Source/WebCore/layout/FormattingContextGeometry.cpp

    r249331 r249349  
    7777    } else {
    7878        if (layoutState.inQuirksMode())
    79             containingBlockHeightValue = Quirks(const_cast<LayoutState&>(layoutState)).heightValueOfNearestContainingBlockWithFixedHeight(layoutBox);
     79            containingBlockHeightValue = Quirks(formattingContext()).heightValueOfNearestContainingBlockWithFixedHeight(layoutBox);
    8080        else {
    8181            auto containingBlockHeight = layoutBox.containingBlock()->style().logicalHeight();
  • trunk/Source/WebCore/layout/FormattingContextQuirks.cpp

    r249331 r249349  
    5454
    5555            auto usedValues = UsedHorizontalValues { layoutState.displayBoxForLayoutBox(*containingBlock->containingBlock()).contentBoxWidth() };
    56             auto verticalMargin = Geometry(layoutState).computedVerticalMargin(*containingBlock, usedValues);
     56            auto verticalMargin = Geometry(formattingContext()).computedVerticalMargin(*containingBlock, usedValues);
    5757            auto verticalPadding = displayBox.paddingTop().valueOr(0) + displayBox.paddingBottom().valueOr(0);
    5858            auto verticalBorder = displayBox.borderTop() + displayBox.borderBottom();
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h

    r249331 r249349  
    7676    class Geometry : public FormattingContext::Geometry {
    7777    public:
    78         Geometry(LayoutState&);
     78        Geometry(const BlockFormattingContext&);
    7979
    8080        HeightAndMargin inFlowHeightAndMargin(const Box&, UsedVerticalValues);
     
    9292        WidthAndMargin inFlowReplacedWidthAndMargin(const Box&, UsedHorizontalValues) const;
    9393        Point staticPositionForOutOfFlowPositioned(const Box&) const;
     94
     95        const BlockFormattingContext& formattingContext() const { return downcast<BlockFormattingContext>(FormattingContext::Geometry::formattingContext()); }
    9496    };
    95     BlockFormattingContext::Geometry geometry() const { return Geometry(layoutState()); }
     97    BlockFormattingContext::Geometry geometry() const { return Geometry(*this); }
    9698
    9799    // This class implements margin collapsing for block formatting context.
    98100    class MarginCollapse {
    99101    public:
    100         MarginCollapse(LayoutState&);
     102        MarginCollapse(const BlockFormattingContext&);
    101103
    102104        UsedVerticalMargin::CollapsedValues collapsedVerticalValues(const Box&, const UsedVerticalMargin::NonCollapsedValues&);
     
    126128        PositiveAndNegativeVerticalMargin::Values positiveNegativeMarginAfter(const Box&, const UsedVerticalMargin::NonCollapsedValues&);
    127129
    128         LayoutState& layoutState() { return m_layoutState; }
    129         const LayoutState& layoutState() const { return m_layoutState; }
     130        LayoutState& layoutState() { return m_blockFormattingContext.layoutState(); }
     131        const LayoutState& layoutState() const { return m_blockFormattingContext.layoutState(); }
     132        const BlockFormattingContext& formattingContext() const { return m_blockFormattingContext; }
    130133
    131         LayoutState& m_layoutState;
     134        const BlockFormattingContext& m_blockFormattingContext;
    132135    };
    133     MarginCollapse marginCollapse() const { return MarginCollapse(layoutState()); }
     136    MarginCollapse marginCollapse() const { return MarginCollapse(*this); }
    134137
    135138    class Quirks : public FormattingContext::Quirks {
    136139    public:
    137         Quirks(LayoutState&);
     140        Quirks(const BlockFormattingContext&);
    138141
    139142        bool needsStretching(const Box&) const;
     
    143146        bool shouldIgnoreMarginBefore(const Box&) const;
    144147        bool shouldIgnoreMarginAfter(const Box&) const;
     148
     149    private:
     150        const BlockFormattingContext& formattingContext() const { return downcast<BlockFormattingContext>(FormattingContext::Quirks::formattingContext()); }
     151
    145152    };
    146     BlockFormattingContext::Quirks quirks() const { return Quirks(layoutState()); }
     153    BlockFormattingContext::Quirks quirks() const { return Quirks(*this); }
    147154
    148155    void setEstimatedMarginBefore(const Box&, const EstimatedMarginBefore&);
     
    161168};
    162169
    163 inline BlockFormattingContext::Geometry::Geometry(LayoutState& layoutState)
    164     : FormattingContext::Geometry(layoutState)
     170inline BlockFormattingContext::Geometry::Geometry(const BlockFormattingContext& blockFormattingContext)
     171    : FormattingContext::Geometry(blockFormattingContext)
    165172{
    166173}
    167174
    168 inline BlockFormattingContext::Quirks::Quirks(LayoutState& layoutState)
    169     : FormattingContext::Quirks(layoutState)
     175inline BlockFormattingContext::Quirks::Quirks(const BlockFormattingContext& blockFormattingContext)
     176    : FormattingContext::Quirks(blockFormattingContext)
    170177{
    171178}
    172179
    173 inline BlockFormattingContext::MarginCollapse::MarginCollapse(LayoutState& layoutState)
    174     : m_layoutState(layoutState)
     180inline BlockFormattingContext::MarginCollapse::MarginCollapse(const BlockFormattingContext& blockFormattingContext)
     181    : m_blockFormattingContext(blockFormattingContext)
    175182{
    176183}
     
    178185}
    179186}
     187
     188SPECIALIZE_TYPE_TRAITS_LAYOUT_FORMATTING_CONTEXT(BlockFormattingContext, isBlockFormattingContext())
     189
    180190#endif
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp

    r249331 r249349  
    8686        auto* lastInFlowChild = downcast<Container>(layoutBox).lastInFlowChild();
    8787        ASSERT(lastInFlowChild);
    88         auto marginCollapse = MarginCollapse(layoutState);
     88        auto marginCollapse = MarginCollapse(formattingContext());
    8989        if (!marginCollapse.marginAfterCollapsesWithParentMarginAfter(*lastInFlowChild)) {
    9090            auto& lastInFlowDisplayBox = layoutState.displayBoxForLayoutBox(*lastInFlowChild);
     
    274274    }
    275275
    276     auto quirks = Quirks(layoutState());
     276    auto quirks = Quirks(formattingContext());
    277277    if (!quirks.needsStretching(layoutBox))
    278278        return heightAndMargin;
  • trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextQuirks.cpp

    r249331 r249349  
    8383        // Stretch the body using the initial containing block's height and shrink it with document box's margin/border/padding.
    8484        // This looks extremely odd when html has non-auto height.
    85         auto documentBoxVerticalMargin = Geometry(layoutState).computedVerticalMargin(documentBox, UsedHorizontalValues { initialContainingBlockDisplayBox.contentBoxWidth() });
     85        auto documentBoxVerticalMargin = Geometry(formattingContext()).computedVerticalMargin(documentBox, UsedHorizontalValues { initialContainingBlockDisplayBox.contentBoxWidth() });
    8686        strechedHeight -= (documentBoxVerticalMargin.before.valueOr(0) + documentBoxVerticalMargin.after.valueOr(0));
    8787
     
    9090
    9191        auto nonCollapsedMargin = heightAndMargin.nonCollapsedMargin;
    92         auto collapsedMargin = MarginCollapse(layoutState).collapsedVerticalValues(layoutBox, nonCollapsedMargin);
     92        auto collapsedMargin = MarginCollapse(formattingContext()).collapsedVerticalValues(layoutBox, nonCollapsedMargin);
    9393        totalVerticalMargin = collapsedMargin.before.valueOr(nonCollapsedMargin.before);
    9494        totalVerticalMargin += collapsedMargin.isCollapsedThrough ? nonCollapsedMargin.after : collapsedMargin.after.valueOr(nonCollapsedMargin.after);
  • trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp

    r249331 r249349  
    516516    // This is the estimate path. We don't yet have positive/negative margin computed.
    517517    auto usedValues = UsedHorizontalValues { layoutState.displayBoxForLayoutBox(*layoutBox.containingBlock()).contentBoxWidth() };
    518     auto computedVerticalMargin = Geometry(layoutState).computedVerticalMargin(layoutBox, usedValues);
     518    auto computedVerticalMargin = Geometry(formattingContext()).computedVerticalMargin(layoutBox, usedValues);
    519519    auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
    520520
     
    542542    // 3. Compute min/max positive and negative collapsed margin values using non-collpased computed margin before.
    543543    auto collapsedMarginBefore = computedPositiveAndNegativeMargin(firstChildCollapsedMarginBefore(), previouSiblingCollapsedMarginAfter());
    544     if (collapsedMarginBefore.isQuirk && Quirks(layoutState()).shouldIgnoreCollapsedQuirkMargin(layoutBox))
     544    if (collapsedMarginBefore.isQuirk && Quirks(formattingContext()).shouldIgnoreCollapsedQuirkMargin(layoutBox))
    545545        collapsedMarginBefore = { };
    546546
     
    584584
    585585    auto usedValues = UsedHorizontalValues { layoutState().displayBoxForLayoutBox(*layoutBox.containingBlock()).contentBoxWidth() };
    586     auto computedVerticalMargin = Geometry(layoutState()).computedVerticalMargin(layoutBox, usedValues);
     586    auto computedVerticalMargin = Geometry(formattingContext()).computedVerticalMargin(layoutBox, usedValues);
    587587    auto nonCollapsedMargin = UsedVerticalMargin::NonCollapsedValues { computedVerticalMargin.before.valueOr(0), computedVerticalMargin.after.valueOr(0) };
    588588    auto marginsCollapseThrough = this->marginsCollapseThrough(layoutBox);
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h

    r249331 r249349  
    5959
    6060    private:
    61         LayoutState& layoutState() const { return m_layoutState; }
     61        LayoutState& layoutState() const { return m_inlineFormattingContext.layoutState(); }
     62        const InlineFormattingContext& formattingContext() const { return m_inlineFormattingContext; }
     63        const Container& formattingRoot() const { return downcast<Container>(m_inlineFormattingContext.root()); }
    6264        LineContent placeInlineItems(const LineInput&) const;
    6365        void createDisplayRuns(const Line::Content&, const Vector<WeakPtr<InlineItem>>& floats, LayoutUnit widthConstraint) const;
     
    6567
    6668    private:
    67         LayoutState& m_layoutState;
    68         const Container& m_formattingRoot;
     69        const InlineFormattingContext& m_inlineFormattingContext;
    6970    };
    7071
    7172    class Quirks : public FormattingContext::Quirks {
    7273    public:
    73         Quirks(LayoutState&);
     74        Quirks(const InlineFormattingContext&);
    7475
    7576        bool lineDescentNeedsCollapsing(const Line::Content&) const;
    7677        Line::InitialConstraints::HeightAndBaseline lineHeightConstraints(const Box& formattingRoot) const;
     78
     79    private:
     80        const InlineFormattingContext& formattingContext() const { return downcast<InlineFormattingContext>(FormattingContext::Quirks::formattingContext()); }
     81
    7782    };
    78     InlineFormattingContext::Quirks quirks() const { return Quirks(layoutState()); }
     83    InlineFormattingContext::Quirks quirks() const { return Quirks(*this); }
    7984
    8085    class Geometry : public FormattingContext::Geometry {
    8186    public:
    82         Geometry(LayoutState&);
     87        Geometry(const InlineFormattingContext&);
    8388
    8489        HeightAndMargin inlineBlockHeightAndMargin(const Box&) const;
    8590        WidthAndMargin inlineBlockWidthAndMargin(const Box&, UsedHorizontalValues);
     91
     92    private:
     93        const InlineFormattingContext& formattingContext() const { return downcast<InlineFormattingContext>(FormattingContext::Geometry::formattingContext()); }
     94
    8695    };
    87     InlineFormattingContext::Geometry geometry() const { return Geometry(layoutState()); }
     96    InlineFormattingContext::Geometry geometry() const { return Geometry(*this); }
    8897
    8998    void layoutFormattingContextRoot(const Box&, UsedHorizontalValues);
     
    103112};
    104113
    105 inline InlineFormattingContext::Geometry::Geometry(LayoutState& layoutState)
    106     : FormattingContext::Geometry(layoutState)
     114inline InlineFormattingContext::Geometry::Geometry(const InlineFormattingContext& inlineFormattingContext)
     115    : FormattingContext::Geometry(inlineFormattingContext)
    107116{
    108117}
    109118
    110 inline InlineFormattingContext::Quirks::Quirks(LayoutState& layoutState)
    111     : FormattingContext::Quirks(layoutState)
     119inline InlineFormattingContext::Quirks::Quirks(const InlineFormattingContext& inlineFormattingContext)
     120    : FormattingContext::Quirks(inlineFormattingContext)
    112121{
    113122}
     
    115124}
    116125}
     126
     127SPECIALIZE_TYPE_TRAITS_LAYOUT_FORMATTING_CONTEXT(InlineFormattingContext, isInlineFormattingContext())
     128
    117129#endif
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp

    r249331 r249349  
    101101class LineLayout {
    102102public:
    103     LineLayout(LayoutState&, const LineInput&);
     103    LineLayout(const InlineFormattingContext&, LayoutState&, const LineInput&);
    104104
    105105    LineContent layout();
     
    154154}
    155155
    156 LineLayout::LineLayout(LayoutState& layoutState, const LineInput& lineInput)
     156LineLayout::LineLayout(const InlineFormattingContext& inlineFormattingContext, LayoutState& layoutState, const LineInput& lineInput)
    157157    : m_layoutState(layoutState)
    158158    , m_lineInput(lineInput)
    159     , m_line(layoutState, lineInput.initialConstraints, lineInput.skipVerticalAligment)
     159    , m_line(inlineFormattingContext, lineInput.initialConstraints, lineInput.skipVerticalAligment)
    160160    , m_lineHasFloatBox(lineInput.floatMinimumLogicalBottom.hasValue())
    161161{
     
    273273
    274274InlineFormattingContext::InlineLayout::InlineLayout(const InlineFormattingContext& inlineFormattingContext)
    275     : m_layoutState(inlineFormattingContext.layoutState())
    276     , m_formattingRoot(downcast<Container>(inlineFormattingContext.root()))
     275    : m_inlineFormattingContext(inlineFormattingContext)
    277276{
    278277}
     
    281280{
    282281    auto& layoutState = this->layoutState();
    283     auto& formattingRootDisplayBox = layoutState.displayBoxForLayoutBox(m_formattingRoot);
    284     auto& floatingState = layoutState.establishedFormattingState(m_formattingRoot).floatingState();
     282    auto& formattingRoot = this->formattingRoot();
     283    auto& formattingRootDisplayBox = layoutState.displayBoxForLayoutBox(formattingRoot);
     284    auto& floatingState = layoutState.establishedFormattingState(formattingRoot).floatingState();
    285285
    286286    auto lineLogicalTop = formattingRootDisplayBox.contentBoxTop();
     
    293293        auto availableWidth = lineInput.initialConstraints.availableLogicalWidth;
    294294        auto lineLogicalLeft = lineInput.initialConstraints.logicalTopLeft.x();
    295         auto floatConstraints = floatingState.constraints({ lineLogicalTop }, m_formattingRoot);
     295        auto floatConstraints = floatingState.constraints({ lineLogicalTop }, formattingRoot);
    296296        // Check if these constraints actually put limitation on the line.
    297297        if (floatConstraints.left && floatConstraints.left->x <= formattingRootDisplayBox.contentBoxLeft())
     
    324324
    325325    IndexAndRange currentInlineItem;
    326     auto quirks = Quirks(layoutState);
     326    auto quirks = Quirks(formattingContext());
    327327    while (currentInlineItem.index < inlineItems.size()) {
    328         auto lineInput = LineInput { { { lineLogicalLeft, lineLogicalTop }, widthConstraint, quirks.lineHeightConstraints(m_formattingRoot) }, Line::SkipVerticalAligment::No, currentInlineItem, inlineItems };
     328        auto lineInput = LineInput { { { lineLogicalLeft, lineLogicalTop }, widthConstraint, quirks.lineHeightConstraints(formattingRoot) }, Line::SkipVerticalAligment::No, currentInlineItem, inlineItems };
    329329        applyFloatConstraint(lineInput);
    330         auto lineContent = LineLayout(layoutState, lineInput).layout();
     330        auto lineContent = LineLayout(formattingContext(), layoutState, lineInput).layout();
    331331        createDisplayRuns(*lineContent.runs, lineContent.floats, widthConstraint);
    332332        if (!lineContent.lastCommitted) {
     
    347347    LayoutUnit maximumLineWidth;
    348348    IndexAndRange currentInlineItem;
    349     auto quirks = Quirks(layoutState);
     349    auto quirks = Quirks(formattingContext());
    350350    while (currentInlineItem.index < inlineItems.size()) {
    351         auto lineContent = LineLayout(layoutState, { { { }, widthConstraint, quirks.lineHeightConstraints(m_formattingRoot) }, Line::SkipVerticalAligment::Yes, currentInlineItem, inlineItems }).layout();
     351        auto lineContent = LineLayout(formattingContext(), layoutState, { { { }, widthConstraint, quirks.lineHeightConstraints(formattingRoot()) }, Line::SkipVerticalAligment::Yes, currentInlineItem, inlineItems }).layout();
    352352        currentInlineItem = { lineContent.lastCommitted->index + 1, WTF::nullopt };
    353353        LayoutUnit floatsWidth;
     
    362362{
    363363    auto& layoutState = this->layoutState();
    364     auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(m_formattingRoot));
     364    auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(formattingRoot()));
    365365    auto& floatingState = formattingState.floatingState();
    366366    auto floatingContext = FloatingContext { floatingState };
     
    392392    // Create final display runs.
    393393    auto& lineRuns = lineContent.runs();
    394     auto geometry = Geometry(layoutState);
     394    auto geometry = Geometry(formattingContext());
    395395    for (unsigned index = 0; index < lineRuns.size(); ++index) {
    396396        auto& lineRun = lineRuns.at(index);
     
    471471    // FIXME linebox needs to be ajusted after content alignment.
    472472    formattingState.addLineBox({ lineBoxRect, lineContent.baseline(), lineContent.baselineOffset() });
    473     alignRuns(m_formattingRoot.style().textAlign(), inlineDisplayRuns, previousLineLastRunIndex.valueOr(-1) + 1, widthConstraint - lineContent.logicalWidth());
     473    alignRuns(formattingRoot().style().textAlign(), inlineDisplayRuns, previousLineLastRunIndex.valueOr(-1) + 1, widthConstraint - lineContent.logicalWidth());
    474474}
    475475
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r249331 r249349  
    5353}
    5454
    55 Line::Line(LayoutState& layoutState, const InitialConstraints& initialConstraints, SkipVerticalAligment skipVerticalAligment)
    56     : m_layoutState(layoutState)
     55Line::Line(const InlineFormattingContext& inlineFormattingContext, const InitialConstraints& initialConstraints, SkipVerticalAligment skipVerticalAligment)
     56    : m_inlineFormattingContext(inlineFormattingContext)
    5757    , m_content(makeUnique<Line::Content>())
    5858    , m_logicalTopLeft(initialConstraints.logicalTopLeft)
     
    7676    // FIXME: This should be cached instead -as the inline items are being added.
    7777    // Return true for empty inline containers like <span></span>.
     78    auto& layoutState = this->layoutState();
    7879    for (auto& run : m_content->runs()) {
    7980        if (run->isContainerStart()) {
    80             if (!isInlineContainerConsideredEmpty(m_layoutState, run->layoutBox()))
     81            if (!isInlineContainerConsideredEmpty(layoutState, run->layoutBox()))
    8182                return false;
    8283            continue;
     
    8687        if (run->layoutBox().establishesFormattingContext()) {
    8788            ASSERT(run->layoutBox().isInlineBlockBox());
    88             auto& displayBox = m_layoutState.displayBoxForLayoutBox(run->layoutBox());
     89            auto& displayBox = layoutState.displayBoxForLayoutBox(run->layoutBox());
    8990            if (!displayBox.width())
    9091                continue;
     
    110111
    111112        // Remove descent when all content is baseline aligned but none of them have descent.
    112         if (InlineFormattingContext::Quirks(m_layoutState).lineDescentNeedsCollapsing(*m_content)) {
     113        if (InlineFormattingContext::Quirks(formattingContext()).lineDescentNeedsCollapsing(*m_content)) {
    113114            m_lineLogicalHeight -= m_baseline.descent;
    114115            m_baseline.descent = { };
    115116        }
    116117
     118        auto& layoutState = this->layoutState();
    117119        for (auto& run : m_content->runs()) {
    118120            LayoutUnit logicalTop;
     
    126128                    logicalTop = baselineOffset() - ascent;
    127129                else if (run->isContainerStart()) {
    128                     auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);
     130                    auto& displayBox = layoutState.displayBoxForLayoutBox(layoutBox);
    129131                    logicalTop = baselineOffset() - ascent - displayBox.borderTop() - displayBox.paddingTop().valueOr(0);
    130132                } else if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) {
    131                     auto& formattingState = downcast<InlineFormattingState>(m_layoutState.establishedFormattingState(layoutBox));
     133                    auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(layoutBox));
    132134                    // Spec makes us generate at least one line -even if it is empty.
    133135                    ASSERT(!formattingState.lineBoxes().isEmpty());
     
    293295void Line::appendNonReplacedInlineBox(const InlineItem& inlineItem, LayoutUnit logicalWidth)
    294296{
    295     auto& displayBox = m_layoutState.displayBoxForLayoutBox(inlineItem.layoutBox());
     297    auto& displayBox = layoutState().displayBoxForLayoutBox(inlineItem.layoutBox());
    296298    auto horizontalMargin = displayBox.horizontalMargin();   
    297299    auto logicalRect = Display::Rect { };
     
    372374            if (layoutBox.isInlineBlockBox() && layoutBox.establishesInlineFormattingContext()) {
    373375                // Inline-blocks with inline content always have baselines.
    374                 auto& formattingState = downcast<InlineFormattingState>(m_layoutState.establishedFormattingState(layoutBox));
     376                auto& formattingState = downcast<InlineFormattingState>(layoutState().establishedFormattingState(layoutBox));
    375377                // Spec makes us generate at least one line -even if it is empty.
    376378                ASSERT(!formattingState.lineBoxes().isEmpty());
     
    412414
    413415    auto& layoutBox = inlineItem.layoutBox();
    414     ASSERT(m_layoutState.hasDisplayBox(layoutBox));
    415     auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);
     416    ASSERT(layoutState().hasDisplayBox(layoutBox));
     417    auto& displayBox = layoutState().displayBoxForLayoutBox(layoutBox);
    416418
    417419    if (layoutBox.isFloatingPositioned())
     
    440442}
    441443
     444LayoutState& Line::layoutState() const
     445{
     446    return formattingContext().layoutState();
     447}
     448
     449const InlineFormattingContext& Line::formattingContext() const
     450{
     451    return m_inlineFormattingContext;
     452}
     453
    442454}
    443455}
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r249331 r249349  
    3636namespace Layout {
    3737
     38class InlineFormattingContext;
     39
    3840class Line {
    3941    WTF_MAKE_ISO_ALLOCATED(Line);
     
    5052    };
    5153    enum class SkipVerticalAligment { No, Yes };
    52     Line(LayoutState&, const InitialConstraints&, SkipVerticalAligment);
     54    Line(const InlineFormattingContext&, const InitialConstraints&, SkipVerticalAligment);
    5355
    5456    class Content {
     
    157159    bool isVisuallyEmpty() const;
    158160
    159     LayoutState& m_layoutState;
     161    LayoutState& layoutState() const;
     162    const InlineFormattingContext& formattingContext() const;
     163
     164    const InlineFormattingContext& m_inlineFormattingContext;
    160165    std::unique_ptr<Content> m_content;
    161166    ListHashSet<Content::Run*> m_trimmableContent;
  • trunk/Source/WebCore/layout/tableformatting/TableFormattingContext.h

    r249331 r249349  
    4646    class Geometry : public FormattingContext::Geometry {
    4747    public:
    48         Geometry(LayoutState&);
     48        Geometry(const TableFormattingContext&);
    4949
    5050        HeightAndMargin tableCellHeightAndMargin(const Box&) const;
     51
     52    private:
     53        const TableFormattingContext& formattingContext() const { return downcast<TableFormattingContext>(FormattingContext::Geometry::formattingContext()); }
    5154    };
    52     TableFormattingContext::Geometry geometry() const { return Geometry(layoutState()); }
     55    TableFormattingContext::Geometry geometry() const { return Geometry(*this); }
    5356
    5457    IntrinsicWidthConstraints computedIntrinsicWidthConstraints() override;
     
    6467};
    6568
    66 inline TableFormattingContext::Geometry::Geometry(LayoutState& layoutState)
    67     : FormattingContext::Geometry(layoutState)
     69inline TableFormattingContext::Geometry::Geometry(const TableFormattingContext& tableFormattingContext)
     70    : FormattingContext::Geometry(tableFormattingContext)
    6871{
    6972}
     
    7174}
    7275}
     76
     77SPECIALIZE_TYPE_TRAITS_LAYOUT_FORMATTING_CONTEXT(TableFormattingContext, isTableFormattingContext())
     78
    7379#endif
Note: See TracChangeset for help on using the changeset viewer.