Skip to content

Commit

Permalink
Text in flex items not breaking under specific conditions
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265252
<rdar://problem/118796634>

Reviewed by Antti Koivisto.

"zero width space" character (ZWSP) is a non-whitespace space character and is a word boundary.

This patch ensures legacy preferred with computation treats "zero width space" as a breakable position.

* LayoutTests/fast/text/flexing-content-fails-with-zero-width-space-expected.html: Added.
* LayoutTests/fast/text/flexing-content-fails-with-zero-width-space.html: Added.
* Source/WebCore/rendering/RenderText.cpp:
(WebCore::isSpaceAccordingToStyle):
(WebCore::RenderText::computePreferredLogicalWidths):

Canonical link: https://commits.webkit.org/271122@main
  • Loading branch information
alanbaradlay committed Nov 26, 2023
1 parent 769ad4e commit 073d844
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<style>
body {
font-family: Ahem;
font-size: 20px;
}

div {
color: green;
}
</style>
<div>X<br>X<br>X</div>
<br>PASS if no red
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<style>
body {
font-family: Ahem;
font-size: 20px;
}

.test {
width: min-content;
color: red;
}

.inline-block {
display: inline-block;
}

.ref {
position: absolute;
top: 8px;
color: green;
}
</style>
<div class=test><div class=inline-block>X</div>X&#8203;<span>X</span></div></div>
<div class=ref>X<br>X<br>X</div>
<br>PASS if no red
6 changes: 3 additions & 3 deletions Source/WebCore/rendering/RenderBlockFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4695,7 +4695,7 @@ void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogical

// This text object will not be rendered, but it may still provide a breaking opportunity.
if (!widths.hasBreak && !childMax) {
if (autoWrap && (widths.beginWS || widths.endWS)) {
if (autoWrap && (widths.beginWS || widths.endWS || widths.endZeroSpace)) {
minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin);
inlineMin = 0;
}
Expand Down Expand Up @@ -4761,8 +4761,8 @@ void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogical

inlineMin = childMin;

if (widths.endWS) {
// We end in whitespace, which means we can end our current line.
if (widths.endWS || widths.endZeroSpace) {
// We end in breakable space, which means we can end our current line.
minLogicalWidth = preferredWidth(minLogicalWidth, inlineMin);
inlineMin = 0;
shouldBreakLineAfterText = false;
Expand Down
4 changes: 3 additions & 1 deletion Source/WebCore/rendering/RenderText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,8 @@ RenderText::Widths RenderText::trimmedPreferredWidths(float leadWidth, bool& str
if (!length || (stripFrontSpaces && text().containsOnly<isASCIIWhitespace>()))
return widths;

widths.endZeroSpace = text()[length - 1] == zeroWidthSpace;

widths.min = m_minWidth.value_or(-1);
widths.max = m_maxWidth.value_or(-1);

Expand Down Expand Up @@ -1260,7 +1262,7 @@ void RenderText::computePreferredLogicalWidths(float leadWidth, WeakHashSet<cons
bool hasBreak = breakAll || isBreakable(lineBreakIteratorFactory, i, nextBreakable, breakNBSP, canUseLineBreakShortcut, keepAllWords, breakAnywhere);
bool betweenWords = true;
unsigned j = i;
while (c != '\n' && !isSpaceAccordingToStyle(c, style) && c != '\t' && (c != softHyphen || style.hyphens() == Hyphens::None)) {
while (c != '\n' && !isSpaceAccordingToStyle(c, style) && c != '\t' && c != zeroWidthSpace && (c != softHyphen || style.hyphens() == Hyphens::None)) {
UChar previousCharacter = c;
j++;
if (j == length)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/rendering/RenderText.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class RenderText : public RenderObject {
float endMax { 0 };
bool beginWS { false };
bool endWS { false };
bool endZeroSpace { false };
bool hasBreakableChar { false };
bool hasBreak { false };
bool endsWithBreak { false };
Expand Down

0 comments on commit 073d844

Please sign in to comment.