From 54e8e23135454d877ccb278402a6cf302ebd9c24 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 13 May 2015 17:58:25 +0200 Subject: [PATCH] Bug 1145395 - Pass nsIContent& to nsHTMLEditor::StripFormattingNodes; r=ehsan --- editor/libeditor/nsHTMLDataTransfer.cpp | 39 ++++++++++--------------- editor/libeditor/nsHTMLEditor.h | 2 +- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/editor/libeditor/nsHTMLDataTransfer.cpp b/editor/libeditor/nsHTMLDataTransfer.cpp index f3a08d705105..ab86b8e3c959 100644 --- a/editor/libeditor/nsHTMLDataTransfer.cpp +++ b/editor/libeditor/nsHTMLDataTransfer.cpp @@ -769,36 +769,27 @@ nsHTMLEditor::IsInLink(nsIDOMNode *aNode, nsCOMPtr *outLink) nsresult -nsHTMLEditor::StripFormattingNodes(nsIDOMNode *aNode, bool aListOnly) +nsHTMLEditor::StripFormattingNodes(nsIContent& aNode, bool aListOnly) { - NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); - - nsCOMPtr content = do_QueryInterface(aNode); - if (content->TextIsOnlyWhitespace()) - { - nsCOMPtr parent, ignored; - aNode->GetParentNode(getter_AddRefs(parent)); - if (parent) - { + if (aNode.TextIsOnlyWhitespace()) { + nsCOMPtr parent = aNode.GetParentNode(); + if (parent) { if (!aListOnly || nsHTMLEditUtils::IsList(parent)) { - return parent->RemoveChild(aNode, getter_AddRefs(ignored)); + ErrorResult rv; + parent->RemoveChild(aNode, rv); + return rv.StealNSResult(); } return NS_OK; } } - if (!nsHTMLEditUtils::IsPre(aNode)) - { - nsCOMPtr child; - aNode->GetLastChild(getter_AddRefs(child)); - - while (child) - { - nsCOMPtr tmp; - child->GetPreviousSibling(getter_AddRefs(tmp)); - nsresult rv = StripFormattingNodes(child, aListOnly); + if (!aNode.IsHTMLElement(nsGkAtoms::pre)) { + nsCOMPtr child = aNode.GetLastChild(); + while (child) { + nsCOMPtr previous = child->GetPreviousSibling(); + nsresult rv = StripFormattingNodes(*child, aListOnly); NS_ENSURE_SUCCESS(rv, rv); - child = tmp; + child = previous.forget(); } } return NS_OK; @@ -2020,7 +2011,7 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(const nsAString &aInputString, NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(contextAsNode, NS_ERROR_FAILURE); - rv = StripFormattingNodes(contextAsNode); + rv = StripFormattingNodes(*contextAsNode); NS_ENSURE_SUCCESS(rv, rv); RemoveBodyAndHead(contextAsNode); @@ -2062,7 +2053,7 @@ nsresult nsHTMLEditor::CreateDOMFragmentFromPaste(const nsAString &aInputString, fragment = contextAsNode; } - rv = StripFormattingNodes(fragment, true); + rv = StripFormattingNodes(*fragment, true); NS_ENSURE_SUCCESS(rv, rv); // If there was no context, then treat all of the data we did get as the diff --git a/editor/libeditor/nsHTMLEditor.h b/editor/libeditor/nsHTMLEditor.h index c6010a7f8b88..9ba37849bd5c 100644 --- a/editor/libeditor/nsHTMLEditor.h +++ b/editor/libeditor/nsHTMLEditor.h @@ -581,7 +581,7 @@ protected: bool *aDoContinue); bool IsInLink(nsIDOMNode *aNode, nsCOMPtr *outLink = nullptr); - nsresult StripFormattingNodes(nsIDOMNode *aNode, bool aOnlyList = false); + nsresult StripFormattingNodes(nsIContent& aNode, bool aOnlyList = false); nsresult CreateDOMFragmentFromPaste(const nsAString & aInputString, const nsAString & aContextStr, const nsAString & aInfoStr,