зеркало из https://github.com/mozilla/gecko-dev.git
Hooking up window element to event chain and adding in support for a few more event types.
This commit is contained in:
Родитель
2c65aece90
Коммит
f85ed9ce71
|
@ -29,9 +29,13 @@
|
|||
#include "nsEventListenerManager.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptContextOwner.h"
|
||||
#include "nsIScriptEventListener.h"
|
||||
#include "nsDOMEvent.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsIEventStateManager.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseMotionListener.h"
|
||||
#include "nsContentList.h"
|
||||
|
||||
#include "nsCSSPropIDs.h"
|
||||
|
@ -57,14 +61,17 @@ static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
|||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventCapturerIID, NS_IDOMEVENTCAPTURER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
|
||||
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIPostDataIID, NS_IPOSTDATA_IID);
|
||||
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
|
||||
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewPostData(PRBool aIsFile, char* aData,
|
||||
nsIPostData** aInstancePtrResult)
|
||||
|
@ -824,24 +831,19 @@ nsresult nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrRe
|
|||
if (nsnull != mListenerManager) {
|
||||
return mListenerManager->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult);;
|
||||
}
|
||||
else {
|
||||
nsIEventListenerManager* l = new nsEventListenerManager();
|
||||
|
||||
if (nsnull == l) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
if (NS_OK == l->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult)) {
|
||||
mListenerManager = l;
|
||||
NS_ADDREF(mListenerManager);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_OK == NS_NewEventListenerManager(aInstancePtrResult)) {
|
||||
mListenerManager = *aInstancePtrResult;
|
||||
NS_ADDREF(mListenerManager);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult)
|
||||
{
|
||||
return NS_NewEventListenerManager(aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsresult nsDocument::HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
|
@ -869,6 +871,13 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext& aPresContext,
|
|||
}
|
||||
|
||||
//Bubbling stage
|
||||
if (DOM_EVENT_CAPTURE != aFlags && nsnull != mScriptContextOwner) {
|
||||
nsIScriptGlobalObject* mGlobal;
|
||||
if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&mGlobal)) {
|
||||
mGlobal->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, DOM_EVENT_BUBBLE, aEventStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/*Need to go to window here*/
|
||||
|
||||
if (DOM_EVENT_INIT == aFlags) {
|
||||
|
@ -931,6 +940,111 @@ nsresult nsDocument::ReleaseEvent(nsIDOMEventListener *aListener)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::AddProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::GetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
if (JS_TypeOfValue(aContext, *aVp) == JSTYPE_FUNCTION && JSVAL_IS_STRING(aID)) {
|
||||
nsAutoString mPropName, mPrefix;
|
||||
mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
|
||||
mPrefix.SetString(mPropName, 2);
|
||||
if (mPrefix == "on") {
|
||||
if (mPropName == "onmousedown" || mPropName == "onmouseup" || mPropName == "onclick" ||
|
||||
mPropName == "onmouseover" || mPropName == "onmouseout") {
|
||||
if (NS_OK != SetScriptEventListener(aContext, kIDOMMouseListenerIID)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
else if (mPropName == "onkeydown" || mPropName == "onkeyup" || mPropName == "onkeypress" ) {
|
||||
if (NS_OK != SetScriptEventListener(aContext, kIDOMKeyListenerIID)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
else if (mPropName == "onmousemove" ) {
|
||||
if (NS_OK != SetScriptEventListener(aContext, kIDOMMouseMotionListenerIID)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::EnumerateProperty(JSContext *aContext)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::Resolve(JSContext *aContext, jsval aID)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::Convert(JSContext *aContext, jsval aID)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void nsDocument::Finalize(JSContext *aContext)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsDocument::SetScriptEventListener(JSContext *aContext, REFNSIID aListenerTypeIID)
|
||||
{
|
||||
//First get the mScriptObject or make one if we don't have one.
|
||||
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
GetScriptObject(mScriptCX, &mScriptObject);
|
||||
}
|
||||
|
||||
if (nsnull != mScriptObject) {
|
||||
nsIEventListenerManager *mManager = nsnull;
|
||||
nsVoidArray *mListeners;
|
||||
|
||||
if (NS_OK == GetListenerManager(&mManager) &&
|
||||
NS_OK == mManager->GetEventListeners(&mListeners, aListenerTypeIID)) {
|
||||
//Run through the listeners for this IID and see if a script listener is registered
|
||||
//If so, we're set.
|
||||
if (nsnull != mListeners) {
|
||||
nsIScriptEventListener *mScriptListener;
|
||||
nsIDOMEventListener *mEventListener;
|
||||
for (int i=0; i<mListeners->Count(); i++) {
|
||||
mEventListener = (nsIDOMEventListener*)mListeners->ElementAt(i);
|
||||
if (NS_OK == mEventListener->QueryInterface(kIScriptEventListenerIID, (void**)&mScriptListener)) {
|
||||
NS_RELEASE(mScriptListener);
|
||||
NS_RELEASE(mManager);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
//If we didn't find a script listener or no listeners existed create and add a new one.
|
||||
nsIDOMEventListener *mScriptListener;
|
||||
if (NS_OK == NS_NewScriptEventListener(&mScriptListener, mScriptCX, mScriptObject)) {
|
||||
mManager->AddEventListener(mScriptListener, aListenerTypeIID);
|
||||
NS_RELEASE(mScriptListener);
|
||||
NS_RELEASE(mManager);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
NS_IF_RELEASE(mManager);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Selection Object
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "nsIScriptContextOwner.h"
|
||||
#include "nsIDOMEventCapturer.h"
|
||||
#include "nsXIFConverter.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
|
||||
class nsISelection;
|
||||
class nsIEventListenerManager;
|
||||
|
@ -49,7 +50,8 @@ protected:
|
|||
|
||||
|
||||
// Base class for our document implementations
|
||||
class nsDocument : public nsIDocument, public nsIDOMDocument, public nsIScriptObjectOwner, public nsIDOMEventCapturer {
|
||||
class nsDocument : public nsIDocument, public nsIDOMDocument, public nsIScriptObjectOwner,
|
||||
public nsIDOMEventCapturer, public nsIJSScriptObject {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -233,8 +235,7 @@ public:
|
|||
NS_IMETHOD ReleaseEvent(nsIDOMEventListener *aListener);
|
||||
NS_IMETHOD AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
NS_IMETHOD RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
|
||||
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
|
||||
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
|
@ -242,6 +243,15 @@ public:
|
|||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
// nsIJSScriptObject interface
|
||||
virtual PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool GetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool SetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool EnumerateProperty(JSContext *aContext);
|
||||
virtual PRBool Resolve(JSContext *aContext, jsval aID);
|
||||
virtual PRBool Convert(JSContext *aContext, jsval aID);
|
||||
virtual void Finalize(JSContext *aContext);
|
||||
|
||||
virtual PRBool IsInRange(nsIContent *aStartContent, nsIContent* aEndContent, nsIContent* aContent) const;
|
||||
virtual PRBool IsBefore(nsIContent *aNewContent, nsIContent* aCurrentContent) const;
|
||||
|
@ -255,6 +265,8 @@ protected:
|
|||
|
||||
protected:
|
||||
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); // subclass hook
|
||||
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
nsresult SetScriptEventListener(JSContext *aContext, REFNSIID aListenerTypeIID);
|
||||
|
||||
nsDocument();
|
||||
virtual ~nsDocument();
|
||||
|
|
|
@ -86,4 +86,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
|
||||
#endif // nsIEventListenerManager_h__
|
||||
|
|
|
@ -28,7 +28,7 @@ static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
|
|||
static char* mEventNames[] = {
|
||||
"onmousedown", "onmouseup", "onclick", "ondblclick", "onmouseover", "onmouseout",
|
||||
"onmousemove", "onkeydown", "onkeyup", "onkeypress", "onfocus", "onblur",
|
||||
"onload", "onabort", "onerror"
|
||||
"onload", "onunload", "onabort", "onerror"
|
||||
};
|
||||
|
||||
nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
|
||||
|
@ -287,6 +287,10 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
|
|||
case NS_MOUSE_RIGHT_BUTTON_UP:
|
||||
return mEventNames[eDOMEvents_mouseup];
|
||||
break;
|
||||
case NS_MOUSE_LEFT_CLICK:
|
||||
case NS_MOUSE_RIGHT_CLICK:
|
||||
return mEventNames[eDOMEvents_click];
|
||||
break;
|
||||
case NS_MOUSE_LEFT_DOUBLECLICK:
|
||||
case NS_MOUSE_RIGHT_DOUBLECLICK:
|
||||
return mEventNames[eDOMEvents_dblclick];
|
||||
|
@ -306,6 +310,25 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
|
|||
case NS_KEY_DOWN:
|
||||
return mEventNames[eDOMEvents_keydown];
|
||||
break;
|
||||
case NS_GOTFOCUS:
|
||||
return mEventNames[eDOMEvents_focus];
|
||||
break;
|
||||
case NS_LOSTFOCUS:
|
||||
return mEventNames[eDOMEvents_blur];
|
||||
break;
|
||||
case NS_PAGE_LOAD:
|
||||
case NS_IMAGE_LOAD:
|
||||
return mEventNames[eDOMEvents_load];
|
||||
break;
|
||||
case NS_PAGE_UNLOAD:
|
||||
return mEventNames[eDOMEvents_unload];
|
||||
break;
|
||||
case NS_IMAGE_ABORT:
|
||||
return mEventNames[eDOMEvents_abort];
|
||||
break;
|
||||
case NS_IMAGE_ERROR:
|
||||
return mEventNames[eDOMEvents_error];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
enum nsDOMEvents {
|
||||
eDOMEvents_mousedown=0, eDOMEvents_mouseup=1, eDOMEvents_click=2, eDOMEvents_dblclick=3, eDOMEvents_mouseover=4, eDOMEvents_mouseout=5,
|
||||
eDOMEvents_mousemove=6, eDOMEvents_keydown=7, eDOMEvents_keyup=8, eDOMEvents_keypress=9, eDOMEvents_focus=10, eDOMEvents_blur=11,
|
||||
eDOMEvents_load=12, eDOMEvents_abort=13, eDOMEvents_error=14
|
||||
eDOMEvents_load=12, eDOMEvents_unload=13, eDOMEvents_abort=14, eDOMEvents_error=15
|
||||
};
|
||||
|
||||
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent);
|
||||
|
|
|
@ -331,3 +331,17 @@ nsresult nsEventListenerManager::ReleaseEvent(nsIDOMEventListener *aListener)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult)
|
||||
{
|
||||
nsIEventListenerManager* l = new nsEventListenerManager();
|
||||
|
||||
if (nsnull == l) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (NS_OK == l->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -29,9 +29,13 @@
|
|||
#include "nsEventListenerManager.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptContextOwner.h"
|
||||
#include "nsIScriptEventListener.h"
|
||||
#include "nsDOMEvent.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsIEventStateManager.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMKeyListener.h"
|
||||
#include "nsIDOMMouseMotionListener.h"
|
||||
#include "nsContentList.h"
|
||||
|
||||
#include "nsCSSPropIDs.h"
|
||||
|
@ -57,14 +61,17 @@ static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
|||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventCapturerIID, NS_IDOMEVENTCAPTURER_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
|
||||
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
|
||||
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIPostDataIID, NS_IPOSTDATA_IID);
|
||||
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
|
||||
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewPostData(PRBool aIsFile, char* aData,
|
||||
nsIPostData** aInstancePtrResult)
|
||||
|
@ -824,24 +831,19 @@ nsresult nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrRe
|
|||
if (nsnull != mListenerManager) {
|
||||
return mListenerManager->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult);;
|
||||
}
|
||||
else {
|
||||
nsIEventListenerManager* l = new nsEventListenerManager();
|
||||
|
||||
if (nsnull == l) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
if (NS_OK == l->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult)) {
|
||||
mListenerManager = l;
|
||||
NS_ADDREF(mListenerManager);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_OK == NS_NewEventListenerManager(aInstancePtrResult)) {
|
||||
mListenerManager = *aInstancePtrResult;
|
||||
NS_ADDREF(mListenerManager);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult)
|
||||
{
|
||||
return NS_NewEventListenerManager(aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsresult nsDocument::HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
|
@ -869,6 +871,13 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext& aPresContext,
|
|||
}
|
||||
|
||||
//Bubbling stage
|
||||
if (DOM_EVENT_CAPTURE != aFlags && nsnull != mScriptContextOwner) {
|
||||
nsIScriptGlobalObject* mGlobal;
|
||||
if (NS_OK == mScriptContextOwner->GetScriptGlobalObject(&mGlobal)) {
|
||||
mGlobal->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, DOM_EVENT_BUBBLE, aEventStatus);
|
||||
}
|
||||
}
|
||||
|
||||
/*Need to go to window here*/
|
||||
|
||||
if (DOM_EVENT_INIT == aFlags) {
|
||||
|
@ -931,6 +940,111 @@ nsresult nsDocument::ReleaseEvent(nsIDOMEventListener *aListener)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::AddProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::GetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
if (JS_TypeOfValue(aContext, *aVp) == JSTYPE_FUNCTION && JSVAL_IS_STRING(aID)) {
|
||||
nsAutoString mPropName, mPrefix;
|
||||
mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
|
||||
mPrefix.SetString(mPropName, 2);
|
||||
if (mPrefix == "on") {
|
||||
if (mPropName == "onmousedown" || mPropName == "onmouseup" || mPropName == "onclick" ||
|
||||
mPropName == "onmouseover" || mPropName == "onmouseout") {
|
||||
if (NS_OK != SetScriptEventListener(aContext, kIDOMMouseListenerIID)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
else if (mPropName == "onkeydown" || mPropName == "onkeyup" || mPropName == "onkeypress" ) {
|
||||
if (NS_OK != SetScriptEventListener(aContext, kIDOMKeyListenerIID)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
else if (mPropName == "onmousemove" ) {
|
||||
if (NS_OK != SetScriptEventListener(aContext, kIDOMMouseMotionListenerIID)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::EnumerateProperty(JSContext *aContext)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::Resolve(JSContext *aContext, jsval aID)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsDocument::Convert(JSContext *aContext, jsval aID)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void nsDocument::Finalize(JSContext *aContext)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsDocument::SetScriptEventListener(JSContext *aContext, REFNSIID aListenerTypeIID)
|
||||
{
|
||||
//First get the mScriptObject or make one if we don't have one.
|
||||
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
GetScriptObject(mScriptCX, &mScriptObject);
|
||||
}
|
||||
|
||||
if (nsnull != mScriptObject) {
|
||||
nsIEventListenerManager *mManager = nsnull;
|
||||
nsVoidArray *mListeners;
|
||||
|
||||
if (NS_OK == GetListenerManager(&mManager) &&
|
||||
NS_OK == mManager->GetEventListeners(&mListeners, aListenerTypeIID)) {
|
||||
//Run through the listeners for this IID and see if a script listener is registered
|
||||
//If so, we're set.
|
||||
if (nsnull != mListeners) {
|
||||
nsIScriptEventListener *mScriptListener;
|
||||
nsIDOMEventListener *mEventListener;
|
||||
for (int i=0; i<mListeners->Count(); i++) {
|
||||
mEventListener = (nsIDOMEventListener*)mListeners->ElementAt(i);
|
||||
if (NS_OK == mEventListener->QueryInterface(kIScriptEventListenerIID, (void**)&mScriptListener)) {
|
||||
NS_RELEASE(mScriptListener);
|
||||
NS_RELEASE(mManager);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
//If we didn't find a script listener or no listeners existed create and add a new one.
|
||||
nsIDOMEventListener *mScriptListener;
|
||||
if (NS_OK == NS_NewScriptEventListener(&mScriptListener, mScriptCX, mScriptObject)) {
|
||||
mManager->AddEventListener(mScriptListener, aListenerTypeIID);
|
||||
NS_RELEASE(mScriptListener);
|
||||
NS_RELEASE(mManager);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
NS_IF_RELEASE(mManager);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Selection Object
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "nsIScriptContextOwner.h"
|
||||
#include "nsIDOMEventCapturer.h"
|
||||
#include "nsXIFConverter.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
|
||||
class nsISelection;
|
||||
class nsIEventListenerManager;
|
||||
|
@ -49,7 +50,8 @@ protected:
|
|||
|
||||
|
||||
// Base class for our document implementations
|
||||
class nsDocument : public nsIDocument, public nsIDOMDocument, public nsIScriptObjectOwner, public nsIDOMEventCapturer {
|
||||
class nsDocument : public nsIDocument, public nsIDOMDocument, public nsIScriptObjectOwner,
|
||||
public nsIDOMEventCapturer, public nsIJSScriptObject {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -233,8 +235,7 @@ public:
|
|||
NS_IMETHOD ReleaseEvent(nsIDOMEventListener *aListener);
|
||||
NS_IMETHOD AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
NS_IMETHOD RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
|
||||
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
|
||||
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
|
@ -242,6 +243,15 @@ public:
|
|||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
// nsIJSScriptObject interface
|
||||
virtual PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool GetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool SetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool EnumerateProperty(JSContext *aContext);
|
||||
virtual PRBool Resolve(JSContext *aContext, jsval aID);
|
||||
virtual PRBool Convert(JSContext *aContext, jsval aID);
|
||||
virtual void Finalize(JSContext *aContext);
|
||||
|
||||
virtual PRBool IsInRange(nsIContent *aStartContent, nsIContent* aEndContent, nsIContent* aContent) const;
|
||||
virtual PRBool IsBefore(nsIContent *aNewContent, nsIContent* aCurrentContent) const;
|
||||
|
@ -255,6 +265,8 @@ protected:
|
|||
|
||||
protected:
|
||||
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); // subclass hook
|
||||
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
nsresult SetScriptEventListener(JSContext *aContext, REFNSIID aListenerTypeIID);
|
||||
|
||||
nsDocument();
|
||||
virtual ~nsDocument();
|
||||
|
|
|
@ -86,4 +86,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
|
||||
#endif // nsIEventListenerManager_h__
|
||||
|
|
|
@ -28,7 +28,7 @@ static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
|
|||
static char* mEventNames[] = {
|
||||
"onmousedown", "onmouseup", "onclick", "ondblclick", "onmouseover", "onmouseout",
|
||||
"onmousemove", "onkeydown", "onkeyup", "onkeypress", "onfocus", "onblur",
|
||||
"onload", "onabort", "onerror"
|
||||
"onload", "onunload", "onabort", "onerror"
|
||||
};
|
||||
|
||||
nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
|
||||
|
@ -287,6 +287,10 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
|
|||
case NS_MOUSE_RIGHT_BUTTON_UP:
|
||||
return mEventNames[eDOMEvents_mouseup];
|
||||
break;
|
||||
case NS_MOUSE_LEFT_CLICK:
|
||||
case NS_MOUSE_RIGHT_CLICK:
|
||||
return mEventNames[eDOMEvents_click];
|
||||
break;
|
||||
case NS_MOUSE_LEFT_DOUBLECLICK:
|
||||
case NS_MOUSE_RIGHT_DOUBLECLICK:
|
||||
return mEventNames[eDOMEvents_dblclick];
|
||||
|
@ -306,6 +310,25 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
|
|||
case NS_KEY_DOWN:
|
||||
return mEventNames[eDOMEvents_keydown];
|
||||
break;
|
||||
case NS_GOTFOCUS:
|
||||
return mEventNames[eDOMEvents_focus];
|
||||
break;
|
||||
case NS_LOSTFOCUS:
|
||||
return mEventNames[eDOMEvents_blur];
|
||||
break;
|
||||
case NS_PAGE_LOAD:
|
||||
case NS_IMAGE_LOAD:
|
||||
return mEventNames[eDOMEvents_load];
|
||||
break;
|
||||
case NS_PAGE_UNLOAD:
|
||||
return mEventNames[eDOMEvents_unload];
|
||||
break;
|
||||
case NS_IMAGE_ABORT:
|
||||
return mEventNames[eDOMEvents_abort];
|
||||
break;
|
||||
case NS_IMAGE_ERROR:
|
||||
return mEventNames[eDOMEvents_error];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
enum nsDOMEvents {
|
||||
eDOMEvents_mousedown=0, eDOMEvents_mouseup=1, eDOMEvents_click=2, eDOMEvents_dblclick=3, eDOMEvents_mouseover=4, eDOMEvents_mouseout=5,
|
||||
eDOMEvents_mousemove=6, eDOMEvents_keydown=7, eDOMEvents_keyup=8, eDOMEvents_keypress=9, eDOMEvents_focus=10, eDOMEvents_blur=11,
|
||||
eDOMEvents_load=12, eDOMEvents_abort=13, eDOMEvents_error=14
|
||||
eDOMEvents_load=12, eDOMEvents_unload=13, eDOMEvents_abort=14, eDOMEvents_error=15
|
||||
};
|
||||
|
||||
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent);
|
||||
|
|
|
@ -331,3 +331,17 @@ nsresult nsEventListenerManager::ReleaseEvent(nsIDOMEventListener *aListener)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult)
|
||||
{
|
||||
nsIEventListenerManager* l = new nsEventListenerManager();
|
||||
|
||||
if (nsnull == l) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (NS_OK == l->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -587,23 +587,19 @@ nsresult nsHTMLContent::GetListenerManager(nsIEventListenerManager **aInstancePt
|
|||
if (nsnull != mListenerManager) {
|
||||
return mListenerManager->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult);;
|
||||
}
|
||||
else {
|
||||
nsIEventListenerManager* l = new nsEventListenerManager();
|
||||
|
||||
if (nsnull == l) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (NS_OK == l->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult)) {
|
||||
mListenerManager = l;
|
||||
NS_ADDREF(mListenerManager);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
if (NS_OK == NS_NewEventListenerManager(aInstancePtrResult)) {
|
||||
mListenerManager = *aInstancePtrResult;
|
||||
NS_ADDREF(mListenerManager);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsHTMLContent::GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult)
|
||||
{
|
||||
return NS_NewEventListenerManager(aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsresult nsHTMLContent::AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID)
|
||||
{
|
||||
nsIEventListenerManager *mManager;
|
||||
|
@ -652,7 +648,7 @@ nsresult nsHTMLContent::HandleDOMEvent(nsIPresContext& aPresContext,
|
|||
}
|
||||
|
||||
//Bubbling stage
|
||||
if (mParent != nsnull) {
|
||||
if (DOM_EVENT_CAPTURE != aFlags && mParent != nsnull) {
|
||||
mRet = mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, DOM_EVENT_BUBBLE, aEventStatus);
|
||||
}
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ public:
|
|||
// nsIDOMEventReceiver interface
|
||||
NS_IMETHOD AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
NS_IMETHOD RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
|
|
Загрузка…
Ссылка в новой задаче