Title: [253711] trunk/Source/WebCore
Revision
253711
Author
[email protected]
Date
2019-12-18 13:28:55 -0800 (Wed, 18 Dec 2019)

Log Message

[LFC][IFC] LineLayoutContext::m_uncommittedList is not always a continuous list of runs
https://bugs.webkit.org/show_bug.cgi?id=205404
<rdar://problem/58049699>

Reviewed by Antti Koivisto.

Since LineLayoutContext's m_uncommittedList is not necessarily continuous set of runs (continuous in the content of not having a soft wrap opportunity)
we can't use LineBreaker's Content struct anymore to store the uncommitted content.
Let's use a dedicated UncommittedContent struct instead. It also enables us to pass in a const RunList& to the ContinousContent. ContinousContent should never mutate this list.

* layout/inlineformatting/InlineLineBreaker.cpp:
(WebCore::Layout::shouldKeepEndOfLineWhitespace):
(WebCore::Layout::LineBreaker::breakingContextForInlineContent):
(WebCore::Layout::LineBreaker::ContinousContent::ContinousContent):
(WebCore::Layout::LineBreaker::ContinousContent::hasTextContentOnly const):
(WebCore::Layout::LineBreaker::ContinousContent::isVisuallyEmptyWhitespaceContentOnly const):
(WebCore::Layout::LineBreaker::ContinousContent::firstTextRunIndex const):
(WebCore::Layout::LineBreaker::ContinousContent::hasNonContentRunsOnly const):
(WebCore::Layout::LineBreaker::ContinousContent::TrailingCollapsibleContent::reset):
(WebCore::Layout::LineBreaker::Content::append): Deleted.
(WebCore::Layout::LineBreaker::Content::reset): Deleted.
(WebCore::Layout::LineBreaker::Content::shrink): Deleted.
(WebCore::Layout::LineBreaker::Content::hasTextContentOnly const): Deleted.
(WebCore::Layout::LineBreaker::Content::isVisuallyEmptyWhitespaceContentOnly const): Deleted.
(WebCore::Layout::LineBreaker::Content::firstTextRunIndex const): Deleted.
(WebCore::Layout::LineBreaker::Content::hasNonContentRunsOnly const): Deleted.
(WebCore::Layout::LineBreaker::Content::TrailingCollapsibleContent::reset): Deleted.
* layout/inlineformatting/InlineLineBreaker.h:
(WebCore::Layout::LineBreaker::ContinousContent::runs const):
(WebCore::Layout::LineBreaker::ContinousContent::isEmpty const):
(WebCore::Layout::LineBreaker::ContinousContent::size const):
(WebCore::Layout::LineBreaker::Content::runs): Deleted.
(WebCore::Layout::LineBreaker::Content::runs const): Deleted.
(WebCore::Layout::LineBreaker::Content::isEmpty const): Deleted.
(WebCore::Layout::LineBreaker::Content::size const): Deleted.
(WebCore::Layout::LineBreaker::Content::width const): Deleted.
(WebCore::Layout::LineBreaker::Content::nonCollapsibleWidth const): Deleted.
(WebCore::Layout::LineBreaker::Content::hasTrailingCollapsibleContent const): Deleted.
(WebCore::Layout::LineBreaker::Content::isTrailingContentFullyCollapsible const): Deleted.
* layout/inlineformatting/LineLayoutContext.cpp:
(WebCore::Layout::LineLayoutContext::processUncommittedContent):
(WebCore::Layout::LineLayoutContext::UncommittedContent::append):
(WebCore::Layout::LineLayoutContext::UncommittedContent::reset):
(WebCore::Layout::LineLayoutContext::UncommittedContent::shrink):
* layout/inlineformatting/LineLayoutContext.h:
(WebCore::Layout::LineLayoutContext::UncommittedContent::width const):
(WebCore::Layout::LineLayoutContext::UncommittedContent::size):
(WebCore::Layout::LineLayoutContext::UncommittedContent::isEmpty):
(WebCore::Layout::LineLayoutContext::UncommittedContent::runs const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (253710 => 253711)


--- trunk/Source/WebCore/ChangeLog	2019-12-18 20:44:13 UTC (rev 253710)
+++ trunk/Source/WebCore/ChangeLog	2019-12-18 21:28:55 UTC (rev 253711)
@@ -1,3 +1,55 @@
+2019-12-18  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] LineLayoutContext::m_uncommittedList is not always a continuous list of runs
+        https://bugs.webkit.org/show_bug.cgi?id=205404
+        <rdar://problem/58049699>
+
+        Reviewed by Antti Koivisto.
+
+        Since LineLayoutContext's m_uncommittedList is not necessarily continuous set of runs (continuous in the content of not having a soft wrap opportunity)
+        we can't use LineBreaker's Content struct anymore to store the uncommitted content.
+        Let's use a dedicated UncommittedContent struct instead. It also enables us to pass in a const RunList& to the ContinousContent. ContinousContent should never mutate this list.
+
+        * layout/inlineformatting/InlineLineBreaker.cpp:
+        (WebCore::Layout::shouldKeepEndOfLineWhitespace):
+        (WebCore::Layout::LineBreaker::breakingContextForInlineContent):
+        (WebCore::Layout::LineBreaker::ContinousContent::ContinousContent):
+        (WebCore::Layout::LineBreaker::ContinousContent::hasTextContentOnly const):
+        (WebCore::Layout::LineBreaker::ContinousContent::isVisuallyEmptyWhitespaceContentOnly const):
+        (WebCore::Layout::LineBreaker::ContinousContent::firstTextRunIndex const):
+        (WebCore::Layout::LineBreaker::ContinousContent::hasNonContentRunsOnly const):
+        (WebCore::Layout::LineBreaker::ContinousContent::TrailingCollapsibleContent::reset):
+        (WebCore::Layout::LineBreaker::Content::append): Deleted.
+        (WebCore::Layout::LineBreaker::Content::reset): Deleted.
+        (WebCore::Layout::LineBreaker::Content::shrink): Deleted.
+        (WebCore::Layout::LineBreaker::Content::hasTextContentOnly const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::isVisuallyEmptyWhitespaceContentOnly const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::firstTextRunIndex const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::hasNonContentRunsOnly const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::TrailingCollapsibleContent::reset): Deleted.
+        * layout/inlineformatting/InlineLineBreaker.h:
+        (WebCore::Layout::LineBreaker::ContinousContent::runs const):
+        (WebCore::Layout::LineBreaker::ContinousContent::isEmpty const):
+        (WebCore::Layout::LineBreaker::ContinousContent::size const):
+        (WebCore::Layout::LineBreaker::Content::runs): Deleted.
+        (WebCore::Layout::LineBreaker::Content::runs const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::isEmpty const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::size const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::width const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::nonCollapsibleWidth const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::hasTrailingCollapsibleContent const): Deleted.
+        (WebCore::Layout::LineBreaker::Content::isTrailingContentFullyCollapsible const): Deleted.
+        * layout/inlineformatting/LineLayoutContext.cpp:
+        (WebCore::Layout::LineLayoutContext::processUncommittedContent):
+        (WebCore::Layout::LineLayoutContext::UncommittedContent::append):
+        (WebCore::Layout::LineLayoutContext::UncommittedContent::reset):
+        (WebCore::Layout::LineLayoutContext::UncommittedContent::shrink):
+        * layout/inlineformatting/LineLayoutContext.h:
+        (WebCore::Layout::LineLayoutContext::UncommittedContent::width const):
+        (WebCore::Layout::LineLayoutContext::UncommittedContent::size):
+        (WebCore::Layout::LineLayoutContext::UncommittedContent::isEmpty):
+        (WebCore::Layout::LineLayoutContext::UncommittedContent::runs const):
+
 2019-12-18  youenn fablet  <[email protected]>
 
         Protect ServiceWorker::postMessage from a null execState

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp (253710 => 253711)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp	2019-12-18 20:44:13 UTC (rev 253710)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.cpp	2019-12-18 21:28:55 UTC (rev 253711)
@@ -54,7 +54,7 @@
     return isTextContentWrappingAllowed(run.inlineItem.style());
 }
 
