Bug 1455891: Remove nsRange::mMaySpanAnonymousSubtrees. r?mats draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 03 Jul 2018 09:48:15 +0200
changeset 813920 da8525dc3818977f0202bbd614ab9e24a8097781
parent 813919 d0c3a5475f3335c4b94e108dcca33483b4e50bc3
child 813921 35ae348b47a2423ddd96ec34f67a1e5b8018a680
push id115046
push userbmo:emilio@crisal.io
push dateWed, 04 Jul 2018 05:02:13 +0000
reviewersmats
bugs1455891
milestone63.0a1
Bug 1455891: Remove nsRange::mMaySpanAnonymousSubtrees. r?mats MozReview-Commit-ID: GhChQy7i690
dom/base/nsRange.cpp
dom/base/nsRange.h
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -293,17 +293,16 @@ nsRange::~nsRange()
 }
 
 nsRange::nsRange(nsINode* aNode)
   : mRoot(nullptr)
   , mRegisteredCommonAncestor(nullptr)
   , mNextStartRef(nullptr)
   , mNextEndRef(nullptr)
   , mIsPositioned(false)
-  , mMaySpanAnonymousSubtrees(false)
   , mIsGenerated(false)
   , mCalledByJS(false)
 {
   MOZ_ASSERT(aNode, "range isn't in a document!");
   mOwner = aNode->OwnerDoc();
 }
 
 /* static */
