зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1574912: part 2) Rename `nsPlainTextSerializer::IsInPre`, `IsHTMLBlock` and `IsElementBlock`. r=hsivonen
In order to clarify their purpose. Differential Revision: https://phabricator.services.mozilla.com/D42520 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
c7bcfd69de
Коммит
231ce6e93d
|
@ -1506,7 +1506,7 @@ bool nsContentUtils::IsHTMLWhitespaceOrNBSP(char16_t aChar) {
|
|||
}
|
||||
|
||||
/* static */
|
||||
bool nsContentUtils::IsHTMLBlock(nsIContent* aContent) {
|
||||
bool nsContentUtils::IsHTMLBlockLevelElement(nsIContent* aContent) {
|
||||
return aContent->IsAnyOfHTMLElements(
|
||||
nsGkAtoms::address, nsGkAtoms::article, nsGkAtoms::aside,
|
||||
nsGkAtoms::blockquote, nsGkAtoms::center, nsGkAtoms::dir, nsGkAtoms::div,
|
||||
|
|
|
@ -571,9 +571,9 @@ class nsContentUtils {
|
|||
static bool IsHTMLWhitespaceOrNBSP(char16_t aChar);
|
||||
|
||||
/**
|
||||
* Is the HTML local name a block element?
|
||||
* https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
||||
*/
|
||||
static bool IsHTMLBlock(nsIContent* aContent);
|
||||
static bool IsHTMLBlockLevelElement(nsIContent* aContent);
|
||||
|
||||
enum ParseHTMLIntegerResultFlags {
|
||||
eParseHTMLInteger_NoFlags = 0,
|
||||
|
|
|
@ -668,7 +668,7 @@ nsresult nsPlainTextSerializer::DoOpenContainer(nsAtom* aTag) {
|
|||
|
||||
// Else make sure we'll separate block level tags,
|
||||
// even if we're about to leave, before doing any other formatting.
|
||||
else if (IsElementBlock(mElement)) {
|
||||
else if (IsCssBlockLevelElement(mElement)) {
|
||||
EnsureVerticalSpace(0);
|
||||
}
|
||||
|
||||
|
@ -758,7 +758,8 @@ nsresult nsPlainTextSerializer::DoCloseContainer(nsAtom* aTag) {
|
|||
}
|
||||
|
||||
if (mFlags & nsIDocumentEncoder::OutputForPlainTextClipboardCopy) {
|
||||
if (DoOutput() && IsInPre() && IsElementBlock(mElement)) {
|
||||
if (DoOutput() && IsElementPreformatted() &&
|
||||
IsCssBlockLevelElement(mElement)) {
|
||||
// If we're closing a preformatted block element, output a line break
|
||||
// when we find a new container.
|
||||
mPreformattedBlockBoundary = true;
|
||||
|
@ -868,7 +869,7 @@ nsresult nsPlainTextSerializer::DoCloseContainer(nsAtom* aTag) {
|
|||
mLineBreakDue = true;
|
||||
} else if (aTag == nsGkAtoms::q) {
|
||||
Write(NS_LITERAL_STRING("\""));
|
||||
} else if (IsElementBlock(mElement)) {
|
||||
} else if (IsCssBlockLevelElement(mElement)) {
|
||||
// All other blocks get 1 vertical space after them
|
||||
// in formatted mode, otherwise 0.
|
||||
// This is hard. Sometimes 0 is a better number, but
|
||||
|
@ -975,7 +976,7 @@ void nsPlainTextSerializer::DoAddText(bool aIsLineBreak,
|
|||
// prettyprinting to mimic the html format, and in neither case
|
||||
// does the formatting of the html source help us.
|
||||
if ((mFlags & nsIDocumentEncoder::OutputPreformatted) ||
|
||||
(mPreFormattedMail && !mWrapColumn) || IsInPre()) {
|
||||
(mPreFormattedMail && !mWrapColumn) || IsElementPreformatted()) {
|
||||
EnsureVerticalSpace(mEmptyLines + 1);
|
||||
} else if (!mInWhitespace) {
|
||||
Write(kSpace);
|
||||
|
@ -1461,13 +1462,14 @@ void nsPlainTextSerializer::Write(const nsAString& aStr) {
|
|||
// that does normal formatted text. The one for preformatted text calls
|
||||
// Output directly while the other code path goes through AddToLine.
|
||||
if ((mPreFormattedMail && !mWrapColumn) ||
|
||||
(IsInPre() && !mPreFormattedMail) ||
|
||||
(IsElementPreformatted() && !mPreFormattedMail && !MayWrap()) ||
|
||||
(mSpanLevel > 0 && mEmptyLines >= 0 && IsQuotedLine(str))) {
|
||||
// No intelligent wrapping.
|
||||
|
||||
// This mustn't be mixed with intelligent wrapping without clearing
|
||||
// the mCurrentLine buffer before!!!
|
||||
NS_ASSERTION(mCurrentLine.IsEmpty() || (IsInPre() && !mPreFormattedMail),
|
||||
NS_ASSERTION(mCurrentLine.IsEmpty() ||
|
||||
(IsElementPreformatted() && !mPreFormattedMail),
|
||||
"Mixed wrapping data and nonwrapping data on the same line");
|
||||
if (!mCurrentLine.IsEmpty()) {
|
||||
FlushLine();
|
||||
|
@ -1674,7 +1676,7 @@ nsAtom* nsPlainTextSerializer::GetIdForContent(nsIContent* aContent) {
|
|||
return localName->IsStatic() ? localName : nullptr;
|
||||
}
|
||||
|
||||
bool nsPlainTextSerializer::IsInPre() {
|
||||
bool nsPlainTextSerializer::IsElementPreformatted() const {
|
||||
return !mPreformatStack.empty() && mPreformatStack.top();
|
||||
}
|
||||
|
||||
|
@ -1689,7 +1691,7 @@ bool nsPlainTextSerializer::IsElementPreformatted(Element* aElement) {
|
|||
return GetIdForContent(aElement) == nsGkAtoms::pre;
|
||||
}
|
||||
|
||||
bool nsPlainTextSerializer::IsElementBlock(Element* aElement) {
|
||||
bool nsPlainTextSerializer::IsCssBlockLevelElement(Element* aElement) {
|
||||
RefPtr<ComputedStyle> computedStyle =
|
||||
nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
|
||||
if (computedStyle) {
|
||||
|
@ -1697,7 +1699,7 @@ bool nsPlainTextSerializer::IsElementBlock(Element* aElement) {
|
|||
return displayStyle->IsBlockOutsideStyle();
|
||||
}
|
||||
// Fall back to looking at the tag, in case there is no style information.
|
||||
return nsContentUtils::IsHTMLBlock(aElement);
|
||||
return nsContentUtils::IsHTMLBlockLevelElement(aElement);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -90,7 +90,11 @@ class nsPlainTextSerializer final : public nsIContentSerializer {
|
|||
void OutputQuotesAndIndent(bool stripTrailingSpaces = false);
|
||||
void Output(nsString& aString);
|
||||
void Write(const nsAString& aString);
|
||||
bool IsInPre();
|
||||
|
||||
// @return true, iff the elements' whitespace and newline characters have to
|
||||
// be preserved according to its style or because it's a `<pre>`
|
||||
// element.
|
||||
bool IsElementPreformatted() const;
|
||||
bool IsInOL();
|
||||
bool IsCurrentNodeConverted();
|
||||
bool MustSuppressLeaf();
|
||||
|
@ -114,7 +118,7 @@ class nsPlainTextSerializer final : public nsIContentSerializer {
|
|||
return !(mFlags & nsIDocumentEncoder::OutputDisallowLineBreaking);
|
||||
}
|
||||
|
||||
inline bool DoOutput() { return mHeadLevel == 0; }
|
||||
inline bool DoOutput() const { return mHeadLevel == 0; }
|
||||
|
||||
inline bool IsQuotedLine(const nsAString& aLine) {
|
||||
return !aLine.IsEmpty() && aLine.First() == char16_t('>');
|
||||
|
@ -128,8 +132,13 @@ class nsPlainTextSerializer final : public nsIContentSerializer {
|
|||
|
||||
bool IsIgnorableRubyAnnotation(nsAtom* aTag);
|
||||
|
||||
bool IsElementPreformatted(mozilla::dom::Element* aElement);
|
||||
bool IsElementBlock(mozilla::dom::Element* aElement);
|
||||
// @return true, iff the elements' whitespace and newline characters have to
|
||||
// be preserved according to its style or because it's a `<pre>`
|
||||
// element.
|
||||
static bool IsElementPreformatted(mozilla::dom::Element* aElement);
|
||||
|
||||
// https://drafts.csswg.org/css-display/#block-level
|
||||
static bool IsCssBlockLevelElement(mozilla::dom::Element* aElement);
|
||||
|
||||
private:
|
||||
nsString mCurrentLine;
|
||||
|
|
Загрузка…
Ссылка в новой задаче