Move the BindToTree call for the document element into SetRootContent. Bug

289209, r=sicking, sr=jst, a=asa
This commit is contained in:
bzbarsky%mit.edu 2005-04-15 01:30:14 +00:00
Родитель 807eaf5a71
Коммит 192b6aaa49
11 изменённых файлов: 62 добавлений и 52 удалений

Просмотреть файл

@ -338,7 +338,18 @@ public:
{
return mRootContent;
}
virtual void SetRootContent(nsIContent* aRoot) = 0;
/**
* Set aRoot as the root content object for this document. If aRoot is
* non-null, this should not be called on documents that currently have a
* root content without first clearing out the document's children. Passing
* in null to unbind the existing root content is allowed. This method will
* bind aRoot to the document; the caller need not call BindToTree on aRoot.
*
* Note that this method never sends out nsIDocumentObserver notifications;
* doing that is the caller's responsibility.
*/
virtual nsresult SetRootContent(nsIContent* aRoot) = 0;
/**
* Get the direct children of the document - content in

Просмотреть файл

@ -1490,21 +1490,34 @@ nsDocument::FindContentForSubDocument(nsIDocument *aDocument) const
return data.mResult;
}
void
nsresult
nsDocument::SetRootContent(nsIContent* aRoot)
{
if (mRootContent) {
PRInt32 indx = mChildren.IndexOf(mRootContent);
if (aRoot) {
mChildren.ReplaceObjectAt(aRoot, indx);
} else {
mChildren.RemoveObjectAt(indx);
if (aRoot) {
NS_ASSERTION(!mRootContent,
"Already have a root content! Clear out first!");
nsresult rv = aRoot->BindToTree(this, nsnull, nsnull, PR_TRUE);
if (NS_SUCCEEDED(rv) && !mChildren.AppendObject(aRoot)) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
} else if (aRoot) {
mChildren.AppendObject(aRoot);
if (NS_FAILED(rv)) {
aRoot->UnbindFromTree();
} else {
mRootContent = aRoot;
}
return rv;
}
mRootContent = aRoot;
if (mRootContent) {
mRootContent->UnbindFromTree();
mChildren.RemoveObject(mRootContent);
mRootContent = nsnull;
}
return NS_OK;
}
nsIContent *

Просмотреть файл

@ -291,7 +291,7 @@ public:
virtual nsIDocument* GetSubDocumentFor(nsIContent *aContent) const;
virtual nsIContent* FindContentForSubDocument(nsIDocument *aDocument) const;
virtual void SetRootContent(nsIContent* aRoot);
virtual nsresult SetRootContent(nsIContent* aRoot);
/**
* Get the direct children of the document - content in

Просмотреть файл

@ -2104,12 +2104,8 @@ HTMLContentSink::Init(nsIDocument* aDoc,
}
NS_ADDREF(mRoot);
rv = mRoot->BindToTree(mDocument, nsnull, nsnull, PR_TRUE);
if (NS_FAILED(rv)) {
mRoot->UnbindFromTree();
return rv;
}
mDocument->SetRootContent(mRoot);
rv = mDocument->SetRootContent(mRoot);
NS_ENSURE_SUCCESS(rv, rv);
}
// Make head part

Просмотреть файл

@ -242,12 +242,9 @@ nsMediaDocument::CreateSyntheticDocument()
if (!root) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = root->BindToTree(this, nsnull, nsnull, PR_TRUE);
if (NS_FAILED(rv)) {
root->UnbindFromTree();
return rv;
}
SetRootContent(root);
rv = SetRootContent(root);
NS_ENSURE_SUCCESS(rv, rv);
rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::body, nsnull,
kNameSpaceID_None,

Просмотреть файл

@ -857,14 +857,12 @@ nsXMLContentSink::SetDocElement(PRInt32 aNameSpaceID,
mDocElement = aContent;
NS_ADDREF(mDocElement);
nsresult rv = mDocElement->BindToTree(mDocument, nsnull, nsnull, PR_TRUE);
nsresult rv = mDocument->SetRootContent(mDocElement);
if (NS_FAILED(rv)) {
mDocElement->UnbindFromTree();
// If we return PR_FALSE here, the caller will bail out because it won't
// find a parent content node to append to, which is fine.
return PR_FALSE;
}
mDocument->SetRootContent(mDocElement);
return PR_TRUE;
}

Просмотреть файл

@ -2573,11 +2573,9 @@ nsXULDocument::PrepareToWalk()
rv = CreateElementFromPrototype(proto, getter_AddRefs(root));
if (NS_FAILED(rv)) return rv;
rv = root->BindToTree(this, nsnull, nsnull, PR_TRUE);
rv = SetRootContent(root);
if (NS_FAILED(rv)) return rv;
SetRootContent(root);
// Add the root element to the XUL document's ID-to-element map.
rv = AddElementToMap(root);
if (NS_FAILED(rv)) return rv;

Просмотреть файл

@ -249,14 +249,13 @@ void txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument,
return;
}
rv = rootContent->BindToTree(doc, nsnull, nsnull, PR_TRUE);
// XXXbz what to do on failure here?
rv = doc->SetRootContent(rootContent);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to bind root to tree");
rootContent->UnbindFromTree();
NS_ERROR("Failed to set root content");
return;
}
doc->SetRootContent(rootContent);
mDocument->CreateElementNS(XHTML_NSURI,
NS_LITERAL_STRING("head"),

Просмотреть файл

@ -301,7 +301,7 @@ void txMozillaXMLOutput::endElement(const nsAString& aName, const PRInt32 aNsID)
nsCOMPtr<nsIDocument> document = do_QueryInterface(mNonAddedParent);
if (document && !mRootContent) {
mRootContent = do_QueryInterface(mCurrentNode);
mRootContent->BindToTree(document, nsnull, nsnull, PR_TRUE);
// XXXbz what to do on failure here?
document->SetRootContent(mRootContent);
}
else {
@ -493,7 +493,7 @@ void txMozillaXMLOutput::closePrevious(PRInt8 aAction)
mParentNode = wrapper;
mRootContent = do_QueryInterface(wrapper);
mRootContent->BindToTree(document, nsnull, nsnull, PR_TRUE);
// XXXbz what to do on failure here?
document->SetRootContent(mRootContent);
}
@ -504,7 +504,7 @@ void txMozillaXMLOutput::closePrevious(PRInt8 aAction)
else {
if (document && currentElement && !mRootContent) {
mRootContent = do_QueryInterface(mCurrentNode);
mRootContent->BindToTree(document, nsnull, nsnull, PR_TRUE);
// XXXbz what to do on failure here?
document->SetRootContent(mRootContent);
}
else {

Просмотреть файл

@ -712,8 +712,10 @@ txMozillaXSLTProcessor::notifyError()
return;
}
rootContent->BindToTree(document, nsnull, nsnull, PR_TRUE);
document->SetRootContent(rootContent);
rv = document->SetRootContent(rootContent);
if (NS_FAILED(rv)) {
return;
}
nsCOMPtr<nsIDOMText> text;
rv = errorDocument->CreateTextNode(mErrorText, getter_AddRefs(text));

Просмотреть файл

@ -362,19 +362,15 @@ nsContentDLF::CreateBlankDocument(nsILoadGroup *aLoadGroup, nsIDocument **aDocum
// blat in the structure
if (htmlElement && headElement && bodyElement) {
rv = htmlElement->BindToTree(blankDoc, nsnull, nsnull, PR_TRUE);
if (NS_FAILED(rv)) {
htmlElement->UnbindFromTree();
} else {
blankDoc->SetRootContent(htmlElement);
rv = blankDoc->SetRootContent(htmlElement);
if (NS_SUCCEEDED(rv)) {
rv = htmlElement->AppendChildTo(headElement, PR_FALSE, PR_FALSE);
htmlElement->AppendChildTo(headElement, PR_FALSE, PR_FALSE);
bodyElement->SetContentID(blankDoc->GetAndIncrementContentID());
// XXXbz Why not notifying here?
htmlElement->AppendChildTo(bodyElement, PR_FALSE, PR_FALSE);
rv = NS_OK;
if (NS_SUCCEEDED(rv)) {
bodyElement->SetContentID(blankDoc->GetAndIncrementContentID());
// XXXbz Why not notifying here?
htmlElement->AppendChildTo(bodyElement, PR_FALSE, PR_FALSE);
}
}
}
}