Compare commits

..

6 Commits

Author SHA1 Message Date
waterson%netscape.com
2d38ee31b9 Remove popup document stuff.
git-svn-id: svn://10.0.0.236/branches/XUL_19991005_BRANCH@49862 18797224-902f-48f8-a5cc-f745e15eee43
1999-10-05 21:08:13 +00:00
waterson%netscape.com
681337f94a Minor cleanup per hyatt review.
git-svn-id: svn://10.0.0.236/branches/XUL_19991005_BRANCH@49860 18797224-902f-48f8-a5cc-f745e15eee43
1999-10-05 21:05:31 +00:00
waterson%netscape.com
093ba49d75 Add 'FindFirst()' method as optimization for GetElementById().
git-svn-id: svn://10.0.0.236/branches/XUL_19991005_BRANCH@49859 18797224-902f-48f8-a5cc-f745e15eee43
1999-10-05 21:04:51 +00:00
waterson%netscape.com
cae4da2742 Fix 'position' atom; was incorrectly 'pos'. Update XXX comments.
git-svn-id: svn://10.0.0.236/branches/XUL_19991005_BRANCH@49850 18797224-902f-48f8-a5cc-f745e15eee43
1999-10-05 20:32:05 +00:00
waterson%netscape.com
0dfb63e165 Roll forward XUL_19991004_BRANCH.
git-svn-id: svn://10.0.0.236/branches/XUL_19991005_BRANCH@49847 18797224-902f-48f8-a5cc-f745e15eee43
1999-10-05 19:36:06 +00:00
(no author)
6dae8be49a This commit was manufactured by cvs2svn to create branch
'XUL_19991005_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/XUL_19991005_BRANCH@49799 18797224-902f-48f8-a5cc-f745e15eee43
1999-10-05 04:13:00 +00:00
586 changed files with 87929 additions and 106012 deletions

View File

@@ -0,0 +1,122 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsIChromeRegistry.h"
#include "nscore.h"
#include "rdf.h"
#ifdef NECKO
#include "nsChromeProtocolHandler.h"
#endif
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
#ifdef NECKO
static NS_DEFINE_CID(kChromeProtocolHandlerCID, NS_CHROMEPROTOCOLHANDLER_CID);
#endif
static NS_IMETHODIMP
NS_ConstructChromeRegistry(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
NS_ASSERTION(aOuter == nsnull, "no aggregation");
nsIChromeRegistry* chromeRegistry;
rv = NS_NewChromeRegistry(&chromeRegistry);
if (NS_FAILED(rv)) {
NS_ERROR("Unable to construct chrome registry");
return rv;
}
rv = chromeRegistry->QueryInterface(aIID, aResult);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
NS_RELEASE(chromeRegistry);
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
nsresult rv;
NS_ASSERTION(aFactory != nsnull, "bad factory pointer");
nsIGenericFactory* fact;
if (aClass.Equals(kChromeRegistryCID)) {
rv = NS_NewGenericFactory(&fact, NS_ConstructChromeRegistry);
}
#ifdef NECKO
else if (aClass.Equals(kChromeProtocolHandlerCID)) {
rv = NS_NewGenericFactory(&fact, nsChromeProtocolHandler::Create);
}
#endif
else {
rv = NS_ERROR_FAILURE;
}
if (NS_SUCCEEDED(rv))
*aFactory = fact;
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
{
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kChromeRegistryCID,
"Chrome Registry",
NS_RDF_DATASOURCE_PROGID_PREFIX "chrome",
aPath,
PR_TRUE, PR_TRUE);
#ifdef NECKO
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kChromeProtocolHandlerCID,
"Chrome Protocol Handler",
NS_NETWORK_PROTOCOL_PROGID_PREFIX "chrome",
aPath, PR_TRUE, PR_TRUE);
#endif
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
{
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kChromeRegistryCID, aPath);
#ifdef NECKO
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kChromeProtocolHandlerCID, aPath);
#endif
return rv;
}

View File

@@ -0,0 +1,200 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifdef NECKO
#include "nsChromeProtocolHandler.h"
#include "nsCRT.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIIOService.h"
#include "nsIChannel.h"
#include "nsIChromeRegistry.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsIScriptSecurityManager.h"
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
////////////////////////////////////////////////////////////////////////////////
nsChromeProtocolHandler::nsChromeProtocolHandler()
{
NS_INIT_REFCNT();
}
nsresult
nsChromeProtocolHandler::Init()
{
return NS_OK;
}
nsChromeProtocolHandler::~nsChromeProtocolHandler()
{
}
NS_IMPL_ISUPPORTS(nsChromeProtocolHandler, nsCOMTypeInfo<nsIProtocolHandler>::GetIID());
NS_METHOD
nsChromeProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsChromeProtocolHandler* ph = new nsChromeProtocolHandler();
if (ph == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(ph);
nsresult rv = ph->Init();
if (NS_SUCCEEDED(rv)) {
rv = ph->QueryInterface(aIID, aResult);
}
NS_RELEASE(ph);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIProtocolHandler methods:
NS_IMETHODIMP
nsChromeProtocolHandler::GetScheme(char* *result)
{
*result = nsCRT::strdup("chrome");
if (*result == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsChromeProtocolHandler::GetDefaultPort(PRInt32 *result)
{
*result = -1; // no port for chrome: URLs
return NS_OK;
}
NS_IMETHODIMP
nsChromeProtocolHandler::MakeAbsolute(const char* aSpec,
nsIURI* aBaseURI,
char* *result)
{
// XXX optimize this to not needlessly construct the URL
nsresult rv;
nsIURI* url;
rv = NewURI(aSpec, aBaseURI, &url);
if (NS_FAILED(rv)) return rv;
rv = url->GetSpec(result);
NS_RELEASE(url);
return rv;
}
NS_IMETHODIMP
nsChromeProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
nsIURI **result)
{
nsresult rv;
// Chrome: URLs (currently) have no additional structure beyond that provided by standard
// URLs, so there is no "outer" given to CreateInstance
nsIURI* url;
if (aBaseURI) {
rv = aBaseURI->Clone(&url);
if (NS_FAILED(rv)) return rv;
rv = url->SetRelativePath(aSpec);
}
else {
rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull,
nsCOMTypeInfo<nsIURI>::GetIID(),
(void**)&url);
if (NS_FAILED(rv)) return rv;
rv = url->SetSpec((char*)aSpec);
}
if (NS_FAILED(rv)) {
NS_RELEASE(url);
return rv;
}
*result = url;
return rv;
}
NS_IMETHODIMP
nsChromeProtocolHandler::NewChannel(const char* verb, nsIURI* uri,
nsILoadGroup *aGroup,
nsIEventSinkGetter* eventSinkGetter,
nsIChannel* *result)
{
nsresult rv;
NS_WITH_SERVICE(nsIChromeRegistry, reg, kChromeRegistryCID, &rv);
if (NS_FAILED(rv)) return rv;
static PRBool inited = PR_FALSE;
if (!inited) {
rv = reg->InitRegistry();
if (NS_FAILED(rv)) return rv;
inited = PR_TRUE;
}
nsIURI* chromeURI;
rv = uri->Clone(&chromeURI); // don't mangle the original
if (NS_FAILED(rv)) return rv;
rv = reg->ConvertChromeURL(chromeURI);
if (NS_FAILED(rv)) {
NS_RELEASE(chromeURI);
return rv;
}
// now fetch the converted URI
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
if (NS_FAILED(rv)) {
NS_RELEASE(chromeURI);
return rv;
}
rv = serv->NewChannelFromURI(verb, chromeURI, aGroup, eventSinkGetter,
result);
// Create a special principal for chrome and set the creator property
// of the result
if (NS_SUCCEEDED(rv)) {
nsresult rv2;
NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv2);
if (NS_FAILED(rv2))
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPrincipal> principal;
if (NS_FAILED(securityManager->GetSystemPrincipal(getter_AddRefs(principal))))
{
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsISupports> owner = do_QueryInterface(principal);
(*result)->SetOwner(owner);
}
NS_RELEASE(chromeURI);
return rv;
}
////////////////////////////////////////////////////////////////////////////////
#endif // NECKO

View File

@@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsChromeProtocolHandler_h___
#define nsChromeProtocolHandler_h___
#include "nsIProtocolHandler.h"
#define NS_CHROMEPROTOCOLHANDLER_CID \
{ /* 61ba33c0-3031-11d3-8cd0-0060b0fc14a3 */ \
0x61ba33c0, \
0x3031, \
0x11d3, \
{0x8c, 0xd0, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
}
class nsChromeProtocolHandler : public nsIProtocolHandler
{
public:
NS_DECL_ISUPPORTS
// nsIProtocolHandler methods:
NS_DECL_NSIPROTOCOLHANDLER
// nsChromeProtocolHandler methods:
nsChromeProtocolHandler();
virtual ~nsChromeProtocolHandler();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
nsresult Init();
protected:
};
#endif /* nsChromeProtocolHandler_h___ */

View File

@@ -0,0 +1,915 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsCOMPtr.h"
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
#include "nsIChromeRegistry.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsCRT.h"
#include "rdf.h"
#include "nsIServiceManager.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsIRDFResource.h"
#include "nsIRDFDataSource.h"
#include "nsHashtable.h"
#include "nsString.h"
#include "nsXPIDLString.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFIntIID, NS_IRDFINT_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
#define CHROME_NAMESPACE_URI "http://chrome.mozilla.org/rdf#"
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, chrome);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, skin);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, content);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, locale);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, platform);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, behavior);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, base);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, main);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, archive);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, displayname);
DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, name);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Description);
// This nasty function should disappear when we land Necko completely and
// change chrome://global/skin/foo to chrome://skin@global/foo
//
void BreakProviderAndRemainingFromPath(const char* i_path, char** o_provider, char** o_remaining);
////////////////////////////////////////////////////////////////////////////////
class nsChromeRegistry : public nsIChromeRegistry,
public nsIRDFDataSource,
public nsIRDFRemoteDataSource
{
public:
NS_DECL_ISUPPORTS
// nsIChromeRegistry methods:
NS_IMETHOD InitRegistry();
NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURL);
// nsIRDFDataSource methods
NS_IMETHOD GetURI(char** uri);
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source /* out */) ;
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsISimpleEnumerator** sources /* out */) ;
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target /* out */) ;
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsISimpleEnumerator** targets /* out */) ;
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv) ;
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) ;
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion /* out */) ;
NS_IMETHOD AddObserver(nsIRDFObserver* n) ;
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) ;
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsISimpleEnumerator** labels /* out */) ;
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsISimpleEnumerator** labels /* out */) ;
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) ;
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands) ;
NS_IMETHOD GetAllCmds(nsIRDFResource* source,
nsISimpleEnumerator/*<nsIRDFResource>*/** commands) ;
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
PRBool* retVal) ;
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments) ;
// nsIRDFRemoteDataSource methods
NS_IMETHOD Init(const char* aURI);
NS_IMETHOD Refresh(PRBool aBlocking);
NS_IMETHOD Flush();
// nsChromeRegistry methods:
nsChromeRegistry();
virtual ~nsChromeRegistry();
static PRUint32 gRefCnt;
static nsIRDFService* gRDFService;
static nsIRDFResource* kCHROME_chrome;
static nsIRDFResource* kCHROME_skin;
static nsIRDFResource* kCHROME_content;
static nsIRDFResource* kCHROME_platform;
static nsIRDFResource* kCHROME_locale;
static nsIRDFResource* kCHROME_behavior;
static nsIRDFResource* kCHROME_base;
static nsIRDFResource* kCHROME_main;
static nsIRDFResource* kCHROME_archive;
static nsIRDFResource* kCHROME_name;
static nsIRDFResource* kCHROME_displayname;
static nsIRDFDataSource* mInner;
protected:
nsresult GetPackageTypeResource(const nsString& aChromeType, nsIRDFResource** aResult);
nsresult GetChromeResource(nsString& aResult, nsIRDFResource* aChromeResource,
nsIRDFResource* aProperty);
};
PRUint32 nsChromeRegistry::gRefCnt ;
nsIRDFService* nsChromeRegistry::gRDFService = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_chrome = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_skin = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_content = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_locale = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_behavior = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_platform = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_base = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_main = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_archive = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_name = nsnull;
nsIRDFResource* nsChromeRegistry::kCHROME_displayname = nsnull;
nsIRDFDataSource* nsChromeRegistry::mInner = nsnull;
////////////////////////////////////////////////////////////////////////////////
nsChromeRegistry::nsChromeRegistry()
{
NS_INIT_REFCNT();
}
nsChromeRegistry::~nsChromeRegistry()
{
--gRefCnt;
if (gRefCnt == 0) {
// Release our inner data source
NS_IF_RELEASE(mInner);
// release all the properties:
NS_IF_RELEASE(kCHROME_chrome);
NS_IF_RELEASE(kCHROME_skin);
NS_IF_RELEASE(kCHROME_content);
NS_IF_RELEASE(kCHROME_platform);
NS_IF_RELEASE(kCHROME_locale);
NS_IF_RELEASE(kCHROME_behavior);
NS_IF_RELEASE(kCHROME_base);
NS_IF_RELEASE(kCHROME_main);
NS_IF_RELEASE(kCHROME_archive);
NS_IF_RELEASE(kCHROME_displayname);
NS_IF_RELEASE(kCHROME_name);
if (gRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
}
}
NS_IMPL_ADDREF(nsChromeRegistry)
NS_IMPL_RELEASE(nsChromeRegistry)
NS_IMETHODIMP
nsChromeRegistry::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsCOMTypeInfo<nsIChromeRegistry>::GetIID()) ||
aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIChromeRegistry*, this);
}
else if (aIID.Equals(nsCOMTypeInfo<nsIRDFDataSource>::GetIID())) {
*aResult = NS_STATIC_CAST(nsIRDFDataSource*, this);
}
else if (aIID.Equals(nsCOMTypeInfo<nsIRDFRemoteDataSource>::GetIID())) {
*aResult = NS_STATIC_CAST(nsIRDFRemoteDataSource*, this);
}
else {
*aResult = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF(this);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIChromeRegistry methods:
/*
The ConvertChromeURL takes a chrome URL and converts it into a resource: or
an HTTP: url type with certain rules. Here are the current portions of a
chrome: url that make up the chrome-
chrome://global/skin/foo?bar
\------/ \----/\---/ \-----/
| | | |
| | | `-- RemainingPortion
| | |
| | `-- Provider
| |
| `-- Package
|
'-- Always "chrome://"
Sometime in future when Necko lands completely this will change to the
following syntax-
chrome://skin@global/foo?bar
This will make the parsing simpler and quicker (since the URL parsing already
takes this into account)
*/
NS_IMETHODIMP
nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL)
#ifdef NECKO
{
nsresult rv = NS_OK;
NS_ASSERTION(aChromeURL, "null url!");
if (!aChromeURL)
return NS_ERROR_NULL_POINTER;
#ifdef NS_DEBUG
//Ensure that we got a chrome url!
nsXPIDLCString scheme;
rv = aChromeURL->GetScheme(getter_Copies(scheme));
if (NS_FAILED(rv)) return rv;
NS_ASSERTION((0 == PL_strncmp(scheme, "chrome", 6)),
"Bad scheme URL in chrome URL conversion!");
if (0 != PL_strncmp(scheme, "chrome", 6))
return NS_ERROR_FAILURE;
#endif
// Obtain the package, provider and remaining from the URL
nsXPIDLCString package, provider, remaining;
#if 0 // This change happens when we switch to using chrome://skin@global/foo..
rv = aChromeURL->GetHost(getter_Copies(package));
if (NS_FAILED(rv)) return rv;
rv = aChromeURL->GetPreHost(getter_Copies(provider));
if (NS_FAILED(rv)) return rv;
rv = aChromeURL->GetPath(getter_Copies(remaining));
if (NS_FAILED(rv)) return rv;
#else // For now however...
rv = aChromeURL->GetHost(getter_Copies(package));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString tempPath;
rv = aChromeURL->GetPath(getter_Copies(tempPath));
if (NS_FAILED(rv)) return rv;
BreakProviderAndRemainingFromPath(
(const char*)tempPath,
getter_Copies(provider),
getter_Copies(remaining));
#endif
// Construct the lookup string-
// which is basically chrome:// + package + provider
nsAutoString lookup("chrome://");
lookup += package; // no trailing slash here
NS_ASSERTION(*provider == '/', "No leading slash here!");
//definitely have a leading slash...
if (*provider != '/')
lookup += '/';
lookup += provider;
// end it on a slash if none is present
if (lookup.CharAt(lookup.Length()-1) != '/')
lookup += '/';
// Get the chromeResource from this lookup string
nsCOMPtr<nsIRDFResource> chromeResource;
if (NS_FAILED(rv = GetPackageTypeResource(lookup, getter_AddRefs(chromeResource)))) {
NS_ERROR("Unable to retrieve the resource corresponding to the chrome skin or content.");
return rv;
}
// Using this chrome resource get the three basic things of a chrome entry-
// base, name, main. and don't bail if they don't exist.
nsAutoString base, name, main;
rv = GetChromeResource(name, chromeResource, kCHROME_name);
if (NS_FAILED (rv)) {
// No name entry was found. No problem.
}
rv = GetChromeResource(base, chromeResource, kCHROME_base);
if (NS_FAILED(rv))
{
// No base entry was found, default it to our cache.
base = "resource:/chrome/";
base += package;
if ((base.CharAt(base.Length()-1) != '/') && *provider != '/')
base += '/';
base += provider;
if (base.CharAt(base.Length()-1) != '/')
base += '/';
if (name.Length())
base += name;
if (base.CharAt(base.Length()-1) != '/')
base += '/';
}
NS_ASSERTION(base.CharAt(base.Length()-1) == '/', "Base doesn't end in a slash!");
if ('/' != base.CharAt(base.Length()-1))
base += '/';
// Now we construct our finalString
nsAutoString finalString(base);
if (!remaining || (0 == PL_strlen(remaining)))
{
rv = GetChromeResource(main, chromeResource, kCHROME_main);
if (NS_FAILED(rv))
{
//we'd definitely need main for an empty remaining
NS_ERROR("Unable to retrieve the main file registry entry for a chrome URL.");
return rv;
}
finalString += main;
}
else
finalString += remaining;
char* finalURI = finalString.ToNewCString();
aChromeURL->SetSpec(finalURI);
/*
#ifndef NECKO
// Clean out possible // in the path
char* path;
rv = aChromeURL->GetPath(&path);
char* cleanPath = path;
for (; '\0' != *path; ++path)
{
if (*path == '/' && *(path+1) == '/')
++path;
*cleanPath++ = *path;
}
aChrome->SetRelativePath(path);
nsCRT::free(path);
#endif
*/
nsCRT::free(finalURI);
return NS_OK;
}
#else
{
nsresult rv = NS_OK;
// Retrieve the resource for this chrome element.
const char* host;
if (NS_FAILED(rv = aChromeURL->GetHost(&host))) {
NS_ERROR("Unable to retrieve the host for a chrome URL.");
return rv;
}
nsAutoString hostStr(host);
const char* file;
// Construct a chrome URL and use it to look up a resource.
nsAutoString windowType = nsAutoString("chrome://") + hostStr + "/";
// Stash any search part of the URL for later
aChromeURL->GetSearch(&file);
nsAutoString searchStr(file);
// Find out the package type of the URL
aChromeURL->GetFile(&file);
nsAutoString restOfURL(file);
// Find the second slash.
nsAutoString packageType("content");
nsAutoString path("");
PRInt32 slashIndex = -1;
if (restOfURL.Length() > 1)
{
// There is something to the right of that slash. A provider type must have
// been specified.
slashIndex = restOfURL.FindChar('/', PR_FALSE,1);
if (slashIndex == -1)
slashIndex = restOfURL.Length();
restOfURL.Mid(packageType, 1, slashIndex - 1);
if (slashIndex < restOfURL.Length()-1)
{
// There are some extra subdirectories to remember.
restOfURL.Right(path, restOfURL.Length()-slashIndex-1);
}
}
windowType += packageType + "/";
// We have the resource URI that we wish to retrieve. Fetch it.
nsCOMPtr<nsIRDFResource> chromeResource;
if (NS_FAILED(rv = GetPackageTypeResource(windowType, getter_AddRefs(chromeResource)))) {
NS_ERROR("Unable to retrieve the resource corresponding to the chrome skin or content.");
return rv;
}
nsAutoString chromeName;
if (NS_FAILED(rv = GetChromeResource(chromeName, chromeResource, kCHROME_name))) {
// No name entry was found. Don't use one.
chromeName = "";
}
nsAutoString chromeBase;
if (NS_FAILED(rv = GetChromeResource(chromeBase, chromeResource, kCHROME_base))) {
// No base entry was found. Default to our cache.
chromeBase = "resource:/chrome/";
chromeBase += hostStr;
chromeBase += "/";
chromeBase += packageType + "/";
if (chromeName != "")
chromeBase += chromeName + "/";
}
// Make sure base ends in a slash
PRInt32 length = chromeBase.Length();
if (length > 0)
{
PRUnichar c = chromeBase.CharAt(length-1);
if (c != '/')
chromeBase += "/"; // Ensure that a slash is present.
}
// Check to see if we should append the "main" entry in the registry.
// Only do this when the user doesn't have anything following "skin"
// or "content" in the specified URL.
if (path.IsEmpty())
{
PRInt32 length = restOfURL.Length();
if (length > 0)
{
PRUnichar c = restOfURL.CharAt(length-1);
if (c != '/')
restOfURL += "/"; // Ensure that a slash is present.
}
// Append the "main" entry.
nsAutoString mainFile;
if (NS_FAILED(rv = GetChromeResource(mainFile, chromeResource, kCHROME_main))) {
NS_ERROR("Unable to retrieve the main file registry entry for a chrome URL.");
return rv;
}
chromeBase += mainFile;
}
else
{
// XXX Just append the rest of the URL to base to get the actual URL to look up.
chromeBase += path;
}
char* finalDecision = chromeBase.ToNewCString();
char* search = searchStr.ToNewCString();
aChromeURL->SetSpec(finalDecision);
if (search && *search) {
aChromeURL->SetSearch(search);
nsCRT::free(search);
}
}
#endif
NS_IMETHODIMP
nsChromeRegistry::InitRegistry()
{
gRefCnt++;
if (gRefCnt == 1) {
nsresult rv;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**)&gRDFService);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
if (NS_FAILED(rv)) return rv;
// get all the properties we'll need:
rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_platform);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_locale);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_behavior);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
nsnull,
nsIRDFDataSource::GetIID(),
(void**) &mInner);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
if (! remote)
return NS_ERROR_UNEXPECTED;
// Retrieve the mInner data source.
nsSpecialSystemDirectory chromeFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
chromeFile += "chrome";
chromeFile += "registry.rdf";
nsFileURL chromeURL(chromeFile);
const char* innerURI = chromeURL.GetAsString();
rv = remote->Init(innerURI);
if (NS_FAILED(rv)) return rv;
}
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
if (! remote)
return NS_ERROR_UNEXPECTED;
// We need to read this synchronously.
nsresult rv = remote->Refresh(PR_TRUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRDFObserver methods:
////////////////////////////////////////////////////////////////////////////////
nsresult
nsChromeRegistry::GetPackageTypeResource(const nsString& aChromeType,
nsIRDFResource** aResult)
{
nsresult rv = NS_OK;
char* url = aChromeType.ToNewCString();
if (NS_FAILED(rv = gRDFService->GetResource(url, aResult))) {
NS_ERROR("Unable to retrieve a resource for this package type.");
*aResult = nsnull;
nsCRT::free(url);
return rv;
}
nsCRT::free(url);
return NS_OK;
}
nsresult
nsChromeRegistry::GetChromeResource(nsString& aResult,
nsIRDFResource* aChromeResource,
nsIRDFResource* aProperty)
{
nsresult rv = NS_OK;
if (mInner == nsnull)
return NS_ERROR_FAILURE; // Must have a DB to attempt this operation.
nsCOMPtr<nsIRDFNode> chromeBase;
if (NS_FAILED(rv = GetTarget(aChromeResource, aProperty, PR_TRUE, getter_AddRefs(chromeBase)))) {
NS_ERROR("Unable to obtain a base resource.");
return rv;
}
if (chromeBase == nsnull)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIRDFResource> resource;
nsCOMPtr<nsIRDFLiteral> literal;
if (NS_SUCCEEDED(rv = chromeBase->QueryInterface(kIRDFResourceIID,
(void**) getter_AddRefs(resource)))) {
nsXPIDLCString uri;
resource->GetValue( getter_Copies(uri) );
aResult = uri;
}
else if (NS_SUCCEEDED(rv = chromeBase->QueryInterface(kIRDFLiteralIID,
(void**) getter_AddRefs(literal)))) {
nsXPIDLString s;
literal->GetValue( getter_Copies(s) );
aResult = s;
}
else {
// This should _never_ happen.
NS_ERROR("uh, this isn't a resource or a literal!");
return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}
nsresult
NS_NewChromeRegistry(nsIChromeRegistry** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsChromeRegistry* chromeRegistry = new nsChromeRegistry();
if (chromeRegistry == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(chromeRegistry);
*aResult = chromeRegistry;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRDFDataSource methods
NS_IMETHODIMP
nsChromeRegistry::GetURI(char** uri)
{
*uri = nsXPIDLCString::Copy("rdf:chrome");
if (! *uri)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsChromeRegistry::GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source /* out */)
{
return mInner->GetSource(property, target, tv, source);
}
NS_IMETHODIMP
nsChromeRegistry::GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsISimpleEnumerator** sources /* out */)
{
return mInner->GetSources(property, target, tv, sources);
}
NS_IMETHODIMP
nsChromeRegistry::GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target /* out */)
{
return mInner->GetTarget(source, property, tv, target);
}
NS_IMETHODIMP
nsChromeRegistry::GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsISimpleEnumerator** targets /* out */)
{
return mInner->GetTargets(source, property, tv, targets);
}
NS_IMETHODIMP
nsChromeRegistry::Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv)
{
return mInner->Assert(source, property, target, tv);
}
NS_IMETHODIMP
nsChromeRegistry::Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target)
{
return mInner->Unassert(source, property, target);
}
NS_IMETHODIMP
nsChromeRegistry::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
return mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
}
NS_IMETHODIMP
nsChromeRegistry::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
}
NS_IMETHODIMP
nsChromeRegistry::HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion /* out */)
{
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
}
NS_IMETHODIMP nsChromeRegistry::AddObserver(nsIRDFObserver* n)
{
return mInner->AddObserver(n);
}
NS_IMETHODIMP nsChromeRegistry::RemoveObserver(nsIRDFObserver* n)
{
return mInner->RemoveObserver(n);
}
NS_IMETHODIMP nsChromeRegistry::ArcLabelsIn(nsIRDFNode* node,
nsISimpleEnumerator** labels /* out */)
{
return mInner->ArcLabelsIn(node, labels);
}
NS_IMETHODIMP nsChromeRegistry::ArcLabelsOut(nsIRDFResource* source,
nsISimpleEnumerator** labels /* out */)
{
return mInner->ArcLabelsOut(source, labels);
}
NS_IMETHODIMP nsChromeRegistry::GetAllResources(nsISimpleEnumerator** aCursor)
{
return mInner->GetAllResources(aCursor);
}
NS_IMETHODIMP
nsChromeRegistry::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands)
{
return mInner->GetAllCommands(source, commands);
}
NS_IMETHODIMP
nsChromeRegistry::GetAllCmds(nsIRDFResource* source,
nsISimpleEnumerator/*<nsIRDFResource>*/** commands)
{
return mInner->GetAllCmds(source, commands);
}
NS_IMETHODIMP
nsChromeRegistry::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
PRBool* retVal)
{
return mInner->IsCommandEnabled(aSources, aCommand, aArguments, retVal);
}
NS_IMETHODIMP
nsChromeRegistry::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
nsIRDFResource* aCommand,
nsISupportsArray/*<nsIRDFResource>*/* aArguments)
{
return mInner->DoCommand(aSources, aCommand, aArguments);
}
////////////////////////////////////////////////////////////////////////
// nsIRDFRemoteDataSource methods
NS_IMETHODIMP
nsChromeRegistry::Init(const char* aURI)
{
return NS_OK;
}
NS_IMETHODIMP
nsChromeRegistry::Refresh(PRBool aBlocking)
{
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
if (! remote)
return NS_ERROR_UNEXPECTED;
return remote->Refresh(aBlocking);
}
NS_IMETHODIMP
nsChromeRegistry::Flush()
{
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
if (! remote)
return NS_ERROR_UNEXPECTED;
return remote->Flush();
}
////////////////////////////////////////////////////////////////////////
//
// Path = provider/remaining
//
void BreakProviderAndRemainingFromPath(const char* i_path, char** o_provider, char** o_remaining)
{
if (!i_path || !o_provider || !o_remaining)
return;
int len = PL_strlen(i_path);
NS_ASSERTION(len>1, "path is messed up!");
char* slash = PL_strchr(i_path+1, '/'); // +1 to skip the leading slash if any
if (slash)
{
*o_provider = PL_strndup(i_path, (slash - i_path)); // dont include the trailing slash
if (slash != (i_path + len-1)) // if that was not the last trailing slash...
{
// don't include the leading slash here as well...
*o_remaining = PL_strndup(slash+1, len - (slash-i_path + 1));
}
else
*o_remaining = nsnull;
}
else // everything is just the provider
*o_provider = PL_strndup(i_path, len);
}

View File

@@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIXULPopupListener_h__
#define nsIXULPopupListener_h__
// {2C453161-0942-11d3-BF87-00105A1B0627}
#define NS_IXULPOPUPLISTENER_IID \
{ 0x2c453161, 0x942, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
class nsIDOMElement;
typedef enum {
eXULPopupType_popup,
eXULPopupType_context,
eXULPopupType_tooltip,
eXULPopupType_blur
} XULPopupType;
class nsIXULPopupListener: public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IXULPOPUPLISTENER_IID; return iid; }
NS_IMETHOD Init(nsIDOMElement* anElement, const XULPopupType& aPopupType) = 0;
};
extern nsresult
NS_NewXULPopupListener(nsIXULPopupListener** result);
#endif // nsIXULPopupListener_h__

View File

