Title: [252696] trunk/Source/WebCore
Revision
252696
Author
[email protected]
Date
2019-11-20 10:57:00 -0800 (Wed, 20 Nov 2019)

Log Message

[LFC][IFC] Cache InlinteTextItem width when possible
https://bugs.webkit.org/show_bug.cgi?id=204412
<rdar://problem/57359366>

Reviewed by Antti Koivisto.

This helps when subsequent inline layouts use the same set of InlineTextItems and they would
keep re-measuring them on each layout frame (e.g. view resize).

* layout/inlineformatting/InlineLineLayout.cpp:
(WebCore::Layout::inlineItemWidth):
* layout/inlineformatting/InlineTextItem.cpp:
(WebCore::Layout::InlineTextItem::createAndAppendTextItems):
(WebCore::Layout::InlineTextItem::createWhitespaceItem):
(WebCore::Layout::InlineTextItem::createNonWhitespaceItem):
(WebCore::Layout::InlineTextItem::createSegmentBreakItem):
(WebCore::Layout::InlineTextItem::InlineTextItem):
(WebCore::Layout::InlineTextItem::left const):
(WebCore::Layout::InlineTextItem::right const):
* layout/inlineformatting/InlineTextItem.h:
(WebCore::Layout::InlineTextItem::width const):
* layout/inlineformatting/text/TextUtil.h:
(WebCore::Layout::TextUtil::width):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (252695 => 252696)


--- trunk/Source/WebCore/ChangeLog	2019-11-20 18:53:27 UTC (rev 252695)
+++ trunk/Source/WebCore/ChangeLog	2019-11-20 18:57:00 UTC (rev 252696)
@@ -1,3 +1,29 @@
+2019-11-20  Zalan Bujtas  <[email protected]>
+
+        [LFC][IFC] Cache InlinteTextItem width when possible
+        https://bugs.webkit.org/show_bug.cgi?id=204412
+        <rdar://problem/57359366>
+
+        Reviewed by Antti Koivisto.
+
+        This helps when subsequent inline layouts use the same set of InlineTextItems and they would
+        keep re-measuring them on each layout frame (e.g. view resize).
+
+        * layout/inlineformatting/InlineLineLayout.cpp:
+        (WebCore::Layout::inlineItemWidth):
+        * layout/inlineformatting/InlineTextItem.cpp:
+        (WebCore::Layout::InlineTextItem::createAndAppendTextItems):
+        (WebCore::Layout::InlineTextItem::createWhitespaceItem):
+        (WebCore::Layout::InlineTextItem::createNonWhitespaceItem):
+        (WebCore::Layout::InlineTextItem::createSegmentBreakItem):
+        (WebCore::Layout::InlineTextItem::InlineTextItem):
+        (WebCore::Layout::InlineTextItem::left const):
+        (WebCore::Layout::InlineTextItem::right const):
+        * layout/inlineformatting/InlineTextItem.h:
+        (WebCore::Layout::InlineTextItem::width const):
+        * layout/inlineformatting/text/TextUtil.h:
+        (WebCore::Layout::TextUtil::width):
+
 2019-11-20  Jer Noble  <[email protected]>
 
         HTML5 audio .ended event not fired when app in background or phone screen is off

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineLineLayout.cpp (252695 => 252696)


--- trunk/Source/WebCore/layout/inlineformatting/InlineLineLayout.cpp	2019-11-20 18:53:27 UTC (rev 252695)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineLineLayout.cpp	2019-11-20 18:57:00 UTC (rev 252696)
@@ -42,6 +42,8 @@
 
     if (is<InlineTextItem>(inlineItem)) {
         auto& inlineTextItem = downcast<InlineTextItem>(inlineItem);
+        if (auto contentWidth = inlineTextItem.width())
+            return *contentWidth;
         auto end = inlineTextItem.isCollapsible() ? inlineTextItem.start() + 1 : inlineTextItem.end();
         return TextUtil::width(inlineTextItem.layoutBox(), inlineTextItem.start(), end, contentLogicalLeft);
     }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp (252695 => 252696)


--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp	2019-11-20 18:53:27 UTC (rev 252695)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp	2019-11-20 18:57:00 UTC (rev 252696)
@@ -89,6 +89,13 @@
     auto& style = inlineBox.style();
     LazyLineBreakIterator lineBreakIterator(text);
     unsigned currentPosition = 0;
+
+    auto inlineItemWidth = [&](auto startPosition, auto length) -> Optional<LayoutUnit> {
+        if (!inlineBox.textContext().canUseSimplifiedContentMeasuring)
+            return { };
+        return TextUtil::width(inlineBox, startPosition, startPosition + length);
+    };
+
     while (currentPosition < text.length()) {
         auto isSegmentBreakCandidate = [](auto character) {
             return character == '\n';
@@ -101,32 +108,33 @@
             ++currentPosition;
             continue;
         }
+
         if (isWhitespaceCharacter(text[currentPosition])) {
             auto length = moveToNextNonWhitespacePosition(text, currentPosition);
-            inlineContent.append(InlineTextItem::createWhitespaceItem(inlineBox, currentPosition, length));
+            inlineContent.append(InlineTextItem::createWhitespaceItem(inlineBox, currentPosition, length, inlineItemWidth(currentPosition, length)));
             currentPosition += length;
             continue;
         }
 
         auto length = moveToNextBreakablePosition(currentPosition, lineBreakIterator, style);
-        inlineContent.append(InlineTextItem::createNonWhitespaceItem(inlineBox, currentPosition, length));
+        inlineContent.append(InlineTextItem::createNonWhitespaceItem(inlineBox, currentPosition, length, inlineItemWidth(currentPosition, length)));
         currentPosition += length;
     }
 }
 
