[LFC][IFC] Remove redundant Line::Content
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Sep 2019 03:23:32 +0000 (03:23 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Sep 2019 03:23:32 +0000 (03:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=202284
<rdar://problem/55757187>

Reviewed by Antti Koivisto.

Line::Content is really just a list or runs at this point.

* layout/inlineformatting/InlineFormattingContext.h:
* layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
(WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns):
* layout/inlineformatting/InlineFormattingContextQuirks.cpp:
(WebCore::Layout::InlineFormattingContext::Quirks::lineDescentNeedsCollapsing const):
* layout/inlineformatting/InlineLine.cpp:
(WebCore::Layout::Line::Run::Run):
(WebCore::Layout::Line::Line):
(WebCore::Layout::Line::isVisuallyEmpty const):
(WebCore::Layout::Line::close):
(WebCore::Layout::Line::appendNonBreakableSpace):
(WebCore::Layout::Line::appendTextContent):
(WebCore::Layout::Line::appendNonReplacedInlineBox):
(WebCore::Layout::Line::appendHardLineBreak):
(WebCore::Layout::Line::Content::Run::Run): Deleted.
* layout/inlineformatting/InlineLine.h:
(WebCore::Layout::Line::Run::layoutBox const):
(WebCore::Layout::Line::Run::logicalRect const):
(WebCore::Layout::Line::Run::textContext const):
(WebCore::Layout::Line::Run::type const):
(WebCore::Layout::Line::Run::isText const):
(WebCore::Layout::Line::Run::isBox const):
(WebCore::Layout::Line::Run::isLineBreak const):
(WebCore::Layout::Line::Run::isContainerStart const):
(WebCore::Layout::Line::Run::isContainerEnd const):
(WebCore::Layout::Line::Run::adjustLogicalTop):
(WebCore::Layout::Line::Run::moveVertically):
(WebCore::Layout::Line::Run::moveHorizontally):
(WebCore::Layout::Line::Run::setTextIsCollapsed):
(WebCore::Layout::Line::Content::Run::layoutBox const): Deleted.
(WebCore::Layout::Line::Content::Run::logicalRect const): Deleted.
(WebCore::Layout::Line::Content::Run::textContext const): Deleted.
(WebCore::Layout::Line::Content::Run::type const): Deleted.
(WebCore::Layout::Line::Content::Run::isText const): Deleted.
(WebCore::Layout::Line::Content::Run::isBox const): Deleted.
(WebCore::Layout::Line::Content::Run::isLineBreak const): Deleted.
(WebCore::Layout::Line::Content::Run::isContainerStart const): Deleted.
(WebCore::Layout::Line::Content::Run::isContainerEnd const): Deleted.
(WebCore::Layout::Line::Content::Run::adjustLogicalTop): Deleted.
(WebCore::Layout::Line::Content::Run::moveVertically): Deleted.
(WebCore::Layout::Line::Content::Run::moveHorizontally): Deleted.
(WebCore::Layout::Line::Content::Run::setTextIsCollapsed): Deleted.
(WebCore::Layout::Line::Content::runs const): Deleted.
(WebCore::Layout::Line::Content::runs): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250411 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/layout/inlineformatting/InlineFormattingContext.h
Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp
Source/WebCore/layout/inlineformatting/InlineFormattingContextQuirks.cpp
Source/WebCore/layout/inlineformatting/InlineLine.cpp
Source/WebCore/layout/inlineformatting/InlineLine.h

index fd59c8f..34eb82f 100644 (file)
@@ -1,5 +1,60 @@
 2019-09-26  Zalan Bujtas  <zalan@apple.com>
 
+        [LFC][IFC] Remove redundant Line::Content
+        https://bugs.webkit.org/show_bug.cgi?id=202284
+        <rdar://problem/55757187>
+
+        Reviewed by Antti Koivisto.
+
+        Line::Content is really just a list or runs at this point.
+
+        * layout/inlineformatting/InlineFormattingContext.h:
+        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
+        (WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns):
+        * layout/inlineformatting/InlineFormattingContextQuirks.cpp:
+        (WebCore::Layout::InlineFormattingContext::Quirks::lineDescentNeedsCollapsing const):
+        * layout/inlineformatting/InlineLine.cpp:
+        (WebCore::Layout::Line::Run::Run):
+        (WebCore::Layout::Line::Line):
+        (WebCore::Layout::Line::isVisuallyEmpty const):
+        (WebCore::Layout::Line::close):
+        (WebCore::Layout::Line::appendNonBreakableSpace):
+        (WebCore::Layout::Line::appendTextContent):
+        (WebCore::Layout::Line::appendNonReplacedInlineBox):
+        (WebCore::Layout::Line::appendHardLineBreak):
+        (WebCore::Layout::Line::Content::Run::Run): Deleted.
+        * layout/inlineformatting/InlineLine.h:
+        (WebCore::Layout::Line::Run::layoutBox const):
+        (WebCore::Layout::Line::Run::logicalRect const):
+        (WebCore::Layout::Line::Run::textContext const):
+        (WebCore::Layout::Line::Run::type const):
+        (WebCore::Layout::Line::Run::isText const):
+        (WebCore::Layout::Line::Run::isBox const):
+        (WebCore::Layout::Line::Run::isLineBreak const):
+        (WebCore::Layout::Line::Run::isContainerStart const):
+        (WebCore::Layout::Line::Run::isContainerEnd const):
+        (WebCore::Layout::Line::Run::adjustLogicalTop):
+        (WebCore::Layout::Line::Run::moveVertically):
+        (WebCore::Layout::Line::Run::moveHorizontally):
+        (WebCore::Layout::Line::Run::setTextIsCollapsed):
+        (WebCore::Layout::Line::Content::Run::layoutBox const): Deleted.
+        (WebCore::Layout::Line::Content::Run::logicalRect const): Deleted.
+        (WebCore::Layout::Line::Content::Run::textContext const): Deleted.
+        (WebCore::Layout::Line::Content::Run::type const): Deleted.
+        (WebCore::Layout::Line::Content::Run::isText const): Deleted.
+        (WebCore::Layout::Line::Content::Run::isBox const): Deleted.
+        (WebCore::Layout::Line::Content::Run::isLineBreak const): Deleted.
+        (WebCore::Layout::Line::Content::Run::isContainerStart const): Deleted.
+        (WebCore::Layout::Line::Content::Run::isContainerEnd const): Deleted.
+        (WebCore::Layout::Line::Content::Run::adjustLogicalTop): Deleted.
+        (WebCore::Layout::Line::Content::Run::moveVertically): Deleted.
+        (WebCore::Layout::Line::Content::Run::moveHorizontally): Deleted.
+        (WebCore::Layout::Line::Content::Run::setTextIsCollapsed): Deleted.
+        (WebCore::Layout::Line::Content::runs const): Deleted.
+        (WebCore::Layout::Line::Content::runs): Deleted.
+
+2019-09-26  Zalan Bujtas  <zalan@apple.com>
+
         [LFC][IFC] Move Line::Content::m_lineBox to Line.
         https://bugs.webkit.org/show_bug.cgi?id=202280
         <rdar://problem/55755798>
index 20a0892..607b16b 100644 (file)
@@ -77,7 +77,7 @@ private:
 
     class Quirks : public FormattingContext::Quirks {
     public:
-        bool lineDescentNeedsCollapsing(const Line::Content&) const;
+        bool lineDescentNeedsCollapsing(const Line::RunList&) const;
         Line::InitialConstraints::HeightAndBaseline lineHeightConstraints(const Box& formattingRoot) const;
 
     private:
index 671880e..67e25aa 100644 (file)
@@ -94,7 +94,7 @@ struct LineInput {
 struct LineContent {
     Optional<IndexAndRange> lastCommitted;
     Vector<WeakPtr<InlineItem>> floats;
-    std::unique_ptr<const Line::Content> runs;
+    const Line::RunList runList;
     const LineBox lineBox;
 };
 
@@ -382,7 +382,7 @@ void InlineFormattingContext::InlineLayout::createDisplayRuns(const LineContent&
     // A line box is always tall enough for all of the boxes it contains.
 
     // Create final display runs.
-    auto& lineRuns = lineContent.runs->runs();
+    auto& lineRuns = lineContent.runList;
     for (unsigned index = 0; index < lineRuns.size(); ++index) {
         auto& run = lineRuns.at(index);
         // Inline level containers (<span>) don't generate inline runs.
@@ -400,7 +400,7 @@ void InlineFormattingContext::InlineLayout::createDisplayRuns(const LineContent&
             if (textContext->isCollapsed)
                 continue;
             // Try to join multiple text runs when possible.
-            const Line::Content::Run* previousRun = !index ? nullptr : lineRuns[index - 1].get();
+            const Line::Run* previousRun = !index ? nullptr : lineRuns[index - 1].get();
             auto previousRunCanBeExtended = previousRun && previousRun->textContext() ? previousRun->textContext()->canBeExtended : false;
             auto currentRunCanBeMergedWithPrevious = !previousRun || &run->layoutBox() == &previousRun->layoutBox();
 
@@ -462,7 +462,7 @@ void InlineFormattingContext::InlineLayout::createDisplayRuns(const LineContent&
         // Text content. Try to join multiple text runs when possible.
         if (lineRun->isText()) {
             auto textContext = lineRun->textContext();
-            const Line::Content::Run* previousLineRun = !index ? nullptr : lineRuns[index - 1].get();
+            const Line::Run* previousLineRun = !index ? nullptr : lineRuns[index - 1].get();
             // FIXME take content breaking into account when part of the layout box is on the previous line.
             auto firstInlineRunForLayoutBox = !previousLineRun || &previousLineRun->layoutBox() != &layoutBox;
             if (firstInlineRunForLayoutBox) {
index dfcc626..779ba27 100644 (file)
@@ -36,7 +36,7 @@
 namespace WebCore {
 namespace Layout {
 
-bool InlineFormattingContext::Quirks::lineDescentNeedsCollapsing(const Line::Content& lineContent) const
+bool InlineFormattingContext::Quirks::lineDescentNeedsCollapsing(const Line::RunList& runList) const
 {
     // Collapse line descent in limited and full quirk mode when there's no baseline aligned content or
     // the baseline aligned content has no descent.
@@ -44,7 +44,7 @@ bool InlineFormattingContext::Quirks::lineDescentNeedsCollapsing(const Line::Con
     if (!layoutState.inQuirksMode() && !layoutState.inLimitedQuirksMode())
         return false;
 
-    for (auto& run : lineContent.runs()) {
+    for (auto& run : runList) {
         auto& layoutBox = run->layoutBox();
         if (layoutBox.style().verticalAlign() != VerticalAlign::Baseline)
             continue;
index 83e5ca3..a010e91 100644 (file)
@@ -37,14 +37,14 @@ namespace Layout {
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(Line);
 
-Line::Content::Run::Run(const InlineItem& inlineItem, const Display::Rect& logicalRect)
+Line::Run::Run(const InlineItem& inlineItem, const Display::Rect& logicalRect)
     : m_layoutBox(inlineItem.layoutBox())
     , m_type(inlineItem.type())
     , m_logicalRect(logicalRect)
 {
 }
 
-Line::Content::Run::Run(const InlineItem& inlineItem, const TextContext& textContext, const Display::Rect& logicalRect)
+Line::Run::Run(const InlineItem& inlineItem, const TextContext& textContext, const Display::Rect& logicalRect)
     : m_layoutBox(inlineItem.layoutBox())
     , m_type(inlineItem.type())
     , m_logicalRect(logicalRect)
@@ -54,7 +54,6 @@ Line::Content::Run::Run(const InlineItem& inlineItem, const TextContext& textCon
 
 Line::Line(const InlineFormattingContext& inlineFormattingContext, const InitialConstraints& initialConstraints, SkipVerticalAligment skipVerticalAligment)
     : m_inlineFormattingContext(inlineFormattingContext)
-    , m_content(makeUnique<Line::Content>())
     , m_initialStrut(initialConstraints.heightAndBaseline.strut)
     , m_lineLogicalWidth(initialConstraints.availableLogicalWidth)
     , m_skipVerticalAligment(skipVerticalAligment == SkipVerticalAligment::Yes)
@@ -76,7 +75,7 @@ bool Line::isVisuallyEmpty() const
     // FIXME: This should be cached instead -as the inline items are being added.
     // Return true for empty inline containers like <span></span>.
     auto& formattingContext = this->formattingContext();
-    for (auto& run : m_content->runs()) {
+    for (auto& run : m_runList) {
         if (run->isContainerStart()) {
             if (!isInlineContainerConsideredEmpty(formattingContext, run->layoutBox()))
                 return false;
@@ -99,7 +98,7 @@ bool Line::isVisuallyEmpty() const
     return true;
 }
 
-std::unique_ptr<Line::Content> Line::close()
+Line::RunList Line::close()
 {
     removeTrailingTrimmableContent();
     if (!m_skipVerticalAligment) {
@@ -110,14 +109,14 @@ std::unique_ptr<Line::Content> Line::close()
         }
 
         // Remove descent when all content is baseline aligned but none of them have descent.
-        if (formattingContext().quirks().lineDescentNeedsCollapsing(*m_content)) {
+        if (formattingContext().quirks().lineDescentNeedsCollapsing(m_runList)) {
             m_lineBox.shrinkVertically(m_lineBox.baseline().descent());
             m_lineBox.baseline().setDescent({ });
         }
 
         auto& layoutState = this->layoutState();
         auto& formattingContext = this->formattingContext();
-        for (auto& run : m_content->runs()) {
+        for (auto& run : m_runList) {
             LayoutUnit logicalTop;
             auto& layoutBox = run->layoutBox();
             auto verticalAlign = layoutBox.style().verticalAlign();
@@ -155,7 +154,7 @@ std::unique_ptr<Line::Content> Line::close()
             run->moveHorizontally(this->logicalLeft());
         }
     }
-    return WTFMove(m_content);
+    return WTFMove(m_runList);
 }
 
 void Line::removeTrailingTrimmableContent()
@@ -212,7 +211,7 @@ void Line::append(const InlineItem& inlineItem, LayoutUnit logicalWidth)
 
 void Line::appendNonBreakableSpace(const InlineItem& inlineItem, const Display::Rect& logicalRect)
 {
-    m_content->runs().append(makeUnique<Content::Run>(inlineItem, logicalRect));
+    m_runList.append(makeUnique<Run>(inlineItem, logicalRect));
     m_lineBox.expandHorizontally(logicalRect.width());
 }
 
@@ -252,12 +251,11 @@ void Line::appendTextContent(const InlineTextItem& inlineItem, LayoutUnit logica
         if (!isTrimmable)
             return false;
         // Leading whitespace.
-        auto& runs = m_content->runs();
-        if (runs.isEmpty())
+        if (m_runList.isEmpty())
             return true;
         // Check if the last item is trimmable as well.
-        for (int index = runs.size() - 1; index >= 0; --index) {
-            auto& run = runs[index];
+        for (int index = m_runList.size() - 1; index >= 0; --index) {
+            auto& run = m_runList[index];
             if (run->isBox())
                 return false;
             if (run->isText())
@@ -280,12 +278,12 @@ void Line::appendTextContent(const InlineTextItem& inlineItem, LayoutUnit logica
         adjustBaselineAndLineHeight(inlineItem, runHeight);
     }
 
-    auto textContext = Content::Run::TextContext { inlineItem.start(), inlineItem.isCollapsed() ? 1 : inlineItem.length(), isCompletelyCollapsed, inlineItem.isWhitespace(), canBeExtended };
-    auto lineItem = makeUnique<Content::Run>(inlineItem, textContext, logicalRect);
+    auto textContext = Run::TextContext { inlineItem.start(), inlineItem.isCollapsed() ? 1 : inlineItem.length(), isCompletelyCollapsed, inlineItem.isWhitespace(), canBeExtended };
+    auto lineItem = makeUnique<Run>(inlineItem, textContext, logicalRect);
     if (isTrimmable && !isCompletelyCollapsed)
         m_trimmableContent.add(lineItem.get());
 
-    m_content->runs().append(WTFMove(lineItem));
+    m_runList.append(WTFMove(lineItem));
     if (!isCompletelyCollapsed)
         m_lineBox.expandHorizontally(logicalWidth);
 }
@@ -303,7 +301,7 @@ void Line::appendNonReplacedInlineBox(const InlineItem& inlineItem, LayoutUnit l
         logicalRect.setHeight(inlineItemContentHeight(inlineItem));
     }
 
-    m_content->runs().append(makeUnique<Content::Run>(inlineItem, logicalRect));
+    m_runList.append(makeUnique<Run>(inlineItem, logicalRect));
     m_lineBox.expandHorizontally(logicalWidth + horizontalMargin.start + horizontalMargin.end);
     m_trimmableContent.clear();
 }
@@ -323,7 +321,7 @@ void Line::appendHardLineBreak(const InlineItem& inlineItem)
         adjustBaselineAndLineHeight(inlineItem, { });
         logicalRect.setHeight(logicalHeight());
     }
-    m_content->runs().append(makeUnique<Content::Run>(inlineItem, logicalRect));
+    m_runList.append(makeUnique<Run>(inlineItem, logicalRect));
 }
 
 void Line::adjustBaselineAndLineHeight(const InlineItem& inlineItem, LayoutUnit runHeight)
index 3f05e80..5370b8c 100644 (file)
@@ -54,55 +54,6 @@ public:
     enum class SkipVerticalAligment { No, Yes };
     Line(const InlineFormattingContext&, const InitialConstraints&, SkipVerticalAligment);
 
-    class Content {
-        WTF_MAKE_FAST_ALLOCATED;
-    public:
-        struct Run {
-            WTF_MAKE_STRUCT_FAST_ALLOCATED;
-            struct TextContext {
-                unsigned start { 0 };
-                unsigned length { 0 };
-                bool isCollapsed { false };
-                bool isWhitespace { false };
-                bool canBeExtended { false };
-            };
-            Run(const InlineItem&, const Display::Rect&);
-            Run(const InlineItem&, const TextContext&, const Display::Rect&);
-
-            const Box& layoutBox() const { return m_layoutBox; }
-            const Display::Rect& logicalRect() const { return m_logicalRect; }
-            const Optional<TextContext> textContext() const { return m_textContext; }
-            InlineItem::Type type() const { return m_type; }
-
-            bool isText() const { return m_type == InlineItem::Type::Text; }
-            bool isBox() const { return m_type == InlineItem::Type::Box; }
-            bool isLineBreak() const { return m_type == InlineItem::Type::HardLineBreak; }
-            bool isContainerStart() const { return m_type == InlineItem::Type::ContainerStart; }
-            bool isContainerEnd() const { return m_type == InlineItem::Type::ContainerEnd; }
-
-        private:
-            friend class Line;
-            void adjustLogicalTop(LayoutUnit logicalTop) { m_logicalRect.setTop(logicalTop); }
-            void moveVertically(LayoutUnit offset) { m_logicalRect.moveVertically(offset); }
-            void moveHorizontally(LayoutUnit offset) { m_logicalRect.moveHorizontally(offset); }
-            void setTextIsCollapsed() { m_textContext->isCollapsed = true; }
-
-            const Box& m_layoutBox;
-            const InlineItem::Type m_type;
-            Display::Rect m_logicalRect;
-            Optional<TextContext> m_textContext;
-        };
-        using Runs = Vector<std::unique_ptr<Run>>;
-        const Runs& runs() const { return m_runs; }
-
-    private:
-        friend class Line;
-        Runs& runs() { return m_runs; }
-
-        Runs m_runs;
-    };
-    std::unique_ptr<Content> close();
-
     void append(const InlineItem&, LayoutUnit logicalWidth);
     bool hasContent() const { return !isVisuallyEmpty(); }
     LayoutUnit availableWidth() const { return logicalWidth() - contentLogicalWidth(); }
@@ -113,6 +64,44 @@ public:
     void moveLogicalLeft(LayoutUnit);
     void moveLogicalRight(LayoutUnit);
 
+    struct Run {
+        WTF_MAKE_STRUCT_FAST_ALLOCATED;
+        struct TextContext {
+            unsigned start { 0 };
+            unsigned length { 0 };
+            bool isCollapsed { false };
+            bool isWhitespace { false };
+            bool canBeExtended { false };
+        };
+        Run(const InlineItem&, const Display::Rect&);
+        Run(const InlineItem&, const TextContext&, const Display::Rect&);
+
+        const Box& layoutBox() const { return m_layoutBox; }
+        const Display::Rect& logicalRect() const { return m_logicalRect; }
+        const Optional<TextContext> textContext() const { return m_textContext; }
+        InlineItem::Type type() const { return m_type; }
+
+        bool isText() const { return m_type == InlineItem::Type::Text; }
+        bool isBox() const { return m_type == InlineItem::Type::Box; }
+        bool isLineBreak() const { return m_type == InlineItem::Type::HardLineBreak; }
+        bool isContainerStart() const { return m_type == InlineItem::Type::ContainerStart; }
+        bool isContainerEnd() const { return m_type == InlineItem::Type::ContainerEnd; }
+
+    private:
+        friend class Line;
+        void adjustLogicalTop(LayoutUnit logicalTop) { m_logicalRect.setTop(logicalTop); }
+        void moveVertically(LayoutUnit offset) { m_logicalRect.moveVertically(offset); }
+        void moveHorizontally(LayoutUnit offset) { m_logicalRect.moveHorizontally(offset); }
+        void setTextIsCollapsed() { m_textContext->isCollapsed = true; }
+
+        const Box& m_layoutBox;
+        const InlineItem::Type m_type;
+        Display::Rect m_logicalRect;
+        Optional<TextContext> m_textContext;
+    };
+    using RunList = Vector<std::unique_ptr<Run>>;
+    RunList close();
+
     static LineBox::Baseline halfLeadingMetrics(const FontMetrics&, LayoutUnit lineLogicalHeight);
 
 private:
@@ -147,8 +136,8 @@ private:
     const InlineFormattingContext& formattingContext() const; 
 
     const InlineFormattingContext& m_inlineFormattingContext;
-    std::unique_ptr<Content> m_content;
-    ListHashSet<Content::Run*> m_trimmableContent;
+    RunList m_runList;
+    ListHashSet<Run*> m_trimmableContent;
 
     Optional<LineBox::Baseline> m_initialStrut;
     LayoutUnit m_lineLogicalWidth;