Bug 1733877 - Remove LineBreaker::Prev() in nsXMLContentSerializer. r=jfkthame,m_kato

`dom/base/test/unit/test_xmlserializer.js` exercises this part of the
code.

Differential Revision: https://phabricator.services.mozilla.com/D128557
This commit is contained in:
Ting-Yu Lin 2021-10-15 18:10:08 +00:00
parent 6df8cf6be5
commit bf848531df

View File

@ -1536,20 +1536,34 @@ bool nsXMLContentSerializer::AppendWrapped_NonWhitespaceSequence(
int32_t wrapPosition = 0;
if (mAllowLineBreaking) {
MOZ_ASSERT(aPos < aEnd,
"We shouldn't be here if aPos reaches the end of text!");
mozilla::intl::LineBreaker* lineBreaker =
nsContentUtils::LineBreaker();
wrapPosition =
lineBreaker->Prev(aSequenceStart, (aEnd - aSequenceStart),
(aPos - aSequenceStart) + 1);
if (wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT) {
// Search forward from aSequenceStart until we find the largest
// wrap position less than or equal to aPos.
int32_t nextWrapPosition = 0;
while (true) {
nextWrapPosition = lineBreaker->Next(
aSequenceStart, aEnd - aSequenceStart, wrapPosition);
MOZ_ASSERT(nextWrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT,
"We should've exited the loop when reaching the end of "
"text in the previous iteration!");
if (aSequenceStart + nextWrapPosition > aPos) {
break;
}
wrapPosition = nextWrapPosition;
}
if (wrapPosition != 0) {
foundWrapPosition = true;
} else {
wrapPosition =
lineBreaker->Next(aSequenceStart, (aEnd - aSequenceStart),
(aPos - aSequenceStart));
MOZ_ASSERT(wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT,
"Next() always treats end-of-text as a break");
// The wrap position found in the first iteration of the above loop
// already exceeds aPos. We however still accept it as valid a wrap
// position.
wrapPosition = nextWrapPosition;
// If the line-breaker returned end-of-text, we don't know that it
// is actually a good wrap position, so ignore it and continue to
// use the fallback code below.