[XForms] External instance not restored (on xforms-reset) after replace=instance. Bug 338933, r=doronr+smaug

This commit is contained in:
allan%beaufour.dk 2006-05-23 15:22:09 +00:00
parent 267150f0fb
commit 93c91e9f56

View File

@ -351,41 +351,26 @@ nsXFormsInstanceElement::BackupOriginalDocument()
NS_IMETHODIMP
nsXFormsInstanceElement::RestoreOriginalDocument()
{
nsresult rv = NS_OK;
// This is called when xforms-reset is received by the model. We assume
// that the backup of the instance document has been populated and is
// loaded into mOriginalDocument. Get the backup's root node, clone it, and
// insert it into the live copy of the instance document. This is the magic
// behind getting xforms-reset to work.
if(mDocument && mOriginalDocument) {
nsCOMPtr<nsIDOMNode> newNode, instanceRootNode, nodeReturn;
nsCOMPtr<nsIDOMElement> instanceRoot;
// first remove all the old stuff
rv = mDocument->GetDocumentElement(getter_AddRefs(instanceRoot));
if(NS_SUCCEEDED(rv)) {
if(instanceRoot) {
rv = mDocument->RemoveChild(instanceRoot, getter_AddRefs(nodeReturn));
NS_ENSURE_SUCCESS(rv, rv);
}
}
// now all of the garbage is out o' there! Put the original data back
// into mDocument
rv = mOriginalDocument->GetDocumentElement(getter_AddRefs(instanceRoot));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(instanceRoot, NS_ERROR_FAILURE);
instanceRootNode = do_QueryInterface(instanceRoot);
rv = instanceRootNode->CloneNode(PR_TRUE, getter_AddRefs(newNode));
if(NS_SUCCEEDED(rv)) {
rv = mDocument->AppendChild(newNode, getter_AddRefs(nodeReturn));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"failed to restore original instance document");
}
// loaded into mOriginalDocument.
if (!mOriginalDocument) {
return NS_ERROR_FAILURE;
}
return rv;
nsCOMPtr<nsIDOMNode> newDocNode;
nsresult rv = mOriginalDocument->CloneNode(PR_TRUE,
getter_AddRefs(newDocNode));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMDocument> newDoc(do_QueryInterface(newDocNode));
NS_ENSURE_STATE(newDoc);
rv = SetInstanceDocument(newDoc);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
NS_IMETHODIMP