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

Changeset 245962 in webkit


Ignore:
Timestamp:
May 31, 2019, 6:43:37 AM (7 years ago)
Author:
Alan Bujtas
Message:

[LFC[IFC] Do not reuse the same Line object.
https://bugs.webkit.org/show_bug.cgi?id=198366
<rdar://problem/51250279>

Reviewed by Antti Koivisto.

This is in preparation for constructing Line inside createInlineRunsForLine and return Line::Content.

  • layout/inlineformatting/InlineFormattingContext.h:
  • layout/inlineformatting/InlineFormattingContextLineLayout.cpp:

(WebCore::Layout::InlineFormattingContext::LineLayout::createLine const):
(WebCore::Layout::InlineFormattingContext::LineLayout::layout const):
(WebCore::Layout::InlineFormattingContext::LineLayout::processInlineRuns const):
(WebCore::Layout::InlineFormattingContext::LineLayout::initializeLine const): Deleted.

  • layout/inlineformatting/InlineLine.cpp:

(WebCore::Layout::Line::Line):
(WebCore::Layout::m_lineLogicalWidth):
(WebCore::Layout::Line::close):
(WebCore::Layout::Line::moveLogicalLeft):
(WebCore::Layout::Line::appendNonBreakableSpace):
(WebCore::Layout::Line::appendTextContent):
(WebCore::Layout::Line::appendNonReplacedInlineBox):
(WebCore::Layout::Line::appendHardLineBreak):
(WebCore::Layout::Line::reset): Deleted.

  • layout/inlineformatting/InlineLine.h:

(WebCore::Layout::Line::hasContent const):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r245961 r245962  
     12019-05-31  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC[IFC] Do not reuse the same Line object.
     4        https://bugs.webkit.org/show_bug.cgi?id=198366
     5        <rdar://problem/51250279>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This is in preparation for constructing Line inside createInlineRunsForLine and return Line::Content.
     10
     11        * layout/inlineformatting/InlineFormattingContext.h:
     12        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
     13        (WebCore::Layout::InlineFormattingContext::LineLayout::createLine const):
     14        (WebCore::Layout::InlineFormattingContext::LineLayout::layout const):
     15        (WebCore::Layout::InlineFormattingContext::LineLayout::processInlineRuns const):
     16        (WebCore::Layout::InlineFormattingContext::LineLayout::initializeLine const): Deleted.
     17        * layout/inlineformatting/InlineLine.cpp:
     18        (WebCore::Layout::Line::Line):
     19        (WebCore::Layout::m_lineLogicalWidth):
     20        (WebCore::Layout::Line::close):
     21        (WebCore::Layout::Line::moveLogicalLeft):
     22        (WebCore::Layout::Line::appendNonBreakableSpace):
     23        (WebCore::Layout::Line::appendTextContent):
     24        (WebCore::Layout::Line::appendNonReplacedInlineBox):
     25        (WebCore::Layout::Line::appendHardLineBreak):
     26        (WebCore::Layout::Line::reset): Deleted.
     27        * layout/inlineformatting/InlineLine.h:
     28        (WebCore::Layout::Line::hasContent const):
     29
    1302019-05-31  Zalan Bujtas  <zalan@apple.com>
    231
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h

    r245812 r245962  
    3131#include "FormattingContext.h"
    3232#include "InlineFormattingState.h"
     33#include "InlineLine.h"
    3334#include <wtf/IsoMalloc.h>
    3435
     
    3839class FloatingState;
    3940class InlineContainer;
    40 class Line;
    4141
    4242// This class implements the layout logic for inline formatting contexts.
     
    5959    private:
    6060        LayoutState& layoutState() const { return m_formattingContext.layoutState(); }
    61         void initializeLine(Line&, LayoutUnit lineLogicalTop, LayoutUnit widthConstraint) const;
     61        std::unique_ptr<Line> createLine(LayoutUnit lineLogicalTop, LayoutUnit widthConstraint) const;
    6262        unsigned createInlineRunsForLine(Line&, unsigned firstInlineItemIndex) const;
    63         void processInlineRuns(Line&) const;
     63        void processInlineRuns(const Line::Content&, LayoutUnit availableWidth) const;
    6464        void commitInlineItemToLine(Line&, const InlineItem&) const;
    6565        void handleFloat(Line&, const FloatingContext&, const InlineItem& floatBox) const;
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp

    r245961 r245962  
    7676}
    7777
    78 void InlineFormattingContext::LineLayout::initializeLine(Line& line, LayoutUnit lineLogicalTop, LayoutUnit availableWidth) const
     78std::unique_ptr<Line> InlineFormattingContext::LineLayout::createLine(LayoutUnit lineLogicalTop, LayoutUnit availableWidth) const
    7979{
    8080    auto& formattingRootDisplayBox = layoutState().displayBoxForLayoutBox(m_formattingRoot);
     
    108108    auto mimimumLineHeight = formattingRootStyle.computedLineHeight();
    109109    auto baselineOffset = Line::halfLeadingMetrics(formattingRootStyle.fontMetrics(), mimimumLineHeight).height;
    110     line.reset({ lineLogicalLeft, lineLogicalTop }, availableWidth, mimimumLineHeight, baselineOffset);
     110    return std::make_unique<Line>(layoutState(), LayoutPoint { lineLogicalLeft, lineLogicalTop }, availableWidth, mimimumLineHeight, baselineOffset);
    111111}
    112112
     
    173173    ASSERT(!m_formattingState.inlineItems().isEmpty());
    174174
    175     Line line(layoutState());
    176     initializeLine(line, layoutState().displayBoxForLayoutBox(m_formattingRoot).contentBoxTop(), widthConstraint);
    177 
    178175    unsigned startInlineItemIndex = 0;
     176    auto lineLogicalTop = layoutState().displayBoxForLayoutBox(m_formattingRoot).contentBoxTop();
    179177    while (true) {
    180         auto nextInlineItemIndex = createInlineRunsForLine(line, startInlineItemIndex);
    181         processInlineRuns(line);
     178        auto line = createLine(lineLogicalTop, widthConstraint);
     179        auto nextInlineItemIndex = createInlineRunsForLine(*line, startInlineItemIndex);
     180        auto lineContent = line->close();
     181        processInlineRuns(*lineContent, line->availableWidth());
    182182        if (nextInlineItemIndex == m_formattingState.inlineItems().size())
    183183            break;
    184184        startInlineItemIndex = nextInlineItemIndex;
    185         initializeLine(line, line.logicalBottom(), widthConstraint);
     185        lineLogicalTop = lineContent->logicalBottom();
    186186    }
    187187}
     
    215215}
    216216
    217 void InlineFormattingContext::LineLayout::processInlineRuns(Line& line) const
    218 {
    219     auto& lineContent = line.close();
     217void InlineFormattingContext::LineLayout::processInlineRuns(const Line::Content& lineContent, LayoutUnit availableWidth) const
     218{
    220219    if (lineContent.isEmpty()) {
    221220        // Spec tells us to create a zero height, empty line box.
     
    315314    m_formattingState.addLineBox({ lineBox });
    316315    if (!lineContent.isVisuallyEmpty())
    317         alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, line.availableWidth());
     316        alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, availableWidth);
    318317}
    319318
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r245961 r245962  
    2929#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    3030
     31#include <wtf/IsoMallocInlines.h>
     32
    3133namespace WebCore {
    3234namespace Layout {
     35
     36WTF_MAKE_ISO_ALLOCATED_IMPL(Line);
    3337
    3438bool Line::Content::isVisuallyEmpty() const
     
    5256}
    5357
    54 Line::Line(const LayoutState& layoutState)
     58Line::Line(const LayoutState& layoutState, const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumHeight, LayoutUnit baselineOffset)
    5559    : m_layoutState(layoutState)
    56 {
    57 }
    58 
    59 void Line::reset(const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumHeight, LayoutUnit baselineOffset)
    60 {
    61     m_logicalTopLeft = topLeft;
    62     m_lineLogicalWidth = availableWidth;
    63     m_logicalHeight = { baselineOffset, minimumHeight - baselineOffset };
    64 
    65     m_contentLogicalWidth = { };
    66 
    67     m_content = { };
    68 
    69     m_trimmableContent.clear();
    70 }
    71 
    72 const Line::Content& Line::close()
     60    , m_content(std::make_unique<Line::Content>())
     61    , m_logicalTopLeft(topLeft)
     62    , m_logicalHeight({ baselineOffset, minimumHeight - baselineOffset })
     63    , m_lineLogicalWidth(availableWidth)
     64{
     65}
     66
     67std::unique_ptr<Line::Content> Line::close()
    7368{
    7469    removeTrailingTrimmableContent();
    7570    // Convert inline run geometry from relative to the baseline to relative to logical top.
    76     for (auto& run : m_content.runs()) {
     71    for (auto& run : m_content->runs()) {
    7772        auto adjustedLogicalTop = run->inlineRun.logicalTop() + m_logicalHeight.height + m_logicalTopLeft.y();
    7873        run->inlineRun.setLogicalTop(adjustedLogicalTop);
    7974    }
    80     m_content.setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
    81     return m_content;
     75    m_content->setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
     76    return WTFMove(m_content);
    8277}
    8378
     
    10196    m_logicalTopLeft.move(delta, 0);
    10297    m_lineLogicalWidth -= delta;
    103     for (auto& run : m_content.runs())
     98    for (auto& run : m_content->runs())
    10499        run->inlineRun.moveHorizontally(delta);
    105100}
     
    121116void Line::appendNonBreakableSpace(const InlineItem& inlineItem, const Display::Rect& logicalRect)
    122117{
    123     m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
     118    m_content->runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
    124119    m_contentLogicalWidth += inlineItem.width();
    125120}
     
    166161            return false;
    167162        // Leading whitespace.
    168         auto& runs = m_content.runs();
     163        auto& runs = m_content->runs();
    169164        if (runs.isEmpty())
    170165            return true;
     
    192187        m_trimmableContent.add(lineItem.get());
    193188
    194     m_content.runs().append(WTFMove(lineItem));
     189    m_content->runs().append(WTFMove(lineItem));
    195190    m_contentLogicalWidth += isCompletelyCollapsed ? LayoutUnit() : runSize.width();
    196191}
     
    220215    auto logicalRect = Display::Rect { logicalTop, contentLogicalRight() + horizontalMargin.start, runSize.width(), runSize.height() };
    221216
    222     m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
     217    m_content->runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
    223218    m_contentLogicalWidth += (runSize.width() + horizontalMargin.start + horizontalMargin.end);
    224219    m_trimmableContent.clear();
     
    235230    auto ascent = inlineItem.layoutBox().style().fontMetrics().ascent();
    236231    auto logicalRect = Display::Rect { -ascent, contentLogicalRight(), { }, logicalHeight() };
    237     m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
     232    m_content->runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
    238233}
    239234
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r245961 r245962  
    3030#include "DisplayRun.h"
    3131#include "InlineItem.h"
     32#include "InlineTextItem.h"
     33#include <wtf/IsoMalloc.h>
    3234
    3335namespace WebCore {
     
    3537
    3638class Line {
     39    WTF_MAKE_ISO_ALLOCATED(Line);
    3740public:
    38     Line(const LayoutState&);
    39 
    40     void reset(const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumLineHeight, LayoutUnit baselineOffset);
     41    Line(const LayoutState&, const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumLineHeight, LayoutUnit baselineOffset);
    4142
    4243    class Content {
     
    7374        Runs m_runs;
    7475    };
    75     const Content& close();
     76    std::unique_ptr<Content> close();
    7677
    7778    void appendTextContent(const InlineTextItem&, LayoutSize);
     
    8283    void appendHardLineBreak(const InlineItem&);
    8384
    84     bool hasContent() const { return !m_content.isVisuallyEmpty(); }
     85    bool hasContent() const { return !m_content->isVisuallyEmpty(); }
    8586
    8687    LayoutUnit trailingTrimmableWidth() const;
     
    113114
    114115    const LayoutState& m_layoutState;
    115     Content m_content;
     116    std::unique_ptr<Content> m_content;
    116117    ListHashSet<Content::Run*> m_trimmableContent;
    117118
Note: See TracChangeset for help on using the changeset viewer.