Replace nsRDFContentUtils with nsXULContentUtils, which can be acquired as a service. This allows it to keep cached member variables to other frequently-accessed services.

This commit is contained in:
waterson%netscape.com 1999-09-07 02:51:13 +00:00
Родитель 5eecd7bc1a
Коммит 49ac7e179a
17 изменённых файлов: 406 добавлений и 882 удалений

Просмотреть файл

@ -63,7 +63,7 @@
#include "nsISupportsArray.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsRDFDOMNodeList.h"
#include "nsStyleConsts.h"
#include "nsIStyleSheet.h"
@ -127,6 +127,7 @@ static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
static NS_DEFINE_IID(kIDOMEventTargetIID, NS_IDOMEVENTTARGET_IID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_IID(kIXULPopupListenerIID, NS_IXULPOPUPLISTENER_IID);
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
@ -412,6 +413,7 @@ private:
static nsrefcnt gRefCnt;
static nsIRDFService* gRDFService;
static nsINameSpaceManager* gNameSpaceManager;
static nsIXULContentUtils* gXULUtils;
static PRInt32 kNameSpaceID_RDF;
static PRInt32 kNameSpaceID_XUL;
static nsIAtom* kIdAtom;
@ -464,6 +466,7 @@ private:
nsrefcnt RDFElementImpl::gRefCnt;
nsIRDFService* RDFElementImpl::gRDFService;
nsINameSpaceManager* RDFElementImpl::gNameSpaceManager;
nsIXULContentUtils* RDFElementImpl::gXULUtils;
nsIAtom* RDFElementImpl::kIdAtom;
nsIAtom* RDFElementImpl::kRefAtom;
nsIAtom* RDFElementImpl::kClassAtom;
@ -592,16 +595,22 @@ RDFElementImpl::RDFElementImpl(PRInt32 aNameSpaceID, nsIAtom* aTag)
}
rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID,
nsnull,
kINameSpaceManagerIID,
(void**) &gNameSpaceManager);
nsnull,
kINameSpaceManagerIID,
(void**) &gNameSpaceManager);
NS_VERIFY(NS_SUCCEEDED(rv), "unable to create namespace manager");
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager");
if (gNameSpaceManager) {
gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF);
gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL);
}
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get XUL content utils");
}
}
@ -671,6 +680,11 @@ RDFElementImpl::~RDFElementImpl()
NS_IF_RELEASE(gNameSpaceManager);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
EventHandlerMapEntry* entry = kEventHandlerMap;
while (entry->mAttributeName) {
NS_IF_RELEASE(entry->mAttributeAtom);
@ -2497,7 +2511,7 @@ RDFElementImpl::GetAttribute(PRInt32 aNameSpaceID,
// a possibly-absolute URI into a relative ID attribute.
NS_ASSERTION(mDocument != nsnull, "not initialized");
if (nsnull != mDocument) {
nsRDFContentUtils::MakeElementID(mDocument, attr->mValue, aResult);
gXULUtils->MakeElementID(mDocument, attr->mValue, aResult);
}
}
#endif
@ -3061,7 +3075,7 @@ RDFElementImpl::GetIdResource(nsIRDFResource** aResource)
const nsXULAttribute* attr = (const nsXULAttribute*) mAttributes->ElementAt(i);
if ((attr->mNameSpaceID == kNameSpaceID_None) &&
(attr->mName == kIdAtom)) {
return nsRDFContentUtils::MakeElementResource(mDocument, attr->mValue, aResource);
return gXULUtils->MakeElementResource(mDocument, attr->mValue, aResource);
}
}
}
@ -3088,7 +3102,7 @@ RDFElementImpl::GetRefResource(nsIRDFResource** aResource)
if (attr->mName != kRefAtom)
continue;
return nsRDFContentUtils::MakeElementResource(mDocument, attr->mValue, aResource);
return gXULUtils->MakeElementResource(mDocument, attr->mValue, aResource);
}
}

Просмотреть файл

