Bug 1191354 part 9 - Remove old nsHTMLEditRules::ConvertListType variant; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Sun, 01 May 2016 16:15:27 +0300
changeset 295647 12906c848272a720d5275f31eb1546a4a2b4a199
parent 295646 68e6b568ad2a4e3793a2e30bb68e373147fd0ec5
child 295648 62d58efcd0c078ab11cae082be3a04bc6ca69810
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 9 - Remove old nsHTMLEditRules::ConvertListType variant; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -3071,17 +3071,17 @@ nsHTMLEditRules::WillMakeList(Selection*
   // or whatever is approriate.  Wohoo!
 
   uint32_t listCount = arrayOfNodes.Length();
   nsCOMPtr<nsINode> curParent;
   nsCOMPtr<Element> curList, prevListItem;
 
   for (uint32_t i = 0; i < listCount; i++) {
     // here's where we actually figure out what to do
-    nsCOMPtr<nsIDOMNode> newBlock;
+    nsCOMPtr<Element> newBlock;
     NS_ENSURE_STATE(arrayOfNodes[i]->IsContent());
     OwningNonNull<nsIContent> curNode = *arrayOfNodes[i]->AsContent();
     int32_t offset;
     curParent = nsEditor::GetNodeLocation(curNode, &offset);
 
     // make sure we don't assemble content that is in different table cells
     // into the same list.  respect table cell boundaries when listifying.
     if (curList && InDifferentTableElements(curList, curNode)) {
@@ -3108,80 +3108,81 @@ nsHTMLEditRules::WillMakeList(Selection*
       if (curList && !nsEditorUtils::IsDescendantOf(curNode, curList)) {
         // move all of our children into curList.  cheezy way to do it: move
         // whole list and then RemoveContainer() on the list.  ConvertListType
         // first: that routine handles converting the list item types, if
         // needed
         NS_ENSURE_STATE(mHTMLEditor);
         res = mHTMLEditor->MoveNode(curNode, curList, -1);
         NS_ENSURE_SUCCESS(res, res);
-        res = ConvertListType(GetAsDOMNode(curNode), address_of(newBlock),
+        res = ConvertListType(curNode->AsElement(), getter_AddRefs(newBlock),
                               listType, itemType);
         NS_ENSURE_SUCCESS(res, res);
         NS_ENSURE_STATE(mHTMLEditor);
-        res = mHTMLEditor->RemoveBlockContainer(newBlock);
+        res = mHTMLEditor->RemoveBlockContainer(GetAsDOMNode(newBlock));
         NS_ENSURE_SUCCESS(res, res);
       } else {
         // replace list with new list type
-        res = ConvertListType(GetAsDOMNode(curNode), address_of(newBlock),
+        res = ConvertListType(curNode->AsElement(), getter_AddRefs(newBlock),
                               listType, itemType);
         NS_ENSURE_SUCCESS(res, res);
-        curList = do_QueryInterface(newBlock);
+        curList = newBlock;
       }
       prevListItem = 0;
       continue;
     }
 
     if (nsHTMLEditUtils::IsListItem(curNode)) {
       NS_ENSURE_STATE(mHTMLEditor);
       if (!curParent->IsHTMLElement(listType)) {
         // list item is in wrong type of list. if we don't have a curList,
         // split the old list and make a new list of correct type.
         if (!curList || nsEditorUtils::IsDescendantOf(curNode, curList)) {
           NS_ENSURE_STATE(mHTMLEditor);
-          res = mHTMLEditor->SplitNode(curParent->AsDOMNode(), offset,
-                                       getter_AddRefs(newBlock));
-          NS_ENSURE_SUCCESS(res, res);
+          NS_ENSURE_STATE(curParent->IsContent());
+          ErrorResult rv;
+          nsCOMPtr<nsIContent> splitNode =
+            mHTMLEditor->SplitNode(*curParent->AsContent(), offset, rv);
+          NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
+          newBlock = splitNode ? splitNode->AsElement() : nullptr;
           int32_t offset;
           nsCOMPtr<nsINode> parent = nsEditor::GetNodeLocation(curParent,
                                                                &offset);
           NS_ENSURE_STATE(mHTMLEditor);
           curList = mHTMLEditor->CreateNode(listType, parent, offset);
           NS_ENSURE_STATE(curList);
         }
         // move list item to new list
         NS_ENSURE_STATE(mHTMLEditor);
         res = mHTMLEditor->MoveNode(curNode, curList, -1);
         NS_ENSURE_SUCCESS(res, res);
         // convert list item type if needed
         NS_ENSURE_STATE(mHTMLEditor);
         if (!curNode->IsHTMLElement(itemType)) {
           NS_ENSURE_STATE(mHTMLEditor);
-          newBlock = dont_AddRef(GetAsDOMNode(
-            mHTMLEditor->ReplaceContainer(curNode->AsElement(),
-                                          itemType).take()));
+          newBlock = mHTMLEditor->ReplaceContainer(curNode->AsElement(),
+                                                   itemType);
           NS_ENSURE_STATE(newBlock);
         }
       } else {
         // item is in right type of list.  But we might still have to move it.
         // and we might need to convert list item types.
         if (!curList) {
           curList = curParent->AsElement();
         } else if (curParent != curList) {
           // move list item to new list
           NS_ENSURE_STATE(mHTMLEditor);
           res = mHTMLEditor->MoveNode(curNode, curList, -1);
           NS_ENSURE_SUCCESS(res, res);
         }
         NS_ENSURE_STATE(mHTMLEditor);
         if (!curNode->IsHTMLElement(itemType)) {
           NS_ENSURE_STATE(mHTMLEditor);
-          newBlock = dont_AddRef(GetAsDOMNode(
-            mHTMLEditor->ReplaceContainer(curNode->AsElement(),
-                                          itemType).take()));
+          newBlock = mHTMLEditor->ReplaceContainer(curNode->AsElement(),
+                                                   itemType);
           NS_ENSURE_STATE(newBlock);
         }
       }
       nsCOMPtr<nsIDOMElement> curElement = do_QueryInterface(curNode);
       NS_NAMED_LITERAL_STRING(typestr, "type");
       if (aBulletType && !aBulletType->IsEmpty()) {
         NS_ENSURE_STATE(mHTMLEditor);
         res = mHTMLEditor->SetAttribute(curElement, typestr, *aBulletType);
@@ -4334,37 +4335,18 @@ nsHTMLEditRules::OutdentPartOfBlock(nsID
   return res;
 }
 
 ///////////////////////////////////////////////////////////////////////////
 // ConvertListType:  convert list type and list item type.
 //
 //
 nsresult
-nsHTMLEditRules::ConvertListType(nsIDOMNode* aList,
-                                 nsCOMPtr<nsIDOMNode>* outList,
-                                 nsIAtom* aListType,
-                                 nsIAtom* aItemType)
-{
-  MOZ_ASSERT(aListType);
-  MOZ_ASSERT(aItemType);
-
-  NS_ENSURE_TRUE(aList && outList, NS_ERROR_NULL_POINTER);
-  nsCOMPtr<Element> list = do_QueryInterface(aList);
-  NS_ENSURE_STATE(list);
-
-  nsCOMPtr<dom::Element> outNode;
-  nsresult rv = ConvertListType(list, getter_AddRefs(outNode), aListType, aItemType);
-  *outList = outNode ? outNode->AsDOMNode() : nullptr;
-  return rv;
-}
-
-nsresult
 nsHTMLEditRules::ConvertListType(Element* aList,
-                                 dom::Element** aOutList,
+                                 Element** aOutList,
                                  nsIAtom* aListType,
                                  nsIAtom* aItemType)
 {
   MOZ_ASSERT(aList);
   MOZ_ASSERT(aOutList);
   MOZ_ASSERT(aListType);
   MOZ_ASSERT(aItemType);
 
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -217,20 +217,16 @@ protected:
                       nsCOMPtr<nsIDOMNode> *aMiddleNode = 0);
   nsresult OutdentPartOfBlock(nsIDOMNode *aBlock,
                               nsIDOMNode *aStartChild,
                               nsIDOMNode *aEndChild,
                               bool aIsBlockIndentedWithCSS,
                               nsCOMPtr<nsIDOMNode> *aLeftNode = 0,
                               nsCOMPtr<nsIDOMNode> *aRightNode = 0);
 
-  nsresult ConvertListType(nsIDOMNode* aList,
-                           nsCOMPtr<nsIDOMNode>* outList,
-                           nsIAtom* aListType,
-                           nsIAtom* aItemType);
   nsresult ConvertListType(Element* aList, Element** aOutList,
                            nsIAtom* aListType, nsIAtom* aItemType);
 
   nsresult CreateStyleForInsertText(Selection& aSelection, nsIDocument& aDoc);
   enum class MozBRCounts { yes, no };
   nsresult IsEmptyBlock(Element& aNode, bool* aOutIsEmptyBlock,
                         MozBRCounts aMozBRCounts = MozBRCounts::yes);
   nsresult CheckForEmptyBlock(nsINode* aStartNode, Element* aBodyNode,