Title: [245962] trunk/Source/WebCore
Revision
245962
Author
[email protected]
Date
2019-05-31 06:43:37 -0700 (Fri, 31 May 2019)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (245961 => 245962)


--- trunk/Source/WebCore/ChangeLog	2019-05-31 12:58:35 UTC (rev 245961)
+++ trunk/Source/WebCore/ChangeLog	2019-05-31 13:43:37 UTC (rev 245962)
@@ -1,5 +1,34 @@
 2019-05-31  Zalan Bujtas  <[email protected]>
 
+        [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):
+
+2019-05-31  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC] Move final runs to a dedicated class (Line::Content)
         https://bugs.webkit.org/show_bug.cgi?id=198360
         <rdar://problem/51247717>

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h (245961 => 245962)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2019-05-31 12:58:35 UTC (rev 245961)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h	2019-05-31 13:43:37 UTC (rev 245962)
@@ -30,6 +30,7 @@
 #include "DisplayBox.h"
 #include "FormattingContext.h"
 #include "InlineFormattingState.h"
+#include "InlineLine.h"
 #include <wtf/IsoMalloc.h>
 
 namespace WebCore {
@@ -37,7 +38,6 @@
 
 class FloatingState;
 class InlineContainer;
-class Line;
 
 // This class implements the layout logic for inline formatting contexts.
 // https://www.w3.org/TR/CSS22/visuren.html#inline-formatting
@@ -58,9 +58,9 @@
 
     private:
         LayoutState& layoutState() const { return m_formattingContext.layoutState(); }
-        void initializeLine(Line&, LayoutUnit lineLogicalTop, LayoutUnit widthConstraint) const;
+        std::unique_ptr<Line> createLine(LayoutUnit lineLogicalTop, LayoutUnit widthConstraint) const;
         unsigned createInlineRunsForLine(Line&, unsigned firstInlineItemIndex) const;
-        void processInlineRuns(Line&) const;
+        void processInlineRuns(const Line::Content&, LayoutUnit availableWidth) const;
         void commitInlineItemToLine(Line&, const InlineItem&) const;
         void handleFloat(Line&, const FloatingContext&, const InlineItem& floatBox) const;
         void alignRuns(TextAlignMode, unsigned firstRunIndex, LayoutUnit availableWidth) const;

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp (245961 => 245962)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp	2019-05-31 12:58:35 UTC (rev 245961)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp	2019-05-31 13:43:37 UTC (rev 245962)
@@ -75,7 +75,7 @@
 {
 }
 
-void InlineFormattingContext::LineLayout::initializeLine(Line& line, LayoutUnit lineLogicalTop, LayoutUnit availableWidth) const
+std::unique_ptr<Line> InlineFormattingContext::LineLayout::createLine(LayoutUnit lineLogicalTop, LayoutUnit availableWidth) const
 {
     auto& formattingRootDisplayBox = layoutState().displayBoxForLayoutBox(m_formattingRoot);
     auto lineLogicalLeft = formattingRootDisplayBox.contentBoxLeft();
@@ -107,7 +107,7 @@
     auto& formattingRootStyle = m_formattingRoot.style();
     auto mimimumLineHeight = formattingRootStyle.computedLineHeight();
     auto baselineOffset = Line::halfLeadingMetrics(formattingRootStyle.fontMetrics(), mimimumLineHeight).height;
-    line.reset({ lineLogicalLeft, lineLogicalTop }, availableWidth, mimimumLineHeight, baselineOffset);
+    return std::make_unique<Line>(layoutState(), LayoutPoint { lineLogicalLeft, lineLogicalTop }, availableWidth, mimimumLineHeight, baselineOffset);
 }
 
 unsigned InlineFormattingContext::LineLayout::createInlineRunsForLine(Line& line, unsigned startInlineItemIndex) const
@@ -172,17 +172,17 @@
 {
     ASSERT(!m_formattingState.inlineItems().isEmpty());
 
-    Line line(layoutState());
-    initializeLine(line, layoutState().displayBoxForLayoutBox(m_formattingRoot).contentBoxTop(), widthConstraint);
-
     unsigned startInlineItemIndex = 0;
+    auto lineLogicalTop = layoutState().displayBoxForLayoutBox(m_formattingRoot).contentBoxTop();
     while (true) {
-        auto nextInlineItemIndex = createInlineRunsForLine(line, startInlineItemIndex);
-        processInlineRuns(line);
+        auto line = createLine(lineLogicalTop, widthConstraint);
+        auto nextInlineItemIndex = createInlineRunsForLine(*line, startInlineItemIndex);
+        auto lineContent = line->close();
+        processInlineRuns(*lineContent, line->availableWidth());
         if (nextInlineItemIndex == m_formattingState.inlineItems().size())
             break;
         startInlineItemIndex = nextInlineItemIndex;
-        initializeLine(line, line.logicalBottom(), widthConstraint);
+        lineLogicalTop = lineContent->logicalBottom();
     }
 }
 
@@ -214,9 +214,8 @@
     return std::max(maximumLineWidth, lineLogicalRight - trimmableTrailingWidth);
 }
 
