diff --git a/mozilla/content/xml/document/public/MANIFEST b/mozilla/content/xml/document/public/MANIFEST index 4f2b66178c3..1cc23cf4908 100644 --- a/mozilla/content/xml/document/public/MANIFEST +++ b/mozilla/content/xml/document/public/MANIFEST @@ -1,2 +1,3 @@ nsIXMLContentSink.h nsIXMLDocument.h +nsIXMLElementFactory.h diff --git a/mozilla/content/xml/document/public/Makefile.in b/mozilla/content/xml/document/public/Makefile.in index 7468395399b..25f73cd463b 100644 --- a/mozilla/content/xml/document/public/Makefile.in +++ b/mozilla/content/xml/document/public/Makefile.in @@ -27,6 +27,7 @@ MODULE = layout EXPORTS = \ nsIXMLContentSink.h \ nsIXMLDocument.h \ + nsIXMLElementFactory.h \ $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/content/xml/document/public/makefile.win b/mozilla/content/xml/document/public/makefile.win index baaa0b47ec5..b5df1e1f8be 100644 --- a/mozilla/content/xml/document/public/makefile.win +++ b/mozilla/content/xml/document/public/makefile.win @@ -20,6 +20,7 @@ DEPTH=..\..\..\.. EXPORTS = \ nsIXMLContentSink.h \ nsIXMLDocument.h \ + nsIXMLElementFactory.h \ $(NULL) MODULE=raptor diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index da252a8cf46..ff712a17d9c 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -18,6 +18,7 @@ */ #include "nsCOMPtr.h" #include "nsXMLContentSink.h" +#include "nsIXMLElementFactory.h" #include "nsIParser.h" #include "nsIUnicharInputStream.h" #include "nsIUnicharStreamLoader.h" @@ -1881,3 +1882,71 @@ nsXMLContentSink::RefreshIfEnabled(nsIViewManager* vm) } return NS_OK; } + + +//////////////////////////////////////////////////////////////////////// +// +// XML Element Factory +// + +class XMLElementFactoryImpl : public nsIXMLElementFactory +{ +protected: + XMLElementFactoryImpl(); + virtual ~XMLElementFactoryImpl(); + +public: + friend + nsresult + NS_NewXMLElementFactory(nsIXMLElementFactory** aResult); + + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsIXMLElementFactory interface + NS_IMETHOD CreateInstanceByTag(const nsString& aTag, nsIXMLContent** aResult); + +}; + + +XMLElementFactoryImpl::XMLElementFactoryImpl() +{ + NS_INIT_REFCNT(); +} + +XMLElementFactoryImpl::~XMLElementFactoryImpl() +{ +} + + +NS_IMPL_ISUPPORTS(XMLElementFactoryImpl, NS_GET_IID(nsIXMLElementFactory)); + + +nsresult +NS_NewXMLElementFactory(nsIXMLElementFactory** aResult) +{ + NS_PRECONDITION(aResult != nsnull, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + XMLElementFactoryImpl* result = new XMLElementFactoryImpl(); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aResult = result; + return NS_OK; +} + + + +NS_IMETHODIMP +XMLElementFactoryImpl::CreateInstanceByTag(const nsString& aTag, nsIXMLContent** aResult) +{ + nsCOMPtr tag = dont_AddRef(NS_NewAtom(aTag)); + if (! tag) + return NS_ERROR_OUT_OF_MEMORY; + + return NS_NewXMLElement(aResult, tag); +} + diff --git a/mozilla/layout/build/nsLayoutCID.h b/mozilla/layout/build/nsLayoutCID.h index 41a4bb05e75..63a42f120a1 100644 --- a/mozilla/layout/build/nsLayoutCID.h +++ b/mozilla/layout/build/nsLayoutCID.h @@ -45,6 +45,11 @@ 0xa6cf9063, 0x15b3, 0x11d2, \ {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} +#define NS_XML_ELEMENT_FACTORY_CID \ +{ /* CF170391-79CC-11d3-BE44-0020A6361667 */ \ + 0xcf170391, 0x79cc, 0x11d3, \ + {0xbe, 0x44, 0x0, 0x20, 0xa6, 0x36, 0x16, 0x67}} + #define NS_IMAGEDOCUMENT_CID \ { /* e11a6080-4daa-11d2-b328-00805f8a3859 */ \ 0xe11a6080, 0x4daa, 0x11d2, \ diff --git a/mozilla/layout/build/nsLayoutFactory.cpp b/mozilla/layout/build/nsLayoutFactory.cpp index 23f88f4a897..85a468b947d 100644 --- a/mozilla/layout/build/nsLayoutFactory.cpp +++ b/mozilla/layout/build/nsLayoutFactory.cpp @@ -45,6 +45,7 @@ #include "nsIEventListenerManager.h" #include "nsILayoutDebugger.h" #include "nsIHTMLElementFactory.h" +#include "nsIXMLElementFactory.h" #include "nsIDocumentEncoder.h" #include "nsCOMPtr.h" #include "nsIFrameSelection.h" @@ -55,6 +56,7 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID); static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID); +static NS_DEFINE_CID(kXMLElementFactoryCID, NS_XML_ELEMENT_FACTORY_CID); static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID); static NS_DEFINE_IID(kCSSParserCID, NS_CSSPARSER_CID); static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID); @@ -364,6 +366,14 @@ nsLayoutFactory::CreateInstance(nsISupports *aOuter, } refCounted = PR_TRUE; } + else if (mClassID.Equals(kXMLElementFactoryCID)) { + res = NS_NewXMLElementFactory((nsIXMLElementFactory**) &inst); + if (NS_FAILED(res)) { + LOG_NEW_FAILURE("NS_NewXMLElementFactory", res); + return res; + } + refCounted = PR_TRUE; + } else if (mClassID.Equals(kTextEncoderCID)) { res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst); if (NS_FAILED(res)) { diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index 1e8c761ff89..31b7320d57e 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -313,6 +313,8 @@ static Components gComponents[] = { { "HTML element factory", NS_HTML_ELEMENT_FACTORY_CID, nsnull, }, { "Text element", NS_TEXTNODE_CID, nsnull, }, + { "XML element factory", NS_XML_ELEMENT_FACTORY_CID, nsnull, }, + { "Selection", NS_SELECTION_CID, nsnull, }, { "Frame selection", NS_FRAMESELECTION_CID, nsnull, }, { "Range", NS_RANGE_CID, nsnull, }, diff --git a/mozilla/layout/xml/document/public/MANIFEST b/mozilla/layout/xml/document/public/MANIFEST index 4f2b66178c3..1cc23cf4908 100644 --- a/mozilla/layout/xml/document/public/MANIFEST +++ b/mozilla/layout/xml/document/public/MANIFEST @@ -1,2 +1,3 @@ nsIXMLContentSink.h nsIXMLDocument.h +nsIXMLElementFactory.h diff --git a/mozilla/layout/xml/document/public/Makefile.in b/mozilla/layout/xml/document/public/Makefile.in index 7468395399b..25f73cd463b 100644 --- a/mozilla/layout/xml/document/public/Makefile.in +++ b/mozilla/layout/xml/document/public/Makefile.in @@ -27,6 +27,7 @@ MODULE = layout EXPORTS = \ nsIXMLContentSink.h \ nsIXMLDocument.h \ + nsIXMLElementFactory.h \ $(NULL) EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) diff --git a/mozilla/layout/xml/document/public/makefile.win b/mozilla/layout/xml/document/public/makefile.win index baaa0b47ec5..b5df1e1f8be 100644 --- a/mozilla/layout/xml/document/public/makefile.win +++ b/mozilla/layout/xml/document/public/makefile.win @@ -20,6 +20,7 @@ DEPTH=..\..\..\.. EXPORTS = \ nsIXMLContentSink.h \ nsIXMLDocument.h \ + nsIXMLElementFactory.h \ $(NULL) MODULE=raptor diff --git a/mozilla/layout/xml/document/public/nsIXMLElementFactory.h b/mozilla/layout/xml/document/public/nsIXMLElementFactory.h new file mode 100644 index 00000000000..bc8a75c3ca4 --- /dev/null +++ b/mozilla/layout/xml/document/public/nsIXMLElementFactory.h @@ -0,0 +1,47 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ +#ifndef nsIXMLElementFactory_h___ +#define nsIXMLElementFactory_h___ + +#include "nslayout.h" +#include "nsISupports.h" + +class nsIXMLContent; +class nsString; + +// {CF170390-79CC-11d3-BE44-0020A6361667} +#define NS_IXML_ELEMENT_FACTORY_IID \ +{ 0xcf170390, 0x79cc, 0x11d3, { 0xbe, 0x44, 0x0, 0x20, 0xa6, 0x36, 0x16, 0x67 } }; + +/** + * An API for creating XML content objects + */ +class nsIXMLElementFactory : public nsISupports { +public: + static const nsIID& GetIID() { static nsIID iid = NS_IXML_ELEMENT_FACTORY_IID; return iid; } + + NS_IMETHOD CreateInstanceByTag(const nsString& aTag, + nsIXMLContent** aResult) = 0; +}; + + +extern nsresult +NS_NewXMLElementFactory(nsIXMLElementFactory** aResult); + +#endif /* nsIXMLElementFactory_h___ */ diff --git a/mozilla/layout/xml/document/src/nsXMLContentSink.cpp b/mozilla/layout/xml/document/src/nsXMLContentSink.cpp index da252a8cf46..ff712a17d9c 100644 --- a/mozilla/layout/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/layout/xml/document/src/nsXMLContentSink.cpp @@ -18,6 +18,7 @@ */ #include "nsCOMPtr.h" #include "nsXMLContentSink.h" +#include "nsIXMLElementFactory.h" #include "nsIParser.h" #include "nsIUnicharInputStream.h" #include "nsIUnicharStreamLoader.h" @@ -1881,3 +1882,71 @@ nsXMLContentSink::RefreshIfEnabled(nsIViewManager* vm) } return NS_OK; } + + +//////////////////////////////////////////////////////////////////////// +// +// XML Element Factory +// + +class XMLElementFactoryImpl : public nsIXMLElementFactory +{ +protected: + XMLElementFactoryImpl(); + virtual ~XMLElementFactoryImpl(); + +public: + friend + nsresult + NS_NewXMLElementFactory(nsIXMLElementFactory** aResult); + + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsIXMLElementFactory interface + NS_IMETHOD CreateInstanceByTag(const nsString& aTag, nsIXMLContent** aResult); + +}; + + +XMLElementFactoryImpl::XMLElementFactoryImpl() +{ + NS_INIT_REFCNT(); +} + +XMLElementFactoryImpl::~XMLElementFactoryImpl() +{ +} + + +NS_IMPL_ISUPPORTS(XMLElementFactoryImpl, NS_GET_IID(nsIXMLElementFactory)); + + +nsresult +NS_NewXMLElementFactory(nsIXMLElementFactory** aResult) +{ + NS_PRECONDITION(aResult != nsnull, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + XMLElementFactoryImpl* result = new XMLElementFactoryImpl(); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aResult = result; + return NS_OK; +} + + + +NS_IMETHODIMP +XMLElementFactoryImpl::CreateInstanceByTag(const nsString& aTag, nsIXMLContent** aResult) +{ + nsCOMPtr tag = dont_AddRef(NS_NewAtom(aTag)); + if (! tag) + return NS_ERROR_OUT_OF_MEMORY; + + return NS_NewXMLElement(aResult, tag); +} +