From 76afffebc92c207cedb9b11d5147dce6ab45dca9 Mon Sep 17 00:00:00 2001 From: "joki%netscape.com" Date: Thu, 19 Nov 1998 03:20:21 +0000 Subject: [PATCH] Adding more backwards compat DOM support (event.which, pageX, and pageY) --- content/events/src/nsDOMEvent.cpp | 44 ++++++++ content/events/src/nsDOMEvent.h | 9 ++ dom/public/coreEvents/nsIDOMNSEvent.h | 21 ++++ dom/public/idl/events/Event.idl | 7 +- dom/src/events/nsJSEvent.cpp | 143 +++++++++++++++++++++++++- layout/events/src/nsDOMEvent.cpp | 44 ++++++++ layout/events/src/nsDOMEvent.h | 9 ++ 7 files changed, 274 insertions(+), 3 deletions(-) diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 2607813d418..1db6f10df1b 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -306,6 +306,50 @@ NS_METHOD nsDOMEvent::SetLayerY(PRInt32 aLayerY) return NS_ERROR_NOT_IMPLEMENTED; } +NS_METHOD nsDOMEvent::GetPageX(PRInt32* aPageX) +{ + return GetClientX(aPageX); +} + +NS_METHOD nsDOMEvent::SetPageX(PRInt32 aPageX) +{ + return SetClientX(aPageX); +} + +NS_METHOD nsDOMEvent::GetPageY(PRInt32* aPageY) +{ + return GetClientY(aPageY); +} + +NS_METHOD nsDOMEvent::SetPageY(PRInt32 aPageY) +{ + return SetClientY(aPageY); +} + +NS_METHOD nsDOMEvent::GetWhich(PRUint32* aWhich) +{ + switch (mEvent->eventStructType) { + case NS_KEY_EVENT: + return GetKeyCode(aWhich); + break; + case NS_MOUSE_EVENT: + return GetButton(aWhich); + break; + } +} + +NS_METHOD nsDOMEvent::SetWhich(PRUint32 aWhich) +{ + switch (mEvent->eventStructType) { + case NS_KEY_EVENT: + return SetKeyCode(aWhich); + break; + case NS_MOUSE_EVENT: + return SetButton(aWhich); + break; + } +} + NS_METHOD nsDOMEvent::DuplicatePrivateData() { //XXX Write me! diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index 953e08e2925..349a32e3433 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -117,6 +117,15 @@ public: NS_IMETHOD GetLayerY(PRInt32* aLayerY); NS_IMETHOD SetLayerY(PRInt32 aLayerY); + NS_IMETHOD GetPageX(PRInt32* aClientX); + NS_IMETHOD SetPageX(PRInt32 aClientX); + + NS_IMETHOD GetPageY(PRInt32* aClientY); + NS_IMETHOD SetPageY(PRInt32 aClientY); + + NS_IMETHOD GetWhich(PRUint32* aKeyCode); + NS_IMETHOD SetWhich(PRUint32 aKeyCode); + NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc); // nsIPrivateDOMEvent interface diff --git a/dom/public/coreEvents/nsIDOMNSEvent.h b/dom/public/coreEvents/nsIDOMNSEvent.h index 5a63a234c4a..dea5f397a02 100644 --- a/dom/public/coreEvents/nsIDOMNSEvent.h +++ b/dom/public/coreEvents/nsIDOMNSEvent.h @@ -75,6 +75,15 @@ public: NS_IMETHOD GetLayerY(PRInt32* aLayerY)=0; NS_IMETHOD SetLayerY(PRInt32 aLayerY)=0; + NS_IMETHOD GetPageX(PRInt32* aPageX)=0; + NS_IMETHOD SetPageX(PRInt32 aPageX)=0; + + NS_IMETHOD GetPageY(PRInt32* aPageY)=0; + NS_IMETHOD SetPageY(PRInt32 aPageY)=0; + + NS_IMETHOD GetWhich(PRUint32* aWhich)=0; + NS_IMETHOD SetWhich(PRUint32 aWhich)=0; + NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc)=0; }; @@ -84,6 +93,12 @@ public: NS_IMETHOD SetLayerX(PRInt32 aLayerX); \ NS_IMETHOD GetLayerY(PRInt32* aLayerY); \ NS_IMETHOD SetLayerY(PRInt32 aLayerY); \ + NS_IMETHOD GetPageX(PRInt32* aPageX); \ + NS_IMETHOD SetPageX(PRInt32 aPageX); \ + NS_IMETHOD GetPageY(PRInt32* aPageY); \ + NS_IMETHOD SetPageY(PRInt32 aPageY); \ + NS_IMETHOD GetWhich(PRUint32* aWhich); \ + NS_IMETHOD SetWhich(PRUint32 aWhich); \ NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc); \ @@ -93,6 +108,12 @@ public: NS_IMETHOD SetLayerX(PRInt32 aLayerX) { return _to##SetLayerX(aLayerX); } \ NS_IMETHOD GetLayerY(PRInt32* aLayerY) { return _to##GetLayerY(aLayerY); } \ NS_IMETHOD SetLayerY(PRInt32 aLayerY) { return _to##SetLayerY(aLayerY); } \ + NS_IMETHOD GetPageX(PRInt32* aPageX) { return _to##GetPageX(aPageX); } \ + NS_IMETHOD SetPageX(PRInt32 aPageX) { return _to##SetPageX(aPageX); } \ + NS_IMETHOD GetPageY(PRInt32* aPageY) { return _to##GetPageY(aPageY); } \ + NS_IMETHOD SetPageY(PRInt32 aPageY) { return _to##SetPageY(aPageY); } \ + NS_IMETHOD GetWhich(PRUint32* aWhich) { return _to##GetWhich(aWhich); } \ + NS_IMETHOD SetWhich(PRUint32 aWhich) { return _to##SetWhich(aWhich); } \ NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc) { return _to##GetRc(aRc); } \ diff --git a/dom/public/idl/events/Event.idl b/dom/public/idl/events/Event.idl index c6664f04daa..5d34dcc35e4 100644 --- a/dom/public/idl/events/Event.idl +++ b/dom/public/idl/events/Event.idl @@ -183,8 +183,11 @@ const int EVENT_SHIFT_MASK = 0x00000004; const int EVENT_META_MASK = 0x00000008; - attribute int layerX; - attribute int layerY; + attribute int layerX; + attribute int layerY; + attribute int pageX; + attribute int pageY; + attribute unsigned long which; readonly attribute RenderingContext rc; }; diff --git a/dom/src/events/nsJSEvent.cpp b/dom/src/events/nsJSEvent.cpp index 6edf92a2571..d440f7fc585 100644 --- a/dom/src/events/nsJSEvent.cpp +++ b/dom/src/events/nsJSEvent.cpp @@ -64,7 +64,10 @@ enum Event_slots { EVENT_BUTTON = -14, NSEVENT_LAYERX = -15, NSEVENT_LAYERY = -16, - NSEVENT_RC = -17 + NSEVENT_PAGEX = -17, + NSEVENT_PAGEY = -18, + NSEVENT_WHICH = -19, + NSEVENT_RC = -20 }; /***********************************************************************/ @@ -295,6 +298,66 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case NSEVENT_PAGEX: + { + PRInt32 prop; + nsIDOMNSEvent* b; + if (NS_OK == a->QueryInterface(kINSEventIID, (void **)&b)) { + if(NS_OK == b->GetPageX(&prop)) { + *vp = INT_TO_JSVAL(prop); + NS_RELEASE(b); + } + else { + NS_RELEASE(b); + return JS_FALSE; + } + } + else { + JS_ReportError(cx, "Object must be of type NSEvent"); + return JS_FALSE; + } + break; + } + case NSEVENT_PAGEY: + { + PRInt32 prop; + nsIDOMNSEvent* b; + if (NS_OK == a->QueryInterface(kINSEventIID, (void **)&b)) { + if(NS_OK == b->GetPageY(&prop)) { + *vp = INT_TO_JSVAL(prop); + NS_RELEASE(b); + } + else { + NS_RELEASE(b); + return JS_FALSE; + } + } + else { + JS_ReportError(cx, "Object must be of type NSEvent"); + return JS_FALSE; + } + break; + } + case NSEVENT_WHICH: + { + PRUint32 prop; + nsIDOMNSEvent* b; + if (NS_OK == a->QueryInterface(kINSEventIID, (void **)&b)) { + if(NS_OK == b->GetWhich(&prop)) { + *vp = INT_TO_JSVAL(prop); + NS_RELEASE(b); + } + else { + NS_RELEASE(b); + return JS_FALSE; + } + } + else { + JS_ReportError(cx, "Object must be of type NSEvent"); + return JS_FALSE; + } + break; + } case NSEVENT_RC: { nsIDOMRenderingContext* prop; @@ -652,6 +715,81 @@ SetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) break; } + case NSEVENT_PAGEX: + { + PRInt32 prop; + int32 temp; + if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) { + prop = (PRInt32)temp; + } + else { + JS_ReportError(cx, "Parameter must be a number"); + return JS_FALSE; + } + + nsIDOMNSEvent *b; + if (NS_OK == a->QueryInterface(kINSEventIID, (void **)&b)) { + b->SetPageX(prop); + NS_RELEASE(b); + } + else { + + JS_ReportError(cx, "Object must be of type NSEvent"); + return JS_FALSE; + } + + break; + } + case NSEVENT_PAGEY: + { + PRInt32 prop; + int32 temp; + if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) { + prop = (PRInt32)temp; + } + else { + JS_ReportError(cx, "Parameter must be a number"); + return JS_FALSE; + } + + nsIDOMNSEvent *b; + if (NS_OK == a->QueryInterface(kINSEventIID, (void **)&b)) { + b->SetPageY(prop); + NS_RELEASE(b); + } + else { + + JS_ReportError(cx, "Object must be of type NSEvent"); + return JS_FALSE; + } + + break; + } + case NSEVENT_WHICH: + { + PRUint32 prop; + int32 temp; + if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) { + prop = (PRUint32)temp; + } + else { + JS_ReportError(cx, "Parameter must be a number"); + return JS_FALSE; + } + + nsIDOMNSEvent *b; + if (NS_OK == a->QueryInterface(kINSEventIID, (void **)&b)) { + b->SetWhich(prop); + NS_RELEASE(b); + } + else { + + JS_ReportError(cx, "Object must be of type NSEvent"); + return JS_FALSE; + } + + break; + } default: { nsIJSScriptObject *object; @@ -778,6 +916,9 @@ static JSPropertySpec EventProperties[] = {"button", EVENT_BUTTON, JSPROP_ENUMERATE}, {"layerX", NSEVENT_LAYERX, JSPROP_ENUMERATE}, {"layerY", NSEVENT_LAYERY, JSPROP_ENUMERATE}, + {"pageX", NSEVENT_PAGEX, JSPROP_ENUMERATE}, + {"pageY", NSEVENT_PAGEY, JSPROP_ENUMERATE}, + {"which", NSEVENT_WHICH, JSPROP_ENUMERATE}, {"rc", NSEVENT_RC, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/layout/events/src/nsDOMEvent.cpp b/layout/events/src/nsDOMEvent.cpp index 2607813d418..1db6f10df1b 100644 --- a/layout/events/src/nsDOMEvent.cpp +++ b/layout/events/src/nsDOMEvent.cpp @@ -306,6 +306,50 @@ NS_METHOD nsDOMEvent::SetLayerY(PRInt32 aLayerY) return NS_ERROR_NOT_IMPLEMENTED; } +NS_METHOD nsDOMEvent::GetPageX(PRInt32* aPageX) +{ + return GetClientX(aPageX); +} + +NS_METHOD nsDOMEvent::SetPageX(PRInt32 aPageX) +{ + return SetClientX(aPageX); +} + +NS_METHOD nsDOMEvent::GetPageY(PRInt32* aPageY) +{ + return GetClientY(aPageY); +} + +NS_METHOD nsDOMEvent::SetPageY(PRInt32 aPageY) +{ + return SetClientY(aPageY); +} + +NS_METHOD nsDOMEvent::GetWhich(PRUint32* aWhich) +{ + switch (mEvent->eventStructType) { + case NS_KEY_EVENT: + return GetKeyCode(aWhich); + break; + case NS_MOUSE_EVENT: + return GetButton(aWhich); + break; + } +} + +NS_METHOD nsDOMEvent::SetWhich(PRUint32 aWhich) +{ + switch (mEvent->eventStructType) { + case NS_KEY_EVENT: + return SetKeyCode(aWhich); + break; + case NS_MOUSE_EVENT: + return SetButton(aWhich); + break; + } +} + NS_METHOD nsDOMEvent::DuplicatePrivateData() { //XXX Write me! diff --git a/layout/events/src/nsDOMEvent.h b/layout/events/src/nsDOMEvent.h index 953e08e2925..349a32e3433 100644 --- a/layout/events/src/nsDOMEvent.h +++ b/layout/events/src/nsDOMEvent.h @@ -117,6 +117,15 @@ public: NS_IMETHOD GetLayerY(PRInt32* aLayerY); NS_IMETHOD SetLayerY(PRInt32 aLayerY); + NS_IMETHOD GetPageX(PRInt32* aClientX); + NS_IMETHOD SetPageX(PRInt32 aClientX); + + NS_IMETHOD GetPageY(PRInt32* aClientY); + NS_IMETHOD SetPageY(PRInt32 aClientY); + + NS_IMETHOD GetWhich(PRUint32* aKeyCode); + NS_IMETHOD SetWhich(PRUint32 aKeyCode); + NS_IMETHOD GetRc(nsIDOMRenderingContext** aRc); // nsIPrivateDOMEvent interface