Bug 1432186 part 5. Remove nsIDOMNode's nodeType attribute. r=mccr8
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 29 Jan 2018 23:10:50 -0500
changeset 748714 1d47247b3290a35214e5cd09b6559d29f4d513bb
parent 748713 7fa8ac3f80d8f1a25929b9fda42889b4cbae72f2
child 748715 d8b7f368b916852a64703905f943b5c5a244d958
push id97228
push usersfraser@mozilla.com
push dateTue, 30 Jan 2018 10:21:04 +0000
reviewersmccr8
bugs1432186
milestone60.0a1
Bug 1432186 part 5. Remove nsIDOMNode's nodeType attribute. r=mccr8 MozReview-Commit-ID: LKsBgKcqtBS
accessible/windows/sdn/sdnAccessible.cpp
dom/base/nsINode.h
dom/interfaces/core/nsIDOMNode.idl
dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
editor/libeditor/EditorBase.cpp
layout/inspector/inDOMView.cpp
layout/inspector/inDeepTreeWalker.cpp
toolkit/components/find/nsFind.cpp
toolkit/components/find/nsFind.h
--- a/accessible/windows/sdn/sdnAccessible.cpp
+++ b/accessible/windows/sdn/sdnAccessible.cpp
@@ -85,20 +85,17 @@ sdnAccessible::get_nodeInfo(BSTR __RPC_F
   *aNodeValue = nullptr;
   *aNumChildren = 0;
   *aUniqueID = 0;
   *aNodeType = 0;
 
   if (IsDefunct())
     return CO_E_OBJNOTCONNECTED;
 
-  nsCOMPtr<nsIDOMNode> DOMNode(do_QueryInterface(mNode));
-
-  uint16_t nodeType = 0;
-  DOMNode->GetNodeType(&nodeType);
+  uint16_t nodeType = mNode->NodeType();
   *aNodeType = static_cast<unsigned short>(nodeType);
 
   if (*aNodeType !=  NODETYPE_TEXT) {
     *aNodeName = ::SysAllocString(mNode->NodeName().get());
   }
 
   nsAutoString nodeValue;
   mNode->GetNodeValue(nodeValue);
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -2265,21 +2265,16 @@ ToSupports(nsINode* aPointer)
 
 inline nsISupports*
 ToCanonicalSupports(nsINode* aPointer)
 {
   return aPointer;
 }
 
 #define NS_FORWARD_NSIDOMNODE_TO_NSINODE_HELPER(...) \
-  NS_IMETHOD GetNodeType(uint16_t* aNodeType) __VA_ARGS__ override \
-  { \
-    *aNodeType = nsINode::NodeType(); \
-    return NS_OK; \
-  } \
   NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) __VA_ARGS__ override \
   { \
     return nsINode::GetParentNode(aParentNode); \
   } \
   NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) __VA_ARGS__ override \
   { \
     return nsINode::GetChildNodes(aChildNodes); \
   } \
--- a/dom/interfaces/core/nsIDOMNode.idl
+++ b/dom/interfaces/core/nsIDOMNode.idl
@@ -27,17 +27,16 @@ interface nsIDOMNode : nsISupports
   const unsigned short      ENTITY_NODE        = 6;
   const unsigned short      PROCESSING_INSTRUCTION_NODE = 7;
   const unsigned short      COMMENT_NODE       = 8;
   const unsigned short      DOCUMENT_NODE      = 9;
   const unsigned short      DOCUMENT_TYPE_NODE = 10;
   const unsigned short      DOCUMENT_FRAGMENT_NODE = 11;
   const unsigned short      NOTATION_NODE      = 12;
 
-  readonly attribute unsigned short   nodeType;
   readonly attribute nsIDOMNode       parentNode;
   readonly attribute nsIDOMNodeList   childNodes;
   readonly attribute nsIDOMNode       firstChild;
   readonly attribute nsIDOMNode       lastChild;
   readonly attribute nsIDOMNode       previousSibling;
   readonly attribute nsIDOMNode       nextSibling;
   // Modified in DOM Level 2:
   readonly attribute nsIDOMDocument   ownerDocument;
