Title: [281754] trunk/Source/WebCore
Revision
281754
Author
[email protected]
Date
2021-08-30 07:12:45 -0700 (Mon, 30 Aug 2021)

Log Message

[LFC][IFC] Introduce Line::Run::Text to hold text content related properties
https://bugs.webkit.org/show_bug.cgi?id=229658

Reviewed by Antti Koivisto.

Let's use a dedicated (and more compact) structure here instead of relying on a display type of structure.
This is in preparation for merging the display and the integration runs.

* layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
(WebCore::Layout::InlineDisplayContentBuilder::createRunsAndUpdateGeometryForLineContent):
* layout/formattingContexts/inline/InlineLine.cpp:
(WebCore::Layout::Line::applyRunExpansion):
(WebCore::Layout::Line::TrimmableTrailingContent::remove):
(WebCore::Layout::Line::Run::Run):
(WebCore::Layout::m_textContent):
(WebCore::Layout::Line::Run::expand):
(WebCore::Layout::Line::Run::removeTrailingWhitespace):
* layout/formattingContexts/inline/InlineLine.h:
(WebCore::Layout::Line::Run::textContent const):
(WebCore::Layout::Line::Run::setNeedsHyphen):
* layout/formattingContexts/inline/InlineLineBuilder.cpp:
(WebCore::Layout::LineBuilder::close):
* layout/formattingContexts/inline/InlineLineRun.h:
(WebCore::Layout::LineRun::Text::needsHyphen const):
(WebCore::Layout::LineRun::Text::Text):
(WebCore::Layout::LineRun::Text::setNeedsHyphen): Deleted.
(WebCore::Layout::LineRun::Text::expand): Deleted.
(WebCore::Layout::LineRun::Text::shrink): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (281753 => 281754)


--- trunk/Source/WebCore/ChangeLog	2021-08-30 09:26:45 UTC (rev 281753)
+++ trunk/Source/WebCore/ChangeLog	2021-08-30 14:12:45 UTC (rev 281754)
@@ -1,3 +1,34 @@
+2021-08-30  Alan Bujtas  <[email protected]>
+
+        [LFC][IFC] Introduce Line::Run::Text to hold text content related properties
+        https://bugs.webkit.org/show_bug.cgi?id=229658
+
+        Reviewed by Antti Koivisto.
+
+        Let's use a dedicated (and more compact) structure here instead of relying on a display type of structure.
+        This is in preparation for merging the display and the integration runs.
+
+        * layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp:
+        (WebCore::Layout::InlineDisplayContentBuilder::createRunsAndUpdateGeometryForLineContent):
+        * layout/formattingContexts/inline/InlineLine.cpp:
+        (WebCore::Layout::Line::applyRunExpansion):
+        (WebCore::Layout::Line::TrimmableTrailingContent::remove):
+        (WebCore::Layout::Line::Run::Run):
+        (WebCore::Layout::m_textContent):
+        (WebCore::Layout::Line::Run::expand):
+        (WebCore::Layout::Line::Run::removeTrailingWhitespace):
+        * layout/formattingContexts/inline/InlineLine.h:
+        (WebCore::Layout::Line::Run::textContent const):
+        (WebCore::Layout::Line::Run::setNeedsHyphen):
+        * layout/formattingContexts/inline/InlineLineBuilder.cpp:
+        (WebCore::Layout::LineBuilder::close):
+        * layout/formattingContexts/inline/InlineLineRun.h:
+        (WebCore::Layout::LineRun::Text::needsHyphen const):
+        (WebCore::Layout::LineRun::Text::Text):
+        (WebCore::Layout::LineRun::Text::setNeedsHyphen): Deleted.
+        (WebCore::Layout::LineRun::Text::expand): Deleted.
+        (WebCore::Layout::LineRun::Text::shrink): Deleted.
+
 2021-08-29  Alan Bujtas  <[email protected]>
 
         [LFC][IFC] Move "line needs integral snapping" computing to IFC from the integration layer

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp (281753 => 281754)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp	2021-08-30 09:26:45 UTC (rev 281753)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp	2021-08-30 14:12:45 UTC (rev 281754)
@@ -88,13 +88,18 @@
                 }
                 return inkOverflow;
             };
