Bug 763869 part 3 - Make aIndexes param optional; r=bz
authorAryeh Gregor <ayg@aryeh.name>
Thu, 14 Jun 2012 09:47:03 +0300
changeset 96827 20a5ddaca1a2e9c2a486014e337e3b2eb5a0f529
parent 96826 947d5be8b6eff8cd69f88e2382a060cb31653c8d
child 96828 d0f514bd6ebcfc46bcb0232464af47211f286be4
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbz
bugs763869
milestone16.0a1
Bug 763869 part 3 - Make aIndexes param optional; r=bz
content/base/src/nsContentIterator.cpp
--- a/content/base/src/nsContentIterator.cpp
+++ b/content/base/src/nsContentIterator.cpp
@@ -102,29 +102,33 @@ public:
   virtual nsINode* GetCurrentNode();
 
   virtual bool IsDone();
 
   virtual nsresult PositionAt(nsINode* aCurNode);
 
 protected:
 
-  nsINode* GetDeepFirstChild(nsINode* aRoot, nsTArray<PRInt32>* aIndexes);
-  nsINode* GetDeepLastChild(nsINode* aRoot, nsTArray<PRInt32>* aIndexes);
+  nsINode* GetDeepFirstChild(nsINode* aRoot,
+                             nsTArray<PRInt32>* aIndexes = nsnull);
+  nsINode* GetDeepLastChild(nsINode* aRoot,
+                            nsTArray<PRInt32>* aIndexes = nsnull);
 
   // Get the next sibling of aNode.  Note that this will generally return null
   // if aNode happens not to be a content node.  That's OK.
-  nsINode* GetNextSibling(nsINode* aNode, nsTArray<PRInt32>* aIndexes);
+  nsINode* GetNextSibling(nsINode* aNode,
+                          nsTArray<PRInt32>* aIndexes = nsnull);
 
   // Get the prev sibling of aNode.  Note that this will generally return null
   // if aNode happens not to be a content node.  That's OK.
-  nsINode* GetPrevSibling(nsINode* aNode, nsTArray<PRInt32>* aIndexes);
+  nsINode* GetPrevSibling(nsINode* aNode,
+                          nsTArray<PRInt32>* aIndexes = nsnull);
 
-  nsINode* NextNode(nsINode* aNode, nsTArray<PRInt32>* aIndexes);
-  nsINode* PrevNode(nsINode* aNode, nsTArray<PRInt32>* aIndexes);
+  nsINode* NextNode(nsINode* aNode, nsTArray<PRInt32>* aIndexes = nsnull);
+  nsINode* PrevNode(nsINode* aNode, nsTArray<PRInt32>* aIndexes = nsnull);
 
   // WARNING: This function is expensive
   nsresult RebuildIndexStack();
 
   void MakeEmpty();
 
   nsCOMPtr<nsINode> mCurNode;
   nsCOMPtr<nsINode> mFirst;
@@ -235,19 +239,19 @@ nsContentIterator::Init(nsINode* aRoot)
     return NS_ERROR_NULL_POINTER;
   }
 
   mIsDone = false;
   mIndexes.Clear();
 
   if (mPre) {
     mFirst = aRoot;
-    mLast  = GetDeepLastChild(aRoot, nsnull);
+    mLast  = GetDeepLastChild(aRoot);
   } else {
-    mFirst = GetDeepFirstChild(aRoot, nsnull);
+    mFirst = GetDeepFirstChild(aRoot);
     mLast  = aRoot;
   }
 
   mCommonParent = aRoot;
   mCurNode = mFirst;
   RebuildIndexStack();
   return NS_OK;
 }
