From 0e3cf9687edbd0c0ed03b7bbee976fe66afbaaad Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Wed, 4 Nov 2020 13:31:30 +0000 Subject: [PATCH] Bug 1665657 - Whitespace that will hang should not contribute to the min inline-size of a textframe. r=emilio This affects a few of the examples in the text/white-space-2 reftest, but the changes look sensible; more significantly from an interop point of view, there are specific web-platform reftests that are currently failing, but will pass after the patch. Differential Revision: https://phabricator.services.mozilla.com/D95811 --- layout/generic/nsTextFrame.cpp | 22 ++++++++++--------- layout/reftests/text/white-space-2-ref.html | 21 ++++++++++-------- layout/reftests/text/white-space-2.html | 2 +- layout/style/nsStyleStruct.h | 9 ++++++++ .../white-space-intrinsic-size-003.html.ini | 2 -- .../white-space-intrinsic-size-013.html.ini | 2 -- .../white-space-intrinsic-size-014.html.ini | 2 -- ...pace-pre-wrap-trailing-spaces-003.html.ini | 2 -- 8 files changed, 34 insertions(+), 28 deletions(-) delete mode 100644 testing/web-platform/meta/css/css-text/white-space/white-space-intrinsic-size-003.html.ini delete mode 100644 testing/web-platform/meta/css/css-text/white-space/white-space-intrinsic-size-013.html.ini delete mode 100644 testing/web-platform/meta/css/css-text/white-space/white-space-intrinsic-size-014.html.ini delete mode 100644 testing/web-platform/meta/css/css-text/white-space/white-space-pre-wrap-trailing-spaces-003.html.ini diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 9cfc15869d79..a22b9efc8918 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -801,12 +801,13 @@ static bool IsTrimmableSpace(char aCh) { } static bool IsTrimmableSpace(const nsTextFragment* aFrag, uint32_t aPos, - const nsStyleText* aStyleText) { + const nsStyleText* aStyleText, + bool aAllowHangingWS = false) { NS_ASSERTION(aPos < aFrag->GetLength(), "No text for IsSpace!"); switch (aFrag->CharAt(aPos)) { case ' ': - return !aStyleText->WhiteSpaceIsSignificant() && + return (!aStyleText->WhiteSpaceIsSignificant() || aAllowHangingWS) && !IsSpaceCombiningSequenceTail(aFrag, aPos + 1); case '\n': return !aStyleText->NewlineIsSignificantStyle() && @@ -814,7 +815,7 @@ static bool IsTrimmableSpace(const nsTextFragment* aFrag, uint32_t aPos, case '\t': case '\r': case '\f': - return !aStyleText->WhiteSpaceIsSignificant(); + return !aStyleText->WhiteSpaceIsSignificant() || aAllowHangingWS; default: return false; } @@ -3049,11 +3050,13 @@ gfxSkipCharsIterator nsTextFrame::EnsureTextRun( static uint32_t GetEndOfTrimmedText(const nsTextFragment* aFrag, const nsStyleText* aStyleText, uint32_t aStart, uint32_t aEnd, - gfxSkipCharsIterator* aIterator) { + gfxSkipCharsIterator* aIterator, + bool aAllowHangingWS = false) { aIterator->SetSkippedOffset(aEnd); while (aIterator->GetSkippedOffset() > aStart) { aIterator->AdvanceSkipped(-1); - if (!IsTrimmableSpace(aFrag, aIterator->GetOriginalOffset(), aStyleText)) + if (!IsTrimmableSpace(aFrag, aIterator->GetOriginalOffset(), aStyleText, + aAllowHangingWS)) return aIterator->GetSkippedOffset() + 1; } return aStart; @@ -8348,6 +8351,7 @@ void nsTextFrame::AddInlineMinISizeForFlow(gfxContext* aRenderingContext, bool collapseWhitespace = !textStyle->WhiteSpaceIsSignificant(); bool preformatNewlines = textStyle->NewlineIsSignificant(this); bool preformatTabs = textStyle->WhiteSpaceIsSignificant(); + bool whitespaceCanHang = textStyle->WhiteSpaceCanHangOrVisuallyCollapse(); gfxFloat tabWidth = -1; uint32_t start = FindStartAfterSkippingWhitespace(&provider, aData, textStyle, &iter, flowEndInTextRun); @@ -8408,9 +8412,9 @@ void nsTextFrame::AddInlineMinISizeForFlow(gfxContext* aRenderingContext, aData->mCurrentLine = NSCoordSaturatingAdd(aData->mCurrentLine, width); aData->mAtStartOfLine = false; - if (collapseWhitespace) { + if (collapseWhitespace || whitespaceCanHang) { uint32_t trimStart = - GetEndOfTrimmedText(frag, textStyle, wordStart, i, &iter); + GetEndOfTrimmedText(frag, textStyle, wordStart, i, &iter, whitespaceCanHang); if (trimStart == start) { // This is *all* trimmable whitespace, so whatever trailingWhitespace // we saw previously is still trailing... @@ -9275,9 +9279,7 @@ void nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth, bool isBreakSpaces = textStyle->mWhiteSpace == StyleWhiteSpace::BreakSpaces; // allow whitespace to overflow the container - bool whitespaceCanHang = !isBreakSpaces && - textStyle->WhiteSpaceCanWrapStyle() && - textStyle->WhiteSpaceIsSignificant(); + bool whitespaceCanHang = textStyle->WhiteSpaceCanHangOrVisuallyCollapse(); gfxBreakPriority breakPriority = aLineLayout.LastOptionalBreakPriority(); gfxTextRun::SuppressBreak suppressBreak = gfxTextRun::eNoSuppressBreak; bool shouldSuppressLineBreak = ShouldSuppressLineBreak(); diff --git a/layout/reftests/text/white-space-2-ref.html b/layout/reftests/text/white-space-2-ref.html index 581daa9d4229..f452f4391413 100644 --- a/layout/reftests/text/white-space-2-ref.html +++ b/layout/reftests/text/white-space-2-ref.html @@ -3,11 +3,14 @@ @@ -17,7 +20,7 @@ b { font-weight:normal; background-color:yellow; white-space:pre; } Kitty

Hello Kitty

Hello Kitty -

Hello +

Hello Kitty @@ -28,7 +31,7 @@ Kitty Kitty

Hello Kitty -

Hello +

Hello Kitty @@ -37,7 +40,7 @@ Kitty Kitty

Hello Kitty

Hello Kitty -

Hello +

Hello Kitty @@ -46,18 +49,18 @@ Kitty Kitty

Hello Kitty

Hello Kitty -

Hello +

Hello Kitty

-

Hello +

Hello Kitty -

Hello +

Hello Kitty -

Hello +

Hello Kitty -

Hello +

Hello Kitty

diff --git a/layout/reftests/text/white-space-2.html b/layout/reftests/text/white-space-2.html index db745e0681b8..84377c7fda6d 100644 --- a/layout/reftests/text/white-space-2.html +++ b/layout/reftests/text/white-space-2.html @@ -3,7 +3,7 @@