-static inline bool shouldKeepEndOfLineWhitespace(const LineBreaker::Content& candidateRuns)
+static inline bool shouldKeepEndOfLineWhitespace(const LineBreaker::ContinousContent& candidateRuns)
 {
     // Grab the style and check for white-space property to decided whether we should let this whitespace content overflow the current line.
     // Note that the "keep" in the context means we let the whitespace content sit on the current line.
@@ -64,7 +64,7 @@
     return whitespace == WhiteSpace::Normal || whitespace == WhiteSpace::NoWrap || whitespace == WhiteSpace::PreWrap || whitespace == WhiteSpace::PreLine;
 }
 
-LineBreaker::BreakingContext LineBreaker::breakingContextForInlineContent(const Content& candidateRuns, const LineStatus& lineStatus)
+LineBreaker::BreakingContext LineBreaker::breakingContextForInlineContent(const ContinousContent& candidateRuns, const LineStatus& lineStatus)
 {
     ASSERT(!candidateRuns.isEmpty());
     if (candidateRuns.width() <= lineStatus.availableWidth)
@@ -386,49 +386,42 @@
     return true;
 }
 
-void LineBreaker::Content::append(const InlineItem& inlineItem, InlineLayoutUnit logicalWidth)
+LineBreaker::ContinousContent::ContinousContent(const RunList& runs)
+    : m_runs(runs)
 {
-    ASSERT(!inlineItem.isFloat());
-    m_continousRuns.append({ inlineItem, logicalWidth });
-    m_width += logicalWidth;
     // Figure out the trailing collapsible state.
-    if (inlineItem.isBox() || inlineItem.isLineBreak())
-        m_trailingCollapsibleContent.reset();
-    else if (inlineItem.isText()) {
-        auto& inlineTextItem = downcast<InlineTextItem>(inlineItem);
-        auto isFullyCollapsible = [&] {
-            return inlineTextItem.isWhitespace() && !TextUtil::shouldPreserveTrailingWhitespace(inlineTextItem.style());
-        };
-        if (isFullyCollapsible()) {
-            m_trailingCollapsibleContent.width += logicalWidth;
-            m_trailingCollapsibleContent.isFullyCollapsible = true;
-        } else if (auto collapsibleWidth = inlineTextItem.style().letterSpacing()) {
-            m_trailingCollapsibleContent.width = collapsibleWidth;
-            m_trailingCollapsibleContent.isFullyCollapsible = false;
-        } else
-            m_trailingCollapsibleContent.reset();
+    for (auto& run : WTF::makeReversedRange(m_runs)) {
+        auto& inlineItem = run.inlineItem;
+        if (inlineItem.isBox() || inlineItem.isLineBreak()) {
+            // We did reach a non-collapsible content. We have all the trailing whitespace now.
+            break;
+        }
+        if (inlineItem.isText()) {
+            auto& inlineTextItem = downcast<InlineTextItem>(inlineItem);
+            auto isFullyCollapsible = [&] {
+                return inlineTextItem.isWhitespace() && !TextUtil::shouldPreserveTrailingWhitespace(inlineTextItem.style());
+            };
+            if (isFullyCollapsible()) {
+                m_trailingCollapsibleContent.width += run.logicalWidth;
+                m_trailingCollapsibleContent.isFullyCollapsible = true;
+                // Let's see if we've got more trailing whitespace content.
+                continue;
+            }
+            if (auto collapsibleWidth = inlineTextItem.style().letterSpacing()) {
+                m_trailingCollapsibleContent.width += collapsibleWidth;
+                m_trailingCollapsibleContent.isFullyCollapsible = false;
+            }
+            // End of whitspace content.
+            break;
+        }
     }
 }
 
-void LineBreaker::Content::reset()
+bool LineBreaker::ContinousContent::hasTextContentOnly() const
 {
-    m_continousRuns.clear();
-    m_trailingCollapsibleContent.reset();
-    m_width = 0_lu;
-}
-
-void LineBreaker::Content::shrink(unsigned newSize)
-{
-    for (auto i = m_continousRuns.size(); i--;)
-        m_width -= m_continousRuns[i].logicalWidth;
-    m_continousRuns.shrink(newSize);
-}
-
-bool LineBreaker::Content::hasTextContentOnly() const
-{
     // <span>text</span> is considered a text run even with the [container start][container end] inline items.
     // Due to commit boundary rules, we just need to check the first non-typeless inline item (can't have both [img] and [text])
-    for (auto& run : m_continousRuns) {
+    for (auto& run : m_runs) {
         auto& inlineItem = run.inlineItem;
         if (inlineItem.isContainerStart() || inlineItem.isContainerEnd())
             continue;
@@ -437,12 +430,12 @@
     return false;
 }
 
-bool LineBreaker::Content::isVisuallyEmptyWhitespaceContentOnly() const
+bool LineBreaker::ContinousContent::isVisuallyEmptyWhitespaceContentOnly() const
 {
     // [<span></span> ] [<span> </span>] [ <span style="padding: 0px;"></span>] are all considered visually empty whitespace content.
     // [<span style="border: 1px solid red"></span> ] while this is whitespace content only, it is not considered visually empty.
     // Due to commit boundary rules, we just need to check the first non-typeless inline item (can't have both [img] and [text])
-    for (auto& run : m_continousRuns) {
+    for (auto& run : m_runs) {
         auto& inlineItem = run.inlineItem;
         // FIXME: check for padding border etc.
         if (inlineItem.isContainerStart() || inlineItem.isContainerEnd())
@@ -452,19 +445,19 @@
     return false;
 }
 
-Optional<unsigned> LineBreaker::Content::firstTextRunIndex() const
+Optional<unsigned> LineBreaker::ContinousContent::firstTextRunIndex() const
 {
-    for (size_t index = 0; index < m_continousRuns.size(); ++index) {
-        if (m_continousRuns[index].inlineItem.isText())
+    for (size_t index = 0; index < m_runs.size(); ++index) {
+        if (m_runs[index].inlineItem.isText())
             return index;
     }
     return { };
 }
 
-bool LineBreaker::Content::hasNonContentRunsOnly() const
+bool LineBreaker::ContinousContent::hasNonContentRunsOnly() const
 {
     // <span></span> <- non content runs.
-    for (auto& run : m_continousRuns) {
+    for (auto& run : m_runs) {
         auto& inlineItem = run.inlineItem;
         if (inlineItem.isContainerStart() || inlineItem.isContainerEnd())
             continue;
@@ -473,7 +466,7 @@
     return true;
 }
 
-void LineBreaker::Content::TrailingCollapsibleContent::reset()
+void LineBreaker::ContinousContent::TrailingCollapsibleContent::reset()
 {
     isFullyCollapsible = false;
     width = 0_lu;

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.h (253710 => 253711)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.h	2019-12-18 20:44:13 UTC (rev 253710)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineBreaker.h	2019-12-18 21:28:55 UTC (rev 253711)
@@ -72,18 +72,15 @@
     // [content]
     // [container start][span1][container end][between][container start][span2][container end]
     // see https://drafts.csswg.org/css-text-3/#line-break-details
-    struct Content {
-        void append(const InlineItem&, InlineLayoutUnit logicalWidth);
-        void reset();
-        void shrink(unsigned newSize);
+    struct ContinousContent {
+        ContinousContent(const RunList&);
 
-        RunList& runs() { return m_continousRuns; }
-        const RunList& runs() const { return m_continousRuns; }
-        bool isEmpty() const { return m_continousRuns.isEmpty(); }
+        const RunList& runs() const { return m_runs; }
+        bool isEmpty() const { return m_runs.isEmpty(); }
         bool hasTextContentOnly() const;
         bool isVisuallyEmptyWhitespaceContentOnly() const;
         bool hasNonContentRunsOnly() const;
-        unsigned size() const { return m_continousRuns.size(); }
+        size_t size() const { return m_runs.size(); }
         InlineLayoutUnit width() const { return m_width; }
         InlineLayoutUnit nonCollapsibleWidth() const { return m_width - m_trailingCollapsibleContent.width; }
 
@@ -93,7 +90,7 @@
         Optional<unsigned> firstTextRunIndex() const;
 
     private:
-        RunList m_continousRuns;
+        RunList m_runs;
         struct TrailingCollapsibleContent {
             void reset();
 
@@ -110,7 +107,7 @@
         bool lineHasFullyCollapsibleTrailingRun { false };
         bool lineIsEmpty { true };
     };
-    BreakingContext breakingContextForInlineContent(const Content& candidateRuns, const LineStatus&);
+    BreakingContext breakingContextForInlineContent(const ContinousContent& candidateRuns, const LineStatus&);
     bool shouldWrapFloatBox(InlineLayoutUnit floatLogicalWidth, InlineLayoutUnit availableWidth, bool lineIsEmpty);
 
     void setHyphenationDisabled() { n_hyphenationIsDisabled = true; }

Modified: trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp (253710 => 253711)


--- trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp	2019-12-18 20:44:13 UTC (rev 253710)
+++ trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp	2019-12-18 21:28:55 UTC (rev 253711)
@@ -208,7 +208,7 @@
     if (shouldDisableHyphenation())
         lineBreaker.setHyphenationDisabled();
     auto lineStatus = LineBreaker::LineStatus { line.availableWidth(), line.trailingCollapsibleWidth(), line.isTrailingRunFullyCollapsible(), lineIsConsideredEmpty };
-    auto breakingContext = lineBreaker.breakingContextForInlineContent(m_uncommittedContent, lineStatus);
+    auto breakingContext = lineBreaker.breakingContextForInlineContent(LineBreaker::ContinousContent { m_uncommittedContent.runs() }, lineStatus);
     // The uncommitted content can fully, partially fit the current line (commit/partial commit) or not at all (reset).
     if (breakingContext.contentWrappingRule == LineBreaker::BreakingContext::ContentWrappingRule::Keep)
         commitPendingContent(line);
@@ -248,7 +248,30 @@
     return breakingContext.contentWrappingRule == LineBreaker::BreakingContext::ContentWrappingRule::Keep ? IsEndOfLine::No : IsEndOfLine::Yes;
 }
 
+void LineLayoutContext::UncommittedContent::append(const InlineItem& inlineItem, InlineLayoutUnit logicalWidth)
+{
+    ASSERT(!inlineItem.isFloat());
+    m_uncommittedList.append({ inlineItem, logicalWidth });
+    m_width += logicalWidth;
 }
+
+void LineLayoutContext::UncommittedContent::reset()
+{
+    m_uncommittedList.clear();
+    m_width = 0_lu;
 }
 
+void LineLayoutContext::UncommittedContent::shrink(size_t newSize)
+{
+    ASSERT(newSize);
+    ASSERT(m_uncommittedList.size());
+    ASSERT(newSize < m_uncommittedList.size());
+    for (size_t i = m_uncommittedList.size() - 1; i >= newSize ; --i)
+        m_width -= m_uncommittedList[i].logicalWidth;
+    m_uncommittedList.shrink(newSize);
+}
+
+}
+}
+
 #endif

Modified: trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.h (253710 => 253711)


--- trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.h	2019-12-18 20:44:13 UTC (rev 253710)
+++ trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.h	2019-12-18 21:28:55 UTC (rev 253711)
@@ -62,7 +62,21 @@
     const InlineFormattingContext& m_inlineFormattingContext;
     const Container& m_formattingContextRoot;
     const InlineItems& m_inlineItems;
-    LineBreaker::Content m_uncommittedContent;
+
+    struct UncommittedContent {
+        void append(const InlineItem&, InlineLayoutUnit logicalWidth);
+        InlineLayoutUnit width() const { return m_width; }
+        size_t size() { return runs().size(); }
+        bool isEmpty() { return runs().isEmpty(); }
+        void reset();
+        void shrink(size_t newSize);
+        const LineBreaker::RunList& runs() const { return m_uncommittedList; }
+
+    private:
+        LineBreaker::RunList m_uncommittedList;
+        InlineLayoutUnit m_width;
+    };
+    UncommittedContent m_uncommittedContent;
     unsigned m_committedInlineItemCount { 0 };
     Vector<WeakPtr<InlineItem>> m_floats;
     std::unique_ptr<InlineTextItem> m_partialLeadingTextItem;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to