Bug 1432603 - replace some nsIDOMNode methods with nsINode methods (part 2). r=bz
authorJorg K <jorgk@jorgk.com>
Thu, 25 Jan 2018 00:33:24 +0100
changeset 30966 cde38eb25eba56a89cbd4afd4d757db567065f92
parent 30965 49cc2b43c34ff0e1354cf243da5652d4d9ba16ad
child 30967 3058d4ba1627fd31e1e7c448d3d80f4a3064306e
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersbz
bugs1432603
Bug 1432603 - replace some nsIDOMNode methods with nsINode methods (part 2). r=bz
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgCompose.h
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -198,60 +198,49 @@ nsMsgCompose::~nsMsgCompose()
 NS_IMPL_ISUPPORTS(nsMsgCompose, nsIMsgCompose, nsIMsgSendListener,
   nsISupportsWeakReference)
 
 //
 // Once we are here, convert the data which we know to be UTF-8 to UTF-16
 // for insertion into the editor
 //
 nsresult
-GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, int32_t &aOffset)
+GetChildOffset(nsINode *aChild, nsINode *aParent, int32_t &aOffset)
 {
   NS_ASSERTION((aChild && aParent), "bad args");
-  nsresult result = NS_ERROR_NULL_POINTER;
-  if (aChild && aParent)
+
+  if (!aChild || !aParent)
+    return NS_ERROR_NULL_POINTER;
+
+  nsINodeList* childNodes = aParent->ChildNodes();
+  for (uint32_t i = 0; i < childNodes->Length(); i++)
   {
-    nsCOMPtr<nsIDOMNodeList> childNodes;
-    result = aParent->GetChildNodes(getter_AddRefs(childNodes));
-    if ((NS_SUCCEEDED(result)) && (childNodes))
+    nsINode* childNode = childNodes->Item(i);
+    if (childNode == aChild)
     {
-      int32_t i=0;
-      for ( ; NS_SUCCEEDED(result); i++)
-      {
-        nsCOMPtr<nsIDOMNode> childNode;
-        result = childNodes->Item(i, getter_AddRefs(childNode));
-        if ((NS_SUCCEEDED(result)) && (childNode))
-        {
-          if (childNode.get()==aChild)
-          {
-            aOffset = i;
-            break;
-          }
-        }
-        else if (!childNode)
-          result = NS_ERROR_NULL_POINTER;
-      }
+      aOffset = i;
+      return NS_OK;
     }
-    else if (!childNodes)
-      result = NS_ERROR_NULL_POINTER;
   }
-  return result;
+
+  return NS_ERROR_NULL_POINTER;
 }
 
 nsresult
-GetNodeLocation(nsIDOMNode *inChild, nsCOMPtr<nsIDOMNode> *outParent, int32_t *outOffset)
+GetNodeLocation(nsIDOMNode *inChild, nsCOMPtr<nsINode> *outParent, int32_t *outOffset)
 {
   NS_ASSERTION((outParent && outOffset), "bad args");
   nsresult result = NS_ERROR_NULL_POINTER;
   if (inChild && outParent && outOffset)
   {
-    result = inChild->GetParentNode(getter_AddRefs(*outParent));
-    if ( (NS_SUCCEEDED(result)) && (*outParent) )
+    nsCOMPtr<nsINode> inChild2 = do_QueryInterface(inChild);
+    *outParent = inChild2->GetParentNode();
+    if (*outParent)
     {
-      result = GetChildOffset(inChild, *outParent, *outOffset);
+      result = GetChildOffset(inChild2, *outParent, *outOffset);
     }
   }
 
   return result;
 }
 
 bool nsMsgCompose::IsEmbeddedObjectSafe(const char * originalScheme,
                                           const char * originalHost,
@@ -589,27 +578,27 @@ nsMsgCompose::InsertDivWrappedTextAtSele
     if (delimiter == end)
       break;
     start = ++delimiter;
     if (start == end)
       break;
   }
 
   htmlEditor->InsertElementAtSelection(divElem, true);
