From 060d72b1fb7ac23e8600ac3ef04f48e1927eac37 Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Thu, 7 Oct 2021 17:10:14 +0000 Subject: [PATCH] Bug 1733876 Part 3 - Consolidate logic dealing with and without aLineBreaker in FindWrapIndexForContent(). r=m_kato This patch only moves logic, and shouldn't change the behavior. Differential Revision: https://phabricator.services.mozilla.com/D127383 --- dom/serializers/nsPlainTextSerializer.cpp | 58 ++++++++++------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/dom/serializers/nsPlainTextSerializer.cpp b/dom/serializers/nsPlainTextSerializer.cpp index 8d57c36707a7..5ec6bf27c71e 100644 --- a/dom/serializers/nsPlainTextSerializer.cpp +++ b/dom/serializers/nsPlainTextSerializer.cpp @@ -144,47 +144,37 @@ int32_t nsPlainTextSerializer::CurrentLine::FindWrapIndexForContent( --goodSpace; // adjust the position since line breaker returns a // position next to space } - } else { - // In this case we don't want strings, especially CJK-ones, to be split. - // See - // https://bugzilla.mozilla.org/show_bug.cgi?id=333064 for more - // information. - - if (aWrapColumn < prefixwidth) { - goodSpace = NS_LINEBREAKER_NEED_MORE_TEXT; - } else { - goodSpace = std::min(aWrapColumn - prefixwidth, mContent.Length() - 1); - while (goodSpace >= 0 && - !nsCRT::IsAsciiSpace(mContent.CharAt(goodSpace))) { - goodSpace--; - } - } - } - - if (goodSpace == NS_LINEBREAKER_NEED_MORE_TEXT) { - // If we didn't find a good place to break, accept long line and - // try to find another place to break - goodSpace = - (prefixwidth > aWrapColumn + 1) ? 1 : aWrapColumn - prefixwidth + 1; - if (aLineBreaker) { + if (goodSpace == NS_LINEBREAKER_NEED_MORE_TEXT) { + // If we didn't find a good place to break, accept long line and + // try to find another place to break + goodSpace = + (prefixwidth > aWrapColumn + 1) ? 1 : aWrapColumn - prefixwidth + 1; if ((uint32_t)goodSpace < mContent.Length()) goodSpace = aLineBreaker->DeprecatedNext(mContent.get(), mContent.Length(), goodSpace); if (goodSpace == NS_LINEBREAKER_NEED_MORE_TEXT) goodSpace = mContent.Length(); - } else { - // In this case we don't want strings, especially CJK-ones, to be - // split. See - // https://bugzilla.mozilla.org/show_bug.cgi?id=333064 for more - // information. - goodSpace = (prefixwidth > aWrapColumn) ? 1 : aWrapColumn - prefixwidth; - const int32_t contentLength = mContent.Length(); - while (goodSpace < contentLength && - !nsCRT::IsAsciiSpace(mContent.CharAt(goodSpace))) { - goodSpace++; - } + } + + return goodSpace; + } + + // In this case we don't want strings, especially CJK-ones, to be split. See + // bug 333064 for more information. + if (aWrapColumn < prefixwidth) { + goodSpace = (prefixwidth > aWrapColumn) ? 1 : aWrapColumn - prefixwidth; + const int32_t contentLength = mContent.Length(); + while (goodSpace < contentLength && + !nsCRT::IsAsciiSpace(mContent.CharAt(goodSpace))) { + goodSpace++; + } + } else { + goodSpace = std::min(aWrapColumn - prefixwidth, mContent.Length() - 1); + while (goodSpace >= 0 && !nsCRT::IsAsciiSpace(mContent.CharAt(goodSpace))) { + goodSpace--; } } + return goodSpace; }