--- a/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
+++ b/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
@@ -853,32 +853,31 @@ PersistNodeFixup::FixupXMLStyleSheetLink
 NS_IMETHODIMP
 PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
                             bool *aSerializeCloneKids,
                             nsIDOMNode **aNodeOut)
 {
     *aNodeOut = nullptr;
     *aSerializeCloneKids = false;
 
-    uint16_t type;
-    nsresult rv = aNodeIn->GetNodeType(&type);
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsINode> nodeIn = do_QueryInterface(aNodeIn);
+    uint16_t type = nodeIn->NodeType();
     if (type != nsIDOMNode::ELEMENT_NODE &&
         type != nsIDOMNode::PROCESSING_INSTRUCTION_NODE) {
         return NS_OK;
     }
 
     // Fixup xml-stylesheet processing instructions
     nsCOMPtr<nsIDOMProcessingInstruction> nodeAsPI = do_QueryInterface(aNodeIn);
     if (nodeAsPI) {
         nsAutoString target;
         nodeAsPI->GetTarget(target);
         if (target.EqualsLiteral("xml-stylesheet"))
         {
-            rv = GetNodeToFixup(aNodeIn, aNodeOut);
+            nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
             if (NS_SUCCEEDED(rv) && *aNodeOut) {
                 nsCOMPtr<nsIDOMProcessingInstruction> outNode =
                     do_QueryInterface(*aNodeOut);
                 nsAutoString href;
                 GetXMLStyleSheetLink(nodeAsPI, href);
                 if (!href.IsEmpty()) {
                     FixupURI(href);
                     FixupXMLStyleSheetLink(outNode, href);
@@ -907,190 +906,190 @@ PersistNodeFixup::FixupNode(nsIDOMNode *
             base->GetHref(href); // Doesn't matter if this fails
             nsCOMPtr<nsIDOMComment> comment;
             nsAutoString commentText;
             commentText.AssignLiteral(" base ");
             if (!href.IsEmpty()) {
                 commentText += NS_LITERAL_STRING("href=\"") + href
                     + NS_LITERAL_STRING("\" ");
             }
-            rv = ownerDocument->CreateComment(commentText,
-                                              getter_AddRefs(comment));
+            ownerDocument->CreateComment(commentText,
+                                         getter_AddRefs(comment));
             if (comment) {
                 return CallQueryInterface(comment, aNodeOut);
             }
         }
         return NS_OK;
     }
 
     // Fix up href and file links in the elements
     RefPtr<dom::HTMLAnchorElement> nodeAsAnchor = dom::HTMLAnchorElement::FromContent(content);
     if (nodeAsAnchor) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAnchor(*aNodeOut);
         }
         return rv;
     }
 
     RefPtr<dom::HTMLAreaElement> nodeAsArea = dom::HTMLAreaElement::FromContent(content);
     if (nodeAsArea) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAnchor(*aNodeOut);
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::body)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "background");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::table)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "background");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::tr)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "background");
         }
         return rv;
     }
 
     if (content->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "background");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::img)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             // Disable image loads
             nsCOMPtr<nsIImageLoadingContent> imgCon =
                 do_QueryInterface(*aNodeOut);
             if (imgCon) {
                 imgCon->SetLoadingEnabled(false);
             }
             FixupAnchor(*aNodeOut);
             FixupAttribute(*aNodeOut, "src");
         }
         return rv;
     }
 
     nsCOMPtr<nsIDOMHTMLMediaElement> nodeAsMedia = do_QueryInterface(aNodeIn);
     if (nodeAsMedia) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "src");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::source)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "src");
         }
         return rv;
     }
 
     if (content->IsSVGElement(nsGkAtoms::img)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             // Disable image loads
             nsCOMPtr<nsIImageLoadingContent> imgCon =
                 do_QueryInterface(*aNodeOut);
             if (imgCon)
                 imgCon->SetLoadingEnabled(false);
 
             // FixupAnchor(*aNodeOut);  // XXXjwatt: is this line needed?
             FixupAttribute(*aNodeOut, "href", "http://www.w3.org/1999/xlink");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::script)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "src");
         }
         return rv;
     }
 
     if (content->IsSVGElement(nsGkAtoms::script)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "href", "http://www.w3.org/1999/xlink");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::embed)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "src");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::object)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "data");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::link)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             // First see if the link represents linked content
             rv = FixupAttribute(*aNodeOut, "href");
             if (NS_FAILED(rv)) {
                 // Perhaps this link is actually an anchor to related content
                 FixupAnchor(*aNodeOut);
             }
             // TODO if "type" attribute == "text/css"
             //        fixup stylesheet
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::frame)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "src");
         }
         return rv;
     }
 
     if (content->IsHTMLElement(nsGkAtoms::iframe)) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             FixupAttribute(*aNodeOut, "src");
         }
         return rv;
     }
 
     RefPtr<dom::HTMLInputElement> nodeAsInput =
         dom::HTMLInputElement::FromContentOrNull(content);
     if (nodeAsInput) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             // Disable image loads
             nsCOMPtr<nsIImageLoadingContent> imgCon =
                 do_QueryInterface(*aNodeOut);
             if (imgCon) {
                 imgCon->SetLoadingEnabled(false);
             }
 
