Add preliminary support for pulsing a container to see if its contents change.

This commit is contained in:
rjc%netscape.com 1999-04-05 23:10:43 +00:00
Родитель 305a97cf84
Коммит 0194c8fecc
9 изменённых файлов: 258 добавлений и 15 удалений

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

@ -63,7 +63,9 @@
#include "nsXPIDLString.h"
#include "rdf.h"
#include "rdfutil.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsIDOMXULElement.h"
#include "nsVoidArray.h"
#include "nsIXULSortService.h"
@ -121,13 +123,15 @@ nsIRDFResource* RDFGenericBuilderImpl::kNC_Column;
nsIRDFResource* RDFGenericBuilderImpl::kNC_Folder;
nsIRDFResource* RDFGenericBuilderImpl::kRDF_child;
////////////////////////////////////////////////////////////////////////
RDFGenericBuilderImpl::RDFGenericBuilderImpl(void)
: mDocument(nsnull),
mDB(nsnull),
mRoot(nsnull)
mRoot(nsnull),
mTimer(nsnull)
{
NS_INIT_REFCNT();
@ -192,6 +196,14 @@ static const char kRDFNameSpaceURI[]
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURIRDF_child, &kRDF_child)),
"couldn't get resource");
}
NS_VERIFY(NS_SUCCEEDED(NS_NewTimer(&mTimer)),
"couldn't get timer");
if (mTimer)
{
mTimer->Init(this, /* PR_TRUE, */ 1L);
}
++gRefCnt;
@ -225,6 +237,13 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void)
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
NS_RELEASE(gNameSpaceManager);
}
if (mTimer)
{
mTimer->Cancel();
NS_RELEASE(mTimer);
mTimer = nsnull;
}
}
////////////////////////////////////////////////////////////////////////

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

@ -33,6 +33,7 @@
#include "nsString.h"
#include "nsXPIDLString.h"
#include "prlog.h"
#include "nsCOMPtr.h"
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
@ -95,3 +96,35 @@ error:
}
nsresult
nsRDFContentUtils::FindTreeBodyElement(nsIContent *tree, nsIContent **treeBody)
{
nsCOMPtr<nsIContent> child;
PRInt32 childIndex = 0, numChildren = 0, nameSpaceID;
nsresult rv;
nsIAtom *treeBodyAtom = NS_NewAtom("treebody");
if (NS_FAILED(rv = tree->ChildCount(numChildren))) return(rv);
for (childIndex=0; childIndex<numChildren; childIndex++)
{
if (NS_FAILED(rv = tree->ChildAt(childIndex, *getter_AddRefs(child)))) return(rv);
if (NS_FAILED(rv = child->GetNameSpaceID(nameSpaceID))) return rv;
// if (nameSpaceID == kNameSpaceID_XUL)
if (1)
{
nsCOMPtr<nsIAtom> tag;
if (NS_FAILED(rv = child->GetTag(*getter_AddRefs(tag)))) return rv;
if (tag.get() == treeBodyAtom)
{
*treeBody = child;
NS_ADDREF(*treeBody);
return NS_OK;
}
}
}
NS_RELEASE(treeBodyAtom);
return(NS_ERROR_FAILURE);
}

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

@ -41,6 +41,9 @@ public:
static nsresult
AttachTextNode(nsIContent* parent, nsIRDFNode* value);
static nsresult
FindTreeBodyElement(nsIContent *tree, nsIContent **treeBody);
};

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

