Bug 1454241: Remove nsINode::eDATA_NODE. r=bz
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 15 Apr 2018 12:46:24 +0200
changeset 470803 cb757c8237f0ae635266eb247032bf9147eb4e38
parent 470802 e998b6b3f9b0fda500d7df3595aeeb955fc3301c
child 470804 6bec96422fe4ba15e76247e7e8b83e506daf1f6d
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1454241
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1454241: Remove nsINode::eDATA_NODE. r=bz MozReview-Commit-ID: 6HQDAwiGgIo
accessible/html/HTMLSelectAccessible.cpp
dom/base/CharacterData.cpp
dom/base/Comment.cpp
dom/base/DocumentType.cpp
dom/base/Selection.cpp
dom/base/nsContentIterator.cpp
dom/base/nsINode.cpp
dom/base/nsINode.h
dom/base/nsTextNode.cpp
dom/xml/CDATASection.cpp
dom/xml/ProcessingInstruction.cpp
editor/libeditor/DeleteRangeTransaction.cpp
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorDOMPoint.h
--- a/accessible/html/HTMLSelectAccessible.cpp
+++ b/accessible/html/HTMLSelectAccessible.cpp
@@ -315,18 +315,17 @@ uint64_t
 HTMLSelectOptGroupAccessible::NativeInteractiveState() const
 {
   return NativelyUnavailable() ? states::UNAVAILABLE : 0;
 }
 
 bool
 HTMLSelectOptGroupAccessible::IsAcceptableChild(nsIContent* aEl) const
 {
-  return aEl->IsNodeOfType(nsINode::eDATA_NODE) ||
-    aEl->IsHTMLElement(nsGkAtoms::option);
+  return aEl->IsCharacterData() || aEl->IsHTMLElement(nsGkAtoms::option);
 }
 
 uint8_t
 HTMLSelectOptGroupAccessible::ActionCount()
 {
   return 0;
 }
 
--- a/dom/base/CharacterData.cpp
+++ b/dom/base/CharacterData.cpp
@@ -658,17 +658,17 @@ nsXBLBinding *
 CharacterData::DoGetXBLBinding() const
 {
   return nullptr;
 }
 
 bool
 CharacterData::IsNodeOfType(uint32_t aFlags) const
 {
-  return !(aFlags & ~eDATA_NODE);
+  return false;
 }
 
 void
 CharacterData::SaveSubtreeState()
 {
 }
 
 #ifdef DEBUG
