added observerdictionary

This commit is contained in:
rickg%netscape.com 1999-04-21 05:36:47 +00:00
parent 95b615b350
commit 1f73279dd4
6 changed files with 206 additions and 0 deletions

View File

@ -161,6 +161,7 @@ public:
//CTagHandlerRegister gTagHandlerRegister;
/************************************************************************
And now for the main class -- CNavDTD...
************************************************************************/
@ -1008,6 +1009,7 @@ void WriteTokenToLog(CToken* aToken) {
}
#endif
/**
* This gets called before we've handled a given start tag.
* It's a generic hook to let us do pre processing.
@ -1025,6 +1027,23 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode
result=CollectSkippedContent(aNode,theAttrCount);
}
/**********************************************************
THIS WILL ULTIMATELY BECOME THE REAL OBSERVER API...
**********************************************************
static CObserverDictionary gObserverDictionary;
nsDeque* theDeque=gObserverDictionary.GetObserversForTag(aTag);
if(theDeque){
int theSize=theDeque->GetSize();
int theIndex=0;
for(theIndex=0;theIndex<theSize;theIndex++){
nsIObserver* theObserver=theDeque->ObjectAt(theIndex);
if(theObserver){
theObserver->Notify();
}
}
}
*/
//**********************************************************
//XXX Hack until I get the node observer API in place...
@ -2918,3 +2937,6 @@ nsresult CNavDTD::DoFragment(PRBool aFlag)
return NS_OK;
}

View File

@ -513,3 +513,64 @@ PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size
return crc_accum;
}
/******************************************************************************
This class is used to store ref's to tag observers during the parse phase.
Note that for simplicity, this is a singleton that is constructed in the
CNavDTD and shared for the duration of the application session. Later on it
might be nice to use a more dynamic approach that would permit observers to
come and go on a document basis.
******************************************************************************/
CObserverDictionary::CObserverDictionary() {
nsCRT::zero(mObservers,sizeof(mObservers));
RegisterObservers();
}
CObserverDictionary::~CObserverDictionary() {
UnregisterObservers();
}
void CObserverDictionary::UnregisterObservers() {
int theIndex=0;
for(theIndex=0;theIndex<NS_HTML_TAG_MAX;theIndex++){
if(mObservers[theIndex]){
/*
nsIObserver* theObserver=0;
while(theObserver=mObserver[theIndex]->Pop()){
NS_RELEASE(theObserver);
}
*/
}
}
}
void CObserverDictionary::RegisterObservers() {
/*
nsIObserverService* theObserverService=GetService("observer"); //or whatever the call is here...
if(theObserverService){
nsIObserverEnumerator* theEnum=theObserverService->GetObserversForTopic("htmlparser"); //again, put the real call here!
if(theEnum){
nsIObserver* theObserver=theEnum->First();
while(theObserver){
const char* theTagStr=theObserver->GetTag();
if(theTagStr){
eHTMLTags theTag=NS_TagToEnum(theTagStr);
if(eHTMLTag_userdefined!=theTag){
nsDeque* theDeque=mObservers[theTag];
if(theDeque){
NS_ADDREF(theObserver);
theDeque->Push(theObserver);
}
}
}
theObserver=theEnum->Next();
}
}
}
*/
}
nsDeque* CObserverDictionary::GetObserversForTag(eHTMLTags aTag) {
nsDeque* result=mObservers[aTag];
return result;
}

View File

@ -234,6 +234,26 @@ struct CRCStruct {
PRInt32 mOperation; //usually open or close
};
/******************************************************************************
This class is used to store ref's to token observers during the parse phase.
Note that for simplicity, this is a singleton that is constructed in the
CNavDTD and shared for the duration of the application session. Later on it
might be nice to use a more dynamic approach that would permit observers to
come and go on a document basis.
******************************************************************************/
class CObserverDictionary {
public:
CObserverDictionary();
~CObserverDictionary();
void RegisterObservers();
void UnregisterObservers();
nsDeque* GetObserversForTag(eHTMLTags aTag);
protected:
nsDeque* mObservers[NS_HTML_TAG_MAX];
};
#endif