-  nsCOMPtr<nsIDOMNode> parent;
+  nsCOMPtr<nsINode> parent;
   int32_t offset;
 
   rv = GetNodeLocation(divNode, address_of(parent), &offset);
   if (NS_SUCCEEDED(rv))
   {
     nsCOMPtr<nsISelection> selection;
     m_editor->GetSelection(getter_AddRefs(selection));
 
     if (selection)
-      selection->Collapse(parent, offset + 1);
+      selection->CollapseNative(parent, offset + 1);
   }
   if (divElem)
     divElem->SetAttribute(NS_LITERAL_STRING("class"), classStr);
 }
 
 NS_IMETHODIMP
 nsMsgCompose::ConvertAndLoadComposeWindow(nsString& aPrefix,
                                           nsString& aBuf,
@@ -788,16 +777,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
         m_editor->EndOfDocument();
         sigOnTopInserted = true;
       }
 
       if (!aBuf.IsEmpty())
       {
         nsresult rv;
         nsCOMPtr<nsIDOMElement> divElem;
+        nsCOMPtr<Element> divElem2;
         nsCOMPtr<nsIDOMElement> extraBr;
 
         if (isForwarded) {
           // Special treatment for forwarded messages: Part 1.
           // Create a <div> of the required class.
           rv = htmlEditor->CreateElementWithDefaults(NS_LITERAL_STRING("div"),
                                                      getter_AddRefs(divElem));
           NS_ENSURE_SUCCESS(rv, rv);
@@ -808,17 +798,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
           attributeValue.AssignLiteral("moz-forward-container");
           divElem->SetAttribute(attributeName, attributeValue);
 
           // We can't insert an empty <div>, so fill it with something.
           rv = htmlEditor->CreateElementWithDefaults(NS_LITERAL_STRING("br"),
                                                      getter_AddRefs(extraBr));
           NS_ENSURE_SUCCESS(rv, rv);
 
-          nsCOMPtr<nsINode> divElem2 = do_QueryInterface(divElem);
+          divElem2 = do_QueryInterface(divElem);
           nsCOMPtr<nsINode> extraBr2 = do_QueryInterface(extraBr);
           ErrorResult rv2;
           divElem2->AppendChild(*extraBr2, rv2);
           if (rv2.Failed()) {
             return rv2.StealNSResult();
           }
 
           // Insert the non-empty <div> into the DOM.
@@ -840,23 +830,23 @@ nsMsgCompose::ConvertAndLoadComposeWindo
         }
         NS_ENSURE_SUCCESS(rv, rv);
 
         if (isForwarded) {
           // Special treatment for forwarded messages: Part 2.
           if (sigOnTopInserted) {
             // Sadly the M-C editor inserts a <br> between the <div> for the signature
             // and this <div>, so remove the <br> we don't want.
-            nsCOMPtr<nsIDOMNode> brBeforeDiv;
+            nsCOMPtr<nsINode> brBeforeDiv;
             nsAutoString tagLocalName;
-            rv = divElem->GetPreviousSibling(getter_AddRefs(brBeforeDiv));
-            if (NS_SUCCEEDED(rv) && brBeforeDiv) {
-              brBeforeDiv->GetLocalName(tagLocalName);
+            brBeforeDiv = divElem2->GetPreviousSibling();
+            if (brBeforeDiv) {
+              tagLocalName = brBeforeDiv->LocalName();
               if (tagLocalName.EqualsLiteral("br")) {
-                rv = m_editor->DeleteNode(brBeforeDiv);
+                rv = m_editor->DeleteNode(brBeforeDiv->AsDOMNode());
                 NS_ENSURE_SUCCESS(rv, rv);
               }
             }
           }
 
           // Clean up the <br> we inserted.
           rv = m_editor->DeleteNode(extraBr);
           NS_ENSURE_SUCCESS(rv, rv);
@@ -888,20 +878,20 @@ nsMsgCompose::ConvertAndLoadComposeWindo
       case 0:
       {
         if (!textEditor)
         {
           m_editor->BeginningOfDocument();
           break;
         }
 
-        nsCOMPtr<nsISelection> selection = nullptr;
-        nsCOMPtr<nsIDOMNode>      parent = nullptr;
-        int32_t                   offset;
-        nsresult                  rv;
+        nsCOMPtr<nsISelection> selection;
+        nsCOMPtr<nsINode> parent;
+        int32_t offset;
+        nsresult rv;
 
         // get parent and offset of mailcite
         rv = GetNodeLocation(nodeInserted, address_of(parent), &offset);
         if (NS_FAILED(rv) || (!parent))
         {
           m_editor->BeginningOfDocument();
           break;
         }
@@ -910,25 +900,25 @@ nsMsgCompose::ConvertAndLoadComposeWindo
         m_editor->GetSelection(getter_AddRefs(selection));
         if (!selection)
         {
           m_editor->BeginningOfDocument();
           break;
         }
 
         // place selection after mailcite
-        selection->Collapse(parent, offset+1);
+        selection->CollapseNative(parent, offset+1);
 
         // insert a break at current selection
         if (!paragraphMode || !aHTMLEditor)
           textEditor->InsertLineBreak();
 
         // i'm not sure if you need to move the selection back to before the
         // break. expirement.
-        selection->Collapse(parent, offset+1);
+        selection->CollapseNative(parent, offset+1);
 
         break;
       }
 
       case 2:
       {
         m_editor->SelectAll();
         break;
@@ -3114,33 +3104,33 @@ QuotingOutputStreamListener::InsertToCom
   }
 
   if (aEditor)
   {
     nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(aEditor);
     if (textEditor)
     {
       nsCOMPtr<nsISelection> selection;
-      nsCOMPtr<nsIDOMNode>   parent;
-      int32_t                offset;
-      nsresult               rv;
+      nsCOMPtr<nsINode> parent;
+      int32_t offset;
+      nsresult rv;
 
       // get parent and offset of mailcite
       rv = GetNodeLocation(nodeInserted, address_of(parent), &offset);
       NS_ENSURE_SUCCESS(rv, rv);
 
       // get selection
       aEditor->GetSelection(getter_AddRefs(selection));
       if (selection)
       {
         // place selection after mailcite
-        selection->Collapse(parent, offset+1);
+        selection->CollapseNative(parent, offset+1);
         // insert a break at current selection
         textEditor->InsertLineBreak();
-        selection->Collapse(parent, offset+1);
+        selection->CollapseNative(parent, offset+1);
       }
       nsCOMPtr<nsISelectionController> selCon;
       aEditor->GetSelectionController(getter_AddRefs(selCon));
 
       if (selCon)
         // After ScrollSelectionIntoView(), the pending notifications might be
         // flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
         selCon->ScrollSelectionIntoView(
@@ -5349,84 +5339,75 @@ nsMsgCompose::DetermineHTMLAction(int32_
   // At this point, ask the user.
   *result = nsIMsgCompSendFormat::AskUser;
   return NS_OK;
 }
 
 /* Decides which tags trigger which convertible mode, i.e. here is the logic
    for BodyConvertible */
 // Helper function. Parameters are not checked.
-nsresult nsMsgCompose::TagConvertible(nsIDOMElement *node,  int32_t *_retval)
+nsresult nsMsgCompose::TagConvertible(Element *node,  int32_t *_retval)
 {
-    nsresult rv;
-
     *_retval = nsIMsgCompConvertible::No;
 
-    uint16_t nodeType;
-    rv = node->GetNodeType(&nodeType);
-    if (NS_FAILED(rv))
-      return rv;
-
     nsAutoString element;
-    rv = node->GetNodeName(element);
-    if (NS_FAILED(rv))
-      return rv;
+    element = node->NodeName();
 
     nsCOMPtr<nsIDOMNode> pItem;
 
     // A style attribute on any element can change layout in any way,
     // so that is not convertible.
     nsAutoString attribValue;
-    if (NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("style"), attribValue)) &&
-        !attribValue.IsEmpty())
+    node->GetAttribute(NS_LITERAL_STRING("style"), attribValue);
+    if (!attribValue.IsEmpty())
     {
       *_retval = nsIMsgCompConvertible::No;
       return NS_OK;
     }
 
     // moz-* classes are used internally by the editor and mail composition
     // (like moz-cite-prefix or moz-signature). Those can be discarded.
     // But any other ones are unconvertible. Style can be attached to them or any
     // other context (e.g. in microformats).
-    if (NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("class"), attribValue)) &&
-        !attribValue.IsEmpty())
+    node->GetAttribute(NS_LITERAL_STRING("class"), attribValue);
+    if (!attribValue.IsEmpty())
     {
       if (StringBeginsWith(attribValue, NS_LITERAL_STRING("moz-"), nsCaseInsensitiveStringComparator())) {
         // We assume that anything with a moz-* class is convertible regardless of the tag,
         // because we add, for example, class="moz-signature" to HTML messages and we still want
         // to be able to downgrade them.
         *_retval = nsIMsgCompConvertible::Plain;
       } else {
         *_retval = nsIMsgCompConvertible::No;
       }
 
       return NS_OK;
     }
 
     // ID attributes can contain attached style/context or be target of links
     // so we should preserve them.
-    if (NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("id"), attribValue)) &&
-        !attribValue.IsEmpty())
+    node->GetAttribute(NS_LITERAL_STRING("id"), attribValue);
+    if (!attribValue.IsEmpty())
     {
       *_retval = nsIMsgCompConvertible::No;
       return NS_OK;
     }
 
     // Alignment is not convertible to plaintext; editor currently uses this.
-    if (NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("align"), attribValue)) &&
-        !attribValue.IsEmpty())
+    node->GetAttribute(NS_LITERAL_STRING("align"), attribValue);
+    if (!attribValue.IsEmpty())
     {
       *_retval = nsIMsgCompConvertible::No;
       return NS_OK;
     }
 
     // Title attribute is not convertible to plaintext;
     // this also preserves any links with titles.