@@ -1142,58 +1141,52 @@ nsRange::IsValidOffset(nsINode* aNode, u
 {
   return aNode &&
          IsValidOffset(aOffset) &&
          static_cast<size_t>(aOffset) <= aNode->Length();
 }
 
 /* static */
 nsINode*
-nsRange::ComputeRootNode(nsINode* aNode, bool aMaySpanAnonymousSubtrees)
+nsRange::ComputeRootNode(nsINode* aNode)
 {
   if (!aNode) {
     return nullptr;
   }
 
   if (aNode->IsContent()) {
     if (aNode->NodeInfo()->NameAtom() == nsGkAtoms::documentTypeNodeName) {
       return nullptr;
     }
 
     nsIContent* content = aNode->AsContent();
-    if (!aMaySpanAnonymousSubtrees) {
-      // If the node is in a shadow tree then the ShadowRoot is the root.
-      ShadowRoot* containingShadow = content->GetContainingShadow();
-      if (containingShadow) {
-        return containingShadow;
-      }
-
-      // If the node has a binding parent, that should be the root.
-      // XXXbz maybe only for native anonymous content?
-      nsINode* root = content->GetBindingParent();
-      if (root) {
-        return root;
-      }
+
+    // If the node is in a shadow tree then the ShadowRoot is the root.
+    if (ShadowRoot* containingShadow = content->GetContainingShadow()) {
+      return containingShadow;
+    }
+
+    // If the node has a binding parent, that should be the root.
+    // XXXbz maybe only for native anonymous content?
+    if (nsINode* root = content->GetBindingParent()) {
+      return root;
     }
   }
 
   // Elements etc. must be in document or in document fragment,
   // text nodes in document, in document fragment or in attribute.
-  nsINode* root = aNode->GetUncomposedDoc();
-  if (root) {
+  if (nsINode* root = aNode->GetUncomposedDoc()) {
     return root;
   }
 
-  root = aNode->SubtreeRoot();
-
-  NS_ASSERTION(!root->IsDocument(),
+  NS_ASSERTION(!aNode->SubtreeRoot()->IsDocument(),
                "GetUncomposedDoc should have returned a doc");
 
   // We allow this because of backward compatibility.
-  return root;
+  return aNode->SubtreeRoot();
 }
 
 /* static */
 bool
 nsRange::IsValidPoints(nsINode* aStartContainer, uint32_t aStartOffset,
                        nsINode* aEndContainer, uint32_t aEndOffset)
 {
   // Use NS_WARN_IF() only for the cases where the arguments are unexpected.
@@ -1375,17 +1368,17 @@ nsRange::SelectNodesInContainer(nsINode*
                                 nsIContent* aEndContent)
 {
   MOZ_ASSERT(aContainer);
   MOZ_ASSERT(aContainer->ComputeIndexOf(aStartContent) <=
                aContainer->ComputeIndexOf(aEndContent));
   MOZ_ASSERT(aStartContent && aContainer->ComputeIndexOf(aStartContent) != -1);
   MOZ_ASSERT(aEndContent && aContainer->ComputeIndexOf(aEndContent) != -1);
 
-  nsINode* newRoot = ComputeRootNode(aContainer, mMaySpanAnonymousSubtrees);
+  nsINode* newRoot = ComputeRootNode(aContainer);
   MOZ_ASSERT(newRoot);
   if (!newRoot) {
     return;
   }
 
   RawRangeBoundary start(aContainer, aStartContent->GetPreviousSibling());
   RawRangeBoundary end(aContainer, aEndContent);
   DoSetRange(start, end, newRoot);
@@ -2578,18 +2571,16 @@ nsRange::CloneContents(ErrorResult& aRv)
   return clonedFrag.forget();
 }
 
 already_AddRefed<nsRange>
 nsRange::CloneRange() const
 {
   RefPtr<nsRange> range = new nsRange(mOwner);
 
-  range->SetMaySpanAnonymousSubtrees(mMaySpanAnonymousSubtrees);
-
   range->DoSetRange(mStart.AsRaw(), mEnd.AsRaw(), mRoot);
 
   return range.forget();
 }
 
 void
 nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv)
 {
--- a/dom/base/nsRange.h
+++ b/dom/base/nsRange.h
@@ -115,21 +115,16 @@ public:
     return mEnd.GetChildAtOffset();
   }
 
   bool IsPositioned() const
   {
     return mIsPositioned;
   }
 
-  void SetMaySpanAnonymousSubtrees(bool aMaySpanAnonymousSubtrees)
-  {
-    mMaySpanAnonymousSubtrees = aMaySpanAnonymousSubtrees;
-  }
-
   /**
    * Return true iff this range is part of a Selection object
    * and isn't detached.
    */
   bool IsInSelection() const
   {
     return !!mSelection;
   }
@@ -384,20 +379,17 @@ private:
 public:
   /**
    * Compute the root node of aNode for initializing range classes.
    * When aNode is in an anonymous subtree, this returns the shadow root or
    * binding parent.  Otherwise, the root node of the document or document
    * fragment.  If this returns nullptr, that means aNode can be neither the
    * start container nor end container of any range.
    */
-  static nsINode* ComputeRootNode(nsINode* aNode)
-  {
-    return ComputeRootNode(aNode, false);
-  }
+  static nsINode* ComputeRootNode(nsINode* aNode);
 
   /**
    * Return true if aStartContainer/aStartOffset and aEndContainer/aEndOffset
    * are valid start and end points for a range.  Otherwise, return false.
    */
   static bool IsValidPoints(nsINode* aStartContainer, uint32_t aStartOffset,
                             nsINode* aEndContainer, uint32_t aEndOffset);
 
@@ -456,34 +448,31 @@ public:
 
   typedef nsTHashtable<nsPtrHashKey<nsRange> > RangeHashTable;
 protected:
 
   void RegisterCommonAncestor(nsINode* aNode);
   void UnregisterCommonAncestor(nsINode* aNode, bool aIsUnlinking);
   nsINode* IsValidBoundary(nsINode* aNode) const
   {
-    return ComputeRootNode(aNode, mMaySpanAnonymousSubtrees);
+    return ComputeRootNode(aNode);
   }
 
   /**
    * XXX nsRange should accept 0 - UINT32_MAX as offset.  However, users of
    *     nsRange treat offset as int32_t.  Additionally, some other internal
    *     APIs like nsINode::ComputeIndexOf() use int32_t.  Therefore,
    *     nsRange should accept only 0 - INT32_MAX as valid offset for now.
    */
   static bool IsValidOffset(uint32_t aOffset)
   {
     return aOffset <= INT32_MAX;
   }
   static bool IsValidOffset(nsINode* aNode, uint32_t aOffset);
 
-  static nsINode* ComputeRootNode(nsINode* aNode,
-                                  bool aMaySpanAnonymousSubtrees);
-
   // CharacterDataChanged set aNotInsertedYet to true to disable an assertion
   // and suppress re-registering a range common ancestor node since
   // the new text node of a splitText hasn't been inserted yet.
   // CharacterDataChanged does the re-registering when needed.
   void DoSetRange(const RawRangeBoundary& lowerBound,
                   const RawRangeBoundary& upperBound,
                   nsINode* aRoot, bool aNotInsertedYet = false);
 
@@ -561,14 +550,13 @@ protected:
   // notifications while holding a strong reference to the new child.
   nsIContent* MOZ_NON_OWNING_REF mNextStartRef;
   nsIContent* MOZ_NON_OWNING_REF mNextEndRef;
 
   RangeBoundary mStart;
   RangeBoundary mEnd;
 
   bool mIsPositioned : 1;
-  bool mMaySpanAnonymousSubtrees : 1;
   bool mIsGenerated : 1;
   bool mCalledByJS : 1;
 };
 
 #endif /* nsRange_h___ */