@ -63,7 +63,9 @@
#include "nsXPIDLString.h"
#include "rdf.h"
#include "rdfutil.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsIDOMXULElement.h"
#include "nsVoidArray.h"
#include "nsIXULSortService.h"
@ -121,13 +123,15 @@ nsIRDFResource* RDFGenericBuilderImpl::kNC_Column;
nsIRDFResource* RDFGenericBuilderImpl::kNC_Folder;
nsIRDFResource* RDFGenericBuilderImpl::kRDF_child;
////////////////////////////////////////////////////////////////////////
RDFGenericBuilderImpl::RDFGenericBuilderImpl(void)
: mDocument(nsnull),
mDB(nsnull),
mRoot(nsnull)
mRoot(nsnull),
mTimer(nsnull)
{
NS_INIT_REFCNT();
@ -192,6 +196,14 @@ static const char kRDFNameSpaceURI[]
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURIRDF_child, &kRDF_child)),
"couldn't get resource");
}
NS_VERIFY(NS_SUCCEEDED(NS_NewTimer(&mTimer)),
"couldn't get timer");
if (mTimer)
{
mTimer->Init(this, /* PR_TRUE, */ 1L);
}
++gRefCnt;
@ -225,6 +237,13 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void)
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
NS_RELEASE(gNameSpaceManager);
}
if (mTimer)
{
mTimer->Cancel();
NS_RELEASE(mTimer);
mTimer = nsnull;
}
}
////////////////////////////////////////////////////////////////////////

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

@ -28,6 +28,8 @@
#include "nsIRDFObserver.h"
#include "nsIDOMNodeObserver.h"
#include "nsIDOMElementObserver.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
class nsIRDFDocument;
class nsIRDFCompositeDataSource;
@ -40,7 +42,8 @@ class nsIRDFService;
class RDFGenericBuilderImpl : public nsIRDFContentModelBuilder,
public nsIRDFObserver,
public nsIDOMNodeObserver,
public nsIDOMElementObserver
public nsIDOMElementObserver,
public nsITimerCallback
{
public:
RDFGenericBuilderImpl();
@ -164,6 +167,11 @@ protected:
nsIRDFCompositeDataSource* mDB;
nsIContent* mRoot;
nsITimer *mTimer;
virtual void
Notify(nsITimer *timer) = 0;
// pseudo-constants
static nsrefcnt gRefCnt;
static nsIRDFService* gRDFService;

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

@ -47,7 +47,7 @@
#include "nsXPIDLString.h"
#include "rdf.h"
#include "rdfutil.h"
#include "nsITimer.h"
#include "nsVoidArray.h"
#include "rdf_qsort.h"
@ -132,6 +132,9 @@ public:
return NS_OK;
}
void
Notify(nsITimer *timer);
// pseudo-constants
static nsrefcnt gRefCnt;
@ -191,6 +194,11 @@ RDFMenuBuilderImpl::~RDFMenuBuilderImpl(void)
}
}
void
RDFMenuBuilderImpl::Notify(nsITimer *timer)
{
}
////////////////////////////////////////////////////////////////////////
// Implementation methods

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

@ -133,6 +133,9 @@ public:
return NS_OK;
}
void
Notify(nsITimer *timer);
// pseudo-constants
static nsrefcnt gRefCnt;
@ -188,6 +191,11 @@ RDFToolbarBuilderImpl::~RDFToolbarBuilderImpl(void)
}
}
void
RDFToolbarBuilderImpl::Notify(nsITimer *timer)
{
}
////////////////////////////////////////////////////////////////////////
// Implementation methods

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

