From a26daa2f0dab91f1b6000cd333d934396e6db91d Mon Sep 17 00:00:00 2001 From: "waterson%netscape.com" Date: Tue, 1 Feb 2000 22:57:36 +0000 Subject: [PATCH] Bugs 20677, 23905. Change nsXULElement to implement nsIContent like nsGenericElement and nsGenericHTMLElement. Specifically, do 'shallow' SetDocument() calls in AppendChildTo(), InsertChildAt() and ReplaceChildAt() methods. Change nsXULDocument to leave newly create element's mDocument as null (so 'null mDocument' means 'this element is not currently in the document'. Fix callers to ensure that a deep SetDocument() is made where necessary. r=hyatt --- content/xul/content/src/nsXULElement.cpp | 128 ++++++++---------- content/xul/content/src/nsXULElement.h | 2 - content/xul/document/src/nsXULDocument.cpp | 14 +- layout/base/nsCSSFrameConstructor.cpp | 5 + .../html/style/src/nsCSSFrameConstructor.cpp | 5 + layout/xul/base/src/nsTreeRowGroupFrame.cpp | 1 + rdf/content/src/nsXULDocument.cpp | 14 +- rdf/content/src/nsXULElement.cpp | 128 ++++++++---------- rdf/content/src/nsXULElement.h | 2 - 9 files changed, 145 insertions(+), 154 deletions(-) diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 0f4843a21828..f54f0b0c70e2 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -916,6 +916,12 @@ nsXULElement::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMN rv = InsertChildAt(newcontent, pos, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to insert aNewChild"); if (NS_FAILED(rv)) return rv; + + // Because InsertChildAt() only does a "shallow" + // SetDocument(), we need to ensure that a "deep" one is + // done now... + rv = newcontent->SetDocument(mDocument, PR_TRUE); + if (NS_FAILED(rv)) return rv; } // XXX Hmm. There's a case here that we handle ambiguously, I @@ -927,6 +933,12 @@ nsXULElement::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMN rv = AppendChildTo(newcontent, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to append a aNewChild"); if (NS_FAILED(rv)) return rv; + + // Because AppendChildTo() only does a "shallow" + // SetDocument(), we need to ensure that a "deep" one is done + // now... + rv = newcontent->SetDocument(mDocument, PR_TRUE); + if (NS_FAILED(rv)) return rv; } NS_ADDREF(aNewChild); @@ -963,6 +975,12 @@ nsXULElement::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMN if (newelement) { rv = ReplaceChildAt(newelement, pos, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to replace old child"); + + // Because ReplaceChildAt() only does a "shallow" + // SetDocument(), we need to ensure that a "deep" one + // is done now... + rv = newelement->SetDocument(mDocument, PR_TRUE); + if (NS_FAILED(rv)) return rv; } } } @@ -1856,40 +1874,39 @@ nsXULElement::GetDocument(nsIDocument*& aResult) const NS_IMETHODIMP nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) { - if (aDocument == mDocument) - return NS_OK; - nsresult rv; - nsCOMPtr rdfDoc; - if (mDocument) { - // Release the named reference to the script object so it can - // be garbage collected. - if (mScriptObject) { - nsCOMPtr global; - mDocument->GetScriptGlobalObject(getter_AddRefs(global)); - if (global) { - nsCOMPtr context; - global->GetContext(getter_AddRefs(context)); - if (context) { - context->RemoveReference((void*) &mScriptObject, mScriptObject); + if (aDocument != mDocument) { + nsCOMPtr rdfDoc; + if (mDocument) { + // Release the named reference to the script object so it can + // be garbage collected. + if (mScriptObject) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + nsCOMPtr context; + global->GetContext(getter_AddRefs(context)); + if (context) { + context->RemoveReference((void*) &mScriptObject, mScriptObject); + } } } } - } - mDocument = aDocument; // not refcounted + mDocument = aDocument; // not refcounted - if (mDocument) { - // Add a named reference to the script object. - if (mScriptObject) { - nsCOMPtr global; - mDocument->GetScriptGlobalObject(getter_AddRefs(global)); - if (global) { - nsCOMPtr context; - global->GetContext(getter_AddRefs(context)); - if (context) { - context->AddNamedReference((void*) &mScriptObject, mScriptObject, "nsXULElement::mScriptObject"); + if (mDocument) { + // Add a named reference to the script object. + if (mScriptObject) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + nsCOMPtr context; + global->GetContext(getter_AddRefs(context)); + if (context) { + context->AddNamedReference((void*) &mScriptObject, mScriptObject, "nsXULElement::mScriptObject"); + } } } } @@ -1916,6 +1933,7 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) child->SetDocument(aDocument, aDeep); } } + return NS_OK; } @@ -2010,10 +2028,10 @@ nsXULElement::InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) aKid->SetParent(NS_STATIC_CAST(nsIStyledContent*, this)); //nsRange::OwnerChildInserted(this, aIndex); - //XXXwaterson this should be shallow - aKid->SetDocument(mDocument, PR_TRUE); + // N.B. that this is "shallow"! + aKid->SetDocument(mDocument, PR_FALSE); - if (aNotify && ElementIsInDocument()) { + if (aNotify && mDocument) { mDocument->ContentInserted(NS_STATIC_CAST(nsIStyledContent*, this), aKid, aIndex); } } @@ -2052,18 +2070,17 @@ nsXULElement::ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) aKid->SetParent(NS_STATIC_CAST(nsIStyledContent*, this)); //nsRange::OwnerChildReplaced(this, aIndex, oldKid); - //XXXwaterson this should be shallow - aKid->SetDocument(mDocument, PR_TRUE); + // N.B. that we only do a "shallow" SetDocument() + // here. Callers beware! + aKid->SetDocument(mDocument, PR_FALSE); - if (aNotify && ElementIsInDocument()) { + if (aNotify && mDocument) { mDocument->ContentReplaced(NS_STATIC_CAST(nsIStyledContent*, this), oldKid, aKid, aIndex); } -#if 0 //XXXwaterson put this in eventually. // This will cause the script object to be unrooted for each // element in the subtree. oldKid->SetDocument(nsnull, PR_TRUE); -#endif // We've got no mo' parent. oldKid->SetParent(nsnull); @@ -2090,10 +2107,10 @@ nsXULElement::AppendChildTo(nsIContent* aKid, PRBool aNotify) aKid->SetParent(NS_STATIC_CAST(nsIStyledContent*, this)); // ranges don't need adjustment since new child is at end of list - //XXXwaterson this should be shallow - aKid->SetDocument(mDocument, PR_TRUE); + // N.B. that this is only "shallow". Callers beware! + aKid->SetDocument(mDocument, PR_FALSE); - if (aNotify && ElementIsInDocument()) { + if (aNotify && mDocument) { PRUint32 cnt; rv = mChildren->Count(&cnt); if (NS_FAILED(rv)) return rv; @@ -2194,15 +2211,13 @@ nsXULElement::RemoveChildAt(PRInt32 aIndex, PRBool aNotify) nsIDocument* doc = mDocument; PRBool removeOk = mChildren->RemoveElementAt(aIndex); //nsRange::OwnerChildRemoved(this, aIndex, oldKid); - if (aNotify && removeOk && ElementIsInDocument()) { + if (aNotify && removeOk && mDocument) { doc->ContentRemoved(NS_STATIC_CAST(nsIStyledContent*, this), oldKid, aIndex); } -#if 0 //XXXwaterson put this in eventually // This will cause the script object to be unrooted for each // element in the subtree. oldKid->SetDocument(nsnull, PR_TRUE); -#endif // We've got no mo' parent. oldKid->SetParent(nsnull); @@ -3248,37 +3263,6 @@ nsXULElement::ExecuteOnBroadcastHandler(nsIDOMElement* anElement, const nsString } -PRBool -nsXULElement::ElementIsInDocument() -{ - // Check to see if the element is really _in_ the document; that - // is, that it actually is in the tree rooted at the document's - // root content. - if (! mDocument) - return PR_FALSE; - - nsresult rv; - - nsCOMPtr root = dont_AddRef( mDocument->GetRootContent() ); - if (! root) - return PR_FALSE; - - // Hack to get off scc's evil-use-of-do_QueryInterface() radar. - nsIStyledContent* p = NS_STATIC_CAST(nsIStyledContent*, this); - nsCOMPtr node = do_QueryInterface(p); - - while (node) { - if (node == root) - return PR_TRUE; - - nsCOMPtr oldNode = node; - rv = oldNode->GetParent(*getter_AddRefs(node)); - if (NS_FAILED(rv)) return PR_FALSE; - } - - return PR_FALSE; -} - nsresult nsXULElement::ExecuteJSCode(nsIDOMElement* anElement, nsEvent* aEvent) { diff --git a/content/xul/content/src/nsXULElement.h b/content/xul/content/src/nsXULElement.h index 333790973f66..30db2625ed7d 100644 --- a/content/xul/content/src/nsXULElement.h +++ b/content/xul/content/src/nsXULElement.h @@ -508,8 +508,6 @@ protected: nsresult ExecuteOnBroadcastHandler(nsIDOMElement* anElement, const nsString& attrName); - PRBool ElementIsInDocument(); - static nsresult ExecuteJSCode(nsIDOMElement* anElement, nsEvent* aEvent); diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index ad4ab633c9fa..c410ba59a5a3 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -4001,9 +4001,6 @@ nsXULDocument::CreateElement(PRInt32 aNameSpaceID, return NS_ERROR_UNEXPECTED; } -#if 1 // XXXwaterson remove this eventually - result->SetDocument(this, PR_FALSE); -#endif result->SetContentID(mNextContentID++); *aResult = result; @@ -5668,6 +5665,17 @@ nsXULDocument::InsertElement(nsIContent* aParent, nsIContent* aChild) if (NS_FAILED(rv)) return rv; } + // Both InsertChildAt() and AppendChildTo() only do a "shallow" + // SetDocument(); make sure that we do a "deep" one now... + nsCOMPtr doc; + rv = aParent->GetDocument(*getter_AddRefs(doc)); + if (NS_FAILED(rv)) return rv; + + NS_ASSERTION(doc != nsnull, "merging into null document"); + + rv = aChild->SetDocument(doc, PR_TRUE); + if (NS_FAILED(rv)) return rv; + return NS_OK; } diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index f1b31d346321..c0cd2ac0537a 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -3900,6 +3900,7 @@ nsCSSFrameConstructor::CreateAnonymousTreeCellFrames(nsIPresShell* aPresS // We have to make a box to hold everything. nsdoc->CreateElementWithNameSpace(nsAutoString("box"), xulNamespace, getter_AddRefs(node)); content = do_QueryInterface(node); + content->SetDocument(doc, PR_FALSE); anonymousItems->AppendElement(content); content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::kClass, nsAutoString("tree-icon"), PR_FALSE); content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, nsAutoString("1"), PR_FALSE); @@ -3908,6 +3909,8 @@ nsCSSFrameConstructor::CreateAnonymousTreeCellFrames(nsIPresShell* aPresS // Make the indentation. nsdoc->CreateElementWithNameSpace(nsAutoString("treeindentation"), xulNamespace, getter_AddRefs(node)); + content = do_QueryInterface(node); + content->SetDocument(doc, PR_FALSE); boxElement->AppendChild(node, getter_AddRefs(dummy)); nsCOMPtr treeRow; @@ -3922,6 +3925,7 @@ nsCSSFrameConstructor::CreateAnonymousTreeCellFrames(nsIPresShell* aPresS // Always make a twisty but disable it for non-containers. nsdoc->CreateElementWithNameSpace(nsAutoString("titledbutton"), xulNamespace, getter_AddRefs(node)); content = do_QueryInterface(node); + content->SetDocument(doc, PR_FALSE); content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::kClass, nsAutoString("twisty"), PR_FALSE); if (container != "true") content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, nsAutoString("true"), PR_FALSE); @@ -3934,6 +3938,7 @@ nsCSSFrameConstructor::CreateAnonymousTreeCellFrames(nsIPresShell* aPresS nsdoc->CreateElementWithNameSpace(nsAutoString("titledbutton"), xulNamespace, getter_AddRefs(node)); buttonContent = do_QueryInterface(node); + buttonContent->SetDocument(doc, PR_FALSE); buttonContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::kClass, classDesc, PR_FALSE); nsAutoString value; diff --git a/layout/html/style/src/nsCSSFrameConstructor.cpp b/layout/html/style/src/nsCSSFrameConstructor.cpp index f1b31d346321..c0cd2ac0537a 100644 --- a/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -3900,6 +3900,7 @@ nsCSSFrameConstructor::CreateAnonymousTreeCellFrames(nsIPresShell* aPresS // We have to make a box to hold everything. nsdoc->CreateElementWithNameSpace(nsAutoString("box"), xulNamespace, getter_AddRefs(node)); content = do_QueryInterface(node); + content->SetDocument(doc, PR_FALSE); anonymousItems->AppendElement(content); content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::kClass, nsAutoString("tree-icon"), PR_FALSE); content->SetAttribute(kNameSpaceID_None, nsXULAtoms::flex, nsAutoString("1"), PR_FALSE); @@ -3908,6 +3909,8 @@ nsCSSFrameConstructor::CreateAnonymousTreeCellFrames(nsIPresShell* aPresS // Make the indentation. nsdoc->CreateElementWithNameSpace(nsAutoString("treeindentation"), xulNamespace, getter_AddRefs(node)); + content = do_QueryInterface(node); + content->SetDocument(doc, PR_FALSE); boxElement->AppendChild(node, getter_AddRefs(dummy)); nsCOMPtr treeRow; @@ -3922,6 +3925,7 @@ nsCSSFrameConstructor::CreateAnonymousTreeCellFrames(nsIPresShell* aPresS // Always make a twisty but disable it for non-containers. nsdoc->CreateElementWithNameSpace(nsAutoString("titledbutton"), xulNamespace, getter_AddRefs(node)); content = do_QueryInterface(node); + content->SetDocument(doc, PR_FALSE); content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::kClass, nsAutoString("twisty"), PR_FALSE); if (container != "true") content->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, nsAutoString("true"), PR_FALSE); @@ -3934,6 +3938,7 @@ nsCSSFrameConstructor::CreateAnonymousTreeCellFrames(nsIPresShell* aPresS nsdoc->CreateElementWithNameSpace(nsAutoString("titledbutton"), xulNamespace, getter_AddRefs(node)); buttonContent = do_QueryInterface(node); + buttonContent->SetDocument(doc, PR_FALSE); buttonContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::kClass, classDesc, PR_FALSE); nsAutoString value; diff --git a/layout/xul/base/src/nsTreeRowGroupFrame.cpp b/layout/xul/base/src/nsTreeRowGroupFrame.cpp index 41bd559c21ae..eab6f42d8a4a 100644 --- a/layout/xul/base/src/nsTreeRowGroupFrame.cpp +++ b/layout/xul/base/src/nsTreeRowGroupFrame.cpp @@ -1653,6 +1653,7 @@ void nsTreeRowGroupFrame::CreateScrollbar(nsIPresContext* aPresContext) document->CreateElement("scrollbar",getter_AddRefs(node)); nsCOMPtr content = do_QueryInterface(node); + content->SetDocument(idocument, PR_FALSE); content->SetParent(mContent); nsCOMPtr xulContent = do_QueryInterface(content); diff --git a/rdf/content/src/nsXULDocument.cpp b/rdf/content/src/nsXULDocument.cpp index ad4ab633c9fa..c410ba59a5a3 100644 --- a/rdf/content/src/nsXULDocument.cpp +++ b/rdf/content/src/nsXULDocument.cpp @@ -4001,9 +4001,6 @@ nsXULDocument::CreateElement(PRInt32 aNameSpaceID, return NS_ERROR_UNEXPECTED; } -#if 1 // XXXwaterson remove this eventually - result->SetDocument(this, PR_FALSE); -#endif result->SetContentID(mNextContentID++); *aResult = result; @@ -5668,6 +5665,17 @@ nsXULDocument::InsertElement(nsIContent* aParent, nsIContent* aChild) if (NS_FAILED(rv)) return rv; } + // Both InsertChildAt() and AppendChildTo() only do a "shallow" + // SetDocument(); make sure that we do a "deep" one now... + nsCOMPtr doc; + rv = aParent->GetDocument(*getter_AddRefs(doc)); + if (NS_FAILED(rv)) return rv; + + NS_ASSERTION(doc != nsnull, "merging into null document"); + + rv = aChild->SetDocument(doc, PR_TRUE); + if (NS_FAILED(rv)) return rv; + return NS_OK; } diff --git a/rdf/content/src/nsXULElement.cpp b/rdf/content/src/nsXULElement.cpp index 0f4843a21828..f54f0b0c70e2 100644 --- a/rdf/content/src/nsXULElement.cpp +++ b/rdf/content/src/nsXULElement.cpp @@ -916,6 +916,12 @@ nsXULElement::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMN rv = InsertChildAt(newcontent, pos, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to insert aNewChild"); if (NS_FAILED(rv)) return rv; + + // Because InsertChildAt() only does a "shallow" + // SetDocument(), we need to ensure that a "deep" one is + // done now... + rv = newcontent->SetDocument(mDocument, PR_TRUE); + if (NS_FAILED(rv)) return rv; } // XXX Hmm. There's a case here that we handle ambiguously, I @@ -927,6 +933,12 @@ nsXULElement::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMN rv = AppendChildTo(newcontent, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to append a aNewChild"); if (NS_FAILED(rv)) return rv; + + // Because AppendChildTo() only does a "shallow" + // SetDocument(), we need to ensure that a "deep" one is done + // now... + rv = newcontent->SetDocument(mDocument, PR_TRUE); + if (NS_FAILED(rv)) return rv; } NS_ADDREF(aNewChild); @@ -963,6 +975,12 @@ nsXULElement::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMN if (newelement) { rv = ReplaceChildAt(newelement, pos, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to replace old child"); + + // Because ReplaceChildAt() only does a "shallow" + // SetDocument(), we need to ensure that a "deep" one + // is done now... + rv = newelement->SetDocument(mDocument, PR_TRUE); + if (NS_FAILED(rv)) return rv; } } } @@ -1856,40 +1874,39 @@ nsXULElement::GetDocument(nsIDocument*& aResult) const NS_IMETHODIMP nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) { - if (aDocument == mDocument) - return NS_OK; - nsresult rv; - nsCOMPtr rdfDoc; - if (mDocument) { - // Release the named reference to the script object so it can - // be garbage collected. - if (mScriptObject) { - nsCOMPtr global; - mDocument->GetScriptGlobalObject(getter_AddRefs(global)); - if (global) { - nsCOMPtr context; - global->GetContext(getter_AddRefs(context)); - if (context) { - context->RemoveReference((void*) &mScriptObject, mScriptObject); + if (aDocument != mDocument) { + nsCOMPtr rdfDoc; + if (mDocument) { + // Release the named reference to the script object so it can + // be garbage collected. + if (mScriptObject) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + nsCOMPtr context; + global->GetContext(getter_AddRefs(context)); + if (context) { + context->RemoveReference((void*) &mScriptObject, mScriptObject); + } } } } - } - mDocument = aDocument; // not refcounted + mDocument = aDocument; // not refcounted - if (mDocument) { - // Add a named reference to the script object. - if (mScriptObject) { - nsCOMPtr global; - mDocument->GetScriptGlobalObject(getter_AddRefs(global)); - if (global) { - nsCOMPtr context; - global->GetContext(getter_AddRefs(context)); - if (context) { - context->AddNamedReference((void*) &mScriptObject, mScriptObject, "nsXULElement::mScriptObject"); + if (mDocument) { + // Add a named reference to the script object. + if (mScriptObject) { + nsCOMPtr global; + mDocument->GetScriptGlobalObject(getter_AddRefs(global)); + if (global) { + nsCOMPtr context; + global->GetContext(getter_AddRefs(context)); + if (context) { + context->AddNamedReference((void*) &mScriptObject, mScriptObject, "nsXULElement::mScriptObject"); + } } } } @@ -1916,6 +1933,7 @@ nsXULElement::SetDocument(nsIDocument* aDocument, PRBool aDeep) child->SetDocument(aDocument, aDeep); } } + return NS_OK; } @@ -2010,10 +2028,10 @@ nsXULElement::InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) aKid->SetParent(NS_STATIC_CAST(nsIStyledContent*, this)); //nsRange::OwnerChildInserted(this, aIndex); - //XXXwaterson this should be shallow - aKid->SetDocument(mDocument, PR_TRUE); + // N.B. that this is "shallow"! + aKid->SetDocument(mDocument, PR_FALSE); - if (aNotify && ElementIsInDocument()) { + if (aNotify && mDocument) { mDocument->ContentInserted(NS_STATIC_CAST(nsIStyledContent*, this), aKid, aIndex); } } @@ -2052,18 +2070,17 @@ nsXULElement::ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) aKid->SetParent(NS_STATIC_CAST(nsIStyledContent*, this)); //nsRange::OwnerChildReplaced(this, aIndex, oldKid); - //XXXwaterson this should be shallow - aKid->SetDocument(mDocument, PR_TRUE); + // N.B. that we only do a "shallow" SetDocument() + // here. Callers beware! + aKid->SetDocument(mDocument, PR_FALSE); - if (aNotify && ElementIsInDocument()) { + if (aNotify && mDocument) { mDocument->ContentReplaced(NS_STATIC_CAST(nsIStyledContent*, this), oldKid, aKid, aIndex); } -#if 0 //XXXwaterson put this in eventually. // This will cause the script object to be unrooted for each // element in the subtree. oldKid->SetDocument(nsnull, PR_TRUE); -#endif // We've got no mo' parent. oldKid->SetParent(nsnull); @@ -2090,10 +2107,10 @@ nsXULElement::AppendChildTo(nsIContent* aKid, PRBool aNotify) aKid->SetParent(NS_STATIC_CAST(nsIStyledContent*, this)); // ranges don't need adjustment since new child is at end of list - //XXXwaterson this should be shallow - aKid->SetDocument(mDocument, PR_TRUE); + // N.B. that this is only "shallow". Callers beware! + aKid->SetDocument(mDocument, PR_FALSE); - if (aNotify && ElementIsInDocument()) { + if (aNotify && mDocument) { PRUint32 cnt; rv = mChildren->Count(&cnt); if (NS_FAILED(rv)) return rv; @@ -2194,15 +2211,13 @@ nsXULElement::RemoveChildAt(PRInt32 aIndex, PRBool aNotify) nsIDocument* doc = mDocument; PRBool removeOk = mChildren->RemoveElementAt(aIndex); //nsRange::OwnerChildRemoved(this, aIndex, oldKid); - if (aNotify && removeOk && ElementIsInDocument()) { + if (aNotify && removeOk && mDocument) { doc->ContentRemoved(NS_STATIC_CAST(nsIStyledContent*, this), oldKid, aIndex); } -#if 0 //XXXwaterson put this in eventually // This will cause the script object to be unrooted for each // element in the subtree. oldKid->SetDocument(nsnull, PR_TRUE); -#endif // We've got no mo' parent. oldKid->SetParent(nsnull); @@ -3248,37 +3263,6 @@ nsXULElement::ExecuteOnBroadcastHandler(nsIDOMElement* anElement, const nsString } -PRBool -nsXULElement::ElementIsInDocument() -{ - // Check to see if the element is really _in_ the document; that - // is, that it actually is in the tree rooted at the document's - // root content. - if (! mDocument) - return PR_FALSE; - - nsresult rv; - - nsCOMPtr root = dont_AddRef( mDocument->GetRootContent() ); - if (! root) - return PR_FALSE; - - // Hack to get off scc's evil-use-of-do_QueryInterface() radar. - nsIStyledContent* p = NS_STATIC_CAST(nsIStyledContent*, this); - nsCOMPtr node = do_QueryInterface(p); - - while (node) { - if (node == root) - return PR_TRUE; - - nsCOMPtr oldNode = node; - rv = oldNode->GetParent(*getter_AddRefs(node)); - if (NS_FAILED(rv)) return PR_FALSE; - } - - return PR_FALSE; -} - nsresult nsXULElement::ExecuteJSCode(nsIDOMElement* anElement, nsEvent* aEvent) { diff --git a/rdf/content/src/nsXULElement.h b/rdf/content/src/nsXULElement.h index 333790973f66..30db2625ed7d 100644 --- a/rdf/content/src/nsXULElement.h +++ b/rdf/content/src/nsXULElement.h @@ -508,8 +508,6 @@ protected: nsresult ExecuteOnBroadcastHandler(nsIDOMElement* anElement, const nsString& attrName); - PRBool ElementIsInDocument(); - static nsresult ExecuteJSCode(nsIDOMElement* anElement, nsEvent* aEvent);