diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 975a45beba42..1949a070ebc0 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -79,7 +79,6 @@ #include "nsIStyledContent.h" #include "nsIStyleRule.h" #include "nsIURL.h" -#include "nsXULTreeElement.h" #include "rdfutil.h" #include "prlog.h" #include "rdf.h" @@ -317,8 +316,8 @@ private: PRBool mContentsMustBeGenerated; nsVoidArray* mBroadcastListeners; // [WEAK] nsIDOMXULElement* mBroadcaster; // [OWNER] - nsXULElement* mInnerXULElement; // [OWNER] nsIController* mController; // [OWNER] + nsCOMPtr mDatabase; // [OWNER] }; @@ -397,7 +396,6 @@ RDFElementImpl::RDFElementImpl(PRInt32 aNameSpaceID, nsIAtom* aTag) mContentsMustBeGenerated(PR_FALSE), mBroadcastListeners(nsnull), mBroadcaster(nsnull), - mInnerXULElement(nsnull), mController(nsnull) { NS_INIT_REFCNT(); @@ -514,8 +512,6 @@ RDFElementImpl::~RDFElementImpl() ++entry; } } - - delete mInnerXULElement; } @@ -576,16 +572,6 @@ RDFElementImpl::QueryInterface(REFNSIID iid, void** result) else if (iid.Equals(kIJSScriptObjectIID)) { *result = NS_STATIC_CAST(nsIJSScriptObject*, this); } - else if (iid.Equals(nsIDOMXULTreeElement::GetIID()) && - (mNameSpaceID == kNameSpaceID_XUL) && - (mTag == kTreeAtom)) { - if (! mInnerXULElement) { - if ((mInnerXULElement = new nsXULTreeElement(this)) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - } - - return mInnerXULElement->QueryInterface(iid, result); - } else { *result = nsnull; return NS_NOINTERFACE; @@ -1275,16 +1261,8 @@ RDFElementImpl::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject if (! mScriptObject) { nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - nsresult (*fn)(nsIScriptContext* aContext, nsISupports* aSupports, nsISupports* aParent, void** aReturn); + rv = NS_NewScriptXULElement(aContext, (nsIDOMXULElement*) this, global, (void**) &mScriptObject); - if (mTag == kTreeAtom) { - fn = NS_NewScriptXULTreeElement; - } - else { - fn = NS_NewScriptXULElement; - } - - rv = fn(aContext, (nsIDOMXULElement*) this, global, (void**) &mScriptObject); NS_RELEASE(global); // Ensure that a reference exists to this element @@ -2532,6 +2510,36 @@ RDFElementImpl::GetResource(nsIRDFResource** aResource) return NS_OK; } + +NS_IMETHODIMP +RDFElementImpl::GetDatabase(nsIRDFCompositeDataSource** aDatabase) +{ + NS_PRECONDITION(aDatabase != nsnull, "null ptr"); + if (! aDatabase) + return NS_ERROR_NULL_POINTER; + + *aDatabase = mDatabase; + NS_IF_ADDREF(*aDatabase); + return NS_OK; +} + + +NS_IMETHODIMP +RDFElementImpl::SetDatabase(nsIRDFCompositeDataSource* aDatabase) +{ + // XXX maybe someday you'll be allowed to change it. + NS_PRECONDITION(mDatabase == nsnull, "already initialized"); + if (mDatabase) + return NS_ERROR_ALREADY_INITIALIZED; + + mDatabase = aDatabase; + + // XXX reconstruct the entire tree now! + + return NS_OK; +} + + //////////////////////////////////////////////////////////////////////// // Implementation methods diff --git a/content/xul/content/src/nsXULTreeElement.cpp b/content/xul/content/src/nsXULTreeElement.cpp deleted file mode 100644 index 8feefaa2d6c1..000000000000 --- a/content/xul/content/src/nsXULTreeElement.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- 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. - */ - -#include "nsCOMPtr.h" -#include "nsIRDFCompositeDataSource.h" -#include "nsIServiceManager.h" -#include "nsRDFCID.h" -#include "nsXULTreeElement.h" - -NS_IMPL_ISUPPORTS_INHERITED(nsXULTreeElement, nsXULElement, nsIDOMXULTreeElement); - -NS_IMETHODIMP -nsXULTreeElement::GetDatabase(nsIRDFCompositeDataSource** aDatabase) -{ - NS_PRECONDITION(aDatabase != nsnull, "null ptr"); - if (! aDatabase) - return NS_ERROR_NULL_POINTER; - - *aDatabase = mDatabase; - NS_IF_ADDREF(*aDatabase); - return NS_OK; -} - - -NS_IMETHODIMP -nsXULTreeElement::SetDatabase(nsIRDFCompositeDataSource* aDatabase) -{ - // XXX maybe someday you'll be allowed to change it. - NS_PRECONDITION(mDatabase == nsnull, "already initialized"); - if (mDatabase) - return NS_ERROR_ALREADY_INITIALIZED; - - mDatabase = aDatabase; - - // XXX reconstruct the entire tree now! - - return NS_OK; -} diff --git a/content/xul/content/src/nsXULTreeElement.h b/content/xul/content/src/nsXULTreeElement.h deleted file mode 100644 index ed9dd9389147..000000000000 --- a/content/xul/content/src/nsXULTreeElement.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- 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 nsXULTreeElement_h__ -#define nsXULTreeElement_h__ - -#include "nsXULElement.h" -#include "nsIDOMXULTreeElement.h" -#include "nsIRDFCompositeDataSource.h" - -class nsXULTreeElement : public nsXULElement, - public nsIDOMXULTreeElement -{ -private: - nsCOMPtr mDatabase; - -public: - nsXULTreeElement(nsIDOMXULElement* aOuter) - : nsXULElement(aOuter) - { - } - - 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 -}; - - -#endif // nsXULTreeElement_h__ diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 5f6b32f25637..dc31d37c77cc 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -2746,6 +2746,17 @@ XULDocumentImpl::CreateElement(const nsString& aTagName, nsIDOMElement** aReturn nsresult rv; +#ifdef PR_LOGGING + if (PR_LOG_TEST(gXULLog, PR_LOG_DEBUG)) { + char* tagCStr = aTagName.ToNewCString(); + + PR_LOG(gXULLog, PR_LOG_DEBUG, + ("xul[CreateElement] %s", tagCStr)); + + delete[] tagCStr; + } +#endif + nsCOMPtr name; PRInt32 nameSpaceID; @@ -2925,6 +2936,19 @@ XULDocumentImpl::CreateElementWithNameSpace(const nsString& aTagName, nsresult rv; +#ifdef PR_LOGGING + if (PR_LOG_TEST(gXULLog, PR_LOG_DEBUG)) { + char* namespaceCStr = aNameSpace.ToNewCString(); + char* tagCStr = aTagName.ToNewCString(); + + PR_LOG(gXULLog, PR_LOG_DEBUG, + ("xul[CreateElementWithNameSpace] [%s]:%s", namespaceCStr, tagCStr)); + + delete[] tagCStr; + delete[] namespaceCStr; + } +#endif + nsCOMPtr name = dont_AddRef(NS_NewAtom(aTagName.GetUnicode())); if (! name) return NS_ERROR_OUT_OF_MEMORY; @@ -3005,12 +3029,12 @@ XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn) nsresult rv; - nsAutoString uri; + nsCAutoString uri; rv = nsRDFContentUtils::MakeElementURI(this, aId, uri); if (NS_FAILED(rv)) return rv; nsCOMPtr resource; - if (NS_FAILED(rv = gRDFService->GetUnicodeResource(uri.GetUnicode(), getter_AddRefs(resource)))) { + if (NS_FAILED(rv = gRDFService->GetResource(uri, getter_AddRefs(resource)))) { NS_ERROR("unable to get resource"); return rv; } @@ -3209,15 +3233,14 @@ XULDocumentImpl::CreatePopupDocument(nsIContent* aPopupElement, nsIDocument** aR nsCOMPtr domRoot = do_QueryInterface(aPopupElement); domRoot->GetAttribute("id", idValue); - nsAutoString uri; + nsCAutoString uri; rv = nsRDFContentUtils::MakeElementURI(this, idValue, uri); if (NS_FAILED(rv)) return rv; // Use the absolute URL to retrieve a resource from the RDF // service that corresponds to the root content. nsCOMPtr rootResource; - if (NS_FAILED(rv = gRDFService->GetUnicodeResource(uri.GetUnicode(), - getter_AddRefs(rootResource)))) { + if (NS_FAILED(rv = gRDFService->GetResource(uri, getter_AddRefs(rootResource)))) { NS_ERROR("Uh-oh. Couldn't obtain the resource for the popup doc root."); return rv; } diff --git a/content/xul/templates/src/nsXULSortService.cpp b/content/xul/templates/src/nsXULSortService.cpp index 889d1a576928..1b3c3a91091d 100644 --- a/content/xul/templates/src/nsXULSortService.cpp +++ b/content/xul/templates/src/nsXULSortService.cpp @@ -82,7 +82,6 @@ #include "nsIRDFService.h" #include "rdf.h" -#include "nsIDOMXULTreeElement.h" #include "nsIDOMXULElement.h" #include "nsILocale.h" @@ -112,7 +111,6 @@ static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID); static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID); -static NS_DEFINE_IID(kIDomXulTreeElementIID, NS_IDOMXULTREEELEMENT_IID); static NS_DEFINE_IID(kIDomXulElementIID, NS_IDOMXULELEMENT_IID); static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID); @@ -1292,7 +1290,7 @@ XULSortServiceImpl::InsertContainerNode(nsIContent *container, nsIContent *node) if (NS_FAILED(rv = FindTreeElement(container, getter_AddRefs(treeNode)))) return(rv); // get composite db for tree - nsCOMPtr domXulTree; + nsCOMPtr domXulTree; sortInfo.rdfService = gRDFService; sortInfo.db = nsnull; @@ -1300,7 +1298,7 @@ XULSortServiceImpl::InsertContainerNode(nsIContent *container, nsIContent *node) // that we're sure that we'll hold a reference to it (and actually // release that reference when the stack frame goes away). nsCOMPtr cds; - rv = treeNode->QueryInterface(kIDomXulTreeElementIID, getter_AddRefs(domXulTree)); + rv = treeNode->QueryInterface(kIDomXulElementIID, getter_AddRefs(domXulTree)); if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv = domXulTree->GetDatabase(getter_AddRefs(cds)))) @@ -1488,7 +1486,7 @@ XULSortServiceImpl::DoSort(nsIDOMNode* node, const nsString& sortResource, // get composite db for tree sortInfo.rdfService = gRDFService; sortInfo.db = nsnull; - nsCOMPtr domXulTree = do_QueryInterface(treeNode); + nsCOMPtr domXulTree = do_QueryInterface(treeNode); if (!domXulTree) return(NS_ERROR_FAILURE); nsCOMPtr cds; if (NS_SUCCEEDED(rv = domXulTree->GetDatabase(getter_AddRefs(cds)))) diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index d804603ff40e..ed3cb67d2b35 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -60,6 +60,7 @@ #include "nsINameSpaceManager.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" +#include "nsITextContent.h" #include "nsIURL.h" #include "nsLayoutCID.h" #include "nsRDFCID.h" @@ -79,11 +80,8 @@ #include "prlog.h" -// Remove this to try running without the C++ builders. This will -// inhibit delegation to the fallback builder for constructing content -// (but still relies on it for determining the correct tagset to use). -#define FALLBACK_BUILDERS 1 - +#define NS_RDF_ELEMENT_WAS_CREATED NS_RDF_NO_VALUE +#define NS_RDF_ELEMENT_WAS_THERE NS_OK static PRLogModuleInfo* gLog; @@ -102,6 +100,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); +static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID); static NS_DEFINE_IID(kXULSortServiceCID, NS_XULSORTSERVICE_CID); static NS_DEFINE_IID(kIXULSortServiceIID, NS_IXULSORTSERVICE_IID); @@ -115,12 +114,13 @@ static NS_DEFINE_CID(kIHTMLElementFactoryIID, NS_IHTML_ELEMENT_FACTORY_IID); //////////////////////////////////////////////////////////////////////// -nsrefcnt RDFGenericBuilderImpl::gRefCnt = 0; +nsrefcnt RDFGenericBuilderImpl::gRefCnt = 0; nsIXULSortService* RDFGenericBuilderImpl::XULSortService = nsnull; nsIAtom* RDFGenericBuilderImpl::kContainerAtom; nsIAtom* RDFGenericBuilderImpl::kLazyContentAtom; nsIAtom* RDFGenericBuilderImpl::kIsContainerAtom; +nsIAtom* RDFGenericBuilderImpl::kIsEmptyAtom; nsIAtom* RDFGenericBuilderImpl::kXULContentsGeneratedAtom; nsIAtom* RDFGenericBuilderImpl::kTemplateContentsGeneratedAtom; nsIAtom* RDFGenericBuilderImpl::kContainerContentsGeneratedAtom; @@ -133,9 +133,8 @@ nsIAtom* RDFGenericBuilderImpl::kContainmentAtom; nsIAtom* RDFGenericBuilderImpl::kNaturalOrderPosAtom; nsIAtom* RDFGenericBuilderImpl::kIgnoreAtom; nsIAtom* RDFGenericBuilderImpl::kRefAtom; +nsIAtom* RDFGenericBuilderImpl::kValueAtom; -nsIAtom* RDFGenericBuilderImpl::kSubcontainmentAtom; -nsIAtom* RDFGenericBuilderImpl::kRootcontainmentAtom; nsIAtom* RDFGenericBuilderImpl::kTemplateAtom; nsIAtom* RDFGenericBuilderImpl::kRuleAtom; nsIAtom* RDFGenericBuilderImpl::kTextAtom; @@ -161,6 +160,26 @@ nsIRDFResource* RDFGenericBuilderImpl::kXUL_element; //////////////////////////////////////////////////////////////////////// +nsresult +NS_NewXULTemplateBuilder(nsIRDFContentModelBuilder** aResult) +{ + nsresult rv; + RDFGenericBuilderImpl* result = new RDFGenericBuilderImpl(); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); // stabilize + + rv = result->Init(); + if (NS_SUCCEEDED(rv)) { + rv = result->QueryInterface(nsCOMTypeInfo::GetIID(), (void**) aResult); + } + + NS_RELEASE(result); + return rv; +} + + RDFGenericBuilderImpl::RDFGenericBuilderImpl(void) : mDocument(nsnull), mDB(nsnull), @@ -168,92 +187,6 @@ RDFGenericBuilderImpl::RDFGenericBuilderImpl(void) mTimer(nsnull) { NS_INIT_REFCNT(); - - if (gRefCnt == 0) { - kContainerAtom = NS_NewAtom("container"); - kLazyContentAtom = NS_NewAtom("lazycontent"); - kIsContainerAtom = NS_NewAtom("iscontainer"); - kXULContentsGeneratedAtom = NS_NewAtom("xulcontentsgenerated"); - kTemplateContentsGeneratedAtom = NS_NewAtom("templatecontentsgenerated"); - kContainerContentsGeneratedAtom = NS_NewAtom("containercontentsgenerated"); - - kIdAtom = NS_NewAtom("id"); - kOpenAtom = NS_NewAtom("open"); - kEmptyAtom = NS_NewAtom("empty"); - kResourceAtom = NS_NewAtom("resource"); - kURIAtom = NS_NewAtom("uri"); - kContainmentAtom = NS_NewAtom("containment"); - kIgnoreAtom = NS_NewAtom("ignore"); - kRefAtom = NS_NewAtom("ref"); - kNaturalOrderPosAtom = NS_NewAtom("pos"); - - kSubcontainmentAtom = NS_NewAtom("subcontainment"); - kRootcontainmentAtom = NS_NewAtom("rootcontainment"); - kTemplateAtom = NS_NewAtom("template"); - kRuleAtom = NS_NewAtom("rule"); - - kTextAtom = NS_NewAtom("text"); - kPropertyAtom = NS_NewAtom("property"); - kInstanceOfAtom = NS_NewAtom("instanceOf"); - - nsresult rv; - - // Register the XUL and RDF namespaces: these'll just retrieve - // the IDs if they've already been registered by someone else. - if (NS_SUCCEEDED(rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, - nsnull, - kINameSpaceManagerIID, - (void**) &gNameSpaceManager))) { - -// XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp -static const char kXULNameSpaceURI[] - = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - -static const char kRDFNameSpaceURI[] - = RDF_NAMESPACE_URI; - - rv = gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace"); - - rv = gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register RDF namespace"); - } - else { - NS_ERROR("couldn't create namepsace manager"); - } - - - // Initialize the global shared reference to the service - // manager and get some shared resource objects. - rv = nsServiceManager::GetService(kRDFServiceCID, - kIRDFServiceIID, - (nsISupports**) &gRDFService); - - if (NS_SUCCEEDED(rv)) { - gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title); - gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child); - gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column); - gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder); - gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child); - gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf); - gRDFService->GetResource(XUL_NAMESPACE_URI "element", &kXUL_element); - } - - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - nsIRDFContainerUtils::GetIID(), - (nsISupports**) &gRDFContainerUtils); - - rv = nsServiceManager::GetService(kXULSortServiceCID, - kIXULSortServiceIID, - (nsISupports**) &XULSortService); - - } - ++gRefCnt; - -#ifdef PR_LOGGING - if (! gLog) - gLog = PR_NewLogModule("nsRDFGenericBuilder"); -#endif } RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) @@ -270,7 +203,8 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) NS_RELEASE(kContainerAtom); NS_RELEASE(kLazyContentAtom); NS_RELEASE(kIsContainerAtom); - NS_RELEASE(kXULContentsGeneratedAtom); + NS_RELEASE(kIsEmptyAtom); + NS_RELEASE(kXULContentsGeneratedAtom); NS_RELEASE(kTemplateContentsGeneratedAtom); NS_RELEASE(kContainerContentsGeneratedAtom); @@ -278,14 +212,13 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) NS_RELEASE(kOpenAtom); NS_RELEASE(kEmptyAtom); NS_RELEASE(kResourceAtom); - NS_RELEASE(kURIAtom); + NS_RELEASE(kURIAtom); NS_RELEASE(kContainmentAtom); NS_RELEASE(kIgnoreAtom); NS_RELEASE(kRefAtom); + NS_RELEASE(kValueAtom); NS_RELEASE(kNaturalOrderPosAtom); - NS_RELEASE(kSubcontainmentAtom); - NS_RELEASE(kRootcontainmentAtom); NS_RELEASE(kTemplateAtom); NS_RELEASE(kRuleAtom); NS_RELEASE(kTextAtom); @@ -307,11 +240,105 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) } if (mTimer) - { - mTimer->Cancel(); - NS_RELEASE(mTimer); - mTimer = nsnull; + { + mTimer->Cancel(); + NS_RELEASE(mTimer); + mTimer = nsnull; + } +} + + +nsresult +RDFGenericBuilderImpl::Init() +{ + if (gRefCnt == 0) { + kContainerAtom = NS_NewAtom("container"); + kLazyContentAtom = NS_NewAtom("lazycontent"); + kIsContainerAtom = NS_NewAtom("iscontainer"); + kIsEmptyAtom = NS_NewAtom("isempty"); + kXULContentsGeneratedAtom = NS_NewAtom("xulcontentsgenerated"); + kTemplateContentsGeneratedAtom = NS_NewAtom("templatecontentsgenerated"); + kContainerContentsGeneratedAtom = NS_NewAtom("containercontentsgenerated"); + + kIdAtom = NS_NewAtom("id"); + kOpenAtom = NS_NewAtom("open"); + kEmptyAtom = NS_NewAtom("empty"); + kResourceAtom = NS_NewAtom("resource"); + kURIAtom = NS_NewAtom("uri"); + kContainmentAtom = NS_NewAtom("containment"); + kIgnoreAtom = NS_NewAtom("ignore"); + kRefAtom = NS_NewAtom("ref"); + kValueAtom = NS_NewAtom("value"); + kNaturalOrderPosAtom = NS_NewAtom("pos"); + + kTemplateAtom = NS_NewAtom("template"); + kRuleAtom = NS_NewAtom("rule"); + + kTextAtom = NS_NewAtom("text"); + kPropertyAtom = NS_NewAtom("property"); + kInstanceOfAtom = NS_NewAtom("instanceOf"); + + nsresult rv; + + // Register the XUL and RDF namespaces: these'll just retrieve + // the IDs if they've already been registered by someone else. + rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, + nsnull, + nsCOMTypeInfo::GetIID(), + (void**) &gNameSpaceManager); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager"); + if (NS_FAILED(rv)) return rv; + + // XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp + static const char kXULNameSpaceURI[] + = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + + static const char kRDFNameSpaceURI[] + = RDF_NAMESPACE_URI; + + rv = gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace"); + if (NS_FAILED(rv)) return rv; + + rv = gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register RDF namespace"); + if (NS_FAILED(rv)) return rv; + + + // Initialize the global shared reference to the service + // manager and get some shared resource objects. + rv = nsServiceManager::GetService(kRDFServiceCID, + kIRDFServiceIID, + (nsISupports**) &gRDFService); + if (NS_FAILED(rv)) return rv; + + gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title); + gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child); + gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column); + gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder); + gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child); + gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf); + gRDFService->GetResource(XUL_NAMESPACE_URI "element", &kXUL_element); + + rv = nsServiceManager::GetService(kRDFContainerUtilsCID, + nsIRDFContainerUtils::GetIID(), + (nsISupports**) &gRDFContainerUtils); + if (NS_FAILED(rv)) return rv; + + rv = nsServiceManager::GetService(kXULSortServiceCID, + kIXULSortServiceIID, + (nsISupports**) &XULSortService); + if (NS_FAILED(rv)) return rv; + } + ++gRefCnt; + +#ifdef PR_LOGGING + if (! gLog) + gLog = PR_NewLogModule("nsRDFGenericBuilder"); +#endif + + return NS_OK; } //////////////////////////////////////////////////////////////////////// @@ -391,10 +418,26 @@ RDFGenericBuilderImpl::SetDataBase(nsIRDFCompositeDataSource* aDataBase) if (mDB) return NS_ERROR_ALREADY_INITIALIZED; + NS_PRECONDITION(mRoot != nsnull, "not initialized"); + if (! mRoot) + return NS_ERROR_NOT_INITIALIZED; + mDB = aDataBase; NS_ADDREF(mDB); mDB->AddObserver(this); + + // Now set the database on the element, so that script writers can + // access it. + nsCOMPtr element( do_QueryInterface(mRoot) ); + NS_ASSERTION(element != nsnull, "not a XULElement"); + if (! element) + return NS_ERROR_UNEXPECTED; + + nsresult rv; + rv = element->SetDatabase(aDataBase); + if (NS_FAILED(rv)) return rv; + return NS_OK; } @@ -415,74 +458,9 @@ RDFGenericBuilderImpl::GetDataBase(nsIRDFCompositeDataSource** aDataBase) NS_IMETHODIMP RDFGenericBuilderImpl::CreateRootContent(nsIRDFResource* aResource) { - // Create a structure that looks like this: - // - // - // - // - // - // - // - // - // Eventually, we should be able to do away with the HTML tags and - // just have it create XUL in some other context. - - nsresult rv; - nsCOMPtr tag; - nsCOMPtr doc; - nsCOMPtr rootAtom; - if (NS_FAILED(rv = GetRootWidgetAtom(getter_AddRefs(rootAtom)))) { - return rv; - } - - if (NS_FAILED(rv = mDocument->QueryInterface(kIDocumentIID, - (void**) getter_AddRefs(doc)))) - return rv; - - // Create the DOCUMENT element - if ((tag = dont_AddRef(NS_NewAtom("document"))) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - nsCOMPtr root; - if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_HTML, /* XXX */ - tag, - getter_AddRefs(root)))) - return rv; - - doc->SetRootContent(NS_STATIC_CAST(nsIContent*, root)); - - // Create the BODY element - nsCOMPtr body; - if ((tag = dont_AddRef(NS_NewAtom("body"))) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_HTML, /* XXX */ - tag, - getter_AddRefs(body)))) - return rv; - - - // Attach the BODY to the DOCUMENT - if (NS_FAILED(rv = root->AppendChildTo(body, PR_FALSE))) - return rv; - - // Create the xul:rootwidget element, and indicate that children should - // be recursively generated on demand - nsCOMPtr widget; - if (NS_FAILED(rv = CreateElement(kNameSpaceID_XUL, - rootAtom, - aResource, - getter_AddRefs(widget)))) - return rv; - - if (NS_FAILED(rv = widget->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE))) - return rv; - - // Attach the ROOTWIDGET to the BODY - if (NS_FAILED(rv = body->AppendChildTo(widget, PR_FALSE))) - return rv; - - return NS_OK; + // XXX Remove this method from the interface + NS_NOTREACHED("whoops"); + return NS_ERROR_UNEXPECTED; } NS_IMETHODIMP @@ -661,13 +639,6 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eSet, aProperty, aTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - // fall through if node wasn't created by a XUL template - rv = SetWidgetAttribute(element, aProperty, aTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -779,12 +750,6 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eClear, aProperty, aTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - rv = UnsetWidgetAttribute(element, aProperty, aTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -899,12 +864,6 @@ RDFGenericBuilderImpl::OnChange(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eSet, aProperty, aNewTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - rv = SetWidgetAttribute(element, aProperty, aNewTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -1020,7 +979,7 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a // Now do the work to change the attribute. There are a couple of // special cases that we need to check for here... if ((elementNameSpaceID == kNameSpaceID_XUL) && - IsItemOrFolder(element) && // XXX IsItemOrFolder(): is this what we really mean? + IsResourceElement(element) && // XXX IsResourceElement(): is this what we really mean? (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kOpenAtom)) { @@ -1058,8 +1017,7 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a } } else if ((elementNameSpaceID == kNameSpaceID_XUL) && - (IsItemOrFolder(element) || // XXX IsItemOrFolder(): is this what we really mean? - IsWidgetInsertionRootElement(element)) && + (IsResourceElement(element)) && (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kIdAtom)) { @@ -1093,6 +1051,9 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a return rv; } + if (! parent) + return NS_ERROR_UNEXPECTED; + if (NS_FAILED(rv = parent->RemoveChildAt(elementIndex, PR_TRUE))) { NS_ERROR("unable to remove element"); return rv; @@ -1145,8 +1106,10 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a } else if ((attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kRefAtom)) { - // Ignore changes to the 'ref=' attribute; the XUL builder - // will take care of that for us. + // Remove all of the template children and rebuild them + rv = RemoveAndRebuildGeneratedChildren(element); + if (NS_FAILED(rv)) return rv; + return NS_OK; } @@ -1235,7 +1198,7 @@ RDFGenericBuilderImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString } if ((elementNameSpaceID == kNameSpaceID_XUL) && - IsItemOrFolder(element) && // XXX Is this what we really mean? + IsResourceElement(element) && // XXX Is this what we really mean? (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kOpenAtom)) { // We are removing the value of the "open" attribute. This may @@ -1300,186 +1263,115 @@ RDFGenericBuilderImpl::OnRemoveAttributeNode(nsIDOMElement* aElement, nsIDOMAttr } +//////////////////////////////////////////////////////////////////////// +// nsITimerCallback methods + +void +RDFGenericBuilderImpl::Notify(nsITimer* aTimer) +{ +} + //////////////////////////////////////////////////////////////////////// // Implementation methods nsresult -RDFGenericBuilderImpl::SetAllAttributesOnElement(nsIContent *aParentNode, nsIContent *aNode, nsIRDFResource *res) +RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement, + nsIRDFResource *aProperty, + nsIRDFResource* aChild, + nsIContent *aRule, + PRBool *aIsMatch) { - // get all arcs out, and if not a containment property, set attribute - nsresult rv = NS_OK; - PRBool markAsContainer = PR_FALSE; - nsCOMPtr arcs; - if (NS_SUCCEEDED(rv = mDB->ArcLabelsOut(res, getter_AddRefs(arcs)))) - { - PRBool hasMore = PR_TRUE; - while(hasMore) - { - rv = arcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) break; - if (hasMore == PR_FALSE) break; + nsresult rv; - nsCOMPtr isupports; - if (NS_FAILED(rv = arcs->GetNext(getter_AddRefs(isupports)))) break; + PRInt32 count; + rv = aRule->GetAttributeCount(count); + if (NS_FAILED(rv)) return(rv); - nsCOMPtr property = do_QueryInterface(isupports); - // Ignore properties that are used to indicate "tree-ness" - if (IsContainmentProperty(aNode, property)) - { - markAsContainer = PR_TRUE; - continue; - } - - // Ignore any properties set in ignore attribute - // Note: since node isn't in the content model yet, start with its parent - if (IsIgnoredProperty(aParentNode, property)) - { - continue; - } - - PRInt32 nameSpaceID; - nsCOMPtr tag; - if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) - break; - nsCOMPtr value; - if (NS_FAILED(rv = mDB->GetTarget(res, property, PR_TRUE, getter_AddRefs(value)))) - break; - if (rv == NS_RDF_NO_VALUE) - continue; - nsAutoString s; - if (NS_SUCCEEDED(rv = nsRDFContentUtils::GetTextForNode(value, s))) - { - aNode->SetAttribute(nameSpaceID, tag, s, PR_FALSE); - } - } - } - if (markAsContainer == PR_TRUE) - { - // mark this as a "container" so that we know to - // recursively generate kids if they're asked for. - rv = aNode->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE); - } - return(rv); -} - - -nsresult -RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIRDFResource *aNode, nsIContent *aRule, PRBool *matchingRuleFound) -{ - nsresult rv = NS_OK; - PRInt32 count; - - *matchingRuleFound = PR_FALSE; - - if (NS_FAILED(rv = aRule->GetAttributeCount(count))) - { - return(rv); - } - - *matchingRuleFound = PR_TRUE; - for (PRInt32 loop=0; loop attribAtom; - if (NS_FAILED(rv = aRule->GetAttributeNameAt(loop, attribNameSpaceID, *getter_AddRefs(attribAtom)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsAutoString attribValue; - if (NS_FAILED(rv = aRule->GetAttribute(attribNameSpaceID, attribAtom, attribValue))) - { - *matchingRuleFound = PR_FALSE; - break; - } - -#ifdef DEBUG - nsAutoString nsName; - attribAtom->ToString(nsName); - char *debugName = nsName.ToNewCString(); - if (debugName) - { - delete [] debugName; - debugName = nsnull; - } -#endif + for (PRInt32 loop=0; loop attr; + rv = aRule->GetAttributeNameAt(loop, attrNameSpaceID, *getter_AddRefs(attr)); + if (NS_FAILED(rv)) return rv; // Note: some attributes must be skipped on XUL template rule subtree // never compare against {}:container attribute - if ((attribAtom.get() == kLazyContentAtom) && (attribNameSpaceID == kNameSpaceID_None)) + if ((attr.get() == kLazyContentAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against rdf:property attribute - else if ((attribAtom.get() == kPropertyAtom) && (attribNameSpaceID == kNameSpaceID_RDF)) + else if ((attr.get() == kPropertyAtom) && (attrNameSpaceID == kNameSpaceID_RDF)) continue; // never compare against rdf:instanceOf attribute - else if ((attribAtom.get() == kInstanceOfAtom) && (attribNameSpaceID == kNameSpaceID_RDF)) + else if ((attr.get() == kInstanceOfAtom) && (attrNameSpaceID == kNameSpaceID_RDF)) continue; // never compare against {}:id attribute - else if ((attribAtom.get() == kIdAtom) && (attribNameSpaceID == kNameSpaceID_None)) - continue; - // never compare against {}:rootcontainment attribute - else if ((attribAtom.get() == kRootcontainmentAtom) && (attribNameSpaceID == kNameSpaceID_None)) - continue; - // never compare against {}:subcontainment attribute - else if ((attribAtom.get() == kSubcontainmentAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kIdAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against {}:xulcontentsgenerated attribute - else if ((attribAtom.get() == kXULContentsGeneratedAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kXULContentsGeneratedAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against {}:itemcontentsgenerated attribute (bogus) - else if ((attribAtom.get() == kTemplateContentsGeneratedAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kTemplateContentsGeneratedAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; - else if ((attribNameSpaceID == kNameSpaceID_None) && (attribAtom.get() == kIsContainerAtom)) - { - // check and see if aNode is a container - PRBool containerFlag = IsContainer(aRule, aNode); - if (containerFlag && (!attribValue.EqualsIgnoreCase("true"))) - { - *matchingRuleFound = PR_FALSE; - break; - } - else if (!containerFlag && (!attribValue.EqualsIgnoreCase("false"))) - { - *matchingRuleFound = PR_FALSE; - break; - } - } - else - { - nsCOMPtr attribAtomResource; + nsAutoString value; + rv = aRule->GetAttribute(attrNameSpaceID, attr, value); + if (NS_FAILED(rv)) return rv; - if (NS_FAILED(rv = GetResource(attribNameSpaceID, attribAtom, getter_AddRefs(attribAtomResource)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsCOMPtr aResult; - if (NS_FAILED(rv = mDB->GetTarget(aNode, attribAtomResource, PR_TRUE, getter_AddRefs(aResult)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsAutoString resultStr; - if (NS_FAILED(rv = nsRDFContentUtils::GetTextForNode(aResult, resultStr))) - { - *matchingRuleFound = PR_FALSE; - break; - } - if (!attribValue.Equals(resultStr)) - { - *matchingRuleFound = PR_FALSE; - break; - } + if ((attrNameSpaceID == kNameSpaceID_None) && (attr.get() == kIsContainerAtom)) { + // check and see if aChild is a container + PRBool isContainer = IsContainer(aRule, aChild); + if (isContainer && (!value.EqualsIgnoreCase("true"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + else if (!isContainer && (!value.EqualsIgnoreCase("false"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } } + else if ((attrNameSpaceID == kNameSpaceID_None) && (attr.get() == kIsEmptyAtom)) { + PRBool isEmpty = IsEmpty(aRule, aChild); + if (isEmpty && (!value.EqualsIgnoreCase("true"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + else if (!isEmpty && (!value.EqualsIgnoreCase("false"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + } + else { + nsCOMPtr property; + rv = GetResource(attrNameSpaceID, attr, getter_AddRefs(property)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr target; + rv = mDB->GetTarget(aChild, property, PR_TRUE, getter_AddRefs(target)); + if (NS_FAILED(rv)) return rv; + + nsAutoString targetStr; + rv = nsRDFContentUtils::GetTextForNode(target, targetStr); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get text for target"); + if (NS_FAILED(rv)) return rv; + + if (!value.Equals(targetStr)) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + } } - return(rv); + + *aIsMatch = PR_TRUE; + return NS_OK; } nsresult -RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent **aTemplate) +RDFGenericBuilderImpl::FindTemplate(nsIContent* aElement, + nsIRDFResource *aProperty, + nsIRDFResource* aChild, + nsIContent **aTemplate) { nsresult rv; @@ -1509,15 +1401,6 @@ RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent if (tag.get() != kTemplateAtom) continue; -#if 0 - // check for debugging - nsAutoString debugValue; - if (NS_SUCCEEDED(rv = tmpl->GetAttribute(kNameSpaceID_None, kDebugAtom, debugValue))) - { - debugValue = "true"; - } -#endif - // found a template; check against any (optional) rules PRInt32 numRuleChildren, numRulesFound = 0; rv = tmpl->ChildCount(numRuleChildren); @@ -1542,11 +1425,11 @@ RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent if (ruleTag.get() == kRuleAtom) { ++numRulesFound; - PRBool matchingRuleFound = PR_FALSE; - rv = IsTemplateRuleMatch(aNode, aRule, &matchingRuleFound); + PRBool isMatch = PR_FALSE; + rv = IsTemplateRuleMatch(aElement, aProperty, aChild, aRule, &isMatch); if (NS_FAILED(rv)) return rv; - if (matchingRuleFound) { + if (isMatch) { // found a matching rule, use it as the template *aTemplate = aRule; NS_ADDREF(*aTemplate); @@ -1583,14 +1466,6 @@ RDFGenericBuilderImpl::IsIgnoreableAttribute(PRInt32 aNameSpaceID, nsIAtom* aAtt else if ((aAttribute == kInstanceOfAtom) && (aNameSpaceID == kNameSpaceID_RDF)) { return PR_TRUE; } - // never copy {}:rootcontainment attribute - else if ((aAttribute == kRootcontainmentAtom) && (aNameSpaceID == kNameSpaceID_None)) { - return PR_TRUE; - } - // never copy {}:subcontainment attribute - else if ((aAttribute == kSubcontainmentAtom) && (aNameSpaceID == kNameSpaceID_None)) { - return PR_TRUE; - } // never copy {}:ID attribute else if ((aAttribute == kIdAtom) && (aNameSpaceID == kNameSpaceID_None)) { return PR_TRUE; @@ -1608,11 +1483,54 @@ RDFGenericBuilderImpl::IsIgnoreableAttribute(PRInt32 aNameSpaceID, nsIAtom* aAtt } } + +nsresult +RDFGenericBuilderImpl::GetSubstitutionText(nsIRDFResource* aResource, + const nsString& aSubstitution, + nsString& aResult) +{ + nsresult rv; + + if (aSubstitution.Find("rdf:") == 0) { + // found an attribute which wants to bind + // its value to RDF so look it up in the + // graph + nsAutoString propertyStr(aSubstitution); + propertyStr.Cut(0,4); + + nsCOMPtr property; + rv = gRDFService->GetUnicodeResource(propertyStr.GetUnicode(), getter_AddRefs(property)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr valueNode; + rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(valueNode)); + if (NS_FAILED(rv)) return rv; + + if (valueNode) { + rv = nsRDFContentUtils::GetTextForNode(valueNode, aResult); + if (NS_FAILED(rv)) return rv; + } + else { + aResult.Truncate(); + } + } + else if (aSubstitution.EqualsIgnoreCase("...")) { + const char *uri = nsnull; + aResource->GetValueConst(&uri); + aResult = uri; + } + else { + aResult = aSubstitution; + } + + return NS_OK; +} + nsresult RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, nsIContent *aRealNode, PRBool aIsUnique, - nsIRDFResource* aResource, + nsIRDFResource* aChild, PRInt32 aNaturalOrderPos) { nsresult rv; @@ -1624,7 +1542,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; nsXPIDLCString resourceCStr; - rv = aResource->GetValue(getter_Copies(resourceCStr)); + rv = aChild->GetValue(getter_Copies(resourceCStr)); if (NS_FAILED(rv)) return rv; nsAutoString tagStr(tag->GetUnicode()); @@ -1651,8 +1569,8 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, rv = tmplKid->GetNameSpaceID(nameSpaceID); if (NS_FAILED(rv)) return rv; - // check whether this item is a containment item for aResource - PRBool isContainmentElement = PR_FALSE; + // check whether this item is the resource element + PRBool isResourceElement = PR_FALSE; if (nameSpaceID == kNameSpaceID_XUL) { nsAutoString idValue; rv = tmplKid->GetAttribute(kNameSpaceID_None, @@ -1661,7 +1579,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (idValue.EqualsIgnoreCase("..."))) { - isContainmentElement = PR_TRUE; + isResourceElement = PR_TRUE; aIsUnique = PR_FALSE; } } @@ -1670,58 +1588,69 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, rv = tmplKid->GetTag(*getter_AddRefs(tag)); if (NS_FAILED(rv)) return rv; + PRBool realKidAlreadyExisted = PR_FALSE; + nsCOMPtr realKid; if (aIsUnique) { - rv = EnsureElementHasGenericChild(aRealNode, - nameSpaceID, - tag, - getter_AddRefs(realKid)); + rv = EnsureElementHasGenericChild(aRealNode, nameSpaceID, tag, getter_AddRefs(realKid)); if (NS_FAILED(rv)) return rv; - // Recurse until we get to a non-unique element. Mark the - // element's contents as being generated so that - // any re-entrant calls don't trigger an infinite recursion. - rv = realKid->SetAttribute(kNameSpaceID_None, - kTemplateContentsGeneratedAtom, - "true", - PR_FALSE); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set contents-generated attribute"); - if (NS_FAILED(rv)) return rv; + if (rv == NS_RDF_ELEMENT_WAS_THERE) { + realKidAlreadyExisted = PR_TRUE; + } + else { + // Mark the element's contents as being generated so + // that any re-entrant calls don't trigger an infinite + // recursion. + rv = realKid->SetAttribute(kNameSpaceID_None, + kTemplateContentsGeneratedAtom, + "true", + PR_FALSE); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set contents-generated attribute"); + if (NS_FAILED(rv)) return rv; + } - rv = BuildContentFromTemplate(tmplKid, realKid, PR_TRUE, aResource, -1); + // Recurse until we get to the resource element. + rv = BuildContentFromTemplate(tmplKid, realKid, PR_TRUE, aChild, -1); if (NS_FAILED(rv)) return rv; } - else if (isContainmentElement) { - rv = CreateElement(nameSpaceID, tag, aResource, getter_AddRefs(realKid)); + else if (isResourceElement) { + rv = CreateElement(nameSpaceID, tag, aChild, getter_AddRefs(realKid)); if (NS_FAILED(rv)) return rv; - if (IsContainer(realKid, aResource)) { + if (IsContainer(realKid, aChild)) { rv = realKid->SetAttribute(kNameSpaceID_None, kContainerAtom, "true", PR_FALSE); if (NS_FAILED(rv)) return rv; // test to see if the container has contents - char* isEmpty = IsEmpty(realKid, aResource) ? "true" : "false"; + char* isEmpty = IsEmpty(realKid, aChild) ? "true" : "false"; rv = realKid->SetAttribute(kNameSpaceID_None, kEmptyAtom, isEmpty, PR_FALSE); if (NS_FAILED(rv)) return rv; } } else if ((tag.get() == kTextAtom) && (nameSpaceID == kNameSpaceID_XUL)) { - // is replaced by text of the + // is replaced by text of the // actual value of the rdf:resource attribute for the given node nsAutoString attrValue; - rv = tmplKid->GetAttribute(kNameSpaceID_RDF, kResourceAtom, attrValue); + rv = tmplKid->GetAttribute(kNameSpaceID_None, kValueAtom, attrValue); if (NS_FAILED(rv)) return rv; if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (attrValue.Length() > 0)) { - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(attrValue.GetUnicode(), getter_AddRefs(property)); + nsAutoString text; + rv = GetSubstitutionText(aChild, attrValue, text); if (NS_FAILED(rv)) return rv; - nsCOMPtr text; - rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(text)); + nsCOMPtr content; + rv = nsComponentManager::CreateInstance(kTextNodeCID, + nsnull, + nsITextContent::GetIID(), + getter_AddRefs(content)); if (NS_FAILED(rv)) return rv; - rv = nsRDFContentUtils::AttachTextNode(aRealNode, text); + rv = content->SetText(text.GetUnicode(), text.Length(), PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = aRealNode->AppendChildTo(nsCOMPtr( do_QueryInterface(content) ), PR_FALSE); if (NS_FAILED(rv)) return rv; } } @@ -1763,7 +1692,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; } - if (realKid) { + if (realKid && !realKidAlreadyExisted) { // save a reference (its ID) to the template node that was used nsAutoString templateID; rv = tmplKid->GetAttribute(kNameSpaceID_None, kIdAtom, templateID); @@ -1778,7 +1707,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; // set natural order hint - if ((aNaturalOrderPos > 0) && (isContainmentElement)) { + if ((aNaturalOrderPos > 0) && (isResourceElement)) { nsAutoString pos, zero("0000"); pos.Append(aNaturalOrderPos, 10); if (pos.Length() < 4) { @@ -1816,49 +1745,29 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - if (attribValue.Find("rdf:") == 0) { - // found an attribute which wants to bind - // its value to RDF so look it up in the - // graph - attribValue.Cut(0,4); + nsAutoString text; + rv = GetSubstitutionText(aChild, attribValue, text); + if (NS_FAILED(rv)) return rv; - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(attribValue.GetUnicode(), getter_AddRefs(property)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr valueNode; - rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(valueNode)); - if (NS_FAILED(rv)) return rv; - - if (valueNode) { - rv = nsRDFContentUtils::GetTextForNode(valueNode, attribValue); - if (NS_FAILED(rv)) return rv; - } - else { - attribValue.Truncate(); - } - } - else if (attribValue.EqualsIgnoreCase("...")) { - const char *uri = nsnull; - aResource->GetValueConst(&uri); - attribValue = uri; - } - - realKid->SetAttribute(attribNameSpaceID, attribName, attribValue, PR_FALSE); + rv = realKid->SetAttribute(attribNameSpaceID, attribName, text, PR_FALSE); + if (NS_FAILED(rv)) return rv; } } } - // Note: add into tree, but only sort if its a containment element! - if ((nsnull != XULSortService) && (isContainmentElement == PR_TRUE)) { - rv = XULSortService->InsertContainerNode(aRealNode, realKid); - if (NS_FAILED(rv)) { + // We'll _already_ have added the unique elements. + if (! aIsUnique) { + // Note: add into tree, but only sort if its a resource element! + if ((nsnull != XULSortService) && (isResourceElement)) { + rv = XULSortService->InsertContainerNode(aRealNode, realKid); + if (NS_FAILED(rv)) { + aRealNode->AppendChildTo(realKid, PR_TRUE); + } + } + else { aRealNode->AppendChildTo(realKid, PR_TRUE); } } - else { - aRealNode->AppendChildTo(realKid, PR_TRUE); - } // If item says its "open", then recurve now and build up its children nsAutoString openState; @@ -1879,85 +1788,24 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, nsresult RDFGenericBuilderImpl::CreateWidgetItem(nsIContent *aElement, nsIRDFResource *aProperty, - nsIRDFResource *aValue, + nsIRDFResource *aChild, PRInt32 aNaturalOrderPos) { nsCOMPtr tmpl; nsresult rv; - rv = FindTemplateForResource(aValue, getter_AddRefs(tmpl)); + rv = FindTemplate(aElement, aProperty, aChild, getter_AddRefs(tmpl)); if (NS_FAILED(rv)) { -#ifdef FALLBACK_BUILDERS - return AddWidgetItem(aElement, aProperty, aValue, aNaturalOrderPos); -#else + // No template. Just bail. return NS_OK; -#endif - } - - // The "container" node which will be used to build children. - nsCOMPtr container; - PRBool isRoot = PR_FALSE; - - // if template specifies a rootcontainment attribute, get it - // and determine if we are building children off of the root - nsAutoString rootAttrValue; - rv = tmpl->GetAttribute(kNameSpaceID_None, - kRootcontainmentAtom, - rootAttrValue); - if (NS_FAILED(rv)) return rv; - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - // XXX Ick. Can we remember this somehow? - nsCOMPtr rootAtom = NS_NewAtom(rootAttrValue); - if (! rootAtom) return NS_ERROR_OUT_OF_MEMORY; - - PRInt32 nameSpaceID; - rv = aElement->GetNameSpaceID(nameSpaceID); - if (NS_FAILED(rv)) return rv; - - if (nameSpaceID == kNameSpaceID_XUL) { - nsCOMPtr tag; - rv = aElement->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - if (tag == rootAtom) - isRoot = PR_TRUE; - } - } - - // if template specifies a subcontainment attribute, get it - // and make sure aElement contains it (if not the root). - if (! isRoot) { - nsAutoString attrValue; - rv = tmpl->GetAttribute(kNameSpaceID_None, - kSubcontainmentAtom, - attrValue); - if (NS_FAILED(rv)) return rv; - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - // XXX Ick. Can we remember this somehow? - nsCOMPtr childrenAtom = NS_NewAtom(attrValue); - if (! childrenAtom) return NS_ERROR_OUT_OF_MEMORY; - - rv = EnsureElementHasGenericChild(aElement, - kNameSpaceID_XUL, - childrenAtom, - getter_AddRefs(container)); - if (NS_FAILED(rv)) return rv; - } - } - - // Otherwise, just use the element as the root. - if (! container) { - container = dont_QueryInterface(aElement); } rv = BuildContentFromTemplate(tmpl, - container, + aElement, PR_TRUE, - aValue, + aChild, aNaturalOrderPos); - + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to build content from template"); return rv; } @@ -2076,6 +1924,14 @@ RDFGenericBuilderImpl::SynchronizeUsingTemplate(nsIContent* aTemplateNode, } + +nsresult +RDFGenericBuilderImpl::RemoveWidgetItem(nsIContent* aElement, nsIRDFResource* aProperty, nsIRDFResource* aValue) +{ + return NS_OK; +} + + nsresult RDFGenericBuilderImpl::CreateContainerContents(nsIContent* aElement, nsIRDFResource* aResource) { @@ -2304,73 +2160,25 @@ RDFGenericBuilderImpl::EnsureElementHasGenericChild(nsIContent* parent, *result = element; NS_ADDREF(*result); + return NS_RDF_ELEMENT_WAS_CREATED; + } + else { + return NS_RDF_ELEMENT_WAS_THERE; } - return NS_OK; } PRBool -RDFGenericBuilderImpl::IsItemOrFolder(nsIContent* aElement) +RDFGenericBuilderImpl::IsResourceElement(nsIContent* aElement) { - // XXX It seems like this should be a pure virtual method that - // subclasses implement? - - // XXX All of the callers of this method actually only seem to - // care if the element is a "folder". - - // Returns PR_TRUE if the element is an "item" or a "folder" in - // the widget. nsresult rv; + nsAutoString str; + rv = aElement->GetAttribute(kNameSpaceID_None, kIdAtom, str); + if (NS_FAILED(rv)) return PR_FALSE; - nsCOMPtr itemAtom; - nsCOMPtr folderAtom; - if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom))) || - NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) { - return rv; - } - - // "element" must be itemAtom - nsCOMPtr tag; - if (NS_FAILED(rv = aElement->GetTag(*getter_AddRefs(tag)))) - return PR_FALSE; - - if (tag != itemAtom && tag != folderAtom) - return PR_FALSE; - - return PR_TRUE; + return (rv == NS_CONTENT_ATTR_HAS_VALUE) ? PR_TRUE : PR_FALSE; } -PRBool -RDFGenericBuilderImpl::IsWidgetInsertionRootElement(nsIContent* element) -{ - // Returns PR_TRUE if the element is the root point to insert new items. - nsresult rv; - - nsCOMPtr rootAtom; - if (NS_FAILED(rv = GetInsertionRootAtom(getter_AddRefs(rootAtom)))) { - return rv; - } - - PRInt32 nameSpaceID; - if (NS_FAILED(rv = element->GetNameSpaceID(nameSpaceID))) { - NS_ERROR("unable to get namespace ID"); - return PR_FALSE; - } - - if (nameSpaceID != kNameSpaceID_XUL) - return PR_FALSE; // not a XUL element - - nsCOMPtr elementTag; - if (NS_FAILED(rv = element->GetTag(*getter_AddRefs(elementTag)))) { - NS_ERROR("unable to get tag"); - return PR_FALSE; - } - - if (elementTag != rootAtom) - return PR_FALSE; // not the place to insert a child - - return PR_TRUE; -} PRBool RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty) @@ -2703,6 +2511,22 @@ RDFGenericBuilderImpl::GetResource(PRInt32 aNameSpaceID, nsresult RDFGenericBuilderImpl::OpenWidgetItem(nsIContent* aElement) { +#ifdef PR_LOGGING + if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { + nsresult rv; + + nsCOMPtr tag; + rv = aElement->GetTag(*getter_AddRefs(tag)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tagStr; + tag->ToString(tagStr); + + PR_LOG(gLog, PR_LOG_DEBUG, + ("rdfgeneric open-widget-item %s", + (const char*) nsCAutoString(tagStr))); + } +#endif return CreateContents(aElement); } @@ -2712,49 +2536,88 @@ RDFGenericBuilderImpl::CloseWidgetItem(nsIContent* aElement) { nsresult rv; - // Find the tag that contains the children so that we can remove all of - // the children. - nsCOMPtr parentAtom; - rv = GetItemAtomThatContainsTheChildren(getter_AddRefs(parentAtom)); +#ifdef PR_LOGGING + if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { + nsCOMPtr tag; + rv = aElement->GetTag(*getter_AddRefs(tag)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tagStr; + tag->ToString(tagStr); + + PR_LOG(gLog, PR_LOG_DEBUG, + ("rdfgeneric close-widget-item %s", + (const char*) nsCAutoString(tagStr))); + } +#endif + + // Find the tag that contains the children so that we can remove + // all of the children. + // + // XXX We make a bit of a leap here and assume that the same + // template that was used to generate _us_ was used to generate + // our _kids_. I'm sure this'll break when we do toolbars or + // something. + nsAutoString tmplID; + rv = aElement->GetAttribute(kNameSpaceID_None, kTemplateAtom, tmplID); if (NS_FAILED(rv)) return rv; - nsCOMPtr parentNode; - nsCOMPtr tag; - rv = aElement->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; // XXX fatal + if (rv != NS_CONTENT_ATTR_HAS_VALUE) + return NS_OK; - if (tag == parentAtom) { - parentNode = dont_QueryInterface(aElement); - rv = NS_OK; + nsCOMPtr xulDoc = do_QueryInterface(mDocument); + if (! xulDoc) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplDOMEle; + rv = xulDoc->GetElementById(tmplID, getter_AddRefs(tmplDOMEle)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr tmpl = do_QueryInterface(tmplDOMEle); + if (! tmpl) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplParent; + rv = tmpl->GetParent(*getter_AddRefs(tmplParent)); + if (NS_FAILED(rv)) return rv; + + NS_ASSERTION(tmplParent != nsnull, "template node has no parent"); + if (! tmplParent) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplParentTag; + rv = tmplParent->GetTag(*getter_AddRefs(tmplParentTag)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr childcontainer; + if ((tmplParentTag == kRuleAtom) || (tmplParentTag == kTemplateAtom)) { + childcontainer = dont_QueryInterface(aElement); } else { - rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, parentAtom, getter_AddRefs(parentNode)); + rv = nsRDFContentUtils::FindChildByTag(aElement, + kNameSpaceID_XUL, + tmplParentTag, + getter_AddRefs(childcontainer)); + + if (NS_FAILED(rv)) return rv; + + if (rv == NS_RDF_NO_VALUE) { + // No tag; must've already been closed + return NS_OK; + } } - if (rv == NS_RDF_NO_VALUE) { - // No tag; must've already been closed - return NS_OK; - } - - NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving parent node for removal"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr ds; - rv = mDocument->GetDocumentDataSource(getter_AddRefs(ds)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get document datasource"); - if (NS_FAILED(rv)) return rv; - PRInt32 count; - rv = parentNode->ChildCount(count); + rv = childcontainer->ChildCount(count); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get count of the parent's children"); if (NS_FAILED(rv)) return rv; while (--count >= 0) { nsCOMPtr child; - rv = parentNode->ChildAt(count, *getter_AddRefs(child)); + rv = childcontainer->ChildAt(count, *getter_AddRefs(child)); if (NS_FAILED(rv)) return rv; - rv = parentNode->RemoveChildAt(count, PR_TRUE); + rv = childcontainer->RemoveChildAt(count, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child"); do { @@ -2786,18 +2649,67 @@ RDFGenericBuilderImpl::CloseWidgetItem(nsIContent* aElement) // This is a _total_ hack to make sure that any XUL we blow away // gets rebuilt. - rv = parentNode->UnsetAttribute(kNameSpaceID_None, - kXULContentsGeneratedAtom, - PR_FALSE); + rv = childcontainer->UnsetAttribute(kNameSpaceID_None, + kXULContentsGeneratedAtom, + PR_FALSE); if (NS_FAILED(rv)) return rv; - rv = parentNode->SetAttribute(kNameSpaceID_None, - kLazyContentAtom, - "true", - PR_FALSE); + rv = childcontainer->SetAttribute(kNameSpaceID_None, + kLazyContentAtom, + "true", + PR_FALSE); if (NS_FAILED(rv)) return rv; return NS_OK; } +nsresult +RDFGenericBuilderImpl::RemoveAndRebuildGeneratedChildren(nsIContent* aElement) +{ + nsresult rv; + + PRInt32 count; + rv = aElement->ChildCount(count); + if (NS_FAILED(rv)) return rv; + + while (--count >= 0) { + nsCOMPtr child; + rv = aElement->ChildAt(count, *getter_AddRefs(child)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tmplID; + rv = child->GetAttribute(kNameSpaceID_None, kTemplateAtom, tmplID); + if (NS_FAILED(rv)) return rv; + + if (rv != NS_CONTENT_ATTR_HAS_VALUE) + continue; + + // It's a generated element. Remove it, and set its document + // to null so that it'll get knocked out of the XUL doc's + // resource-to-element map. + rv = aElement->RemoveChildAt(count, PR_TRUE); + NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child"); + + rv = child->SetDocument(nsnull, PR_TRUE); + if (NS_FAILED(rv)) return rv; + } + + // Clear the contents-generated attribute so that the next time we + // come back, we'll regenerate the kids we just killed. + rv = aElement->UnsetAttribute(kNameSpaceID_None, + kTemplateContentsGeneratedAtom, + PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = aElement->UnsetAttribute(kNameSpaceID_None, + kContainerContentsGeneratedAtom, + PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = CreateContents(aElement); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + diff --git a/dom/public/idl/xul/XULElement.idl b/dom/public/idl/xul/XULElement.idl index 3e929fb0e9aa..0fc40452aff6 100644 --- a/dom/public/idl/xul/XULElement.idl +++ b/dom/public/idl/xul/XULElement.idl @@ -2,16 +2,16 @@ interface XULElement : Element { /* IID: { 0x574ed81, 0xc088, 0x11d2, \ { 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } */ - readonly attribute xpidl nsIRDFResource resource; - attribute xpidl nsIController controller; + attribute DOMString id; + attribute DOMString className; + readonly attribute CSSStyleDeclaration style; + attribute xpidl nsIRDFCompositeDataSource database; + readonly attribute xpidl nsIRDFResource resource; + attribute xpidl nsIController controller; - attribute DOMString id; - attribute DOMString className; - readonly attribute CSSStyleDeclaration style; + void addBroadcastListener(in DOMString attr, in Element element); + void removeBroadcastListener(in DOMString attr, in Element element); + void doCommand(); - 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); + NodeList getElementsByAttribute(in DOMString name, in DOMString value); }; diff --git a/dom/public/idl/xul/XULTreeElement.idl b/dom/public/idl/xul/XULTreeElement.idl deleted file mode 100644 index 0817a1eb8b1a..000000000000 --- a/dom/public/idl/xul/XULTreeElement.idl +++ /dev/null @@ -1,5 +0,0 @@ -interface XULTreeElement : XULElement { -/* IID: { 0xa6cf90ec, 0x15b3, 0x11d2, \ - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } */ - attribute xpidl nsIRDFCompositeDataSource database; -}; diff --git a/dom/public/xul/nsIDOMXULElement.h b/dom/public/xul/nsIDOMXULElement.h index e63e7e6cb8c7..d5672470b64a 100644 --- a/dom/public/xul/nsIDOMXULElement.h +++ b/dom/public/xul/nsIDOMXULElement.h @@ -28,6 +28,7 @@ class nsIController; class nsIDOMElement; class nsIDOMCSSStyleDeclaration; +class nsIRDFCompositeDataSource; class nsIRDFResource; class nsIDOMNodeList; @@ -39,11 +40,6 @@ class nsIDOMXULElement : public nsIDOMElement { public: static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULELEMENT_IID; return iid; } - NS_IMETHOD GetResource(nsIRDFResource** aResource)=0; - - NS_IMETHOD GetController(nsIController** aController)=0; - NS_IMETHOD SetController(nsIController* aController)=0; - NS_IMETHOD GetId(nsString& aId)=0; NS_IMETHOD SetId(const nsString& aId)=0; @@ -52,6 +48,14 @@ public: 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; @@ -63,14 +67,16 @@ public: #define NS_DECL_IDOMXULELEMENT \ - NS_IMETHOD GetResource(nsIRDFResource** aResource); \ - NS_IMETHOD GetController(nsIController** aController); \ - NS_IMETHOD SetController(nsIController* aController); \ 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(); \ @@ -79,14 +85,16 @@ public: #define NS_FORWARD_IDOMXULELEMENT(_to) \ - 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 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(); } \ diff --git a/dom/public/xul/nsIDOMXULTreeElement.h b/dom/public/xul/nsIDOMXULTreeElement.h deleted file mode 100644 index 1ffbb1f0f97c..000000000000 --- a/dom/public/xul/nsIDOMXULTreeElement.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- 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 nsIRDFCompositeDataSource; - -#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 GetDatabase(nsIRDFCompositeDataSource** aDatabase)=0; - NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase)=0; -}; - - -#define NS_DECL_IDOMXULTREEELEMENT \ - NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase); \ - NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase); \ - - - -#define NS_FORWARD_IDOMXULTREEELEMENT(_to) \ - NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase) { return _to GetDatabase(aDatabase); } \ - NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase) { return _to SetDatabase(aDatabase); } \ - - -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__ diff --git a/dom/src/xul/nsJSXULDocument.cpp b/dom/src/xul/nsJSXULDocument.cpp index 8912f0ab0d7d..262c5c4243ff 100644 --- a/dom/src/xul/nsJSXULDocument.cpp +++ b/dom/src/xul/nsJSXULDocument.cpp @@ -51,11 +51,8 @@ NS_DEF_PTR(nsIDOMNodeList); // enum XULDocument_slots { XULDOCUMENT_POPUPELEMENT = -1, - XULDOCUMENT_TOOLTIPELEMENT = -2, - XULDOCUMENT_FOCUS = -3 - }; /***********************************************************************/ @@ -67,86 +64,45 @@ 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); - nsIScriptSecurityManager *secMan; - PRBool ok = PR_FALSE; - if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { - return JS_FALSE; - } - switch(JSVAL_TO_INT(id)) { - case XULDOCUMENT_POPUPELEMENT: - { - secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.popupelement", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIDOMElement* prop; - if (NS_OK == a->GetPopupElement(&prop)) { - // get the js object - nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); - } - else { - return JS_FALSE; - } - break; - } - case XULDOCUMENT_TOOLTIPELEMENT: - { - secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.tooltipelement", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIDOMElement* prop; - if (NS_OK == a->GetTooltipElement(&prop)) { - // get the js object nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); } @@ -193,100 +149,52 @@ 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); - nsIScriptSecurityManager *secMan; - PRBool ok = PR_FALSE; - if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { - return JS_FALSE; - } - switch(JSVAL_TO_INT(id)) { - case XULDOCUMENT_POPUPELEMENT: - { - secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.popupelement", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIDOMElement* prop; - if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop, - kIElementIID, "Element", - cx, *vp)) { - return JS_FALSE; - } - - a->SetPopupElement(prop); - NS_IF_RELEASE(prop); - break; - } - case XULDOCUMENT_TOOLTIPELEMENT: - { - secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.tooltipelement", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIDOMElement* prop; - if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop, - kIElementIID, "Element", - cx, *vp)) { - return JS_FALSE; - } - - a->SetTooltipElement(prop); - NS_IF_RELEASE(prop); break; } @@ -340,8 +248,6 @@ PR_STATIC_CALLBACK(JSBool) XULDocumentGetElementById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsIDOMXULDocument *nativeThis = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj); - - JSBool rBool = JS_FALSE; nsIDOMElement* nativeRet; nsAutoString b0; @@ -393,8 +299,6 @@ PR_STATIC_CALLBACK(JSBool) XULDocumentGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsIDOMXULDocument *nativeThis = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj); - - JSBool rBool = JS_FALSE; nsIDOMNodeList* nativeRet; nsAutoString b0; nsAutoString b1; @@ -466,9 +370,7 @@ JSClass XULDocumentClass = { static JSPropertySpec XULDocumentProperties[] = { {"popupElement", XULDOCUMENT_POPUPELEMENT, JSPROP_ENUMERATE}, - {"tooltipElement", XULDOCUMENT_TOOLTIPELEMENT, JSPROP_ENUMERATE}, - {"focus", XULDOCUMENT_FOCUS, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/dom/src/xul/nsJSXULElement.cpp b/dom/src/xul/nsJSXULElement.cpp index 7f5b0423eb99..aebb60cfbbbb 100644 --- a/dom/src/xul/nsJSXULElement.cpp +++ b/dom/src/xul/nsJSXULElement.cpp @@ -30,6 +30,7 @@ #include "nsIController.h" #include "nsIDOMElement.h" #include "nsIDOMCSSStyleDeclaration.h" +#include "nsIRDFCompositeDataSource.h" #include "nsIDOMXULElement.h" #include "nsIRDFResource.h" #include "nsIDOMNodeList.h" @@ -41,6 +42,7 @@ 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); @@ -48,6 +50,7 @@ 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); @@ -56,11 +59,12 @@ NS_DEF_PTR(nsIDOMNodeList); // XULElement property ids // enum XULElement_slots { - XULELEMENT_RESOURCE = -1, - XULELEMENT_CONTROLLER = -2, - XULELEMENT_ID = -3, - XULELEMENT_CLASSNAME = -4, - XULELEMENT_STYLE = -5 + XULELEMENT_ID = -1, + XULELEMENT_CLASSNAME = -2, + XULELEMENT_STYLE = -3, + XULELEMENT_DATABASE = -4, + XULELEMENT_RESOURCE = -5, + XULELEMENT_CONTROLLER = -6 }; /***********************************************************************/ @@ -70,7 +74,7 @@ enum XULElement_slots { PR_STATIC_CALLBACK(JSBool) GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMXULElement *a = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); + nsIDOMXULElement *a = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -80,45 +84,11 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; - PRBool ok; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } switch(JSVAL_TO_INT(id)) { - case XULELEMENT_RESOURCE: - { - secMan->CheckScriptAccess(scriptCX, obj, "xulelement.resource", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIRDFResource* prop; - if (NS_OK == a->GetResource(&prop)) { - // get the js object; n.b., this will do a release on 'prop' - nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp); - } - else { - return JS_FALSE; - } - break; - } - case XULELEMENT_CONTROLLER: - { - secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIController* prop; - if (NS_OK == a->GetController(&prop)) { - // get the js object; n.b., this will do a release on 'prop' - nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIController::GetIID(), cx, vp); - } - else { - return JS_FALSE; - } - break; - } case XULELEMENT_ID: { secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", &ok); @@ -168,6 +138,57 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case XULELEMENT_DATABASE: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.database", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIRDFCompositeDataSource* prop; + if (NS_OK == a->GetDatabase(&prop)) { + // get the js object; n.b., this will do a release on 'prop' + nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp); + } + else { + return JS_FALSE; + } + break; + } + case XULELEMENT_RESOURCE: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.resource", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIRDFResource* prop; + if (NS_OK == a->GetResource(&prop)) { + // get the js object; n.b., this will do a release on 'prop' + nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp); + } + else { + return JS_FALSE; + } + break; + } + case XULELEMENT_CONTROLLER: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIController* prop; + if (NS_OK == a->GetController(&prop)) { + // get the js object; n.b., this will do a release on 'prop' + nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIController::GetIID(), cx, vp); + } + else { + return JS_FALSE; + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); } @@ -187,7 +208,7 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) PR_STATIC_CALLBACK(JSBool) SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMXULElement *a = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); + nsIDOMXULElement *a = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -197,28 +218,11 @@ SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; - PRBool ok; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } switch(JSVAL_TO_INT(id)) { - case XULELEMENT_CONTROLLER: - { - secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIController* prop; - if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop, - kIControllerIID, cx, *vp)) { - return JS_FALSE; - } - - a->SetController(prop); - NS_IF_RELEASE(prop); - break; - } case XULELEMENT_ID: { secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", &ok); @@ -247,6 +251,40 @@ SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) break; } + case XULELEMENT_DATABASE: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.database", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIRDFCompositeDataSource* prop; + if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop, + kIRDFCompositeDataSourceIID, cx, *vp)) { + return JS_FALSE; + } + + a->SetDatabase(prop); + NS_IF_RELEASE(prop); + break; + } + case XULELEMENT_CONTROLLER: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIController* prop; + if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop, + kIControllerIID, cx, *vp)) { + return JS_FALSE; + } + + a->SetController(prop); + NS_IF_RELEASE(prop); + break; + } default: return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); } @@ -296,8 +334,7 @@ ResolveXULElement(JSContext *cx, JSObject *obj, jsval id) PR_STATIC_CALLBACK(JSBool) XULElementAddBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); nsAutoString b0; nsIDOMElementPtr b1; @@ -356,8 +393,7 @@ XULElementAddBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval * PR_STATIC_CALLBACK(JSBool) XULElementRemoveBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); nsAutoString b0; nsIDOMElementPtr b1; @@ -416,8 +452,7 @@ XULElementRemoveBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsva PR_STATIC_CALLBACK(JSBool) XULElementDoCommand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); *rval = JSVAL_NULL; @@ -464,8 +499,7 @@ XULElementDoCommand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval PR_STATIC_CALLBACK(JSBool) XULElementGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMNodeList* nativeRet; nsAutoString b0; nsAutoString b1; @@ -536,11 +570,12 @@ JSClass XULElementClass = { // static JSPropertySpec XULElementProperties[] = { - {"resource", XULELEMENT_RESOURCE, JSPROP_ENUMERATE | JSPROP_READONLY}, - {"controller", XULELEMENT_CONTROLLER, JSPROP_ENUMERATE}, {"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} }; diff --git a/dom/src/xul/nsJSXULTreeElement.cpp b/dom/src/xul/nsJSXULTreeElement.cpp deleted file mode 100644 index 4aa14374fa05..000000000000 --- a/dom/src/xul/nsJSXULTreeElement.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/* -*- 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 "nscore.h" -#include "nsIScriptContext.h" -#include "nsIScriptSecurityManager.h" -#include "nsIJSScriptObject.h" -#include "nsIScriptObjectOwner.h" -#include "nsIScriptGlobalObject.h" -#include "nsIPtr.h" -#include "nsString.h" -#include "nsIRDFCompositeDataSource.h" -#include "nsIDOMXULTreeElement.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(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID); -static NS_DEFINE_IID(kIXULTreeElementIID, NS_IDOMXULTREEELEMENT_IID); - -NS_DEF_PTR(nsIRDFCompositeDataSource); -NS_DEF_PTR(nsIDOMXULTreeElement); - -// -// XULTreeElement property ids -// -enum XULTreeElement_slots { - XULTREEELEMENT_DATABASE = -1 -}; - -/***********************************************************************/ -// -// XULTreeElement Properties Getter -// -PR_STATIC_CALLBACK(JSBool) -GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) -{ - nsIDOMXULTreeElement *a = (nsIDOMXULTreeElement*)JS_GetPrivate(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); - nsIScriptSecurityManager *secMan; - PRBool ok; - if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { - return JS_FALSE; - } - switch(JSVAL_TO_INT(id)) { - case XULTREEELEMENT_DATABASE: - { - secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.database", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIRDFCompositeDataSource* prop; - if (NS_OK == a->GetDatabase(&prop)) { - // get the js object; n.b., this will do a release on 'prop' - nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp); - } - else { - return JS_FALSE; - } - break; - } - default: - return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); - } - NS_RELEASE(secMan); - } - else { - return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); - } - - return PR_TRUE; -} - -/***********************************************************************/ -// -// XULTreeElement Properties Setter -// -PR_STATIC_CALLBACK(JSBool) -SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) -{ - nsIDOMXULTreeElement *a = (nsIDOMXULTreeElement*)JS_GetPrivate(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); - nsIScriptSecurityManager *secMan; - PRBool ok; - if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { - return JS_FALSE; - } - switch(JSVAL_TO_INT(id)) { - case XULTREEELEMENT_DATABASE: - { - secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.database", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIRDFCompositeDataSource* prop; - if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop, - kIRDFCompositeDataSourceIID, cx, *vp)) { - return JS_FALSE; - } - - a->SetDatabase(prop); - NS_IF_RELEASE(prop); - break; - } - default: - return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); - } - NS_RELEASE(secMan); - } - else { - return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); - } - - return PR_TRUE; -} - - -// -// XULTreeElement finalizer -// -PR_STATIC_CALLBACK(void) -FinalizeXULTreeElement(JSContext *cx, JSObject *obj) -{ - nsJSUtils::nsGenericFinalize(cx, obj); -} - - -// -// XULTreeElement enumerate -// -PR_STATIC_CALLBACK(JSBool) -EnumerateXULTreeElement(JSContext *cx, JSObject *obj) -{ - return nsJSUtils::nsGenericEnumerate(cx, obj); -} - - -// -// XULTreeElement resolve -// -PR_STATIC_CALLBACK(JSBool) -ResolveXULTreeElement(JSContext *cx, JSObject *obj, jsval id) -{ - return nsJSUtils::nsGenericResolve(cx, obj, id); -} - - -/***********************************************************************/ -// -// class for XULTreeElement -// -JSClass XULTreeElementClass = { - "XULTreeElement", - JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, - JS_PropertyStub, - JS_PropertyStub, - GetXULTreeElementProperty, - SetXULTreeElementProperty, - EnumerateXULTreeElement, - ResolveXULTreeElement, - JS_ConvertStub, - FinalizeXULTreeElement -}; - - -// -// XULTreeElement class properties -// -static JSPropertySpec XULTreeElementProperties[] = -{ - {"database", XULTREEELEMENT_DATABASE, JSPROP_ENUMERATE}, - {0} -}; - - -// -// XULTreeElement class methods -// -static JSFunctionSpec XULTreeElementMethods[] = -{ - {0} -}; - - -// -// XULTreeElement constructor -// -PR_STATIC_CALLBACK(JSBool) -XULTreeElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - return JS_FALSE; -} - - -// -// XULTreeElement class initialization -// -extern "C" NS_DOM nsresult NS_InitXULTreeElementClass(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, "XULTreeElement", &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_InitXULElementClass(aContext, (void **)&parent_proto)) { - return NS_ERROR_FAILURE; - } - proto = JS_InitClass(jscontext, // context - global, // global object - parent_proto, // parent proto - &XULTreeElementClass, // JSClass - XULTreeElement, // JSNative ctor - 0, // ctor args - XULTreeElementProperties, // proto props - XULTreeElementMethods, // 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 XULTreeElement JavaScript object -// -extern "C" NS_DOM nsresult NS_NewScriptXULTreeElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) -{ - NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULTreeElement"); - JSObject *proto; - JSObject *parent; - nsIScriptObjectOwner *owner; - JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); - nsresult result = NS_OK; - nsIDOMXULTreeElement *aXULTreeElement; - - 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_InitXULTreeElementClass(aContext, (void **)&proto)) { - return NS_ERROR_FAILURE; - } - - result = aSupports->QueryInterface(kIXULTreeElementIID, (void **)&aXULTreeElement); - if (NS_OK != result) { - return result; - } - - // create a js object for this class - *aReturn = JS_NewObject(jscontext, &XULTreeElementClass, proto, parent); - if (nsnull != *aReturn) { - // connect the native object to the js object - JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULTreeElement); - } - else { - NS_RELEASE(aXULTreeElement); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} diff --git a/mailnews/addrbook/public/nsIAddressBook.idl b/mailnews/addrbook/public/nsIAddressBook.idl index 38b3a2efcc58..b5f33548974e 100644 --- a/mailnews/addrbook/public/nsIAddressBook.idl +++ b/mailnews/addrbook/public/nsIAddressBook.idl @@ -24,15 +24,14 @@ %{C++ #include "nsIDOMNodeList.h" -#include "nsIDOMXULTreeElement.h" #include "nsIDOMXULElement.h" %} [scriptable, uuid(D60B84F1-2A8C-11d3-9E07-00A0C92B5F0D)] interface nsIAddressBook : nsISupports { - void DeleteCards(in nsIDOMXULTreeElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node); + void DeleteCards(in nsIDOMXULElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node); void NewAddressBook(in nsIRDFCompositeDataSource db, in nsIDOMXULElement srcDir, in string name); - void DeleteAddressBook(in nsIDOMXULTreeElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node); + void DeleteAddressBook(in nsIDOMXULElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node); }; diff --git a/mailnews/addrbook/resources/content/dirPane.js b/mailnews/addrbook/resources/content/dirPane.js index 94d5e6d02401..474cff5d2b0a 100644 --- a/mailnews/addrbook/resources/content/dirPane.js +++ b/mailnews/addrbook/resources/content/dirPane.js @@ -9,11 +9,5 @@ function ChangeDirectoryByURI(uri) { var tree = top.window.frames[0].frames[1].document.getElementById('resultTree'); //dump("tree = " + tree + "\n"); - - var treechildrenList = tree.getElementsByTagName('treechildren'); - if ( treechildrenList.length == 1 ) - { - var body = treechildrenList[0]; - body.setAttribute('id', uri);// body no longer valid after setting id. - } + tree.setAttribute('ref', uri);// body no longer valid after setting id. } diff --git a/mailnews/addrbook/resources/content/dirPane.xul b/mailnews/addrbook/resources/content/dirPane.xul index 049be16f249f..2a837d01104f 100644 --- a/mailnews/addrbook/resources/content/dirPane.xul +++ b/mailnews/addrbook/resources/content/dirPane.xul @@ -18,7 +18,8 @@ diff --git a/mailnews/addrbook/resources/content/resultPane.xul b/mailnews/addrbook/resources/content/resultPane.xul index 71c222cbdfd5..54e7f82459a8 100644 --- a/mailnews/addrbook/resources/content/resultPane.xul +++ b/mailnews/addrbook/resources/content/resultPane.xul @@ -23,7 +23,8 @@ rdf:containment="http://home.netscape.com/NC-rdf#CardChild"> diff --git a/mailnews/addrbook/resources/content/selectaddress.js b/mailnews/addrbook/resources/content/selectaddress.js index 8afacba471f2..b4d16676431b 100644 --- a/mailnews/addrbook/resources/content/selectaddress.js +++ b/mailnews/addrbook/resources/content/selectaddress.js @@ -121,13 +121,7 @@ function saChangeDirectoryByURI(uri) { var tree = frames["resultsFrame"].document.getElementById('resultTree'); //dump("tree = " + tree + "\n"); - - var treechildrenList = tree.getElementsByTagName('treechildren'); - if ( treechildrenList.length == 1 ) - { - var body = treechildrenList[0]; - body.setAttribute('id', uri);// body no longer valid after setting id. - } + tree.setAttribute('ref', uri);// body no longer valid after setting id. } diff --git a/mailnews/addrbook/resources/content/selectaddress.xul b/mailnews/addrbook/resources/content/selectaddress.xul index d4afea9d072c..a4ea4265be7d 100644 --- a/mailnews/addrbook/resources/content/selectaddress.xul +++ b/mailnews/addrbook/resources/content/selectaddress.xul @@ -93,6 +93,16 @@ Rights Reserved. + + diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index a32a1fad6371..55ee179045f3 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -27,7 +27,7 @@ #include "prprf.h" #include "nsCOMPtr.h" -#include "nsIDOMXULTreeElement.h" +#include "nsIDOMXULElement.h" #include "nsIRDFCompositeDataSource.h" #include "nsIRDFResource.h" #include "nsIRDFService.h" @@ -55,7 +55,7 @@ static nsresult ConvertDOMListToResourceArray(nsIDOMNodeList *nodeList, nsISuppo nsresult rv = NS_OK; PRUint32 listLength; nsIDOMNode *node; - nsIDOMXULTreeElement *xulElement; + nsIDOMXULElement *xulElement; nsIRDFResource *resource; if(!resourceArray) @@ -109,7 +109,7 @@ NS_IMPL_ISUPPORTS(nsAddressBook, nsIAddressBook::GetIID()); // NS_IMETHODIMP nsAddressBook::DeleteCards -(nsIDOMXULTreeElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList) +(nsIDOMXULElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList) { nsresult rv; @@ -206,7 +206,7 @@ NS_IMETHODIMP nsAddressBook::NewAddressBook } NS_IMETHODIMP nsAddressBook::DeleteAddressBook -(nsIDOMXULTreeElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList) +(nsIDOMXULElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList) { nsresult rv; diff --git a/mailnews/addrbook/src/nsAddressBook.h b/mailnews/addrbook/src/nsAddressBook.h index fea0b413e7c2..5562eadc2fa6 100644 --- a/mailnews/addrbook/src/nsAddressBook.h +++ b/mailnews/addrbook/src/nsAddressBook.h @@ -39,9 +39,9 @@ public: NS_DECL_ISUPPORTS // nsIAddressBook - NS_IMETHOD DeleteCards(nsIDOMXULTreeElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList); + NS_IMETHOD DeleteCards(nsIDOMXULElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList); NS_IMETHOD NewAddressBook(nsIRDFCompositeDataSource* db, nsIDOMXULElement *srcDirectory, const char *name); - NS_IMETHOD DeleteAddressBook(nsIDOMXULTreeElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList); + NS_IMETHOD DeleteAddressBook(nsIDOMXULElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList); protected: nsresult DoCommand(nsIRDFCompositeDataSource *db, char * command, nsISupportsArray *srcArray, diff --git a/mailnews/base/prefs/resources/content/accounttree.xul b/mailnews/base/prefs/resources/content/accounttree.xul index 9e88eb423e3b..c793facc71d5 100644 --- a/mailnews/base/prefs/resources/content/accounttree.xul +++ b/mailnews/base/prefs/resources/content/accounttree.xul @@ -22,7 +22,8 @@ diff --git a/mailnews/base/public/nsIMessenger.idl b/mailnews/base/public/nsIMessenger.idl index b1b402dbd9a4..6f1a7918746e 100644 --- a/mailnews/base/public/nsIMessenger.idl +++ b/mailnews/base/public/nsIMessenger.idl @@ -24,7 +24,6 @@ %{C++ #include "nsIDOMWindow.h" #include "nsIDOMNodeList.h" -#include "nsIDOMXULTreeElement.h" #include "nsIDOMXULElement.h" %} @@ -39,12 +38,12 @@ interface nsIMessenger : nsISupports { void Open3PaneWindow(); void SetWindow(in nsIDOMWindow ptr); void OpenURL(in string str); - void DeleteMessages(in nsIDOMXULTreeElement tree, in nsIDOMXULElement srcFolder, in nsIDOMNodeList node); + void DeleteMessages(in nsIDOMXULElement tree, in nsIDOMXULElement srcFolder, in nsIDOMNodeList node); void DeleteFolders(in nsIRDFCompositeDataSource db, in nsIDOMXULElement parentFolder, in nsIDOMXULElement folder); void CopyMessages(in nsIRDFCompositeDataSource database, in nsIDOMXULElement srcFolderElement, in nsIDOMXULElement dstFolderElement, in nsIDOMNodeList messages, in boolean isMove); - nsISupports GetRDFResourceForMessage(in nsIDOMXULTreeElement tree, in nsIDOMNodeList node); + nsISupports GetRDFResourceForMessage(in nsIDOMXULElement tree, in nsIDOMNodeList node); void Exit(); void Close(); void OnUnload(); diff --git a/mailnews/base/resources/content/commandglue.js b/mailnews/base/resources/content/commandglue.js index 3b5fc356d964..5330bf6a758f 100644 --- a/mailnews/base/resources/content/commandglue.js +++ b/mailnews/base/resources/content/commandglue.js @@ -71,7 +71,7 @@ function GetThreadTree() function GetThreadTreeFolder() { var tree = GetThreadTree(); - return tree.childNodes[9]; + return tree; } function FindMessenger() @@ -194,7 +194,7 @@ function ChangeFolderByURI(uri) { var folder = GetThreadTreeFolder(); var beforeTime = new Date(); - folder.setAttribute('id', uri); + folder.setAttribute('ref', uri); var afterTime = new Date(); var timeToLoad = (afterTime.getTime() - beforeTime.getTime())/1000; if(showPerformance) diff --git a/mailnews/base/resources/content/folderPane.xul b/mailnews/base/resources/content/folderPane.xul index 43ee8f0f292f..e4c480ab9623 100644 --- a/mailnews/base/resources/content/folderPane.xul +++ b/mailnews/base/resources/content/folderPane.xul @@ -37,7 +37,8 @@ diff --git a/mailnews/base/resources/content/messenger.xul b/mailnews/base/resources/content/messenger.xul index ca2adba27ba5..a114e1ce8940 100644 --- a/mailnews/base/resources/content/messenger.xul +++ b/mailnews/base/resources/content/messenger.xul @@ -477,9 +477,25 @@ Rights Reserved. + + diff --git a/mailnews/base/resources/content/threadPane.xul b/mailnews/base/resources/content/threadPane.xul index 2bdabcdb5123..620362dd091d 100644 --- a/mailnews/base/resources/content/threadPane.xul +++ b/mailnews/base/resources/content/threadPane.xul @@ -42,7 +42,8 @@ Rights Reserved. @@ -93,10 +95,6 @@ Rights Reserved. &totalColumn.label; - - - - diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index 9496ede13b4c..dc0d394707d9 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -46,7 +46,7 @@ #include "nsIMsgFolder.h" #include "nsIPop3Service.h" -#include "nsIDOMXULTreeElement.h" +#include "nsIDOMXULElement.h" #include "nsIRDFCompositeDataSource.h" #include "nsIRDFResource.h" #include "nsIRDFService.h" @@ -100,12 +100,12 @@ public: NS_IMETHOD GetNewMessages(nsIRDFCompositeDataSource *db, nsIDOMXULElement *folderElement); NS_IMETHOD SetWindow(nsIDOMWindow* aWin); NS_IMETHOD OpenURL(const char * url); - NS_IMETHOD DeleteMessages(nsIDOMXULTreeElement *tree, nsIDOMXULElement *srcFolderElement, nsIDOMNodeList *nodeList); + NS_IMETHOD DeleteMessages(nsIDOMXULElement *tree, nsIDOMXULElement *srcFolderElement, nsIDOMNodeList *nodeList); NS_IMETHOD DeleteFolders(nsIRDFCompositeDataSource *db, nsIDOMXULElement *parentFolder, nsIDOMXULElement *folder); NS_IMETHOD CopyMessages(nsIRDFCompositeDataSource *database, nsIDOMXULElement *srcFolderElement, nsIDOMXULElement *dstFolderElement, nsIDOMNodeList *messages, PRBool isMove); - NS_IMETHOD GetRDFResourceForMessage(nsIDOMXULTreeElement *tree, + NS_IMETHOD GetRDFResourceForMessage(nsIDOMXULElement *tree, nsIDOMNodeList *nodeList, nsISupports **aSupport); NS_IMETHOD Exit(); @@ -150,7 +150,7 @@ static nsresult ConvertDOMListToResourceArray(nsIDOMNodeList *nodeList, nsISuppo nsresult rv = NS_OK; PRUint32 listLength; nsIDOMNode *node; - nsIDOMXULTreeElement *xulElement; + nsIDOMXULElement *xulElement; nsIRDFResource *resource; if(!resourceArray) @@ -465,7 +465,7 @@ nsMessenger::DoCommand(nsIRDFCompositeDataSource* db, char *command, } NS_IMETHODIMP -nsMessenger::DeleteMessages(nsIDOMXULTreeElement *tree, nsIDOMXULElement *srcFolderElement, nsIDOMNodeList *nodeList) +nsMessenger::DeleteMessages(nsIDOMXULElement *tree, nsIDOMXULElement *srcFolderElement, nsIDOMNodeList *nodeList) { nsresult rv; @@ -664,7 +664,7 @@ nsMessenger::CopyMessages(nsIRDFCompositeDataSource *database, nsIDOMXULElement } NS_IMETHODIMP -nsMessenger::GetRDFResourceForMessage(nsIDOMXULTreeElement *tree, +nsMessenger::GetRDFResourceForMessage(nsIDOMXULElement *tree, nsIDOMNodeList *nodeList, nsISupports **aSupport) { diff --git a/mailnews/compose/resources/content/messengercompose.xul b/mailnews/compose/resources/content/messengercompose.xul index 52b45d63f22a..80ab368d8ea6 100644 --- a/mailnews/compose/resources/content/messengercompose.xul +++ b/mailnews/compose/resources/content/messengercompose.xul @@ -156,6 +156,14 @@ Rights Reserved. + diff --git a/rdf/base/src/nsRDFContentSink.cpp b/rdf/base/src/nsRDFContentSink.cpp index 8f6315cf816c..80eafaf797f9 100644 --- a/rdf/base/src/nsRDFContentSink.cpp +++ b/rdf/base/src/nsRDFContentSink.cpp @@ -529,10 +529,6 @@ RDFContentSinkImpl::OpenContainer(const nsIParserNode& aNode) NS_IMETHODIMP RDFContentSinkImpl::CloseContainer(const nsIParserNode& aNode) { -#ifdef DEBUG - const nsString& text = aNode.GetText(); -#endif - FlushText(); nsIRDFResource* resource; @@ -540,13 +536,14 @@ RDFContentSinkImpl::CloseContainer(const nsIParserNode& aNode) // XXX parser didn't catch unmatched tags? #ifdef PR_LOGGING if (PR_LOG_TEST(gLog, PR_LOG_ALWAYS)) { - char* tag = text.ToNewCString(); + const nsString& tagStr = aNode.GetText(); + char* tagCStr = tagStr.ToNewCString(); PR_LOG(gLog, PR_LOG_ALWAYS, ("rdfxml: extra close tag '%s' at line %d", - tag, aNode.GetSourceLineNumber())); + tagCStr, aNode.GetSourceLineNumber())); - delete[] tag; + delete[] tagCStr; } #endif diff --git a/rdf/build/dlldeps.cpp b/rdf/build/dlldeps.cpp index 59f66cc042a5..80da67915e26 100644 --- a/rdf/build/dlldeps.cpp +++ b/rdf/build/dlldeps.cpp @@ -26,6 +26,7 @@ void XXXNeverCalled() { nsAutoString s; + nsCAutoString cs; // nsRDFParserUtils nsRDFParserUtils::EntityToUnicode(""); @@ -36,12 +37,12 @@ void XXXNeverCalled() // nsRDFContentUtils nsRDFContentUtils::AttachTextNode(nsnull, nsnull); nsRDFContentUtils::FindChildByTag(nsnull, 0, nsnull, nsnull); - nsRDFContentUtils::FindChildByTagAndResource(nsnull, 0, nsnull, nsnull, nsnull); + nsRDFContentUtils::FindChildByResource(nsnull, nsnull, nsnull); nsRDFContentUtils::GetElementResource(nsnull, nsnull); nsRDFContentUtils::GetElementRefResource(nsnull, nsnull); nsRDFContentUtils::GetTextForNode(nsnull, s); nsRDFContentUtils::GetElementLogString(nsnull, s); - nsRDFContentUtils::MakeElementURI(nsnull, s, s); + nsRDFContentUtils::MakeElementURI(nsnull, s, cs); nsRDFContentUtils::MakeElementID(nsnull, s, s); // rdfutils diff --git a/rdf/build/nsRDFCID.h b/rdf/build/nsRDFCID.h index b0ad55e56777..c80f883dde01 100644 --- a/rdf/build/nsRDFCID.h +++ b/rdf/build/nsRDFCID.h @@ -66,22 +66,10 @@ #define NS_RDFCOMPOSITEDATASOURCE_CID \ { 0xe638d761, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } -// {954F0813-81DC-11d2-B52A-000000000000} -#define NS_RDFHTMLBUILDER_CID \ -{ 0x954f0813, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } - // {3D262D00-8B5A-11d2-8EB0-00805F29F370} -#define NS_RDFTREEBUILDER_CID \ +#define NS_XULTEMPLATEBUILDER_CID \ { 0x3d262d00, 0x8b5a, 0x11d2, { 0x8e, 0xb0, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } } -// {CF6547E1-D427-11d2-96ED-00104B7B7DEB} -#define NS_RDFMENUBUILDER_CID \ -{ 0xcf6547e1, 0xd427, 0x11d2, { 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } - -// {FEA36A61-D48F-11d2-96ED-00104B7B7DEB} -#define NS_RDFTOOLBARBUILDER_CID \ -{ 0xfea36a61, 0xd48f, 0x11d2, { 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } - // {7BAF62E0-8E61-11d2-8EB1-00805F29F370} #define NS_RDFXMLDATASOURCE_CID \ { 0x7baf62e0, 0x8e61, 0x11d2, { 0x8e, 0xb1, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } } diff --git a/rdf/build/nsRDFFactory.cpp b/rdf/build/nsRDFFactory.cpp index 70b1c61369ee..6f075bda34c8 100644 --- a/rdf/build/nsRDFFactory.cpp +++ b/rdf/build/nsRDFFactory.cpp @@ -65,12 +65,8 @@ static NS_DEFINE_CID(kRDFFileSystemDataSourceCID, NS_RDFFILESYSTEMDATASO static NS_DEFINE_CID(kRDFSearchDataSourceCID, NS_RDFSEARCHDATASOURCE_CID); static NS_DEFINE_CID(kRDFFindDataSourceCID, NS_RDFFINDDATASOURCE_CID); static NS_DEFINE_CID(kRDFFTPDataSourceCID, NS_RDFFTPDATASOURCE_CID); -static NS_DEFINE_CID(kRDFHTMLBuilderCID, NS_RDFHTMLBUILDER_CID); static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); -static NS_DEFINE_CID(kRDFMenuBuilderCID, NS_RDFMENUBUILDER_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); -static NS_DEFINE_CID(kRDFToolbarBuilderCID, NS_RDFTOOLBARBUILDER_CID); -static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID); static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID); static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID); static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID); @@ -80,6 +76,7 @@ static NS_DEFINE_CID(kXULDocumentInfoCID, NS_XULDOCUMENTINFO_CID static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID); static NS_DEFINE_CID(kXULKeyListenerCID, NS_XULKEYLISTENER_CID); static NS_DEFINE_CID(kXULFocusTrackerCID, NS_XULFOCUSTRACKER_CID); +static NS_DEFINE_CID(kXULTemplateBuilderCID, NS_XULTEMPLATEBUILDER_CID); class RDFFactoryImpl : public nsIFactory { @@ -224,20 +221,8 @@ RDFFactoryImpl::CreateInstance(nsISupports *aOuter, if (NS_FAILED(rv = NS_NewXULDocumentInfo((nsIXULDocumentInfo**) &inst))) return rv; } - else if (mClassID.Equals(kRDFHTMLBuilderCID)) { - if (NS_FAILED(rv = NS_NewRDFHTMLBuilder((nsIRDFContentModelBuilder**) &inst))) - return rv; - } - else if (mClassID.Equals(kRDFMenuBuilderCID)) { - if (NS_FAILED(rv = NS_NewRDFMenuBuilder((nsIRDFContentModelBuilder**) &inst))) - return rv; - } - else if (mClassID.Equals(kRDFToolbarBuilderCID)) { - if (NS_FAILED(rv = NS_NewRDFToolbarBuilder((nsIRDFContentModelBuilder**) &inst))) - return rv; - } - else if (mClassID.Equals(kRDFTreeBuilderCID)) { - if (NS_FAILED(rv = NS_NewRDFTreeBuilder((nsIRDFContentModelBuilder**) &inst))) + else if (mClassID.Equals(kXULTemplateBuilderCID)) { + if (NS_FAILED(rv = NS_NewXULTemplateBuilder((nsIRDFContentModelBuilder**) &inst))) return rv; } else if (mClassID.Equals(kRDFXULBuilderCID)) { @@ -415,11 +400,6 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath) NS_RDF_PROGID "/container-utils", aPath, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) goto done; - rv = compMgr->RegisterComponent(kRDFHTMLBuilderCID, - "RDF HTML Builder", - NS_RDF_PROGID "/html-builder", - aPath, PR_TRUE, PR_TRUE); - if (NS_FAILED(rv)) goto done; rv = compMgr->RegisterComponent(kRDFServiceCID, "RDF Service", NS_RDF_PROGID "/rdf-service", @@ -430,19 +410,9 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath) NS_RDF_PROGID "/xul-sort-service", aPath, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) goto done; - rv = compMgr->RegisterComponent(kRDFTreeBuilderCID, - "RDF Tree Builder", - NS_RDF_PROGID "/tree-builder", - aPath, PR_TRUE, PR_TRUE); - if (NS_FAILED(rv)) goto done; - rv = compMgr->RegisterComponent(kRDFMenuBuilderCID, - "RDF Menu Builder", - NS_RDF_PROGID "/menu-builder", - aPath, PR_TRUE, PR_TRUE); - if (NS_FAILED(rv)) goto done; - rv = compMgr->RegisterComponent(kRDFToolbarBuilderCID, - "RDF Toolbar Builder", - NS_RDF_PROGID "/toolbar-builder", + rv = compMgr->RegisterComponent(kXULTemplateBuilderCID, + "XUL Template Builder", + NS_RDF_PROGID "/xul-template-builder", aPath, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) goto done; rv = compMgr->RegisterComponent(kRDFXULBuilderCID, @@ -524,17 +494,11 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath) if (NS_FAILED(rv)) goto done; rv = compMgr->UnregisterComponent(kRDFContentSinkCID, aPath); if (NS_FAILED(rv)) goto done; - rv = compMgr->UnregisterComponent(kRDFHTMLBuilderCID, aPath); - if (NS_FAILED(rv)) goto done; rv = compMgr->UnregisterComponent(kRDFServiceCID, aPath); if (NS_FAILED(rv)) goto done; rv = compMgr->UnregisterComponent(kXULSortServiceCID, aPath); if (NS_FAILED(rv)) goto done; - rv = compMgr->UnregisterComponent(kRDFTreeBuilderCID, aPath); - if (NS_FAILED(rv)) goto done; - rv = compMgr->UnregisterComponent(kRDFMenuBuilderCID, aPath); - if (NS_FAILED(rv)) goto done; - rv = compMgr->UnregisterComponent(kRDFToolbarBuilderCID, aPath); + rv = compMgr->UnregisterComponent(kXULTemplateBuilderCID, aPath); if (NS_FAILED(rv)) goto done; rv = compMgr->UnregisterComponent(kRDFXULBuilderCID, aPath); if (NS_FAILED(rv)) goto done; diff --git a/rdf/content/public/MANIFEST b/rdf/content/public/MANIFEST index 29703b69f448..253e1bfa89c1 100644 --- a/rdf/content/public/MANIFEST +++ b/rdf/content/public/MANIFEST @@ -3,7 +3,6 @@ nsIDOMElementObserver.h nsIDOMNodeObserver.h nsIDOMXULDocument.h nsIDOMXULElement.h -nsIDOMXULTreeElement.h nsIRDFContentModelBuilder.h nsIRDFDocument.h nsIXULSortService.h diff --git a/rdf/content/public/Makefile.in b/rdf/content/public/Makefile.in index e4531f8b69e1..62eb06ba373c 100644 --- a/rdf/content/public/Makefile.in +++ b/rdf/content/public/Makefile.in @@ -29,7 +29,6 @@ EXPORTS = \ nsIDOMNodeObserver.h \ nsIDOMXULDocument.h \ nsIDOMXULElement.h \ - nsIDOMXULTreeElement.h \ nsIRDFContentModelBuilder.h \ nsIRDFDocument.h \ nsIXULSortService.h \ diff --git a/rdf/content/public/idl/XULElement.idl b/rdf/content/public/idl/XULElement.idl index 3e929fb0e9aa..0fc40452aff6 100644 --- a/rdf/content/public/idl/XULElement.idl +++ b/rdf/content/public/idl/XULElement.idl @@ -2,16 +2,16 @@ interface XULElement : Element { /* IID: { 0x574ed81, 0xc088, 0x11d2, \ { 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } */ - readonly attribute xpidl nsIRDFResource resource; - attribute xpidl nsIController controller; + attribute DOMString id; + attribute DOMString className; + readonly attribute CSSStyleDeclaration style; + attribute xpidl nsIRDFCompositeDataSource database; + readonly attribute xpidl nsIRDFResource resource; + attribute xpidl nsIController controller; - attribute DOMString id; - attribute DOMString className; - readonly attribute CSSStyleDeclaration style; + void addBroadcastListener(in DOMString attr, in Element element); + void removeBroadcastListener(in DOMString attr, in Element element); + void doCommand(); - 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); + NodeList getElementsByAttribute(in DOMString name, in DOMString value); }; diff --git a/rdf/content/public/idl/XULTreeElement.idl b/rdf/content/public/idl/XULTreeElement.idl deleted file mode 100644 index 0817a1eb8b1a..000000000000 --- a/rdf/content/public/idl/XULTreeElement.idl +++ /dev/null @@ -1,5 +0,0 @@ -interface XULTreeElement : XULElement { -/* IID: { 0xa6cf90ec, 0x15b3, 0x11d2, \ - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } */ - attribute xpidl nsIRDFCompositeDataSource database; -}; diff --git a/rdf/content/public/idl/makefile.win b/rdf/content/public/idl/makefile.win index dfee6db82b84..0c5746e9372c 100644 --- a/rdf/content/public/idl/makefile.win +++ b/rdf/content/public/idl/makefile.win @@ -25,8 +25,7 @@ IDLSRCS = \ NodeObserver.idl \ XULDocument.idl \ XULElement.idl \ - XULTreeElement.idl \ - XULFocusTracker.idl \ + XULFocusTracker.idl \ $(NULL) XPCOM_DESTDIR=$(DEPTH)\rdf\content\public diff --git a/rdf/content/public/makefile.win b/rdf/content/public/makefile.win index ad0e9e93b399..0690781f5f78 100644 --- a/rdf/content/public/makefile.win +++ b/rdf/content/public/makefile.win @@ -25,7 +25,6 @@ EXPORTS = \ nsIDOMNodeObserver.h \ nsIDOMXULDocument.h \ nsIDOMXULElement.h \ - nsIDOMXULTreeElement.h \ nsIRDFContentModelBuilder.h \ nsIRDFDocument.h \ nsIXULSortService.h \ diff --git a/rdf/content/public/nsIDOMXULElement.h b/rdf/content/public/nsIDOMXULElement.h index e63e7e6cb8c7..d5672470b64a 100644 --- a/rdf/content/public/nsIDOMXULElement.h +++ b/rdf/content/public/nsIDOMXULElement.h @@ -28,6 +28,7 @@ class nsIController; class nsIDOMElement; class nsIDOMCSSStyleDeclaration; +class nsIRDFCompositeDataSource; class nsIRDFResource; class nsIDOMNodeList; @@ -39,11 +40,6 @@ class nsIDOMXULElement : public nsIDOMElement { public: static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULELEMENT_IID; return iid; } - NS_IMETHOD GetResource(nsIRDFResource** aResource)=0; - - NS_IMETHOD GetController(nsIController** aController)=0; - NS_IMETHOD SetController(nsIController* aController)=0; - NS_IMETHOD GetId(nsString& aId)=0; NS_IMETHOD SetId(const nsString& aId)=0; @@ -52,6 +48,14 @@ public: 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; @@ -63,14 +67,16 @@ public: #define NS_DECL_IDOMXULELEMENT \ - NS_IMETHOD GetResource(nsIRDFResource** aResource); \ - NS_IMETHOD GetController(nsIController** aController); \ - NS_IMETHOD SetController(nsIController* aController); \ 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(); \ @@ -79,14 +85,16 @@ public: #define NS_FORWARD_IDOMXULELEMENT(_to) \ - 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 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(); } \ diff --git a/rdf/content/public/nsIDOMXULTreeElement.h b/rdf/content/public/nsIDOMXULTreeElement.h deleted file mode 100644 index 1ffbb1f0f97c..000000000000 --- a/rdf/content/public/nsIDOMXULTreeElement.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- 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 nsIRDFCompositeDataSource; - -#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 GetDatabase(nsIRDFCompositeDataSource** aDatabase)=0; - NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase)=0; -}; - - -#define NS_DECL_IDOMXULTREEELEMENT \ - NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase); \ - NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase); \ - - - -#define NS_FORWARD_IDOMXULTREEELEMENT(_to) \ - NS_IMETHOD GetDatabase(nsIRDFCompositeDataSource** aDatabase) { return _to GetDatabase(aDatabase); } \ - NS_IMETHOD SetDatabase(nsIRDFCompositeDataSource* aDatabase) { return _to SetDatabase(aDatabase); } \ - - -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__ diff --git a/rdf/content/public/nsIRDFContentModelBuilder.h b/rdf/content/public/nsIRDFContentModelBuilder.h index d67539285501..8af3daf0b547 100644 --- a/rdf/content/public/nsIRDFContentModelBuilder.h +++ b/rdf/content/public/nsIRDFContentModelBuilder.h @@ -78,10 +78,7 @@ public: nsIContent** aResult) = 0; }; -extern nsresult NS_NewRDFHTMLBuilder(nsIRDFContentModelBuilder** aResult); -extern nsresult NS_NewRDFMenuBuilder(nsIRDFContentModelBuilder** aResult); -extern nsresult NS_NewRDFToolbarBuilder(nsIRDFContentModelBuilder** aResult); -extern nsresult NS_NewRDFTreeBuilder(nsIRDFContentModelBuilder** aResult); +extern nsresult NS_NewXULTemplateBuilder(nsIRDFContentModelBuilder** aResult); extern nsresult NS_NewRDFXULBuilder(nsIRDFContentModelBuilder** aResult); #endif // nsIRDFContentModelBuilder_h__ diff --git a/rdf/content/src/Makefile.in b/rdf/content/src/Makefile.in index f0c2dfece0e9..8d08ec2b2052 100644 --- a/rdf/content/src/Makefile.in +++ b/rdf/content/src/Makefile.in @@ -31,21 +31,15 @@ CPPSRCS = \ nsJSNodeObserver.cpp \ nsJSXULDocument.cpp \ nsJSXULElement.cpp \ - nsJSXULTreeElement.cpp \ nsJSXULFocusTracker.cpp \ nsRDFContentUtils.cpp \ nsRDFDOMNodeList.cpp \ nsRDFElement.cpp \ nsRDFGenericBuilder.cpp \ - nsRDFHTMLBuilder.cpp \ - nsRDFMenuBuilder.cpp \ - nsRDFToolbarBuilder.cpp \ - nsRDFTreeBuilder.cpp \ nsRDFXULBuilder.cpp \ nsXULAttributes.cpp \ nsXULDocument.cpp \ - nsXULSortService.cpp \ - nsXULTreeElement.cpp \ + nsXULSortService.cpp \ nsXULDocumentInfo.cpp \ nsXULPopupListener.cpp \ nsXULFocusTracker.cpp \ diff --git a/rdf/content/src/makefile.win b/rdf/content/src/makefile.win index 3e66dc849e3a..a0913daaf3b0 100644 --- a/rdf/content/src/makefile.win +++ b/rdf/content/src/makefile.win @@ -27,29 +27,23 @@ LCFLAGS = \ $(NULL) CPP_OBJS=\ + .\$(OBJDIR)\nsJSXULFocusTracker.obj \ .\$(OBJDIR)\nsRDFGenericBuilder.obj \ - .\$(OBJDIR)\nsRDFMenuBuilder.obj \ - .\$(OBJDIR)\nsRDFToolbarBuilder.obj \ .\$(OBJDIR)\nsXULAttributes.obj \ + .\$(OBJDIR)\nsXULFocusTracker.obj \ + .\$(OBJDIR)\nsXULPopupListener.obj \ .\$(OBJDIR)\nsJSElementObserver.obj \ .\$(OBJDIR)\nsJSNodeObserver.obj \ .\$(OBJDIR)\nsJSXULDocument.obj \ .\$(OBJDIR)\nsJSXULElement.obj \ - .\$(OBJDIR)\nsJSXULTreeElement.obj \ - .\$(OBJDIR)\nsJSXULFocusTracker.obj \ .\$(OBJDIR)\nsRDFContentUtils.obj \ .\$(OBJDIR)\nsRDFDOMNodeList.obj \ .\$(OBJDIR)\nsRDFElement.obj \ - .\$(OBJDIR)\nsRDFHTMLBuilder.obj \ - .\$(OBJDIR)\nsRDFTreeBuilder.obj \ .\$(OBJDIR)\nsRDFXULBuilder.obj \ .\$(OBJDIR)\nsXULDocument.obj \ - .\$(OBJDIR)\nsXULDocumentInfo.obj \ - .\$(OBJDIR)\nsXULPopupListener.obj \ - .\$(OBJDIR)\nsXULFocusTracker.obj \ - .\$(OBJDIR)\nsXULSortService.obj \ - .\$(OBJDIR)\nsXULTreeElement.obj \ + .\$(OBJDIR)\nsXULDocumentInfo.obj \ .\$(OBJDIR)\nsXULKeyListener.obj \ + .\$(OBJDIR)\nsXULSortService.obj \ $(NULL) # XXX we are including layout\html\base\src to get HTML elements diff --git a/rdf/content/src/nsJSElementObserver.cpp b/rdf/content/src/nsJSElementObserver.cpp index 225a6891260e..77f19ef006dd 100644 --- a/rdf/content/src/nsJSElementObserver.cpp +++ b/rdf/content/src/nsJSElementObserver.cpp @@ -51,7 +51,7 @@ NS_DEF_PTR(nsIDOMElementObserver); PR_STATIC_CALLBACK(JSBool) GetElementObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMElementObserver *a = (nsIDOMElementObserver*)JS_GetPrivate(cx, obj); + nsIDOMElementObserver *a = (nsIDOMElementObserver*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -61,6 +61,7 @@ GetElementObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } @@ -85,7 +86,7 @@ GetElementObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) PR_STATIC_CALLBACK(JSBool) SetElementObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMElementObserver *a = (nsIDOMElementObserver*)JS_GetPrivate(cx, obj); + nsIDOMElementObserver *a = (nsIDOMElementObserver*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -95,6 +96,7 @@ SetElementObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } @@ -149,7 +151,7 @@ ResolveElementObserver(JSContext *cx, JSObject *obj, jsval id) PR_STATIC_CALLBACK(JSBool) ElementObserverOnSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMElementObserver *nativeThis = (nsIDOMElementObserver*)JS_GetPrivate(cx, obj); + nsIDOMElementObserver *nativeThis = (nsIDOMElementObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMElementPtr b0; nsAutoString b1; nsAutoString b2; @@ -211,7 +213,7 @@ ElementObserverOnSetAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *a PR_STATIC_CALLBACK(JSBool) ElementObserverOnRemoveAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMElementObserver *nativeThis = (nsIDOMElementObserver*)JS_GetPrivate(cx, obj); + nsIDOMElementObserver *nativeThis = (nsIDOMElementObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMElementPtr b0; nsAutoString b1; @@ -270,7 +272,7 @@ ElementObserverOnRemoveAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval PR_STATIC_CALLBACK(JSBool) ElementObserverOnSetAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMElementObserver *nativeThis = (nsIDOMElementObserver*)JS_GetPrivate(cx, obj); + nsIDOMElementObserver *nativeThis = (nsIDOMElementObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMElementPtr b0; nsIDOMAttrPtr b1; @@ -335,7 +337,7 @@ ElementObserverOnSetAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsva PR_STATIC_CALLBACK(JSBool) ElementObserverOnRemoveAttributeNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMElementObserver *nativeThis = (nsIDOMElementObserver*)JS_GetPrivate(cx, obj); + nsIDOMElementObserver *nativeThis = (nsIDOMElementObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMElementPtr b0; nsIDOMAttrPtr b1; diff --git a/rdf/content/src/nsJSNodeObserver.cpp b/rdf/content/src/nsJSNodeObserver.cpp index 566ad103656a..68908107c6fa 100644 --- a/rdf/content/src/nsJSNodeObserver.cpp +++ b/rdf/content/src/nsJSNodeObserver.cpp @@ -48,7 +48,7 @@ NS_DEF_PTR(nsIDOMNodeObserver); PR_STATIC_CALLBACK(JSBool) GetNodeObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMNodeObserver *a = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj); + nsIDOMNodeObserver *a = (nsIDOMNodeObserver*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -58,6 +58,7 @@ GetNodeObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } @@ -82,7 +83,7 @@ GetNodeObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) PR_STATIC_CALLBACK(JSBool) SetNodeObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMNodeObserver *a = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj); + nsIDOMNodeObserver *a = (nsIDOMNodeObserver*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -92,6 +93,7 @@ SetNodeObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } @@ -146,8 +148,7 @@ ResolveNodeObserver(JSContext *cx, JSObject *obj, jsval id) PR_STATIC_CALLBACK(JSBool) NodeObserverOnSetNodeValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMNodePtr b0; nsAutoString b1; @@ -206,8 +207,7 @@ NodeObserverOnSetNodeValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv PR_STATIC_CALLBACK(JSBool) NodeObserverOnInsertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMNodePtr b0; nsIDOMNodePtr b1; nsIDOMNodePtr b2; @@ -281,8 +281,7 @@ NodeObserverOnInsertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv PR_STATIC_CALLBACK(JSBool) NodeObserverOnReplaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMNodePtr b0; nsIDOMNodePtr b1; nsIDOMNodePtr b2; @@ -356,8 +355,7 @@ NodeObserverOnReplaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv PR_STATIC_CALLBACK(JSBool) NodeObserverOnRemoveChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMNodePtr b0; nsIDOMNodePtr b1; @@ -422,8 +420,7 @@ NodeObserverOnRemoveChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, PR_STATIC_CALLBACK(JSBool) NodeObserverOnAppendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMNodePtr b0; nsIDOMNodePtr b1; diff --git a/rdf/content/src/nsJSXULDocument.cpp b/rdf/content/src/nsJSXULDocument.cpp index 8912f0ab0d7d..262c5c4243ff 100644 --- a/rdf/content/src/nsJSXULDocument.cpp +++ b/rdf/content/src/nsJSXULDocument.cpp @@ -51,11 +51,8 @@ NS_DEF_PTR(nsIDOMNodeList); // enum XULDocument_slots { XULDOCUMENT_POPUPELEMENT = -1, - XULDOCUMENT_TOOLTIPELEMENT = -2, - XULDOCUMENT_FOCUS = -3 - }; /***********************************************************************/ @@ -67,86 +64,45 @@ 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); - nsIScriptSecurityManager *secMan; - PRBool ok = PR_FALSE; - if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { - return JS_FALSE; - } - switch(JSVAL_TO_INT(id)) { - case XULDOCUMENT_POPUPELEMENT: - { - secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.popupelement", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIDOMElement* prop; - if (NS_OK == a->GetPopupElement(&prop)) { - // get the js object - nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); - } - else { - return JS_FALSE; - } - break; - } - case XULDOCUMENT_TOOLTIPELEMENT: - { - secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.tooltipelement", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIDOMElement* prop; - if (NS_OK == a->GetTooltipElement(&prop)) { - // get the js object nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); } @@ -193,100 +149,52 @@ 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); - nsIScriptSecurityManager *secMan; - PRBool ok = PR_FALSE; - if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { - return JS_FALSE; - } - switch(JSVAL_TO_INT(id)) { - case XULDOCUMENT_POPUPELEMENT: - { - secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.popupelement", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIDOMElement* prop; - if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop, - kIElementIID, "Element", - cx, *vp)) { - return JS_FALSE; - } - - a->SetPopupElement(prop); - NS_IF_RELEASE(prop); - break; - } - case XULDOCUMENT_TOOLTIPELEMENT: - { - secMan->CheckScriptAccess(scriptCX, obj, "xuldocument.tooltipelement", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIDOMElement* prop; - if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop, - kIElementIID, "Element", - cx, *vp)) { - return JS_FALSE; - } - - a->SetTooltipElement(prop); - NS_IF_RELEASE(prop); break; } @@ -340,8 +248,6 @@ PR_STATIC_CALLBACK(JSBool) XULDocumentGetElementById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsIDOMXULDocument *nativeThis = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj); - - JSBool rBool = JS_FALSE; nsIDOMElement* nativeRet; nsAutoString b0; @@ -393,8 +299,6 @@ PR_STATIC_CALLBACK(JSBool) XULDocumentGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsIDOMXULDocument *nativeThis = (nsIDOMXULDocument*)nsJSUtils::nsGetNativeThis(cx, obj); - - JSBool rBool = JS_FALSE; nsIDOMNodeList* nativeRet; nsAutoString b0; nsAutoString b1; @@ -466,9 +370,7 @@ JSClass XULDocumentClass = { static JSPropertySpec XULDocumentProperties[] = { {"popupElement", XULDOCUMENT_POPUPELEMENT, JSPROP_ENUMERATE}, - {"tooltipElement", XULDOCUMENT_TOOLTIPELEMENT, JSPROP_ENUMERATE}, - {"focus", XULDOCUMENT_FOCUS, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/rdf/content/src/nsJSXULElement.cpp b/rdf/content/src/nsJSXULElement.cpp index 7f5b0423eb99..aebb60cfbbbb 100644 --- a/rdf/content/src/nsJSXULElement.cpp +++ b/rdf/content/src/nsJSXULElement.cpp @@ -30,6 +30,7 @@ #include "nsIController.h" #include "nsIDOMElement.h" #include "nsIDOMCSSStyleDeclaration.h" +#include "nsIRDFCompositeDataSource.h" #include "nsIDOMXULElement.h" #include "nsIRDFResource.h" #include "nsIDOMNodeList.h" @@ -41,6 +42,7 @@ 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); @@ -48,6 +50,7 @@ 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); @@ -56,11 +59,12 @@ NS_DEF_PTR(nsIDOMNodeList); // XULElement property ids // enum XULElement_slots { - XULELEMENT_RESOURCE = -1, - XULELEMENT_CONTROLLER = -2, - XULELEMENT_ID = -3, - XULELEMENT_CLASSNAME = -4, - XULELEMENT_STYLE = -5 + XULELEMENT_ID = -1, + XULELEMENT_CLASSNAME = -2, + XULELEMENT_STYLE = -3, + XULELEMENT_DATABASE = -4, + XULELEMENT_RESOURCE = -5, + XULELEMENT_CONTROLLER = -6 }; /***********************************************************************/ @@ -70,7 +74,7 @@ enum XULElement_slots { PR_STATIC_CALLBACK(JSBool) GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMXULElement *a = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); + nsIDOMXULElement *a = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -80,45 +84,11 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; - PRBool ok; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } switch(JSVAL_TO_INT(id)) { - case XULELEMENT_RESOURCE: - { - secMan->CheckScriptAccess(scriptCX, obj, "xulelement.resource", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIRDFResource* prop; - if (NS_OK == a->GetResource(&prop)) { - // get the js object; n.b., this will do a release on 'prop' - nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp); - } - else { - return JS_FALSE; - } - break; - } - case XULELEMENT_CONTROLLER: - { - secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIController* prop; - if (NS_OK == a->GetController(&prop)) { - // get the js object; n.b., this will do a release on 'prop' - nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIController::GetIID(), cx, vp); - } - else { - return JS_FALSE; - } - break; - } case XULELEMENT_ID: { secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", &ok); @@ -168,6 +138,57 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case XULELEMENT_DATABASE: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.database", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIRDFCompositeDataSource* prop; + if (NS_OK == a->GetDatabase(&prop)) { + // get the js object; n.b., this will do a release on 'prop' + nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp); + } + else { + return JS_FALSE; + } + break; + } + case XULELEMENT_RESOURCE: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.resource", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIRDFResource* prop; + if (NS_OK == a->GetResource(&prop)) { + // get the js object; n.b., this will do a release on 'prop' + nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp); + } + else { + return JS_FALSE; + } + break; + } + case XULELEMENT_CONTROLLER: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIController* prop; + if (NS_OK == a->GetController(&prop)) { + // get the js object; n.b., this will do a release on 'prop' + nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIController::GetIID(), cx, vp); + } + else { + return JS_FALSE; + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); } @@ -187,7 +208,7 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) PR_STATIC_CALLBACK(JSBool) SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMXULElement *a = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); + nsIDOMXULElement *a = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -197,28 +218,11 @@ SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; - PRBool ok; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } switch(JSVAL_TO_INT(id)) { - case XULELEMENT_CONTROLLER: - { - secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIController* prop; - if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop, - kIControllerIID, cx, *vp)) { - return JS_FALSE; - } - - a->SetController(prop); - NS_IF_RELEASE(prop); - break; - } case XULELEMENT_ID: { secMan->CheckScriptAccess(scriptCX, obj, "xulelement.id", &ok); @@ -247,6 +251,40 @@ SetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) break; } + case XULELEMENT_DATABASE: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.database", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIRDFCompositeDataSource* prop; + if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop, + kIRDFCompositeDataSourceIID, cx, *vp)) { + return JS_FALSE; + } + + a->SetDatabase(prop); + NS_IF_RELEASE(prop); + break; + } + case XULELEMENT_CONTROLLER: + { + secMan->CheckScriptAccess(scriptCX, obj, "xulelement.controller", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + nsIController* prop; + if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop, + kIControllerIID, cx, *vp)) { + return JS_FALSE; + } + + a->SetController(prop); + NS_IF_RELEASE(prop); + break; + } default: return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); } @@ -296,8 +334,7 @@ ResolveXULElement(JSContext *cx, JSObject *obj, jsval id) PR_STATIC_CALLBACK(JSBool) XULElementAddBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); nsAutoString b0; nsIDOMElementPtr b1; @@ -356,8 +393,7 @@ XULElementAddBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval * PR_STATIC_CALLBACK(JSBool) XULElementRemoveBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); nsAutoString b0; nsIDOMElementPtr b1; @@ -416,8 +452,7 @@ XULElementRemoveBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsva PR_STATIC_CALLBACK(JSBool) XULElementDoCommand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); *rval = JSVAL_NULL; @@ -464,8 +499,7 @@ XULElementDoCommand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval PR_STATIC_CALLBACK(JSBool) XULElementGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)JS_GetPrivate(cx, obj); - JSBool rBool = JS_FALSE; + nsIDOMXULElement *nativeThis = (nsIDOMXULElement*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMNodeList* nativeRet; nsAutoString b0; nsAutoString b1; @@ -536,11 +570,12 @@ JSClass XULElementClass = { // static JSPropertySpec XULElementProperties[] = { - {"resource", XULELEMENT_RESOURCE, JSPROP_ENUMERATE | JSPROP_READONLY}, - {"controller", XULELEMENT_CONTROLLER, JSPROP_ENUMERATE}, {"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} }; diff --git a/rdf/content/src/nsJSXULFocusTracker.cpp b/rdf/content/src/nsJSXULFocusTracker.cpp index e5f6cabee691..84e52d3e6402 100644 --- a/rdf/content/src/nsJSXULFocusTracker.cpp +++ b/rdf/content/src/nsJSXULFocusTracker.cpp @@ -57,7 +57,7 @@ enum XULFocusTracker_slots { PR_STATIC_CALLBACK(JSBool) GetXULFocusTrackerProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMXULFocusTracker *a = (nsIDOMXULFocusTracker*)JS_GetPrivate(cx, obj); + nsIDOMXULFocusTracker *a = (nsIDOMXULFocusTracker*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -67,7 +67,7 @@ GetXULFocusTrackerProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; - PRBool ok; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } @@ -108,7 +108,7 @@ GetXULFocusTrackerProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) PR_STATIC_CALLBACK(JSBool) SetXULFocusTrackerProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - nsIDOMXULFocusTracker *a = (nsIDOMXULFocusTracker*)JS_GetPrivate(cx, obj); + nsIDOMXULFocusTracker *a = (nsIDOMXULFocusTracker*)nsJSUtils::nsGetNativeThis(cx, obj); // If there's no private data, this must be the prototype, so ignore if (nsnull == a) { @@ -118,7 +118,7 @@ SetXULFocusTrackerProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); nsIScriptSecurityManager *secMan; - PRBool ok; + PRBool ok = PR_FALSE; if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { return JS_FALSE; } @@ -190,7 +190,7 @@ ResolveXULFocusTracker(JSContext *cx, JSObject *obj, jsval id) PR_STATIC_CALLBACK(JSBool) XULFocusTrackerAddFocusListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)JS_GetPrivate(cx, obj); + nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMElementPtr b0; *rval = JSVAL_NULL; @@ -246,7 +246,7 @@ XULFocusTrackerAddFocusListener(JSContext *cx, JSObject *obj, uintN argc, jsval PR_STATIC_CALLBACK(JSBool) XULFocusTrackerRemoveFocusListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)JS_GetPrivate(cx, obj); + nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)nsJSUtils::nsGetNativeThis(cx, obj); nsIDOMElementPtr b0; *rval = JSVAL_NULL; @@ -302,7 +302,7 @@ XULFocusTrackerRemoveFocusListener(JSContext *cx, JSObject *obj, uintN argc, jsv PR_STATIC_CALLBACK(JSBool) XULFocusTrackerFocusChanged(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)JS_GetPrivate(cx, obj); + nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)nsJSUtils::nsGetNativeThis(cx, obj); *rval = JSVAL_NULL; @@ -349,7 +349,7 @@ XULFocusTrackerFocusChanged(JSContext *cx, JSObject *obj, uintN argc, jsval *arg PR_STATIC_CALLBACK(JSBool) XULFocusTrackerGetController(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)JS_GetPrivate(cx, obj); + nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)nsJSUtils::nsGetNativeThis(cx, obj); nsIController* nativeRet; *rval = JSVAL_NULL; @@ -398,7 +398,7 @@ XULFocusTrackerGetController(JSContext *cx, JSObject *obj, uintN argc, jsval *ar PR_STATIC_CALLBACK(JSBool) XULFocusTrackerSetController(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)JS_GetPrivate(cx, obj); + nsIDOMXULFocusTracker *nativeThis = (nsIDOMXULFocusTracker*)nsJSUtils::nsGetNativeThis(cx, obj); nsIControllerPtr b0; *rval = JSVAL_NULL; @@ -425,7 +425,7 @@ XULFocusTrackerSetController(JSContext *cx, JSObject *obj, uintN argc, jsval *ar if (argc >= 1) { - if (JS_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports**)&b0, + if (JS_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports**) &b0, kIControllerIID, cx, argv[0])) { return JS_FALSE; } diff --git a/rdf/content/src/nsJSXULTreeElement.cpp b/rdf/content/src/nsJSXULTreeElement.cpp deleted file mode 100644 index 4aa14374fa05..000000000000 --- a/rdf/content/src/nsJSXULTreeElement.cpp +++ /dev/null @@ -1,328 +0,0 @@ -/* -*- 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 "nscore.h" -#include "nsIScriptContext.h" -#include "nsIScriptSecurityManager.h" -#include "nsIJSScriptObject.h" -#include "nsIScriptObjectOwner.h" -#include "nsIScriptGlobalObject.h" -#include "nsIPtr.h" -#include "nsString.h" -#include "nsIRDFCompositeDataSource.h" -#include "nsIDOMXULTreeElement.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(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID); -static NS_DEFINE_IID(kIXULTreeElementIID, NS_IDOMXULTREEELEMENT_IID); - -NS_DEF_PTR(nsIRDFCompositeDataSource); -NS_DEF_PTR(nsIDOMXULTreeElement); - -// -// XULTreeElement property ids -// -enum XULTreeElement_slots { - XULTREEELEMENT_DATABASE = -1 -}; - -/***********************************************************************/ -// -// XULTreeElement Properties Getter -// -PR_STATIC_CALLBACK(JSBool) -GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) -{ - nsIDOMXULTreeElement *a = (nsIDOMXULTreeElement*)JS_GetPrivate(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); - nsIScriptSecurityManager *secMan; - PRBool ok; - if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { - return JS_FALSE; - } - switch(JSVAL_TO_INT(id)) { - case XULTREEELEMENT_DATABASE: - { - secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.database", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIRDFCompositeDataSource* prop; - if (NS_OK == a->GetDatabase(&prop)) { - // get the js object; n.b., this will do a release on 'prop' - nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp); - } - else { - return JS_FALSE; - } - break; - } - default: - return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); - } - NS_RELEASE(secMan); - } - else { - return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); - } - - return PR_TRUE; -} - -/***********************************************************************/ -// -// XULTreeElement Properties Setter -// -PR_STATIC_CALLBACK(JSBool) -SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) -{ - nsIDOMXULTreeElement *a = (nsIDOMXULTreeElement*)JS_GetPrivate(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); - nsIScriptSecurityManager *secMan; - PRBool ok; - if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { - return JS_FALSE; - } - switch(JSVAL_TO_INT(id)) { - case XULTREEELEMENT_DATABASE: - { - secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.database", &ok); - if (!ok) { - //Need to throw error here - return JS_FALSE; - } - nsIRDFCompositeDataSource* prop; - if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop, - kIRDFCompositeDataSourceIID, cx, *vp)) { - return JS_FALSE; - } - - a->SetDatabase(prop); - NS_IF_RELEASE(prop); - break; - } - default: - return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); - } - NS_RELEASE(secMan); - } - else { - return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); - } - - return PR_TRUE; -} - - -// -// XULTreeElement finalizer -// -PR_STATIC_CALLBACK(void) -FinalizeXULTreeElement(JSContext *cx, JSObject *obj) -{ - nsJSUtils::nsGenericFinalize(cx, obj); -} - - -// -// XULTreeElement enumerate -// -PR_STATIC_CALLBACK(JSBool) -EnumerateXULTreeElement(JSContext *cx, JSObject *obj) -{ - return nsJSUtils::nsGenericEnumerate(cx, obj); -} - - -// -// XULTreeElement resolve -// -PR_STATIC_CALLBACK(JSBool) -ResolveXULTreeElement(JSContext *cx, JSObject *obj, jsval id) -{ - return nsJSUtils::nsGenericResolve(cx, obj, id); -} - - -/***********************************************************************/ -// -// class for XULTreeElement -// -JSClass XULTreeElementClass = { - "XULTreeElement", - JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, - JS_PropertyStub, - JS_PropertyStub, - GetXULTreeElementProperty, - SetXULTreeElementProperty, - EnumerateXULTreeElement, - ResolveXULTreeElement, - JS_ConvertStub, - FinalizeXULTreeElement -}; - - -// -// XULTreeElement class properties -// -static JSPropertySpec XULTreeElementProperties[] = -{ - {"database", XULTREEELEMENT_DATABASE, JSPROP_ENUMERATE}, - {0} -}; - - -// -// XULTreeElement class methods -// -static JSFunctionSpec XULTreeElementMethods[] = -{ - {0} -}; - - -// -// XULTreeElement constructor -// -PR_STATIC_CALLBACK(JSBool) -XULTreeElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) -{ - return JS_FALSE; -} - - -// -// XULTreeElement class initialization -// -extern "C" NS_DOM nsresult NS_InitXULTreeElementClass(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, "XULTreeElement", &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_InitXULElementClass(aContext, (void **)&parent_proto)) { - return NS_ERROR_FAILURE; - } - proto = JS_InitClass(jscontext, // context - global, // global object - parent_proto, // parent proto - &XULTreeElementClass, // JSClass - XULTreeElement, // JSNative ctor - 0, // ctor args - XULTreeElementProperties, // proto props - XULTreeElementMethods, // 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 XULTreeElement JavaScript object -// -extern "C" NS_DOM nsresult NS_NewScriptXULTreeElement(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) -{ - NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULTreeElement"); - JSObject *proto; - JSObject *parent; - nsIScriptObjectOwner *owner; - JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); - nsresult result = NS_OK; - nsIDOMXULTreeElement *aXULTreeElement; - - 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_InitXULTreeElementClass(aContext, (void **)&proto)) { - return NS_ERROR_FAILURE; - } - - result = aSupports->QueryInterface(kIXULTreeElementIID, (void **)&aXULTreeElement); - if (NS_OK != result) { - return result; - } - - // create a js object for this class - *aReturn = JS_NewObject(jscontext, &XULTreeElementClass, proto, parent); - if (nsnull != *aReturn) { - // connect the native object to the js object - JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULTreeElement); - } - else { - NS_RELEASE(aXULTreeElement); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} diff --git a/rdf/content/src/nsRDFContentUtils.cpp b/rdf/content/src/nsRDFContentUtils.cpp index 69fd687a89de..365c9e4efd85 100644 --- a/rdf/content/src/nsRDFContentUtils.cpp +++ b/rdf/content/src/nsRDFContentUtils.cpp @@ -71,8 +71,6 @@ static NS_DEFINE_IID(kILocaleIID, NS_ILOCALE_IID); static NS_DEFINE_CID(kDateTimeFormatCID, NS_DATETIMEFORMAT_CID); static NS_DEFINE_CID(kDateTimeFormatIID, NS_IDATETIMEFORMAT_IID); - - nsresult nsRDFContentUtils::AttachTextNode(nsIContent* parent, nsIRDFNode* value) { @@ -142,11 +140,9 @@ nsRDFContentUtils::FindChildByTag(nsIContent* aElement, nsresult -nsRDFContentUtils::FindChildByTagAndResource(nsIContent* aElement, - PRInt32 aNameSpaceID, - nsIAtom* aTag, - nsIRDFResource* aResource, - nsIContent** aResult) +nsRDFContentUtils::FindChildByResource(nsIContent* aElement, + nsIRDFResource* aResource, + nsIContent** aResult) { nsresult rv; @@ -159,28 +155,12 @@ nsRDFContentUtils::FindChildByTagAndResource(nsIContent* aElement, if (NS_FAILED(rv = aElement->ChildAt(i, *getter_AddRefs(kid)))) return rv; // XXX fatal - // Make sure it's a - PRInt32 nameSpaceID; - if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID))) - return rv; // XXX fatal - - if (nameSpaceID != aNameSpaceID) - continue; // wrong namespace - - nsCOMPtr tag; - if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(tag)))) - return rv; // XXX fatal - - if (tag.get() != aTag) - continue; // wrong tag - // 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 resource; rv = GetElementResource(kid, getter_AddRefs(resource)); - NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving resource"); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) continue; if (resource.get() != aResource) continue; // not the resource we want @@ -221,14 +201,18 @@ nsRDFContentUtils::GetElementResource(nsIContent* aElement, nsIRDFResource** aRe if (! doc) return NS_ERROR_FAILURE; - nsAutoString uri; + char buf[256]; + nsCAutoString uri; + nsStr::Initialize(uri, buf, sizeof(buf) - 1, 0, eOneByte, PR_FALSE); + buf[0] = 0; + rv = nsRDFContentUtils::MakeElementURI(doc, id, uri); if (NS_FAILED(rv)) return rv; NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv); if (NS_FAILED(rv)) return rv; - rv = rdf->GetUnicodeResource(uri.GetUnicode(), aResult); + rv = rdf->GetResource(uri, aResult); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create resource"); if (NS_FAILED(rv)) return rv; @@ -452,7 +436,7 @@ nsRDFContentUtils::GetAttributeLogString(nsIContent* aElement, PRInt32 aNameSpac nsresult -nsRDFContentUtils::MakeElementURI(nsIDocument* aDocument, const nsString& aElementID, nsString& aURI) +nsRDFContentUtils::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. @@ -477,11 +461,12 @@ nsRDFContentUtils::MakeElementURI(nsIDocument* aDocument, const nsString& aEleme if (! spec) return NS_ERROR_FAILURE; - aURI = spec; // copied by nsString, right + aURI = spec; + #ifdef NECKO nsCRT::free(spec); #endif - if (aElementID.First() != PRUnichar('#')) { + if (aElementID.First() != '#') { aURI += '#'; } aURI += aElementID; diff --git a/rdf/content/src/nsRDFContentUtils.h b/rdf/content/src/nsRDFContentUtils.h index ba337756a15c..602aa74d6b6b 100644 --- a/rdf/content/src/nsRDFContentUtils.h +++ b/rdf/content/src/nsRDFContentUtils.h @@ -33,6 +33,7 @@ class nsIContent; class nsIDocument; class nsIDOMNodeList; class nsIRDFNode; +class nsCString; class nsString; @@ -50,11 +51,9 @@ public: nsIContent **aResult); static nsresult - FindChildByTagAndResource(nsIContent* aElement, - PRInt32 aNameSpaceID, - nsIAtom* aTag, - nsIRDFResource* aResource, - nsIContent** aResult); + FindChildByResource(nsIContent* aElement, + nsIRDFResource* aResource, + nsIContent** aResult); static nsresult GetElementResource(nsIContent* aElement, nsIRDFResource** aResult); @@ -72,7 +71,7 @@ public: GetAttributeLogString(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aTag, nsString& aResult); static nsresult - MakeElementURI(nsIDocument* aDocument, const nsString& aElementID, nsString& aURI); + MakeElementURI(nsIDocument* aDocument, const nsString& aElementID, nsCString& aURI); static nsresult MakeElementID(nsIDocument* aDocument, const nsString& aURI, nsString& aElementID); diff --git a/rdf/content/src/nsRDFElement.cpp b/rdf/content/src/nsRDFElement.cpp index 975a45beba42..1949a070ebc0 100644 --- a/rdf/content/src/nsRDFElement.cpp +++ b/rdf/content/src/nsRDFElement.cpp @@ -79,7 +79,6 @@ #include "nsIStyledContent.h" #include "nsIStyleRule.h" #include "nsIURL.h" -#include "nsXULTreeElement.h" #include "rdfutil.h" #include "prlog.h" #include "rdf.h" @@ -317,8 +316,8 @@ private: PRBool mContentsMustBeGenerated; nsVoidArray* mBroadcastListeners; // [WEAK] nsIDOMXULElement* mBroadcaster; // [OWNER] - nsXULElement* mInnerXULElement; // [OWNER] nsIController* mController; // [OWNER] + nsCOMPtr mDatabase; // [OWNER] }; @@ -397,7 +396,6 @@ RDFElementImpl::RDFElementImpl(PRInt32 aNameSpaceID, nsIAtom* aTag) mContentsMustBeGenerated(PR_FALSE), mBroadcastListeners(nsnull), mBroadcaster(nsnull), - mInnerXULElement(nsnull), mController(nsnull) { NS_INIT_REFCNT(); @@ -514,8 +512,6 @@ RDFElementImpl::~RDFElementImpl() ++entry; } } - - delete mInnerXULElement; } @@ -576,16 +572,6 @@ RDFElementImpl::QueryInterface(REFNSIID iid, void** result) else if (iid.Equals(kIJSScriptObjectIID)) { *result = NS_STATIC_CAST(nsIJSScriptObject*, this); } - else if (iid.Equals(nsIDOMXULTreeElement::GetIID()) && - (mNameSpaceID == kNameSpaceID_XUL) && - (mTag == kTreeAtom)) { - if (! mInnerXULElement) { - if ((mInnerXULElement = new nsXULTreeElement(this)) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - } - - return mInnerXULElement->QueryInterface(iid, result); - } else { *result = nsnull; return NS_NOINTERFACE; @@ -1275,16 +1261,8 @@ RDFElementImpl::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject if (! mScriptObject) { nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - nsresult (*fn)(nsIScriptContext* aContext, nsISupports* aSupports, nsISupports* aParent, void** aReturn); + rv = NS_NewScriptXULElement(aContext, (nsIDOMXULElement*) this, global, (void**) &mScriptObject); - if (mTag == kTreeAtom) { - fn = NS_NewScriptXULTreeElement; - } - else { - fn = NS_NewScriptXULElement; - } - - rv = fn(aContext, (nsIDOMXULElement*) this, global, (void**) &mScriptObject); NS_RELEASE(global); // Ensure that a reference exists to this element @@ -2532,6 +2510,36 @@ RDFElementImpl::GetResource(nsIRDFResource** aResource) return NS_OK; } + +NS_IMETHODIMP +RDFElementImpl::GetDatabase(nsIRDFCompositeDataSource** aDatabase) +{ + NS_PRECONDITION(aDatabase != nsnull, "null ptr"); + if (! aDatabase) + return NS_ERROR_NULL_POINTER; + + *aDatabase = mDatabase; + NS_IF_ADDREF(*aDatabase); + return NS_OK; +} + + +NS_IMETHODIMP +RDFElementImpl::SetDatabase(nsIRDFCompositeDataSource* aDatabase) +{ + // XXX maybe someday you'll be allowed to change it. + NS_PRECONDITION(mDatabase == nsnull, "already initialized"); + if (mDatabase) + return NS_ERROR_ALREADY_INITIALIZED; + + mDatabase = aDatabase; + + // XXX reconstruct the entire tree now! + + return NS_OK; +} + + //////////////////////////////////////////////////////////////////////// // Implementation methods diff --git a/rdf/content/src/nsRDFGenericBuilder.cpp b/rdf/content/src/nsRDFGenericBuilder.cpp index d804603ff40e..ed3cb67d2b35 100644 --- a/rdf/content/src/nsRDFGenericBuilder.cpp +++ b/rdf/content/src/nsRDFGenericBuilder.cpp @@ -60,6 +60,7 @@ #include "nsINameSpaceManager.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" +#include "nsITextContent.h" #include "nsIURL.h" #include "nsLayoutCID.h" #include "nsRDFCID.h" @@ -79,11 +80,8 @@ #include "prlog.h" -// Remove this to try running without the C++ builders. This will -// inhibit delegation to the fallback builder for constructing content -// (but still relies on it for determining the correct tagset to use). -#define FALLBACK_BUILDERS 1 - +#define NS_RDF_ELEMENT_WAS_CREATED NS_RDF_NO_VALUE +#define NS_RDF_ELEMENT_WAS_THERE NS_OK static PRLogModuleInfo* gLog; @@ -102,6 +100,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); +static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID); static NS_DEFINE_IID(kXULSortServiceCID, NS_XULSORTSERVICE_CID); static NS_DEFINE_IID(kIXULSortServiceIID, NS_IXULSORTSERVICE_IID); @@ -115,12 +114,13 @@ static NS_DEFINE_CID(kIHTMLElementFactoryIID, NS_IHTML_ELEMENT_FACTORY_IID); //////////////////////////////////////////////////////////////////////// -nsrefcnt RDFGenericBuilderImpl::gRefCnt = 0; +nsrefcnt RDFGenericBuilderImpl::gRefCnt = 0; nsIXULSortService* RDFGenericBuilderImpl::XULSortService = nsnull; nsIAtom* RDFGenericBuilderImpl::kContainerAtom; nsIAtom* RDFGenericBuilderImpl::kLazyContentAtom; nsIAtom* RDFGenericBuilderImpl::kIsContainerAtom; +nsIAtom* RDFGenericBuilderImpl::kIsEmptyAtom; nsIAtom* RDFGenericBuilderImpl::kXULContentsGeneratedAtom; nsIAtom* RDFGenericBuilderImpl::kTemplateContentsGeneratedAtom; nsIAtom* RDFGenericBuilderImpl::kContainerContentsGeneratedAtom; @@ -133,9 +133,8 @@ nsIAtom* RDFGenericBuilderImpl::kContainmentAtom; nsIAtom* RDFGenericBuilderImpl::kNaturalOrderPosAtom; nsIAtom* RDFGenericBuilderImpl::kIgnoreAtom; nsIAtom* RDFGenericBuilderImpl::kRefAtom; +nsIAtom* RDFGenericBuilderImpl::kValueAtom; -nsIAtom* RDFGenericBuilderImpl::kSubcontainmentAtom; -nsIAtom* RDFGenericBuilderImpl::kRootcontainmentAtom; nsIAtom* RDFGenericBuilderImpl::kTemplateAtom; nsIAtom* RDFGenericBuilderImpl::kRuleAtom; nsIAtom* RDFGenericBuilderImpl::kTextAtom; @@ -161,6 +160,26 @@ nsIRDFResource* RDFGenericBuilderImpl::kXUL_element; //////////////////////////////////////////////////////////////////////// +nsresult +NS_NewXULTemplateBuilder(nsIRDFContentModelBuilder** aResult) +{ + nsresult rv; + RDFGenericBuilderImpl* result = new RDFGenericBuilderImpl(); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); // stabilize + + rv = result->Init(); + if (NS_SUCCEEDED(rv)) { + rv = result->QueryInterface(nsCOMTypeInfo::GetIID(), (void**) aResult); + } + + NS_RELEASE(result); + return rv; +} + + RDFGenericBuilderImpl::RDFGenericBuilderImpl(void) : mDocument(nsnull), mDB(nsnull), @@ -168,92 +187,6 @@ RDFGenericBuilderImpl::RDFGenericBuilderImpl(void) mTimer(nsnull) { NS_INIT_REFCNT(); - - if (gRefCnt == 0) { - kContainerAtom = NS_NewAtom("container"); - kLazyContentAtom = NS_NewAtom("lazycontent"); - kIsContainerAtom = NS_NewAtom("iscontainer"); - kXULContentsGeneratedAtom = NS_NewAtom("xulcontentsgenerated"); - kTemplateContentsGeneratedAtom = NS_NewAtom("templatecontentsgenerated"); - kContainerContentsGeneratedAtom = NS_NewAtom("containercontentsgenerated"); - - kIdAtom = NS_NewAtom("id"); - kOpenAtom = NS_NewAtom("open"); - kEmptyAtom = NS_NewAtom("empty"); - kResourceAtom = NS_NewAtom("resource"); - kURIAtom = NS_NewAtom("uri"); - kContainmentAtom = NS_NewAtom("containment"); - kIgnoreAtom = NS_NewAtom("ignore"); - kRefAtom = NS_NewAtom("ref"); - kNaturalOrderPosAtom = NS_NewAtom("pos"); - - kSubcontainmentAtom = NS_NewAtom("subcontainment"); - kRootcontainmentAtom = NS_NewAtom("rootcontainment"); - kTemplateAtom = NS_NewAtom("template"); - kRuleAtom = NS_NewAtom("rule"); - - kTextAtom = NS_NewAtom("text"); - kPropertyAtom = NS_NewAtom("property"); - kInstanceOfAtom = NS_NewAtom("instanceOf"); - - nsresult rv; - - // Register the XUL and RDF namespaces: these'll just retrieve - // the IDs if they've already been registered by someone else. - if (NS_SUCCEEDED(rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, - nsnull, - kINameSpaceManagerIID, - (void**) &gNameSpaceManager))) { - -// XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp -static const char kXULNameSpaceURI[] - = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - -static const char kRDFNameSpaceURI[] - = RDF_NAMESPACE_URI; - - rv = gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace"); - - rv = gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register RDF namespace"); - } - else { - NS_ERROR("couldn't create namepsace manager"); - } - - - // Initialize the global shared reference to the service - // manager and get some shared resource objects. - rv = nsServiceManager::GetService(kRDFServiceCID, - kIRDFServiceIID, - (nsISupports**) &gRDFService); - - if (NS_SUCCEEDED(rv)) { - gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title); - gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child); - gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column); - gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder); - gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child); - gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf); - gRDFService->GetResource(XUL_NAMESPACE_URI "element", &kXUL_element); - } - - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - nsIRDFContainerUtils::GetIID(), - (nsISupports**) &gRDFContainerUtils); - - rv = nsServiceManager::GetService(kXULSortServiceCID, - kIXULSortServiceIID, - (nsISupports**) &XULSortService); - - } - ++gRefCnt; - -#ifdef PR_LOGGING - if (! gLog) - gLog = PR_NewLogModule("nsRDFGenericBuilder"); -#endif } RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) @@ -270,7 +203,8 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) NS_RELEASE(kContainerAtom); NS_RELEASE(kLazyContentAtom); NS_RELEASE(kIsContainerAtom); - NS_RELEASE(kXULContentsGeneratedAtom); + NS_RELEASE(kIsEmptyAtom); + NS_RELEASE(kXULContentsGeneratedAtom); NS_RELEASE(kTemplateContentsGeneratedAtom); NS_RELEASE(kContainerContentsGeneratedAtom); @@ -278,14 +212,13 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) NS_RELEASE(kOpenAtom); NS_RELEASE(kEmptyAtom); NS_RELEASE(kResourceAtom); - NS_RELEASE(kURIAtom); + NS_RELEASE(kURIAtom); NS_RELEASE(kContainmentAtom); NS_RELEASE(kIgnoreAtom); NS_RELEASE(kRefAtom); + NS_RELEASE(kValueAtom); NS_RELEASE(kNaturalOrderPosAtom); - NS_RELEASE(kSubcontainmentAtom); - NS_RELEASE(kRootcontainmentAtom); NS_RELEASE(kTemplateAtom); NS_RELEASE(kRuleAtom); NS_RELEASE(kTextAtom); @@ -307,11 +240,105 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) } if (mTimer) - { - mTimer->Cancel(); - NS_RELEASE(mTimer); - mTimer = nsnull; + { + mTimer->Cancel(); + NS_RELEASE(mTimer); + mTimer = nsnull; + } +} + + +nsresult +RDFGenericBuilderImpl::Init() +{ + if (gRefCnt == 0) { + kContainerAtom = NS_NewAtom("container"); + kLazyContentAtom = NS_NewAtom("lazycontent"); + kIsContainerAtom = NS_NewAtom("iscontainer"); + kIsEmptyAtom = NS_NewAtom("isempty"); + kXULContentsGeneratedAtom = NS_NewAtom("xulcontentsgenerated"); + kTemplateContentsGeneratedAtom = NS_NewAtom("templatecontentsgenerated"); + kContainerContentsGeneratedAtom = NS_NewAtom("containercontentsgenerated"); + + kIdAtom = NS_NewAtom("id"); + kOpenAtom = NS_NewAtom("open"); + kEmptyAtom = NS_NewAtom("empty"); + kResourceAtom = NS_NewAtom("resource"); + kURIAtom = NS_NewAtom("uri"); + kContainmentAtom = NS_NewAtom("containment"); + kIgnoreAtom = NS_NewAtom("ignore"); + kRefAtom = NS_NewAtom("ref"); + kValueAtom = NS_NewAtom("value"); + kNaturalOrderPosAtom = NS_NewAtom("pos"); + + kTemplateAtom = NS_NewAtom("template"); + kRuleAtom = NS_NewAtom("rule"); + + kTextAtom = NS_NewAtom("text"); + kPropertyAtom = NS_NewAtom("property"); + kInstanceOfAtom = NS_NewAtom("instanceOf"); + + nsresult rv; + + // Register the XUL and RDF namespaces: these'll just retrieve + // the IDs if they've already been registered by someone else. + rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, + nsnull, + nsCOMTypeInfo::GetIID(), + (void**) &gNameSpaceManager); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager"); + if (NS_FAILED(rv)) return rv; + + // XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp + static const char kXULNameSpaceURI[] + = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + + static const char kRDFNameSpaceURI[] + = RDF_NAMESPACE_URI; + + rv = gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace"); + if (NS_FAILED(rv)) return rv; + + rv = gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register RDF namespace"); + if (NS_FAILED(rv)) return rv; + + + // Initialize the global shared reference to the service + // manager and get some shared resource objects. + rv = nsServiceManager::GetService(kRDFServiceCID, + kIRDFServiceIID, + (nsISupports**) &gRDFService); + if (NS_FAILED(rv)) return rv; + + gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title); + gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child); + gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column); + gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder); + gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child); + gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf); + gRDFService->GetResource(XUL_NAMESPACE_URI "element", &kXUL_element); + + rv = nsServiceManager::GetService(kRDFContainerUtilsCID, + nsIRDFContainerUtils::GetIID(), + (nsISupports**) &gRDFContainerUtils); + if (NS_FAILED(rv)) return rv; + + rv = nsServiceManager::GetService(kXULSortServiceCID, + kIXULSortServiceIID, + (nsISupports**) &XULSortService); + if (NS_FAILED(rv)) return rv; + } + ++gRefCnt; + +#ifdef PR_LOGGING + if (! gLog) + gLog = PR_NewLogModule("nsRDFGenericBuilder"); +#endif + + return NS_OK; } //////////////////////////////////////////////////////////////////////// @@ -391,10 +418,26 @@ RDFGenericBuilderImpl::SetDataBase(nsIRDFCompositeDataSource* aDataBase) if (mDB) return NS_ERROR_ALREADY_INITIALIZED; + NS_PRECONDITION(mRoot != nsnull, "not initialized"); + if (! mRoot) + return NS_ERROR_NOT_INITIALIZED; + mDB = aDataBase; NS_ADDREF(mDB); mDB->AddObserver(this); + + // Now set the database on the element, so that script writers can + // access it. + nsCOMPtr element( do_QueryInterface(mRoot) ); + NS_ASSERTION(element != nsnull, "not a XULElement"); + if (! element) + return NS_ERROR_UNEXPECTED; + + nsresult rv; + rv = element->SetDatabase(aDataBase); + if (NS_FAILED(rv)) return rv; + return NS_OK; } @@ -415,74 +458,9 @@ RDFGenericBuilderImpl::GetDataBase(nsIRDFCompositeDataSource** aDataBase) NS_IMETHODIMP RDFGenericBuilderImpl::CreateRootContent(nsIRDFResource* aResource) { - // Create a structure that looks like this: - // - // - // - // - // - // - // - // - // Eventually, we should be able to do away with the HTML tags and - // just have it create XUL in some other context. - - nsresult rv; - nsCOMPtr tag; - nsCOMPtr doc; - nsCOMPtr rootAtom; - if (NS_FAILED(rv = GetRootWidgetAtom(getter_AddRefs(rootAtom)))) { - return rv; - } - - if (NS_FAILED(rv = mDocument->QueryInterface(kIDocumentIID, - (void**) getter_AddRefs(doc)))) - return rv; - - // Create the DOCUMENT element - if ((tag = dont_AddRef(NS_NewAtom("document"))) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - nsCOMPtr root; - if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_HTML, /* XXX */ - tag, - getter_AddRefs(root)))) - return rv; - - doc->SetRootContent(NS_STATIC_CAST(nsIContent*, root)); - - // Create the BODY element - nsCOMPtr body; - if ((tag = dont_AddRef(NS_NewAtom("body"))) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_HTML, /* XXX */ - tag, - getter_AddRefs(body)))) - return rv; - - - // Attach the BODY to the DOCUMENT - if (NS_FAILED(rv = root->AppendChildTo(body, PR_FALSE))) - return rv; - - // Create the xul:rootwidget element, and indicate that children should - // be recursively generated on demand - nsCOMPtr widget; - if (NS_FAILED(rv = CreateElement(kNameSpaceID_XUL, - rootAtom, - aResource, - getter_AddRefs(widget)))) - return rv; - - if (NS_FAILED(rv = widget->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE))) - return rv; - - // Attach the ROOTWIDGET to the BODY - if (NS_FAILED(rv = body->AppendChildTo(widget, PR_FALSE))) - return rv; - - return NS_OK; + // XXX Remove this method from the interface + NS_NOTREACHED("whoops"); + return NS_ERROR_UNEXPECTED; } NS_IMETHODIMP @@ -661,13 +639,6 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eSet, aProperty, aTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - // fall through if node wasn't created by a XUL template - rv = SetWidgetAttribute(element, aProperty, aTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -779,12 +750,6 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eClear, aProperty, aTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - rv = UnsetWidgetAttribute(element, aProperty, aTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -899,12 +864,6 @@ RDFGenericBuilderImpl::OnChange(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eSet, aProperty, aNewTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - rv = SetWidgetAttribute(element, aProperty, aNewTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -1020,7 +979,7 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a // Now do the work to change the attribute. There are a couple of // special cases that we need to check for here... if ((elementNameSpaceID == kNameSpaceID_XUL) && - IsItemOrFolder(element) && // XXX IsItemOrFolder(): is this what we really mean? + IsResourceElement(element) && // XXX IsResourceElement(): is this what we really mean? (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kOpenAtom)) { @@ -1058,8 +1017,7 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a } } else if ((elementNameSpaceID == kNameSpaceID_XUL) && - (IsItemOrFolder(element) || // XXX IsItemOrFolder(): is this what we really mean? - IsWidgetInsertionRootElement(element)) && + (IsResourceElement(element)) && (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kIdAtom)) { @@ -1093,6 +1051,9 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a return rv; } + if (! parent) + return NS_ERROR_UNEXPECTED; + if (NS_FAILED(rv = parent->RemoveChildAt(elementIndex, PR_TRUE))) { NS_ERROR("unable to remove element"); return rv; @@ -1145,8 +1106,10 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a } else if ((attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kRefAtom)) { - // Ignore changes to the 'ref=' attribute; the XUL builder - // will take care of that for us. + // Remove all of the template children and rebuild them + rv = RemoveAndRebuildGeneratedChildren(element); + if (NS_FAILED(rv)) return rv; + return NS_OK; } @@ -1235,7 +1198,7 @@ RDFGenericBuilderImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString } if ((elementNameSpaceID == kNameSpaceID_XUL) && - IsItemOrFolder(element) && // XXX Is this what we really mean? + IsResourceElement(element) && // XXX Is this what we really mean? (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kOpenAtom)) { // We are removing the value of the "open" attribute. This may @@ -1300,186 +1263,115 @@ RDFGenericBuilderImpl::OnRemoveAttributeNode(nsIDOMElement* aElement, nsIDOMAttr } +//////////////////////////////////////////////////////////////////////// +// nsITimerCallback methods + +void +RDFGenericBuilderImpl::Notify(nsITimer* aTimer) +{ +} + //////////////////////////////////////////////////////////////////////// // Implementation methods nsresult -RDFGenericBuilderImpl::SetAllAttributesOnElement(nsIContent *aParentNode, nsIContent *aNode, nsIRDFResource *res) +RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement, + nsIRDFResource *aProperty, + nsIRDFResource* aChild, + nsIContent *aRule, + PRBool *aIsMatch) { - // get all arcs out, and if not a containment property, set attribute - nsresult rv = NS_OK; - PRBool markAsContainer = PR_FALSE; - nsCOMPtr arcs; - if (NS_SUCCEEDED(rv = mDB->ArcLabelsOut(res, getter_AddRefs(arcs)))) - { - PRBool hasMore = PR_TRUE; - while(hasMore) - { - rv = arcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) break; - if (hasMore == PR_FALSE) break; + nsresult rv; - nsCOMPtr isupports; - if (NS_FAILED(rv = arcs->GetNext(getter_AddRefs(isupports)))) break; + PRInt32 count; + rv = aRule->GetAttributeCount(count); + if (NS_FAILED(rv)) return(rv); - nsCOMPtr property = do_QueryInterface(isupports); - // Ignore properties that are used to indicate "tree-ness" - if (IsContainmentProperty(aNode, property)) - { - markAsContainer = PR_TRUE; - continue; - } - - // Ignore any properties set in ignore attribute - // Note: since node isn't in the content model yet, start with its parent - if (IsIgnoredProperty(aParentNode, property)) - { - continue; - } - - PRInt32 nameSpaceID; - nsCOMPtr tag; - if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) - break; - nsCOMPtr value; - if (NS_FAILED(rv = mDB->GetTarget(res, property, PR_TRUE, getter_AddRefs(value)))) - break; - if (rv == NS_RDF_NO_VALUE) - continue; - nsAutoString s; - if (NS_SUCCEEDED(rv = nsRDFContentUtils::GetTextForNode(value, s))) - { - aNode->SetAttribute(nameSpaceID, tag, s, PR_FALSE); - } - } - } - if (markAsContainer == PR_TRUE) - { - // mark this as a "container" so that we know to - // recursively generate kids if they're asked for. - rv = aNode->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE); - } - return(rv); -} - - -nsresult -RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIRDFResource *aNode, nsIContent *aRule, PRBool *matchingRuleFound) -{ - nsresult rv = NS_OK; - PRInt32 count; - - *matchingRuleFound = PR_FALSE; - - if (NS_FAILED(rv = aRule->GetAttributeCount(count))) - { - return(rv); - } - - *matchingRuleFound = PR_TRUE; - for (PRInt32 loop=0; loop attribAtom; - if (NS_FAILED(rv = aRule->GetAttributeNameAt(loop, attribNameSpaceID, *getter_AddRefs(attribAtom)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsAutoString attribValue; - if (NS_FAILED(rv = aRule->GetAttribute(attribNameSpaceID, attribAtom, attribValue))) - { - *matchingRuleFound = PR_FALSE; - break; - } - -#ifdef DEBUG - nsAutoString nsName; - attribAtom->ToString(nsName); - char *debugName = nsName.ToNewCString(); - if (debugName) - { - delete [] debugName; - debugName = nsnull; - } -#endif + for (PRInt32 loop=0; loop attr; + rv = aRule->GetAttributeNameAt(loop, attrNameSpaceID, *getter_AddRefs(attr)); + if (NS_FAILED(rv)) return rv; // Note: some attributes must be skipped on XUL template rule subtree // never compare against {}:container attribute - if ((attribAtom.get() == kLazyContentAtom) && (attribNameSpaceID == kNameSpaceID_None)) + if ((attr.get() == kLazyContentAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against rdf:property attribute - else if ((attribAtom.get() == kPropertyAtom) && (attribNameSpaceID == kNameSpaceID_RDF)) + else if ((attr.get() == kPropertyAtom) && (attrNameSpaceID == kNameSpaceID_RDF)) continue; // never compare against rdf:instanceOf attribute - else if ((attribAtom.get() == kInstanceOfAtom) && (attribNameSpaceID == kNameSpaceID_RDF)) + else if ((attr.get() == kInstanceOfAtom) && (attrNameSpaceID == kNameSpaceID_RDF)) continue; // never compare against {}:id attribute - else if ((attribAtom.get() == kIdAtom) && (attribNameSpaceID == kNameSpaceID_None)) - continue; - // never compare against {}:rootcontainment attribute - else if ((attribAtom.get() == kRootcontainmentAtom) && (attribNameSpaceID == kNameSpaceID_None)) - continue; - // never compare against {}:subcontainment attribute - else if ((attribAtom.get() == kSubcontainmentAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kIdAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against {}:xulcontentsgenerated attribute - else if ((attribAtom.get() == kXULContentsGeneratedAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kXULContentsGeneratedAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against {}:itemcontentsgenerated attribute (bogus) - else if ((attribAtom.get() == kTemplateContentsGeneratedAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kTemplateContentsGeneratedAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; - else if ((attribNameSpaceID == kNameSpaceID_None) && (attribAtom.get() == kIsContainerAtom)) - { - // check and see if aNode is a container - PRBool containerFlag = IsContainer(aRule, aNode); - if (containerFlag && (!attribValue.EqualsIgnoreCase("true"))) - { - *matchingRuleFound = PR_FALSE; - break; - } - else if (!containerFlag && (!attribValue.EqualsIgnoreCase("false"))) - { - *matchingRuleFound = PR_FALSE; - break; - } - } - else - { - nsCOMPtr attribAtomResource; + nsAutoString value; + rv = aRule->GetAttribute(attrNameSpaceID, attr, value); + if (NS_FAILED(rv)) return rv; - if (NS_FAILED(rv = GetResource(attribNameSpaceID, attribAtom, getter_AddRefs(attribAtomResource)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsCOMPtr aResult; - if (NS_FAILED(rv = mDB->GetTarget(aNode, attribAtomResource, PR_TRUE, getter_AddRefs(aResult)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsAutoString resultStr; - if (NS_FAILED(rv = nsRDFContentUtils::GetTextForNode(aResult, resultStr))) - { - *matchingRuleFound = PR_FALSE; - break; - } - if (!attribValue.Equals(resultStr)) - { - *matchingRuleFound = PR_FALSE; - break; - } + if ((attrNameSpaceID == kNameSpaceID_None) && (attr.get() == kIsContainerAtom)) { + // check and see if aChild is a container + PRBool isContainer = IsContainer(aRule, aChild); + if (isContainer && (!value.EqualsIgnoreCase("true"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + else if (!isContainer && (!value.EqualsIgnoreCase("false"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } } + else if ((attrNameSpaceID == kNameSpaceID_None) && (attr.get() == kIsEmptyAtom)) { + PRBool isEmpty = IsEmpty(aRule, aChild); + if (isEmpty && (!value.EqualsIgnoreCase("true"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + else if (!isEmpty && (!value.EqualsIgnoreCase("false"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + } + else { + nsCOMPtr property; + rv = GetResource(attrNameSpaceID, attr, getter_AddRefs(property)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr target; + rv = mDB->GetTarget(aChild, property, PR_TRUE, getter_AddRefs(target)); + if (NS_FAILED(rv)) return rv; + + nsAutoString targetStr; + rv = nsRDFContentUtils::GetTextForNode(target, targetStr); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get text for target"); + if (NS_FAILED(rv)) return rv; + + if (!value.Equals(targetStr)) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + } } - return(rv); + + *aIsMatch = PR_TRUE; + return NS_OK; } nsresult -RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent **aTemplate) +RDFGenericBuilderImpl::FindTemplate(nsIContent* aElement, + nsIRDFResource *aProperty, + nsIRDFResource* aChild, + nsIContent **aTemplate) { nsresult rv; @@ -1509,15 +1401,6 @@ RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent if (tag.get() != kTemplateAtom) continue; -#if 0 - // check for debugging - nsAutoString debugValue; - if (NS_SUCCEEDED(rv = tmpl->GetAttribute(kNameSpaceID_None, kDebugAtom, debugValue))) - { - debugValue = "true"; - } -#endif - // found a template; check against any (optional) rules PRInt32 numRuleChildren, numRulesFound = 0; rv = tmpl->ChildCount(numRuleChildren); @@ -1542,11 +1425,11 @@ RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent if (ruleTag.get() == kRuleAtom) { ++numRulesFound; - PRBool matchingRuleFound = PR_FALSE; - rv = IsTemplateRuleMatch(aNode, aRule, &matchingRuleFound); + PRBool isMatch = PR_FALSE; + rv = IsTemplateRuleMatch(aElement, aProperty, aChild, aRule, &isMatch); if (NS_FAILED(rv)) return rv; - if (matchingRuleFound) { + if (isMatch) { // found a matching rule, use it as the template *aTemplate = aRule; NS_ADDREF(*aTemplate); @@ -1583,14 +1466,6 @@ RDFGenericBuilderImpl::IsIgnoreableAttribute(PRInt32 aNameSpaceID, nsIAtom* aAtt else if ((aAttribute == kInstanceOfAtom) && (aNameSpaceID == kNameSpaceID_RDF)) { return PR_TRUE; } - // never copy {}:rootcontainment attribute - else if ((aAttribute == kRootcontainmentAtom) && (aNameSpaceID == kNameSpaceID_None)) { - return PR_TRUE; - } - // never copy {}:subcontainment attribute - else if ((aAttribute == kSubcontainmentAtom) && (aNameSpaceID == kNameSpaceID_None)) { - return PR_TRUE; - } // never copy {}:ID attribute else if ((aAttribute == kIdAtom) && (aNameSpaceID == kNameSpaceID_None)) { return PR_TRUE; @@ -1608,11 +1483,54 @@ RDFGenericBuilderImpl::IsIgnoreableAttribute(PRInt32 aNameSpaceID, nsIAtom* aAtt } } + +nsresult +RDFGenericBuilderImpl::GetSubstitutionText(nsIRDFResource* aResource, + const nsString& aSubstitution, + nsString& aResult) +{ + nsresult rv; + + if (aSubstitution.Find("rdf:") == 0) { + // found an attribute which wants to bind + // its value to RDF so look it up in the + // graph + nsAutoString propertyStr(aSubstitution); + propertyStr.Cut(0,4); + + nsCOMPtr property; + rv = gRDFService->GetUnicodeResource(propertyStr.GetUnicode(), getter_AddRefs(property)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr valueNode; + rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(valueNode)); + if (NS_FAILED(rv)) return rv; + + if (valueNode) { + rv = nsRDFContentUtils::GetTextForNode(valueNode, aResult); + if (NS_FAILED(rv)) return rv; + } + else { + aResult.Truncate(); + } + } + else if (aSubstitution.EqualsIgnoreCase("...")) { + const char *uri = nsnull; + aResource->GetValueConst(&uri); + aResult = uri; + } + else { + aResult = aSubstitution; + } + + return NS_OK; +} + nsresult RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, nsIContent *aRealNode, PRBool aIsUnique, - nsIRDFResource* aResource, + nsIRDFResource* aChild, PRInt32 aNaturalOrderPos) { nsresult rv; @@ -1624,7 +1542,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; nsXPIDLCString resourceCStr; - rv = aResource->GetValue(getter_Copies(resourceCStr)); + rv = aChild->GetValue(getter_Copies(resourceCStr)); if (NS_FAILED(rv)) return rv; nsAutoString tagStr(tag->GetUnicode()); @@ -1651,8 +1569,8 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, rv = tmplKid->GetNameSpaceID(nameSpaceID); if (NS_FAILED(rv)) return rv; - // check whether this item is a containment item for aResource - PRBool isContainmentElement = PR_FALSE; + // check whether this item is the resource element + PRBool isResourceElement = PR_FALSE; if (nameSpaceID == kNameSpaceID_XUL) { nsAutoString idValue; rv = tmplKid->GetAttribute(kNameSpaceID_None, @@ -1661,7 +1579,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (idValue.EqualsIgnoreCase("..."))) { - isContainmentElement = PR_TRUE; + isResourceElement = PR_TRUE; aIsUnique = PR_FALSE; } } @@ -1670,58 +1588,69 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, rv = tmplKid->GetTag(*getter_AddRefs(tag)); if (NS_FAILED(rv)) return rv; + PRBool realKidAlreadyExisted = PR_FALSE; + nsCOMPtr realKid; if (aIsUnique) { - rv = EnsureElementHasGenericChild(aRealNode, - nameSpaceID, - tag, - getter_AddRefs(realKid)); + rv = EnsureElementHasGenericChild(aRealNode, nameSpaceID, tag, getter_AddRefs(realKid)); if (NS_FAILED(rv)) return rv; - // Recurse until we get to a non-unique element. Mark the - // element's contents as being generated so that - // any re-entrant calls don't trigger an infinite recursion. - rv = realKid->SetAttribute(kNameSpaceID_None, - kTemplateContentsGeneratedAtom, - "true", - PR_FALSE); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set contents-generated attribute"); - if (NS_FAILED(rv)) return rv; + if (rv == NS_RDF_ELEMENT_WAS_THERE) { + realKidAlreadyExisted = PR_TRUE; + } + else { + // Mark the element's contents as being generated so + // that any re-entrant calls don't trigger an infinite + // recursion. + rv = realKid->SetAttribute(kNameSpaceID_None, + kTemplateContentsGeneratedAtom, + "true", + PR_FALSE); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set contents-generated attribute"); + if (NS_FAILED(rv)) return rv; + } - rv = BuildContentFromTemplate(tmplKid, realKid, PR_TRUE, aResource, -1); + // Recurse until we get to the resource element. + rv = BuildContentFromTemplate(tmplKid, realKid, PR_TRUE, aChild, -1); if (NS_FAILED(rv)) return rv; } - else if (isContainmentElement) { - rv = CreateElement(nameSpaceID, tag, aResource, getter_AddRefs(realKid)); + else if (isResourceElement) { + rv = CreateElement(nameSpaceID, tag, aChild, getter_AddRefs(realKid)); if (NS_FAILED(rv)) return rv; - if (IsContainer(realKid, aResource)) { + if (IsContainer(realKid, aChild)) { rv = realKid->SetAttribute(kNameSpaceID_None, kContainerAtom, "true", PR_FALSE); if (NS_FAILED(rv)) return rv; // test to see if the container has contents - char* isEmpty = IsEmpty(realKid, aResource) ? "true" : "false"; + char* isEmpty = IsEmpty(realKid, aChild) ? "true" : "false"; rv = realKid->SetAttribute(kNameSpaceID_None, kEmptyAtom, isEmpty, PR_FALSE); if (NS_FAILED(rv)) return rv; } } else if ((tag.get() == kTextAtom) && (nameSpaceID == kNameSpaceID_XUL)) { - // is replaced by text of the + // is replaced by text of the // actual value of the rdf:resource attribute for the given node nsAutoString attrValue; - rv = tmplKid->GetAttribute(kNameSpaceID_RDF, kResourceAtom, attrValue); + rv = tmplKid->GetAttribute(kNameSpaceID_None, kValueAtom, attrValue); if (NS_FAILED(rv)) return rv; if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (attrValue.Length() > 0)) { - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(attrValue.GetUnicode(), getter_AddRefs(property)); + nsAutoString text; + rv = GetSubstitutionText(aChild, attrValue, text); if (NS_FAILED(rv)) return rv; - nsCOMPtr text; - rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(text)); + nsCOMPtr content; + rv = nsComponentManager::CreateInstance(kTextNodeCID, + nsnull, + nsITextContent::GetIID(), + getter_AddRefs(content)); if (NS_FAILED(rv)) return rv; - rv = nsRDFContentUtils::AttachTextNode(aRealNode, text); + rv = content->SetText(text.GetUnicode(), text.Length(), PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = aRealNode->AppendChildTo(nsCOMPtr( do_QueryInterface(content) ), PR_FALSE); if (NS_FAILED(rv)) return rv; } } @@ -1763,7 +1692,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; } - if (realKid) { + if (realKid && !realKidAlreadyExisted) { // save a reference (its ID) to the template node that was used nsAutoString templateID; rv = tmplKid->GetAttribute(kNameSpaceID_None, kIdAtom, templateID); @@ -1778,7 +1707,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; // set natural order hint - if ((aNaturalOrderPos > 0) && (isContainmentElement)) { + if ((aNaturalOrderPos > 0) && (isResourceElement)) { nsAutoString pos, zero("0000"); pos.Append(aNaturalOrderPos, 10); if (pos.Length() < 4) { @@ -1816,49 +1745,29 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - if (attribValue.Find("rdf:") == 0) { - // found an attribute which wants to bind - // its value to RDF so look it up in the - // graph - attribValue.Cut(0,4); + nsAutoString text; + rv = GetSubstitutionText(aChild, attribValue, text); + if (NS_FAILED(rv)) return rv; - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(attribValue.GetUnicode(), getter_AddRefs(property)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr valueNode; - rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(valueNode)); - if (NS_FAILED(rv)) return rv; - - if (valueNode) { - rv = nsRDFContentUtils::GetTextForNode(valueNode, attribValue); - if (NS_FAILED(rv)) return rv; - } - else { - attribValue.Truncate(); - } - } - else if (attribValue.EqualsIgnoreCase("...")) { - const char *uri = nsnull; - aResource->GetValueConst(&uri); - attribValue = uri; - } - - realKid->SetAttribute(attribNameSpaceID, attribName, attribValue, PR_FALSE); + rv = realKid->SetAttribute(attribNameSpaceID, attribName, text, PR_FALSE); + if (NS_FAILED(rv)) return rv; } } } - // Note: add into tree, but only sort if its a containment element! - if ((nsnull != XULSortService) && (isContainmentElement == PR_TRUE)) { - rv = XULSortService->InsertContainerNode(aRealNode, realKid); - if (NS_FAILED(rv)) { + // We'll _already_ have added the unique elements. + if (! aIsUnique) { + // Note: add into tree, but only sort if its a resource element! + if ((nsnull != XULSortService) && (isResourceElement)) { + rv = XULSortService->InsertContainerNode(aRealNode, realKid); + if (NS_FAILED(rv)) { + aRealNode->AppendChildTo(realKid, PR_TRUE); + } + } + else { aRealNode->AppendChildTo(realKid, PR_TRUE); } } - else { - aRealNode->AppendChildTo(realKid, PR_TRUE); - } // If item says its "open", then recurve now and build up its children nsAutoString openState; @@ -1879,85 +1788,24 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, nsresult RDFGenericBuilderImpl::CreateWidgetItem(nsIContent *aElement, nsIRDFResource *aProperty, - nsIRDFResource *aValue, + nsIRDFResource *aChild, PRInt32 aNaturalOrderPos) { nsCOMPtr tmpl; nsresult rv; - rv = FindTemplateForResource(aValue, getter_AddRefs(tmpl)); + rv = FindTemplate(aElement, aProperty, aChild, getter_AddRefs(tmpl)); if (NS_FAILED(rv)) { -#ifdef FALLBACK_BUILDERS - return AddWidgetItem(aElement, aProperty, aValue, aNaturalOrderPos); -#else + // No template. Just bail. return NS_OK; -#endif - } - - // The "container" node which will be used to build children. - nsCOMPtr container; - PRBool isRoot = PR_FALSE; - - // if template specifies a rootcontainment attribute, get it - // and determine if we are building children off of the root - nsAutoString rootAttrValue; - rv = tmpl->GetAttribute(kNameSpaceID_None, - kRootcontainmentAtom, - rootAttrValue); - if (NS_FAILED(rv)) return rv; - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - // XXX Ick. Can we remember this somehow? - nsCOMPtr rootAtom = NS_NewAtom(rootAttrValue); - if (! rootAtom) return NS_ERROR_OUT_OF_MEMORY; - - PRInt32 nameSpaceID; - rv = aElement->GetNameSpaceID(nameSpaceID); - if (NS_FAILED(rv)) return rv; - - if (nameSpaceID == kNameSpaceID_XUL) { - nsCOMPtr tag; - rv = aElement->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - if (tag == rootAtom) - isRoot = PR_TRUE; - } - } - - // if template specifies a subcontainment attribute, get it - // and make sure aElement contains it (if not the root). - if (! isRoot) { - nsAutoString attrValue; - rv = tmpl->GetAttribute(kNameSpaceID_None, - kSubcontainmentAtom, - attrValue); - if (NS_FAILED(rv)) return rv; - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - // XXX Ick. Can we remember this somehow? - nsCOMPtr childrenAtom = NS_NewAtom(attrValue); - if (! childrenAtom) return NS_ERROR_OUT_OF_MEMORY; - - rv = EnsureElementHasGenericChild(aElement, - kNameSpaceID_XUL, - childrenAtom, - getter_AddRefs(container)); - if (NS_FAILED(rv)) return rv; - } - } - - // Otherwise, just use the element as the root. - if (! container) { - container = dont_QueryInterface(aElement); } rv = BuildContentFromTemplate(tmpl, - container, + aElement, PR_TRUE, - aValue, + aChild, aNaturalOrderPos); - + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to build content from template"); return rv; } @@ -2076,6 +1924,14 @@ RDFGenericBuilderImpl::SynchronizeUsingTemplate(nsIContent* aTemplateNode, } + +nsresult +RDFGenericBuilderImpl::RemoveWidgetItem(nsIContent* aElement, nsIRDFResource* aProperty, nsIRDFResource* aValue) +{ + return NS_OK; +} + + nsresult RDFGenericBuilderImpl::CreateContainerContents(nsIContent* aElement, nsIRDFResource* aResource) { @@ -2304,73 +2160,25 @@ RDFGenericBuilderImpl::EnsureElementHasGenericChild(nsIContent* parent, *result = element; NS_ADDREF(*result); + return NS_RDF_ELEMENT_WAS_CREATED; + } + else { + return NS_RDF_ELEMENT_WAS_THERE; } - return NS_OK; } PRBool -RDFGenericBuilderImpl::IsItemOrFolder(nsIContent* aElement) +RDFGenericBuilderImpl::IsResourceElement(nsIContent* aElement) { - // XXX It seems like this should be a pure virtual method that - // subclasses implement? - - // XXX All of the callers of this method actually only seem to - // care if the element is a "folder". - - // Returns PR_TRUE if the element is an "item" or a "folder" in - // the widget. nsresult rv; + nsAutoString str; + rv = aElement->GetAttribute(kNameSpaceID_None, kIdAtom, str); + if (NS_FAILED(rv)) return PR_FALSE; - nsCOMPtr itemAtom; - nsCOMPtr folderAtom; - if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom))) || - NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) { - return rv; - } - - // "element" must be itemAtom - nsCOMPtr tag; - if (NS_FAILED(rv = aElement->GetTag(*getter_AddRefs(tag)))) - return PR_FALSE; - - if (tag != itemAtom && tag != folderAtom) - return PR_FALSE; - - return PR_TRUE; + return (rv == NS_CONTENT_ATTR_HAS_VALUE) ? PR_TRUE : PR_FALSE; } -PRBool -RDFGenericBuilderImpl::IsWidgetInsertionRootElement(nsIContent* element) -{ - // Returns PR_TRUE if the element is the root point to insert new items. - nsresult rv; - - nsCOMPtr rootAtom; - if (NS_FAILED(rv = GetInsertionRootAtom(getter_AddRefs(rootAtom)))) { - return rv; - } - - PRInt32 nameSpaceID; - if (NS_FAILED(rv = element->GetNameSpaceID(nameSpaceID))) { - NS_ERROR("unable to get namespace ID"); - return PR_FALSE; - } - - if (nameSpaceID != kNameSpaceID_XUL) - return PR_FALSE; // not a XUL element - - nsCOMPtr elementTag; - if (NS_FAILED(rv = element->GetTag(*getter_AddRefs(elementTag)))) { - NS_ERROR("unable to get tag"); - return PR_FALSE; - } - - if (elementTag != rootAtom) - return PR_FALSE; // not the place to insert a child - - return PR_TRUE; -} PRBool RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty) @@ -2703,6 +2511,22 @@ RDFGenericBuilderImpl::GetResource(PRInt32 aNameSpaceID, nsresult RDFGenericBuilderImpl::OpenWidgetItem(nsIContent* aElement) { +#ifdef PR_LOGGING + if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { + nsresult rv; + + nsCOMPtr tag; + rv = aElement->GetTag(*getter_AddRefs(tag)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tagStr; + tag->ToString(tagStr); + + PR_LOG(gLog, PR_LOG_DEBUG, + ("rdfgeneric open-widget-item %s", + (const char*) nsCAutoString(tagStr))); + } +#endif return CreateContents(aElement); } @@ -2712,49 +2536,88 @@ RDFGenericBuilderImpl::CloseWidgetItem(nsIContent* aElement) { nsresult rv; - // Find the tag that contains the children so that we can remove all of - // the children. - nsCOMPtr parentAtom; - rv = GetItemAtomThatContainsTheChildren(getter_AddRefs(parentAtom)); +#ifdef PR_LOGGING + if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { + nsCOMPtr tag; + rv = aElement->GetTag(*getter_AddRefs(tag)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tagStr; + tag->ToString(tagStr); + + PR_LOG(gLog, PR_LOG_DEBUG, + ("rdfgeneric close-widget-item %s", + (const char*) nsCAutoString(tagStr))); + } +#endif + + // Find the tag that contains the children so that we can remove + // all of the children. + // + // XXX We make a bit of a leap here and assume that the same + // template that was used to generate _us_ was used to generate + // our _kids_. I'm sure this'll break when we do toolbars or + // something. + nsAutoString tmplID; + rv = aElement->GetAttribute(kNameSpaceID_None, kTemplateAtom, tmplID); if (NS_FAILED(rv)) return rv; - nsCOMPtr parentNode; - nsCOMPtr tag; - rv = aElement->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; // XXX fatal + if (rv != NS_CONTENT_ATTR_HAS_VALUE) + return NS_OK; - if (tag == parentAtom) { - parentNode = dont_QueryInterface(aElement); - rv = NS_OK; + nsCOMPtr xulDoc = do_QueryInterface(mDocument); + if (! xulDoc) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplDOMEle; + rv = xulDoc->GetElementById(tmplID, getter_AddRefs(tmplDOMEle)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr tmpl = do_QueryInterface(tmplDOMEle); + if (! tmpl) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplParent; + rv = tmpl->GetParent(*getter_AddRefs(tmplParent)); + if (NS_FAILED(rv)) return rv; + + NS_ASSERTION(tmplParent != nsnull, "template node has no parent"); + if (! tmplParent) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplParentTag; + rv = tmplParent->GetTag(*getter_AddRefs(tmplParentTag)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr childcontainer; + if ((tmplParentTag == kRuleAtom) || (tmplParentTag == kTemplateAtom)) { + childcontainer = dont_QueryInterface(aElement); } else { - rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, parentAtom, getter_AddRefs(parentNode)); + rv = nsRDFContentUtils::FindChildByTag(aElement, + kNameSpaceID_XUL, + tmplParentTag, + getter_AddRefs(childcontainer)); + + if (NS_FAILED(rv)) return rv; + + if (rv == NS_RDF_NO_VALUE) { + // No tag; must've already been closed + return NS_OK; + } } - if (rv == NS_RDF_NO_VALUE) { - // No tag; must've already been closed - return NS_OK; - } - - NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving parent node for removal"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr ds; - rv = mDocument->GetDocumentDataSource(getter_AddRefs(ds)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get document datasource"); - if (NS_FAILED(rv)) return rv; - PRInt32 count; - rv = parentNode->ChildCount(count); + rv = childcontainer->ChildCount(count); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get count of the parent's children"); if (NS_FAILED(rv)) return rv; while (--count >= 0) { nsCOMPtr child; - rv = parentNode->ChildAt(count, *getter_AddRefs(child)); + rv = childcontainer->ChildAt(count, *getter_AddRefs(child)); if (NS_FAILED(rv)) return rv; - rv = parentNode->RemoveChildAt(count, PR_TRUE); + rv = childcontainer->RemoveChildAt(count, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child"); do { @@ -2786,18 +2649,67 @@ RDFGenericBuilderImpl::CloseWidgetItem(nsIContent* aElement) // This is a _total_ hack to make sure that any XUL we blow away // gets rebuilt. - rv = parentNode->UnsetAttribute(kNameSpaceID_None, - kXULContentsGeneratedAtom, - PR_FALSE); + rv = childcontainer->UnsetAttribute(kNameSpaceID_None, + kXULContentsGeneratedAtom, + PR_FALSE); if (NS_FAILED(rv)) return rv; - rv = parentNode->SetAttribute(kNameSpaceID_None, - kLazyContentAtom, - "true", - PR_FALSE); + rv = childcontainer->SetAttribute(kNameSpaceID_None, + kLazyContentAtom, + "true", + PR_FALSE); if (NS_FAILED(rv)) return rv; return NS_OK; } +nsresult +RDFGenericBuilderImpl::RemoveAndRebuildGeneratedChildren(nsIContent* aElement) +{ + nsresult rv; + + PRInt32 count; + rv = aElement->ChildCount(count); + if (NS_FAILED(rv)) return rv; + + while (--count >= 0) { + nsCOMPtr child; + rv = aElement->ChildAt(count, *getter_AddRefs(child)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tmplID; + rv = child->GetAttribute(kNameSpaceID_None, kTemplateAtom, tmplID); + if (NS_FAILED(rv)) return rv; + + if (rv != NS_CONTENT_ATTR_HAS_VALUE) + continue; + + // It's a generated element. Remove it, and set its document + // to null so that it'll get knocked out of the XUL doc's + // resource-to-element map. + rv = aElement->RemoveChildAt(count, PR_TRUE); + NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child"); + + rv = child->SetDocument(nsnull, PR_TRUE); + if (NS_FAILED(rv)) return rv; + } + + // Clear the contents-generated attribute so that the next time we + // come back, we'll regenerate the kids we just killed. + rv = aElement->UnsetAttribute(kNameSpaceID_None, + kTemplateContentsGeneratedAtom, + PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = aElement->UnsetAttribute(kNameSpaceID_None, + kContainerContentsGeneratedAtom, + PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = CreateContents(aElement); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + diff --git a/rdf/content/src/nsRDFGenericBuilder.h b/rdf/content/src/nsRDFGenericBuilder.h index b44e22126501..2862f61a2ff0 100644 --- a/rdf/content/src/nsRDFGenericBuilder.h +++ b/rdf/content/src/nsRDFGenericBuilder.h @@ -51,6 +51,8 @@ public: RDFGenericBuilderImpl(); virtual ~RDFGenericBuilderImpl(); + nsresult Init(); + // nsISupports interface NS_DECL_ISUPPORTS @@ -91,30 +93,42 @@ public: // nsIDOMElementObserver interface NS_DECL_IDOMELEMENTOBSERVER + // nsITimerCallback interface + virtual void Notify(nsITimer* aTimer); + // Implementation methods nsresult - SetAllAttributesOnElement(nsIContent *aParentNode, nsIContent *aNode, nsIRDFResource *res); - - nsresult - FindTemplateForResource(nsIRDFResource *aNode, nsIContent **theTemplate); + FindTemplate(nsIContent* aElement, + nsIRDFResource* aProperty, + nsIRDFResource* aChild, + nsIContent **theTemplate); nsresult - IsTemplateRuleMatch(nsIRDFResource *aNode, nsIContent *aRule, PRBool *matchingRuleFound); + IsTemplateRuleMatch(nsIContent* aElement, + nsIRDFResource* aProperty, + nsIRDFResource* aChild, + nsIContent *aRule, + PRBool *isMatch); PRBool IsIgnoreableAttribute(PRInt32 aNameSpaceID, nsIAtom* aAtom); + nsresult + GetSubstitutionText(nsIRDFResource* aResource, + const nsString& aSubstitution, + nsString& aResult); + nsresult BuildContentFromTemplate(nsIContent *aTemplateNode, nsIContent *aRealNode, PRBool aIsUnique, - nsIRDFResource* aValue, + nsIRDFResource* aChild, PRInt32 aNaturalOrderPos); nsresult CreateWidgetItem(nsIContent* aElement, nsIRDFResource* aProperty, - nsIRDFResource* aValue, + nsIRDFResource* aChild, PRInt32 aNaturalOrderPos); enum eUpdateAction { eSet, eClear }; @@ -126,6 +140,11 @@ public: nsIRDFResource* aProperty, nsIRDFNode* aValue); + nsresult + RemoveWidgetItem(nsIContent* aElement, + nsIRDFResource* aProperty, + nsIRDFResource* aValue); + nsresult CreateContainerContents(nsIContent* aElement, nsIRDFResource* aResource); @@ -138,27 +157,6 @@ public: nsIAtom* aTag, nsIContent** aResult); - virtual nsresult - AddWidgetItem(nsIContent* aWidgetElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue, - PRInt32 naturalOrderPos) = 0; - - virtual nsresult - RemoveWidgetItem(nsIContent* aWidgetElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue) = 0; - - virtual nsresult - SetWidgetAttribute(nsIContent* aWidgetElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue) = 0; - - virtual nsresult - UnsetWidgetAttribute(nsIContent* aWidgetElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue) = 0; - virtual PRBool IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty); @@ -178,11 +176,8 @@ public: IsElementInWidget(nsIContent* aElement); PRBool - IsItemOrFolder(nsIContent* aElement); + IsResourceElement(nsIContent* aElement); - PRBool - IsWidgetInsertionRootElement(nsIContent* aElement); - nsresult GetDOMNodeResource(nsIDOMNode* aNode, nsIRDFResource** aResource); @@ -198,20 +193,8 @@ public: CloseWidgetItem(nsIContent* aElement); virtual nsresult - GetRootWidgetAtom(nsIAtom** aResult) = 0; - - virtual nsresult - GetWidgetItemAtom(nsIAtom** aResult) = 0; - - virtual nsresult - GetWidgetFolderAtom(nsIAtom** aResult) = 0; - - virtual nsresult - GetInsertionRootAtom(nsIAtom** aResult) = 0; - - virtual nsresult - GetItemAtomThatContainsTheChildren(nsIAtom** aResult) = 0; - // Well, you come up with a better name. + RemoveAndRebuildGeneratedChildren(nsIContent* aElement); + protected: nsIRDFDocument* mDocument; @@ -220,9 +203,6 @@ protected: nsITimer *mTimer; - virtual void - Notify(nsITimer *timer) = 0; - // pseudo-constants static nsrefcnt gRefCnt; static nsIRDFService* gRDFService; @@ -232,6 +212,7 @@ protected: static nsIAtom* kContainerAtom; static nsIAtom* kLazyContentAtom; static nsIAtom* kIsContainerAtom; + static nsIAtom* kIsEmptyAtom; static nsIAtom* kXULContentsGeneratedAtom; static nsIAtom* kTemplateContentsGeneratedAtom; static nsIAtom* kContainerContentsGeneratedAtom; @@ -244,9 +225,8 @@ protected: static nsIAtom* kContainmentAtom; static nsIAtom* kIgnoreAtom; static nsIAtom* kRefAtom; + static nsIAtom* kValueAtom; - static nsIAtom* kSubcontainmentAtom; - static nsIAtom* kRootcontainmentAtom; static nsIAtom* kTemplateAtom; static nsIAtom* kRuleAtom; static nsIAtom* kTextAtom; diff --git a/rdf/content/src/nsRDFMenuBuilder.cpp b/rdf/content/src/nsRDFMenuBuilder.cpp deleted file mode 100644 index 50ba406bec16..000000000000 --- a/rdf/content/src/nsRDFMenuBuilder.cpp +++ /dev/null @@ -1,447 +0,0 @@ -/* -*- 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. - */ - - -#include "nsCOMPtr.h" -#include "nsCRT.h" -#include "nsIAtom.h" -#include "nsIContent.h" -#include "nsIDOMElement.h" -#include "nsIDOMElementObserver.h" -#include "nsIDOMNode.h" -#include "nsIDOMNodeObserver.h" -#include "nsIDocument.h" -#include "nsINameSpaceManager.h" -#include "nsIRDFContentModelBuilder.h" -#include "nsIRDFCompositeDataSource.h" -#include "nsIRDFDocument.h" -#include "nsIRDFNode.h" -#include "nsIRDFObserver.h" -#include "nsIRDFService.h" -#include "nsIServiceManager.h" -#include "nsINameSpaceManager.h" -#include "nsIServiceManager.h" -#include "nsISupportsArray.h" -#include "nsIURL.h" -#include "nsLayoutCID.h" -#include "nsRDFCID.h" -#include "nsRDFContentUtils.h" -#include "nsString.h" -#include "nsXPIDLString.h" -#include "rdf.h" -#include "rdfutil.h" -#include "nsITimer.h" -#include "nsVoidArray.h" - -#include "nsRDFGenericBuilder.h" - -//////////////////////////////////////////////////////////////////////// - -static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); -static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID); -static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); -static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID); -static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID); -static NS_DEFINE_IID(kIRDFObserverIID, NS_IRDFOBSERVER_IID); -static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - -static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); -static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); - -//////////////////////////////////////////////////////////////////////// - -class RDFMenuBuilderImpl : public RDFGenericBuilderImpl -{ -public: - RDFMenuBuilderImpl(); - virtual ~RDFMenuBuilderImpl(); - - // Implementation methods - nsresult - AddWidgetItem(nsIContent* aMenuItemElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue, PRInt32 aNaturalOrderPos); - - nsresult - RemoveWidgetItem(nsIContent* aMenuItemElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue); - - nsresult - SetWidgetAttribute(nsIContent* aMenuItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue); - - nsresult - UnsetWidgetAttribute(nsIContent* aMenuItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue); - - nsresult - GetRootWidgetAtom(nsIAtom** aResult) { - NS_ADDREF(kMenuAtom); - *aResult = kMenuAtom; - return NS_OK; - } - - nsresult - GetWidgetItemAtom(nsIAtom** aResult) { - NS_ADDREF(kMenuItemAtom); - *aResult = kMenuItemAtom; - return NS_OK; - } - - nsresult - GetWidgetFolderAtom(nsIAtom** aResult) { - NS_ADDREF(kMenuAtom); - *aResult = kMenuAtom; - return NS_OK; - } - - nsresult - GetInsertionRootAtom(nsIAtom** aResult) { - NS_ADDREF(kMenuAtom); - *aResult = kMenuAtom; - return NS_OK; - } - - nsresult - GetItemAtomThatContainsTheChildren(nsIAtom** aResult) { - NS_ADDREF(kMenuAtom); - *aResult = kMenuAtom; - return NS_OK; - } - - void - Notify(nsITimer *timer); - - // pseudo-constants - static nsrefcnt gRefCnt; - - static nsIAtom* kMenuBarAtom; - static nsIAtom* kMenuAtom; - static nsIAtom* kMenuItemAtom; - static nsIAtom* kNameAtom; -}; - -//////////////////////////////////////////////////////////////////////// - -nsrefcnt RDFMenuBuilderImpl::gRefCnt = 0; - -nsIAtom* RDFMenuBuilderImpl::kMenuAtom; -nsIAtom* RDFMenuBuilderImpl::kMenuItemAtom; -nsIAtom* RDFMenuBuilderImpl::kMenuBarAtom; -nsIAtom* RDFMenuBuilderImpl::kNameAtom; - -//////////////////////////////////////////////////////////////////////// - -nsresult -NS_NewRDFMenuBuilder(nsIRDFContentModelBuilder** result) -{ - NS_PRECONDITION(result != nsnull, "null ptr"); - if (! result) - return NS_ERROR_NULL_POINTER; - - RDFMenuBuilderImpl* builder = new RDFMenuBuilderImpl(); - if (! builder) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(builder); - *result = builder; - return NS_OK; -} - - - -RDFMenuBuilderImpl::RDFMenuBuilderImpl(void) - : RDFGenericBuilderImpl() -{ - if (gRefCnt == 0) { - kMenuAtom = NS_NewAtom("menu"); - kMenuItemAtom = NS_NewAtom("menuitem"); - kMenuBarAtom = NS_NewAtom("menubar"); - kNameAtom = NS_NewAtom("name"); - } - - ++gRefCnt; -} - -RDFMenuBuilderImpl::~RDFMenuBuilderImpl(void) -{ - --gRefCnt; - if (gRefCnt == 0) { - NS_RELEASE(kMenuAtom); - NS_RELEASE(kMenuItemAtom); - NS_RELEASE(kMenuBarAtom); - NS_RELEASE(kNameAtom); - } -} - -void -RDFMenuBuilderImpl::Notify(nsITimer *timer) -{ -} - -//////////////////////////////////////////////////////////////////////// -// Implementation methods - -nsresult -RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue, - PRInt32 naturalOrderPos) -{ - nsresult rv; - - nsCOMPtr menuParent; - menuParent = dont_QueryInterface(aElement); - if (!IsItemOrFolder(aElement) && !IsWidgetInsertionRootElement(aElement)) - { - NS_ERROR("Can't add something here!"); - return NS_ERROR_UNEXPECTED; - } - - // Find out if we're a container or not. - PRBool markAsContainer = IsContainer(aElement, aValue) && !IsEmpty(aElement, aValue); - nsCOMPtr itemAtom; - - // Figure out what atom to use based on whether or not we're a container - // or leaf - if (markAsContainer) - { - // We're a menu element - GetWidgetFolderAtom(getter_AddRefs(itemAtom)); - } - else - { - // We're a menuitem element - GetWidgetItemAtom(getter_AddRefs(itemAtom)); - } - - // Create the element - nsCOMPtr menuItem; - if (NS_FAILED(rv = CreateElement(kNameSpaceID_XUL, - itemAtom, - aValue, - getter_AddRefs(menuItem)))) - return rv; - - // Add the new menu item to the element. - menuParent->AppendChildTo(menuItem, PR_TRUE); - - // Add miscellaneous attributes by iterating _all_ of the - // properties out of the resource. - nsCOMPtr arcs; - rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out"); - if (NS_FAILED(rv)) return rv; - - while (1) { - PRBool hasMore; - rv = arcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) return rv; - - if (! hasMore) - break; - - nsCOMPtr isupports; - rv = arcs->GetNext(getter_AddRefs(isupports)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr property = do_QueryInterface(isupports); - - // Ignore properties that are used to indicate containment - if (IsContainmentProperty(aElement, property)) - continue; - - // Ignore properties that we have been explicitly _asked_ to - // ignore. - if (IsIgnoredProperty(aElement, property)) - continue; - - PRInt32 nameSpaceID; - nsCOMPtr tag; - if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) { - NS_ERROR("unable to split property"); - return rv; - } - - nsCOMPtr value; - if (NS_FAILED(rv = mDB->GetTarget(aValue, property, PR_TRUE, getter_AddRefs(value)))) { - NS_ERROR("unable to get target"); - return rv; - } - - // ArcsLabelsOut is allowed to be promiscuous, giving back - // potential arc labels that may not currently have a value. - if (rv == NS_RDF_NO_VALUE) - continue; - - nsAutoString s; - rv = nsRDFContentUtils::GetTextForNode(value, s); - if (NS_FAILED(rv)) return rv; - - rv = menuItem->SetAttribute(nameSpaceID, tag, s, PR_FALSE); - if (NS_FAILED(rv)) return rv; - - // XXX This should go away and just be determined dynamically; - // e.g., by setting an attribute on the "xul:menu" tag - nsAutoString tagStr; - tag->ToString(tagStr); - if (tagStr.EqualsIgnoreCase("name")) { - // Hack to ensure that we add in a lowercase name attribute also. - menuItem->SetAttribute(kNameSpaceID_None, kNameAtom, s, PR_FALSE); - } - } - - // XXX: This is a hack until the menu folks get their act together. - menuItem->SetAttribute(kNameSpaceID_None, kOpenAtom, "true", PR_FALSE); - - // Finally, mark this as a "container" so that we know to - // recursively generate kids if they're asked for. - if (markAsContainer == PR_TRUE) - { - // Finally, mark this as a "container" so that we know to - // recursively generate kids if they're asked for. - if (NS_FAILED(rv = menuItem->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE))) - return rv; - } - - return NS_OK; -} - - -nsresult -RDFMenuBuilderImpl::RemoveWidgetItem(nsIContent* aMenuItemElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue) -{ - nsresult rv; - - // Find the doomed kid and blow it away. - PRInt32 count; - if (NS_FAILED(rv = aMenuItemElement->ChildCount(count))) - return rv; - - for (PRInt32 i = 0; i < count; ++i) { - nsCOMPtr kid; - rv = aMenuItemElement->ChildAt(i, *getter_AddRefs(kid)); - if (NS_FAILED(rv)) return rv; - - // Make sure it's a or - PRInt32 nameSpaceID; - rv = kid->GetNameSpaceID(nameSpaceID); - if (NS_FAILED(rv)) return rv; - - if (nameSpaceID != kNameSpaceID_XUL) - continue; // wrong namespace - - nsCOMPtr tag; - rv = kid->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - if ((tag.get() != kMenuItemAtom) && - (tag.get() != kMenuAtom)) - continue; // wrong tag - - // 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 resource; - rv = nsRDFContentUtils::GetElementRefResource(kid, getter_AddRefs(resource)); - NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving resource"); - if(NS_FAILED(rv)) return rv; - - if (resource.get() != aValue) - continue; // not the resource we want - - // Fount it! Now kill it. - rv = aMenuItemElement->RemoveChildAt(i, PR_TRUE); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove xul:menu[item] from xul:menu"); - if (NS_FAILED(rv)) return rv; - - return NS_OK; - } - - // XXX make this a warning - NS_WARNING("unable to find child to remove"); - return NS_OK; -} - -nsresult -RDFMenuBuilderImpl::SetWidgetAttribute(nsIContent* aMenuItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue) -{ - nsresult rv; - - PRInt32 nameSpaceID; - nsCOMPtr tag; - rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - nsAutoString value; - rv = nsRDFContentUtils::GetTextForNode(aValue, value); - if (NS_FAILED(rv)) return rv; - - rv = aMenuItemElement->SetAttribute(nameSpaceID, tag, value, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - // XXX This should go away and just be determined dynamically; - // e.g., by setting an attribute on the "xul:menu" tag. - nsAutoString tagStr; - tag->ToString(tagStr); - if (tagStr.EqualsIgnoreCase("name")) { - // Hack to ensure that we add in a lowercase name attribute also. - aMenuItemElement->SetAttribute(kNameSpaceID_None, kNameAtom, value, PR_TRUE); - } - - return NS_OK; -} - -nsresult -RDFMenuBuilderImpl::UnsetWidgetAttribute(nsIContent* aMenuItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue) -{ - nsresult rv; - - PRInt32 nameSpaceID; - nsCOMPtr tag; - rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - rv = aMenuItemElement->UnsetAttribute(nameSpaceID, tag, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - // XXX This should go away and just be determined dynamically; - // e.g., by setting an attribute on the "xul:menu" tag. - nsAutoString tagStr; - tag->ToString(tagStr); - if (tagStr.EqualsIgnoreCase("name")) { - // Hack to ensure that we add in a lowercase name attribute also. - aMenuItemElement->UnsetAttribute(kNameSpaceID_None, kNameAtom, PR_TRUE); - } - - return NS_OK; -} - diff --git a/rdf/content/src/nsRDFToolbarBuilder.cpp b/rdf/content/src/nsRDFToolbarBuilder.cpp deleted file mode 100644 index 45c7e540e51d..000000000000 --- a/rdf/content/src/nsRDFToolbarBuilder.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/* -*- 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. - */ - -/* XXX: Teach this how to make toolboxes as well as toolbars. */ - -#include "nsCOMPtr.h" -#include "nsCRT.h" -#include "nsIAtom.h" -#include "nsIContent.h" -#include "nsIDOMElement.h" -#include "nsIDOMElementObserver.h" -#include "nsIDOMNode.h" -#include "nsIDOMNodeObserver.h" -#include "nsIDocument.h" -#include "nsINameSpaceManager.h" -#include "nsIRDFContentModelBuilder.h" -#include "nsIRDFCompositeDataSource.h" -#include "nsIRDFDocument.h" -#include "nsIRDFNode.h" -#include "nsIRDFObserver.h" -#include "nsIRDFService.h" -#include "nsIServiceManager.h" -#include "nsINameSpaceManager.h" -#include "nsIServiceManager.h" -#include "nsISupportsArray.h" -#include "nsIURL.h" -#include "nsLayoutCID.h" -#include "nsRDFCID.h" -#include "nsRDFContentUtils.h" -#include "nsString.h" -#include "nsXPIDLString.h" -#include "rdf.h" -#include "rdfutil.h" - -#include "nsVoidArray.h" - -#include "nsRDFGenericBuilder.h" - -//////////////////////////////////////////////////////////////////////// - -static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); -static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID); -static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); -static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID); -static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID); -static NS_DEFINE_IID(kIRDFObserverIID, NS_IRDFOBSERVER_IID); -static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - -static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); -static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); - -//////////////////////////////////////////////////////////////////////// - -class RDFToolbarBuilderImpl : public RDFGenericBuilderImpl -{ -public: - RDFToolbarBuilderImpl(); - virtual ~RDFToolbarBuilderImpl(); - - // Implementation methods - nsresult - AddWidgetItem(nsIContent* aToolbarItemElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue, PRInt32 aNaturalOrderPos); - - nsresult - RemoveWidgetItem(nsIContent* aTreeItemElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue); - - nsresult - SetWidgetAttribute(nsIContent* aToolbarItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue); - - nsresult - UnsetWidgetAttribute(nsIContent* aToolbarItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue); - - nsresult - GetRootWidgetAtom(nsIAtom** aResult) { - NS_ADDREF(kToolbarAtom); - *aResult = kToolbarAtom; - return NS_OK; - } - - nsresult - GetWidgetItemAtom(nsIAtom** aResult) { - NS_ADDREF(kTitledButtonAtom); - *aResult = kTitledButtonAtom; - return NS_OK; - } - - nsresult - GetWidgetFolderAtom(nsIAtom** aResult) { - NS_ADDREF(kTitledButtonAtom); - *aResult = kTitledButtonAtom; - return NS_OK; - } - - nsresult - GetInsertionRootAtom(nsIAtom** aResult) { - NS_ADDREF(kToolbarAtom); - *aResult = kToolbarAtom; - return NS_OK; - } - - nsresult - GetItemAtomThatContainsTheChildren(nsIAtom** aResult) { - NS_ADDREF(kTitledButtonAtom); - *aResult = kTitledButtonAtom; - return NS_OK; - } - - void - Notify(nsITimer *timer); - - // pseudo-constants - static nsrefcnt gRefCnt; - - static nsIAtom* kToolbarAtom; - static nsIAtom* kTitledButtonAtom; - static nsIAtom* kAlignAtom; - static nsIAtom* kSrcAtom; - static nsIAtom* kValueAtom; -}; - -//////////////////////////////////////////////////////////////////////// - -nsrefcnt RDFToolbarBuilderImpl::gRefCnt = 0; - -nsIAtom* RDFToolbarBuilderImpl::kToolbarAtom; -nsIAtom* RDFToolbarBuilderImpl::kTitledButtonAtom; -nsIAtom* RDFToolbarBuilderImpl::kAlignAtom; -nsIAtom* RDFToolbarBuilderImpl::kSrcAtom; -nsIAtom* RDFToolbarBuilderImpl::kValueAtom; - -//////////////////////////////////////////////////////////////////////// - -nsresult -NS_NewRDFToolbarBuilder(nsIRDFContentModelBuilder** result) -{ - NS_PRECONDITION(result != nsnull, "null ptr"); - if (! result) - return NS_ERROR_NULL_POINTER; - - RDFToolbarBuilderImpl* builder = new RDFToolbarBuilderImpl(); - if (! builder) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(builder); - *result = builder; - return NS_OK; -} - - - -RDFToolbarBuilderImpl::RDFToolbarBuilderImpl(void) - : RDFGenericBuilderImpl() -{ - if (gRefCnt == 0) { - kToolbarAtom = NS_NewAtom("toolbar"); - kTitledButtonAtom = NS_NewAtom("titledbutton"); - kAlignAtom = NS_NewAtom("align"); - kSrcAtom = NS_NewAtom("src"); - kValueAtom = NS_NewAtom("value"); - } - - ++gRefCnt; -} - -RDFToolbarBuilderImpl::~RDFToolbarBuilderImpl(void) -{ - --gRefCnt; - if (gRefCnt == 0) { - - NS_RELEASE(kToolbarAtom); - NS_RELEASE(kTitledButtonAtom); - NS_RELEASE(kAlignAtom); - NS_RELEASE(kSrcAtom); - NS_RELEASE(kValueAtom); - } -} - -void -RDFToolbarBuilderImpl::Notify(nsITimer *timer) -{ -} - -//////////////////////////////////////////////////////////////////////// -// Implementation methods - -nsresult -RDFToolbarBuilderImpl::AddWidgetItem(nsIContent* aElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue, - PRInt32 naturalOrderPos) -{ - nsresult rv; - - nsCOMPtr toolbarParent; - toolbarParent = dont_QueryInterface(aElement); - if (!IsItemOrFolder(aElement) && !IsWidgetInsertionRootElement(aElement)) - { - NS_ERROR("Can't add something here!"); - return NS_ERROR_UNEXPECTED; - } - - PRBool markAsContainer = IsContainer(aElement, aValue); - - // Create the element - nsCOMPtr toolbarItem; - if (NS_FAILED(rv = CreateElement(kNameSpaceID_XUL, - kTitledButtonAtom, - aValue, - getter_AddRefs(toolbarItem)))) - return rv; - - // Add the to the element. - toolbarParent->AppendChildTo(toolbarItem, PR_TRUE); - - // Add miscellaneous attributes by iterating _all_ of the - // properties out of the resource. - - // XXX Per Bug 3367, this'll have to be fixed. - nsCOMPtr arcs; - rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out"); - if (NS_FAILED(rv)) return rv; - - while (1) { - PRBool hasMore; - rv = arcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) return rv; - - if (! hasMore) - break; - - nsCOMPtr isupports; - rv = arcs->GetNext(getter_AddRefs(isupports)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr property = do_QueryInterface(isupports); - - // Ignore properties that are used to indicate containment - if (IsContainmentProperty(aElement, property)) - continue; - - // Ignore properties that we have been explicitly _asked_ to - // ignore. - if (IsIgnoredProperty(aElement, property)) - continue; - - PRInt32 nameSpaceID; - nsCOMPtr tag; - if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) { - NS_ERROR("unable to split property"); - return rv; - } - - nsCOMPtr value; - if (NS_FAILED(rv = mDB->GetTarget(aValue, property, PR_TRUE, getter_AddRefs(value)))) { - NS_ERROR("unable to get target"); - return rv; - } - - // ArcsLabelsOut is allowed to be promiscuous, giving back - // potential arc labels that may not currently have a value. - if (rv == NS_RDF_NO_VALUE) - continue; - - nsAutoString s; - rv = nsRDFContentUtils::GetTextForNode(value, s); - if (NS_FAILED(rv)) return rv; - - toolbarItem->SetAttribute(nameSpaceID, tag, s, PR_FALSE); - - nsString tagStr; - tag->ToString(tagStr); - if (tagStr.EqualsIgnoreCase("name")) { - // Hack to ensure that we add in a lowercase value attribute also. - toolbarItem->SetAttribute(kNameSpaceID_None, kValueAtom, s, PR_FALSE); - } - - // XXX (Dave) I want these to go away. Style sheets should be used for these. - toolbarItem->SetAttribute(kNameSpaceID_None, kAlignAtom, "right", PR_FALSE); - toolbarItem->SetAttribute(kNameSpaceID_None, kSrcAtom, "resource:/res/toolbar/TB_Location.gif", PR_FALSE); - } - - // Finally, mark this as a "container" so that we know to - // recursively generate kids if they're asked for. - if (markAsContainer == PR_TRUE) - { - // Finally, mark this as a "container" so that we know to - // recursively generate kids if they're asked for. - if (NS_FAILED(rv = toolbarItem->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE))) - return rv; - } - - return NS_OK; -} - - - -nsresult -RDFToolbarBuilderImpl::RemoveWidgetItem(nsIContent* aToolbarItemElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue) -{ - nsresult rv; - - // Find the doomed kid and blow it away. - PRInt32 count; - if (NS_FAILED(rv = aToolbarItemElement->ChildCount(count))) - return rv; - - for (PRInt32 i = 0; i < count; ++i) { - nsCOMPtr kid; - rv = aToolbarItemElement->ChildAt(i, *getter_AddRefs(kid)); - if (NS_FAILED(rv)) return rv; - - // Make sure it's a or - PRInt32 nameSpaceID; - rv = kid->GetNameSpaceID(nameSpaceID); - if (NS_FAILED(rv)) return rv; - - if (nameSpaceID != kNameSpaceID_XUL) - continue; // wrong namespace - - nsCOMPtr tag; - rv = kid->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - if ((tag.get() != kTitledButtonAtom) && - (tag.get() != kToolbarAtom)) - continue; // wrong tag - - // 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 resource; - rv = nsRDFContentUtils::GetElementRefResource(kid, getter_AddRefs(resource)); - NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving resource"); - if(NS_FAILED(rv)) return rv; - - if (resource.get() != aValue) - continue; // not the resource we want - - // Fount it! Now kill it. - rv = aToolbarItemElement->RemoveChildAt(i, PR_TRUE); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove xul:toolbar/titledbutton from xul:toolbar"); - if (NS_FAILED(rv)) return rv; - - return NS_OK; - } - - // XXX make this a warning - NS_WARNING("unable to find child to remove"); - return NS_OK; -} - - -nsresult -RDFToolbarBuilderImpl::SetWidgetAttribute(nsIContent* aToolbarItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue) -{ - nsresult rv; - - PRInt32 nameSpaceID; - nsCOMPtr tag; - rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - nsAutoString value; - rv = nsRDFContentUtils::GetTextForNode(aValue, value); - if (NS_FAILED(rv)) return rv; - - rv = aToolbarItemElement->SetAttribute(nameSpaceID, tag, value, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - // XXX This should go away and just be determined dynamically; - // e.g., by setting an attribute on the "xul:menu" tag. - nsAutoString tagStr; - tag->ToString(tagStr); - if (tagStr.EqualsIgnoreCase("name")) { - // Hack to ensure that we add in a lowercase name attribute also. - aToolbarItemElement->SetAttribute(kNameSpaceID_None, kValueAtom, value, PR_TRUE); - } - - return NS_OK; -} - -nsresult -RDFToolbarBuilderImpl::UnsetWidgetAttribute(nsIContent* aToolbarItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue) -{ - nsresult rv; - - PRInt32 nameSpaceID; - nsCOMPtr tag; - rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - rv = aToolbarItemElement->UnsetAttribute(nameSpaceID, tag, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - // XXX This should go away and just be determined dynamically; - // e.g., by setting an attribute on the "xul:menu" tag. - nsAutoString tagStr; - tag->ToString(tagStr); - if (tagStr.EqualsIgnoreCase("name")) { - // Hack to ensure that we add in a lowercase name attribute also. - aToolbarItemElement->UnsetAttribute(kNameSpaceID_None, kValueAtom, PR_TRUE); - } - - return NS_OK; -} - - diff --git a/rdf/content/src/nsRDFTreeBuilder.cpp b/rdf/content/src/nsRDFTreeBuilder.cpp deleted file mode 100644 index 98d258fa4244..000000000000 --- a/rdf/content/src/nsRDFTreeBuilder.cpp +++ /dev/null @@ -1,1796 +0,0 @@ -/* -*- 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 nsIRDFDocument implementation that builds a tree widget XUL - content model that is to be used with a tree control. - - TO DO - - 1) We have a serious problem if all the columns aren't created by - the time that we start inserting rows into the table. Need to fix - this so that columns can be dynamically added and removed (we - need to do this anyway to handle column re-ordering or - manipulation via DOM calls). - - */ - -#include "nsCOMPtr.h" -#include "nsCRT.h" -#include "nsIAtom.h" -#include "nsIContent.h" -#include "nsIDOMElement.h" -#include "nsIDOMElementObserver.h" -#include "nsIDOMNode.h" -#include "nsIDOMNodeObserver.h" -#include "nsIDOMXULTreeElement.h" -#include "nsIDocument.h" -#include "nsINameSpaceManager.h" -#include "nsIRDFContainer.h" -#include "nsIRDFContentModelBuilder.h" -#include "nsIRDFCompositeDataSource.h" -#include "nsIRDFDocument.h" -#include "nsIRDFNode.h" -#include "nsIRDFObserver.h" -#include "nsIRDFService.h" -#include "nsIServiceManager.h" -#include "nsINameSpaceManager.h" -#include "nsIServiceManager.h" -#include "nsISupportsArray.h" -#include "nsITextContent.h" -#include "nsIURL.h" -#include "nsLayoutCID.h" -#include "nsRDFCID.h" -#include "nsRDFContentUtils.h" -#include "nsString.h" -#include "nsXPIDLString.h" -#include "rdf.h" -#include "rdfutil.h" -#include "nsITimer.h" -#include "nsVoidArray.h" -#include "nsQuickSort.h" -#include "nsRDFGenericBuilder.h" -#include "prtime.h" -#include "prlog.h" -#include "nsIXULSortService.h" - -//////////////////////////////////////////////////////////////////////// - -DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child); -DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns); -DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Column); -DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder); -DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Title); - -DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, child); - -//////////////////////////////////////////////////////////////////////// - -static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); -static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID); -static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); -static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID); -static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID); -static NS_DEFINE_IID(kIRDFObserverIID, NS_IRDFOBSERVER_IID); -static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - -static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); -static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); - -static NS_DEFINE_IID(kIDomXulElementIID, NS_IDOMXULELEMENT_IID); - -static NS_DEFINE_IID(kXULSortServiceCID, NS_XULSORTSERVICE_CID); -static NS_DEFINE_IID(kIXULSortServiceIID, NS_IXULSORTSERVICE_IID); - -#define BUILDER_NOTIFY_MINIMUM_TIMEOUT 5000L - -#ifdef PR_LOGGING -static PRLogModuleInfo* gLog; -#endif - -//////////////////////////////////////////////////////////////////////// - -class RDFTreeBuilderImpl : public RDFGenericBuilderImpl -{ -public: - RDFTreeBuilderImpl(); - virtual ~RDFTreeBuilderImpl(); - - // nsIRDFContentModelBuilder interface - NS_IMETHOD SetDataBase(nsIRDFCompositeDataSource* aDataBase); - - // nsIDOMNodeObserver interface - NS_IMETHOD OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild); - NS_IMETHOD OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild); - - // Implementation methods - nsresult - AddWidgetItem(nsIContent* aTreeItemElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue, PRInt32 aNaturalOrderPos); - - nsresult - RemoveWidgetItem(nsIContent* aElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue); - - nsresult - SetWidgetAttribute(nsIContent* aTreeItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue); - - nsresult - UnsetWidgetAttribute(nsIContent* aTreeItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue); - - nsresult - FindTextElement(nsIContent* aElement, - nsITextContent** aResult); - - nsresult - EnsureCell(nsIContent* aTreeItemElement, PRInt32 aIndex, nsIContent** aCellElement); - - nsresult - CreateTreeItemCells(nsIContent* aTreeItemElement); - - nsresult - FindTreeCellForProperty(nsIContent* aTreeRowElement, - nsIRDFResource* aProperty, - nsIContent** aTreeCell); - - nsresult - GetColumnForProperty(nsIContent* aTreeElement, - nsIRDFResource* aProperty, - PRInt32* aIndex); - - nsresult - GetRootWidgetAtom(nsIAtom** aResult) { - NS_ADDREF(kTreeAtom); - *aResult = kTreeAtom; - return NS_OK; - } - - nsresult - GetWidgetItemAtom(nsIAtom** aResult) { - NS_ADDREF(kTreeItemAtom); - *aResult = kTreeItemAtom; - return NS_OK; - } - - nsresult - GetWidgetFolderAtom(nsIAtom** aResult) { - NS_ADDREF(kTreeItemAtom); - *aResult = kTreeItemAtom; - return NS_OK; - } - - nsresult - GetInsertionRootAtom(nsIAtom** aResult) { - NS_ADDREF(kTreeChildrenAtom); - *aResult = kTreeChildrenAtom; - return NS_OK; - } - - nsresult - GetItemAtomThatContainsTheChildren(nsIAtom** aResult) { - NS_ADDREF(kTreeChildrenAtom); - *aResult = kTreeChildrenAtom; - return NS_OK; - } - - nsresult - UpdateContainer(nsIContent *container); - - nsresult - CheckRDFGraphForUpdates(nsIContent *container); - - void - Notify(nsITimer *timer); - - // pseudo-constants - static nsrefcnt gRefCnt; - - static nsIAtom* kPropertyAtom; - static nsIAtom* kTreeAtom; - static nsIAtom* kTreeRowAtom; - static nsIAtom* kTreeCellAtom; - static nsIAtom* kTreeChildrenAtom; - static nsIAtom* kTreeColAtom; - static nsIAtom* kTreeHeadAtom; - static nsIAtom* kTreeIconAtom; - static nsIAtom* kTreeIndentationAtom; - static nsIAtom* kTreeItemAtom; - static nsIAtom* kTitledButtonAtom; - static nsIAtom* kPulseAtom; - static nsIAtom* kLastPulseAtom; - static nsIAtom* kOpenAtom; - - static nsIXULSortService *XULSortService; -}; - -//////////////////////////////////////////////////////////////////////// - -nsrefcnt RDFTreeBuilderImpl::gRefCnt = 0; -nsIXULSortService* RDFTreeBuilderImpl::XULSortService = nsnull; - -nsIAtom* RDFTreeBuilderImpl::kPropertyAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeRowAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeCellAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeChildrenAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeColAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeHeadAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeIconAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeIndentationAtom; -nsIAtom* RDFTreeBuilderImpl::kTreeItemAtom; -nsIAtom* RDFTreeBuilderImpl::kTitledButtonAtom; -nsIAtom* RDFTreeBuilderImpl::kPulseAtom; -nsIAtom* RDFTreeBuilderImpl::kLastPulseAtom; -nsIAtom* RDFTreeBuilderImpl::kOpenAtom; - -//////////////////////////////////////////////////////////////////////// - -nsresult -NS_NewRDFTreeBuilder(nsIRDFContentModelBuilder** result) -{ - NS_PRECONDITION(result != nsnull, "null ptr"); - if (! result) - return NS_ERROR_NULL_POINTER; - - RDFTreeBuilderImpl* builder = new RDFTreeBuilderImpl(); - if (! builder) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(builder); - *result = builder; - return NS_OK; -} - - - -RDFTreeBuilderImpl::RDFTreeBuilderImpl(void) - : RDFGenericBuilderImpl() -{ - if (gRefCnt == 0) { - kPropertyAtom = NS_NewAtom("property"); - kTreeAtom = NS_NewAtom("tree"); - kTreeRowAtom = NS_NewAtom("treerow"); - kTreeCellAtom = NS_NewAtom("treecell"); - kTreeChildrenAtom = NS_NewAtom("treechildren"); - kTreeColAtom = NS_NewAtom("treecol"); - kTreeHeadAtom = NS_NewAtom("treehead"); - kTreeIconAtom = NS_NewAtom("treeicon"); - kTreeIndentationAtom = NS_NewAtom("treeindentation"); - kTreeItemAtom = NS_NewAtom("treeitem"); - kTitledButtonAtom = NS_NewAtom("titledbutton"); - kPulseAtom = NS_NewAtom("pulse"); - kLastPulseAtom = NS_NewAtom("lastPulse"); - kOpenAtom = NS_NewAtom("open"); - - nsresult rv = nsServiceManager::GetService(kXULSortServiceCID, - kIXULSortServiceIID, (nsISupports**) &XULSortService); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get XUL Sort service"); - } - ++gRefCnt; - -#ifdef PR_LOGGING - if (! gLog) - gLog = PR_NewLogModule("nsRDFTreeBuilder"); -#endif -} - -RDFTreeBuilderImpl::~RDFTreeBuilderImpl(void) -{ - --gRefCnt; - if (gRefCnt == 0) { - NS_RELEASE(kPropertyAtom); - NS_RELEASE(kTreeAtom); - NS_RELEASE(kTreeRowAtom); - NS_RELEASE(kTreeCellAtom); - NS_RELEASE(kTreeChildrenAtom); - NS_RELEASE(kTreeColAtom); - NS_RELEASE(kTreeHeadAtom); - NS_RELEASE(kTreeIconAtom); - NS_RELEASE(kTreeIndentationAtom); - NS_RELEASE(kTreeItemAtom); - NS_RELEASE(kTitledButtonAtom); - NS_RELEASE(kPulseAtom); - NS_RELEASE(kLastPulseAtom); - NS_RELEASE(kOpenAtom); - - nsServiceManager::ReleaseService(kXULSortServiceCID, XULSortService); - XULSortService = nsnull; - } -} - -nsresult -RDFTreeBuilderImpl::UpdateContainer(nsIContent *container) -{ - PRInt32 childIndex = 0, numChildren = 0, numGrandChildren, grandChildrenIndex, nameSpaceID; - nsCOMPtr child, grandChild; - nsresult rv; - - if (NS_FAILED(rv = container->ChildCount(numChildren))) return(rv); - - for (childIndex=0; childIndexChildAt(childIndex, *getter_AddRefs(child)))) break; - if (NS_FAILED(rv = child->GetNameSpaceID(nameSpaceID))) break; - if (nameSpaceID == kNameSpaceID_XUL) - { - nsCOMPtr tag; - if (NS_FAILED(rv = child->GetTag(*getter_AddRefs(tag)))) return rv; - if (tag.get() == kTreeItemAtom) - { - nsIDOMXULElement *dom; - if (NS_SUCCEEDED(rv = child->QueryInterface(kIDomXulElementIID, (void **)&dom))) - { - nsAutoString open(""); - if (NS_SUCCEEDED(rv = child->GetAttribute(kNameSpaceID_None, kOpenAtom, open))) - { - if (open.EqualsIgnoreCase("true")) - { - nsAutoString pulse(""); - if (NS_SUCCEEDED(rv = child->GetAttribute(kNameSpaceID_None, kPulseAtom, pulse))) - { - if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (pulse.Length() > 0)) - { - PRInt32 errorCode; - PRInt32 pulseInterval = pulse.ToInteger(&errorCode); - if ((!errorCode) && (pulseInterval > 0)) - { - nsAutoString lastPulse(""); - PRInt32 lastPulseTime = 0; - if (NS_SUCCEEDED(rv = child->GetAttribute(kNameSpaceID_None, kLastPulseAtom, lastPulse))) - { - if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (lastPulse.Length() > 0)) - { - lastPulseTime = lastPulse.ToInteger(&errorCode); - if (errorCode) lastPulseTime = 0; - } - } - PRInt32 now; - PRTime prNow = PR_Now(), oneMillion, temp; - LL_I2L(oneMillion, PR_USEC_PER_SEC); - LL_DIV(temp, prNow, oneMillion); - LL_L2I(now, temp); - if ((lastPulseTime == 0L) || ((now - lastPulseTime) > pulseInterval)) - { - lastPulse.SetLength(0); - lastPulse.Append(now, 10); - // note: don't check for errors when unsetting the attribute in case this is the 1st time - child->UnsetAttribute(kNameSpaceID_None, kLastPulseAtom, PR_FALSE); - if (NS_SUCCEEDED(rv = child->SetAttribute(kNameSpaceID_None, kLastPulseAtom, lastPulse, PR_FALSE))) - { -#ifdef PR_LOGGING - if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { - nsIRDFResource *res; - if (NS_SUCCEEDED(rv = dom->GetResource(&res))) - { - nsXPIDLCString uri; - res->GetValue( getter_Copies(uri) ); - const char *url = uri; - PR_LOG(gLog, PR_LOG_DEBUG, - (" URL '%s' gets a pulse now (at %lu)\n", url, now)); - NS_RELEASE(res); - } - } -#endif - CheckRDFGraphForUpdates(child); - } - } - } - } - } - - // recurse on grandchildren - if (NS_FAILED(rv = child->ChildCount(numGrandChildren))) continue; - for (grandChildrenIndex=0; grandChildrenIndexChildAt(grandChildrenIndex, *getter_AddRefs(grandChild)))) - continue; - if (NS_FAILED(rv = grandChild->GetNameSpaceID(nameSpaceID))) continue; - if (nameSpaceID == kNameSpaceID_XUL) - { - nsCOMPtr grandChildTag; - if (NS_FAILED(rv = grandChild->GetTag(*getter_AddRefs(grandChildTag)))) - continue; - if (grandChildTag.get() == kTreeChildrenAtom) - { - rv = UpdateContainer(grandChild); - } - } - } - } - } - NS_RELEASE(dom); - } - } - } - } - return(NS_OK); -} - -int openSortCallback(const void *data1, const void *data2, void *sortData); - -nsresult -RDFTreeBuilderImpl::CheckRDFGraphForUpdates(nsIContent *container) -{ - nsresult rv = NS_OK; - - nsCOMPtr domElement( do_QueryInterface(container) ); - NS_ASSERTION(domElement, "not a XULTreeElement"); - if (!domElement) return(NS_ERROR_UNEXPECTED); - - // get composite db for tree - if (!mRoot) return(NS_ERROR_UNEXPECTED); - nsCOMPtr domXulTree( do_QueryInterface(mRoot) ); - NS_ASSERTION(domXulTree, "not a nsIDOMXULTreeElement"); - if (!domXulTree) return(NS_ERROR_UNEXPECTED); - - nsCOMPtr db; - if (NS_FAILED(rv = domXulTree->GetDatabase(getter_AddRefs(db)))) - { - return(rv); - } - - nsCOMPtr childArray; - rv = NS_NewISupportsArray(getter_AddRefs(childArray)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr res; - if (NS_SUCCEEDED(rv = domElement->GetResource(getter_AddRefs(res)))) - { - // XXX Per Bug 3367, this'll have to be fixed. - nsCOMPtr arcs; - rv = mDB->ArcLabelsOut(res, getter_AddRefs(arcs)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out"); - if (NS_FAILED(rv)) return rv; - - while (1) { - PRBool hasMore; - rv = arcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) - return rv; - - if (! hasMore) - break; - - nsCOMPtr isupports; - rv = arcs->GetNext(getter_AddRefs(isupports)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value"); - if(NS_FAILED(rv)) return rv; - - nsCOMPtr property = do_QueryInterface(isupports); - - if (!IsContainmentProperty(container, property)) continue; - - // XXX this seems gratuitous? why is it here? - PRInt32 nameSpaceID; - nsCOMPtr tag; - if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) - { - NS_ERROR("unable to split property"); - return(rv); - } - - nsCOMPtr targets; - rv = db->GetTargets(res, property, PR_TRUE, getter_AddRefs(targets)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get targets for property"); - if (NS_FAILED(rv)) return rv; - - while (1) { - PRBool hasMore; - rv = targets->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) return rv; - - if (! hasMore) - break; - - nsCOMPtr isupports; - rv = targets->GetNext(getter_AddRefs(isupports)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr valueResource = do_QueryInterface(isupports); - if (valueResource) { - // Note: hack, storing value then property in array - childArray->AppendElement(valueResource.get()); - childArray->AppendElement(property.get()); - } - } - } - } - - PRUint32 cnt = 0; - rv = childArray->Count(&cnt); - NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed"); - PRInt32 numElements = cnt; - if (numElements > 0) - { - nsIRDFResource ** flatArray = new nsIRDFResource*[numElements]; - if (flatArray) - { - // flatten array of resources, sort them, then add/remove as necessary - PRInt32 loop; - for (loop=0; loopElementAt(loop); - } -// nsQuickSort((void *)flatArray, numElements, sizeof(nsIRDFNode *), -// openSortCallback, (void *)sortInfo); - - // first, remove any nodes that are stale - nsCOMPtr child; - if (NS_SUCCEEDED(rv = nsRDFContentUtils::FindChildByTag(container, - kNameSpaceID_XUL, kTreeChildrenAtom, getter_AddRefs(child))) - && (rv != NS_RDF_NO_VALUE) && (child)) - { - // note: enumerate backwards so that indexing is easy - PRInt32 numGrandChildren; - if (NS_FAILED(rv = child->ChildCount(numGrandChildren))) numGrandChildren = 0; - nsCOMPtr grandChild; - for (PRInt32 grandchildIndex=numGrandChildren-1; grandchildIndex >= 0; grandchildIndex--) - { - if (NS_FAILED(rv = child->ChildAt(grandchildIndex, *getter_AddRefs(grandChild)))) break; - PRInt32 nameSpaceID; - if (NS_FAILED(rv = grandChild->GetNameSpaceID(nameSpaceID))) break; - if (nameSpaceID == kNameSpaceID_XUL) - { - nsCOMPtr aRes; - PRBool removeNode = PR_TRUE; - if (NS_SUCCEEDED(rv = nsRDFContentUtils::GetElementRefResource(grandChild, getter_AddRefs(aRes)))) - { - PRInt32 innerLoop; - for (innerLoop=0; innerLoop < numElements; innerLoop+=2) - { - PRBool equals = PR_FALSE; - if (NS_SUCCEEDED(rv = aRes.get()->EqualsNode(flatArray[innerLoop], &equals))) - { - if (equals == PR_TRUE) - { - removeNode = PR_FALSE; - break; - } - } - } - if (removeNode == PR_TRUE) - { - child->RemoveChildAt(grandchildIndex, PR_TRUE); - } - } - } - } - } - - // second, add any nodes that are new - for (loop=0; loopChildCount(numGrandChildren))) numGrandChildren = 0; - nsCOMPtr grandChild; - for (PRInt32 grandchildIndex=0; grandchildIndexChildAt(grandchildIndex, *getter_AddRefs(grandChild)))) break; - PRInt32 nameSpaceID; - if (NS_FAILED(rv = grandChild->GetNameSpaceID(nameSpaceID))) break; - if (nameSpaceID == kNameSpaceID_XUL) - { - nsCOMPtr aRes; - if (NS_SUCCEEDED(rv = nsRDFContentUtils::GetElementRefResource(grandChild, getter_AddRefs(aRes)))) - { - PRBool equals = PR_FALSE; - if (NS_SUCCEEDED(rv = theRes->EqualsNode(aRes, &equals))) - { - if (equals == PR_TRUE) - { - nodeFound = PR_TRUE; - break; - } - } - } - } - } - if (nodeFound == PR_FALSE) - { - AddWidgetItem(container, flatArray[loop+1], flatArray[loop], 0); - } - } - } - - delete [] flatArray; - flatArray = nsnull; - } - } - rv = childArray->Count(&cnt); - if (NS_FAILED(rv)) return rv; - for (int i = cnt - 1; i >= 0; i--) - { - childArray->RemoveElementAt(i); - } - return(NS_OK); -} - -void -RDFTreeBuilderImpl::Notify(nsITimer *timer) -{ - if (!mTimer) return; - - if (mRoot) - { - nsresult rv; -#ifdef PR_LOGGING - if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { - nsIDOMXULElement *domElement; - - if (NS_SUCCEEDED(rv = mRoot->QueryInterface(kIDomXulElementIID, (void **)&domElement))) - { - nsIRDFResource *res; - - if (NS_SUCCEEDED(rv = domElement->GetResource(&res))) - { - nsXPIDLCString uri; - res->GetValue( getter_Copies(uri) ); - const char *url = uri; - PR_LOG(gLog, PR_LOG_DEBUG, - ("Timer fired for '%s'\n", url)); - - NS_RELEASE(res); - } - NS_RELEASE(domElement); - } - } -#endif - nsIContent *treeChildren; - if (NS_SUCCEEDED(rv = nsRDFContentUtils::FindChildByTag(mRoot, kNameSpaceID_XUL, kTreeChildrenAtom, &treeChildren)) && - (rv != NS_RDF_NO_VALUE)) - { - UpdateContainer(treeChildren); - NS_RELEASE(treeChildren); - } - } - mTimer->Cancel(); - NS_RELEASE(mTimer); - mTimer = nsnull; - - // reschedule timer (if document still around) - if (mDocument) - { - NS_VERIFY(NS_SUCCEEDED(NS_NewTimer(&mTimer)), "couldn't get timer"); - if (mTimer) - { - mTimer->Init(this, /* PR_TRUE, */ BUILDER_NOTIFY_MINIMUM_TIMEOUT); - } - } -} - -//////////////////////////////////////////////////////////////////////// -// nsIRDFContentModelBuilder interface - -NS_IMETHODIMP -RDFTreeBuilderImpl::SetDataBase(nsIRDFCompositeDataSource* aDataBase) -{ - NS_PRECONDITION(mRoot != nsnull, "not initialized"); - if (! mRoot) - return NS_ERROR_NOT_INITIALIZED; - - nsresult rv; - if (NS_FAILED(rv = RDFGenericBuilderImpl::SetDataBase(aDataBase))) - return rv; - - // Now set the database on the tree root, so that script writers - // can access it. - nsCOMPtr element( do_QueryInterface(mRoot) ); - NS_ASSERTION(element, "not a XULTreeElement"); - if (! element) - return NS_ERROR_UNEXPECTED; - - rv = element->SetDatabase(aDataBase); - NS_ASSERTION(NS_SUCCEEDED(rv), "couldn't set database on tree element"); - return rv; -} - - -//////////////////////////////////////////////////////////////////////// -// nsIDOMNodeObserver interface - -NS_IMETHODIMP -RDFTreeBuilderImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild) -{ - NS_PRECONDITION(aParent != nsnull, "null ptr"); - if (! aParent) - return NS_ERROR_NULL_POINTER; - - NS_PRECONDITION(aNewChild != nsnull, "null ptr"); - if (! aNewChild) - return NS_ERROR_NULL_POINTER; - - nsresult rv; - nsCOMPtr resource; - rv = GetDOMNodeResource(aParent, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - // XXX it's not a resource element, so there's no assertions - // we need to make on the back-end. Should we just do the - // update? - return NS_OK; - } - - // Get the nsIContent interface, it's a bit more utilitarian - nsCOMPtr parent( do_QueryInterface(aParent) ); - NS_ASSERTION(parent != nsnull, "parent doesn't support nsIContent"); - if (! parent) return NS_ERROR_UNEXPECTED; - - // Make sure that the element is in the widget. XXX Even this may be - // a bit too promiscuous: an element may also be a XUL element... - if (!IsElementInWidget(parent)) - return NS_OK; - - // Split the parent into its namespace and tag components - PRInt32 parentNameSpaceID; - rv = parent->GetNameSpaceID(parentNameSpaceID); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr parentNameAtom; - rv = parent->GetTag( *getter_AddRefs(parentNameAtom) ); - if (NS_FAILED(rv)) return rv; - - // Now do the same for the child - nsCOMPtr child( do_QueryInterface(aNewChild) ); - NS_ASSERTION(child != nsnull, "child doesn't support nsIContent"); - if (! child) return NS_ERROR_UNEXPECTED; - - PRInt32 childNameSpaceID; - rv = child->GetNameSpaceID(childNameSpaceID); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr childNameAtom; - rv = child->GetTag( *getter_AddRefs(childNameAtom) ); - if (NS_FAILED(rv)) return rv; - - // Now see if there's anything we can do about it. - - if ((parentNameSpaceID == kNameSpaceID_XUL) && - (parentNameAtom.get() == kTreeChildrenAtom)) { - // The parent is a xul:treechildren - - if ((childNameSpaceID == kNameSpaceID_XUL) && - (childNameAtom.get() == kTreeItemAtom)) { - - // ...and the child is a tree item. We can do this. First, - // get the rdf:property out of the child to see what the - // relationship was between the parent and the child. - nsAutoString propertyStr; - rv = child->GetAttribute(kNameSpaceID_RDF, kPropertyAtom, propertyStr); - if (NS_FAILED(rv)) return rv; - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - // It's a relationship that we'll need to set up in - // RDF. So let's assert it into the graph. First we - // need the property resource. - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(propertyStr.GetUnicode(), getter_AddRefs(property)); - if (NS_FAILED(rv)) return rv; - - // And now we need the child's resource. - nsCOMPtr target; - rv = nsRDFContentUtils::GetElementRefResource(child, getter_AddRefs(target)); - NS_ASSERTION(NS_SUCCEEDED(rv) && (target != nsnull), "expected child to have resource"); - if (NS_FAILED(rv)) return rv; - - if (! target) - return NS_ERROR_UNEXPECTED; - - // We'll handle things a bit differently if we're - // tinkering with an RDF container... - PRBool isContainer, isOrdinal; - if (NS_SUCCEEDED(gRDFContainerUtils->IsContainer(mDB, resource, &isContainer)) && - isContainer && - NS_SUCCEEDED(gRDFContainerUtils->IsOrdinalProperty(property, &isOrdinal)) && - isOrdinal) - { - nsCOMPtr container; - rv = NS_NewRDFContainer(getter_AddRefs(container)); - if (NS_FAILED(rv)) return rv; - - rv = container->Init(mDB, resource); - if (NS_FAILED(rv)) return rv; - - rv = container->AppendElement(target); - } - else { - rv = mDB->Assert(resource, property, target, PR_TRUE); - } - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove element from DB"); - if (NS_FAILED(rv)) return rv; - - return NS_OK; - } - - // Otherwise, it's a random element that doesn't - // correspond to anything in the graph. Fall through... - } - } - else if ((parentNameSpaceID == kNameSpaceID_XUL) && - (parentNameAtom.get() == kTreeItemAtom)) { - - // The parent is a xul:treeitem. - - // XXX We really only care about treeitems in the body; not - // treeitems in the header... - if ((childNameSpaceID == kNameSpaceID_XUL) && - (childNameAtom.get() == kTreeCellAtom)) { - - // ...and the child is a tree cell. They're adding a value - // for a property. - NS_NOTYETIMPLEMENTED("write me"); - } - } - else if ((parentNameSpaceID == kNameSpaceID_XUL) && - (parentNameAtom.get() == kTreeCellAtom)) { - - // The parent is a xul:treecell. They're changing the value of - // a cell. - - // XXX We really only care about cells in the body; not cells - // in the header... - NS_NOTYETIMPLEMENTED("write me"); - } - - - // If we get here, then they're trying to manipulate the DOM in - // some way that doesn't translate into a sensible update to the RDF - // graph. So, just whack the change into the content model - rv = parent->AppendChildTo(child, PR_TRUE); - NS_ASSERTION(NS_SUCCEEDED(rv), "error appending child to parent"); - if (NS_FAILED(rv)) return rv; - - return NS_OK; -} - - -NS_IMETHODIMP -RDFTreeBuilderImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild) -{ - NS_PRECONDITION(aParent != nsnull, "null ptr"); - if (!aParent) - return NS_ERROR_NULL_POINTER; - - NS_PRECONDITION(aOldChild != nsnull, "null ptr"); - if (!aOldChild) - return NS_ERROR_NULL_POINTER; - - nsresult rv; - - nsCOMPtr resource; - rv = GetDOMNodeResource(aParent, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - // XXX it's not a resource element, so there's no assertions - // we need to make on the back-end. Should we just do the - // update? - return NS_OK; - } - - // Get the nsIContent interface, it's a bit more utilitarian - nsCOMPtr parent( do_QueryInterface(aParent) ); - NS_ASSERTION(parent != nsnull, "parent doesn't support nsIContent"); - if (! parent) return NS_ERROR_UNEXPECTED; - - // Make sure that the element is in the widget. XXX Even this may be - // a bit too promiscuous: an element may also be a XUL element... - if (!IsElementInWidget(parent)) - return NS_OK; - - // Split the parent into its namespace and tag components - PRInt32 parentNameSpaceID; - rv = parent->GetNameSpaceID(parentNameSpaceID); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr parentNameAtom; - rv = parent->GetTag( *getter_AddRefs(parentNameAtom) ); - if (NS_FAILED(rv)) return rv; - - // Now do the same for the child - nsCOMPtr child( do_QueryInterface(aOldChild) ); - NS_ASSERTION(child != nsnull, "child doesn't support nsIContent"); - if (! child) return NS_ERROR_UNEXPECTED; - - PRInt32 childNameSpaceID; - rv = child->GetNameSpaceID(childNameSpaceID); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr childNameAtom; - rv = child->GetTag( *getter_AddRefs(childNameAtom) ); - if (NS_FAILED(rv)) return rv; - - // Now see if there's anything we can do about it. - - if ((parentNameSpaceID == kNameSpaceID_XUL) && - (parentNameAtom.get() == kTreeChildrenAtom)) { - // The parent is a xul:treechildren - - if ((childNameSpaceID == kNameSpaceID_XUL) && - (childNameAtom.get() == kTreeItemAtom)) { - - // ...and the child is a tree item. We can do this. First, - // get the rdf:property out of the child to see what the - // relationship was between the parent and the child. - nsAutoString propertyStr; - rv = child->GetAttribute(kNameSpaceID_RDF, kPropertyAtom, propertyStr); - if (NS_FAILED(rv)) return rv; - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - // It's a relationship set up by RDF. So let's - // unassert it from the graph. First we need the - // property resource. - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(propertyStr.GetUnicode(), getter_AddRefs(property)); - if (NS_FAILED(rv)) return rv; - - // And now we need the child's resource. - nsCOMPtr target; - rv = nsRDFContentUtils::GetElementRefResource(child, getter_AddRefs(target)); - NS_ASSERTION(NS_SUCCEEDED(rv) && (target != nsnull), "expected child to have resource"); - if (NS_FAILED(rv)) return rv; - - if (! target) - return NS_ERROR_UNEXPECTED; - - // We'll handle things a bit differently if we're - // tinkering with an RDF container... - PRBool isContainer, isOrdinal; - if (NS_SUCCEEDED(gRDFContainerUtils->IsContainer(mDB, resource, &isContainer)) && - isContainer && - NS_SUCCEEDED(gRDFContainerUtils->IsOrdinalProperty(property, &isOrdinal)) && - isOrdinal) - { - nsCOMPtr container; - rv = NS_NewRDFContainer(getter_AddRefs(container)); - if (NS_FAILED(rv)) return rv; - - rv = container->Init(mDB, resource); - if (NS_FAILED(rv)) return rv; - - rv = container->RemoveElement(target, PR_TRUE); - } - else { - rv = mDB->Unassert(resource, property, target); - } - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove element from DB"); - if (NS_FAILED(rv)) return rv; - - return NS_OK; - } - - // Otherwise, it's a random element that doesn't - // correspond to anything in the graph. Fall through... - } - } - else if ((parentNameSpaceID == kNameSpaceID_XUL) && - (parentNameAtom.get() == kTreeItemAtom)) { - - // The parent is a xul:treeitem. - - // XXX We really only care about treeitems in the body; not - // treeitems in the header... - if ((childNameSpaceID == kNameSpaceID_XUL) && - (childNameAtom.get() == kTreeCellAtom)) { - - // ...and the child is a tree cell. They're adding a value - // for a property. - NS_NOTYETIMPLEMENTED("write me"); - } - } - else if ((parentNameSpaceID == kNameSpaceID_XUL) && - (parentNameAtom.get() == kTreeCellAtom)) { - - // The parent is a xul:treecell. They're changing the value of - // a cell. - - // XXX We really only care about cells in the body; not cells - // in the header... - NS_NOTYETIMPLEMENTED("write me"); - } - - // If we get here, then they're trying to manipulate the DOM in - // some way that doesn't translate into a sensible update to the RDF - // graph. So, just whack the change into the content model - PRInt32 i; - rv = parent->IndexOf(child, i); - if (NS_FAILED(rv)) return rv; - - NS_ASSERTION(i >= 0, "child was already removed"); - if (i >= 0) { - rv = parent->RemoveChildAt(i, PR_TRUE); - NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child from parent"); - if (NS_FAILED(rv)) return rv; - } - - return NS_OK; -} - - -//////////////////////////////////////////////////////////////////////// -// Implementation methods - -nsresult -RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue, - PRInt32 aNaturalOrderPos) -{ - // If it's a tree property, then we need to add the new child - // element to a special "children" element in the parent. The - // child element's value will be the value of the - // property. We'll also attach an "ID=" attribute to the new - // child; e.g., - // - // - // ... - // - // - // - // - // - // - // - // - // - // - // - // - // ... - // - // - // - // - // - // ... - // - // - // We can also handle the case where they've specified RDF - // contents on the tag, in which case we'll just - // dangle the new row directly off the treebody. - - nsresult rv; - - nsCOMPtr treeChildren; - if (IsItemOrFolder(aElement)) { - // Ensure that the element exists on the parent. - if (NS_FAILED(rv = EnsureElementHasGenericChild(aElement, - kNameSpaceID_XUL, - kTreeChildrenAtom, - getter_AddRefs(treeChildren)))) - return rv; - } - else if (IsWidgetInsertionRootElement(aElement)) { - // We'll just use the as the element onto which - // we'll dangle a new row. - treeChildren = do_QueryInterface(aElement); - if (! treeChildren) { - NS_ERROR("aElement is not nsIContent!?!"); - return NS_ERROR_UNEXPECTED; - } - } - else { - NS_ERROR("new tree row doesn't fit here!"); - return NS_ERROR_UNEXPECTED; - } - - // Find out if we're a container or not. - PRBool markAsContainer = PR_FALSE; - - // Create the element - nsCOMPtr treeItem; - if (NS_FAILED(rv = CreateElement(kNameSpaceID_XUL, - kTreeItemAtom, - aValue, - getter_AddRefs(treeItem)))) - return rv; - - // Set the rdf:property attribute to be the arc label from the - // parent. This indicates how it got generated, so we can keep any - // subsequent changes via the DOM in sink. This property should be - // immutable. - { - nsXPIDLCString uri; - aProperty->GetValue( getter_Copies(uri) ); - treeItem->SetAttribute(kNameSpaceID_RDF, kPropertyAtom, (const char*) uri, PR_FALSE); - } - - // Create the cell substructure - if (NS_FAILED(rv = CreateTreeItemCells(treeItem))) - return rv; - - // Add the to the element. - if (nsnull != XULSortService) - { - XULSortService->InsertContainerNode(treeChildren, treeItem); - } - else - { - treeChildren->AppendChildTo(treeItem, PR_TRUE); - } - - // Add miscellaneous attributes by iterating _all_ of the - // properties out of the resource. - nsCOMPtr arcs; - rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out"); - if (NS_FAILED(rv)) return rv; - - while (1) { - PRBool hasMore; - rv = arcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) return rv; - - if (! hasMore) - break; - - nsCOMPtr isupports; - rv = arcs->GetNext(getter_AddRefs(isupports)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr property = do_QueryInterface(isupports); - - // Ignore properties that are used to indicate "tree-ness" - if (IsContainmentProperty(aElement, property)) - { - markAsContainer = PR_TRUE; - continue; - } - - // Ignore properties that we have been explicitly _asked_ to - // ignore. - if (IsIgnoredProperty(aElement, property)) - continue; - - PRInt32 nameSpaceID; - nsCOMPtr tag; - rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to split property"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr value; - rv = mDB->GetTarget(aValue, property, PR_TRUE, getter_AddRefs(value)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get target"); - if (NS_FAILED(rv)) return rv; - - // ArcsLabelsOut is allowed to be promiscuous, giving back - // potential arc labels that may not currently have a value. - if (rv == NS_RDF_NO_VALUE) - continue; - - nsCOMPtr resource; - nsCOMPtr literal; - - nsAutoString s; - if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, getter_AddRefs(resource)))) { - nsXPIDLCString uri; - resource->GetValue( getter_Copies(uri) ); - s = uri; - } - else if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFLiteralIID, getter_AddRefs(literal)))) { - nsXPIDLString p; - literal->GetValue( getter_Copies(p) ); - s = p; - } - else { - NS_ERROR("not a resource or a literal"); - return NS_ERROR_UNEXPECTED; - } - - treeItem->SetAttribute(nameSpaceID, tag, s, PR_FALSE); - - if (aNaturalOrderPos > 0) - { - // XXX Add this to menu builder as well, or better yet, abstract out. - nsAutoString pos, zero("0000"); - pos.Append(aNaturalOrderPos, 10); - if (pos.Length() < 4) - { - pos.Insert(zero, 0, 4-pos.Length()); - } - treeItem->SetAttribute(kNameSpaceID_None, kNaturalOrderPosAtom, pos, PR_FALSE); - } - } - - if (markAsContainer) - { - // Finally, mark this as a "container" so that we know to - // recursively generate kids if they're asked for. - if (NS_FAILED(rv = treeItem->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE))) - return rv; - } - - return NS_OK; -} - - - - -nsresult -RDFTreeBuilderImpl::RemoveWidgetItem(nsIContent* aElement, - nsIRDFResource* aProperty, - nsIRDFResource* aValue) -{ - nsresult rv; - - // We may put in a situation where we've been asked to either - // remove a xul:treeitem directly from a xul:treechildren (or - // xul:treebody) tag; or, we may be asked to remove a xul:treeitem - // from a grandparent xul:treeitem tag. - - // Verify that the element is actually a xul:treeitem - PRInt32 nameSpaceID; - if (NS_FAILED(rv = aElement->GetNameSpaceID(nameSpaceID))) { - NS_ERROR("unable to get element's namespace ID"); - return rv; - } - - nsCOMPtr tag; - if (NS_FAILED(rv = aElement->GetTag(*getter_AddRefs(tag)))) { - NS_ERROR("unable to get element's tag"); - return rv; - } - - nsCOMPtr treechildren; // put it here so it stays in scope - - if ((nameSpaceID == kNameSpaceID_XUL) && (tag.get() == kTreeItemAtom)) { - rv = nsRDFContentUtils::FindChildByTag(aElement, - kNameSpaceID_XUL, - kTreeChildrenAtom, - getter_AddRefs(treechildren)); - // XXX make this a warning - NS_ASSERTION(NS_OK == rv, "attempt to remove child from an element with no treechildren"); - if (NS_OK != rv) return rv; - - aElement = treechildren.get(); - } - - // Now we assume that aElement is a xul:treebody or a - // xul:treechildren; we'll just make sure for kicks. - { - aElement->GetNameSpaceID(nameSpaceID); - NS_ASSERTION(kNameSpaceID_XUL == nameSpaceID, "not a xul:treebody or xul:treechildren"); - if (kNameSpaceID_XUL != nameSpaceID) - return NS_ERROR_UNEXPECTED; - - aElement->GetTag(*getter_AddRefs(tag)); - NS_ASSERTION((kTreeChildrenAtom == tag.get()), - "not a xul:treebody or xul:treechildren"); - if (kTreeChildrenAtom != tag.get()) - return NS_ERROR_UNEXPECTED; - } - - // Allright, now grovel to find the doomed kid and blow it away. - PRInt32 count; - if (NS_FAILED(rv = aElement->ChildCount(count))) - return rv; - - for (PRInt32 i = 0; i < count; ++i) { - nsCOMPtr kid; - if (NS_FAILED(rv = aElement->ChildAt(i, *getter_AddRefs(kid)))) - return rv; // XXX fatal - - // Make sure it's a - PRInt32 nameSpaceID; - if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID))) - return rv; // XXX fatal - - if (nameSpaceID != kNameSpaceID_XUL) - continue; // wrong namespace - - nsCOMPtr tag; - if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(tag)))) - return rv; // XXX fatal - - if (tag.get() != kTreeItemAtom) - continue; // wrong tag - - // 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 resource; - if (NS_FAILED(rv = nsRDFContentUtils::GetElementRefResource(kid, getter_AddRefs(resource)))) { - NS_ERROR("severe error retrieving resource"); - return rv; - } - - if (resource.get() != aValue) - continue; // not the resource we want - - // Fount it! Now kill it. - if (NS_FAILED(rv = aElement->RemoveChildAt(i, PR_TRUE))) { - NS_ERROR("unable to remove xul:treeitem from xul:treechildren"); - return rv; - } - - return NS_OK; - } - - // XXX make this a warning - NS_WARNING("unable to find child to remove"); - return NS_OK; -} - - - -nsresult -RDFTreeBuilderImpl::SetWidgetAttribute(nsIContent* aTreeItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue) -{ - nsresult rv; - - // figure out the textual value that we want to use - nsAutoString value; - rv = nsRDFContentUtils::GetTextForNode(aValue, value); - - // see if it's a cell in the tree - PRInt32 index; - if (NS_SUCCEEDED(rv = GetColumnForProperty(mRoot, aProperty, &index))) { - // ...yep. - nsCOMPtr treerow; - rv = EnsureElementHasGenericChild(aTreeItemElement, - kNameSpaceID_XUL, - kTreeRowAtom, - getter_AddRefs(treerow)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to ensure item's treerow exists"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr cellElement; - rv = EnsureCell(treerow, index, getter_AddRefs(cellElement)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to ensure cell exists"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr text; - rv = FindTextElement(cellElement, getter_AddRefs(text)); - if (NS_FAILED(rv)) return rv; - - if (text) { - rv = text->SetText(value.GetUnicode(), value.Length(), PR_TRUE); - } - else { - rv = nsRDFContentUtils::AttachTextNode(cellElement, aValue); - } - if (NS_FAILED(rv)) return rv; - } - - - // no matter what, it's also been set as an attribute. - PRInt32 nameSpaceID; - nsCOMPtr tagAtom; - rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tagAtom)); - if (NS_FAILED(rv)) return rv; - - rv = aTreeItemElement->SetAttribute(nameSpaceID, tagAtom, value, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - return NS_OK; -} - -nsresult -RDFTreeBuilderImpl::UnsetWidgetAttribute(nsIContent* aTreeItemElement, - nsIRDFResource* aProperty, - nsIRDFNode* aValue) -{ - nsresult rv; - - PRInt32 index; - if (NS_SUCCEEDED(rv = GetColumnForProperty(mRoot, aProperty, &index))) { - // it's a cell. find it. - nsCOMPtr treerow; - rv = EnsureElementHasGenericChild(aTreeItemElement, - kNameSpaceID_XUL, - kTreeRowAtom, - getter_AddRefs(treerow)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to ensure item's treerow exists"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr cellElement; - rv = EnsureCell(treerow, index, getter_AddRefs(cellElement)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to ensure cell exists"); - if (NS_FAILED(rv)) return rv; - - // find the text element - nsCOMPtr text; - rv = FindTextElement(cellElement, getter_AddRefs(text)); - if (NS_FAILED(rv)) return rv; - - if (text) { - rv = text->SetText(nsAutoString().GetUnicode(), 0, PR_TRUE); - } - else { - rv = NS_OK; // It was never there. nothing to unset! - } - if (NS_FAILED(rv)) return rv; - } - - // no matter what, it's also been created as an attribute. - PRInt32 nameSpaceID; - nsCOMPtr tagAtom; - rv = mDocument->SplitProperty(aProperty, &nameSpaceID, getter_AddRefs(tagAtom)); - if (NS_FAILED(rv)) return rv; - - rv = aTreeItemElement->UnsetAttribute(nameSpaceID, tagAtom, PR_TRUE); - if (NS_FAILED(rv)) return rv; - - return NS_OK; -} - - -nsresult -RDFTreeBuilderImpl::FindTextElement(nsIContent* aElement, - nsITextContent** aResult) -{ - nsresult rv; - - PRInt32 count; - rv = aElement->ChildCount(count); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element child count"); - if (NS_FAILED(rv)) return rv; - - while (--count >= 0) { - nsCOMPtr child; - rv = aElement->ChildAt(count, *getter_AddRefs(child)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get child element"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr text( do_QueryInterface(child) ); - if (text) { - *aResult = text; - NS_ADDREF(*aResult); - return NS_OK; - } - - // depth-first search - rv = FindTextElement(child, aResult); - if (NS_FAILED(rv)) return rv; - - if (*aResult) - return NS_OK; - } - - *aResult = nsnull; - return NS_OK; -} - -nsresult -RDFTreeBuilderImpl::EnsureCell(nsIContent* aTreeRowElement, - PRInt32 aIndex, - nsIContent** aCellElement) -{ - // This method returns that the aIndex-th element - // if it is already present, and if not, will create up to aIndex - // nodes to create it. - NS_PRECONDITION(aIndex >= 0, "invalid arg"); - if (aIndex < 0) - return NS_ERROR_INVALID_ARG; - - nsresult rv; - - // XXX at this point, we should probably ensure that aElement is - // actually a ... - - - // Iterate through the children of the , counting - // tags until we get to the aIndex-th one. - PRInt32 count; - if (NS_FAILED(rv = aTreeRowElement->ChildCount(count))) { - NS_ERROR("unable to get xul:treerow's child count"); - return rv; - } - - for (PRInt32 i = 0; i < count; ++i) { - nsCOMPtr kid; - if (NS_FAILED(rv = aTreeRowElement->ChildAt(i, *getter_AddRefs(kid)))) { - NS_ERROR("unable to retrieve xul:treerow's child"); - return rv; - } - - PRInt32 nameSpaceID; - if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID))) { - NS_ERROR("unable to get child namespace"); - return rv; - } - - if (nameSpaceID != kNameSpaceID_XUL) - continue; // not - - nsCOMPtr tag; - if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(tag)))) { - NS_ERROR("unable to get child tag"); - return rv; - } - - if (tag.get() != kTreeCellAtom) - continue; // not - - // Okay, it's a xul:treecell; see if it's the right one... - if (aIndex == 0) { - *aCellElement = kid; - NS_ADDREF(*aCellElement); - return NS_OK; - } - - // Nope, decrement the counter and move on... - --aIndex; - } - - // Create all of the xul:treecell elements up to and including the - // index of the cell that was asked for. - NS_ASSERTION(aIndex >= 0, "uh oh, I thought aIndex was s'posed t' be >= 0..."); - - nsCOMPtr cellElement; - while (aIndex-- >= 0) { - if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_XUL, - kTreeCellAtom, - getter_AddRefs(cellElement)))) { - NS_ERROR("unable to create new xul:treecell"); - return rv; - } - - if (NS_FAILED(rv = aTreeRowElement->AppendChildTo(cellElement, PR_FALSE))) { - NS_ERROR("unable to append xul:treecell to treerow"); - return rv; - } - } - - *aCellElement = cellElement; - NS_ADDREF(*aCellElement); - return NS_OK; -} - -nsresult -RDFTreeBuilderImpl::CreateTreeItemCells(nsIContent* aTreeItemElement) -{ - // - // - // value - // ... - // - // - nsresult rv; - - // XXX at this point, we should probably ensure that aElement is - // actually a ... - nsCOMPtr treeRowElement; - rv = NS_NewRDFElement(kNameSpaceID_XUL, - kTreeRowAtom, - getter_AddRefs(treeRowElement)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to create a tree row."); - return rv; - } - aTreeItemElement->AppendChildTo(treeRowElement, PR_FALSE); - - // Get the treeitem's resource so that we can generate cell - // values. We could QI for the nsIRDFResource here, but doing this - // via the nsIContent interface allows us to support generic nodes - // that might get added in by DOM calls. - nsCOMPtr treeItemResource; - rv = nsRDFContentUtils::GetElementRefResource(aTreeItemElement, getter_AddRefs(treeItemResource)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get tree item resource"); - if (NS_FAILED(rv)) return rv; - - PRInt32 count; - if (NS_FAILED(rv = mRoot->ChildCount(count))) { - NS_ERROR("unable to count xul:tree element's kids"); - return rv; - } - - // Iterate through all the columns that have been specified, - // constructing a cell in the content model for each one. - PRInt32 cellIndex = 0; - for (PRInt32 i = 0; i < count; ++i) { - nsCOMPtr kid; - if (NS_FAILED(rv = mRoot->ChildAt(i, *getter_AddRefs(kid)))) { - NS_ERROR("unable to get xul:tree's child"); - return rv; - } - - PRInt32 nameSpaceID; - if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID))) { - NS_ERROR("unable to get child's namespace"); - return rv; - } - - if (nameSpaceID != kNameSpaceID_XUL) - continue; // not - - nsCOMPtr tag; - if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(tag)))) { - NS_ERROR("unable to get child's tag"); - return rv; - } - - if (tag.get() != kTreeColAtom) - continue; // not - - // Okay, we've found a column. Ensure that we've got a real - // tree cell that lives beneath _this_ tree item for its - // value. - nsCOMPtr cellElement; - if (NS_FAILED(rv = EnsureCell(treeRowElement, cellIndex, getter_AddRefs(cellElement)))) { - NS_ERROR("unable to find/create cell element"); - return rv; - } - - // The first cell gets a element and a - // element... - // - // XXX This is bogus: dogfood ready crap. We need to figure - // out a better way to specify this. - if (cellIndex == 0) { - nsCOMPtr indentationElement; - rv = NS_NewRDFElement(kNameSpaceID_XUL, - kTreeIndentationAtom, - getter_AddRefs(indentationElement)); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create indentation node"); - if (NS_FAILED(rv)) return rv; - - rv = cellElement->AppendChildTo(indentationElement, PR_FALSE); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to append indentation element"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr iconElement; - rv = NS_NewRDFElement(kNameSpaceID_XUL, - kTitledButtonAtom /* kTreeIconAtom */, - getter_AddRefs(iconElement)); - - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create icon node"); - if (NS_FAILED(rv)) return rv; - - rv = cellElement->AppendChildTo(iconElement, PR_FALSE); - NS_ASSERTION(NS_SUCCEEDED(rv), "uanble to append icon element"); - if (NS_FAILED(rv)) return rv; - } - - - // The column property is stored in the RDF:resource attribute - // of the tag. - nsAutoString uri; - rv = kid->GetAttribute(kNameSpaceID_RDF, kResourceAtom, uri); - NS_ASSERTION(NS_SUCCEEDED(rv), "severe error occured retrieving attribute"); - if (NS_FAILED(rv)) return rv; - - // Set its value, if we know it. - nsCOMPtr value; - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - - // First construct a property resource from the URI... - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(uri.GetUnicode(), getter_AddRefs(property)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to construct resource for xul:treecell"); - if (NS_FAILED(rv)) return rv; - - // ...then query the RDF back-end - rv = mDB->GetTarget(treeItemResource, - property, - PR_TRUE, - getter_AddRefs(value)); - - if (NS_FAILED(rv)) return rv; - } - - // Attach a plain old text node: nothing fancy. Here's - // where we'd do wacky stuff like pull in an icon or - // whatever. - - // XXX At one point, I had optimized this to _only_ create a - // text node if the thing had a value. However, due to a - // incremental reflow bug in the table code (5759), this - // didn't work. So we always create a text node, even if it's - // empty. - rv = nsRDFContentUtils::AttachTextNode(cellElement, value); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to attach text node to xul:treecell"); - if (NS_FAILED(rv)) return rv; - - ++cellIndex; - } - - return NS_OK; -} - - -nsresult -RDFTreeBuilderImpl::GetColumnForProperty(nsIContent* aTreeElement, - nsIRDFResource* aProperty, - PRInt32* aIndex) -{ - nsresult rv; - - nsXPIDLCString propertyURI; - if (NS_FAILED(rv = aProperty->GetValue( getter_Copies(propertyURI) ))) { - NS_ERROR("unable to get property's URI"); - return rv; - } - - // XXX should ensure that aTreeElement really is a xul:tree - - PRInt32 count; - if (NS_FAILED(rv = aTreeElement->ChildCount(count))) { - NS_ERROR("unable to count xul:tree element's kids"); - return rv; - } - - // Iterate through the columns to find the one that's appropriate - // for this cell. - PRInt32 index = 0; - for (PRInt32 i = 0; i < count; ++i) { - nsCOMPtr kid; - if (NS_FAILED(rv = aTreeElement->ChildAt(i, *getter_AddRefs(kid)))) { - NS_ERROR("unable to get xul:tree's child"); - return rv; - } - - PRInt32 nameSpaceID; - if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID))) { - NS_ERROR("unable to get child's namespace"); - return rv; - } - - if (nameSpaceID != kNameSpaceID_XUL) - continue; // not - - nsCOMPtr tag; - if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(tag)))) { - NS_ERROR("unable to get child's tag"); - return rv; - } - - if (tag.get() != kTreeColAtom) - continue; // not - - // Okay, we've found a column. Is it the right one? The - // column property is stored in the RDF:resource attribute of - // the tag.... - nsAutoString uri; - if (NS_FAILED(rv = kid->GetAttribute(kNameSpaceID_RDF, kResourceAtom, uri))) { - NS_ERROR("severe error occured retrieving attribute"); - return rv; - } - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - if (0 == nsCRT::strcmp(uri.GetUnicode(), propertyURI)) { - *aIndex = index; - return NS_OK; - } - } - - ++index; - } - - // Nope, couldn't find it. - return NS_ERROR_FAILURE; -} diff --git a/rdf/content/src/nsRDFXULBuilder.cpp b/rdf/content/src/nsRDFXULBuilder.cpp index 92150a05d900..a10ed8e39b62 100644 --- a/rdf/content/src/nsRDFXULBuilder.cpp +++ b/rdf/content/src/nsRDFXULBuilder.cpp @@ -109,9 +109,7 @@ static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); -static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID); -static NS_DEFINE_CID(kRDFMenuBuilderCID, NS_RDFMENUBUILDER_CID); -static NS_DEFINE_CID(kRDFToolbarBuilderCID, NS_RDFTOOLBARBUILDER_CID); +static NS_DEFINE_CID(kXULTemplateBuilderCID, NS_XULTEMPLATEBUILDER_CID); static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID); static NS_DEFINE_CID(kXULDocumentInfoCID, NS_XULDOCUMENTINFO_CID); static NS_DEFINE_CID(kXULKeyListenerCID, NS_XULKEYLISTENER_CID); @@ -317,8 +315,8 @@ public: nsIRDFResource* aProperty, nsIRDFNode* aValue); - nsresult CreateBuilder(const nsCID& aBuilderCID, nsIContent* aElement, - const nsString& aDataSources); + nsresult CreateTemplateBuilder(nsIContent* aElement, + const nsString& aDataSources); nsresult GetRDFResourceFromXULElement(nsIDOMNode* aNode, nsIRDFResource** aResult); @@ -430,7 +428,7 @@ RDFXULBuilderImpl::Init() NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register RDF namespace"); if (NS_FAILED(rv)) return rv; - kLazyContentAtom = NS_NewAtom("lazycontent"); + kLazyContentAtom = NS_NewAtom("lazycontent"); kDataSourcesAtom = NS_NewAtom("datasources"); kIdAtom = NS_NewAtom("id"); kInstanceOfAtom = NS_NewAtom("instanceof"); @@ -1669,63 +1667,6 @@ RDFXULBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& aName return NS_OK; } - if ((nameSpaceID == kNameSpaceID_None) && (nameAtom.get() == kRefAtom)) { - // They're changing the RDF 'ref=' of the element. Do some - // trickery so that any generic builders that are referring to - // this element will reconstruct the contents of the - // element. Blow away _all_ of the children, and re-annotate - // the node s.t. children will be reconstructed properly. - PRInt32 count; - rv = element->ChildCount(count); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element's child count"); - if (NS_FAILED(rv)) return rv; - - while (--count >= 0) { - nsCOMPtr child; - rv = element->ChildAt(count, *getter_AddRefs(child)); - if (NS_FAILED(rv)) return rv; - - rv = element->RemoveChildAt(count, PR_TRUE); - NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child"); - - if (! IsXULElement(child)) { - // If it's _not_ a XUL element, then we want to blow - // it and all of its kids out of the XUL document's - // resource-to-element map. - rv = child->SetDocument(nsnull, PR_TRUE); - if (NS_FAILED(rv)) return rv; - } - } - - // Clear the contents-generated attribute so that the next time we - // come back, we'll regenerate the kids we just killed. - rv = element->UnsetAttribute(kNameSpaceID_None, - kTemplateContentsGeneratedAtom, - PR_FALSE); - if (NS_FAILED(rv)) return rv; - - rv = element->UnsetAttribute(kNameSpaceID_None, - kContainerContentsGeneratedAtom, - PR_FALSE); - if (NS_FAILED(rv)) return rv; - - // This is a _total_ hack to make sure that any XUL we blow away - // gets rebuilt. - rv = element->UnsetAttribute(kNameSpaceID_None, - kXULContentsGeneratedAtom, - PR_FALSE); - if (NS_FAILED(rv)) return rv; - - rv = element->SetAttribute(kNameSpaceID_RDF, - kLazyContentAtom, - "true", - PR_FALSE); - if (NS_FAILED(rv)) return rv; - - // Fall through and change the property "normally" now. - } - - // If we get here, it's a vanilla property that we need to go into // the RDF graph to update. So, build an RDF resource from the // property name... @@ -2643,15 +2584,7 @@ RDFXULBuilderImpl::CreateXULElement(nsINameSpace* aContainingNameSpace, kDataSourcesAtom, dataSources)) { - nsCID builderCID; - if (aTagName == kTreeAtom) - builderCID = kRDFTreeBuilderCID; - else if (aTagName == kMenuAtom || aTagName == kMenuBarAtom) - builderCID = kRDFMenuBuilderCID; - else if (aTagName == kToolbarAtom) - builderCID = kRDFToolbarBuilderCID; - - rv = CreateBuilder(builderCID, element, dataSources); + rv = CreateTemplateBuilder(element, dataSources); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add datasources"); } } @@ -2928,20 +2861,19 @@ RDFXULBuilderImpl::RemoveAttribute(nsIContent* aElement, } nsresult -RDFXULBuilderImpl::CreateBuilder(const nsCID& aBuilderCID, nsIContent* aElement, - const nsString& aDataSources) +RDFXULBuilderImpl::CreateTemplateBuilder(nsIContent* aElement, + const nsString& aDataSources) { nsresult rv; // construct a new builder nsCOMPtr builder; - if (NS_FAILED(rv = nsComponentManager::CreateInstance(aBuilderCID, - nsnull, - kIRDFContentModelBuilderIID, - (void**) getter_AddRefs(builder)))) { - NS_ERROR("unable to create tree content model builder"); - return rv; - } + rv = nsComponentManager::CreateInstance(kXULTemplateBuilderCID, + nsnull, + kIRDFContentModelBuilderIID, + (void**) getter_AddRefs(builder)); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create tree content model builder"); + if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv = builder->SetRootContent(aElement))) { NS_ERROR("unable to set builder's root content element"); @@ -2981,6 +2913,14 @@ RDFXULBuilderImpl::CreateBuilder(const nsCID& aBuilderCID, nsIContent* aElement, // PRInt32 first = 0; + nsCOMPtr document = do_QueryInterface(mDocument); + if (! document) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr docURL = dont_AddRef( document->GetDocumentURL() ); + if (! docURL) + return NS_ERROR_UNEXPECTED; + while(1) { while (first < aDataSources.Length() && nsString::IsSpace(aDataSources.CharAt(first))) ++first; @@ -2996,6 +2936,9 @@ RDFXULBuilderImpl::CreateBuilder(const nsCID& aBuilderCID, nsIContent* aElement, aDataSources.Mid(uri, first, last - first); first = last + 1; + rv = rdf_MakeAbsoluteURI(docURL, uri); + if (NS_FAILED(rv)) return rv; + nsCOMPtr ds; // Some monkey business to convert the nsAutoString to a diff --git a/rdf/content/src/nsXULDocument.cpp b/rdf/content/src/nsXULDocument.cpp index 5f6b32f25637..dc31d37c77cc 100644 --- a/rdf/content/src/nsXULDocument.cpp +++ b/rdf/content/src/nsXULDocument.cpp @@ -2746,6 +2746,17 @@ XULDocumentImpl::CreateElement(const nsString& aTagName, nsIDOMElement** aReturn nsresult rv; +#ifdef PR_LOGGING + if (PR_LOG_TEST(gXULLog, PR_LOG_DEBUG)) { + char* tagCStr = aTagName.ToNewCString(); + + PR_LOG(gXULLog, PR_LOG_DEBUG, + ("xul[CreateElement] %s", tagCStr)); + + delete[] tagCStr; + } +#endif + nsCOMPtr name; PRInt32 nameSpaceID; @@ -2925,6 +2936,19 @@ XULDocumentImpl::CreateElementWithNameSpace(const nsString& aTagName, nsresult rv; +#ifdef PR_LOGGING + if (PR_LOG_TEST(gXULLog, PR_LOG_DEBUG)) { + char* namespaceCStr = aNameSpace.ToNewCString(); + char* tagCStr = aTagName.ToNewCString(); + + PR_LOG(gXULLog, PR_LOG_DEBUG, + ("xul[CreateElementWithNameSpace] [%s]:%s", namespaceCStr, tagCStr)); + + delete[] tagCStr; + delete[] namespaceCStr; + } +#endif + nsCOMPtr name = dont_AddRef(NS_NewAtom(aTagName.GetUnicode())); if (! name) return NS_ERROR_OUT_OF_MEMORY; @@ -3005,12 +3029,12 @@ XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn) nsresult rv; - nsAutoString uri; + nsCAutoString uri; rv = nsRDFContentUtils::MakeElementURI(this, aId, uri); if (NS_FAILED(rv)) return rv; nsCOMPtr resource; - if (NS_FAILED(rv = gRDFService->GetUnicodeResource(uri.GetUnicode(), getter_AddRefs(resource)))) { + if (NS_FAILED(rv = gRDFService->GetResource(uri, getter_AddRefs(resource)))) { NS_ERROR("unable to get resource"); return rv; } @@ -3209,15 +3233,14 @@ XULDocumentImpl::CreatePopupDocument(nsIContent* aPopupElement, nsIDocument** aR nsCOMPtr domRoot = do_QueryInterface(aPopupElement); domRoot->GetAttribute("id", idValue); - nsAutoString uri; + nsCAutoString uri; rv = nsRDFContentUtils::MakeElementURI(this, idValue, uri); if (NS_FAILED(rv)) return rv; // Use the absolute URL to retrieve a resource from the RDF // service that corresponds to the root content. nsCOMPtr rootResource; - if (NS_FAILED(rv = gRDFService->GetUnicodeResource(uri.GetUnicode(), - getter_AddRefs(rootResource)))) { + if (NS_FAILED(rv = gRDFService->GetResource(uri, getter_AddRefs(rootResource)))) { NS_ERROR("Uh-oh. Couldn't obtain the resource for the popup doc root."); return rv; } diff --git a/rdf/content/src/nsXULElement.cpp b/rdf/content/src/nsXULElement.cpp index 975a45beba42..1949a070ebc0 100644 --- a/rdf/content/src/nsXULElement.cpp +++ b/rdf/content/src/nsXULElement.cpp @@ -79,7 +79,6 @@ #include "nsIStyledContent.h" #include "nsIStyleRule.h" #include "nsIURL.h" -#include "nsXULTreeElement.h" #include "rdfutil.h" #include "prlog.h" #include "rdf.h" @@ -317,8 +316,8 @@ private: PRBool mContentsMustBeGenerated; nsVoidArray* mBroadcastListeners; // [WEAK] nsIDOMXULElement* mBroadcaster; // [OWNER] - nsXULElement* mInnerXULElement; // [OWNER] nsIController* mController; // [OWNER] + nsCOMPtr mDatabase; // [OWNER] }; @@ -397,7 +396,6 @@ RDFElementImpl::RDFElementImpl(PRInt32 aNameSpaceID, nsIAtom* aTag) mContentsMustBeGenerated(PR_FALSE), mBroadcastListeners(nsnull), mBroadcaster(nsnull), - mInnerXULElement(nsnull), mController(nsnull) { NS_INIT_REFCNT(); @@ -514,8 +512,6 @@ RDFElementImpl::~RDFElementImpl() ++entry; } } - - delete mInnerXULElement; } @@ -576,16 +572,6 @@ RDFElementImpl::QueryInterface(REFNSIID iid, void** result) else if (iid.Equals(kIJSScriptObjectIID)) { *result = NS_STATIC_CAST(nsIJSScriptObject*, this); } - else if (iid.Equals(nsIDOMXULTreeElement::GetIID()) && - (mNameSpaceID == kNameSpaceID_XUL) && - (mTag == kTreeAtom)) { - if (! mInnerXULElement) { - if ((mInnerXULElement = new nsXULTreeElement(this)) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - } - - return mInnerXULElement->QueryInterface(iid, result); - } else { *result = nsnull; return NS_NOINTERFACE; @@ -1275,16 +1261,8 @@ RDFElementImpl::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject if (! mScriptObject) { nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - nsresult (*fn)(nsIScriptContext* aContext, nsISupports* aSupports, nsISupports* aParent, void** aReturn); + rv = NS_NewScriptXULElement(aContext, (nsIDOMXULElement*) this, global, (void**) &mScriptObject); - if (mTag == kTreeAtom) { - fn = NS_NewScriptXULTreeElement; - } - else { - fn = NS_NewScriptXULElement; - } - - rv = fn(aContext, (nsIDOMXULElement*) this, global, (void**) &mScriptObject); NS_RELEASE(global); // Ensure that a reference exists to this element @@ -2532,6 +2510,36 @@ RDFElementImpl::GetResource(nsIRDFResource** aResource) return NS_OK; } + +NS_IMETHODIMP +RDFElementImpl::GetDatabase(nsIRDFCompositeDataSource** aDatabase) +{ + NS_PRECONDITION(aDatabase != nsnull, "null ptr"); + if (! aDatabase) + return NS_ERROR_NULL_POINTER; + + *aDatabase = mDatabase; + NS_IF_ADDREF(*aDatabase); + return NS_OK; +} + + +NS_IMETHODIMP +RDFElementImpl::SetDatabase(nsIRDFCompositeDataSource* aDatabase) +{ + // XXX maybe someday you'll be allowed to change it. + NS_PRECONDITION(mDatabase == nsnull, "already initialized"); + if (mDatabase) + return NS_ERROR_ALREADY_INITIALIZED; + + mDatabase = aDatabase; + + // XXX reconstruct the entire tree now! + + return NS_OK; +} + + //////////////////////////////////////////////////////////////////////// // Implementation methods diff --git a/rdf/content/src/nsXULSortService.cpp b/rdf/content/src/nsXULSortService.cpp index 889d1a576928..1b3c3a91091d 100644 --- a/rdf/content/src/nsXULSortService.cpp +++ b/rdf/content/src/nsXULSortService.cpp @@ -82,7 +82,6 @@ #include "nsIRDFService.h" #include "rdf.h" -#include "nsIDOMXULTreeElement.h" #include "nsIDOMXULElement.h" #include "nsILocale.h" @@ -112,7 +111,6 @@ static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID); static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID); -static NS_DEFINE_IID(kIDomXulTreeElementIID, NS_IDOMXULTREEELEMENT_IID); static NS_DEFINE_IID(kIDomXulElementIID, NS_IDOMXULELEMENT_IID); static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID); @@ -1292,7 +1290,7 @@ XULSortServiceImpl::InsertContainerNode(nsIContent *container, nsIContent *node) if (NS_FAILED(rv = FindTreeElement(container, getter_AddRefs(treeNode)))) return(rv); // get composite db for tree - nsCOMPtr domXulTree; + nsCOMPtr domXulTree; sortInfo.rdfService = gRDFService; sortInfo.db = nsnull; @@ -1300,7 +1298,7 @@ XULSortServiceImpl::InsertContainerNode(nsIContent *container, nsIContent *node) // that we're sure that we'll hold a reference to it (and actually // release that reference when the stack frame goes away). nsCOMPtr cds; - rv = treeNode->QueryInterface(kIDomXulTreeElementIID, getter_AddRefs(domXulTree)); + rv = treeNode->QueryInterface(kIDomXulElementIID, getter_AddRefs(domXulTree)); if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv = domXulTree->GetDatabase(getter_AddRefs(cds)))) @@ -1488,7 +1486,7 @@ XULSortServiceImpl::DoSort(nsIDOMNode* node, const nsString& sortResource, // get composite db for tree sortInfo.rdfService = gRDFService; sortInfo.db = nsnull; - nsCOMPtr domXulTree = do_QueryInterface(treeNode); + nsCOMPtr domXulTree = do_QueryInterface(treeNode); if (!domXulTree) return(NS_ERROR_FAILURE); nsCOMPtr cds; if (NS_SUCCEEDED(rv = domXulTree->GetDatabase(getter_AddRefs(cds)))) diff --git a/rdf/content/src/nsXULTemplateBuilder.cpp b/rdf/content/src/nsXULTemplateBuilder.cpp index d804603ff40e..ed3cb67d2b35 100644 --- a/rdf/content/src/nsXULTemplateBuilder.cpp +++ b/rdf/content/src/nsXULTemplateBuilder.cpp @@ -60,6 +60,7 @@ #include "nsINameSpaceManager.h" #include "nsIServiceManager.h" #include "nsISupportsArray.h" +#include "nsITextContent.h" #include "nsIURL.h" #include "nsLayoutCID.h" #include "nsRDFCID.h" @@ -79,11 +80,8 @@ #include "prlog.h" -// Remove this to try running without the C++ builders. This will -// inhibit delegation to the fallback builder for constructing content -// (but still relies on it for determining the correct tagset to use). -#define FALLBACK_BUILDERS 1 - +#define NS_RDF_ELEMENT_WAS_CREATED NS_RDF_NO_VALUE +#define NS_RDF_ELEMENT_WAS_THERE NS_OK static PRLogModuleInfo* gLog; @@ -102,6 +100,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); +static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID); static NS_DEFINE_IID(kXULSortServiceCID, NS_XULSORTSERVICE_CID); static NS_DEFINE_IID(kIXULSortServiceIID, NS_IXULSORTSERVICE_IID); @@ -115,12 +114,13 @@ static NS_DEFINE_CID(kIHTMLElementFactoryIID, NS_IHTML_ELEMENT_FACTORY_IID); //////////////////////////////////////////////////////////////////////// -nsrefcnt RDFGenericBuilderImpl::gRefCnt = 0; +nsrefcnt RDFGenericBuilderImpl::gRefCnt = 0; nsIXULSortService* RDFGenericBuilderImpl::XULSortService = nsnull; nsIAtom* RDFGenericBuilderImpl::kContainerAtom; nsIAtom* RDFGenericBuilderImpl::kLazyContentAtom; nsIAtom* RDFGenericBuilderImpl::kIsContainerAtom; +nsIAtom* RDFGenericBuilderImpl::kIsEmptyAtom; nsIAtom* RDFGenericBuilderImpl::kXULContentsGeneratedAtom; nsIAtom* RDFGenericBuilderImpl::kTemplateContentsGeneratedAtom; nsIAtom* RDFGenericBuilderImpl::kContainerContentsGeneratedAtom; @@ -133,9 +133,8 @@ nsIAtom* RDFGenericBuilderImpl::kContainmentAtom; nsIAtom* RDFGenericBuilderImpl::kNaturalOrderPosAtom; nsIAtom* RDFGenericBuilderImpl::kIgnoreAtom; nsIAtom* RDFGenericBuilderImpl::kRefAtom; +nsIAtom* RDFGenericBuilderImpl::kValueAtom; -nsIAtom* RDFGenericBuilderImpl::kSubcontainmentAtom; -nsIAtom* RDFGenericBuilderImpl::kRootcontainmentAtom; nsIAtom* RDFGenericBuilderImpl::kTemplateAtom; nsIAtom* RDFGenericBuilderImpl::kRuleAtom; nsIAtom* RDFGenericBuilderImpl::kTextAtom; @@ -161,6 +160,26 @@ nsIRDFResource* RDFGenericBuilderImpl::kXUL_element; //////////////////////////////////////////////////////////////////////// +nsresult +NS_NewXULTemplateBuilder(nsIRDFContentModelBuilder** aResult) +{ + nsresult rv; + RDFGenericBuilderImpl* result = new RDFGenericBuilderImpl(); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); // stabilize + + rv = result->Init(); + if (NS_SUCCEEDED(rv)) { + rv = result->QueryInterface(nsCOMTypeInfo::GetIID(), (void**) aResult); + } + + NS_RELEASE(result); + return rv; +} + + RDFGenericBuilderImpl::RDFGenericBuilderImpl(void) : mDocument(nsnull), mDB(nsnull), @@ -168,92 +187,6 @@ RDFGenericBuilderImpl::RDFGenericBuilderImpl(void) mTimer(nsnull) { NS_INIT_REFCNT(); - - if (gRefCnt == 0) { - kContainerAtom = NS_NewAtom("container"); - kLazyContentAtom = NS_NewAtom("lazycontent"); - kIsContainerAtom = NS_NewAtom("iscontainer"); - kXULContentsGeneratedAtom = NS_NewAtom("xulcontentsgenerated"); - kTemplateContentsGeneratedAtom = NS_NewAtom("templatecontentsgenerated"); - kContainerContentsGeneratedAtom = NS_NewAtom("containercontentsgenerated"); - - kIdAtom = NS_NewAtom("id"); - kOpenAtom = NS_NewAtom("open"); - kEmptyAtom = NS_NewAtom("empty"); - kResourceAtom = NS_NewAtom("resource"); - kURIAtom = NS_NewAtom("uri"); - kContainmentAtom = NS_NewAtom("containment"); - kIgnoreAtom = NS_NewAtom("ignore"); - kRefAtom = NS_NewAtom("ref"); - kNaturalOrderPosAtom = NS_NewAtom("pos"); - - kSubcontainmentAtom = NS_NewAtom("subcontainment"); - kRootcontainmentAtom = NS_NewAtom("rootcontainment"); - kTemplateAtom = NS_NewAtom("template"); - kRuleAtom = NS_NewAtom("rule"); - - kTextAtom = NS_NewAtom("text"); - kPropertyAtom = NS_NewAtom("property"); - kInstanceOfAtom = NS_NewAtom("instanceOf"); - - nsresult rv; - - // Register the XUL and RDF namespaces: these'll just retrieve - // the IDs if they've already been registered by someone else. - if (NS_SUCCEEDED(rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, - nsnull, - kINameSpaceManagerIID, - (void**) &gNameSpaceManager))) { - -// XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp -static const char kXULNameSpaceURI[] - = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; - -static const char kRDFNameSpaceURI[] - = RDF_NAMESPACE_URI; - - rv = gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace"); - - rv = gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register RDF namespace"); - } - else { - NS_ERROR("couldn't create namepsace manager"); - } - - - // Initialize the global shared reference to the service - // manager and get some shared resource objects. - rv = nsServiceManager::GetService(kRDFServiceCID, - kIRDFServiceIID, - (nsISupports**) &gRDFService); - - if (NS_SUCCEEDED(rv)) { - gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title); - gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child); - gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column); - gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder); - gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child); - gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf); - gRDFService->GetResource(XUL_NAMESPACE_URI "element", &kXUL_element); - } - - rv = nsServiceManager::GetService(kRDFContainerUtilsCID, - nsIRDFContainerUtils::GetIID(), - (nsISupports**) &gRDFContainerUtils); - - rv = nsServiceManager::GetService(kXULSortServiceCID, - kIXULSortServiceIID, - (nsISupports**) &XULSortService); - - } - ++gRefCnt; - -#ifdef PR_LOGGING - if (! gLog) - gLog = PR_NewLogModule("nsRDFGenericBuilder"); -#endif } RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) @@ -270,7 +203,8 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) NS_RELEASE(kContainerAtom); NS_RELEASE(kLazyContentAtom); NS_RELEASE(kIsContainerAtom); - NS_RELEASE(kXULContentsGeneratedAtom); + NS_RELEASE(kIsEmptyAtom); + NS_RELEASE(kXULContentsGeneratedAtom); NS_RELEASE(kTemplateContentsGeneratedAtom); NS_RELEASE(kContainerContentsGeneratedAtom); @@ -278,14 +212,13 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) NS_RELEASE(kOpenAtom); NS_RELEASE(kEmptyAtom); NS_RELEASE(kResourceAtom); - NS_RELEASE(kURIAtom); + NS_RELEASE(kURIAtom); NS_RELEASE(kContainmentAtom); NS_RELEASE(kIgnoreAtom); NS_RELEASE(kRefAtom); + NS_RELEASE(kValueAtom); NS_RELEASE(kNaturalOrderPosAtom); - NS_RELEASE(kSubcontainmentAtom); - NS_RELEASE(kRootcontainmentAtom); NS_RELEASE(kTemplateAtom); NS_RELEASE(kRuleAtom); NS_RELEASE(kTextAtom); @@ -307,11 +240,105 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void) } if (mTimer) - { - mTimer->Cancel(); - NS_RELEASE(mTimer); - mTimer = nsnull; + { + mTimer->Cancel(); + NS_RELEASE(mTimer); + mTimer = nsnull; + } +} + + +nsresult +RDFGenericBuilderImpl::Init() +{ + if (gRefCnt == 0) { + kContainerAtom = NS_NewAtom("container"); + kLazyContentAtom = NS_NewAtom("lazycontent"); + kIsContainerAtom = NS_NewAtom("iscontainer"); + kIsEmptyAtom = NS_NewAtom("isempty"); + kXULContentsGeneratedAtom = NS_NewAtom("xulcontentsgenerated"); + kTemplateContentsGeneratedAtom = NS_NewAtom("templatecontentsgenerated"); + kContainerContentsGeneratedAtom = NS_NewAtom("containercontentsgenerated"); + + kIdAtom = NS_NewAtom("id"); + kOpenAtom = NS_NewAtom("open"); + kEmptyAtom = NS_NewAtom("empty"); + kResourceAtom = NS_NewAtom("resource"); + kURIAtom = NS_NewAtom("uri"); + kContainmentAtom = NS_NewAtom("containment"); + kIgnoreAtom = NS_NewAtom("ignore"); + kRefAtom = NS_NewAtom("ref"); + kValueAtom = NS_NewAtom("value"); + kNaturalOrderPosAtom = NS_NewAtom("pos"); + + kTemplateAtom = NS_NewAtom("template"); + kRuleAtom = NS_NewAtom("rule"); + + kTextAtom = NS_NewAtom("text"); + kPropertyAtom = NS_NewAtom("property"); + kInstanceOfAtom = NS_NewAtom("instanceOf"); + + nsresult rv; + + // Register the XUL and RDF namespaces: these'll just retrieve + // the IDs if they've already been registered by someone else. + rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID, + nsnull, + nsCOMTypeInfo::GetIID(), + (void**) &gNameSpaceManager); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager"); + if (NS_FAILED(rv)) return rv; + + // XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp + static const char kXULNameSpaceURI[] + = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + + static const char kRDFNameSpaceURI[] + = RDF_NAMESPACE_URI; + + rv = gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace"); + if (NS_FAILED(rv)) return rv; + + rv = gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register RDF namespace"); + if (NS_FAILED(rv)) return rv; + + + // Initialize the global shared reference to the service + // manager and get some shared resource objects. + rv = nsServiceManager::GetService(kRDFServiceCID, + kIRDFServiceIID, + (nsISupports**) &gRDFService); + if (NS_FAILED(rv)) return rv; + + gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title); + gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child); + gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column); + gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder); + gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child); + gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf); + gRDFService->GetResource(XUL_NAMESPACE_URI "element", &kXUL_element); + + rv = nsServiceManager::GetService(kRDFContainerUtilsCID, + nsIRDFContainerUtils::GetIID(), + (nsISupports**) &gRDFContainerUtils); + if (NS_FAILED(rv)) return rv; + + rv = nsServiceManager::GetService(kXULSortServiceCID, + kIXULSortServiceIID, + (nsISupports**) &XULSortService); + if (NS_FAILED(rv)) return rv; + } + ++gRefCnt; + +#ifdef PR_LOGGING + if (! gLog) + gLog = PR_NewLogModule("nsRDFGenericBuilder"); +#endif + + return NS_OK; } //////////////////////////////////////////////////////////////////////// @@ -391,10 +418,26 @@ RDFGenericBuilderImpl::SetDataBase(nsIRDFCompositeDataSource* aDataBase) if (mDB) return NS_ERROR_ALREADY_INITIALIZED; + NS_PRECONDITION(mRoot != nsnull, "not initialized"); + if (! mRoot) + return NS_ERROR_NOT_INITIALIZED; + mDB = aDataBase; NS_ADDREF(mDB); mDB->AddObserver(this); + + // Now set the database on the element, so that script writers can + // access it. + nsCOMPtr element( do_QueryInterface(mRoot) ); + NS_ASSERTION(element != nsnull, "not a XULElement"); + if (! element) + return NS_ERROR_UNEXPECTED; + + nsresult rv; + rv = element->SetDatabase(aDataBase); + if (NS_FAILED(rv)) return rv; + return NS_OK; } @@ -415,74 +458,9 @@ RDFGenericBuilderImpl::GetDataBase(nsIRDFCompositeDataSource** aDataBase) NS_IMETHODIMP RDFGenericBuilderImpl::CreateRootContent(nsIRDFResource* aResource) { - // Create a structure that looks like this: - // - // - // - // - // - // - // - // - // Eventually, we should be able to do away with the HTML tags and - // just have it create XUL in some other context. - - nsresult rv; - nsCOMPtr tag; - nsCOMPtr doc; - nsCOMPtr rootAtom; - if (NS_FAILED(rv = GetRootWidgetAtom(getter_AddRefs(rootAtom)))) { - return rv; - } - - if (NS_FAILED(rv = mDocument->QueryInterface(kIDocumentIID, - (void**) getter_AddRefs(doc)))) - return rv; - - // Create the DOCUMENT element - if ((tag = dont_AddRef(NS_NewAtom("document"))) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - nsCOMPtr root; - if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_HTML, /* XXX */ - tag, - getter_AddRefs(root)))) - return rv; - - doc->SetRootContent(NS_STATIC_CAST(nsIContent*, root)); - - // Create the BODY element - nsCOMPtr body; - if ((tag = dont_AddRef(NS_NewAtom("body"))) == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - - if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_HTML, /* XXX */ - tag, - getter_AddRefs(body)))) - return rv; - - - // Attach the BODY to the DOCUMENT - if (NS_FAILED(rv = root->AppendChildTo(body, PR_FALSE))) - return rv; - - // Create the xul:rootwidget element, and indicate that children should - // be recursively generated on demand - nsCOMPtr widget; - if (NS_FAILED(rv = CreateElement(kNameSpaceID_XUL, - rootAtom, - aResource, - getter_AddRefs(widget)))) - return rv; - - if (NS_FAILED(rv = widget->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE))) - return rv; - - // Attach the ROOTWIDGET to the BODY - if (NS_FAILED(rv = body->AppendChildTo(widget, PR_FALSE))) - return rv; - - return NS_OK; + // XXX Remove this method from the interface + NS_NOTREACHED("whoops"); + return NS_ERROR_UNEXPECTED; } NS_IMETHODIMP @@ -661,13 +639,6 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eSet, aProperty, aTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - // fall through if node wasn't created by a XUL template - rv = SetWidgetAttribute(element, aProperty, aTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -779,12 +750,6 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eClear, aProperty, aTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - rv = UnsetWidgetAttribute(element, aProperty, aTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -899,12 +864,6 @@ RDFGenericBuilderImpl::OnChange(nsIRDFResource* aSource, rv = SynchronizeUsingTemplate(templateNode, element, eSet, aProperty, aNewTarget); if (NS_FAILED(rv)) return rv; } -#ifdef FALLBACK_BUILDERS - else { - rv = SetWidgetAttribute(element, aProperty, aNewTarget); - if (NS_FAILED(rv)) return rv; - } -#endif } } return NS_OK; @@ -1020,7 +979,7 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a // Now do the work to change the attribute. There are a couple of // special cases that we need to check for here... if ((elementNameSpaceID == kNameSpaceID_XUL) && - IsItemOrFolder(element) && // XXX IsItemOrFolder(): is this what we really mean? + IsResourceElement(element) && // XXX IsResourceElement(): is this what we really mean? (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kOpenAtom)) { @@ -1058,8 +1017,7 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a } } else if ((elementNameSpaceID == kNameSpaceID_XUL) && - (IsItemOrFolder(element) || // XXX IsItemOrFolder(): is this what we really mean? - IsWidgetInsertionRootElement(element)) && + (IsResourceElement(element)) && (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kIdAtom)) { @@ -1093,6 +1051,9 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a return rv; } + if (! parent) + return NS_ERROR_UNEXPECTED; + if (NS_FAILED(rv = parent->RemoveChildAt(elementIndex, PR_TRUE))) { NS_ERROR("unable to remove element"); return rv; @@ -1145,8 +1106,10 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a } else if ((attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kRefAtom)) { - // Ignore changes to the 'ref=' attribute; the XUL builder - // will take care of that for us. + // Remove all of the template children and rebuild them + rv = RemoveAndRebuildGeneratedChildren(element); + if (NS_FAILED(rv)) return rv; + return NS_OK; } @@ -1235,7 +1198,7 @@ RDFGenericBuilderImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString } if ((elementNameSpaceID == kNameSpaceID_XUL) && - IsItemOrFolder(element) && // XXX Is this what we really mean? + IsResourceElement(element) && // XXX Is this what we really mean? (attrNameSpaceID == kNameSpaceID_None) && (attrNameAtom.get() == kOpenAtom)) { // We are removing the value of the "open" attribute. This may @@ -1300,186 +1263,115 @@ RDFGenericBuilderImpl::OnRemoveAttributeNode(nsIDOMElement* aElement, nsIDOMAttr } +//////////////////////////////////////////////////////////////////////// +// nsITimerCallback methods + +void +RDFGenericBuilderImpl::Notify(nsITimer* aTimer) +{ +} + //////////////////////////////////////////////////////////////////////// // Implementation methods nsresult -RDFGenericBuilderImpl::SetAllAttributesOnElement(nsIContent *aParentNode, nsIContent *aNode, nsIRDFResource *res) +RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement, + nsIRDFResource *aProperty, + nsIRDFResource* aChild, + nsIContent *aRule, + PRBool *aIsMatch) { - // get all arcs out, and if not a containment property, set attribute - nsresult rv = NS_OK; - PRBool markAsContainer = PR_FALSE; - nsCOMPtr arcs; - if (NS_SUCCEEDED(rv = mDB->ArcLabelsOut(res, getter_AddRefs(arcs)))) - { - PRBool hasMore = PR_TRUE; - while(hasMore) - { - rv = arcs->HasMoreElements(&hasMore); - if (NS_FAILED(rv)) break; - if (hasMore == PR_FALSE) break; + nsresult rv; - nsCOMPtr isupports; - if (NS_FAILED(rv = arcs->GetNext(getter_AddRefs(isupports)))) break; + PRInt32 count; + rv = aRule->GetAttributeCount(count); + if (NS_FAILED(rv)) return(rv); - nsCOMPtr property = do_QueryInterface(isupports); - // Ignore properties that are used to indicate "tree-ness" - if (IsContainmentProperty(aNode, property)) - { - markAsContainer = PR_TRUE; - continue; - } - - // Ignore any properties set in ignore attribute - // Note: since node isn't in the content model yet, start with its parent - if (IsIgnoredProperty(aParentNode, property)) - { - continue; - } - - PRInt32 nameSpaceID; - nsCOMPtr tag; - if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) - break; - nsCOMPtr value; - if (NS_FAILED(rv = mDB->GetTarget(res, property, PR_TRUE, getter_AddRefs(value)))) - break; - if (rv == NS_RDF_NO_VALUE) - continue; - nsAutoString s; - if (NS_SUCCEEDED(rv = nsRDFContentUtils::GetTextForNode(value, s))) - { - aNode->SetAttribute(nameSpaceID, tag, s, PR_FALSE); - } - } - } - if (markAsContainer == PR_TRUE) - { - // mark this as a "container" so that we know to - // recursively generate kids if they're asked for. - rv = aNode->SetAttribute(kNameSpaceID_None, kLazyContentAtom, "true", PR_FALSE); - } - return(rv); -} - - -nsresult -RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIRDFResource *aNode, nsIContent *aRule, PRBool *matchingRuleFound) -{ - nsresult rv = NS_OK; - PRInt32 count; - - *matchingRuleFound = PR_FALSE; - - if (NS_FAILED(rv = aRule->GetAttributeCount(count))) - { - return(rv); - } - - *matchingRuleFound = PR_TRUE; - for (PRInt32 loop=0; loop attribAtom; - if (NS_FAILED(rv = aRule->GetAttributeNameAt(loop, attribNameSpaceID, *getter_AddRefs(attribAtom)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsAutoString attribValue; - if (NS_FAILED(rv = aRule->GetAttribute(attribNameSpaceID, attribAtom, attribValue))) - { - *matchingRuleFound = PR_FALSE; - break; - } - -#ifdef DEBUG - nsAutoString nsName; - attribAtom->ToString(nsName); - char *debugName = nsName.ToNewCString(); - if (debugName) - { - delete [] debugName; - debugName = nsnull; - } -#endif + for (PRInt32 loop=0; loop attr; + rv = aRule->GetAttributeNameAt(loop, attrNameSpaceID, *getter_AddRefs(attr)); + if (NS_FAILED(rv)) return rv; // Note: some attributes must be skipped on XUL template rule subtree // never compare against {}:container attribute - if ((attribAtom.get() == kLazyContentAtom) && (attribNameSpaceID == kNameSpaceID_None)) + if ((attr.get() == kLazyContentAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against rdf:property attribute - else if ((attribAtom.get() == kPropertyAtom) && (attribNameSpaceID == kNameSpaceID_RDF)) + else if ((attr.get() == kPropertyAtom) && (attrNameSpaceID == kNameSpaceID_RDF)) continue; // never compare against rdf:instanceOf attribute - else if ((attribAtom.get() == kInstanceOfAtom) && (attribNameSpaceID == kNameSpaceID_RDF)) + else if ((attr.get() == kInstanceOfAtom) && (attrNameSpaceID == kNameSpaceID_RDF)) continue; // never compare against {}:id attribute - else if ((attribAtom.get() == kIdAtom) && (attribNameSpaceID == kNameSpaceID_None)) - continue; - // never compare against {}:rootcontainment attribute - else if ((attribAtom.get() == kRootcontainmentAtom) && (attribNameSpaceID == kNameSpaceID_None)) - continue; - // never compare against {}:subcontainment attribute - else if ((attribAtom.get() == kSubcontainmentAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kIdAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against {}:xulcontentsgenerated attribute - else if ((attribAtom.get() == kXULContentsGeneratedAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kXULContentsGeneratedAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; // never compare against {}:itemcontentsgenerated attribute (bogus) - else if ((attribAtom.get() == kTemplateContentsGeneratedAtom) && (attribNameSpaceID == kNameSpaceID_None)) + else if ((attr.get() == kTemplateContentsGeneratedAtom) && (attrNameSpaceID == kNameSpaceID_None)) continue; - else if ((attribNameSpaceID == kNameSpaceID_None) && (attribAtom.get() == kIsContainerAtom)) - { - // check and see if aNode is a container - PRBool containerFlag = IsContainer(aRule, aNode); - if (containerFlag && (!attribValue.EqualsIgnoreCase("true"))) - { - *matchingRuleFound = PR_FALSE; - break; - } - else if (!containerFlag && (!attribValue.EqualsIgnoreCase("false"))) - { - *matchingRuleFound = PR_FALSE; - break; - } - } - else - { - nsCOMPtr attribAtomResource; + nsAutoString value; + rv = aRule->GetAttribute(attrNameSpaceID, attr, value); + if (NS_FAILED(rv)) return rv; - if (NS_FAILED(rv = GetResource(attribNameSpaceID, attribAtom, getter_AddRefs(attribAtomResource)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsCOMPtr aResult; - if (NS_FAILED(rv = mDB->GetTarget(aNode, attribAtomResource, PR_TRUE, getter_AddRefs(aResult)))) - { - *matchingRuleFound = PR_FALSE; - break; - } - nsAutoString resultStr; - if (NS_FAILED(rv = nsRDFContentUtils::GetTextForNode(aResult, resultStr))) - { - *matchingRuleFound = PR_FALSE; - break; - } - if (!attribValue.Equals(resultStr)) - { - *matchingRuleFound = PR_FALSE; - break; - } + if ((attrNameSpaceID == kNameSpaceID_None) && (attr.get() == kIsContainerAtom)) { + // check and see if aChild is a container + PRBool isContainer = IsContainer(aRule, aChild); + if (isContainer && (!value.EqualsIgnoreCase("true"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + else if (!isContainer && (!value.EqualsIgnoreCase("false"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } } + else if ((attrNameSpaceID == kNameSpaceID_None) && (attr.get() == kIsEmptyAtom)) { + PRBool isEmpty = IsEmpty(aRule, aChild); + if (isEmpty && (!value.EqualsIgnoreCase("true"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + else if (!isEmpty && (!value.EqualsIgnoreCase("false"))) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + } + else { + nsCOMPtr property; + rv = GetResource(attrNameSpaceID, attr, getter_AddRefs(property)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr target; + rv = mDB->GetTarget(aChild, property, PR_TRUE, getter_AddRefs(target)); + if (NS_FAILED(rv)) return rv; + + nsAutoString targetStr; + rv = nsRDFContentUtils::GetTextForNode(target, targetStr); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get text for target"); + if (NS_FAILED(rv)) return rv; + + if (!value.Equals(targetStr)) { + *aIsMatch = PR_FALSE; + return NS_OK; + } + } } - return(rv); + + *aIsMatch = PR_TRUE; + return NS_OK; } nsresult -RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent **aTemplate) +RDFGenericBuilderImpl::FindTemplate(nsIContent* aElement, + nsIRDFResource *aProperty, + nsIRDFResource* aChild, + nsIContent **aTemplate) { nsresult rv; @@ -1509,15 +1401,6 @@ RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent if (tag.get() != kTemplateAtom) continue; -#if 0 - // check for debugging - nsAutoString debugValue; - if (NS_SUCCEEDED(rv = tmpl->GetAttribute(kNameSpaceID_None, kDebugAtom, debugValue))) - { - debugValue = "true"; - } -#endif - // found a template; check against any (optional) rules PRInt32 numRuleChildren, numRulesFound = 0; rv = tmpl->ChildCount(numRuleChildren); @@ -1542,11 +1425,11 @@ RDFGenericBuilderImpl::FindTemplateForResource(nsIRDFResource *aNode, nsIContent if (ruleTag.get() == kRuleAtom) { ++numRulesFound; - PRBool matchingRuleFound = PR_FALSE; - rv = IsTemplateRuleMatch(aNode, aRule, &matchingRuleFound); + PRBool isMatch = PR_FALSE; + rv = IsTemplateRuleMatch(aElement, aProperty, aChild, aRule, &isMatch); if (NS_FAILED(rv)) return rv; - if (matchingRuleFound) { + if (isMatch) { // found a matching rule, use it as the template *aTemplate = aRule; NS_ADDREF(*aTemplate); @@ -1583,14 +1466,6 @@ RDFGenericBuilderImpl::IsIgnoreableAttribute(PRInt32 aNameSpaceID, nsIAtom* aAtt else if ((aAttribute == kInstanceOfAtom) && (aNameSpaceID == kNameSpaceID_RDF)) { return PR_TRUE; } - // never copy {}:rootcontainment attribute - else if ((aAttribute == kRootcontainmentAtom) && (aNameSpaceID == kNameSpaceID_None)) { - return PR_TRUE; - } - // never copy {}:subcontainment attribute - else if ((aAttribute == kSubcontainmentAtom) && (aNameSpaceID == kNameSpaceID_None)) { - return PR_TRUE; - } // never copy {}:ID attribute else if ((aAttribute == kIdAtom) && (aNameSpaceID == kNameSpaceID_None)) { return PR_TRUE; @@ -1608,11 +1483,54 @@ RDFGenericBuilderImpl::IsIgnoreableAttribute(PRInt32 aNameSpaceID, nsIAtom* aAtt } } + +nsresult +RDFGenericBuilderImpl::GetSubstitutionText(nsIRDFResource* aResource, + const nsString& aSubstitution, + nsString& aResult) +{ + nsresult rv; + + if (aSubstitution.Find("rdf:") == 0) { + // found an attribute which wants to bind + // its value to RDF so look it up in the + // graph + nsAutoString propertyStr(aSubstitution); + propertyStr.Cut(0,4); + + nsCOMPtr property; + rv = gRDFService->GetUnicodeResource(propertyStr.GetUnicode(), getter_AddRefs(property)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr valueNode; + rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(valueNode)); + if (NS_FAILED(rv)) return rv; + + if (valueNode) { + rv = nsRDFContentUtils::GetTextForNode(valueNode, aResult); + if (NS_FAILED(rv)) return rv; + } + else { + aResult.Truncate(); + } + } + else if (aSubstitution.EqualsIgnoreCase("...")) { + const char *uri = nsnull; + aResource->GetValueConst(&uri); + aResult = uri; + } + else { + aResult = aSubstitution; + } + + return NS_OK; +} + nsresult RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, nsIContent *aRealNode, PRBool aIsUnique, - nsIRDFResource* aResource, + nsIRDFResource* aChild, PRInt32 aNaturalOrderPos) { nsresult rv; @@ -1624,7 +1542,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; nsXPIDLCString resourceCStr; - rv = aResource->GetValue(getter_Copies(resourceCStr)); + rv = aChild->GetValue(getter_Copies(resourceCStr)); if (NS_FAILED(rv)) return rv; nsAutoString tagStr(tag->GetUnicode()); @@ -1651,8 +1569,8 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, rv = tmplKid->GetNameSpaceID(nameSpaceID); if (NS_FAILED(rv)) return rv; - // check whether this item is a containment item for aResource - PRBool isContainmentElement = PR_FALSE; + // check whether this item is the resource element + PRBool isResourceElement = PR_FALSE; if (nameSpaceID == kNameSpaceID_XUL) { nsAutoString idValue; rv = tmplKid->GetAttribute(kNameSpaceID_None, @@ -1661,7 +1579,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (idValue.EqualsIgnoreCase("..."))) { - isContainmentElement = PR_TRUE; + isResourceElement = PR_TRUE; aIsUnique = PR_FALSE; } } @@ -1670,58 +1588,69 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, rv = tmplKid->GetTag(*getter_AddRefs(tag)); if (NS_FAILED(rv)) return rv; + PRBool realKidAlreadyExisted = PR_FALSE; + nsCOMPtr realKid; if (aIsUnique) { - rv = EnsureElementHasGenericChild(aRealNode, - nameSpaceID, - tag, - getter_AddRefs(realKid)); + rv = EnsureElementHasGenericChild(aRealNode, nameSpaceID, tag, getter_AddRefs(realKid)); if (NS_FAILED(rv)) return rv; - // Recurse until we get to a non-unique element. Mark the - // element's contents as being generated so that - // any re-entrant calls don't trigger an infinite recursion. - rv = realKid->SetAttribute(kNameSpaceID_None, - kTemplateContentsGeneratedAtom, - "true", - PR_FALSE); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set contents-generated attribute"); - if (NS_FAILED(rv)) return rv; + if (rv == NS_RDF_ELEMENT_WAS_THERE) { + realKidAlreadyExisted = PR_TRUE; + } + else { + // Mark the element's contents as being generated so + // that any re-entrant calls don't trigger an infinite + // recursion. + rv = realKid->SetAttribute(kNameSpaceID_None, + kTemplateContentsGeneratedAtom, + "true", + PR_FALSE); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set contents-generated attribute"); + if (NS_FAILED(rv)) return rv; + } - rv = BuildContentFromTemplate(tmplKid, realKid, PR_TRUE, aResource, -1); + // Recurse until we get to the resource element. + rv = BuildContentFromTemplate(tmplKid, realKid, PR_TRUE, aChild, -1); if (NS_FAILED(rv)) return rv; } - else if (isContainmentElement) { - rv = CreateElement(nameSpaceID, tag, aResource, getter_AddRefs(realKid)); + else if (isResourceElement) { + rv = CreateElement(nameSpaceID, tag, aChild, getter_AddRefs(realKid)); if (NS_FAILED(rv)) return rv; - if (IsContainer(realKid, aResource)) { + if (IsContainer(realKid, aChild)) { rv = realKid->SetAttribute(kNameSpaceID_None, kContainerAtom, "true", PR_FALSE); if (NS_FAILED(rv)) return rv; // test to see if the container has contents - char* isEmpty = IsEmpty(realKid, aResource) ? "true" : "false"; + char* isEmpty = IsEmpty(realKid, aChild) ? "true" : "false"; rv = realKid->SetAttribute(kNameSpaceID_None, kEmptyAtom, isEmpty, PR_FALSE); if (NS_FAILED(rv)) return rv; } } else if ((tag.get() == kTextAtom) && (nameSpaceID == kNameSpaceID_XUL)) { - // is replaced by text of the + // is replaced by text of the // actual value of the rdf:resource attribute for the given node nsAutoString attrValue; - rv = tmplKid->GetAttribute(kNameSpaceID_RDF, kResourceAtom, attrValue); + rv = tmplKid->GetAttribute(kNameSpaceID_None, kValueAtom, attrValue); if (NS_FAILED(rv)) return rv; if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (attrValue.Length() > 0)) { - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(attrValue.GetUnicode(), getter_AddRefs(property)); + nsAutoString text; + rv = GetSubstitutionText(aChild, attrValue, text); if (NS_FAILED(rv)) return rv; - nsCOMPtr text; - rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(text)); + nsCOMPtr content; + rv = nsComponentManager::CreateInstance(kTextNodeCID, + nsnull, + nsITextContent::GetIID(), + getter_AddRefs(content)); if (NS_FAILED(rv)) return rv; - rv = nsRDFContentUtils::AttachTextNode(aRealNode, text); + rv = content->SetText(text.GetUnicode(), text.Length(), PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = aRealNode->AppendChildTo(nsCOMPtr( do_QueryInterface(content) ), PR_FALSE); if (NS_FAILED(rv)) return rv; } } @@ -1763,7 +1692,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; } - if (realKid) { + if (realKid && !realKidAlreadyExisted) { // save a reference (its ID) to the template node that was used nsAutoString templateID; rv = tmplKid->GetAttribute(kNameSpaceID_None, kIdAtom, templateID); @@ -1778,7 +1707,7 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; // set natural order hint - if ((aNaturalOrderPos > 0) && (isContainmentElement)) { + if ((aNaturalOrderPos > 0) && (isResourceElement)) { nsAutoString pos, zero("0000"); pos.Append(aNaturalOrderPos, 10); if (pos.Length() < 4) { @@ -1816,49 +1745,29 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - if (attribValue.Find("rdf:") == 0) { - // found an attribute which wants to bind - // its value to RDF so look it up in the - // graph - attribValue.Cut(0,4); + nsAutoString text; + rv = GetSubstitutionText(aChild, attribValue, text); + if (NS_FAILED(rv)) return rv; - nsCOMPtr property; - rv = gRDFService->GetUnicodeResource(attribValue.GetUnicode(), getter_AddRefs(property)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr valueNode; - rv = mDB->GetTarget(aResource, property, PR_TRUE, getter_AddRefs(valueNode)); - if (NS_FAILED(rv)) return rv; - - if (valueNode) { - rv = nsRDFContentUtils::GetTextForNode(valueNode, attribValue); - if (NS_FAILED(rv)) return rv; - } - else { - attribValue.Truncate(); - } - } - else if (attribValue.EqualsIgnoreCase("...")) { - const char *uri = nsnull; - aResource->GetValueConst(&uri); - attribValue = uri; - } - - realKid->SetAttribute(attribNameSpaceID, attribName, attribValue, PR_FALSE); + rv = realKid->SetAttribute(attribNameSpaceID, attribName, text, PR_FALSE); + if (NS_FAILED(rv)) return rv; } } } - // Note: add into tree, but only sort if its a containment element! - if ((nsnull != XULSortService) && (isContainmentElement == PR_TRUE)) { - rv = XULSortService->InsertContainerNode(aRealNode, realKid); - if (NS_FAILED(rv)) { + // We'll _already_ have added the unique elements. + if (! aIsUnique) { + // Note: add into tree, but only sort if its a resource element! + if ((nsnull != XULSortService) && (isResourceElement)) { + rv = XULSortService->InsertContainerNode(aRealNode, realKid); + if (NS_FAILED(rv)) { + aRealNode->AppendChildTo(realKid, PR_TRUE); + } + } + else { aRealNode->AppendChildTo(realKid, PR_TRUE); } } - else { - aRealNode->AppendChildTo(realKid, PR_TRUE); - } // If item says its "open", then recurve now and build up its children nsAutoString openState; @@ -1879,85 +1788,24 @@ RDFGenericBuilderImpl::BuildContentFromTemplate(nsIContent *aTemplateNode, nsresult RDFGenericBuilderImpl::CreateWidgetItem(nsIContent *aElement, nsIRDFResource *aProperty, - nsIRDFResource *aValue, + nsIRDFResource *aChild, PRInt32 aNaturalOrderPos) { nsCOMPtr tmpl; nsresult rv; - rv = FindTemplateForResource(aValue, getter_AddRefs(tmpl)); + rv = FindTemplate(aElement, aProperty, aChild, getter_AddRefs(tmpl)); if (NS_FAILED(rv)) { -#ifdef FALLBACK_BUILDERS - return AddWidgetItem(aElement, aProperty, aValue, aNaturalOrderPos); -#else + // No template. Just bail. return NS_OK; -#endif - } - - // The "container" node which will be used to build children. - nsCOMPtr container; - PRBool isRoot = PR_FALSE; - - // if template specifies a rootcontainment attribute, get it - // and determine if we are building children off of the root - nsAutoString rootAttrValue; - rv = tmpl->GetAttribute(kNameSpaceID_None, - kRootcontainmentAtom, - rootAttrValue); - if (NS_FAILED(rv)) return rv; - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - // XXX Ick. Can we remember this somehow? - nsCOMPtr rootAtom = NS_NewAtom(rootAttrValue); - if (! rootAtom) return NS_ERROR_OUT_OF_MEMORY; - - PRInt32 nameSpaceID; - rv = aElement->GetNameSpaceID(nameSpaceID); - if (NS_FAILED(rv)) return rv; - - if (nameSpaceID == kNameSpaceID_XUL) { - nsCOMPtr tag; - rv = aElement->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - if (tag == rootAtom) - isRoot = PR_TRUE; - } - } - - // if template specifies a subcontainment attribute, get it - // and make sure aElement contains it (if not the root). - if (! isRoot) { - nsAutoString attrValue; - rv = tmpl->GetAttribute(kNameSpaceID_None, - kSubcontainmentAtom, - attrValue); - if (NS_FAILED(rv)) return rv; - - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - // XXX Ick. Can we remember this somehow? - nsCOMPtr childrenAtom = NS_NewAtom(attrValue); - if (! childrenAtom) return NS_ERROR_OUT_OF_MEMORY; - - rv = EnsureElementHasGenericChild(aElement, - kNameSpaceID_XUL, - childrenAtom, - getter_AddRefs(container)); - if (NS_FAILED(rv)) return rv; - } - } - - // Otherwise, just use the element as the root. - if (! container) { - container = dont_QueryInterface(aElement); } rv = BuildContentFromTemplate(tmpl, - container, + aElement, PR_TRUE, - aValue, + aChild, aNaturalOrderPos); - + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to build content from template"); return rv; } @@ -2076,6 +1924,14 @@ RDFGenericBuilderImpl::SynchronizeUsingTemplate(nsIContent* aTemplateNode, } + +nsresult +RDFGenericBuilderImpl::RemoveWidgetItem(nsIContent* aElement, nsIRDFResource* aProperty, nsIRDFResource* aValue) +{ + return NS_OK; +} + + nsresult RDFGenericBuilderImpl::CreateContainerContents(nsIContent* aElement, nsIRDFResource* aResource) { @@ -2304,73 +2160,25 @@ RDFGenericBuilderImpl::EnsureElementHasGenericChild(nsIContent* parent, *result = element; NS_ADDREF(*result); + return NS_RDF_ELEMENT_WAS_CREATED; + } + else { + return NS_RDF_ELEMENT_WAS_THERE; } - return NS_OK; } PRBool -RDFGenericBuilderImpl::IsItemOrFolder(nsIContent* aElement) +RDFGenericBuilderImpl::IsResourceElement(nsIContent* aElement) { - // XXX It seems like this should be a pure virtual method that - // subclasses implement? - - // XXX All of the callers of this method actually only seem to - // care if the element is a "folder". - - // Returns PR_TRUE if the element is an "item" or a "folder" in - // the widget. nsresult rv; + nsAutoString str; + rv = aElement->GetAttribute(kNameSpaceID_None, kIdAtom, str); + if (NS_FAILED(rv)) return PR_FALSE; - nsCOMPtr itemAtom; - nsCOMPtr folderAtom; - if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom))) || - NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) { - return rv; - } - - // "element" must be itemAtom - nsCOMPtr tag; - if (NS_FAILED(rv = aElement->GetTag(*getter_AddRefs(tag)))) - return PR_FALSE; - - if (tag != itemAtom && tag != folderAtom) - return PR_FALSE; - - return PR_TRUE; + return (rv == NS_CONTENT_ATTR_HAS_VALUE) ? PR_TRUE : PR_FALSE; } -PRBool -RDFGenericBuilderImpl::IsWidgetInsertionRootElement(nsIContent* element) -{ - // Returns PR_TRUE if the element is the root point to insert new items. - nsresult rv; - - nsCOMPtr rootAtom; - if (NS_FAILED(rv = GetInsertionRootAtom(getter_AddRefs(rootAtom)))) { - return rv; - } - - PRInt32 nameSpaceID; - if (NS_FAILED(rv = element->GetNameSpaceID(nameSpaceID))) { - NS_ERROR("unable to get namespace ID"); - return PR_FALSE; - } - - if (nameSpaceID != kNameSpaceID_XUL) - return PR_FALSE; // not a XUL element - - nsCOMPtr elementTag; - if (NS_FAILED(rv = element->GetTag(*getter_AddRefs(elementTag)))) { - NS_ERROR("unable to get tag"); - return PR_FALSE; - } - - if (elementTag != rootAtom) - return PR_FALSE; // not the place to insert a child - - return PR_TRUE; -} PRBool RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResource* aProperty) @@ -2703,6 +2511,22 @@ RDFGenericBuilderImpl::GetResource(PRInt32 aNameSpaceID, nsresult RDFGenericBuilderImpl::OpenWidgetItem(nsIContent* aElement) { +#ifdef PR_LOGGING + if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { + nsresult rv; + + nsCOMPtr tag; + rv = aElement->GetTag(*getter_AddRefs(tag)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tagStr; + tag->ToString(tagStr); + + PR_LOG(gLog, PR_LOG_DEBUG, + ("rdfgeneric open-widget-item %s", + (const char*) nsCAutoString(tagStr))); + } +#endif return CreateContents(aElement); } @@ -2712,49 +2536,88 @@ RDFGenericBuilderImpl::CloseWidgetItem(nsIContent* aElement) { nsresult rv; - // Find the tag that contains the children so that we can remove all of - // the children. - nsCOMPtr parentAtom; - rv = GetItemAtomThatContainsTheChildren(getter_AddRefs(parentAtom)); +#ifdef PR_LOGGING + if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { + nsCOMPtr tag; + rv = aElement->GetTag(*getter_AddRefs(tag)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tagStr; + tag->ToString(tagStr); + + PR_LOG(gLog, PR_LOG_DEBUG, + ("rdfgeneric close-widget-item %s", + (const char*) nsCAutoString(tagStr))); + } +#endif + + // Find the tag that contains the children so that we can remove + // all of the children. + // + // XXX We make a bit of a leap here and assume that the same + // template that was used to generate _us_ was used to generate + // our _kids_. I'm sure this'll break when we do toolbars or + // something. + nsAutoString tmplID; + rv = aElement->GetAttribute(kNameSpaceID_None, kTemplateAtom, tmplID); if (NS_FAILED(rv)) return rv; - nsCOMPtr parentNode; - nsCOMPtr tag; - rv = aElement->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; // XXX fatal + if (rv != NS_CONTENT_ATTR_HAS_VALUE) + return NS_OK; - if (tag == parentAtom) { - parentNode = dont_QueryInterface(aElement); - rv = NS_OK; + nsCOMPtr xulDoc = do_QueryInterface(mDocument); + if (! xulDoc) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplDOMEle; + rv = xulDoc->GetElementById(tmplID, getter_AddRefs(tmplDOMEle)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr tmpl = do_QueryInterface(tmplDOMEle); + if (! tmpl) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplParent; + rv = tmpl->GetParent(*getter_AddRefs(tmplParent)); + if (NS_FAILED(rv)) return rv; + + NS_ASSERTION(tmplParent != nsnull, "template node has no parent"); + if (! tmplParent) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr tmplParentTag; + rv = tmplParent->GetTag(*getter_AddRefs(tmplParentTag)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr childcontainer; + if ((tmplParentTag == kRuleAtom) || (tmplParentTag == kTemplateAtom)) { + childcontainer = dont_QueryInterface(aElement); } else { - rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, parentAtom, getter_AddRefs(parentNode)); + rv = nsRDFContentUtils::FindChildByTag(aElement, + kNameSpaceID_XUL, + tmplParentTag, + getter_AddRefs(childcontainer)); + + if (NS_FAILED(rv)) return rv; + + if (rv == NS_RDF_NO_VALUE) { + // No tag; must've already been closed + return NS_OK; + } } - if (rv == NS_RDF_NO_VALUE) { - // No tag; must've already been closed - return NS_OK; - } - - NS_ASSERTION(NS_SUCCEEDED(rv), "severe error retrieving parent node for removal"); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr ds; - rv = mDocument->GetDocumentDataSource(getter_AddRefs(ds)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get document datasource"); - if (NS_FAILED(rv)) return rv; - PRInt32 count; - rv = parentNode->ChildCount(count); + rv = childcontainer->ChildCount(count); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get count of the parent's children"); if (NS_FAILED(rv)) return rv; while (--count >= 0) { nsCOMPtr child; - rv = parentNode->ChildAt(count, *getter_AddRefs(child)); + rv = childcontainer->ChildAt(count, *getter_AddRefs(child)); if (NS_FAILED(rv)) return rv; - rv = parentNode->RemoveChildAt(count, PR_TRUE); + rv = childcontainer->RemoveChildAt(count, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child"); do { @@ -2786,18 +2649,67 @@ RDFGenericBuilderImpl::CloseWidgetItem(nsIContent* aElement) // This is a _total_ hack to make sure that any XUL we blow away // gets rebuilt. - rv = parentNode->UnsetAttribute(kNameSpaceID_None, - kXULContentsGeneratedAtom, - PR_FALSE); + rv = childcontainer->UnsetAttribute(kNameSpaceID_None, + kXULContentsGeneratedAtom, + PR_FALSE); if (NS_FAILED(rv)) return rv; - rv = parentNode->SetAttribute(kNameSpaceID_None, - kLazyContentAtom, - "true", - PR_FALSE); + rv = childcontainer->SetAttribute(kNameSpaceID_None, + kLazyContentAtom, + "true", + PR_FALSE); if (NS_FAILED(rv)) return rv; return NS_OK; } +nsresult +RDFGenericBuilderImpl::RemoveAndRebuildGeneratedChildren(nsIContent* aElement) +{ + nsresult rv; + + PRInt32 count; + rv = aElement->ChildCount(count); + if (NS_FAILED(rv)) return rv; + + while (--count >= 0) { + nsCOMPtr child; + rv = aElement->ChildAt(count, *getter_AddRefs(child)); + if (NS_FAILED(rv)) return rv; + + nsAutoString tmplID; + rv = child->GetAttribute(kNameSpaceID_None, kTemplateAtom, tmplID); + if (NS_FAILED(rv)) return rv; + + if (rv != NS_CONTENT_ATTR_HAS_VALUE) + continue; + + // It's a generated element. Remove it, and set its document + // to null so that it'll get knocked out of the XUL doc's + // resource-to-element map. + rv = aElement->RemoveChildAt(count, PR_TRUE); + NS_ASSERTION(NS_SUCCEEDED(rv), "error removing child"); + + rv = child->SetDocument(nsnull, PR_TRUE); + if (NS_FAILED(rv)) return rv; + } + + // Clear the contents-generated attribute so that the next time we + // come back, we'll regenerate the kids we just killed. + rv = aElement->UnsetAttribute(kNameSpaceID_None, + kTemplateContentsGeneratedAtom, + PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = aElement->UnsetAttribute(kNameSpaceID_None, + kContainerContentsGeneratedAtom, + PR_FALSE); + if (NS_FAILED(rv)) return rv; + + rv = CreateContents(aElement); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + diff --git a/rdf/content/src/nsXULTreeElement.cpp b/rdf/content/src/nsXULTreeElement.cpp deleted file mode 100644 index 8feefaa2d6c1..000000000000 --- a/rdf/content/src/nsXULTreeElement.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- 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. - */ - -#include "nsCOMPtr.h" -#include "nsIRDFCompositeDataSource.h" -#include "nsIServiceManager.h" -#include "nsRDFCID.h" -#include "nsXULTreeElement.h" - -NS_IMPL_ISUPPORTS_INHERITED(nsXULTreeElement, nsXULElement, nsIDOMXULTreeElement); - -NS_IMETHODIMP -nsXULTreeElement::GetDatabase(nsIRDFCompositeDataSource** aDatabase) -{ - NS_PRECONDITION(aDatabase != nsnull, "null ptr"); - if (! aDatabase) - return NS_ERROR_NULL_POINTER; - - *aDatabase = mDatabase; - NS_IF_ADDREF(*aDatabase); - return NS_OK; -} - - -NS_IMETHODIMP -nsXULTreeElement::SetDatabase(nsIRDFCompositeDataSource* aDatabase) -{ - // XXX maybe someday you'll be allowed to change it. - NS_PRECONDITION(mDatabase == nsnull, "already initialized"); - if (mDatabase) - return NS_ERROR_ALREADY_INITIALIZED; - - mDatabase = aDatabase; - - // XXX reconstruct the entire tree now! - - return NS_OK; -} diff --git a/rdf/content/src/nsXULTreeElement.h b/rdf/content/src/nsXULTreeElement.h deleted file mode 100644 index ed9dd9389147..000000000000 --- a/rdf/content/src/nsXULTreeElement.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- 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 nsXULTreeElement_h__ -#define nsXULTreeElement_h__ - -#include "nsXULElement.h" -#include "nsIDOMXULTreeElement.h" -#include "nsIRDFCompositeDataSource.h" - -class nsXULTreeElement : public nsXULElement, - public nsIDOMXULTreeElement -{ -private: - nsCOMPtr mDatabase; - -public: - nsXULTreeElement(nsIDOMXULElement* aOuter) - : nsXULElement(aOuter) - { - } - - 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 -}; - - -#endif // nsXULTreeElement_h__ diff --git a/rdf/datasource/src/nsXULContentSink.cpp b/rdf/datasource/src/nsXULContentSink.cpp index b86084d3bf25..54be467ba1f3 100644 --- a/rdf/datasource/src/nsXULContentSink.cpp +++ b/rdf/datasource/src/nsXULContentSink.cpp @@ -1292,10 +1292,10 @@ XULContentSinkImpl::GetXULIDAttribute(const nsIParserNode& aNode, nsAutoString id = aNode.GetValueAt(i); nsRDFParserUtils::StripAndConvert(id); - nsAutoString uri; + nsCAutoString uri; nsRDFContentUtils::MakeElementURI(mDocument, id, uri); - return gRDFService->GetUnicodeResource(uri.GetUnicode(), aResource); + return gRDFService->GetResource(uri, aResource); } // Otherwise, we couldn't find anything, so just gensym one... diff --git a/rdf/macbuild/rdf.mcp b/rdf/macbuild/rdf.mcp index 88c4d231c4da..75fd93475a24 100644 Binary files a/rdf/macbuild/rdf.mcp and b/rdf/macbuild/rdf.mcp differ diff --git a/rdf/resources/customize.xul b/rdf/resources/customize.xul index 9b2eccbe7f9b..9d6394d72c6d 100644 --- a/rdf/resources/customize.xul +++ b/rdf/resources/customize.xul @@ -53,11 +53,13 @@ + onclick="selected()" + ref="NC:SidebarRoot" > @@ -75,9 +78,6 @@ Name - - - diff --git a/rdf/resources/dom-test-1.xul b/rdf/resources/dom-test-1.xul index 7601f0f7dbae..1712ce222eae 100644 --- a/rdf/resources/dom-test-1.xul +++ b/rdf/resources/dom-test-1.xul @@ -71,17 +71,14 @@ var tree = document.getElementById("tree"); dump("tree = " + tree + "\n"); - var body = tree.childNodes[2]; // template, treehead, treechildren - dump("body = " + body + "\n"); - - var currentRef = body.getAttribute("ref"); + var currentRef = tree.getAttribute("ref"); dump("currentRef = " + currentRef + "\n"); if (currentRef == "NC:BookmarksRoot") { - body.setAttribute("ref", "NC:PersonalToolbarFolder"); + tree.setAttribute("ref", "NC:PersonalToolbarFolder"); } else { - body.setAttribute("ref", "NC:BookmarksRoot"); + tree.setAttribute("ref", "NC:BookmarksRoot"); } } @@ -92,31 +89,35 @@ Swap Body (Bookmarks Root/Personal Toolbar Folder) - + @@ -125,8 +126,6 @@ URL - - diff --git a/rdf/resources/flash.xul b/rdf/resources/flash.xul index b50c57507b50..e07b72439d48 100644 --- a/rdf/resources/flash.xul +++ b/rdf/resources/flash.xul @@ -38,31 +38,35 @@ @@ -78,7 +82,5 @@ &tree.header.time.label; - - diff --git a/suite/browser/hiddenWindow.xul b/suite/browser/hiddenWindow.xul index af134a2428f0..ae81811c03fc 100644 --- a/suite/browser/hiddenWindow.xul +++ b/suite/browser/hiddenWindow.xul @@ -484,7 +484,7 @@ Contributor(s): ______________________________________. --> datasources="rdf:bookmarks rdf:files rdf:find" id="NC:BookmarksRoot">