diff --git a/mozilla/content/base/public/nsIContent.h b/mozilla/content/base/public/nsIContent.h index 128c507c2f6..d6a5027bd7a 100644 --- a/mozilla/content/base/public/nsIContent.h +++ b/mozilla/content/base/public/nsIContent.h @@ -30,6 +30,7 @@ class nsISizeOfHandler; class nsString; class nsString; class nsVoidArray; +class nsIDOMEvent; // IID for the nsIContent interface #define NS_ICONTENT_IID \ @@ -132,6 +133,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) = 0; }; diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 0debcc51ba8..318116d1e52 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -35,6 +35,7 @@ class nsIStyleSheet; class nsIURL; class nsIViewManager; class nsString; +class nsIDOMEvent; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ @@ -174,6 +175,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) = 0; }; diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index bcaebfc7148..e4a9f16c64f 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -704,13 +704,14 @@ nsresult nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrRe nsresult nsDocument::HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { //Capturing stage //Local handling stage if (nsnull != mListenerManager) { - mListenerManager->HandleEvent(aPresContext, aEvent, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aEventStatus); } //Bubbling stage diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 4602cece179..d7509abc13d 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -208,6 +208,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); protected: diff --git a/mozilla/content/events/public/makefile.win b/mozilla/content/events/public/makefile.win index 79adf21f959..c1fcc7bbb8d 100644 --- a/mozilla/content/events/public/makefile.win +++ b/mozilla/content/events/public/makefile.win @@ -20,6 +20,7 @@ IGNORE_MANIFEST=1 EXPORTS = \ nsIEventListenerManager.h \ + nsIEventStateManager.h \ $(NULL) MODULE=raptor diff --git a/mozilla/content/events/public/nsIEventListenerManager.h b/mozilla/content/events/public/nsIEventListenerManager.h index 7bb0213f644..f85f75d8a77 100644 --- a/mozilla/content/events/public/nsIEventListenerManager.h +++ b/mozilla/content/events/public/nsIEventListenerManager.h @@ -25,6 +25,7 @@ class nsIPresContext; class nsIDOMEventListener; +class nsIDOMEvent; /* * Event listener manager interface. @@ -66,6 +67,7 @@ public: virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) = 0; /** diff --git a/mozilla/content/events/public/nsIEventStateManager.h b/mozilla/content/events/public/nsIEventStateManager.h new file mode 100644 index 00000000000..03489f17164 --- /dev/null +++ b/mozilla/content/events/public/nsIEventStateManager.h @@ -0,0 +1,58 @@ +/* -*- 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 nsIEventStateManager_h__ +#define nsIEventStateManager_h__ + +#include "nsGUIEvent.h" +#include "nsISupports.h" +#include "nsVoidArray.h" + +class nsIPresContext; +class nsIDOMEventState; +class nsIDOMEvent; + +/* + * Event listener manager interface. + */ +#define NS_IEVENTSTATEMANAGER_IID \ +{ /* c8488290-07ce-11d2-bd88-00805f8ae3f4 */ \ +0xc8488290, 0x07ce, 0x11d2, \ +{0xbd, 0x88, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } + +class nsIEventStateManager : public nsISupports { + +public: + + /** + * Gets the current event target. + * @param + */ + + NS_IMETHOD GetEventTarget(nsISupports **aResult) = 0; + + /** + * Gets the current event target. + * @param + */ + + NS_IMETHOD SetEventTarget(nsISupports *aSupports) = 0; + +}; + +#endif // nsIEventStateManager_h__ diff --git a/mozilla/content/events/src/makefile.win b/mozilla/content/events/src/makefile.win index 218fde56372..111651d3103 100644 --- a/mozilla/content/events/src/makefile.win +++ b/mozilla/content/events/src/makefile.win @@ -22,23 +22,25 @@ include <$(DEPTH)\config\config.mak> LIBRARY_NAME=raptorevents_s MODULE=raptor -REQUIRES=xpcom raptor dom +REQUIRES=xpcom raptor dom js DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN CPPSRCS= nsEventListenerManager.cpp \ + nsEventStateManager.cpp \ nsDOMEvent.cpp \ $(NULL) CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \ + .\$(OBJDIR)\nsEventStateManager.obj \ .\$(OBJDIR)\nsDOMEvent.obj \ $(NULL) -EXPORTS= nsEventListenerManager.h +EXPORTS= nsEventListenerManager.h nsEventStateManager.h LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ - -I$(PUBLIC)\dom + -I$(PUBLIC)\dom -I$(PUBLIC)\js LCFLAGS = \ $(LCFLAGS) \ diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index 3c8119247a1..4d47b9b19c1 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -17,7 +17,9 @@ */ #include "nsDOMEvent.h" +#include "nsIDOMNode.h" +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID); static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID); @@ -56,9 +58,9 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType) return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode*& aTarget) +NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) { - return NS_ERROR_NOT_IMPLEMENTED; + return kTarget->QueryInterface(kIDOMNodeIID, (void**)aTarget); } NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX) @@ -73,33 +75,39 @@ NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY) NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX) { - return NS_ERROR_NOT_IMPLEMENTED; + //XXX these are not client coords yet + aX = kEvent->point.x; + return NS_OK; } NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY) { - return NS_ERROR_NOT_IMPLEMENTED; + //XXX these are not client coords yet + aY = kEvent->point.y; + return NS_OK; } NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown) { - return NS_ERROR_NOT_IMPLEMENTED; + aIsDown = ((nsInputEvent*)kEvent)->isAlt; + return NS_OK; } NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown) { - return NS_ERROR_NOT_IMPLEMENTED; + aIsDown = ((nsInputEvent*)kEvent)->isControl; + return NS_OK; } NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown) { - aIsDown = es.isShift; + aIsDown = ((nsInputEvent*)kEvent)->isShift; return NS_OK; } NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_OK; } NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode) @@ -109,13 +117,40 @@ NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode) NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode) { - aKeyCode = es.keyCode; + switch (kEvent->message) { + case NS_KEY_UP: + case NS_KEY_DOWN: + aKeyCode = ((nsKeyEvent*)kEvent)->keyCode; + break; + default: + return NS_ERROR_FAILURE; + break; + } return NS_OK; } NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton) { - return NS_ERROR_NOT_IMPLEMENTED; + switch (kEvent->message) { + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_LEFT_DOUBLECLICK: + aButton = 1; + break; + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + aButton = 2; + break; + case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_RIGHT_DOUBLECLICK: + aButton = 3; + break; + default: + return NS_ERROR_FAILURE; + break; + } + return NS_OK; } // nsINSEventInterface @@ -129,3 +164,14 @@ NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY) return NS_ERROR_NOT_IMPLEMENTED; } +NS_METHOD nsDOMEvent::SetGUIEvent(nsGUIEvent *aEvent) +{ + kEvent = aEvent; + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetEventTarget(nsISupports *aTarget) +{ + kTarget = aTarget; + return NS_OK; +} diff --git a/mozilla/content/events/src/nsDOMEvent.h b/mozilla/content/events/src/nsDOMEvent.h index 2d7bff8c7c1..d3b84483a7d 100644 --- a/mozilla/content/events/src/nsDOMEvent.h +++ b/mozilla/content/events/src/nsDOMEvent.h @@ -23,6 +23,8 @@ #include "nsINSEvent.h" #include "nsISupports.h" #include "nsPoint.h" +#include "nsGUIEvent.h" +class nsIContent; class nsDOMEvent : public nsIDOMEvent, public nsINSEvent { @@ -44,7 +46,7 @@ public: // nsIDOMEventInterface NS_IMETHOD GetType(nsString& aType); - NS_IMETHOD GetTarget(nsIDOMNode*& aTarget); + NS_IMETHOD GetTarget(nsIDOMNode** aTarget); NS_IMETHOD GetScreenX(PRInt32& aX); NS_IMETHOD GetScreenY(PRInt32& aY); @@ -65,22 +67,14 @@ public: NS_IMETHOD GetLayerX(PRInt32& aX); NS_IMETHOD GetLayerY(PRInt32& aY); - struct nsDOMEventStruct { - PRUint32 message; - nsPoint point; - PRUint32 time; - void* nativeMsg; - - PRBool isShift; - PRBool isControl; - PRBool isAlt; - PRUint32 clickCount; - PRUint32 keyCode; -} es; + NS_IMETHOD SetGUIEvent(nsGUIEvent *aEvent); + NS_IMETHOD SetEventTarget(nsISupports *aTarget); protected: PRUint32 mRefCnt : 31; + nsGUIEvent *kEvent; + nsISupports *kTarget; }; #endif // nsDOMEvent_h__ \ No newline at end of file diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index 47d8129f428..3e5490bf498 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -18,6 +18,7 @@ #include "nsISupports.h" #include "nsGUIEvent.h" +#include "nsIPresContext.h" #include "nsDOMEvent.h" #include "nsEventListenerManager.h" #include "nsIDOMEventListener.h" @@ -27,6 +28,7 @@ #include "nsIDOMFocusListener.h" #include "nsIDOMLoadListener.h" #include "nsIDOMDragListener.h" +#include "nsIEventStateManager.h" static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID); @@ -69,39 +71,26 @@ nsresult nsEventListenerManager::QueryInterface(const nsIID& aIID, return NS_NOINTERFACE; } -nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent) +nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, + nsIPresContext& aPresContext, + nsIDOMEvent** aDOMEvent) { + nsIEventStateManager *mManager; + nsISupports *mTarget; + nsDOMEvent* it = new nsDOMEvent(); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - - if (NS_OK == it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent)) { - switch(aGUIEvent->message) { - 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: - case NS_MOUSE_MOVE: - break; - - case NS_KEY_UP: - case NS_KEY_DOWN: - it->es.keyCode = ((nsKeyEvent*)aGUIEvent)->keyCode; - it->es.isShift = ((nsKeyEvent*)aGUIEvent)->isShift; - break; - } - - return NS_OK; + + it->SetGUIEvent(aGUIEvent); + if (NS_OK == aPresContext.GetEventStateManager(&mManager)) { + mManager->GetEventTarget(&mTarget); + NS_RELEASE(mManager); } + it->SetEventTarget(mTarget); - return NS_ERROR_FAILURE; + return it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent); } nsresult nsEventListenerManager::GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID) @@ -208,9 +197,10 @@ nsresult nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListe nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { - nsIDOMEvent *domEvent; + nsresult mRet; switch(aEvent->message) { case NS_MOUSE_LEFT_BUTTON_DOWN: @@ -218,9 +208,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_RIGHT_BUTTON_DOWN: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDown(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -230,9 +223,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_RIGHT_BUTTON_UP: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseUp(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -241,9 +237,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_RIGHT_DOUBLECLICK: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDblClick(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -251,9 +250,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_ENTER: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOver(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -261,9 +263,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_EXIT: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOut(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -271,9 +276,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_MOVE: if (nsnull != mMouseMotionListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseMotionListener*)(mMouseMotionListeners->ElementAt(i)))->MouseMove(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -281,20 +289,26 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_KEY_UP: if (nsnull != mKeyListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyDown(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyUp(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; diff --git a/mozilla/content/events/src/nsEventListenerManager.h b/mozilla/content/events/src/nsEventListenerManager.h index 638f80fbe5a..8ee56a6e66c 100644 --- a/mozilla/content/events/src/nsEventListenerManager.h +++ b/mozilla/content/events/src/nsEventListenerManager.h @@ -55,13 +55,15 @@ public: virtual nsresult CaptureEvent(nsIDOMEventListener *aListener); virtual nsresult ReleaseEvent(nsIDOMEventListener *aListener); - virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus); + virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); protected: PRUint32 mRefCnt : 31; - virtual nsresult TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent); + virtual nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, + nsIPresContext& aPresContext, + nsIDOMEvent** aDOMEvent); nsVoidArray* mEventListeners; nsVoidArray* mMouseListeners; diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp new file mode 100644 index 00000000000..67a3f2d907f --- /dev/null +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -0,0 +1,66 @@ +/* -*- 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. + */ + +#include "nsISupports.h" +#include "nsIEventStateManager.h" +#include "nsEventStateManager.h" + +static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +nsEventStateManager::nsEventStateManager() { + mEventTarget = nsnull; +} + +nsEventStateManager::~nsEventStateManager() { +} + +NS_IMPL_ADDREF(nsEventStateManager) +NS_IMPL_RELEASE(nsEventStateManager) +NS_IMPL_QUERY_INTERFACE(nsEventStateManager, kIEventStateManagerIID); + +NS_METHOD nsEventStateManager::GetEventTarget(nsISupports **aResult) +{ + NS_PRECONDITION(nsnull != aResult, "null ptr"); + if (nsnull == aResult) { + return NS_ERROR_NULL_POINTER; + } + *aResult = mEventTarget; + NS_IF_ADDREF(mEventTarget); + return NS_OK; +} + +NS_METHOD nsEventStateManager::SetEventTarget(nsISupports *aSupports) +{ + mEventTarget = aSupports; + return NS_OK; +} + +nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + nsIEventStateManager* manager = new nsEventStateManager(); + if (nsnull == manager) { + return NS_ERROR_OUT_OF_MEMORY; + } + return manager->QueryInterface(kIEventStateManagerIID, (void **) aInstancePtrResult); +} + diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h new file mode 100644 index 00000000000..bafaa090187 --- /dev/null +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -0,0 +1,52 @@ +/* -*- 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 nsEventStateManager_h__ +#define nsEventStateManager_h__ + +#include "nsIEventStateManager.h" +class nsIDOMEvent; + +/* + * Event listener manager + */ + +class nsEventStateManager : public nsIEventStateManager { + +public: + nsEventStateManager(); + virtual ~nsEventStateManager(); + + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + + NS_IMETHOD GetEventTarget(nsISupports **aResult); + NS_IMETHOD SetEventTarget(nsISupports *aSupports); + +protected: + + PRUint32 mRefCnt : 31; + + nsISupports* mEventTarget; + +}; + +extern nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult); + +#endif // nsEventStateManager_h__ diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index 73810c0512c..45f387d5c8e 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -23,6 +23,7 @@ #include "nsIImageGroup.h" #include "nsIFrame.h" #include "nsIRenderingContext.h" +#include "nsEventStateManager.h" #define NOISY_IMAGES @@ -42,6 +43,7 @@ nsPresContext::nsPresContext() mImageGroup = nsnull; mLinkHandler = nsnull; mContainer = nsnull; + mEventManager = nsnull; } nsPresContext::~nsPresContext() @@ -69,6 +71,7 @@ nsPresContext::~nsPresContext() NS_IF_RELEASE(mLinkHandler); NS_IF_RELEASE(mContainer); + NS_IF_RELEASE(mEventManager); } nsrefcnt @@ -362,3 +365,24 @@ nsPresContext::GetContainer(nsISupports** aResult) NS_IF_ADDREF(mContainer); return NS_OK; } + +NS_METHOD +nsPresContext::GetEventStateManager(nsIEventStateManager** aManager) +{ + NS_PRECONDITION(nsnull != aManager, "null ptr"); + if (nsnull == aManager) { + return NS_ERROR_NULL_POINTER; + } + + if (nsnull == mEventManager) { + nsresult rv = NS_NewEventStateManager(&mEventManager); + if (NS_OK != rv) { + return rv; + } + } + + *aManager = mEventManager; + NS_IF_ADDREF(mEventManager); + return NS_OK; +} + diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index af81806f7a4..01ddba92cf7 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -35,6 +35,7 @@ class nsIPresShell; class nsIStyleContext; class nsIAtom; class nsString; +class nsIEventStateManager; #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ @@ -157,6 +158,8 @@ public: //be sure to Relase() after you are done with the Get() virtual nsIDeviceContext * GetDeviceContext() const = 0; + + NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; }; // Bit values for LoadImage's aImageStatus diff --git a/mozilla/layout/base/public/nsIContent.h b/mozilla/layout/base/public/nsIContent.h index 128c507c2f6..d6a5027bd7a 100644 --- a/mozilla/layout/base/public/nsIContent.h +++ b/mozilla/layout/base/public/nsIContent.h @@ -30,6 +30,7 @@ class nsISizeOfHandler; class nsString; class nsString; class nsVoidArray; +class nsIDOMEvent; // IID for the nsIContent interface #define NS_ICONTENT_IID \ @@ -132,6 +133,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) = 0; }; diff --git a/mozilla/layout/base/public/nsIDocument.h b/mozilla/layout/base/public/nsIDocument.h index 0debcc51ba8..318116d1e52 100644 --- a/mozilla/layout/base/public/nsIDocument.h +++ b/mozilla/layout/base/public/nsIDocument.h @@ -35,6 +35,7 @@ class nsIStyleSheet; class nsIURL; class nsIViewManager; class nsString; +class nsIDOMEvent; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ @@ -174,6 +175,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) = 0; }; diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index af81806f7a4..01ddba92cf7 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -35,6 +35,7 @@ class nsIPresShell; class nsIStyleContext; class nsIAtom; class nsString; +class nsIEventStateManager; #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ @@ -157,6 +158,8 @@ public: //be sure to Relase() after you are done with the Get() virtual nsIDeviceContext * GetDeviceContext() const = 0; + + NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; }; // Bit values for LoadImage's aImageStatus diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index af81806f7a4..01ddba92cf7 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -35,6 +35,7 @@ class nsIPresShell; class nsIStyleContext; class nsIAtom; class nsString; +class nsIEventStateManager; #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ @@ -157,6 +158,8 @@ public: //be sure to Relase() after you are done with the Get() virtual nsIDeviceContext * GetDeviceContext() const = 0; + + NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager) = 0; }; // Bit values for LoadImage's aImageStatus diff --git a/mozilla/layout/base/src/nsDocument.cpp b/mozilla/layout/base/src/nsDocument.cpp index bcaebfc7148..e4a9f16c64f 100644 --- a/mozilla/layout/base/src/nsDocument.cpp +++ b/mozilla/layout/base/src/nsDocument.cpp @@ -704,13 +704,14 @@ nsresult nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrRe nsresult nsDocument::HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { //Capturing stage //Local handling stage if (nsnull != mListenerManager) { - mListenerManager->HandleEvent(aPresContext, aEvent, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aEventStatus); } //Bubbling stage diff --git a/mozilla/layout/base/src/nsDocument.h b/mozilla/layout/base/src/nsDocument.h index 4602cece179..d7509abc13d 100644 --- a/mozilla/layout/base/src/nsDocument.h +++ b/mozilla/layout/base/src/nsDocument.h @@ -208,6 +208,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); protected: diff --git a/mozilla/layout/base/src/nsFrame.cpp b/mozilla/layout/base/src/nsFrame.cpp index 080a5363e5b..547bfe39e0b 100644 --- a/mozilla/layout/base/src/nsFrame.cpp +++ b/mozilla/layout/base/src/nsFrame.cpp @@ -32,6 +32,7 @@ #include #include "nsIPtr.h" #include "nsISizeOfHandler.h" +#include "nsIEventStateManager.h" #define DO_SELECTION 0 @@ -533,7 +534,12 @@ NS_METHOD nsFrame::HandleEvent(nsIPresContext& aPresContext, { aEventStatus = nsEventStatus_eIgnore; - mContent->HandleDOMEvent(aPresContext, aEvent, aEventStatus); + nsIEventStateManager *mManager; + if (NS_OK == aPresContext.GetEventStateManager(&mManager)) { + mManager->SetEventTarget((nsISupports*)mContent); + NS_RELEASE(mManager); + } + mContent->HandleDOMEvent(aPresContext, aEvent, nsnull, aEventStatus); #if DO_SELECTION diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index 73810c0512c..45f387d5c8e 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -23,6 +23,7 @@ #include "nsIImageGroup.h" #include "nsIFrame.h" #include "nsIRenderingContext.h" +#include "nsEventStateManager.h" #define NOISY_IMAGES @@ -42,6 +43,7 @@ nsPresContext::nsPresContext() mImageGroup = nsnull; mLinkHandler = nsnull; mContainer = nsnull; + mEventManager = nsnull; } nsPresContext::~nsPresContext() @@ -69,6 +71,7 @@ nsPresContext::~nsPresContext() NS_IF_RELEASE(mLinkHandler); NS_IF_RELEASE(mContainer); + NS_IF_RELEASE(mEventManager); } nsrefcnt @@ -362,3 +365,24 @@ nsPresContext::GetContainer(nsISupports** aResult) NS_IF_ADDREF(mContainer); return NS_OK; } + +NS_METHOD +nsPresContext::GetEventStateManager(nsIEventStateManager** aManager) +{ + NS_PRECONDITION(nsnull != aManager, "null ptr"); + if (nsnull == aManager) { + return NS_ERROR_NULL_POINTER; + } + + if (nsnull == mEventManager) { + nsresult rv = NS_NewEventStateManager(&mEventManager); + if (NS_OK != rv) { + return rv; + } + } + + *aManager = mEventManager; + NS_IF_ADDREF(mEventManager); + return NS_OK; +} + diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index a21a92ae73e..8ebdffe1006 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -59,19 +59,21 @@ public: virtual float GetPixelsToTwips() const; virtual float GetTwipsToPixels() const; virtual nsIDeviceContext* GetDeviceContext() const; + NS_IMETHOD GetEventStateManager(nsIEventStateManager** aManager); protected: nsPresContext(); virtual ~nsPresContext(); - nsIPresShell* mShell; - nsRect mVisibleArea; - nsIDeviceContext* mDeviceContext; - nsIImageGroup* mImageGroup; - nsILinkHandler* mLinkHandler; - nsISupports* mContainer; - nsFont mDefaultFont; - nsVoidArray mImageLoaders; + nsIPresShell* mShell; + nsRect mVisibleArea; + nsIDeviceContext* mDeviceContext; + nsIImageGroup* mImageGroup; + nsILinkHandler* mLinkHandler; + nsISupports* mContainer; + nsFont mDefaultFont; + nsVoidArray mImageLoaders; + nsIEventStateManager* mEventManager; }; #endif /* nsPresContext_h___ */ diff --git a/mozilla/layout/base/tests/TestContainerFrame.cpp b/mozilla/layout/base/tests/TestContainerFrame.cpp index aa5bb3957fb..0af4c88d086 100644 --- a/mozilla/layout/base/tests/TestContainerFrame.cpp +++ b/mozilla/layout/base/tests/TestContainerFrame.cpp @@ -82,7 +82,7 @@ public: void List(FILE* out = stdout, PRInt32 aIndent = 0) const {;} NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const { return NS_OK; } - NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus) + NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) {return NS_OK;} NS_DECL_ISUPPORTS diff --git a/mozilla/layout/build/Makefile b/mozilla/layout/build/Makefile index 667ca5869db..e89aa52c65f 100644 --- a/mozilla/layout/build/Makefile +++ b/mozilla/layout/build/Makefile @@ -36,6 +36,6 @@ LOBJS = \ $(DIST)/lib/libraptorhtmlforms_s.a \ $(DIST)/lib/libraptorhtmlstyle_s.a \ $(DIST)/lib/libraptorhtmltable_s.a \ - $(DIST)/lib/libraptorevents_s.a \ + $(DIST)/lib/libraptorevents_s.a \ include $(DEPTH)/config/rules.mk diff --git a/mozilla/layout/events/public/Makefile b/mozilla/layout/events/public/Makefile index e17c0a37984..da3ff3bd61e 100644 --- a/mozilla/layout/events/public/Makefile +++ b/mozilla/layout/events/public/Makefile @@ -21,6 +21,7 @@ MODULE = raptor EXPORTS = \ nsIEventListenerManager.h \ + nsIEventStateManager.h \ $(NULL) include $(DEPTH)/config/config.mk diff --git a/mozilla/layout/events/public/makefile.win b/mozilla/layout/events/public/makefile.win index 79adf21f959..c1fcc7bbb8d 100644 --- a/mozilla/layout/events/public/makefile.win +++ b/mozilla/layout/events/public/makefile.win @@ -20,6 +20,7 @@ IGNORE_MANIFEST=1 EXPORTS = \ nsIEventListenerManager.h \ + nsIEventStateManager.h \ $(NULL) MODULE=raptor diff --git a/mozilla/layout/events/public/nsIEventListenerManager.h b/mozilla/layout/events/public/nsIEventListenerManager.h index 7bb0213f644..f85f75d8a77 100644 --- a/mozilla/layout/events/public/nsIEventListenerManager.h +++ b/mozilla/layout/events/public/nsIEventListenerManager.h @@ -25,6 +25,7 @@ class nsIPresContext; class nsIDOMEventListener; +class nsIDOMEvent; /* * Event listener manager interface. @@ -66,6 +67,7 @@ public: virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) = 0; /** diff --git a/mozilla/layout/events/public/nsIEventStateManager.h b/mozilla/layout/events/public/nsIEventStateManager.h new file mode 100644 index 00000000000..03489f17164 --- /dev/null +++ b/mozilla/layout/events/public/nsIEventStateManager.h @@ -0,0 +1,58 @@ +/* -*- 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 nsIEventStateManager_h__ +#define nsIEventStateManager_h__ + +#include "nsGUIEvent.h" +#include "nsISupports.h" +#include "nsVoidArray.h" + +class nsIPresContext; +class nsIDOMEventState; +class nsIDOMEvent; + +/* + * Event listener manager interface. + */ +#define NS_IEVENTSTATEMANAGER_IID \ +{ /* c8488290-07ce-11d2-bd88-00805f8ae3f4 */ \ +0xc8488290, 0x07ce, 0x11d2, \ +{0xbd, 0x88, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } + +class nsIEventStateManager : public nsISupports { + +public: + + /** + * Gets the current event target. + * @param + */ + + NS_IMETHOD GetEventTarget(nsISupports **aResult) = 0; + + /** + * Gets the current event target. + * @param + */ + + NS_IMETHOD SetEventTarget(nsISupports *aSupports) = 0; + +}; + +#endif // nsIEventStateManager_h__ diff --git a/mozilla/layout/events/src/Makefile b/mozilla/layout/events/src/Makefile index 447485c3396..e6a50284793 100644 --- a/mozilla/layout/events/src/Makefile +++ b/mozilla/layout/events/src/Makefile @@ -23,6 +23,7 @@ DEFINES += -D_IMPL_NS_HTML CPPSRCS = \ nsEventListenerManager.cpp \ + nsEventStateManager.cpp \ nsDOMEvent.cpp \ $(NULL) @@ -30,9 +31,10 @@ MODULE = raptor EXPORTS = \ nsEventListenerManager.h \ + nsEventStateManager.h \ $(NULL) -REQUIRES = xpcom raptor dom +REQUIRES = xpcom raptor dom js include $(DEPTH)/config/config.mk diff --git a/mozilla/layout/events/src/makefile.win b/mozilla/layout/events/src/makefile.win index 218fde56372..111651d3103 100644 --- a/mozilla/layout/events/src/makefile.win +++ b/mozilla/layout/events/src/makefile.win @@ -22,23 +22,25 @@ include <$(DEPTH)\config\config.mak> LIBRARY_NAME=raptorevents_s MODULE=raptor -REQUIRES=xpcom raptor dom +REQUIRES=xpcom raptor dom js DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN CPPSRCS= nsEventListenerManager.cpp \ + nsEventStateManager.cpp \ nsDOMEvent.cpp \ $(NULL) CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \ + .\$(OBJDIR)\nsEventStateManager.obj \ .\$(OBJDIR)\nsDOMEvent.obj \ $(NULL) -EXPORTS= nsEventListenerManager.h +EXPORTS= nsEventListenerManager.h nsEventStateManager.h LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ - -I$(PUBLIC)\dom + -I$(PUBLIC)\dom -I$(PUBLIC)\js LCFLAGS = \ $(LCFLAGS) \ diff --git a/mozilla/layout/events/src/nsDOMEvent.cpp b/mozilla/layout/events/src/nsDOMEvent.cpp index 3c8119247a1..4d47b9b19c1 100644 --- a/mozilla/layout/events/src/nsDOMEvent.cpp +++ b/mozilla/layout/events/src/nsDOMEvent.cpp @@ -17,7 +17,9 @@ */ #include "nsDOMEvent.h" +#include "nsIDOMNode.h" +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMEventIID, NS_IDOMEVENT_IID); static NS_DEFINE_IID(kINSEventIID, NS_INSEVENT_IID); @@ -56,9 +58,9 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType) return NS_ERROR_NOT_IMPLEMENTED; } -NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode*& aTarget) +NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) { - return NS_ERROR_NOT_IMPLEMENTED; + return kTarget->QueryInterface(kIDOMNodeIID, (void**)aTarget); } NS_METHOD nsDOMEvent::GetScreenX(PRInt32& aX) @@ -73,33 +75,39 @@ NS_METHOD nsDOMEvent::GetScreenY(PRInt32& aY) NS_METHOD nsDOMEvent::GetClientX(PRInt32& aX) { - return NS_ERROR_NOT_IMPLEMENTED; + //XXX these are not client coords yet + aX = kEvent->point.x; + return NS_OK; } NS_METHOD nsDOMEvent::GetClientY(PRInt32& aY) { - return NS_ERROR_NOT_IMPLEMENTED; + //XXX these are not client coords yet + aY = kEvent->point.y; + return NS_OK; } NS_METHOD nsDOMEvent::GetAltKey(PRBool& aIsDown) { - return NS_ERROR_NOT_IMPLEMENTED; + aIsDown = ((nsInputEvent*)kEvent)->isAlt; + return NS_OK; } NS_METHOD nsDOMEvent::GetCtrlKey(PRBool& aIsDown) { - return NS_ERROR_NOT_IMPLEMENTED; + aIsDown = ((nsInputEvent*)kEvent)->isControl; + return NS_OK; } NS_METHOD nsDOMEvent::GetShiftKey(PRBool& aIsDown) { - aIsDown = es.isShift; + aIsDown = ((nsInputEvent*)kEvent)->isShift; return NS_OK; } NS_METHOD nsDOMEvent::GetMetaKey(PRBool& aIsDown) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_OK; } NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode) @@ -109,13 +117,40 @@ NS_METHOD nsDOMEvent::GetCharCode(PRUint32& aCharCode) NS_METHOD nsDOMEvent::GetKeyCode(PRUint32& aKeyCode) { - aKeyCode = es.keyCode; + switch (kEvent->message) { + case NS_KEY_UP: + case NS_KEY_DOWN: + aKeyCode = ((nsKeyEvent*)kEvent)->keyCode; + break; + default: + return NS_ERROR_FAILURE; + break; + } return NS_OK; } NS_METHOD nsDOMEvent::GetButton(PRUint32& aButton) { - return NS_ERROR_NOT_IMPLEMENTED; + switch (kEvent->message) { + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_LEFT_DOUBLECLICK: + aButton = 1; + break; + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + aButton = 2; + break; + case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_RIGHT_DOUBLECLICK: + aButton = 3; + break; + default: + return NS_ERROR_FAILURE; + break; + } + return NS_OK; } // nsINSEventInterface @@ -129,3 +164,14 @@ NS_METHOD nsDOMEvent::GetLayerY(PRInt32& aY) return NS_ERROR_NOT_IMPLEMENTED; } +NS_METHOD nsDOMEvent::SetGUIEvent(nsGUIEvent *aEvent) +{ + kEvent = aEvent; + return NS_OK; +} + +NS_METHOD nsDOMEvent::SetEventTarget(nsISupports *aTarget) +{ + kTarget = aTarget; + return NS_OK; +} diff --git a/mozilla/layout/events/src/nsDOMEvent.h b/mozilla/layout/events/src/nsDOMEvent.h index 2d7bff8c7c1..d3b84483a7d 100644 --- a/mozilla/layout/events/src/nsDOMEvent.h +++ b/mozilla/layout/events/src/nsDOMEvent.h @@ -23,6 +23,8 @@ #include "nsINSEvent.h" #include "nsISupports.h" #include "nsPoint.h" +#include "nsGUIEvent.h" +class nsIContent; class nsDOMEvent : public nsIDOMEvent, public nsINSEvent { @@ -44,7 +46,7 @@ public: // nsIDOMEventInterface NS_IMETHOD GetType(nsString& aType); - NS_IMETHOD GetTarget(nsIDOMNode*& aTarget); + NS_IMETHOD GetTarget(nsIDOMNode** aTarget); NS_IMETHOD GetScreenX(PRInt32& aX); NS_IMETHOD GetScreenY(PRInt32& aY); @@ -65,22 +67,14 @@ public: NS_IMETHOD GetLayerX(PRInt32& aX); NS_IMETHOD GetLayerY(PRInt32& aY); - struct nsDOMEventStruct { - PRUint32 message; - nsPoint point; - PRUint32 time; - void* nativeMsg; - - PRBool isShift; - PRBool isControl; - PRBool isAlt; - PRUint32 clickCount; - PRUint32 keyCode; -} es; + NS_IMETHOD SetGUIEvent(nsGUIEvent *aEvent); + NS_IMETHOD SetEventTarget(nsISupports *aTarget); protected: PRUint32 mRefCnt : 31; + nsGUIEvent *kEvent; + nsISupports *kTarget; }; #endif // nsDOMEvent_h__ \ No newline at end of file diff --git a/mozilla/layout/events/src/nsEventListenerManager.cpp b/mozilla/layout/events/src/nsEventListenerManager.cpp index 47d8129f428..3e5490bf498 100644 --- a/mozilla/layout/events/src/nsEventListenerManager.cpp +++ b/mozilla/layout/events/src/nsEventListenerManager.cpp @@ -18,6 +18,7 @@ #include "nsISupports.h" #include "nsGUIEvent.h" +#include "nsIPresContext.h" #include "nsDOMEvent.h" #include "nsEventListenerManager.h" #include "nsIDOMEventListener.h" @@ -27,6 +28,7 @@ #include "nsIDOMFocusListener.h" #include "nsIDOMLoadListener.h" #include "nsIDOMDragListener.h" +#include "nsIEventStateManager.h" static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID); @@ -69,39 +71,26 @@ nsresult nsEventListenerManager::QueryInterface(const nsIID& aIID, return NS_NOINTERFACE; } -nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent) +nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, + nsIPresContext& aPresContext, + nsIDOMEvent** aDOMEvent) { + nsIEventStateManager *mManager; + nsISupports *mTarget; + nsDOMEvent* it = new nsDOMEvent(); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } - - if (NS_OK == it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent)) { - switch(aGUIEvent->message) { - 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: - case NS_MOUSE_MOVE: - break; - - case NS_KEY_UP: - case NS_KEY_DOWN: - it->es.keyCode = ((nsKeyEvent*)aGUIEvent)->keyCode; - it->es.isShift = ((nsKeyEvent*)aGUIEvent)->isShift; - break; - } - - return NS_OK; + + it->SetGUIEvent(aGUIEvent); + if (NS_OK == aPresContext.GetEventStateManager(&mManager)) { + mManager->GetEventTarget(&mTarget); + NS_RELEASE(mManager); } + it->SetEventTarget(mTarget); - return NS_ERROR_FAILURE; + return it->QueryInterface(kIDOMEventIID, (void **) aDOMEvent); } nsresult nsEventListenerManager::GetEventListeners(nsVoidArray *aListeners, const nsIID& aIID) @@ -208,9 +197,10 @@ nsresult nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListe nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { - nsIDOMEvent *domEvent; + nsresult mRet; switch(aEvent->message) { case NS_MOUSE_LEFT_BUTTON_DOWN: @@ -218,9 +208,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_RIGHT_BUTTON_DOWN: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDown(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -230,9 +223,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_RIGHT_BUTTON_UP: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseUp(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -241,9 +237,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_RIGHT_DOUBLECLICK: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseDblClick(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -251,9 +250,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_ENTER: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOver(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -261,9 +263,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_EXIT: if (nsnull != mMouseListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseListener*)(mMouseListeners->ElementAt(i)))->MouseOut(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -271,9 +276,12 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_MOVE: if (nsnull != mMouseMotionListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMMouseMotionListener*)(mMouseMotionListeners->ElementAt(i)))->MouseMove(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; } } } @@ -281,20 +289,26 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext& aPresContext, case NS_KEY_UP: if (nsnull != mKeyListeners) { for (int i=0; iCount(); i++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyDown(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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++) { - TranslateGUI2DOM(aEvent, &domEvent); - if (nsnull != domEvent && !((nsIDOMKeyListener*)(mKeyListeners->ElementAt(i)))->KeyUp(domEvent)) { - aEventStatus = nsEventStatus_eConsumeNoDefault; + 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; diff --git a/mozilla/layout/events/src/nsEventListenerManager.h b/mozilla/layout/events/src/nsEventListenerManager.h index 638f80fbe5a..8ee56a6e66c 100644 --- a/mozilla/layout/events/src/nsEventListenerManager.h +++ b/mozilla/layout/events/src/nsEventListenerManager.h @@ -55,13 +55,15 @@ public: virtual nsresult CaptureEvent(nsIDOMEventListener *aListener); virtual nsresult ReleaseEvent(nsIDOMEventListener *aListener); - virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus); + virtual nsresult HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); protected: PRUint32 mRefCnt : 31; - virtual nsresult TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, nsIDOMEvent** aDOMEvent); + virtual nsresult nsEventListenerManager::TranslateGUI2DOM(nsGUIEvent*& aGUIEvent, + nsIPresContext& aPresContext, + nsIDOMEvent** aDOMEvent); nsVoidArray* mEventListeners; nsVoidArray* mMouseListeners; diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp new file mode 100644 index 00000000000..67a3f2d907f --- /dev/null +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -0,0 +1,66 @@ +/* -*- 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. + */ + +#include "nsISupports.h" +#include "nsIEventStateManager.h" +#include "nsEventStateManager.h" + +static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +nsEventStateManager::nsEventStateManager() { + mEventTarget = nsnull; +} + +nsEventStateManager::~nsEventStateManager() { +} + +NS_IMPL_ADDREF(nsEventStateManager) +NS_IMPL_RELEASE(nsEventStateManager) +NS_IMPL_QUERY_INTERFACE(nsEventStateManager, kIEventStateManagerIID); + +NS_METHOD nsEventStateManager::GetEventTarget(nsISupports **aResult) +{ + NS_PRECONDITION(nsnull != aResult, "null ptr"); + if (nsnull == aResult) { + return NS_ERROR_NULL_POINTER; + } + *aResult = mEventTarget; + NS_IF_ADDREF(mEventTarget); + return NS_OK; +} + +NS_METHOD nsEventStateManager::SetEventTarget(nsISupports *aSupports) +{ + mEventTarget = aSupports; + return NS_OK; +} + +nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + nsIEventStateManager* manager = new nsEventStateManager(); + if (nsnull == manager) { + return NS_ERROR_OUT_OF_MEMORY; + } + return manager->QueryInterface(kIEventStateManagerIID, (void **) aInstancePtrResult); +} + diff --git a/mozilla/layout/events/src/nsEventStateManager.h b/mozilla/layout/events/src/nsEventStateManager.h new file mode 100644 index 00000000000..bafaa090187 --- /dev/null +++ b/mozilla/layout/events/src/nsEventStateManager.h @@ -0,0 +1,52 @@ +/* -*- 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 nsEventStateManager_h__ +#define nsEventStateManager_h__ + +#include "nsIEventStateManager.h" +class nsIDOMEvent; + +/* + * Event listener manager + */ + +class nsEventStateManager : public nsIEventStateManager { + +public: + nsEventStateManager(); + virtual ~nsEventStateManager(); + + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + + NS_IMETHOD GetEventTarget(nsISupports **aResult); + NS_IMETHOD SetEventTarget(nsISupports *aSupports); + +protected: + + PRUint32 mRefCnt : 31; + + nsISupports* mEventTarget; + +}; + +extern nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult); + +#endif // nsEventStateManager_h__ diff --git a/mozilla/layout/html/base/src/nsHTMLContent.cpp b/mozilla/layout/html/base/src/nsHTMLContent.cpp index 7ee60312c8e..d47e62b4f30 100644 --- a/mozilla/layout/html/base/src/nsHTMLContent.cpp +++ b/mozilla/layout/html/base/src/nsHTMLContent.cpp @@ -596,18 +596,19 @@ nsresult nsHTMLContent::RemoveEventListener(nsIDOMEventListener *aListener, cons nsresult nsHTMLContent::HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { //Capturing stage //Local handling stage if (nsnull != mListenerManager) { - mListenerManager->HandleEvent(aPresContext, aEvent, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aEventStatus); } //Bubbling stage if (mParent != nsnull) { - return mParent->HandleDOMEvent(aPresContext, aEvent, aEventStatus); + return mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aEventStatus); } return NS_OK; diff --git a/mozilla/layout/html/base/src/nsHTMLContent.h b/mozilla/layout/html/base/src/nsHTMLContent.h index 6aee0656171..afc0ee324ad 100644 --- a/mozilla/layout/html/base/src/nsHTMLContent.h +++ b/mozilla/layout/html/base/src/nsHTMLContent.h @@ -135,6 +135,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); protected: diff --git a/mozilla/layout/html/base/src/nsHTMLTagContent.cpp b/mozilla/layout/html/base/src/nsHTMLTagContent.cpp index 9d954960854..ca046805682 100644 --- a/mozilla/layout/html/base/src/nsHTMLTagContent.cpp +++ b/mozilla/layout/html/base/src/nsHTMLTagContent.cpp @@ -565,11 +565,12 @@ void nsHTMLTagContent::TriggerLink(nsIPresContext& aPresContext, nsresult nsHTMLTagContent::HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { nsresult ret = NS_OK; - ret = nsHTMLContent::HandleDOMEvent(aPresContext, aEvent, aEventStatus); + ret = nsHTMLContent::HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aEventStatus); if (NS_OK == ret && nsEventStatus_eIgnore == aEventStatus) { switch (aEvent->message) { diff --git a/mozilla/layout/html/base/src/nsHTMLTagContent.h b/mozilla/layout/html/base/src/nsHTMLTagContent.h index c6935ff7b6a..0c52507ee8c 100644 --- a/mozilla/layout/html/base/src/nsHTMLTagContent.h +++ b/mozilla/layout/html/base/src/nsHTMLTagContent.h @@ -116,6 +116,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); // Utility routines for making attribute parsing easier diff --git a/mozilla/layout/html/base/src/nsRootPart.cpp b/mozilla/layout/html/base/src/nsRootPart.cpp index b9cadd02f3e..f10a338a329 100644 --- a/mozilla/layout/html/base/src/nsRootPart.cpp +++ b/mozilla/layout/html/base/src/nsRootPart.cpp @@ -35,6 +35,7 @@ #include "nsStyleConsts.h" #include "nsIViewManager.h" #include "nsHTMLAtoms.h" +#include "nsIEventStateManager.h" class RootFrame : public nsContainerFrame { public: @@ -150,41 +151,48 @@ NS_METHOD RootFrame::HandleEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsEventStatus& aEventStatus) { - mContent->HandleDOMEvent(aPresContext, aEvent, aEventStatus); + nsIEventStateManager *mManager; + + if (NS_OK == aPresContext.GetEventStateManager(&mManager)) { + mManager->SetEventTarget((nsISupports*)mContent); + NS_RELEASE(mManager); + } + mContent->HandleDOMEvent(aPresContext, aEvent, nsnull, aEventStatus); - switch (aEvent->message) { - case NS_MOUSE_MOVE: - case NS_MOUSE_ENTER: - { - nsIFrame* target = this; - PRInt32 cursor; + if (aEventStatus != nsEventStatus_eConsumeNoDefault) { + switch (aEvent->message) { + case NS_MOUSE_MOVE: + case NS_MOUSE_ENTER: + { + nsIFrame* target = this; + PRInt32 cursor; - GetCursorAt(aPresContext, aEvent->point, &target, cursor); - if (cursor == NS_STYLE_CURSOR_INHERIT) { - cursor = NS_STYLE_CURSOR_DEFAULT; + GetCursorAt(aPresContext, aEvent->point, &target, cursor); + if (cursor == NS_STYLE_CURSOR_INHERIT) { + cursor = NS_STYLE_CURSOR_DEFAULT; + } + nsCursor c; + switch (cursor) { + default: + case NS_STYLE_CURSOR_DEFAULT: + c = eCursor_standard; + break; + case NS_STYLE_CURSOR_HAND: + c = eCursor_hyperlink; + break; + case NS_STYLE_CURSOR_IBEAM: + c = eCursor_select; + break; + } + nsIWidget* window; + target->GetWindow(window); + window->SetCursor(c); + NS_RELEASE(window); } - nsCursor c; - switch (cursor) { - default: - case NS_STYLE_CURSOR_DEFAULT: - c = eCursor_standard; - break; - case NS_STYLE_CURSOR_HAND: - c = eCursor_hyperlink; - break; - case NS_STYLE_CURSOR_IBEAM: - c = eCursor_select; - break; - } - nsIWidget* window; - target->GetWindow(window); - window->SetCursor(c); - NS_RELEASE(window); + break; } - break; } - aEventStatus = nsEventStatus_eIgnore; return NS_OK; } @@ -470,6 +478,7 @@ public: NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); @@ -507,9 +516,10 @@ RootPart::CreateFrame(nsIPresContext* aPresContext, nsresult RootPart::HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, + nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) { - return mDocument->HandleDOMEvent(aPresContext, aEvent, aEventStatus); + return mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aEventStatus); } nsresult