@ -62,10 +62,9 @@
#include "nsXPIDLString.h"
#include "rdf.h"
#include "rdfutil.h"
#include "nsITimer.h"
#include "nsVoidArray.h"
#include "rdf_qsort.h"
#include "nsRDFGenericBuilder.h"
////////////////////////////////////////////////////////////////////////
@ -93,6 +92,10 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kIDomXulElementIID, NS_IDOMXULELEMENT_IID);
#define BUILDER_NOTIFY_MINIMUM_TIMEOUT 5000L
////////////////////////////////////////////////////////////////////////
class RDFTreeBuilderImpl : public RDFGenericBuilderImpl
@ -174,6 +177,12 @@ public:
return NS_OK;
}
nsresult
UpdateContainer(nsIContent *container);
void
Notify(nsITimer *timer);
// pseudo-constants
static nsrefcnt gRefCnt;
@ -187,8 +196,9 @@ public:
static nsIAtom* kTreeIconAtom;
static nsIAtom* kTreeIndentationAtom;
static nsIAtom* kTreeItemAtom;
static nsIAtom* kTitledButtonAtom;
static nsIAtom* kPulseAtom;
static nsIAtom* kOpenAtom;
};
////////////////////////////////////////////////////////////////////////
@ -205,8 +215,9 @@ nsIAtom* RDFTreeBuilderImpl::kTreeHeadAtom;
nsIAtom* RDFTreeBuilderImpl::kTreeIconAtom;
nsIAtom* RDFTreeBuilderImpl::kTreeIndentationAtom;
nsIAtom* RDFTreeBuilderImpl::kTreeItemAtom;
nsIAtom* RDFTreeBuilderImpl::kTitledButtonAtom;
nsIAtom* RDFTreeBuilderImpl::kPulseAtom;
nsIAtom* RDFTreeBuilderImpl::kOpenAtom;
////////////////////////////////////////////////////////////////////////
@ -242,10 +253,10 @@ RDFTreeBuilderImpl::RDFTreeBuilderImpl(void)
kTreeIconAtom = NS_NewAtom("treeicon");
kTreeIndentationAtom = NS_NewAtom("treeindentation");
kTreeItemAtom = NS_NewAtom("treeitem");
kTitledButtonAtom = NS_NewAtom("titledbutton");
kPulseAtom = NS_NewAtom("pulse");
kOpenAtom = NS_NewAtom("open");
}
++gRefCnt;
}
@ -263,11 +274,126 @@ RDFTreeBuilderImpl::~RDFTreeBuilderImpl(void)
NS_RELEASE(kTreeIconAtom);
NS_RELEASE(kTreeIndentationAtom);
NS_RELEASE(kTreeItemAtom);
NS_RELEASE(kTitledButtonAtom);
NS_RELEASE(kPulseAtom);
NS_RELEASE(kOpenAtom);
}
}
nsresult
RDFTreeBuilderImpl::UpdateContainer(nsIContent *container)
{
PRInt32 childIndex = 0, numChildren = 0, numGrandChildren, grandChildrenIndex, nameSpaceID;
nsCOMPtr<nsIContent> child, grandChild;
nsresult rv;
if (NS_FAILED(rv = container->ChildCount(numChildren))) return(rv);
for (childIndex=0; childIndex<numChildren; childIndex++)
{
if (NS_FAILED(rv = container->ChildAt(childIndex, *getter_AddRefs(child)))) break;
if (NS_FAILED(rv = child->GetNameSpaceID(nameSpaceID))) break;
if (nameSpaceID == kNameSpaceID_XUL)
{
nsCOMPtr<nsIAtom> tag;
if (NS_FAILED(rv = child->GetTag(*getter_AddRefs(tag)))) return rv;
if (tag.get() == kTreeItemAtom)
{
nsIDOMXULElement *dom;
if (NS_SUCCEEDED(rv = child->QueryInterface(kIDomXulElementIID, (void **)&dom)))
{
nsAutoString open("");
if (NS_SUCCEEDED(rv = child->GetAttribute(kNameSpaceID_None, kOpenAtom, open)))
{
if (open.EqualsIgnoreCase("true"))
{
nsAutoString pulse("");
if (NS_SUCCEEDED(rv = child->GetAttribute(kNameSpaceID_None, kPulseAtom, pulse)))
{
if ((rv == NS_CONTENT_ATTR_HAS_VALUE) && (pulse.Length() > 0))
{
#ifdef DEBUG
nsIRDFResource *res;
if (NS_SUCCEEDED(rv = dom->GetResource(&res)))
{
nsXPIDLCString uri;
res->GetValue( getter_Copies(uri) );
const char *url = uri;
printf(" URL wants a pulse: '%s'\n", url);
NS_RELEASE(res);
}
#endif
}
}
// recurse on grandchildren
if (NS_FAILED(rv = child->ChildCount(numGrandChildren))) continue;
for (grandChildrenIndex=0; grandChildrenIndex<numGrandChildren; grandChildrenIndex++)
{
if (NS_FAILED(rv = child->ChildAt(grandChildrenIndex, *getter_AddRefs(grandChild))))
continue;
if (NS_FAILED(rv = grandChild->GetNameSpaceID(nameSpaceID))) continue;
if (nameSpaceID == kNameSpaceID_XUL)
{
nsCOMPtr<nsIAtom> tag;
if (NS_FAILED(rv = grandChild->GetTag(*getter_AddRefs(tag))))
continue;
if (tag.get() == kTreeChildrenAtom)
{
UpdateContainer(grandChild);
}
}
}
}
}
NS_RELEASE(dom);
}
}
}
}
return(NS_OK);
}
void
RDFTreeBuilderImpl::Notify(nsITimer *timer)
{
NS_VERIFY(NS_SUCCEEDED(NS_NewTimer(&mTimer)),
"couldn't get timer");
if (!mTimer) return;
if (mRoot)
{
#ifdef DEBUG
nsIDOMXULElement *domElement;
nsresult rv;
if (NS_SUCCEEDED(rv = mRoot->QueryInterface(kIDomXulElementIID, (void **)&domElement)))
{
nsIRDFResource *res;
if (NS_SUCCEEDED(rv = domElement->GetResource(&res)))
{
nsXPIDLCString uri;
res->GetValue( getter_Copies(uri) );
const char *url = uri;
printf("Timer fired for '%s'\n", url);
NS_RELEASE(res);
}
NS_RELEASE(domElement);
}
#endif
nsIContent *treeBody;
if (NS_SUCCEEDED(rv = nsRDFContentUtils::FindTreeBodyElement(mRoot, &treeBody)))
{
UpdateContainer(treeBody);
NS_RELEASE(treeBody);
}
}
// reschedule
mTimer->Init(this, /* PR_TRUE, */ BUILDER_NOTIFY_MINIMUM_TIMEOUT);
}
////////////////////////////////////////////////////////////////////////
// nsIRDFContentModelBuilder interface

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

