Adding support for event handlers in html tags and moving event handler IIDs to central file.

This commit is contained in:
joki%netscape.com 1998-07-31 18:21:37 +00:00
Родитель 9b120e109e
Коммит 44c03fce8e
25 изменённых файлов: 589 добавлений и 80 удалений

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

@ -31,12 +31,11 @@
#include "nsIScriptContextOwner.h"
#include "nsIScriptEventListener.h"
#include "nsDOMEvent.h"
#include "nsDOMEventsIIDs.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIEventStateManager.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsContentList.h"
#include "nsIDOMEventListener.h"
#include "nsCSSPropIDs.h"
#include "nsCSSProps.h"
@ -63,9 +62,6 @@ static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventCapturerIID, NS_IDOMEVENTCAPTURER_IID);
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIPostDataIID, NS_IPOSTDATA_IID);

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

@ -25,7 +25,7 @@
class nsIPresContext;
class nsIDOMEventListener;
class nsIDOMEvent;
class nsIScriptObjectOwner;
/*
* Event listener manager interface.
@ -53,6 +53,23 @@ public:
virtual nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID) = 0;
/**
* Creates a script event listener for the given script object with name mName and function
* content mFunc.
* @param an event listener
*/
virtual nsresult AddScriptEventListener(nsIScriptContext*aContext, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName, const nsString& aFunc, REFNSIID aIID) = 0;
/**
* Registers an event listners which already exists on the given script object with the event
* listener manager.
* @param an event listener
*/
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aScriptObjectOwner,
REFNSIID aIID) = 0;
/**
* Removes events listeners of all types.
* @param an event listener

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

@ -4,3 +4,4 @@
nsEventListenerManager.h
nsEventStateManager.h
nsDOMEvent.h
nsDOMEventsIIDs.h

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

@ -29,15 +29,17 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= nsEventListenerManager.cpp \
nsEventStateManager.cpp \
nsDOMEvent.cpp \
nsDOMEventsIIDs.cpp \
$(NULL)
CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \
.\$(OBJDIR)\nsEventStateManager.obj \
.\$(OBJDIR)\nsDOMEvent.obj \
.\$(OBJDIR)\nsDOMEventsIIDs.obj \
$(NULL)
EXPORTS= nsEventListenerManager.h nsEventStateManager.h nsDOMEvent.h
EXPORTS= nsEventListenerManager.h nsEventStateManager.h nsDOMEvent.h nsDOMEventsIIDs.h
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\dom -I$(PUBLIC)\js

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

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDOMEventsIIDs.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMFocusListener.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);

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

@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsDOMEVENTSIIDs_h___
#define nsDOMEVENTSIIDs_h___
#include "nsISupports.h"
extern const nsIID kIDOMMouseListenerIID;
extern const nsIID kIDOMKeyListenerIID;
extern const nsIID kIDOMMouseMotionListenerIID;
extern const nsIID kIDOMFocusListenerIID;
extern const nsIID kIDOMLoadListenerIID;
extern const nsIID kIDOMDragListenerIID;
#endif /* nsDOMEVENTSIIDs_h___ */

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

