Changed GetTagName api to return a tag for the index passed in.

This enables observers to register for more than one tag.
This commit is contained in:
neeti%netscape.com 1999-05-17 20:00:58 +00:00
Родитель d0b617b231
Коммит 3ac427b96c
7 изменённых файлов: 66 добавлений и 48 удалений

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

@ -40,7 +40,7 @@ public:
* This method return the tag which the observer care about * This method return the tag which the observer care about
*/ */
// NS_IMETHOD GetTagName(const char * oTag); // NS_IMETHOD GetTagName(const char * oTag);
NS_IMETHOD_(const char*) GetTagName(); NS_IMETHOD_(const char*)GetTagNameAt(PRUint32 aTagIndex);
/* /*
* Subject call observer when the parser hit the tag * Subject call observer when the parser hit the tag

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

@ -28,6 +28,7 @@
#include "nsIPICS.h" #include "nsIPICS.h"
#include "nspics.h" #include "nspics.h"
#include "nsIWebShellServices.h" #include "nsIWebShellServices.h"
#include "plstr.h"
#include "prenv.h" #include "prenv.h"
//static NS_DEFINE_IID(kIObserverIID, NS_IOBSERVER_IID); //static NS_DEFINE_IID(kIObserverIID, NS_IOBSERVER_IID);
@ -108,10 +109,15 @@ NS_IMETHODIMP nsPICSElementObserver::QueryInterface(REFNSIID aIID, void** aInsta
return NS_NOINTERFACE; return NS_NOINTERFACE;
} }
const char* nsPICSElementObserver::GetTagName() const char* nsPICSElementObserver::GetTagNameAt(PRUint32 aTagIndex)
{ {
return "META"; if (aTagIndex == 0) {
// return NS_OK; return "META";
} if (aTagIndex == 1) {
return "BODY";
}else {
return nsnull;
}
} }
NS_IMETHODIMP nsPICSElementObserver::Notify(PRUint32 aDocumentID, eHTMLTags aTag, NS_IMETHODIMP nsPICSElementObserver::Notify(PRUint32 aDocumentID, eHTMLTags aTag,
@ -126,42 +132,44 @@ NS_IMETHODIMP nsPICSElementObserver::Notify(PRUint32 aDocumentID, eHTMLTags aTag
nsIURL* uaURL = nsnull; nsIURL* uaURL = nsnull;
// rv = NS_NewURL(&uaURL, nsString(aSpec)); // rv = NS_NewURL(&uaURL, nsString(aSpec));
if(numOfAttributes >= 2) { if(aTag == eHTMLTag_meta) {
const nsString& theValue1=valueArray[0]; if(numOfAttributes >= 2) {
char *val1 = theValue1.ToNewCString(); const nsString& theValue1=valueArray[0];
if(theValue1.EqualsIgnoreCase("\"PICS-LABEL\"")) { char *val1 = theValue1.ToNewCString();
printf("\nReceived notification for a PICS-LABEl\n"); if(theValue1.EqualsIgnoreCase("\"PICS-LABEL\"")) {
const nsString& theValue2=valueArray[1]; printf("\nReceived notification for a PICS-LABEl\n");
char *label = theValue2.ToNewCString(); const nsString& theValue2=valueArray[1];
if (valueArray[numOfAttributes]) { char *label = theValue2.ToNewCString();
const nsString& theURLValue=valueArray[numOfAttributes]; if (valueArray[numOfAttributes]) {
rv = NS_NewURL(&uaURL, theURLValue); const nsString& theURLValue=valueArray[numOfAttributes];
} rv = NS_NewURL(&uaURL, theURLValue);
nsIPICS *pics = NULL; }
rv = nsRepository::CreateInstance(kPICSCID, nsIPICS *pics = NULL;
NULL, rv = nsRepository::CreateInstance(kPICSCID,
kIPICSIID, NULL,
(void **) &pics); kIPICSIID,
if(rv == NS_OK) { (void **) &pics);
pics->GetWebShell(aDocumentID, ws); if(rv == NS_OK) {
if(ws) { pics->GetWebShell(aDocumentID, ws);
status = pics->ProcessPICSLabel(label); if(ws) {
if(uaURL) status = pics->ProcessPICSLabel(label);
pics->SetNotified(ws, uaURL, PR_TRUE); if(uaURL)
pics->SetNotified(ws, uaURL, PR_TRUE);
if(status) { if(status) {
if(ws) { if(ws) {
char * text = PR_GetEnv("NGLAYOUT_HOME"); char * text = PR_GetEnv("NGLAYOUT_HOME");
nsString mtemplateURL = text ? text : "resource:/res/samples/picstest1.html"; nsString mtemplateURL = text ? text : "resource:/res/samples/picstest1.html";
// ws->LoadURL(mtemplateURL, nsnull, nsnull); // ws->LoadURL(mtemplateURL, nsnull, nsnull);
nsCharsetSource s; nsCharsetSource s;
ws->SetRendering(PR_TRUE); ws->SetRendering(PR_TRUE);
ws->StopDocumentLoad(); ws->StopDocumentLoad();
ws->LoadDocument("resource:/res/samples/picstest1.html", nsnull, s); ws->LoadDocument("resource:/res/samples/picstest1.html", nsnull, s);
}
} }
} }
} }
} }
} }
} }
return NS_OK; return NS_OK;

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

@ -673,9 +673,10 @@ void CObserverDictionary::RegisterObservers() {
if (NS_SUCCEEDED(result)) if (NS_SUCCEEDED(result))
result = inst->QueryInterface(nsIElementObserver::GetIID(), (void**)&theElementObserver); result = inst->QueryInterface(nsIElementObserver::GetIID(), (void**)&theElementObserver);
if(result == NS_OK) { if(result == NS_OK) {
const char* theTagStr; const char* theTagStr = nsnull;
theTagStr = theElementObserver->GetTagName(); PRUint32 theTagIndex = 0;
if(theTagStr != nsnull) { theTagStr = theElementObserver->GetTagNameAt(theTagIndex);
while (theTagStr != nsnull) {
eHTMLTags theTag = NS_TagToEnum(theTagStr); eHTMLTags theTag = NS_TagToEnum(theTagStr);
if(eHTMLTag_userdefined!=theTag){ if(eHTMLTag_userdefined!=theTag){
if(mObservers[theTag] == nsnull) { if(mObservers[theTag] == nsnull) {
@ -684,6 +685,8 @@ void CObserverDictionary::RegisterObservers() {
NS_ADDREF(theElementObserver); NS_ADDREF(theElementObserver);
mObservers[theTag]->Push(theElementObserver); mObservers[theTag]->Push(theElementObserver);
} }
theTagIndex++;
theTagStr = theElementObserver->GetTagNameAt(theTagIndex);
} }
} }
} }

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

@ -44,7 +44,7 @@ public:
/* /*
* This method return the tag which the observer care about * This method return the tag which the observer care about
*/ */
NS_IMETHOD_(const char*)GetTagName() = 0; NS_IMETHOD_(const char*)GetTagNameAt(PRUint32 aTagIndex) = 0;
/* /*
* Subject call observer when the parser hit the tag * Subject call observer when the parser hit the tag

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

@ -58,7 +58,7 @@ public:
/* /*
* This method return the tag which the observer care about * This method return the tag which the observer care about
*/ */
NS_IMETHOD_(const char*) GetTagName(); NS_IMETHOD_(const char*)GetTagNameAt(PRUint32 aTagIndex);
/* /*
* Subject call observer when the parser hit the tag * Subject call observer when the parser hit the tag
@ -133,9 +133,13 @@ NS_IMETHODIMP nsMetaCharsetObserver::QueryInterface(REFNSIID aIID, void** aInsta
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
NS_IMETHODIMP_(const char*) nsMetaCharsetObserver::GetTagName() NS_IMETHODIMP_(const char*) nsMetaCharsetObserver::GetTagNameAt(PRUint32 aTagIndex)
{ {
return "META"; if (aTagIndex == 0) {
return "META";
}else {
return nsnull;
}
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------

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

@ -673,9 +673,10 @@ void CObserverDictionary::RegisterObservers() {
if (NS_SUCCEEDED(result)) if (NS_SUCCEEDED(result))
result = inst->QueryInterface(nsIElementObserver::GetIID(), (void**)&theElementObserver); result = inst->QueryInterface(nsIElementObserver::GetIID(), (void**)&theElementObserver);
if(result == NS_OK) { if(result == NS_OK) {
const char* theTagStr; const char* theTagStr = nsnull;
theTagStr = theElementObserver->GetTagName(); PRUint32 theTagIndex = 0;
if(theTagStr != nsnull) { theTagStr = theElementObserver->GetTagNameAt(theTagIndex);
while (theTagStr != nsnull) {
eHTMLTags theTag = NS_TagToEnum(theTagStr); eHTMLTags theTag = NS_TagToEnum(theTagStr);
if(eHTMLTag_userdefined!=theTag){ if(eHTMLTag_userdefined!=theTag){
if(mObservers[theTag] == nsnull) { if(mObservers[theTag] == nsnull) {
@ -684,6 +685,8 @@ void CObserverDictionary::RegisterObservers() {
NS_ADDREF(theElementObserver); NS_ADDREF(theElementObserver);
mObservers[theTag]->Push(theElementObserver); mObservers[theTag]->Push(theElementObserver);
} }
theTagIndex++;
theTagStr = theElementObserver->GetTagNameAt(theTagIndex);
} }
} }
} }

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

@ -44,7 +44,7 @@ public:
/* /*
* This method return the tag which the observer care about * This method return the tag which the observer care about
*/ */
NS_IMETHOD_(const char*)GetTagName() = 0; NS_IMETHOD_(const char*)GetTagNameAt(PRUint32 aTagIndex) = 0;
/* /*
* Subject call observer when the parser hit the tag * Subject call observer when the parser hit the tag