@@ -1135,32 +1134,32 @@ PersistNodeFixup::FixupNode(nsIDOMNode *
                     break;
             }
         }
         return rv;
     }
 
     dom::HTMLTextAreaElement* nodeAsTextArea = dom::HTMLTextAreaElement::FromContent(content);
     if (nodeAsTextArea) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             // Tell the document encoder to serialize the text child we create below
             *aSerializeCloneKids = true;
 
             nsAutoString valueStr;
             nodeAsTextArea->GetValue(valueStr);
 
             (*aNodeOut)->SetTextContent(valueStr);
         }
         return rv;
     }
 
     dom::HTMLOptionElement* nodeAsOption = dom::HTMLOptionElement::FromContent(content);
     if (nodeAsOption) {
-        rv = GetNodeToFixup(aNodeIn, aNodeOut);
+        nsresult rv = GetNodeToFixup(aNodeIn, aNodeOut);
         if (NS_SUCCEEDED(rv) && *aNodeOut) {
             nsCOMPtr<nsIContent> outContent = do_QueryInterface(*aNodeOut);
             dom::HTMLOptionElement* outElt = dom::HTMLOptionElement::FromContent(outContent);
             bool selected = nodeAsOption->Selected();
             IgnoredErrorResult ignored;
             outElt->SetDefaultSelected(selected, ignored);
         }
         return rv;
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -4054,19 +4054,18 @@ EditorBase::AreNodesSameType(nsIContent*
 bool
 EditorBase::IsTextNode(nsIDOMNode* aNode)
 {
   if (!aNode) {
     NS_NOTREACHED("null node passed to IsTextNode()");
     return false;
   }
 
-  uint16_t nodeType;
-  aNode->GetNodeType(&nodeType);
-  return (nodeType == nsIDOMNode::TEXT_NODE);
+  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+  return IsTextNode(node);
 }
 
 // static
 nsIContent*
 EditorBase::GetNodeAtRangeOffsetPoint(const RawRangeBoundary& aPoint)
 {
   if (NS_WARN_IF(!aPoint.IsSet())) {
     return nullptr;
--- a/layout/inspector/inDOMView.cpp
+++ b/layout/inspector/inDOMView.cpp
@@ -277,23 +277,22 @@ inDOMView::GetRowProperties(int32_t inde
 NS_IMETHODIMP
 inDOMView::GetCellProperties(int32_t row, nsITreeColumn* col,
                              nsAString& aProps)
 {
   inDOMViewNode* node = nullptr;
   RowToNode(row, &node);
   if (!node) return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIContent> content = do_QueryInterface(node->node);
-  if (content && content->IsInAnonymousSubtree()) {
+  nsCOMPtr<nsINode> domNode = do_QueryInterface(node->node);
+  if (domNode->IsInAnonymousSubtree()) {
     aProps.AppendLiteral("anonymous ");
   }
 
-  uint16_t nodeType;
-  node->node->GetNodeType(&nodeType);
+  uint16_t nodeType = domNode->NodeType();
   switch (nodeType) {
     case nsIDOMNode::ELEMENT_NODE:
       aProps.AppendLiteral("ELEMENT_NODE");
       break;
     case nsIDOMNode::ATTRIBUTE_NODE:
       aProps.AppendLiteral("ATTRIBUTE_NODE");
       break;
     case nsIDOMNode::TEXT_NODE:
--- a/layout/inspector/inDeepTreeWalker.cpp
+++ b/layout/inspector/inDeepTreeWalker.cpp
@@ -199,20 +199,21 @@ inDeepTreeWalker::SetCurrentNode(nsIDOMN
   // mCurrentNode can only be null if init either failed, or has not been
   // called yet.
   if (!mCurrentNode || !aCurrentNode) {
     return NS_ERROR_FAILURE;
   }
 
   // If Document nodes are skipped by the walk, we should not allow
   // one to set one as the current node either.
-  uint16_t nodeType = 0;
-  aCurrentNode->GetNodeType(&nodeType);
-  if (!mShowDocumentsAsNodes && nodeType == nsIDOMNode::DOCUMENT_NODE) {
-    return NS_ERROR_FAILURE;
+  if (!mShowDocumentsAsNodes) {
+    nsCOMPtr<nsINode> node = do_QueryInterface(aCurrentNode);
+    if (node->NodeType() == nsIDOMNode::DOCUMENT_NODE) {
+      return NS_ERROR_FAILURE;
+    }
   }
 
   return SetCurrentNode(aCurrentNode, nullptr);
 }
 
 
 nsresult
 inDeepTreeWalker::SetCurrentNode(nsIDOMNode* aCurrentNode,
@@ -228,24 +229,25 @@ inDeepTreeWalker::SetCurrentNode(nsIDOMN
   mCurrentNode = aCurrentNode;
 
   // If siblings were not passed in as argument we have to
   // get them from the parent node of aCurrentNode.
   // Note: in the mShowDoucmentsAsNodes case when a sub document
   // is set as the current, we don't want to get the children
   // from the iframe accidentally here, so let's just skip this
   // part for document nodes, they should never have siblings.
-  uint16_t nodeType = 0;
-  aCurrentNode->GetNodeType(&nodeType);
-  if (!mSiblings && nodeType != nsIDOMNode::DOCUMENT_NODE) {
-    nsCOMPtr<nsIDOMNode> parent = GetParent();
-    if (parent) {
-      mSiblings = GetChildren(parent,
-                              mShowAnonymousContent,
-                              mShowSubDocuments);
+  if (!mSiblings) {
+    nsCOMPtr<nsINode> currentNode = do_QueryInterface(aCurrentNode);
+    if (currentNode->NodeType() != nsIDOMNode::DOCUMENT_NODE) {
+      nsCOMPtr<nsIDOMNode> parent = GetParent();
+      if (parent) {
+        mSiblings = GetChildren(parent,
+                                mShowAnonymousContent,
+                                mShowSubDocuments);
+      }
     }
   }
 
   if (mSiblings && mSiblings->Length()) {
     // We cached all the siblings (if there are any) of the current node, but we
     // still have to set the index too, to be able to iterate over them.
     nsCOMPtr<nsIContent> currentAsContent = do_QueryInterface(mCurrentNode);
     MOZ_ASSERT(currentAsContent);
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -834,26 +834,16 @@ nsFind::IsBlockNode(nsIContent* aContent
                                     nsGkAtoms::td)) {
     return true;
   }
 
   return nsContentUtils::IsHTMLBlock(aContent);
 }
 
 bool
-nsFind::IsTextNode(nsIDOMNode* aNode)
-{
-  uint16_t nodeType;
-  aNode->GetNodeType(&nodeType);
-
-  return nodeType == nsIDOMNode::TEXT_NODE ||
-         nodeType == nsIDOMNode::CDATA_SECTION_NODE;
-}
-
-bool
 nsFind::IsVisibleNode(nsIDOMNode* aDOMNode)
 {
   nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
   if (!content) {
     return false;
   }
 
   nsIFrame* frame = content->GetPrimaryFrame();
--- a/toolkit/components/find/nsFind.h
+++ b/toolkit/components/find/nsFind.h
@@ -49,17 +49,16 @@ protected:
   int32_t mIterOffset;
   nsCOMPtr<nsIDOMNode> mIterNode;
 
   // Last block parent, so that we will notice crossing block boundaries:
   nsCOMPtr<nsIDOMNode> mLastBlockParent;
   nsresult GetBlockParent(nsIDOMNode* aNode, nsIDOMNode** aParent);
 
   // Utility routines:
-  bool IsTextNode(nsIDOMNode* aNode);
   bool IsBlockNode(nsIContent* aNode);
   bool SkipNode(nsIContent* aNode);
   bool IsVisibleNode(nsIDOMNode* aNode);
 
   // Move in the right direction for our search:
   nsresult NextNode(nsIDOMRange* aSearchRange,
                     nsIDOMRange* aStartPoint, nsIDOMRange* aEndPoint,
                     bool aContinueOk);