@ -30,6 +30,8 @@
#include "nsIDOMDragListener.h"
#include "nsIEventStateManager.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptEventListener.h"
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
@ -40,6 +42,7 @@ static NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
static NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
static NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
nsEventListenerManager::nsEventListenerManager()
{
@ -153,6 +156,72 @@ nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener
return NS_OK;
}
const char *mEventArgv[] = {"event"};
nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID)
{
nsVoidArray *mListeners;
if (NS_OK == GetEventListeners(&mListeners, aIID)) {
//Run through the listeners for this IID and see if a script listener is registered
//If so, we're set.
if (nsnull != mListeners) {
nsIScriptEventListener *mScriptListener;
nsIDOMEventListener *mEventListener;
for (int i=0; i<mListeners->Count(); i++) {
mEventListener = (nsIDOMEventListener*)mListeners->ElementAt(i);
if (NS_OK == mEventListener->QueryInterface(kIScriptEventListenerIID, (void**)&mScriptListener)) {
NS_RELEASE(mScriptListener);
return NS_OK;
}
}
}
//If we didn't find a script listener or no listeners existed create and add a new one.
nsIDOMEventListener *mScriptListener;
if (NS_OK == NS_NewScriptEventListener(&mScriptListener, aContext, aObject)) {
AddEventListener(mScriptListener, aIID);
NS_RELEASE(mScriptListener);
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
nsresult nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName, const nsString& aFunc, REFNSIID aIID)
{
JSObject *mScriptObject;
if (NS_OK == aScriptObjectOwner->GetScriptObject(aContext, (void**)&mScriptObject)) {
JSContext* mJSContext = (JSContext*)aContext->GetNativeContext();
nsString mName, mLowerName;
char* mCharName;
aName->ToString(mName);
mName.ToLowerCase(mLowerName);
mCharName = mLowerName.ToNewCString();
if (nsnull != mCharName) {
JS_CompileUCFunction(mJSContext, mScriptObject, mCharName,
1, mEventArgv, (jschar*)aFunc.GetUnicode(), aFunc.Length(),
nsnull, 0);
delete mCharName;
return SetJSEventListener(aContext, mScriptObject, aIID);
}
}
return NS_ERROR_FAILURE;
}
nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aScriptObjectOwner,
REFNSIID aIID)
{
JSObject *mScriptObject;
if (NS_OK == aScriptObjectOwner->GetScriptObject(aContext, (void**)&mScriptObject)) {
return SetJSEventListener(aContext, mScriptObject, aIID);
}
return NS_ERROR_FAILURE;
}
/**
* Removes event listeners of all types.
* @param an event listener

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

@ -20,6 +20,8 @@
#define nsEventListenerManager_h__
#include "nsIEventListenerManager.h"
#include "jsapi.h"
class nsIDOMEvent;
/*
@ -52,16 +54,28 @@ public:
* @param an event listener
*/
virtual nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
virtual nsresult AddEventListener(nsIDOMEventListener *aListener, REFNSIID aIID);
virtual nsresult AddScriptEventListener(nsIScriptContext* aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName,
const nsString& aFunc,
const nsIID& aIID);
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
const nsIID& aIID);
virtual nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
virtual nsresult RemoveEventListener(nsIDOMEventListener *aListener, REFNSIID aIID);
virtual nsresult CaptureEvent(nsIDOMEventListener *aListener);
virtual nsresult ReleaseEvent(nsIDOMEventListener *aListener);
virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, nsEventStatus& aEventStatus);
virtual nsresult HandleEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsEventStatus& aEventStatus);
protected:
nsresult SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID);
PRUint32 mRefCnt : 31;

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

@ -97,9 +97,22 @@ nsIAtom* nsHTMLAtoms::noresize;
nsIAtom* nsHTMLAtoms::noshade;
nsIAtom* nsHTMLAtoms::nowrap;
nsIAtom* nsHTMLAtoms::ol;
nsIAtom* nsHTMLAtoms::onabort;
nsIAtom* nsHTMLAtoms::onblur;
nsIAtom* nsHTMLAtoms::onclick;
nsIAtom* nsHTMLAtoms::ondblclick;
nsIAtom* nsHTMLAtoms::ondragdrop;
nsIAtom* nsHTMLAtoms::onerror;
nsIAtom* nsHTMLAtoms::onfocus;
nsIAtom* nsHTMLAtoms::onkeydown;
nsIAtom* nsHTMLAtoms::onkeypress;
nsIAtom* nsHTMLAtoms::onkeyup;
nsIAtom* nsHTMLAtoms::onload;
nsIAtom* nsHTMLAtoms::onmousedown;
nsIAtom* nsHTMLAtoms::onmousemove;
nsIAtom* nsHTMLAtoms::onmouseover;
nsIAtom* nsHTMLAtoms::onmouseout;
nsIAtom* nsHTMLAtoms::onmouseup;
nsIAtom* nsHTMLAtoms::onunload;
nsIAtom* nsHTMLAtoms::outOfDate;
nsIAtom* nsHTMLAtoms::overflow;
@ -232,9 +245,22 @@ void nsHTMLAtoms::AddrefAtoms()
noshade = NS_NewAtom("NOSHADE");
nowrap = NS_NewAtom("NOWRAP");
ol = NS_NewAtom("OL");
onabort = NS_NewAtom("ONABORT");
onblur = NS_NewAtom("ONBLUR");
onclick = NS_NewAtom("ONCLICK");
ondragdrop = NS_NewAtom("ONDBLCLICK");
ondragdrop = NS_NewAtom("ONDRAGDROP");
onerror = NS_NewAtom("ONERROR");
onfocus = NS_NewAtom("ONFOCUS");
onkeydown = NS_NewAtom("ONKEYDOWN");
onkeypress = NS_NewAtom("ONKEYPRESS");
onkeyup = NS_NewAtom("ONKEYUP");
onload = NS_NewAtom("ONLOAD");
onmousedown = NS_NewAtom("ONMOUSEDOWN");
onmousemove = NS_NewAtom("ONMOUSEMOVE");
onmouseover = NS_NewAtom("ONMOUSEOVER");
onmouseout = NS_NewAtom("ONMOUSEOUT");
onmouseup = NS_NewAtom("ONMOUSEUP");
onunload = NS_NewAtom("ONUNLOAD");
outOfDate = NS_NewAtom("OUT-OF-DATE");
overflow = NS_NewAtom("OVERFLOW");
@ -365,9 +391,22 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(noshade);
NS_RELEASE(nowrap);
NS_RELEASE(ol);
NS_RELEASE(onabort);
NS_RELEASE(onblur);
NS_RELEASE(onclick);
NS_RELEASE(ondblclick);
NS_RELEASE(ondragdrop);
NS_RELEASE(onerror);
NS_RELEASE(onfocus);
NS_RELEASE(onkeydown);
NS_RELEASE(onkeypress);
NS_RELEASE(onkeyup);
NS_RELEASE(onload);
NS_RELEASE(onmousedown);
NS_RELEASE(onmousemove);
NS_RELEASE(onmouseover);
NS_RELEASE(onmouseout);
NS_RELEASE(onmouseup);
NS_RELEASE(onunload);
NS_RELEASE(outOfDate);
NS_RELEASE(overflow);

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

