From 878a4d9d580e5fb81b7ceb9572a6b6cdc4f292dd Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Thu, 6 Apr 2000 22:32:36 +0000 Subject: [PATCH] Fixing an XBL event handling bug and a menu shortcut bug. r=brendan, a=leaf --- dom/public/nsIJSEventListener.h | 2 ++ dom/src/events/nsJSEventListener.cpp | 20 ++++++++++++++++---- dom/src/events/nsJSEventListener.h | 5 +++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/dom/public/nsIJSEventListener.h b/dom/public/nsIJSEventListener.h index 6497fbc454f5..eba30f6b6465 100644 --- a/dom/public/nsIJSEventListener.h +++ b/dom/public/nsIJSEventListener.h @@ -29,6 +29,7 @@ class nsIScriptContext; class nsIScriptObjectOwner; class nsIDOMEventListener; +class nsString; #define NS_IJSEVENTLISTENER_IID \ { 0xa6cf9118, 0x15b3, 0x11d2, \ @@ -41,6 +42,7 @@ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJSEVENTLISTENER_IID) NS_IMETHOD GetEventTarget(nsIScriptContext** aContext, nsIScriptObjectOwner** aOwner) = 0; + NS_IMETHOD SetEventName(nsIAtom* aName) = 0; }; extern "C" NS_DOM nsresult NS_NewJSEventListener(nsIDOMEventListener ** aInstancePtrResult, nsIScriptContext *aContext, nsIScriptObjectOwner* aOwner); diff --git a/dom/src/events/nsJSEventListener.cpp b/dom/src/events/nsJSEventListener.cpp index a531714c5205..137bcadc5e95 100644 --- a/dom/src/events/nsJSEventListener.cpp +++ b/dom/src/events/nsJSEventListener.cpp @@ -80,6 +80,12 @@ NS_IMPL_RELEASE(nsJSEventListener) //static nsString onPrefix = "on"; +nsresult nsJSEventListener::SetEventName(nsIAtom* aName) +{ + mEventName = aName; + return NS_OK; +} + nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) { jsval funval; @@ -94,12 +100,18 @@ nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) JSObject* obj; nsresult result = NS_OK; - if (NS_OK != aEvent->GetType(eventString)) { - //JS can't handle this event yet or can't handle it at all - return NS_OK; + if (!mEventName) { + if (NS_OK != aEvent->GetType(eventString)) { + //JS can't handle this event yet or can't handle it at all + return NS_OK; + } + + eventString.InsertWithConversion("on", 0, 2); + } + else { + mEventName->ToString(eventString); } - eventString.InsertWithConversion("on", 0, 2); eventChars = eventString.ToNewCString(); result = mOwner->GetScriptObject(mContext, (void**)&obj); diff --git a/dom/src/events/nsJSEventListener.h b/dom/src/events/nsJSEventListener.h index 3c0e366ec9f0..525058ca3db2 100644 --- a/dom/src/events/nsJSEventListener.h +++ b/dom/src/events/nsJSEventListener.h @@ -28,6 +28,8 @@ #include "nsIJSEventListener.h" #include "nsIDOMMouseListener.h" #include "jsapi.h" +#include "nsCOMPtr.h" +#include "nsIAtom.h" //nsIDOMMouseListener interface class nsJSEventListener : public nsIDOMEventListener, @@ -45,9 +47,12 @@ public: //nsIJSEventListener interface NS_IMETHOD GetEventTarget(nsIScriptContext** aContext, nsIScriptObjectOwner** aOwner); + NS_IMETHOD SetEventName(nsIAtom* aName); + protected: nsIScriptContext* mContext; nsIScriptObjectOwner* mOwner; + nsCOMPtr mEventName; };