@@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 nsIRDFNodeList_h__
#define nsIRDFNodeList_h__
#include "nsISupports.h"
// {661D1971-5CD2-11d3-BE36-00104BDE6048}
#define NS_IRDFNODELIST_IID \
{ 0x661d1971, 0x5cd2, 0x11d3, { 0xbe, 0x36, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
class nsIRDFNodeList : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IRDFNODELIST_IID; return iid; }
NS_IMETHOD AppendNode(nsIDOMNode* aNode) = 0;
NS_IMETHOD RemoveNode(nsIDOMNode* aNode) = 0;
};
#endif // nsIRDFNodeList_h__

View File

@@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
A private interface to the tree element
*/
#ifndef nsIXULTreeContent_h__
#define nsIXULTreeContent_h__
#include "nsISupports.h"
// {661D1970-5CD2-11d3-BE36-00104BDE6048}
#define NS_IXULTREECONTENT_IID \
{ 0x661d1970, 0x5cd2, 0x11d3, { 0xbe, 0x36, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
class nsIXULTreeContent : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IXULTREECONTENT_IID; return iid; }
NS_IMETHOD FireOnSelectHandler() = 0;
};
#endif // nsIXULTreeContent_h__

View File

@@ -0,0 +1,232 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
Helper class to implement the nsIDOMNodeList interface.
XXX It's probably wrong in some sense, as it uses the "naked"
content interface to look for kids. (I assume in general this is
bad because there may be pseudo-elements created for presentation
that aren't visible to the DOM.)
*/
#include "nsDOMCID.h"
#include "nsIDOMNode.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsIScriptGlobalObject.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsRDFDOMNodeList.h"
////////////////////////////////////////////////////////////////////////
// GUID definitions
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID);
static NS_DEFINE_IID(kIDOMScriptObjectFactoryIID, NS_IDOM_SCRIPT_OBJECT_FACTORY_IID);
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
////////////////////////////////////////////////////////////////////////
// ctors & dtors
nsRDFDOMNodeList::nsRDFDOMNodeList(void)
: mInner(nsnull),
mElements(nsnull),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
nsRDFDOMNodeList::~nsRDFDOMNodeList(void)
{
NS_IF_RELEASE(mElements);
delete mInner;
}
nsresult
nsRDFDOMNodeList::Create(nsRDFDOMNodeList** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRDFDOMNodeList* list = new nsRDFDOMNodeList();
if (! list)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
if (NS_FAILED(rv = list->Init())) {
delete list;
return rv;
}
NS_ADDREF(list);
*aResult = list;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(nsRDFDOMNodeList);
NS_IMPL_RELEASE(nsRDFDOMNodeList);
nsresult
nsRDFDOMNodeList::QueryInterface(REFNSIID aIID, void** aResult)
{
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsCOMTypeInfo<nsIDOMNodeList>::GetIID()) ||
aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIDOMNodeList*, this);
}
else if (aIID.Equals(nsCOMTypeInfo<nsIRDFNodeList>::GetIID())) {
*aResult = NS_STATIC_CAST(nsIRDFNodeList*, this);
}
else if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
}
else {
*aResult = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF(this);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNodeList interface
NS_IMETHODIMP
nsRDFDOMNodeList::GetLength(PRUint32* aLength)
{
NS_ASSERTION(aLength != nsnull, "null ptr");
if (! aLength)
return NS_ERROR_NULL_POINTER;
PRUint32 cnt;
nsresult rv = mElements->Count(&cnt);
if (NS_FAILED(rv)) return rv;
*aLength = cnt;
return NS_OK;
}
NS_IMETHODIMP
nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
NS_PRECONDITION(aReturn != nsnull, "null ptr");
if (! aReturn)
return NS_ERROR_NULL_POINTER;
PRUint32 cnt;
nsresult rv = mElements->Count(&cnt);
if (NS_FAILED(rv)) return rv;
NS_PRECONDITION(aIndex < cnt, "invalid arg");
if (aIndex >= (PRUint32) cnt)
return NS_ERROR_INVALID_ARG;
// Cast is okay because we're in a closed system.
*aReturn = (nsIDOMNode*) mElements->ElementAt(aIndex);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIScriptObjectOwner interface
NS_IMETHODIMP
nsRDFDOMNodeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult rv = NS_OK;
nsIScriptGlobalObject* global = aContext->GetGlobalObject();
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID,
kIDOMScriptObjectFactoryIID,
(nsISupports **)&factory))) {
rv = factory->NewScriptNodeList(aContext,
(nsISupports*)(nsIDOMNodeList*)this,
global,
(void**)&mScriptObject);
nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory);
}
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return rv;
}
NS_IMETHODIMP
nsRDFDOMNodeList::SetScriptObject(void* aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// Implementation methods
nsresult
nsRDFDOMNodeList::Init(void)
{
nsresult rv;
if (NS_FAILED(rv = NS_NewISupportsArray(&mElements))) {
NS_ERROR("unable to create elements array");
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
nsRDFDOMNodeList::AppendNode(nsIDOMNode* aNode)
{
NS_PRECONDITION(aNode != nsnull, "null ptr");
if (! aNode)
return NS_ERROR_NULL_POINTER;
return mElements->AppendElement(aNode);
}
NS_IMETHODIMP
nsRDFDOMNodeList::RemoveNode(nsIDOMNode* aNode)
{
NS_PRECONDITION(aNode != nsnull, "null ptr");
if (! aNode)
return NS_ERROR_NULL_POINTER;
return mElements->RemoveElement(aNode);
}

View File

@@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 nsRDFDOMNodeList_h__
#define nsRDFDOMNodeList_h__
#include "nsIDOMNodeList.h"
#include "nsIRDFNodeList.h"
#include "nsIScriptObjectOwner.h"
class nsIDOMNode;
class nsISupportsArray;
class nsRDFDOMNodeList : public nsIDOMNodeList,
public nsIRDFNodeList,
public nsIScriptObjectOwner
{
private:
nsISupports* mInner;
nsISupportsArray* mElements;
void* mScriptObject;
nsRDFDOMNodeList(void);
nsresult Init(void);
public:
static nsresult Create(nsRDFDOMNodeList** aResult);
virtual ~nsRDFDOMNodeList(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMNodeList interface
NS_DECL_IDOMNODELIST
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
// Implementation methods
NS_IMETHOD AppendNode(nsIDOMNode* aNode);
NS_IMETHOD RemoveNode(nsIDOMNode* aNode);
};
#endif // nsRDFDOMNodeList_h__

View File

@@ -0,0 +1,663 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
A helper class used to implement attributes.
*/
/*
* Notes
*
* A lot of these methods delegate back to the original content node
* that created them. This is so that we can lazily produce attribute
* values from the RDF graph as they're asked for.
*
*/
#include "nsCOMPtr.h"
#include "nsDOMCID.h"
#include "nsIContent.h"
#include "nsICSSParser.h"
#include "nsIDOMElement.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsINameSpaceManager.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsXULAttributes.h"
#include "nsLayoutCID.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
static NS_DEFINE_CID(kICSSParserIID, NS_ICSS_PARSER_IID);
////////////////////////////////////////////////////////////////////////
// nsXULAttribute
nsXULAttribute::nsXULAttribute(nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aName,
const nsString& aValue)
: mNameSpaceID(aNameSpaceID),
mName(aName),
mValue(aValue),
mContent(aContent),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
NS_IF_ADDREF(aName);
}
nsXULAttribute::~nsXULAttribute()
{
NS_IF_RELEASE(mName);
}
nsresult
NS_NewXULAttribute(nsXULAttribute** aResult,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aName,
const nsString& aValue)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (! (*aResult = new nsXULAttribute(aContent, aNameSpaceID, aName, aValue)))
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
return NS_OK;
}
// nsISupports interface
NS_IMPL_ADDREF(nsXULAttribute);
NS_IMPL_RELEASE(nsXULAttribute);
NS_IMETHODIMP
nsXULAttribute::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIDOMAttr::GetIID()) ||
aIID.Equals(nsIDOMNode::GetIID()) ||
aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIDOMAttr*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (aIID.Equals(nsIScriptObjectOwner::GetIID())) {
*aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
*aResult = nsnull;
return NS_NOINTERFACE;
}
}
// nsIDOMNode interface
NS_IMETHODIMP
nsXULAttribute::GetNodeName(nsString& aNodeName)
{
const PRUnichar *unicodeString;
mName->GetUnicode(&unicodeString);
aNodeName.SetString(unicodeString);
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::GetNodeValue(nsString& aNodeValue)
{
aNodeValue=mValue;
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::SetNodeValue(const nsString& aNodeValue)
{
return SetValue(aNodeValue);
}
NS_IMETHODIMP
nsXULAttribute::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = (PRUint16)nsIDOMNode::ATTRIBUTE_NODE;
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::GetParentNode(nsIDOMNode** aParentNode)
{
*aParentNode = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::GetChildNodes(nsIDOMNodeList** aChildNodes)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULAttribute::GetFirstChild(nsIDOMNode** aFirstChild)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULAttribute::GetLastChild(nsIDOMNode** aLastChild)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULAttribute::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
*aPreviousSibling = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::GetNextSibling(nsIDOMNode** aNextSibling)
{
*aNextSibling = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
{
*aAttributes = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULAttribute::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULAttribute::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULAttribute::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULAttribute::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULAttribute::HasChildNodes(PRBool* aReturn)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULAttribute::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsIDOMAttr interface
NS_IMETHODIMP
nsXULAttribute::GetName(nsString& aName)
{
const PRUnichar *unicodeString;
mName->GetUnicode(&unicodeString);
aName.SetString(unicodeString);
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::GetSpecified(PRBool* aSpecified)
{
// XXX this'll break when we make Clone() work
*aSpecified = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::GetValue(nsString& aValue)
{
aValue=mValue;
return NS_OK;
}
NS_IMETHODIMP
nsXULAttribute::SetValue(const nsString& aValue)
{
nsCOMPtr<nsIDOMElement> element( do_QueryInterface(mContent) );
if (element) {
nsAutoString qualifiedName;
GetQualifiedName(qualifiedName);
return element->SetAttribute(qualifiedName, aValue);
}
else {
return NS_ERROR_FAILURE;
}
}
// nsIScriptObjectOwner interface
NS_IMETHODIMP
nsXULAttribute::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject)
{
nsresult rv = NS_OK;
if (! mScriptObject) {
nsIDOMScriptObjectFactory *factory;
rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID,
nsIDOMScriptObjectFactory::GetIID(),
(nsISupports **)&factory);
if (NS_FAILED(rv))
return rv;
rv = factory->NewScriptAttr(aContext,
(nsISupports*)(nsIDOMAttr*) this,
(nsISupports*) mContent,
(void**) &mScriptObject);
nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory);
}
*aScriptObject = mScriptObject;
return rv;
}
NS_IMETHODIMP
nsXULAttribute::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
// Implementation methods
void
nsXULAttribute::GetQualifiedName(nsString& aQualifiedName)
{
aQualifiedName.Truncate();
if ((mNameSpaceID != kNameSpaceID_None) &&
(mNameSpaceID != kNameSpaceID_Unknown)) {
nsresult rv;
nsIAtom* prefix;
rv = mContent->GetNameSpacePrefixFromId(mNameSpaceID, prefix);
if (NS_SUCCEEDED(rv) && (prefix != nsnull)) {
const PRUnichar *unicodeString;
prefix->GetUnicode(&unicodeString);
aQualifiedName.Append(unicodeString);
aQualifiedName.Append(':');
NS_RELEASE(prefix);
}
}
const PRUnichar *unicodeString;
mName->GetUnicode(&unicodeString);
aQualifiedName.Append(unicodeString);
}
////////////////////////////////////////////////////////////////////////
// nsXULAttributes
nsXULAttributes::nsXULAttributes(nsIContent* aContent)
: mContent(aContent),
mClassList(nsnull),
mStyleRule(nsnull),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
nsXULAttributes::~nsXULAttributes()
{
PRInt32 count = mAttributes.Count();
for (PRInt32 indx = 0; indx < count; indx++) {
nsXULAttribute* attr = (nsXULAttribute*)mAttributes.ElementAt(indx);
NS_RELEASE(attr);
}
}
nsresult
NS_NewXULAttributes(nsXULAttributes** aResult, nsIContent* aContent)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (! (*aResult = new nsXULAttributes(aContent)))
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
return NS_OK;
}
// nsISupports interface
NS_IMPL_ADDREF(nsXULAttributes);
NS_IMPL_RELEASE(nsXULAttributes);
NS_IMETHODIMP
nsXULAttributes::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIDOMNamedNodeMap::GetIID()) ||
aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIDOMNamedNodeMap*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (aIID.Equals(nsIScriptObjectOwner::GetIID())) {
*aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
*aResult = nsnull;
return NS_NOINTERFACE;
}
}
// nsIDOMNamedNodeMap interface
NS_IMETHODIMP
nsXULAttributes::GetLength(PRUint32* aLength)
{
NS_PRECONDITION(aLength != nsnull, "null ptr");
if (! aLength)
return NS_ERROR_NULL_POINTER;
*aLength = mAttributes.Count();
return NS_OK;
}
NS_IMETHODIMP
nsXULAttributes::GetNamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
NS_PRECONDITION(aReturn != nsnull, "null ptr");
if (! aReturn)
return NS_ERROR_NULL_POINTER;
nsresult rv;
*aReturn = nsnull;
PRInt32 nameSpaceID;
nsIAtom* name;
if (NS_FAILED(rv = mContent->ParseAttributeString(aName, name, nameSpaceID)))
return rv;
if (kNameSpaceID_Unknown == nameSpaceID) {
nameSpaceID = kNameSpaceID_None; // ignore unknown prefix XXX is this correct?
}
// XXX doing this instead of calling mContent->GetAttribute() will
// make it a lot harder to lazily instantiate properties from the
// graph. The problem is, how else do we get the named item?
for (PRInt32 i = mAttributes.Count() - 1; i >= 0; --i) {
nsXULAttribute* attr = (nsXULAttribute*) mAttributes[i];
if (((nameSpaceID == attr->mNameSpaceID) ||
(nameSpaceID == kNameSpaceID_Unknown) ||
(nameSpaceID == kNameSpaceID_None)) &&
(name == attr->mName)) {
NS_ADDREF(attr);
*aReturn = attr;
break;
}
}
NS_RELEASE(name);
return NS_OK;
}
NS_IMETHODIMP
nsXULAttributes::SetNamedItem(nsIDOMNode* aArg, nsIDOMNode** aReturn)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULAttributes::RemoveNamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
nsCOMPtr<nsIDOMElement> element( do_QueryInterface(mContent) );
if (element) {
return element->RemoveAttribute(aName);
*aReturn = nsnull; // XXX should be the element we just removed
return NS_OK;
}
else {
return NS_ERROR_FAILURE;
}
}
NS_IMETHODIMP
nsXULAttributes::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
*aReturn = (nsXULAttribute*) mAttributes[aIndex];
NS_IF_ADDREF(*aReturn);
return NS_OK;
}
// nsIScriptObjectOwner interface
NS_IMETHODIMP
nsXULAttributes::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject)
{
nsresult rv = NS_OK;
if (! mScriptObject) {
nsIDOMScriptObjectFactory *factory;
rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID,
nsIDOMScriptObjectFactory::GetIID(),
(nsISupports **)&factory);
if (NS_FAILED(rv))
return rv;
rv = factory->NewScriptNamedNodeMap(aContext,
(nsISupports*)(nsIDOMNamedNodeMap*) this,
(nsISupports*) mContent,
(void**) &mScriptObject);
nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory);
}
*aScriptObject = mScriptObject;
return rv;
}
NS_IMETHODIMP
nsXULAttributes::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
// Implementation methods
nsresult
nsXULAttributes::GetClasses(nsVoidArray& aArray) const
{
aArray.Clear();
const nsClassList* classList = mClassList;
while (nsnull != classList) {
aArray.AppendElement(classList->mAtom); // NOTE atom is not addrefed
classList = classList->mNext;
}
return NS_OK;
}
nsresult
nsXULAttributes::HasClass(nsIAtom* aClass) const
{
const nsClassList* classList = mClassList;
while (nsnull != classList) {
if (classList->mAtom == aClass) {
return NS_OK;
}
classList = classList->mNext;
}
return NS_COMFALSE;
}
nsresult nsXULAttributes::UpdateClassList(const nsString& aValue)
{
if (mClassList != nsnull)
{
delete mClassList;
mClassList = nsnull;
}
if (aValue != "")
ParseClasses(aValue, &mClassList);
return NS_OK;
}
nsresult nsXULAttributes::UpdateStyleRule(nsIURI* aDocURL, const nsString& aValue)
{
if (aValue == "")
{
// XXX: Removing the rule. Is this sufficient?
NS_IF_RELEASE(mStyleRule);
mStyleRule = nsnull;
return NS_OK;
}
nsICSSParser* css;
nsresult result = nsComponentManager::CreateInstance(kCSSParserCID,
nsnull,
kICSSParserIID,
(void**)&css);
if (NS_OK != result) {
return result;
}
nsIStyleRule* rule;
result = css->ParseDeclarations(aValue, aDocURL, rule);
//NS_IF_RELEASE(docURL);
if ((NS_OK == result) && (nsnull != rule)) {
mStyleRule = rule; //Addrefed already during parse, so don't need to addref again.
//result = SetHTMLAttribute(aAttribute, nsHTMLValue(rule), aNotify);
}
//else {
// result = SetHTMLAttribute(aAttribute, nsHTMLValue(aValue), aNotify);
//}
NS_RELEASE(css);
return NS_OK;
}
nsresult nsXULAttributes::GetInlineStyleRule(nsIStyleRule*& aRule)
{
nsresult result = NS_ERROR_NULL_POINTER;
if (mStyleRule != nsnull)
{
aRule = mStyleRule;
NS_ADDREF(aRule);
result = NS_OK;
}
return result;
}
void
nsXULAttributes::ParseClasses(const nsString& aClassString, nsClassList** aClassList)
{
static const PRUnichar kNullCh = PRUnichar('\0');
NS_ASSERTION(nsnull == *aClassList, "non null start list");
nsAutoString classStr(aClassString); // copy to work buffer
classStr.Append(kNullCh); // put an extra null at the end
PRUnichar* start = (PRUnichar*)(const PRUnichar*)classStr.GetUnicode();
PRUnichar* end = start;
while (kNullCh != *start) {
while ((kNullCh != *start) && nsString::IsSpace(*start)) { // skip leading space
start++;
}
end = start;
while ((kNullCh != *end) && (PR_FALSE == nsString::IsSpace(*end))) { // look for space or end
end++;
}
*end = kNullCh; // end string here
if (start < end) {
*aClassList = new nsClassList(NS_NewAtom(start));
aClassList = &((*aClassList)->mNext);
}
start = ++end;
}
}

View File

@@ -0,0 +1,180 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
A set of helper classes used to implement attributes.
*/
#ifndef nsXULAttributes_h__
#define nsXULAttributes_h__
#include "nsIDOMAttr.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIScriptObjectOwner.h"
#include "nsIStyleRule.h"
#include "nsString.h"
#include "nsIAtom.h"
#include "nsVoidArray.h"
class nsIURI;
struct nsClassList {
nsClassList(nsIAtom* aAtom)
: mAtom(aAtom),
mNext(nsnull)
{
}
nsClassList(const nsClassList& aCopy)
: mAtom(aCopy.mAtom),
mNext(nsnull)
{
NS_ADDREF(mAtom);
if (nsnull != aCopy.mNext) {
mNext = new nsClassList(*(aCopy.mNext));
}
}
~nsClassList(void)
{
NS_IF_RELEASE(mAtom);
if (nsnull != mNext) {
delete mNext;
}
}
nsIAtom* mAtom;
nsClassList* mNext;
};
////////////////////////////////////////////////////////////////////////
class nsXULAttribute : public nsIDOMAttr,
public nsIScriptObjectOwner
{
private:
nsXULAttribute(nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aName,
const nsString& aValue);
virtual ~nsXULAttribute();
friend nsresult
NS_NewXULAttribute(nsXULAttribute** aResult,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aName,
const nsString& aValue);
public:
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMNode interface
NS_DECL_IDOMNODE
// nsIDOMAttr interface
NS_DECL_IDOMATTR
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// Implementation methods
void GetQualifiedName(nsString& aAttributeName);
PRInt32 GetNameSpaceID();
nsIAtom* GetName();
const nsString& GetValue();
// Publicly exposed to make life easier. This is a private class
// anyway.
PRInt32 mNameSpaceID;
nsIAtom* mName;
nsAutoString mValue;
private:
nsIContent* mContent;
void* mScriptObject;
};
nsresult
NS_NewXULAttribute(nsXULAttribute** aResult,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aName,
const nsString& aValue);
////////////////////////////////////////////////////////////////////////
class nsXULAttributes : public nsIDOMNamedNodeMap,
public nsIScriptObjectOwner
{
public:
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMNamedNodeMap interface
NS_DECL_IDOMNAMEDNODEMAP
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// Implementation methods
// VoidArray Helpers
PRInt32 Count() { return mAttributes.Count(); };
nsXULAttribute* ElementAt(PRInt32 i) { return (nsXULAttribute*)mAttributes.ElementAt(i); };
void AppendElement(nsXULAttribute* aElement) { mAttributes.AppendElement((void*)aElement); };
void RemoveElementAt(PRInt32 aIndex) { mAttributes.RemoveElementAt(aIndex); };
// Style Helpers
nsresult GetClasses(nsVoidArray& aArray) const;
nsresult HasClass(nsIAtom* aClass) const;
nsresult UpdateClassList(const nsString& aValue);
nsresult UpdateStyleRule(nsIURI* aDocURL, const nsString& aValue);
nsresult GetInlineStyleRule(nsIStyleRule*& aRule);
private:
friend nsresult
NS_NewXULAttributes(nsXULAttributes** aResult, nsIContent* aContent);
nsXULAttributes(nsIContent* aContent);
virtual ~nsXULAttributes();
static void
ParseClasses(const nsString& aClassString, nsClassList** aClassList);
nsIContent* mContent;
nsClassList* mClassList;
nsIStyleRule* mStyleRule;
nsVoidArray mAttributes;
void* mScriptObject;
};
nsresult
NS_NewXULAttributes(nsXULAttributes** aResult, nsIContent* aContent);
#endif // nsXULAttributes_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
This class serves as a base for aggregates that will implement a
per-element XUL API.
*/
#ifndef nsXULElement_h__
#define nsXULElement_h__
#include "nsIDOMXULElement.h"
class nsXULElement : public nsISupports
{
protected:
nsIDOMXULElement* mOuter;
nsXULElement(nsIDOMXULElement* aOuter) : mOuter(aOuter) {}
public:
virtual ~nsXULElement() {};
// nsISupports interface. Subclasses should use the
// NS_DECL/IMPL_ISUPPORTS_INHERITED macros to implement the
// nsISupports interface.
NS_IMETHOD_(nsrefcnt) AddRef() {
return mOuter->AddRef();
}
NS_IMETHOD_(nsrefcnt) Release() {
return mOuter->Release();
}
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aResult) {
return mOuter->QueryInterface(aIID, aResult);
}
};
#endif // nsXULElement_h__

View File