@ -130,9 +130,22 @@ public:
static nsIAtom* nowrap;
static nsIAtom* ol;
static nsIAtom* onabort;
static nsIAtom* onblur;
static nsIAtom* onclick;
static nsIAtom* ondblclick;
static nsIAtom* ondragdrop;
static nsIAtom* onerror;
static nsIAtom* onfocus;
static nsIAtom* onkeydown;
static nsIAtom* onkeypress;
static nsIAtom* onkeyup;
static nsIAtom* onload;
static nsIAtom* onmousedown;
static nsIAtom* onmousemove;
static nsIAtom* onmouseover;
static nsIAtom* onmouseout;
static nsIAtom* onmouseup;
static nsIAtom* onunload;
static nsIAtom* outOfDate;
static nsIAtom* overflow;

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

@ -130,9 +130,22 @@ public:
static nsIAtom* nowrap;
static nsIAtom* ol;
static nsIAtom* onabort;
static nsIAtom* onblur;
static nsIAtom* onclick;
static nsIAtom* ondblclick;
static nsIAtom* ondragdrop;
static nsIAtom* onerror;
static nsIAtom* onfocus;
static nsIAtom* onkeydown;
static nsIAtom* onkeypress;
static nsIAtom* onkeyup;
static nsIAtom* onload;
static nsIAtom* onmousedown;
static nsIAtom* onmousemove;
static nsIAtom* onmouseover;
static nsIAtom* onmouseout;
static nsIAtom* onmouseup;
static nsIAtom* onunload;
static nsIAtom* outOfDate;
static nsIAtom* overflow;

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

