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

git-svn-id: svn://10.0.0.236/trunk@198263 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
allan%beaufour.dk
2006-05-23 15:22:09 +00:00
parent f6cb4c91d6
commit e773c8420e

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