Bug 1191354 part 3 - Clean up nsHTMLEditRules::InsertMozBRIfNeeded; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 16:14:15 +0300
changeset 295641 142b62061350cfb576d1dc1ab08b61b7245d3e3c
parent 295640 d556b4103dee44d5669c1074f467e8874c975e14
child 295642 6c6fd98812c7fe979ce4d0c6f9f38bc712d74d77
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1191354
milestone49.0a1
Bug 1191354 part 3 - Clean up nsHTMLEditRules::InsertMozBRIfNeeded; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -3502,22 +3502,22 @@ nsHTMLEditRules::DidMakeBasicBlock(Selec
                                    nsRulesInfo *aInfo, nsresult aResult)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   // check for empty block.  if so, put a moz br in it.
   if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIDOMNode> parent;
-  int32_t offset;
-  nsresult res = nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset);
+  NS_ENSURE_STATE(aSelection->GetRangeAt(0) &&
+                  aSelection->GetRangeAt(0)->GetStartParent());
+  nsresult res =
+    InsertMozBRIfNeeded(*aSelection->GetRangeAt(0)->GetStartParent());
   NS_ENSURE_SUCCESS(res, res);
-  res = InsertMozBRIfNeeded(parent);
-  return res;
+  return NS_OK;
 }
 
 nsresult
 nsHTMLEditRules::WillIndent(Selection* aSelection,
                             bool* aCancel, bool* aHandled)
 {
   nsresult res;
   NS_ENSURE_STATE(mHTMLEditor);
@@ -6474,19 +6474,19 @@ nsHTMLEditRules::SplitParagraph(nsIDOMNo
 
   // remove ID attribute on the paragraph we just created
   nsCOMPtr<nsIDOMElement> rightElt = do_QueryInterface(rightPara);
   NS_ENSURE_STATE(mHTMLEditor);
   res = mHTMLEditor->RemoveAttribute(rightElt, NS_LITERAL_STRING("id"));
   NS_ENSURE_SUCCESS(res, res);
 
   // check both halves of para to see if we need mozBR
-  res = InsertMozBRIfNeeded(GetAsDOMNode(leftPara));
+  res = InsertMozBRIfNeeded(*leftPara);
   NS_ENSURE_SUCCESS(res, res);
-  res = InsertMozBRIfNeeded(GetAsDOMNode(rightPara));
+  res = InsertMozBRIfNeeded(*rightPara);
   NS_ENSURE_SUCCESS(res, res);
 
   // selection to beginning of right hand para;
   // look inside any containers that are up front.
   nsCOMPtr<nsINode> rightParaNode = do_QueryInterface(rightPara);
   NS_ENSURE_STATE(mHTMLEditor && rightParaNode);
   nsCOMPtr<nsIDOMNode> child =
     GetAsDOMNode(mHTMLEditor->GetLeftmostChild(rightParaNode, true));
@@ -8060,30 +8060,31 @@ nsHTMLEditRules::UpdateDocChangeRange(ns
       res = mDocChangeRange->SetEnd(endNode, endOffset);
       NS_ENSURE_SUCCESS(res, res);
     }
   }
   return res;
 }
 
 nsresult
-nsHTMLEditRules::InsertMozBRIfNeeded(nsIDOMNode *aNode)
-{
-  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
-  if (!IsBlockNode(aNode)) return NS_OK;
+nsHTMLEditRules::InsertMozBRIfNeeded(nsINode& aNode)
+{
+  if (!IsBlockNode(aNode.AsDOMNode())) {
+    return NS_OK;
+  }
 
   bool isEmpty;
   NS_ENSURE_STATE(mHTMLEditor);
-  nsresult res = mHTMLEditor->IsEmptyNode(aNode, &isEmpty);
+  nsresult res = mHTMLEditor->IsEmptyNode(&aNode, &isEmpty);
   NS_ENSURE_SUCCESS(res, res);
   if (!isEmpty) {
     return NS_OK;
   }
 
-  return CreateMozBR(aNode, 0);
+  return CreateMozBR(aNode.AsDOMNode(), 0);
 }
 
 NS_IMETHODIMP
 nsHTMLEditRules::WillCreateNode(const nsAString& aTag, nsIDOMNode *aParent, int32_t aPosition)
 {
   return NS_OK;
 }
 
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -333,17 +333,17 @@ protected:
    * table element is its own nearest table element ancestor.
    */
   bool     InDifferentTableElements(nsIDOMNode* aNode1, nsIDOMNode* aNode2);
   bool     InDifferentTableElements(nsINode* aNode1, nsINode* aNode2);
   nsresult RemoveEmptyNodes();
   nsresult SelectionEndpointInNode(nsINode *aNode, bool *aResult);
   nsresult UpdateDocChangeRange(nsRange* aRange);
   nsresult ConfirmSelectionInBody();
-  nsresult InsertMozBRIfNeeded(nsIDOMNode *aNode);
+  nsresult InsertMozBRIfNeeded(nsINode& aNode);
   bool     IsEmptyInline(nsIDOMNode *aNode);
   bool     ListIsEmptyLine(nsTArray<mozilla::OwningNonNull<nsINode>>& arrayOfNodes);
   nsresult RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignType, bool aChildrenOnly);
   nsresult MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode, bool aStarts);
   nsresult AlignBlock(nsIDOMElement * aElement, const nsAString * aAlignType, bool aContentsOnly);
   nsresult RelativeChangeIndentationOfElementNode(nsIDOMNode *aNode, int8_t aRelativeChange);
   void DocumentModifiedWorker();