@ -97,9 +97,22 @@ nsIAtom* nsHTMLAtoms::noresize;
nsIAtom* nsHTMLAtoms::noshade;
nsIAtom* nsHTMLAtoms::nowrap;
nsIAtom* nsHTMLAtoms::ol;
nsIAtom* nsHTMLAtoms::onabort;
nsIAtom* nsHTMLAtoms::onblur;
nsIAtom* nsHTMLAtoms::onclick;
nsIAtom* nsHTMLAtoms::ondblclick;
nsIAtom* nsHTMLAtoms::ondragdrop;
nsIAtom* nsHTMLAtoms::onerror;
nsIAtom* nsHTMLAtoms::onfocus;
nsIAtom* nsHTMLAtoms::onkeydown;
nsIAtom* nsHTMLAtoms::onkeypress;
nsIAtom* nsHTMLAtoms::onkeyup;
nsIAtom* nsHTMLAtoms::onload;
nsIAtom* nsHTMLAtoms::onmousedown;
nsIAtom* nsHTMLAtoms::onmousemove;
nsIAtom* nsHTMLAtoms::onmouseover;
nsIAtom* nsHTMLAtoms::onmouseout;
nsIAtom* nsHTMLAtoms::onmouseup;
nsIAtom* nsHTMLAtoms::onunload;
nsIAtom* nsHTMLAtoms::outOfDate;
nsIAtom* nsHTMLAtoms::overflow;
@ -232,9 +245,22 @@ void nsHTMLAtoms::AddrefAtoms()
noshade = NS_NewAtom("NOSHADE");
nowrap = NS_NewAtom("NOWRAP");
ol = NS_NewAtom("OL");
onabort = NS_NewAtom("ONABORT");
onblur = NS_NewAtom("ONBLUR");
onclick = NS_NewAtom("ONCLICK");
ondragdrop = NS_NewAtom("ONDBLCLICK");
ondragdrop = NS_NewAtom("ONDRAGDROP");
onerror = NS_NewAtom("ONERROR");
onfocus = NS_NewAtom("ONFOCUS");
onkeydown = NS_NewAtom("ONKEYDOWN");
onkeypress = NS_NewAtom("ONKEYPRESS");
onkeyup = NS_NewAtom("ONKEYUP");
onload = NS_NewAtom("ONLOAD");
onmousedown = NS_NewAtom("ONMOUSEDOWN");
onmousemove = NS_NewAtom("ONMOUSEMOVE");
onmouseover = NS_NewAtom("ONMOUSEOVER");
onmouseout = NS_NewAtom("ONMOUSEOUT");
onmouseup = NS_NewAtom("ONMOUSEUP");
onunload = NS_NewAtom("ONUNLOAD");
outOfDate = NS_NewAtom("OUT-OF-DATE");
overflow = NS_NewAtom("OVERFLOW");
@ -365,9 +391,22 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(noshade);
NS_RELEASE(nowrap);
NS_RELEASE(ol);
NS_RELEASE(onabort);
NS_RELEASE(onblur);
NS_RELEASE(onclick);
NS_RELEASE(ondblclick);
NS_RELEASE(ondragdrop);
NS_RELEASE(onerror);
NS_RELEASE(onfocus);
NS_RELEASE(onkeydown);
NS_RELEASE(onkeypress);
NS_RELEASE(onkeyup);
NS_RELEASE(onload);
NS_RELEASE(onmousedown);
NS_RELEASE(onmousemove);
NS_RELEASE(onmouseover);
NS_RELEASE(onmouseout);
NS_RELEASE(onmouseup);
NS_RELEASE(onunload);
NS_RELEASE(outOfDate);
NS_RELEASE(overflow);

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

@ -31,12 +31,11 @@
#include "nsIScriptContextOwner.h"
#include "nsIScriptEventListener.h"
#include "nsDOMEvent.h"
#include "nsDOMEventsIIDs.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIEventStateManager.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsContentList.h"
#include "nsIDOMEventListener.h"
#include "nsCSSPropIDs.h"
#include "nsCSSProps.h"
@ -63,9 +62,6 @@ static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventCapturerIID, NS_IDOMEVENTCAPTURER_IID);
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIPostDataIID, NS_IPOSTDATA_IID);

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

@ -25,7 +25,7 @@
class nsIPresContext;
class nsIDOMEventListener;
class nsIDOMEvent;
class nsIScriptObjectOwner;
/*
* Event listener manager interface.
@ -53,6 +53,23 @@ public:
virtual nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID) = 0;
/**
* Creates a script event listener for the given script object with name mName and function
* content mFunc.
* @param an event listener
*/
virtual nsresult AddScriptEventListener(nsIScriptContext*aContext, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName, const nsString& aFunc, REFNSIID aIID) = 0;
/**
* Registers an event listners which already exists on the given script object with the event
* listener manager.
* @param an event listener
*/
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aScriptObjectOwner,
REFNSIID aIID) = 0;
/**
* Removes events listeners of all types.
* @param an event listener

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

@ -4,3 +4,4 @@
nsEventListenerManager.h
nsEventStateManager.h
nsDOMEvent.h
nsDOMEventsIIDs.h

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

@ -25,6 +25,7 @@ CPPSRCS = \
nsEventListenerManager.cpp \
nsEventStateManager.cpp \
nsDOMEvent.cpp \
nsDOMEventsIIDs.cpp \
$(NULL)
MODULE = raptor
@ -33,6 +34,7 @@ EXPORTS = \
nsEventListenerManager.h \
nsEventStateManager.h \
nsDOMEvent.h \
nsDOMEventsIIDs.h \
$(NULL)
REQUIRES = xpcom raptor dom js

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

@ -29,15 +29,17 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= nsEventListenerManager.cpp \
nsEventStateManager.cpp \
nsDOMEvent.cpp \
nsDOMEventsIIDs.cpp \
$(NULL)
CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \
.\$(OBJDIR)\nsEventStateManager.obj \
.\$(OBJDIR)\nsDOMEvent.obj \
.\$(OBJDIR)\nsDOMEventsIIDs.obj \
$(NULL)
EXPORTS= nsEventListenerManager.h nsEventStateManager.h nsDOMEvent.h
EXPORTS= nsEventListenerManager.h nsEventStateManager.h nsDOMEvent.h nsDOMEventsIIDs.h
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\dom -I$(PUBLIC)\js

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

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDOMEventsIIDs.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMFocusListener.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);

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

@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsDOMEVENTSIIDs_h___
#define nsDOMEVENTSIIDs_h___
#include "nsISupports.h"
extern const nsIID kIDOMMouseListenerIID;
extern const nsIID kIDOMKeyListenerIID;
extern const nsIID kIDOMMouseMotionListenerIID;
extern const nsIID kIDOMFocusListenerIID;
extern const nsIID kIDOMLoadListenerIID;
extern const nsIID kIDOMDragListenerIID;
#endif /* nsDOMEVENTSIIDs_h___ */

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

