From 86f11fca6385c8ef0ff042bde4ebec94d482ac0d Mon Sep 17 00:00:00 2001 From: "doronr%us.ibm.com" Date: Fri, 18 Feb 2005 21:32:46 +0000 Subject: [PATCH] Bug 279057 - Implement hasFeature for XForms. Patch by smaug, r=bryner/sr=jst git-svn-id: svn://10.0.0.236/trunk@169429 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDOMAttribute.cpp | 8 +-- mozilla/content/base/src/nsDocument.cpp | 12 ++-- .../content/base/src/nsGenericDOMDataNode.cpp | 3 +- mozilla/content/base/src/nsGenericElement.cpp | 57 +++++++++++++++-- mozilla/content/base/src/nsGenericElement.h | 14 +++- mozilla/dom/public/idl/base/Makefile.in | 1 + .../idl/base/nsIDOMNSFeatureFactory.idl | 64 +++++++++++++++++++ .../xforms/nsXFormsElementFactory.cpp | 24 ++++++- .../xforms/nsXFormsElementFactory.h | 5 +- mozilla/extensions/xforms/nsXFormsModule.cpp | 10 +++ 10 files changed, 180 insertions(+), 18 deletions(-) create mode 100644 mozilla/dom/public/idl/base/nsIDOMNSFeatureFactory.idl diff --git a/mozilla/content/base/src/nsDOMAttribute.cpp b/mozilla/content/base/src/nsDOMAttribute.cpp index dcc205b658e..240d64e1bfb 100644 --- a/mozilla/content/base/src/nsDOMAttribute.cpp +++ b/mozilla/content/base/src/nsDOMAttribute.cpp @@ -425,7 +425,8 @@ nsDOMAttribute::IsSupported(const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn) { - return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); + return nsGenericElement::InternalIsSupported(NS_STATIC_CAST(nsIDOMAttr*, this), + aFeature, aVersion, aReturn); } NS_IMETHODIMP @@ -644,9 +645,8 @@ nsDOMAttribute::GetFeature(const nsAString& aFeature, const nsAString& aVersion, nsISupports** aReturn) { - NS_NOTYETIMPLEMENTED("nsDocument::GetFeature()"); - - return NS_ERROR_NOT_IMPLEMENTED; + return nsGenericElement::InternalGetFeature(NS_STATIC_CAST(nsIDOMAttr*, this), + aFeature, aVersion, aReturn); } NS_IMETHODIMP diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 50ef0669ca3..08c0eee76a4 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -332,7 +332,9 @@ nsDOMImplementation::HasFeature(const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn) { - return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); + return nsGenericElement::InternalIsSupported( + NS_STATIC_CAST(nsIDOMDOMImplementation*, this), + aFeature, aVersion, aReturn); } NS_IMETHODIMP @@ -3421,7 +3423,8 @@ NS_IMETHODIMP nsDocument::IsSupported(const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn) { - return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); + return nsGenericElement::InternalIsSupported(NS_STATIC_CAST(nsIDOMDocument*, this), + aFeature, aVersion, aReturn); } NS_IMETHODIMP @@ -3557,9 +3560,8 @@ nsDocument::GetFeature(const nsAString& aFeature, const nsAString& aVersion, nsISupports** aReturn) { - NS_NOTYETIMPLEMENTED("nsDocument::GetFeature()"); - - return NS_ERROR_NOT_IMPLEMENTED; + return nsGenericElement::InternalGetFeature(NS_STATIC_CAST(nsIDOMDocument*, this), + aFeature, aVersion, aReturn); } NS_IMETHODIMP diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index b54c80bccac..22097f5509e 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -254,7 +254,8 @@ nsGenericDOMDataNode::IsSupported(const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn) { - return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); + return nsGenericElement::InternalIsSupported(NS_STATIC_CAST(nsIContent*, this), + aFeature, aVersion, aReturn); } nsresult diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 04e0bbbc11b..e7f40d893e3 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -103,6 +103,8 @@ #include "nsIDOMXPathEvaluator.h" #include "nsNodeInfoManager.h" +#include "nsICategoryManager.h" +#include "nsIDOMNSFeatureFactory.h" #ifdef MOZ_SVG PRBool NS_SVG_TestFeature(const nsAString &fstr); @@ -386,9 +388,7 @@ nsNode3Tearoff::GetFeature(const nsAString& aFeature, const nsAString& aVersion, nsISupports** aReturn) { - NS_NOTYETIMPLEMENTED("nsNode3Tearoff::GetFeature()"); - - return NS_ERROR_NOT_IMPLEMENTED; + return nsGenericElement::InternalGetFeature(this, aFeature, aVersion, aReturn); } NS_IMETHODIMP @@ -1128,7 +1128,8 @@ extern PRBool gCheckedForXPathDOM; extern PRBool gHaveXPathDOM; nsresult -nsGenericElement::InternalIsSupported(const nsAString& aFeature, +nsGenericElement::InternalIsSupported(nsISupports* aObject, + const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn) { @@ -1192,15 +1193,61 @@ nsGenericElement::InternalIsSupported(const nsAString& aFeature, } #endif /* MOZ_SVG */ + else { + nsCOMPtr factory = + GetDOMFeatureFactory(aFeature, aVersion); + + if (factory) { + factory->HasFeature(aObject, aFeature, aVersion, aReturn); + } + } return NS_OK; } +nsresult +nsGenericElement::InternalGetFeature(nsISupports* aObject, + const nsAString& aFeature, + const nsAString& aVersion, + nsISupports** aReturn) +{ + *aReturn = nsnull; + nsCOMPtr factory = + GetDOMFeatureFactory(aFeature, aVersion); + + if (factory) { + factory->GetFeature(aObject, aFeature, aVersion, aReturn); + } + + return NS_OK; +} + +already_AddRefed +nsGenericElement::GetDOMFeatureFactory(const nsAString& aFeature, + const nsAString& aVersion) +{ + nsIDOMNSFeatureFactory *factory = nsnull; + nsCOMPtr categoryManager = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID); + if (categoryManager) { + nsCAutoString featureCategory(NS_DOMNS_FEATURE_PREFIX); + AppendUTF16toUTF8(aFeature, featureCategory); + nsXPIDLCString contractID; + nsresult rv = categoryManager->GetCategoryEntry(featureCategory.get(), + NS_ConvertUTF16toUTF8(aVersion).get(), + getter_Copies(contractID)); + if (NS_SUCCEEDED(rv)) { + CallGetService(contractID.get(), &factory); // addrefs + } + } + return factory; +} + NS_IMETHODIMP nsGenericElement::IsSupported(const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn) { - return InternalIsSupported(aFeature, aVersion, aReturn); + return InternalIsSupported(this, aFeature, aVersion, aReturn); } NS_IMETHODIMP diff --git a/mozilla/content/base/src/nsGenericElement.h b/mozilla/content/base/src/nsGenericElement.h index 51dca716dc9..42bcf3d8749 100644 --- a/mozilla/content/base/src/nsGenericElement.h +++ b/mozilla/content/base/src/nsGenericElement.h @@ -64,6 +64,7 @@ class nsIURI; class nsVoidArray; class nsINodeInfo; class nsIControllers; +class nsIDOMNSFeatureFactory; typedef unsigned long PtrBits; @@ -598,14 +599,25 @@ public: /** * Check whether a spec feature/version is supported. + * @param aObject the object, which should support the feature, + * for example nsIDOMNode or nsIDOMDOMImplementation * @param aFeature the feature ("Views", "Core", "HTML", "Range" ...) * @param aVersion the version ("1.0", "2.0", ...) * @param aReturn whether the feature is supported or not [OUT] */ - static nsresult InternalIsSupported(const nsAString& aFeature, + static nsresult InternalIsSupported(nsISupports* aObject, + const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn); + static nsresult InternalGetFeature(nsISupports* aObject, + const nsAString& aFeature, + const nsAString& aVersion, + nsISupports** aReturn); + + static already_AddRefed + GetDOMFeatureFactory(const nsAString& aFeature, const nsAString& aVersion); + /** * Quick helper to determine whether there are any mutation listeners * of a given type that apply to this content (are at or above it). diff --git a/mozilla/dom/public/idl/base/Makefile.in b/mozilla/dom/public/idl/base/Makefile.in index f530fa09914..4fea75f9bd4 100644 --- a/mozilla/dom/public/idl/base/Makefile.in +++ b/mozilla/dom/public/idl/base/Makefile.in @@ -73,6 +73,7 @@ XPIDLSRCS = \ nsIDOMWindowInternal.idl \ nsIDOMJSWindow.idl \ nsIDOMChromeWindow.idl \ + nsIDOMNSFeatureFactory.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/dom/public/idl/base/nsIDOMNSFeatureFactory.idl b/mozilla/dom/public/idl/base/nsIDOMNSFeatureFactory.idl new file mode 100644 index 00000000000..7eea1cb600d --- /dev/null +++ b/mozilla/dom/public/idl/base/nsIDOMNSFeatureFactory.idl @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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/MPL/ + * + * 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.org code. + * + * The Initial Developer of the Original Code is + * Olli Pettay. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Olli Pettay (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "domstubs.idl" + +[scriptable, uuid(dc5ba787-b648-4b01-a8e7-b293ffb044ef)] +interface nsIDOMNSFeatureFactory : nsISupports +{ + /** + * @param object: usually either nsIDOMNode or nsIDOMDOMImplementation + * @param feature: the name of the feature + * @param version: the version of the feature + */ + boolean hasFeature(in nsISupports object, + in DOMString feature, + in DOMString version); + /** + * @param object: usually either nsIDOMNode or nsIDOMDOMImplementation + * @param feature: the name of the feature + * @param version: the version of the feature + */ + nsISupports getFeature(in nsISupports object, + in DOMString feature, + in DOMString version); +}; + +%{C++ +#define NS_DOMNS_FEATURE_PREFIX "MozillaDOMFeature-" +%} diff --git a/mozilla/extensions/xforms/nsXFormsElementFactory.cpp b/mozilla/extensions/xforms/nsXFormsElementFactory.cpp index 6a543603bf3..8f0e4f36bc8 100644 --- a/mozilla/extensions/xforms/nsXFormsElementFactory.cpp +++ b/mozilla/extensions/xforms/nsXFormsElementFactory.cpp @@ -90,7 +90,9 @@ NS_HIDDEN_(nsresult) NS_NewXFormsToggleElement(nsIXTFElement **aResult); NS_HIDDEN_(nsresult) NS_NewXFormsCaseElement(nsIXTFElement **aResult); NS_HIDDEN_(nsresult) NS_NewXFormsSwitchElement(nsIXTFElement **aResult); -NS_IMPL_ISUPPORTS1(nsXFormsElementFactory, nsIXTFElementFactory) +NS_IMPL_ISUPPORTS2(nsXFormsElementFactory, + nsIXTFElementFactory, + nsIDOMNSFeatureFactory) NS_IMETHODIMP nsXFormsElementFactory::CreateElement(const nsAString& aTagName, @@ -183,3 +185,23 @@ nsXFormsElementFactory::CreateElement(const nsAString& aTagName, *aElement = nsnull; return NS_ERROR_FAILURE; } + +NS_IMETHODIMP +nsXFormsElementFactory::HasFeature(nsISupports *aObject, + const nsAString& aFeature, + const nsAString& aVersion, + PRBool *aReturn) +{ + *aReturn = aFeature.EqualsLiteral("org.w3c.xforms.dom") && + aVersion.EqualsLiteral("1.0"); + return NS_OK; +} + +NS_IMETHODIMP +nsXFormsElementFactory::GetFeature(nsISupports *aObject, + const nsAString & aFeature, + const nsAString & aVersion, + nsISupports **aReturn) +{ + return NS_ERROR_NOT_AVAILABLE; +} diff --git a/mozilla/extensions/xforms/nsXFormsElementFactory.h b/mozilla/extensions/xforms/nsXFormsElementFactory.h index b3b33d6cd39..a55a69204d3 100644 --- a/mozilla/extensions/xforms/nsXFormsElementFactory.h +++ b/mozilla/extensions/xforms/nsXFormsElementFactory.h @@ -37,6 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIXTFElementFactory.h" +#include "nsIDOMNSFeatureFactory.h" #define NS_XFORMSELEMENTFACTORY_CID \ {0xc068f682, 0x03b5, 0x4e96, {0x81, 0xe1, 0x60, 0x13, 0xf9, 0x12, 0x88, 0xb2}} @@ -44,9 +45,11 @@ /** * Factory class for all XForms elements */ -class nsXFormsElementFactory : public nsIXTFElementFactory +class nsXFormsElementFactory : public nsIXTFElementFactory, + public nsIDOMNSFeatureFactory { public: NS_DECL_ISUPPORTS NS_DECL_NSIXTFELEMENTFACTORY + NS_DECL_NSIDOMNSFEATUREFACTORY }; diff --git a/mozilla/extensions/xforms/nsXFormsModule.cpp b/mozilla/extensions/xforms/nsXFormsModule.cpp index f23d25b71e9..d024c933783 100644 --- a/mozilla/extensions/xforms/nsXFormsModule.cpp +++ b/mozilla/extensions/xforms/nsXFormsModule.cpp @@ -67,6 +67,13 @@ RegisterXFormsModule(nsIComponentManager *aCompMgr, return NS_ERROR_FAILURE; nsXPIDLCString previous; + nsresult rv = + catman->AddCategoryEntry(NS_DOMNS_FEATURE_PREFIX "org.w3c.xforms.dom", + "1.0", + NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_NAMESPACE_XFORMS, + PR_TRUE, PR_TRUE, getter_Copies(previous)); + NS_ENSURE_SUCCESS(rv, rv); + return catman->AddCategoryEntry("agent-style-sheets", "xforms stylesheet", "chrome://xforms/content/xforms.css", @@ -85,6 +92,9 @@ UnregisterXFormsModule(nsIComponentManager *aCompMgr, if (!catman) return NS_ERROR_FAILURE; + catman->DeleteCategoryEntry(NS_DOMNS_FEATURE_PREFIX "org.w3c.xforms.dom", + "1.0", PR_TRUE); + return catman->DeleteCategoryEntry("agent-style-sheets", "xforms stylesheet", PR_TRUE); }