Title: [272128] trunk/Source/WebCore
Revision
272128
Author
[email protected]
Date
2021-01-31 16:45:56 -0800 (Sun, 31 Jan 2021)

Log Message

[LFC][IFC] InlineContentBreaker::processOverflowingTextContent should find breaking positions even after the overflowing run
https://bugs.webkit.org/show_bug.cgi?id=221189

Reviewed by Antti Koivisto.

When the content has multiple (continous)runs, and we find the overflowing one
1. first start searching backwards to see if we can find something that's breakable (this is already implemented)
2. start searching forward to see if we can find something that's breakable -though in this case it's surely overflowing.

This patch implements #2.

* layout/inlineformatting/InlineContentBreaker.cpp:
(WebCore::Layout::InlineContentBreaker::processOverflowingTextContent const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (272127 => 272128)


--- trunk/Source/WebCore/ChangeLog	2021-01-31 20:48:01 UTC (rev 272127)
+++ trunk/Source/WebCore/ChangeLog	2021-02-01 00:45:56 UTC (rev 272128)
@@ -1,5 +1,21 @@
 2021-01-31  Zalan Bujtas  <[email protected]>
 
+        [LFC][IFC] InlineContentBreaker::processOverflowingTextContent should find breaking positions even after the overflowing run
+        https://bugs.webkit.org/show_bug.cgi?id=221189
+
+        Reviewed by Antti Koivisto.
+
+        When the content has multiple (continous)runs, and we find the overflowing one
+        1. first start searching backwards to see if we can find something that's breakable (this is already implemented)
+        2. start searching forward to see if we can find something that's breakable -though in this case it's surely overflowing.
+
+        This patch implements #2.
+
+        * layout/inlineformatting/InlineContentBreaker.cpp:
+        (WebCore::Layout::InlineContentBreaker::processOverflowingTextContent const):
+
+2021-01-31  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC] Do not use a max value to indicate infinite available space in InlineContentBreaker::tryBreakingTextRun
         https://bugs.webkit.org/show_bug.cgi?id=221188
 

Modified: trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.cpp (272127 => 272128)


--- trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.cpp	2021-01-31 20:48:01 UTC (rev 272127)
+++ trunk/Source/WebCore/layout/inlineformatting/InlineContentBreaker.cpp	2021-02-01 00:45:56 UTC (rev 272128)
@@ -312,19 +312,50 @@
         ++index;
     }
     // We did not manage to break the run that actually overflows the line.
-    // Let's try to find the last breakable position starting from the overflowing run and wrap it at the content boundary (as it surely fits).
-    while (index--) {
-        auto& run = runs[index];
-        accumulatedRunWidth -= run.logicalWidth;
+    // Let's try to find the a previous breaking position starting from the overflowing run. It surely fits.
+    auto previousRunIndex = index;
+    auto previousAccumulatedContentWidth = accumulatedRunWidth;
+    while (previousRunIndex--) {
+        auto& run = runs[previousRunIndex];
+        previousAccumulatedContentWidth -= run.logicalWidth;
         if (isBreakableRun(run)) {
             ASSERT(run.inlineItem.isText());
-            if (auto partialRun = tryBreakingTextRun(run, lineStatus.contentLogicalRight + accumulatedRunWidth, { })) {
-                // We know this run fits, so if wrapping is allowed on the run, it should return a non-empty left-side.
+            if (auto partialRun = tryBreakingTextRun(run, lineStatus.contentLogicalRight + previousAccumulatedContentWidth, { })) {
+                // We know this run fits, so if breaking is allowed on the run, it should return a non-empty left-side
+                // since it's either at hypen position or the entire run is returned.
                 ASSERT(partialRun->length);
-                return TrailingTextContent { index, false, partialRun };
+                auto runIsFullyAccommodated = partialRun->length == downcast<InlineTextItem>(run.inlineItem).length();
+                return TrailingTextContent { previousRunIndex, false, runIsFullyAccommodated ? WTF::nullopt : partialRun };
             }
         }
     }
+    // At this point we know that there's no breakable run all the way to the overflowing run.
+    // Now we need to check if any run after the overflowing content can break.
+    // e.g. <span>this_content_overflows_but_not_breakable<span><span style="word-break: break-all">but_this_is_breakable</span>
+    auto nextRunIndex = index;
+    auto nextAccumulatedContentWidth = accumulatedRunWidth;
+    while (++nextRunIndex < runs.size()) {
+        auto& run = runs[nextRunIndex];
+        nextAccumulatedContentWidth += run.logicalWidth;
+        if (isBreakableRun(run)) {
+            ASSERT(run.inlineItem.isText());
+            // We know that this run does not fit the available space. If we can break at any position, let's just use the start of the run.
+            if (wordBreakBehavior(run.inlineItem.style()) == WordBreakRule::AtArbitraryPosition) {
+                // We must be on an inline box boundary. Let's go back to the run in front of the inline box start run.
+                // e.g. <span>unbreakable_and_overflow<span style="word-break: break-all">breakable</span>
+                // We are at "breakable", <span> is at nextRunIndex - 1 and the trailing run is at nextRunIndex - 2.
+                ASSERT(runs[nextRunIndex - 1].inlineItem.isInlineBoxStart());
+                // At worst we are back to the overflowing run, like in the example above.
+                ASSERT(nextRunIndex - 2 >= index);
+                return TrailingTextContent { nextRunIndex - 2, true, { } };
+            }
+            if (auto partialRun = tryBreakingTextRun(run, lineStatus.contentLogicalRight + nextAccumulatedContentWidth, { })) {
+                ASSERT(partialRun->length);
+                // We managed to break this text run mid content. It has to be a hyphen break.
+                return TrailingTextContent { nextRunIndex, true, partialRun };
+            }
+        }
+    }
     // Give up, there's no breakable run in here.
     return { };
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to