-void InlineFormattingContext::LineLayout::processInlineRuns(Line& line) const
+void InlineFormattingContext::LineLayout::processInlineRuns(const Line::Content& lineContent, LayoutUnit availableWidth) const
 {
-    auto& lineContent = line.close();
     if (lineContent.isEmpty()) {
         // Spec tells us to create a zero height, empty line box.
         auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , 0 };
@@ -314,7 +313,7 @@
     // FIXME linebox needs to be ajusted after content alignment.
     m_formattingState.addLineBox({ lineBox });
     if (!lineContent.isVisuallyEmpty())
-        alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, line.availableWidth());
+        alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, availableWidth);
 }
 
 void InlineFormattingContext::LineLayout::handleFloat(Line& line, const FloatingContext& floatingContext, const InlineItem& floatItem) const

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp (245961 => 245962)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp	2019-05-31 12:58:35 UTC (rev 245961)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp	2019-05-31 13:43:37 UTC (rev 245962)
@@ -28,9 +28,13 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include <wtf/IsoMallocInlines.h>
+
 namespace WebCore {
 namespace Layout {
 
+WTF_MAKE_ISO_ALLOCATED_IMPL(Line);
+
 bool Line::Content::isVisuallyEmpty() const
 {
     // Return true for empty inline containers like <span></span>.
@@ -51,34 +55,25 @@
 {
 }
 
-Line::Line(const LayoutState& layoutState)
+Line::Line(const LayoutState& layoutState, const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumHeight, LayoutUnit baselineOffset)
     : m_layoutState(layoutState)
+    , m_content(std::make_unique<Line::Content>())
+    , m_logicalTopLeft(topLeft)
+    , m_logicalHeight({ baselineOffset, minimumHeight - baselineOffset })
+    , m_lineLogicalWidth(availableWidth)
 {
 }
 
-void Line::reset(const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumHeight, LayoutUnit baselineOffset)
+std::unique_ptr<Line::Content> Line::close()
 {
-    m_logicalTopLeft = topLeft;
-    m_lineLogicalWidth = availableWidth;
-    m_logicalHeight = { baselineOffset, minimumHeight - baselineOffset };
-
-    m_contentLogicalWidth = { };
-
-    m_content = { };
-
-    m_trimmableContent.clear();
-}
-
-const Line::Content& Line::close()
-{
     removeTrailingTrimmableContent();
     // Convert inline run geometry from relative to the baseline to relative to logical top.
-    for (auto& run : m_content.runs()) {
+    for (auto& run : m_content->runs()) {
         auto adjustedLogicalTop = run->inlineRun.logicalTop() + m_logicalHeight.height + m_logicalTopLeft.y();
         run->inlineRun.setLogicalTop(adjustedLogicalTop);
     }
-    m_content.setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
-    return m_content;
+    m_content->setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
+    return WTFMove(m_content);
 }
 
 void Line::removeTrailingTrimmableContent()
@@ -100,7 +95,7 @@
     // Shrink the line and move the items.
     m_logicalTopLeft.move(delta, 0);
     m_lineLogicalWidth -= delta;
-    for (auto& run : m_content.runs())
+    for (auto& run : m_content->runs())
         run->inlineRun.moveHorizontally(delta);
 }
 
@@ -120,7 +115,7 @@
 
 void Line::appendNonBreakableSpace(const InlineItem& inlineItem, const Display::Rect& logicalRect)
 {
-    m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
+    m_content->runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
     m_contentLogicalWidth += inlineItem.width();
 }
 
@@ -165,7 +160,7 @@
         if (!isTrimmable)
             return false;
         // Leading whitespace.
-        auto& runs = m_content.runs();
+        auto& runs = m_content->runs();
         if (runs.isEmpty())
             return true;
         // Check if the last item is trimmable as well.
@@ -191,7 +186,7 @@
     if (isTrimmable)
         m_trimmableContent.add(lineItem.get());
 
-    m_content.runs().append(WTFMove(lineItem));
+    m_content->runs().append(WTFMove(lineItem));
     m_contentLogicalWidth += isCompletelyCollapsed ? LayoutUnit() : runSize.width();
 }
 
@@ -219,7 +214,7 @@
     auto horizontalMargin = displayBox.horizontalMargin();
     auto logicalRect = Display::Rect { logicalTop, contentLogicalRight() + horizontalMargin.start, runSize.width(), runSize.height() };
 
-    m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
+    m_content->runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
     m_contentLogicalWidth += (runSize.width() + horizontalMargin.start + horizontalMargin.end);
     m_trimmableContent.clear();
 }
@@ -234,7 +229,7 @@
 {
     auto ascent = inlineItem.layoutBox().style().fontMetrics().ascent();
     auto logicalRect = Display::Rect { -ascent, contentLogicalRight(), { }, logicalHeight() };
-    m_content.runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
+    m_content->runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
 }
 
 Line::UsedHeightAndDepth Line::halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight)

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLine.h (245961 => 245962)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLine.h	2019-05-31 12:58:35 UTC (rev 245961)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLine.h	2019-05-31 13:43:37 UTC (rev 245962)
@@ -29,16 +29,17 @@
 
 #include "DisplayRun.h"
 #include "InlineItem.h"