@ -115,7 +115,7 @@
#include "nsLayoutCID.h"
#include "nsParserCIID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsRDFDOMNodeList.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h" // XXX should go away
@ -195,6 +195,7 @@ static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_CID(kXULCommandDispatcherCID, NS_XULCOMMANDDISPATCHER_CID);
static NS_DEFINE_IID(kIXULCommandDispatcherIID, NS_IXULCOMMANDDISPATCHER_IID);
@ -873,6 +874,8 @@ protected:
static nsINameSpaceManager* gNameSpaceManager;
static PRInt32 kNameSpaceID_XUL;
static nsIXULContentUtils* gXULUtils;
nsIContent*
FindContent(const nsIContent* aStartNode,
const nsIContent* aTest1,
@ -959,6 +962,8 @@ nsIRDFResource* XULDocumentImpl::kXUL_element;
nsINameSpaceManager* XULDocumentImpl::gNameSpaceManager;
PRInt32 XULDocumentImpl::kNameSpaceID_XUL;
nsIXULContentUtils* XULDocumentImpl::gXULUtils;
////////////////////////////////////////////////////////////////////////
// ctors & dtors
@ -1019,6 +1024,11 @@ XULDocumentImpl::XULDocumentImpl(void)
#define XUL_NAMESPACE_URI "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
static const char kXULNameSpaceURI[] = XUL_NAMESPACE_URI;
gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL);
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
}
#ifdef PR_LOGGING
@ -1113,6 +1123,11 @@ XULDocumentImpl::~XULDocumentImpl()
NS_IF_RELEASE(kRDF_instanceOf);
NS_IF_RELEASE(kRDF_type);
NS_IF_RELEASE(kXUL_element);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
}
}
@ -2709,7 +2724,9 @@ XULDocumentImpl::SplitProperty(nsIRDFResource* aProperty,
if (! p)
return NS_ERROR_UNEXPECTED;
nsAutoString uri(p);
PRUnichar buf[256];
nsAutoString uri(CBufDescriptor(buf, PR_TRUE, sizeof(buf) / sizeof(PRUnichar), 0));
uri = p;
// First try to split the namespace using the rightmost '#' or '/'
// character.
@ -3150,7 +3167,7 @@ XULDocumentImpl::Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aA
nsresult rv;
nsCOMPtr<nsIRDFResource> source;
rv = nsRDFContentUtils::GetElementResource(aElement, getter_AddRefs(source));
rv = gXULUtils->GetElementResource(aElement, getter_AddRefs(source));
if (NS_FAILED(rv)) return rv;
// No ID, so nothing to persist.
@ -3159,7 +3176,7 @@ XULDocumentImpl::Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aA
// Ick. Construct a resource from the namespace and attribute.
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(aNameSpaceID, aAttribute, getter_AddRefs(property));
rv = gXULUtils->GetResource(aNameSpaceID, aAttribute, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsAutoString value;
@ -3309,7 +3326,7 @@ XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
nsresult rv;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::MakeElementResource(this, aId, getter_AddRefs(resource));
rv = gXULUtils->MakeElementResource(this, aId, getter_AddRefs(resource));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupportsArray> elements;
@ -3362,7 +3379,7 @@ XULDocumentImpl::AddElementToMap(nsIContent* aElement, PRBool aDeep)
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::MakeElementResource(this, value, getter_AddRefs(resource));
rv = gXULUtils->MakeElementResource(this, value, getter_AddRefs(resource));
rv = mResources.Add(resource, aElement);
if (NS_FAILED(rv)) return rv;
@ -3408,7 +3425,7 @@ XULDocumentImpl::RemoveElementFromMap(nsIContent* aElement, PRBool aDeep)
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::MakeElementResource(this, value, getter_AddRefs(resource));
rv = gXULUtils->MakeElementResource(this, value, getter_AddRefs(resource));
rv = mResources.Remove(resource, aElement);
if (NS_FAILED(rv)) return rv;
@ -3612,7 +3629,7 @@ XULDocumentImpl::CreatePopupDocument(nsIContent* aPopupElement, nsIDocument** aR
// Use the absolute URL to retrieve a resource from the RDF
// service that corresponds to the root content.
nsCOMPtr<nsIRDFResource> rootResource;
rv = nsRDFContentUtils::MakeElementResource(this, idValue, getter_AddRefs(rootResource));
rv = gXULUtils->MakeElementResource(this, idValue, getter_AddRefs(rootResource));
if (NS_FAILED(rv)) return rv;
// Tell the builder to create its root from this resrouce.

Просмотреть файл

@ -41,7 +41,7 @@
#include "nsIURL.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "rdf.h"
@ -109,6 +109,8 @@ 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_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_IID(kIDomXulElementIID, NS_IDOMXULELEMENT_IID);
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
@ -186,6 +188,8 @@ private:
static nsIRDFService *gRDFService;
static nsIXULContentUtils *gXULUtils;
nsresult FindTreeElement(nsIContent* aElement,nsIContent** aTreeElement);
nsresult FindTreeChildrenElement(nsIContent *tree, nsIContent **treeBody);
nsresult GetSortColumnIndex(nsIContent *tree, const nsString&sortResource, const nsString& sortDirection, PRInt32 *colIndex);
@ -221,6 +225,8 @@ nsICollation *XULSortServiceImpl::collationService = nsnull;
nsIRDFService *XULSortServiceImpl::gRDFService = nsnull;
nsrefcnt XULSortServiceImpl::gRefCnt = 0;
nsIXULContentUtils *XULSortServiceImpl::gXULUtils = nsnull;
nsIAtom* XULSortServiceImpl::kTreeAtom;
nsIAtom* XULSortServiceImpl::kTreeBodyAtom;
nsIAtom* XULSortServiceImpl::kTreeCellAtom;
@ -275,6 +281,12 @@ XULSortServiceImpl::XULSortServiceImpl(void)
NS_ERROR("couldn't create rdf service");
}
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get XUL content utils");
nsILocaleFactory *localeFactory = nsnull;
nsILocale *locale = nsnull;
@ -369,8 +381,16 @@ XULSortServiceImpl::~XULSortServiceImpl(void)
NS_IF_RELEASE(collationService);
collationService = nsnull;
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
if (gRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
}
}
@ -1120,7 +1140,7 @@ XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, so
for (loop = 0; loop < numElements; loop++)
{
nsIRDFResource *resource;
nsRDFContentUtils::GetElementResource(flatArray[loop], &resource);
gXULUtils->GetElementResource(flatArray[loop], &resource);
// Note that we don't release; see part deux below...
}
@ -1137,7 +1157,7 @@ XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, so
for (loop = 0; loop < numElements; loop++)
{
nsIRDFResource *resource;
nsRDFContentUtils::GetElementResource(flatArray[loop], &resource);
gXULUtils->GetElementResource(flatArray[loop], &resource);
nsrefcnt refcnt;
NS_RELEASE2(resource, refcnt);
NS_RELEASE(resource);
@ -1307,7 +1327,7 @@ XULSortServiceImpl::InsertContainerNode(nsIContent *container, nsIContent *node,
&& (rv == NS_CONTENT_ATTR_HAS_VALUE))
{
nsCOMPtr<nsIRDFResource> containerRes;
rv = nsRDFContentUtils::MakeElementResource(doc, id, getter_AddRefs(containerRes));
rv = gXULUtils->MakeElementResource(doc, id, getter_AddRefs(containerRes));
if (NS_SUCCEEDED(rv)) {
rv = sortInfo.db->HasAssertion(containerRes,

Просмотреть файл

@ -62,7 +62,7 @@
#include "nsIXULSortService.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
@ -93,8 +93,8 @@ 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);
static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
static NS_DEFINE_CID(kIHTMLElementFactoryIID, NS_IHTML_ELEMENT_FACTORY_IID);
@ -277,6 +277,7 @@ protected:
static nsIRDFContainerUtils* gRDFContainerUtils;
static nsINameSpaceManager* gNameSpaceManager;
static nsIHTMLElementFactory* gHTMLElementFactory;
static nsIXULContentUtils* gXULUtils;
static nsIAtom* kContainerAtom;
static nsIAtom* kContainerContentsGeneratedAtom;
@ -358,6 +359,7 @@ nsIRDFService* RDFGenericBuilderImpl::gRDFService;
nsIRDFContainerUtils* RDFGenericBuilderImpl::gRDFContainerUtils;
nsINameSpaceManager* RDFGenericBuilderImpl::gNameSpaceManager;
nsIHTMLElementFactory* RDFGenericBuilderImpl::gHTMLElementFactory;
nsIXULContentUtils* RDFGenericBuilderImpl::gXULUtils;
nsIRDFResource* RDFGenericBuilderImpl::kNC_Title;
nsIRDFResource* RDFGenericBuilderImpl::kNC_child;
@ -441,11 +443,28 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void)
NS_IF_RELEASE(kRDF_instanceOf);
NS_IF_RELEASE(kXUL_element);
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
nsServiceManager::ReleaseService(kXULSortServiceCID, gXULSortService);
if (gRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
if (gRDFContainerUtils) {
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
gRDFContainerUtils = nsnull;
}
if (gXULSortService) {
nsServiceManager::ReleaseService(kXULSortServiceCID, gXULSortService);
gXULSortService = nsnull;
}
NS_RELEASE(gNameSpaceManager);
NS_IF_RELEASE(gHTMLElementFactory);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
}
}
@ -529,7 +548,7 @@ RDFGenericBuilderImpl::Init()
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kXULSortServiceCID,
kIXULSortServiceIID,
nsCOMTypeInfo<nsIXULSortService>::GetIID(),
(nsISupports**) &gXULSortService);
if (NS_FAILED(rv)) return rv;
@ -538,6 +557,11 @@ RDFGenericBuilderImpl::Init()
kIHTMLElementFactoryIID,
(void**) &gHTMLElementFactory);
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
if (NS_FAILED(rv)) return rv;
}
#ifdef PR_LOGGING
@ -665,7 +689,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
nsresult rv;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::GetElementRefResource(aElement, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(aElement, getter_AddRefs(resource));
if (NS_SUCCEEDED(rv)) {
// The element has a resource; that means that it corresponds
// to something in the graph, so we need to go to the graph to
@ -698,7 +722,7 @@ RDFGenericBuilderImpl::OpenContainer(nsIContent* aElement)
return NS_OK;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::GetElementRefResource(aElement, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(aElement, getter_AddRefs(resource));
// If it has no resource, there's nothing that we need to be
// concerned about here.
@ -917,7 +941,7 @@ RDFGenericBuilderImpl::CreateElement(PRInt32 aNameSpaceID,
if (NS_FAILED(rv)) return rv;
nsAutoString id;
rv = nsRDFContentUtils::MakeElementID(doc, nsAutoString(uri), id);
rv = gXULUtils->MakeElementID(doc, nsAutoString(uri), id);
if (NS_FAILED(rv)) return rv;
rv = result->SetAttribute(kNameSpaceID_None, kIdAtom, id, PR_FALSE);
@ -1376,7 +1400,7 @@ RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement,
}
else {
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(attrNameSpaceID, attr, getter_AddRefs(property));
rv = gXULUtils->GetResource(attrNameSpaceID, attr, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> target;
@ -1384,7 +1408,7 @@ RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement,
if (NS_FAILED(rv)) return rv;
nsAutoString targetStr;
rv = nsRDFContentUtils::GetTextForNode(target, targetStr);
rv = gXULUtils->GetTextForNode(target, targetStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get text for target");
if (NS_FAILED(rv)) return rv;
@ -1540,7 +1564,7 @@ RDFGenericBuilderImpl::GetSubstitutionText(nsIRDFResource* aResource,
if (NS_FAILED(rv)) return rv;
if (valueNode) {
rv = nsRDFContentUtils::GetTextForNode(valueNode, aResult);
rv = gXULUtils->GetTextForNode(valueNode, aResult);
if (NS_FAILED(rv)) return rv;
}
else {
@ -1838,7 +1862,7 @@ RDFGenericBuilderImpl::AddPersistentAttributes(nsIContent* aTemplateNode, nsIRDF
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(nameSpaceID, tag, getter_AddRefs(property));
rv = gXULUtils->GetResource(nameSpaceID, tag, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> target;
@ -1937,7 +1961,7 @@ RDFGenericBuilderImpl::SynchronizeUsingTemplate(nsIContent* aTemplateNode,
if (property.get() == aProperty) {
nsAutoString text("");
rv = nsRDFContentUtils::GetTextForNode(aValue, text);
rv = gXULUtils->GetTextForNode(aValue, text);
if (NS_FAILED(rv)) return rv;
if ((text.Length() > 0) && (aAction == eSet)) {
@ -2020,7 +2044,7 @@ RDFGenericBuilderImpl::RemoveWidgetItem(nsIContent* aElement,
nsCOMPtr<nsIContent> child( do_QueryInterface(isupports) );
NS_IF_RELEASE(isupports);
if (! nsRDFContentUtils::IsContainedBy(child, aElement))
if (! gXULUtils->IsContainedBy(child, aElement))
continue;
nsCOMPtr<nsIContent> parent;
@ -2190,7 +2214,7 @@ RDFGenericBuilderImpl::CreateTemplateContents(nsIContent* aElement, const nsStri
nsCOMPtr<nsIContent> element = aElement;
while (element) {
rv = nsRDFContentUtils::GetElementRefResource(element, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(element, getter_AddRefs(resource));
if (NS_SUCCEEDED(rv)) break;
nsCOMPtr<nsIContent> parent;
@ -2215,7 +2239,7 @@ RDFGenericBuilderImpl::EnsureElementHasGenericChild(nsIContent* parent,
{
nsresult rv;
rv = nsRDFContentUtils::FindChildByTag(parent, nameSpaceID, tag, result);
rv = gXULUtils->FindChildByTag(parent, nameSpaceID, tag, result);
if (NS_FAILED(rv)) return rv;
if (rv == NS_RDF_NO_VALUE) {
@ -2544,7 +2568,7 @@ RDFGenericBuilderImpl::GetDOMNodeResource(nsIDOMNode* aNode, nsIRDFResource** aR
return rv;
}
return nsRDFContentUtils::GetElementRefResource(element, aResource);
return gXULUtils->GetElementRefResource(element, aResource);
}
@ -2564,11 +2588,11 @@ RDFGenericBuilderImpl::FindInsertionPoint(nsIContent* aElement, nsIContent** aRe
if (NS_FAILED(rv)) return rv;
if (tagName.Equals("tree") || tagName.Equals("treeitem")) {
rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("treechildren"), aResult);
rv = gXULUtils->FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("treechildren"), aResult);
if (NS_FAILED(rv)) return rv;
}
else if (tagName.Equals("menu")) {
rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("menupopup"), aResult);
rv = gXULUtils->FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("menupopup"), aResult);
if (NS_FAILED(rv)) return rv;
}
else {
@ -2723,10 +2747,10 @@ RDFGenericBuilderImpl::ForceTreeReflow(nsITimer* aTimer, void* aClosure)
// XXX What if kTreeChildrenAtom & kNameSpaceXUL are clobbered b/c
// the generic builder has been destroyed?
nsCOMPtr<nsIContent> treechildren;
rv = nsRDFContentUtils::FindChildByTag(builder->mRoot,
kNameSpaceID_XUL,
kTreeChildrenAtom,
getter_AddRefs(treechildren));
rv = gXULUtils->FindChildByTag(builder->mRoot,
kNameSpaceID_XUL,
kTreeChildrenAtom,
getter_AddRefs(treechildren));
if (NS_FAILED(rv)) return; // couldn't find

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsRDFCID.h"
#include "nsIComponentManager.h"
#include "rdf.h"
#include "nsIXULContentUtils.h"
#include "nsIXULSortService.h"
#include "nsIXULDocumentInfo.h"
#include "nsIXULPopupListener.h"
@ -70,6 +71,7 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_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);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
static NS_DEFINE_CID(kXULDocumentInfoCID, NS_XULDOCUMENTINFO_CID);
@ -282,12 +284,17 @@ NSGetFactory(nsISupports* aServiceMgr,
if (! aFactory)
return NS_ERROR_NULL_POINTER;
nsIGenericFactory::ConstructorProcPtr constructor = nsnull;
// Classes that use generic factories
if (aClass.Equals(kRDFInMemoryDataSourceCID)) {
nsIGenericFactory::ConstructorProcPtr constructor;
constructor = NS_NewRDFInMemoryDataSource;
}
else if (aClass.Equals(kXULContentUtilsCID)) {
constructor = NS_NewXULContentUtils;
}
// XXX Factor this part out if we get more of these
if (constructor) {
nsresult rv;
NS_WITH_SERVICE1(nsIComponentManager, compMgr, aServiceMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
@ -307,6 +314,7 @@ NSGetFactory(nsISupports* aServiceMgr,
NS_ADDREF(*aFactory);
}
else {
// everyone else.
RDFFactoryImpl* factory = new RDFFactoryImpl(aClass, aClassName, aProgID);
if (factory == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
@ -454,6 +462,12 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
NS_RDF_PROGID "/xul-command-dispatcher",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
rv = compMgr->RegisterComponent(kXULContentUtilsCID,
"XUL Content Utilities",
NS_RDF_PROGID "/xul-content-utils",
aPath, PR_TRUE, PR_TRUE);
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
@ -510,7 +524,9 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kXULPopupListenerCID, aPath);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kXULCommandDispatcherCID, aPath);
rv = compMgr->UnregisterComponent(kXULCommandDispatcherCID, aPath);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kXULContentUtilsCID, aPath);
done:
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);

Просмотреть файл

@ -31,12 +31,12 @@ CPPSRCS = \
nsJSXULElement.cpp \
nsJSXULCommandDispatcher.cpp \
nsJSXULTreeElement.cpp \
nsRDFContentUtils.cpp \
nsRDFDOMNodeList.cpp \
nsRDFElement.cpp \
nsRDFGenericBuilder.cpp \
nsRDFXULBuilder.cpp \
nsXULAttributes.cpp \
nsXULContentUtils.cpp \
nsXULDocument.cpp \
nsXULSortService.cpp \
nsXULDocumentInfo.cpp \

Просмотреть файл

@ -35,11 +35,11 @@ CPP_OBJS=\
.\$(OBJDIR)\nsJSXULDocument.obj \
.\$(OBJDIR)\nsJSXULElement.obj \
.\$(OBJDIR)\nsJSXULTreeElement.obj \
.\$(OBJDIR)\nsRDFContentUtils.obj \
.\$(OBJDIR)\nsRDFDOMNodeList.obj \
.\$(OBJDIR)\nsRDFElement.obj \
.\$(OBJDIR)\nsRDFXULBuilder.obj \
.\$(OBJDIR)\nsXULDocument.obj \
.\$(OBJDIR)\nsXULContentUtils.obj \
.\$(OBJDIR)\nsXULDocumentInfo.obj \
.\$(OBJDIR)\nsXULKeyListener.obj \
.\$(OBJDIR)\nsXULSortService.obj \

Просмотреть файл

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

Просмотреть файл

@ -1,98 +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.
*/
/*
A package of routines shared by the RDF content code.
*/
#ifndef nsRDFContentUtils_h__
#define nsRDFContentUtils_h__
#include "nsError.h"
class nsIAtom;
class nsIContent;
class nsIDocument;
class nsIDOMNodeList;
class nsIRDFNode;
class nsCString;
class nsString;
class nsRDFContentUtils
{
public:
static nsresult
AttachTextNode(nsIContent* parent, nsIRDFNode* value);
static nsresult
FindChildByTag(nsIContent *aElement,
PRInt32 aNameSpaceID,
nsIAtom* aTag,
nsIContent **aResult);
static nsresult
FindChildByResource(nsIContent* aElement,
nsIRDFResource* aResource,
nsIContent** aResult);
static nsresult
GetElementResource(nsIContent* aElement, nsIRDFResource** aResult);
static nsresult
GetElementRefResource(nsIContent* aElement, nsIRDFResource** aResult);
static nsresult
GetTextForNode(nsIRDFNode* aNode, nsString& aResult);
static nsresult
GetElementLogString(nsIContent* aElement, nsString& aResult);
static nsresult
GetAttributeLogString(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aTag, nsString& aResult);
static nsresult
MakeElementURI(nsIDocument* aDocument, const nsString& aElementID, nsCString& aURI);
static nsresult
MakeElementResource(nsIDocument* aDocument, const nsString& aElementID, nsIRDFResource** aResult);
static nsresult
MakeElementID(nsIDocument* aDocument, const nsString& aURI, nsString& aElementID);
static PRBool
IsContainedBy(nsIContent* aElement, nsIContent* aContainer);
static nsresult
GetResource(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult);
static nsresult
GetResource(PRInt32 aNameSpaceID, const nsString& aAttribute, nsIRDFResource** aResult);
};
// in nsRDFElement.cpp
extern nsresult
NS_NewRDFElement(PRInt32 aNameSpaceID, nsIAtom* aTag, nsIContent** aResult);
#endif // nsRDFContentUtils_h__

Просмотреть файл

@ -63,7 +63,7 @@
#include "nsISupportsArray.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsRDFDOMNodeList.h"
#include "nsStyleConsts.h"
#include "nsIStyleSheet.h"
@ -127,6 +127,7 @@ static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
static NS_DEFINE_IID(kIDOMEventTargetIID, NS_IDOMEVENTTARGET_IID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_IID(kIXULPopupListenerIID, NS_IXULPOPUPLISTENER_IID);
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
@ -412,6 +413,7 @@ private:
static nsrefcnt gRefCnt;
static nsIRDFService* gRDFService;
static nsINameSpaceManager* gNameSpaceManager;
static nsIXULContentUtils* gXULUtils;
static PRInt32 kNameSpaceID_RDF;
static PRInt32 kNameSpaceID_XUL;
static nsIAtom* kIdAtom;
@ -464,6 +466,7 @@ private:
nsrefcnt RDFElementImpl::gRefCnt;
nsIRDFService* RDFElementImpl::gRDFService;
nsINameSpaceManager* RDFElementImpl::gNameSpaceManager;
nsIXULContentUtils* RDFElementImpl::gXULUtils;
nsIAtom* RDFElementImpl::kIdAtom;
nsIAtom* RDFElementImpl::kRefAtom;
nsIAtom* RDFElementImpl::kClassAtom;
@ -592,16 +595,22 @@ RDFElementImpl::RDFElementImpl(PRInt32 aNameSpaceID, nsIAtom* aTag)
}
rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID,
nsnull,
kINameSpaceManagerIID,
(void**) &gNameSpaceManager);
nsnull,
kINameSpaceManagerIID,
(void**) &gNameSpaceManager);
NS_VERIFY(NS_SUCCEEDED(rv), "unable to create namespace manager");
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager");
if (gNameSpaceManager) {
gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF);
gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL);
}
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get XUL content utils");
}
}
@ -671,6 +680,11 @@ RDFElementImpl::~RDFElementImpl()
NS_IF_RELEASE(gNameSpaceManager);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
EventHandlerMapEntry* entry = kEventHandlerMap;
while (entry->mAttributeName) {
NS_IF_RELEASE(entry->mAttributeAtom);
@ -2497,7 +2511,7 @@ RDFElementImpl::GetAttribute(PRInt32 aNameSpaceID,
// a possibly-absolute URI into a relative ID attribute.
NS_ASSERTION(mDocument != nsnull, "not initialized");
if (nsnull != mDocument) {
nsRDFContentUtils::MakeElementID(mDocument, attr->mValue, aResult);
gXULUtils->MakeElementID(mDocument, attr->mValue, aResult);
}
}
#endif
@ -3061,7 +3075,7 @@ RDFElementImpl::GetIdResource(nsIRDFResource** aResource)
const nsXULAttribute* attr = (const nsXULAttribute*) mAttributes->ElementAt(i);
if ((attr->mNameSpaceID == kNameSpaceID_None) &&
(attr->mName == kIdAtom)) {
return nsRDFContentUtils::MakeElementResource(mDocument, attr->mValue, aResource);
return gXULUtils->MakeElementResource(mDocument, attr->mValue, aResource);
}
}
}
@ -3088,7 +3102,7 @@ RDFElementImpl::GetRefResource(nsIRDFResource** aResource)
if (attr->mName != kRefAtom)
continue;
return nsRDFContentUtils::MakeElementResource(mDocument, attr->mValue, aResource);
return gXULUtils->MakeElementResource(mDocument, attr->mValue, aResource);
}
}

Просмотреть файл

@ -62,7 +62,7 @@
#include "nsIXULSortService.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
@ -93,8 +93,8 @@ 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);
static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
static NS_DEFINE_CID(kIHTMLElementFactoryIID, NS_IHTML_ELEMENT_FACTORY_IID);
@ -277,6 +277,7 @@ protected:
static nsIRDFContainerUtils* gRDFContainerUtils;
static nsINameSpaceManager* gNameSpaceManager;
static nsIHTMLElementFactory* gHTMLElementFactory;
static nsIXULContentUtils* gXULUtils;
static nsIAtom* kContainerAtom;
static nsIAtom* kContainerContentsGeneratedAtom;
@ -358,6 +359,7 @@ nsIRDFService* RDFGenericBuilderImpl::gRDFService;
nsIRDFContainerUtils* RDFGenericBuilderImpl::gRDFContainerUtils;
nsINameSpaceManager* RDFGenericBuilderImpl::gNameSpaceManager;
nsIHTMLElementFactory* RDFGenericBuilderImpl::gHTMLElementFactory;
nsIXULContentUtils* RDFGenericBuilderImpl::gXULUtils;
nsIRDFResource* RDFGenericBuilderImpl::kNC_Title;
nsIRDFResource* RDFGenericBuilderImpl::kNC_child;
@ -441,11 +443,28 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void)
NS_IF_RELEASE(kRDF_instanceOf);
NS_IF_RELEASE(kXUL_element);
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
nsServiceManager::ReleaseService(kXULSortServiceCID, gXULSortService);
if (gRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
if (gRDFContainerUtils) {
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
gRDFContainerUtils = nsnull;
}
if (gXULSortService) {
nsServiceManager::ReleaseService(kXULSortServiceCID, gXULSortService);
gXULSortService = nsnull;
}
NS_RELEASE(gNameSpaceManager);
NS_IF_RELEASE(gHTMLElementFactory);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
}
}
@ -529,7 +548,7 @@ RDFGenericBuilderImpl::Init()
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kXULSortServiceCID,
kIXULSortServiceIID,
nsCOMTypeInfo<nsIXULSortService>::GetIID(),
(nsISupports**) &gXULSortService);
if (NS_FAILED(rv)) return rv;
@ -538,6 +557,11 @@ RDFGenericBuilderImpl::Init()
kIHTMLElementFactoryIID,
(void**) &gHTMLElementFactory);
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
if (NS_FAILED(rv)) return rv;
}
#ifdef PR_LOGGING
@ -665,7 +689,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
nsresult rv;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::GetElementRefResource(aElement, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(aElement, getter_AddRefs(resource));
if (NS_SUCCEEDED(rv)) {
// The element has a resource; that means that it corresponds
// to something in the graph, so we need to go to the graph to
@ -698,7 +722,7 @@ RDFGenericBuilderImpl::OpenContainer(nsIContent* aElement)
return NS_OK;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::GetElementRefResource(aElement, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(aElement, getter_AddRefs(resource));
// If it has no resource, there's nothing that we need to be
// concerned about here.
@ -917,7 +941,7 @@ RDFGenericBuilderImpl::CreateElement(PRInt32 aNameSpaceID,
if (NS_FAILED(rv)) return rv;
nsAutoString id;
rv = nsRDFContentUtils::MakeElementID(doc, nsAutoString(uri), id);
rv = gXULUtils->MakeElementID(doc, nsAutoString(uri), id);
if (NS_FAILED(rv)) return rv;
rv = result->SetAttribute(kNameSpaceID_None, kIdAtom, id, PR_FALSE);
@ -1376,7 +1400,7 @@ RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement,
}
else {
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(attrNameSpaceID, attr, getter_AddRefs(property));
rv = gXULUtils->GetResource(attrNameSpaceID, attr, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> target;
@ -1384,7 +1408,7 @@ RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement,
if (NS_FAILED(rv)) return rv;
nsAutoString targetStr;
rv = nsRDFContentUtils::GetTextForNode(target, targetStr);
rv = gXULUtils->GetTextForNode(target, targetStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get text for target");
if (NS_FAILED(rv)) return rv;
@ -1540,7 +1564,7 @@ RDFGenericBuilderImpl::GetSubstitutionText(nsIRDFResource* aResource,
if (NS_FAILED(rv)) return rv;
if (valueNode) {
rv = nsRDFContentUtils::GetTextForNode(valueNode, aResult);
rv = gXULUtils->GetTextForNode(valueNode, aResult);
if (NS_FAILED(rv)) return rv;
}
else {
@ -1838,7 +1862,7 @@ RDFGenericBuilderImpl::AddPersistentAttributes(nsIContent* aTemplateNode, nsIRDF
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(nameSpaceID, tag, getter_AddRefs(property));
rv = gXULUtils->GetResource(nameSpaceID, tag, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> target;
@ -1937,7 +1961,7 @@ RDFGenericBuilderImpl::SynchronizeUsingTemplate(nsIContent* aTemplateNode,
if (property.get() == aProperty) {
nsAutoString text("");
rv = nsRDFContentUtils::GetTextForNode(aValue, text);
rv = gXULUtils->GetTextForNode(aValue, text);
if (NS_FAILED(rv)) return rv;
if ((text.Length() > 0) && (aAction == eSet)) {
@ -2020,7 +2044,7 @@ RDFGenericBuilderImpl::RemoveWidgetItem(nsIContent* aElement,
nsCOMPtr<nsIContent> child( do_QueryInterface(isupports) );
NS_IF_RELEASE(isupports);
if (! nsRDFContentUtils::IsContainedBy(child, aElement))
if (! gXULUtils->IsContainedBy(child, aElement))
continue;
nsCOMPtr<nsIContent> parent;
@ -2190,7 +2214,7 @@ RDFGenericBuilderImpl::CreateTemplateContents(nsIContent* aElement, const nsStri
nsCOMPtr<nsIContent> element = aElement;
while (element) {
rv = nsRDFContentUtils::GetElementRefResource(element, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(element, getter_AddRefs(resource));
if (NS_SUCCEEDED(rv)) break;
nsCOMPtr<nsIContent> parent;
@ -2215,7 +2239,7 @@ RDFGenericBuilderImpl::EnsureElementHasGenericChild(nsIContent* parent,
{
nsresult rv;
rv = nsRDFContentUtils::FindChildByTag(parent, nameSpaceID, tag, result);
rv = gXULUtils->FindChildByTag(parent, nameSpaceID, tag, result);
if (NS_FAILED(rv)) return rv;
if (rv == NS_RDF_NO_VALUE) {
@ -2544,7 +2568,7 @@ RDFGenericBuilderImpl::GetDOMNodeResource(nsIDOMNode* aNode, nsIRDFResource** aR
return rv;
}
return nsRDFContentUtils::GetElementRefResource(element, aResource);
return gXULUtils->GetElementRefResource(element, aResource);
}
@ -2564,11 +2588,11 @@ RDFGenericBuilderImpl::FindInsertionPoint(nsIContent* aElement, nsIContent** aRe
if (NS_FAILED(rv)) return rv;
if (tagName.Equals("tree") || tagName.Equals("treeitem")) {
rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("treechildren"), aResult);
rv = gXULUtils->FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("treechildren"), aResult);
if (NS_FAILED(rv)) return rv;
}
else if (tagName.Equals("menu")) {
rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("menupopup"), aResult);
rv = gXULUtils->FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("menupopup"), aResult);
if (NS_FAILED(rv)) return rv;
}
else {
@ -2723,10 +2747,10 @@ RDFGenericBuilderImpl::ForceTreeReflow(nsITimer* aTimer, void* aClosure)
// XXX What if kTreeChildrenAtom & kNameSpaceXUL are clobbered b/c
// the generic builder has been destroyed?
nsCOMPtr<nsIContent> treechildren;
rv = nsRDFContentUtils::FindChildByTag(builder->mRoot,
kNameSpaceID_XUL,
kTreeChildrenAtom,
getter_AddRefs(treechildren));
rv = gXULUtils->FindChildByTag(builder->mRoot,
kNameSpaceID_XUL,
kTreeChildrenAtom,
getter_AddRefs(treechildren));
if (NS_FAILED(rv)) return; // couldn't find

Просмотреть файл

@ -68,7 +68,7 @@
#include "nsLayoutCID.h"
#include "nsIHTMLElementFactory.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "prlog.h"
@ -112,6 +112,7 @@ static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
static NS_DEFINE_CID(kXULDocumentInfoCID, NS_XULDOCUMENTINFO_CID);
static NS_DEFINE_CID(kXULKeyListenerCID, NS_XULKEYLISTENER_CID);
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
////////////////////////////////////////////////////////////////////////
@ -180,6 +181,7 @@ private:
static nsIRDFService* gRDFService;
static nsIRDFContainerUtils* gRDFContainerUtils;
static nsINameSpaceManager* gNameSpaceManager;
static nsIXULContentUtils* gXULUtils;
static PRInt32 kNameSpaceID_RDF;
static PRInt32 kNameSpaceID_XUL;
@ -338,6 +340,7 @@ PRInt32 RDFXULBuilderImpl::gRefCnt;
nsIRDFService* RDFXULBuilderImpl::gRDFService;
nsIRDFContainerUtils* RDFXULBuilderImpl::gRDFContainerUtils;
nsINameSpaceManager* RDFXULBuilderImpl::gNameSpaceManager;
nsIXULContentUtils* RDFXULBuilderImpl::gXULUtils;
PRInt32 RDFXULBuilderImpl::kNameSpaceID_RDF = kNameSpaceID_Unknown;
PRInt32 RDFXULBuilderImpl::kNameSpaceID_XUL = kNameSpaceID_Unknown;
@ -448,6 +451,12 @@ RDFXULBuilderImpl::Init()
(nsISupports**) &gRDFContainerUtils);
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
if (NS_FAILED(rv)) return rv;
}
rv = nsComponentManager::CreateInstance(kHTMLElementFactoryCID,
@ -480,6 +489,11 @@ RDFXULBuilderImpl::~RDFXULBuilderImpl(void)
gRDFContainerUtils = nsnull;
}
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
NS_IF_RELEASE(gNameSpaceManager);
NS_IF_RELEASE(kRDF_instanceOf);
@ -628,7 +642,7 @@ RDFXULBuilderImpl::CreateContents(nsIContent* aElement)
#ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
nsAutoString elementStr;
rv = nsRDFContentUtils::GetElementLogString(aElement, elementStr);
rv = gXULUtils->GetElementLogString(aElement, elementStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element string");
char* elementCStr = elementStr.ToNewCString();
@ -645,7 +659,7 @@ RDFXULBuilderImpl::CreateContents(nsIContent* aElement)
// via the nsIContent interface allows us to support generic nodes
// that might get added in by DOM calls.
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::GetElementResource(aElement, getter_AddRefs(resource));
rv = gXULUtils->GetElementResource(aElement, getter_AddRefs(resource));
// If it doesn't have a resource, then it's not a XUL element (maybe it was
// an anonymous template node generated by RDF). Regardless, we don't care.
@ -848,7 +862,7 @@ RDFXULBuilderImpl::OnAssert(nsIRDFResource* aSource,
aProperty->GetValue(getter_Copies(property));
nsAutoString targetStr;
nsRDFContentUtils::GetTextForNode(aTarget, targetStr);
gXULUtils->GetTextForNode(aTarget, targetStr);
char* targetCStr = targetStr.ToNewCString();
@ -976,7 +990,7 @@ RDFXULBuilderImpl::OnUnassert(nsIRDFResource* aSource,
aProperty->GetValue(getter_Copies(property));
nsAutoString targetStr;
nsRDFContentUtils::GetTextForNode(aTarget, targetStr);
gXULUtils->GetTextForNode(aTarget, targetStr);
char* targetCStr = targetStr.ToNewCString();
@ -1095,10 +1109,10 @@ RDFXULBuilderImpl::OnChange(nsIRDFResource* aSource,
aProperty->GetValue(getter_Copies(property));
nsAutoString oldTargetStr;
nsRDFContentUtils::GetTextForNode(aOldTarget, oldTargetStr);
gXULUtils->GetTextForNode(aOldTarget, oldTargetStr);
nsAutoString newTargetStr;
nsRDFContentUtils::GetTextForNode(aNewTarget, newTargetStr);
gXULUtils->GetTextForNode(aNewTarget, newTargetStr);
char* oldTargetCStr = oldTargetStr.ToNewCString();
char* newTargetCStr = newTargetStr.ToNewCString();
@ -1243,11 +1257,11 @@ RDFXULBuilderImpl::AppendChild(nsINameSpace* aNameSpace,
#ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
nsAutoString parentStr;
rv = nsRDFContentUtils::GetElementLogString(aElement, parentStr);
rv = gXULUtils->GetElementLogString(aElement, parentStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get parent element string");
nsAutoString childStr;
rv = nsRDFContentUtils::GetElementLogString(child, childStr);
rv = gXULUtils->GetElementLogString(child, childStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get child element string");
char* parentCStr = parentStr.ToNewCString();
@ -1268,7 +1282,7 @@ RDFXULBuilderImpl::AppendChild(nsINameSpace* aNameSpace,
}
else if (literal = do_QueryInterface(aValue)) {
// If it's a literal, then add it as a simple text node.
rv = nsRDFContentUtils::AttachTextNode(aElement, literal);
rv = gXULUtils->AttachTextNode(aElement, literal);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add text to content model");
if (NS_FAILED(rv)) return rv;
}
@ -1318,11 +1332,11 @@ RDFXULBuilderImpl::InsertChildAt(nsINameSpace* aNameSpace,
#ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
nsAutoString parentStr;
rv = nsRDFContentUtils::GetElementLogString(aElement, parentStr);
rv = gXULUtils->GetElementLogString(aElement, parentStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get parent element string");
nsAutoString childStr;
rv = nsRDFContentUtils::GetElementLogString(child, childStr);
rv = gXULUtils->GetElementLogString(child, childStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get child element string");
char* parentCStr = parentStr.ToNewCString();
@ -1345,7 +1359,7 @@ RDFXULBuilderImpl::InsertChildAt(nsINameSpace* aNameSpace,
// If it's a literal, then add it as a simple text node.
//
// XXX Appending is wrong wrong wrong.
rv = nsRDFContentUtils::AttachTextNode(aElement, literal);
rv = gXULUtils->AttachTextNode(aElement, literal);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add text to content model");
if (NS_FAILED(rv)) return rv;
}
@ -1398,11 +1412,11 @@ RDFXULBuilderImpl::ReplaceChildAt(nsINameSpace* aNameSpace,
#ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
nsAutoString parentStr;
rv = nsRDFContentUtils::GetElementLogString(aElement, parentStr);
rv = gXULUtils->GetElementLogString(aElement, parentStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get parent element string");
nsAutoString childStr;
rv = nsRDFContentUtils::GetElementLogString(child, childStr);
rv = gXULUtils->GetElementLogString(child, childStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get child element string");
char* parentCStr = parentStr.ToNewCString();
@ -1425,7 +1439,7 @@ RDFXULBuilderImpl::ReplaceChildAt(nsINameSpace* aNameSpace,
// If it's a literal, then add it as a simple text node.
//
// XXX Appending is wrong wrong wrong.
rv = nsRDFContentUtils::AttachTextNode(aElement, literal);
rv = gXULUtils->AttachTextNode(aElement, literal);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add text to content model");
if (NS_FAILED(rv)) return rv;
}
@ -1466,7 +1480,7 @@ RDFXULBuilderImpl::RemoveChild(nsIContent* aElement, nsIRDFNode* aValue)
aElement->ChildAt(count, *getter_AddRefs(child));
nsCOMPtr<nsIRDFResource> elementResource;
rv = nsRDFContentUtils::GetElementResource(child, getter_AddRefs(elementResource));
rv = gXULUtils->GetElementResource(child, getter_AddRefs(elementResource));
if (resource != elementResource)
continue;
@ -1474,11 +1488,11 @@ RDFXULBuilderImpl::RemoveChild(nsIContent* aElement, nsIRDFNode* aValue)
#ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
nsAutoString parentStr;
rv = nsRDFContentUtils::GetElementLogString(aElement, parentStr);
rv = gXULUtils->GetElementLogString(aElement, parentStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get parent element string");
nsAutoString childStr;
rv = nsRDFContentUtils::GetElementLogString(child, childStr);
rv = gXULUtils->GetElementLogString(child, childStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get child element string");
char* parentCStr = parentStr.ToNewCString();
@ -1552,7 +1566,7 @@ RDFXULBuilderImpl::CreateOrReuseElement(nsINameSpace* aContainingNameSpace,
#ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
nsAutoString elementStr;
rv = nsRDFContentUtils::GetElementLogString(*aResult, elementStr);
rv = gXULUtils->GetElementLogString(*aResult, elementStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element string");
char* elementCStr = elementStr.ToNewCString();
@ -1627,7 +1641,7 @@ RDFXULBuilderImpl::CreateHTMLElement(nsINameSpace* aContainingNameSpace,
if (NS_FAILED(rv)) return rv;
nsAutoString id;
rv = nsRDFContentUtils::MakeElementID(doc, nsAutoString(uri), id);
rv = gXULUtils->MakeElementID(doc, nsAutoString(uri), id);
if (NS_FAILED(rv)) return rv;
rv = element->SetAttribute(kNameSpaceID_None, kIdAtom, id, PR_FALSE);
@ -1811,7 +1825,7 @@ RDFXULBuilderImpl::CreateXULElement(nsINameSpace* aContainingNameSpace,
if (NS_FAILED(rv)) return rv;
nsAutoString id;
rv = nsRDFContentUtils::MakeElementID(document, nsAutoString(uri), id);
rv = gXULUtils->MakeElementID(document, nsAutoString(uri), id);
if (NS_FAILED(rv)) return rv;
rv = element->SetAttribute(kNameSpaceID_None, kIdAtom, id, PR_FALSE);
@ -2034,15 +2048,15 @@ RDFXULBuilderImpl::AddAttribute(nsIContent* aElement,
#ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
nsAutoString elementStr;
rv = nsRDFContentUtils::GetElementLogString(aElement, elementStr);
rv = gXULUtils->GetElementLogString(aElement, elementStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element string");
nsAutoString attrStr;
rv = nsRDFContentUtils::GetAttributeLogString(aElement, nameSpaceID, tag, attrStr);
rv = gXULUtils->GetAttributeLogString(aElement, nameSpaceID, tag, attrStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get child element string");
nsAutoString valueStr;
rv = nsRDFContentUtils::GetTextForNode(aValue, valueStr);
rv = gXULUtils->GetTextForNode(aValue, valueStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get value text");
char* elementCStr = elementStr.ToNewCString();
@ -2125,7 +2139,7 @@ RDFXULBuilderImpl::AddAttribute(nsIContent* aElement,
}
nsAutoString value;
rv = nsRDFContentUtils::GetTextForNode(aValue, value);
rv = gXULUtils->GetTextForNode(aValue, value);
if (NS_FAILED(rv)) return rv;
rv = aElement->SetAttribute(nameSpaceID, tag, value, PR_TRUE);
@ -2153,15 +2167,15 @@ RDFXULBuilderImpl::RemoveAttribute(nsIContent* aElement,
#ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
nsAutoString elementStr;
rv = nsRDFContentUtils::GetElementLogString(aElement, elementStr);
rv = gXULUtils->GetElementLogString(aElement, elementStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element string");
nsAutoString attrStr;
rv = nsRDFContentUtils::GetAttributeLogString(aElement, nameSpaceID, tag, attrStr);
rv = gXULUtils->GetAttributeLogString(aElement, nameSpaceID, tag, attrStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get child element string");
nsAutoString valueStr;
rv = nsRDFContentUtils::GetTextForNode(aValue, valueStr);
rv = gXULUtils->GetTextForNode(aValue, valueStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get value text");
char* elementCStr = elementStr.ToNewCString();
@ -2342,7 +2356,7 @@ RDFXULBuilderImpl::GetRDFResourceFromXULElement(nsIDOMNode* aNode, nsIRDFResourc
NS_ASSERTION(NS_SUCCEEDED(rv), "DOM element doesn't support nsIContent");
if (NS_FAILED(rv)) return rv;
return nsRDFContentUtils::GetElementResource(element, aResult);
return gXULUtils->GetElementResource(element, aResult);
}
@ -2494,7 +2508,7 @@ RDFXULBuilderImpl::IsXULElement(nsIContent* aElement)
nsresult rv;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::GetElementResource(aElement, getter_AddRefs(resource));
rv = gXULUtils->GetElementResource(aElement, getter_AddRefs(resource));
if (NS_FAILED(rv)) return PR_FALSE;
PRBool isXULElement;

Просмотреть файл

@ -115,7 +115,7 @@
#include "nsLayoutCID.h"
#include "nsParserCIID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsRDFDOMNodeList.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h" // XXX should go away
@ -195,6 +195,7 @@ static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_CID(kXULCommandDispatcherCID, NS_XULCOMMANDDISPATCHER_CID);
static NS_DEFINE_IID(kIXULCommandDispatcherIID, NS_IXULCOMMANDDISPATCHER_IID);
@ -873,6 +874,8 @@ protected:
static nsINameSpaceManager* gNameSpaceManager;
static PRInt32 kNameSpaceID_XUL;
static nsIXULContentUtils* gXULUtils;
nsIContent*
FindContent(const nsIContent* aStartNode,
const nsIContent* aTest1,
@ -959,6 +962,8 @@ nsIRDFResource* XULDocumentImpl::kXUL_element;
nsINameSpaceManager* XULDocumentImpl::gNameSpaceManager;
PRInt32 XULDocumentImpl::kNameSpaceID_XUL;
nsIXULContentUtils* XULDocumentImpl::gXULUtils;
////////////////////////////////////////////////////////////////////////
// ctors & dtors
@ -1019,6 +1024,11 @@ XULDocumentImpl::XULDocumentImpl(void)
#define XUL_NAMESPACE_URI "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
static const char kXULNameSpaceURI[] = XUL_NAMESPACE_URI;
gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL);
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
}
#ifdef PR_LOGGING
@ -1113,6 +1123,11 @@ XULDocumentImpl::~XULDocumentImpl()
NS_IF_RELEASE(kRDF_instanceOf);
NS_IF_RELEASE(kRDF_type);
NS_IF_RELEASE(kXUL_element);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
}
}
@ -2709,7 +2724,9 @@ XULDocumentImpl::SplitProperty(nsIRDFResource* aProperty,
if (! p)
return NS_ERROR_UNEXPECTED;
nsAutoString uri(p);
PRUnichar buf[256];
nsAutoString uri(CBufDescriptor(buf, PR_TRUE, sizeof(buf) / sizeof(PRUnichar), 0));
uri = p;
// First try to split the namespace using the rightmost '#' or '/'
// character.
@ -3150,7 +3167,7 @@ XULDocumentImpl::Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aA
nsresult rv;
nsCOMPtr<nsIRDFResource> source;
rv = nsRDFContentUtils::GetElementResource(aElement, getter_AddRefs(source));
rv = gXULUtils->GetElementResource(aElement, getter_AddRefs(source));
if (NS_FAILED(rv)) return rv;
// No ID, so nothing to persist.
@ -3159,7 +3176,7 @@ XULDocumentImpl::Persist(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aA
// Ick. Construct a resource from the namespace and attribute.
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(aNameSpaceID, aAttribute, getter_AddRefs(property));
rv = gXULUtils->GetResource(aNameSpaceID, aAttribute, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsAutoString value;
@ -3309,7 +3326,7 @@ XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
nsresult rv;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::MakeElementResource(this, aId, getter_AddRefs(resource));
rv = gXULUtils->MakeElementResource(this, aId, getter_AddRefs(resource));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupportsArray> elements;
@ -3362,7 +3379,7 @@ XULDocumentImpl::AddElementToMap(nsIContent* aElement, PRBool aDeep)
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::MakeElementResource(this, value, getter_AddRefs(resource));
rv = gXULUtils->MakeElementResource(this, value, getter_AddRefs(resource));
rv = mResources.Add(resource, aElement);
if (NS_FAILED(rv)) return rv;
@ -3408,7 +3425,7 @@ XULDocumentImpl::RemoveElementFromMap(nsIContent* aElement, PRBool aDeep)
if (rv == NS_CONTENT_ATTR_HAS_VALUE) {
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::MakeElementResource(this, value, getter_AddRefs(resource));
rv = gXULUtils->MakeElementResource(this, value, getter_AddRefs(resource));
rv = mResources.Remove(resource, aElement);
if (NS_FAILED(rv)) return rv;
@ -3612,7 +3629,7 @@ XULDocumentImpl::CreatePopupDocument(nsIContent* aPopupElement, nsIDocument** aR
// Use the absolute URL to retrieve a resource from the RDF
// service that corresponds to the root content.
nsCOMPtr<nsIRDFResource> rootResource;
rv = nsRDFContentUtils::MakeElementResource(this, idValue, getter_AddRefs(rootResource));
rv = gXULUtils->MakeElementResource(this, idValue, getter_AddRefs(rootResource));
if (NS_FAILED(rv)) return rv;
// Tell the builder to create its root from this resrouce.

Просмотреть файл

@ -63,7 +63,7 @@
#include "nsISupportsArray.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsRDFDOMNodeList.h"
#include "nsStyleConsts.h"
#include "nsIStyleSheet.h"
@ -127,6 +127,7 @@ static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
static NS_DEFINE_IID(kIDOMEventTargetIID, NS_IDOMEVENTTARGET_IID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_IID(kIXULPopupListenerIID, NS_IXULPOPUPLISTENER_IID);
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
@ -412,6 +413,7 @@ private:
static nsrefcnt gRefCnt;
static nsIRDFService* gRDFService;
static nsINameSpaceManager* gNameSpaceManager;
static nsIXULContentUtils* gXULUtils;
static PRInt32 kNameSpaceID_RDF;
static PRInt32 kNameSpaceID_XUL;
static nsIAtom* kIdAtom;
@ -464,6 +466,7 @@ private:
nsrefcnt RDFElementImpl::gRefCnt;
nsIRDFService* RDFElementImpl::gRDFService;
nsINameSpaceManager* RDFElementImpl::gNameSpaceManager;
nsIXULContentUtils* RDFElementImpl::gXULUtils;
nsIAtom* RDFElementImpl::kIdAtom;
nsIAtom* RDFElementImpl::kRefAtom;
nsIAtom* RDFElementImpl::kClassAtom;
@ -592,16 +595,22 @@ RDFElementImpl::RDFElementImpl(PRInt32 aNameSpaceID, nsIAtom* aTag)
}
rv = nsComponentManager::CreateInstance(kNameSpaceManagerCID,
nsnull,
kINameSpaceManagerIID,
(void**) &gNameSpaceManager);
nsnull,
kINameSpaceManagerIID,
(void**) &gNameSpaceManager);
NS_VERIFY(NS_SUCCEEDED(rv), "unable to create namespace manager");
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create namespace manager");
if (gNameSpaceManager) {
gNameSpaceManager->RegisterNameSpace(kRDFNameSpaceURI, kNameSpaceID_RDF);
gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL);
}
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get XUL content utils");
}
}
@ -671,6 +680,11 @@ RDFElementImpl::~RDFElementImpl()
NS_IF_RELEASE(gNameSpaceManager);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
EventHandlerMapEntry* entry = kEventHandlerMap;
while (entry->mAttributeName) {
NS_IF_RELEASE(entry->mAttributeAtom);
@ -2497,7 +2511,7 @@ RDFElementImpl::GetAttribute(PRInt32 aNameSpaceID,
// a possibly-absolute URI into a relative ID attribute.
NS_ASSERTION(mDocument != nsnull, "not initialized");
if (nsnull != mDocument) {
nsRDFContentUtils::MakeElementID(mDocument, attr->mValue, aResult);
gXULUtils->MakeElementID(mDocument, attr->mValue, aResult);
}
}
#endif
@ -3061,7 +3075,7 @@ RDFElementImpl::GetIdResource(nsIRDFResource** aResource)
const nsXULAttribute* attr = (const nsXULAttribute*) mAttributes->ElementAt(i);
if ((attr->mNameSpaceID == kNameSpaceID_None) &&
(attr->mName == kIdAtom)) {
return nsRDFContentUtils::MakeElementResource(mDocument, attr->mValue, aResource);
return gXULUtils->MakeElementResource(mDocument, attr->mValue, aResource);
}
}
}
@ -3088,7 +3102,7 @@ RDFElementImpl::GetRefResource(nsIRDFResource** aResource)
if (attr->mName != kRefAtom)
continue;
return nsRDFContentUtils::MakeElementResource(mDocument, attr->mValue, aResource);
return gXULUtils->MakeElementResource(mDocument, attr->mValue, aResource);
}
}

Просмотреть файл

@ -41,7 +41,7 @@
#include "nsIURL.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "rdf.h"
@ -109,6 +109,8 @@ 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_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_IID(kIDomXulElementIID, NS_IDOMXULELEMENT_IID);
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
@ -186,6 +188,8 @@ private:
static nsIRDFService *gRDFService;
static nsIXULContentUtils *gXULUtils;
nsresult FindTreeElement(nsIContent* aElement,nsIContent** aTreeElement);
nsresult FindTreeChildrenElement(nsIContent *tree, nsIContent **treeBody);
nsresult GetSortColumnIndex(nsIContent *tree, const nsString&sortResource, const nsString& sortDirection, PRInt32 *colIndex);
@ -221,6 +225,8 @@ nsICollation *XULSortServiceImpl::collationService = nsnull;
nsIRDFService *XULSortServiceImpl::gRDFService = nsnull;
nsrefcnt XULSortServiceImpl::gRefCnt = 0;
nsIXULContentUtils *XULSortServiceImpl::gXULUtils = nsnull;
nsIAtom* XULSortServiceImpl::kTreeAtom;
nsIAtom* XULSortServiceImpl::kTreeBodyAtom;
nsIAtom* XULSortServiceImpl::kTreeCellAtom;
@ -275,6 +281,12 @@ XULSortServiceImpl::XULSortServiceImpl(void)
NS_ERROR("couldn't create rdf service");
}
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get XUL content utils");
nsILocaleFactory *localeFactory = nsnull;
nsILocale *locale = nsnull;
@ -369,8 +381,16 @@ XULSortServiceImpl::~XULSortServiceImpl(void)
NS_IF_RELEASE(collationService);
collationService = nsnull;
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
if (gRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
}
}
@ -1120,7 +1140,7 @@ XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, so
for (loop = 0; loop < numElements; loop++)
{
nsIRDFResource *resource;
nsRDFContentUtils::GetElementResource(flatArray[loop], &resource);
gXULUtils->GetElementResource(flatArray[loop], &resource);
// Note that we don't release; see part deux below...
}
@ -1137,7 +1157,7 @@ XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, so
for (loop = 0; loop < numElements; loop++)
{
nsIRDFResource *resource;
nsRDFContentUtils::GetElementResource(flatArray[loop], &resource);
gXULUtils->GetElementResource(flatArray[loop], &resource);
nsrefcnt refcnt;
NS_RELEASE2(resource, refcnt);
NS_RELEASE(resource);
@ -1307,7 +1327,7 @@ XULSortServiceImpl::InsertContainerNode(nsIContent *container, nsIContent *node,
&& (rv == NS_CONTENT_ATTR_HAS_VALUE))
{
nsCOMPtr<nsIRDFResource> containerRes;
rv = nsRDFContentUtils::MakeElementResource(doc, id, getter_AddRefs(containerRes));
rv = gXULUtils->MakeElementResource(doc, id, getter_AddRefs(containerRes));
if (NS_SUCCEEDED(rv)) {
rv = sortInfo.db->HasAssertion(containerRes,

Просмотреть файл

@ -62,7 +62,7 @@
#include "nsIXULSortService.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
@ -93,8 +93,8 @@ 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);
static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
static NS_DEFINE_CID(kIHTMLElementFactoryIID, NS_IHTML_ELEMENT_FACTORY_IID);
@ -277,6 +277,7 @@ protected:
static nsIRDFContainerUtils* gRDFContainerUtils;
static nsINameSpaceManager* gNameSpaceManager;
static nsIHTMLElementFactory* gHTMLElementFactory;
static nsIXULContentUtils* gXULUtils;
static nsIAtom* kContainerAtom;
static nsIAtom* kContainerContentsGeneratedAtom;
@ -358,6 +359,7 @@ nsIRDFService* RDFGenericBuilderImpl::gRDFService;
nsIRDFContainerUtils* RDFGenericBuilderImpl::gRDFContainerUtils;
nsINameSpaceManager* RDFGenericBuilderImpl::gNameSpaceManager;
nsIHTMLElementFactory* RDFGenericBuilderImpl::gHTMLElementFactory;
nsIXULContentUtils* RDFGenericBuilderImpl::gXULUtils;
nsIRDFResource* RDFGenericBuilderImpl::kNC_Title;
nsIRDFResource* RDFGenericBuilderImpl::kNC_child;
@ -441,11 +443,28 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void)
NS_IF_RELEASE(kRDF_instanceOf);
NS_IF_RELEASE(kXUL_element);
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
nsServiceManager::ReleaseService(kXULSortServiceCID, gXULSortService);
if (gRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
if (gRDFContainerUtils) {
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
gRDFContainerUtils = nsnull;
}
if (gXULSortService) {
nsServiceManager::ReleaseService(kXULSortServiceCID, gXULSortService);
gXULSortService = nsnull;
}
NS_RELEASE(gNameSpaceManager);
NS_IF_RELEASE(gHTMLElementFactory);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
}
}
@ -529,7 +548,7 @@ RDFGenericBuilderImpl::Init()
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kXULSortServiceCID,
kIXULSortServiceIID,
nsCOMTypeInfo<nsIXULSortService>::GetIID(),
(nsISupports**) &gXULSortService);
if (NS_FAILED(rv)) return rv;
@ -538,6 +557,11 @@ RDFGenericBuilderImpl::Init()
kIHTMLElementFactoryIID,
(void**) &gHTMLElementFactory);
if (NS_FAILED(rv)) return rv;
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
if (NS_FAILED(rv)) return rv;
}
#ifdef PR_LOGGING
@ -665,7 +689,7 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
nsresult rv;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::GetElementRefResource(aElement, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(aElement, getter_AddRefs(resource));
if (NS_SUCCEEDED(rv)) {
// The element has a resource; that means that it corresponds
// to something in the graph, so we need to go to the graph to
@ -698,7 +722,7 @@ RDFGenericBuilderImpl::OpenContainer(nsIContent* aElement)
return NS_OK;
nsCOMPtr<nsIRDFResource> resource;
rv = nsRDFContentUtils::GetElementRefResource(aElement, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(aElement, getter_AddRefs(resource));
// If it has no resource, there's nothing that we need to be
// concerned about here.
@ -917,7 +941,7 @@ RDFGenericBuilderImpl::CreateElement(PRInt32 aNameSpaceID,
if (NS_FAILED(rv)) return rv;
nsAutoString id;
rv = nsRDFContentUtils::MakeElementID(doc, nsAutoString(uri), id);
rv = gXULUtils->MakeElementID(doc, nsAutoString(uri), id);
if (NS_FAILED(rv)) return rv;
rv = result->SetAttribute(kNameSpaceID_None, kIdAtom, id, PR_FALSE);
@ -1376,7 +1400,7 @@ RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement,
}
else {
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(attrNameSpaceID, attr, getter_AddRefs(property));
rv = gXULUtils->GetResource(attrNameSpaceID, attr, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> target;
@ -1384,7 +1408,7 @@ RDFGenericBuilderImpl::IsTemplateRuleMatch(nsIContent* aElement,
if (NS_FAILED(rv)) return rv;
nsAutoString targetStr;
rv = nsRDFContentUtils::GetTextForNode(target, targetStr);
rv = gXULUtils->GetTextForNode(target, targetStr);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get text for target");
if (NS_FAILED(rv)) return rv;
@ -1540,7 +1564,7 @@ RDFGenericBuilderImpl::GetSubstitutionText(nsIRDFResource* aResource,
if (NS_FAILED(rv)) return rv;
if (valueNode) {
rv = nsRDFContentUtils::GetTextForNode(valueNode, aResult);
rv = gXULUtils->GetTextForNode(valueNode, aResult);
if (NS_FAILED(rv)) return rv;
}
else {
@ -1838,7 +1862,7 @@ RDFGenericBuilderImpl::AddPersistentAttributes(nsIContent* aTemplateNode, nsIRDF
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(nameSpaceID, tag, getter_AddRefs(property));
rv = gXULUtils->GetResource(nameSpaceID, tag, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> target;
@ -1937,7 +1961,7 @@ RDFGenericBuilderImpl::SynchronizeUsingTemplate(nsIContent* aTemplateNode,
if (property.get() == aProperty) {
nsAutoString text("");
rv = nsRDFContentUtils::GetTextForNode(aValue, text);
rv = gXULUtils->GetTextForNode(aValue, text);
if (NS_FAILED(rv)) return rv;
if ((text.Length() > 0) && (aAction == eSet)) {
@ -2020,7 +2044,7 @@ RDFGenericBuilderImpl::RemoveWidgetItem(nsIContent* aElement,
nsCOMPtr<nsIContent> child( do_QueryInterface(isupports) );
NS_IF_RELEASE(isupports);
if (! nsRDFContentUtils::IsContainedBy(child, aElement))
if (! gXULUtils->IsContainedBy(child, aElement))
continue;
nsCOMPtr<nsIContent> parent;
@ -2190,7 +2214,7 @@ RDFGenericBuilderImpl::CreateTemplateContents(nsIContent* aElement, const nsStri
nsCOMPtr<nsIContent> element = aElement;
while (element) {
rv = nsRDFContentUtils::GetElementRefResource(element, getter_AddRefs(resource));
rv = gXULUtils->GetElementRefResource(element, getter_AddRefs(resource));
if (NS_SUCCEEDED(rv)) break;
nsCOMPtr<nsIContent> parent;
@ -2215,7 +2239,7 @@ RDFGenericBuilderImpl::EnsureElementHasGenericChild(nsIContent* parent,
{
nsresult rv;
rv = nsRDFContentUtils::FindChildByTag(parent, nameSpaceID, tag, result);
rv = gXULUtils->FindChildByTag(parent, nameSpaceID, tag, result);
if (NS_FAILED(rv)) return rv;
if (rv == NS_RDF_NO_VALUE) {
@ -2544,7 +2568,7 @@ RDFGenericBuilderImpl::GetDOMNodeResource(nsIDOMNode* aNode, nsIRDFResource** aR
return rv;
}
return nsRDFContentUtils::GetElementRefResource(element, aResource);
return gXULUtils->GetElementRefResource(element, aResource);
}
@ -2564,11 +2588,11 @@ RDFGenericBuilderImpl::FindInsertionPoint(nsIContent* aElement, nsIContent** aRe
if (NS_FAILED(rv)) return rv;
if (tagName.Equals("tree") || tagName.Equals("treeitem")) {
rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("treechildren"), aResult);
rv = gXULUtils->FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("treechildren"), aResult);
if (NS_FAILED(rv)) return rv;
}
else if (tagName.Equals("menu")) {
rv = nsRDFContentUtils::FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("menupopup"), aResult);
rv = gXULUtils->FindChildByTag(aElement, kNameSpaceID_XUL, NS_NewAtom("menupopup"), aResult);
if (NS_FAILED(rv)) return rv;
}
else {
@ -2723,10 +2747,10 @@ RDFGenericBuilderImpl::ForceTreeReflow(nsITimer* aTimer, void* aClosure)
// XXX What if kTreeChildrenAtom & kNameSpaceXUL are clobbered b/c
// the generic builder has been destroyed?
nsCOMPtr<nsIContent> treechildren;
rv = nsRDFContentUtils::FindChildByTag(builder->mRoot,
kNameSpaceID_XUL,
kTreeChildrenAtom,
getter_AddRefs(treechildren));
rv = gXULUtils->FindChildByTag(builder->mRoot,
kNameSpaceID_XUL,
kTreeChildrenAtom,
getter_AddRefs(treechildren));
if (NS_FAILED(rv)) return; // couldn't find

Просмотреть файл

@ -67,7 +67,7 @@
#include "nsIXULContentSink.h"
#include "nsLayoutCID.h"
#include "nsRDFCID.h"
#include "nsRDFContentUtils.h"
#include "nsIXULContentUtils.h"
#include "nsRDFParserUtils.h"
#include "nsVoidArray.h"
#include "prlog.h"
@ -121,6 +121,7 @@ static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kXULContentUtilsCID, NS_XULCONTENTUTILS_CID);
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
@ -176,6 +177,8 @@ protected:
static nsrefcnt gRefCnt;
static nsIRDFService* gRDFService;
static nsIXULContentUtils* gXULUtils;
// pseudo-constants
PRInt32 kNameSpaceID_XUL; // XXX per-instance member variable
@ -270,6 +273,7 @@ protected:
nsrefcnt XULContentSinkImpl::gRefCnt = 0;
nsIRDFService* XULContentSinkImpl::gRDFService = nsnull;
nsIXULContentUtils* XULContentSinkImpl::gXULUtils = nsnull;
nsIRDFResource* XULContentSinkImpl::kRDF_child;
nsIRDFResource* XULContentSinkImpl::kRDF_instanceOf;
@ -320,6 +324,12 @@ XULContentSinkImpl::XULContentSinkImpl()
gRDFService->GetResource(XUL_NAMESPACE_URI "#tag", &kXUL_tag);
gRDFService->GetResource("position", &kPosition);
}
rv = nsServiceManager::GetService(kXULContentUtilsCID,
nsCOMTypeInfo<nsIXULContentUtils>::GetIID(),
(nsISupports**) &gXULUtils);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get XUL content utils");
}
#ifdef PR_LOGGING
@ -443,12 +453,21 @@ XULContentSinkImpl::~XULContentSinkImpl()
PR_FREEIF(mText);
if (--gRefCnt == 0) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
if (gRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
NS_IF_RELEASE(kRDF_child);
NS_IF_RELEASE(kRDF_instanceOf);
NS_IF_RELEASE(kXUL_tag);
NS_IF_RELEASE(kXUL_element);
NS_IF_RELEASE(kPosition);
if (gXULUtils) {
nsServiceManager::ReleaseService(kXULContentUtilsCID, gXULUtils);
gXULUtils = nsnull;
}
}
// Delete all the elements from our overlay array
@ -1270,7 +1289,7 @@ XULContentSinkImpl::GetXULIDAttribute(const nsIParserNode& aNode,
nsRDFParserUtils::StripAndConvert(id);
nsCAutoString uri;
nsRDFContentUtils::MakeElementURI(mDocument, id, uri);
gXULUtils->MakeElementURI(mDocument, id, uri);
return gRDFService->GetResource(uri, aResource);
}
@ -1353,7 +1372,7 @@ XULContentSinkImpl::AddAttributes(const nsIParserNode& aNode,
//if (nameSpaceID == kNameSpaceID_HTML)
// attr.ToLowerCase(); // Not our problem. You'd better be lowercase.
nsCOMPtr<nsIRDFResource> property;
rv = nsRDFContentUtils::GetResource(nameSpaceID, attr, getter_AddRefs(property));
rv = gXULUtils->GetResource(nameSpaceID, attr, getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFLiteral> value;
@ -1422,7 +1441,7 @@ XULContentSinkImpl::OpenTag(const nsIParserNode& aNode)
// Convert the container's namespace/tag pair to a fully qualified
// URI so that we can specify it as an RDF resource.
nsCOMPtr<nsIRDFResource> tagResource;
rv = nsRDFContentUtils::GetResource(nameSpaceID, tag, getter_AddRefs(tagResource));
rv = gXULUtils->GetResource(nameSpaceID, tag, getter_AddRefs(tagResource));
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to construct resource from namespace/tag pair");
if (NS_FAILED(rv)) return rv;