-            formattingState.addLineRun({ lineIndex, LineRun::Type::Text, layoutBox, textRunRect, inkOverflow(), lineRun.expansion(), lineRun.textContent() });
+            ASSERT(lineRun.textContent() && is<InlineTextBox>(layoutBox));
+            auto& textContent = lineRun.textContent();
+            formattingState.addLineRun({ lineIndex, LineRun::Type::Text, layoutBox, textRunRect, inkOverflow(), lineRun.expansion(), LineRun::Text { textContent->start, textContent->length, downcast<InlineTextBox>(layoutBox).content(), textContent->needsHyphen } });
             break;
         }
         case InlineItem::Type::SoftLineBreak: {
             auto softLineBreakRunRect = lineBox.logicalRectForTextRun(lineRun);
             softLineBreakRunRect.moveBy(lineBoxLogicalTopLeft);
-            formattingState.addLineRun({ lineIndex, LineRun::Type::SoftLineBreak, layoutBox, softLineBreakRunRect, softLineBreakRunRect, lineRun.expansion(), lineRun.textContent() });
+
+            ASSERT(lineRun.textContent() && is<InlineTextBox>(layoutBox));
+            auto& textContent = lineRun.textContent();
+            formattingState.addLineRun({ lineIndex, LineRun::Type::SoftLineBreak, layoutBox, softLineBreakRunRect, softLineBreakRunRect, lineRun.expansion(), LineRun::Text { textContent->start, textContent->length, downcast<InlineTextBox>(layoutBox).content(), textContent->needsHyphen } });
             break;
         }
         case InlineItem::Type::HardLineBreak: {

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp (281753 => 281754)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2021-08-30 09:26:45 UTC (rev 281753)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp	2021-08-30 14:12:45 UTC (rev 281754)
@@ -96,7 +96,7 @@
                 expansionBehavior = ForbidLeftExpansion | ForbidRightExpansion;
             else {
                 expansionBehavior = (runIsAfterExpansion ? ForbidLeftExpansion : AllowLeftExpansion) | AllowRightExpansion;
-                std::tie(expansionOpportunitiesInRun, runIsAfterExpansion) = FontCascade::expansionOpportunityCount(StringView(run.textContent()->content()).substring(run.textContent()->start(), run.textContent()->length()), run.style().direction(), expansionBehavior);
+                std::tie(expansionOpportunitiesInRun, runIsAfterExpansion) = FontCascade::expansionOpportunityCount(StringView(downcast<InlineTextBox>(run.layoutBox()).content()).substring(run.textContent()->start, run.textContent()->length), run.style().direction(), expansionBehavior);
             }
         } else if (run.isBox())
             runIsAfterExpansion = false;
@@ -428,7 +428,7 @@
         ASSERT(run.isWordBreakOpportunity() || run.isInlineBoxStart() || run.isInlineBoxEnd() || run.isLineBreak());
         run.moveHorizontally(-trimmableWidth);
     }