@@ -316,17 +320,17 @@ nsContentIterator::Init(nsIDOMRange* aDO
     // sure what that comment above is talking about.
 
     if (mPre) {
       // XXX: In the future, if start offset is after the last
       //      character in the cdata node, should we set mFirst to
       //      the next sibling?
 
       if (!startIsData) {
-        mFirst = GetNextSibling(startNode, nsnull);
+        mFirst = GetNextSibling(startNode);
 
         // Does mFirst node really intersect the range?  The range could be
         // 'degenerate', i.e., not collapsed but still contain no content.
 
         if (mFirst && !NodeIsInTraversalRange(mFirst, mPre, startNode,
                                               startIndx, endNode, endIndx)) {
           mFirst = nsnull;
         }
@@ -342,17 +346,17 @@ nsContentIterator::Init(nsIDOMRange* aDO
         mFirst = nsnull;
       }
     }
   } else {
     if (mPre) {
       mFirst = cChild;
     } else {
       // post-order
-      mFirst = GetDeepFirstChild(cChild, nsnull);
+      mFirst = GetDeepFirstChild(cChild);
 
       // Does mFirst node really intersect the range?  The range could be
       // 'degenerate', i.e., not collapsed but still contain no content.
 
       if (mFirst && !NodeIsInTraversalRange(mFirst, mPre, startNode, startIndx,
                                             endNode, endIndx)) {
         mFirst = nsnull;
       }
@@ -374,17 +378,17 @@ nsContentIterator::Init(nsIDOMRange* aDO
       }
     } else {
       // post-order
       //
       // XXX: In the future, if end offset is before the first character in the
       //      cdata node, should we set mLast to the prev sibling?
 
       if (!endIsData) {
-        mLast = GetPrevSibling(endNode, nsnull);
+        mLast = GetPrevSibling(endNode);
 
         if (!NodeIsInTraversalRange(mLast, mPre, startNode, startIndx,
                                     endNode, endIndx)) {
           mLast = nsnull;
         }
       } else {
         mLast = endNode->AsContent();
       }
@@ -396,17 +400,17 @@ nsContentIterator::Init(nsIDOMRange* aDO
 
     if (!cChild) {
       // No child at offset!
       NS_NOTREACHED("nsContentIterator::nsContentIterator");
       return NS_ERROR_FAILURE;
     }
 
     if (mPre) {
-      mLast  = GetDeepLastChild(cChild, nsnull);
+      mLast  = GetDeepLastChild(cChild);
 
       if (!NodeIsInTraversalRange(mLast, mPre, startNode, startIndx,
                                   endNode, endIndx)) {
         mLast = nsnull;
       }
     } else {
       // post-order
       mLast = cChild;
@@ -1193,25 +1197,25 @@ nsContentSubtreeIterator::Init(nsIDOMRan
       node = startParent;
     } else {
       firstCandidate = child;
     }
   }
 
   if (!firstCandidate) {
     // then firstCandidate is next node after node
-    firstCandidate = GetNextSibling(node, nsnull);
+    firstCandidate = GetNextSibling(node);
 
     if (!firstCandidate) {
       MakeEmpty();
       return NS_OK;
     }
   }
 
-  firstCandidate = GetDeepFirstChild(firstCandidate, nsnull);
+  firstCandidate = GetDeepFirstChild(firstCandidate);
 
   // confirm that this first possible contained node is indeed contained.  Else
   // we have a range that does not fully contain any node.
 
   bool nodeBefore, nodeAfter;
   MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
     nsRange::CompareNodeToRange(firstCandidate, mRange, &nodeBefore, &nodeAfter)));
 
@@ -1240,20 +1244,20 @@ nsContentSubtreeIterator::Init(nsIDOMRan
   } else {
     lastCandidate = endParent->GetChildAt(--offset);
     NS_ASSERTION(lastCandidate,
                  "tree traversal trouble in nsContentSubtreeIterator::Init");
   }
 
   if (!lastCandidate) {
     // then lastCandidate is prev node before node
-    lastCandidate = GetPrevSibling(node, nsnull);
+    lastCandidate = GetPrevSibling(node);
   }
 
-  lastCandidate = GetDeepLastChild(lastCandidate, nsnull);
+  lastCandidate = GetDeepLastChild(lastCandidate);
 
   // confirm that this last possible contained node is indeed contained.  Else
   // we have a range that does not fully contain any node.
 
   MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
     nsRange::CompareNodeToRange(lastCandidate, mRange, &nodeBefore, &nodeAfter)));
 
   if (nodeBefore || nodeAfter) {
@@ -1301,17 +1305,17 @@ nsContentSubtreeIterator::Next()
     return;
   }
 
   if (mCurNode == mLast) {
     mIsDone = true;
     return;
   }
 
-  nsINode* nextNode = GetNextSibling(mCurNode, nsnull);
+  nsINode* nextNode = GetNextSibling(mCurNode);
   NS_ASSERTION(nextNode, "No next sibling!?! This could mean deadlock!");
 
   PRInt32 i = mEndNodes.IndexOf(nextNode);
   while (i != -1) {
     // as long as we are finding ancestors of the endpoint of the range,
     // dive down into their children
     nextNode = nextNode->GetFirstChild();
     NS_ASSERTION(nextNode, "Iterator error, expected a child node!");
@@ -1341,21 +1345,21 @@ nsContentSubtreeIterator::Prev()
     return;
   }
 
   if (mCurNode == mFirst) {
     mIsDone = true;
     return;
   }
 
-  nsINode* prevNode = GetDeepFirstChild(mCurNode, nsnull);
+  nsINode* prevNode = GetDeepFirstChild(mCurNode);
 
-  prevNode = PrevNode(prevNode, nsnull);
+  prevNode = PrevNode(prevNode);
 
-  prevNode = GetDeepLastChild(prevNode, nsnull);
+  prevNode = GetDeepLastChild(prevNode);
 
   mCurNode = GetTopAncestorInRange(prevNode);
 
   // This shouldn't be needed, but since our selection code can put us
   // in a situation where mFirst is in generated content, we need this
   // to stop the iterator when we've walked past past the first node!
   mIsDone = mCurNode == nsnull;
 }