From d3bad03d4fc5b791b71098a8da8afcc4a52f5866 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Sat, 20 Sep 2008 21:55:04 +0300 Subject: [PATCH] Bug 450160 - DOMImplementation createDocument does not create an HTML document, r+sr=bz --- content/base/test/Makefile.in | 1 + content/base/test/test_bug450160.html | 150 ++++++++++++++++++++ content/html/document/src/nsHTMLDocument.h | 2 +- content/html/document/src/nsIHTMLDocument.h | 8 +- content/xml/document/src/nsXMLDocument.cpp | 50 ++++++- 5 files changed, 200 insertions(+), 11 deletions(-) create mode 100644 content/base/test/test_bug450160.html diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index 5e73f27c69ff..614b9c9804bb 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -210,6 +210,7 @@ _TEST_FILES = test_bug5141.html \ file_bug391728.html \ file_bug391728_2.html \ test_bug368972.html \ + test_bug450160.html \ test_bug454326.html \ $(NULL) diff --git a/content/base/test/test_bug450160.html b/content/base/test/test_bug450160.html new file mode 100644 index 000000000000..39be810485f8 --- /dev/null +++ b/content/base/test/test_bug450160.html @@ -0,0 +1,150 @@ + + + + + Test for Bug 450160 + + + + + +Mozilla Bug 450160 +

+ +
+
+
+ + diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 53f657c90db3..20a4c4518397 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -177,7 +177,7 @@ public: virtual void RemovedForm(); virtual PRInt32 GetNumFormsSynchronous(); virtual void TearingDownEditor(nsIEditor *aEditor); - + virtual void SetIsXHTML(PRBool aXHTML) { mIsRegularHTML = !aXHTML; } PRBool IsXHTML() { return !mIsRegularHTML; diff --git a/content/html/document/src/nsIHTMLDocument.h b/content/html/document/src/nsIHTMLDocument.h index 583a44b33f31..85417de97fde 100644 --- a/content/html/document/src/nsIHTMLDocument.h +++ b/content/html/document/src/nsIHTMLDocument.h @@ -55,10 +55,10 @@ class nsIDOMHTMLBodyElement; class nsIScriptElement; class nsIEditor; -// 19d63a6c-cc94-499c-892a-955add772e10 +// 5a959364-a2f4-4cac-9a2c-957055dc3569 #define NS_IHTMLDOCUMENT_IID \ -{ 0x19d63a6c, 0xcc94, 0x499c, \ - { 0x89, 0x2a, 0x95, 0x5a, 0xdd, 0x77, 0x2e, 0x10 } } +{ 0x5a959364, 0xa2f4, 0x4cac, \ + { 0x9a, 0x2c, 0x95, 0x70, 0x55, 0xdc, 0x35, 0x69 } } /** @@ -190,6 +190,8 @@ public: * Called when this nsIHTMLDocument's editor is destroyed. */ virtual void TearingDownEditor(nsIEditor *aEditor) = 0; + + virtual void SetIsXHTML(PRBool aXHTML) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLDocument, NS_IHTMLDOCUMENT_IID) diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 5f5ce0d7c2f0..a536fe233044 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -92,7 +92,7 @@ #include "nsNodeUtils.h" #include "nsIConsoleService.h" #include "nsIScriptError.h" - +#include "nsIHTMLDocument.h" // ================================================================== // = @@ -117,23 +117,59 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult, *aInstancePtrResult = nsnull; - nsRefPtr doc = new nsXMLDocument(); - if (!doc) - return NS_ERROR_OUT_OF_MEMORY; - - rv = doc->Init(); + nsCOMPtr d; + PRBool isHTML = PR_FALSE; + PRBool isXHTML = PR_FALSE; + if (aDoctype) { + nsAutoString publicId; + aDoctype->GetPublicId(publicId); + if (publicId.EqualsLiteral("-//W3C//DTD HTML 4.01//EN") || + publicId.EqualsLiteral("-//W3C//DTD HTML 4.01 Frameset//EN") || + publicId.EqualsLiteral("-//W3C//DTD HTML 4.01 Transitional//EN") || + publicId.EqualsLiteral("-//W3C//DTD HTML 4.0//EN") || + publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Frameset//EN") || + publicId.EqualsLiteral("-//W3C//DTD HTML 4.0 Transitional//EN")) { + rv = NS_NewHTMLDocument(getter_AddRefs(d)); + isHTML = PR_TRUE; + } else if (publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Strict//EN") || + publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Transitional//EN") || + publicId.EqualsLiteral("-//W3C//DTD XHTML 1.0 Frameset//EN")) { + rv = NS_NewHTMLDocument(getter_AddRefs(d)); + isHTML = PR_TRUE; + isXHTML = PR_TRUE; + } +#ifdef MOZ_SVG + else if (publicId.EqualsLiteral("-//W3C//DTD SVG 1.1//EN")) { + rv = NS_NewSVGDocument(getter_AddRefs(d)); + } +#endif + // XXX Add support for XUL documents. + else { + rv = NS_NewXMLDocument(getter_AddRefs(d)); + } + } else { + rv = NS_NewXMLDocument(getter_AddRefs(d)); + } if (NS_FAILED(rv)) { return rv; } + if (isHTML) { + nsCOMPtr htmlDoc = do_QueryInterface(d); + NS_ASSERTION(htmlDoc, "HTML Document doesn't implement nsIHTMLDocument?"); + htmlDoc->SetCompatibilityMode(eCompatibility_FullStandards); + htmlDoc->SetIsXHTML(isXHTML); + } + nsDocument* doc = static_cast(d.get()); doc->SetLoadedAsData(aLoadedAsData); doc->nsDocument::SetDocumentURI(aDocumentURI); // Must set the principal first, since SetBaseURI checks it. doc->SetPrincipal(aPrincipal); doc->SetBaseURI(aBaseURI); - // XMLDocuments get to be UTF-8 by default, unlike the legacy HTML mess + // XMLDocuments and documents "created in memory" get to be UTF-8 by default, + // unlike the legacy HTML mess doc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8")); if (aDoctype) {