--- a/dom/base/Comment.cpp
+++ b/dom/base/Comment.cpp
@@ -23,17 +23,17 @@ Comment::~Comment()
 {
 }
 
 NS_IMPL_ISUPPORTS_INHERITED(Comment, CharacterData, nsIDOMNode)
 
 bool
 Comment::IsNodeOfType(uint32_t aFlags) const
 {
-  return !(aFlags & ~(eCOMMENT | eDATA_NODE));
+  return !(aFlags & ~eCOMMENT);
 }
 
 already_AddRefed<CharacterData>
 Comment::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo, bool aCloneText) const
 {
   RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
   RefPtr<Comment> it = new Comment(ni.forget());
   if (aCloneText) {
--- a/dom/base/DocumentType.cpp
+++ b/dom/base/DocumentType.cpp
@@ -52,31 +52,26 @@ DocumentType::DocumentType(already_AddRe
                            const nsAString& aInternalSubset) :
   CharacterData(aNodeInfo),
   mPublicId(aPublicId),
   mSystemId(aSystemId),
   mInternalSubset(aInternalSubset)
 {
   MOZ_ASSERT(mNodeInfo->NodeType() == DOCUMENT_TYPE_NODE,
              "Bad NodeType in aNodeInfo");
+  MOZ_ASSERT(!IsCharacterData());
 }
 
-DocumentType::~DocumentType()
-{
-}
+DocumentType::~DocumentType() = default;
 
 NS_IMPL_ISUPPORTS_INHERITED(DocumentType, CharacterData, nsIDOMNode)
 
 bool
 DocumentType::IsNodeOfType(uint32_t aFlags) const
 {
-  // Don't claim to be eDATA_NODE since we're just inheriting
-  // CharacterData for convenience. Doctypes aren't really
-  // data nodes (they have a null .nodeValue and don't implement
-  // the DOM CharacterData interface)
   return false;
 }
 
 const nsTextFragment*
 DocumentType::GetText()
 {
   return nullptr;
 }
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -3210,17 +3210,17 @@ Selection::ContainsNode(nsINode& aNode, 
 {
   nsresult rv;
   if (mRanges.Length() == 0) {
     return false;
   }
 
   // XXXbz this duplicates the GetNodeLength code in nsRange.cpp
   uint32_t nodeLength;
-  bool isData = aNode.IsNodeOfType(nsINode::eDATA_NODE);
+  bool isData = aNode.IsCharacterData();
   if (isData) {
     nodeLength = aNode.AsText()->TextLength();
   } else {
     nodeLength = aNode.GetChildCount();
   }
 
   nsTArray<nsRange*> overlappingRanges;
   rv = GetRangesForIntervalArray(&aNode, 0, &aNode, nodeLength,
--- a/dom/base/nsContentIterator.cpp
+++ b/dom/base/nsContentIterator.cpp
@@ -35,17 +35,17 @@ NodeIsInTraversalRange(nsINode* aNode, b
   if (NS_WARN_IF(!aStart.IsSet()) || NS_WARN_IF(!aEnd.IsSet()) ||
       NS_WARN_IF(!aNode)) {
     return false;
   }
 
   // If a leaf node contains an end point of the traversal range, it is
   // always in the traversal range.
   if (aNode == aStart.Container() || aNode == aEnd.Container()) {
-    if (aNode->IsNodeOfType(nsINode::eDATA_NODE)) {
+    if (aNode->IsCharacterData()) {
       return true; // text node or something
     }
     if (!aNode->HasChildren()) {
       MOZ_ASSERT(aNode != aStart.Container() || aStart.IsStartOfContainer(),
         "aStart.Container() doesn't have children and not a data node, "
         "aStart should be at the beginning of its container");
       MOZ_ASSERT(aNode != aEnd.Container() || aEnd.IsStartOfContainer(),
         "aEnd.Container() doesn't have children and not a data node, "
@@ -312,17 +312,17 @@ nsContentIterator::InitInternal(const Ra
 {
   // get common content parent
   mCommonParent =
     nsContentUtils::GetCommonAncestor(aStart.Container(), aEnd.Container());
   if (NS_WARN_IF(!mCommonParent)) {
     return NS_ERROR_FAILURE;
   }
 
-  bool startIsData = aStart.Container()->IsNodeOfType(nsINode::eDATA_NODE);
+  bool startIsData = aStart.Container()->IsCharacterData();
 
   // Check to see if we have a collapsed range, if so, there is nothing to
   // iterate over.
   //
   // XXX: CharacterDataNodes (text nodes) are currently an exception, since
   //      we always want to be able to iterate text nodes at the end points
   //      of a range.
 
@@ -405,17 +405,17 @@ nsContentIterator::InitInternal(const Ra
         mFirst = nullptr;
       }
     }
   }
 
 
   // Find last node in range.
 
-  bool endIsData = aEnd.Container()->IsNodeOfType(nsINode::eDATA_NODE);
+  bool endIsData = aEnd.Container()->IsCharacterData();
 
   if (endIsData || !aEnd.Container()->HasChildren() || aEnd.IsStartOfContainer()) {
     if (mPre) {
       if (NS_WARN_IF(!aEnd.Container()->IsContent())) {
         // Not much else to do here...
         mLast = nullptr;
       } else {
         // If the end node is a non-container element and the end offset is 0,
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -524,17 +524,17 @@ void
 nsINode::GetNodeValueInternal(nsAString& aNodeValue)
 {
   SetDOMStringToNull(aNodeValue);
 }
 
 nsINode*
 nsINode::RemoveChild(nsINode& aOldChild, ErrorResult& aError)
 {
-  if (IsNodeOfType(eDATA_NODE)) {
+  if (IsCharacterData()) {
     // aOldChild can't be one of our children.
     aError.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
     return nullptr;
   }
 
   if (aOldChild.GetParentNode() == this) {
     nsContentUtils::MaybeFireNodeRemoved(&aOldChild, this, OwnerDoc());
   }
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -415,18 +415,16 @@ public:
     /** nsIAttribute nodes */
     eATTRIBUTE           = 1 << 2,
     /** xml processing instructions */
     ePROCESSING_INSTRUCTION = 1 << 4,
     /** comment nodes */
     eCOMMENT             = 1 << 5,
     /** form control elements */
     eHTML_FORM_CONTROL   = 1 << 6,
-    /** character data nodes (comments, PIs, text). */
-    eDATA_NODE           = 1 << 8,
     /** animation elements */
     eANIMATION           = 1 << 10,
     /** filter elements that implement SVGFilterPrimitiveStandardAttributes */
     eFILTER              = 1 << 11,
     /** SVGGeometryElement */
     eSHAPE               = 1 << 12
   };
 
--- a/dom/base/nsTextNode.cpp
+++ b/dom/base/nsTextNode.cpp
@@ -105,17 +105,17 @@ JSObject*
 nsTextNode::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return TextBinding::Wrap(aCx, this, aGivenProto);
 }
 
 bool
 nsTextNode::IsNodeOfType(uint32_t aFlags) const
 {
-  return !(aFlags & ~eDATA_NODE);
+  return false;
 }
 
 already_AddRefed<CharacterData>
 nsTextNode::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo, bool aCloneText) const
 {
   already_AddRefed<mozilla::dom::NodeInfo> ni = RefPtr<mozilla::dom::NodeInfo>(aNodeInfo).forget();
   RefPtr<nsTextNode> it = new nsTextNode(ni);
   if (aCloneText) {
--- a/dom/xml/CDATASection.cpp
+++ b/dom/xml/CDATASection.cpp
@@ -21,17 +21,17 @@ JSObject*
 CDATASection::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return CDATASectionBinding::Wrap(aCx, this, aGivenProto);
 }
 
 bool
 CDATASection::IsNodeOfType(uint32_t aFlags) const
 {
-  return !(aFlags & ~eDATA_NODE);
+  return false;
 }
 
 already_AddRefed<CharacterData>
 CDATASection::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo, bool aCloneText) const
 {
   RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
   RefPtr<CDATASection> it = new CDATASection(ni.forget());
   if (aCloneText) {
--- a/dom/xml/ProcessingInstruction.cpp
+++ b/dom/xml/ProcessingInstruction.cpp
@@ -77,17 +77,17 @@ ProcessingInstruction::GetAttrValue(nsAt
 
   GetData(data);
   return nsContentUtils::GetPseudoAttributeValue(data, aName, aValue);
 }
 
 bool
 ProcessingInstruction::IsNodeOfType(uint32_t aFlags) const
 {
-  return !(aFlags & ~(ePROCESSING_INSTRUCTION | eDATA_NODE));
+  return !(aFlags & ~ePROCESSING_INSTRUCTION);
 }
 
 already_AddRefed<CharacterData>
 ProcessingInstruction::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo,
                                      bool aCloneText) const
 {
   nsAutoString data;
   GetData(data);
--- a/editor/libeditor/DeleteRangeTransaction.cpp
+++ b/editor/libeditor/DeleteRangeTransaction.cpp
@@ -131,29 +131,27 @@ DeleteRangeTransaction::CreateTxnsToDele
     return NS_ERROR_INVALID_ARG;
   }
 
   if (NS_WARN_IF(!mEditorBase)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // see what kind of node we have
-  if (aStart.Container()->IsNodeOfType(nsINode::eDATA_NODE)) {
+  if (RefPtr<CharacterData> charDataNode =
+        CharacterData::FromNode(aStart.Container())) {
     // if the node is a chardata node, then delete chardata content
     int32_t numToDel;
     if (aStart == aEnd) {
       numToDel = 1;
     } else {
       numToDel = aEnd.Offset() - aStart.Offset();
       MOZ_DIAGNOSTIC_ASSERT(numToDel > 0);
     }
 
-    RefPtr<CharacterData> charDataNode =
-      static_cast<CharacterData*>(aStart.Container());
-
     RefPtr<DeleteTextTransaction> deleteTextTransaction =
       DeleteTextTransaction::MaybeCreate(*mEditorBase, *charDataNode,
                                          aStart.Offset(), numToDel);
     // If the text node isn't editable, it should be never undone/redone.
     // So, the transaction shouldn't be recorded.
     if (NS_WARN_IF(!deleteTextTransaction)) {
       return NS_ERROR_FAILURE;
     }
@@ -188,17 +186,18 @@ DeleteRangeTransaction::CreateTxnsToDele
   if (NS_WARN_IF(!aPoint.IsSetAndValid())) {
     return NS_ERROR_INVALID_ARG;
   }
 
   if (NS_WARN_IF(!mEditorBase)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  if (!aPoint.Container()->IsNodeOfType(nsINode::eDATA_NODE)) {
+  RefPtr<CharacterData> dataNode = CharacterData::FromNode(aPoint.Container());
+  if (!dataNode) {
     return NS_OK;
   }
 
   // If the node is a chardata node, then delete chardata content
   uint32_t startOffset, numToDelete;
   if (nsIEditor::eNext == aAction) {
     startOffset = aPoint.Offset();
     numToDelete = aPoint.Container()->Length() - aPoint.Offset();
@@ -206,18 +205,16 @@ DeleteRangeTransaction::CreateTxnsToDele
     startOffset = 0;
     numToDelete = aPoint.Offset();
   }
 
   if (!numToDelete) {
     return NS_OK;
   }
 
-  RefPtr<CharacterData> dataNode =
-    static_cast<CharacterData*>(aPoint.Container());
   RefPtr<DeleteTextTransaction> deleteTextTransaction =
     DeleteTextTransaction::MaybeCreate(*mEditorBase, *dataNode,
                                        startOffset, numToDelete);
   // If the text node isn't editable, it should be never undone/redone.
   // So, the transaction shouldn't be recorded.
   if (NS_WARN_IF(!deleteTextTransaction)) {
     return NS_ERROR_FAILURE;
   }
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -4589,19 +4589,18 @@ EditorBase::CreateTxnForDeleteRange(nsRa
     // thing to our left
     nsCOMPtr<nsIContent> priorNode = GetPreviousEditableNode(*node);
     if (NS_WARN_IF(!priorNode)) {
       return nullptr;
     }
 
     // there is a priorNode, so delete its last child (if chardata, delete the
     // last char). if it has no children, delete it
-    if (priorNode->IsNodeOfType(nsINode::eDATA_NODE)) {
-      RefPtr<CharacterData> priorNodeAsCharData =
-        static_cast<CharacterData*>(priorNode.get());
+    if (RefPtr<CharacterData> priorNodeAsCharData =
+          CharacterData::FromNode(priorNode)) {
       uint32_t length = priorNode->Length();
       // Bail out for empty chardata XXX: Do we want to do something else?
       if (NS_WARN_IF(!length)) {
         return nullptr;
       }
       RefPtr<DeleteTextTransaction> deleteTextTransaction =
         DeleteTextTransaction::MaybeCreateForPreviousCharacter(
                                  *this, *priorNodeAsCharData, length);
@@ -4629,19 +4628,18 @@ EditorBase::CreateTxnForDeleteRange(nsRa
     // right
     nsCOMPtr<nsIContent> nextNode = GetNextEditableNode(*node);
     if (NS_WARN_IF(!nextNode)) {
       return nullptr;
     }
 
     // there is a nextNode, so delete its first child (if chardata, delete the
     // first char). if it has no children, delete it
-    if (nextNode->IsNodeOfType(nsINode::eDATA_NODE)) {
-      RefPtr<CharacterData> nextNodeAsCharData =
-        static_cast<CharacterData*>(nextNode.get());
+    if (RefPtr<CharacterData> nextNodeAsCharData =
+          CharacterData::FromNode(nextNode)) {
       uint32_t length = nextNode->Length();
       // Bail out for empty chardata XXX: Do we want to do something else?
       if (NS_WARN_IF(!length)) {
         return nullptr;
       }
       RefPtr<DeleteTextTransaction> deleteTextTransaction =
         DeleteTextTransaction::MaybeCreateForNextCharacter(
                                  *this, *nextNodeAsCharData, 0);
@@ -4659,22 +4657,20 @@ EditorBase::CreateTxnForDeleteRange(nsRa
       DeleteNodeTransaction::MaybeCreate(*this, *nextNode);
     if (NS_WARN_IF(!deleteNodeTransaction)) {
       return nullptr;
     }
     nextNode.forget(aRemovingNode);
     return deleteNodeTransaction.forget();
   }
 
-  if (node->IsNodeOfType(nsINode::eDATA_NODE)) {
+  if (RefPtr<CharacterData> nodeAsCharData = CharacterData::FromNode(node)) {
     if (NS_WARN_IF(aAction != ePrevious && aAction != eNext)) {
       return nullptr;
     }
-    RefPtr<CharacterData> nodeAsCharData =
-      static_cast<CharacterData*>(node.get());
     // We have chardata, so delete a char at the proper offset
     RefPtr<DeleteTextTransaction> deleteTextTransaction =
       aAction == ePrevious ?
         DeleteTextTransaction::MaybeCreateForPreviousCharacter(
                                  *this, *nodeAsCharData, offset) :
         DeleteTextTransaction::MaybeCreateForNextCharacter(
                                  *this, *nodeAsCharData, offset);
     if (NS_WARN_IF(!deleteTextTransaction)) {
@@ -4692,36 +4688,35 @@ EditorBase::CreateTxnForDeleteRange(nsRa
   if (aAction == ePrevious) {
     selectedNode =
       GetPreviousEditableNode(EditorRawDOMPoint(node, child, offset));
   } else if (aAction == eNext) {
     selectedNode = GetNextEditableNode(EditorRawDOMPoint(node, child, offset));
   }
 
   while (selectedNode &&
-         selectedNode->IsNodeOfType(nsINode::eDATA_NODE) &&
+         selectedNode->IsCharacterData() &&
          !selectedNode->Length()) {
     // Can't delete an empty chardata node (bug 762183)
     if (aAction == ePrevious) {
       selectedNode = GetPreviousEditableNode(*selectedNode);
     } else if (aAction == eNext) {
       selectedNode = GetNextEditableNode(*selectedNode);
     }
   }
 
   if (NS_WARN_IF(!selectedNode)) {
     return nullptr;
   }
 
-  if (selectedNode->IsNodeOfType(nsINode::eDATA_NODE)) {
+  if (RefPtr<CharacterData> selectedNodeAsCharData =
+        CharacterData::FromNode(selectedNode)) {
     if (NS_WARN_IF(aAction != ePrevious && aAction != eNext)) {
       return nullptr;
     }
-    RefPtr<CharacterData> selectedNodeAsCharData =
-      static_cast<CharacterData*>(selectedNode.get());
     // we are deleting from a chardata node, so do a character deletion
     uint32_t position = 0;
     if (aAction == ePrevious) {
       position = selectedNode->Length();
     }
     RefPtr<DeleteTextTransaction> deleteTextTransaction =
       aAction == ePrevious ?
         DeleteTextTransaction::MaybeCreateForPreviousCharacter(
--- a/editor/libeditor/EditorDOMPoint.h
+++ b/editor/libeditor/EditorDOMPoint.h
@@ -217,17 +217,17 @@ public:
 
   /**
    * IsInDataNode() returns true if the container node is a data node including
    * text node.
    */
   bool
   IsInDataNode() const
   {
-    return mParent && mParent->IsNodeOfType(nsINode::eDATA_NODE);
+    return mParent && mParent->IsCharacterData();
   }
 
   /**
    * IsInTextNode() returns true if the container node is a text node.
    */
   bool
   IsInTextNode() const
   {