@ -63,7 +63,9 @@
#include "nsXPIDLString.h"
#include "rdf.h"
#include "rdfutil.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsIDOMXULElement.h"
#include "nsVoidArray.h"
#include "nsIXULSortService.h"
@ -121,13 +123,15 @@ nsIRDFResource* RDFGenericBuilderImpl::kNC_Column;
nsIRDFResource* RDFGenericBuilderImpl::kNC_Folder;
nsIRDFResource* RDFGenericBuilderImpl::kRDF_child;
////////////////////////////////////////////////////////////////////////
RDFGenericBuilderImpl::RDFGenericBuilderImpl(void)
: mDocument(nsnull),
mDB(nsnull),
mRoot(nsnull)
mRoot(nsnull),
mTimer(nsnull)
{
NS_INIT_REFCNT();
@ -192,6 +196,14 @@ static const char kRDFNameSpaceURI[]
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURIRDF_child, &kRDF_child)),
"couldn't get resource");
}
NS_VERIFY(NS_SUCCEEDED(NS_NewTimer(&mTimer)),
"couldn't get timer");
if (mTimer)
{
mTimer->Init(this, /* PR_TRUE, */ 1L);
}
++gRefCnt;
@ -225,6 +237,13 @@ RDFGenericBuilderImpl::~RDFGenericBuilderImpl(void)
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
NS_RELEASE(gNameSpaceManager);
}
if (mTimer)
{
mTimer->Cancel();
NS_RELEASE(mTimer);
mTimer = nsnull;
}
}
////////////////////////////////////////////////////////////////////////