Fixes for 19650 and 15133. Added nsHTMLDocument::Resolve(). Script event handler compilation is deferred till when the event handler is first invoked. Atoms used for event name comparisions instead of strings. R=joki

This commit is contained in:
vidur%netscape.com 1999-11-25 00:05:21 +00:00
Родитель bc1a90e967
Коммит dd88339f19
22 изменённых файлов: 826 добавлений и 353 удалений

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

@ -72,6 +72,7 @@
#include "nsINameSpaceManager.h" #include "nsINameSpaceManager.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsLayoutAtoms.h"
#include "nsLayoutCID.h" #include "nsLayoutCID.h"
#include "nsIDOMSelection.h" #include "nsIDOMSelection.h"
#include "nsIDOMRange.h" #include "nsIDOMRange.h"
@ -2499,71 +2500,72 @@ PRBool nsDocument::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID))); mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
mPrefix.SetString(mPropName.GetUnicode(), 2); mPrefix.SetString(mPropName.GetUnicode(), 2);
if (mPrefix == "on") { if (mPrefix == "on") {
nsCOMPtr<nsIAtom> atom = getter_AddRefs(NS_NewAtom(mPropName));
nsIEventListenerManager *mManager = nsnull; nsIEventListenerManager *mManager = nsnull;
if (mPropName == "onmousedown" || mPropName == "onmouseup" || mPropName == "onclick" || if (atom == nsLayoutAtoms::onmousedown || atom == nsLayoutAtoms::onmouseup || atom == nsLayoutAtoms::onclick ||
mPropName == "onmouseover" || mPropName == "onmouseout") { atom == nsLayoutAtoms::onmouseover || atom == nsLayoutAtoms::onmouseout) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMMouseListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMMouseListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onkeydown" || mPropName == "onkeyup" || mPropName == "onkeypress") { else if (atom == nsLayoutAtoms::onkeydown || atom == nsLayoutAtoms::onkeyup || atom == nsLayoutAtoms::onkeypress) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMKeyListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMKeyListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onmousemove") { else if (atom == nsLayoutAtoms::onmousemove) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMMouseMotionListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMMouseMotionListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onfocus" || mPropName == "onblur") { else if (atom == nsLayoutAtoms::onfocus || atom == nsLayoutAtoms::onblur) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMFocusListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMFocusListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onsubmit" || mPropName == "onreset" || mPropName == "onchange" || else if (atom == nsLayoutAtoms::onsubmit || atom == nsLayoutAtoms::onreset || atom == nsLayoutAtoms::onchange ||
mPropName == "onselect") { atom == nsLayoutAtoms::onselect) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMFormListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMFormListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onload" || mPropName == "onunload" || mPropName == "onabort" || else if (atom == nsLayoutAtoms::onload || atom == nsLayoutAtoms::onunload || atom == nsLayoutAtoms::onabort ||
mPropName == "onerror") { atom == nsLayoutAtoms::onerror) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMLoadListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMLoadListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onpaint") { else if (atom == nsLayoutAtoms::onpaint) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *) nsIScriptContext *mScriptCX = (nsIScriptContext *)
JS_GetContextPrivate(aContext); JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this,
kIDOMPaintListenerIID)) { atom, kIDOMPaintListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }

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