@@ -0,0 +1,539 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
This file provides the implementation for xul popup listener which
tracks xul popups, context menus, and tooltips
*/
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIXULPopupListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsRDFCID.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsIScriptContextOwner.h"
#include "nsIDOMXULDocument.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIDOMUIEvent.h"
#include "nsITimer.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
static NS_DEFINE_IID(kIXULPopupListenerIID, NS_IXULPOPUPLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDomEventListenerIID, NS_IDOMEVENTLISTENER_IID);
////////////////////////////////////////////////////////////////////////
// PopupListenerImpl
//
// This is the popup listener implementation for popup menus, context menus,
// and tooltips.
//
class XULPopupListenerImpl : public nsIXULPopupListener,
public nsIDOMMouseListener,
public nsIDOMMouseMotionListener
{
public:
XULPopupListenerImpl(void);
virtual ~XULPopupListenerImpl(void);
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsIXULPopupListener
NS_IMETHOD Init(nsIDOMElement* aElement, const XULPopupType& popupType);
// nsIDOMMouseListener
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent) ;
// nsIDOMMouseMotionListener
virtual nsresult MouseMove(nsIDOMEvent* aMouseEvent);
virtual nsresult DragMove(nsIDOMEvent* aMouseEvent) { return NS_OK; };
// nsIDOMEventListener
virtual nsresult HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; };
protected:
virtual nsresult LaunchPopup(nsIDOMEvent* anEvent);
virtual nsresult LaunchPopup(PRInt32 aClientX, PRInt32 aClientY) ;
nsresult FindDocumentForNode(nsIDOMNode* inNode, nsIDOMXULDocument** outDoc) ;
private:
// |mElement| is the node to which this listener is attached.
nsIDOMElement* mElement; // Weak ref. The element will go away first.
// The popup that is getting shown on top of mElement.
nsIDOMElement* mPopupContent;
// The type of the popup
XULPopupType popupType;
// The following members are not used unless |popupType| is tooltip.
// a timer for determining if a tooltip should be displayed.
static void sTooltipCallback ( nsITimer *aTimer, void *aClosure ) ;
nsCOMPtr<nsITimer> mTooltipTimer;
PRInt32 mMouseClientX, mMouseClientY; // mouse coordinates for tooltip event
// The node hovered over that fired the timer. This may turn into the node that
// triggered the tooltip, but only if the timer ever gets around to firing.
nsIDOMNode* mPossibleTooltipNode; // weak ref.
};
////////////////////////////////////////////////////////////////////////
XULPopupListenerImpl::XULPopupListenerImpl(void)
: mElement(nsnull), mPopupContent(nsnull),
mMouseClientX(0), mMouseClientY(0),
mPossibleTooltipNode(nsnull)
{
NS_INIT_REFCNT();
}
XULPopupListenerImpl::~XULPopupListenerImpl(void)
{
//XXX do we need to close the popup here? Will we get the right events as
//XXX the topLevel window is going away when the closebox is pressed?
}
NS_IMPL_ADDREF(XULPopupListenerImpl)
NS_IMPL_RELEASE(XULPopupListenerImpl)
NS_IMETHODIMP
XULPopupListenerImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(nsIXULPopupListener::GetIID()) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIXULPopupListener*, this);
NS_ADDREF_THIS();
return NS_OK;
}
else if (iid.Equals(nsIDOMMouseListener::GetIID())) {
*result = NS_STATIC_CAST(nsIDOMMouseListener*, this);
NS_ADDREF_THIS();
return NS_OK;
}
else if (iid.Equals(nsIDOMMouseMotionListener::GetIID())) {
*result = NS_STATIC_CAST(nsIDOMMouseMotionListener*, this);
NS_ADDREF_THIS();
return NS_OK;
}
// compiler problems with nsIDOMEventListener::GetIID() cause us to do it this
// way. Please excuse the lameness (hyatt and pinkerton).
else if (iid.Equals(kIDomEventListenerIID)) {
*result = (nsIDOMEventListener*)(nsIDOMMouseListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
XULPopupListenerImpl::Init(nsIDOMElement* aElement, const XULPopupType& popup)
{
mElement = aElement; // Weak reference. Don't addref it.
popupType = popup;
return NS_OK;
}
////////////////////////////////////////////////////////////////
// nsIDOMMouseListener
nsresult
XULPopupListenerImpl::MouseDown(nsIDOMEvent* aMouseEvent)
{
PRUint16 button;
nsCOMPtr<nsIDOMUIEvent> uiEvent;
uiEvent = do_QueryInterface(aMouseEvent);
if (!uiEvent) {
//non-ui event passed in. bad things.
return NS_OK;
}
// Get the node that was clicked on.
nsCOMPtr<nsIDOMNode> targetNode;
uiEvent->GetTarget( getter_AddRefs( targetNode ) );
// Get the document with the popup.
nsCOMPtr<nsIDocument> document;
nsCOMPtr<nsIContent> content = do_QueryInterface(mElement);
nsresult rv;
if (NS_FAILED(rv = content->GetDocument(*getter_AddRefs(document)))) {
NS_ERROR("Unable to retrieve the document.");
return rv;
}
// Turn the document into a XUL document so we can use SetPopupNode.
nsCOMPtr<nsIDOMXULDocument> xulDocument = do_QueryInterface(document);
if (xulDocument == nsnull) {
NS_ERROR("Popup attached to an element that isn't in XUL!");
return NS_ERROR_FAILURE;
}
// Store clicked-on node in xul document.
xulDocument->SetPopupNode( targetNode );
switch (popupType) {
case eXULPopupType_popup:
// Check for left mouse button down
uiEvent->GetButton(&button);
if (button == 1) {
// Time to launch a popup menu.
LaunchPopup(aMouseEvent);
}
break;
case eXULPopupType_context:
#ifdef XP_MAC
// XXX: Handle Mac (currently checks if CTRL key is down)
PRBool ctrlKey = PR_FALSE;
uiEvent->GetCtrlKey(&ctrlKey);
if (ctrlKey == PR_TRUE)
#else
// Check for right mouse button down
uiEvent->GetButton(&button);
if (button == 3)
#endif
{
// Time to launch a context menu.
LaunchPopup(aMouseEvent);
}
break;
case eXULPopupType_tooltip:
case eXULPopupType_blur:
// ignore
break;
}
return NS_OK;
}
//
// MouseMove
//
// If we're a tooltip, fire off a timer to see if a tooltip should be shown.
//
nsresult
XULPopupListenerImpl::MouseMove(nsIDOMEvent* aMouseEvent)
{
// make sure we're a tooltip. if not, bail.
if ( popupType != eXULPopupType_tooltip )
return NS_OK;
nsCOMPtr<nsIDOMUIEvent> uiEvent ( do_QueryInterface(aMouseEvent) );
if (!uiEvent)
return NS_OK;
// stash the coordinates of the event so that we can still get back to it from within the
// timer scallback. Also stash the node that started this so we can put it into the
// document later on (if the timer ever fires).
uiEvent->GetClientX(&mMouseClientX);
uiEvent->GetClientY(&mMouseClientY);
//XXX recognize when a popup is already up and immediately show the
//XXX tooltip for the new item if the dom element is different than
//XXX the element for which we are currently displaying the tip.
//XXX
//XXX for now, just be stupid to get things working.
if (mPopupContent || mTooltipTimer)
return NS_OK;
NS_NewTimer ( getter_AddRefs(mTooltipTimer) );
if ( mTooltipTimer ) {
nsCOMPtr<nsIDOMNode> eventTarget;
aMouseEvent->GetTarget(getter_AddRefs(eventTarget));
mPossibleTooltipNode = eventTarget.get();
mTooltipTimer->Init(sTooltipCallback, this, 500); // 500 ms delay
}
else
NS_WARNING ( "Could not create a timer for tooltip tracking" );
return NS_OK;
} // MouseMove
//
// MouseOut
//
// If we're a tooltip, hide any tip that might be showing and remove any
// timer that is pending since the mouse is no longer over this area.
//
nsresult
XULPopupListenerImpl::MouseOut(nsIDOMEvent* aMouseEvent)
{
// make sure we're a tooltip. if not, bail.
if ( popupType != eXULPopupType_tooltip )
return NS_OK;
if ( mTooltipTimer ) {
mTooltipTimer->Cancel();
mTooltipTimer = nsnull;
}
if ( mPopupContent ) {
mPopupContent->RemoveAttribute("menugenerated"); // hide the popup
mPopupContent->RemoveAttribute("menuactive");
mPopupContent = nsnull; // release the popup
// clear out the tooltip node on the document
nsCOMPtr<nsIDOMNode> eventTarget;
aMouseEvent->GetTarget(getter_AddRefs(eventTarget));
nsCOMPtr<nsIDOMXULDocument> doc;
FindDocumentForNode ( eventTarget, getter_AddRefs(doc) );
if ( doc )
doc->SetTooltipNode(nsnull);
}
return NS_OK;
} // MouseOut
//
// FindDocumentForNode
//
// Given a DOM content node, finds the XUL document associated with it
//
nsresult
XULPopupListenerImpl :: FindDocumentForNode ( nsIDOMNode* inElement, nsIDOMXULDocument** outDoc )
{
nsresult rv = NS_OK;
if ( !outDoc || !inElement )
return NS_ERROR_INVALID_ARG;
// get the document associated with this content element
nsCOMPtr<nsIDocument> document;
nsCOMPtr<nsIContent> content = do_QueryInterface(inElement);
if (!content)
return rv;
if (NS_FAILED(rv = content->GetDocument(*getter_AddRefs(document)))) {
NS_ERROR("Unable to retrieve the document.");
return rv;
}
// Turn the document into a XUL document so we can use getElementById
nsCOMPtr<nsIDOMXULDocument> xulDocument = do_QueryInterface(document);
if (xulDocument == nsnull) {
NS_ERROR("Popup attached to an element that isn't in XUL!");
return NS_ERROR_FAILURE;
}
*outDoc = xulDocument;
NS_ADDREF ( *outDoc );
return rv;
} // FindDocumentForNode
//
// LaunchPopup
//
nsresult
XULPopupListenerImpl::LaunchPopup ( nsIDOMEvent* anEvent )
{
// Retrieve our x and y position.
nsCOMPtr<nsIDOMUIEvent> uiEvent ( do_QueryInterface(anEvent) );
if (!uiEvent) {
//non-ui event passed in. bad things.
return NS_OK;
}
PRInt32 xPos, yPos;
uiEvent->GetClientX(&xPos);
uiEvent->GetClientY(&yPos);
return LaunchPopup(xPos, yPos);
}
//
// LaunchPopup
//
// Given the element on which the event was triggered and the mouse locations in
// Client and widget coordinates, popup a new window showing the appropriate
// content.
//
// This looks for an attribute on |aElement| of the appropriate popup type
// (popup, context, tooltip) and uses that attribute's value as an ID for
// the popup content in the document.
//
nsresult
XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY)
{
nsresult rv = NS_OK;
nsAutoString type("popup");
if ( popupType == eXULPopupType_context )
type = "context";
else if ( popupType == eXULPopupType_tooltip )
type = "tooltip";
nsAutoString identifier;
mElement->GetAttribute(type, identifier);
if (identifier == "")
return rv;
// Try to find the popup content and the document. We don't use FindDocumentForNode()
// in this case because we need the nsIDocument interface anyway for the script
// context.
nsCOMPtr<nsIDocument> document;
nsCOMPtr<nsIContent> content = do_QueryInterface(mElement);
if (NS_FAILED(rv = content->GetDocument(*getter_AddRefs(document)))) {
NS_ERROR("Unable to retrieve the document.");
return rv;
}
// Turn the document into a XUL document so we can use getElementById
nsCOMPtr<nsIDOMXULDocument> xulDocument = do_QueryInterface(document);
if (xulDocument == nsnull) {
NS_ERROR("Popup attached to an element that isn't in XUL!");
return NS_ERROR_FAILURE;
}
// XXX Handle the _child case for popups and context menus!
// Use getElementById to obtain the popup content and gracefully fail if
// we didn't find any popup content in the document.
nsCOMPtr<nsIDOMElement> popupContent;
if (NS_FAILED(rv = xulDocument->GetElementById(identifier, getter_AddRefs(popupContent)))) {
NS_ERROR("GetElementById had some kind of spasm.");
return rv;
}
if ( !popupContent )
return NS_OK;
// We have some popup content. Obtain our window.
nsIScriptContextOwner* owner = document->GetScriptContextOwner();
nsCOMPtr<nsIScriptContext> context;
if (NS_OK == owner->GetScriptContext(getter_AddRefs(context))) {
nsIScriptGlobalObject* global = context->GetGlobalObject();
if (global) {
// Get the DOM window
nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(global);
if (domWindow != nsnull) {
// Find out if we're anchored.
nsAutoString anchorAlignment("none");
mElement->GetAttribute("popupanchor", anchorAlignment);
nsAutoString popupAlignment("topleft");
mElement->GetAttribute("popupalign", popupAlignment);
PRInt32 xPos = aClientX, yPos = aClientY;
mPopupContent = popupContent.get();
nsCOMPtr<nsIDOMWindow> uselessPopup; // XXX Should go away.
domWindow->CreatePopup(mElement, popupContent,
xPos, yPos,
type, anchorAlignment, popupAlignment,
getter_AddRefs(uselessPopup));
}
NS_RELEASE(global);
}
}
NS_IF_RELEASE(owner);
return NS_OK;
}
//
// sTooltipCallback
//
// A timer callback, fired when the mouse has hovered inside of a frame for the
// appropriate amount of time. Getting to this point means that we should show the
// toolip.
//
// This relies on certain things being cached into the |aClosure| object passed to
// us by the timer:
// -- the x/y coordinates of the mouse
// -- the dom node the user hovered over
//
void
XULPopupListenerImpl :: sTooltipCallback (nsITimer *aTimer, void *aClosure)
{
XULPopupListenerImpl* self = NS_STATIC_CAST(XULPopupListenerImpl*, aClosure);
if ( self ) {
// set the node in the document that triggered the tooltip and show it
nsCOMPtr<nsIDOMXULDocument> doc;
self->FindDocumentForNode ( self->mPossibleTooltipNode, getter_AddRefs(doc) );
if ( doc ) {
nsCOMPtr<nsIDOMElement> element ( do_QueryInterface(self->mPossibleTooltipNode) );
if ( element ) {
// check that node is enabled before showing tooltip
nsAutoString disabledState;
element->GetAttribute ( "disabled", disabledState );
if ( disabledState != "true" ) {
doc->SetTooltipNode ( element );
self->LaunchPopup (self->mMouseClientX, self->mMouseClientY+16);
} // if node enabled
} else {
// Tooltip on non-element; e.g., text
doc->SetTooltipNode ( self->mPossibleTooltipNode );
self->LaunchPopup ( self->mMouseClientX, self->mMouseClientY+16);
}
} // if document
} // if "self" data valid
} // sTimerCallback
////////////////////////////////////////////////////////////////
nsresult
NS_NewXULPopupListener(nsIXULPopupListener** pop)
{
XULPopupListenerImpl* popup = new XULPopupListenerImpl();
if (!popup)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(popup);
*pop = popup;
return NS_OK;
}

View File

@@ -0,0 +1,369 @@
/* -*- 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.
*/
/*
Implementation methods for the XUL tree element APIs.
*/
#include "nsCOMPtr.h"
#include "nsRDFCID.h"
#include "nsXULTreeElement.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsINameSpaceManager.h"
#include "nsString.h"
nsIAtom* nsXULTreeElement::kSelectedAtom;
int nsXULTreeElement::gRefCnt = 0;
NS_IMPL_ADDREF_INHERITED(nsXULTreeElement, nsXULElement);
NS_IMPL_RELEASE_INHERITED(nsXULTreeElement, nsXULElement);
nsresult
nsXULTreeElement::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsCOMTypeInfo<nsIDOMXULTreeElement>::GetIID())) {
*aResult = NS_STATIC_CAST(nsIDOMXULTreeElement*, this);
}
else if (aIID.Equals(nsCOMTypeInfo<nsIXULTreeContent>::GetIID())) {
*aResult = NS_STATIC_CAST(nsIXULTreeContent*, this);
}
else {
return nsXULElement::QueryInterface(aIID, aResult);
}
NS_ADDREF(NS_REINTERPRET_CAST(nsISupports*, *aResult));
return NS_OK;
}
nsXULTreeElement::nsXULTreeElement(nsIDOMXULElement* aOuter)
:nsXULElement(aOuter)
{
if (gRefCnt++ == 0) {
kSelectedAtom = NS_NewAtom("selected");
}
nsresult rv;
nsRDFDOMNodeList* children;
rv = nsRDFDOMNodeList::Create(&children);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create DOM node list");
if (NS_FAILED(rv)) return;
mSelectedItems = children;
children = nsnull;
rv = nsRDFDOMNodeList::Create(&children);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create DOM node list");
if (NS_FAILED(rv)) return;
mSelectedCells = children;
}
nsXULTreeElement::~nsXULTreeElement()
{
NS_IF_RELEASE(mSelectedItems);
NS_IF_RELEASE(mSelectedCells);
if (--gRefCnt == 0) {
NS_IF_RELEASE(kSelectedAtom);
}
}
NS_IMETHODIMP
nsXULTreeElement::GetSelectedItems(nsIDOMNodeList** aSelectedItems)
{
NS_IF_ADDREF(mSelectedItems);
*aSelectedItems = mSelectedItems;
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::GetSelectedCells(nsIDOMNodeList** aSelectedCells)
{
NS_IF_ADDREF(mSelectedCells);
*aSelectedCells = mSelectedCells;
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectItem(nsIDOMXULElement* aTreeItem)
{
// Sanity check. If we're the only item, just bail.
PRUint32 length;
mSelectedItems->GetLength(&length);
if (length == 1) {
// See if the single item already selected is us.
nsCOMPtr<nsIDOMNode> domNode;
mSelectedItems->Item(0, getter_AddRefs(domNode));
nsCOMPtr<nsIDOMXULElement> treeItem = do_QueryInterface(domNode);
if (treeItem.get() == aTreeItem)
return NS_OK;
}
// First clear our selection.
ClearItemSelectionInternal();
// Now add ourselves to the selection by setting our selected attribute.
AddItemToSelectionInternal(aTreeItem);
FireOnSelectHandler();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectCell(nsIDOMXULElement* aTreeCell)
{
// Sanity check. If we're the only item, just bail.
PRUint32 length;
mSelectedCells->GetLength(&length);
if (length == 1) {
// See if the single item already selected is us.
nsCOMPtr<nsIDOMNode> domNode;
mSelectedCells->Item(0, getter_AddRefs(domNode));
nsCOMPtr<nsIDOMXULElement> treeCell = do_QueryInterface(domNode);
if (treeCell.get() == aTreeCell)
return NS_OK;
}
// First clear our selection.
ClearCellSelectionInternal();
// Now add ourselves to the selection by setting our selected attribute.
AddCellToSelectionInternal(aTreeCell);
FireOnSelectHandler();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::ClearItemSelection()
{
ClearItemSelectionInternal();
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::ClearItemSelectionInternal()
{
// Enumerate the elements and remove them from the selection.
PRUint32 length;
mSelectedItems->GetLength(&length);
for (PRUint32 i = 0; i < length; i++) {
nsCOMPtr<nsIDOMNode> node;
mSelectedItems->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
}
void
nsXULTreeElement::ClearCellSelectionInternal()
{
// Enumerate the elements and remove them from the selection.
PRUint32 length;
mSelectedCells->GetLength(&length);
for (PRUint32 i = 0; i < length; i++) {
nsCOMPtr<nsIDOMNode> node;
mSelectedCells->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
}
NS_IMETHODIMP
nsXULTreeElement::ClearCellSelection()
{
ClearCellSelectionInternal();
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::AddItemToSelectionInternal(nsIDOMXULElement* aTreeItem)
{
// Without clearing the selection, perform the add.
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, nsAutoString("true"), PR_TRUE);
}
NS_IMETHODIMP
nsXULTreeElement::AddItemToSelection(nsIDOMXULElement* aTreeItem)
{
// Without clearing the selection, perform the add.
AddItemToSelectionInternal(aTreeItem);
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::RemoveItemFromSelectionInternal(nsIDOMXULElement* aTreeItem)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
NS_IMETHODIMP
nsXULTreeElement::RemoveItemFromSelection(nsIDOMXULElement* aTreeItem)
{
RemoveItemFromSelectionInternal(aTreeItem);
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::AddCellToSelectionInternal(nsIDOMXULElement* aTreeCell)
{
// Without clearing the selection, perform the add.
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeCell);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, nsAutoString("true"), PR_TRUE);
}
NS_IMETHODIMP
nsXULTreeElement::AddCellToSelection(nsIDOMXULElement* aTreeCell)
{
AddCellToSelectionInternal(aTreeCell);
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::RemoveCellFromSelectionInternal(nsIDOMXULElement* aTreeCell)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeCell);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
NS_IMETHODIMP
nsXULTreeElement::RemoveCellFromSelection(nsIDOMXULElement* aTreeCell)
{
RemoveCellFromSelectionInternal(aTreeCell);
FireOnSelectHandler();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::ToggleItemSelection(nsIDOMXULElement* aTreeItem)
{
nsAutoString isSelected;
aTreeItem->GetAttribute("selected", isSelected);
if (isSelected == "true")
RemoveItemFromSelectionInternal(aTreeItem);
else AddItemToSelectionInternal(aTreeItem);
FireOnSelectHandler();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::ToggleCellSelection(nsIDOMXULElement* aTreeCell)
{
nsAutoString isSelected;
aTreeCell->GetAttribute("selected", isSelected);
if (isSelected == "true")
RemoveCellFromSelectionInternal(aTreeCell);
else AddCellToSelectionInternal(aTreeCell);
FireOnSelectHandler();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)
{
// XXX Fill in.
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)
{
// XXX Fill in.
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectAll()
{
// XXX Select anything that isn't selected.
// Write later.
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::InvertSelection()
{
// XXX Woo hoo. Write this later.
// Yikes. Involves an enumeration of the whole tree.
return NS_OK;
}
nsresult
nsXULTreeElement::FireOnSelectHandler()
{
nsCOMPtr<nsIContent> content = do_QueryInterface(mOuter);
nsCOMPtr<nsIDocument> document;
content->GetDocument(*getter_AddRefs(document));
// The frame code can suppress the firing of this handler by setting an attribute
// for us. Look for that and bail if it's present.
nsCOMPtr<nsIAtom> kSuppressSelectChange = dont_AddRef(NS_NewAtom("suppressonselect"));
nsAutoString value;
content->GetAttribute(kNameSpaceID_None, kSuppressSelectChange, value);
if (value == "true")
return NS_OK;
PRInt32 count = document->GetNumberOfShells();
for (PRInt32 i = 0; i < count; i++) {
nsIPresShell* shell = document->GetShellAt(i);
if (nsnull == shell)
continue;
// Retrieve the context in which our DOM event will fire.
nsCOMPtr<nsIPresContext> aPresContext;
shell->GetPresContext(getter_AddRefs(aPresContext));
NS_RELEASE(shell);
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_FORM_SELECTED;
content->HandleDOMEvent(*aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
}
return NS_OK;
}

View File

@@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
An aggregate object that implements the XUL tree widget APIs
*/
#ifndef nsXULTreeElement_h__
#define nsXULTreeElement_h__
#include "nsXULElement.h"
#include "nsIDOMXULTreeElement.h"
#include "nsIXULTreeContent.h"
#include "nsRDFDOMNodeList.h"
class nsXULTreeElement : public nsXULElement,
public nsIDOMXULTreeElement,
public nsIXULTreeContent
{
public:
nsXULTreeElement(nsIDOMXULElement* aOuter);
~nsXULTreeElement();
NS_DECL_ISUPPORTS_INHERITED
// nsIDOMNode interface
NS_FORWARD_IDOMNODE(mOuter->);
// nsIDOMElement interface
NS_FORWARD_IDOMELEMENT(mOuter->);
// nsIDOMXULElement interface
NS_FORWARD_IDOMXULELEMENT(mOuter->);
// nsIDOMXULTreeElement interface
NS_DECL_IDOMXULTREEELEMENT
// nsIXULTreeContent interface
NS_IMETHOD FireOnSelectHandler();
static nsIAtom* kSelectedAtom;
static int gRefCnt;
protected:
// Helpers
void ClearItemSelectionInternal();
void ClearCellSelectionInternal();
void AddItemToSelectionInternal(nsIDOMXULElement* aTreeItem);
void RemoveItemFromSelectionInternal(nsIDOMXULElement* aTreeItem);
void AddCellToSelectionInternal(nsIDOMXULElement* aTreeCell);
void RemoveCellFromSelectionInternal(nsIDOMXULElement* aTreeCell);
protected:
nsRDFDOMNodeList* mSelectedItems;
nsRDFDOMNodeList* mSelectedCells;
};
#endif // nsXULTreeElement_h__

View File

@@ -0,0 +1,27 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
interface nsIDOMXULCommandDispatcher;
[scriptable, uuid(D5B61B82-1DA4-11d3-BF87-00105A1B0627)]
interface nsIController : nsISupports {
attribute nsIDOMXULCommandDispatcher commandDispatcher;
boolean IsCommandEnabled(in string command);
void DoCommand(in string command);
};

View File

@@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 nsIXULContentSink_h__
#define nsIXULContentSink_h__
#include "nsIXMLContentSink.h"
class nsIDocument;
class nsIRDFDataSource;
// {E49AA620-C16C-11d2-A6AA-00104BDE6048}
#define NS_IXULCONTENTSINK_IID \
{ 0xe49aa620, 0xc16c, 0x11d2, { 0xa6, 0xaa, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
class nsIXULContentSink : public nsIXMLContentSink
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IXULCONTENTSINK_IID; return iid; }
NS_IMETHOD Init(nsIDocument* aDocument) = 0;
NS_IMETHOD UnblockNextOverlay() = 0;
NS_IMETHOD UpdateOverlayCounters(PRInt32 aDelta) = 0;
};
nsresult
NS_NewXULContentSink(nsIXULContentSink** aResult);
#endif // nsIXULContentSink_h__

View File

@@ -0,0 +1,41 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* DOM stubs so that we can pass DOM objects across XPConnect */
%{C++
/* C++ should ignore this file because there are real DOM interfaces
elsewhere, so if 0 it out
*/
#if 0
%}
#include "domstubs.idl"
[scriptable, uuid(0574ed81-c088-11d2-96ed-00104b7b7deb)]
interface nsIDOMXULElement : nsIDOMElement {};
[scriptable, uuid(a6cf90ec-15b3-11d2-932e-00805f8add32)]
interface nsIDOMXULTreeElement : nsIDOMXULElement {};
[scriptable, uuid(f3c50361-14fe-11d3-bf87-00105a1b0627)]
interface nsIDOMXULFocusTracker : nsISupports {};
%{C++
#endif
%}

View File

@@ -0,0 +1,317 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
Maps IDs to elements.
*/
#include "nsCRT.h"
#include "nsElementMap.h"
#include "nsIContent.h"
#include "nsISupportsArray.h"
#include "nsString.h"
#include "prlog.h"
#ifdef PR_LOGGING
static PRLogModuleInfo* gMapLog;
#endif
nsElementMap::nsElementMap()
{
// Create a table for mapping IDs to elements in the content tree.
static PRInt32 kInitialResourceTableSize = 1023;
mMap = PL_NewHashTable(kInitialResourceTableSize,
Hash,
Compare,
PL_CompareValues,
nsnull,
nsnull);
NS_ASSERTION(mMap != nsnull, "could not create hash table for resources");
#ifdef PR_LOGGING
if (! gMapLog)
gMapLog = PR_NewLogModule("nsElementMap");
PR_LOG(gMapLog, PR_LOG_ALWAYS,
("xulelemap(%p) created", this));
#endif
}
nsElementMap::~nsElementMap()
{
if (mMap) {
PL_HashTableEnumerateEntries(mMap, ReleaseContentList, nsnull);
PL_HashTableDestroy(mMap);
}
PR_LOG(gMapLog, PR_LOG_ALWAYS,
("xulelemap(%p) destroyed", this));
}
PRIntn
nsElementMap::ReleaseContentList(PLHashEntry* aHashEntry, PRIntn aIndex, void* aClosure)
{
PRUnichar* id =
NS_REINTERPRET_CAST(PRUnichar*, NS_CONST_CAST(void*, aHashEntry->key));
delete[] id;
ContentListItem* head =
NS_REINTERPRET_CAST(ContentListItem*, aHashEntry->value);
while (head) {
ContentListItem* doomed = head;
head = head->mNext;
delete doomed;
}
return HT_ENUMERATE_NEXT;
}
nsresult
nsElementMap::Add(const nsString& aID, nsIContent* aContent)
{
NS_PRECONDITION(mMap != nsnull, "not initialized");
if (! mMap)
return NS_ERROR_NOT_INITIALIZED;
ContentListItem* head =
(ContentListItem*) PL_HashTableLookup(mMap, aID.GetUnicode());
if (! head) {
head = new ContentListItem(aContent);
if (! head)
return NS_ERROR_OUT_OF_MEMORY;
PRUnichar* key = new PRUnichar[aID.Length() + 1];
if (! key)
return NS_ERROR_OUT_OF_MEMORY;
nsCRT::memcpy(key, aID.GetUnicode(), aID.Length() * sizeof(PRUnichar));
key[aID.Length()] = PRUnichar(0);
PL_HashTableAdd(mMap, key, head);
NS_ADDREF(aContent);
}
else {
while (1) {
if (head->mContent == aContent) {
// This can happen if an element that was created via
// frame construction code is then "appended" to the
// content model with aNotify == PR_TRUE. If you see
// this warning, it's an indication that you're
// unnecessarily notifying the frame system, and
// potentially causing unnecessary reflow.
//NS_ERROR("element was already in the map");
PR_LOG(gMapLog, PR_LOG_ALWAYS,
("xulelemap(%p) dup [%p] <-- %s\n",
this, aContent, (const char*) nsCAutoString(aID)));
return NS_OK;
}
if (! head->mNext)
break;
head = head->mNext;
}
head->mNext = new ContentListItem(aContent);
if (! head->mNext)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(aContent);
}
PR_LOG(gMapLog, PR_LOG_ALWAYS,
("xulelemap(%p) add [%p] <-- %s\n",
this, aContent, (const char*) nsCAutoString(aID)));
return NS_OK;
}
nsresult
nsElementMap::Remove(const nsString& aID, nsIContent* aContent)
{
NS_PRECONDITION(mMap != nsnull, "not initialized");
if (! mMap)
return NS_ERROR_NOT_INITIALIZED;
PR_LOG(gMapLog, PR_LOG_ALWAYS,
("xulelemap(%p) remove [%p] <-- %s\n",
this, aContent, (const char*) nsCAutoString(aID)));
PLHashEntry** hep = PL_HashTableRawLookup(mMap,
Hash(aID.GetUnicode()),
aID.GetUnicode());
// XXX Don't comment out this assert: if you get here, something
// has gone dreadfully, horribly wrong. Curse. Scream. File a bug
// against waterson@netscape.com.
NS_ASSERTION(hep != nsnull && *hep != nsnull, "attempt to remove an element that was never added");
if (!hep || !*hep)
return NS_ERROR_ILLEGAL_VALUE;
ContentListItem* head = NS_REINTERPRET_CAST(ContentListItem*, (*hep)->value);
if (head->mContent == aContent) {
NS_RELEASE(aContent);
ContentListItem* next = head->mNext;
if (next) {
(*hep)->value = next;
}
else {
// It was the last reference in the table
PRUnichar* key = NS_REINTERPRET_CAST(PRUnichar*, NS_CONST_CAST(void*, (*hep)->key));
PL_HashTableRawRemove(mMap, hep, *hep);
delete[] key;
}
delete head;
}
else {
ContentListItem* item = head->mNext;
while (item) {
if (item->mContent == aContent) {
head->mNext = item->mNext;
NS_RELEASE(aContent);
delete item;
break;
}
head = item;
item = item->mNext;
}
}
return NS_OK;
}
nsresult
nsElementMap::Find(const nsString& aID, nsISupportsArray* aResults)
{
NS_PRECONDITION(mMap != nsnull, "not initialized");
if (! mMap)
return NS_ERROR_NOT_INITIALIZED;
aResults->Clear();
ContentListItem* item =
NS_REINTERPRET_CAST(ContentListItem*, PL_HashTableLookup(mMap, aID.GetUnicode()));
while (item) {
aResults->AppendElement(item->mContent);
item = item->mNext;
}
return NS_OK;
}
nsresult
nsElementMap::FindFirst(const nsString& aID, nsIContent** aResult)
{
NS_PRECONDITION(mMap != nsnull, "not initialized");
if (! mMap)
return NS_ERROR_NOT_INITIALIZED;
ContentListItem* item =
NS_REINTERPRET_CAST(ContentListItem*, PL_HashTableLookup(mMap, aID.GetUnicode()));
if (item) {
*aResult = item->mContent;
NS_ADDREF(*aResult);
}
else {
*aResult = nsnull;
}
return NS_OK;
}
nsresult
nsElementMap::Enumerate(nsElementMapEnumerator aEnumerator, void* aClosure)
{
EnumerateClosure closure = { aEnumerator, aClosure };
PL_HashTableEnumerateEntries(mMap, EnumerateImpl, &closure);
return NS_OK;
}
PRIntn
nsElementMap::EnumerateImpl(PLHashEntry* aHashEntry, PRIntn aIndex, void* aClosure)
{
EnumerateClosure* closure = NS_REINTERPRET_CAST(EnumerateClosure*, aClosure);
const PRUnichar* id =
NS_REINTERPRET_CAST(const PRUnichar*, aHashEntry->key);
ContentListItem** link =
NS_REINTERPRET_CAST(ContentListItem**, &aHashEntry->value);
ContentListItem* item = *link;
while (item) {
PRIntn result = (*closure->mEnumerator)(id, item->mContent, closure->mClosure);
if (result == HT_ENUMERATE_REMOVE) {
NS_RELEASE(item->mContent);
*link = item->mNext;
if ((! *link) && (link == NS_REINTERPRET_CAST(ContentListItem**, &aHashEntry->value))) {
PRUnichar* key = NS_CONST_CAST(PRUnichar*, id);
delete[] key;
return HT_ENUMERATE_REMOVE;
}
}
else {
link = &item->mNext;
}
item = item->mNext;
}
return HT_ENUMERATE_NEXT;
}
PLHashNumber
nsElementMap::Hash(const void* aKey)
{
PLHashNumber result = 0;
const PRUnichar* s = NS_REINTERPRET_CAST(const PRUnichar*, aKey);
while (*s != nsnull) {
result = (result >> 28) ^ (result << 4) ^ *s;
++s;
}
return result;
}
PRIntn
nsElementMap::Compare(const void* aLeft, const void* aRight)
{
return 0 == nsCRT::strcmp(NS_REINTERPRET_CAST(const PRUnichar*, aLeft),
NS_REINTERPRET_CAST(const PRUnichar*, aRight));
}

View File

@@ -0,0 +1,93 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
Maintains one-to-many mapping between element IDs and content
nodes.
*/
#ifndef nsElementMap_h__
#define nsElementMap_h__
#include "nscore.h"
#include "nsError.h"
#include "plhash.h"
class nsString;
class nsIContent;
class nsISupportsArray;
class nsElementMap
{
private:
PLHashTable* mMap;
class ContentListItem {
public:
ContentListItem(nsIContent* aContent)
: mNext(nsnull), mContent(aContent) {}
ContentListItem* mNext;
nsIContent* mContent;
};
static PLHashNumber
Hash(const void* akey);
static PRIntn
Compare(const void* aLeft, const void* aRight);
static PRIntn
ReleaseContentList(PLHashEntry* aHashEntry, PRIntn aIndex, void* aClosure);
public:
nsElementMap(void);
virtual ~nsElementMap();
nsresult
Add(const nsString& aID, nsIContent* aContent);
nsresult
Remove(const nsString& aID, nsIContent* aContent);
nsresult
Find(const nsString& aID, nsISupportsArray* aResults);
nsresult
FindFirst(const nsString& aID, nsIContent** aContent);
typedef PRIntn (*nsElementMapEnumerator)(const nsString& aID,
nsIContent* aElement,
void* aClosure);
nsresult
Enumerate(nsElementMapEnumerator aEnumerator, void* aClosure);
private:
struct EnumerateClosure {
nsElementMapEnumerator mEnumerator;
void* mClosure;
};
static PRIntn
EnumerateImpl(PLHashEntry* aHashEntry, PRIntn aIndex, void* aClosure);
};
#endif // nsElementMap_h__

View File

@@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 nsForwardReference_h__
#define nsForwardReference_h__
class nsForwardReference
{
protected:
nsForwardReference() {}
public:
virtual ~nsForwardReference() {}
enum Result {
eResolveSucceeded, // resolution succeeded, i'm done
eResolveLater, // couldn't resolve, try me later
eResolveError // something bad happened, don't try again
};
/**
* Attempt to resolve the forward reference.
*
* @return a Result that tells the resolver how to treat
* the reference.
*/
virtual Result Resolve() = 0;
};
#endif // nsForwardReference_h__

View File

@@ -0,0 +1,456 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
This file provides the implementation for the sort service manager.
*/
#include "nsCOMPtr.h"
#include "nsVoidArray.h"
#include "nsIDOMElement.h"
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIXULCommandDispatcher.h"
#include "nsIDOMFocusListener.h"
#include "nsRDFCID.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsIScriptContextOwner.h"
#include "nsIDOMXULDocument.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIDOMUIEvent.h"
#include "nsIDOMXULElement.h"
#include "nsIController.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDomNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDomElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDomEventListenerIID, NS_IDOMEVENTLISTENER_IID);
////////////////////////////////////////////////////////////////////////
// XULCommandDispatcherImpl
//
// This is the focus manager for XUL documents.
//
class XULCommandDispatcherImpl : public nsIDOMXULCommandDispatcher,
public nsIXULCommandDispatcher,
public nsIDOMFocusListener,
public nsIScriptObjectOwner
{
public:
XULCommandDispatcherImpl(void);
virtual ~XULCommandDispatcherImpl(void);
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMXULCommandDispatcher interface
NS_DECL_IDOMXULCOMMANDDISPATCHER
// nsIDOMFocusListener
virtual nsresult Focus(nsIDOMEvent* aEvent);
virtual nsresult Blur(nsIDOMEvent* aEvent);
// nsIDOMEventListener
virtual nsresult HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; };
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
protected:
void* mScriptObject; // ????
// XXX THis was supposed to be WEAK, but c'mon, that's an accident
// waiting to happen! If somebody deletes the node, then asks us
// for the focus, we'll get killed!
nsCOMPtr<nsIDOMElement> mCurrentElement; // [OWNER]
class Updater {
public:
Updater(nsIDOMElement* aElement,
const nsString& aEvents,
const nsString& aTargets)
: mElement(aElement),
mEvents(aEvents),
mTargets(aTargets),
mNext(nsnull)
{}
nsIDOMElement* mElement; // [WEAK]
nsString mEvents;
nsString mTargets;
Updater* mNext;
};
Updater* mUpdaters;
PRBool Matches(const nsString& aList, const nsString& aElement);
};
////////////////////////////////////////////////////////////////////////
XULCommandDispatcherImpl::XULCommandDispatcherImpl(void)
: mScriptObject(nsnull), mCurrentElement(nsnull), mUpdaters(nsnull)
{
NS_INIT_REFCNT();
}
XULCommandDispatcherImpl::~XULCommandDispatcherImpl(void)
{
while (mUpdaters) {
Updater* doomed = mUpdaters;
mUpdaters = mUpdaters->mNext;
delete doomed;
}
}
NS_IMPL_ADDREF(XULCommandDispatcherImpl)
NS_IMPL_RELEASE(XULCommandDispatcherImpl)
NS_IMETHODIMP
XULCommandDispatcherImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kISupportsIID)) {
*result = (nsISupports*)(nsIXULCommandDispatcher*)this;
NS_ADDREF_THIS();
return NS_OK;
}
else if (iid.Equals(nsIXULCommandDispatcher::GetIID())) {
*result = NS_STATIC_CAST(nsIXULCommandDispatcher*, this);
NS_ADDREF_THIS();
return NS_OK;
}
else if (iid.Equals(nsIDOMXULCommandDispatcher::GetIID())) {
*result = NS_STATIC_CAST(nsIDOMXULCommandDispatcher*, this);
NS_ADDREF_THIS();
return NS_OK;
}
else if (iid.Equals(nsIDOMFocusListener::GetIID())) {
*result = NS_STATIC_CAST(nsIDOMFocusListener*, this);
NS_ADDREF_THIS();
return NS_OK;
}
else if (iid.Equals(kIDomEventListenerIID)) {
*result = (nsIDOMEventListener*)(nsIDOMFocusListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
else if (iid.Equals(kIScriptObjectOwnerIID)) {
*result = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////
// nsIDOMXULTracker Interface
NS_IMETHODIMP
XULCommandDispatcherImpl::GetFocusedElement(nsIDOMElement** aElement)
{
*aElement = mCurrentElement;
NS_IF_ADDREF(*aElement);
return NS_OK;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::SetFocusedElement(nsIDOMElement* aElement)
{
mCurrentElement = aElement;
UpdateCommands(nsAutoString(aElement ? "focus" : "blur"));
return NS_OK;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::GetFocusedWindow(nsIDOMWindow** aElement)
{
// XXX Implement
return NS_OK;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::SetFocusedWindow(nsIDOMWindow* aElement)
{
// XXX Implement
return NS_OK;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::AddCommandUpdater(nsIDOMElement* aElement,
const nsString& aEvents,
const nsString& aTargets)
{
NS_PRECONDITION(aElement != nsnull, "null ptr");
if (! aElement)
return NS_ERROR_NULL_POINTER;
Updater* updater = mUpdaters;
Updater** link = &mUpdaters;
while (updater) {
if (updater->mElement == aElement) {
// If the updater was already in the list, then replace
// (?) the 'events' and 'targets' filters with the new
// specification.
updater->mEvents = aEvents;
updater->mTargets = aTargets;
return NS_OK;
}
link = &(updater->mNext);
updater = updater->mNext;
}
// If we get here, this is a new updater. Append it to the list.
updater = new Updater(aElement, aEvents, aTargets);
if (! updater)
return NS_ERROR_OUT_OF_MEMORY;
*link = updater;
return NS_OK;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::RemoveCommandUpdater(nsIDOMElement* aElement)
{
NS_PRECONDITION(aElement != nsnull, "null ptr");
if (! aElement)
return NS_ERROR_NULL_POINTER;
Updater* updater = mUpdaters;
Updater** link = &mUpdaters;
while (updater) {
if (updater->mElement == aElement) {
*link = updater->mNext;
delete updater;
return NS_OK;
}
link = &(updater->mNext);
updater = updater->mNext;
}
// Hmm. Not found. Oh well.
return NS_OK;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::UpdateCommands(const nsString& aEventName)
{
nsresult rv;
nsAutoString id;
if (mCurrentElement) {
rv = mCurrentElement->GetAttribute(nsAutoString("id"), id);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element's id");
if (NS_FAILED(rv)) return rv;
}
for (Updater* updater = mUpdaters; updater != nsnull; updater = updater->mNext) {
// Skip any nodes that don't match our 'events' or 'targets'
// filters.
if (! Matches(updater->mEvents, aEventName))
continue;
if (! Matches(updater->mTargets, id))
continue;
nsCOMPtr<nsIContent> content = do_QueryInterface(updater->mElement);
NS_ASSERTION(content != nsnull, "not an nsIContent");
if (! content)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIDocument> document;
rv = content->GetDocument(*getter_AddRefs(document));
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get document");
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(document != nsnull, "element has no document");
if (! document)
continue;
PRInt32 count = document->GetNumberOfShells();
for (PRInt32 i = 0; i < count; i++) {
nsCOMPtr<nsIPresShell> shell = dont_AddRef(document->GetShellAt(i));
if (! shell)
continue;
// Retrieve the context in which our DOM event will fire.
nsCOMPtr<nsIPresContext> context;
rv = shell->GetPresContext(getter_AddRefs(context));
if (NS_FAILED(rv)) return rv;
// Handle the DOM event
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_XUL_COMMAND_UPDATE;
content->HandleDOMEvent(*context, &event, nsnull, NS_EVENT_FLAG_INIT, status);
}
}
return NS_OK;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::GetController(nsIController** aResult)
{
if (mCurrentElement) {
nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(mCurrentElement);
if (xulElement)
return xulElement->GetController(aResult);
}
*aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::SetController(nsIController* aController)
{
if (mCurrentElement) {
nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(mCurrentElement);
if (xulElement)
return xulElement->SetController(aController);
}
return NS_OK;
}
/////
// nsIDOMFocusListener
/////
nsresult
XULCommandDispatcherImpl::Focus(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMNode> t;
aEvent->GetTarget(getter_AddRefs(t));
nsCOMPtr<nsIDOMElement> target = do_QueryInterface(t);
if (target) {
SetFocusedElement(target);
UpdateCommands("focus");
}
return NS_OK;
}
nsresult
XULCommandDispatcherImpl::Blur(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMNode> t;
aEvent->GetTarget(getter_AddRefs(t));
nsCOMPtr<nsIDOMElement> target = do_QueryInterface(t);
if (target == mCurrentElement) {
SetFocusedElement(nsnull);
UpdateCommands("blur");
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIScriptObjectOwner interface
NS_IMETHODIMP
XULCommandDispatcherImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult res = NS_OK;
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
if (nsnull == mScriptObject) {
res = NS_NewScriptXULCommandDispatcher(aContext, (nsISupports *)(nsIDOMXULCommandDispatcher*)this, global, (void**)&mScriptObject);
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return res;
}
NS_IMETHODIMP
XULCommandDispatcherImpl::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
PRBool
XULCommandDispatcherImpl::Matches(const nsString& aList, const nsString& aElement)
{
if (aList == "*")
return PR_TRUE; // match _everything_!
PRInt32 indx = aList.Find(aElement);
if (indx == -1)
return PR_FALSE; // not in the list at all
// okay, now make sure it's not a substring snafu; e.g., 'ur'
// found inside of 'blur'.
if (indx > 0) {
PRUnichar ch = aList[indx - 1];
if (! nsString::IsSpace(ch) && ch != PRUnichar(','))
return PR_FALSE;
}
if (indx + aElement.Length() < aList.Length()) {
PRUnichar ch = aList[indx + aElement.Length()];
if (! nsString::IsSpace(ch) && ch != PRUnichar(','))
return PR_FALSE;
}
return PR_TRUE;
}
////////////////////////////////////////////////////////////////
nsresult
NS_NewXULCommandDispatcher(nsIXULCommandDispatcher** CommandDispatcher)
{
XULCommandDispatcherImpl* focus = new XULCommandDispatcherImpl();
if (!focus)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(focus);
*CommandDispatcher = focus;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,91 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
A content model builder interface. An object that implements this
interface is associated with an nsIXULDocument object to construct
an NGLayout content model.
*/
#ifndef nsIRDFContentModelBuilder_h__
#define nsIRDFContentModelBuilder_h__
#include "nsISupports.h"
class nsIAtom;
class nsIContent;
class nsIRDFCompositeDataSource;
class nsIXULDocument;
class nsIRDFNode;
class nsIRDFResource;
// {541AFCB0-A9A3-11d2-8EC5-00805F29F370}
#define NS_IRDFCONTENTMODELBUILDER_IID \
{ 0x541afcb0, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFContentModelBuilder : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IRDFCONTENTMODELBUILDER_IID; return iid; }
/**
* Point the content model builder to the document. The content model
* builder must not reference count the document.
*/
NS_IMETHOD SetDocument(nsIXULDocument* aDocument) = 0;
NS_IMETHOD SetDataBase(nsIRDFCompositeDataSource* aDataBase) = 0;
NS_IMETHOD GetDataBase(nsIRDFCompositeDataSource** aDataBase) = 0;
/**
* Set the root element from which this content model will
* operate.
*/
NS_IMETHOD CreateRootContent(nsIRDFResource* aResource) = 0;
NS_IMETHOD SetRootContent(nsIContent* aElement) = 0;
/**
* Construct the contents for a container element.
*/
NS_IMETHOD CreateContents(nsIContent* aElement) = 0;
/**
* 'Open' a container element that was closed before. This gives
* the container a chance to populate its contents.
*/
NS_IMETHOD OpenContainer(nsIContent* aContainer) = 0;
/**
* 'Close' an open container. This gives the container a chance to
* release unused content nodes.
*/
NS_IMETHOD CloseContainer(nsIContent* aContainer) = 0;
/**
* Rebuild the contents of a container.
*/
NS_IMETHOD RebuildContainer(nsIContent* aContainer) = 0;
};
extern nsresult NS_NewXULTemplateBuilder(nsIRDFContentModelBuilder** aResult);
extern nsresult NS_NewRDFXULBuilder(nsIRDFContentModelBuilder** aResult);
#endif // nsIRDFContentModelBuilder_h__

View File

@@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIRDFCompositeDataSource.idl"
#include "nsIRDFResource.idl"
[ptr] native nsIRDFResourceArray( nsIRDFResource *);
interface nsIContent;
interface nsIDOMNode;
[scriptable, uuid(BFD05261-834C-11d2-8EAC-00805F29F371)]
interface nsIXULSortService : nsISupports
{
void Sort(in nsIDOMNode node, in string sortResource, in string sortDirection);
[noscript] void OpenContainer(in nsIRDFCompositeDataSource db, in nsIContent container,
in nsIRDFResourceArray flatArray, in long numElements, in long elementSize);
[noscript] void InsertContainerNode(in nsIContent container, in nsIContent node, in boolean aNotify);
};
%{C++
extern nsresult
NS_NewXULSortService(nsIXULSortService **result);
%}

View File

@@ -0,0 +1,776 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
A package of routines shared by the XUL content code.
*/
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIRDFNode.h"
#include "nsINameSpace.h"
#include "nsINameSpaceManager.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsITextContent.h"
#include "nsIURL.h"
#include "nsIXMLContent.h"
#include "nsIXULContentUtils.h"
#include "nsLayoutCID.h"
#include "nsNeckoUtil.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "prlog.h"
#include "prtime.h"
#include "rdf.h"
#include "rdfutil.h"
#include "nsILocale.h"
#include "nsLocaleCID.h"
#include "nsILocaleFactory.h"
#include "nsIDateTimeFormat.h"
#include "nsDateTimeFormatCID.h"
#include "nsIScriptableDateFormat.h"
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFIntIID, NS_IRDFINT_IID);
static NS_DEFINE_IID(kIRDFDateIID, NS_IRDFDATE_IID);
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID); // XXX grr...
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kLocaleFactoryCID, NS_LOCALEFACTORY_CID);
static NS_DEFINE_IID(kILocaleFactoryIID, NS_ILOCALEFACTORY_IID);
static NS_DEFINE_CID(kLocaleCID, NS_LOCALE_CID);
static NS_DEFINE_IID(kILocaleIID, NS_ILOCALE_IID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID);
static NS_DEFINE_CID(kDateTimeFormatIID, NS_IDATETIMEFORMAT_IID);
//------------------------------------------------------------------------
class nsXULContentUtils : public nsIXULContentUtils
{
protected:
nsXULContentUtils();
nsresult Init();
virtual ~nsXULContentUtils();
friend NS_IMETHODIMP
NS_NewXULContentUtils(nsISupports* aOuter, const nsIID& aIID, void** aResult);
static nsrefcnt gRefCnt;
static nsIRDFService* gRDF;
static nsINameSpaceManager* gNameSpaceManager;
static nsIDateTimeFormat* gFormat;
public:
// nsISupports methods
NS_DECL_ISUPPORTS
// nsIXULContentUtils methods
NS_IMETHOD
AttachTextNode(nsIContent* parent, nsIRDFNode* value);
NS_IMETHOD
FindChildByTag(nsIContent *aElement,
PRInt32 aNameSpaceID,
nsIAtom* aTag,
nsIContent **aResult);
NS_IMETHOD
FindChildByResource(nsIContent* aElement,
nsIRDFResource* aResource,
nsIContent** aResult);
NS_IMETHOD
GetElementResource(nsIContent* aElement, nsIRDFResource** aResult);
NS_IMETHOD
GetElementRefResource(nsIContent* aElement, nsIRDFResource** aResult);
NS_IMETHOD
GetTextForNode(nsIRDFNode* aNode, nsString& aResult);
NS_IMETHOD
GetElementLogString(nsIContent* aElement, nsString& aResult);
NS_IMETHOD
GetAttributeLogString(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aTag, nsString& aResult);
NS_IMETHOD
MakeElementURI(nsIDocument* aDocument, const nsString& aElementID, nsCString& aURI);
NS_IMETHOD
MakeElementResource(nsIDocument* aDocument, const nsString& aElementID, nsIRDFResource** aResult);
NS_IMETHOD
MakeElementID(nsIDocument* aDocument, const nsString& aURI, nsString& aElementID);
NS_IMETHOD_(PRBool)
IsContainedBy(nsIContent* aElement, nsIContent* aContainer);
NS_IMETHOD
GetResource(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult);
NS_IMETHOD
GetResource(PRInt32 aNameSpaceID, const nsString& aAttribute, nsIRDFResource** aResult);
};
nsrefcnt nsXULContentUtils::gRefCnt;
nsIRDFService* nsXULContentUtils::gRDF;
nsINameSpaceManager* nsXULContentUtils::gNameSpaceManager;
nsIDateTimeFormat* nsXULContentUtils::gFormat;
//------------------------------------------------------------------------
// Constructors n' stuff
nsXULContentUtils::nsXULContentUtils()
{
NS_INIT_REFCNT();
}
nsresult
nsXULContentUtils::Init()
{
if (gRefCnt++ == 0) {
nsresult rv;
rv = nsServiceManager::GetService(kRDFServiceCID,
nsCOMTypeInfo<nsIRDFService>::GetIID(),
(nsISupports**) &gRDF);
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID,
nsnull,
nsCOMTypeInfo<nsINameSpaceManager>::GetIID(),
(void**) &gNameSpaceManager);
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::CreateInstance(kDateTimeFormatCID,
nsnull,
nsCOMTypeInfo<nsIDateTimeFormat>::GetIID(),
(void**) &gFormat);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}
nsXULContentUtils::~nsXULContentUtils()
{
if (--gRefCnt == 0) {
if (gRDF) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDF);
gRDF = nsnull;
}
NS_IF_RELEASE(gNameSpaceManager);
}
}
NS_IMETHODIMP
NS_NewXULContentUtils(nsISupports* aOuter, const nsIID& aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aOuter == nsnull, "no aggregation");
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
nsXULContentUtils* result = new nsXULContentUtils();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
rv = result->Init();
if (NS_FAILED(rv)) {
delete result;
return rv;
}
NS_ADDREF(result);
rv = result->QueryInterface(aIID, aResult);
NS_RELEASE(result);
return rv;
}
//------------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ISUPPORTS(nsXULContentUtils, nsCOMTypeInfo<nsIXULContentUtils>::GetIID());
//------------------------------------------------------------------------
// nsIXULContentUtils methods
NS_IMETHODIMP
nsXULContentUtils::AttachTextNode(nsIContent* parent, nsIRDFNode* value)
{
nsresult rv;
nsAutoString s;
rv = GetTextForNode(value, s);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsITextContent> text;
rv = nsComponentManager::CreateInstance(kTextNodeCID,
nsnull,
nsITextContent::GetIID(),
getter_AddRefs(text));
if (NS_FAILED(rv)) return rv;
rv = text->SetText(s.GetUnicode(), s.Length(), PR_FALSE);
if (NS_FAILED(rv)) return rv;
// hook it up to the child
rv = parent->AppendChildTo(nsCOMPtr<nsIContent>( do_QueryInterface(text) ), PR_FALSE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
nsXULContentUtils::FindChildByTag(nsIContent* aElement,
PRInt32 aNameSpaceID,
nsIAtom* aTag,
nsIContent** aResult)
{
nsresult rv;
PRInt32 count;
if (NS_FAILED(rv = aElement->ChildCount(count)))
return rv;
for (PRInt32 i = 0; i < count; ++i) {
nsCOMPtr<nsIContent> kid;
if (NS_FAILED(rv = aElement->ChildAt(i, *getter_AddRefs(kid))))
return rv; // XXX fatal
PRInt32 nameSpaceID;
if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID)))
return rv; // XXX fatal
if (nameSpaceID != aNameSpaceID)
continue; // wrong namespace
nsCOMPtr<nsIAtom> kidTag;
if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(kidTag))))
return rv; // XXX fatal
if (kidTag.get() != aTag)
continue;
*aResult = kid;
NS_ADDREF(*aResult);
return NS_OK;
}
return NS_RDF_NO_VALUE; // not found
}
NS_IMETHODIMP
nsXULContentUtils::FindChildByResource(nsIContent* aElement,
nsIRDFResource* aResource,
nsIContent** aResult)
{
nsresult rv;
PRInt32 count;
if (NS_FAILED(rv = aElement->ChildCount(count)))
return rv;
for (PRInt32 i = 0; i < count; ++i) {
nsCOMPtr<nsIContent> kid;
if (NS_FAILED(rv = aElement->ChildAt(i, *getter_AddRefs(kid))))
return rv; // XXX fatal
// Now get the resource ID from the RDF:ID attribute. We do it
// via the content model, because you're never sure who
// might've added this stuff in...
nsCOMPtr<nsIRDFResource> resource;
rv = GetElementResource(kid, getter_AddRefs(resource));
if (NS_FAILED(rv)) continue;
if (resource.get() != aResource)
continue; // not the resource we want
// Fount it!
*aResult = kid;
NS_ADDREF(*aResult);
return NS_OK;
}
return NS_RDF_NO_VALUE; // not found
}
NS_IMETHODIMP
nsXULContentUtils::GetElementResource(nsIContent* aElement, nsIRDFResource** aResult)
{
// Perform a reverse mapping from an element in the content model
// to an RDF resource.
nsresult rv;
PRUnichar buf[128];
nsAutoString id(CBufDescriptor(buf, PR_TRUE, sizeof(buf) / sizeof(PRUnichar), 0));
nsCOMPtr<nsIAtom> kIdAtom( dont_AddRef(NS_NewAtom("id")) );
rv = aElement->GetAttribute(kNameSpaceID_None, kIdAtom, id);
NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving attribute");
if (NS_FAILED(rv)) return rv;
if (rv != NS_CONTENT_ATTR_HAS_VALUE)
return NS_ERROR_FAILURE;
// Since the element will store its ID attribute as a document-relative value,
// we may need to qualify it first...
nsCOMPtr<nsIDocument> doc;
rv = aElement->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(doc != nsnull, "element is not in any document");
if (! doc)
return NS_ERROR_FAILURE;
rv = nsXULContentUtils::MakeElementResource(doc, id, aResult);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
nsXULContentUtils::GetElementRefResource(nsIContent* aElement, nsIRDFResource** aResult)
{
// Perform a reverse mapping from an element in the content model
// to an RDF resource. Check for a "ref" attribute first, then
// fallback on an "id" attribute.
nsresult rv;
PRUnichar buf[128];
nsAutoString uri(CBufDescriptor(buf, PR_TRUE, sizeof(buf) / sizeof(PRUnichar), 0));
nsCOMPtr<nsIAtom> kIdAtom( dont_AddRef(NS_NewAtom("ref")) );
rv = aElement->GetAttribute(kNameSpaceID_None, kIdAtom, uri);
NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving attribute");
if (NS_FAILED(rv)) return rv;
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
// We'll use rdf_MakeAbsolute() to translate this to a URL.
nsCOMPtr<nsIDocument> doc;
rv = aElement->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> url = dont_AddRef( doc->GetDocumentURL() );
NS_ASSERTION(url != nsnull, "element has no document");
if (! url)
return NS_ERROR_UNEXPECTED;
rv = rdf_MakeAbsoluteURI(url, uri);
if (NS_FAILED(rv)) return rv;
rv = gRDF->GetUnicodeResource(uri.GetUnicode(), aResult);
}
else {
rv = GetElementResource(aElement, aResult);
}
return rv;
}
/*
Note: this routine is similiar, yet distinctly different from, nsBookmarksService::GetTextForNode
*/
NS_IMETHODIMP
nsXULContentUtils::GetTextForNode(nsIRDFNode* aNode, nsString& aResult)
{
if (! aNode) {
aResult.Truncate();
return NS_OK;
}
nsresult rv;
// Literals are the most common, so try these first.
nsCOMPtr<nsIRDFLiteral> literal = do_QueryInterface(aNode);
if (literal) {
const PRUnichar* p;
rv = literal->GetValueConst(&p);
if (NS_FAILED(rv)) return rv;
aResult = p;
return NS_OK;
}
nsCOMPtr<nsIRDFDate> dateLiteral = do_QueryInterface(aNode);
if (dateLiteral) {
PRInt64 value;
rv = dateLiteral->GetValue(&value);
if (NS_FAILED(rv)) return rv;
rv = gFormat->FormatPRTime(nsnull /* nsILocale* locale */,
kDateFormatShort,
kTimeFormatSeconds,
PRTime(value),
aResult);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
nsCOMPtr<nsIRDFInt> intLiteral = do_QueryInterface(aNode);
if (intLiteral) {
PRInt32 value;
rv = intLiteral->GetValue(&value);
if (NS_FAILED(rv)) return rv;
aResult.Truncate();
aResult.Append(value, 10);
return NS_OK;
}
nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(aNode);
if (resource) {
const char* p;
rv = resource->GetValueConst(&p);
if (NS_FAILED(rv)) return rv;
aResult = p;
return NS_OK;
}
NS_ERROR("not a resource or a literal");
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsXULContentUtils::GetElementLogString(nsIContent* aElement, nsString& aResult)
{
nsresult rv;
aResult = '<';
nsCOMPtr<nsINameSpace> ns;
PRInt32 elementNameSpaceID;
rv = aElement->GetNameSpaceID(elementNameSpaceID);
if (NS_FAILED(rv)) return rv;
if (kNameSpaceID_HTML == elementNameSpaceID) {
aResult.Append("html:");
}
else {
nsCOMPtr<nsIXMLContent> xml( do_QueryInterface(aElement) );
NS_ASSERTION(xml != nsnull, "not an XML or HTML element");
if (! xml) return NS_ERROR_UNEXPECTED;
rv = xml->GetContainingNameSpace(*getter_AddRefs(ns));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIAtom> prefix;
rv = ns->FindNameSpacePrefix(elementNameSpaceID, *getter_AddRefs(prefix));
if (NS_SUCCEEDED(rv) && (prefix != nsnull)) {
nsAutoString prefixStr;
prefix->ToString(prefixStr);
if (prefixStr.Length()) {
const PRUnichar *unicodeString;
prefix->GetUnicode(&unicodeString);
aResult.Append(unicodeString);
aResult.Append(':');
}
}
}
nsCOMPtr<nsIAtom> tag;
rv = aElement->GetTag(*getter_AddRefs(tag));
if (NS_FAILED(rv)) return rv;
const PRUnichar *unicodeString;
tag->GetUnicode(&unicodeString);
aResult.Append(unicodeString);
PRInt32 count;
rv = aElement->GetAttributeCount(count);
if (NS_FAILED(rv)) return rv;
for (PRInt32 i = 0; i < count; ++i) {
aResult.Append(' ');
PRInt32 nameSpaceID;
nsCOMPtr<nsIAtom> name;
rv = aElement->GetAttributeNameAt(i, nameSpaceID, *getter_AddRefs(name));
if (NS_FAILED(rv)) return rv;
nsAutoString attr;
nsXULContentUtils::GetAttributeLogString(aElement, nameSpaceID, name, attr);
aResult.Append(attr);
aResult.Append("=\"");
nsAutoString value;
rv = aElement->GetAttribute(nameSpaceID, name, value);
if (NS_FAILED(rv)) return rv;
aResult.Append(value);
aResult.Append("\"");
}
aResult.Append('>');
return NS_OK;
}
NS_IMETHODIMP
nsXULContentUtils::GetAttributeLogString(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aTag, nsString& aResult)
{
nsresult rv;
PRInt32 elementNameSpaceID;
rv = aElement->GetNameSpaceID(elementNameSpaceID);
if (NS_FAILED(rv)) return rv;
if ((kNameSpaceID_HTML == elementNameSpaceID) ||
(kNameSpaceID_None == aNameSpaceID)) {
aResult.Truncate();
}
else {
// we may have a namespace prefix on the attribute
nsCOMPtr<nsIXMLContent> xml( do_QueryInterface(aElement) );
NS_ASSERTION(xml != nsnull, "not an XML or HTML element");
if (! xml) return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsINameSpace> ns;
rv = xml->GetContainingNameSpace(*getter_AddRefs(ns));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIAtom> prefix;
rv = ns->FindNameSpacePrefix(aNameSpaceID, *getter_AddRefs(prefix));
if (NS_SUCCEEDED(rv) && (prefix != nsnull)) {
nsAutoString prefixStr;
prefix->ToString(prefixStr);
if (prefixStr.Length()) {
const PRUnichar *unicodeString;
prefix->GetUnicode(&unicodeString);
aResult.Append(unicodeString);
aResult.Append(':');
}
}
}
const PRUnichar *unicodeString;
aTag->GetUnicode(&unicodeString);
aResult.Append(unicodeString);
return NS_OK;
}
NS_IMETHODIMP
nsXULContentUtils::MakeElementURI(nsIDocument* aDocument, const nsString& aElementID, nsCString& aURI)
{
// Convert an element's ID to a URI that can be used to refer to
// the element in the XUL graph.
if (aElementID.FindChar(':') > 0) {
// Assume it's absolute already. Use as is.
aURI = aElementID;
}
else {
nsresult rv;
nsCOMPtr<nsIURI> docURL;
rv = aDocument->GetBaseURL(*getter_AddRefs(docURL));
if (NS_FAILED(rv)) return rv;
// XXX Urgh. This is so broken; I'd really just like to use
// NS_MakeAbsolueURI(). Unfortunatly, doing that breaks
// MakeElementID in some cases that I haven't yet been able to
// figure out.
#define USE_BROKEN_RELATIVE_PARSING
#ifdef USE_BROKEN_RELATIVE_PARSING
nsXPIDLCString spec;
docURL->GetSpec(getter_Copies(spec));
if (! spec)
return NS_ERROR_FAILURE;
aURI = spec;
if (aElementID.First() != '#') {
aURI.Append('#');
}
aURI.Append(nsCAutoString(aElementID));
#else
nsXPIDLCString spec;
rv = NS_MakeAbsoluteURI(nsCAutoString(aElementID), docURL, getter_Copies(spec));
if (NS_SUCCEEDED(rv)) {
aURI = spec;
}
else {
NS_WARNING("MakeElementURI: NS_MakeAbsoluteURI failed");
aURI = aElementID;
}
#endif
}
return NS_OK;
}
NS_IMETHODIMP
nsXULContentUtils::MakeElementResource(nsIDocument* aDocument, const nsString& aID, nsIRDFResource** aResult)
{
nsresult rv;
char buf[256];
nsCAutoString uri(CBufDescriptor(buf, PR_TRUE, sizeof(buf), 0));
rv = MakeElementURI(aDocument, aID, uri);
if (NS_FAILED(rv)) return rv;
rv = gRDF->GetResource(uri, aResult);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create resource");
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
nsXULContentUtils::MakeElementID(nsIDocument* aDocument, const nsString& aURI, nsString& aElementID)
{
// Convert a URI into an element ID that can be accessed from the
// DOM APIs.
nsresult rv;
nsCOMPtr<nsIURI> docURL;
rv = aDocument->GetBaseURL(*getter_AddRefs(docURL));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString spec;
docURL->GetSpec(getter_Copies(spec));
if (! spec)
return NS_ERROR_FAILURE;
if (aURI.Find(spec) == 0) {
#ifdef USE_BROKEN_RELATIVE_PARSING
static const PRInt32 kFudge = 1; // XXX assume '#'
#else
static const PRInt32 kFudge = 0;
#endif
PRInt32 len = PL_strlen(spec);
aURI.Right(aElementID, aURI.Length() - (len + kFudge));
}
else {
aElementID = aURI;
}
return NS_OK;
}
NS_IMETHODIMP_(PRBool)
nsXULContentUtils::IsContainedBy(nsIContent* aElement, nsIContent* aContainer)
{
nsCOMPtr<nsIContent> element( dont_QueryInterface(aElement) );
while (element) {
nsresult rv;
nsCOMPtr<nsIContent> parent;
rv = element->GetParent(*getter_AddRefs(parent));
if (NS_FAILED(rv)) return PR_FALSE;
if (parent.get() == aContainer)
return PR_TRUE;
element = parent;
}
return PR_FALSE;
}
NS_IMETHODIMP
nsXULContentUtils::GetResource(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult)
{
// construct a fully-qualified URI from the namespace/tag pair.
NS_PRECONDITION(aAttribute != nsnull, "null ptr");
if (! aAttribute)
return NS_ERROR_NULL_POINTER;
nsresult rv;
nsAutoString attr;
rv = aAttribute->ToString(attr);
if (NS_FAILED(rv)) return rv;
return GetResource(aNameSpaceID, attr, aResult);
}
NS_IMETHODIMP
nsXULContentUtils::GetResource(PRInt32 aNameSpaceID, const nsString& aAttribute, nsIRDFResource** aResult)
{
// construct a fully-qualified URI from the namespace/tag pair.
// XXX should we allow nodes with no namespace???
//NS_PRECONDITION(aNameSpaceID != kNameSpaceID_Unknown, "no namespace");
//if (aNameSpaceID == kNameSpaceID_Unknown)
// return NS_ERROR_UNEXPECTED;
nsresult rv;
PRUnichar buf[256];
nsAutoString uri(CBufDescriptor(buf, PR_TRUE, sizeof(buf) / sizeof(PRUnichar), 0));
if (aNameSpaceID != kNameSpaceID_Unknown && aNameSpaceID != kNameSpaceID_None) {
rv = gNameSpaceManager->GetNameSpaceURI(aNameSpaceID, uri);
// XXX ignore failure; treat as "no namespace"
}
// XXX check to see if we need to insert a '/' or a '#'. Oy.
if (uri.Length() > 0 && uri.Last() != '#' && uri.Last() != '/' && aAttribute.First() != '#')
uri.Append('#');
uri.Append(aAttribute);
rv = gRDF->GetUnicodeResource(uri.GetUnicode(), aResult);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
interface XULCommandDispatcher {
/* IID: { 0xf3c50361, 0x14fe, 0x11d3, \
{ 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } */
attribute Element focusedElement;
attribute Window focusedWindow;
void addCommandUpdater(in Element updater, in DOMString events, in DOMString targets);
void removeCommandUpdater(in Element updater);
void updateCommands(in DOMString eventName);
xpidl nsIController getController();
void setController(in xpidl nsIController controller);
};

View File

@@ -0,0 +1,15 @@
interface XULDocument : Document {
/* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
attribute Node popupNode;
attribute Node tooltipNode;
readonly attribute XULCommandDispatcher commandDispatcher;
Element getElementById(in DOMString id);
NodeList getElementsByAttribute(in DOMString name, in DOMString value);
void persist(in DOMString id, in DOMString attr);
};

View File

@@ -0,0 +1,17 @@
interface XULElement : Element {
/* IID: { 0x574ed81, 0xc088, 0x11d2, \
{ 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } */
attribute DOMString id;
attribute DOMString className;
readonly attribute CSSStyleDeclaration style;
attribute xpidl nsIRDFCompositeDataSource database;
readonly attribute xpidl nsIRDFResource resource;
attribute xpidl nsIController controller;
void addBroadcastListener(in DOMString attr, in Element element);
void removeBroadcastListener(in DOMString attr, in Element element);
void doCommand();
NodeList getElementsByAttribute(in DOMString name, in DOMString value);
};

View File

@@ -0,0 +1,27 @@
interface XULTreeElement : XULElement {
/* IID: { 0xa6cf90ec, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } */
readonly attribute NodeList selectedItems;
readonly attribute NodeList selectedCells;
void selectItem(in XULElement treeItem);
void selectCell(in XULElement treeCell);
void clearItemSelection();
void clearCellSelection();
void addItemToSelection(in XULElement treeItem);
void removeItemFromSelection(in XULElement treeItem);
void addCellToSelection(in XULElement treeCell);
void removeCellFromSelection(in XULElement treeCell);
void toggleItemSelection(in XULElement treeItem);
void toggleCellSelection(in XULElement treeCell);
void selectItemRange(in XULElement startItem, in XULElement endItem);
void selectCellRange(in XULElement startItem, in XULElement endItem);
void selectAll();
void invertSelection();
};

View File

@@ -0,0 +1,86 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMXULCommandDispatcher_h__
#define nsIDOMXULCommandDispatcher_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIController;
class nsIDOMElement;
class nsIDOMWindow;
#define NS_IDOMXULCOMMANDDISPATCHER_IID \
{ 0xf3c50361, 0x14fe, 0x11d3, \
{ 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
class nsIDOMXULCommandDispatcher : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULCOMMANDDISPATCHER_IID; return iid; }
NS_IMETHOD GetFocusedElement(nsIDOMElement** aFocusedElement)=0;
NS_IMETHOD SetFocusedElement(nsIDOMElement* aFocusedElement)=0;
NS_IMETHOD GetFocusedWindow(nsIDOMWindow** aFocusedWindow)=0;
NS_IMETHOD SetFocusedWindow(nsIDOMWindow* aFocusedWindow)=0;
NS_IMETHOD AddCommandUpdater(nsIDOMElement* aUpdater, const nsString& aEvents, const nsString& aTargets)=0;
NS_IMETHOD RemoveCommandUpdater(nsIDOMElement* aUpdater)=0;
NS_IMETHOD UpdateCommands(const nsString& aEventName)=0;
NS_IMETHOD GetController(nsIController** aReturn)=0;
NS_IMETHOD SetController(nsIController* aController)=0;
};
#define NS_DECL_IDOMXULCOMMANDDISPATCHER \
NS_IMETHOD GetFocusedElement(nsIDOMElement** aFocusedElement); \
NS_IMETHOD SetFocusedElement(nsIDOMElement* aFocusedElement); \
NS_IMETHOD GetFocusedWindow(nsIDOMWindow** aFocusedWindow); \
NS_IMETHOD SetFocusedWindow(nsIDOMWindow* aFocusedWindow); \
NS_IMETHOD AddCommandUpdater(nsIDOMElement* aUpdater, const nsString& aEvents, const nsString& aTargets); \
NS_IMETHOD RemoveCommandUpdater(nsIDOMElement* aUpdater); \
NS_IMETHOD UpdateCommands(const nsString& aEventName); \
NS_IMETHOD GetController(nsIController** aReturn); \
NS_IMETHOD SetController(nsIController* aController); \
#define NS_FORWARD_IDOMXULCOMMANDDISPATCHER(_to) \
NS_IMETHOD GetFocusedElement(nsIDOMElement** aFocusedElement) { return _to GetFocusedElement(aFocusedElement); } \
NS_IMETHOD SetFocusedElement(nsIDOMElement* aFocusedElement) { return _to SetFocusedElement(aFocusedElement); } \
NS_IMETHOD GetFocusedWindow(nsIDOMWindow** aFocusedWindow) { return _to GetFocusedWindow(aFocusedWindow); } \
NS_IMETHOD SetFocusedWindow(nsIDOMWindow* aFocusedWindow) { return _to SetFocusedWindow(aFocusedWindow); } \
NS_IMETHOD AddCommandUpdater(nsIDOMElement* aUpdater, const nsString& aEvents, const nsString& aTargets) { return _to AddCommandUpdater(aUpdater, aEvents, aTargets); } \
NS_IMETHOD RemoveCommandUpdater(nsIDOMElement* aUpdater) { return _to RemoveCommandUpdater(aUpdater); } \
NS_IMETHOD UpdateCommands(const nsString& aEventName) { return _to UpdateCommands(aEventName); } \
NS_IMETHOD GetController(nsIController** aReturn) { return _to GetController(aReturn); } \
NS_IMETHOD SetController(nsIController* aController) { return _to SetController(aController); } \
extern "C" NS_DOM nsresult NS_InitXULCommandDispatcherClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptXULCommandDispatcher(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMXULCommandDispatcher_h__

View File

@@ -0,0 +1,84 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMXULDocument_h__
#define nsIDOMXULDocument_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMDocument.h"
class nsIDOMElement;
class nsIDOMNode;
class nsIDOMXULCommandDispatcher;
class nsIDOMNodeList;
#define NS_IDOMXULDOCUMENT_IID \
{ 0x17ddd8c0, 0xc5f8, 0x11d2, \
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
class nsIDOMXULDocument : public nsIDOMDocument {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULDOCUMENT_IID; return iid; }
NS_IMETHOD GetPopupNode(nsIDOMNode** aPopupNode)=0;
NS_IMETHOD SetPopupNode(nsIDOMNode* aPopupNode)=0;
NS_IMETHOD GetTooltipNode(nsIDOMNode** aTooltipNode)=0;
NS_IMETHOD SetTooltipNode(nsIDOMNode* aTooltipNode)=0;
NS_IMETHOD GetCommandDispatcher(nsIDOMXULCommandDispatcher** aCommandDispatcher)=0;
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn)=0;
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn)=0;
NS_IMETHOD Persist(const nsString& aId, const nsString& aAttr)=0;
};
#define NS_DECL_IDOMXULDOCUMENT \
NS_IMETHOD GetPopupNode(nsIDOMNode** aPopupNode); \
NS_IMETHOD SetPopupNode(nsIDOMNode* aPopupNode); \
NS_IMETHOD GetTooltipNode(nsIDOMNode** aTooltipNode); \
NS_IMETHOD SetTooltipNode(nsIDOMNode* aTooltipNode); \
NS_IMETHOD GetCommandDispatcher(nsIDOMXULCommandDispatcher** aCommandDispatcher); \
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn); \
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn); \
NS_IMETHOD Persist(const nsString& aId, const nsString& aAttr); \
#define NS_FORWARD_IDOMXULDOCUMENT(_to) \
NS_IMETHOD GetPopupNode(nsIDOMNode** aPopupNode) { return _to GetPopupNode(aPopupNode); } \
NS_IMETHOD SetPopupNode(nsIDOMNode* aPopupNode) { return _to SetPopupNode(aPopupNode); } \
NS_IMETHOD GetTooltipNode(nsIDOMNode** aTooltipNode) { return _to GetTooltipNode(aTooltipNode); } \
NS_IMETHOD SetTooltipNode(nsIDOMNode* aTooltipNode) { return _to SetTooltipNode(aTooltipNode); } \
NS_IMETHOD GetCommandDispatcher(nsIDOMXULCommandDispatcher** aCommandDispatcher) { return _to GetCommandDispatcher(aCommandDispatcher); } \
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn) { return _to GetElementById(aId, aReturn); } \
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn) { return _to GetElementsByAttribute(aName, aValue, aReturn); } \
NS_IMETHOD Persist(const nsString& aId, const nsString& aAttr) { return _to Persist(aId, aAttr); } \
extern "C" NS_DOM nsresult NS_InitXULDocumentClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptXULDocument(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMXULDocument_h__

View File

@@ -0,0 +1,108 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMXULElement_h__
#define nsIDOMXULElement_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMElement.h"
class nsIController;
class nsIDOMElement;
class nsIDOMCSSStyleDeclaration;
class nsIRDFCompositeDataSource;
class nsIRDFResource;
class nsIDOMNodeList;
#define NS_IDOMXULELEMENT_IID \
{ 0x574ed81, 0xc088, 0x11d2, \
{ 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } }
class nsIDOMXULElement : public nsIDOMElement {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULELEMENT_IID; return iid; }
NS_IMETHOD GetId(nsString& aId)=0;
NS_IMETHOD SetId(const nsString& aId)=0;
NS_IMETHOD GetClassName(nsString& aClassName)=0;
NS_IMETHOD SetClassName(const nsString& aClassName)=0;
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle)=0;
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase)=0;
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase)=0;
NS_IMETHOD GetResource(nsIRDFResource** aResource)=0;
NS_IMETHOD GetController(nsIController** aController)=0;
NS_IMETHOD SetController(nsIController* aController)=0;
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement)=0;
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement)=0;
NS_IMETHOD DoCommand()=0;
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn)=0;
};
#define NS_DECL_IDOMXULELEMENT \
NS_IMETHOD GetId(nsString& aId); \
NS_IMETHOD SetId(const nsString& aId); \
NS_IMETHOD GetClassName(nsString& aClassName); \
NS_IMETHOD SetClassName(const nsString& aClassName); \
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle); \
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase); \
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase); \
NS_IMETHOD GetResource(nsIRDFResource** aResource); \
NS_IMETHOD GetController(nsIController** aController); \
NS_IMETHOD SetController(nsIController* aController); \
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement); \
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement); \
NS_IMETHOD DoCommand(); \
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn); \
#define NS_FORWARD_IDOMXULELEMENT(_to) \
NS_IMETHOD GetId(nsString& aId) { return _to GetId(aId); } \
NS_IMETHOD SetId(const nsString& aId) { return _to SetId(aId); } \
NS_IMETHOD GetClassName(nsString& aClassName) { return _to GetClassName(aClassName); } \
NS_IMETHOD SetClassName(const nsString& aClassName) { return _to SetClassName(aClassName); } \
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { return _to GetStyle(aStyle); } \
NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase) { return _to GetDatabase(aDatabase); } \
NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase) { return _to SetDatabase(aDatabase); } \
NS_IMETHOD GetResource(nsIRDFResource** aResource) { return _to GetResource(aResource); } \
NS_IMETHOD GetController(nsIController** aController) { return _to GetController(aController); } \
NS_IMETHOD SetController(nsIController* aController) { return _to SetController(aController); } \
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement) { return _to AddBroadcastListener(aAttr, aElement); } \
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMElement* aElement) { return _to RemoveBroadcastListener(aAttr, aElement); } \
NS_IMETHOD DoCommand() { return _to DoCommand(); } \
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn) { return _to GetElementsByAttribute(aName, aValue, aReturn); } \
extern "C" NS_DOM nsresult NS_InitXULElementClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptXULElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMXULElement_h__