View File

@ -161,6 +161,7 @@ public:
//CTagHandlerRegister gTagHandlerRegister;
/************************************************************************
And now for the main class -- CNavDTD...
************************************************************************/
@ -1008,6 +1009,7 @@ void WriteTokenToLog(CToken* aToken) {
}
#endif
/**
* This gets called before we've handled a given start tag.
* It's a generic hook to let us do pre processing.
@ -1025,6 +1027,23 @@ nsresult CNavDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNode
result=CollectSkippedContent(aNode,theAttrCount);
}
/**********************************************************
THIS WILL ULTIMATELY BECOME THE REAL OBSERVER API...
**********************************************************
static CObserverDictionary gObserverDictionary;
nsDeque* theDeque=gObserverDictionary.GetObserversForTag(aTag);
if(theDeque){
int theSize=theDeque->GetSize();
int theIndex=0;
for(theIndex=0;theIndex<theSize;theIndex++){
nsIObserver* theObserver=theDeque->ObjectAt(theIndex);
if(theObserver){
theObserver->Notify();
}
}
}
*/
//**********************************************************
//XXX Hack until I get the node observer API in place...
@ -2918,3 +2937,6 @@ nsresult CNavDTD::DoFragment(PRBool aFlag)
return NS_OK;
}

View File

@ -513,3 +513,64 @@ PRUint32 AccumulateCRC(PRUint32 crc_accum, char *data_blk_ptr, int data_blk_size
return crc_accum;
}
/******************************************************************************
This class is used to store ref's to tag observers during the parse phase.
Note that for simplicity, this is a singleton that is constructed in the
CNavDTD and shared for the duration of the application session. Later on it
might be nice to use a more dynamic approach that would permit observers to
come and go on a document basis.
******************************************************************************/
CObserverDictionary::CObserverDictionary() {
nsCRT::zero(mObservers,sizeof(mObservers));
RegisterObservers();
}
CObserverDictionary::~CObserverDictionary() {
UnregisterObservers();
}
void CObserverDictionary::UnregisterObservers() {
int theIndex=0;
for(theIndex=0;theIndex<NS_HTML_TAG_MAX;theIndex++){
if(mObservers[theIndex]){
/*
nsIObserver* theObserver=0;
while(theObserver=mObserver[theIndex]->Pop()){
NS_RELEASE(theObserver);
}
*/
}
}
}
void CObserverDictionary::RegisterObservers() {
/*
nsIObserverService* theObserverService=GetService("observer"); //or whatever the call is here...
if(theObserverService){
nsIObserverEnumerator* theEnum=theObserverService->GetObserversForTopic("htmlparser"); //again, put the real call here!
if(theEnum){
nsIObserver* theObserver=theEnum->First();
while(theObserver){
const char* theTagStr=theObserver->GetTag();
if(theTagStr){
eHTMLTags theTag=NS_TagToEnum(theTagStr);
if(eHTMLTag_userdefined!=theTag){
nsDeque* theDeque=mObservers[theTag];
if(theDeque){
NS_ADDREF(theObserver);
theDeque->Push(theObserver);
}
}
}
theObserver=theEnum->Next();
}
}
}
*/
}
nsDeque* CObserverDictionary::GetObserversForTag(eHTMLTags aTag) {
nsDeque* result=mObservers[aTag];
return result;
}

View File

@ -234,6 +234,26 @@ struct CRCStruct {
PRInt32 mOperation; //usually open or close
};
/******************************************************************************
This class is used to store ref's to token observers during the parse phase.
Note that for simplicity, this is a singleton that is constructed in the
CNavDTD and shared for the duration of the application session. Later on it
might be nice to use a more dynamic approach that would permit observers to
come and go on a document basis.
******************************************************************************/
class CObserverDictionary {
public:
CObserverDictionary();
~CObserverDictionary();
void RegisterObservers();
void UnregisterObservers();
nsDeque* GetObserversForTag(eHTMLTags aTag);
protected:
nsDeque* mObservers[NS_HTML_TAG_MAX];
};
#endif