@ -965,7 +965,8 @@ nsGenericElement::GetScriptObject(nsIScriptContext* aContext,
nsAutoString tag; nsAutoString tag;
mTag->ToString(tag); mTag->ToString(tag);
res = factory->NewScriptElement(tag, aContext, mContent, res = factory->NewScriptElement(tag, aContext, mContent,
mParent, (void**)&slots->mScriptObject); mParent ? (nsISupports*)mParent : (nsISupports*)mDocument,
(void**)&slots->mScriptObject);
NS_RELEASE(factory); NS_RELEASE(factory);
char tagBuf[50]; char tagBuf[50];
@ -1112,71 +1113,72 @@ nsGenericElement::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
propName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID))); propName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
prefix.SetString(propName.GetUnicode(), 2); prefix.SetString(propName.GetUnicode(), 2);
if (prefix == "on") { if (prefix == "on") {
nsCOMPtr<nsIAtom> atom = getter_AddRefs(NS_NewAtom(propName));
nsIEventListenerManager *manager = nsnull; nsIEventListenerManager *manager = nsnull;
if (propName == "onmousedown" || propName == "onmouseup" || propName == "onclick" || if (atom == nsLayoutAtoms::onmousedown || atom == nsLayoutAtoms::onmouseup || atom == nsLayoutAtoms::onclick ||
propName == "onmouseover" || propName == "onmouseout") { atom == nsLayoutAtoms::onmouseover || atom == nsLayoutAtoms::onmouseout) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMMouseListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMMouseListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onkeydown" || propName == "onkeyup" || propName == "onkeypress") { else if (atom == nsLayoutAtoms::onkeydown || atom == nsLayoutAtoms::onkeyup || atom == nsLayoutAtoms::onkeypress) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMKeyListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMKeyListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onmousemove") { else if (atom == nsLayoutAtoms::onmousemove) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMMouseMotionListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMMouseMotionListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onfocus" || propName == "onblur") { else if (atom == nsLayoutAtoms::onfocus || atom == nsLayoutAtoms::onblur) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMFocusListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMFocusListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onsubmit" || propName == "onreset" || propName == "onchange" || else if (atom == nsLayoutAtoms::onsubmit || atom == nsLayoutAtoms::onreset || atom == nsLayoutAtoms::onchange ||
propName == "onselect") { atom == nsLayoutAtoms::onselect) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMFormListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMFormListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onload" || propName == "onunload" || propName == "onabort" || else if (atom == nsLayoutAtoms::onload || atom == nsLayoutAtoms::onunload || atom == nsLayoutAtoms::onabort ||
propName == "onerror") { atom == nsLayoutAtoms::onerror) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMLoadListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMLoadListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onpaint") { else if (atom == nsLayoutAtoms::onpaint) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *) nsIScriptContext *mScriptCX = (nsIScriptContext *)
JS_GetContextPrivate(aContext); JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner,
kIDOMPaintListenerIID)) { atom, kIDOMPaintListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
@ -1305,7 +1307,7 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute,
if (NS_OK == receiver->GetListenerManager(&manager)) { if (NS_OK == receiver->GetListenerManager(&manager)) {
nsIScriptObjectOwner *mObjectOwner; nsIScriptObjectOwner *mObjectOwner;
if (NS_OK == global->QueryInterface(kIScriptObjectOwnerIID, (void**)&mObjectOwner)) { if (NS_OK == global->QueryInterface(kIScriptObjectOwnerIID, (void**)&mObjectOwner)) {
ret = manager->AddScriptEventListener(context, mObjectOwner, aAttribute, aValue, aIID); ret = manager->AddScriptEventListener(context, mObjectOwner, aAttribute, aValue, aIID, PR_FALSE);
NS_RELEASE(mObjectOwner); NS_RELEASE(mObjectOwner);
} }
NS_RELEASE(manager); NS_RELEASE(manager);
@ -1321,7 +1323,7 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute,
if (NS_OK == mContent->QueryInterface(kIScriptObjectOwnerIID, if (NS_OK == mContent->QueryInterface(kIScriptObjectOwnerIID,
(void**) &cowner)) { (void**) &cowner)) {
ret = manager->AddScriptEventListener(context, cowner, ret = manager->AddScriptEventListener(context, cowner,
aAttribute, aValue, aIID); aAttribute, aValue, aIID, PR_TRUE);
NS_RELEASE(cowner); NS_RELEASE(cowner);
} }
NS_RELEASE(manager); NS_RELEASE(manager);

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

@ -85,15 +85,21 @@ public:
* @param an event listener * @param an event listener
*/ */
virtual nsresult AddScriptEventListener(nsIScriptContext*aContext, nsIScriptObjectOwner *aScriptObjectOwner, virtual nsresult AddScriptEventListener(nsIScriptContext*aContext,
nsIAtom *aName, const nsString& aFunc, REFNSIID aIID) = 0; nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName,
const nsString& aFunc,
REFNSIID aIID,
PRBool aDeferCompilation) = 0;
/** /**
* Registers an event listners which already exists on the given script object with the event * Registers an event listners which already exists on the given script object with the event
* listener manager. * listener manager.
* @param an event listener * @param an event listener
*/ */
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aScriptObjectOwner, virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom* aName,
REFNSIID aIID) = 0; REFNSIID aIID) = 0;
/** /**

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

@ -41,10 +41,14 @@
#include "nsIPrivateDOMEvent.h" #include "nsIPrivateDOMEvent.h"
#include "nsIScriptObjectOwner.h" #include "nsIScriptObjectOwner.h"
#include "nsIScriptEventListener.h" #include "nsIScriptEventListener.h"
#include "nsIJSEventListener.h"
#include "nsDOMEventsIIDs.h" #include "nsDOMEventsIIDs.h"
#include "prmem.h" #include "prmem.h"
#include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectData.h" #include "nsIScriptGlobalObjectData.h"
#include "nsLayoutAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
@ -236,6 +240,7 @@ nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener
ls->mListener = aListener; ls->mListener = aListener;
ls->mFlags = aFlags; ls->mFlags = aFlags;
ls->mSubType = aSubType; ls->mSubType = aSubType;
ls->mHandlerIsString = 0;
(*listeners)->InsertElementAt((void*)ls, (*listeners)->Count()); (*listeners)->InsertElementAt((void*)ls, (*listeners)->Count());
NS_ADDREF(aListener); NS_ADDREF(aListener);
} }
@ -288,133 +293,133 @@ nsresult nsEventListenerManager::RemoveEventListenerByIID(nsIDOMEventListener *a
return NS_OK; return NS_OK;
} }
nsresult nsEventListenerManager::GetIdentifiersForType(const nsString& aType, nsIID& aIID, PRInt32* aFlags) nsresult nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aFlags)
{ {
if (aType == "mousedown") { if (aType == nsLayoutAtoms::onmousedown) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_MOUSEDOWN; *aFlags = NS_EVENT_BITS_MOUSE_MOUSEDOWN;
} }
else if (aType == "mouseup") { else if (aType == nsLayoutAtoms::onmouseup) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_MOUSEUP; *aFlags = NS_EVENT_BITS_MOUSE_MOUSEUP;
} }
else if (aType == "click") { else if (aType == nsLayoutAtoms::onclick) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_CLICK; *aFlags = NS_EVENT_BITS_MOUSE_CLICK;
} }
else if (aType == "dblclick") { else if (aType == nsLayoutAtoms::ondblclick) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_DBLCLICK; *aFlags = NS_EVENT_BITS_MOUSE_DBLCLICK;
} }
else if (aType == "mouseover") { else if (aType == nsLayoutAtoms::onmouseover) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_MOUSEOVER; *aFlags = NS_EVENT_BITS_MOUSE_MOUSEOVER;
} }
else if (aType == "mouseout") { else if (aType == nsLayoutAtoms::onmouseout) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_MOUSEOUT; *aFlags = NS_EVENT_BITS_MOUSE_MOUSEOUT;
} }
else if (aType == "keydown") { else if (aType == nsLayoutAtoms::onkeydown) {
aIID = kIDOMKeyListenerIID; aIID = kIDOMKeyListenerIID;
*aFlags = NS_EVENT_BITS_KEY_KEYDOWN; *aFlags = NS_EVENT_BITS_KEY_KEYDOWN;
} }
else if (aType == "keyup") { else if (aType == nsLayoutAtoms::onkeyup) {
aIID = kIDOMKeyListenerIID; aIID = kIDOMKeyListenerIID;
*aFlags = NS_EVENT_BITS_KEY_KEYUP; *aFlags = NS_EVENT_BITS_KEY_KEYUP;
} }
else if (aType == "keypress") { else if (aType == nsLayoutAtoms::onkeypress) {
aIID = kIDOMKeyListenerIID; aIID = kIDOMKeyListenerIID;
*aFlags = NS_EVENT_BITS_KEY_KEYPRESS; *aFlags = NS_EVENT_BITS_KEY_KEYPRESS;
} }
else if (aType == "mousemove") { else if (aType == nsLayoutAtoms::onmousemove) {
aIID = kIDOMMouseMotionListenerIID; aIID = kIDOMMouseMotionListenerIID;
*aFlags = NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE; *aFlags = NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE;
} }
else if (aType == "focus") { else if (aType == nsLayoutAtoms::onfocus) {
aIID = kIDOMFocusListenerIID; aIID = kIDOMFocusListenerIID;
*aFlags = NS_EVENT_BITS_FOCUS_FOCUS; *aFlags = NS_EVENT_BITS_FOCUS_FOCUS;
} }
else if (aType == "blur") { else if (aType == nsLayoutAtoms::onblur) {
aIID = kIDOMFocusListenerIID; aIID = kIDOMFocusListenerIID;
*aFlags = NS_EVENT_BITS_FOCUS_BLUR; *aFlags = NS_EVENT_BITS_FOCUS_BLUR;
} }
else if (aType == "submit") { else if (aType == nsLayoutAtoms::onsubmit) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_SUBMIT; *aFlags = NS_EVENT_BITS_FORM_SUBMIT;
} }
else if (aType == "reset") { else if (aType == nsLayoutAtoms::onreset) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_RESET; *aFlags = NS_EVENT_BITS_FORM_RESET;
} }
else if (aType == "change") { else if (aType == nsLayoutAtoms::onchange) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_CHANGE; *aFlags = NS_EVENT_BITS_FORM_CHANGE;
} }
else if (aType == "select") { else if (aType == nsLayoutAtoms::onselect) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_SELECT; *aFlags = NS_EVENT_BITS_FORM_SELECT;
} }
else if (aType == "input") { else if (aType == nsLayoutAtoms::oninput) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_INPUT; *aFlags = NS_EVENT_BITS_FORM_INPUT;
} }
else if (aType == "load") { else if (aType == nsLayoutAtoms::onload) {
aIID = kIDOMLoadListenerIID; aIID = kIDOMLoadListenerIID;
*aFlags = NS_EVENT_BITS_LOAD_LOAD; *aFlags = NS_EVENT_BITS_LOAD_LOAD;
} }
else if (aType == "unload") { else if (aType == nsLayoutAtoms::onunload) {
aIID = kIDOMLoadListenerIID; aIID = kIDOMLoadListenerIID;
*aFlags = NS_EVENT_BITS_LOAD_UNLOAD; *aFlags = NS_EVENT_BITS_LOAD_UNLOAD;
} }
else if (aType == "abort") { else if (aType == nsLayoutAtoms::onabort) {
aIID = kIDOMLoadListenerIID; aIID = kIDOMLoadListenerIID;
*aFlags = NS_EVENT_BITS_LOAD_ABORT; *aFlags = NS_EVENT_BITS_LOAD_ABORT;
} }
else if (aType == "error") { else if (aType == nsLayoutAtoms::onerror) {
aIID = kIDOMLoadListenerIID; aIID = kIDOMLoadListenerIID;
*aFlags = NS_EVENT_BITS_LOAD_ERROR; *aFlags = NS_EVENT_BITS_LOAD_ERROR;
} }
else if (aType == "paint") { else if (aType == nsLayoutAtoms::onpaint) {
aIID = kIDOMPaintListenerIID; aIID = kIDOMPaintListenerIID;
*aFlags = NS_EVENT_BITS_PAINT_PAINT; *aFlags = NS_EVENT_BITS_PAINT_PAINT;
} // extened this to handle IME related events } // extened this to handle IME related events
else if (aType == "create") { else if (aType == nsLayoutAtoms::oncreate) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_MENU_CREATE; *aFlags = NS_EVENT_BITS_MENU_CREATE;
} }
else if (aType == "destroy") { else if (aType == nsLayoutAtoms::ondestroy) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_MENU_DESTROY; *aFlags = NS_EVENT_BITS_MENU_DESTROY;
} }
else if (aType == "command") { else if (aType == nsLayoutAtoms::oncommand) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_MENU_ACTION; *aFlags = NS_EVENT_BITS_MENU_ACTION;
} }
else if (aType == "broadcast") { else if (aType == nsLayoutAtoms::onbroadcast) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_XUL_BROADCAST; *aFlags = NS_EVENT_BITS_XUL_BROADCAST;
} }
else if (aType == "commandupdate") { else if (aType == nsLayoutAtoms::oncommandupdate) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_XUL_COMMAND_UPDATE; *aFlags = NS_EVENT_BITS_XUL_COMMAND_UPDATE;
} }
else if (aType == "dragenter") { else if (aType == nsLayoutAtoms::ondragenter) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_ENTER; *aFlags = NS_EVENT_BITS_DRAG_ENTER;
} }
else if (aType == "dragover") { else if (aType == nsLayoutAtoms::ondragover) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_OVER; *aFlags = NS_EVENT_BITS_DRAG_OVER;
} }
else if (aType == "dragexit") { else if (aType == nsLayoutAtoms::ondragexit) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_EXIT; *aFlags = NS_EVENT_BITS_DRAG_EXIT;
} }
else if (aType == "dragdrop") { else if (aType == nsLayoutAtoms::ondragdrop) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_DROP; *aFlags = NS_EVENT_BITS_DRAG_DROP;
} }
else if (aType == "draggesture") { else if (aType == nsLayoutAtoms::ondraggesture) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_GESTURE; *aFlags = NS_EVENT_BITS_DRAG_GESTURE;
} }
@ -429,11 +434,18 @@ nsresult nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aLi
{ {
PRInt32 subType; PRInt32 subType;
nsIID iid; nsIID iid;
nsAutoString str("on");
nsIAtom* atom;
if (NS_OK == GetIdentifiersForType(aType, iid, &subType)) { str.Append(aType);
atom = NS_NewAtom(str);
if (NS_OK == GetIdentifiersForType(atom, iid, &subType)) {
AddEventListener(aListener, iid, aFlags, subType); AddEventListener(aListener, iid, aFlags, subType);
} }
NS_IF_RELEASE(atom);
return NS_OK; return NS_OK;
} }
@ -443,38 +455,81 @@ nsresult nsEventListenerManager::RemoveEventListenerByType(nsIDOMEventListener *
PRInt32 subType; PRInt32 subType;
nsIID iid; nsIID iid;
if (NS_OK == GetIdentifiersForType(aType, iid, &subType)) { nsAutoString str("on");
nsIAtom* atom;
str.Append(aType);
atom = NS_NewAtom(str);
if (NS_OK == GetIdentifiersForType(atom, iid, &subType)) {
RemoveEventListener(aListener, iid, aFlags, subType); RemoveEventListener(aListener, iid, aFlags, subType);
} }
NS_IF_RELEASE(atom);
return NS_OK; return NS_OK;
} }
nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID) nsListenerStruct*
nsEventListenerManager::FindJSEventListener(REFNSIID aIID)
{ {
nsVoidArray *mListeners; nsVoidArray *listeners;
if (NS_OK == GetEventListeners(&mListeners, aIID)) { nsresult result = GetEventListeners(&listeners, aIID);
if (NS_SUCCEEDED(result)) {
//Run through the listeners for this IID and see if a script listener is registered //Run through the listeners for this IID and see if a script listener is registered
//If so, we're set. if (nsnull != listeners) {
if (nsnull != mListeners) {
nsListenerStruct *ls; nsListenerStruct *ls;
for (int i=0; i<mListeners->Count(); i++) { for (int i=0; i<listeners->Count(); i++) {
ls = (nsListenerStruct*)mListeners->ElementAt(i); ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) { if (ls->mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) {
return NS_OK; return ls;
} }
} }
} }
}
return nsnull;
}
nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aOwner,
nsIAtom* aName,
REFNSIID aIID,
PRBool aIsString)
{
nsIDOMEventListener* theListener = nsnull;
nsresult result = NS_OK;
nsListenerStruct *ls;
ls = FindJSEventListener(aIID);
if (nsnull == ls) {
//If we didn't find a script listener or no listeners existed create and add a new one. //If we didn't find a script listener or no listeners existed create and add a new one.
nsIDOMEventListener *mScriptListener; nsIDOMEventListener* scriptListener;
if (NS_OK == NS_NewJSEventListener(&mScriptListener, aContext, aObject)) { result = NS_NewJSEventListener(&scriptListener, aContext, aOwner);
AddEventListenerByIID(mScriptListener, aIID, NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT); if (NS_SUCCEEDED(result)) {
NS_RELEASE(mScriptListener); AddEventListenerByIID(scriptListener, aIID, NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT);
return NS_OK; NS_RELEASE(scriptListener);
ls = FindJSEventListener(aIID);
} }
} }
return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(result) && ls) {
PRInt32 flags;
nsIID iid;
result = GetIdentifiersForType(aName, iid, &flags);
if (NS_SUCCEEDED(result)) {
if (aIsString) {
ls->mHandlerIsString |= flags;
}
else {
ls->mHandlerIsString &= ~flags;
}
}
}
return result;
} }
nsresult nsresult
@ -482,28 +537,82 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext,
nsIScriptObjectOwner *aScriptObjectOwner, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName, nsIAtom *aName,
const nsString& aBody, const nsString& aBody,
REFNSIID aIID) REFNSIID aIID,
PRBool aDeferCompilation)
{ {
JSObject *scriptObject; JSObject *scriptObject;
nsresult rv; nsresult rv;
rv = aScriptObjectOwner->GetScriptObject(aContext, (void**)&scriptObject); if (!aDeferCompilation) {
if (NS_FAILED(rv)) rv = aScriptObjectOwner->GetScriptObject(aContext, (void**)&scriptObject);
return NS_ERROR_FAILURE; if (NS_FAILED(rv))
rv = aContext->CompileFunction(scriptObject, aName, aBody); return rv;
if (NS_FAILED(rv)) rv = aContext->CompileFunction(scriptObject, aName, aBody);
return NS_ERROR_FAILURE; if (NS_FAILED(rv))
return SetJSEventListener(aContext, scriptObject, aIID); return rv;
}
return SetJSEventListener(aContext, aScriptObjectOwner, aName, aIID, aDeferCompilation);
} }
nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aScriptObjectOwner, nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext,
REFNSIID aIID) nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName,
REFNSIID aIID)
{ {
JSObject *scriptObject; return SetJSEventListener(aContext, aScriptObjectOwner, aName, aIID, PR_FALSE);
if (NS_SUCCEEDED(aScriptObjectOwner->GetScriptObject(aContext, (void**)&scriptObject))) { }
return SetJSEventListener(aContext, scriptObject, aIID);
nsresult
nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
nsIDOMEvent* aDOMEvent,
PRUint32 aSubType)
{
nsresult result = NS_OK;
// If this is a script handler and we haven't yet
// compiled the event handler itself
if ((aListenerStruct->mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) &&
(aListenerStruct->mHandlerIsString & aSubType)) {
nsCOMPtr<nsIJSEventListener> jslistener = do_QueryInterface(aListenerStruct->mListener);
if (jslistener) {
nsCOMPtr<nsIScriptObjectOwner> owner;
nsCOMPtr<nsIScriptContext> scriptCX;
result = jslistener->GetEventTarget(getter_AddRefs(scriptCX), getter_AddRefs(owner));
if (NS_SUCCEEDED(result)) {
JSObject* jsobj;
result = owner->GetScriptObject(scriptCX, (void**)&jsobj);
// This should never happen for anything but content
// XXX I don't like that we have to reference content
// from here. The alternative is to store the event handler
// string on the JS object itself.
if (NS_SUCCEEDED(result)) {
nsCOMPtr<nsIContent> content = do_QueryInterface(owner);
NS_ASSERTION(content, "only content should have event handler attributes");
if (content) {
nsAutoString eventString;
if (NS_SUCCEEDED(aDOMEvent->GetType(eventString))) {
eventString.Insert("on", 0, 2);
nsCOMPtr<nsIAtom> atom = getter_AddRefs(NS_NewAtom(eventString));
nsString handlerBody;
result = content->GetAttribute(kNameSpaceID_None, atom, handlerBody);
if (NS_SUCCEEDED(result)) {
result = scriptCX->CompileFunction(jsobj, atom, handlerBody);
aListenerStruct->mHandlerIsString &= ~aSubType;
}
}
}
}
}
}
} }
return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(result)) {
result = aListenerStruct->mListener->HandleEvent(aDOMEvent);
}
return result;
} }
/** /**
@ -548,7 +657,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
nsIDOMMouseListener *mMouseListener; nsIDOMMouseListener *mMouseListener;
ls = (nsListenerStruct*)mMouseListeners->ElementAt(i); ls = (nsListenerStruct*)mMouseListeners->ElementAt(i);
if (ls->mFlags & aFlags) { if (ls->mFlags & aFlags) {
if (NS_OK == ls->mListener->QueryInterface(kIDOMMouseListenerIID, (void**)&mMouseListener)) { if (NS_OK == ls->mListener->QueryInterface(kIDOMMouseListenerIID, (void**)&mMouseListener)) {
switch(aEvent->message) { switch(aEvent->message) {
@ -585,10 +694,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN: case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_BUTTON_DOWN: case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_RIGHT_BUTTON_DOWN: case NS_MOUSE_RIGHT_BUTTON_DOWN:
subType = NS_EVENT_BITS_MOUSE_MOUSEDOWN;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEDOWN) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEDOWN) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -596,6 +707,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_LEFT_BUTTON_UP: case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_UP: case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_UP: case NS_MOUSE_RIGHT_BUTTON_UP:
subType = NS_EVENT_BITS_MOUSE_MOUSEUP;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEUP) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEUP) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -603,6 +715,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_LEFT_CLICK: case NS_MOUSE_LEFT_CLICK:
case NS_MOUSE_MIDDLE_CLICK: case NS_MOUSE_MIDDLE_CLICK:
case NS_MOUSE_RIGHT_CLICK: case NS_MOUSE_RIGHT_CLICK:
subType = NS_EVENT_BITS_MOUSE_CLICK;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_CLICK) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_CLICK) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -610,16 +723,19 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_LEFT_DOUBLECLICK: case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_MIDDLE_DOUBLECLICK: case NS_MOUSE_MIDDLE_DOUBLECLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK: case NS_MOUSE_RIGHT_DOUBLECLICK:
subType = NS_EVENT_BITS_MOUSE_DBLCLICK;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_DBLCLICK) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_DBLCLICK) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_MOUSE_ENTER: case NS_MOUSE_ENTER:
subType = NS_EVENT_BITS_MOUSE_MOUSEOVER;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEOVER) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEOVER) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_MOUSE_EXIT: case NS_MOUSE_EXIT:
subType = NS_EVENT_BITS_MOUSE_MOUSEOUT;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEOUT) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEOUT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -628,7 +744,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -662,8 +778,10 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_MOUSE_MOVE: case NS_MOUSE_MOVE:
subType = NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE;
if (ls->mSubType & NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE) { if (ls->mSubType & NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -672,7 +790,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -709,13 +827,16 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_COMPOSITION_START: case NS_COMPOSITION_START:
subType = NS_EVENT_BITS_COMPOSITION_START;
if (ls->mSubType & NS_EVENT_BITS_COMPOSITION_START) { if (ls->mSubType & NS_EVENT_BITS_COMPOSITION_START) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_COMPOSITION_END: case NS_COMPOSITION_END:
subType = NS_EVENT_BITS_COMPOSITION_END;
if (ls->mSubType & NS_EVENT_BITS_COMPOSITION_END) { if (ls->mSubType & NS_EVENT_BITS_COMPOSITION_END) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -724,7 +845,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -754,11 +875,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = NS_EVENT_BITS_TEXT_TEXT;
if (ls->mSubType & NS_EVENT_BITS_TEXT_TEXT) { if (ls->mSubType & NS_EVENT_BITS_TEXT_TEXT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -800,18 +922,22 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_KEY_UP: case NS_KEY_UP:
subType = NS_EVENT_BITS_KEY_KEYUP;
if (ls->mSubType & NS_EVENT_BITS_KEY_KEYUP) { if (ls->mSubType & NS_EVENT_BITS_KEY_KEYUP) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_KEY_DOWN: case NS_KEY_DOWN:
subType = NS_EVENT_BITS_KEY_KEYDOWN;
if (ls->mSubType & NS_EVENT_BITS_KEY_KEYDOWN) { if (ls->mSubType & NS_EVENT_BITS_KEY_KEYDOWN) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_KEY_PRESS: case NS_KEY_PRESS:
subType = NS_EVENT_BITS_KEY_KEYPRESS;
if (ls->mSubType & NS_EVENT_BITS_KEY_KEYPRESS) { if (ls->mSubType & NS_EVENT_BITS_KEY_KEYPRESS) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -820,7 +946,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -858,13 +984,16 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_FOCUS_CONTENT: case NS_FOCUS_CONTENT:
subType = NS_EVENT_BITS_FOCUS_FOCUS;
if (ls->mSubType & NS_EVENT_BITS_FOCUS_FOCUS) { if (ls->mSubType & NS_EVENT_BITS_FOCUS_FOCUS) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_BLUR_CONTENT: case NS_BLUR_CONTENT:
subType = NS_EVENT_BITS_FOCUS_BLUR;
if (ls->mSubType & NS_EVENT_BITS_FOCUS_BLUR) { if (ls->mSubType & NS_EVENT_BITS_FOCUS_BLUR) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -873,7 +1002,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -923,28 +1052,34 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_FORM_SUBMIT: case NS_FORM_SUBMIT:
subType = NS_EVENT_BITS_FORM_SUBMIT;
if (ls->mSubType & NS_EVENT_BITS_FORM_SUBMIT) { if (ls->mSubType & NS_EVENT_BITS_FORM_SUBMIT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_FORM_RESET: case NS_FORM_RESET:
subType = NS_EVENT_BITS_FORM_RESET;
if (ls->mSubType & NS_EVENT_BITS_FORM_RESET) { if (ls->mSubType & NS_EVENT_BITS_FORM_RESET) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_FORM_CHANGE: case NS_FORM_CHANGE:
subType = NS_EVENT_BITS_FORM_CHANGE;
if (ls->mSubType & NS_EVENT_BITS_FORM_CHANGE) { if (ls->mSubType & NS_EVENT_BITS_FORM_CHANGE) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_FORM_SELECTED: case NS_FORM_SELECTED:
subType = NS_EVENT_BITS_FORM_SELECT;
if (ls->mSubType & NS_EVENT_BITS_FORM_SELECT) { if (ls->mSubType & NS_EVENT_BITS_FORM_SELECT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_FORM_INPUT: case NS_FORM_INPUT:
subType = NS_EVENT_BITS_FORM_INPUT;
if (ls->mSubType & NS_EVENT_BITS_FORM_INPUT) { if (ls->mSubType & NS_EVENT_BITS_FORM_INPUT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -953,7 +1088,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -992,13 +1127,16 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_PAGE_LOAD: case NS_PAGE_LOAD:
subType = NS_EVENT_BITS_LOAD_LOAD;
if (ls->mSubType & NS_EVENT_BITS_LOAD_LOAD) { if (ls->mSubType & NS_EVENT_BITS_LOAD_LOAD) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_PAGE_UNLOAD: case NS_PAGE_UNLOAD:
subType = NS_EVENT_BITS_LOAD_UNLOAD;
if (ls->mSubType & NS_EVENT_BITS_LOAD_UNLOAD) { if (ls->mSubType & NS_EVENT_BITS_LOAD_UNLOAD) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -1007,7 +1145,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -1036,11 +1174,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = NS_EVENT_BITS_PAINT_PAINT;
if (ls->mSubType & NS_EVENT_BITS_PAINT_PAINT) { if (ls->mSubType & NS_EVENT_BITS_PAINT_PAINT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -1088,24 +1227,30 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_DRAGDROP_ENTER: case NS_DRAGDROP_ENTER:
subType = NS_EVENT_BITS_DRAG_ENTER;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_ENTER) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_ENTER)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
case NS_DRAGDROP_OVER: case NS_DRAGDROP_OVER:
subType = NS_EVENT_BITS_DRAG_OVER;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_OVER) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_OVER)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
case NS_DRAGDROP_EXIT: case NS_DRAGDROP_EXIT:
subType = NS_EVENT_BITS_DRAG_EXIT;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_EXIT) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_EXIT)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
case NS_DRAGDROP_DROP: case NS_DRAGDROP_DROP:
subType = NS_EVENT_BITS_DRAG_DROP;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_DROP) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_DROP)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
case NS_DRAGDROP_GESTURE: case NS_DRAGDROP_GESTURE:
subType = NS_EVENT_BITS_DRAG_GESTURE;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_GESTURE) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_GESTURE)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
@ -1113,7 +1258,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || dragStruct->mSubType == NS_EVENT_BITS_DRAG_NONE) if (correctSubType || dragStruct->mSubType == NS_EVENT_BITS_DRAG_NONE)
ret = dragStruct->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(dragStruct, *aDOMEvent, subType);
} }
} }
} }
@ -1162,28 +1307,34 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_MENU_CREATE: case NS_MENU_CREATE:
subType = NS_EVENT_BITS_MENU_CREATE;
if (ls->mSubType & NS_EVENT_BITS_MENU_CREATE) { if (ls->mSubType & NS_EVENT_BITS_MENU_CREATE) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_MENU_DESTROY: case NS_MENU_DESTROY:
subType = NS_EVENT_BITS_MENU_DESTROY;
if (ls->mSubType & NS_EVENT_BITS_MENU_DESTROY) { if (ls->mSubType & NS_EVENT_BITS_MENU_DESTROY) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_MENU_ACTION: case NS_MENU_ACTION:
subType = NS_EVENT_BITS_MENU_ACTION;
if (ls->mSubType & NS_EVENT_BITS_MENU_ACTION) { if (ls->mSubType & NS_EVENT_BITS_MENU_ACTION) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_XUL_BROADCAST: case NS_XUL_BROADCAST:
subType = NS_EVENT_BITS_XUL_BROADCAST;
if (ls->mSubType & NS_EVENT_BITS_XUL_BROADCAST) { if (ls->mSubType & NS_EVENT_BITS_XUL_BROADCAST) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_XUL_COMMAND_UPDATE: case NS_XUL_COMMAND_UPDATE:
subType = NS_EVENT_BITS_XUL_COMMAND_UPDATE;
if (ls->mSubType & NS_EVENT_BITS_XUL_COMMAND_UPDATE) { if (ls->mSubType & NS_EVENT_BITS_XUL_COMMAND_UPDATE) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -1192,7 +1343,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }

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

@ -27,11 +27,13 @@
#include "jsapi.h" #include "jsapi.h"
class nsIDOMEvent; class nsIDOMEvent;
class nsIAtom;
typedef struct { typedef struct {
nsIDOMEventListener* mListener; nsIDOMEventListener* mListener;
PRUint8 mFlags; PRUint8 mFlags;
PRUint8 mSubType; PRUint8 mSubType;
PRUint32 mHandlerIsString;
} nsListenerStruct; } nsListenerStruct;
//Flag must live higher than all event flags in nsGUIEvent.h //Flag must live higher than all event flags in nsGUIEvent.h
@ -68,13 +70,15 @@ public:
virtual nsresult AddEventListenerByType(nsIDOMEventListener *aListener, const nsString& type, PRInt32 aFlags); virtual nsresult AddEventListenerByType(nsIDOMEventListener *aListener, const nsString& type, PRInt32 aFlags);
virtual nsresult RemoveEventListenerByType(nsIDOMEventListener *aListener, const nsString& type, PRInt32 aFlags) ; virtual nsresult RemoveEventListenerByType(nsIDOMEventListener *aListener, const nsString& type, PRInt32 aFlags) ;
virtual nsresult AddScriptEventListener(nsIScriptContext* aContext, virtual nsresult AddScriptEventListener(nsIScriptContext*aContext,
nsIScriptObjectOwner *aScriptObjectOwner, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName, nsIAtom *aName,
const nsString& aFunc, const nsString& aFunc,
const nsIID& aIID); REFNSIID aIID,
PRBool aDeferCompilation);
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext, virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aScriptObjectOwner, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom* aName,
const nsIID& aIID); const nsIID& aIID);
@ -93,9 +97,14 @@ public:
virtual nsresult RemoveAllListeners(PRBool aScriptOnly); virtual nsresult RemoveAllListeners(PRBool aScriptOnly);
static nsresult GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aSubType);
protected: protected:
nsresult SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID); nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
nsresult GetIdentifiersForType(const nsString& aType, nsIID& aIID, PRInt32* aSubType); nsIDOMEvent* aDOMEvent,
PRUint32 aSubType);
nsListenerStruct* FindJSEventListener(REFNSIID aIID);
nsresult SetJSEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aOwner, nsIAtom* aName, REFNSIID aIID, PRBool aIsString);
nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType); nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType);
nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType); nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType);
void ReleaseListeners(nsVoidArray** aListeners, PRBool aScriptOnly); void ReleaseListeners(nsVoidArray** aListeners, PRBool aScriptOnly);

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

@ -61,6 +61,7 @@
#include "nsIHTMLContentContainer.h" #include "nsIHTMLContentContainer.h"
#include "nsHTMLParts.h" #include "nsHTMLParts.h"
#include "nsString.h" #include "nsString.h"
#include "nsLayoutAtoms.h"
#include "nsHTMLAtoms.h" #include "nsHTMLAtoms.h"
#include "nsDOMEventsIIDs.h" #include "nsDOMEventsIIDs.h"
#include "nsIEventStateManager.h" #include "nsIEventStateManager.h"
@ -632,36 +633,36 @@ nsGenericHTMLElement::SetAttribute(PRInt32 aNameSpaceID,
} }
else { else {
// Check for event handlers // Check for event handlers
if ((nsHTMLAtoms::onclick == aAttribute) || if ((nsLayoutAtoms::onclick == aAttribute) ||
(nsHTMLAtoms::ondblclick == aAttribute) || (nsLayoutAtoms::ondblclick == aAttribute) ||
(nsHTMLAtoms::onmousedown == aAttribute) || (nsLayoutAtoms::onmousedown == aAttribute) ||
(nsHTMLAtoms::onmouseup == aAttribute) || (nsLayoutAtoms::onmouseup == aAttribute) ||
(nsHTMLAtoms::onmouseover == aAttribute) || (nsLayoutAtoms::onmouseover == aAttribute) ||
(nsHTMLAtoms::onmouseout == aAttribute)) (nsLayoutAtoms::onmouseout == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMMouseListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMMouseListenerIID);
else if ((nsHTMLAtoms::onkeydown == aAttribute) || else if ((nsLayoutAtoms::onkeydown == aAttribute) ||
(nsHTMLAtoms::onkeyup == aAttribute) || (nsLayoutAtoms::onkeyup == aAttribute) ||
(nsHTMLAtoms::onkeypress == aAttribute)) (nsLayoutAtoms::onkeypress == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMKeyListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMKeyListenerIID);
else if (nsHTMLAtoms::onmousemove == aAttribute) else if (nsLayoutAtoms::onmousemove == aAttribute)
AddScriptEventListener(aAttribute, aValue, kIDOMMouseMotionListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMMouseMotionListenerIID);
else if (nsHTMLAtoms::onload == aAttribute) else if (nsLayoutAtoms::onload == aAttribute)
AddScriptEventListener(nsHTMLAtoms::onload, aValue, kIDOMLoadListenerIID); AddScriptEventListener(nsLayoutAtoms::onload, aValue, kIDOMLoadListenerIID);
else if ((nsHTMLAtoms::onunload == aAttribute) || else if ((nsLayoutAtoms::onunload == aAttribute) ||
(nsHTMLAtoms::onabort == aAttribute) || (nsLayoutAtoms::onabort == aAttribute) ||
(nsHTMLAtoms::onerror == aAttribute)) (nsLayoutAtoms::onerror == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMLoadListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMLoadListenerIID);
else if ((nsHTMLAtoms::onfocus == aAttribute) || else if ((nsLayoutAtoms::onfocus == aAttribute) ||
(nsHTMLAtoms::onblur == aAttribute)) (nsLayoutAtoms::onblur == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMFocusListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMFocusListenerIID);
else if ((nsHTMLAtoms::onsubmit == aAttribute) || else if ((nsLayoutAtoms::onsubmit == aAttribute) ||
(nsHTMLAtoms::onreset == aAttribute) || (nsLayoutAtoms::onreset == aAttribute) ||
(nsHTMLAtoms::onchange == aAttribute) || (nsLayoutAtoms::onchange == aAttribute) ||
(nsHTMLAtoms::onselect == aAttribute)) (nsLayoutAtoms::onselect == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID);
else if (nsHTMLAtoms::onpaint == aAttribute) else if (nsLayoutAtoms::onpaint == aAttribute)
AddScriptEventListener(aAttribute, aValue, kIDOMPaintListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMPaintListenerIID);
else if (nsHTMLAtoms::oninput == aAttribute) else if (nsLayoutAtoms::oninput == aAttribute)
AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID);
} }

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

@ -192,29 +192,6 @@ HTML_ATOM(noshade, "noshade")
HTML_ATOM(nowrap, "nowrap") HTML_ATOM(nowrap, "nowrap")
HTML_ATOM(object, "object") HTML_ATOM(object, "object")
HTML_ATOM(ol, "ol") HTML_ATOM(ol, "ol")
HTML_ATOM(onabort, "onabort")
HTML_ATOM(onblur, "onblur")
HTML_ATOM(onchange, "onchange")
HTML_ATOM(onselect, "onselect")
HTML_ATOM(onclick, "onclick")
HTML_ATOM(ondblclick, "ondblclick")
HTML_ATOM(ondragdrop, "ondragdrop")
HTML_ATOM(onerror, "onerror")
HTML_ATOM(onfocus, "onfocus")
HTML_ATOM(oninput, "oninput")
HTML_ATOM(onkeydown, "onkeydown")
HTML_ATOM(onkeypress, "onkeypress")
HTML_ATOM(onkeyup, "onkeyup")
HTML_ATOM(onload, "onload")
HTML_ATOM(onmousedown, "onmousedown")
HTML_ATOM(onmousemove, "onmousemove")
HTML_ATOM(onmouseover, "onmouseover")
HTML_ATOM(onmouseout, "onmouseout")
HTML_ATOM(onmouseup, "onmouseup")
HTML_ATOM(onpaint, "onpaint")
HTML_ATOM(onreset, "onreset")
HTML_ATOM(onsubmit, "onsubmit")
HTML_ATOM(onunload, "onunload")
HTML_ATOM(option, "option") HTML_ATOM(option, "option")
HTML_ATOM(overflow, "overflow") HTML_ATOM(overflow, "overflow")
HTML_ATOM(p, "p") HTML_ATOM(p, "p")

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

@ -2495,6 +2495,52 @@ nsHTMLDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject
return res; return res;
} }
PRBool
nsHTMLDocument::Resolve(JSContext *aContext, jsval aID)
{
nsCOMPtr<nsIDOMElement> element;
char* str = JS_GetStringBytes(JS_ValueToString(aContext, aID));
nsAutoString name(str);
nsresult result = NS_OK;
PRBool ret = PR_TRUE;
result = NamedItem(name, getter_AddRefs(element));
if (NS_SUCCEEDED(result) && element) {
nsCOMPtr<nsIScriptObjectOwner> owner = do_QueryInterface(element);
if (owner) {
nsCOMPtr<nsIScriptContext> scriptContext;
nsCOMPtr<nsIScriptContextOwner> contextOwner;
contextOwner = getter_AddRefs(GetScriptContextOwner());
if (contextOwner) {
result = contextOwner->GetScriptContext(getter_AddRefs(scriptContext));
}
if (!scriptContext) {
scriptContext = dont_AddRef((nsIScriptContext*)JS_GetContextPrivate(aContext));
}
JSObject* obj;
if (scriptContext) {
result = owner->GetScriptObject(scriptContext, (void**)&obj);
if (NS_SUCCEEDED(result) && (nsnull != obj)) {
JSObject* myObj;
result = GetScriptObject(scriptContext, (void**)&myObj);
ret = ::JS_DefineProperty(aContext, myObj,
str, OBJECT_TO_JSVAL(obj),
nsnull, nsnull, 0);
}
}
}
}
if (NS_FAILED(result)) {
ret = PR_FALSE;
}
return ret;
}
//---------------------------- //----------------------------
static PRBool IsInline(eHTMLTags aTag) static PRBool IsInline(eHTMLTags aTag)

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

@ -124,6 +124,9 @@ public:
// From nsIScriptObjectOwner interface, implemented by nsDocument // From nsIScriptObjectOwner interface, implemented by nsDocument
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
// From nsJSScriptObject interface, implemented by nsDocument
virtual PRBool Resolve(JSContext *aContext, jsval aID);
/** /**
* Finds text in content * Finds text in content

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

@ -192,29 +192,6 @@ HTML_ATOM(noshade, "noshade")
HTML_ATOM(nowrap, "nowrap") HTML_ATOM(nowrap, "nowrap")
HTML_ATOM(object, "object") HTML_ATOM(object, "object")
HTML_ATOM(ol, "ol") HTML_ATOM(ol, "ol")
HTML_ATOM(onabort, "onabort")
HTML_ATOM(onblur, "onblur")
HTML_ATOM(onchange, "onchange")
HTML_ATOM(onselect, "onselect")
HTML_ATOM(onclick, "onclick")
HTML_ATOM(ondblclick, "ondblclick")
HTML_ATOM(ondragdrop, "ondragdrop")
HTML_ATOM(onerror, "onerror")
HTML_ATOM(onfocus, "onfocus")
HTML_ATOM(oninput, "oninput")
HTML_ATOM(onkeydown, "onkeydown")
HTML_ATOM(onkeypress, "onkeypress")
HTML_ATOM(onkeyup, "onkeyup")
HTML_ATOM(onload, "onload")
HTML_ATOM(onmousedown, "onmousedown")
HTML_ATOM(onmousemove, "onmousemove")
HTML_ATOM(onmouseover, "onmouseover")
HTML_ATOM(onmouseout, "onmouseout")
HTML_ATOM(onmouseup, "onmouseup")
HTML_ATOM(onpaint, "onpaint")
HTML_ATOM(onreset, "onreset")
HTML_ATOM(onsubmit, "onsubmit")
HTML_ATOM(onunload, "onunload")
HTML_ATOM(option, "option") HTML_ATOM(option, "option")
HTML_ATOM(overflow, "overflow") HTML_ATOM(overflow, "overflow")
HTML_ATOM(p, "p") HTML_ATOM(p, "p")

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

@ -111,6 +111,40 @@ LAYOUT_ATOM(overflowProperty, "OverflowProperty")
LAYOUT_ATOM(overflowLinesProperty, "OverflowLinesProperty") LAYOUT_ATOM(overflowLinesProperty, "OverflowLinesProperty")
LAYOUT_ATOM(viewProperty, "ViewProperty") LAYOUT_ATOM(viewProperty, "ViewProperty")
// Alphabetical list of event handler names
LAYOUT_ATOM(onabort, "onabort")
LAYOUT_ATOM(onblur, "onblur")
LAYOUT_ATOM(onbroadcast, "onbroadcast")
LAYOUT_ATOM(onchange, "onchange")
LAYOUT_ATOM(onclick, "onclick")
LAYOUT_ATOM(oncommand, "oncommand")
LAYOUT_ATOM(oncommandupdate, "oncommandupdate")
LAYOUT_ATOM(oncreate, "oncreate")
LAYOUT_ATOM(ondblclick, "ondblclick")
LAYOUT_ATOM(ondestroy, "ondestroy")
LAYOUT_ATOM(ondragdrop, "ondragdrop")
LAYOUT_ATOM(ondragenter, "ondragenter")
LAYOUT_ATOM(ondragexit, "ondragexit")
LAYOUT_ATOM(ondraggesture, "ondraggesture")
LAYOUT_ATOM(ondragover, "ondragover")
LAYOUT_ATOM(onerror, "onerror")
LAYOUT_ATOM(onfocus, "onfocus")
LAYOUT_ATOM(oninput, "oninput")
LAYOUT_ATOM(onkeydown, "onkeydown")
LAYOUT_ATOM(onkeypress, "onkeypress")
LAYOUT_ATOM(onkeyup, "onkeyup")
LAYOUT_ATOM(onload, "onload")
LAYOUT_ATOM(onmousedown, "onmousedown")
LAYOUT_ATOM(onmousemove, "onmousemove")
LAYOUT_ATOM(onmouseover, "onmouseover")
LAYOUT_ATOM(onmouseout, "onmouseout")
LAYOUT_ATOM(onmouseup, "onmouseup")
LAYOUT_ATOM(onpaint, "onpaint")
LAYOUT_ATOM(onreset, "onreset")
LAYOUT_ATOM(onselect, "onselect")
LAYOUT_ATOM(onsubmit, "onsubmit")
LAYOUT_ATOM(onunload, "onunload")
#ifdef DEBUG #ifdef DEBUG
// Alphabetical list of atoms used by debugging code // Alphabetical list of atoms used by debugging code
LAYOUT_ATOM(cellMap, "TableCellMap") LAYOUT_ATOM(cellMap, "TableCellMap")

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

@ -111,6 +111,40 @@ LAYOUT_ATOM(overflowProperty, "OverflowProperty")
LAYOUT_ATOM(overflowLinesProperty, "OverflowLinesProperty") LAYOUT_ATOM(overflowLinesProperty, "OverflowLinesProperty")
LAYOUT_ATOM(viewProperty, "ViewProperty") LAYOUT_ATOM(viewProperty, "ViewProperty")
// Alphabetical list of event handler names
LAYOUT_ATOM(onabort, "onabort")
LAYOUT_ATOM(onblur, "onblur")
LAYOUT_ATOM(onbroadcast, "onbroadcast")
LAYOUT_ATOM(onchange, "onchange")
LAYOUT_ATOM(onclick, "onclick")
LAYOUT_ATOM(oncommand, "oncommand")
LAYOUT_ATOM(oncommandupdate, "oncommandupdate")
LAYOUT_ATOM(oncreate, "oncreate")
LAYOUT_ATOM(ondblclick, "ondblclick")
LAYOUT_ATOM(ondestroy, "ondestroy")
LAYOUT_ATOM(ondragdrop, "ondragdrop")
LAYOUT_ATOM(ondragenter, "ondragenter")
LAYOUT_ATOM(ondragexit, "ondragexit")
LAYOUT_ATOM(ondraggesture, "ondraggesture")
LAYOUT_ATOM(ondragover, "ondragover")
LAYOUT_ATOM(onerror, "onerror")
LAYOUT_ATOM(onfocus, "onfocus")
LAYOUT_ATOM(oninput, "oninput")
LAYOUT_ATOM(onkeydown, "onkeydown")
LAYOUT_ATOM(onkeypress, "onkeypress")
LAYOUT_ATOM(onkeyup, "onkeyup")
LAYOUT_ATOM(onload, "onload")
LAYOUT_ATOM(onmousedown, "onmousedown")
LAYOUT_ATOM(onmousemove, "onmousemove")
LAYOUT_ATOM(onmouseover, "onmouseover")
LAYOUT_ATOM(onmouseout, "onmouseout")
LAYOUT_ATOM(onmouseup, "onmouseup")
LAYOUT_ATOM(onpaint, "onpaint")
LAYOUT_ATOM(onreset, "onreset")
LAYOUT_ATOM(onselect, "onselect")
LAYOUT_ATOM(onsubmit, "onsubmit")
LAYOUT_ATOM(onunload, "onunload")
#ifdef DEBUG #ifdef DEBUG
// Alphabetical list of atoms used by debugging code // Alphabetical list of atoms used by debugging code
LAYOUT_ATOM(cellMap, "TableCellMap") LAYOUT_ATOM(cellMap, "TableCellMap")

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

@ -111,6 +111,40 @@ LAYOUT_ATOM(overflowProperty, "OverflowProperty")
LAYOUT_ATOM(overflowLinesProperty, "OverflowLinesProperty") LAYOUT_ATOM(overflowLinesProperty, "OverflowLinesProperty")
LAYOUT_ATOM(viewProperty, "ViewProperty") LAYOUT_ATOM(viewProperty, "ViewProperty")
// Alphabetical list of event handler names
LAYOUT_ATOM(onabort, "onabort")
LAYOUT_ATOM(onblur, "onblur")
LAYOUT_ATOM(onbroadcast, "onbroadcast")
LAYOUT_ATOM(onchange, "onchange")
LAYOUT_ATOM(onclick, "onclick")
LAYOUT_ATOM(oncommand, "oncommand")
LAYOUT_ATOM(oncommandupdate, "oncommandupdate")
LAYOUT_ATOM(oncreate, "oncreate")
LAYOUT_ATOM(ondblclick, "ondblclick")
LAYOUT_ATOM(ondestroy, "ondestroy")
LAYOUT_ATOM(ondragdrop, "ondragdrop")
LAYOUT_ATOM(ondragenter, "ondragenter")
LAYOUT_ATOM(ondragexit, "ondragexit")
LAYOUT_ATOM(ondraggesture, "ondraggesture")
LAYOUT_ATOM(ondragover, "ondragover")
LAYOUT_ATOM(onerror, "onerror")
LAYOUT_ATOM(onfocus, "onfocus")
LAYOUT_ATOM(oninput, "oninput")
LAYOUT_ATOM(onkeydown, "onkeydown")
LAYOUT_ATOM(onkeypress, "onkeypress")
LAYOUT_ATOM(onkeyup, "onkeyup")
LAYOUT_ATOM(onload, "onload")
LAYOUT_ATOM(onmousedown, "onmousedown")
LAYOUT_ATOM(onmousemove, "onmousemove")
LAYOUT_ATOM(onmouseover, "onmouseover")
LAYOUT_ATOM(onmouseout, "onmouseout")
LAYOUT_ATOM(onmouseup, "onmouseup")
LAYOUT_ATOM(onpaint, "onpaint")
LAYOUT_ATOM(onreset, "onreset")
LAYOUT_ATOM(onselect, "onselect")
LAYOUT_ATOM(onsubmit, "onsubmit")
LAYOUT_ATOM(onunload, "onunload")
#ifdef DEBUG #ifdef DEBUG
// Alphabetical list of atoms used by debugging code // Alphabetical list of atoms used by debugging code
LAYOUT_ATOM(cellMap, "TableCellMap") LAYOUT_ATOM(cellMap, "TableCellMap")

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

@ -72,6 +72,7 @@
#include "nsINameSpaceManager.h" #include "nsINameSpaceManager.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsLayoutAtoms.h"
#include "nsLayoutCID.h" #include "nsLayoutCID.h"
#include "nsIDOMSelection.h" #include "nsIDOMSelection.h"
#include "nsIDOMRange.h" #include "nsIDOMRange.h"
@ -2499,71 +2500,72 @@ PRBool nsDocument::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID))); mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
mPrefix.SetString(mPropName.GetUnicode(), 2); mPrefix.SetString(mPropName.GetUnicode(), 2);
if (mPrefix == "on") { if (mPrefix == "on") {
nsCOMPtr<nsIAtom> atom = getter_AddRefs(NS_NewAtom(mPropName));
nsIEventListenerManager *mManager = nsnull; nsIEventListenerManager *mManager = nsnull;
if (mPropName == "onmousedown" || mPropName == "onmouseup" || mPropName == "onclick" || if (atom == nsLayoutAtoms::onmousedown || atom == nsLayoutAtoms::onmouseup || atom == nsLayoutAtoms::onclick ||
mPropName == "onmouseover" || mPropName == "onmouseout") { atom == nsLayoutAtoms::onmouseover || atom == nsLayoutAtoms::onmouseout) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMMouseListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMMouseListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onkeydown" || mPropName == "onkeyup" || mPropName == "onkeypress") { else if (atom == nsLayoutAtoms::onkeydown || atom == nsLayoutAtoms::onkeyup || atom == nsLayoutAtoms::onkeypress) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMKeyListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMKeyListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onmousemove") { else if (atom == nsLayoutAtoms::onmousemove) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMMouseMotionListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMMouseMotionListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onfocus" || mPropName == "onblur") { else if (atom == nsLayoutAtoms::onfocus || atom == nsLayoutAtoms::onblur) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMFocusListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMFocusListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onsubmit" || mPropName == "onreset" || mPropName == "onchange" || else if (atom == nsLayoutAtoms::onsubmit || atom == nsLayoutAtoms::onreset || atom == nsLayoutAtoms::onchange ||
mPropName == "onselect") { atom == nsLayoutAtoms::onselect) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMFormListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMFormListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onload" || mPropName == "onunload" || mPropName == "onabort" || else if (atom == nsLayoutAtoms::onload || atom == nsLayoutAtoms::onunload || atom == nsLayoutAtoms::onabort ||
mPropName == "onerror") { atom == nsLayoutAtoms::onerror) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMLoadListenerIID)) { if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMLoadListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (mPropName == "onpaint") { else if (atom == nsLayoutAtoms::onpaint) {
if (NS_OK == GetListenerManager(&mManager)) { if (NS_OK == GetListenerManager(&mManager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *) nsIScriptContext *mScriptCX = (nsIScriptContext *)
JS_GetContextPrivate(aContext); JS_GetContextPrivate(aContext);
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this,
kIDOMPaintListenerIID)) { atom, kIDOMPaintListenerIID)) {
NS_RELEASE(mManager); NS_RELEASE(mManager);
return PR_FALSE; return PR_FALSE;
} }

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

@ -965,7 +965,8 @@ nsGenericElement::GetScriptObject(nsIScriptContext* aContext,
nsAutoString tag; nsAutoString tag;
mTag->ToString(tag); mTag->ToString(tag);
res = factory->NewScriptElement(tag, aContext, mContent, res = factory->NewScriptElement(tag, aContext, mContent,
mParent, (void**)&slots->mScriptObject); mParent ? (nsISupports*)mParent : (nsISupports*)mDocument,
(void**)&slots->mScriptObject);
NS_RELEASE(factory); NS_RELEASE(factory);
char tagBuf[50]; char tagBuf[50];
@ -1112,71 +1113,72 @@ nsGenericElement::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
propName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID))); propName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
prefix.SetString(propName.GetUnicode(), 2); prefix.SetString(propName.GetUnicode(), 2);
if (prefix == "on") { if (prefix == "on") {
nsCOMPtr<nsIAtom> atom = getter_AddRefs(NS_NewAtom(propName));
nsIEventListenerManager *manager = nsnull; nsIEventListenerManager *manager = nsnull;
if (propName == "onmousedown" || propName == "onmouseup" || propName == "onclick" || if (atom == nsLayoutAtoms::onmousedown || atom == nsLayoutAtoms::onmouseup || atom == nsLayoutAtoms::onclick ||
propName == "onmouseover" || propName == "onmouseout") { atom == nsLayoutAtoms::onmouseover || atom == nsLayoutAtoms::onmouseout) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMMouseListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMMouseListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onkeydown" || propName == "onkeyup" || propName == "onkeypress") { else if (atom == nsLayoutAtoms::onkeydown || atom == nsLayoutAtoms::onkeyup || atom == nsLayoutAtoms::onkeypress) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMKeyListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMKeyListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onmousemove") { else if (atom == nsLayoutAtoms::onmousemove) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMMouseMotionListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMMouseMotionListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onfocus" || propName == "onblur") { else if (atom == nsLayoutAtoms::onfocus || atom == nsLayoutAtoms::onblur) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMFocusListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMFocusListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onsubmit" || propName == "onreset" || propName == "onchange" || else if (atom == nsLayoutAtoms::onsubmit || atom == nsLayoutAtoms::onreset || atom == nsLayoutAtoms::onchange ||
propName == "onselect") { atom == nsLayoutAtoms::onselect) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMFormListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMFormListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onload" || propName == "onunload" || propName == "onabort" || else if (atom == nsLayoutAtoms::onload || atom == nsLayoutAtoms::onunload || atom == nsLayoutAtoms::onabort ||
propName == "onerror") { atom == nsLayoutAtoms::onerror) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, kIDOMLoadListenerIID)) { if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, atom, kIDOMLoadListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
} }
} }
else if (propName == "onpaint") { else if (atom == nsLayoutAtoms::onpaint) {
if (NS_OK == GetListenerManager(&manager)) { if (NS_OK == GetListenerManager(&manager)) {
nsIScriptContext *mScriptCX = (nsIScriptContext *) nsIScriptContext *mScriptCX = (nsIScriptContext *)
JS_GetContextPrivate(aContext); JS_GetContextPrivate(aContext);
if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner, if (NS_OK != manager->RegisterScriptEventListener(mScriptCX, owner,
kIDOMPaintListenerIID)) { atom, kIDOMPaintListenerIID)) {
NS_RELEASE(manager); NS_RELEASE(manager);
return PR_FALSE; return PR_FALSE;
} }
@ -1305,7 +1307,7 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute,
if (NS_OK == receiver->GetListenerManager(&manager)) { if (NS_OK == receiver->GetListenerManager(&manager)) {
nsIScriptObjectOwner *mObjectOwner; nsIScriptObjectOwner *mObjectOwner;
if (NS_OK == global->QueryInterface(kIScriptObjectOwnerIID, (void**)&mObjectOwner)) { if (NS_OK == global->QueryInterface(kIScriptObjectOwnerIID, (void**)&mObjectOwner)) {
ret = manager->AddScriptEventListener(context, mObjectOwner, aAttribute, aValue, aIID); ret = manager->AddScriptEventListener(context, mObjectOwner, aAttribute, aValue, aIID, PR_FALSE);
NS_RELEASE(mObjectOwner); NS_RELEASE(mObjectOwner);
} }
NS_RELEASE(manager); NS_RELEASE(manager);
@ -1321,7 +1323,7 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute,
if (NS_OK == mContent->QueryInterface(kIScriptObjectOwnerIID, if (NS_OK == mContent->QueryInterface(kIScriptObjectOwnerIID,
(void**) &cowner)) { (void**) &cowner)) {
ret = manager->AddScriptEventListener(context, cowner, ret = manager->AddScriptEventListener(context, cowner,
aAttribute, aValue, aIID); aAttribute, aValue, aIID, PR_TRUE);
NS_RELEASE(cowner); NS_RELEASE(cowner);
} }
NS_RELEASE(manager); NS_RELEASE(manager);

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

@ -85,15 +85,21 @@ public:
* @param an event listener * @param an event listener
*/ */
virtual nsresult AddScriptEventListener(nsIScriptContext*aContext, nsIScriptObjectOwner *aScriptObjectOwner, virtual nsresult AddScriptEventListener(nsIScriptContext*aContext,
nsIAtom *aName, const nsString& aFunc, REFNSIID aIID) = 0; nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName,
const nsString& aFunc,
REFNSIID aIID,
PRBool aDeferCompilation) = 0;
/** /**
* Registers an event listners which already exists on the given script object with the event * Registers an event listners which already exists on the given script object with the event
* listener manager. * listener manager.
* @param an event listener * @param an event listener
*/ */
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aScriptObjectOwner, virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom* aName,
REFNSIID aIID) = 0; REFNSIID aIID) = 0;
/** /**

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

@ -41,10 +41,14 @@
#include "nsIPrivateDOMEvent.h" #include "nsIPrivateDOMEvent.h"
#include "nsIScriptObjectOwner.h" #include "nsIScriptObjectOwner.h"
#include "nsIScriptEventListener.h" #include "nsIScriptEventListener.h"
#include "nsIJSEventListener.h"
#include "nsDOMEventsIIDs.h" #include "nsDOMEventsIIDs.h"
#include "prmem.h" #include "prmem.h"
#include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectData.h" #include "nsIScriptGlobalObjectData.h"
#include "nsLayoutAtoms.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
@ -236,6 +240,7 @@ nsresult nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener
ls->mListener = aListener; ls->mListener = aListener;
ls->mFlags = aFlags; ls->mFlags = aFlags;
ls->mSubType = aSubType; ls->mSubType = aSubType;
ls->mHandlerIsString = 0;
(*listeners)->InsertElementAt((void*)ls, (*listeners)->Count()); (*listeners)->InsertElementAt((void*)ls, (*listeners)->Count());
NS_ADDREF(aListener); NS_ADDREF(aListener);
} }
@ -288,133 +293,133 @@ nsresult nsEventListenerManager::RemoveEventListenerByIID(nsIDOMEventListener *a
return NS_OK; return NS_OK;
} }
nsresult nsEventListenerManager::GetIdentifiersForType(const nsString& aType, nsIID& aIID, PRInt32* aFlags) nsresult nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aFlags)
{ {
if (aType == "mousedown") { if (aType == nsLayoutAtoms::onmousedown) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_MOUSEDOWN; *aFlags = NS_EVENT_BITS_MOUSE_MOUSEDOWN;
} }
else if (aType == "mouseup") { else if (aType == nsLayoutAtoms::onmouseup) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_MOUSEUP; *aFlags = NS_EVENT_BITS_MOUSE_MOUSEUP;
} }
else if (aType == "click") { else if (aType == nsLayoutAtoms::onclick) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_CLICK; *aFlags = NS_EVENT_BITS_MOUSE_CLICK;
} }
else if (aType == "dblclick") { else if (aType == nsLayoutAtoms::ondblclick) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_DBLCLICK; *aFlags = NS_EVENT_BITS_MOUSE_DBLCLICK;
} }
else if (aType == "mouseover") { else if (aType == nsLayoutAtoms::onmouseover) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_MOUSEOVER; *aFlags = NS_EVENT_BITS_MOUSE_MOUSEOVER;
} }
else if (aType == "mouseout") { else if (aType == nsLayoutAtoms::onmouseout) {
aIID = kIDOMMouseListenerIID; aIID = kIDOMMouseListenerIID;
*aFlags = NS_EVENT_BITS_MOUSE_MOUSEOUT; *aFlags = NS_EVENT_BITS_MOUSE_MOUSEOUT;
} }
else if (aType == "keydown") { else if (aType == nsLayoutAtoms::onkeydown) {
aIID = kIDOMKeyListenerIID; aIID = kIDOMKeyListenerIID;
*aFlags = NS_EVENT_BITS_KEY_KEYDOWN; *aFlags = NS_EVENT_BITS_KEY_KEYDOWN;
} }
else if (aType == "keyup") { else if (aType == nsLayoutAtoms::onkeyup) {
aIID = kIDOMKeyListenerIID; aIID = kIDOMKeyListenerIID;
*aFlags = NS_EVENT_BITS_KEY_KEYUP; *aFlags = NS_EVENT_BITS_KEY_KEYUP;
} }
else if (aType == "keypress") { else if (aType == nsLayoutAtoms::onkeypress) {
aIID = kIDOMKeyListenerIID; aIID = kIDOMKeyListenerIID;
*aFlags = NS_EVENT_BITS_KEY_KEYPRESS; *aFlags = NS_EVENT_BITS_KEY_KEYPRESS;
} }
else if (aType == "mousemove") { else if (aType == nsLayoutAtoms::onmousemove) {
aIID = kIDOMMouseMotionListenerIID; aIID = kIDOMMouseMotionListenerIID;
*aFlags = NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE; *aFlags = NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE;
} }
else if (aType == "focus") { else if (aType == nsLayoutAtoms::onfocus) {
aIID = kIDOMFocusListenerIID; aIID = kIDOMFocusListenerIID;
*aFlags = NS_EVENT_BITS_FOCUS_FOCUS; *aFlags = NS_EVENT_BITS_FOCUS_FOCUS;
} }
else if (aType == "blur") { else if (aType == nsLayoutAtoms::onblur) {
aIID = kIDOMFocusListenerIID; aIID = kIDOMFocusListenerIID;
*aFlags = NS_EVENT_BITS_FOCUS_BLUR; *aFlags = NS_EVENT_BITS_FOCUS_BLUR;
} }
else if (aType == "submit") { else if (aType == nsLayoutAtoms::onsubmit) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_SUBMIT; *aFlags = NS_EVENT_BITS_FORM_SUBMIT;
} }
else if (aType == "reset") { else if (aType == nsLayoutAtoms::onreset) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_RESET; *aFlags = NS_EVENT_BITS_FORM_RESET;
} }
else if (aType == "change") { else if (aType == nsLayoutAtoms::onchange) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_CHANGE; *aFlags = NS_EVENT_BITS_FORM_CHANGE;
} }
else if (aType == "select") { else if (aType == nsLayoutAtoms::onselect) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_SELECT; *aFlags = NS_EVENT_BITS_FORM_SELECT;
} }
else if (aType == "input") { else if (aType == nsLayoutAtoms::oninput) {
aIID = kIDOMFormListenerIID; aIID = kIDOMFormListenerIID;
*aFlags = NS_EVENT_BITS_FORM_INPUT; *aFlags = NS_EVENT_BITS_FORM_INPUT;
} }
else if (aType == "load") { else if (aType == nsLayoutAtoms::onload) {
aIID = kIDOMLoadListenerIID; aIID = kIDOMLoadListenerIID;
*aFlags = NS_EVENT_BITS_LOAD_LOAD; *aFlags = NS_EVENT_BITS_LOAD_LOAD;
} }
else if (aType == "unload") { else if (aType == nsLayoutAtoms::onunload) {
aIID = kIDOMLoadListenerIID; aIID = kIDOMLoadListenerIID;
*aFlags = NS_EVENT_BITS_LOAD_UNLOAD; *aFlags = NS_EVENT_BITS_LOAD_UNLOAD;
} }
else if (aType == "abort") { else if (aType == nsLayoutAtoms::onabort) {
aIID = kIDOMLoadListenerIID; aIID = kIDOMLoadListenerIID;
*aFlags = NS_EVENT_BITS_LOAD_ABORT; *aFlags = NS_EVENT_BITS_LOAD_ABORT;
} }
else if (aType == "error") { else if (aType == nsLayoutAtoms::onerror) {
aIID = kIDOMLoadListenerIID; aIID = kIDOMLoadListenerIID;
*aFlags = NS_EVENT_BITS_LOAD_ERROR; *aFlags = NS_EVENT_BITS_LOAD_ERROR;
} }
else if (aType == "paint") { else if (aType == nsLayoutAtoms::onpaint) {
aIID = kIDOMPaintListenerIID; aIID = kIDOMPaintListenerIID;
*aFlags = NS_EVENT_BITS_PAINT_PAINT; *aFlags = NS_EVENT_BITS_PAINT_PAINT;
} // extened this to handle IME related events } // extened this to handle IME related events
else if (aType == "create") { else if (aType == nsLayoutAtoms::oncreate) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_MENU_CREATE; *aFlags = NS_EVENT_BITS_MENU_CREATE;
} }
else if (aType == "destroy") { else if (aType == nsLayoutAtoms::ondestroy) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_MENU_DESTROY; *aFlags = NS_EVENT_BITS_MENU_DESTROY;
} }
else if (aType == "command") { else if (aType == nsLayoutAtoms::oncommand) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_MENU_ACTION; *aFlags = NS_EVENT_BITS_MENU_ACTION;
} }
else if (aType == "broadcast") { else if (aType == nsLayoutAtoms::onbroadcast) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_XUL_BROADCAST; *aFlags = NS_EVENT_BITS_XUL_BROADCAST;
} }
else if (aType == "commandupdate") { else if (aType == nsLayoutAtoms::oncommandupdate) {
aIID = kIDOMMenuListenerIID; aIID = kIDOMMenuListenerIID;
*aFlags = NS_EVENT_BITS_XUL_COMMAND_UPDATE; *aFlags = NS_EVENT_BITS_XUL_COMMAND_UPDATE;
} }
else if (aType == "dragenter") { else if (aType == nsLayoutAtoms::ondragenter) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_ENTER; *aFlags = NS_EVENT_BITS_DRAG_ENTER;
} }
else if (aType == "dragover") { else if (aType == nsLayoutAtoms::ondragover) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_OVER; *aFlags = NS_EVENT_BITS_DRAG_OVER;
} }
else if (aType == "dragexit") { else if (aType == nsLayoutAtoms::ondragexit) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_EXIT; *aFlags = NS_EVENT_BITS_DRAG_EXIT;
} }
else if (aType == "dragdrop") { else if (aType == nsLayoutAtoms::ondragdrop) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_DROP; *aFlags = NS_EVENT_BITS_DRAG_DROP;
} }
else if (aType == "draggesture") { else if (aType == nsLayoutAtoms::ondraggesture) {
aIID = NS_GET_IID(nsIDOMDragListener); aIID = NS_GET_IID(nsIDOMDragListener);
*aFlags = NS_EVENT_BITS_DRAG_GESTURE; *aFlags = NS_EVENT_BITS_DRAG_GESTURE;
} }
@ -429,11 +434,18 @@ nsresult nsEventListenerManager::AddEventListenerByType(nsIDOMEventListener *aLi
{ {
PRInt32 subType; PRInt32 subType;
nsIID iid; nsIID iid;
nsAutoString str("on");
nsIAtom* atom;
if (NS_OK == GetIdentifiersForType(aType, iid, &subType)) { str.Append(aType);
atom = NS_NewAtom(str);
if (NS_OK == GetIdentifiersForType(atom, iid, &subType)) {
AddEventListener(aListener, iid, aFlags, subType); AddEventListener(aListener, iid, aFlags, subType);
} }
NS_IF_RELEASE(atom);
return NS_OK; return NS_OK;
} }
@ -443,38 +455,81 @@ nsresult nsEventListenerManager::RemoveEventListenerByType(nsIDOMEventListener *
PRInt32 subType; PRInt32 subType;
nsIID iid; nsIID iid;
if (NS_OK == GetIdentifiersForType(aType, iid, &subType)) { nsAutoString str("on");
nsIAtom* atom;
str.Append(aType);
atom = NS_NewAtom(str);
if (NS_OK == GetIdentifiersForType(atom, iid, &subType)) {
RemoveEventListener(aListener, iid, aFlags, subType); RemoveEventListener(aListener, iid, aFlags, subType);
} }
NS_IF_RELEASE(atom);
return NS_OK; return NS_OK;
} }
nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID) nsListenerStruct*
nsEventListenerManager::FindJSEventListener(REFNSIID aIID)
{ {
nsVoidArray *mListeners; nsVoidArray *listeners;
if (NS_OK == GetEventListeners(&mListeners, aIID)) { nsresult result = GetEventListeners(&listeners, aIID);
if (NS_SUCCEEDED(result)) {
//Run through the listeners for this IID and see if a script listener is registered //Run through the listeners for this IID and see if a script listener is registered
//If so, we're set. if (nsnull != listeners) {
if (nsnull != mListeners) {
nsListenerStruct *ls; nsListenerStruct *ls;
for (int i=0; i<mListeners->Count(); i++) { for (int i=0; i<listeners->Count(); i++) {
ls = (nsListenerStruct*)mListeners->ElementAt(i); ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) { if (ls->mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) {
return NS_OK; return ls;
} }
} }
} }
}
return nsnull;
}
nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aOwner,
nsIAtom* aName,
REFNSIID aIID,
PRBool aIsString)
{
nsIDOMEventListener* theListener = nsnull;
nsresult result = NS_OK;
nsListenerStruct *ls;
ls = FindJSEventListener(aIID);
if (nsnull == ls) {
//If we didn't find a script listener or no listeners existed create and add a new one. //If we didn't find a script listener or no listeners existed create and add a new one.
nsIDOMEventListener *mScriptListener; nsIDOMEventListener* scriptListener;
if (NS_OK == NS_NewJSEventListener(&mScriptListener, aContext, aObject)) { result = NS_NewJSEventListener(&scriptListener, aContext, aOwner);
AddEventListenerByIID(mScriptListener, aIID, NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT); if (NS_SUCCEEDED(result)) {
NS_RELEASE(mScriptListener); AddEventListenerByIID(scriptListener, aIID, NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT);
return NS_OK; NS_RELEASE(scriptListener);
ls = FindJSEventListener(aIID);
} }
} }
return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(result) && ls) {
PRInt32 flags;
nsIID iid;
result = GetIdentifiersForType(aName, iid, &flags);
if (NS_SUCCEEDED(result)) {
if (aIsString) {
ls->mHandlerIsString |= flags;
}
else {
ls->mHandlerIsString &= ~flags;
}
}
}
return result;
} }
nsresult nsresult
@ -482,28 +537,82 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext,
nsIScriptObjectOwner *aScriptObjectOwner, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName, nsIAtom *aName,
const nsString& aBody, const nsString& aBody,
REFNSIID aIID) REFNSIID aIID,
PRBool aDeferCompilation)
{ {
JSObject *scriptObject; JSObject *scriptObject;
nsresult rv; nsresult rv;
rv = aScriptObjectOwner->GetScriptObject(aContext, (void**)&scriptObject); if (!aDeferCompilation) {
if (NS_FAILED(rv)) rv = aScriptObjectOwner->GetScriptObject(aContext, (void**)&scriptObject);
return NS_ERROR_FAILURE; if (NS_FAILED(rv))
rv = aContext->CompileFunction(scriptObject, aName, aBody); return rv;
if (NS_FAILED(rv)) rv = aContext->CompileFunction(scriptObject, aName, aBody);
return NS_ERROR_FAILURE; if (NS_FAILED(rv))
return SetJSEventListener(aContext, scriptObject, aIID); return rv;
}
return SetJSEventListener(aContext, aScriptObjectOwner, aName, aIID, aDeferCompilation);
} }
nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aScriptObjectOwner, nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext,
REFNSIID aIID) nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName,
REFNSIID aIID)
{ {
JSObject *scriptObject; return SetJSEventListener(aContext, aScriptObjectOwner, aName, aIID, PR_FALSE);
if (NS_SUCCEEDED(aScriptObjectOwner->GetScriptObject(aContext, (void**)&scriptObject))) { }
return SetJSEventListener(aContext, scriptObject, aIID);
nsresult
nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
nsIDOMEvent* aDOMEvent,
PRUint32 aSubType)
{
nsresult result = NS_OK;
// If this is a script handler and we haven't yet
// compiled the event handler itself
if ((aListenerStruct->mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) &&
(aListenerStruct->mHandlerIsString & aSubType)) {
nsCOMPtr<nsIJSEventListener> jslistener = do_QueryInterface(aListenerStruct->mListener);
if (jslistener) {
nsCOMPtr<nsIScriptObjectOwner> owner;
nsCOMPtr<nsIScriptContext> scriptCX;
result = jslistener->GetEventTarget(getter_AddRefs(scriptCX), getter_AddRefs(owner));
if (NS_SUCCEEDED(result)) {
JSObject* jsobj;
result = owner->GetScriptObject(scriptCX, (void**)&jsobj);
// This should never happen for anything but content
// XXX I don't like that we have to reference content
// from here. The alternative is to store the event handler
// string on the JS object itself.
if (NS_SUCCEEDED(result)) {
nsCOMPtr<nsIContent> content = do_QueryInterface(owner);
NS_ASSERTION(content, "only content should have event handler attributes");
if (content) {
nsAutoString eventString;
if (NS_SUCCEEDED(aDOMEvent->GetType(eventString))) {
eventString.Insert("on", 0, 2);
nsCOMPtr<nsIAtom> atom = getter_AddRefs(NS_NewAtom(eventString));
nsString handlerBody;
result = content->GetAttribute(kNameSpaceID_None, atom, handlerBody);
if (NS_SUCCEEDED(result)) {
result = scriptCX->CompileFunction(jsobj, atom, handlerBody);
aListenerStruct->mHandlerIsString &= ~aSubType;
}
}
}
}
}
}
} }
return NS_ERROR_FAILURE;
if (NS_SUCCEEDED(result)) {
result = aListenerStruct->mListener->HandleEvent(aDOMEvent);
}
return result;
} }
/** /**
@ -548,7 +657,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
nsIDOMMouseListener *mMouseListener; nsIDOMMouseListener *mMouseListener;
ls = (nsListenerStruct*)mMouseListeners->ElementAt(i); ls = (nsListenerStruct*)mMouseListeners->ElementAt(i);
if (ls->mFlags & aFlags) { if (ls->mFlags & aFlags) {
if (NS_OK == ls->mListener->QueryInterface(kIDOMMouseListenerIID, (void**)&mMouseListener)) { if (NS_OK == ls->mListener->QueryInterface(kIDOMMouseListenerIID, (void**)&mMouseListener)) {
switch(aEvent->message) { switch(aEvent->message) {
@ -585,10 +694,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN: case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_BUTTON_DOWN: case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_RIGHT_BUTTON_DOWN: case NS_MOUSE_RIGHT_BUTTON_DOWN:
subType = NS_EVENT_BITS_MOUSE_MOUSEDOWN;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEDOWN) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEDOWN) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -596,6 +707,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_LEFT_BUTTON_UP: case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_UP: case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_UP: case NS_MOUSE_RIGHT_BUTTON_UP:
subType = NS_EVENT_BITS_MOUSE_MOUSEUP;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEUP) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEUP) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -603,6 +715,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_LEFT_CLICK: case NS_MOUSE_LEFT_CLICK:
case NS_MOUSE_MIDDLE_CLICK: case NS_MOUSE_MIDDLE_CLICK:
case NS_MOUSE_RIGHT_CLICK: case NS_MOUSE_RIGHT_CLICK:
subType = NS_EVENT_BITS_MOUSE_CLICK;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_CLICK) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_CLICK) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -610,16 +723,19 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_LEFT_DOUBLECLICK: case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_MIDDLE_DOUBLECLICK: case NS_MOUSE_MIDDLE_DOUBLECLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK: case NS_MOUSE_RIGHT_DOUBLECLICK:
subType = NS_EVENT_BITS_MOUSE_DBLCLICK;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_DBLCLICK) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_DBLCLICK) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_MOUSE_ENTER: case NS_MOUSE_ENTER:
subType = NS_EVENT_BITS_MOUSE_MOUSEOVER;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEOVER) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEOVER) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_MOUSE_EXIT: case NS_MOUSE_EXIT:
subType = NS_EVENT_BITS_MOUSE_MOUSEOUT;
if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEOUT) { if (ls->mSubType & NS_EVENT_BITS_MOUSE_MOUSEOUT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -628,7 +744,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -662,8 +778,10 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_MOUSE_MOVE: case NS_MOUSE_MOVE:
subType = NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE;
if (ls->mSubType & NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE) { if (ls->mSubType & NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -672,7 +790,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -709,13 +827,16 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_COMPOSITION_START: case NS_COMPOSITION_START:
subType = NS_EVENT_BITS_COMPOSITION_START;
if (ls->mSubType & NS_EVENT_BITS_COMPOSITION_START) { if (ls->mSubType & NS_EVENT_BITS_COMPOSITION_START) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_COMPOSITION_END: case NS_COMPOSITION_END:
subType = NS_EVENT_BITS_COMPOSITION_END;
if (ls->mSubType & NS_EVENT_BITS_COMPOSITION_END) { if (ls->mSubType & NS_EVENT_BITS_COMPOSITION_END) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -724,7 +845,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -754,11 +875,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = NS_EVENT_BITS_TEXT_TEXT;
if (ls->mSubType & NS_EVENT_BITS_TEXT_TEXT) { if (ls->mSubType & NS_EVENT_BITS_TEXT_TEXT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -800,18 +922,22 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_KEY_UP: case NS_KEY_UP:
subType = NS_EVENT_BITS_KEY_KEYUP;
if (ls->mSubType & NS_EVENT_BITS_KEY_KEYUP) { if (ls->mSubType & NS_EVENT_BITS_KEY_KEYUP) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_KEY_DOWN: case NS_KEY_DOWN:
subType = NS_EVENT_BITS_KEY_KEYDOWN;
if (ls->mSubType & NS_EVENT_BITS_KEY_KEYDOWN) { if (ls->mSubType & NS_EVENT_BITS_KEY_KEYDOWN) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_KEY_PRESS: case NS_KEY_PRESS:
subType = NS_EVENT_BITS_KEY_KEYPRESS;
if (ls->mSubType & NS_EVENT_BITS_KEY_KEYPRESS) { if (ls->mSubType & NS_EVENT_BITS_KEY_KEYPRESS) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -820,7 +946,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -858,13 +984,16 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_FOCUS_CONTENT: case NS_FOCUS_CONTENT:
subType = NS_EVENT_BITS_FOCUS_FOCUS;
if (ls->mSubType & NS_EVENT_BITS_FOCUS_FOCUS) { if (ls->mSubType & NS_EVENT_BITS_FOCUS_FOCUS) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_BLUR_CONTENT: case NS_BLUR_CONTENT:
subType = NS_EVENT_BITS_FOCUS_BLUR;
if (ls->mSubType & NS_EVENT_BITS_FOCUS_BLUR) { if (ls->mSubType & NS_EVENT_BITS_FOCUS_BLUR) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -873,7 +1002,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -923,28 +1052,34 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_FORM_SUBMIT: case NS_FORM_SUBMIT:
subType = NS_EVENT_BITS_FORM_SUBMIT;
if (ls->mSubType & NS_EVENT_BITS_FORM_SUBMIT) { if (ls->mSubType & NS_EVENT_BITS_FORM_SUBMIT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_FORM_RESET: case NS_FORM_RESET:
subType = NS_EVENT_BITS_FORM_RESET;
if (ls->mSubType & NS_EVENT_BITS_FORM_RESET) { if (ls->mSubType & NS_EVENT_BITS_FORM_RESET) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_FORM_CHANGE: case NS_FORM_CHANGE:
subType = NS_EVENT_BITS_FORM_CHANGE;
if (ls->mSubType & NS_EVENT_BITS_FORM_CHANGE) { if (ls->mSubType & NS_EVENT_BITS_FORM_CHANGE) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_FORM_SELECTED: case NS_FORM_SELECTED:
subType = NS_EVENT_BITS_FORM_SELECT;
if (ls->mSubType & NS_EVENT_BITS_FORM_SELECT) { if (ls->mSubType & NS_EVENT_BITS_FORM_SELECT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_FORM_INPUT: case NS_FORM_INPUT:
subType = NS_EVENT_BITS_FORM_INPUT;
if (ls->mSubType & NS_EVENT_BITS_FORM_INPUT) { if (ls->mSubType & NS_EVENT_BITS_FORM_INPUT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -953,7 +1088,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -992,13 +1127,16 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_PAGE_LOAD: case NS_PAGE_LOAD:
subType = NS_EVENT_BITS_LOAD_LOAD;
if (ls->mSubType & NS_EVENT_BITS_LOAD_LOAD) { if (ls->mSubType & NS_EVENT_BITS_LOAD_LOAD) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_PAGE_UNLOAD: case NS_PAGE_UNLOAD:
subType = NS_EVENT_BITS_LOAD_UNLOAD;
if (ls->mSubType & NS_EVENT_BITS_LOAD_UNLOAD) { if (ls->mSubType & NS_EVENT_BITS_LOAD_UNLOAD) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -1007,7 +1145,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -1036,11 +1174,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = NS_EVENT_BITS_PAINT_PAINT;
if (ls->mSubType & NS_EVENT_BITS_PAINT_PAINT) { if (ls->mSubType & NS_EVENT_BITS_PAINT_PAINT) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }
@ -1088,24 +1227,30 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_DRAGDROP_ENTER: case NS_DRAGDROP_ENTER:
subType = NS_EVENT_BITS_DRAG_ENTER;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_ENTER) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_ENTER)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
case NS_DRAGDROP_OVER: case NS_DRAGDROP_OVER:
subType = NS_EVENT_BITS_DRAG_OVER;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_OVER) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_OVER)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
case NS_DRAGDROP_EXIT: case NS_DRAGDROP_EXIT:
subType = NS_EVENT_BITS_DRAG_EXIT;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_EXIT) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_EXIT)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
case NS_DRAGDROP_DROP: case NS_DRAGDROP_DROP:
subType = NS_EVENT_BITS_DRAG_DROP;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_DROP) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_DROP)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
case NS_DRAGDROP_GESTURE: case NS_DRAGDROP_GESTURE:
subType = NS_EVENT_BITS_DRAG_GESTURE;
if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_GESTURE) if (dragStruct->mSubType & NS_EVENT_BITS_DRAG_GESTURE)
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
break; break;
@ -1113,7 +1258,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || dragStruct->mSubType == NS_EVENT_BITS_DRAG_NONE) if (correctSubType || dragStruct->mSubType == NS_EVENT_BITS_DRAG_NONE)
ret = dragStruct->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(dragStruct, *aDOMEvent, subType);
} }
} }
} }
@ -1162,28 +1307,34 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
} }
else { else {
PRBool correctSubType = PR_FALSE; PRBool correctSubType = PR_FALSE;
PRUint32 subType = 0;
switch(aEvent->message) { switch(aEvent->message) {
case NS_MENU_CREATE: case NS_MENU_CREATE:
subType = NS_EVENT_BITS_MENU_CREATE;
if (ls->mSubType & NS_EVENT_BITS_MENU_CREATE) { if (ls->mSubType & NS_EVENT_BITS_MENU_CREATE) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_MENU_DESTROY: case NS_MENU_DESTROY:
subType = NS_EVENT_BITS_MENU_DESTROY;
if (ls->mSubType & NS_EVENT_BITS_MENU_DESTROY) { if (ls->mSubType & NS_EVENT_BITS_MENU_DESTROY) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_MENU_ACTION: case NS_MENU_ACTION:
subType = NS_EVENT_BITS_MENU_ACTION;
if (ls->mSubType & NS_EVENT_BITS_MENU_ACTION) { if (ls->mSubType & NS_EVENT_BITS_MENU_ACTION) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_XUL_BROADCAST: case NS_XUL_BROADCAST:
subType = NS_EVENT_BITS_XUL_BROADCAST;
if (ls->mSubType & NS_EVENT_BITS_XUL_BROADCAST) { if (ls->mSubType & NS_EVENT_BITS_XUL_BROADCAST) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
break; break;
case NS_XUL_COMMAND_UPDATE: case NS_XUL_COMMAND_UPDATE:
subType = NS_EVENT_BITS_XUL_COMMAND_UPDATE;
if (ls->mSubType & NS_EVENT_BITS_XUL_COMMAND_UPDATE) { if (ls->mSubType & NS_EVENT_BITS_XUL_COMMAND_UPDATE) {
correctSubType = PR_TRUE; correctSubType = PR_TRUE;
} }
@ -1192,7 +1343,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break; break;
} }
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = ls->mListener->HandleEvent(*aDOMEvent); ret = HandleEventSubType(ls, *aDOMEvent, subType);
} }
} }
} }

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

@ -27,11 +27,13 @@
#include "jsapi.h" #include "jsapi.h"
class nsIDOMEvent; class nsIDOMEvent;
class nsIAtom;
typedef struct { typedef struct {
nsIDOMEventListener* mListener; nsIDOMEventListener* mListener;
PRUint8 mFlags; PRUint8 mFlags;
PRUint8 mSubType; PRUint8 mSubType;
PRUint32 mHandlerIsString;
} nsListenerStruct; } nsListenerStruct;
//Flag must live higher than all event flags in nsGUIEvent.h //Flag must live higher than all event flags in nsGUIEvent.h
@ -68,13 +70,15 @@ public:
virtual nsresult AddEventListenerByType(nsIDOMEventListener *aListener, const nsString& type, PRInt32 aFlags); virtual nsresult AddEventListenerByType(nsIDOMEventListener *aListener, const nsString& type, PRInt32 aFlags);
virtual nsresult RemoveEventListenerByType(nsIDOMEventListener *aListener, const nsString& type, PRInt32 aFlags) ; virtual nsresult RemoveEventListenerByType(nsIDOMEventListener *aListener, const nsString& type, PRInt32 aFlags) ;
virtual nsresult AddScriptEventListener(nsIScriptContext* aContext, virtual nsresult AddScriptEventListener(nsIScriptContext*aContext,
nsIScriptObjectOwner *aScriptObjectOwner, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName, nsIAtom *aName,
const nsString& aFunc, const nsString& aFunc,
const nsIID& aIID); REFNSIID aIID,
PRBool aDeferCompilation);
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext, virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aScriptObjectOwner, nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom* aName,
const nsIID& aIID); const nsIID& aIID);
@ -93,9 +97,14 @@ public:
virtual nsresult RemoveAllListeners(PRBool aScriptOnly); virtual nsresult RemoveAllListeners(PRBool aScriptOnly);
static nsresult GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aSubType);
protected: protected:
nsresult SetJSEventListener(nsIScriptContext *aContext, JSObject *aObject, REFNSIID aIID); nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
nsresult GetIdentifiersForType(const nsString& aType, nsIID& aIID, PRInt32* aSubType); nsIDOMEvent* aDOMEvent,
PRUint32 aSubType);
nsListenerStruct* FindJSEventListener(REFNSIID aIID);
nsresult SetJSEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aOwner, nsIAtom* aName, REFNSIID aIID, PRBool aIsString);
nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType); nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType);
nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType); nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType);
void ReleaseListeners(nsVoidArray** aListeners, PRBool aScriptOnly); void ReleaseListeners(nsVoidArray** aListeners, PRBool aScriptOnly);

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

@ -192,29 +192,6 @@ HTML_ATOM(noshade, "noshade")
HTML_ATOM(nowrap, "nowrap") HTML_ATOM(nowrap, "nowrap")
HTML_ATOM(object, "object") HTML_ATOM(object, "object")
HTML_ATOM(ol, "ol") HTML_ATOM(ol, "ol")
HTML_ATOM(onabort, "onabort")
HTML_ATOM(onblur, "onblur")
HTML_ATOM(onchange, "onchange")
HTML_ATOM(onselect, "onselect")
HTML_ATOM(onclick, "onclick")
HTML_ATOM(ondblclick, "ondblclick")
HTML_ATOM(ondragdrop, "ondragdrop")
HTML_ATOM(onerror, "onerror")
HTML_ATOM(onfocus, "onfocus")
HTML_ATOM(oninput, "oninput")
HTML_ATOM(onkeydown, "onkeydown")
HTML_ATOM(onkeypress, "onkeypress")
HTML_ATOM(onkeyup, "onkeyup")
HTML_ATOM(onload, "onload")
HTML_ATOM(onmousedown, "onmousedown")
HTML_ATOM(onmousemove, "onmousemove")
HTML_ATOM(onmouseover, "onmouseover")
HTML_ATOM(onmouseout, "onmouseout")
HTML_ATOM(onmouseup, "onmouseup")
HTML_ATOM(onpaint, "onpaint")
HTML_ATOM(onreset, "onreset")
HTML_ATOM(onsubmit, "onsubmit")
HTML_ATOM(onunload, "onunload")
HTML_ATOM(option, "option") HTML_ATOM(option, "option")
HTML_ATOM(overflow, "overflow") HTML_ATOM(overflow, "overflow")
HTML_ATOM(p, "p") HTML_ATOM(p, "p")

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

@ -61,6 +61,7 @@
#include "nsIHTMLContentContainer.h" #include "nsIHTMLContentContainer.h"
#include "nsHTMLParts.h" #include "nsHTMLParts.h"
#include "nsString.h" #include "nsString.h"
#include "nsLayoutAtoms.h"
#include "nsHTMLAtoms.h" #include "nsHTMLAtoms.h"
#include "nsDOMEventsIIDs.h" #include "nsDOMEventsIIDs.h"
#include "nsIEventStateManager.h" #include "nsIEventStateManager.h"
@ -632,36 +633,36 @@ nsGenericHTMLElement::SetAttribute(PRInt32 aNameSpaceID,
} }
else { else {
// Check for event handlers // Check for event handlers
if ((nsHTMLAtoms::onclick == aAttribute) || if ((nsLayoutAtoms::onclick == aAttribute) ||
(nsHTMLAtoms::ondblclick == aAttribute) || (nsLayoutAtoms::ondblclick == aAttribute) ||
(nsHTMLAtoms::onmousedown == aAttribute) || (nsLayoutAtoms::onmousedown == aAttribute) ||
(nsHTMLAtoms::onmouseup == aAttribute) || (nsLayoutAtoms::onmouseup == aAttribute) ||
(nsHTMLAtoms::onmouseover == aAttribute) || (nsLayoutAtoms::onmouseover == aAttribute) ||
(nsHTMLAtoms::onmouseout == aAttribute)) (nsLayoutAtoms::onmouseout == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMMouseListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMMouseListenerIID);
else if ((nsHTMLAtoms::onkeydown == aAttribute) || else if ((nsLayoutAtoms::onkeydown == aAttribute) ||
(nsHTMLAtoms::onkeyup == aAttribute) || (nsLayoutAtoms::onkeyup == aAttribute) ||
(nsHTMLAtoms::onkeypress == aAttribute)) (nsLayoutAtoms::onkeypress == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMKeyListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMKeyListenerIID);
else if (nsHTMLAtoms::onmousemove == aAttribute) else if (nsLayoutAtoms::onmousemove == aAttribute)
AddScriptEventListener(aAttribute, aValue, kIDOMMouseMotionListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMMouseMotionListenerIID);
else if (nsHTMLAtoms::onload == aAttribute) else if (nsLayoutAtoms::onload == aAttribute)
AddScriptEventListener(nsHTMLAtoms::onload, aValue, kIDOMLoadListenerIID); AddScriptEventListener(nsLayoutAtoms::onload, aValue, kIDOMLoadListenerIID);
else if ((nsHTMLAtoms::onunload == aAttribute) || else if ((nsLayoutAtoms::onunload == aAttribute) ||
(nsHTMLAtoms::onabort == aAttribute) || (nsLayoutAtoms::onabort == aAttribute) ||
(nsHTMLAtoms::onerror == aAttribute)) (nsLayoutAtoms::onerror == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMLoadListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMLoadListenerIID);
else if ((nsHTMLAtoms::onfocus == aAttribute) || else if ((nsLayoutAtoms::onfocus == aAttribute) ||
(nsHTMLAtoms::onblur == aAttribute)) (nsLayoutAtoms::onblur == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMFocusListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMFocusListenerIID);
else if ((nsHTMLAtoms::onsubmit == aAttribute) || else if ((nsLayoutAtoms::onsubmit == aAttribute) ||
(nsHTMLAtoms::onreset == aAttribute) || (nsLayoutAtoms::onreset == aAttribute) ||
(nsHTMLAtoms::onchange == aAttribute) || (nsLayoutAtoms::onchange == aAttribute) ||
(nsHTMLAtoms::onselect == aAttribute)) (nsLayoutAtoms::onselect == aAttribute))
AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID);
else if (nsHTMLAtoms::onpaint == aAttribute) else if (nsLayoutAtoms::onpaint == aAttribute)
AddScriptEventListener(aAttribute, aValue, kIDOMPaintListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMPaintListenerIID);
else if (nsHTMLAtoms::oninput == aAttribute) else if (nsLayoutAtoms::oninput == aAttribute)
AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID); AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID);
} }

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

@ -2495,6 +2495,52 @@ nsHTMLDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject
return res; return res;
} }
PRBool
nsHTMLDocument::Resolve(JSContext *aContext, jsval aID)
{
nsCOMPtr<nsIDOMElement> element;
char* str = JS_GetStringBytes(JS_ValueToString(aContext, aID));
nsAutoString name(str);
nsresult result = NS_OK;
PRBool ret = PR_TRUE;
result = NamedItem(name, getter_AddRefs(element));
if (NS_SUCCEEDED(result) && element) {
nsCOMPtr<nsIScriptObjectOwner> owner = do_QueryInterface(element);
if (owner) {
nsCOMPtr<nsIScriptContext> scriptContext;
nsCOMPtr<nsIScriptContextOwner> contextOwner;
contextOwner = getter_AddRefs(GetScriptContextOwner());
if (contextOwner) {
result = contextOwner->GetScriptContext(getter_AddRefs(scriptContext));
}
if (!scriptContext) {
scriptContext = dont_AddRef((nsIScriptContext*)JS_GetContextPrivate(aContext));
}
JSObject* obj;
if (scriptContext) {
result = owner->GetScriptObject(scriptContext, (void**)&obj);
if (NS_SUCCEEDED(result) && (nsnull != obj)) {
JSObject* myObj;
result = GetScriptObject(scriptContext, (void**)&myObj);
ret = ::JS_DefineProperty(aContext, myObj,
str, OBJECT_TO_JSVAL(obj),
nsnull, nsnull, 0);
}
}
}
}
if (NS_FAILED(result)) {
ret = PR_FALSE;
}
return ret;
}
//---------------------------- //----------------------------
static PRBool IsInline(eHTMLTags aTag) static PRBool IsInline(eHTMLTags aTag)

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

@ -124,6 +124,9 @@ public:
// From nsIScriptObjectOwner interface, implemented by nsDocument // From nsIScriptObjectOwner interface, implemented by nsDocument
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
// From nsJSScriptObject interface, implemented by nsDocument
virtual PRBool Resolve(JSContext *aContext, jsval aID);
/** /**
* Finds text in content * Finds text in content