View File

@@ -0,0 +1,116 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMXULTreeElement_h__
#define nsIDOMXULTreeElement_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMXULElement.h"
class nsIDOMXULElement;
class nsIDOMNodeList;
#define NS_IDOMXULTREEELEMENT_IID \
{ 0xa6cf90ec, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
class nsIDOMXULTreeElement : public nsIDOMXULElement {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULTREEELEMENT_IID; return iid; }
NS_IMETHOD GetSelectedItems(nsIDOMNodeList** aSelectedItems)=0;
NS_IMETHOD GetSelectedCells(nsIDOMNodeList** aSelectedCells)=0;
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem)=0;
NS_IMETHOD SelectCell(nsIDOMXULElement* aTreeCell)=0;
NS_IMETHOD ClearItemSelection()=0;
NS_IMETHOD ClearCellSelection()=0;
NS_IMETHOD AddItemToSelection(nsIDOMXULElement* aTreeItem)=0;
NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem)=0;
NS_IMETHOD AddCellToSelection(nsIDOMXULElement* aTreeCell)=0;
NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell)=0;
NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem)=0;
NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell)=0;
NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)=0;
NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)=0;
NS_IMETHOD SelectAll()=0;
NS_IMETHOD InvertSelection()=0;
};
#define NS_DECL_IDOMXULTREEELEMENT \
NS_IMETHOD GetSelectedItems(nsIDOMNodeList** aSelectedItems); \
NS_IMETHOD GetSelectedCells(nsIDOMNodeList** aSelectedCells); \
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD SelectCell(nsIDOMXULElement* aTreeCell); \
NS_IMETHOD ClearItemSelection(); \
NS_IMETHOD ClearCellSelection(); \
NS_IMETHOD AddItemToSelection(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD AddCellToSelection(nsIDOMXULElement* aTreeCell); \
NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell); \
NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell); \
NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem); \
NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem); \
NS_IMETHOD SelectAll(); \
NS_IMETHOD InvertSelection(); \
#define NS_FORWARD_IDOMXULTREEELEMENT(_to) \
NS_IMETHOD GetSelectedItems(nsIDOMNodeList** aSelectedItems) { return _to GetSelectedItems(aSelectedItems); } \
NS_IMETHOD GetSelectedCells(nsIDOMNodeList** aSelectedCells) { return _to GetSelectedCells(aSelectedCells); } \
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem) { return _to SelectItem(aTreeItem); } \
NS_IMETHOD SelectCell(nsIDOMXULElement* aTreeCell) { return _to SelectCell(aTreeCell); } \
NS_IMETHOD ClearItemSelection() { return _to ClearItemSelection(); } \
NS_IMETHOD ClearCellSelection() { return _to ClearCellSelection(); } \
NS_IMETHOD AddItemToSelection(nsIDOMXULElement* aTreeItem) { return _to AddItemToSelection(aTreeItem); } \
NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem) { return _to RemoveItemFromSelection(aTreeItem); } \
NS_IMETHOD AddCellToSelection(nsIDOMXULElement* aTreeCell) { return _to AddCellToSelection(aTreeCell); } \
NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell) { return _to RemoveCellFromSelection(aTreeCell); } \
NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem) { return _to ToggleItemSelection(aTreeItem); } \
NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell) { return _to ToggleCellSelection(aTreeCell); } \
NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem) { return _to SelectItemRange(aStartItem, aEndItem); } \
NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem) { return _to SelectCellRange(aStartItem, aEndItem); } \
NS_IMETHOD SelectAll() { return _to SelectAll(); } \
NS_IMETHOD InvertSelection() { return _to InvertSelection(); } \
extern "C" NS_DOM nsresult NS_InitXULTreeElementClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptXULTreeElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMXULTreeElement_h__

