From cec22bc0a9ca9bbcff38c3eed49ff45c4a538687 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Tue, 25 May 1999 00:29:55 +0000 Subject: [PATCH] Better fix for 6746. --- content/xul/document/src/nsXULDocument.cpp | 6 +-- rdf/content/src/nsRDFXULBuilder.cpp | 51 ++++++++++++++-------- rdf/content/src/nsXULDocument.cpp | 6 +-- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 668fe337192b..7eff605ea471 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -62,6 +62,7 @@ #include "nsIParser.h" #include "nsIPresContext.h" #include "nsIPresShell.h" +#include "nsIHTMLContent.h" #include "nsIRDFCompositeDataSource.h" #include "nsIRDFContainerUtils.h" #include "nsIRDFContentModelBuilder.h" @@ -2675,11 +2676,6 @@ XULDocumentImpl::SetForm(nsIDOMHTMLFormElement* aForm) if (aForm) { NS_ADDREF(aForm); mHiddenForm = aForm; - nsCOMPtr content = do_QueryInterface(aForm); - if (content) { - // Add this node as a child - mRootContent->AppendChildTo(content, PR_TRUE); - } } return NS_OK; } diff --git a/rdf/content/src/nsRDFXULBuilder.cpp b/rdf/content/src/nsRDFXULBuilder.cpp index f4b53009071a..36ccf38fdd6d 100644 --- a/rdf/content/src/nsRDFXULBuilder.cpp +++ b/rdf/content/src/nsRDFXULBuilder.cpp @@ -636,6 +636,39 @@ RDFXULBuilderImpl::CreateContents(nsIContent* aElement) if (NS_FAILED(rv)) return rv; } + // If we're the root content, then prepend a special hidden form + // element. + if (aElement == mRoot) { + // Always insert a hidden form as the very first child of the window. + // Create a new form element. + nsAutoString tag("form"); + nsCOMPtr newElement; + if (!mHTMLElementFactory) { + rv = nsComponentManager::CreateInstance(kHTMLElementFactoryCID, + nsnull, + kIHTMLElementFactoryIID, + (void**) &mHTMLElementFactory); + if (NS_FAILED(rv)) { + return rv; + } + } + rv = mHTMLElementFactory->CreateInstanceByTag(tag, + getter_AddRefs(newElement)); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create HTML element"); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr htmlFormElement = do_QueryInterface(newElement); + if (htmlFormElement) { + mDocument->SetForm(htmlFormElement); + + nsCOMPtr content = do_QueryInterface(htmlFormElement); + if (content) { + // Add this node as a child + mRoot->InsertChildAt(content, 0, PR_FALSE); + } + } + } + // Now that we've built the children, check to see if the includesrc attribute // exists on the node. nsString includeSrc; @@ -1696,23 +1729,7 @@ RDFXULBuilderImpl::CreateHTMLElement(nsINameSpace* aContainingNameSpace, // Retrieve the hidden form from the XUL document. nsCOMPtr htmlFormElement; mDocument->GetForm(getter_AddRefs(htmlFormElement)); - if (!htmlFormElement) { - // Create a new form element. - nsAutoString tag("form"); - nsCOMPtr newElement; - rv = mHTMLElementFactory->CreateInstanceByTag(tag, - getter_AddRefs(newElement)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create HTML element"); - if (NS_FAILED(rv)) return rv; - - htmlFormElement = do_QueryInterface(newElement); - if (!htmlFormElement) { - NS_ERROR("Uh-oh! Couldn't make a form!"); - return NS_ERROR_FAILURE; - } - mDocument->SetForm(htmlFormElement); - } - + // Set the form htmlFormControl->SetForm(htmlFormElement); } diff --git a/rdf/content/src/nsXULDocument.cpp b/rdf/content/src/nsXULDocument.cpp index 668fe337192b..7eff605ea471 100644 --- a/rdf/content/src/nsXULDocument.cpp +++ b/rdf/content/src/nsXULDocument.cpp @@ -62,6 +62,7 @@ #include "nsIParser.h" #include "nsIPresContext.h" #include "nsIPresShell.h" +#include "nsIHTMLContent.h" #include "nsIRDFCompositeDataSource.h" #include "nsIRDFContainerUtils.h" #include "nsIRDFContentModelBuilder.h" @@ -2675,11 +2676,6 @@ XULDocumentImpl::SetForm(nsIDOMHTMLFormElement* aForm) if (aForm) { NS_ADDREF(aForm); mHiddenForm = aForm; - nsCOMPtr content = do_QueryInterface(aForm); - if (content) { - // Add this node as a child - mRootContent->AppendChildTo(content, PR_TRUE); - } } return NS_OK; }