+#include "InlineTextItem.h"
+#include <wtf/IsoMalloc.h>
 
 namespace WebCore {
 namespace Layout {
 
 class Line {
+    WTF_MAKE_ISO_ALLOCATED(Line);
 public:
-    Line(const LayoutState&);
+    Line(const LayoutState&, const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumLineHeight, LayoutUnit baselineOffset);
 
-    void reset(const LayoutPoint& topLeft, LayoutUnit availableWidth, LayoutUnit minimumLineHeight, LayoutUnit baselineOffset);
-
     class Content {
     public:
         struct Run {
@@ -72,7 +73,7 @@
         Display::Rect m_logicalRect;
         Runs m_runs;
     };
-    const Content& close();
+    std::unique_ptr<Content> close();
 
     void appendTextContent(const InlineTextItem&, LayoutSize);
     void appendNonReplacedInlineBox(const InlineItem&, LayoutSize);
@@ -81,7 +82,7 @@
     void appendInlineContainerEnd(const InlineItem&);
     void appendHardLineBreak(const InlineItem&);
 
-    bool hasContent() const { return !m_content.isVisuallyEmpty(); }
+    bool hasContent() const { return !m_content->isVisuallyEmpty(); }
 
     LayoutUnit trailingTrimmableWidth() const;
 
@@ -112,7 +113,7 @@
     void removeTrailingTrimmableContent();
 
     const LayoutState& m_layoutState;
-    Content m_content;
+    std::unique_ptr<Content> m_content;
     ListHashSet<Content::Run*> m_trimmableContent;
 
     LayoutPoint m_logicalTopLeft;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to