From 74ea691ed501c092b4ceefaeed38b4bb5f73efac Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 24 Apr 2015 14:27:35 +0300 Subject: [PATCH] Bug 1153629 part 11 - Clean up nsHTMLEditRules::AdjustSpecialBreaks; r=ehsan --- editor/libeditor/nsHTMLEditRules.cpp | 47 ++++++++++------------------ editor/libeditor/nsHTMLEditRules.h | 2 +- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/editor/libeditor/nsHTMLEditRules.cpp b/editor/libeditor/nsHTMLEditRules.cpp index b97eb7ea6b2f..221a23a580a0 100644 --- a/editor/libeditor/nsHTMLEditRules.cpp +++ b/editor/libeditor/nsHTMLEditRules.cpp @@ -276,8 +276,7 @@ nsHTMLEditRules::Init(nsPlaintextEditor *aEditor) if (node->IsElement()) { ErrorResult rv; mDocChangeRange->SelectNode(*node, rv); - res = AdjustSpecialBreaks(node); - NS_ENSURE_SUCCESS(res, res); + AdjustSpecialBreaks(); } // add ourselves as a listener to edit actions @@ -461,8 +460,7 @@ nsHTMLEditRules::AfterEditInner(EditAction action, } // add in any needed
s, and remove any unneeded ones. - res = AdjustSpecialBreaks(); - NS_ENSURE_SUCCESS(res, res); + AdjustSpecialBreaks(); // merge any adjacent text nodes if ( (action != EditAction::insertText && @@ -7295,37 +7293,26 @@ nsHTMLEditRules::ClearCachedStyles() } -nsresult -nsHTMLEditRules::AdjustSpecialBreaks(bool aSafeToAskFrames) +void +nsHTMLEditRules::AdjustSpecialBreaks() { - nsCOMArray arrayOfNodes; - nsCOMPtr isupports; - int32_t nodeCount,j; - - // gather list of empty nodes - NS_ENSURE_STATE(mHTMLEditor); + NS_ENSURE_TRUE(mHTMLEditor, ); + + // Gather list of empty nodes + nsTArray> nodeArray; nsEmptyEditableFunctor functor(mHTMLEditor); nsDOMIterator iter(*mDocChangeRange); - iter.AppendList(functor, arrayOfNodes); + iter.AppendList(functor, nodeArray); - // put moz-br's into these empty li's and td's - nodeCount = arrayOfNodes.Count(); - for (j = 0; j < nodeCount; j++) - { - // need to put br at END of node. It may have - // empty containers in it and still pass the "IsEmptynode" test, - // and we want the br's to be after them. Also, we want the br - // to be after the selection if the selection is in this node. - uint32_t len; - nsCOMPtr theNode = arrayOfNodes[0]; - arrayOfNodes.RemoveObjectAt(0); - nsresult res = nsEditor::GetLengthOfDOMNode(theNode, len); - NS_ENSURE_SUCCESS(res, res); - res = CreateMozBR(theNode, (int32_t)len); - NS_ENSURE_SUCCESS(res, res); + // Put moz-br's into these empty li's and td's + for (auto& node : nodeArray) { + // Need to put br at END of node. It may have empty containers in it and + // still pass the "IsEmptyNode" test, and we want the br's to be after + // them. Also, we want the br to be after the selection if the selection + // is in this node. + nsresult res = CreateMozBR(node->AsDOMNode(), (int32_t)node->Length()); + NS_ENSURE_SUCCESS(res, ); } - - return NS_OK; } nsresult diff --git a/editor/libeditor/nsHTMLEditRules.h b/editor/libeditor/nsHTMLEditRules.h index 64ec7974a7de..6094a5f0e43b 100644 --- a/editor/libeditor/nsHTMLEditRules.h +++ b/editor/libeditor/nsHTMLEditRules.h @@ -312,7 +312,7 @@ protected: nsresult CacheInlineStyles(nsIDOMNode *aNode); nsresult ReapplyCachedStyles(); void ClearCachedStyles(); - nsresult AdjustSpecialBreaks(bool aSafeToAskFrames = false); + void AdjustSpecialBreaks(); nsresult AdjustWhitespace(mozilla::dom::Selection* aSelection); nsresult PinSelectionToNewBlock(mozilla::dom::Selection* aSelection); nsresult CheckInterlinePosition(mozilla::dom::Selection* aSelection);