Title: [247668] trunk/Source/WebCore
Revision
247668
Author
[email protected]
Date
2019-07-20 11:52:15 -0700 (Sat, 20 Jul 2019)

Log Message

[LFC][IFC] Add support for mid-word break.
https://bugs.webkit.org/show_bug.cgi?id=199976
<rdar://problem/53337349>

Reviewed by Antti Koivisto.

Introduce leading and trailing InlineTextItem to support incoming and outgoing partial content.
TextUtil::split is a straight copy of SimpleLineLayout::split.

* layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
(WebCore::Layout::inlineItemWidth):
(WebCore::Layout::LineLayout::close):
(WebCore::Layout::LineLayout::placeInlineItem):
(WebCore::Layout::LineLayout::layout):
* layout/inlineformatting/InlineTextItem.cpp:
(WebCore::Layout::InlineTextItem::split const):
(WebCore::Layout::InlineTextItem::split): Deleted.
* layout/inlineformatting/InlineTextItem.h:
(WebCore::Layout::InlineTextItem::inlineBox const):
* layout/inlineformatting/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::split):
* layout/inlineformatting/text/TextUtil.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (247667 => 247668)


--- trunk/Source/WebCore/ChangeLog	2019-07-20 13:47:11 UTC (rev 247667)
+++ trunk/Source/WebCore/ChangeLog	2019-07-20 18:52:15 UTC (rev 247668)
@@ -1,5 +1,30 @@
 2019-07-20  Zalan Bujtas  <[email protected]>
 
+        [LFC][IFC] Add support for mid-word break.
+        https://bugs.webkit.org/show_bug.cgi?id=199976
+        <rdar://problem/53337349>
+
+        Reviewed by Antti Koivisto.
+
+        Introduce leading and trailing InlineTextItem to support incoming and outgoing partial content.
+        TextUtil::split is a straight copy of SimpleLineLayout::split.
+
+        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
+        (WebCore::Layout::inlineItemWidth):
+        (WebCore::Layout::LineLayout::close):
+        (WebCore::Layout::LineLayout::placeInlineItem):
+        (WebCore::Layout::LineLayout::layout):
+        * layout/inlineformatting/InlineTextItem.cpp:
+        (WebCore::Layout::InlineTextItem::split const):
+        (WebCore::Layout::InlineTextItem::split): Deleted.
+        * layout/inlineformatting/InlineTextItem.h:
+        (WebCore::Layout::InlineTextItem::inlineBox const):
+        * layout/inlineformatting/text/TextUtil.cpp:
+        (WebCore::Layout::TextUtil::split):
+        * layout/inlineformatting/text/TextUtil.h:
+
+2019-07-20  Zalan Bujtas  <[email protected]>
+
         [Text autosizing] Do not nuke the style on dynamicViewportSizeUpdate
         https://bugs.webkit.org/show_bug.cgi?id=199718
         <rdar://problem/53344961>

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp (247667 => 247668)


--- trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp	2019-07-20 13:47:11 UTC (rev 247667)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp	2019-07-20 18:52:15 UTC (rev 247668)
@@ -49,7 +49,7 @@
     if (is<InlineTextItem>(inlineItem)) {
         auto& inlineTextItem = downcast<InlineTextItem>(inlineItem);
         auto end = inlineTextItem.isCollapsed() ? inlineTextItem.start() + 1 : inlineTextItem.end();
-        return TextUtil::width(downcast<InlineBox>(inlineTextItem.layoutBox()), inlineTextItem.start(), end, contentLogicalLeft);
+        return TextUtil::width(inlineTextItem.inlineBox(), inlineTextItem.start(), end, contentLogicalLeft);
     }
 
     auto& layoutBox = inlineItem.layoutBox();
@@ -115,7 +115,6 @@
         struct Run {
             const InlineItem& inlineItem;
             LayoutUnit logicalWidth;
-            // FIXME: add optional breaking context (start and end position) for split text content.
         };
         void add(const InlineItem&, LayoutUnit logicalWidth);
         void reset();
