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
*/
// 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

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

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

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

@ -673,9 +673,10 @@ void CObserverDictionary::RegisterObservers() {
if (NS_SUCCEEDED(result))
result = inst->QueryInterface(nsIElementObserver::GetIID(), (void**)&theElementObserver);
if(result == NS_OK) {
const char* theTagStr;
theTagStr = theElementObserver->GetTagName();
if(theTagStr != nsnull) {
const char* theTagStr = nsnull;
PRUint32 theTagIndex = 0;
theTagStr = theElementObserver->GetTagNameAt(theTagIndex);
while (theTagStr != nsnull) {
eHTMLTags theTag = NS_TagToEnum(theTagStr);
if(eHTMLTag_userdefined!=theTag){
if(mObservers[theTag] == nsnull) {
@ -684,6 +685,8 @@ void CObserverDictionary::RegisterObservers() {
NS_ADDREF(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
*/
NS_IMETHOD_(const char*)GetTagName() = 0;
NS_IMETHOD_(const char*)GetTagNameAt(PRUint32 aTagIndex) = 0;
/*
* Subject call observer when the parser hit the tag

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

@ -58,7 +58,7 @@ public:
/*
* 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
@ -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))
result = inst->QueryInterface(nsIElementObserver::GetIID(), (void**)&theElementObserver);
if(result == NS_OK) {
const char* theTagStr;
theTagStr = theElementObserver->GetTagName();
if(theTagStr != nsnull) {
const char* theTagStr = nsnull;
PRUint32 theTagIndex = 0;
theTagStr = theElementObserver->GetTagNameAt(theTagIndex);
while (theTagStr != nsnull) {
eHTMLTags theTag = NS_TagToEnum(theTagStr);
if(eHTMLTag_userdefined!=theTag){
if(mObservers[theTag] == nsnull) {
@ -684,6 +685,8 @@ void CObserverDictionary::RegisterObservers() {
NS_ADDREF(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
*/
NS_IMETHOD_(const char*)GetTagName() = 0;
NS_IMETHOD_(const char*)GetTagNameAt(PRUint32 aTagIndex) = 0;
/*
* Subject call observer when the parser hit the tag