@ -30,6 +30,8 @@
#include "nsIDOMDragListener.h"
#include "nsIEventStateManager.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptEventListener.h"
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
@ -40,6 +42,7 @@ static NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
static NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
static NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
nsEventListenerManager::nsEventListenerManager()
{
@ -153,6 +156,72 @@ nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener
return NS_OK;
}
const char *mEventArgv[] = {"event"};
nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID)
{
nsVoidArray *mListeners;
if (NS_OK == GetEventListeners(&mListeners, aIID)) {
//Run through the listeners for this IID and see if a script listener is registered
//If so, we're set.
if (nsnull != mListeners) {
nsIScriptEventListener *mScriptListener;
nsIDOMEventListener *mEventListener;
for (int i=0; i<mListeners->Count(); i++) {
mEventListener = (nsIDOMEventListener*)mListeners->ElementAt(i);
if (NS_OK == mEventListener->QueryInterface(kIScriptEventListenerIID, (void**)&mScriptListener)) {
NS_RELEASE(mScriptListener);
return NS_OK;
}
}
}
//If we didn't find a script listener or no listeners existed create and add a new one.
nsIDOMEventListener *mScriptListener;
if (NS_OK == NS_NewScriptEventListener(&mScriptListener, aContext, aObject)) {
AddEventListener(mScriptListener, aIID);
NS_RELEASE(mScriptListener);
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
nsresult nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName, const nsString& aFunc, REFNSIID aIID)
{
JSObject *mScriptObject;
if (NS_OK == aScriptObjectOwner->GetScriptObject(aContext, (void**)&mScriptObject)) {
JSContext* mJSContext = (JSContext*)aContext->GetNativeContext();
nsString mName, mLowerName;
char* mCharName;
aName->ToString(mName);
mName.ToLowerCase(mLowerName);
mCharName = mLowerName.ToNewCString();
if (nsnull != mCharName) {
JS_CompileUCFunction(mJSContext, mScriptObject, mCharName,
1, mEventArgv, (jschar*)aFunc.GetUnicode(), aFunc.Length(),
nsnull, 0);
delete mCharName;
return SetJSEventListener(aContext, mScriptObject, aIID);
}
}
return NS_ERROR_FAILURE;
}
nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aScriptObjectOwner,
REFNSIID aIID)
{
JSObject *mScriptObject;
if (NS_OK == aScriptObjectOwner->GetScriptObject(aContext, (void**)&mScriptObject)) {
return SetJSEventListener(aContext, mScriptObject, aIID);
}
return NS_ERROR_FAILURE;
}
/**
* Removes event listeners of all types.
* @param an event listener

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

@ -20,6 +20,8 @@
#define nsEventListenerManager_h__
#include "nsIEventListenerManager.h"
#include "jsapi.h"
class nsIDOMEvent;
/*
@ -52,16 +54,28 @@ public:
* @param an event listener
*/
virtual nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
virtual nsresult AddEventListener(nsIDOMEventListener *aListener, REFNSIID aIID);
virtual nsresult AddScriptEventListener(nsIScriptContext* aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName,
const nsString& aFunc,
const nsIID& aIID);
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
const nsIID& aIID);
virtual nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
virtual nsresult RemoveEventListener(nsIDOMEventListener *aListener, REFNSIID aIID);
virtual nsresult CaptureEvent(nsIDOMEventListener *aListener);
virtual nsresult ReleaseEvent(nsIDOMEventListener *aListener);
virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, nsEventStatus& aEventStatus);
virtual nsresult HandleEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsEventStatus& aEventStatus);
protected:
nsresult SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID);
PRUint32 mRefCnt : 31;

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

