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
This commit is contained in:
doronr%us.ibm.com
2005-02-18 21:32:46 +00:00
parent e54571aca7
commit 86f11fca63
10 changed files with 180 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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<nsIDOMNSFeatureFactory> 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<nsIDOMNSFeatureFactory> factory =
GetDOMFeatureFactory(aFeature, aVersion);
if (factory) {
factory->GetFeature(aObject, aFeature, aVersion, aReturn);
}
return NS_OK;
}
already_AddRefed<nsIDOMNSFeatureFactory>
nsGenericElement::GetDOMFeatureFactory(const nsAString& aFeature,
const nsAString& aVersion)
{
nsIDOMNSFeatureFactory *factory = nsnull;
nsCOMPtr<nsICategoryManager> 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

View File

@@ -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<nsIDOMNSFeatureFactory>
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).

View File

@@ -73,6 +73,7 @@ XPIDLSRCS = \
nsIDOMWindowInternal.idl \
nsIDOMJSWindow.idl \
nsIDOMChromeWindow.idl \
nsIDOMNSFeatureFactory.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -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 <Olli.Pettay@helsinki.fi> (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-"
%}

View File

@@ -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;
}

View File

@@ -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
};

View File

@@ -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);
}