-std::unique_ptr<InlineTextItem> InlineTextItem::createWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length)
+std::unique_ptr<InlineTextItem> InlineTextItem::createWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length, Optional<LayoutUnit> width)
 {
-    return makeUnique<InlineTextItem>(inlineBox, start, length, TextItemType::Whitespace);
+    return makeUnique<InlineTextItem>(inlineBox, start, length, width, TextItemType::Whitespace);
 }
 
-std::unique_ptr<InlineTextItem> InlineTextItem::createNonWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length)
+std::unique_ptr<InlineTextItem> InlineTextItem::createNonWhitespaceItem(const Box& inlineBox, unsigned start, unsigned length, Optional<LayoutUnit> width)
 {
-    return makeUnique<InlineTextItem>(inlineBox, start, length, TextItemType::NonWhitespace);
+    return makeUnique<InlineTextItem>(inlineBox, start, length, width, TextItemType::NonWhitespace);
 }
 
 std::unique_ptr<InlineTextItem> InlineTextItem::createSegmentBreakItem(const Box& inlineBox, unsigned position)
 {
-    return makeUnique<InlineTextItem>(inlineBox, position, 1, TextItemType::SegmentBreak);
+    return makeUnique<InlineTextItem>(inlineBox, position, 1, WTF::nullopt, TextItemType::SegmentBreak);
 }
 
 std::unique_ptr<InlineTextItem> InlineTextItem::createEmptyItem(const Box& inlineBox)
@@ -134,10 +142,11 @@
     return makeUnique<InlineTextItem>(inlineBox);
 }
 
-InlineTextItem::InlineTextItem(const Box& inlineBox, unsigned start, unsigned length, TextItemType textItemType)
+InlineTextItem::InlineTextItem(const Box& inlineBox, unsigned start, unsigned length, Optional<LayoutUnit> width, TextItemType textItemType)
     : InlineItem(inlineBox, Type::Text)
     , m_start(start)
     , m_length(length)
+    , m_width(width)
     , m_textItemType(textItemType)
 {
 }
@@ -151,7 +160,7 @@
 {
     RELEASE_ASSERT(length <= this->length());
     ASSERT(m_textItemType != TextItemType::Undefined);
-    return makeUnique<InlineTextItem>(layoutBox(), start(), length, m_textItemType);
+    return makeUnique<InlineTextItem>(layoutBox(), start(), length, WTF::nullopt, m_textItemType);
 }
 
 std::unique_ptr<InlineTextItem> InlineTextItem::right(unsigned length) const
@@ -158,7 +167,7 @@
 {
     RELEASE_ASSERT(length <= this->length());
     ASSERT(m_textItemType != TextItemType::Undefined);
-    return makeUnique<InlineTextItem>(layoutBox(), end() - length, length, m_textItemType);
+    return makeUnique<InlineTextItem>(layoutBox(), end() - length, length, WTF::nullopt, m_textItemType);
 }
 
 }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h (252695 => 252696)


--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h	2019-11-20 18:53:27 UTC (rev 252695)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h	2019-11-20 18:57:00 UTC (rev 252696)
@@ -37,8 +37,8 @@
 public:
     static void createAndAppendTextItems(InlineItems&, const Box&);
 
-    static std::unique_ptr<InlineTextItem> createWhitespaceItem(const Box&, unsigned start, unsigned length);
-    static std::unique_ptr<InlineTextItem> createNonWhitespaceItem(const Box&, unsigned start, unsigned length);
+    static std::unique_ptr<InlineTextItem> createWhitespaceItem(const Box&, unsigned start, unsigned length, Optional<LayoutUnit> width);
+    static std::unique_ptr<InlineTextItem> createNonWhitespaceItem(const Box&, unsigned start, unsigned length, Optional<LayoutUnit> width);
     static std::unique_ptr<InlineTextItem> createSegmentBreakItem(const Box&, unsigned position);
     static std::unique_ptr<InlineTextItem> createEmptyItem(const Box&);
 
@@ -49,17 +49,19 @@
     bool isWhitespace() const { return m_textItemType == TextItemType::Whitespace || isSegmentBreak(); }
     bool isCollapsible() const { return isWhitespace() && style().collapseWhiteSpace(); }
     bool isSegmentBreak() const { return m_textItemType == TextItemType::SegmentBreak; }
+    Optional<LayoutUnit> width() const { return m_width; }
 
     std::unique_ptr<InlineTextItem> left(unsigned length) const;
     std::unique_ptr<InlineTextItem> right(unsigned length) const;
 
     enum class TextItemType { Undefined, Whitespace, NonWhitespace, SegmentBreak };
-    InlineTextItem(const Box&, unsigned start, unsigned length, TextItemType);
+    InlineTextItem(const Box&, unsigned start, unsigned length, Optional<LayoutUnit> width, TextItemType);
     InlineTextItem(const Box&);
 
 private:
     unsigned m_start { 0 };
     unsigned m_length { 0 };
+    Optional<LayoutUnit> m_width;
     TextItemType m_textItemType { TextItemType::Undefined };
 };
 

Modified: trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.h (252695 => 252696)


--- trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.h	2019-11-20 18:53:27 UTC (rev 252695)
+++ trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.h	2019-11-20 18:57:00 UTC (rev 252696)
@@ -34,7 +34,7 @@
 
 class TextUtil {
 public:
-    static LayoutUnit width(const Box&, unsigned from, unsigned to, LayoutUnit contentLogicalLeft);
+    static LayoutUnit width(const Box&, unsigned from, unsigned to, LayoutUnit contentLogicalLeft = { });
     static Optional<unsigned> hyphenPositionBefore(const InlineItem&, unsigned from, unsigned length);
     struct SplitData {
         unsigned start { 0 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to