@ -97,9 +97,22 @@ nsIAtom* nsHTMLAtoms::noresize;
nsIAtom* nsHTMLAtoms::noshade;
nsIAtom* nsHTMLAtoms::nowrap;
nsIAtom* nsHTMLAtoms::ol;
nsIAtom* nsHTMLAtoms::onabort;
nsIAtom* nsHTMLAtoms::onblur;
nsIAtom* nsHTMLAtoms::onclick;
nsIAtom* nsHTMLAtoms::ondblclick;
nsIAtom* nsHTMLAtoms::ondragdrop;
nsIAtom* nsHTMLAtoms::onerror;
nsIAtom* nsHTMLAtoms::onfocus;
nsIAtom* nsHTMLAtoms::onkeydown;
nsIAtom* nsHTMLAtoms::onkeypress;
nsIAtom* nsHTMLAtoms::onkeyup;
nsIAtom* nsHTMLAtoms::onload;
nsIAtom* nsHTMLAtoms::onmousedown;
nsIAtom* nsHTMLAtoms::onmousemove;
nsIAtom* nsHTMLAtoms::onmouseover;
nsIAtom* nsHTMLAtoms::onmouseout;
nsIAtom* nsHTMLAtoms::onmouseup;
nsIAtom* nsHTMLAtoms::onunload;
nsIAtom* nsHTMLAtoms::outOfDate;
nsIAtom* nsHTMLAtoms::overflow;
@ -232,9 +245,22 @@ void nsHTMLAtoms::AddrefAtoms()
noshade = NS_NewAtom("NOSHADE");
nowrap = NS_NewAtom("NOWRAP");
ol = NS_NewAtom("OL");
onabort = NS_NewAtom("ONABORT");
onblur = NS_NewAtom("ONBLUR");
onclick = NS_NewAtom("ONCLICK");
ondragdrop = NS_NewAtom("ONDBLCLICK");
ondragdrop = NS_NewAtom("ONDRAGDROP");
onerror = NS_NewAtom("ONERROR");
onfocus = NS_NewAtom("ONFOCUS");
onkeydown = NS_NewAtom("ONKEYDOWN");
onkeypress = NS_NewAtom("ONKEYPRESS");
onkeyup = NS_NewAtom("ONKEYUP");
onload = NS_NewAtom("ONLOAD");
onmousedown = NS_NewAtom("ONMOUSEDOWN");
onmousemove = NS_NewAtom("ONMOUSEMOVE");
onmouseover = NS_NewAtom("ONMOUSEOVER");
onmouseout = NS_NewAtom("ONMOUSEOUT");
onmouseup = NS_NewAtom("ONMOUSEUP");
onunload = NS_NewAtom("ONUNLOAD");
outOfDate = NS_NewAtom("OUT-OF-DATE");
overflow = NS_NewAtom("OVERFLOW");
@ -365,9 +391,22 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(noshade);
NS_RELEASE(nowrap);
NS_RELEASE(ol);
NS_RELEASE(onabort);
NS_RELEASE(onblur);
NS_RELEASE(onclick);
NS_RELEASE(ondblclick);
NS_RELEASE(ondragdrop);
NS_RELEASE(onerror);
NS_RELEASE(onfocus);
NS_RELEASE(onkeydown);
NS_RELEASE(onkeypress);
NS_RELEASE(onkeyup);
NS_RELEASE(onload);
NS_RELEASE(onmousedown);
NS_RELEASE(onmousemove);
NS_RELEASE(onmouseover);
NS_RELEASE(onmouseout);
NS_RELEASE(onmouseup);
NS_RELEASE(onunload);
NS_RELEASE(outOfDate);
NS_RELEASE(overflow);

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

@ -130,9 +130,22 @@ public:
static nsIAtom* nowrap;
static nsIAtom* ol;
static nsIAtom* onabort;
static nsIAtom* onblur;
static nsIAtom* onclick;
static nsIAtom* ondblclick;
static nsIAtom* ondragdrop;
static nsIAtom* onerror;
static nsIAtom* onfocus;
static nsIAtom* onkeydown;
static nsIAtom* onkeypress;
static nsIAtom* onkeyup;
static nsIAtom* onload;
static nsIAtom* onmousedown;
static nsIAtom* onmousemove;
static nsIAtom* onmouseover;
static nsIAtom* onmouseout;
static nsIAtom* onmouseup;
static nsIAtom* onunload;
static nsIAtom* outOfDate;
static nsIAtom* overflow;

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

