Title: [293644] trunk
Revision
293644
Author
za...@apple.com
Date
2022-04-30 06:01:57 -0700 (Sat, 30 Apr 2022)

Log Message

[LFC][IFC] Do not wrap </span> to the next line when it is preceded by overflowing text
https://bugs.webkit.org/show_bug.cgi?id=239879
<rdar://problem/92497176>

Reviewed by Antti Koivisto.

Source/WebCore:

This patch makes sure that inline content run(s) ("X") followed by inline box end run(s) (</span></span>)
don't get separated when they overflow the line (e.g. width: 0px).

Test: fast/inline/overflowing-content-inside-inline-box.html

* layout/formattingContexts/inline/InlineContentBreaker.cpp:
(WebCore::Layout::InlineContentBreaker::processOverflowingContent const):

LayoutTests:

* fast/inline/overflowing-content-inside-inline-box-expected.html: Added.
* fast/inline/overflowing-content-inside-inline-box.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (293643 => 293644)


--- trunk/LayoutTests/ChangeLog	2022-04-30 07:26:02 UTC (rev 293643)
+++ trunk/LayoutTests/ChangeLog	2022-04-30 13:01:57 UTC (rev 293644)
@@ -1,3 +1,14 @@
+2022-04-30  Alan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Do not wrap </span> to the next line when it is preceded by overflowing text
+        https://bugs.webkit.org/show_bug.cgi?id=239879
+        <rdar://problem/92497176>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/inline/overflowing-content-inside-inline-box-expected.html: Added.
+        * fast/inline/overflowing-content-inside-inline-box.html: Added.
+
 2022-04-27  Jean-Yves Avenard  <j...@apple.com>
 
         [ Monterey WK2 ] media/media-source/media-source-webm-vorbis-partial.html is a constant failure

Added: trunk/LayoutTests/fast/inline/overflowing-content-inside-inline-box-expected.html (0 => 293644)


--- trunk/LayoutTests/fast/inline/overflowing-content-inside-inline-box-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/inline/overflowing-content-inside-inline-box-expected.html	2022-04-30 13:01:57 UTC (rev 293644)
@@ -0,0 +1,12 @@
+<style>
+div {
+  width: 1em;
+  word-break: break-word;
+  font-family: Ahem;
+}
+
+span {
+  border: 1px solid green;
+}
+</style>
+<div><span>X</span><span>X</span><span>X</span></div>

Added: trunk/LayoutTests/fast/inline/overflowing-content-inside-inline-box.html (0 => 293644)


--- trunk/LayoutTests/fast/inline/overflowing-content-inside-inline-box.html	                        (rev 0)
+++ trunk/LayoutTests/fast/inline/overflowing-content-inside-inline-box.html	2022-04-30 13:01:57 UTC (rev 293644)
@@ -0,0 +1,12 @@
+<style>
+div {
+  width: 0px;
+  word-break: break-word;
+  font-family: Ahem;
+}
+
+span {
+  border: 1px solid green;
+}
+</style>
+<div><span>X</span><span>X</span><span>X</span></div>

Modified: trunk/Source/WebCore/ChangeLog (293643 => 293644)


--- trunk/Source/WebCore/ChangeLog	2022-04-30 07:26:02 UTC (rev 293643)
+++ trunk/Source/WebCore/ChangeLog	2022-04-30 13:01:57 UTC (rev 293644)
@@ -1,3 +1,19 @@
+2022-04-30  Alan Bujtas  <za...@apple.com>
+
+        [LFC][IFC] Do not wrap </span> to the next line when it is preceded by overflowing text
+        https://bugs.webkit.org/show_bug.cgi?id=239879
+        <rdar://problem/92497176>
+
+        Reviewed by Antti Koivisto.
+
+        This patch makes sure that inline content run(s) ("X") followed by inline box end run(s) (</span></span>)
+        don't get separated when they overflow the line (e.g. width: 0px).
+
+        Test: fast/inline/overflowing-content-inside-inline-box.html
+
+        * layout/formattingContexts/inline/InlineContentBreaker.cpp:
+        (WebCore::Layout::InlineContentBreaker::processOverflowingContent const):
+
 2022-04-29  Rob Buis  <rb...@igalia.com>
 
         REGRESSION(r290770): element.scrollIntoViewIfNeeded() scrolls to top even when element is already in viewport

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.cpp (293643 => 293644)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.cpp	2022-04-30 07:26:02 UTC (rev 293643)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.cpp	2022-04-30 13:01:57 UTC (rev 293644)
@@ -201,7 +201,8 @@
             if (!trailingContent) {
                 // We tried to break the content but the available space can't even accommodate the first glyph.
                 // 1. Wrap the content over to the next line when we've got content on the line already.
-                // 2. Keep the first glyph on the empty line (or keep the whole run if it has only one glyph/completely empty).
+                // 2. Keep the first glyph on the empty line (or keep the whole run if it has only one glyph/completely empty)
+                // including closing inline boxes e.g. <span><span>X</span></span> where "X" is the overflowing glyph).
                 if (lineStatus.hasContent)
                     return Result { Result::Action::Wrap, IsEndOfLine::Yes };
 
@@ -212,9 +213,23 @@
                 ASSERT(firstCharacterLength > 0);
 
                 if (inlineTextItem.length() <= firstCharacterLength) {
-                    if (continuousContent.runs().size() == 1)
-                        return Result { Result::Action::Keep, IsEndOfLine::Yes };
-                    return Result { Result::Action::Break, IsEndOfLine::Yes, Result::PartialTrailingContent { leadingTextRunIndex, { } } };
+                    auto trailingRunIndex = [&]() -> std::optional<size_t> {
+                        // Keep the overflowing text content and the closing inline box runs together.
+                        // e.g. X</span><span>Y</span> where "X" overflows, the trailing run index is 1.
+                        auto& runs = continuousContent.runs();
+                        if (leadingTextRunIndex == runs.size() - 1)
+                            return { };
+                        if (!runs[leadingTextRunIndex + 1].inlineItem.isInlineBoxEnd())
+                            return leadingTextRunIndex;
+                        for (auto runIndex = leadingTextRunIndex + 1; runIndex < runs.size(); ++runIndex) {
+                            if (!runs[runIndex].inlineItem.isInlineBoxEnd())
+                                return runIndex - 1;
+                        }
+                        return { };
+                    };
+                    if (auto runToBreakAfter = trailingRunIndex())
+                        return Result { Result::Action::Break, IsEndOfLine::Yes, Result::PartialTrailingContent { *runToBreakAfter, { } } };
+                    return Result { Result::Action::Keep, IsEndOfLine::Yes };
                 }
 
                 auto firstCharacterWidth = TextUtil::width(inlineTextItem, leadingTextRun.style.fontCascade(), inlineTextItem.start(), inlineTextItem.start() + firstCharacterLength, lineStatus.contentLogicalRight);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to