Changeset 240975 in webkit


Ignore:
Timestamp:
Feb 5, 2019 8:01:30 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] collectInlineContent should use pre-computed margins, paddings and borders
https://bugs.webkit.org/show_bug.cgi?id=194269

Reviewed by Antti Koivisto.

In this patch we pre-compute the margins padding and borders for formatting context roots, replaced boxes and non-replaced containers.
These property values are input to collectInlineContent's inline item detaching logic.

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::nextInPreOrder):
(WebCore::Layout::InlineFormattingContext::layout const):
(WebCore::Layout::InlineFormattingContext::computeMarginBorderAndPadding const):
(WebCore::Layout::InlineFormattingContext::collectInlineContent const):

  • layout/inlineformatting/InlineFormattingContext.h:
  • layout/layouttree/LayoutBox.h: ran out bits.
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r240971 r240975  
     12019-02-05  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] collectInlineContent should use pre-computed margins, paddings and borders
     4        https://bugs.webkit.org/show_bug.cgi?id=194269
     5
     6        Reviewed by Antti Koivisto.
     7
     8        In this patch we pre-compute the margins padding and borders for formatting context roots, replaced boxes and non-replaced containers.
     9        These property values are input to collectInlineContent's inline item detaching logic.
     10
     11        * layout/inlineformatting/InlineFormattingContext.cpp:
     12        (WebCore::Layout::nextInPreOrder):
     13        (WebCore::Layout::InlineFormattingContext::layout const):
     14        (WebCore::Layout::InlineFormattingContext::computeMarginBorderAndPadding const):
     15        (WebCore::Layout::InlineFormattingContext::collectInlineContent const):
     16        * layout/inlineformatting/InlineFormattingContext.h:
     17        * layout/layouttree/LayoutBox.h: ran out bits.
     18
    1192019-02-05  Antoine Quint  <graouts@apple.com>
    220
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r240924 r240975  
    5454}
    5555
     56static inline const Box* nextInPreOrder(const Box& layoutBox, const Container& root)
     57{
     58    const Box* nextInPreOrder = nullptr;
     59    if (!layoutBox.establishesFormattingContext() && is<Container>(layoutBox) && downcast<Container>(layoutBox).hasInFlowOrFloatingChild())
     60        return downcast<Container>(layoutBox).firstInFlowOrFloatingChild();
     61
     62    for (nextInPreOrder = &layoutBox; nextInPreOrder && nextInPreOrder != &root; nextInPreOrder = nextInPreOrder->parent()) {
     63        if (auto* nextSibling = nextInPreOrder->nextInFlowOrFloatingSibling())
     64            return nextSibling;
     65    }
     66    return nullptr;
     67}
     68
    5669void InlineFormattingContext::layout() const
    5770{
     
    6073
    6174    LOG_WITH_STREAM(FormattingContextLayout, stream << "[Start] -> inline formatting context -> formatting root(" << &root() << ")");
     75    auto& root = downcast<Container>(this->root());
     76    auto* layoutBox = root.firstInFlowOrFloatingChild();
     77    // Compute width/height for non-text content and margin/border/padding for inline containers.
     78    while (layoutBox) {
     79        if (layoutBox->establishesFormattingContext())
     80            layoutFormattingContextRoot(*layoutBox);
     81        else if (is<Container>(*layoutBox))
     82            computeMarginBorderAndPadding(downcast<InlineContainer>(*layoutBox));
     83        else if (layoutBox->isReplaced())
     84            computeWidthAndHeightForReplacedInlineBox(*layoutBox);
     85        layoutBox = nextInPreOrder(*layoutBox, root);
     86    }
    6287
    6388    InlineRunProvider inlineRunProvider;
    6489    collectInlineContent(inlineRunProvider);
    65     // Compute width/height for non-text content.
    66     for (auto& inlineRun : inlineRunProvider.runs()) {
    67         if (inlineRun.isText())
    68             continue;
    69 
    70         auto& layoutBox = inlineRun.inlineItem().layoutBox();
    71         if (layoutBox.establishesFormattingContext()) {
    72             layoutFormattingContextRoot(layoutBox);
    73             continue;
    74         }
    75         computeWidthAndHeightForReplacedInlineBox(layoutBox);
    76     }
    77 
    7890    layoutInlineContent(inlineRunProvider);
    79     LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root() << ")");
     91    LOG_WITH_STREAM(FormattingContextLayout, stream << "[End] -> inline formatting context -> formatting root(" << &root << ")");
    8092}
    8193
     
    330342}
    331343
     344void InlineFormattingContext::computeMarginBorderAndPadding(const InlineContainer& inlineContainer) const
     345{
     346    // Non-replaced, non-formatting root containers (<span></span>) don't have width property -> non width computation.
     347    ASSERT(!inlineContainer.replaced());
     348    ASSERT(!inlineContainer.establishesFormattingContext());
     349
     350    computeBorderAndPadding(inlineContainer);
     351    auto& displayBox = layoutState().displayBoxForLayoutBox(inlineContainer);
     352    auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutState(), inlineContainer);
     353    displayBox.setHorizontalComputedMargin(computedHorizontalMargin);
     354    displayBox.setHorizontalMargin({ computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) });
     355}
     356
    332357void InlineFormattingContext::computeWidthAndMargin(const Box& layoutBox) const
    333358{
     
    471496    enum class NonBreakableWidthType { Start, End };
    472497    auto nonBreakableWidth = [&](auto& container, auto type) {
    473         auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutState, container);
    474         auto horizontalMargin = UsedHorizontalMargin { computedHorizontalMargin.start.valueOr(0), computedHorizontalMargin.end.valueOr(0) };
    475         auto border = Geometry::computedBorder(layoutState, container);
    476         auto padding = Geometry::computedPadding(layoutState, container);
    477 
     498        auto& displayBox = layoutState.displayBoxForLayoutBox(container);
    478499        if (type == NonBreakableWidthType::Start)
    479             return border.horizontal.left + horizontalMargin.start + (padding ? padding->horizontal.left : LayoutUnit());
    480         return border.horizontal.right + horizontalMargin.end + (padding ? padding->horizontal.right : LayoutUnit());
     500            return displayBox.marginStart() + displayBox.borderLeft() + displayBox.paddingLeft().valueOr(0);
     501        return displayBox.marginEnd() + displayBox.borderRight() + displayBox.paddingRight().valueOr(0);
    481502    };
    482503
     
    497518                // Formatting contexts are treated as leaf nodes.
    498519                auto& inlineItem = createAndAppendInlineItem(inlineRunProvider, inlineContent, container);
    499                 auto computedHorizontalMargin = Geometry::computedHorizontalMargin(layoutState, container);
    500                 auto currentNonBreakableStartWidth = nonBreakableStartWidth.valueOr(0) + computedHorizontalMargin.start.valueOr(0) + nonBreakableEndWidth.valueOr(0);
    501                 addDetachingRules(inlineItem, currentNonBreakableStartWidth, computedHorizontalMargin.end);
     520                auto& displayBox = layoutState.displayBoxForLayoutBox(container);
     521                auto currentNonBreakableStartWidth = nonBreakableStartWidth.valueOr(0) + displayBox.marginStart() + nonBreakableEndWidth.valueOr(0);
     522                addDetachingRules(inlineItem, currentNonBreakableStartWidth, displayBox.marginEnd());
    502523                nonBreakableStartWidth = { };
    503524                nonBreakableEndWidth = { };
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h

    r240924 r240975  
    3636namespace Layout {
    3737
     38class InlineContainer;
    3839class InlineFormattingState;
    3940class InlineRunProvider;
     
    113114    void layoutFormattingContextRoot(const Box&) const;
    114115    void computeWidthAndHeightForReplacedInlineBox(const Box&) const;
     116    void computeMarginBorderAndPadding(const InlineContainer&) const;
    115117    void computeHeightAndMargin(const Box&) const;
    116118    void computeWidthAndMargin(const Box&) const;
  • trunk/Source/WebCore/layout/layouttree/LayoutBox.h

    r240845 r240975  
    156156    std::unique_ptr<Replaced> m_replaced;
    157157
    158     unsigned m_baseTypeFlags : 4;
     158    unsigned m_baseTypeFlags : 5;
    159159};
    160160
Note: See TracChangeset for help on using the changeset viewer.