@@ -138,6 +137,8 @@
     UncommittedContent m_uncommittedContent;
     unsigned m_committedInlineItemCount { 0 };
     Vector<WeakPtr<InlineItem>> m_floats;
+    std::unique_ptr<InlineTextItem> m_leadingPartialInlineTextItem;
+    std::unique_ptr<InlineTextItem> m_trailingPartialInlineTextItem;
 };
 
 void LineLayout::UncommittedContent::add(const InlineItem& inlineItem, LayoutUnit logicalWidth)
@@ -175,8 +176,13 @@
     ASSERT(m_committedInlineItemCount || m_lineHasFloatBox);
     if (!m_committedInlineItemCount)
         return LineContent { WTF::nullopt, WTFMove(m_floats), m_line.close() };
-    // FIXME Add partial context if applicable.
-    auto lastCommitedItem = IndexAndRange { m_lineInput.firstInlineItem.index + (m_committedInlineItemCount - 1), { } };
+
+    auto lastInlineItemIndex = m_lineInput.firstInlineItem.index + m_committedInlineItemCount - 1;
+    Optional<IndexAndRange::Range> partialContext;
+    if (m_trailingPartialInlineTextItem)
+        partialContext = IndexAndRange::Range { m_trailingPartialInlineTextItem->start(), m_trailingPartialInlineTextItem->length() };
+
+    auto lastCommitedItem = IndexAndRange { lastInlineItemIndex, partialContext };
     return LineContent { lastCommitedItem, WTFMove(m_floats), m_line.close() };
 }
 
@@ -199,8 +205,13 @@
     // Partial content stays on the current line.
     if (breakingContext.breakingBehavior == LineBreaker::BreakingBehavior::Split) {
         ASSERT(inlineItem.isText());
-
-        ASSERT_NOT_IMPLEMENTED_YET();
+        auto& inlineTextItem = downcast<InlineTextItem>(inlineItem);
+        auto splitData = TextUtil::split(inlineTextItem.inlineBox(), inlineTextItem.start(), inlineTextItem.length(), itemLogicalWidth, availableWidth, currentLogicalRight);
+        // Construct a partial trailing inline item.
+        ASSERT(!m_trailingPartialInlineTextItem);
+        m_trailingPartialInlineTextItem = inlineTextItem.split(splitData.start, splitData.length);
+        m_uncommittedContent.add(*m_trailingPartialInlineTextItem, splitData.logicalWidth);
+        commitPendingContent();
         return IsEndOfLine::Yes;
     }
 
@@ -236,8 +247,10 @@
         RELEASE_ASSERT(originalTextItem->isText());
 
         auto textRange = *firstInlineItem.partialContext;
-        auto partialInlineItem = downcast<InlineTextItem>(*originalTextItem).split(textRange.start, textRange.length);
-        if (placeInlineItem(partialInlineItem) == IsEndOfLine::Yes)
+        // Construct a partial leading inline item.
+        ASSERT(!m_leadingPartialInlineTextItem);
+        m_leadingPartialInlineTextItem = downcast<InlineTextItem>(*originalTextItem).split(textRange.start, textRange.length);
+        if (placeInlineItem(*m_leadingPartialInlineTextItem) == IsEndOfLine::Yes)
             return close();
         ++firstNonPartialIndex;
     }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp (247667 => 247668)


--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp	2019-07-20 13:47:11 UTC (rev 247667)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.cpp	2019-07-20 18:52:15 UTC (rev 247668)
@@ -127,11 +127,11 @@
 {
 }
 
-InlineTextItem InlineTextItem::split(unsigned splitPosition, unsigned length)
+std::unique_ptr<InlineTextItem> InlineTextItem::split(unsigned splitPosition, unsigned length) const
 {
     RELEASE_ASSERT(splitPosition >= this->start());
     RELEASE_ASSERT(splitPosition + length <= end());
-    return { downcast<InlineBox>(layoutBox()), splitPosition, length, isWhitespace(), isCollapsed() };
+    return std::make_unique<InlineTextItem>(inlineBox(), splitPosition, length, isWhitespace(), isCollapsed());
 }
 
 }

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h (247667 => 247668)


--- trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h	2019-07-20 13:47:11 UTC (rev 247667)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineTextItem.h	2019-07-20 18:52:15 UTC (rev 247668)
@@ -27,6 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "InlineBox.h"
 #include "InlineFormattingState.h"
 #include "InlineItem.h"
 
@@ -46,8 +47,10 @@
     bool isWhitespace() const { return m_isWhitespace; }
     bool isCollapsed() const { return m_isCollapsed; }
 
-    InlineTextItem split(unsigned splitPosition, unsigned length);
+    const InlineBox& inlineBox() const { return downcast<InlineBox>(layoutBox()); }
 
+    std::unique_ptr<InlineTextItem> split(unsigned splitPosition, unsigned length) const;
+
 private:
     unsigned m_start { 0 };
     unsigned m_length { 0 };

Modified: trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp (247667 => 247668)


--- trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp	2019-07-20 13:47:11 UTC (rev 247667)
+++ trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.cpp	2019-07-20 18:52:15 UTC (rev 247668)
@@ -97,6 +97,34 @@
     return inlineTextItem.isWhitespace() && inlineTextItem.style().collapseWhiteSpace();
 }
 
+TextUtil::SplitData TextUtil::split(const InlineBox& inlineBox, unsigned startPosition, unsigned length, LayoutUnit textWidth, LayoutUnit availableWidth, LayoutUnit contentLogicalLeft)
+{
+    // FIXME This should take hypens into account.
+    ASSERT(availableWidth >= 0);
+    auto left = startPosition;
+    // Pathological case of (extremely)long string and narrow lines.
+    // Adjust the range so that we can pick a reasonable midpoint.
+    LayoutUnit averageCharacterWidth = textWidth / length;
+    auto right = std::min<unsigned>(left + (2 * availableWidth / averageCharacterWidth).toUnsigned(), (startPosition + length - 1));
+    // Preserve the left width for the final split position so that we don't need to remeasure the left side again.
+    LayoutUnit leftSideWidth = 0;
+    while (left < right) {
+        auto middle = (left + right) / 2;
+        auto width = TextUtil::width(inlineBox, startPosition, middle + 1, contentLogicalLeft);
+        if (width < availableWidth) {
+            left = middle + 1;
+            leftSideWidth = width;
+        } else if (width > availableWidth)
+            right = middle;
+        else {
+            right = middle + 1;
+            leftSideWidth = width;
+            break;
+        }
+    }
+    return { startPosition, right - startPosition, leftSideWidth };
 }
+
 }
+}
 #endif

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


--- trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.h	2019-07-20 13:47:11 UTC (rev 247667)
+++ trunk/Source/WebCore/layout/inlineformatting/text/TextUtil.h	2019-07-20 18:52:15 UTC (rev 247668)
@@ -32,11 +32,19 @@
 namespace WebCore {
 namespace Layout {
 
+class InlineBox;
+
 class TextUtil {
 public:
     static LayoutUnit width(const InlineBox&, unsigned from, unsigned to, LayoutUnit contentLogicalLeft);
     static Optional<unsigned> hyphenPositionBefore(const InlineItem&, unsigned from, unsigned length);
     static bool isTrimmableContent(const InlineItem&);
+    struct SplitData {
+        unsigned start { 0 };
+        unsigned length { 0 };
+        LayoutUnit logicalWidth;
+    };
+    static SplitData split(const InlineBox&, unsigned startPosition, unsigned length, LayoutUnit textWidth, LayoutUnit availableWidth, LayoutUnit contentLogicalLeft);
 
 private:
     static LayoutUnit fixedPitchWidth(String, const RenderStyle&, unsigned from, unsigned to, LayoutUnit contentLogicalLeft);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to