Checking in Alex Fritze's (alex.fritze@crocodile-clips.com) changes to make xmldoc.createElementNS() create the correct type of element. r=hidday@geocities.com, sr=me (and slight modifications done by me).

This commit is contained in:
jst%netscape.com 2001-11-17 05:32:30 +00:00
Родитель 11d79ce6ef
Коммит d154fa1201
5 изменённых файлов: 42 добавлений и 43 удалений

Просмотреть файл

@ -84,7 +84,7 @@ public:
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_LAYOUT, 7)
extern nsresult
NS_NewXMLElement(nsIXMLContent** aResult, nsINodeInfo* aNodeInfo);
NS_NewXMLElement(nsIContent** aResult, nsINodeInfo* aNodeInfo);
// XXX These belongs elsewhere
extern nsresult

Просмотреть файл

@ -68,10 +68,8 @@
nsresult
NS_NewXMLElement(nsIXMLContent** aInstancePtrResult, nsINodeInfo *aNodeInfo)
NS_NewXMLElement(nsIContent** aInstancePtrResult, nsINodeInfo *aNodeInfo)
{
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
nsXMLElement* it = new nsXMLElement();
if (!it) {

Просмотреть файл

@ -808,7 +808,8 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode)
}
nsresult
nsXMLContentSink::CreateElement(const nsIParserNode& aNode, PRInt32 aNameSpaceID,
nsXMLContentSink::CreateElement(const nsIParserNode& aNode,
PRInt32 aNameSpaceID,
nsINodeInfo* aNodeInfo, nsIContent** aResult)
{
// The first step here is to see if someone has provided their
@ -820,9 +821,7 @@ nsXMLContentSink::CreateElement(const nsIParserNode& aNode, PRInt32 aNameSpaceID
// Create the content element using the element factory.
elementFactory->CreateInstanceByTag(aNodeInfo, aResult);
else {
nsCOMPtr<nsIXMLContent> xmlContent;
NS_NewXMLElement(getter_AddRefs(xmlContent), aNodeInfo);
return CallQueryInterface(xmlContent, aResult);
NS_NewXMLElement(aResult, aNodeInfo);
}
return NS_OK;
@ -1913,12 +1912,7 @@ NS_IMETHODIMP
XMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo *aNodeInfo,
nsIContent** aResult)
{
nsCOMPtr<nsIXMLContent> xmlContent;
nsresult rv = NS_NewXMLElement(getter_AddRefs(xmlContent), aNodeInfo);
nsCOMPtr<nsIContent> result = do_QueryInterface(xmlContent);
*aResult = result;
NS_IF_ADDREF(*aResult);
return rv;
return NS_NewXMLElement(aResult, aNodeInfo);
}
void

Просмотреть файл

@ -98,8 +98,10 @@
#include "nsMimeTypes.h"
#include "nsContentUtils.h"
#include "nsIElementFactory.h"
static NS_DEFINE_CID(kHTMLStyleSheetCID,NS_HTMLSTYLESHEET_CID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
// XXX The XML world depends on the html atoms
#include "nsHTMLAtoms.h"
@ -762,7 +764,6 @@ nsXMLDocument::CreateElement(const nsAReadableString& aTagName,
*aReturn = nsnull;
NS_ENSURE_TRUE(aTagName.Length(), NS_ERROR_DOM_INVALID_CHARACTER_ERR);
nsIXMLContent* content;
nsCOMPtr<nsINodeInfo> nodeInfo;
nsresult rv;
@ -770,13 +771,7 @@ nsXMLDocument::CreateElement(const nsAReadableString& aTagName,
*getter_AddRefs(nodeInfo));
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewXMLElement(&content, nodeInfo);
NS_ENSURE_SUCCESS(rv, rv);
rv = content->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aReturn);
NS_RELEASE(content);
return rv;
return CreateElement(nodeInfo, aReturn);
}
NS_IMETHODIMP
@ -893,27 +888,7 @@ nsXMLDocument::CreateElementNS(const nsAReadableString& aNamespaceURI,
*getter_AddRefs(nodeInfo));
NS_ENSURE_SUCCESS(rv, rv);
PRInt32 namespaceID;
nodeInfo->GetNamespaceID(namespaceID);
nsCOMPtr<nsIContent> content;
if (namespaceID == kNameSpaceID_HTML) {
nsCOMPtr<nsIHTMLContent> htmlContent;
rv = NS_CreateHTMLElement(getter_AddRefs(htmlContent), nodeInfo, PR_TRUE);
content = do_QueryInterface(htmlContent);
}
else {
nsCOMPtr<nsIXMLContent> xmlContent;
rv = NS_NewXMLElement(getter_AddRefs(xmlContent), nodeInfo);
content = do_QueryInterface(xmlContent);
}
NS_ENSURE_SUCCESS(rv, rv);
content->SetContentID(mNextContentID++);
return content->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aReturn);
return CreateElement(nodeInfo, aReturn);
}
static nsIContent *
@ -1040,3 +1015,33 @@ nsXMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
return result;
}
nsresult
nsXMLDocument::CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult)
{
*aResult = nsnull;
nsresult rv;
nsCOMPtr<nsIContent> content;
PRInt32 namespaceID;
aNodeInfo->GetNamespaceID(namespaceID);
nsCOMPtr<nsIElementFactory> elementFactory;
mNameSpaceManager->GetElementFactory(namespaceID,
getter_AddRefs(elementFactory));
if (elementFactory) {
rv = elementFactory->CreateInstanceByTag(aNodeInfo,
getter_AddRefs(content));
} else {
rv = NS_NewXMLElement(getter_AddRefs(content), aNodeInfo);
}
NS_ENSURE_SUCCESS(rv, rv);
content->SetContentID(mNextContentID++);
return CallQueryInterface(content, aResult);
}

Просмотреть файл

@ -125,6 +125,8 @@ protected:
virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet); // subclass hook for sheet ordering
virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex);
nsresult CreateElement(nsINodeInfo *aNodeInfo, nsIDOMElement** aResult);
// For HTML elements in our content model
// XXX This is not clean, but is there a better way?
nsIHTMLStyleSheet* mAttrStyleSheet;