Bug 101710: Fix topcrash regression in Find. r=sfraser, sr=kin

This commit is contained in:
rjesup%wgate.com 2001-09-27 21:49:40 +00:00
parent fcf0c7709b
commit 629c4c0235

View File

@ -574,8 +574,11 @@ nsresult nsContentIterator::GetNextSibling(nsCOMPtr<nsIContent> aNode,
{ {
if (aIndexes) if (aIndexes)
{ {
// pop node off the stack, go up one level and try again. // pop node off the stack, go up one level and return parent or fail.
aIndexes->RemoveElementAt(aIndexes->Count()-1); // Don't leave the index empty, especially if we're
// returning NULL. This confuses other parts of the code.
if (aIndexes->Count() > 1)
aIndexes->RemoveElementAt(aIndexes->Count()-1);
} }
return GetNextSibling(parent, aSibling, aIndexes); return GetNextSibling(parent, aSibling, aIndexes);
} }
@ -624,7 +627,8 @@ nsresult nsContentIterator::GetPrevSibling(nsCOMPtr<nsIContent> aNode,
} }
// indx is now canonically correct // indx is now canonically correct
if (NS_SUCCEEDED(parent->ChildAt(--indx, *getter_AddRefs(sib))) && sib) if (indx > 0 &&
NS_SUCCEEDED(parent->ChildAt(--indx, *getter_AddRefs(sib))) && sib)
{ {
*aSibling = sib; *aSibling = sib;
// update index cache // update index cache
@ -728,7 +732,10 @@ nsresult nsContentIterator::NextNode(nsCOMPtr<nsIContent> *ioNextNode, nsVoidArr
if (aIndexes) if (aIndexes)
{ {
// pop an entry off the index stack // pop an entry off the index stack
aIndexes->RemoveElementAt(aIndexes->Count()-1); // Don't leave the index empty, especially if we're
// returning NULL. This confuses other parts of the code.
if (aIndexes->Count() > 1)
aIndexes->RemoveElementAt(aIndexes->Count()-1);
} }
else mCachedIndex = 0; // this might be wrong, but we are better off guessing else mCachedIndex = 0; // this might be wrong, but we are better off guessing
*ioNextNode = parent; *ioNextNode = parent;
@ -828,11 +835,7 @@ nsresult nsContentIterator::First()
{ {
if (!mFirst) if (!mFirst)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
mIsDone = PR_FALSE; return PositionAt(mFirst);
if (mFirst == mCurNode)
return NS_OK;
mCurNode = mFirst;
return NS_OK;
} }
@ -840,11 +843,7 @@ nsresult nsContentIterator::Last()
{ {
if (!mLast) if (!mLast)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
mIsDone = PR_FALSE; return PositionAt(mLast);
if (mLast == mCurNode)
return NS_OK;
mCurNode = mLast;
return NS_OK;
} }
@ -1057,6 +1056,12 @@ public:
NS_IMETHOD MakePost(); NS_IMETHOD MakePost();
// Must override these because we don't do PositionAt
NS_IMETHOD First();
// Must override these because we don't do PositionAt
NS_IMETHOD Last();
protected: protected:
nsresult GetTopAncestorInRange( nsCOMPtr<nsIContent> aNode, nsresult GetTopAncestorInRange( nsCOMPtr<nsIContent> aNode,
@ -1267,7 +1272,7 @@ nsresult nsContentSubtreeIterator::Init(nsIDOMRange* aRange)
lastCandidate = GetDeepLastChild(lastCandidate, nsnull); lastCandidate = GetDeepLastChild(lastCandidate, nsnull);
// confirm that this first possible contained node // confirm that this last possible contained node
// is indeed contained. Else we have a range that // is indeed contained. Else we have a range that
// does not fully contain any node. // does not fully contain any node.
@ -1295,6 +1300,31 @@ nsresult nsContentSubtreeIterator::Init(nsIDOMRange* aRange)
* nsContentSubtreeIterator overrides of ContentIterator routines * nsContentSubtreeIterator overrides of ContentIterator routines
****************************************************************/ ****************************************************************/
// we can't call PositionAt in a subtree iterator...
nsresult nsContentSubtreeIterator::First()
{
if (!mFirst)
return NS_ERROR_FAILURE;
mIsDone = PR_FALSE;
if (mFirst == mCurNode)
return NS_OK;
mCurNode = mFirst;
return NS_OK;
}
// we can't call PositionAt in a subtree iterator...
nsresult nsContentSubtreeIterator::Last()
{
if (!mLast)
return NS_ERROR_FAILURE;
mIsDone = PR_FALSE;
if (mLast == mCurNode)
return NS_OK;
mCurNode = mLast;
return NS_OK;
}
nsresult nsContentSubtreeIterator::Next() nsresult nsContentSubtreeIterator::Next()
{ {
if (mIsDone) if (mIsDone)