From c5865cbcc918feda59a8fbf8d5f16b07c4ddd054 Mon Sep 17 00:00:00 2001 From: "sicking%bigfoot.com" Date: Wed, 2 Nov 2005 07:39:11 +0000 Subject: [PATCH] Bug 185498: Don't rely on ::CreateElement to create html elements. Also make sure we insert html-s when appropriate r=Pike sr=peterv --- content/xslt/src/xslt/txMozillaXMLOutput.cpp | 33 +++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/content/xslt/src/xslt/txMozillaXMLOutput.cpp b/content/xslt/src/xslt/txMozillaXMLOutput.cpp index 058611da7833..80d33b96e38b 100644 --- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp +++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp @@ -64,6 +64,7 @@ #include "nsINameSpaceManager.h" #include "nsICSSStyleSheet.h" #include "txStringUtils.h" +#include "nsIHTMLDocument.h" extern nsINameSpaceManager* gTxNameSpaceManager; @@ -354,8 +355,17 @@ void txMozillaXMLOutput::startElement(const nsAString& aName, mDontAddCurrent = PR_FALSE; if ((mOutputFormat.mMethod == eHTMLOutput) && (aNsID == kNameSpaceID_None)) { - rv = mDocument->CreateElement(aName, - getter_AddRefs(element)); + if (mDocumentIsHTML) { + rv = mDocument->CreateElement(aName, + getter_AddRefs(element)); + } + else { + nsAutoString lcname; + ToLowerCase(aName, lcname); + rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI), + lcname, + getter_AddRefs(element)); + } if (NS_FAILED(rv)) { return; } @@ -539,9 +549,15 @@ void txMozillaXMLOutput::endHTMLElement(nsIDOMElement* aElement, // If no section, wrap table's children in a tbody. nsCOMPtr wrapper; - rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI), - NS_LITERAL_STRING("tbody"), - getter_AddRefs(wrapper)); + if (mDocumentIsHTML) { + rv = mDocument->CreateElement(NS_LITERAL_STRING("tbody"), + getter_AddRefs(wrapper)); + } + else { + rv = mDocument->CreateElementNS(NS_LITERAL_STRING(kXHTMLNameSpaceURI), + NS_LITERAL_STRING("tbody"), + getter_AddRefs(wrapper)); + } NS_ASSERTION(NS_SUCCEEDED(rv), "Can't create tbody element"); if (wrapper) { @@ -671,18 +687,25 @@ txMozillaXMLOutput::createResultDocument(const nsAString& aName, PRInt32 aNsID, if (mOutputFormat.mMethod == eHTMLOutput) { doc = do_CreateInstance(kHTMLDocumentCID, &rv); NS_ENSURE_SUCCESS(rv, rv); + + mDocumentIsHTML = PR_TRUE; } else { // We should check the root name/namespace here and create the // appropriate document doc = do_CreateInstance(kXMLDocumentCID, &rv); NS_ENSURE_SUCCESS(rv, rv); + + mDocumentIsHTML = PR_FALSE; } mDocument = do_QueryInterface(doc); } else { mDocument = aResultDocument; doc = do_QueryInterface(aResultDocument); + + nsCOMPtr htmlDoc = do_QueryInterface(aResultDocument); + mDocumentIsHTML = !!htmlDoc; } mCurrentNode = mDocument;