From b2e3cc44eb796ff2a7483dcafe532c7028bd7d31 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Mon, 9 Sep 2002 19:44:29 +0000 Subject: [PATCH] document.forms can get confused and insert the same form multiple times in the list. Bug 166752, r=caillon/jkeiser, sr=jst, a=asa --- content/base/src/nsContentList.cpp | 37 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/content/base/src/nsContentList.cpp b/content/base/src/nsContentList.cpp index e54b630120f6..8690d516f7f8 100644 --- a/content/base/src/nsContentList.cpp +++ b/content/base/src/nsContentList.cpp @@ -603,6 +603,8 @@ NS_IMETHODIMP nsContentList::ContentAppended(nsIDocument *aDocument, nsIContent* aContainer, PRInt32 aNewIndexInContainer) { + NS_PRECONDITION(aContainer, "Can't get at the new content if no container!"); + /* * If the state is LIST_DIRTY then we have no useful information in * our list and we want to put off doing work as much as possible. @@ -631,24 +633,22 @@ nsContentList::ContentAppended(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* ourLastContent = NS_STATIC_CAST(nsIContent*, mElements.ElementAt(ourCount - 1)); /* - * We want to append instead of invalidating in two cases: - * 1) aContainer is an ancestor of ourLastContent (this case - covers aContainer == ourLastContent) - * 2) aContainer comes after ourLastContent in document order + * We want to append instead of invalidating if the first thing + * that got appended comes after ourLastContent. */ - if (nsContentUtils::ContentIsDescendantOf(ourLastContent, aContainer)) { - appendToList = PR_TRUE; - } else { - nsCOMPtr ourLastDOM3Node(do_QueryInterface(ourLastContent)); - nsCOMPtr newNodeContainer(do_QueryInterface(aContainer)); - if (ourLastDOM3Node && newNodeContainer) { - PRUint16 comparisonFlags; - nsresult rv = ourLastDOM3Node->CompareTreePosition(newNodeContainer, - &comparisonFlags); - if (NS_SUCCEEDED(rv) && - (comparisonFlags & nsIDOMNode::TREE_POSITION_FOLLOWING)) { - appendToList = PR_TRUE; - } + nsCOMPtr ourLastDOM3Node(do_QueryInterface(ourLastContent)); + if (ourLastDOM3Node) { + nsCOMPtr firstAppendedContent; + aContainer->ChildAt(aNewIndexInContainer, + *getter_AddRefs(firstAppendedContent)); + nsCOMPtr newNode(do_QueryInterface(firstAppendedContent)); + NS_ASSERTION(newNode, "Content being inserted is not a node.... why?"); + PRUint16 comparisonFlags; + nsresult rv = ourLastDOM3Node->CompareTreePosition(newNode, + &comparisonFlags); + if (NS_SUCCEEDED(rv) && + (comparisonFlags & nsIDOMNode::TREE_POSITION_FOLLOWING)) { + appendToList = PR_TRUE; } } } @@ -822,7 +822,8 @@ nsContentList::CheckDocumentExistence() PRBool nsContentList::MatchSelf(nsIContent *aContent) { - + NS_PRECONDITION(aContent, "Can't match null stuff, you know"); + if (Match(aContent)) return PR_TRUE;