@ -36,9 +36,8 @@
#include "nsISizeOfHandler.h"
#include "nsIEventListenerManager.h"
#include "nsIScriptEventListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsIScriptContextOwner.h"
#include "nsDOMEventsIIDs.h"
#include "jsapi.h"
#include "nsXIFConverter.h"
@ -46,10 +45,8 @@
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kIScriptObjectOwner, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
@ -244,8 +241,49 @@ void nsHTMLTagContent::ToHTMLString(nsString& aBuf) const
aBuf.Append('>');
}
void nsHTMLTagContent::SetDocument(nsIDocument* aDocument)
{
nsHTMLContent::SetDocument(aDocument);
// Once the element is added to the doc tree we need to check if event handler
// were registered on it. Unfortunately, this means doing a GetAttribute for
// every type of handler.
if (nsnull != mAttributes) {
nsHTMLValue mValue;
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onclick, mValue))
AddScriptEventListener(nsHTMLAtoms::onclick, mValue, kIDOMMouseListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::ondblclick, mValue))
AddScriptEventListener(nsHTMLAtoms::onclick, mValue, kIDOMMouseListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onmousedown, mValue))
AddScriptEventListener(nsHTMLAtoms::onmousedown, mValue, kIDOMMouseListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onmouseup, mValue))
AddScriptEventListener(nsHTMLAtoms::onmouseup, mValue, kIDOMMouseListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onmouseover, mValue))
AddScriptEventListener(nsHTMLAtoms::onmouseover, mValue, kIDOMMouseListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onmouseout, mValue))
AddScriptEventListener(nsHTMLAtoms::onmouseout, mValue, kIDOMMouseListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onkeydown, mValue))
AddScriptEventListener(nsHTMLAtoms::onkeydown, mValue, kIDOMKeyListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onkeyup, mValue))
AddScriptEventListener(nsHTMLAtoms::onkeyup, mValue, kIDOMKeyListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onkeypress, mValue))
AddScriptEventListener(nsHTMLAtoms::onkeypress, mValue, kIDOMKeyListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onmousemove, mValue))
AddScriptEventListener(nsHTMLAtoms::onmousemove, mValue, kIDOMMouseMotionListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onload, mValue))
AddScriptEventListener(nsHTMLAtoms::onload, mValue, kIDOMLoadListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onunload, mValue))
AddScriptEventListener(nsHTMLAtoms::onunload, mValue, kIDOMLoadListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onabort, mValue))
AddScriptEventListener(nsHTMLAtoms::onabort, mValue, kIDOMLoadListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onerror, mValue))
AddScriptEventListener(nsHTMLAtoms::onerror, mValue, kIDOMLoadListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onfocus, mValue))
AddScriptEventListener(nsHTMLAtoms::onfocus, mValue, kIDOMFocusListenerIID);
if (eContentAttr_HasValue == mAttributes->GetAttribute(nsHTMLAtoms::onblur, mValue))
AddScriptEventListener(nsHTMLAtoms::onblur, mValue, kIDOMFocusListenerIID);
}
}
void nsHTMLTagContent::SetAttribute(const nsString& aName,
const nsString& aValue)
@ -339,6 +377,28 @@ nsHTMLTagContent::AttributeToString(nsIAtom* aAttribute,
return eContentAttr_NotThere;
}
nsresult
nsHTMLTagContent::AddScriptEventListener(nsIAtom* aAttribute, nsHTMLValue& aValue, REFNSIID aIID)
{
nsresult mRet = NS_OK;
nsIScriptContext* mContext;
nsIScriptContextOwner* mOwner;
if (nsnull != mDocument) {
mOwner = mDocument->GetScriptContextOwner();
if (NS_OK == mOwner->GetScriptContext(&mContext)) {
if (nsnull != mListenerManager || NS_OK == GetListenerManager(&mListenerManager)) {
nsString mValue;
aValue.GetStringValue(mValue);
mRet = mListenerManager->AddScriptEventListener(mContext, this, aAttribute, mValue, aIID);
}
NS_RELEASE(mContext);
}
NS_RELEASE(mOwner);
}
return mRet;
}
// Note: Subclasses should override to parse the value string; in
// addition, when they see an unknown attribute they should call this
// so that global attributes are handled (like CLASS, ID, STYLE, etc.)
@ -524,22 +584,31 @@ PRBool nsHTMLTagContent::SetProperty(JSContext *aContext, jsval aID, jsval *a
if (mPrefix == "on") {
if (mPropName == "onmousedown" || mPropName == "onmouseup" || mPropName == "onclick" ||
mPropName == "onmouseover" || mPropName == "onmouseout") {
if (NS_OK != SetScriptEventListener(aContext, kIDOMMouseListenerIID)) {
if (nsnull != mListenerManager || NS_OK == GetListenerManager(&mListenerManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mListenerManager->RegisterScriptEventListener(mScriptCX, this, kIDOMMouseListenerIID)) {
return PR_FALSE;
}
}
}
else if (mPropName == "onkeydown" || mPropName == "onkeyup" || mPropName == "onkeypress" ) {
if (NS_OK != SetScriptEventListener(aContext, kIDOMKeyListenerIID)) {
if (nsnull != mListenerManager || NS_OK == GetListenerManager(&mListenerManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mListenerManager->RegisterScriptEventListener(mScriptCX, this, kIDOMKeyListenerIID)) {
return PR_FALSE;
}
}
}
else if (mPropName == "onmousemove" ) {
if (NS_OK != SetScriptEventListener(aContext, kIDOMMouseMotionListenerIID)) {
if (nsnull != mListenerManager || NS_OK == GetListenerManager(&mListenerManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mListenerManager->RegisterScriptEventListener(mScriptCX, this, kIDOMMouseMotionListenerIID)) {
return PR_FALSE;
}
}
}
}
}
return PR_TRUE;
}
@ -562,49 +631,6 @@ void nsHTMLTagContent::Finalize(JSContext *aContext)
{
}
nsresult nsHTMLTagContent::SetScriptEventListener(JSContext *aContext, REFNSIID aListenerTypeIID)
{
//First get the mScriptObject or make one if we don't have one.
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (nsnull == mScriptObject) {
NS_NewScriptElement(mScriptCX, this, mParent, (void**)&mScriptObject);
}
if (nsnull != mScriptObject) {
nsIEventListenerManager *mManager = nsnull;
nsVoidArray *mListeners;
if (NS_OK == GetListenerManager(&mManager) &&
NS_OK == mManager->GetEventListeners(&mListeners, aListenerTypeIID)) {
//Run through the listeners for this IID and see if a script listener is registered
//If so, we're set.
if (nsnull != mListeners) {
nsIScriptEventListener *mScriptListener;
nsIDOMEventListener *mEventListener;
for (int i=0; i<mListeners->Count(); i++) {
mEventListener = (nsIDOMEventListener*)mListeners->ElementAt(i);
if (NS_OK == mEventListener->QueryInterface(kIScriptEventListenerIID, (void**)&mScriptListener)) {
NS_RELEASE(mScriptListener);
NS_RELEASE(mManager);
return NS_OK;
}
}
}
//If we didn't find a script listener or no listeners existed create and add a new one.
nsIDOMEventListener *mScriptListener;
if (NS_OK == NS_NewScriptEventListener(&mScriptListener, mScriptCX, mScriptObject)) {
mManager->AddEventListener(mScriptListener, aListenerTypeIID);
NS_RELEASE(mScriptListener);
NS_RELEASE(mManager);
return NS_OK;
}
}
NS_IF_RELEASE(mManager);
}
return NS_ERROR_FAILURE;
}
//
// Implementation of nsIDOMNode interface
//

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

@ -103,6 +103,10 @@ public:
virtual nsIStyleRule* GetStyleRule(void);
// Override from nsHTMLContent to allow setting of event handlers once
// tag content is added to the doc tree.
virtual void SetDocument(nsIDocument* aDocument);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -260,14 +264,15 @@ protected:
nsHTMLValue& aValue,
nsString& aResult) const;
virtual nsresult AddScriptEventListener(nsIAtom* aAttribute, nsHTMLValue& aValue, REFNSIID aIID);
void TriggerLink(nsIPresContext& aPresContext,
const nsString& aBase,
const nsString& aURLSpec,
const nsString& aTargetSpec,
PRBool aClick);
nsresult SetScriptEventListener(JSContext *aContext, REFNSIID aListenerTypeIID);
nsIAtom* mTag;
nsIHTMLAttributes* mAttributes;
};