View File

@@ -0,0 +1,636 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nsDOMError.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIScriptSecurityManager.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsCOMPtr.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIController.h"
#include "nsIDOMElement.h"
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIDOMWindow.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIControllerIID, NS_ICONTROLLER_IID);
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIXULCommandDispatcherIID, NS_IDOMXULCOMMANDDISPATCHER_IID);
static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
NS_DEF_PTR(nsIController);
NS_DEF_PTR(nsIDOMElement);
NS_DEF_PTR(nsIDOMXULCommandDispatcher);
NS_DEF_PTR(nsIDOMWindow);
//
// XULCommandDispatcher property ids
//
enum XULCommandDispatcher_slots {
XULCOMMANDDISPATCHER_FOCUSEDELEMENT = -1,
XULCOMMANDDISPATCHER_FOCUSEDWINDOW = -2
};
/***********************************************************************/
//
// XULCommandDispatcher Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetXULCommandDispatcherProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULCommandDispatcher *a = (nsIDOMXULCommandDispatcher*)nsJSUtils::nsGetNativeThis(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
switch(JSVAL_TO_INT(id)) {
case XULCOMMANDDISPATCHER_FOCUSEDELEMENT:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.focusedelement", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMElement* prop;
nsresult result = NS_OK;
result = a->GetFocusedElement(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
case XULCOMMANDDISPATCHER_FOCUSEDWINDOW:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.focusedwindow", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMWindow* prop;
nsresult result = NS_OK;
result = a->GetFocusedWindow(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// XULCommandDispatcher Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetXULCommandDispatcherProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULCommandDispatcher *a = (nsIDOMXULCommandDispatcher*)nsJSUtils::nsGetNativeThis(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
switch(JSVAL_TO_INT(id)) {
case XULCOMMANDDISPATCHER_FOCUSEDELEMENT:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.focusedelement", PR_TRUE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMElement* prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop,
kIElementIID, "Element",
cx, *vp)) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
a->SetFocusedElement(prop);
NS_IF_RELEASE(prop);
break;
}
case XULCOMMANDDISPATCHER_FOCUSEDWINDOW:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.focusedwindow", PR_TRUE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMWindow* prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop,
kIWindowIID, "Window",
cx, *vp)) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
a->SetFocusedWindow(prop);
NS_IF_RELEASE(prop);
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// XULCommandDispatcher finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeXULCommandDispatcher(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// XULCommandDispatcher enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateXULCommandDispatcher(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// XULCommandDispatcher resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveXULCommandDispatcher(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method AddCommandUpdater
//
PR_STATIC_CALLBACK(JSBool)
XULCommandDispatcherAddCommandUpdater(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULCommandDispatcher *nativeThis = (nsIDOMXULCommandDispatcher*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIDOMElementPtr b0;
nsAutoString b1;
nsAutoString b2;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.addcommandupdater",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 3) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIElementIID,
"Element",
cx,
argv[0])) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]);
result = nativeThis->AddCommandUpdater(b0, b1, b2);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method RemoveCommandUpdater
//
PR_STATIC_CALLBACK(JSBool)
XULCommandDispatcherRemoveCommandUpdater(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULCommandDispatcher *nativeThis = (nsIDOMXULCommandDispatcher*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIDOMElementPtr b0;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.removecommandupdater",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 1) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIElementIID,
"Element",
cx,
argv[0])) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
result = nativeThis->RemoveCommandUpdater(b0);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method UpdateCommands
//
PR_STATIC_CALLBACK(JSBool)
XULCommandDispatcherUpdateCommands(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULCommandDispatcher *nativeThis = (nsIDOMXULCommandDispatcher*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsAutoString b0;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.updatecommands",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 1) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
result = nativeThis->UpdateCommands(b0);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method GetController
//
PR_STATIC_CALLBACK(JSBool)
XULCommandDispatcherGetController(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULCommandDispatcher *nativeThis = (nsIDOMXULCommandDispatcher*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIController* nativeRet;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.getcontroller",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
result = nativeThis->GetController(&nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
// n.b., this will release nativeRet
nsJSUtils::nsConvertXPCObjectToJSVal(nativeRet, nsIController::GetIID(), cx, rval);
}
return JS_TRUE;
}
//
// Native method SetController
//
PR_STATIC_CALLBACK(JSBool)
XULCommandDispatcherSetController(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULCommandDispatcher *nativeThis = (nsIDOMXULCommandDispatcher*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIControllerPtr b0;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulcommanddispatcher.setcontroller",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 1) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports**) &b0,
kIControllerIID, cx, argv[0])) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_XPC_OBJECT_ERR);
}
result = nativeThis->SetController(b0);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for XULCommandDispatcher
//
JSClass XULCommandDispatcherClass = {
"XULCommandDispatcher",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub,
JS_PropertyStub,
GetXULCommandDispatcherProperty,
SetXULCommandDispatcherProperty,
EnumerateXULCommandDispatcher,
ResolveXULCommandDispatcher,
JS_ConvertStub,
FinalizeXULCommandDispatcher
};
//
// XULCommandDispatcher class properties
//
static JSPropertySpec XULCommandDispatcherProperties[] =
{
{"focusedElement", XULCOMMANDDISPATCHER_FOCUSEDELEMENT, JSPROP_ENUMERATE},
{"focusedWindow", XULCOMMANDDISPATCHER_FOCUSEDWINDOW, JSPROP_ENUMERATE},
{0}
};
//
// XULCommandDispatcher class methods
//
static JSFunctionSpec XULCommandDispatcherMethods[] =
{
{"addCommandUpdater", XULCommandDispatcherAddCommandUpdater, 3},
{"removeCommandUpdater", XULCommandDispatcherRemoveCommandUpdater, 1},
{"updateCommands", XULCommandDispatcherUpdateCommands, 1},
{"getController", XULCommandDispatcherGetController, 0},
{"setController", XULCommandDispatcherSetController, 1},
{0}
};
//
// XULCommandDispatcher constructor
//
PR_STATIC_CALLBACK(JSBool)
XULCommandDispatcher(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// XULCommandDispatcher class initialization
//
extern "C" NS_DOM nsresult NS_InitXULCommandDispatcherClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "XULCommandDispatcher", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&XULCommandDispatcherClass, // JSClass
XULCommandDispatcher, // JSNative ctor
0, // ctor args
XULCommandDispatcherProperties, // proto props
XULCommandDispatcherMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new XULCommandDispatcher JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptXULCommandDispatcher(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULCommandDispatcher");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMXULCommandDispatcher *aXULCommandDispatcher;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitXULCommandDispatcherClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIXULCommandDispatcherIID, (void **)&aXULCommandDispatcher);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &XULCommandDispatcherClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULCommandDispatcher);
}
else {
NS_RELEASE(aXULCommandDispatcher);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -0,0 +1,554 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nsDOMError.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIScriptSecurityManager.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsCOMPtr.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIDOMXULDocument.h"
#include "nsIDOMNodeList.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIXULCommandDispatcherIID, NS_IDOMXULCOMMANDDISPATCHER_IID);
static NS_DEFINE_IID(kIXULDocumentIID, NS_IDOMXULDOCUMENT_IID);
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
NS_DEF_PTR(nsIDOMElement);
NS_DEF_PTR(nsIDOMNode);
NS_DEF_PTR(nsIDOMXULCommandDispatcher);
NS_DEF_PTR(nsIDOMXULDocument);
NS_DEF_PTR(nsIDOMNodeList);
//
// XULDocument property ids
//
enum XULDocument_slots {
XULDOCUMENT_POPUPNODE = -1,
XULDOCUMENT_TOOLTIPNODE = -2,
XULDOCUMENT_COMMANDDISPATCHER = -3
};
/***********************************************************************/
//
// XULDocument Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULDocument *a = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
switch(JSVAL_TO_INT(id)) {
case XULDOCUMENT_POPUPNODE:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.popupnode", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMNode* prop;
nsresult result = NS_OK;
result = a->GetPopupNode(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
case XULDOCUMENT_TOOLTIPNODE:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.tooltipnode", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMNode* prop;
nsresult result = NS_OK;
result = a->GetTooltipNode(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
case XULDOCUMENT_COMMANDDISPATCHER:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.commanddispatcher", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMXULCommandDispatcher* prop;
nsresult result = NS_OK;
result = a->GetCommandDispatcher(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// XULDocument Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULDocument *a = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
switch(JSVAL_TO_INT(id)) {
case XULDOCUMENT_POPUPNODE:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.popupnode", PR_TRUE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMNode* prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop,
kINodeIID, "Node",
cx, *vp)) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
a->SetPopupNode(prop);
NS_IF_RELEASE(prop);
break;
}
case XULDOCUMENT_TOOLTIPNODE:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.tooltipnode", PR_TRUE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMNode* prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop,
kINodeIID, "Node",
cx, *vp)) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
a->SetTooltipNode(prop);
NS_IF_RELEASE(prop);
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// XULDocument finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeXULDocument(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// XULDocument enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateXULDocument(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// XULDocument resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveXULDocument(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method GetElementById
//
PR_STATIC_CALLBACK(JSBool)
XULDocumentGetElementById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULDocument *nativeThis = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIDOMElement* nativeRet;
nsAutoString b0;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.getelementbyid",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 1) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
result = nativeThis->GetElementById(b0, &nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, rval);
}
return JS_TRUE;
}
//
// Native method GetElementsByAttribute
//
PR_STATIC_CALLBACK(JSBool)
XULDocumentGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULDocument *nativeThis = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIDOMNodeList* nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.getelementsbyattribute",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 2) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
result = nativeThis->GetElementsByAttribute(b0, b1, &nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, rval);
}
return JS_TRUE;
}
//
// Native method Persist
//
PR_STATIC_CALLBACK(JSBool)
XULDocumentPersist(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULDocument *nativeThis = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.persist",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 2) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
result = nativeThis->Persist(b0, b1);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for XULDocument
//
JSClass XULDocumentClass = {
"XULDocument",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub,
JS_PropertyStub,
GetXULDocumentProperty,
SetXULDocumentProperty,
EnumerateXULDocument,
ResolveXULDocument,
JS_ConvertStub,
FinalizeXULDocument
};
//
// XULDocument class properties
//
static JSPropertySpec XULDocumentProperties[] =
{
{"popupNode", XULDOCUMENT_POPUPNODE, JSPROP_ENUMERATE},
{"tooltipNode", XULDOCUMENT_TOOLTIPNODE, JSPROP_ENUMERATE},
{"commandDispatcher", XULDOCUMENT_COMMANDDISPATCHER, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
//
// XULDocument class methods
//
static JSFunctionSpec XULDocumentMethods[] =
{
{"getElementById", XULDocumentGetElementById, 1},
{"getElementsByAttribute", XULDocumentGetElementsByAttribute, 2},
{"persist", XULDocumentPersist, 2},
{0}
};
//
// XULDocument constructor
//
PR_STATIC_CALLBACK(JSBool)
XULDocument(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// XULDocument class initialization
//
extern "C" NS_DOM nsresult NS_InitXULDocumentClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "XULDocument", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitDocumentClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&XULDocumentClass, // JSClass
XULDocument, // JSNative ctor
0, // ctor args
XULDocumentProperties, // proto props
XULDocumentMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new XULDocument JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptXULDocument(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULDocument");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMXULDocument *aXULDocument;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitXULDocumentClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIXULDocumentIID, (void **)&aXULDocument);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &XULDocumentClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULDocument);
}
else {
NS_RELEASE(aXULDocument);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -0,0 +1,704 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nsDOMError.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIScriptSecurityManager.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsCOMPtr.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIController.h"
#include "nsIDOMElement.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIDOMXULElement.h"
#include "nsIRDFResource.h"
#include "nsIDOMNodeList.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIControllerIID, NS_ICONTROLLER_IID);
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kICSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
static NS_DEFINE_IID(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID);
static NS_DEFINE_IID(kIXULElementIID, NS_IDOMXULELEMENT_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
NS_DEF_PTR(nsIController);
NS_DEF_PTR(nsIDOMElement);
NS_DEF_PTR(nsIDOMCSSStyleDeclaration);
NS_DEF_PTR(nsIRDFCompositeDataSource);
NS_DEF_PTR(nsIDOMXULElement);
NS_DEF_PTR(nsIRDFResource);
NS_DEF_PTR(nsIDOMNodeList);
//
// XULElement property ids
//
enum XULElement_slots {
XULELEMENT_ID = -1,
XULELEMENT_CLASSNAME = -2,
XULELEMENT_STYLE = -3,
XULELEMENT_DATABASE = -4,
XULELEMENT_RESOURCE = -5,
XULELEMENT_CONTROLLER = -6
};
/***********************************************************************/
//
// XULElement Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULElement *a = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
switch(JSVAL_TO_INT(id)) {
case XULELEMENT_ID:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsAutoString prop;
nsresult result = NS_OK;
result = a->GetId(prop);
if (NS_SUCCEEDED(result)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
case XULELEMENT_CLASSNAME:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.classname", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsAutoString prop;
nsresult result = NS_OK;
result = a->GetClassName(prop);
if (NS_SUCCEEDED(result)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
case XULELEMENT_STYLE:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.style", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIDOMCSSStyleDeclaration* prop;
nsresult result = NS_OK;
result = a->GetStyle(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
case XULELEMENT_DATABASE:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.database", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIRDFCompositeDataSource* prop;
nsresult result = NS_OK;
result = a->GetDatabase(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object; n.b., this will do a release on 'prop'
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
case XULELEMENT_RESOURCE:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.resource", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIRDFResource* prop;
nsresult result = NS_OK;
result = a->GetResource(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object; n.b., this will do a release on 'prop'
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
case XULELEMENT_CONTROLLER:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIController* prop;
nsresult result = NS_OK;
result = a->GetController(&prop);
if (NS_SUCCEEDED(result)) {
// get the js object; n.b., this will do a release on 'prop'
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIController::GetIID(), cx, vp);
}
else {
return nsJSUtils::nsReportError(cx, result);
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// XULElement Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULElement *a = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
switch(JSVAL_TO_INT(id)) {
case XULELEMENT_ID:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", PR_TRUE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsAutoString prop;
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
a->SetId(prop);
break;
}
case XULELEMENT_CLASSNAME:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.classname", PR_TRUE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsAutoString prop;
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
a->SetClassName(prop);
break;
}
case XULELEMENT_DATABASE:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.database", PR_TRUE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIRDFCompositeDataSource* prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop,
kIRDFCompositeDataSourceIID, cx, *vp)) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_XPC_OBJECT_ERR);
}
a->SetDatabase(prop);
NS_IF_RELEASE(prop);
break;
}
case XULELEMENT_CONTROLLER:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", PR_TRUE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
nsIController* prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop,
kIControllerIID, cx, *vp)) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_XPC_OBJECT_ERR);
}
a->SetController(prop);
NS_IF_RELEASE(prop);
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// XULElement finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeXULElement(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// XULElement enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateXULElement(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// XULElement resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveXULElement(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method AddBroadcastListener
//
PR_STATIC_CALLBACK(JSBool)
XULElementAddBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsAutoString b0;
nsIDOMElementPtr b1;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.addbroadcastlistener",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 2) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kIElementIID,
"Element",
cx,
argv[1])) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
result = nativeThis->AddBroadcastListener(b0, b1);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method RemoveBroadcastListener
//
PR_STATIC_CALLBACK(JSBool)
XULElementRemoveBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsAutoString b0;
nsIDOMElementPtr b1;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.removebroadcastlistener",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 2) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kIElementIID,
"Element",
cx,
argv[1])) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
result = nativeThis->RemoveBroadcastListener(b0, b1);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method DoCommand
//
PR_STATIC_CALLBACK(JSBool)
XULElementDoCommand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.docommand",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
result = nativeThis->DoCommand();
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method GetElementsByAttribute
//
PR_STATIC_CALLBACK(JSBool)
XULElementGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsIDOMNodeList* nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECMAN_ERR);
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "xulelement.getelementsbyattribute",PR_FALSE , &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_SECURITY_ERR);
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (argc < 2) {
return nsJSUtils::nsReportError(cx, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
result = nativeThis->GetElementsByAttribute(b0, b1, &nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, result);
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, rval);
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for XULElement
//
JSClass XULElementClass = {
"XULElement",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub,
JS_PropertyStub,
GetXULElementProperty,
SetXULElementProperty,
EnumerateXULElement,
ResolveXULElement,
JS_ConvertStub,
FinalizeXULElement
};
//
// XULElement class properties
//
static JSPropertySpec XULElementProperties[] =
{
{"id", XULELEMENT_ID, JSPROP_ENUMERATE},
{"className", XULELEMENT_CLASSNAME, JSPROP_ENUMERATE},
{"style", XULELEMENT_STYLE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"database", XULELEMENT_DATABASE, JSPROP_ENUMERATE},
{"resource", XULELEMENT_RESOURCE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"controller", XULELEMENT_CONTROLLER, JSPROP_ENUMERATE},
{0}
};
//
// XULElement class methods
//
static JSFunctionSpec XULElementMethods[] =
{
{"addBroadcastListener", XULElementAddBroadcastListener, 2},
{"removeBroadcastListener", XULElementRemoveBroadcastListener, 2},
{"doCommand", XULElementDoCommand, 0},
{"getElementsByAttribute", XULElementGetElementsByAttribute, 2},
{0}
};
//
// XULElement constructor
//
PR_STATIC_CALLBACK(JSBool)
XULElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// XULElement class initialization
//
extern "C" NS_DOM nsresult NS_InitXULElementClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "XULElement", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitElementClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&XULElementClass, // JSClass
XULElement, // JSNative ctor
0, // ctor args
XULElementProperties, // proto props
XULElementMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new XULElement JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptXULElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULElement");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMXULElement *aXULElement;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitXULElementClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIXULElementIID, (void **)&aXULElement);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &XULElementClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULElement);
}
else {
NS_RELEASE(aXULElement);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

File diff suppressed because it is too large Load Diff

36
mozilla/rdf/Makefile.in Normal file
View File

@@ -0,0 +1,36 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = base util content datasource resources chrome build
ifdef MOZ_BRPROF
DIRS += brprof
endif
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,28 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = idl public src
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,15 @@
nsIRDFCompositeDataSource.idl
nsIRDFContainer.idl
nsIRDFContainerUtils.idl
nsIRDFDataSource.idl
nsIRDFLiteral.idl
nsIRDFNode.idl
nsIRDFObserver.idl
nsIRDFPurgeableDataSource.idl
nsIRDFRemoteDataSource.idl
nsIRDFResource.idl
nsIRDFService.idl
nsIRDFXMLSink.idl
nsIRDFXMLSource.idl
nsIXULSortService.idl
xulstubs.idl

View File

@@ -0,0 +1,47 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdf
XPIDLSRCS = \
nsIRDFCompositeDataSource.idl \
nsIRDFContainer.idl \
nsIRDFContainerUtils.idl \
nsIRDFDataSource.idl \
nsIRDFLiteral.idl \
nsIRDFNode.idl \
nsIRDFObserver.idl \
nsIRDFPurgeableDataSource.idl \
nsIRDFRemoteDataSource.idl \
nsIRDFResource.idl \
nsIRDFService.idl \
nsIRDFXMLSink.idl \
nsIRDFXMLSource.idl \
nsIController.idl \
xulstubs.idl \
nsIXULSortService.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,40 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
MODULE=rdf
XPIDLSRCS= .\nsIRDFNode.idl \
.\nsIRDFResource.idl \
.\nsIRDFLiteral.idl \
.\nsIRDFObserver.idl \
.\nsIRDFDataSource.idl \
.\nsIRDFCompositeDataSource.idl \
.\nsIRDFService.idl \
.\nsIRDFContainer.idl \
.\nsIRDFContainerUtils.idl \
.\nsIRDFPurgeableDataSource.idl \
.\nsIRDFRemoteDataSource.idl \
.\nsIRDFXMLSink.idl \
.\nsIRDFXMLSource.idl \
.\nsIController.idl \
.\xulstubs.idl \
.\nsIXULSortService.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,27 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
interface nsIDOMXULCommandDispatcher;
[scriptable, uuid(D5B61B82-1DA4-11d3-BF87-00105A1B0627)]
interface nsIController : nsISupports {
attribute nsIDOMXULCommandDispatcher commandDispatcher;
boolean IsCommandEnabled(in string command);
void DoCommand(in string command);
};

View File

@@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIRDFDataSource.idl"
// An nsIRDFCompositeDataSource composes individual data sources, providing
// the illusion of a single, coherent RDF graph.
[scriptable, uuid(96343820-307C-11D2-BC15-00805F912FE7)]
interface nsIRDFCompositeDataSource : nsIRDFDataSource {
attribute boolean allowNegativeAssertions; // true by default
attribute boolean coalesceDuplicateArcs; // true by default
// Add a datasource the the database.
void AddDataSource(in nsIRDFDataSource aDataSource);
// Remove a datasource from the database
void RemoveDataSource(in nsIRDFDataSource aDataSource);
};
%{C++
extern nsresult
NS_NewRDFCompositeDataSource(nsIRDFCompositeDataSource** result);
%}

View File

@@ -0,0 +1,106 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIRDFDataSource.idl"
#include "nsIRDFResource.idl"
#include "nsIRDFNode.idl"
#include "nsIEnumerator.idl"
// A wrapper for manipulating RDF containers
[scriptable, uuid(D4214E90-FB94-11D2-BDD8-00104BDE6048)]
interface nsIRDFContainer : nsISupports {
readonly attribute nsIRDFDataSource DataSource;
readonly attribute nsIRDFResource Resource;
/**
* Initialize the container wrapper to the specified resource
* using the specified datasource for context.
*/
void Init(in nsIRDFDataSource aDataSource, in nsIRDFResource aContainer);
/**
* Return the number of elements in the container. Note that this
* may not always be accurate due to aggregation.
*/
long GetCount();
/**
* Return an enumerator that can be used to enumerate the contents
* of the container in ascending order.
*/
nsISimpleEnumerator GetElements();
/**
* Append an element to the container, assigning it the next
* available ordinal.
*/
void AppendElement(in nsIRDFNode aElement);
/**
* Remove the first occurence of the specified element from the
* container. If aRenumber is 'true'
*/
void RemoveElement(in nsIRDFNode aElement, in boolean aRenumber);
/**
* Insert aElement at the specified index. If aRenumber is 'true', then
* the underlying RDF graph will be 're-numbered' to accomodate the new
* element.
*/
void InsertElementAt(in nsIRDFNode aElement, in long aIndex, in boolean aRenumber);
/**
* Remove the element at the specified index. If aRenumber is 'true', then
* the underlying RDF graph will be 're-numbered' to accomodate the new
* element.
*
* @return the element that was removed.
*/
nsIRDFNode RemoveElementAt(in long aIndex, in boolean aRenumber);
/**
* Determine the index of an element in the container.
*
* @return The index of the specified element in the container. If
* the element is not contained in the container, this function
* returns '-1'.
*/
long IndexOf(in nsIRDFNode aElement);
};
%{C++
nsresult
NS_NewRDFContainer(nsIRDFContainer** aResult);
nsresult
NS_NewRDFContainer(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource,
nsIRDFContainer** aResult);
/**
* Create a cursor on a container that enumerates its contents in
* order
*/
nsresult
NS_NewContainerEnumerator(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer,
nsISimpleEnumerator** aResult);
%}

View File

@@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIRDFContainer.idl"
#include "nsIRDFResource.idl"
// Container utilities
[scriptable, uuid(D4214E91-FB94-11D2-BDD8-00104BDE6048)]
interface nsIRDFContainerUtils : nsISupports {
// Returns 'true' if the property is an RDF ordinal property.
boolean IsOrdinalProperty(in nsIRDFResource aProperty);
// Convert the specified index to an ordinal property.
nsIRDFResource IndexToOrdinalResource(in long aIndex);
// Convert the specified ordinal property into an index
long OrdinalResourceToIndex(in nsIRDFResource aOrdinal);
// Return 'true' if the specified resource is a container
boolean IsContainer(in nsIRDFDataSource aDataSource, in nsIRDFResource aResource);
// Return 'true' if the specified resource is a bag
boolean IsBag(in nsIRDFDataSource aDataSource, in nsIRDFResource aResource);
// Return 'true' if the specified resource is a sequence
boolean IsSeq(in nsIRDFDataSource aDataSource, in nsIRDFResource aResource);
// Return 'true' if the specified resource is an alternation
boolean IsAlt(in nsIRDFDataSource aDataSource, in nsIRDFResource aResource);
// Decorates the specified resource appropriately to make it
// usable as an empty bag in the specified data source.
nsIRDFContainer MakeBag(in nsIRDFDataSource aDataSource, in nsIRDFResource aResource);
// Decorates the specified resource appropriately to make it
// usable as an empty sequence in the specified data source.
nsIRDFContainer MakeSeq(in nsIRDFDataSource aDataSource, in nsIRDFResource aResource);
// Decorates the specified resource appropriately to make it
// usable as an empty alternation in the specified data source.
nsIRDFContainer MakeAlt(in nsIRDFDataSource aDataSource, in nsIRDFResource aResource);
};
%{C++
extern nsresult
NS_NewRDFContainerUtils(nsIRDFContainerUtils** aResult);
%}

View File

@@ -0,0 +1,196 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsISupportsArray.idl"
#include "nsIRDFResource.idl"
#include "nsIRDFNode.idl"
#include "nsIEnumerator.idl"
#include "nsIRDFObserver.idl"
%{C++
#include "nsISupportsArray.h"
%}
[scriptable, uuid(0F78DA58-8321-11d2-8EAC-00805F29F370)]
interface nsIRDFDataSource : nsISupports
{
/** The "URI" of the data source. This used by the RDF service's
* |GetDataSource()| method to cache datasources.
*/
readonly attribute string URI;
/** Find an RDF resource that points to a given node over the
* specified arc & truth value
*
* @return NS_RDF_NO_VALUE if there is no source that leads
* to the target with the specified property.
*/
nsIRDFResource GetSource(in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
/**
* Find all RDF resources that point to a given node over the
* specified arc & truth value
*
* @return NS_OK unless a catastrophic error occurs. If the
* method returns NS_OK, you may assume that nsISimpleEnumerator points
* to a valid (but possibly empty) cursor.
*/
nsISimpleEnumerator GetSources(in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
/**
* Find a child of that is related to the source by the given arc
* arc and truth value
*
* @return NS_RDF_NO_VALUE if there is no target accessable from the
* source via the specified property.
*/
nsIRDFNode GetTarget(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in boolean aTruthValue);
/**
* Find all children of that are related to the source by the given arc
* arc and truth value.
*
* @return NS_OK unless a catastrophic error occurs. If the
* method returns NS_OK, you may assume that nsISimpleEnumerator points
* to a valid (but possibly empty) cursor.
*/
nsISimpleEnumerator GetTargets(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in boolean aTruthValue);
/**
* Add an assertion to the graph.
*/
void Assert(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
/**
* Remove an assertion from the graph.
*/
void Unassert(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
/**
* Change an assertion from
*
* [aSource]--[aProperty]-->[aOldTarget]
*
* to
*
* [aSource]--[aProperty]-->[aNewTarget]
*/
void Change(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aOldTarget,
in nsIRDFNode aNewTarget);
/**
* 'Move' an assertion from
*
* [aOldSource]--[aProperty]-->[aTarget]
*
* to
*
* [aNewSource]--[aProperty]-->[aTarget]
*/
void Move(in nsIRDFResource aOldSource,
in nsIRDFResource aNewSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
/**
* Query whether an assertion exists in this graph.
*/
boolean HasAssertion(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
/**
* Add an observer to this data source. If the datasource
* supports observers, the datasource source should hold a strong
* reference to the observer.
*/
void AddObserver(in nsIRDFObserver aObserver);
/**
* Remove an observer from this data source.
*/
void RemoveObserver(in nsIRDFObserver aObserver);
/**
* Get a cursor to iterate over all the arcs that point into a node.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsISimpleEnumerator object.
*/
nsISimpleEnumerator ArcLabelsIn(in nsIRDFNode aNode);
/**
* Get a cursor to iterate over all the arcs that originate in
* a resource.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsISimpleEnumerator object.
*/
nsISimpleEnumerator ArcLabelsOut(in nsIRDFResource aSource);
/**
* Retrieve all of the resources that the data source currently
* refers to.
*/
nsISimpleEnumerator GetAllResources();
/**
* Returns the set of all commands defined for a given source.
*/
nsIEnumerator GetAllCommands(in nsIRDFResource aSource);
/**
* Returns whether a given command is enabled for a set of sources.
*/
boolean IsCommandEnabled(in nsISupportsArray aSources,
in nsIRDFResource aCommand,
in nsISupportsArray aArguments);
/**
* Perform the specified command on set of sources.
*/
void DoCommand(in nsISupportsArray aSources,
in nsIRDFResource aCommand,
in nsISupportsArray aArguments);
/**
* Returns the set of all commands defined for a given source.
*/
nsISimpleEnumerator GetAllCmds(in nsIRDFResource aSource);
};

View File

@@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIRDFNode.idl"
%{C++
#include "nscore.h" // for PRUnichar
%}
/**
* A literal node in the graph, whose value is a string.
*/
[scriptable, uuid(E0C493D2-9542-11d2-8EB8-00805F29F370)]
interface nsIRDFLiteral : nsIRDFNode {
/**
* The Unicode string value of the literal.
*/
readonly attribute wstring Value;
/**
* An unscriptable version used to avoid a string copy. Meant
* for use as a performance optimization.
*/
[noscript] void GetValueConst([shared] out wstring aConstValue);
};
/**
* A literal node in the graph, whose value is a date
*/
[scriptable, uuid(E13A24E1-C77A-11d2-80BE-006097B76B8E)]
interface nsIRDFDate : nsIRDFNode {
/**
* The date value of the literal
*/
readonly attribute long long Value;
};
/**
* A literal node in the graph, whose value is an integer
*/
[scriptable, uuid(E13A24E3-C77A-11d2-80BE-006097B76B8E)]
interface nsIRDFInt : nsIRDFNode {
/**
* The integer value of the literal
*/
readonly attribute long Value;
};

View File

@@ -0,0 +1,28 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
// An nsIRDFNode object is an abstract placeholder for a node in the
// RDF data model. Its concreted implementations (e.g., nsIRDFResource
// or nsIRDFLiteral) are the actual objects that populate the graph.
[scriptable, uuid(0F78DA50-8321-11d2-8EAC-00805F29F370)]
interface nsIRDFNode : nsISupports {
// Determine if two nodes are identical
boolean EqualsNode(in nsIRDFNode aNode);
};

View File

@@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIRDFResource.idl"
#include "nsIRDFNode.idl"
// An nsIRDFObserver object is an observer that will be notified
// when assertions are made or removed from a datasource
[scriptable, uuid(3CC75360-484A-11D2-BC16-00805F912FE7)]
interface nsIRDFObserver : nsISupports {
// This method is called whenever a new assertion is made
// in the data source
void OnAssert(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
// This method is called whenever an assertion is removed
// from the data source
void OnUnassert(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
void OnChange(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aOldTarget,
in nsIRDFNode aNewTarget);
void OnMove(in nsIRDFResource aOldSource,
in nsIRDFResource aNewSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
};

View File

@@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIRDFResource.idl"
#include "nsIRDFNode.idl"
[scriptable, uuid(951700F0-FED0-11D2-BDD9-00104BDE6048)]
interface nsIRDFPurgeableDataSource : nsISupports
{
boolean Mark(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
void Sweep();
};

View File

@@ -0,0 +1,34 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
[scriptable, uuid(1D297320-27F7-11d3-BE01-000064657374)]
interface nsIRDFRemoteDataSource : nsISupports
{
// Specify the URI for the data source: this is the prefix
// that will be used to register the data source in the
// data source registry.
void Init(in string uri);
void Refresh(in boolean aBlocking);
// Request that a data source write it's contents out to
// permanent storage if applicable.
void Flush();
};

View File

@@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIRDFNode.idl"
/**
* An nsIRDFResource is an object that has unique identity in the
* RDF data model. The object's identity is determined by its URI.
*/
[scriptable, uuid(E0C493D1-9542-11d2-8EB8-00805F29F370)]
interface nsIRDFResource : nsIRDFNode {
/**
* The single-byte string value of the resource
*/
readonly attribute string Value;
/**
* An unscriptable version used to avoid a string copy. Meant
* for use as a performance optimization.
*/
[noscript] void GetValueConst([shared] out string aConstValue);
/**
* This method is called by the nsIRDFService after constructing
* a resource object to initialize it's URI. You would not normally
* call this method directly
*/
void Init(in string uri);
/**
* Determine if the resource has the given URI.
*/
boolean EqualsString(in string aURI);
};

View File

@@ -0,0 +1,125 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIRDFResource.idl"
#include "nsIRDFLiteral.idl"
#include "nsIRDFDataSource.idl"
// The RDF service interface. This is a singleton object, and should be
// obtained from the <tt>nsServiceManager</tt>.
[scriptable, uuid(BFD05261-834C-11d2-8EAC-00805F29F370)]
interface nsIRDFService : nsISupports {
// Construct an RDF resource from a single-byte URI. <tt>nsIRDFSerivce</tt>
// caches resources that are in-use, so multiple calls to <tt>GetResource()</tt>
// for the same <tt>uri</tt> will return identical pointers. FindResource
// is used to find out whether there already exists a resource corresponding to that url.
nsIRDFResource GetResource(in string aURI);
// Construct an RDF resource from a Unicode URI. This is provided
// as a convenience method, allowing automatic, in-line C++
// conversion from <tt>nsString</tt> objects. The <tt>uri</tt> will
// be converted to a single-byte representation internally.
nsIRDFResource GetUnicodeResource(in wstring aURI);
nsIRDFResource GetAnonymousResource();
// Construct an RDF literal from a Unicode string.
nsIRDFLiteral GetLiteral(in wstring aValue);
// Construct an RDF literal from a PRTime.
nsIRDFDate GetDateLiteral(in long long aValue);
// Construct an RDF literal from an int.
nsIRDFInt GetIntLiteral(in long aValue);
boolean IsAnonymousResource(in nsIRDFResource aResource);
// Registers a resource with the RDF system, making it unique w.r.t.
// GetResource.
//
// An implementation of nsIRDFResource should call this in its
// Init() method if it wishes the resource to be globally unique
// (which is usually the case).
//
// NOTE that the resource will <i>not</i> be ref-counted by the
// RDF service: the assumption is that the resource implementation
// will call nsIRDFService::UnregisterResource() when the last
// reference to the resource is released.
//
// NOTE that the nsIRDFService implementation may choose to
// maintain a reference to the resource's URI; therefore, the
// resource implementation should ensure that the resource's URI
// (accessable via nsIRDFResource::GetValue(const char* *aURI)) is
// valid before calling RegisterResource(). Furthermore, the
// resource implementation should ensure that this pointer
// <i>remains</i> valid for the lifetime of the resource. (The
// implementation of the resource cache in nsIRDFService uses the
// URI maintained "internally" in the resource as a key into the
// cache rather than copying the resource URI itself.)
void RegisterResource(in nsIRDFResource aResource, in boolean aReplace);
// Called to notify the resource manager that a resource is no
// longer in use. This method should only be called from the
// destructor of a "custom" resource implementation to notify the
// RDF service that the last reference to the resource has been
// released, so the resource is no longer valid.
//
// NOTE. As mentioned in nsIRDFResourceFactory::CreateResource(),
// the RDF service will use the result of
// nsIRDFResource::GetValue() as a key into its cache. For this
// reason, you must always un-cache the resource <b>before</b>
// releasing the storage for the <tt>const char*</tt> URI.
void UnregisterResource(in nsIRDFResource aResource);
// Register a <i>named data source</i>. The RDF service will call
// <tt>nsIRDFDataSource::GetURI()</tt> to determine the URI under
// which to register the data source.
//
// Note that the data source will <i>not</i> be refcounted by the
// RDF service! The assumption is that an RDF data source
// registers with the service once it is initialized (via
// <tt>nsIRDFDataSource::Init()</tt>), and unregisters when the
// last reference to the data source is released.
void RegisterDataSource(in nsIRDFDataSource aDataSource,
in boolean aReplace);
// Unregister a <i>named data source</i>. The RDF service will call
// <tt>nsIRDFDataSource::GetURI()</tt> to determine the URI under which the
// data source was registered.
void UnregisterDataSource(in nsIRDFDataSource aDataSource);
// Get the <i>named data source</i> corresponding to the URI. If a data
// source has been registered via <tt>RegisterDataSource()</tt>, that
// data source will be returned.
//
// If no data source is currently
// registered for the specified URI, and a data source <i>constructor</i>
// function has been registered via <tt>RegisterDatasourceConstructor()</tt>,
// the RDF service will call the constructor to attempt to construct a
// new data source. If construction is successful, the data source will
// be initialized via <tt>nsIRDFDataSource::Init()</tt>.
nsIRDFDataSource GetDataSource(in string aURI);
};
%{C++
extern nsresult
NS_NewRDFService(nsIRDFService** result);
%}

View File

@@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
// XXX Until these get scriptable. See nsIRDFXMLSink::AddNameSpace()
[ptr] native nsIAtomPtr(nsIAtom);
[ref] native nsStringRef(nsString);
%{C++
class nsIAtom;
class nsString;
%}
interface nsIRDFXMLSink;
[scriptable, uuid(EB1A5D30-AB33-11D2-8EC6-00805F29F370)]
interface nsIRDFXMLSinkObserver : nsISupports
{
void OnBeginLoad(in nsIRDFXMLSink aSink);
void OnInterrupt(in nsIRDFXMLSink aSink);
void OnResume(in nsIRDFXMLSink aSink);
void OnEndLoad(in nsIRDFXMLSink aSink);
};
[scriptable, uuid(EB1A5D31-AB33-11D2-8EC6-00805F29F370)]
interface nsIRDFXMLSink : nsISupports
{
attribute boolean ReadOnly;
void BeginLoad();
void Interrupt();
void Resume();
void EndLoad();
[noscript] void AddNameSpace(in nsIAtomPtr aPrefix,
[const] in nsStringRef aURI);
void AddXMLSinkObserver(in nsIRDFXMLSinkObserver aObserver);
void RemoveXMLSinkObserver(in nsIRDFXMLSinkObserver aObserver);
};

View File

@@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
// XXX Until this gets scriptable
[ptr] native nsIOutputStreamPtr(nsIOutputStream);
%{C++
class nsIOutputStream;
%}
[uuid(4DA56F10-99FE-11d2-8EBB-00805F29F370)]
interface nsIRDFXMLSource : nsISupports
{
void Serialize(in nsIOutputStreamPtr aStream);
};

View File

@@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
#include "nsIRDFCompositeDataSource.idl"
#include "nsIRDFResource.idl"
[ptr] native nsIRDFResourceArray( nsIRDFResource *);
interface nsIContent;
interface nsIDOMNode;
[scriptable, uuid(BFD05261-834C-11d2-8EAC-00805F29F371)]
interface nsIXULSortService : nsISupports
{
void Sort(in nsIDOMNode node, in string sortResource, in string sortDirection);
[noscript] void OpenContainer(in nsIRDFCompositeDataSource db, in nsIContent container,
in nsIRDFResourceArray flatArray, in long numElements, in long elementSize);
[noscript] void InsertContainerNode(in nsIContent container, in nsIContent node, in boolean aNotify);
};
%{C++
extern nsresult
NS_NewXULSortService(nsIXULSortService **result);
%}

View File

@@ -0,0 +1,41 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* DOM stubs so that we can pass DOM objects across XPConnect */
%{C++
/* C++ should ignore this file because there are real DOM interfaces
elsewhere, so if 0 it out
*/
#if 0
%}
#include "domstubs.idl"
[scriptable, uuid(0574ed81-c088-11d2-96ed-00104b7b7deb)]
interface nsIDOMXULElement : nsIDOMElement {};
[scriptable, uuid(a6cf90ec-15b3-11d2-932e-00805f8add32)]
interface nsIDOMXULTreeElement : nsIDOMXULElement {};
[scriptable, uuid(f3c50361-14fe-11d3-bf87-00105a1b0627)]
interface nsIDOMXULFocusTracker : nsISupports {};
%{C++
#endif
%}

View File

@@ -0,0 +1,28 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..
MODULE = rdf
DIRS=\
idl \
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,3 @@
rdf.h
nsIRDFContentSink.h
nsRDFInterfaces.h

View File

@@ -0,0 +1,36 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdf
EXPORTS = \
rdf.h \
nsIRDFContentSink.h \
nsRDFInterfaces.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,31 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
MODULE=rdf
DEPTH=..\..\..
EXPORTS=\
rdf.h \
nsRDFInterfaces.h \
nsIRDFContentSink.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,72 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
An RDF-specific content sink. The content sink is targeted by the
parser for building the RDF content model.
*/
#ifndef nsIRDFContentSink_h___
#define nsIRDFContentSink_h___
#include "nsIXMLContentSink.h"
class nsIDocument;
class nsIRDFDataSource;
class nsINameSpaceManager;
class nsIURI;
// {751843E2-8309-11d2-8EAC-00805F29F370}
#define NS_IRDFCONTENTSINK_IID \
{ 0x751843e2, 0x8309, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* This interface represents a content sink for RDF files.
*/
class nsIRDFContentSink : public nsIXMLContentSink {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IRDFCONTENTSINK_IID; return iid; }
/**
* Initialize the content sink.
*/
NS_IMETHOD Init(nsIURI* aURL, nsINameSpaceManager* aNameSpaceManager) = 0;
/**
* Set the content sink's RDF Data source
*/
NS_IMETHOD SetDataSource(nsIRDFDataSource* aDataSource) = 0;
/**
* Retrieve the content sink's RDF data source.
*/
NS_IMETHOD GetDataSource(nsIRDFDataSource*& rDataSource) = 0;
};
/**
* This constructs a content sink that can be used without a
* document, say, to create a stand-alone in-memory graph.
*/
nsresult
NS_NewRDFContentSink(nsIRDFContentSink** aResult);
#endif // nsIRDFContentSink_h___

View File

@@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
The RDF resource factory interface. A resource factory produces
nsIRDFResource objects for a specified URI prefix.
*/
#ifndef nsIRDFResourceFactory_h__
#define nsIRDFResourceFactory_h__
#if 0 // obsolete
#include "nsISupports.h"
class nsIRDFResource;
// {8CE57A20-A02C-11d2-8EBF-00805F29F370}
#define NS_IRDFRESOURCEFACTORY_IID \
{ 0x8ce57a20, 0xa02c, 0x11d2, { 0x8e, 0xbf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A resource factory can be registered with <tt>nsIRDFService</tt> to produce
* resources with a certain <i>URI prefix</i>. The resource factory will be called
* upon to create a new resource, which the resource manager will cache.
*
* @see nsIRDFService::RegisterResourceFactory
* @see nsIRDFService::UnRegisterResourceFactory
*/
class nsIRDFResourceFactory : public nsISupports
{
public:
static const nsIID& GetIID() { static nsIID iid = NS_IRDFRESOURCEFACTORY_IID; return iid; }
/**
* This method is called by the RDF service to create a new
* resource.
*
* NOTE. After constructing a new resource via a call to
* nsIRDFResourceFactory::CreateResource(), the implementation of
* the RDF service calls nsIRDFResource::GetValue() on the
* resulting resource. The resulting <tt>const char*</tt> is used
* as a key for the resource cache. (The assumption is that the
* custom resource implementation needs to store this information,
* anyway.)
*
* This has important implications for a custom resource's
* destructor; namely, that you must call
* nsIRDFService::UnCacheResource() <b>before</b> releasing the
* storage for the resource's URI. See
* nsIRDFService::UnCacheResource() for more information.
*/
NS_IMETHOD CreateResource(const char* aURI, nsIRDFResource** aResult) = 0;
};
#endif
#endif // nsIRDFResourceFactory_h__

View File

@@ -0,0 +1,60 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIRDFTree_h__
#define nsIRDFTree_h__
#include "nscore.h"
#include "nsISupports.h"
#include "prtypes.h"
#include "rdf.h" // for error codes
/*
An interface for presenting a tree view of an rdf datasource (or
database).
Any datasource can also support nsIRDFTree. The interface is purely
syntactic sugar for traversing simple tree where the child relation
corresponds to the property type nc:child (nc = http://home.netscape.com/NC-rdf#).
Each leaf is assumed to have a certain predefined set of properties
such as creationDate, size, lastModificationDate, lastVisitDate, etc.
This interface is substantially less general than nsIRDFDataSource,
but is adequate for bookmarks, the file system, history and a few
other very commonly used data sources.
*/
// {7D7EEBD1-AA41-11d2-80B7-006097B76B8E}
#define NS_IRDFTREE_IID \
{ 0x7d7eebd1, 0xaa41, 0x11d2, { 0x80, 0xb7, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } };
class nsIRDFTree : public nsISupports {
public:
NS_IMETHOD ListChildren (nsIRDFResource* folder, nsVoidArray** result);
// XXX should define something called nsResourceArray and use that
NS_IMETHOD IsFolder (nsIRDFResource* node, PRBool* result);
NS_IMETHOD GetProperty (nsIRDFResource* node, nsIRDFResource* property,
nsIRDFNode** result);
}
#endif

View File

@@ -0,0 +1,165 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
This interface encapsulates information about an RDF/XML file,
including the root resource, CSS style sheets, and named data
sources.
This file also includes an observer interface for nsIRDFXMLDocument
objects.
*/
#ifndef nsIRDFXMLDocument_h__
#define nsIRDFXMLDocument_h__
#include "nsISupports.h"
class nsIOutputStream;
class nsIURI;
// {EB1A5D30-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDOCUMENTOBSERVER_IID \
{ 0xeb1a5d30, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDocumentObserver : public nsISupports
{
public:
/**
* Called when the RDF/XML document begins to load.
*/
NS_IMETHOD OnBeginLoad(void) = 0;
/**
* Called when the RDF/XML document load is interrupted for some reason.
*/
NS_IMETHOD OnInterrupt(void) = 0;
/**
* Called when an interrupted RDF/XML document load is resumed.
*/
NS_IMETHOD OnResume(void) = 0;
/**
* Called whtn the RDF/XML document load is complete.
*/
NS_IMETHOD OnEndLoad(void) = 0;
/**
* Called when the root resource of the RDF/XML document is found
*/
NS_IMETHOD OnRootResourceFound(nsIRDFResource* aResource) = 0;
/**
* Called when a CSS style sheet is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnCSSStyleSheetAdded(nsIURI* aCSSStyleSheetURL) = 0;
/**
* Called when a named data source is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnNamedDataSourceAdded(const char* aNamedDataSourceURI) = 0;
};
// {EB1A5D31-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDOCUMENT_IID \
{ 0xeb1a5d31, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDocument : public nsISupports
{
public:
/**
* Notify the document that the load is beginning.
*/
NS_IMETHOD BeginLoad(void) = 0;
/**
* Notify the document that the load is being interrupted.
*/
NS_IMETHOD Interrupt(void) = 0;
/**
* Notify the document that an interrupted load is being resumed.
*/
NS_IMETHOD Resume(void) = 0;
/**
* Notify the document that the load is ending.
*/
NS_IMETHOD EndLoad(void) = 0;
/**
* Set the root resource for the document.
*/
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
/**
* Retrieve the root resource for the document.
*/
NS_IMETHOD GetRootResource(nsIRDFResource** aResource) = 0;
/**
* Add a CSS style sheet to the document.
* @param aStyleSheetURL An nsIURI object that is the URL of the style
* sheet to add to the document.
*/
NS_IMETHOD AddCSSStyleSheetURL(nsIURI* aStyleSheetURL) = 0;
/**
* Get the set of style sheets that have been included in the
* document.
* @param aStyleSheetURLs (out) A pointer to an array of pointers to nsIURI objects.
* @param aCount (out) The number of nsIURI objects returned.
*/
NS_IMETHOD GetCSSStyleSheetURLs(nsIURI*** aStyleSheetURLs, PRInt32* aCount) = 0;
/**
* Add a named data source to the document.
* @param aNamedDataSoruceURI A URI identifying the data source.
*/
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI) = 0;
/**
* Get the set of named data sources that have been included in
* the document
* @param aNamedDataSourceURIs (out) A pointer to an array of C-style character
* strings.
* @param aCount (out) The number of named data sources in the array.
*/
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount) = 0;
/**
* Add an observer to the document. The observer will be notified of
* RDF/XML events via the nsIRDFXMLDocumentObserver interface. Note that
* the observer is <em>not</em> reference counted.
*/
NS_IMETHOD AddDocumentObserver(nsIRDFXMLDocumentObserver* aObserver) = 0;
/**
* Remove an observer from the document.
*/
NS_IMETHOD RemoveDocumentObserver(nsIRDFXMLDocumentObserver* aObserver) = 0;
};
#endif // nsIRDFXMLDocument_h__

View File

@@ -0,0 +1,40 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsRDFInterfaces_h__
#define nsRDFInterfaces_h__
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFContentSink.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFLiteral.h"
#include "nsIRDFNode.h"
#include "nsIRDFObserver.h"
#include "nsIRDFPurgeableDataSource.h"
#include "nsIRDFResource.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFXMLSource.h"
#include "nsRDFInterfaces.h"
#include "rdf.h"
#endif // nsRDFInterfaces_h__

View File

@@ -0,0 +1,109 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
A catch-all header file for miscellaneous RDF stuff. Currently
contains error codes and vocabulary macros.
*/
#ifndef rdf_h___
#define rdf_h___
#include "nsError.h"
/**
* The following macros are to aid in vocabulary definition. They
* creates const char*'s for "kURI[prefix]_[name]", appropriate
* complete namespace qualification on the URI, e.g.,
*
* #define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
* DEFINE_RDF_ELEMENT(RDF_NAMESPACE_URI, RDF, ID);
*
* will define:
*
* kURIRDF_ID to be "http://www.w3.org/TR/WD-rdf-syntax#ID"
*/
#define DEFINE_RDF_VOCAB(ns, prefix, name) \
static const char* kURI##prefix##_##name = ns #name
/**
* Core RDF vocabularies that we use to define semantics
*/
#define RDF_NAMESPACE_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
#define WEB_NAMESPACE_URI "http://home.netscape.com/WEB-rdf#"
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
/**
* @name Standard RDF error codes
*/
/*@{*/
/* Returned from nsIRDFCursor::Advance() if the cursor has no more
elements to enuemrate */
#define NS_RDF_CURSOR_EMPTY NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_RDF, 1)
/* Returned from nsIRDFDataSource::GetSource() and GetTarget() if the source/target
has no value */
#define NS_RDF_NO_VALUE NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_RDF, 2)
/* Returned from nsIRDFDataSource::Assert() and Unassert() if the assertion (or
unassertion was accepted by the datasource*/
#define NS_RDF_ASSERTION_ACCEPTED NS_OK
/* Returned from nsIRDFDataSource::Assert() and Unassert() if the assertion (or
unassertion) was rejected by the datasource; i.e., the datasource was not
willing to record the statement. */
#define NS_RDF_ASSERTION_REJECTED NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_RDF, 3)
/* ProgID prefixes for RDF DLL registration. */
#define NS_RDF_PROGID "component://netscape/rdf"
#define NS_RDF_DATASOURCE_PROGID NS_RDF_PROGID "/datasource"
#define NS_RDF_DATASOURCE_PROGID_PREFIX NS_RDF_DATASOURCE_PROGID "?name="
#define NS_RDF_RESOURCE_FACTORY_PROGID "component://netscape/rdf/resource-factory"
#define NS_RDF_RESOURCE_FACTORY_PROGID_PREFIX NS_RDF_RESOURCE_FACTORY_PROGID "?name="
/*@}*/
#ifdef _IMPL_NS_RDF
#ifdef XP_PC
#define NS_RDF _declspec(dllexport)
#else /* !XP_PC */
#ifdef MOZ_STRIP_NOT_EXPORTED
#define NS_RDF __attribute__ ((dllexport))
#else
#define NS_RDF
#endif /* !MOZ_STRIP_NOT_EXPORTED */
#endif /* !XP_PC */
#else /* !_IMPL_NS_RDF */
#ifdef XP_PC
#define NS_RDF _declspec(dllimport)
#else /* !XP_PC */
#define NS_RDF
#endif /* !XP_PC */
#endif /* !_IMPL_NS_RDF */
#endif /* rdf_h___ */

View File

@@ -0,0 +1,49 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdfbase
LIBRARY_NAME = rdfbase_s
REQUIRES = netlib rdf rdfutil raptor xpcom
CPPSRCS = \
nsCompositeDataSource.cpp \
nsContainerEnumerator.cpp \
nsDefaultResourceFactory.cpp \
nsInMemoryDataSource.cpp \
nsRDFContentSink.cpp \
nsRDFContainer.cpp \
nsRDFContainerUtils.cpp \
nsRDFParserUtils.cpp \
nsRDFService.cpp \
nsRDFXMLDataSource.cpp \
rdfutil.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,45 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
LCFLAGS=
MODULE=rdf
LIBRARY_NAME=rdfbase_s
CPP_OBJS=\
.\$(OBJDIR)\nsCompositeDataSource.obj \
.\$(OBJDIR)\nsContainerEnumerator.obj \
.\$(OBJDIR)\nsDefaultResourceFactory.obj \
.\$(OBJDIR)\nsInMemoryDataSource.obj \
.\$(OBJDIR)\nsRDFContentSink.obj \
.\$(OBJDIR)\nsRDFContainer.obj \
.\$(OBJDIR)\nsRDFContainerUtils.obj \
.\$(OBJDIR)\nsRDFParserUtils.obj \
.\$(OBJDIR)\nsRDFService.obj \
.\$(OBJDIR)\nsRDFXMLDataSource.obj \
.\$(OBJDIR)\rdfutil.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,251 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
A simple cursor that enumerates the elements of an RDF container
(RDF:Bag, RDF:Seq, or RDF:Alt).
Caveats
-------
1. This uses an implementation-specific detail to determine the
index of the last element in the container; specifically, the RDF
utilities maintain a counter attribute on the container that
holds the numeric value of the next value that is to be
assigned. So, this cursor will bust if you use it with a bag that
hasn't been created using the RDF utility routines.
*/
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "prlog.h"
#include "rdf.h"
#include "rdfutil.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
////////////////////////////////////////////////////////////////////////
class ContainerEnumeratorImpl : public nsISimpleEnumerator {
private:
// pseudo-constants
static nsrefcnt gRefCnt;
static nsIRDFResource* kRDF_nextVal;
nsCOMPtr<nsIRDFDataSource> mDataSource;
nsCOMPtr<nsIRDFResource> mContainer;
nsCOMPtr<nsIRDFResource> mOrdinalProperty;
nsISimpleEnumerator* mCurrent;
nsIRDFNode* mResult;
PRInt32 mNextIndex;
public:
ContainerEnumeratorImpl(nsIRDFDataSource* ds, nsIRDFResource* container);
virtual ~ContainerEnumeratorImpl(void);
NS_DECL_ISUPPORTS
NS_DECL_NSISIMPLEENUMERATOR
};
nsrefcnt ContainerEnumeratorImpl::gRefCnt;
nsIRDFResource* ContainerEnumeratorImpl::kRDF_nextVal;
ContainerEnumeratorImpl::ContainerEnumeratorImpl(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer)
: mCurrent(nsnull),
mResult(nsnull),
mNextIndex(1)
{
NS_INIT_REFCNT();
mDataSource = dont_QueryInterface(aDataSource);
mContainer = dont_QueryInterface(aContainer);
if (gRefCnt++ == 0) {
nsresult rv;
NS_WITH_SERVICE(nsIRDFService, service, kRDFServiceCID, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to acquire resource manager");
if (NS_FAILED(rv))
return;
rv = service->GetResource(RDF_NAMESPACE_URI "nextVal", &kRDF_nextVal);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
}
}
ContainerEnumeratorImpl::~ContainerEnumeratorImpl(void)
{
NS_IF_RELEASE(mResult);
NS_IF_RELEASE(mCurrent);
if (--gRefCnt == 0) {
NS_IF_RELEASE(kRDF_nextVal);
}
}
NS_IMPL_ISUPPORTS(ContainerEnumeratorImpl, nsISimpleEnumerator::GetIID());
NS_IMETHODIMP
ContainerEnumeratorImpl::HasMoreElements(PRBool* aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsresult rv;
// If we've already queued up a next value, then we know there are more elements.
if (mResult) {
*aResult = PR_TRUE;
return NS_OK;
}
// Otherwise, we need to grovel
// Figure out the upper bound so we'll know when we're done.
nsCOMPtr<nsIRDFNode> nextValNode;
rv = mDataSource->GetTarget(mContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));
if (NS_FAILED(rv)) return rv;
if (rv != NS_OK)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIRDFLiteral> nextVal = do_QueryInterface(nextValNode);
if (! nextVal)
return NS_ERROR_UNEXPECTED;
nsXPIDLString nextValStr;
rv = nextVal->GetValue(getter_Copies(nextValStr));
if (NS_FAILED(rv)) return rv;
PRInt32 err;
PRInt32 count = nsAutoString(nextValStr).ToInteger(&err);
if (NS_FAILED(err))
return NS_ERROR_UNEXPECTED;
// Now iterate through each index.
while (mNextIndex < count) {
if (! mCurrent) {
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = rdfc->IndexToOrdinalResource(mNextIndex, getter_AddRefs(mOrdinalProperty));
if (NS_FAILED(rv)) return rv;
rv = mDataSource->GetTargets(mContainer, mOrdinalProperty, PR_TRUE, &mCurrent);
if (NS_FAILED(rv)) return rv;
++mNextIndex;
}
do {
PRBool hasMore;
rv = mCurrent->HasMoreElements(&hasMore);
if (NS_FAILED(rv)) return rv;
// Is the current enumerator depleted?
if (! hasMore) {
NS_RELEASE(mCurrent);
break;
}
// "Peek" ahead and pull out the next target.
nsCOMPtr<nsISupports> result;
rv = mCurrent->GetNext(getter_AddRefs(result));
if (NS_FAILED(rv)) return rv;
rv = result->QueryInterface(nsIRDFNode::GetIID(), (void**) &mResult);
if (NS_FAILED(rv)) return rv;
*aResult = PR_TRUE;
return NS_OK;
} while (1);
}
// If we get here, we ran out of elements. The cursor is empty.
*aResult = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
ContainerEnumeratorImpl::GetNext(nsISupports** aResult)
{
nsresult rv;
PRBool hasMore;
rv = HasMoreElements(&hasMore);
if (NS_FAILED(rv)) return rv;
if (! hasMore)
return NS_ERROR_UNEXPECTED;
// Don't AddRef: we "transfer" ownership to the caller
*aResult = mResult;
mResult = nsnull;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewContainerEnumerator(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer,
nsISimpleEnumerator** aResult)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aContainer != nsnull, "null ptr");
if (! aContainer)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
ContainerEnumeratorImpl* result = new ContainerEnumeratorImpl(aDataSource, aContainer);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aResult = result;
return NS_OK;
}

View File

@@ -0,0 +1,43 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
The default resource factory implementation. This resource factory
produces nsIRDFResource objects for any URI prefix that is not
covered by some other factory.
*/
#include "nsRDFResource.h"
nsresult
NS_NewDefaultResource(nsIRDFResource** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRDFResource* resource = new nsRDFResource();
if (! resource)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(resource);
*aResult = resource;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
This header file just contains prototypes for the factory methods
for "builtin" data sources that are included in rdf.dll.
Each of these data sources is exposed to the external world via its
CID in ../include/nsRDFCID.h.
*/
#ifndef nsBaseDataSources_h__
#define nsBaseDataSources_h__
#include "nsError.h"
class nsIRDFDataSource;
// in nsInMemoryDataSource.cpp
NS_IMETHODIMP
NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResult);
// in nsRDFXMLDataSource.cpp
extern nsresult
NS_NewRDFXMLDataSource(nsIRDFDataSource** aResult);
#endif // nsBaseDataSources_h__

View File

@@ -0,0 +1,688 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
Implementation for the RDF container.
Notes
-----
1. RDF containers are one-indexed. This means that a lot of the loops
that you'd normally think you'd write like this:
for (i = 0; i < count; ++i) {}
You've gotta write like this:
for (i = 1; i <= count; ++i) {}
"Sure, right, yeah, of course.", you say. Well maybe I'm just
thick, but it's easy to slip up.
2. The RDF:nextVal property on the container is an
implementation-level hack that is used to quickly compute the
next value for appending to the container. It will no doubt
become royally screwed up in the case of aggregation.
3. The RDF:nextVal property is also used to retrieve the count of
elements in the container.
*/
#include "nsCOMPtr.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "rdf.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
class RDFContainerImpl : public nsIRDFContainer
{
public:
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFContainer interface
NS_DECL_NSIRDFCONTAINER
private:
friend nsresult NS_NewRDFContainer(nsIRDFContainer** aResult);
RDFContainerImpl();
virtual ~RDFContainerImpl();
nsresult Renumber(PRInt32 aStartIndex, PRInt32 aIncrement);
nsresult SetNextValue(PRInt32 aIndex);
nsresult GetNextValue(nsIRDFResource** aResult);
nsIRDFDataSource* mDataSource;
nsIRDFResource* mContainer;
// pseudo constants
static PRInt32 gRefCnt;
static nsIRDFService* gRDFService;
static nsIRDFContainerUtils* gRDFContainerUtils;
static nsIRDFResource* kRDF_nextVal;
};
PRInt32 RDFContainerImpl::gRefCnt = 0;
nsIRDFService* RDFContainerImpl::gRDFService;
nsIRDFContainerUtils* RDFContainerImpl::gRDFContainerUtils;
nsIRDFResource* RDFContainerImpl::kRDF_nextVal;
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ISUPPORTS(RDFContainerImpl, nsIRDFContainer::GetIID());
////////////////////////////////////////////////////////////////////////
// nsIRDFContainer interface
NS_IMETHODIMP
RDFContainerImpl::GetDataSource(nsIRDFDataSource** _retval)
{
*_retval = mDataSource;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP
RDFContainerImpl::GetResource(nsIRDFResource** _retval)
{
*_retval = mContainer;
NS_IF_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP
RDFContainerImpl::Init(nsIRDFDataSource *aDataSource, nsIRDFResource *aContainer)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aContainer != nsnull, "null ptr");
if (! aContainer)
return NS_ERROR_NULL_POINTER;
nsresult rv;
PRBool isContainer;
rv = gRDFContainerUtils->IsContainer(aDataSource, aContainer, &isContainer);
if (NS_FAILED(rv)) return rv;
if (! isContainer) {
#ifdef DEBUG
nsCAutoString msg;
nsXPIDLCString uri;
aContainer->GetValue(getter_Copies(uri));
msg += uri;
msg += " is not an RDF container";
NS_WARNING((const char*) msg);
#endif
return NS_ERROR_UNEXPECTED;
}
NS_IF_RELEASE(mDataSource);
mDataSource = aDataSource;
NS_ADDREF(mDataSource);
NS_IF_RELEASE(mContainer);
mContainer = aContainer;
NS_ADDREF(mContainer);
return NS_OK;
}
NS_IMETHODIMP
RDFContainerImpl::GetCount(PRInt32 *aCount)
{
NS_PRECONDITION(aCount != nsnull, "null ptr");
if (! aCount)
return NS_ERROR_NULL_POINTER;
nsresult rv;
// Get the next value, which hangs off of the bag via the
// RDF:nextVal property. This is the _next value_ that will get
// assigned in a one-indexed array. So, it's actually _one more_
// than the actual count of elements in the container.
//
// XXX To handle aggregation, this should probably be a
// GetTargets() that enumerates all of the values and picks the
// largest one.
nsCOMPtr<nsIRDFNode> nextValNode;
rv = mDataSource->GetTarget(mContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));
if (NS_FAILED(rv)) return rv;
if (rv == NS_RDF_NO_VALUE)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIRDFLiteral> nextValLiteral;
rv = nextValNode->QueryInterface(nsIRDFLiteral::GetIID(), getter_AddRefs(nextValLiteral));
if (NS_FAILED(rv)) return rv;
nsXPIDLString s;
rv = nextValLiteral->GetValue( getter_Copies(s) );
if (NS_FAILED(rv)) return rv;
nsAutoString nextValStr = (const PRUnichar*) s;
PRInt32 nextVal;
PRInt32 err;
nextVal = nextValStr.ToInteger(&err);
if (NS_FAILED(err))
return NS_ERROR_UNEXPECTED;
*aCount = nextVal - 1;
return NS_OK;
}
NS_IMETHODIMP
RDFContainerImpl::GetElements(nsISimpleEnumerator **_retval)
{
return NS_NewContainerEnumerator(mDataSource, mContainer, _retval);
}
NS_IMETHODIMP
RDFContainerImpl::AppendElement(nsIRDFNode *aElement)
{
NS_PRECONDITION(aElement != nsnull, "null ptr");
if (! aElement)
return NS_ERROR_NULL_POINTER;
nsresult rv;
nsCOMPtr<nsIRDFResource> nextVal;
rv = GetNextValue(getter_AddRefs(nextVal));
if (NS_FAILED(rv)) return rv;
rv = mDataSource->Assert(mContainer, nextVal, aElement, PR_TRUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
RDFContainerImpl::RemoveElement(nsIRDFNode *aElement, PRBool aRenumber)
{
NS_PRECONDITION(aElement != nsnull, "null ptr");
if (! aElement)
return NS_ERROR_NULL_POINTER;
nsresult rv;
PRInt32 idx;
rv = IndexOf(aElement, &idx);
if (NS_FAILED(rv)) return rv;
if (idx < 0) {
NS_WARNING("attempt to remove non-existant element");
return NS_OK;
}
// Remove the element.
nsCOMPtr<nsIRDFResource> ordinal;
rv = gRDFContainerUtils->IndexToOrdinalResource(idx,
getter_AddRefs(ordinal));
if (NS_FAILED(rv)) return rv;
rv = mDataSource->Unassert(mContainer, ordinal, aElement);
if (NS_FAILED(rv)) return rv;
if (aRenumber) {
// Now slide the rest of the collection backwards to fill in
// the gap. This will have the side effect of completely
// renumber the container from index to the end.
rv = Renumber(idx + 1, -1);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}
NS_IMETHODIMP
RDFContainerImpl::InsertElementAt(nsIRDFNode *aElement, PRInt32 aIndex, PRBool aRenumber)
{
NS_PRECONDITION(aElement != nsnull, "null ptr");
if (! aElement)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aIndex >= 1, "illegal value");
if (aIndex < 1)
return NS_ERROR_ILLEGAL_VALUE;
nsresult rv;
PRInt32 count;
rv = GetCount(&count);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(aIndex <= count + 1, "illegal value");
if (aIndex > count + 1)
return NS_ERROR_ILLEGAL_VALUE;
if (aRenumber) {
// Make a hole for the element. This will have the side effect of
// completely renumbering the container from 'aIndex' to 'count',
// and will spew assertions.
rv = Renumber(aIndex, +1);
if (NS_FAILED(rv)) return rv;
}
nsCOMPtr<nsIRDFResource> ordinal;
rv = gRDFContainerUtils->IndexToOrdinalResource(aIndex, getter_AddRefs(ordinal));
if (NS_FAILED(rv)) return rv;
rv = mDataSource->Assert(mContainer, ordinal, aElement, PR_TRUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
RDFContainerImpl::RemoveElementAt(PRInt32 aIndex, PRBool aRenumber, nsIRDFNode** _retval)
{
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (! _retval)
return NS_ERROR_NULL_POINTER;
*_retval = nsnull;
if (aIndex< 1)
return NS_ERROR_ILLEGAL_VALUE;
nsresult rv;
PRInt32 count;
rv = GetCount(&count);
if (NS_FAILED(rv)) return rv;
if (aIndex > count)
return NS_ERROR_ILLEGAL_VALUE;
nsCOMPtr<nsIRDFResource> ordinal;
rv = gRDFContainerUtils->IndexToOrdinalResource(aIndex, getter_AddRefs(ordinal));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> old;
rv = mDataSource->GetTarget(mContainer, ordinal, PR_TRUE, getter_AddRefs(old));
if (NS_FAILED(rv)) return rv;
if (rv == NS_OK) {
rv = mDataSource->Unassert(mContainer, ordinal, old);
if (NS_FAILED(rv)) return rv;
if (aRenumber) {
// Now slide the rest of the collection backwards to fill in
// the gap. This will have the side effect of completely
// renumber the container from index to the end.
rv = Renumber(aIndex + 1, -1);
if (NS_FAILED(rv)) return rv;
}
}
*_retval = old;
NS_ADDREF(*_retval);
return NS_OK;
}
NS_IMETHODIMP
RDFContainerImpl::IndexOf(nsIRDFNode *aElement, PRInt32 *aIndex)
{
NS_PRECONDITION(aElement != nsnull, "null ptr");
if (! aElement)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aIndex != nsnull, "null ptr");
if (! aIndex)
return NS_ERROR_NULL_POINTER;
nsresult rv;
PRInt32 count;
rv = GetCount(&count);
if (NS_FAILED(rv)) return rv;
for (PRInt32 idx = 1; idx <= count; ++idx) {
nsCOMPtr<nsIRDFResource> ordinal;
rv = gRDFContainerUtils->IndexToOrdinalResource(idx, getter_AddRefs(ordinal));
if (NS_FAILED(rv)) return rv;
// Get all of the elements in the container with the specified
// ordinal. This is an ultra-paranoid way to do it, but -- due
// to aggregation, we may end up with a container that has >1
// element for the same ordinal.
nsCOMPtr<nsISimpleEnumerator> targets;
rv = mDataSource->GetTargets(mContainer, ordinal, PR_TRUE, getter_AddRefs(targets));
if (NS_FAILED(rv)) return rv;
while (1) {
PRBool hasMore;
rv = targets->HasMoreElements(&hasMore);
if (NS_FAILED(rv)) return rv;
if (! hasMore)
break;
nsCOMPtr<nsISupports> isupports;
rv = targets->GetNext(getter_AddRefs(isupports));
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to read cursor");
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> element = do_QueryInterface(isupports);
if (element.get() != aElement)
continue;
// Okay, we've found it!
*aIndex = idx;
return NS_OK;
}
}
NS_WARNING("element not found");
*aIndex = -1;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
RDFContainerImpl::RDFContainerImpl()
: mDataSource(nsnull), mContainer(nsnull)
{
NS_INIT_REFCNT();
if (gRefCnt++ == 0) {
nsresult rv;
rv = nsServiceManager::GetService(kRDFServiceCID,
nsIRDFService::GetIID(),
(nsISupports**) &gRDFService);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
if (NS_SUCCEEDED(rv)) {
gRDFService->GetResource(RDF_NAMESPACE_URI "nextVal", &kRDF_nextVal);
}
rv = nsServiceManager::GetService(kRDFContainerUtilsCID,
nsIRDFContainerUtils::GetIID(),
(nsISupports**) &gRDFContainerUtils);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF container utils service");
}
}
RDFContainerImpl::~RDFContainerImpl()
{
NS_IF_RELEASE(mContainer);
NS_IF_RELEASE(mDataSource);
if (--gRefCnt == 0) {
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
}
}
nsresult
NS_NewRDFContainer(nsIRDFContainer** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
RDFContainerImpl* result =
new RDFContainerImpl();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aResult = result;
return NS_OK;
}
nsresult
NS_NewRDFContainer(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource,
nsIRDFContainer** aResult)
{
nsresult rv;
rv = NS_NewRDFContainer(aResult);
if (NS_FAILED(rv)) return rv;
rv = (*aResult)->Init(aDataSource, aResource);
if (NS_FAILED(rv)) {
NS_RELEASE(*aResult);
}
return rv;
}
nsresult
RDFContainerImpl::Renumber(PRInt32 aStartIndex, PRInt32 aIncrement)
{
// Renumber the elements in the container starting with
// aStartIndex, updating each element's index by aIncrement. For
// example,
//
// (1:a 2:b 3:c)
// Renumber(2, +1);
// (1:a 3:b 4:c)
// Renumber(3, -1);
// (1:a 2:b 3:c)
//
nsresult rv;
if (! aIncrement)
return NS_OK;
PRInt32 count;
rv = GetCount(&count);
if (NS_FAILED(rv)) return rv;
PRInt32 i;
if (aIncrement < 0) {
i = aStartIndex;
}
else {
i = count; // we're one-indexed.
}
while ((aIncrement < 0) ? (i <= count) : (i >= aStartIndex)) {
nsCOMPtr<nsIRDFResource> oldOrdinal;
rv = gRDFContainerUtils->IndexToOrdinalResource(i, getter_AddRefs(oldOrdinal));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFResource> newOrdinal;
rv = gRDFContainerUtils->IndexToOrdinalResource(i + aIncrement, getter_AddRefs(newOrdinal));
if (NS_FAILED(rv)) return rv;
// Because of aggregation, we need to be paranoid about the
// possibility that >1 element may be present per ordinal. If
// there _is_ in fact more than one element, they'll all get
// assigned to the same new ordinal; i.e., we don't make any
// attempt to "clean up" the duplicate numbering. (Doing so
// would require two passes.)
nsCOMPtr<nsISimpleEnumerator> targets;
rv = mDataSource->GetTargets(mContainer, oldOrdinal, PR_TRUE, getter_AddRefs(targets));
if (NS_FAILED(rv)) return rv;
while (1) {
PRBool hasMore;
rv = targets->HasMoreElements(&hasMore);
if (NS_FAILED(rv)) return rv;
if (! hasMore)
break;
nsCOMPtr<nsISupports> isupports;
rv = targets->GetNext(getter_AddRefs(isupports));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> element( do_QueryInterface(isupports) );
NS_ASSERTION(element != nsnull, "something funky in the enumerator");
if (! element)
return NS_ERROR_UNEXPECTED;
rv = mDataSource->Unassert(mContainer, oldOrdinal, element);
if (NS_FAILED(rv)) return rv;
rv = mDataSource->Assert(mContainer, newOrdinal, element, PR_TRUE);
if (NS_FAILED(rv)) return rv;
}
i -= aIncrement;
}
// Update the container's nextVal to reflect the renumbering
rv = SetNextValue(count + aIncrement + 1);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
nsresult
RDFContainerImpl::SetNextValue(PRInt32 aIndex)
{
nsresult rv;
// Remove the current value of nextVal, if there is one.
nsCOMPtr<nsIRDFNode> nextValNode;
if (NS_SUCCEEDED(rv = mDataSource->GetTarget(mContainer,
kRDF_nextVal,
PR_TRUE,
getter_AddRefs(nextValNode)))) {
if (NS_FAILED(rv = mDataSource->Unassert(mContainer, kRDF_nextVal, nextValNode))) {
NS_ERROR("unable to update nextVal");
return rv;
}
}
nsAutoString s;
s.Append(aIndex, 10);
nsCOMPtr<nsIRDFLiteral> nextVal;
if (NS_FAILED(rv = gRDFService->GetLiteral(s.GetUnicode(), getter_AddRefs(nextVal)))) {
NS_ERROR("unable to get nextVal literal");
return rv;
}
rv = mDataSource->Assert(mContainer, kRDF_nextVal, nextVal, PR_TRUE);
if (rv != NS_RDF_ASSERTION_ACCEPTED) {
NS_ERROR("unable to update nextVal");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
RDFContainerImpl::GetNextValue(nsIRDFResource** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsresult rv;
// Get the next value, which hangs off of the bag via the
// RDF:nextVal property.
nsCOMPtr<nsIRDFNode> nextValNode;
rv = mDataSource->GetTarget(mContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));
if (NS_FAILED(rv)) return rv;
if (rv == NS_RDF_NO_VALUE)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIRDFLiteral> nextValLiteral;
rv = nextValNode->QueryInterface(nsIRDFLiteral::GetIID(), getter_AddRefs(nextValLiteral));
if (NS_FAILED(rv)) return rv;
const PRUnichar* s;
rv = nextValLiteral->GetValueConst(&s);
if (NS_FAILED(rv)) return rv;
PRInt32 nextVal = 0;
{
for (const PRUnichar* p = s; *p != 0; ++p) {
NS_ASSERTION(*p >= '0' && *p <= '9', "not a digit");
if (*p < '0' || *p > '9')
break;
nextVal *= 10;
nextVal += *p - '0';
}
}
char buf[sizeof(kRDFNameSpaceURI) + 16];
nsCAutoString nextValStr(CBufDescriptor(buf, PR_TRUE, sizeof(buf), 0));
nextValStr = kRDFNameSpaceURI;
nextValStr.Append("_");
nextValStr.Append(nextVal, 10);
rv = gRDFService->GetResource((const char*) nextValStr, aResult);
if (NS_FAILED(rv)) return rv;
// Now increment the RDF:nextVal property.
rv = mDataSource->Unassert(mContainer, kRDF_nextVal, nextValLiteral);
if (NS_FAILED(rv)) return rv;
++nextVal;
nextValStr.Truncate();
nextValStr.Append(nextVal, 10);
rv = gRDFService->GetLiteral(nsAutoString(nextValStr).GetUnicode(), getter_AddRefs(nextValLiteral));
if (NS_FAILED(rv)) return rv;
rv = mDataSource->Assert(mContainer, kRDF_nextVal, nextValLiteral, PR_TRUE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}

View File

@@ -0,0 +1,424 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
Implementation for the RDF container utils.
*/
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "plstr.h"
#include "prprf.h"
#include "rdf.h"
#include "rdfutil.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
class RDFContainerUtilsImpl : public nsIRDFContainerUtils
{
public:
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFContainerUtils interface
NS_DECL_NSIRDFCONTAINERUTILS
private:
friend nsresult NS_NewRDFContainerUtils(nsIRDFContainerUtils** aResult);
RDFContainerUtilsImpl();
virtual ~RDFContainerUtilsImpl();
nsresult MakeContainer(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource,
nsIRDFResource* aType,
nsIRDFContainer** aResult);
PRBool IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType);
// pseudo constants
static PRInt32 gRefCnt;
static nsIRDFService* gRDFService;
static nsIRDFResource* kRDF_instanceOf;
static nsIRDFResource* kRDF_nextVal;
static nsIRDFResource* kRDF_Bag;
static nsIRDFResource* kRDF_Seq;
static nsIRDFResource* kRDF_Alt;
};
PRInt32 RDFContainerUtilsImpl::gRefCnt = 0;
nsIRDFService* RDFContainerUtilsImpl::gRDFService;
nsIRDFResource* RDFContainerUtilsImpl::kRDF_instanceOf;
nsIRDFResource* RDFContainerUtilsImpl::kRDF_nextVal;
nsIRDFResource* RDFContainerUtilsImpl::kRDF_Bag;
nsIRDFResource* RDFContainerUtilsImpl::kRDF_Seq;
nsIRDFResource* RDFContainerUtilsImpl::kRDF_Alt;
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ISUPPORTS(RDFContainerUtilsImpl, nsIRDFContainerUtils::GetIID());
////////////////////////////////////////////////////////////////////////
// nsIRDFContainerUtils interface
NS_IMETHODIMP
RDFContainerUtilsImpl::IsOrdinalProperty(nsIRDFResource *aProperty, PRBool *_retval)
{
NS_PRECONDITION(aProperty != nsnull, "null ptr");
if (! aProperty)
return NS_ERROR_NULL_POINTER;
nsresult rv;
const char *propertyStr;
rv = aProperty->GetValueConst( &propertyStr );
if (NS_FAILED(rv)) return rv;
if (PL_strncmp(propertyStr, kRDFNameSpaceURI, sizeof(kRDFNameSpaceURI) - 1) != 0) {
*_retval = PR_FALSE;
return NS_OK;
}
const char* s = propertyStr;
s += sizeof(kRDFNameSpaceURI) - 1;
if (*s != '_') {
*_retval = PR_FALSE;
return NS_OK;
}
++s;
while (*s) {
if (*s < '0' || *s > '9') {
*_retval = PR_FALSE;
return NS_OK;
}
++s;
}
*_retval = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
RDFContainerUtilsImpl::IndexToOrdinalResource(PRInt32 aIndex, nsIRDFResource **aOrdinal)
{
NS_PRECONDITION(aIndex > 0, "illegal value");
if (aIndex <= 0)
return NS_ERROR_ILLEGAL_VALUE;
// 16 digits should be plenty to hold a decimal version of a
// PRInt32.
char buf[sizeof(kRDFNameSpaceURI) + 16 + 1];
PL_strcpy(buf, kRDFNameSpaceURI);
buf[sizeof(kRDFNameSpaceURI) - 1] = '_';
PR_snprintf(buf + sizeof(kRDFNameSpaceURI), 16, "%ld", aIndex);
nsresult rv;
rv = gRDFService->GetResource(buf, aOrdinal);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get ordinal resource");
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
RDFContainerUtilsImpl::OrdinalResourceToIndex(nsIRDFResource *aOrdinal, PRInt32 *aIndex)
{
NS_PRECONDITION(aOrdinal != nsnull, "null ptr");
if (! aOrdinal)
return NS_ERROR_NULL_POINTER;
const char *ordinalStr;
if (NS_FAILED(aOrdinal->GetValueConst( &ordinalStr )))
return PR_FALSE;
const char* s = ordinalStr;
if (PL_strncmp(s, kRDFNameSpaceURI, sizeof(kRDFNameSpaceURI) - 1) != 0) {
NS_ERROR("not an ordinal");
return NS_ERROR_UNEXPECTED;
}
s += sizeof(kRDFNameSpaceURI) - 1;
if (*s != '_') {
NS_ERROR("not an ordinal");
return NS_ERROR_UNEXPECTED;
}
PRInt32 idx = 0;
++s;
while (*s) {
if (*s < '0' || *s > '9') {
NS_ERROR("not an ordinal");
return NS_ERROR_UNEXPECTED;
}
idx *= 10;
idx += (*s - '0');
++s;
}
*aIndex = idx;
return NS_OK;
}
NS_IMETHODIMP
RDFContainerUtilsImpl::IsContainer(nsIRDFDataSource *aDataSource, nsIRDFResource *aResource, PRBool *_retval)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aResource != nsnull, "null ptr");
if (! aResource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (! _retval)
return NS_ERROR_NULL_POINTER;
if (IsA(aDataSource, aResource, kRDF_Bag) ||
IsA(aDataSource, aResource, kRDF_Seq) ||
IsA(aDataSource, aResource, kRDF_Alt)) {
*_retval = PR_TRUE;
}
else {
*_retval = PR_FALSE;
}
return NS_OK;
}
NS_IMETHODIMP
RDFContainerUtilsImpl::IsBag(nsIRDFDataSource *aDataSource, nsIRDFResource *aResource, PRBool *_retval)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aResource != nsnull, "null ptr");
if (! aResource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (! _retval)
return NS_ERROR_NULL_POINTER;
*_retval = IsA(aDataSource, aResource, kRDF_Bag);
return NS_OK;
}
NS_IMETHODIMP
RDFContainerUtilsImpl::IsSeq(nsIRDFDataSource *aDataSource, nsIRDFResource *aResource, PRBool *_retval)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aResource != nsnull, "null ptr");
if (! aResource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (! _retval)
return NS_ERROR_NULL_POINTER;
*_retval = IsA(aDataSource, aResource, kRDF_Seq);
return NS_OK;
}
NS_IMETHODIMP
RDFContainerUtilsImpl::IsAlt(nsIRDFDataSource *aDataSource, nsIRDFResource *aResource, PRBool *_retval)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aResource != nsnull, "null ptr");
if (! aResource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (! _retval)
return NS_ERROR_NULL_POINTER;
*_retval = IsA(aDataSource, aResource, kRDF_Alt);
return NS_OK;
}
NS_IMETHODIMP
RDFContainerUtilsImpl::MakeBag(nsIRDFDataSource *aDataSource, nsIRDFResource *aResource, nsIRDFContainer **_retval)
{
return MakeContainer(aDataSource, aResource, kRDF_Bag, _retval);
}
NS_IMETHODIMP
RDFContainerUtilsImpl::MakeSeq(nsIRDFDataSource *aDataSource, nsIRDFResource *aResource, nsIRDFContainer **_retval)
{
return MakeContainer(aDataSource, aResource, kRDF_Seq, _retval);
}
NS_IMETHODIMP
RDFContainerUtilsImpl::MakeAlt(nsIRDFDataSource *aDataSource, nsIRDFResource *aResource, nsIRDFContainer **_retval)
{
return MakeContainer(aDataSource, aResource, kRDF_Alt, _retval);
}
////////////////////////////////////////////////////////////////////////
RDFContainerUtilsImpl::RDFContainerUtilsImpl()
{
NS_INIT_REFCNT();
if (gRefCnt++ == 0) {
nsresult rv;
rv = nsServiceManager::GetService(kRDFServiceCID,
nsIRDFService::GetIID(),
(nsISupports**) &gRDFService);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
if (NS_SUCCEEDED(rv)) {
gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf);
gRDFService->GetResource(RDF_NAMESPACE_URI "nextVal", &kRDF_nextVal);
gRDFService->GetResource(RDF_NAMESPACE_URI "Bag", &kRDF_Bag);
gRDFService->GetResource(RDF_NAMESPACE_URI "Seq", &kRDF_Seq);
gRDFService->GetResource(RDF_NAMESPACE_URI "Alt", &kRDF_Alt);
}
}
}
RDFContainerUtilsImpl::~RDFContainerUtilsImpl()
{
if (--gRefCnt == 0) {
if (gRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
NS_IF_RELEASE(kRDF_instanceOf);
NS_IF_RELEASE(kRDF_nextVal);
NS_IF_RELEASE(kRDF_Bag);
NS_IF_RELEASE(kRDF_Seq);
NS_IF_RELEASE(kRDF_Alt);
}
}
nsresult
NS_NewRDFContainerUtils(nsIRDFContainerUtils** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
RDFContainerUtilsImpl* result =
new RDFContainerUtilsImpl();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aResult = result;
return NS_OK;
}
nsresult
RDFContainerUtilsImpl::MakeContainer(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType, nsIRDFContainer** aResult)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aResource != nsnull, "null ptr");
if (! aResource)
return NS_ERROR_NULL_POINTER;
nsresult rv;
// Check to see if somebody has already turned it into a container; if so
// don't try to do it again.
PRBool isContainer;
rv = IsContainer(aDataSource, aResource, &isContainer);
if (NS_FAILED(rv)) return rv;
if (isContainer)
return NS_OK;
rv = aDataSource->Assert(aResource, kRDF_instanceOf, aType, PR_TRUE);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFLiteral> nextVal;
rv = gRDFService->GetLiteral(nsAutoString("1").GetUnicode(), getter_AddRefs(nextVal));
if (NS_FAILED(rv)) return rv;
rv = aDataSource->Assert(aResource, kRDF_nextVal, nextVal, PR_TRUE);
if (NS_FAILED(rv)) return rv;
if (aResult) {
rv = NS_NewRDFContainer(aResult);
if (NS_FAILED(rv)) return rv;
rv = (*aResult)->Init(aDataSource, aResource);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}
PRBool
RDFContainerUtilsImpl::IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType)
{
nsresult rv;
PRBool result;
rv = aDataSource->HasAssertion(aResource, kRDF_instanceOf, aType, PR_TRUE, &result);
if (NS_FAILED(rv)) return PR_FALSE;
return result;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,262 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
Some useful parsing routines.
This isn't the best place for them: I wish that they'd go into some
shared area (like mozilla/base).
*/
#include <stdlib.h> // XXX for atoi(), maybe this should go into nsCRT?
#include "nsCRT.h"
#include "nsIURL.h"
#include "nsString.h"
#include "nsRDFParserUtils.h"
// XXX This totally sucks. I wish that mozilla/base had this code.
PRUnichar
nsRDFParserUtils::EntityToUnicode(const char* buf)
{
if ((buf[0] == 'g') &&
(buf[1] == 't') &&
(buf[2] == '\0'))
return PRUnichar('>');
if ((buf[0] == 'l') &&
(buf[1] == 't') &&
(buf[2] == '\0'))
return PRUnichar('<');
if ((buf[0] == 'a') &&
(buf[1] == 'm') &&
(buf[2] == 'p') &&
(buf[3] == '\0'))
return PRUnichar('&');
if ((buf[0] == 'a') &&
(buf[1] == 'p') &&
(buf[2] == 'o') &&
(buf[3] == 's') &&
(buf[4] == '\0'))
return PRUnichar('\'');
if ((buf[0] == 'q') &&
(buf[1] == 'u') &&
(buf[2] == 'o') &&
(buf[3] == 't') &&
(buf[4] == '\0'))
return PRUnichar('"');
NS_NOTYETIMPLEMENTED("look this up in the declared-entity table");
return PRUnichar('?');
}
// XXX Code copied from nsHTMLContentSink. It should be shared.
void
nsRDFParserUtils::StripAndConvert(nsString& aResult)
{
// Strip quotes if present
PRUnichar first = aResult.First();
if ((first == '"') || (first == '\'')) {
if (aResult.Last() == first) {
aResult.Cut(0, 1);
PRInt32 pos = aResult.Length() - 1;
if (pos >= 0) {
aResult.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
// Reduce any entities
// XXX Note: as coded today, this will only convert well formed
// entities. This may not be compatible enough.
// XXX there is a table in navigator that translates some numeric entities
// should we be doing that? If so then it needs to live in two places (bad)
// so we should add a translate numeric entity method from the parser...
char cbuf[100];
PRInt32 i = 0;
while (i < aResult.Length()) {
// If we have the start of an entity (and it's not at the end of
// our string) then translate the entity into it's unicode value.
if ((aResult.CharAt(i++) == '&') && (i < aResult.Length())) {
PRInt32 start = i - 1;
PRUnichar e = aResult.CharAt(i);
if (e == '#') {
// Convert a numeric character reference
i++;
char* cp = cbuf;
char* limit = cp + sizeof(cbuf) - 1;
PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length();
while ((i < slen) && (cp < limit)) {
PRUnichar f = aResult.CharAt(i);
if (f == ';') {
i++;
ok = PR_TRUE;
break;
}
if ((f >= '0') && (f <= '9')) {
*cp++ = char(f);
i++;
continue;
}
break;
}
if (!ok || (cp == cbuf)) {
continue;
}
*cp = '\0';
if (cp - cbuf > 5) {
continue;
}
PRInt32 ch = PRInt32( ::atoi(cbuf) );
if (ch > 65535) {
continue;
}
// Remove entity from string and replace it with the integer
// value.
aResult.Cut(start, i - start);
aResult.Insert(PRUnichar(ch), start);
i = start + 1;
}
else if (((e >= 'A') && (e <= 'Z')) ||
((e >= 'a') && (e <= 'z'))) {
// Convert a named entity
i++;
char* cp = cbuf;
char* limit = cp + sizeof(cbuf) - 1;
*cp++ = char(e);
PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length();
while ((i < slen) && (cp < limit)) {
PRUnichar f = aResult.CharAt(i);
if (f == ';') {
i++;
ok = PR_TRUE;
break;
}
if (((f >= '0') && (f <= '9')) ||
((f >= 'A') && (f <= 'Z')) ||
((f >= 'a') && (f <= 'z'))) {
*cp++ = char(f);
i++;
continue;
}
break;
}
if (!ok || (cp == cbuf)) {
continue;
}
*cp = '\0';
PRInt32 ch;
// XXX Um, here's where we should be converting a
// named entity. I removed this to avoid a link-time
// dependency on core raptor.
ch = EntityToUnicode(cbuf);
if (ch < 0) {
continue;
}
// Remove entity from string and replace it with the integer
// value.
aResult.Cut(start, i - start);
aResult.Insert(PRUnichar(ch), start);
i = start + 1;
}
else if (e == '{') {
// Convert a script entity
// XXX write me!
NS_NOTYETIMPLEMENTED("convert a script entity");
}
}
}
}
nsresult
nsRDFParserUtils::GetQuotedAttributeValue(const nsString& aSource,
const nsString& aAttribute,
nsString& aValue)
{
static const char kQuote = '\"';
static const char kApostrophe = '\'';
PRInt32 offset;
PRInt32 endOffset = -1;
nsresult result = NS_OK;
offset = aSource.Find(aAttribute);
if (-1 != offset) {
offset = aSource.FindChar('=', PR_FALSE,offset);
PRUnichar next = aSource.CharAt(++offset);
if (kQuote == next) {
endOffset = aSource.FindChar(kQuote, PR_FALSE,++offset);
}
else if (kApostrophe == next) {
endOffset = aSource.FindChar(kApostrophe, PR_FALSE,++offset);
}
if (-1 != endOffset) {
aSource.Mid(aValue, offset, endOffset-offset);
}
else {
// Mismatched quotes - return an error
result = NS_ERROR_FAILURE;
}
}
else {
aValue.Truncate();
}
return result;
}
PRBool
nsRDFParserUtils::IsJavaScriptLanguage(const nsString& aName)
{
if (aName.EqualsIgnoreCase("JavaScript") ||
aName.EqualsIgnoreCase("LiveScript") ||
aName.EqualsIgnoreCase("Mocha")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.1")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.2")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.3")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.4")) {
return PR_TRUE;
}
else {
return PR_FALSE;
}
}

View File

@@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
Some useful parsing routines.
*/
#ifndef nsRDFParserUtils_h__
#define nsRDFParserUtils_h__
#include "nscore.h"
#include "nsError.h"
class nsIURI;
class nsString;
class nsRDFParserUtils {
public:
static PRUnichar
EntityToUnicode(const char* buf);
static void
StripAndConvert(nsString& aResult);
static nsresult
GetQuotedAttributeValue(const nsString& aSource,
const nsString& aAttribute,
nsString& aValue);
static PRBool
IsJavaScriptLanguage(const nsString& aName);
};
#endif // nsRDFPasrserUtils_h__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,167 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
Implementations for a bunch of useful RDF utility routines. Many of
these will eventually be exported outside of RDF.DLL via the
nsIRDFService interface.
TO DO
1) Make this so that it doesn't permanently leak the RDF service
object.
2) Make container functions thread-safe. They currently don't ensure
that the RDF:nextVal property is maintained safely.
*/
#include "nsCOMPtr.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#ifdef NECKO
#include "nsIIOService.h"
#include "nsIURL.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#endif // NECKO
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "prtime.h"
#include "rdfutil.h"
////////////////////////////////////////////////////////////////////////
nsresult
rdf_MakeRelativeRef(const nsString& aBaseURI, nsString& aURI)
{
// This implementation is extremely simple: e.g., it can't compute
// relative paths, or anything fancy like that. If the context URI
// is not a prefix of the URI in question, we'll just bail.
if (aURI.Find(aBaseURI) != 0)
return NS_OK;
// Otherwise, pare down the target URI, removing the context URI.
aURI.Cut(0, aBaseURI.Length());
if (aURI.First() == '/')
aURI.Cut(0, 1);
return NS_OK;
}
nsresult
rdf_MakeRelativeName(const nsString& aBaseURI, nsString& aURI)
{
nsresult rv;
rv = rdf_MakeRelativeRef(aBaseURI, aURI);
if (NS_FAILED(rv)) return rv;
if (aURI.First() == '#')
aURI.Cut(0, 1);
return NS_OK;
}
nsresult
rdf_MakeAbsoluteURI(const nsString& aBaseURI, nsString& aURI)
{
nsresult rv;
nsAutoString result;
#ifndef NECKO
rv = NS_MakeAbsoluteURL(nsnull, aBaseURI, aURI, result);
#else
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURI> baseUri;
char *uriStr = aBaseURI.ToNewCString();
if (! uriStr)
return NS_ERROR_OUT_OF_MEMORY;
rv = service->NewURI(uriStr, nsnull, getter_AddRefs(baseUri));
nsCRT::free(uriStr);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString absUrlStr;
char *urlSpec = aURI.ToNewCString();
if (! urlSpec)
return NS_ERROR_OUT_OF_MEMORY;
rv = service->MakeAbsolute(urlSpec, baseUri, getter_Copies(absUrlStr));
nsCRT::free(urlSpec);
result = (const char*) absUrlStr;
#endif // NECKO
if (NS_SUCCEEDED(rv)) {
aURI = result;
}
else {
// There are some ugly URIs (e.g., "NC:Foo") that netlib can't
// parse. If NS_MakeAbsoluteURL fails, then just punt and
// assume that aURI was already absolute.
}
return NS_OK;
}
nsresult
rdf_MakeAbsoluteURI(nsIURI* aURL, nsString& aURI)
{
nsresult rv;
nsAutoString result;
#ifndef NECKO
rv = NS_MakeAbsoluteURL(aURL, nsAutoString(""), aURI, result);
#else
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsIURI *baseUri = nsnull;
rv = aURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri);
if (NS_FAILED(rv)) return rv;
char *absUrlStr = nsnull;
rv = service->MakeAbsolute(nsCAutoString(aURI), baseUri, &absUrlStr);
NS_RELEASE(baseUri);
result = absUrlStr;
nsCRT::free(absUrlStr);
#endif // NECKO
if (NS_SUCCEEDED(rv)) {
aURI = result;
}
else {
// There are some ugly URIs (e.g., "NC:Foo") that netlib can't
// parse. If NS_MakeAbsoluteURL fails, then just punt and
// assume that aURI was already absolute.
}
return NS_OK;
}

View File

@@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
/*
A bunch of useful RDF utility routines. Many of these will
eventually be exported outside of RDF.DLL via the nsIRDFService
interface.
TO DO
1) Move the anonymous resource stuff to nsIRDFService?
2) All that's left is rdf_PossiblyMakeRelative() and
-Absolute(). Maybe those go on nsIRDFService, too.
*/
#ifndef rdfutil_h__
#define rdfutil_h__
#include "prtypes.h"
class nsCString;
class nsString;
class nsIURI;
nsresult
rdf_MakeRelativeRef(const nsString& aBaseURI, nsString& aURI);
nsresult
rdf_MakeRelativeName(const nsString& aBaseURI, nsString& aURI);
nsresult
rdf_MakeAbsoluteURI(const nsString& aBaseURI, nsString& aURI);
nsresult
rdf_MakeAbsoluteURI(nsIURI* aBaseURL, nsString& aURI);
#endif // rdfutil_h__

View File

@@ -0,0 +1,28 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src build
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,46 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = brprof
LIBRARY_NAME = brprof
IS_COMPONENT = 1
CPPSRCS = nsBrowsingProfileFactory.cpp
REQUIRES = xpcom
SHARED_LIBRARY_LIBS = $(DIST)/lib/libbrprof_s.a
EXTRA_DSO_LDOPTS = \
$(MKSHLIB_FORCE_ALL) \
$(SHARED_LIBRARY_LIBS) \
$(MKSHLIB_UNFORCE_ALL)
include $(topsrcdir)/config/rules.mk
$(LIBRARY) $(SHARED_LIBRARY): $(SHARED_LIBRARY_LIBS) Makefile
install:: $(TARGETS)
$(INSTALL) $(srcdir)/directory.rdf $(DIST)/bin/res/samples

Binary file not shown.

View File

@@ -0,0 +1 @@
#include "MacPrefix.h"

View File

@@ -0,0 +1,2 @@
# target: brprof.shlb
mozilla/rdf/brprof/src/nsBrowsingProfile.cpp

View File

@@ -0,0 +1,2 @@
#define DEBUG 1
#include "MacPrefix_debug.h"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,44 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
MODULE=brprof
MAKE_OBJ_TYPE=DLL
DLLNAME=brprof
DLL=.\$(OBJDIR)\$(DLLNAME).dll
CPP_OBJS=\
.\$(OBJDIR)\nsBrowsingProfileFactory.obj \
$(NULL)
# XXX linking in raptor is a heinous crime that will go away once we
# have a more DOM-based mechanism for constructing elements and
# hooking in to their changes.
LLIBS=\
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\brprof_s.lib \
$(LIBNSPR)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
$(MAKE_INSTALL) directory.rdf $(DIST)\bin\res\samples

View File

@@ -0,0 +1,104 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsIBrowsingProfile.h"
#include "nscore.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
static NS_DEFINE_CID(kBrowsingProfileCID, NS_BROWSINGPROFILE_CID);
static NS_IMETHODIMP
nsConstructBrowsingProfile(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
NS_ASSERTION(aOuter == nsnull, "no aggregation");
nsIBrowsingProfile* brprof;
rv = NS_NewBrowsingProfile(&brprof);
if (NS_FAILED(rv)) {
NS_ERROR("Unable to construct browsing profile");
return rv;
}
rv = brprof->QueryInterface(aIID, aResult);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
NS_RELEASE(brprof);
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
nsresult rv;
NS_ASSERTION(aFactory != nsnull, "bad factory pointer");
NS_ASSERTION(aClass.Equals(kBrowsingProfileCID), "incorrectly registered");
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
nsIGenericFactory* factory;
rv = compMgr->CreateInstance(kGenericFactoryCID, nsnull, nsIGenericFactory::GetIID(),
(void**)&factory);
if (NS_FAILED(rv)) return rv;
rv = factory->SetConstructor(nsConstructBrowsingProfile);
if (NS_FAILED(rv)) {
delete factory;
return rv;
}
NS_ADDREF(factory);
*aFactory = factory;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
{
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kBrowsingProfileCID,
"Browsing Profile", nsnull, aPath,
PR_TRUE, PR_TRUE);
return rv;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
{
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr,
aServMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kBrowsingProfileCID, aPath);
return rv;
}

View File

@@ -0,0 +1,24 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..
MODULE = rdf
DIRS= public src build
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1 @@
nsIBrowsingProfile.h

Some files were not shown because too many files have changed in this diff Show More