diff --git a/mozilla/content/base/public/nsContentCID.h b/mozilla/content/base/public/nsContentCID.h index 739cc8a0418..ee6a67764ef 100644 --- a/mozilla/content/base/public/nsContentCID.h +++ b/mozilla/content/base/public/nsContentCID.h @@ -274,6 +274,12 @@ #define NS_RANGEUTILS_CID \ { 0xa6cf9126, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } +#ifdef MOZ_MATHML +// {68b9fbda-f230-45a9-bf92-dbbbd4ac8555} +#define NS_MATHMLELEMENTFACTORY_CID \ +{ 0x68b9fbda, 0xf230, 0x45a9, {0xbf, 0x92, 0xdb, 0xbb, 0xd4, 0xac, 0x85, 0x55 } } +#endif // MOZ_MATHML + #ifdef MOZ_SVG // {4E48C00A-E20F-4061-B869-2BAC285D68E8} diff --git a/mozilla/content/base/public/nsIElementFactory.h b/mozilla/content/base/public/nsIElementFactory.h index 74cd042c9a1..0382e4d562b 100644 --- a/mozilla/content/base/public/nsIElementFactory.h +++ b/mozilla/content/base/public/nsIElementFactory.h @@ -68,6 +68,11 @@ public: #define NS_HTML_ELEMENT_FACTORY_CONTRACTID NS_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_HTML_NAMESPACE #define NS_XML_ELEMENT_FACTORY_CONTRACTID NS_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_XML_NAMESPACE +#ifdef MOZ_MATHML +#define NS_MATHML_NAMESPACE "http://www.w3.org/1998/Math/MathML" +#define NS_MATHML_ELEMENT_FACTORY_CONTRACTID NS_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_MATHML_NAMESPACE +#endif + #ifdef MOZ_SVG #define NS_SVG_DEPRECATED_NAMESPACE "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.svg" #define NS_SVG_DEPRECATED_ELEMENT_FACTORY_CONTRACTID \ diff --git a/mozilla/content/base/public/nsINameSpaceManager.h b/mozilla/content/base/public/nsINameSpaceManager.h index 58993dff52e..f521846a041 100644 --- a/mozilla/content/base/public/nsINameSpaceManager.h +++ b/mozilla/content/base/public/nsINameSpaceManager.h @@ -56,6 +56,7 @@ class nsIElementFactory; #define kNameSpaceID_HTML2 5 // This is not a real namespace #define kNameSpaceID_XSLT 6 #define kNameSpaceID_XBL 7 +#define kNameSpaceID_MathML 8 #define kNameSpaceID_XHTML kNameSpaceID_HTML // 'html' is by definition bound to the namespace name "urn:w3-org-ns:HTML" XXX ??? diff --git a/mozilla/content/base/src/nsNameSpaceManager.cpp b/mozilla/content/base/src/nsNameSpaceManager.cpp index a5261b5b7af..ce7cde2b25c 100644 --- a/mozilla/content/base/src/nsNameSpaceManager.cpp +++ b/mozilla/content/base/src/nsNameSpaceManager.cpp @@ -59,6 +59,7 @@ static const char kXHTMLNameSpaceURI[] = "http://www.w3.org/1999/xhtml"; static const char kXLinkNameSpaceURI[] = "http://www.w3.org/1999/xlink"; static const char kXSLTNameSpaceURI[] = "http://www.w3.org/1999/XSL/Transform"; static const char kXBLNameSpaceURI[] = "http://www.mozilla.org/xbl"; +static const char kMathMLNameSpaceURI[] = "http://www.w3.org/1998/Math/MathML"; //----------------------------------------------------------- // Name Space ID table support @@ -91,6 +92,7 @@ static void InitializeNameSpaceManager() nsString* html = new nsString( NS_ConvertASCIItoUCS2(kHTMLNameSpaceURI) ); nsString* xslt = new nsString( NS_ConvertASCIItoUCS2(kXSLTNameSpaceURI) ); nsString* xbl = new nsString(NS_ConvertASCIItoUCS2(kXBLNameSpaceURI)); + nsString* mathml = new nsString(NS_ConvertASCIItoUCS2(kMathMLNameSpaceURI)); gURIArray->AppendElement(xmlns); // ordering here needs to match IDs gURIArray->AppendElement(xml); @@ -99,6 +101,7 @@ static void InitializeNameSpaceManager() gURIArray->AppendElement(html); gURIArray->AppendElement(xslt); gURIArray->AppendElement(xbl); + gURIArray->AppendElement(mathml); nsStringKey xmlnsKey(*xmlns); nsStringKey xmlKey(*xml); @@ -107,6 +110,7 @@ static void InitializeNameSpaceManager() nsStringKey htmlKey(*html); nsStringKey xsltKey(*xslt); nsStringKey xblKey(*xbl); + nsStringKey mathmlKey(*mathml); gURIToIDTable->Put(&xmlnsKey, (void*)kNameSpaceID_XMLNS); gURIToIDTable->Put(&xmlKey, (void*)kNameSpaceID_XML); @@ -115,6 +119,7 @@ static void InitializeNameSpaceManager() gURIToIDTable->Put(&htmlKey, (void*)kNameSpaceID_HTML); gURIToIDTable->Put(&xsltKey, (void*)kNameSpaceID_XSLT); gURIToIDTable->Put(&xblKey, (void*)kNameSpaceID_XBL); + gURIToIDTable->Put(&mathmlKey, (void*)kNameSpaceID_MathML); NS_NewISupportsArray(&gElementFactoryArray); diff --git a/mozilla/content/build/nsContentCID.h b/mozilla/content/build/nsContentCID.h index 739cc8a0418..ee6a67764ef 100644 --- a/mozilla/content/build/nsContentCID.h +++ b/mozilla/content/build/nsContentCID.h @@ -274,6 +274,12 @@ #define NS_RANGEUTILS_CID \ { 0xa6cf9126, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } +#ifdef MOZ_MATHML +// {68b9fbda-f230-45a9-bf92-dbbbd4ac8555} +#define NS_MATHMLELEMENTFACTORY_CID \ +{ 0x68b9fbda, 0xf230, 0x45a9, {0xbf, 0x92, 0xdb, 0xbb, 0xd4, 0xac, 0x85, 0x55 } } +#endif // MOZ_MATHML + #ifdef MOZ_SVG // {4E48C00A-E20F-4061-B869-2BAC285D68E8} diff --git a/mozilla/content/build/nsContentModule.cpp b/mozilla/content/build/nsContentModule.cpp index 730b123a1b8..84f8f367766 100644 --- a/mozilla/content/build/nsContentModule.cpp +++ b/mozilla/content/build/nsContentModule.cpp @@ -281,6 +281,10 @@ extern nsresult NS_NewXULElementFactory(nsIElementFactory** aResult); extern NS_IMETHODIMP NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult); #endif +#ifdef MOZ_MATHML +extern nsresult NS_NewMathMLElementFactory(nsIElementFactory** aResult); +#endif + #ifdef MOZ_SVG extern nsresult NS_NewSVGElementFactory(nsIElementFactory** aResult); #endif @@ -355,6 +359,9 @@ MAKE_CTOR(CreateXULPopupListener, nsIXULPopupListener, NS_NewXUL // NS_NewXULPrototypeCache MAKE_CTOR(CreateXULElementFactory, nsIElementFactory, NS_NewXULElementFactory) #endif +#ifdef MOZ_MATHML +MAKE_CTOR(CreateMathMLElementFactory, nsIElementFactory, NS_NewMathMLElementFactory) +#endif #ifdef MOZ_SVG MAKE_CTOR(CreateSVGElementFactory, nsIElementFactory, NS_NewSVGElementFactory) #endif @@ -790,6 +797,13 @@ static const nsModuleComponentInfo gComponents[] = { CreateXULElementFactory }, #endif +#ifdef MOZ_MATHML + { "MathML Element Factory", + NS_MATHMLELEMENTFACTORY_CID, + NS_MATHML_ELEMENT_FACTORY_CONTRACTID, + CreateMathMLElementFactory }, +#endif + #ifdef MOZ_SVG { "SVG element factory (deprecated namespace)", NS_SVGELEMENTFACTORY_CID, diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index c06571cc671..b5e9681400c 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -1430,16 +1430,14 @@ NS_IMPL_ISUPPORTS1(XMLElementFactoryImpl, nsIElementFactory) nsresult NS_NewXMLElementFactory(nsIElementFactory** aResult) { - NS_PRECONDITION(aResult != nsnull, "null ptr"); - if (! aResult) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aResult); XMLElementFactoryImpl* result = new XMLElementFactoryImpl(); - if (! result) - return NS_ERROR_OUT_OF_MEMORY; + NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); - NS_ADDREF(result); *aResult = result; + NS_ADDREF(*aResult); + return NS_OK; } @@ -1452,6 +1450,118 @@ XMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo *aNodeInfo, return NS_NewXMLElement(aResult, aNodeInfo); } + +#ifdef MOZ_MATHML +//////////////////////////////////////////////////////////////////////// +// MathML Element Factory - temporary location for bug 132844 +// Will be factored out post 1.0 + +class MathMLElementFactoryImpl : public nsIElementFactory +{ +protected: + MathMLElementFactoryImpl(); + virtual ~MathMLElementFactoryImpl(); + +public: + friend + nsresult + NS_NewMathMLElementFactory(nsIElementFactory** aResult); + + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsIElementFactory interface + NS_IMETHOD CreateInstanceByTag(nsINodeInfo *aNodeInfo, nsIContent** aResult); + +}; + +MathMLElementFactoryImpl::MathMLElementFactoryImpl() +{ + NS_INIT_REFCNT(); +} + +MathMLElementFactoryImpl::~MathMLElementFactoryImpl() +{ +} + +NS_IMPL_ISUPPORTS1(MathMLElementFactoryImpl, nsIElementFactory) + +nsresult +NS_NewMathMLElementFactory(nsIElementFactory** aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + + MathMLElementFactoryImpl* result = new MathMLElementFactoryImpl(); + NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); + + *aResult = result; + NS_ADDREF(*aResult); + + return NS_OK; +} + +NS_IMETHODIMP +MathMLElementFactoryImpl::CreateInstanceByTag(nsINodeInfo* aNodeInfo, + nsIContent** aResult) +{ + static const char kMathMLStyleSheetURI[] = "resource:///res/mathml.css"; + + // this bit of code is to load mathml.css on demand + nsCOMPtr doc; + aNodeInfo->GetDocument(*getter_AddRefs(doc)); + if (doc) { + PRBool alreadyLoaded = PR_FALSE; + PRInt32 i = 0, sheetCount = 0; + doc->GetNumberOfStyleSheets(&sheetCount); + for (; i < sheetCount; i++) { + nsCOMPtr sheet; + doc->GetStyleSheetAt(i, getter_AddRefs(sheet)); + NS_ASSERTION(sheet, "unexpected null stylesheet in the document"); + if (sheet) { + nsCOMPtr uri; + sheet->GetURL(*getter_AddRefs(uri)); + nsCAutoString uriStr; + uri->GetSpec(uriStr); + if (uriStr.Equals(kMathMLStyleSheetURI)) { + alreadyLoaded = PR_TRUE; + break; + } + } + } + if (!alreadyLoaded) { + nsCOMPtr htmlContainer(do_QueryInterface(doc)); + if (htmlContainer) { + nsCOMPtr cssLoader; + htmlContainer->GetCSSLoader(*getter_AddRefs(cssLoader)); + if (cssLoader) { + nsCOMPtr uri; + NS_NewURI(getter_AddRefs(uri), kMathMLStyleSheetURI); + if (uri) { + PRBool complete; + nsCOMPtr sheet; + cssLoader->LoadAgentSheet(uri, *getter_AddRefs(sheet), complete, nsnull); +#ifdef NS_DEBUG + nsCAutoString uriStr; + uri->GetSpec(uriStr); + printf("MathML Factory: loading catalog stylesheet: %s ... %s\n", uriStr.get(), sheet.get() ? "Done" : "Failed"); + NS_ASSERTION(uriStr.Equals(kMathMLStyleSheetURI), "resolved URI unexpected"); +#endif + if (sheet) { + doc->AddStyleSheet(sheet, NS_STYLESHEET_FROM_CATALOG); + } + } + } + } + } + } + + return NS_NewXMLElement(aResult, aNodeInfo); +} +#endif // MOZ_MATHML + + +//////////////////////////////////////////////////////////////////////// + void nsXMLContentSink::GetElementFactory(PRInt32 aNameSpaceID, nsIElementFactory** aResult) diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 6a04877a275..162f3264416 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -6607,7 +6607,7 @@ nsCSSFrameConstructor::ConstructMathMLFrame(nsIPresShell* aPresShell, nsFrameItems& aFrameItems) { // Make sure that we remain confined in the MathML world - if (aNameSpaceID != nsMathMLAtoms::nameSpaceID) + if (aNameSpaceID != kNameSpaceID_MathML) return NS_OK; PRBool processChildren = PR_TRUE; // Whether we should process child content. diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index 6a04877a275..162f3264416 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -6607,7 +6607,7 @@ nsCSSFrameConstructor::ConstructMathMLFrame(nsIPresShell* aPresShell, nsFrameItems& aFrameItems) { // Make sure that we remain confined in the MathML world - if (aNameSpaceID != nsMathMLAtoms::nameSpaceID) + if (aNameSpaceID != kNameSpaceID_MathML) return NS_OK; PRBool processChildren = PR_TRUE; // Whether we should process child content. diff --git a/mozilla/layout/mathml/base/src/nsMathMLFrame.cpp b/mozilla/layout/mathml/base/src/nsMathMLFrame.cpp index 8420423dd06..adef341bd2a 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLFrame.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLFrame.cpp @@ -557,7 +557,7 @@ GetMathMLAttributeStyleSheet(nsIPresContext* aPresContext, return; cssSheet->Init(uri); cssSheet->SetTitle(NS_ConvertASCIItoUCS2(kTitle)); - cssSheet->SetDefaultNameSpaceID(nsMathMLAtoms::nameSpaceID); + cssSheet->SetDefaultNameSpaceID(kNameSpaceID_MathML); nsCOMPtr sheet(do_QueryInterface(cssSheet)); // insert the stylesheet into the styleset without notifying observers diff --git a/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp b/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp index 0baaa3c205f..71933a7eae5 100644 --- a/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp +++ b/mozilla/layout/mathml/content/src/nsMathMLAtoms.cpp @@ -17,17 +17,9 @@ * * Contributor(s): * Roger B. Sidje - * (Following the model of the Gecko team) */ -#include "nsString.h" -#include "nsINameSpaceManager.h" #include "nsMathMLAtoms.h" -#include "nsLayoutCID.h" - -static const char kMathMLNameSpace[] = "http://www.w3.org/1998/Math/MathML"; - -PRInt32 nsMathMLAtoms::nameSpaceID; // define storage for all atoms #define MATHML_ATOM(_name, _value) nsIAtom* nsMathMLAtoms::_name; @@ -36,29 +28,10 @@ PRInt32 nsMathMLAtoms::nameSpaceID; static nsrefcnt gRefCnt = 0; -static nsINameSpaceManager* gNameSpaceManager; void nsMathMLAtoms::AddRefAtoms() { if (gRefCnt == 0) { - /* MathML Atoms registers the MathML name space ID because it's a convenient - place to do this, if you don't want a permanent, "well-known" ID. - */ - NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); - nsCOMPtr nsmgr = - do_CreateInstance(kNameSpaceManagerCID); - - if (nsmgr) { -// gNameSpaceManager->CreateRootNameSpace(namespace); - nsmgr->RegisterNameSpace(NS_ConvertASCIItoUCS2(kMathMLNameSpace), - nameSpaceID); - - gNameSpaceManager = nsmgr; - NS_ADDREF(gNameSpaceManager); - } else { - NS_ASSERTION(0, "failed to create MathML atoms namespace manager"); - } - - // now register the atoms + // create atoms #define MATHML_ATOM(_name, _value) _name = NS_NewPermanentAtom(_value); #include "nsMathMLAtomList.h" #undef MATHML_ATOM @@ -69,10 +42,9 @@ void nsMathMLAtoms::AddRefAtoms() { void nsMathMLAtoms::ReleaseAtoms() { NS_PRECONDITION(gRefCnt != 0, "bad release of MathML atoms"); if (--gRefCnt == 0) { + // release atoms #define MATHML_ATOM(_name, _value) NS_RELEASE(_name); #include "nsMathMLAtomList.h" #undef MATHML_ATOM - - NS_IF_RELEASE(gNameSpaceManager); } } diff --git a/mozilla/layout/mathml/content/src/nsMathMLAtoms.h b/mozilla/layout/mathml/content/src/nsMathMLAtoms.h index 029b324f253..6af167d297e 100644 --- a/mozilla/layout/mathml/content/src/nsMathMLAtoms.h +++ b/mozilla/layout/mathml/content/src/nsMathMLAtoms.h @@ -40,9 +40,6 @@ public: static void AddRefAtoms(); static void ReleaseAtoms(); - // MathML namespace ID, good for the life of the nsMathMLAtoms object - static PRInt32 nameSpaceID; - /* Declare all atoms The atom names and values are stored in nsMathMLAtomList.h and