Bug 1584170: part 1) Factor out duplicated code to `IsInOlOrUl`. r=hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D48320

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mirko Brodesser 2019-10-21 09:06:12 +00:00
Родитель 4170fd9b5c
Коммит 1f69cf48a9
2 изменённых файлов: 10 добавлений и 4 удалений

Просмотреть файл

@ -743,12 +743,12 @@ nsresult nsPlainTextSerializer::DoOpenContainer(const nsAtom* aTag) {
} }
} else if (aTag == nsGkAtoms::ul) { } else if (aTag == nsGkAtoms::ul) {
// Indent here to support nested lists, which aren't included in li :-( // Indent here to support nested lists, which aren't included in li :-(
EnsureVerticalSpace(mULCount + mOLStackIndex == 0 ? 1 : 0); EnsureVerticalSpace(IsInOlOrUl() ? 0 : 1);
// Must end the current line before we change indention // Must end the current line before we change indention
mCurrentLine.mIndentation.mLength += kIndentSizeList; mCurrentLine.mIndentation.mLength += kIndentSizeList;
mULCount++; mULCount++;
} else if (aTag == nsGkAtoms::ol) { } else if (aTag == nsGkAtoms::ol) {
EnsureVerticalSpace(mULCount + mOLStackIndex == 0 ? 1 : 0); EnsureVerticalSpace(IsInOlOrUl() ? 0 : 1);
if (mSettings.HasFlag(nsIDocumentEncoder::OutputFormatted)) { if (mSettings.HasFlag(nsIDocumentEncoder::OutputFormatted)) {
// Must end the current line before we change indention // Must end the current line before we change indention
if (mOLStackIndex < OLStackSize) { if (mOLStackIndex < OLStackSize) {
@ -974,7 +974,8 @@ nsresult nsPlainTextSerializer::DoCloseContainer(const nsAtom* aTag) {
} else if (aTag == nsGkAtoms::ul) { } else if (aTag == nsGkAtoms::ul) {
mOutputManager->Flush(mCurrentLine); mOutputManager->Flush(mCurrentLine);
mCurrentLine.mIndentation.mLength -= kIndentSizeList; mCurrentLine.mIndentation.mLength -= kIndentSizeList;
if (--mULCount + mOLStackIndex == 0) { --mULCount;
if (!IsInOlOrUl()) {
mFloatingLines = 1; mFloatingLines = 1;
mLineBreakDue = true; mLineBreakDue = true;
} }
@ -984,7 +985,7 @@ nsresult nsPlainTextSerializer::DoCloseContainer(const nsAtom* aTag) {
mCurrentLine.mIndentation.mLength -= kIndentSizeList; mCurrentLine.mIndentation.mLength -= kIndentSizeList;
NS_ASSERTION(mOLStackIndex, "Wrong OLStack level!"); NS_ASSERTION(mOLStackIndex, "Wrong OLStack level!");
mOLStackIndex--; mOLStackIndex--;
if (mULCount + mOLStackIndex == 0) { if (!IsInOlOrUl()) {
mFloatingLines = 1; mFloatingLines = 1;
mLineBreakDue = true; mLineBreakDue = true;
} }
@ -1765,6 +1766,10 @@ bool nsPlainTextSerializer::IsInOL() const {
return false; return false;
} }
bool nsPlainTextSerializer::IsInOlOrUl() const {
return (mULCount > 0) || (mOLStackIndex > 0);
}
/* /*
@return 0 = no header, 1 = h1, ..., 6 = h6 @return 0 = no header, 1 = h1, ..., 6 = h6
*/ */

Просмотреть файл

@ -106,6 +106,7 @@ class nsPlainTextSerializer final : public nsIContentSerializer {
// element. // element.
bool IsElementPreformatted() const; bool IsElementPreformatted() const;
bool IsInOL() const; bool IsInOL() const;
bool IsInOlOrUl() const;
bool IsCurrentNodeConverted() const; bool IsCurrentNodeConverted() const;
bool MustSuppressLeaf() const; bool MustSuppressLeaf() const;