diff --git a/mozilla/content/events/public/nsIEventListenerManager.h b/mozilla/content/events/public/nsIEventListenerManager.h index f85f75d8a77..295e079287f 100644 --- a/mozilla/content/events/public/nsIEventListenerManager.h +++ b/mozilla/content/events/public/nsIEventListenerManager.h @@ -44,7 +44,7 @@ public: * @param */ - virtual nsresult GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID) = 0; + virtual nsresult GetEventListeners(nsVoidArray **aListeners, const nsIID& aIID) = 0; /** * Sets events listeners of all types. diff --git a/mozilla/content/events/public/nsIEventStateManager.h b/mozilla/content/events/public/nsIEventStateManager.h index 03489f17164..cb6d57e54c1 100644 --- a/mozilla/content/events/public/nsIEventStateManager.h +++ b/mozilla/content/events/public/nsIEventStateManager.h @@ -22,6 +22,7 @@ #include "nsGUIEvent.h" #include "nsISupports.h" #include "nsVoidArray.h" +#include "nsIContent.h" class nsIPresContext; class nsIDOMEventState; @@ -53,6 +54,10 @@ public: NS_IMETHOD SetEventTarget(nsISupports *aSupports) = 0; + + NS_IMETHOD GetLastMouseOverContent(nsIContent **aContent) = 0; + NS_IMETHOD SetLastMouseOverContent(nsIContent *aContent) = 0; + }; #endif // nsIEventStateManager_h__ diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index 866ae23846b..8350b106f76 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -21,12 +21,28 @@ static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID); -static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID); +static NS_DEFINE_IID(kIDOMNSEventIID, NS_IDOMNSEVENT_IID); -nsDOMEvent::nsDOMEvent() { + +enum mEventEnum { + onmousedown=0, onmouseup=1, onclick=2, ondblclick=3, onmouseover=4, onmouseout=5, + onmousemove=6, onkeydown=7, onkeyup=8, onkeypress=9, onfocus=10, onblur=11, + onload=12, onabort=13, onerror=14 +}; + +static char* mEventNames[] = { + "onmousedown", "onmouseup", "onclick", "ondblclick", "onmouseover", "onmouseout", + "onmousemove", "onkeydown", "onkeyup", "onkeypress", "onfocus", "onblur", + "onload", "onabort", "onerror" +}; + +nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext) { + kPresContext = aPresContext; + NS_ADDREF(kPresContext); } nsDOMEvent::~nsDOMEvent() { + NS_RELEASE(kPresContext); } NS_IMPL_ADDREF(nsDOMEvent) @@ -44,8 +60,8 @@ nsresult nsDOMEvent::QueryInterface(const nsIID& aIID, AddRef(); return NS_OK; } - if (aIID.Equals(kINSEventIID)) { - *aInstancePtrResult = (void*) ((nsINSEvent*)this); + if (aIID.Equals(kIDOMNSEventIID)) { + *aInstancePtrResult = (void*) ((nsIDOMNSEvent*)this); AddRef(); return NS_OK; } @@ -54,6 +70,18 @@ nsresult nsDOMEvent::QueryInterface(const nsIID& aIID, // nsIDOMEventInterface NS_METHOD nsDOMEvent::GetType(nsString& aType) +{ + const char* mName = GetEventName(kEvent->message); + + if (nsnull != mName) { + aType = nsString(mName); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +NS_METHOD nsDOMEvent::SetType(const nsString& aType) { return NS_ERROR_NOT_IMPLEMENTED; } @@ -63,64 +91,112 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) return kTarget->QueryInterface(kIDOMNodeIID, (void**)aTarget); } -NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX) +NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY) +NS_METHOD nsDOMEvent::GetScreenX(PRInt32* aScreenX) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX) -{ - //XXX these are not client coords yet - aX = kEvent->point.x; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY) -{ - //XXX these are not client coords yet - aY = kEvent->point.y; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown) -{ - aIsDown = ((nsInputEvent*)kEvent)->isAlt; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown) -{ - aIsDown = ((nsInputEvent*)kEvent)->isControl; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown) -{ - aIsDown = ((nsInputEvent*)kEvent)->isShift; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown) -{ - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode) +NS_METHOD nsDOMEvent::SetScreenX(PRInt32 aScreenX) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode) +NS_METHOD nsDOMEvent::GetScreenY(PRInt32* aScreenY) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::SetScreenY(PRInt32 aScreenY) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetClientX(PRInt32* aClientX) +{ + *aClientX = NS_TO_INT_ROUND(kEvent->point.x * kPresContext->GetTwipsToPixels()); + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetClientX(PRInt32 aClientX) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetClientY(PRInt32* aClientY) +{ + *aClientY = NS_TO_INT_ROUND(kEvent->point.y * kPresContext->GetTwipsToPixels()); + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetClientY(PRInt32 aClientY) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetAltKey(PRBool* aIsDown) +{ + *aIsDown = ((nsInputEvent*)kEvent)->isAlt; + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetAltKey(PRBool aAltKey) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetCtrlKey(PRBool* aIsDown) +{ + *aIsDown = ((nsInputEvent*)kEvent)->isControl; + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetCtrlKey(PRBool aCtrlKey) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetShiftKey(PRBool* aIsDown) +{ + *aIsDown = ((nsInputEvent*)kEvent)->isShift; + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetShiftKey(PRBool aShiftKey) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetMetaKey(PRBool* aIsDown) +{ + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetMetaKey(PRBool aMetaKey) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetCharCode(PRUint32* aCharCode) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::SetCharCode(PRUint32 aCharCode) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetKeyCode(PRUint32* aKeyCode) { switch (kEvent->message) { case NS_KEY_UP: case NS_KEY_DOWN: - aKeyCode = ((nsKeyEvent*)kEvent)->keyCode; + *aKeyCode = ((nsKeyEvent*)kEvent)->keyCode; break; default: return NS_ERROR_FAILURE; @@ -128,22 +204,27 @@ NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode) return NS_OK; } -NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton) +NS_METHOD nsDOMEvent::SetKeyCode(PRUint32 aKeyCode) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetButton(PRUint32* aButton) { switch (kEvent->message) { case NS_MOUSE_LEFT_BUTTON_UP: case NS_MOUSE_LEFT_BUTTON_DOWN: case NS_MOUSE_LEFT_DOUBLECLICK: - aButton = 1; + *aButton = 1; break; case NS_MOUSE_MIDDLE_BUTTON_UP: case NS_MOUSE_MIDDLE_BUTTON_DOWN: - aButton = 2; + *aButton = 2; break; case NS_MOUSE_RIGHT_BUTTON_UP: case NS_MOUSE_RIGHT_BUTTON_DOWN: case NS_MOUSE_RIGHT_DOUBLECLICK: - aButton = 3; + *aButton = 3; break; default: return NS_ERROR_FAILURE; @@ -151,13 +232,28 @@ NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton) return NS_OK; } -// nsINSEventInterface -NS_METHOD nsDOMEvent::GetLayerX(PRInt32& aX) +NS_METHOD nsDOMEvent::SetButton(PRUint32 aButton) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY) +// nsINSEventInterface +NS_METHOD nsDOMEvent::GetLayerX(PRInt32* aLayerX) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::SetLayerX(PRInt32 aLayerX) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetLayerY(PRInt32* aLayerY) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::SetLayerY(PRInt32 aLayerY) { return NS_ERROR_NOT_IMPLEMENTED; } @@ -173,3 +269,41 @@ NS_METHOD nsDOMEvent::SetEventTarget(nsISupports *aTarget) kTarget = aTarget; return NS_OK; } + +const char* nsDOMEvent::GetEventName(PRUint32 aEventType) +{ + switch(aEventType) { + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + return mEventNames[onmousedown]; + break; + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_UP: + return mEventNames[onmouseup]; + break; + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + return mEventNames[ondblclick]; + break; + /*case NS_MOUSE_ENTER: + return mEventNames[onmouseover]; + break; + case NS_MOUSE_EXIT: + return mEventNames[onmouseout]; + break;*/ + case NS_MOUSE_MOVE: + return mEventNames[onmousemove]; + break; + case NS_KEY_UP: + return mEventNames[onkeyup]; + break; + case NS_KEY_DOWN: + return mEventNames[onkeydown]; + break; + default: + break; + } + return nsnull; +} diff --git a/mozilla/content/events/src/nsDOMEvent.h b/mozilla/content/events/src/nsDOMEvent.h index 9e93e8ff7cd..2f1847ee3f4 100644 --- a/mozilla/content/events/src/nsDOMEvent.h +++ b/mozilla/content/events/src/nsDOMEvent.h @@ -20,13 +20,13 @@ #define nsDOMEvent_h__ #include "nsIDOMEvent.h" -#include "nsINSEvent.h" #include "nsISupports.h" +#include "nsIPresContext.h" #include "nsPoint.h" #include "nsGUIEvent.h" class nsIContent; -class nsDOMEvent : public nsIDOMEvent, public nsINSEvent { +class nsDOMEvent : public nsIDOMEvent, public nsIDOMNSEvent { public: @@ -36,7 +36,7 @@ public: nsEventStatus_eConsumeDoDefault // The event is consumed, but do default processing }; - nsDOMEvent(); + nsDOMEvent(nsIPresContext* aPresContext); virtual ~nsDOMEvent(); NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); @@ -44,29 +44,53 @@ public: NS_IMETHOD_(nsrefcnt) Release(); // nsIDOMEventInterface - NS_IMETHOD GetType(nsString& aType); + NS_IMETHOD GetType(nsString& aType); + NS_IMETHOD SetType(const nsString& aType); - NS_IMETHOD GetTarget(nsIDOMNode** aTarget); + NS_IMETHOD GetTarget(nsIDOMNode** aTarget); + NS_IMETHOD SetTarget(nsIDOMNode* aTarget); - NS_IMETHOD GetScreenX(PRInt32& aX); - NS_IMETHOD GetScreenY(PRInt32& aY); + NS_IMETHOD GetScreenX(PRInt32* aScreenX); + NS_IMETHOD SetScreenX(PRInt32 aScreenX); - NS_IMETHOD GetClientX(PRInt32& aX); - NS_IMETHOD GetClientY(PRInt32& aY); + NS_IMETHOD GetScreenY(PRInt32* aScreenY); + NS_IMETHOD SetScreenY(PRInt32 aScreenY); - NS_IMETHOD GetAltKey(PRBool& aIsDown); - NS_IMETHOD GetCtrlKey(PRBool& aIsDown); - NS_IMETHOD GetShiftKey(PRBool& aIsDown); - NS_IMETHOD GetMetaKey(PRBool& aIsDown); + NS_IMETHOD GetClientX(PRInt32* aClientX); + NS_IMETHOD SetClientX(PRInt32 aClientX); - NS_IMETHOD GetCharCode(PRUint32& aCharCode); - NS_IMETHOD GetKeyCode(PRUint32& aKeyCode); - NS_IMETHOD GetButton(PRUint32& aButton); + NS_IMETHOD GetClientY(PRInt32* aClientY); + NS_IMETHOD SetClientY(PRInt32 aClientY); + + NS_IMETHOD GetAltKey(PRBool* aAltKey); + NS_IMETHOD SetAltKey(PRBool aAltKey); + + NS_IMETHOD GetCtrlKey(PRBool* aCtrlKey); + NS_IMETHOD SetCtrlKey(PRBool aCtrlKey); + + NS_IMETHOD GetShiftKey(PRBool* aShiftKey); + NS_IMETHOD SetShiftKey(PRBool aShiftKey); + + NS_IMETHOD GetMetaKey(PRBool* aMetaKey); + NS_IMETHOD SetMetaKey(PRBool aMetaKey); + + NS_IMETHOD GetCharCode(PRUint32* aCharCode); + NS_IMETHOD SetCharCode(PRUint32 aCharCode); + + NS_IMETHOD GetKeyCode(PRUint32* aKeyCode); + NS_IMETHOD SetKeyCode(PRUint32 aKeyCode); + + NS_IMETHOD GetButton(PRUint32* aButton); + NS_IMETHOD SetButton(PRUint32 aButton); // nsINSEventInterface - NS_IMETHOD GetLayerX(PRInt32& aX); - NS_IMETHOD GetLayerY(PRInt32& aY); + NS_IMETHOD GetLayerX(PRInt32* aLayerX); + NS_IMETHOD SetLayerX(PRInt32 aLayerX); + NS_IMETHOD GetLayerY(PRInt32* aLayerY); + NS_IMETHOD SetLayerY(PRInt32 aLayerY); + + // Local functions NS_IMETHOD SetGUIEvent(nsGUIEvent *aEvent); NS_IMETHOD SetEventTarget(nsISupports *aTarget); @@ -75,6 +99,9 @@ protected: PRUint32 mRefCnt : 31; nsGUIEvent *kEvent; nsISupports *kTarget; + nsIPresContext *kPresContext; + + const char* GetEventName(PRUint32 aEventType); }; #endif // nsDOMEvent_h__ diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index 3e5490bf498..7556d31bc5f 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -78,7 +78,7 @@ nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIEventStateManager *mManager; nsISupports *mTarget; - nsDOMEvent* it = new nsDOMEvent(); + nsDOMEvent* it = new nsDOMEvent(&aPresContext); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } @@ -93,8 +93,27 @@ nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, return it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent); } -nsresult nsEventListenerManager::GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID) +nsresult nsEventListenerManager::GetEventListeners(nsVoidArray **aListeners, const nsIID& aIID) { + if (aIID.Equals(kIDOMMouseListenerIID)) { + *aListeners = mMouseListeners; + } + if (aIID.Equals(kIDOMMouseMotionListenerIID)) { + *aListeners = mMouseMotionListeners; + } + if (aIID.Equals(kIDOMKeyListenerIID)) { + *aListeners = mKeyListeners; + } + if (aIID.Equals(kIDOMLoadListenerIID)) { + *aListeners = mLoadListeners; + } + if (aIID.Equals(kIDOMFocusListenerIID)) { + *aListeners = mFocusListeners; + } + if (aIID.Equals(kIDOMDragListenerIID)) { + *aListeners = mDragListeners; + } + return NS_OK; } @@ -200,121 +219,135 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { - nsresult mRet; + nsresult mRet = NS_OK; switch(aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + case NS_MOUSE_ENTER: + case NS_MOUSE_EXIT: + if (nsnull != mMouseListeners) { if (nsnull == aDOMEvent) { TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); } if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDown(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseUp(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDblClick(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_ENTER: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOver(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_EXIT: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOut(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_MOVE: - if (nsnull != mMouseMotionListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseMotionListener*)(mMouseMotionListeners->ElementAt(i)))->MouseMove(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_KEY_UP: - if (nsnull != mKeyListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyUp(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_KEY_DOWN: - if (nsnull != mKeyListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyDown(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; + for (int i=0; iCount(); i++) { + nsIDOMEventListener *mEventListener; + nsIDOMMouseListener *mMouseListener; + mEventListener = (nsIDOMEventListener*)mMouseListeners->ElementAt(i); + + if (NS_OK == mEventListener->QueryInterface(kIDOMMouseListenerIID, (void**)&mMouseListener)) { + switch(aEvent->message) { + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + mRet = mMouseListener->MouseDown(aDOMEvent); + break; + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_UP: + mRet = mMouseListener->MouseUp(aDOMEvent); + break; + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + mRet = mMouseListener->MouseDblClick(aDOMEvent); + break; + case NS_MOUSE_ENTER: + mRet = mMouseListener->MouseOver(aDOMEvent); + break; + case NS_MOUSE_EXIT: + mRet = mMouseListener->MouseOut(aDOMEvent); + break; + default: + break; + } + NS_RELEASE(mMouseListener); + } + else { + mRet = mEventListener->ProcessEvent(aDOMEvent); + } + aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; + } + } + } + break; + + case NS_MOUSE_MOVE: + if (nsnull != mMouseMotionListeners) { + if (nsnull == aDOMEvent) { + TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); + } + if (nsnull != aDOMEvent) { + for (int i=0; iCount(); i++) { + nsIDOMEventListener *mEventListener; + nsIDOMMouseMotionListener *mMouseMotionListener; + + mEventListener = (nsIDOMEventListener*)mMouseMotionListeners->ElementAt(i); + + if (NS_OK == mEventListener->QueryInterface(kIDOMMouseMotionListenerIID, (void**)&mMouseMotionListener)) { + switch(aEvent->message) { + case NS_MOUSE_MOVE: + mRet = mMouseMotionListener->MouseMove(aDOMEvent); + break; + default: + break; + } + NS_RELEASE(mMouseMotionListener); + } + else { + mRet = mEventListener->ProcessEvent(aDOMEvent); + } + aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; + } + } + } + break; + + case NS_KEY_UP: + case NS_KEY_DOWN: + if (nsnull != mKeyListeners) { + if (nsnull == aDOMEvent) { + TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); + } + if (nsnull != aDOMEvent) { + for (int i=0; iCount(); i++) { + nsIDOMEventListener *mEventListener; + nsIDOMKeyListener *mKeyListener; + + mEventListener = (nsIDOMEventListener*)mKeyListeners->ElementAt(i); + + if (NS_OK == mEventListener->QueryInterface(kIDOMKeyListenerIID, (void**)&mKeyListener)) { + switch(aEvent->message) { + case NS_KEY_UP: + mRet = mKeyListener->KeyUp(aDOMEvent); + break; + case NS_KEY_DOWN: + mRet = mKeyListener->KeyDown(aDOMEvent); + break; + default: + break; + } + NS_RELEASE(mKeyListener); + } + else { + mRet = mEventListener->ProcessEvent(aDOMEvent); + } + aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; + } + } + } + break; + + default: + break; } - return NS_OK; } diff --git a/mozilla/content/events/src/nsEventListenerManager.h b/mozilla/content/events/src/nsEventListenerManager.h index c0d4be2e612..a650bda9103 100644 --- a/mozilla/content/events/src/nsEventListenerManager.h +++ b/mozilla/content/events/src/nsEventListenerManager.h @@ -41,7 +41,7 @@ public: * @param */ - virtual nsresult GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID); + virtual nsresult GetEventListeners(nsVoidArray **aListeners, const nsIID& aIID); /** * Sets events listeners of all types. diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index fd9119ef67a..f68dacbc6dd 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -25,10 +25,13 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); nsEventStateManager::nsEventStateManager() { mEventTarget = nsnull; + mLastMouseOverContent = nsnull; NS_INIT_REFCNT(); } nsEventStateManager::~nsEventStateManager() { + NS_IF_RELEASE(mEventTarget); + NS_IF_RELEASE(mLastMouseOverContent); } NS_IMPL_ADDREF(nsEventStateManager) @@ -48,7 +51,30 @@ NS_METHOD nsEventStateManager::GetEventTarget(nsISupports **aResult) NS_METHOD nsEventStateManager::SetEventTarget(nsISupports *aSupports) { + NS_IF_RELEASE(mEventTarget); + mEventTarget = aSupports; + NS_ADDREF(mEventTarget); + return NS_OK; +} + +NS_METHOD nsEventStateManager::GetLastMouseOverContent(nsIContent **aContent) +{ + NS_PRECONDITION(nsnull != aContent, "null ptr"); + if (nsnull == aContent) { + return NS_ERROR_NULL_POINTER; + } + *aContent = mLastMouseOverContent; + NS_IF_ADDREF(mLastMouseOverContent); + return NS_OK; +} + +NS_METHOD nsEventStateManager::SetLastMouseOverContent(nsIContent *aContent) +{ + NS_IF_RELEASE(mLastMouseOverContent); + + mLastMouseOverContent = aContent; + NS_ADDREF(mLastMouseOverContent); return NS_OK; } diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index bafaa090187..2108eb6ffd2 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -39,12 +39,14 @@ public: NS_IMETHOD GetEventTarget(nsISupports **aResult); NS_IMETHOD SetEventTarget(nsISupports *aSupports); + NS_IMETHOD GetLastMouseOverContent(nsIContent **aContent); + NS_IMETHOD SetLastMouseOverContent(nsIContent *aContent); protected: PRUint32 mRefCnt : 31; nsISupports* mEventTarget; - + nsIContent* mLastMouseOverContent; }; extern nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult); diff --git a/mozilla/dom/public/Makefile b/mozilla/dom/public/Makefile index b063ee4e1cd..f2ba408f2ef 100644 --- a/mozilla/dom/public/Makefile +++ b/mozilla/dom/public/Makefile @@ -21,14 +21,15 @@ DIRS = coreDom coreEvents events html DEFINES = -D_IMPL_NS_DOM -EXPORTS = \ - nsIScriptContext.h \ - nsIScriptContextOwner.h \ - nsIJSScriptObject.h \ - nsIScriptObjectOwner.h \ - nsIScriptGlobalObject.h \ - nsIDOMWindow.h \ - nsIDOMNavigator.h \ +EXPORTS = \ + nsIScriptContext.h \ + nsIScriptContextOwner.h \ + nsIJSScriptObject.h \ + nsIScriptEventListener.h \ + nsIScriptObjectOwner.h \ + nsIScriptGlobalObject.h \ + nsIDOMWindow.h \ + nsIDOMNavigator.h \ $(NULL) MODULE = dom diff --git a/mozilla/dom/public/coreEvents/nsIDOMEvent.h b/mozilla/dom/public/coreEvents/nsIDOMEvent.h index 4b0b87d1185..6d778325767 100644 --- a/mozilla/dom/public/coreEvents/nsIDOMEvent.h +++ b/mozilla/dom/public/coreEvents/nsIDOMEvent.h @@ -15,167 +15,231 @@ * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ #ifndef nsIDOMEvent_h__ #define nsIDOMEvent_h__ #include "nsISupports.h" -class nsIDOMNode; -class nsString; +#include "nsString.h" +#include "nsIScriptContext.h" + +class nsIDOMNode; +class nsIDOMEvent; +class nsIDOMNSEvent; -/* - * Base DOM event class. - */ #define NS_IDOMEVENT_IID \ -{ /* 9af61790-df03-11d1-bd85-00805f8ae3f4 */ \ -0x9af61790, 0xdf03, 0x11d1, \ -{0xbd, 0x85, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } +{ 0x6f765329, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } class nsIDOMEvent : public nsISupports { - public: -/* - * Virtual key bindings for keyboard events - * NOTE: These are repeated in nsGUIEvent.h and must be kept in sync - */ -#define NS_VK_CANCEL 0x03 -#define NS_VK_BACK 0x08 -#define NS_VK_TAB 0x09 -#define NS_VK_CLEAR 0x0C -#define NS_VK_RETURN 0x0D -#define NS_VK_SHIFT 0x10 -#define NS_VK_CONTROL 0x11 -#define NS_VK_ALT 0x12 -#define NS_VK_PAUSE 0x13 -#define NS_VK_CAPS_LOCK 0x14 -#define NS_VK_ESCAPE 0x1B -#define NS_VK_SPACE 0x20 -#define NS_VK_PAGE_UP 0x21 -#define NS_VK_PAGE_DOWN 0x22 -#define NS_VK_END 0x23 -#define NS_VK_HOME 0x24 -#define NS_VK_LEFT 0x25 -#define NS_VK_UP 0x26 -#define NS_VK_RIGHT 0x27 -#define NS_VK_DOWN 0x28 -#define NS_VK_PRINTSCREEN 0x2C -#define NS_VK_INSERT 0x2D -#define NS_VK_DELETE 0x2E + enum { + VK_CANCEL = 3, + VK_BACK = 8, + VK_TAB = 9, + VK_CLEAR = 12, + VK_RETURN = 13, + VK_SHIFT = 16, + VK_CONTROL = 17, + VK_ALT = 18, + VK_PAUSE = 19, + VK_CAPS_LOCK = 20, + VK_ESCAPE = 27, + VK_SPACE = 32, + VK_PAGE_UP = 33, + VK_PAGE_DOWN = 34, + VK_END = 35, + VK_HOME = 36, + VK_LEFT = 37, + VK_UP = 38, + VK_RIGHT = 39, + VK_DOWN = 40, + VK_PRINTSCREEN = 44, + VK_INSERT = 45, + VK_DELETE = 46, + VK_0 = 48, + VK_1 = 49, + VK_2 = 50, + VK_3 = 51, + VK_4 = 52, + VK_5 = 53, + VK_6 = 54, + VK_7 = 55, + VK_8 = 56, + VK_9 = 57, + VK_SEMICOLON = 59, + VK_EQUALS = 61, + VK_A = 65, + VK_B = 66, + VK_C = 67, + VK_D = 68, + VK_E = 69, + VK_F = 70, + VK_G = 71, + VK_H = 72, + VK_I = 73, + VK_J = 74, + VK_K = 75, + VK_L = 76, + VK_M = 77, + VK_N = 78, + VK_O = 79, + VK_P = 80, + VK_Q = 81, + VK_R = 82, + VK_S = 83, + VK_T = 84, + VK_U = 85, + VK_V = 86, + VK_W = 87, + VK_X = 88, + VK_Y = 89, + VK_Z = 90, + VK_NUMPAD0 = 96, + VK_NUMPAD1 = 97, + VK_NUMPAD2 = 98, + VK_NUMPAD3 = 99, + VK_NUMPAD4 = 100, + VK_NUMPAD5 = 101, + VK_NUMPAD6 = 102, + VK_NUMPAD7 = 103, + VK_NUMPAD8 = 104, + VK_NUMPAD9 = 105, + VK_MULTIPLY = 106, + VK_ADD = 107, + VK_SEPARATOR = 108, + VK_SUBTRACT = 109, + VK_DECIMAL = 110, + VK_DIVIDE = 111, + VK_F1 = 112, + VK_F2 = 113, + VK_F3 = 114, + VK_F4 = 115, + VK_F5 = 116, + VK_F6 = 117, + VK_F7 = 118, + VK_F8 = 119, + VK_F9 = 120, + VK_F10 = 121, + VK_F11 = 122, + VK_F12 = 123, + VK_F13 = 124, + VK_F14 = 125, + VK_F15 = 126, + VK_F16 = 127, + VK_F17 = 128, + VK_F18 = 129, + VK_F19 = 130, + VK_F20 = 131, + VK_F21 = 132, + VK_F22 = 133, + VK_F23 = 134, + VK_F24 = 135, + VK_NUM_LOCK = 144, + VK_SCROLL_LOCK = 145, + VK_COMMA = 188, + VK_PERIOD = 190, + VK_SLASH = 191, + VK_BACK_QUOTE = 192, + VK_OPEN_BRACKET = 219, + VK_BACK_SLASH = 220, + VK_CLOSE_BRACKET = 221, + VK_QUOTE = 222 + }; -// NS_VK_0 - NS_VK_9 match their ascii values -#define NS_VK_0 0x30 -#define NS_VK_1 0x31 -#define NS_VK_2 0x32 -#define NS_VK_3 0x33 -#define NS_VK_4 0x34 -#define NS_VK_5 0x35 -#define NS_VK_6 0x36 -#define NS_VK_7 0x37 -#define NS_VK_8 0x38 -#define NS_VK_9 0x39 + NS_IMETHOD GetType(nsString& aType)=0; + NS_IMETHOD SetType(const nsString& aType)=0; -#define NS_VK_SEMICOLON 0x3B -#define NS_VK_EQUALS 0x3D + NS_IMETHOD GetTarget(nsIDOMNode** aTarget)=0; + NS_IMETHOD SetTarget(nsIDOMNode* aTarget)=0; -// NS_VK_A - NS_VK_Z match their ascii values -#define NS_VK_A 0x41 -#define NS_VK_B 0x42 -#define NS_VK_C 0x43 -#define NS_VK_D 0x44 -#define NS_VK_E 0x45 -#define NS_VK_F 0x46 -#define NS_VK_G 0x47 -#define NS_VK_H 0x48 -#define NS_VK_I 0x49 -#define NS_VK_J 0x4A -#define NS_VK_K 0x4B -#define NS_VK_L 0x4C -#define NS_VK_M 0x4D -#define NS_VK_N 0x4E -#define NS_VK_O 0x4F -#define NS_VK_P 0x50 -#define NS_VK_Q 0x51 -#define NS_VK_R 0x52 -#define NS_VK_S 0x53 -#define NS_VK_T 0x54 -#define NS_VK_U 0x55 -#define NS_VK_V 0x56 -#define NS_VK_W 0x57 -#define NS_VK_X 0x58 -#define NS_VK_Y 0x59 -#define NS_VK_Z 0x5A + NS_IMETHOD GetScreenX(PRInt32* aScreenX)=0; + NS_IMETHOD SetScreenX(PRInt32 aScreenX)=0; -#define NS_VK_NUMPAD0 0x60 -#define NS_VK_NUMPAD1 0x61 -#define NS_VK_NUMPAD2 0x62 -#define NS_VK_NUMPAD3 0x63 -#define NS_VK_NUMPAD4 0x64 -#define NS_VK_NUMPAD5 0x65 -#define NS_VK_NUMPAD6 0x66 -#define NS_VK_NUMPAD7 0x67 -#define NS_VK_NUMPAD8 0x68 -#define NS_VK_NUMPAD9 0x69 -#define NS_VK_MULTIPLY 0x6A -#define NS_VK_ADD 0x6B -#define NS_VK_SEPARATOR 0x6C -#define NS_VK_SUBTRACT 0x6D -#define NS_VK_DECIMAL 0x6E -#define NS_VK_DIVIDE 0x6F -#define NS_VK_F1 0x70 -#define NS_VK_F2 0x71 -#define NS_VK_F3 0x72 -#define NS_VK_F4 0x73 -#define NS_VK_F5 0x74 -#define NS_VK_F6 0x75 -#define NS_VK_F7 0x76 -#define NS_VK_F8 0x77 -#define NS_VK_F9 0x78 -#define NS_VK_F10 0x79 -#define NS_VK_F11 0x7A -#define NS_VK_F12 0x7B -#define NS_VK_F13 0x7C -#define NS_VK_F14 0x7D -#define NS_VK_F15 0x7E -#define NS_VK_F16 0x7F -#define NS_VK_F17 0x80 -#define NS_VK_F18 0x81 -#define NS_VK_F19 0x82 -#define NS_VK_F20 0x83 -#define NS_VK_F21 0x84 -#define NS_VK_F22 0x85 -#define NS_VK_F23 0x86 -#define NS_VK_F24 0x87 + NS_IMETHOD GetScreenY(PRInt32* aScreenY)=0; + NS_IMETHOD SetScreenY(PRInt32 aScreenY)=0; -#define NS_VK_NUM_LOCK 0x90 -#define NS_VK_SCROLL_LOCK 0x91 + NS_IMETHOD GetClientX(PRInt32* aClientX)=0; + NS_IMETHOD SetClientX(PRInt32 aClientX)=0; -#define NS_VK_COMMA 0xBC -#define NS_VK_PERIOD 0xBE -#define NS_VK_SLASH 0xBF -#define NS_VK_BACK_QUOTE 0xC0 -#define NS_VK_OPEN_BRACKET 0xDB -#define NS_VK_BACK_SLASH 0xDC -#define NS_VK_CLOSE_BRACKET 0xDD -#define NS_VK_QUOTE 0xDE + NS_IMETHOD GetClientY(PRInt32* aClientY)=0; + NS_IMETHOD SetClientY(PRInt32 aClientY)=0; -NS_IMETHOD GetType(nsString& aType) = 0; + NS_IMETHOD GetAltKey(PRBool* aAltKey)=0; + NS_IMETHOD SetAltKey(PRBool aAltKey)=0; -NS_IMETHOD GetTarget(nsIDOMNode** aTarget) = 0; + NS_IMETHOD GetCtrlKey(PRBool* aCtrlKey)=0; + NS_IMETHOD SetCtrlKey(PRBool aCtrlKey)=0; -NS_IMETHOD GetScreenX(PRInt32& aX) = 0; -NS_IMETHOD GetScreenY(PRInt32& aY) = 0; + NS_IMETHOD GetShiftKey(PRBool* aShiftKey)=0; + NS_IMETHOD SetShiftKey(PRBool aShiftKey)=0; -NS_IMETHOD GetClientX(PRInt32& aX) = 0; -NS_IMETHOD GetClientY(PRInt32& aY) = 0; + NS_IMETHOD GetMetaKey(PRBool* aMetaKey)=0; + NS_IMETHOD SetMetaKey(PRBool aMetaKey)=0; -NS_IMETHOD GetAltKey(PRBool& aIsDown) = 0; -NS_IMETHOD GetCtrlKey(PRBool& aIsDown) = 0; -NS_IMETHOD GetShiftKey(PRBool& aIsDown) = 0; -NS_IMETHOD GetMetaKey(PRBool& aIsDown) = 0; + NS_IMETHOD GetCharCode(PRUint32* aCharCode)=0; + NS_IMETHOD SetCharCode(PRUint32 aCharCode)=0; -NS_IMETHOD GetCharCode(PRUint32& aCharCode) = 0; -NS_IMETHOD GetKeyCode(PRUint32& aKeyCode) = 0; -NS_IMETHOD GetButton(PRUint32& aButton) = 0; + NS_IMETHOD GetKeyCode(PRUint32* aKeyCode)=0; + NS_IMETHOD SetKeyCode(PRUint32 aKeyCode)=0; + NS_IMETHOD GetButton(PRUint32* aButton)=0; + NS_IMETHOD SetButton(PRUint32 aButton)=0; }; + +#define NS_IDOMNSEVENT_IID \ +{ 0x6f76532a, 0xee43, 0x11d1, \ + { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +class nsIDOMNSEvent : public nsISupports { +public: + enum { + EVENT_MOUSEDOWN = 1, + EVENT_MOUSEUP = 2, + EVENT_MOUSEOVER = 4, + EVENT_MOUSEOUT = 8, + EVENT_MOUSEMOVE = 16, + EVENT_MOUSEDRAG = 32, + EVENT_CLICK = 64, + EVENT_DBLCLICK = 128, + EVENT_KEYDOWN = 256, + EVENT_KEYUP = 512, + EVENT_KEYPRESS = 1024, + EVENT_DRAGDROP = 2048, + EVENT_FOCUS = 4096, + EVENT_BLUR = 8192, + EVENT_SELECT = 16384, + EVENT_CHANGE = 32768, + EVENT_RESET = 65536, + EVENT_SUBMIT = 131072, + EVENT_SCROLL = 262144, + EVENT_LOAD = 524288, + EVENT_UNLOAD = 1048576, + EVENT_XFER_DONE = 2097152, + EVENT_ABORT = 4194304, + EVENT_ERROR = 8388608, + EVENT_LOCATE = 16777216, + EVENT_MOVE = 33554432, + EVENT_RESIZE = 67108864, + EVENT_FORWARD = 134217728, + EVENT_HELP = 268435456, + EVENT_BACK = 536870912, + EVENT_ALT_MASK = 1, + EVENT_CONTROL_MASK = 2, + EVENT_SHIFT_MASK = 4, + EVENT_META_MASK = 8 + }; + + NS_IMETHOD GetLayerX(PRInt32* aLayerX)=0; + NS_IMETHOD SetLayerX(PRInt32 aLayerX)=0; + + NS_IMETHOD GetLayerY(PRInt32* aLayerY)=0; + NS_IMETHOD SetLayerY(PRInt32 aLayerY)=0; +}; + +extern nsresult NS_InitEventClass(nsIScriptContext *aContext, void **aPrototype); + +extern "C" NS_DOM nsresult NS_NewScriptEvent(nsIScriptContext *aContext, nsIDOMEvent *aSupports, nsISupports *aParent, void **aReturn); + #endif // nsIDOMEvent_h__ diff --git a/mozilla/dom/public/events/nsINSEvent.h b/mozilla/dom/public/events/nsINSEvent.h index 522c633297f..eb59ae14094 100644 --- a/mozilla/dom/public/events/nsINSEvent.h +++ b/mozilla/dom/public/events/nsINSEvent.h @@ -33,6 +33,44 @@ class nsIDOMNode; class nsINSEvent : public nsISupports { public: +/* + * Event mask provided for backwards compatibility with 4.0 + */ +#define EVENT_MOUSEDOWN 0x00000001 +#define EVENT_MOUSEUP 0x00000002 +#define EVENT_MOUSEOVER 0x00000004 +#define EVENT_MOUSEOUT 0x00000008 +#define EVENT_MOUSEMOVE 0x00000010 +#define EVENT_MOUSEDRAG 0x00000020 +#define EVENT_CLICK 0x00000040 +#define EVENT_DBLCLICK 0x00000080 +#define EVENT_KEYDOWN 0x00000100 +#define EVENT_KEYUP 0x00000200 +#define EVENT_KEYPRESS 0x00000400 +#define EVENT_DRAGDROP 0x00000800 +#define EVENT_FOCUS 0x00001000 +#define EVENT_BLUR 0x00002000 +#define EVENT_SELECT 0x00004000 +#define EVENT_CHANGE 0x00008000 +#define EVENT_RESET 0x00010000 +#define EVENT_SUBMIT 0x00020000 +#define EVENT_SCROLL 0x00040000 +#define EVENT_LOAD 0x00080000 +#define EVENT_UNLOAD 0x00100000 +#define EVENT_XFER_DONE 0x00200000 +#define EVENT_ABORT 0x00400000 +#define EVENT_ERROR 0x00800000 +#define EVENT_LOCATE 0x01000000 +#define EVENT_MOVE 0x02000000 +#define EVENT_RESIZE 0x04000000 +#define EVENT_FORWARD 0x08000000 +#define EVENT_HELP 0x10000000 +#define EVENT_BACK 0x20000000 + +#define EVENT_ALT_MASK 0x00000001 +#define EVENT_CONTROL_MASK 0x00000002 +#define EVENT_SHIFT_MASK 0x00000004 +#define EVENT_META_MASK 0x00000008 NS_IMETHOD GetLayerX(PRInt32& aX) = 0; NS_IMETHOD GetLayerY(PRInt32& aY) = 0; diff --git a/mozilla/dom/public/makefile.win b/mozilla/dom/public/makefile.win index 9cceb4d0e30..7ec04a379a4 100644 --- a/mozilla/dom/public/makefile.win +++ b/mozilla/dom/public/makefile.win @@ -22,7 +22,7 @@ DIRS=coreDom coreEvents events html DEFINES=-D_IMPL_NS_DOM EXPORTS=nsIScriptContext.h nsIJSScriptObject.h nsIScriptObjectOwner.h \ nsIScriptGlobalObject.h nsIDOMWindow.h nsIScriptContextOwner.h \ - nsIDOMNavigator.h + nsIDOMNavigator.h nsIScriptEventListener.h MODULE=dom diff --git a/mozilla/dom/public/nsIDOMNavigator.h b/mozilla/dom/public/nsIDOMNavigator.h index 3447db616d6..0e88103a620 100644 --- a/mozilla/dom/public/nsIDOMNavigator.h +++ b/mozilla/dom/public/nsIDOMNavigator.h @@ -27,7 +27,7 @@ class nsIDOMNavigator; #define NS_IDOMNAVIGATOR_IID \ -{ 0x6f765329, 0xee43, 0x11d1, \ +{ 0x6f76532b, 0xee43, 0x11d1, \ { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } class nsIDOMNavigator : public nsISupports { diff --git a/mozilla/dom/public/nsIDOMWindow.h b/mozilla/dom/public/nsIDOMWindow.h index a8b8c329640..845859f6c8a 100644 --- a/mozilla/dom/public/nsIDOMWindow.h +++ b/mozilla/dom/public/nsIDOMWindow.h @@ -30,7 +30,7 @@ class nsIDOMDocument; class nsIDOMWindow; #define NS_IDOMWINDOW_IID \ -{ 0x6f76532a, 0xee43, 0x11d1, \ +{ 0x6f76532c, 0xee43, 0x11d1, \ { 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } class nsIDOMWindow : public nsISupports { diff --git a/mozilla/dom/public/nsIScriptEventListener.h b/mozilla/dom/public/nsIScriptEventListener.h new file mode 100644 index 00000000000..4e8687916ff --- /dev/null +++ b/mozilla/dom/public/nsIScriptEventListener.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsIScriptEventListener_h__ +#define nsIScriptEventListener_h__ + +#include "nsISupports.h" + +class nsIDOMEventListener; + +/* + * Event listener interface. + */ + +#define NS_ISCRIPTEVENTLISTENER_IID \ +{ /* e34ed820-1b62-11d2-bd89-00805f8ae3f4 */ \ +0xe34ed820, 0x1b62, 0x11d2, \ +{0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } + +class nsIScriptEventListener : public nsISupports { + +public: + + /** + * Processes all events excepting mouse and key events. + * @param anEvent the event to process. @see nsIDOMEvent.h for event types. + */ + + //virtual nsresult nsAddJSEventHandler(nsIDOMEvent* aEvent) = 0; + +}; + +extern "C" NS_DOM nsresult NS_NewScriptEventListener(nsIDOMEventListener ** aInstancePtrResult, nsIScriptContext *aContext, void *aObj); + +#endif // nsIScriptEventListener_h__ diff --git a/mozilla/dom/src/Makefile b/mozilla/dom/src/Makefile index 2cc8202601c..03618331685 100644 --- a/mozilla/dom/src/Makefile +++ b/mozilla/dom/src/Makefile @@ -17,6 +17,6 @@ DEPTH=../.. -DIRS = base coreDOM html build +DIRS = base coreDOM html build events include $(DEPTH)/config/rules.mk diff --git a/mozilla/dom/src/build/Makefile b/mozilla/dom/src/build/Makefile index e6676a53ac6..6f0d80f1200 100644 --- a/mozilla/dom/src/build/Makefile +++ b/mozilla/dom/src/build/Makefile @@ -44,6 +44,7 @@ EXTRA_DSO_LDOPTS = \ $(LD_ALL) \ $(DIST)/lib/libjsdombase_s.a \ $(DIST)/lib/libjsdomcore_s.a \ + $(DIST)/lib/libjsdomevents_s.a \ $(DIST)/lib/libjsdomhtml_s.a \ $(LD_NONE) \ $(DIST)/bin/libraptorbase.so \ diff --git a/mozilla/dom/src/build/dlldeps.cpp b/mozilla/dom/src/build/dlldeps.cpp index d2e3ac5db96..77cc2c8973b 100644 --- a/mozilla/dom/src/build/dlldeps.cpp +++ b/mozilla/dom/src/build/dlldeps.cpp @@ -18,6 +18,7 @@ #include "nsJSEnvironment.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMNavigator.h" +#include "nsIScriptEventListener.h" // Force references to all of the symbols that we want exported from // the dll that are located in the .lib files we link with @@ -27,4 +28,5 @@ void XXXDomNeverCalled() nsJSContext* jcx = new nsJSContext(0); NS_NewScriptGlobalObject(0); NS_NewScriptNavigator(0, 0, 0, 0); + NS_NewScriptEventListener(0, 0, 0); } diff --git a/mozilla/dom/src/build/makefile.win b/mozilla/dom/src/build/makefile.win index 768fafa3059..fd217aed190 100644 --- a/mozilla/dom/src/build/makefile.win +++ b/mozilla/dom/src/build/makefile.win @@ -36,6 +36,7 @@ DLL=.\$(OBJDIR)\$(DLLNAME).dll MISCDEP = \ $(DIST)\lib\jsdombase_s.lib \ $(DIST)\lib\jsdomcore_s.lib \ + $(DIST)\lib\jsdomevents_s.lib \ $(DIST)\lib\jsdomhtml_s.lib \ $(DIST)\lib\raptorbase.lib \ $(DIST)\lib\netlib.lib \ @@ -54,6 +55,7 @@ LCFLAGS = \ LLIBS= \ $(DIST)\lib\jsdombase_s.lib \ $(DIST)\lib\jsdomcore_s.lib \ + $(DIST)\lib\jsdomevents_s.lib \ $(DIST)\lib\jsdomhtml_s.lib \ $(DIST)\lib\raptorbase.lib \ $(DIST)\lib\netlib.lib \ diff --git a/mozilla/dom/src/makefile.win b/mozilla/dom/src/makefile.win index 9d5ae57ae0e..544ea648b63 100644 --- a/mozilla/dom/src/makefile.win +++ b/mozilla/dom/src/makefile.win @@ -18,6 +18,6 @@ DEPTH=..\.. IGNORE_MANIFEST=1 -DIRS = base coreDOM html build +DIRS = base coreDOM html build events include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/layout/base/public/nsIFrame.h b/mozilla/layout/base/public/nsIFrame.h index 9c60e385289..49312d923f0 100644 --- a/mozilla/layout/base/public/nsIFrame.h +++ b/mozilla/layout/base/public/nsIFrame.h @@ -360,9 +360,10 @@ public: * no cursor is wanted). In addition, if a cursor is desired * then *aFrame is set to the frame that wants the cursor. */ - NS_IMETHOD GetCursorAt(nsIPresContext& aPresContext, + NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor) = 0; /** diff --git a/mozilla/layout/base/src/nsContainerFrame.cpp b/mozilla/layout/base/src/nsContainerFrame.cpp index 0f7e40f72fc..6b3d0ea8eba 100644 --- a/mozilla/layout/base/src/nsContainerFrame.cpp +++ b/mozilla/layout/base/src/nsContainerFrame.cpp @@ -330,12 +330,14 @@ NS_METHOD nsContainerFrame::HandleEvent(nsIPresContext& aPresContext, return NS_OK; } -NS_METHOD nsContainerFrame::GetCursorAt(nsIPresContext& aPresContext, +NS_METHOD nsContainerFrame::GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor) { aCursor = NS_STYLE_CURSOR_INHERIT; + *aContent = mContent; nsIFrame* kid; FirstChild(kid); @@ -345,7 +347,7 @@ NS_METHOD nsContainerFrame::GetCursorAt(nsIPresContext& aPresContext, kid->GetRect(kidRect); if (kidRect.Contains(aPoint)) { tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y); - kid->GetCursorAt(aPresContext, tmp, aFrame, aCursor); + kid->GetCursorAndContentAt(aPresContext, tmp, aFrame, aContent, aCursor); break; } kid->GetNextSibling(kid); diff --git a/mozilla/layout/base/src/nsContainerFrame.h b/mozilla/layout/base/src/nsContainerFrame.h index 301a3fe0921..53747851699 100644 --- a/mozilla/layout/base/src/nsContainerFrame.h +++ b/mozilla/layout/base/src/nsContainerFrame.h @@ -133,9 +133,10 @@ public: nsGUIEvent* aEvent, nsEventStatus& aEventStatus); - NS_IMETHOD GetCursorAt(nsIPresContext& aPresContext, + NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor); // Child frame enumeration. diff --git a/mozilla/layout/base/src/nsFrame.cpp b/mozilla/layout/base/src/nsFrame.cpp index 5cb33ce84cf..d49764c09b1 100644 --- a/mozilla/layout/base/src/nsFrame.cpp +++ b/mozilla/layout/base/src/nsFrame.cpp @@ -998,11 +998,13 @@ void nsFrame::AdjustPointsInSameContent(nsIPresContext& aPresContext, //} } -NS_METHOD nsFrame::GetCursorAt(nsIPresContext& aPresContext, +NS_METHOD nsFrame::GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor) { + *aContent = mContent; aCursor = NS_STYLE_CURSOR_INHERIT; return NS_OK; } diff --git a/mozilla/layout/base/src/nsFrame.h b/mozilla/layout/base/src/nsFrame.h index d4315d99a22..d36e9003233 100644 --- a/mozilla/layout/base/src/nsFrame.h +++ b/mozilla/layout/base/src/nsFrame.h @@ -138,9 +138,10 @@ public: NS_IMETHOD HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus); - NS_IMETHOD GetCursorAt(nsIPresContext& aPresContext, + NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor); NS_IMETHOD GetFrameState(nsFrameState& aResult); NS_IMETHOD SetFrameState(nsFrameState aNewState); diff --git a/mozilla/layout/build/Makefile b/mozilla/layout/build/Makefile index 2562c3ddd3f..d391a9e0058 100644 --- a/mozilla/layout/build/Makefile +++ b/mozilla/layout/build/Makefile @@ -56,6 +56,7 @@ EXTRA_DSO_LDOPTS = \ $(DIST)/bin/libraptorbase.so \ $(DIST)/bin/libgmbaseunix.so \ $(DIST)/bin/libjsdom.so \ + $(DIST)/bin/libjs.so \ $(DIST)/bin/libnetlib.so \ $(DIST)/bin/libxpcom.so \ $(DIST)/bin/libnspr21.so \ diff --git a/mozilla/layout/build/makefile.win b/mozilla/layout/build/makefile.win index cd515fb7074..ce5b693b009 100644 --- a/mozilla/layout/build/makefile.win +++ b/mozilla/layout/build/makefile.win @@ -48,6 +48,7 @@ MISCDEP = \ $(DIST)\lib\raptorhtmlpars.lib \ $(DIST)\lib\jsdom.lib \ $(DIST)\lib\libplc21.lib \ + $(DIST)\lib\js3240.lib \ $(LIBNSPR) LCFLAGS = \ @@ -75,6 +76,7 @@ LLIBS= \ $(DIST)\lib\jsdom.lib \ $(DIST)\lib\netlib.lib \ $(DIST)\lib\libplc21.lib \ + $(DIST)\lib\js3240.lib \ $(LIBNSPR) include <$(DEPTH)\layout\config\rules.mak> diff --git a/mozilla/layout/events/public/nsIEventListenerManager.h b/mozilla/layout/events/public/nsIEventListenerManager.h index f85f75d8a77..295e079287f 100644 --- a/mozilla/layout/events/public/nsIEventListenerManager.h +++ b/mozilla/layout/events/public/nsIEventListenerManager.h @@ -44,7 +44,7 @@ public: * @param */ - virtual nsresult GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID) = 0; + virtual nsresult GetEventListeners(nsVoidArray **aListeners, const nsIID& aIID) = 0; /** * Sets events listeners of all types. diff --git a/mozilla/layout/events/public/nsIEventStateManager.h b/mozilla/layout/events/public/nsIEventStateManager.h index 03489f17164..cb6d57e54c1 100644 --- a/mozilla/layout/events/public/nsIEventStateManager.h +++ b/mozilla/layout/events/public/nsIEventStateManager.h @@ -22,6 +22,7 @@ #include "nsGUIEvent.h" #include "nsISupports.h" #include "nsVoidArray.h" +#include "nsIContent.h" class nsIPresContext; class nsIDOMEventState; @@ -53,6 +54,10 @@ public: NS_IMETHOD SetEventTarget(nsISupports *aSupports) = 0; + + NS_IMETHOD GetLastMouseOverContent(nsIContent **aContent) = 0; + NS_IMETHOD SetLastMouseOverContent(nsIContent *aContent) = 0; + }; #endif // nsIEventStateManager_h__ diff --git a/mozilla/layout/events/src/nsDOMEvent.cpp b/mozilla/layout/events/src/nsDOMEvent.cpp index 866ae23846b..8350b106f76 100644 --- a/mozilla/layout/events/src/nsDOMEvent.cpp +++ b/mozilla/layout/events/src/nsDOMEvent.cpp @@ -21,12 +21,28 @@ static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID); -static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID); +static NS_DEFINE_IID(kIDOMNSEventIID, NS_IDOMNSEVENT_IID); -nsDOMEvent::nsDOMEvent() { + +enum mEventEnum { + onmousedown=0, onmouseup=1, onclick=2, ondblclick=3, onmouseover=4, onmouseout=5, + onmousemove=6, onkeydown=7, onkeyup=8, onkeypress=9, onfocus=10, onblur=11, + onload=12, onabort=13, onerror=14 +}; + +static char* mEventNames[] = { + "onmousedown", "onmouseup", "onclick", "ondblclick", "onmouseover", "onmouseout", + "onmousemove", "onkeydown", "onkeyup", "onkeypress", "onfocus", "onblur", + "onload", "onabort", "onerror" +}; + +nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext) { + kPresContext = aPresContext; + NS_ADDREF(kPresContext); } nsDOMEvent::~nsDOMEvent() { + NS_RELEASE(kPresContext); } NS_IMPL_ADDREF(nsDOMEvent) @@ -44,8 +60,8 @@ nsresult nsDOMEvent::QueryInterface(const nsIID& aIID, AddRef(); return NS_OK; } - if (aIID.Equals(kINSEventIID)) { - *aInstancePtrResult = (void*) ((nsINSEvent*)this); + if (aIID.Equals(kIDOMNSEventIID)) { + *aInstancePtrResult = (void*) ((nsIDOMNSEvent*)this); AddRef(); return NS_OK; } @@ -54,6 +70,18 @@ nsresult nsDOMEvent::QueryInterface(const nsIID& aIID, // nsIDOMEventInterface NS_METHOD nsDOMEvent::GetType(nsString& aType) +{ + const char* mName = GetEventName(kEvent->message); + + if (nsnull != mName) { + aType = nsString(mName); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +NS_METHOD nsDOMEvent::SetType(const nsString& aType) { return NS_ERROR_NOT_IMPLEMENTED; } @@ -63,64 +91,112 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) return kTarget->QueryInterface(kIDOMNodeIID, (void**)aTarget); } -NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX) +NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY) +NS_METHOD nsDOMEvent::GetScreenX(PRInt32* aScreenX) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX) -{ - //XXX these are not client coords yet - aX = kEvent->point.x; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY) -{ - //XXX these are not client coords yet - aY = kEvent->point.y; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown) -{ - aIsDown = ((nsInputEvent*)kEvent)->isAlt; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown) -{ - aIsDown = ((nsInputEvent*)kEvent)->isControl; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown) -{ - aIsDown = ((nsInputEvent*)kEvent)->isShift; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown) -{ - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode) +NS_METHOD nsDOMEvent::SetScreenX(PRInt32 aScreenX) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode) +NS_METHOD nsDOMEvent::GetScreenY(PRInt32* aScreenY) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::SetScreenY(PRInt32 aScreenY) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetClientX(PRInt32* aClientX) +{ + *aClientX = NS_TO_INT_ROUND(kEvent->point.x * kPresContext->GetTwipsToPixels()); + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetClientX(PRInt32 aClientX) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetClientY(PRInt32* aClientY) +{ + *aClientY = NS_TO_INT_ROUND(kEvent->point.y * kPresContext->GetTwipsToPixels()); + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetClientY(PRInt32 aClientY) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetAltKey(PRBool* aIsDown) +{ + *aIsDown = ((nsInputEvent*)kEvent)->isAlt; + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetAltKey(PRBool aAltKey) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetCtrlKey(PRBool* aIsDown) +{ + *aIsDown = ((nsInputEvent*)kEvent)->isControl; + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetCtrlKey(PRBool aCtrlKey) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetShiftKey(PRBool* aIsDown) +{ + *aIsDown = ((nsInputEvent*)kEvent)->isShift; + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetShiftKey(PRBool aShiftKey) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetMetaKey(PRBool* aIsDown) +{ + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetMetaKey(PRBool aMetaKey) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetCharCode(PRUint32* aCharCode) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::SetCharCode(PRUint32 aCharCode) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetKeyCode(PRUint32* aKeyCode) { switch (kEvent->message) { case NS_KEY_UP: case NS_KEY_DOWN: - aKeyCode = ((nsKeyEvent*)kEvent)->keyCode; + *aKeyCode = ((nsKeyEvent*)kEvent)->keyCode; break; default: return NS_ERROR_FAILURE; @@ -128,22 +204,27 @@ NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode) return NS_OK; } -NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton) +NS_METHOD nsDOMEvent::SetKeyCode(PRUint32 aKeyCode) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetButton(PRUint32* aButton) { switch (kEvent->message) { case NS_MOUSE_LEFT_BUTTON_UP: case NS_MOUSE_LEFT_BUTTON_DOWN: case NS_MOUSE_LEFT_DOUBLECLICK: - aButton = 1; + *aButton = 1; break; case NS_MOUSE_MIDDLE_BUTTON_UP: case NS_MOUSE_MIDDLE_BUTTON_DOWN: - aButton = 2; + *aButton = 2; break; case NS_MOUSE_RIGHT_BUTTON_UP: case NS_MOUSE_RIGHT_BUTTON_DOWN: case NS_MOUSE_RIGHT_DOUBLECLICK: - aButton = 3; + *aButton = 3; break; default: return NS_ERROR_FAILURE; @@ -151,13 +232,28 @@ NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton) return NS_OK; } -// nsINSEventInterface -NS_METHOD nsDOMEvent::GetLayerX(PRInt32& aX) +NS_METHOD nsDOMEvent::SetButton(PRUint32 aButton) { return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY) +// nsINSEventInterface +NS_METHOD nsDOMEvent::GetLayerX(PRInt32* aLayerX) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::SetLayerX(PRInt32 aLayerX) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::GetLayerY(PRInt32* aLayerY) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_METHOD nsDOMEvent::SetLayerY(PRInt32 aLayerY) { return NS_ERROR_NOT_IMPLEMENTED; } @@ -173,3 +269,41 @@ NS_METHOD nsDOMEvent::SetEventTarget(nsISupports *aTarget) kTarget = aTarget; return NS_OK; } + +const char* nsDOMEvent::GetEventName(PRUint32 aEventType) +{ + switch(aEventType) { + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + return mEventNames[onmousedown]; + break; + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_UP: + return mEventNames[onmouseup]; + break; + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + return mEventNames[ondblclick]; + break; + /*case NS_MOUSE_ENTER: + return mEventNames[onmouseover]; + break; + case NS_MOUSE_EXIT: + return mEventNames[onmouseout]; + break;*/ + case NS_MOUSE_MOVE: + return mEventNames[onmousemove]; + break; + case NS_KEY_UP: + return mEventNames[onkeyup]; + break; + case NS_KEY_DOWN: + return mEventNames[onkeydown]; + break; + default: + break; + } + return nsnull; +} diff --git a/mozilla/layout/events/src/nsDOMEvent.h b/mozilla/layout/events/src/nsDOMEvent.h index 9e93e8ff7cd..2f1847ee3f4 100644 --- a/mozilla/layout/events/src/nsDOMEvent.h +++ b/mozilla/layout/events/src/nsDOMEvent.h @@ -20,13 +20,13 @@ #define nsDOMEvent_h__ #include "nsIDOMEvent.h" -#include "nsINSEvent.h" #include "nsISupports.h" +#include "nsIPresContext.h" #include "nsPoint.h" #include "nsGUIEvent.h" class nsIContent; -class nsDOMEvent : public nsIDOMEvent, public nsINSEvent { +class nsDOMEvent : public nsIDOMEvent, public nsIDOMNSEvent { public: @@ -36,7 +36,7 @@ public: nsEventStatus_eConsumeDoDefault // The event is consumed, but do default processing }; - nsDOMEvent(); + nsDOMEvent(nsIPresContext* aPresContext); virtual ~nsDOMEvent(); NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); @@ -44,29 +44,53 @@ public: NS_IMETHOD_(nsrefcnt) Release(); // nsIDOMEventInterface - NS_IMETHOD GetType(nsString& aType); + NS_IMETHOD GetType(nsString& aType); + NS_IMETHOD SetType(const nsString& aType); - NS_IMETHOD GetTarget(nsIDOMNode** aTarget); + NS_IMETHOD GetTarget(nsIDOMNode** aTarget); + NS_IMETHOD SetTarget(nsIDOMNode* aTarget); - NS_IMETHOD GetScreenX(PRInt32& aX); - NS_IMETHOD GetScreenY(PRInt32& aY); + NS_IMETHOD GetScreenX(PRInt32* aScreenX); + NS_IMETHOD SetScreenX(PRInt32 aScreenX); - NS_IMETHOD GetClientX(PRInt32& aX); - NS_IMETHOD GetClientY(PRInt32& aY); + NS_IMETHOD GetScreenY(PRInt32* aScreenY); + NS_IMETHOD SetScreenY(PRInt32 aScreenY); - NS_IMETHOD GetAltKey(PRBool& aIsDown); - NS_IMETHOD GetCtrlKey(PRBool& aIsDown); - NS_IMETHOD GetShiftKey(PRBool& aIsDown); - NS_IMETHOD GetMetaKey(PRBool& aIsDown); + NS_IMETHOD GetClientX(PRInt32* aClientX); + NS_IMETHOD SetClientX(PRInt32 aClientX); - NS_IMETHOD GetCharCode(PRUint32& aCharCode); - NS_IMETHOD GetKeyCode(PRUint32& aKeyCode); - NS_IMETHOD GetButton(PRUint32& aButton); + NS_IMETHOD GetClientY(PRInt32* aClientY); + NS_IMETHOD SetClientY(PRInt32 aClientY); + + NS_IMETHOD GetAltKey(PRBool* aAltKey); + NS_IMETHOD SetAltKey(PRBool aAltKey); + + NS_IMETHOD GetCtrlKey(PRBool* aCtrlKey); + NS_IMETHOD SetCtrlKey(PRBool aCtrlKey); + + NS_IMETHOD GetShiftKey(PRBool* aShiftKey); + NS_IMETHOD SetShiftKey(PRBool aShiftKey); + + NS_IMETHOD GetMetaKey(PRBool* aMetaKey); + NS_IMETHOD SetMetaKey(PRBool aMetaKey); + + NS_IMETHOD GetCharCode(PRUint32* aCharCode); + NS_IMETHOD SetCharCode(PRUint32 aCharCode); + + NS_IMETHOD GetKeyCode(PRUint32* aKeyCode); + NS_IMETHOD SetKeyCode(PRUint32 aKeyCode); + + NS_IMETHOD GetButton(PRUint32* aButton); + NS_IMETHOD SetButton(PRUint32 aButton); // nsINSEventInterface - NS_IMETHOD GetLayerX(PRInt32& aX); - NS_IMETHOD GetLayerY(PRInt32& aY); + NS_IMETHOD GetLayerX(PRInt32* aLayerX); + NS_IMETHOD SetLayerX(PRInt32 aLayerX); + NS_IMETHOD GetLayerY(PRInt32* aLayerY); + NS_IMETHOD SetLayerY(PRInt32 aLayerY); + + // Local functions NS_IMETHOD SetGUIEvent(nsGUIEvent *aEvent); NS_IMETHOD SetEventTarget(nsISupports *aTarget); @@ -75,6 +99,9 @@ protected: PRUint32 mRefCnt : 31; nsGUIEvent *kEvent; nsISupports *kTarget; + nsIPresContext *kPresContext; + + const char* GetEventName(PRUint32 aEventType); }; #endif // nsDOMEvent_h__ diff --git a/mozilla/layout/events/src/nsEventListenerManager.cpp b/mozilla/layout/events/src/nsEventListenerManager.cpp index 3e5490bf498..7556d31bc5f 100644 --- a/mozilla/layout/events/src/nsEventListenerManager.cpp +++ b/mozilla/layout/events/src/nsEventListenerManager.cpp @@ -78,7 +78,7 @@ nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIEventStateManager *mManager; nsISupports *mTarget; - nsDOMEvent* it = new nsDOMEvent(); + nsDOMEvent* it = new nsDOMEvent(&aPresContext); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } @@ -93,8 +93,27 @@ nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, return it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent); } -nsresult nsEventListenerManager::GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID) +nsresult nsEventListenerManager::GetEventListeners(nsVoidArray **aListeners, const nsIID& aIID) { + if (aIID.Equals(kIDOMMouseListenerIID)) { + *aListeners = mMouseListeners; + } + if (aIID.Equals(kIDOMMouseMotionListenerIID)) { + *aListeners = mMouseMotionListeners; + } + if (aIID.Equals(kIDOMKeyListenerIID)) { + *aListeners = mKeyListeners; + } + if (aIID.Equals(kIDOMLoadListenerIID)) { + *aListeners = mLoadListeners; + } + if (aIID.Equals(kIDOMFocusListenerIID)) { + *aListeners = mFocusListeners; + } + if (aIID.Equals(kIDOMDragListenerIID)) { + *aListeners = mDragListeners; + } + return NS_OK; } @@ -200,121 +219,135 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { - nsresult mRet; + nsresult mRet = NS_OK; switch(aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + case NS_MOUSE_ENTER: + case NS_MOUSE_EXIT: + if (nsnull != mMouseListeners) { if (nsnull == aDOMEvent) { TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); } if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDown(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseUp(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDblClick(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_ENTER: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOver(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_EXIT: - if (nsnull != mMouseListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOut(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_MOUSE_MOVE: - if (nsnull != mMouseMotionListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMMouseMotionListener*)(mMouseMotionListeners->ElementAt(i)))->MouseMove(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_KEY_UP: - if (nsnull != mKeyListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyUp(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; - case NS_KEY_DOWN: - if (nsnull != mKeyListeners) { - for (int i=0; iCount(); i++) { - if (nsnull == aDOMEvent) { - TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); - } - if (nsnull != aDOMEvent) { - mRet = ((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyDown(aDOMEvent); - aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; - } - } - } - break; + for (int i=0; iCount(); i++) { + nsIDOMEventListener *mEventListener; + nsIDOMMouseListener *mMouseListener; + mEventListener = (nsIDOMEventListener*)mMouseListeners->ElementAt(i); + + if (NS_OK == mEventListener->QueryInterface(kIDOMMouseListenerIID, (void**)&mMouseListener)) { + switch(aEvent->message) { + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + mRet = mMouseListener->MouseDown(aDOMEvent); + break; + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_UP: + mRet = mMouseListener->MouseUp(aDOMEvent); + break; + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + mRet = mMouseListener->MouseDblClick(aDOMEvent); + break; + case NS_MOUSE_ENTER: + mRet = mMouseListener->MouseOver(aDOMEvent); + break; + case NS_MOUSE_EXIT: + mRet = mMouseListener->MouseOut(aDOMEvent); + break; + default: + break; + } + NS_RELEASE(mMouseListener); + } + else { + mRet = mEventListener->ProcessEvent(aDOMEvent); + } + aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; + } + } + } + break; + + case NS_MOUSE_MOVE: + if (nsnull != mMouseMotionListeners) { + if (nsnull == aDOMEvent) { + TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); + } + if (nsnull != aDOMEvent) { + for (int i=0; iCount(); i++) { + nsIDOMEventListener *mEventListener; + nsIDOMMouseMotionListener *mMouseMotionListener; + + mEventListener = (nsIDOMEventListener*)mMouseMotionListeners->ElementAt(i); + + if (NS_OK == mEventListener->QueryInterface(kIDOMMouseMotionListenerIID, (void**)&mMouseMotionListener)) { + switch(aEvent->message) { + case NS_MOUSE_MOVE: + mRet = mMouseMotionListener->MouseMove(aDOMEvent); + break; + default: + break; + } + NS_RELEASE(mMouseMotionListener); + } + else { + mRet = mEventListener->ProcessEvent(aDOMEvent); + } + aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; + } + } + } + break; + + case NS_KEY_UP: + case NS_KEY_DOWN: + if (nsnull != mKeyListeners) { + if (nsnull == aDOMEvent) { + TranslateGUI2DOM(aEvent, aPresContext, &aDOMEvent); + } + if (nsnull != aDOMEvent) { + for (int i=0; iCount(); i++) { + nsIDOMEventListener *mEventListener; + nsIDOMKeyListener *mKeyListener; + + mEventListener = (nsIDOMEventListener*)mKeyListeners->ElementAt(i); + + if (NS_OK == mEventListener->QueryInterface(kIDOMKeyListenerIID, (void**)&mKeyListener)) { + switch(aEvent->message) { + case NS_KEY_UP: + mRet = mKeyListener->KeyUp(aDOMEvent); + break; + case NS_KEY_DOWN: + mRet = mKeyListener->KeyDown(aDOMEvent); + break; + default: + break; + } + NS_RELEASE(mKeyListener); + } + else { + mRet = mEventListener->ProcessEvent(aDOMEvent); + } + aEventStatus = (NS_OK == mRet) ? nsEventStatus_eIgnore : nsEventStatus_eConsumeNoDefault; + } + } + } + break; + + default: + break; } - return NS_OK; } diff --git a/mozilla/layout/events/src/nsEventListenerManager.h b/mozilla/layout/events/src/nsEventListenerManager.h index c0d4be2e612..a650bda9103 100644 --- a/mozilla/layout/events/src/nsEventListenerManager.h +++ b/mozilla/layout/events/src/nsEventListenerManager.h @@ -41,7 +41,7 @@ public: * @param */ - virtual nsresult GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID); + virtual nsresult GetEventListeners(nsVoidArray **aListeners, const nsIID& aIID); /** * Sets events listeners of all types. diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp index fd9119ef67a..f68dacbc6dd 100644 --- a/mozilla/layout/events/src/nsEventStateManager.cpp +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -25,10 +25,13 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); nsEventStateManager::nsEventStateManager() { mEventTarget = nsnull; + mLastMouseOverContent = nsnull; NS_INIT_REFCNT(); } nsEventStateManager::~nsEventStateManager() { + NS_IF_RELEASE(mEventTarget); + NS_IF_RELEASE(mLastMouseOverContent); } NS_IMPL_ADDREF(nsEventStateManager) @@ -48,7 +51,30 @@ NS_METHOD nsEventStateManager::GetEventTarget(nsISupports **aResult) NS_METHOD nsEventStateManager::SetEventTarget(nsISupports *aSupports) { + NS_IF_RELEASE(mEventTarget); + mEventTarget = aSupports; + NS_ADDREF(mEventTarget); + return NS_OK; +} + +NS_METHOD nsEventStateManager::GetLastMouseOverContent(nsIContent **aContent) +{ + NS_PRECONDITION(nsnull != aContent, "null ptr"); + if (nsnull == aContent) { + return NS_ERROR_NULL_POINTER; + } + *aContent = mLastMouseOverContent; + NS_IF_ADDREF(mLastMouseOverContent); + return NS_OK; +} + +NS_METHOD nsEventStateManager::SetLastMouseOverContent(nsIContent *aContent) +{ + NS_IF_RELEASE(mLastMouseOverContent); + + mLastMouseOverContent = aContent; + NS_ADDREF(mLastMouseOverContent); return NS_OK; } diff --git a/mozilla/layout/events/src/nsEventStateManager.h b/mozilla/layout/events/src/nsEventStateManager.h index bafaa090187..2108eb6ffd2 100644 --- a/mozilla/layout/events/src/nsEventStateManager.h +++ b/mozilla/layout/events/src/nsEventStateManager.h @@ -39,12 +39,14 @@ public: NS_IMETHOD GetEventTarget(nsISupports **aResult); NS_IMETHOD SetEventTarget(nsISupports *aSupports); + NS_IMETHOD GetLastMouseOverContent(nsIContent **aContent); + NS_IMETHOD SetLastMouseOverContent(nsIContent *aContent); protected: PRUint32 mRefCnt : 31; nsISupports* mEventTarget; - + nsIContent* mLastMouseOverContent; }; extern nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult); diff --git a/mozilla/layout/generic/nsHTMLContainerFrame.cpp b/mozilla/layout/generic/nsHTMLContainerFrame.cpp index 58f631e6d74..3b5d6c35e04 100644 --- a/mozilla/layout/generic/nsHTMLContainerFrame.cpp +++ b/mozilla/layout/generic/nsHTMLContainerFrame.cpp @@ -96,18 +96,22 @@ NS_METHOD nsHTMLContainerFrame::HandleEvent(nsIPresContext& aPresContext, return nsContainerFrame::HandleEvent(aPresContext, aEvent, aEventStatus); } -NS_METHOD nsHTMLContainerFrame::GetCursorAt(nsIPresContext& aPresContext, +NS_METHOD nsHTMLContainerFrame::GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor) { + // Set content here, child will override if found. + *aContent = mContent; + // Get my cursor const nsStyleColor* styleColor = (const nsStyleColor*) mStyleContext->GetStyleData(eStyleStruct_Color); PRInt32 myCursor = styleColor->mCursor; // Get child's cursor, if any - nsContainerFrame::GetCursorAt(aPresContext, aPoint, aFrame, aCursor); + nsContainerFrame::GetCursorAndContentAt(aPresContext, aPoint, aFrame, aContent, aCursor); if (aCursor != NS_STYLE_CURSOR_INHERIT) { nsIAtom* tag = mContent->GetTag(); if (nsHTMLAtoms::a == tag) { diff --git a/mozilla/layout/generic/nsHTMLContainerFrame.h b/mozilla/layout/generic/nsHTMLContainerFrame.h index 52d886fb856..eacc819002e 100644 --- a/mozilla/layout/generic/nsHTMLContainerFrame.h +++ b/mozilla/layout/generic/nsHTMLContainerFrame.h @@ -34,9 +34,10 @@ public: NS_IMETHOD HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus); - NS_IMETHOD GetCursorAt(nsIPresContext& aPresContext, + NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor); NS_IMETHOD ContentAppended(nsIPresShell* aShell, nsIPresContext* aPresContext, diff --git a/mozilla/layout/generic/nsIFrame.h b/mozilla/layout/generic/nsIFrame.h index 9c60e385289..49312d923f0 100644 --- a/mozilla/layout/generic/nsIFrame.h +++ b/mozilla/layout/generic/nsIFrame.h @@ -360,9 +360,10 @@ public: * no cursor is wanted). In addition, if a cursor is desired * then *aFrame is set to the frame that wants the cursor. */ - NS_IMETHOD GetCursorAt(nsIPresContext& aPresContext, + NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor) = 0; /** diff --git a/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp b/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp index 58f631e6d74..3b5d6c35e04 100644 --- a/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp +++ b/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp @@ -96,18 +96,22 @@ NS_METHOD nsHTMLContainerFrame::HandleEvent(nsIPresContext& aPresContext, return nsContainerFrame::HandleEvent(aPresContext, aEvent, aEventStatus); } -NS_METHOD nsHTMLContainerFrame::GetCursorAt(nsIPresContext& aPresContext, +NS_METHOD nsHTMLContainerFrame::GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor) { + // Set content here, child will override if found. + *aContent = mContent; + // Get my cursor const nsStyleColor* styleColor = (const nsStyleColor*) mStyleContext->GetStyleData(eStyleStruct_Color); PRInt32 myCursor = styleColor->mCursor; // Get child's cursor, if any - nsContainerFrame::GetCursorAt(aPresContext, aPoint, aFrame, aCursor); + nsContainerFrame::GetCursorAndContentAt(aPresContext, aPoint, aFrame, aContent, aCursor); if (aCursor != NS_STYLE_CURSOR_INHERIT) { nsIAtom* tag = mContent->GetTag(); if (nsHTMLAtoms::a == tag) { diff --git a/mozilla/layout/html/base/src/nsHTMLContainerFrame.h b/mozilla/layout/html/base/src/nsHTMLContainerFrame.h index 52d886fb856..eacc819002e 100644 --- a/mozilla/layout/html/base/src/nsHTMLContainerFrame.h +++ b/mozilla/layout/html/base/src/nsHTMLContainerFrame.h @@ -34,9 +34,10 @@ public: NS_IMETHOD HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus); - NS_IMETHOD GetCursorAt(nsIPresContext& aPresContext, + NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor); NS_IMETHOD ContentAppended(nsIPresShell* aShell, nsIPresContext* aPresContext, diff --git a/mozilla/layout/html/base/src/nsHTMLImage.cpp b/mozilla/layout/html/base/src/nsHTMLImage.cpp index 1070d82fc9b..052f3cd8205 100644 --- a/mozilla/layout/html/base/src/nsHTMLImage.cpp +++ b/mozilla/layout/html/base/src/nsHTMLImage.cpp @@ -85,9 +85,10 @@ public: NS_METHOD HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus); - NS_IMETHOD GetCursorAt(nsIPresContext& aPresContext, + NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor); protected: @@ -571,13 +572,15 @@ ImageFrame::HandleEvent(nsIPresContext& aPresContext, } NS_METHOD -ImageFrame::GetCursorAt(nsIPresContext& aPresContext, +ImageFrame::GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor) { // The default cursor is to have no cursor aCursor = NS_STYLE_CURSOR_INHERIT; + *aContent = mContent; const nsStyleColor* styleColor = (const nsStyleColor*) mStyleContext->GetStyleData(eStyleStruct_Color); diff --git a/mozilla/layout/html/base/src/nsHTMLTagContent.cpp b/mozilla/layout/html/base/src/nsHTMLTagContent.cpp index 2ffd4bb5d6e..3f981b6c037 100644 --- a/mozilla/layout/html/base/src/nsHTMLTagContent.cpp +++ b/mozilla/layout/html/base/src/nsHTMLTagContent.cpp @@ -34,6 +34,12 @@ #include "nsISupportsArray.h" #include "nsXIFConverter.h" #include "nsISizeOfHandler.h" +#include "nsIEventListenerManager.h" +#include "nsIScriptEventListener.h" +#include "nsIDOMMouseListener.h" +#include "nsIDOMKeyListener.h" +#include "nsIDOMMouseMotionListener.h" +#include "jsapi.h" #include "nsXIFConverter.h" @@ -41,6 +47,11 @@ static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID); static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); static NS_DEFINE_IID(kIScriptObjectOwner, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID); +static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID); +static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID); +static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); /** @@ -147,6 +158,11 @@ nsresult nsHTMLTagContent::QueryInterface(REFNSIID aIID, void** aInstancePtr) AddRef(); return NS_OK; } + if (aIID.Equals(kIJSScriptObjectIID)) { + *aInstancePtr = (void*)(nsIJSScriptObject*)this; + AddRef(); + return NS_OK; + } } return res; @@ -484,6 +500,107 @@ nsresult nsHTMLTagContent::GetScriptObject(nsIScriptContext *aContext, void** aS return res; } +PRBool nsHTMLTagContent::AddProperty(JSContext *aContext, jsval aID, jsval *aVp) +{ + return PR_TRUE; +} + +PRBool nsHTMLTagContent::DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp) +{ + return PR_TRUE; +} + +PRBool nsHTMLTagContent::GetProperty(JSContext *aContext, jsval aID, jsval *aVp) +{ + return PR_TRUE; +} + +PRBool nsHTMLTagContent::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 nsHTMLTagContent::EnumerateProperty(JSContext *aContext) +{ + return PR_TRUE; +} + +PRBool nsHTMLTagContent::Resolve(JSContext *aContext, jsval aID) +{ + return PR_TRUE; +} + +PRBool nsHTMLTagContent::Convert(JSContext *aContext, jsval aID) +{ + return PR_TRUE; +} + +void nsHTMLTagContent::Finalize(JSContext *aContext) +{ +} + +nsresult nsHTMLTagContent::SetScriptEventListener(JSContext *aContext, REFNSIID aListenerTypeIID) +{ + //First get the mScriptObject or make one if we don't have one. + nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext); + + if (nsnull == mScriptObject) { + NS_NewScriptElement(mScriptCX, this, mParent, (void**)&mScriptObject); + } + + if (nsnull != mScriptObject) { + nsIEventListenerManager *mManager; + 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; iCount(); i++) { + mEventListener = (nsIDOMEventListener*)mListeners->ElementAt(i); + if (NS_OK == mEventListener->QueryInterface(kIScriptEventListenerIID, (void**)&mScriptListener)) { + NS_RELEASE(mScriptListener); + return NS_OK; + } + } + } + //If we didn't find a script listener or no listeners existed create and add a new one. + nsIDOMEventListener *mScriptListener; + if (NS_OK == NS_NewScriptEventListener(&mScriptListener, mScriptCX, mScriptObject)) { + mManager->AddEventListener(mScriptListener, aListenerTypeIID); + return NS_OK; + } + } + } + return NS_ERROR_FAILURE; +} + // // Implementation of nsIDOMNode interface // diff --git a/mozilla/layout/html/base/src/nsHTMLTagContent.h b/mozilla/layout/html/base/src/nsHTMLTagContent.h index 9ecb322aecb..07c5bdbaee5 100644 --- a/mozilla/layout/html/base/src/nsHTMLTagContent.h +++ b/mozilla/layout/html/base/src/nsHTMLTagContent.h @@ -21,6 +21,7 @@ #include "nsHTMLContent.h" #include "nsHTMLValue.h" #include "nsIDOMElement.h" +#include "nsIJSScriptObject.h" class nsIHTMLAttributes; class nsIPresContext; @@ -29,7 +30,7 @@ class nsIStyleContext; /** * Base class for tagged html content objects, holds attributes. */ -class nsHTMLTagContent : public nsHTMLContent, public nsIDOMElement { +class nsHTMLTagContent : public nsHTMLContent, public nsIDOMElement, public nsIJSScriptObject { public: // nsIContent @@ -110,6 +111,16 @@ public: // nsIScriptObjectOwner interface NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + // 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); + // nsISupports interface NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); NS_IMETHOD_(nsrefcnt) AddRef(void); @@ -145,6 +156,7 @@ public: NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn); NS_IMETHOD Normalize(); + // nsIDOMEventReceiver interface NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, @@ -258,6 +270,8 @@ protected: const nsString& aTargetSpec, PRBool aClick); + nsresult SetScriptEventListener(JSContext *aContext, REFNSIID aListenerTypeIID); + nsIAtom* mTag; nsIHTMLAttributes* mAttributes; }; diff --git a/mozilla/layout/html/base/src/nsRootPart.cpp b/mozilla/layout/html/base/src/nsRootPart.cpp index ca7658f2b8b..81f73c03968 100644 --- a/mozilla/layout/html/base/src/nsRootPart.cpp +++ b/mozilla/layout/html/base/src/nsRootPart.cpp @@ -172,7 +172,7 @@ NS_METHOD RootFrame::HandleEvent(nsIPresContext& aPresContext, nsIFrame* target = this; PRInt32 cursor; - GetCursorAt(aPresContext, aEvent->point, &target, cursor); + GetCursorAndContentAt(aPresContext, aEvent->point, &target, &mContent, cursor); if (cursor == NS_STYLE_CURSOR_INHERIT) { cursor = NS_STYLE_CURSOR_DEFAULT; } @@ -514,9 +514,10 @@ NS_METHOD RootContentFrame::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_ENTER: { nsIFrame* target = this; + nsIContent* mTargetContent = mContent; PRInt32 cursor; - GetCursorAt(aPresContext, aEvent->point, &target, cursor); + GetCursorAndContentAt(aPresContext, aEvent->point, &target, &mTargetContent, cursor); if (cursor == NS_STYLE_CURSOR_INHERIT) { cursor = NS_STYLE_CURSOR_DEFAULT; } @@ -537,6 +538,39 @@ NS_METHOD RootContentFrame::HandleEvent(nsIPresContext& aPresContext, target->GetWindow(window); window->SetCursor(c); NS_RELEASE(window); + + //If the content object under the cursor has changed, fire a mouseover/out + nsIEventStateManager *mStateManager; + nsIContent *mLastContent; + if (NS_OK == aPresContext.GetEventStateManager(&mStateManager)) { + mStateManager->GetLastMouseOverContent(&mLastContent); + if (mLastContent != mTargetContent) { + if (nsnull != mLastContent) { + //fire mouseout + /*mLastContent->HandleDOMEvent(*/ + } + NS_IF_RELEASE(mLastContent); + //fire mouseover + /*mTargetContent->HandleDOMEvent(*/ + mStateManager->SetLastMouseOverContent(mTargetContent); + } + } + } + break; + case NS_MOUSE_EXIT: + //Don't know if this is actually hooked up. + { + //Fire of mouseout to the last content object. + nsIEventStateManager *mStateManager; + nsIContent *mLastContent; + if (NS_OK == aPresContext.GetEventStateManager(&mStateManager)) { + mStateManager->GetLastMouseOverContent(&mLastContent); + if (nsnull != mLastContent) { + //fire mouseout + /*mLastContent->HandleDOMEvent(*/ + } + NS_IF_RELEASE(mLastContent); + } } break; } diff --git a/mozilla/layout/html/base/src/nsTextContent.cpp b/mozilla/layout/html/base/src/nsTextContent.cpp index 68e84eab965..00b4d4819eb 100644 --- a/mozilla/layout/html/base/src/nsTextContent.cpp +++ b/mozilla/layout/html/base/src/nsTextContent.cpp @@ -129,9 +129,10 @@ public: NS_IMETHOD Paint(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); - NS_IMETHOD GetCursorAt(nsIPresContext& aPresContext, + NS_IMETHOD GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor); NS_IMETHOD ContentChanged(nsIPresShell* aShell, nsIPresContext* aPresContext, @@ -454,11 +455,13 @@ TextFrame::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) return nsFrame::QueryInterface(aIID, aInstancePtrResult); } -NS_METHOD TextFrame::GetCursorAt(nsIPresContext& aPresContext, +NS_METHOD TextFrame::GetCursorAndContentAt(nsIPresContext& aPresContext, const nsPoint& aPoint, nsIFrame** aFrame, + nsIContent** aContent, PRInt32& aCursor) { + *aContent = mContent; aCursor = NS_STYLE_CURSOR_IBEAM; return NS_OK; } diff --git a/mozilla/layout/html/tests/Makefile b/mozilla/layout/html/tests/Makefile index e1743f2b3a1..8754dfa3104 100644 --- a/mozilla/layout/html/tests/Makefile +++ b/mozilla/layout/html/tests/Makefile @@ -43,6 +43,7 @@ EX_LIBS = \ $(DIST)/lib/libplc21.a \ $(DIST)/lib/libplds21.a \ $(DIST)/lib/libnspr21.a \ + $(DIST)/bin/libjs.so \ $(NULL) PROGS = $(addprefix $(OBJDIR)/, $(CPPSRCS:.cpp=)) diff --git a/mozilla/layout/html/tests/makefile.win b/mozilla/layout/html/tests/makefile.win index 80a1135af99..9cd2f0d5fae 100644 --- a/mozilla/layout/html/tests/makefile.win +++ b/mozilla/layout/html/tests/makefile.win @@ -58,7 +58,8 @@ LLIBS= \ $(DIST)\lib\jsdom.lib \ $(DIST)\lib\netlib.lib \ $(LIBNSPR) \ - $(DIST)\lib\libplc21.lib + $(DIST)\lib\libplc21.lib \ + $(DIST)\lib\js3240.lib include <$(DEPTH)\layout\config\rules.mak>