-    if (NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("title"), attribValue)) &&
-        !attribValue.IsEmpty())
+    node->GetAttribute(NS_LITERAL_STRING("title"), attribValue);
+    if (!attribValue.IsEmpty())
     {
       *_retval = nsIMsgCompConvertible::No;
       return NS_OK;
     }
 
     if      ( // Considered convertible to plaintext: Some "simple" elements
               // without non-convertible attributes like style, class, id,
               // or align (see above).
@@ -5478,46 +5459,43 @@ nsresult nsMsgCompose::TagConvertible(ns
             )
     {
       *_retval = nsIMsgCompConvertible::Altering;
     }
     else if (element.LowerCaseEqualsLiteral("body"))
     {
       *_retval = nsIMsgCompConvertible::Plain;
 
-        bool hasAttribute;
+      if (node->HasAttribute(NS_LITERAL_STRING("background")) ||  // There is a background image
+          node->HasAttribute(NS_LITERAL_STRING("dir"))) {         // dir=rtl attributes should not downconvert
+        *_retval = nsIMsgCompConvertible::No;
+      } else {
         nsAutoString color;
-        if (NS_SUCCEEDED(node->HasAttribute(NS_LITERAL_STRING("background"), &hasAttribute))
-            && hasAttribute)  // There is a background image
-          *_retval = nsIMsgCompConvertible::No;
-        else if (NS_SUCCEEDED(node->HasAttribute(NS_LITERAL_STRING("text"), &hasAttribute)) &&
-                 hasAttribute &&
-                 NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("text"), color)) &&
-                 !color.EqualsLiteral("#000000")) {
-          *_retval = nsIMsgCompConvertible::Altering;
+        if (node->HasAttribute(NS_LITERAL_STRING("text"))) {
+          node->GetAttribute(NS_LITERAL_STRING("text"), color);
+          if (!color.EqualsLiteral("#000000"))
+            *_retval = nsIMsgCompConvertible::Altering;
         }
-        else if (NS_SUCCEEDED(node->HasAttribute(NS_LITERAL_STRING("bgcolor"), &hasAttribute)) &&
-                 hasAttribute &&
-                 NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("bgcolor"), color)) &&
-                 !color.LowerCaseEqualsLiteral("#ffffff")) {
-          *_retval = nsIMsgCompConvertible::Altering;
+        if (*_retval != nsIMsgCompConvertible::Altering &&  // small optimization
+            node->HasAttribute(NS_LITERAL_STRING("bgcolor"))) {
+          node->GetAttribute(NS_LITERAL_STRING("bgcolor"), color);
+          if (!color.LowerCaseEqualsLiteral("#ffffff"))
+            *_retval = nsIMsgCompConvertible::Altering;
         }
-        else if (NS_SUCCEEDED(node->HasAttribute(NS_LITERAL_STRING("dir"), &hasAttribute))
-            && hasAttribute)  // dir=rtl attributes should not downconvert
-          *_retval = nsIMsgCompConvertible::No;
-
-        //ignore special color setting for link, vlink and alink at this point.
+      }
+
+      //ignore special color setting for link, vlink and alink at this point.
     }
     else if (element.LowerCaseEqualsLiteral("blockquote"))
     {
       // Skip <blockquote type="cite">
       *_retval = nsIMsgCompConvertible::Yes;
 
-      if (NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("type"), attribValue)) &&
-          attribValue.LowerCaseEqualsLiteral("cite"))
+      node->GetAttribute(NS_LITERAL_STRING("type"), attribValue);
+      if (attribValue.LowerCaseEqualsLiteral("cite"))
       {
         *_retval = nsIMsgCompConvertible::Plain;
       }
     }
     else if (
               element.LowerCaseEqualsLiteral("div") ||
               element.LowerCaseEqualsLiteral("span") ||
               element.LowerCaseEqualsLiteral("a")
@@ -5528,88 +5506,67 @@ nsresult nsMsgCompose::TagConvertible(ns
 
       // Maybe, it's an <a> element inserted by another recognizer (e.g. 4.x')
       if (element.LowerCaseEqualsLiteral("a"))
       {
         /* Ignore anchor tag, if the URI is the same as the text
            (as inserted by recognizers) */
         *_retval = nsIMsgCompConvertible::Altering;
 
-          nsAutoString hrefValue;
-          bool hasChild;
-          if (NS_SUCCEEDED(node->GetAttribute(NS_LITERAL_STRING("href"), hrefValue)) &&
-              NS_SUCCEEDED(node->HasChildNodes(&hasChild)) && hasChild)
-          {
-            nsCOMPtr<nsIDOMNodeList> children;
-            if (NS_SUCCEEDED(node->GetChildNodes(getter_AddRefs(children))) &&
-                children &&
-                NS_SUCCEEDED(children->Item(0, getter_AddRefs(pItem))) &&
-                pItem)
-            {
-              nsAutoString textValue;
-              if (NS_SUCCEEDED(pItem->GetNodeValue(textValue)) &&
-                  textValue == hrefValue)
-                *_retval = nsIMsgCompConvertible::Plain;
-            }
-          }
+        nsAutoString hrefValue;
+        node->GetAttribute(NS_LITERAL_STRING("href"), hrefValue);
+        nsINodeList* children = node->ChildNodes();
+        if (children->Length() > 0) {
+          nsINode* pItem = children->Item(0);
+          nsAutoString textValue;
+          pItem->GetNodeValue(textValue);
+          if (textValue == hrefValue)
+            *_retval = nsIMsgCompConvertible::Plain;
+        }
       }
 
       // Lastly, test, if it is just a "simple" <div> or <span>
       else if (
                 element.LowerCaseEqualsLiteral("div") ||
                 element.LowerCaseEqualsLiteral("span")
               )
       {
         *_retval = nsIMsgCompConvertible::Plain;
       }
     }
 
-    return rv;
+    return NS_OK;
 }
 
