Made sure to add a named reference to the event handlers. a=sar%netscape.com for checkin during closed tree.

This commit is contained in:
waterson%netscape.com 1999-02-24 00:01:26 +00:00
Родитель 2479974bdc
Коммит c60c67adc4
3 изменённых файлов: 330 добавлений и 102 удалений

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

@ -24,7 +24,9 @@
TO DO
1) Implement DOM interfaces.
1) Convert mBroadcastListeners to a _pointer_ to an nsVoidArray,
instead of an automatic nsVoidArray. This should reduce the
footprint per element by 40-50 bytes.
*/
@ -231,7 +233,7 @@ public:
nsresult GetResource(nsIRDFResource** aResource);
nsresult EnsureContentsGenerated(void) const;
void AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID);
nsresult AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID);
static nsresult
GetElementsByTagName(nsIDOMNode* aNode,
@ -941,6 +943,22 @@ RDFElementImpl::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject
(void**) &mScriptObject);
NS_RELEASE(global);
// Ensure that a reference exists to this element
if (mDocument) {
nsAutoString tag;
mTag->ToString(tag);
char buf[64];
char* p = buf;
if (tag.Length() >= sizeof(buf))
p = new char[tag.Length() + 1];
aContext->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);
if (p != buf)
delete[] p;
}
}
*aScriptObject = mScriptObject;
@ -1047,20 +1065,73 @@ RDFElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep)
GetResource(getter_AddRefs(resource));
nsCOMPtr<nsIRDFDocument> rdfDoc;
if (mDocument && resource) {
if (mDocument) {
// Remove this element from the RDF resource-to-element map in
// the old document.
if (resource) {
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {
rv = rdfDoc->RemoveElementForResource(resource, this);
NS_ASSERTION(NS_SUCCEEDED(rv), "error unmapping resource from element");
}
}
// Release the named reference to the script object so it can
// be garbage collected.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
context->RemoveReference((void *) &mScriptObject,
mScriptObject);
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
mDocument = aDocument; // not refcounted
if (mDocument && resource) {
if (mDocument) {
// Add this element to the RDF resource-to-element map in the
// new document.
if (resource) {
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {
rv = rdfDoc->AddElementForResource(resource, this);
NS_ASSERTION(NS_SUCCEEDED(rv), "error mapping resource to element");
}
}
// Add a named reference to the script object.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
nsAutoString tag;
mTag->ToString(tag);
char buf[64];
char* p = buf;
if (tag.Length() >= sizeof(buf))
p = new char[tag.Length() + 1];
context->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);
if (p != buf)
delete[] p;
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
if (aDeep && mChildren) {
for (PRInt32 i = mChildren->Count() - 1; i >= 0; --i) {
// XXX this entire block could be more rigorous about
@ -1427,6 +1498,7 @@ RDFElementImpl::SetAttribute(PRInt32 aNameSpaceID,
else if (attributeName.EqualsIgnoreCase("onpaint"))
AddScriptEventListener(aName, aValue, kIDOMPaintListenerIID);
// Notify any broadcasters that are listening to this node.
count = mBroadcastListeners.Count();
for (PRInt32 i = 0; i < count; i++) {
XULBroadcastListener* xulListener = (XULBroadcastListener*)mBroadcastListeners[i];
@ -1471,13 +1543,16 @@ RDFElementImpl::SetAttribute(PRInt32 aNameSpaceID,
return rv;
}
void RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID)
nsresult
RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID)
{
if (! mDocument)
return NS_OK; // XXX
nsresult ret = NS_OK;
nsIScriptContext* context;
nsIScriptContextOwner* owner;
if (nsnull != mDocument) {
owner = mDocument->GetScriptContextOwner();
if (NS_OK == owner->GetScriptContext(&context)) {
nsIEventListenerManager *manager;
@ -1494,7 +1569,8 @@ void RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aVal
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
return ret;
}
NS_IMETHODIMP

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

@ -24,7 +24,9 @@
TO DO
1) Implement DOM interfaces.
1) Convert mBroadcastListeners to a _pointer_ to an nsVoidArray,
instead of an automatic nsVoidArray. This should reduce the
footprint per element by 40-50 bytes.
*/
@ -231,7 +233,7 @@ public:
nsresult GetResource(nsIRDFResource** aResource);
nsresult EnsureContentsGenerated(void) const;
void AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID);
nsresult AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID);
static nsresult
GetElementsByTagName(nsIDOMNode* aNode,
@ -941,6 +943,22 @@ RDFElementImpl::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject
(void**) &mScriptObject);
NS_RELEASE(global);
// Ensure that a reference exists to this element
if (mDocument) {
nsAutoString tag;
mTag->ToString(tag);
char buf[64];
char* p = buf;
if (tag.Length() >= sizeof(buf))
p = new char[tag.Length() + 1];
aContext->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);
if (p != buf)
delete[] p;
}
}
*aScriptObject = mScriptObject;
@ -1047,20 +1065,73 @@ RDFElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep)
GetResource(getter_AddRefs(resource));
nsCOMPtr<nsIRDFDocument> rdfDoc;
if (mDocument && resource) {
if (mDocument) {
// Remove this element from the RDF resource-to-element map in
// the old document.
if (resource) {
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {
rv = rdfDoc->RemoveElementForResource(resource, this);
NS_ASSERTION(NS_SUCCEEDED(rv), "error unmapping resource from element");
}
}
// Release the named reference to the script object so it can
// be garbage collected.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
context->RemoveReference((void *) &mScriptObject,
mScriptObject);
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
mDocument = aDocument; // not refcounted
if (mDocument && resource) {
if (mDocument) {
// Add this element to the RDF resource-to-element map in the
// new document.
if (resource) {
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {
rv = rdfDoc->AddElementForResource(resource, this);
NS_ASSERTION(NS_SUCCEEDED(rv), "error mapping resource to element");
}
}
// Add a named reference to the script object.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
nsAutoString tag;
mTag->ToString(tag);
char buf[64];
char* p = buf;
if (tag.Length() >= sizeof(buf))
p = new char[tag.Length() + 1];
context->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);
if (p != buf)
delete[] p;
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
if (aDeep && mChildren) {
for (PRInt32 i = mChildren->Count() - 1; i >= 0; --i) {
// XXX this entire block could be more rigorous about
@ -1427,6 +1498,7 @@ RDFElementImpl::SetAttribute(PRInt32 aNameSpaceID,
else if (attributeName.EqualsIgnoreCase("onpaint"))
AddScriptEventListener(aName, aValue, kIDOMPaintListenerIID);
// Notify any broadcasters that are listening to this node.
count = mBroadcastListeners.Count();
for (PRInt32 i = 0; i < count; i++) {
XULBroadcastListener* xulListener = (XULBroadcastListener*)mBroadcastListeners[i];
@ -1471,13 +1543,16 @@ RDFElementImpl::SetAttribute(PRInt32 aNameSpaceID,
return rv;
}
void RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID)
nsresult
RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID)
{
if (! mDocument)
return NS_OK; // XXX
nsresult ret = NS_OK;
nsIScriptContext* context;
nsIScriptContextOwner* owner;
if (nsnull != mDocument) {
owner = mDocument->GetScriptContextOwner();
if (NS_OK == owner->GetScriptContext(&context)) {
nsIEventListenerManager *manager;
@ -1494,7 +1569,8 @@ void RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aVal
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
return ret;
}
NS_IMETHODIMP

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

@ -24,7 +24,9 @@
TO DO
1) Implement DOM interfaces.
1) Convert mBroadcastListeners to a _pointer_ to an nsVoidArray,
instead of an automatic nsVoidArray. This should reduce the
footprint per element by 40-50 bytes.
*/
@ -231,7 +233,7 @@ public:
nsresult GetResource(nsIRDFResource** aResource);
nsresult EnsureContentsGenerated(void) const;
void AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID);
nsresult AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID);
static nsresult
GetElementsByTagName(nsIDOMNode* aNode,
@ -941,6 +943,22 @@ RDFElementImpl::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject
(void**) &mScriptObject);
NS_RELEASE(global);
// Ensure that a reference exists to this element
if (mDocument) {
nsAutoString tag;
mTag->ToString(tag);
char buf[64];
char* p = buf;
if (tag.Length() >= sizeof(buf))
p = new char[tag.Length() + 1];
aContext->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);
if (p != buf)
delete[] p;
}
}
*aScriptObject = mScriptObject;
@ -1047,20 +1065,73 @@ RDFElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep)
GetResource(getter_AddRefs(resource));
nsCOMPtr<nsIRDFDocument> rdfDoc;
if (mDocument && resource) {
if (mDocument) {
// Remove this element from the RDF resource-to-element map in
// the old document.
if (resource) {
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {
rv = rdfDoc->RemoveElementForResource(resource, this);
NS_ASSERTION(NS_SUCCEEDED(rv), "error unmapping resource from element");
}
}
// Release the named reference to the script object so it can
// be garbage collected.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
context->RemoveReference((void *) &mScriptObject,
mScriptObject);
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
mDocument = aDocument; // not refcounted
if (mDocument && resource) {
if (mDocument) {
// Add this element to the RDF resource-to-element map in the
// new document.
if (resource) {
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {
rv = rdfDoc->AddElementForResource(resource, this);
NS_ASSERTION(NS_SUCCEEDED(rv), "error mapping resource to element");
}
}
// Add a named reference to the script object.
if (mScriptObject) {
nsIScriptContextOwner *owner = mDocument->GetScriptContextOwner();
if (nsnull != owner) {
nsIScriptContext *context;
if (NS_OK == owner->GetScriptContext(&context)) {
nsAutoString tag;
mTag->ToString(tag);
char buf[64];
char* p = buf;
if (tag.Length() >= sizeof(buf))
p = new char[tag.Length() + 1];
context->AddNamedReference((void*) &mScriptObject, mScriptObject, buf);
if (p != buf)
delete[] p;
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
}
}
if (aDeep && mChildren) {
for (PRInt32 i = mChildren->Count() - 1; i >= 0; --i) {
// XXX this entire block could be more rigorous about
@ -1427,6 +1498,7 @@ RDFElementImpl::SetAttribute(PRInt32 aNameSpaceID,
else if (attributeName.EqualsIgnoreCase("onpaint"))
AddScriptEventListener(aName, aValue, kIDOMPaintListenerIID);
// Notify any broadcasters that are listening to this node.
count = mBroadcastListeners.Count();
for (PRInt32 i = 0; i < count; i++) {
XULBroadcastListener* xulListener = (XULBroadcastListener*)mBroadcastListeners[i];
@ -1471,13 +1543,16 @@ RDFElementImpl::SetAttribute(PRInt32 aNameSpaceID,
return rv;
}
void RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID)
nsresult
RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aValue, REFNSIID aIID)
{
if (! mDocument)
return NS_OK; // XXX
nsresult ret = NS_OK;
nsIScriptContext* context;
nsIScriptContextOwner* owner;
if (nsnull != mDocument) {
owner = mDocument->GetScriptContextOwner();
if (NS_OK == owner->GetScriptContext(&context)) {
nsIEventListenerManager *manager;
@ -1494,7 +1569,8 @@ void RDFElementImpl::AddScriptEventListener(nsIAtom* aName, const nsString& aVal
NS_RELEASE(context);
}
NS_RELEASE(owner);
}
return ret;
}
NS_IMETHODIMP