-    if (!trimmableRun.textContent()->length()) {
+    if (!trimmableRun.textContent()->length) {
         // This trimmable run is fully collapsed now (e.g. <div><img>    <span></span></div>).
         // We don't need to keep it around anymore.
         m_runs.remove(*m_firstTrimmableRunIndex);
@@ -457,7 +457,7 @@
     : m_type(softLineBreakItem.type())
     , m_layoutBox(&softLineBreakItem.layoutBox())
     , m_logicalLeft(logicalLeft)
-    , m_textContent({ softLineBreakItem.position(), 1, softLineBreakItem.inlineTextBox().content() })
+    , m_textContent({ softLineBreakItem.position(), 1 })
 {
 }
 
@@ -468,7 +468,7 @@
     , m_logicalWidth(logicalWidth)
     , m_trailingWhitespaceType(trailingWhitespaceType(inlineTextItem))
     , m_trailingWhitespaceWidth(m_trailingWhitespaceType != TrailingWhitespace::None ? logicalWidth : InlineLayoutUnit { })
-    , m_textContent({ inlineTextItem.start(), m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length(), inlineTextItem.inlineTextBox().content() })
+    , m_textContent({ inlineTextItem.start(), m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length() })
 {
 }
 
@@ -483,11 +483,11 @@
 
     if (m_trailingWhitespaceType == TrailingWhitespace::None) {
         m_trailingWhitespaceWidth = { };
-        m_textContent->expand(inlineTextItem.length());
+        m_textContent->length += inlineTextItem.length();
         return;
     }
     m_trailingWhitespaceWidth += logicalWidth;
-    m_textContent->expand(m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length());
+    m_textContent->length += m_trailingWhitespaceType == TrailingWhitespace::Collapsed ? 1 : inlineTextItem.length();
 }
 
 bool Line::Run::hasTrailingLetterSpacing() const
@@ -513,9 +513,9 @@
 {
     // According to https://www.w3.org/TR/css-text-3/#white-space-property matrix
     // Trimmable whitespace is always collapsible so the length of the trailing trimmable whitespace is always 1 (or non-existent).
-    ASSERT(m_textContent->length());
+    ASSERT(m_textContent->length);
     constexpr size_t trailingTrimmableContentLength = 1;
-    m_textContent->shrink(trailingTrimmableContentLength);
+    m_textContent->length -= trailingTrimmableContentLength;
     visuallyCollapseTrailingWhitespace(m_trailingWhitespaceWidth);
 }
 

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h (281753 => 281754)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h	2021-08-30 09:26:45 UTC (rev 281753)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLine.h	2021-08-30 14:12:45 UTC (rev 281754)
@@ -72,7 +72,12 @@
 
         const Box& layoutBox() const { return *m_layoutBox; }
         const RenderStyle& style() const { return m_layoutBox->style(); }
-        const std::optional<LineRun::Text>& textContent() const { return m_textContent; }
+        struct Text {
+            size_t start { 0 };
+            size_t length { 0 };
+            bool needsHyphen { false };
+        };
+        const std::optional<Text>& textContent() const { return m_textContent; }
 
         InlineLayoutUnit logicalWidth() const { return m_logicalWidth; }
         InlineLayoutUnit logicalLeft() const { return m_logicalLeft; }
@@ -118,7 +123,7 @@
         InlineLayoutUnit m_logicalWidth { 0 };
         TrailingWhitespace m_trailingWhitespaceType { TrailingWhitespace::None };
         InlineLayoutUnit m_trailingWhitespaceWidth { 0 };
-        std::optional<LineRun::Text> m_textContent;
+        std::optional<Text> m_textContent;
         LineRun::Expansion m_expansion;
     };
     using RunList = Vector<Run, 10>;
@@ -192,7 +197,7 @@
 inline void Line::Run::setNeedsHyphen(InlineLayoutUnit hyphenLogicalWidth)
 {
     ASSERT(m_textContent);
-    m_textContent->setNeedsHyphen();
+    m_textContent->needsHyphen = true;
     m_logicalWidth += hyphenLogicalWidth;
 }
 

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp (281753 => 281754)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp	2021-08-30 09:26:45 UTC (rev 281753)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBuilder.cpp	2021-08-30 14:12:45 UTC (rev 281754)
@@ -375,7 +375,7 @@
     auto lineEndsWithHyphen = false;
     if (!m_line.runs().isEmpty()) {
         auto& lastTextContent = m_line.runs().last().textContent();
-        lineEndsWithHyphen = lastTextContent && lastTextContent->needsHyphen();
+        lineEndsWithHyphen = lastTextContent && lastTextContent->needsHyphen;
     }
     m_successiveHyphenatedLineCount = lineEndsWithHyphen ? m_successiveHyphenatedLineCount + 1 : 0;
     return lineRange;

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineRun.h (281753 => 281754)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineRun.h	2021-08-30 09:26:45 UTC (rev 281753)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineRun.h	2021-08-30 14:12:45 UTC (rev 281754)
@@ -39,7 +39,7 @@
     struct Text {
         WTF_MAKE_STRUCT_FAST_ALLOCATED;
     public:
-        Text(size_t position, size_t length, const String&);
+        Text(size_t position, size_t length, const String&, bool needsHyphen = false);
 
         size_t start() const { return m_start; }
         size_t end() const { return start() + length(); }
@@ -47,11 +47,7 @@
         String content() const { return m_contentString; }
 
         bool needsHyphen() const { return m_needsHyphen; }
-        void setNeedsHyphen() { m_needsHyphen = true; }
 
-        void expand(size_t delta) { m_length += delta; }
-        void shrink(size_t delta) { m_length -= delta; }
-
     private:
         size_t m_start { 0 };
         size_t m_length { 0 };
@@ -137,9 +133,10 @@
 {
 }
 
-inline LineRun::Text::Text(size_t start, size_t length, const String& contentString)
+inline LineRun::Text::Text(size_t start, size_t length, const String& contentString, bool needsHyphen)
     : m_start(start)
     , m_length(length)
+    , m_needsHyphen(needsHyphen)
     , m_contentString(contentString)
 {
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to