-nsresult nsMsgCompose::_NodeTreeConvertible(nsIDOMElement *node, int32_t *_retval)
+nsresult nsMsgCompose::_NodeTreeConvertible(Element *node, int32_t *_retval)
 {
     NS_ENSURE_TRUE(node && _retval, NS_ERROR_NULL_POINTER);
 
     nsresult rv;
     int32_t result;
 
     // Check this node
     rv = TagConvertible(node, &result);
     if (NS_FAILED(rv))
         return rv;
 
     // Walk tree recursively to check the children
-    bool hasChild;
-    if (NS_SUCCEEDED(node->HasChildNodes(&hasChild)) && hasChild)
+    nsINodeList* children = node->ChildNodes();
+    for (uint32_t i = 0; i < children->Length(); i++)
     {
-      nsCOMPtr<nsIDOMNodeList> children;
-      if (NS_SUCCEEDED(node->GetChildNodes(getter_AddRefs(children)))
-          && children)
-      {
-        uint32_t nbrOfElements;
-        rv = children->GetLength(&nbrOfElements);
-        for (uint32_t i = 0; NS_SUCCEEDED(rv) && i < nbrOfElements; i++)
-        {
-          nsCOMPtr<nsIDOMNode> pItem;
-          if (NS_SUCCEEDED(children->Item(i, getter_AddRefs(pItem)))
-              && pItem)
-          {
-            // We assume all nodes that are not elements are convertible,
-            // so only test elements.
-            nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(pItem);
-            if (domElement) {
-              int32_t curresult;
-              rv = _NodeTreeConvertible(domElement, &curresult);
-
-              if (NS_SUCCEEDED(rv) && curresult > result)
-                result = curresult;
-            }
-          }
-        }
+      nsINode* pItem = children->Item(i);
+      // We assume all nodes that are not elements are convertible,
+      // so only test elements.
+      nsCOMPtr<Element> domElement = do_QueryInterface(pItem);
+      if (domElement) {
+        int32_t curresult;
+        rv = _NodeTreeConvertible(domElement, &curresult);
+
+        if (NS_SUCCEEDED(rv) && curresult > result)
+          result = curresult;
       }
     }
 
     *_retval = result;
     return rv;
 }
 
 NS_IMETHODIMP
@@ -5624,17 +5581,18 @@ nsMsgCompose::BodyConvertible(int32_t *_
       return rv;
 
     // get the top level element, which contains <html>
     nsCOMPtr<nsIDOMElement> rootElement;
     rv = rootDocument->GetDocumentElement(getter_AddRefs(rootElement));
     if (NS_FAILED(rv) || !rootElement)
       return rv;
 
-    return _NodeTreeConvertible(rootElement, _retval);
+    nsCOMPtr<Element> rootElement2 = do_QueryInterface(rootElement);
+    return _NodeTreeConvertible(rootElement2, _retval);
 }
 
 NS_IMETHODIMP
 nsMsgCompose::GetIdentity(nsIMsgIdentity **aIdentity)
 {
   NS_ENSURE_ARG_POINTER(aIdentity);
   NS_IF_ADDREF(*aIdentity = m_identity);
   return NS_OK;
@@ -5649,29 +5607,30 @@ nsresult
 nsMsgCompose::MoveToAboveQuote(void)
 {
   nsCOMPtr<nsIDOMElement> rootElement;
   nsresult rv = m_editor->GetRootElement(getter_AddRefs(rootElement));
   if (NS_FAILED(rv) || !rootElement) {
     return rv;
   }
 
-  nsCOMPtr<nsIDOMNode> node;
+  nsCOMPtr<nsINode> node;
   nsAutoString attributeName;
   nsAutoString attributeValue;
   nsAutoString tagLocalName;
   attributeName.AssignLiteral("class");
 
-  rv = rootElement->GetFirstChild(getter_AddRefs(node));
-  while (NS_SUCCEEDED(rv) && node) {
-    nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
+  nsCOMPtr<nsINode> rootElement2 = do_QueryInterface(rootElement);
+  node = rootElement2->GetFirstChild();
+  while (node) {
+    nsCOMPtr<Element> element = do_QueryInterface(node);
     if (element) {
       // First check for <blockquote>. This will most likely not trigger
       // since well-behaved quotes are preceded by a cite prefix.
-      node->GetLocalName(tagLocalName);
+      tagLocalName = node->LocalName();
       if (tagLocalName.EqualsLiteral("blockquote")) {
         break;
       }
 
       // Get the class value.
       element->GetAttribute(attributeName, attributeValue);
 
       // Now check for the cite prefix, so an element with
@@ -5683,29 +5642,28 @@ nsMsgCompose::MoveToAboveQuote(void)
       // Next check for forwarded content.
       // The forwarded part is inside an element with
       // class="moz-forward-container".
       if (attributeValue.Find("moz-forward-container", true) != kNotFound) {
         break;
       }
     }
 
-    rv = node->GetNextSibling(getter_AddRefs(node));
-    if (NS_FAILED(rv) || !node) {
+    node = node->GetNextSibling();
+    if (!node) {
       // No further siblings found, so we didn't find what we were looking for.
       rv = NS_OK;
-      node = nullptr;
       break;
     }
   }
 
   // Now position. If no quote was found, we position to the very front.
   int32_t offset = 0;
   if (node) {
-    rv = GetChildOffset(node, rootElement, offset);
+    rv = GetChildOffset(node, rootElement2, offset);
     if (NS_FAILED(rv)) {
       return rv;
     }
   }
   nsCOMPtr<nsISelection> selection;
   m_editor->GetSelection(getter_AddRefs(selection));
   if (selection)
     rv = selection->Collapse(rootElement, offset);
@@ -5741,28 +5699,29 @@ nsMsgCompose::MoveToBeginningOfDocument(
  * after the last container so we don't accidentally position into a
  * <blockquote>. That's why we use our own function.
  */
 nsresult
 nsMsgCompose::MoveToEndOfDocument(void)
 {
   int32_t offset;
   nsCOMPtr<nsIDOMElement> rootElement;
-  nsCOMPtr<nsIDOMNode> lastNode;
+  nsCOMPtr<nsINode> lastNode;
   nsresult rv = m_editor->GetRootElement(getter_AddRefs(rootElement));
   if (NS_FAILED(rv) || !rootElement) {
     return rv;
   }
 
-  rv = rootElement->GetLastChild(getter_AddRefs(lastNode));
-  if (NS_FAILED(rv) || !lastNode) {
-    return rv;
+  nsCOMPtr<nsINode> rootElement2 = do_QueryInterface(rootElement);
+  lastNode = rootElement2->GetLastChild();
+  if (!lastNode) {
+    return NS_ERROR_NULL_POINTER;
   }
 
-  rv = GetChildOffset(lastNode, rootElement, offset);
+  rv = GetChildOffset(lastNode, rootElement2, offset);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsCOMPtr<nsISelection> selection;
   m_editor->GetSelection(getter_AddRefs(selection));
   if (selection)
     rv = selection->Collapse(rootElement, offset + 1);
@@ -5783,66 +5742,66 @@ nsMsgCompose::SetIdentity(nsIMsgIdentity
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMElement> rootElement;
   rv = m_editor->GetRootElement(getter_AddRefs(rootElement));
   if (NS_FAILED(rv) || !rootElement)
     return rv;
 
   //First look for the current signature, if we have one
-  nsCOMPtr<nsIDOMNode> lastNode;
-  nsCOMPtr<nsIDOMNode> node;
-  nsCOMPtr<nsIDOMNode> tempNode;
+  nsCOMPtr<nsINode> lastNode;
+  nsCOMPtr<nsINode> node;
+  nsCOMPtr<nsINode> tempNode;
   nsAutoString tagLocalName;
 
-  rv = rootElement->GetLastChild(getter_AddRefs(lastNode));
-  if (NS_SUCCEEDED(rv) && lastNode)
+  nsCOMPtr<nsINode> rootElement2 = do_QueryInterface(rootElement);
+  lastNode = rootElement2->GetLastChild();
+  if (lastNode)
   {
     node = lastNode;
     // In html, the signature is inside an element with
     // class="moz-signature"
     bool signatureFound = false;
     nsAutoString attributeName;
     attributeName.AssignLiteral("class");
 
-    do
+    while (node)
     {
-      nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
+      nsCOMPtr<Element> element = do_QueryInterface(node);
       if (element)
       {
         nsAutoString attributeValue;
 
-        rv = element->GetAttribute(attributeName, attributeValue);
+        element->GetAttribute(attributeName, attributeValue);
 
         if (attributeValue.Find("moz-signature", true) != kNotFound) {
           signatureFound = true;
           break;
         }
       }
-    } while (!signatureFound &&
-             node &&
-             NS_SUCCEEDED(node->GetPreviousSibling(getter_AddRefs(node))));
+      node = node->GetPreviousSibling();
+    }
 
     if (signatureFound)
     {
       m_editor->BeginTransaction();
-      node->GetPreviousSibling(getter_AddRefs(tempNode));
-      rv = m_editor->DeleteNode(node);
+      tempNode = node->GetPreviousSibling();
+      rv = m_editor->DeleteNode(node->AsDOMNode());
       if (NS_FAILED(rv))
       {
         m_editor->EndTransaction();
         return rv;
       }
 
       // Also, remove the <br> right before the signature.
       if (tempNode)
       {
-        tempNode->GetLocalName(tagLocalName);
+        tagLocalName = tempNode->LocalName();
         if (tagLocalName.EqualsLiteral("br"))
-          m_editor->DeleteNode(tempNode);
+          m_editor->DeleteNode(tempNode->AsDOMNode());
       }
       m_editor->EndTransaction();
     }
   }
 
   if (!CheckIncludeSignaturePrefs(aIdentity))
     return NS_OK;
 
--- a/mailnews/compose/src/nsMsgCompose.h
+++ b/mailnews/compose/src/nsMsgCompose.h
@@ -16,16 +16,17 @@
 #include "nsIMsgCopyServiceListener.h"
 #include "nsIBaseWindow.h"
 #include "nsIAbDirectory.h"
 #include "nsIWebProgressListener.h"
 #include "nsIMimeConverter.h"
 #include "nsIMsgFolder.h"
 #include "nsIDOMNode.h"
 #include "mozIDOMWindow.h"
+#include "mozilla/dom/Element.h"
 
 // Forward declares
 class QuotingOutputStreamListener;
 class nsMsgComposeSendListener;
 class nsIEditorMailSupport;
 class nsIRDFService;
 class nsIArray;
 struct nsMsgMailList;
@@ -82,18 +83,18 @@ protected:
   nsresult GetABDirAndMailLists(const nsACString& aDirUri,
                                 nsCOMArray<nsIAbDirectory>& aDirArray,
                                 nsTArray<nsMsgMailList>& aMailListArray);
   nsresult ResolveMailList(nsIAbDirectory* aMailList,
                            nsCOMArray<nsIAbDirectory>& allDirectoriesArray,
                            nsTArray<nsMsgMailList>& allMailListArray,
                            nsTArray<nsMsgMailList>& mailListResolved,
                            nsTArray<nsMsgRecipient>& aListMembers);
-  nsresult TagConvertible(nsIDOMElement *node,  int32_t *_retval);
-  nsresult _NodeTreeConvertible(nsIDOMElement *node, int32_t *_retval);
+  nsresult TagConvertible(mozilla::dom::Element *node,  int32_t *_retval);
+  nsresult _NodeTreeConvertible(mozilla::dom::Element *node, int32_t *_retval);
   nsresult MoveToAboveQuote(void);
   nsresult MoveToBeginningOfDocument(void);
   nsresult MoveToEndOfDocument(void);
   nsresult ReplaceFileURLs(nsAutoString &sigData);
   nsresult DataURLForFileURL(const nsAString &aFileURL, nsAString &aDataURL);
 
 // 3 = To, Cc, Bcc
 #define MAX_OF_RECIPIENT_ARRAY 3