Bug 1191356 part 1 - Clean up nsHTMLEditRules::RemoveListStructure; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 16:16:26 +0300
changeset 295652 e9c7181b7bb448768fd0e1f4370cf487445af118
parent 295651 a5a4a49c518861102961a40b642eaff00264c533
child 295653 1c306ee11299c610d1d389f1515de565a37474ea
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
bugs1191356
milestone49.0a1
Bug 1191356 part 1 - Clean up nsHTMLEditRules::RemoveListStructure; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -3313,17 +3313,17 @@ nsHTMLEditRules::WillRemoveList(Selectio
       do
       {
         res = PopListItem(GetAsDOMNode(curNode), &bOutOfList);
         NS_ENSURE_SUCCESS(res, res);
       } while (!bOutOfList); // keep popping it out until it's not in a list anymore
     }
     else if (nsHTMLEditUtils::IsList(curNode)) // node is a list, move list items out
     {
-      res = RemoveListStructure(GetAsDOMNode(curNode));
+      res = RemoveListStructure(*curNode->AsElement());
       NS_ENSURE_SUCCESS(res, res);
     }
   }
   return res;
 }
 
 
 nsresult
@@ -7808,56 +7808,47 @@ nsHTMLEditRules::PopListItem(nsIDOMNode 
     res = mHTMLEditor->RemoveBlockContainer(GetAsDOMNode(listItem));
     NS_ENSURE_SUCCESS(res, res);
     *aOutOfList = true;
   }
   return res;
 }
 
 nsresult
-nsHTMLEditRules::RemoveListStructure(nsIDOMNode *aList)
-{
-  NS_ENSURE_ARG_POINTER(aList);
-
+nsHTMLEditRules::RemoveListStructure(Element& aList)
+{
+  NS_ENSURE_STATE(mHTMLEditor);
+  nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
   nsresult res;
 
-  nsCOMPtr<nsIDOMNode> child;
-  aList->GetFirstChild(getter_AddRefs(child));
-
-  while (child)
-  {
-    if (nsHTMLEditUtils::IsListItem(child))
-    {
-      bool bOutOfList;
-      do
-      {
-        res = PopListItem(child, &bOutOfList);
+  while (aList.GetFirstChild()) {
+    OwningNonNull<nsIContent> child = *aList.GetFirstChild();
+
+    if (nsHTMLEditUtils::IsListItem(child)) {
+      bool isOutOfList;
+      // Keep popping it out until it's not in a list anymore
+      do {
+        res = PopListItem(child->AsDOMNode(), &isOutOfList);
         NS_ENSURE_SUCCESS(res, res);
-      } while (!bOutOfList);   // keep popping it out until it's not in a list anymore
-    }
-    else if (nsHTMLEditUtils::IsList(child))
-    {
-      res = RemoveListStructure(child);
+      } while (!isOutOfList);
+    } else if (nsHTMLEditUtils::IsList(child)) {
+      res = RemoveListStructure(*child->AsElement());
       NS_ENSURE_SUCCESS(res, res);
-    }
-    else
-    {
-      // delete any non- list items for now
-      NS_ENSURE_STATE(mHTMLEditor);
+    } else {
+      // Delete any non-list items for now
       res = mHTMLEditor->DeleteNode(child);
       NS_ENSURE_SUCCESS(res, res);
     }
-    aList->GetFirstChild(getter_AddRefs(child));
-  }
-  // delete the now-empty list
-  NS_ENSURE_STATE(mHTMLEditor);
-  res = mHTMLEditor->RemoveBlockContainer(aList);
+  }
+
+  // Delete the now-empty list
+  res = mHTMLEditor->RemoveBlockContainer(aList.AsDOMNode());
   NS_ENSURE_SUCCESS(res, res);
 
-  return res;
+  return NS_OK;
 }
 
 
 nsresult
 nsHTMLEditRules::ConfirmSelectionInBody()
 {
   // get the body
   NS_ENSURE_STATE(mHTMLEditor);
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -281,17 +281,17 @@ protected:
                            nsIAtom& aBlockTag);
   nsresult MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
   nsresult SplitAsNeeded(nsIAtom& aTag, nsCOMPtr<nsINode>& inOutParent,
                          int32_t& inOutOffset);
   nsresult AddTerminatingBR(nsIDOMNode *aBlock);
   ::DOMPoint JoinNodesSmart(nsIContent& aNodeLeft, nsIContent& aNodeRight);
   Element* GetTopEnclosingMailCite(nsINode& aNode);
   nsresult PopListItem(nsIDOMNode *aListItem, bool *aOutOfList);
-  nsresult RemoveListStructure(nsIDOMNode *aList);
+  nsresult RemoveListStructure(Element& aList);
   nsresult CacheInlineStyles(nsIDOMNode *aNode);
   nsresult ReapplyCachedStyles();
   void ClearCachedStyles();
   void AdjustSpecialBreaks();
   nsresult AdjustWhitespace(Selection* aSelection);
   nsresult PinSelectionToNewBlock(Selection* aSelection);
   void CheckInterlinePosition(Selection& aSelection);
   nsresult AdjustSelection(Selection* aSelection,