Commit 40d46174 authored by longsonr's avatar longsonr
Browse files

Bug 1570799 - pass the original element into...

Bug 1570799 - pass the original element into nsXMLContentSerializer::CheckElementEnd so that we can determine whether it has children properly r=hsivonen

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

--HG--
extra : moz-landing-system : lando
parent 6626259e
......@@ -239,7 +239,8 @@ class nsDocumentEncoder : public nsIDocumentEncoder {
nsresult SerializeToStringRecursive(nsINode* aNode, nsAString& aStr,
bool aDontSerializeRoot,
uint32_t aMaxLength = 0);
nsresult SerializeNodeEnd(nsINode& aNode, nsAString& aStr);
nsresult SerializeNodeEnd(nsINode& aOriginalNode, nsAString& aStr,
nsINode* aFixupNode = nullptr);
// This serializes the content of aNode.
nsresult SerializeToStringIterative(nsINode* aNode, nsAString& aStr);
nsresult SerializeRangeToString(nsRange* aRange, nsAString& aOutputString);
......@@ -660,9 +661,8 @@ nsresult nsDocumentEncoder::SerializeNodeStart(nsINode& aOriginalNode,
nsLayoutUtils::IsInvisibleBreak(node)) {
return rv;
}
Element* originalElement = aOriginalNode.AsElement();
rv = mSerializer->AppendElementStart(node->AsElement(), originalElement,
aStr);
rv = mSerializer->AppendElementStart(node->AsElement(),
aOriginalNode.AsElement(), aStr);
return rv;
}
......@@ -697,26 +697,33 @@ nsresult nsDocumentEncoder::SerializeNodeStart(nsINode& aOriginalNode,
return rv;
}
nsresult nsDocumentEncoder::SerializeNodeEnd(nsINode& aNode, nsAString& aStr) {
nsresult nsDocumentEncoder::SerializeNodeEnd(nsINode& aOriginalNode,
nsAString& aStr,
nsINode* aFixupNode) {
if (mNeedsPreformatScanning) {
if (aNode.IsElement()) {
mSerializer->ForgetElementForPreformat(aNode.AsElement());
} else if (aNode.IsText()) {
const nsCOMPtr<nsINode> parent = aNode.GetParent();
if (aOriginalNode.IsElement()) {
mSerializer->ForgetElementForPreformat(aOriginalNode.AsElement());
} else if (aOriginalNode.IsText()) {
const nsCOMPtr<nsINode> parent = aOriginalNode.GetParent();
if (parent && parent->IsElement()) {
mSerializer->ForgetElementForPreformat(parent->AsElement());
}
}
}
if (IsInvisibleNodeAndShouldBeSkipped(aNode)) {
if (IsInvisibleNodeAndShouldBeSkipped(aOriginalNode)) {
return NS_OK;
}
nsresult rv = NS_OK;
if (aNode.IsElement()) {
rv = mSerializer->AppendElementEnd(aNode.AsElement(), aStr);
FixupNodeDeterminer fixupNodeDeterminer{mNodeFixup, aFixupNode,
aOriginalNode};
nsINode* node = &fixupNodeDeterminer.GetFixupNodeFallBackToOriginalNode();
if (node->IsElement()) {
rv = mSerializer->AppendElementEnd(node->AsElement(),
aOriginalNode.AsElement(), aStr);
}
return rv;
......@@ -773,7 +780,7 @@ nsresult nsDocumentEncoder::SerializeToStringRecursive(nsINode* aNode,
}
if (!aDontSerializeRoot) {
rv = SerializeNodeEnd(*maybeFixedNode, aStr);
rv = SerializeNodeEnd(*aNode, aStr, maybeFixedNode);
NS_ENSURE_SUCCESS(rv, rv);
}
......
......@@ -256,7 +256,9 @@ nsHTMLContentSerializer::AppendElementStart(Element* aElement,
}
NS_IMETHODIMP
nsHTMLContentSerializer::AppendElementEnd(Element* aElement, nsAString& aStr) {
nsHTMLContentSerializer::AppendElementEnd(Element* aElement,
Element* aOriginalElement,
nsAString& aStr) {
NS_ENSURE_ARG(aElement);
nsAtom* name = aElement->NodeInfo()->NameAtom();
......
......@@ -29,6 +29,7 @@ class nsHTMLContentSerializer final : public nsXHTMLContentSerializer {
nsAString& aStr) override;
NS_IMETHOD AppendElementEnd(mozilla::dom::Element* aElement,
mozilla::dom::Element* aOriginalElement,
nsAString& aStr) override;
NS_IMETHOD AppendDocumentStart(mozilla::dom::Document* aDocument,
......
......@@ -60,6 +60,7 @@ class nsIContentSerializer : public nsISupports {
nsAString& aStr) = 0;
NS_IMETHOD AppendElementEnd(mozilla::dom::Element* aElement,
mozilla::dom::Element* aOriginalElement,
nsAString& aStr) = 0;
NS_IMETHOD Flush(nsAString& aStr) = 0;
......
......@@ -419,7 +419,9 @@ nsPlainTextSerializer::AppendElementStart(Element* aElement,
}
NS_IMETHODIMP
nsPlainTextSerializer::AppendElementEnd(Element* aElement, nsAString& aStr) {
nsPlainTextSerializer::AppendElementEnd(Element* aElement,
Element* aOriginalElement,
nsAString& aStr) {
NS_ENSURE_ARG(aElement);
mElement = aElement;
......
......@@ -69,6 +69,7 @@ class nsPlainTextSerializer final : public nsIContentSerializer {
mozilla::dom::Element* aOriginalElement,
nsAString& aStr) override;
NS_IMETHOD AppendElementEnd(mozilla::dom::Element* aElement,
mozilla::dom::Element* aOriginalElement,
nsAString& aStr) override;
NS_IMETHOD Flush(nsAString& aStr) override;
......
......@@ -410,6 +410,7 @@ bool nsXHTMLContentSerializer::CheckElementStart(Element* aElement,
}
bool nsXHTMLContentSerializer::CheckElementEnd(Element* aElement,
Element* aOriginalElement,
bool& aForceFormat,
nsAString& aStr) {
NS_ASSERTION(!mIsHTMLSerializer,
......@@ -428,7 +429,8 @@ bool nsXHTMLContentSerializer::CheckElementEnd(Element* aElement,
}
bool dummyFormat;
return nsXMLContentSerializer::CheckElementEnd(aElement, dummyFormat, aStr);
return nsXMLContentSerializer::CheckElementEnd(aElement, aOriginalElement,
dummyFormat, aStr);
}
bool nsXHTMLContentSerializer::AppendAndTranslateEntities(
......
......@@ -52,6 +52,7 @@ class nsXHTMLContentSerializer : public nsXMLContentSerializer {
nsAString& aStr) override;
virtual bool CheckElementEnd(mozilla::dom::Element* aContent,
mozilla::dom::Element* aOriginalElement,
bool& aForceFormat, nsAString& aStr) override;
virtual void AfterElementEnd(nsIContent* aContent, nsAString& aStr) override;
......
......@@ -955,13 +955,16 @@ bool nsXMLContentSerializer::AppendEndOfElementStart(Element* aElement,
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendElementEnd(Element* aElement, nsAString& aStr) {
nsXMLContentSerializer::AppendElementEnd(Element* aElement,
Element* aOriginalElement,
nsAString& aStr) {
NS_ENSURE_ARG(aElement);
nsIContent* content = aElement;
bool forceFormat = false, outputElementEnd;
outputElementEnd = CheckElementEnd(aElement, forceFormat, aStr);
outputElementEnd =
CheckElementEnd(aElement, aOriginalElement, forceFormat, aStr);
nsAtom* name = content->NodeInfo()->NameAtom();
......@@ -1083,15 +1086,12 @@ bool nsXMLContentSerializer::CheckElementStart(Element*, bool& aForceFormat,
}
bool nsXMLContentSerializer::CheckElementEnd(Element* aElement,
Element* aOriginalElement,
bool& aForceFormat,
nsAString& aStr) {
// We don't output a separate end tag for empty element
aForceFormat = false;
// XXXbz this is a bit messed up, but by now we don't have our fixed-up
// version of aElement anymore. Let's hope fixup never changes the localName
// or namespace...
return ElementNeedsSeparateEndTag(aElement, aElement);
return ElementNeedsSeparateEndTag(aElement, aOriginalElement);
}
bool nsXMLContentSerializer::AppendToString(const char16_t aChar,
......
......@@ -63,6 +63,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
nsAString& aStr) override;
NS_IMETHOD AppendElementEnd(mozilla::dom::Element* aElement,
mozilla::dom::Element* aOriginalElement,
nsAString& aStr) override;
NS_IMETHOD Flush(nsAString& aStr) override { return NS_OK; }
......@@ -305,6 +306,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
* @return boolean true if the element can be output
*/
virtual bool CheckElementEnd(mozilla::dom::Element* aElement,
mozilla::dom::Element* aOriginalElement,
bool& aForceFormat, nsAString& aStr);
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment