From ae4febb7f604d7164f448001783e431e839954b5 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Thu, 11 Mar 1999 19:48:43 +0000 Subject: [PATCH] Helper class for handling of XUL fragments. --- rdf/content/public/nsIXULDocumentInfo.h | 50 ++++++++++ rdf/content/src/nsXULDocumentInfo.cpp | 120 ++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 rdf/content/public/nsIXULDocumentInfo.h create mode 100644 rdf/content/src/nsXULDocumentInfo.cpp diff --git a/rdf/content/public/nsIXULDocumentInfo.h b/rdf/content/public/nsIXULDocumentInfo.h new file mode 100644 index 000000000000..b7248abe265e --- /dev/null +++ b/rdf/content/public/nsIXULDocumentInfo.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + + The sort service interface. This is a singleton object, and should be + obtained from the nsServiceManager. + */ + +#ifndef nsIXULDocumentInfo_h__ +#define nsIXULDocumentInfo_h__ + +#include "nsISupports.h" + +// {798E24A1-D7A5-11d2-BF86-00105A1B0627} +#define NS_IXULDOCUMENTINFO_IID \ +{ 0x798e24a1, 0xd7a5, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } + +class nsIDocument; +class nsIRDFResource; + +class nsIXULDocumentInfo : public nsISupports { +public: + static const nsIID& GetIID() { static nsIID iid = NS_IXULDOCUMENTINFO_IID; return iid; } + + NS_IMETHOD Init(nsIDocument* aParentDoc, nsIRDFResource* aFragmentRoot) = 0; + NS_IMETHOD GetDocument(nsIDocument** aResult) = 0; + NS_IMETHOD GetResource(nsIRDFResource** aResult) = 0; +}; + + +extern nsresult +NS_NewXULDocumentInfo(nsIXULDocumentInfo** result); + +#endif // nsIXULDocumentInfo_h__ diff --git a/rdf/content/src/nsXULDocumentInfo.cpp b/rdf/content/src/nsXULDocumentInfo.cpp new file mode 100644 index 000000000000..4eba416ea51c --- /dev/null +++ b/rdf/content/src/nsXULDocumentInfo.cpp @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + This file provides the implementation for the sort service manager. + */ + + +#include "nsIXULDocumentInfo.h" +#include "nsIDocument.h" +#include "nsIRDFResource.h" +#include "nsRDFCID.h" + +//////////////////////////////////////////////////////////////////////// + +static NS_DEFINE_IID(kXULDocumentInfoCID, NS_XULDOCUMENTINFO_CID); +static NS_DEFINE_IID(kIXULDocumentInfoIID, NS_IXULDOCUMENTINFO_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + + +//////////////////////////////////////////////////////////////////////// +// DocumentInfoImpl +// +// This is the document info object passed to the doc loader +// +class XULDocumentInfoImpl : public nsIXULDocumentInfo +{ +public: + XULDocumentInfoImpl(void); + virtual ~XULDocumentInfoImpl(void); + + // nsISupports + NS_DECL_ISUPPORTS + + // nsIDocumentInfo + NS_IMETHOD Init(nsIDocument* aDocument, nsIRDFResource* aResource); + NS_IMETHOD GetDocument(nsIDocument** aDocument); + NS_IMETHOD GetResource(nsIRDFResource** aResource); + +private: + nsIDocument* mParentDocument; + nsIRDFResource* mFragmentRoot; +}; + + +//////////////////////////////////////////////////////////////////////// + +XULDocumentInfoImpl::XULDocumentInfoImpl(void) +:mParentDocument(nsnull), mFragmentRoot(nsnull) +{ + NS_INIT_REFCNT(); +} + + +XULDocumentInfoImpl::~XULDocumentInfoImpl(void) +{ + NS_IF_RELEASE(mParentDocument); + NS_IF_RELEASE(mFragmentRoot); +} + +nsresult +XULDocumentInfoImpl::Init(nsIDocument* aDocument, nsIRDFResource* aResource) { + NS_IF_RELEASE(aDocument); + NS_IF_RELEASE(aResource); + + mParentDocument = aDocument; + mFragmentRoot = aResource; + + NS_IF_ADDREF(mParentDocument); + NS_IF_ADDREF(mFragmentRoot); + + return NS_OK; +} + +nsresult +XULDocumentInfoImpl::GetDocument(nsIDocument** aDocument) { + NS_IF_ADDREF(mParentDocument); + *aDocument = mParentDocument; + return NS_OK; +} + +nsresult +XULDocumentInfoImpl::GetResource(nsIRDFResource** aResource) { + NS_IF_ADDREF(mFragmentRoot); + *aResource = mFragmentRoot; + return NS_OK; +} + +NS_IMPL_ADDREF(XULDocumentInfoImpl); +NS_IMPL_RELEASE(XULDocumentInfoImpl); + +NS_IMPL_QUERY_INTERFACE(XULDocumentInfoImpl, kIXULDocumentInfoIID); + +//////////////////////////////////////////////////////////////////////// + + +nsresult +NS_NewXULDocumentInfo(nsIXULDocumentInfo** aResult) +{ + XULDocumentInfoImpl* info = new XULDocumentInfoImpl(); + NS_ADDREF(info); + *aResult = info; + return NS_OK; +} +