From f542d90ef4e32bb00bd511f996840156ae1fdf2d Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Thu, 7 Sep 2000 01:07:29 +0000 Subject: [PATCH] Adding originalTarget to Event object. r=joki --- content/events/public/nsIPrivateDOMEvent.h | 1 + content/events/src/nsDOMEvent.cpp | 20 +++++++ content/events/src/nsDOMEvent.h | 3 + dom/public/coreEvents/nsIDOMEvent.h | 4 ++ dom/public/idl/events/Event.idl | 64 ---------------------- dom/public/nsDOMPropEnums.h | 3 +- dom/public/nsDOMPropNames.h | 1 + dom/src/base/nsGlobalWindow.cpp | 1 + dom/src/events/nsJSEvent.cpp | 23 ++++++-- layout/events/public/nsIPrivateDOMEvent.h | 1 + layout/events/src/nsDOMEvent.cpp | 20 +++++++ layout/events/src/nsDOMEvent.h | 3 + 12 files changed, 75 insertions(+), 69 deletions(-) diff --git a/content/events/public/nsIPrivateDOMEvent.h b/content/events/public/nsIPrivateDOMEvent.h index 14f97f280f9..2c12c5156fc 100644 --- a/content/events/public/nsIPrivateDOMEvent.h +++ b/content/events/public/nsIPrivateDOMEvent.h @@ -47,6 +47,7 @@ public: NS_IMETHOD DuplicatePrivateData() = 0; NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) = 0; NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aTarget) = 0; + NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aTarget) = 0; NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0; NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent) = 0; NS_IMETHOD GetRealTarget(nsIDOMEventTarget** aRealTarget) = 0; diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 4f5ef037e84..60aa9d4d5cc 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -83,6 +83,7 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsAR } mTarget = nsnull; mCurrentTarget = nsnull; + mOriginalTarget = nsnull; mText = nsnull; mTextRange = nsnull; @@ -119,6 +120,7 @@ nsDOMEvent::~nsDOMEvent() { NS_IF_RELEASE(mPresContext); NS_IF_RELEASE(mTarget); NS_IF_RELEASE(mCurrentTarget); + NS_IF_RELEASE(mOriginalTarget); NS_IF_RELEASE(mTextRange); if (mEventIsInternal) { @@ -207,6 +209,14 @@ nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) return NS_OK; } +NS_IMETHODIMP +nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget) +{ + *aOriginalTarget = mOriginalTarget; + NS_IF_ADDREF(*aOriginalTarget); + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::GetEventPhase(PRUint16* aEventPhase) { @@ -1022,6 +1032,16 @@ NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget) return NS_OK; } +NS_METHOD nsDOMEvent::SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget) +{ + if (mOriginalTarget != aOriginalTarget) { + NS_IF_RELEASE(mOriginalTarget); + NS_IF_ADDREF(aOriginalTarget); + mOriginalTarget = aOriginalTarget; + } + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::IsDispatchStopped(PRBool* aIsDispatchStopped) { diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index dcf6d665234..75fe572939a 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -99,6 +99,7 @@ public: NS_IMETHOD GetType(nsAWritableString& aType); NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget); NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget); + NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget); NS_IMETHOD GetEventPhase(PRUint16* aEventPhase); NS_IMETHOD GetBubbles(PRBool* aBubbles); NS_IMETHOD GetCancelable(PRBool* aCancelable); @@ -147,6 +148,7 @@ public: NS_IMETHOD DuplicatePrivateData(); NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget); NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget); + NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget); NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped); NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent); NS_IMETHOD GetRealTarget(nsIDOMEventTarget** aTarget); @@ -173,6 +175,7 @@ protected: nsIPresContext* mPresContext; nsIDOMEventTarget* mTarget; nsIDOMEventTarget* mCurrentTarget; + nsIDOMEventTarget* mOriginalTarget; nsString* mText; nsIPrivateTextRangeList* mTextRange; const char* GetEventName(PRUint32 aEventType); diff --git a/dom/public/coreEvents/nsIDOMEvent.h b/dom/public/coreEvents/nsIDOMEvent.h index b2c6be781fb..e592ad6d269 100644 --- a/dom/public/coreEvents/nsIDOMEvent.h +++ b/dom/public/coreEvents/nsIDOMEvent.h @@ -84,6 +84,8 @@ public: NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)=0; + NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)=0; + NS_IMETHOD GetEventPhase(PRUint16* aEventPhase)=0; NS_IMETHOD GetBubbles(PRBool* aBubbles)=0; @@ -108,6 +110,7 @@ public: NS_IMETHOD GetType(nsAWritableString& aType); \ NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget); \ NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget); \ + NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget); \ NS_IMETHOD GetEventPhase(PRUint16* aEventPhase); \ NS_IMETHOD GetBubbles(PRBool* aBubbles); \ NS_IMETHOD GetCancelable(PRBool* aCancelable); \ @@ -124,6 +127,7 @@ public: NS_IMETHOD GetType(nsAWritableString& aType) { return _to GetType(aType); } \ NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget) { return _to GetTarget(aTarget); } \ NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) { return _to GetCurrentTarget(aCurrentTarget); } \ + NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget) { return _to GetOriginalTarget(aOriginalTarget); } \ NS_IMETHOD GetEventPhase(PRUint16* aEventPhase) { return _to GetEventPhase(aEventPhase); } \ NS_IMETHOD GetBubbles(PRBool* aBubbles) { return _to GetBubbles(aBubbles); } \ NS_IMETHOD GetCancelable(PRBool* aCancelable) { return _to GetCancelable(aCancelable); } \ diff --git a/dom/public/idl/events/Event.idl b/dom/public/idl/events/Event.idl index 13b090a4c6e..e69de29bb2d 100644 --- a/dom/public/idl/events/Event.idl +++ b/dom/public/idl/events/Event.idl @@ -1,64 +0,0 @@ - interface Event { - /* IID: { 0xa66b7b80, 0xff46, 0xbd97, \ - { 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0x8a, 0xdd, 0x32 } } */ - - - const unsigned short CAPTURING_PHASE = 1; - const unsigned short AT_TARGET = 2; - const unsigned short BUBBLING_PHASE = 3; - - const int MOUSEDOWN = 0x00000001; - const int MOUSEUP = 0x00000002; - const int MOUSEOVER = 0x00000004; - const int MOUSEOUT = 0x00000008; - const int MOUSEMOVE = 0x00000010; - const int MOUSEDRAG = 0x00000020; - const int CLICK = 0x00000040; - const int DBLCLICK = 0x00000080; - const int KEYDOWN = 0x00000100; - const int KEYUP = 0x00000200; - const int KEYPRESS = 0x00000400; - const int DRAGDROP = 0x00000800; - const int FOCUS = 0x00001000; - const int BLUR = 0x00002000; - const int SELECT = 0x00004000; - const int CHANGE = 0x00008000; - const int RESET = 0x00010000; - const int SUBMIT = 0x00020000; - const int SCROLL = 0x00040000; - const int LOAD = 0x00080000; - const int UNLOAD = 0x00100000; - const int XFER_DONE = 0x00200000; - const int ABORT = 0x00400000; - const int ERROR = 0x00800000; - const int LOCATE = 0x01000000; - const int MOVE = 0x02000000; - const int RESIZE = 0x04000000; - const int FORWARD = 0x08000000; - const int HELP = 0x10000000; - const int BACK = 0x20000000; - const int TEXT = 0x40000000; - - const int ALT_MASK = 0x00000001; - const int CONTROL_MASK = 0x00000002; - const int SHIFT_MASK = 0x00000004; - const int META_MASK = 0x00000008; - - - readonly attribute wstring type; - readonly attribute EventTarget target; - readonly attribute EventTarget currentTarget; - readonly attribute unsigned short eventPhase; - readonly attribute boolean bubbles; - readonly attribute boolean cancelable; - readonly attribute unsigned longlong timeStamp; - - void stopPropagation(); - void preventBubble(); - void preventCapture(); - void preventDefault(); - void initEvent(in wstring eventTypeArg, - in boolean canBubbleArg, - in boolean cancelableArg); - }; - diff --git a/dom/public/nsDOMPropEnums.h b/dom/public/nsDOMPropEnums.h index ed18b2b7f8c..35a7f2824d9 100644 --- a/dom/public/nsDOMPropEnums.h +++ b/dom/public/nsDOMPropEnums.h @@ -294,7 +294,8 @@ enum nsDOMProp { NS_DOM_PROP_EVENT_CANCELABLE, NS_DOM_PROP_EVENT_CURRENTTARGET, NS_DOM_PROP_EVENT_EVENTPHASE, - NS_DOM_PROP_EVENT_INITEVENT, + NS_DOM_PROP_EVENT_INITEVENT, + NS_DOM_PROP_EVENT_ORIGINALTARGET, NS_DOM_PROP_EVENT_PREVENTBUBBLE, NS_DOM_PROP_EVENT_PREVENTCAPTURE, NS_DOM_PROP_EVENT_PREVENTDEFAULT, diff --git a/dom/public/nsDOMPropNames.h b/dom/public/nsDOMPropNames.h index c07f04e8b7d..1889b22f546 100644 --- a/dom/public/nsDOMPropNames.h +++ b/dom/public/nsDOMPropNames.h @@ -293,6 +293,7 @@ "event.currenttarget", \ "event.eventphase", \ "event.initevent", \ + "event.originaltarget", \ "event.preventbubble", \ "event.preventcapture", \ "event.preventdefault", \ diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 85b42ba6156..ca8e13ee781 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -20,6 +20,7 @@ * Contributor(s): * Travis Bogard * Brendan Eich + * David Hyatt (hyatt@netscape.com) */ // Local Includes diff --git a/dom/src/events/nsJSEvent.cpp b/dom/src/events/nsJSEvent.cpp index a18dedfbd67..4d38f76607e 100644 --- a/dom/src/events/nsJSEvent.cpp +++ b/dom/src/events/nsJSEvent.cpp @@ -51,10 +51,11 @@ enum Event_slots { EVENT_TYPE = -1, EVENT_TARGET = -2, EVENT_CURRENTTARGET = -3, - EVENT_EVENTPHASE = -4, - EVENT_BUBBLES = -5, - EVENT_CANCELABLE = -6, - EVENT_TIMESTAMP = -7 + EVENT_ORIGINALTARGET = -4, + EVENT_EVENTPHASE = -5, + EVENT_BUBBLES = -6, + EVENT_CANCELABLE = -7, + EVENT_TIMESTAMP = -8 }; /***********************************************************************/ @@ -115,6 +116,19 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case EVENT_ORIGINALTARGET: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_ORIGINALTARGET, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + nsIDOMEventTarget* prop; + rv = a->GetOriginalTarget(&prop); + if (NS_SUCCEEDED(rv)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); + } + } + break; + } case EVENT_EVENTPHASE: { rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_EVENTPHASE, PR_FALSE); @@ -464,6 +478,7 @@ static JSPropertySpec EventProperties[] = {"type", EVENT_TYPE, JSPROP_ENUMERATE | JSPROP_READONLY}, {"target", EVENT_TARGET, JSPROP_ENUMERATE | JSPROP_READONLY}, {"currentTarget", EVENT_CURRENTTARGET, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"originalTarget", EVENT_ORIGINALTARGET, JSPROP_ENUMERATE | JSPROP_READONLY}, {"eventPhase", EVENT_EVENTPHASE, JSPROP_ENUMERATE | JSPROP_READONLY}, {"bubbles", EVENT_BUBBLES, JSPROP_ENUMERATE | JSPROP_READONLY}, {"cancelable", EVENT_CANCELABLE, JSPROP_ENUMERATE | JSPROP_READONLY}, diff --git a/layout/events/public/nsIPrivateDOMEvent.h b/layout/events/public/nsIPrivateDOMEvent.h index 14f97f280f9..2c12c5156fc 100644 --- a/layout/events/public/nsIPrivateDOMEvent.h +++ b/layout/events/public/nsIPrivateDOMEvent.h @@ -47,6 +47,7 @@ public: NS_IMETHOD DuplicatePrivateData() = 0; NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) = 0; NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aTarget) = 0; + NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aTarget) = 0; NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0; NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent) = 0; NS_IMETHOD GetRealTarget(nsIDOMEventTarget** aRealTarget) = 0; diff --git a/layout/events/src/nsDOMEvent.cpp b/layout/events/src/nsDOMEvent.cpp index 4f5ef037e84..60aa9d4d5cc 100644 --- a/layout/events/src/nsDOMEvent.cpp +++ b/layout/events/src/nsDOMEvent.cpp @@ -83,6 +83,7 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsAR } mTarget = nsnull; mCurrentTarget = nsnull; + mOriginalTarget = nsnull; mText = nsnull; mTextRange = nsnull; @@ -119,6 +120,7 @@ nsDOMEvent::~nsDOMEvent() { NS_IF_RELEASE(mPresContext); NS_IF_RELEASE(mTarget); NS_IF_RELEASE(mCurrentTarget); + NS_IF_RELEASE(mOriginalTarget); NS_IF_RELEASE(mTextRange); if (mEventIsInternal) { @@ -207,6 +209,14 @@ nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) return NS_OK; } +NS_IMETHODIMP +nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget) +{ + *aOriginalTarget = mOriginalTarget; + NS_IF_ADDREF(*aOriginalTarget); + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::GetEventPhase(PRUint16* aEventPhase) { @@ -1022,6 +1032,16 @@ NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget) return NS_OK; } +NS_METHOD nsDOMEvent::SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget) +{ + if (mOriginalTarget != aOriginalTarget) { + NS_IF_RELEASE(mOriginalTarget); + NS_IF_ADDREF(aOriginalTarget); + mOriginalTarget = aOriginalTarget; + } + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::IsDispatchStopped(PRBool* aIsDispatchStopped) { diff --git a/layout/events/src/nsDOMEvent.h b/layout/events/src/nsDOMEvent.h index dcf6d665234..75fe572939a 100644 --- a/layout/events/src/nsDOMEvent.h +++ b/layout/events/src/nsDOMEvent.h @@ -99,6 +99,7 @@ public: NS_IMETHOD GetType(nsAWritableString& aType); NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget); NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget); + NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget); NS_IMETHOD GetEventPhase(PRUint16* aEventPhase); NS_IMETHOD GetBubbles(PRBool* aBubbles); NS_IMETHOD GetCancelable(PRBool* aCancelable); @@ -147,6 +148,7 @@ public: NS_IMETHOD DuplicatePrivateData(); NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget); NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget); + NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget); NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped); NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent); NS_IMETHOD GetRealTarget(nsIDOMEventTarget** aTarget); @@ -173,6 +175,7 @@ protected: nsIPresContext* mPresContext; nsIDOMEventTarget* mTarget; nsIDOMEventTarget* mCurrentTarget; + nsIDOMEventTarget* mOriginalTarget; nsString* mText; nsIPrivateTextRangeList* mTextRange; const char* GetEventName(PRUint32 aEventType);