From ec91adc761bbe9cbd772533444eaccc3cc455efd Mon Sep 17 00:00:00 2001 From: "joki%netscape.com" Date: Tue, 16 May 2000 11:35:12 +0000 Subject: [PATCH] Updating mozilla to DOM Level 2 events support. Fixes for bug 34722, 35378, 8411, 10330, plus some others that weren't filed. git-svn-id: svn://10.0.0.236/trunk@70028 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocument.cpp | 66 ++++- mozilla/content/base/src/nsDocument.h | 6 + .../content/base/src/nsGenericDOMDataNode.cpp | 20 +- .../content/base/src/nsGenericDOMDataNode.h | 6 +- mozilla/content/base/src/nsGenericElement.cpp | 19 +- .../events/public/nsIEventListenerManager.h | 9 + .../events/public/nsIEventStateManager.h | 2 + .../events/public/nsIPrivateDOMEvent.h | 10 +- mozilla/content/events/src/nsDOMEvent.cpp | 264 ++++++++++++++---- mozilla/content/events/src/nsDOMEvent.h | 19 +- .../events/src/nsEventListenerManager.cpp | 103 +++++-- .../events/src/nsEventListenerManager.h | 12 +- .../events/src/nsEventStateManager.cpp | 30 +- .../content/events/src/nsEventStateManager.h | 3 + .../html/content/src/nsHTMLLabelElement.cpp | 2 +- .../content/xml/content/src/nsXMLEntity.cpp | 2 +- .../content/xml/content/src/nsXMLNotation.cpp | 2 +- .../src/nsXMLProcessingInstruction.cpp | 2 +- .../content/xul/content/src/nsXULElement.cpp | 36 ++- .../content/xul/content/src/nsXULElement.h | 1 + .../xul/content/src/nsXULPopupListener.cpp | 18 +- .../document/src/nsXULCommandDispatcher.cpp | 5 +- .../xul/document/src/nsXULDocument.cpp | 61 +++- .../content/xul/document/src/nsXULDocument.h | 6 + mozilla/docshell/base/nsDocShell.cpp | 2 +- mozilla/dom/public/base/nsIDOMAbstractView.h | 2 +- mozilla/dom/public/coreDom/MANIFEST | 1 + mozilla/dom/public/coreDom/Makefile.in | 1 + mozilla/dom/public/coreDom/makefile.win | 1 + .../dom/public/coreDom/nsIDOMDocumentEvent.h | 54 ++++ mozilla/dom/public/coreEvents/nsIDOMEvent.h | 22 +- .../dom/public/coreEvents/nsIDOMEventTarget.h | 5 + .../dom/public/coreEvents/nsIDOMMouseEvent.h | 12 +- mozilla/dom/public/idl/base/Window.idl | 1 + mozilla/dom/public/idl/coreDom/Document.idl | 8 + mozilla/dom/public/idl/coreDom/Node.idl | 3 +- mozilla/dom/public/idl/events/Event.idl | 14 +- .../dom/public/idl/events/MouseKeyEvent.idl | 5 +- mozilla/dom/public/nsDOMPropEnums.h | 9 +- mozilla/dom/public/nsDOMPropNames.h | 9 +- mozilla/dom/src/base/nsGlobalWindow.cpp | 40 ++- mozilla/dom/src/base/nsGlobalWindow.h | 1 + mozilla/dom/src/base/nsJSWindow.cpp | 57 +++- mozilla/dom/src/coreDOM/nsJSDocument.cpp | 52 ++++ mozilla/dom/src/coreDOM/nsJSNode.cpp | 55 ++++ mozilla/dom/src/events/nsJSEvent.cpp | 70 ++++- mozilla/dom/src/events/nsJSKeyEvent.cpp | 37 +-- mozilla/dom/tools/FileGen.cpp | 18 ++ mozilla/dom/tools/IdlInterface.cpp | 2 + mozilla/dom/tools/IdlParser.cpp | 24 ++ mozilla/dom/tools/IdlScanner.cpp | 27 +- mozilla/dom/tools/IdlScanner.h | 2 + mozilla/dom/tools/IdlVariable.cpp | 10 + mozilla/dom/tools/IdlVariable.h | 2 + mozilla/dom/tools/JSStubGen.cpp | 8 + .../base/nsEditorShellMouseListener.cpp | 13 +- .../src/nsEditorShellMouseListener.cpp | 13 +- .../ui/dialogs/content/EdImageMapShapes.js | 4 +- .../extensions/xmlterm/ui/XMLTermCommands.js | 4 +- mozilla/layout/base/nsPresShell.cpp | 23 +- mozilla/layout/base/src/nsDocument.cpp | 66 ++++- mozilla/layout/base/src/nsDocument.h | 6 + .../layout/base/src/nsGenericDOMDataNode.cpp | 20 +- .../layout/base/src/nsGenericDOMDataNode.h | 6 +- mozilla/layout/base/src/nsGenericElement.cpp | 19 +- .../events/public/nsIEventListenerManager.h | 9 + .../events/public/nsIEventStateManager.h | 2 + .../layout/events/public/nsIPrivateDOMEvent.h | 10 +- mozilla/layout/events/src/nsDOMEvent.cpp | 264 ++++++++++++++---- mozilla/layout/events/src/nsDOMEvent.h | 19 +- .../events/src/nsEventListenerManager.cpp | 103 +++++-- .../events/src/nsEventListenerManager.h | 12 +- .../layout/events/src/nsEventStateManager.cpp | 30 +- .../layout/events/src/nsEventStateManager.h | 3 + mozilla/layout/forms/nsListControlFrame.cpp | 12 +- mozilla/layout/html/base/src/nsPresShell.cpp | 23 +- .../html/content/src/nsHTMLLabelElement.cpp | 2 +- .../html/forms/src/nsGfxListControlFrame.cpp | 12 +- .../html/forms/src/nsGfxTextControlFrame.cpp | 4 +- .../html/forms/src/nsListControlFrame.cpp | 12 +- .../html/table/src/nsTableOuterFrame.cpp | 9 + mozilla/layout/tables/nsTableOuterFrame.cpp | 9 + .../xml/content/src/nsXMLDocumentType.cpp | 2 +- .../layout/xml/content/src/nsXMLEntity.cpp | 2 +- .../layout/xml/content/src/nsXMLNotation.cpp | 2 +- .../src/nsXMLProcessingInstruction.cpp | 2 +- .../xul/base/src/nsToolbarDragListener.cpp | 12 +- .../xul/base/src/nsToolbarDragListener.h | 1 + .../xul/base/src/nsTreeItemDragCapturer.cpp | 21 +- .../xul/base/src/nsTreeTwistyListener.cpp | 3 +- .../content/abResultsTreeOverlay.xul | 2 +- .../resources/content/msgMail3PaneWindow.js | 4 +- .../base/resources/content/subscribe.js | 2 +- .../resources/content/profileManager.js | 2 +- .../content/src/nsXULCommandDispatcher.cpp | 5 +- mozilla/rdf/content/src/nsXULDocument.cpp | 61 +++- mozilla/rdf/content/src/nsXULDocument.h | 6 + mozilla/rdf/content/src/nsXULElement.cpp | 36 ++- mozilla/rdf/content/src/nsXULElement.h | 1 + mozilla/rdf/content/src/nsXULKeyListener.cpp | 3 +- .../rdf/content/src/nsXULPopupListener.cpp | 18 +- mozilla/view/public/nsIScrollableView.h | 2 +- mozilla/view/src/nsScrollPortView.cpp | 7 +- mozilla/view/src/nsScrollPortView.h | 2 +- mozilla/view/src/nsScrollingView.cpp | 72 +++-- mozilla/view/src/nsScrollingView.h | 2 +- .../webshell/tests/viewer/nsBaseDialog.cpp | 17 +- .../webshell/tests/viewer/nsFindDialog.cpp | 14 +- .../tests/viewer/nsImageInspectorDialog.cpp | 21 +- .../tests/viewer/nsPrintSetupDialog.cpp | 18 +- .../tests/viewer/nsTableInspectorDialog.cpp | 19 +- mozilla/widget/public/nsGUIEvent.h | 2 + .../components/bookmarks/resources/bm-find.js | 2 +- .../bookmarks/resources/bm-panel.js | 2 +- .../bookmarks/resources/bookmarks.js | 2 +- .../xpfe/components/directory/directory.js | 2 +- .../filepicker/res/content/filepicker.js | 2 +- .../components/history/resources/history.xul | 2 +- .../related/resources/related-panel.js | 2 +- .../search/resources/findresults.xul | 2 +- .../search/resources/internetresults.xul | 2 +- .../search/resources/search-panel.js | 2 +- 122 files changed, 1861 insertions(+), 487 deletions(-) create mode 100644 mozilla/dom/public/coreDom/nsIDOMDocumentEvent.h diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index f287b576077..742c2982c76 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -688,6 +688,12 @@ nsresult nsDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIDOMDocumentEvent))) { + nsIDOMDocumentEvent* tmp = this; + *aInstancePtr = (void*) tmp; + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(NS_GET_IID(nsIDOMDocumentStyle))) { nsIDOMDocumentStyle* tmp = this; *aInstancePtr = (void*) tmp; @@ -2628,7 +2634,7 @@ nsresult nsDocument::GetNewListenerManager(nsIEventListenerManager **aInstancePt nsresult nsDocument::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, @@ -2640,9 +2646,10 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, nsresult mRet = NS_OK; nsIDOMEvent* mDOMEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &mDOMEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); } //Capturing stage @@ -2651,9 +2658,10 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Local handling stage - if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { + if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && + !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -2662,7 +2670,7 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, release here. if (nsnull != *aDOMEvent) { nsrefcnt rc; @@ -2731,6 +2739,52 @@ nsresult nsDocument::RemoveEventListener(const nsString& aType, nsIDOMEventListe return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsDocument::DispatchEvent(nsIDOMEvent* aEvent) +{ + // Obtain a presentation context + PRInt32 count = GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(GetShellAt(0)); + + // Retrieve the context + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent((nsISupports *)(nsIDOMDocument *)this, aEvent); + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsDocument::CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn) +{ + // Obtain a presentation context + PRInt32 count = GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(GetShellAt(0)); + + // Retrieve the context + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + + if (presContext) { + nsCOMPtr lm; + if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(lm)))) { + return lm->CreateEvent(presContext, nsnull, aEventType, aReturn); + } + } + + return NS_ERROR_FAILURE; +} + PRBool nsDocument::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) { return PR_TRUE; diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 5004723cfa8..0d184090494 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -42,6 +42,7 @@ #include "nsIPrincipal.h" #include "nsIBindingManager.h" #include "nsINodeInfo.h" +#include "nsIDOMDocumentEvent.h" class nsIEventListenerManager; class nsDOMStyleSheetList; @@ -113,6 +114,7 @@ protected: class nsDocument : public nsIDocument, public nsIDOMDocument, public nsIDOMNSDocument, + public nsIDOMDocumentEvent, public nsIDOMDocumentStyle, public nsIDOMDocumentView, public nsIDiskDocument, @@ -371,6 +373,9 @@ public: // nsIDOMDocumentView NS_DECL_IDOMDOCUMENTVIEW + // nsIDOMDocumentEvent + NS_DECL_IDOMDOCUMENTEVENT + // nsIDOMEventReceiver interface NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); @@ -397,6 +402,7 @@ public: PRBool aUseCapture); NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index d296e2e6766..21e76bf7f81 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -71,7 +71,10 @@ nsGenericDOMDataNode::nsGenericDOMDataNode() nsGenericDOMDataNode::~nsGenericDOMDataNode() { - NS_IF_RELEASE(mListenerManager); + if (mListenerManager) { + mListenerManager->SetListenerTarget(nsnull); + NS_RELEASE(mListenerManager); + } delete mRangeList; } @@ -529,7 +532,7 @@ nsGenericDOMDataNode::SetScriptObject(void *aScriptObject) //---------------------------------------------------------------------- nsresult -nsGenericDOMDataNode::GetListenerManager(nsIEventListenerManager** aResult) +nsGenericDOMDataNode::GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aResult) { if (nsnull != mListenerManager) { NS_ADDREF(mListenerManager); @@ -540,6 +543,7 @@ nsGenericDOMDataNode::GetListenerManager(nsIEventListenerManager** aResult) if (NS_OK == rv) { mListenerManager = *aResult; NS_ADDREF(mListenerManager); + mListenerManager->SetListenerTarget(aOuterContent); } return rv; } @@ -748,9 +752,10 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext, nsresult ret = NS_OK; nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); //Initiate capturing phase. Special case first call to document if (nsnull != mDocument) { @@ -765,9 +770,10 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext, } //Local handling stage - if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { + if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && + !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, nsnull, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -777,7 +783,7 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext, NS_EVENT_FLAG_BUBBLE, aEventStatus); } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, // release here. if (nsnull != *aDOMEvent) { diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.h b/mozilla/content/base/src/nsGenericDOMDataNode.h index ca18ec5c68f..df1383235c2 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.h +++ b/mozilla/content/base/src/nsGenericDOMDataNode.h @@ -260,7 +260,7 @@ struct nsGenericDOMDataNode { //---------------------------------------- - nsresult GetListenerManager(nsIEventListenerManager** aInstancePtrResult); + nsresult GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aInstancePtrResult); void ToCString(nsString& aBuf, PRInt32 aOffset, PRInt32 aLen) const; @@ -609,14 +609,14 @@ struct nsGenericDOMDataNode { } \ if (_id.Equals(kIDOMEventReceiverIID)) { \ nsCOMPtr man; \ - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ \ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ return man->QueryInterface(kIDOMEventReceiverIID, (void**)_iptr); \ } \ return NS_NOINTERFACE; \ } \ if (_id.Equals(kIDOMEventTargetIID)) { \ nsCOMPtr man; \ - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ \ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ return man->QueryInterface(kIDOMEventTargetIID, (void**)_iptr); \ } \ return NS_NOINTERFACE; \ diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 501d053b535..983741df8ff 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -401,7 +401,10 @@ nsGenericElement::~nsGenericElement() mDOMSlots->mAttributeMap->DropReference(); NS_RELEASE(mDOMSlots->mAttributeMap); } - NS_IF_RELEASE(mDOMSlots->mListenerManager); + if (nsnull != mDOMSlots->mListenerManager) { + mDOMSlots->mListenerManager->SetListenerTarget(nsnull); + NS_RELEASE(mDOMSlots->mListenerManager); + } // XXX Should really be arena managed PR_DELETE(mDOMSlots); } @@ -1284,9 +1287,10 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext, nsresult ret = NS_OK; nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); } //Capturing stage evaluation @@ -1310,9 +1314,11 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext, } //Local handling stage - if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { + if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && + !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { aEvent->flags |= aFlags; - mDOMSlots->mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + nsCOMPtr curTarg(do_QueryInterface(mContent)); + mDOMSlots->mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, curTarg, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -1334,7 +1340,7 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext, } } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, // release here. if (nsnull != *aDOMEvent) { @@ -1557,6 +1563,7 @@ nsGenericElement::GetListenerManager(nsIEventListenerManager** aResult) if (NS_OK == rv) { slots->mListenerManager = *aResult; NS_ADDREF(slots->mListenerManager); + slots->mListenerManager->SetListenerTarget(mContent); } return rv; } diff --git a/mozilla/content/events/public/nsIEventListenerManager.h b/mozilla/content/events/public/nsIEventListenerManager.h index 0b717c5bcde..81a2113843f 100644 --- a/mozilla/content/events/public/nsIEventListenerManager.h +++ b/mozilla/content/events/public/nsIEventListenerManager.h @@ -30,6 +30,7 @@ class nsIPresContext; class nsIDOMEventListener; class nsIScriptObjectOwner; +class nsIDOMEventTarget; /* * Event listener manager interface. @@ -104,6 +105,7 @@ public: virtual nsresult HandleEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aFlags, nsEventStatus* aEventStatus) = 0; @@ -114,6 +116,7 @@ public: */ virtual nsresult CreateEvent(nsIPresContext* aPresContext, nsEvent* aEvent, + const nsString& aEventType, nsIDOMEvent** aDOMEvent) = 0; /** @@ -133,6 +136,12 @@ public: * manager. */ virtual nsresult RemoveAllListeners(PRBool aScriptOnly) = 0; + + /** + * Removes all event listeners registered by this instance of the listener + * manager. + */ + virtual nsresult SetListenerTarget(nsISupports* aTarget) = 0; }; extern NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult); diff --git a/mozilla/content/events/public/nsIEventStateManager.h b/mozilla/content/events/public/nsIEventStateManager.h index cfe62177e5e..96f94d7cc1a 100644 --- a/mozilla/content/events/public/nsIEventStateManager.h +++ b/mozilla/content/events/public/nsIEventStateManager.h @@ -83,6 +83,8 @@ public: NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor) = 0; + //Method for centralized distribution of new DOM events + NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent) = 0; }; #define NS_EVENT_STATE_UNSPECIFIED 0x0000 diff --git a/mozilla/content/events/public/nsIPrivateDOMEvent.h b/mozilla/content/events/public/nsIPrivateDOMEvent.h index 62c0f15d886..f3b4f5d6987 100644 --- a/mozilla/content/events/public/nsIPrivateDOMEvent.h +++ b/mozilla/content/events/public/nsIPrivateDOMEvent.h @@ -36,7 +36,7 @@ class nsIPresContext; 0x80a98c80, 0x2036, 0x11d2, \ {0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } -class nsIDOMNode; +class nsIDOMEventTarget; class nsIDOMEvent; class nsIPrivateDOMEvent : public nsISupports { @@ -45,11 +45,15 @@ public: static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATEDOMEVENT_IID; return iid; } NS_IMETHOD DuplicatePrivateData() = 0; - NS_IMETHOD SetTarget(nsIDOMNode* aNode) = 0; + NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) = 0; + NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aTarget) = 0; NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0; }; extern nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent); -extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent); +extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, + nsIPresContext* aPresContext, + const nsString& aEventType, + nsEvent *aEvent); #endif // nsIPrivateDOMEvent_h__ diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index 1bed17d560b..e1f4f9fd41c 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -34,6 +34,12 @@ #include "nsIViewManager.h" #include "nsIPrivateCompositionEvent.h" #include "nsIScrollableView.h" +#include "nsIDOMEventTarget.h" +#include "nsIInterfaceRequestor.h" +#include "nsIDOMWindow.h" +#include "nsIDOMAbstractView.h" +#include "prmem.h" +#include "nsLayoutAtoms.h" static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID); @@ -46,16 +52,39 @@ static char* mEventNames[] = { "dragenter", "dragover", "dragexit", "dragdrop", "draggesture" }; -nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) { +nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsString& aEventType) { mPresContext = aPresContext; if (mPresContext) NS_ADDREF(mPresContext); - mEvent = aEvent; + if (aEvent) { + mEventIsInternal = PR_FALSE; + mEvent = aEvent; + } + else { + //Allocate internal event + if (aEventType.EqualsIgnoreCase("MouseEvent")) { + mEvent = PR_NEWZAP(nsMouseEvent); + mEvent->eventStructType = NS_MOUSE_EVENT; + } + else if (aEventType.EqualsIgnoreCase("KeyEvent")) { + mEvent = PR_NEWZAP(nsKeyEvent); + mEvent->eventStructType = NS_KEY_EVENT; + } + else if (aEventType.EqualsIgnoreCase("HTMLEvent")) { + mEvent = PR_NEWZAP(nsEvent); + mEvent->eventStructType = NS_EVENT; + } + else { + mEvent = PR_NEWZAP(nsEvent); + mEvent->eventStructType = NS_EVENT; + } + } mTarget = nsnull; + mCurrentTarget = nsnull; mText = nsnull; mTextRange = nsnull; - if (aEvent->eventStructType ==NS_TEXT_EVENT) { + if (aEvent->eventStructType == NS_TEXT_EVENT) { // // extract the IME composition string // @@ -87,8 +116,13 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) { nsDOMEvent::~nsDOMEvent() { NS_IF_RELEASE(mPresContext); NS_IF_RELEASE(mTarget); + NS_IF_RELEASE(mCurrentTarget); NS_IF_RELEASE(mTextRange); + if (mEventIsInternal) { + PR_DELETE(mEvent); + } + if (mText!=nsnull) delete mText; } @@ -121,7 +155,7 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType) return NS_ERROR_FAILURE; } -NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) +NS_METHOD nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget) { if (nsnull != mTarget) { *aTarget = mTarget; @@ -138,7 +172,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) } if (targetContent) { - if (NS_OK == targetContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&mTarget)) { + if (NS_OK == targetContent->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)&mTarget)) { *aTarget = mTarget; NS_ADDREF(mTarget); } @@ -154,7 +188,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) } if (doc) { - if (NS_OK == doc->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&mTarget)) { + if (NS_OK == doc->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)&mTarget)) { *aTarget = mTarget; NS_ADDREF(mTarget); } @@ -166,9 +200,9 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) } NS_IMETHODIMP -nsDOMEvent::GetCurrentNode(nsIDOMNode** aCurrentNode) +nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) { - *aCurrentNode = nsnull; + *aCurrentTarget = nsnull; return NS_OK; } @@ -194,13 +228,29 @@ nsDOMEvent::GetEventPhase(PRUint16* aEventPhase) NS_IMETHODIMP nsDOMEvent::GetBubbles(PRBool* aBubbles) { - return NS_ERROR_NOT_IMPLEMENTED; + *aBubbles = mEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE; + return NS_OK; } NS_IMETHODIMP nsDOMEvent::GetCancelable(PRBool* aCancelable) { - return NS_ERROR_NOT_IMPLEMENTED; + *aCancelable = mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMEvent::GetTimeStamp(PRUint64* aTimeStamp) +{ + *aTimeStamp = mEvent->time; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMEvent::StopPropagation() +{ + mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH; + return NS_OK; } NS_IMETHODIMP @@ -224,20 +274,64 @@ nsDOMEvent::PreventCapture() NS_IMETHODIMP nsDOMEvent::PreventDefault() { - mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT; + if (!(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL)) { + mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT; + } return NS_OK; } NS_IMETHODIMP nsDOMEvent::GetView(nsIDOMAbstractView** aView) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_ARG_POINTER(aView); + *aView = nsnull; + nsresult rv = NS_OK; + + nsCOMPtr container; + rv = mPresContext->GetContainer(getter_AddRefs(container)); + NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv); + + nsCOMPtr ifrq(do_QueryInterface(container)); + NS_ENSURE_TRUE(ifrq, NS_OK); + + nsCOMPtr window; + ifrq->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(window)); + NS_ENSURE_TRUE(window, NS_OK); + + window->QueryInterface(NS_GET_IID(nsIDOMAbstractView), (void **)aView); + + return rv; } NS_IMETHODIMP nsDOMEvent::GetDetail(PRInt32* aDetail) { - return NS_ERROR_NOT_IMPLEMENTED; + //detail is valid for more than just mouseevents but we don't + //use it for anything else right now + if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) { + *aDetail = 0; + return NS_OK; + } + + switch (mEvent->message) { + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_LEFT_CLICK: + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_CLICK: + case NS_MOUSE_MIDDLE_DOUBLECLICK: + case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_RIGHT_CLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + *aDetail = ((nsMouseEvent*)mEvent)->clickCount; + break; + default: + break; + } + return NS_OK; } NS_METHOD nsDOMEvent::GetText(nsString& aText) @@ -515,35 +609,7 @@ NS_METHOD nsDOMEvent::GetButton(PRUint16* aButton) return NS_OK; } -NS_METHOD nsDOMEvent::GetClickCount(PRUint16* aClickCount) -{ - if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) { - *aClickCount = 0; - return NS_OK; - } - - switch (mEvent->message) { - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_LEFT_CLICK: - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_CLICK: - case NS_MOUSE_MIDDLE_DOUBLECLICK: - case NS_MOUSE_RIGHT_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - case NS_MOUSE_RIGHT_CLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - *aClickCount = ((nsMouseEvent*)mEvent)->clickCount; - break; - default: - break; - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetRelatedNode(nsIDOMNode** aRelatedNode) +NS_METHOD nsDOMEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) { nsIEventStateManager *manager; nsIContent *relatedContent = nsnull; @@ -555,11 +621,11 @@ NS_METHOD nsDOMEvent::GetRelatedNode(nsIDOMNode** aRelatedNode) } if (relatedContent) { - ret = relatedContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aRelatedNode); + ret = relatedContent->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)aRelatedTarget); NS_RELEASE(relatedContent); } else { - *aRelatedNode = nsnull; + *aRelatedTarget = nsnull; } return ret; @@ -793,30 +859,109 @@ NS_METHOD nsDOMEvent::GetPreventDefault(PRBool* aReturn) return NS_OK; } -//XXX The following four methods are for custom event dispatch inside the DOM. -//They will be implemented post-beta +nsresult +nsDOMEvent::SetEventType(const nsString& aEventTypeArg) +{ + nsAutoString str; str.AssignWithConversion("on"); + nsIAtom* atom; + + str.Append(aEventTypeArg); + atom = NS_NewAtom(str); + + if (atom == nsLayoutAtoms::onmousedown && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_LEFT_BUTTON_DOWN; + } + else if (atom == nsLayoutAtoms::onmouseup && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_LEFT_BUTTON_UP; + } + else if (atom == nsLayoutAtoms::onclick && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_LEFT_CLICK; + } + else if (atom == nsLayoutAtoms::onmouseover && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_ENTER_SYNTH; + } + else if (atom == nsLayoutAtoms::onmouseout && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_EXIT_SYNTH; + } + else if (atom == nsLayoutAtoms::onmousemove && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_MOVE; + } + else if (atom == nsLayoutAtoms::onkeydown && mEvent->eventStructType == NS_KEY_EVENT) { + mEvent->message = NS_KEY_DOWN; + } + else if (atom == nsLayoutAtoms::onkeyup && mEvent->eventStructType == NS_KEY_EVENT) { + mEvent->message = NS_KEY_UP; + } + else if (atom == nsLayoutAtoms::onkeypress && mEvent->eventStructType == NS_KEY_EVENT) { + mEvent->message = NS_KEY_PRESS; + } + else if (atom == nsLayoutAtoms::onfocus && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FOCUS_CONTENT; + } + else if (atom == nsLayoutAtoms::onblur && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_BLUR_CONTENT; + } + else if (atom == nsLayoutAtoms::onsubmit && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FORM_SUBMIT; + } + else if (atom == nsLayoutAtoms::onreset && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FORM_RESET; + } + else if (atom == nsLayoutAtoms::onchange && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FORM_CHANGE; + } + else if (atom == nsLayoutAtoms::onselect && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FORM_SELECTED; + } + else if (atom == nsLayoutAtoms::onload && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_PAGE_LOAD; + } + else if (atom == nsLayoutAtoms::onunload && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_PAGE_UNLOAD; + } + else if (atom == nsLayoutAtoms::onabort && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_IMAGE_ABORT; + } + else if (atom == nsLayoutAtoms::onerror && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_IMAGE_ERROR; + } + else { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::InitEvent(const nsString& aEventTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg), NS_ERROR_FAILURE); + mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE; + mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL; + return NS_OK; } NS_IMETHODIMP nsDOMEvent::InitUIEvent(const nsString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIDOMAbstractView* aViewArg, PRInt32 aDetailArg) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsDOMEvent::InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE); + //mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE; + //mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL; + return NS_OK; } NS_IMETHODIMP nsDOMEvent::InitKeyEvent(const nsString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg, nsIDOMAbstractView* aViewArg) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE); + mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE; + mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL; + return NS_OK; } @@ -828,7 +973,7 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData() return NS_OK; } -NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget) +NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget) { if (mTarget != aTarget) { NS_IF_RELEASE(mTarget); @@ -838,6 +983,16 @@ NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget) return NS_OK; } +NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget) +{ + if (mCurrentTarget != aCurrentTarget) { + NS_IF_RELEASE(mCurrentTarget); + NS_IF_ADDREF(aCurrentTarget); + mCurrentTarget = aCurrentTarget; + } + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::IsDispatchStopped(PRBool* aIsDispatchStopped) { @@ -936,9 +1091,12 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return nsnull; } -nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent) +nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, + nsIPresContext* aPresContext, + const nsString& aEventType, + nsEvent *aEvent) { - nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent); + nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent, aEventType); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/content/events/src/nsDOMEvent.h b/mozilla/content/events/src/nsDOMEvent.h index a5818713cfe..90be2ae6253 100644 --- a/mozilla/content/events/src/nsDOMEvent.h +++ b/mozilla/content/events/src/nsDOMEvent.h @@ -85,18 +85,20 @@ public: eDOMEvents_draggesture }; - nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent); + nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsString& aEventType); virtual ~nsDOMEvent(); NS_DECL_ISUPPORTS // nsIDOMEvent Interface NS_IMETHOD GetType(nsString& aType); - NS_IMETHOD GetTarget(nsIDOMNode** aTarget); - NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode); + NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget); + NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget); NS_IMETHOD GetEventPhase(PRUint16* aEventPhase); NS_IMETHOD GetBubbles(PRBool* aBubbles); NS_IMETHOD GetCancelable(PRBool* aCancelable); + NS_IMETHOD GetTimeStamp(PRUint64* aTimestamp); + NS_IMETHOD StopPropagation(); NS_IMETHOD PreventBubble(); NS_IMETHOD PreventCapture(); NS_IMETHOD PreventDefault(); @@ -117,8 +119,7 @@ public: NS_IMETHOD GetShiftKey(PRBool* aShiftKey); NS_IMETHOD GetMetaKey(PRBool* aMetaKey); NS_IMETHOD GetButton(PRUint16* aButton); - NS_IMETHOD GetClickCount(PRUint16* aClickCount); - NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode); + NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget); NS_IMETHOD GetCharCode(PRUint32* aCharCode); NS_IMETHOD GetKeyCode(PRUint32* aKeyCode); NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg); @@ -139,7 +140,8 @@ public: // nsIPrivateDOMEvent interface NS_IMETHOD DuplicatePrivateData(); - NS_IMETHOD SetTarget(nsIDOMNode* aNode); + NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget); + NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget); NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped); // nsIPrivateTextEvent interface @@ -154,10 +156,13 @@ protected: //Internal helper funcs nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, float* aT2P); + nsresult SetEventType(const nsString& aEventTypeArg); nsEvent* mEvent; + PRBool mEventIsInternal; nsIPresContext* mPresContext; - nsIDOMNode* mTarget; + nsIDOMEventTarget* mTarget; + nsIDOMEventTarget* mCurrentTarget; nsString* mText; nsIPrivateTextRangeList* mTextRange; const char* GetEventName(PRUint32 aEventType); diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index 50676b07a8c..bae5cab6ef9 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -22,7 +22,6 @@ #include "nsISupports.h" #include "nsGUIEvent.h" -#include "nsIPresContext.h" #include "nsDOMEvent.h" #include "nsEventListenerManager.h" #include "nsIDOMEventListener.h" @@ -54,6 +53,8 @@ #include "nsDOMPropEnums.h" #include "nsDOMError.h" #include "nsIJSContextStack.h" +#include "nsIDocument.h" +#include "nsIPresShell.h" static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID); @@ -75,6 +76,7 @@ nsEventListenerManager::nsEventListenerManager() mCompositionListeners = nsnull; mMenuListeners = nsnull; mDestroyed = PR_FALSE; + mTarget = nsnull; NS_INIT_REFCNT(); } @@ -616,6 +618,7 @@ nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *a nsresult nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, nsIDOMEvent* aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aSubType, PRUint32 aPhaseFlags) { @@ -700,7 +703,10 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, } if (NS_SUCCEEDED(result)) { + nsCOMPtr aPrivDOMEvent(do_QueryInterface(aDOMEvent)); + aPrivDOMEvent->SetCurrentTarget(aCurrentTarget); result = aListenerStruct->mListener->HandleEvent(aDOMEvent); + aPrivDOMEvent->SetCurrentTarget(nsnull); } return result; @@ -714,6 +720,7 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aFlags, nsEventStatus* aEventStatus) { @@ -727,6 +734,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, keys which cause window deletion, can destroy this object before we're ready. */ nsCOMPtr kungFuDeathGrip(this); + nsAutoString empty; switch(aEvent->message) { case NS_MOUSE_LEFT_BUTTON_DOWN: @@ -745,7 +753,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_MOUSE_EXIT_SYNTH: if (nsnull != mMouseListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mMouseListeners && iCount(); i++) { @@ -840,7 +848,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -852,7 +860,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_MOUSE_MOVE: if (nsnull != mMouseMotionListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mMouseMotionListeners && iCount(); i++) { @@ -886,7 +894,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -903,7 +911,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, #endif if (nsnull != mCompositionListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,empty,aEvent); } if (NS_OK == ret) { for(int i=0; mTextListeners && iCount();i++) { @@ -951,7 +959,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -965,7 +973,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, #endif if (nsnull != mTextListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,empty,aEvent); } if (NS_OK == ret) { for (int i=0; mTextListeners && iCount(); i++) { @@ -986,7 +994,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, correctSubType = PR_TRUE; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1000,7 +1008,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_KEY_PRESS: if (nsnull != mKeyListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mKeyListeners && iCount(); i++) { @@ -1052,7 +1060,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1065,7 +1073,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_BLUR_CONTENT: if (nsnull != mFocusListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mFocusListeners && iCount(); i++) { @@ -1108,7 +1116,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1124,7 +1132,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_FORM_INPUT: if (nsnull != mFormListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mFormListeners && iCount(); i++) { @@ -1194,7 +1202,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1211,7 +1219,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, if (nsnull != mLoadListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mLoadListeners && iCount(); i++) { @@ -1266,7 +1274,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1278,7 +1286,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_PAINT: if (nsnull != mPaintListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mPaintListeners && iCount(); i++) { @@ -1300,7 +1308,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, correctSubType = PR_TRUE; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1316,7 +1324,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_DRAGDROP_GESTURE: if (nsnull != mDragListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { @@ -1379,7 +1387,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || dragStruct->mSubType == NS_EVENT_BITS_DRAG_NONE) - ret = HandleEventSubType(dragStruct, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(dragStruct, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1395,7 +1403,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_XUL_COMMAND_UPDATE: if (nsnull != mMenuListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mMenuListeners && iCount(); i++) { @@ -1474,7 +1482,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1505,9 +1513,15 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, nsresult nsEventListenerManager::CreateEvent(nsIPresContext* aPresContext, nsEvent* aEvent, + const nsString& aEventType, nsIDOMEvent** aDOMEvent) { - return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + if (!aEvent && !aEventType.EqualsIgnoreCase("MouseEvent") && !aEventType.EqualsIgnoreCase("KeyEvent") && + !aEventType.EqualsIgnoreCase("HTMLEvent")) { + return NS_ERROR_FAILURE; + } + + return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEventType, aEvent); } /** @@ -1753,6 +1767,13 @@ nsresult nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly) return NS_OK; } +nsresult nsEventListenerManager::SetListenerTarget(nsISupports* aTarget) +{ + //WEAK reference, must be set back to nsnull when done + mTarget = aTarget; + return NS_OK; +} + // nsIDOMEventTarget interface NS_IMETHODIMP nsEventListenerManager::AddEventListener(const nsString& aType, @@ -1774,6 +1795,38 @@ nsEventListenerManager::RemoveEventListener(const nsString& aType, return RemoveEventListenerByType(aListener, aType, flags); } +NS_IMETHODIMP +nsEventListenerManager::DispatchEvent(nsIDOMEvent* aEvent) +{ + //If we don't have a target set this doesn't work. + if (mTarget) { + nsCOMPtr targetContent(do_QueryInterface(mTarget)); + if (targetContent) { + nsCOMPtr document; + targetContent->GetDocument(*getter_AddRefs(document)); + + if (document) { + // Obtain a presentation context + PRInt32 count = document->GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(document->GetShellAt(0)); + + // Retrieve the context + nsCOMPtr aPresContext; + shell->GetPresContext(getter_AddRefs(aPresContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent(mTarget, aEvent); + } + } + } + } + return NS_ERROR_FAILURE; +} + // nsIDOMEventReceiver interface NS_IMETHODIMP nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener, @@ -1806,7 +1859,7 @@ nsEventListenerManager::GetNewListenerManager(nsIEventListenerManager **aInstanc NS_IMETHODIMP nsEventListenerManager::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) diff --git a/mozilla/content/events/src/nsEventListenerManager.h b/mozilla/content/events/src/nsEventListenerManager.h index d9662e7fcfc..5ac323c0042 100644 --- a/mozilla/content/events/src/nsEventListenerManager.h +++ b/mozilla/content/events/src/nsEventListenerManager.h @@ -41,7 +41,7 @@ typedef struct { } nsListenerStruct; //Flag must live higher than all event flags in nsGUIEvent.h -#define NS_PRIV_EVENT_FLAG_SCRIPT 0x20 +#define NS_PRIV_EVENT_FLAG_SCRIPT 0x80 /* * Event listener manager @@ -94,15 +94,19 @@ public: virtual nsresult HandleEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aFlags, nsEventStatus* aEventStatus); virtual nsresult CreateEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, + nsEvent* aEvent, + const nsString& aEventType, nsIDOMEvent** aDOMEvent); virtual nsresult RemoveAllListeners(PRBool aScriptOnly); + virtual nsresult SetListenerTarget(nsISupports* aTarget); + static nsresult GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aSubType); // nsIDOMEventTarget interface @@ -112,6 +116,7 @@ public: NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMEventReceiver interface NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); @@ -123,6 +128,7 @@ public: protected: nsresult HandleEventSubType(nsListenerStruct* aListenerStruct, nsIDOMEvent* aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aSubType, PRUint32 aPhaseFlags); nsListenerStruct* FindJSEventListener(REFNSIID aIID); @@ -146,6 +152,8 @@ protected: nsVoidArray* mMenuListeners; nsCOMPtr mPrincipal; PRBool mDestroyed; + + nsISupports* mTarget; //WEAK }; diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index aeac88d34eb..68f55779927 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -899,7 +899,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, { if (sv) { if (action == MOUSE_SCROLL_N_LINES) - sv->ScrollByLines(numLines); + sv->ScrollByLines(0, numLines); else sv->ScrollByPages((numLines > 0) ? 1 : -1); ForceViewUpdate(focusView); @@ -996,7 +996,27 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, nsIScrollableView* sv = GetNearestScrollingView(aView); if (sv) { nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; - sv->ScrollByLines((keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1); + sv->ScrollByLines(0, (keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1); + + // force the update to happen now, otherwise multiple scrolls can + // occur before the update is processed. (bug #7354) + nsIViewManager* vm = nsnull; + if (NS_OK == aView->GetViewManager(vm) && nsnull != vm) { + // I'd use Composite here, but it doesn't always work. + // vm->Composite(); + vm->ForceUpdate(); + NS_RELEASE(vm); + } + } + } + break; + case NS_VK_LEFT: + case NS_VK_RIGHT: + if (!mCurrentFocus) { + nsIScrollableView* sv = GetNearestScrollingView(aView); + if (sv) { + nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; + sv->ScrollByLines((keyEvent->keyCode == NS_VK_RIGHT) ? 1 : -1, 0); // force the update to happen now, otherwise multiple scrolls can // occur before the update is processed. (bug #7354) @@ -2579,6 +2599,12 @@ void nsEventStateManager::ForceViewUpdate(nsIView* aView) } } +NS_IMETHODIMP +nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent) +{ + return NS_OK; +} + nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult) { nsresult rv; diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 70e9a34ae59..470f63741b8 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -99,6 +99,9 @@ public: NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor); + //Method for centralized distribution of new DOM events + NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent); + protected: void UpdateCursor(nsIPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus); void GenerateMouseEnterExit(nsIPresContext* aPresContext, nsGUIEvent* aEvent); diff --git a/mozilla/content/html/content/src/nsHTMLLabelElement.cpp b/mozilla/content/html/content/src/nsHTMLLabelElement.cpp index 50c36ea6e41..31a5f89f254 100644 --- a/mozilla/content/html/content/src/nsHTMLLabelElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLLabelElement.cpp @@ -389,7 +389,7 @@ nsHTMLLabelElement::HandleDOMEvent(nsIPresContext* aPresContext, // Now a little special trickery because we are a label: // We need to pass this event on to our child iff it is a focus, // keypress/up/dn, mouseclick/dblclick/up/down. - if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT == aFlags) && + if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT & aFlags) && ((nsEventStatus_eIgnore == *aEventStatus) || (nsEventStatus_eConsumeNoDefault == *aEventStatus)) ) { PRBool isFormElement = PR_FALSE; diff --git a/mozilla/content/xml/content/src/nsXMLEntity.cpp b/mozilla/content/xml/content/src/nsXMLEntity.cpp index b37c163f0c2..ec221cab34e 100644 --- a/mozilla/content/xml/content/src/nsXMLEntity.cpp +++ b/mozilla/content/xml/content/src/nsXMLEntity.cpp @@ -134,7 +134,7 @@ nsXMLEntity::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) } if (aIID.Equals(kIDOMEventReceiverIID)) { nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ return man->QueryInterface(kIDOMEventReceiverIID, (void**)aInstancePtrResult); } return NS_NOINTERFACE; diff --git a/mozilla/content/xml/content/src/nsXMLNotation.cpp b/mozilla/content/xml/content/src/nsXMLNotation.cpp index 35a88bf474c..55377b96cc6 100644 --- a/mozilla/content/xml/content/src/nsXMLNotation.cpp +++ b/mozilla/content/xml/content/src/nsXMLNotation.cpp @@ -131,7 +131,7 @@ nsXMLNotation::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) } if (aIID.Equals(kIDOMEventReceiverIID)) { nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ return man->QueryInterface(kIDOMEventReceiverIID, (void**)aInstancePtrResult); } return NS_NOINTERFACE; diff --git a/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp b/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp index 1566a1ef5c4..d265d6e2d01 100644 --- a/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp +++ b/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp @@ -137,7 +137,7 @@ nsXMLProcessingInstruction::QueryInterface(REFNSIID aIID, void** aInstancePtrRes } if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver))) { nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ return man->QueryInterface(kIDOMEventReceiverIID, (void**)aInstancePtrResult); } return NS_NOINTERFACE; diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index 99892a8d79b..6d8a4f53777 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -2060,6 +2060,28 @@ nsXULElement::RemoveEventListener(const nsString& aType, nsIDOMEventListener* aL return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsXULElement::DispatchEvent(nsIDOMEvent* aEvent) +{ + // Obtain a presentation context + PRInt32 count = mDocument->GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(mDocument->GetShellAt(0)); + + // Retrieve the context + nsCOMPtr aPresContext; + shell->GetPresContext(getter_AddRefs(aPresContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent(NS_STATIC_CAST(nsIStyledContent*, this), aEvent); + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsXULElement::GetListenerManager(nsIEventListenerManager** aResult) { @@ -2090,7 +2112,7 @@ nsXULElement::GetNewListenerManager(nsIEventListenerManager **aResult) NS_IMETHODIMP nsXULElement::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } @@ -3449,9 +3471,10 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, nsresult ret = NS_OK; nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); // In order for the event to have a proper target for events that don't go through // the presshell (onselect, oncommand, oncreate, ondestroy) we need to set our target // ourselves. Also, key sets and menus don't have frames and therefore need their @@ -3474,7 +3497,8 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, NS_ERROR("Unable to instantiate a listener manager on this event."); return ret; } - if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, aDOMEvent))) { + nsAutoString empty; + if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent))) { NS_ERROR("This event will fail without the ability to create the event early."); return ret; } @@ -3522,7 +3546,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, //Local handling stage if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -3556,7 +3580,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, } } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, // release here. if (nsnull != *aDOMEvent) { diff --git a/mozilla/content/xul/content/src/nsXULElement.h b/mozilla/content/xul/content/src/nsXULElement.h index b2198266922..3a6e280421f 100644 --- a/mozilla/content/xul/content/src/nsXULElement.h +++ b/mozilla/content/xul/content/src/nsXULElement.h @@ -465,6 +465,7 @@ public: PRBool aUseCapture); NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMEventReceiver NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); diff --git a/mozilla/content/xul/content/src/nsXULPopupListener.cpp b/mozilla/content/xul/content/src/nsXULPopupListener.cpp index dbaa1452112..839785f4fc4 100644 --- a/mozilla/content/xul/content/src/nsXULPopupListener.cpp +++ b/mozilla/content/xul/content/src/nsXULPopupListener.cpp @@ -47,7 +47,7 @@ #include "nsIDOMMouseEvent.h" #include "nsITimer.h" #include "nsIDOMNSUIEvent.h" - +#include "nsIDOMEventTarget.h" //////////////////////////////////////////////////////////////////////// @@ -193,8 +193,10 @@ XULPopupListenerImpl::MouseDown(nsIDOMEvent* aMouseEvent) } // Get the node that was clicked on. + nsCOMPtr target; + mouseEvent->GetTarget( getter_AddRefs( target ) ); nsCOMPtr targetNode; - mouseEvent->GetTarget( getter_AddRefs( targetNode ) ); + if (target) targetNode = do_QueryInterface(target); // Get the document with the popup. nsCOMPtr document; @@ -279,9 +281,11 @@ XULPopupListenerImpl::MouseMove(nsIDOMEvent* aMouseEvent) NS_NewTimer ( getter_AddRefs(mTooltipTimer) ); if ( mTooltipTimer ) { - nsCOMPtr eventTarget; + nsCOMPtr eventTarget; + nsCOMPtr eventTargetNode; aMouseEvent->GetTarget(getter_AddRefs(eventTarget)); - mPossibleTooltipNode = eventTarget.get(); + if (eventTarget) eventTargetNode = do_QueryInterface(eventTarget); + mPossibleTooltipNode = eventTargetNode.get(); mTooltipTimer->Init(sTooltipCallback, this, 500, NS_PRIORITY_HIGH); // 500 ms delay } else @@ -317,10 +321,12 @@ XULPopupListenerImpl::MouseOut(nsIDOMEvent* aMouseEvent) mPopupContent = nsnull; // release the popup // clear out the tooltip node on the document - nsCOMPtr eventTarget; + nsCOMPtr eventTarget; + nsCOMPtr eventTargetNode; aMouseEvent->GetTarget(getter_AddRefs(eventTarget)); + if (eventTarget) eventTargetNode = do_QueryInterface(eventTarget); nsCOMPtr doc; - FindDocumentForNode ( eventTarget, getter_AddRefs(doc) ); + FindDocumentForNode ( eventTargetNode, getter_AddRefs(doc) ); if ( doc ) doc->SetTooltipNode(nsnull); } diff --git a/mozilla/content/xul/document/src/nsXULCommandDispatcher.cpp b/mozilla/content/xul/document/src/nsXULCommandDispatcher.cpp index ded65ac062e..3be627c63eb 100644 --- a/mozilla/content/xul/document/src/nsXULCommandDispatcher.cpp +++ b/mozilla/content/xul/document/src/nsXULCommandDispatcher.cpp @@ -47,6 +47,7 @@ #include "nsRDFCID.h" #include "nsXULCommandDispatcher.h" #include "prlog.h" +#include "nsIDOMEventTarget.h" #ifdef PR_LOGGING static PRLogModuleInfo* gLog; @@ -350,7 +351,7 @@ nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent) if (mSuppressFocus) return NS_OK; - nsCOMPtr t; + nsCOMPtr t; aEvent->GetTarget(getter_AddRefs(t)); #ifdef DEBUG_hyatt @@ -419,7 +420,7 @@ nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent) if (mSuppressFocus) return NS_OK; - nsCOMPtr t; + nsCOMPtr t; aEvent->GetTarget(getter_AddRefs(t)); #ifdef DEBUG_hyatt diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 4d0b6711db1..b1df4da3d78 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -76,6 +76,7 @@ #include "nsIFormControl.h" #include "nsIHTMLContent.h" #include "nsIElementFactory.h" +#include "nsIEventStateManager.h" #include "nsIInputStream.h" #include "nsILoadGroup.h" #include "nsINameSpace.h" @@ -573,6 +574,9 @@ nsXULDocument::QueryInterface(REFNSIID iid, void** result) else if (iid.Equals(NS_GET_IID(nsIDOMNSDocument))) { *result = NS_STATIC_CAST(nsIDOMNSDocument*, this); } + else if (iid.Equals(NS_GET_IID(nsIDOMDocumentEvent))) { + *result = NS_STATIC_CAST(nsIDOMDocumentEvent*, this); + } else if (iid.Equals(NS_GET_IID(nsIDOMDocumentView))) { *result = NS_STATIC_CAST(nsIDOMDocumentView*, this); } @@ -1952,9 +1956,10 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, nsresult ret = NS_OK; nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); } //Capturing stage @@ -1965,7 +1970,7 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, //Local handling stage if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -1974,7 +1979,7 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, release here. if (nsnull != *aDOMEvent) { nsrefcnt rc; @@ -4002,6 +4007,52 @@ nsXULDocument::RemoveEventListener(const nsString& aType, nsIDOMEventListener* a return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsXULDocument::DispatchEvent(nsIDOMEvent* aEvent) +{ + // Obtain a presentation context + PRInt32 count = GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(GetShellAt(0)); + + // Retrieve the context + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent(NS_STATIC_CAST(nsIDocument*, this), aEvent); + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsXULDocument::CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn) +{ + // Obtain a presentation context + PRInt32 count = GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(GetShellAt(0)); + + // Retrieve the context + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + + if (presContext) { + nsCOMPtr lm; + if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(lm)))) { + return lm->CreateEvent(presContext, nsnull, aEventType, aReturn); + } + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsXULDocument::GetListenerManager(nsIEventListenerManager** aResult) { @@ -4031,7 +4082,7 @@ nsXULDocument::GetNewListenerManager(nsIEventListenerManager **aResult) NS_IMETHODIMP nsXULDocument::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } nsresult diff --git a/mozilla/content/xul/document/src/nsXULDocument.h b/mozilla/content/xul/document/src/nsXULDocument.h index c11b52b06a9..6bf9aa88ba8 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.h +++ b/mozilla/content/xul/document/src/nsXULDocument.h @@ -67,6 +67,7 @@ #include "nsIStreamLoader.h" #include "nsIBindingManager.h" #include "nsINodeInfo.h" +#include "nsIDOMDocumentEvent.h" class nsIAtom; class nsIElementFactory; @@ -93,6 +94,7 @@ class nsXULDocument : public nsIDocument, public nsIXULDocument, public nsIStreamLoadableDocument, public nsIDOMXULDocument, + public nsIDOMDocumentEvent, public nsIDOMDocumentView, public nsIDOMNSDocument, public nsIDOMEventCapturer, @@ -335,10 +337,14 @@ public: PRBool aUseCapture); NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMDocument interface NS_DECL_IDOMDOCUMENT + // nsIDOMDocumentEvent interface + NS_DECL_IDOMDOCUMENTEVENT + // nsIDOMDocumentView interface NS_DECL_IDOMDOCUMENTVIEW diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index b68dd332858..b66bb561507 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -1926,7 +1926,7 @@ NS_IMETHODIMP nsDocShell::ScrollByLines(PRInt32 numLines) NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(scrollView->ScrollByLines(numLines), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(scrollView->ScrollByLines(0, numLines), NS_ERROR_FAILURE); return NS_OK; } diff --git a/mozilla/dom/public/base/nsIDOMAbstractView.h b/mozilla/dom/public/base/nsIDOMAbstractView.h index 459a838ae12..eec7e0689d0 100644 --- a/mozilla/dom/public/base/nsIDOMAbstractView.h +++ b/mozilla/dom/public/base/nsIDOMAbstractView.h @@ -32,7 +32,7 @@ class nsIDOMDocumentView; #define NS_IDOMABSTRACTVIEW_IID \ { 0xf51ebade, 0x8b1a, 0x11d3, \ - { 0xaa, 0xe7, 0x00, 0x10, 0x83, 0x01, 0x23, 0xb4 } } + { 0xaa, 0xe7, 0x00, 0x10, 0x83, 0x01, 0x23, 0xb4 } } class nsIDOMAbstractView : public nsISupports { public: diff --git a/mozilla/dom/public/coreDom/MANIFEST b/mozilla/dom/public/coreDom/MANIFEST index c4ba5a51b56..73b1ea3fb29 100644 --- a/mozilla/dom/public/coreDom/MANIFEST +++ b/mozilla/dom/public/coreDom/MANIFEST @@ -27,6 +27,7 @@ nsIDOMComment.h nsIDOMDOMImplementation.h nsIDOMDocument.h nsIDOMDocumentCSS.h +nsIDOMDocumentEvent.h nsIDOMDocumentFragment.h nsIDOMDocumentStyle.h nsIDOMDocumentType.h diff --git a/mozilla/dom/public/coreDom/Makefile.in b/mozilla/dom/public/coreDom/Makefile.in index 8cea0f9058e..901efa2294a 100644 --- a/mozilla/dom/public/coreDom/Makefile.in +++ b/mozilla/dom/public/coreDom/Makefile.in @@ -36,6 +36,7 @@ EXPORTS = \ nsIDOMDOMImplementation.h \ nsIDOMDocument.h \ nsIDOMDocumentCSS.h \ + nsIDOMDocumentEvent.h \ nsIDOMDocumentFragment.h \ nsIDOMDocumentStyle.h \ nsIDOMDocumentType.h \ diff --git a/mozilla/dom/public/coreDom/makefile.win b/mozilla/dom/public/coreDom/makefile.win index 97d8562c973..dbcd0ce00c5 100644 --- a/mozilla/dom/public/coreDom/makefile.win +++ b/mozilla/dom/public/coreDom/makefile.win @@ -31,6 +31,7 @@ EXPORTS = \ nsIDOMDOMImplementation.h \ nsIDOMDocument.h \ nsIDOMDocumentCSS.h \ + nsIDOMDocumentEvent.h \ nsIDOMDocumentFragment.h \ nsIDOMDocumentStyle.h \ nsIDOMDocumentType.h \ diff --git a/mozilla/dom/public/coreDom/nsIDOMDocumentEvent.h b/mozilla/dom/public/coreDom/nsIDOMDocumentEvent.h new file mode 100644 index 00000000000..53c40d17ca4 --- /dev/null +++ b/mozilla/dom/public/coreDom/nsIDOMDocumentEvent.h @@ -0,0 +1,54 @@ +/* -*- 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.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#ifndef nsIDOMDocumentEvent_h__ +#define nsIDOMDocumentEvent_h__ + +#include "nsISupports.h" +#include "nsString.h" +#include "nsIScriptContext.h" + +class nsIDOMEvent; + +#define NS_IDOMDOCUMENTEVENT_IID \ + { 0x46b91d66, 0x28e2, 0x11d4, \ + { 0xab, 0x1e, 0x00, 0x10, 0x83, 0x01, 0x23, 0xb4 } } + +class nsIDOMDocumentEvent : public nsISupports { +public: + static const nsIID& GetIID() { static nsIID iid = NS_IDOMDOCUMENTEVENT_IID; return iid; } + + NS_IMETHOD CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn)=0; +}; + + +#define NS_DECL_IDOMDOCUMENTEVENT \ + NS_IMETHOD CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn); \ + + + +#define NS_FORWARD_IDOMDOCUMENTEVENT(_to) \ + NS_IMETHOD CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn) { return _to CreateEvent(aEventType, aReturn); } \ + + +#endif // nsIDOMDocumentEvent_h__ diff --git a/mozilla/dom/public/coreEvents/nsIDOMEvent.h b/mozilla/dom/public/coreEvents/nsIDOMEvent.h index e1f5eeb1f74..aa2f12882cb 100644 --- a/mozilla/dom/public/coreEvents/nsIDOMEvent.h +++ b/mozilla/dom/public/coreEvents/nsIDOMEvent.h @@ -28,7 +28,7 @@ #include "nsString.h" #include "nsIScriptContext.h" -class nsIDOMNode; +class nsIDOMEventTarget; #define NS_IDOMEVENT_IID \ { 0xa66b7b80, 0xff46, 0xbd97, \ @@ -80,9 +80,9 @@ public: NS_IMETHOD GetType(nsString& aType)=0; - NS_IMETHOD GetTarget(nsIDOMNode** aTarget)=0; + NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget)=0; - NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode)=0; + NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)=0; NS_IMETHOD GetEventPhase(PRUint16* aEventPhase)=0; @@ -90,6 +90,10 @@ public: NS_IMETHOD GetCancelable(PRBool* aCancelable)=0; + NS_IMETHOD GetTimeStamp(PRUint64* aTimeStamp)=0; + + NS_IMETHOD StopPropagation()=0; + NS_IMETHOD PreventBubble()=0; NS_IMETHOD PreventCapture()=0; @@ -102,11 +106,13 @@ public: #define NS_DECL_IDOMEVENT \ NS_IMETHOD GetType(nsString& aType); \ - NS_IMETHOD GetTarget(nsIDOMNode** aTarget); \ - NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode); \ + NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget); \ + NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget); \ NS_IMETHOD GetEventPhase(PRUint16* aEventPhase); \ NS_IMETHOD GetBubbles(PRBool* aBubbles); \ NS_IMETHOD GetCancelable(PRBool* aCancelable); \ + NS_IMETHOD GetTimeStamp(PRUint64* aTimeStamp); \ + NS_IMETHOD StopPropagation(); \ NS_IMETHOD PreventBubble(); \ NS_IMETHOD PreventCapture(); \ NS_IMETHOD PreventDefault(); \ @@ -116,11 +122,13 @@ public: #define NS_FORWARD_IDOMEVENT(_to) \ NS_IMETHOD GetType(nsString& aType) { return _to GetType(aType); } \ - NS_IMETHOD GetTarget(nsIDOMNode** aTarget) { return _to GetTarget(aTarget); } \ - NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode) { return _to GetCurrentNode(aCurrentNode); } \ + NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget) { return _to GetTarget(aTarget); } \ + NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) { return _to GetCurrentTarget(aCurrentTarget); } \ 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); } \ + NS_IMETHOD GetTimeStamp(PRUint64* aTimeStamp) { return _to GetTimeStamp(aTimeStamp); } \ + NS_IMETHOD StopPropagation() { return _to StopPropagation(); } \ NS_IMETHOD PreventBubble() { return _to PreventBubble(); } \ NS_IMETHOD PreventCapture() { return _to PreventCapture(); } \ NS_IMETHOD PreventDefault() { return _to PreventDefault(); } \ diff --git a/mozilla/dom/public/coreEvents/nsIDOMEventTarget.h b/mozilla/dom/public/coreEvents/nsIDOMEventTarget.h index 58d963630ae..f0b3fb3f167 100644 --- a/mozilla/dom/public/coreEvents/nsIDOMEventTarget.h +++ b/mozilla/dom/public/coreEvents/nsIDOMEventTarget.h @@ -29,6 +29,7 @@ #include "nsIScriptContext.h" class nsIDOMEventListener; +class nsIDOMEvent; #define NS_IDOMEVENTTARGET_IID \ { 0x1c773b30, 0xd1cf, 0x11d2, \ @@ -41,18 +42,22 @@ public: NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)=0; NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)=0; + + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvt)=0; }; #define NS_DECL_IDOMEVENTTARGET \ NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); \ NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); \ + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvt); \ #define NS_FORWARD_IDOMEVENTTARGET(_to) \ NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture) { return _to AddEventListener(aType, aListener, aUseCapture); } \ NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture) { return _to RemoveEventListener(aType, aListener, aUseCapture); } \ + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvt) { return _to DispatchEvent(aEvt); } \ #endif // nsIDOMEventTarget_h__ diff --git a/mozilla/dom/public/coreEvents/nsIDOMMouseEvent.h b/mozilla/dom/public/coreEvents/nsIDOMMouseEvent.h index 12083673967..5b6d8056155 100644 --- a/mozilla/dom/public/coreEvents/nsIDOMMouseEvent.h +++ b/mozilla/dom/public/coreEvents/nsIDOMMouseEvent.h @@ -29,7 +29,7 @@ #include "nsIScriptContext.h" #include "nsIDOMUIEvent.h" -class nsIDOMNode; +class nsIDOMEventTarget; #define NS_IDOMMOUSEEVENT_IID \ { 0xff751edc, 0x8b02, 0xaae7, \ @@ -57,9 +57,7 @@ public: NS_IMETHOD GetButton(PRUint16* aButton)=0; - NS_IMETHOD GetClickCount(PRUint16* aClickCount)=0; - - NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode)=0; + NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)=0; NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg)=0; }; @@ -75,8 +73,7 @@ public: NS_IMETHOD GetShiftKey(PRBool* aShiftKey); \ NS_IMETHOD GetMetaKey(PRBool* aMetaKey); \ NS_IMETHOD GetButton(PRUint16* aButton); \ - NS_IMETHOD GetClickCount(PRUint16* aClickCount); \ - NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode); \ + NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget); \ NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg); \ @@ -91,8 +88,7 @@ public: NS_IMETHOD GetShiftKey(PRBool* aShiftKey) { return _to GetShiftKey(aShiftKey); } \ NS_IMETHOD GetMetaKey(PRBool* aMetaKey) { return _to GetMetaKey(aMetaKey); } \ NS_IMETHOD GetButton(PRUint16* aButton) { return _to GetButton(aButton); } \ - NS_IMETHOD GetClickCount(PRUint16* aClickCount) { return _to GetClickCount(aClickCount); } \ - NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode) { return _to GetRelatedNode(aRelatedNode); } \ + NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) { return _to GetRelatedTarget(aRelatedTarget); } \ NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg) { return _to InitMouseEvent(aTypeArg, aCtrlKeyArg, aAltKeyArg, aShiftKeyArg, aMetaKeyArg, aScreenXArg, aScreenYArg, aClientXArg, aClientYArg, aButtonArg, aDetailArg); } \ diff --git a/mozilla/dom/public/idl/base/Window.idl b/mozilla/dom/public/idl/base/Window.idl index 951816ad44a..0932f1aee74 100644 --- a/mozilla/dom/public/idl/base/Window.idl +++ b/mozilla/dom/public/idl/base/Window.idl @@ -91,6 +91,7 @@ interface EventTarget { void addEventListener(in DOMString type, in function EventListener listener, in boolean useCapture); void removeEventListener(in DOMString type, in function EventListener listener, in boolean useCapture); + void dispatchEvent(in Event evt); }; // Introduced in DOM Level 2: diff --git a/mozilla/dom/public/idl/coreDom/Document.idl b/mozilla/dom/public/idl/coreDom/Document.idl index 452c10fe97d..8d8ab355f36 100644 --- a/mozilla/dom/public/idl/coreDom/Document.idl +++ b/mozilla/dom/public/idl/coreDom/Document.idl @@ -64,6 +64,14 @@ interface DocumentCSS : DocumentStyle { in DOMString pseudoElt); }; +// Introduced in DOM Level 2: +interface DocumentEvent { +/* IID: { 0x46b91d66, 0x28e2, 0x11d4, \ + { 0xab, 0x1e, 0x00, 0x10, 0x83, 0x01, 0x23, 0xb4 } } */ + + Event createEvent(in DOMString eventType); +}; + interface NSDocument { /* IID: { 0xa6cf90cd, 0x15b3, 0x11d2, \ { 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } */ diff --git a/mozilla/dom/public/idl/coreDom/Node.idl b/mozilla/dom/public/idl/coreDom/Node.idl index 3de75aedb9e..55928e4f3e9 100644 --- a/mozilla/dom/public/idl/coreDom/Node.idl +++ b/mozilla/dom/public/idl/coreDom/Node.idl @@ -62,4 +62,5 @@ void addEventListener(in DOMString type, in function EventListener listener, in boolean useCapture); void removeEventListener(in DOMString type, in function EventListener listener, in boolean useCapture); - }; + void dispatchEvent(in Event evt); +}; diff --git a/mozilla/dom/public/idl/events/Event.idl b/mozilla/dom/public/idl/events/Event.idl index 5a67f0703b3..e9e642ce678 100644 --- a/mozilla/dom/public/idl/events/Event.idl +++ b/mozilla/dom/public/idl/events/Event.idl @@ -45,13 +45,15 @@ const int META_MASK = 0x00000008; - readonly attribute wstring type; - readonly attribute Node target; - readonly attribute Node currentNode; - readonly attribute unsigned short eventPhase; - readonly attribute boolean bubbles; - readonly attribute boolean cancelable; + 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(); diff --git a/mozilla/dom/public/idl/events/MouseKeyEvent.idl b/mozilla/dom/public/idl/events/MouseKeyEvent.idl index 09a3aad47f8..1fcd7c231ec 100644 --- a/mozilla/dom/public/idl/events/MouseKeyEvent.idl +++ b/mozilla/dom/public/idl/events/MouseKeyEvent.idl @@ -159,9 +159,8 @@ noscript readonly attribute boolean shiftKey; noscript readonly attribute boolean metaKey; - readonly attribute unsigned short button; - readonly attribute unsigned short clickCount; - readonly attribute Node relatedNode; + readonly attribute unsigned short button; + readonly attribute EventTarget relatedTarget; void initMouseEvent(in DOMString typeArg, in boolean ctrlKeyArg, diff --git a/mozilla/dom/public/nsDOMPropEnums.h b/mozilla/dom/public/nsDOMPropEnums.h index 8190c2821df..1e1a511faa2 100644 --- a/mozilla/dom/public/nsDOMPropEnums.h +++ b/mozilla/dom/public/nsDOMPropEnums.h @@ -248,6 +248,7 @@ enum nsDOMProp { NS_DOM_PROP_DOCUMENT_IMPLEMENTATION, NS_DOM_PROP_DOCUMENT_IMPORTNODE, NS_DOM_PROP_DOCUMENTCSS_GETOVERRIDESTYLE, + NS_DOM_PROP_DOCUMENTEVENT_CREATEEVENT, NS_DOM_PROP_DOCUMENTSTYLE_STYLESHEETS, NS_DOM_PROP_DOCUMENTTYPE_ENTITIES, NS_DOM_PROP_DOCUMENTTYPE_INTERNALSUBSET, @@ -285,15 +286,18 @@ enum nsDOMProp { NS_DOM_PROP_ENTITY_SYSTEMID, NS_DOM_PROP_EVENT_BUBBLES, NS_DOM_PROP_EVENT_CANCELABLE, - NS_DOM_PROP_EVENT_CURRENTNODE, + NS_DOM_PROP_EVENT_CURRENTTARGET, NS_DOM_PROP_EVENT_EVENTPHASE, NS_DOM_PROP_EVENT_INITEVENT, NS_DOM_PROP_EVENT_PREVENTBUBBLE, NS_DOM_PROP_EVENT_PREVENTCAPTURE, NS_DOM_PROP_EVENT_PREVENTDEFAULT, + NS_DOM_PROP_EVENT_STOPPROPAGATION, NS_DOM_PROP_EVENT_TARGET, + NS_DOM_PROP_EVENT_TIMESTAMP, NS_DOM_PROP_EVENT_TYPE, NS_DOM_PROP_EVENTTARGET_ADDEVENTLISTENER, + NS_DOM_PROP_EVENTTARGET_DISPATCHEVENT, NS_DOM_PROP_EVENTTARGET_REMOVEEVENTLISTENER, NS_DOM_PROP_HISTORY_BACK, NS_DOM_PROP_HISTORY_CURRENT, @@ -685,11 +689,10 @@ enum nsDOMProp { NS_DOM_PROP_MIMETYPEARRAY_LENGTH, NS_DOM_PROP_MIMETYPEARRAY_NAMEDITEM, NS_DOM_PROP_MOUSEEVENT_BUTTON, - NS_DOM_PROP_MOUSEEVENT_CLICKCOUNT, NS_DOM_PROP_MOUSEEVENT_CLIENTX, NS_DOM_PROP_MOUSEEVENT_CLIENTY, NS_DOM_PROP_MOUSEEVENT_INITMOUSEEVENT, - NS_DOM_PROP_MOUSEEVENT_RELATEDNODE, + NS_DOM_PROP_MOUSEEVENT_RELATEDTARGET, NS_DOM_PROP_MOUSEEVENT_SCREENX, NS_DOM_PROP_MOUSEEVENT_SCREENY, NS_DOM_PROP_NAMEDNODEMAP_GETNAMEDITEM, diff --git a/mozilla/dom/public/nsDOMPropNames.h b/mozilla/dom/public/nsDOMPropNames.h index 6ffb44de3ad..2ff20a06e79 100644 --- a/mozilla/dom/public/nsDOMPropNames.h +++ b/mozilla/dom/public/nsDOMPropNames.h @@ -247,6 +247,7 @@ "document.implementation", \ "document.importnode", \ "documentcss.getoverridestyle", \ + "documentevent.createevent", \ "documentstyle.stylesheets", \ "documenttype.entities", \ "documenttype.internalsubset", \ @@ -284,15 +285,18 @@ "entity.systemid", \ "event.bubbles", \ "event.cancelable", \ - "event.currentnode", \ + "event.currenttarget", \ "event.eventphase", \ "event.initevent", \ "event.preventbubble", \ "event.preventcapture", \ "event.preventdefault", \ + "event.stoppropagation", \ "event.target", \ + "event.timestamp", \ "event.type", \ "eventtarget.addeventlistener", \ + "eventtarget.dispatchevent", \ "eventtarget.removeeventlistener", \ "history.back", \ "history.current", \ @@ -684,11 +688,10 @@ "mimetypearray.length", \ "mimetypearray.nameditem", \ "mouseevent.button", \ - "mouseevent.clickcount", \ "mouseevent.clientx", \ "mouseevent.clienty", \ "mouseevent.initmouseevent", \ - "mouseevent.relatednode", \ + "mouseevent.relatedtarget", \ "mouseevent.screenx", \ "mouseevent.screeny", \ "namednodemap.getnameditem", \ diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 09bd6ea026e..95190e95f42 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -376,10 +376,11 @@ NS_IMETHODIMP GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext, nsCOMPtr kungFuDeathGrip1(mChromeEventHandler); nsCOMPtr kungFuDeathGrip2(mContext); - if(NS_EVENT_FLAG_INIT == aFlags) + if(NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); } //Capturing stage @@ -391,11 +392,11 @@ NS_IMETHODIMP GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext, } //Local handling stage - if(mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) + if(mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && + !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, - aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -415,7 +416,7 @@ NS_IMETHODIMP GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext, } } - if(NS_EVENT_FLAG_INIT == aFlags) + if(NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, release here. if(*aDOMEvent) @@ -2147,6 +2148,31 @@ NS_IMETHODIMP GlobalWindowImpl::RemoveEventListener(const nsString& aType, return NS_ERROR_FAILURE; } +NS_IMETHODIMP GlobalWindowImpl::DispatchEvent(nsIDOMEvent* aEvent) +{ + if (mDocument) { + nsCOMPtr idoc(do_QueryInterface(mDocument)); + if (idoc) { + // Obtain a presentation context + PRInt32 count = idoc->GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(idoc->GetShellAt(0)); + + // Retrieve the context + nsCOMPtr aPresContext; + shell->GetPresContext(getter_AddRefs(aPresContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent(NS_STATIC_CAST(nsIScriptGlobalObject*, this), aEvent); + } + } + } + return NS_ERROR_FAILURE; +} + //***************************************************************************** // GlobalWindowImpl::nsIDOMEventReceiver //***************************************************************************** @@ -2203,7 +2229,7 @@ NS_IMETHODIMP GlobalWindowImpl::GetNewListenerManager(nsIEventListenerManager ** NS_IMETHODIMP GlobalWindowImpl::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } //***************************************************************************** diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index f36faeba7a9..c4fe925a3a5 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -128,6 +128,7 @@ public: nsIDOMEventListener* aListener, PRBool aUseCapture); NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMEventReceiver NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, diff --git a/mozilla/dom/src/base/nsJSWindow.cpp b/mozilla/dom/src/base/nsJSWindow.cpp index ff5be3d95eb..6232dbf4b43 100644 --- a/mozilla/dom/src/base/nsJSWindow.cpp +++ b/mozilla/dom/src/base/nsJSWindow.cpp @@ -44,8 +44,8 @@ #include "nsIDOMAbstractView.h" #include "nsIDOMScreen.h" #include "nsIDOMHistory.h" -#include "nsIDOMWindowCollection.h" #include "nsIDOMEvent.h" +#include "nsIDOMWindowCollection.h" #include "nsIDOMEventListener.h" #include "nsIDOMEventTarget.h" #include "nsISidebar.h" @@ -69,8 +69,8 @@ static NS_DEFINE_IID(kIBarPropIID, NS_IDOMBARPROP_IID); static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID); static NS_DEFINE_IID(kIScreenIID, NS_IDOMSCREEN_IID); static NS_DEFINE_IID(kIHistoryIID, NS_IDOMHISTORY_IID); -static NS_DEFINE_IID(kIWindowCollectionIID, NS_IDOMWINDOWCOLLECTION_IID); static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID); +static NS_DEFINE_IID(kIWindowCollectionIID, NS_IDOMWINDOWCOLLECTION_IID); static NS_DEFINE_IID(kIEventListenerIID, NS_IDOMEVENTLISTENER_IID); static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID); static NS_DEFINE_IID(kISidebarIID, NS_ISIDEBAR_IID); @@ -2610,6 +2610,58 @@ EventTargetRemoveEventListener(JSContext *cx, JSObject *obj, uintN argc, jsval * } +// +// Native method DispatchEvent +// +PR_STATIC_CALLBACK(JSBool) +EventTargetDispatchEvent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMWindow *privateThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIEventTargetIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsCOMPtr b0; + // If there's no private data, this must be the prototype, so ignore + if (!nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENTTARGET_DISPATCHEVENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0), + kIEventIID, + NS_ConvertASCIItoUCS2("Event"), + cx, + argv[0])) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR); + } + + result = nativeThis->DispatchEvent(b0); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + // // Native method GetComputedStyle // @@ -2775,6 +2827,7 @@ static JSFunctionSpec WindowMethods[] = {"getSelection", WindowGetSelection, 0}, {"addEventListener", EventTargetAddEventListener, 3}, {"removeEventListener", EventTargetRemoveEventListener, 3}, + {"dispatchEvent", EventTargetDispatchEvent, 1}, {"getComputedStyle", ViewCSSGetComputedStyle, 2}, {0} }; diff --git a/mozilla/dom/src/coreDOM/nsJSDocument.cpp b/mozilla/dom/src/coreDOM/nsJSDocument.cpp index 902ecf4a817..da41179cacc 100644 --- a/mozilla/dom/src/coreDOM/nsJSDocument.cpp +++ b/mozilla/dom/src/coreDOM/nsJSDocument.cpp @@ -44,6 +44,8 @@ #include "nsIDOMAbstractView.h" #include "nsIDOMNode.h" #include "nsIDOMCDATASection.h" +#include "nsIDOMDocumentEvent.h" +#include "nsIDOMEvent.h" #include "nsIDOMText.h" #include "nsIDOMDOMImplementation.h" #include "nsIDOMDocumentType.h" @@ -70,6 +72,8 @@ static NS_DEFINE_IID(kIProcessingInstructionIID, NS_IDOMPROCESSINGINSTRUCTION_II static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID); static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kICDATASectionIID, NS_IDOMCDATASECTION_IID); +static NS_DEFINE_IID(kIDocumentEventIID, NS_IDOMDOCUMENTEVENT_IID); +static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID); static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID); static NS_DEFINE_IID(kIDOMImplementationIID, NS_IDOMDOMIMPLEMENTATION_IID); static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID); @@ -985,6 +989,53 @@ DocumentCSSGetOverrideStyle(JSContext *cx, JSObject *obj, uintN argc, jsval *arg } +// +// Native method CreateEvent +// +PR_STATIC_CALLBACK(JSBool) +DocumentEventCreateEvent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMDocument *privateThis = (nsIDOMDocument*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIDocumentEventIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsIDOMEvent* nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (!nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENTEVENT_CREATEEVENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->CreateEvent(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + // // Native method CreateElementWithNameSpace // @@ -1180,6 +1231,7 @@ static JSFunctionSpec DocumentMethods[] = {"getElementsByTagNameNS", DocumentGetElementsByTagNameNS, 2}, {"getElementById", DocumentGetElementById, 1}, {"getOverrideStyle", DocumentCSSGetOverrideStyle, 2}, + {"createEvent", DocumentEventCreateEvent, 1}, {"createElementWithNameSpace", NSDocumentCreateElementWithNameSpace, 2}, {"createRange", NSDocumentCreateRange, 0}, {"load", NSDocumentLoad, 2}, diff --git a/mozilla/dom/src/coreDOM/nsJSNode.cpp b/mozilla/dom/src/coreDOM/nsJSNode.cpp index cc56ca9930f..498fa3c2941 100644 --- a/mozilla/dom/src/coreDOM/nsJSNode.cpp +++ b/mozilla/dom/src/coreDOM/nsJSNode.cpp @@ -38,6 +38,7 @@ #include "nsIDOMNamedNodeMap.h" #include "nsIDOMNode.h" #include "nsIDOMEventListener.h" +#include "nsIDOMEvent.h" #include "nsIDOMEventTarget.h" #include "nsIDOMNodeList.h" @@ -49,6 +50,7 @@ static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID); static NS_DEFINE_IID(kINamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID); static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIEventListenerIID, NS_IDOMEVENTLISTENER_IID); +static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID); static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID); static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID); @@ -850,6 +852,58 @@ EventTargetRemoveEventListener(JSContext *cx, JSObject *obj, uintN argc, jsval * } +// +// Native method DispatchEvent +// +PR_STATIC_CALLBACK(JSBool) +EventTargetDispatchEvent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMNode *privateThis = (nsIDOMNode*)nsJSUtils::nsGetNativeThis(cx, obj); + nsCOMPtr nativeThis; + nsresult result = NS_OK; + if (NS_OK != privateThis->QueryInterface(kIEventTargetIID, getter_AddRefs(nativeThis))) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR); + } + + nsCOMPtr b0; + // If there's no private data, this must be the prototype, so ignore + if (!nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENTTARGET_DISPATCHEVENT, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0), + kIEventIID, + NS_ConvertASCIItoUCS2("Event"), + cx, + argv[0])) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR); + } + + result = nativeThis->DispatchEvent(b0); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + /***********************************************************************/ // // class for Node @@ -908,6 +962,7 @@ static JSFunctionSpec NodeMethods[] = {"supports", NodeSupports, 2}, {"addEventListener", EventTargetAddEventListener, 3}, {"removeEventListener", EventTargetRemoveEventListener, 3}, + {"dispatchEvent", EventTargetDispatchEvent, 1}, {0} }; diff --git a/mozilla/dom/src/events/nsJSEvent.cpp b/mozilla/dom/src/events/nsJSEvent.cpp index dc2d4d7b245..f8fcb810f25 100644 --- a/mozilla/dom/src/events/nsJSEvent.cpp +++ b/mozilla/dom/src/events/nsJSEvent.cpp @@ -34,15 +34,15 @@ #include "nsCOMPtr.h" #include "nsDOMPropEnums.h" #include "nsString.h" -#include "nsIDOMNode.h" #include "nsIDOMEvent.h" +#include "nsIDOMEventTarget.h" static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); -static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID); +static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID); // // Event property ids @@ -50,10 +50,11 @@ static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID); enum Event_slots { EVENT_TYPE = -1, EVENT_TARGET = -2, - EVENT_CURRENTNODE = -3, + EVENT_CURRENTTARGET = -3, EVENT_EVENTPHASE = -4, EVENT_BUBBLES = -5, - EVENT_CANCELABLE = -6 + EVENT_CANCELABLE = -6, + EVENT_TIMESTAMP = -7 }; /***********************************************************************/ @@ -92,7 +93,7 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_TARGET, PR_FALSE); if (NS_SUCCEEDED(rv)) { - nsIDOMNode* prop; + nsIDOMEventTarget* prop; rv = a->GetTarget(&prop); if (NS_SUCCEEDED(rv)) { // get the js object @@ -101,12 +102,12 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } - case EVENT_CURRENTNODE: + case EVENT_CURRENTTARGET: { - rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_CURRENTNODE, PR_FALSE); + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_CURRENTTARGET, PR_FALSE); if (NS_SUCCEEDED(rv)) { - nsIDOMNode* prop; - rv = a->GetCurrentNode(&prop); + nsIDOMEventTarget* prop; + rv = a->GetCurrentTarget(&prop); if (NS_SUCCEEDED(rv)) { // get the js object nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); @@ -150,6 +151,18 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } + case EVENT_TIMESTAMP: + { + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_TIMESTAMP, PR_FALSE); + if (NS_SUCCEEDED(rv)) { + PRUint64 prop; + rv = a->GetTimeStamp(&prop); + if (NS_SUCCEEDED(rv)) { + *vp = INT_TO_JSVAL(prop); + } + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp); } @@ -228,6 +241,41 @@ ResolveEvent(JSContext *cx, JSObject *obj, jsval id) } +// +// Native method StopPropagation +// +PR_STATIC_CALLBACK(JSBool) +EventStopPropagation(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMEvent *nativeThis = (nsIDOMEvent*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_STOPPROPAGATION, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + result = nativeThis->StopPropagation(); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + // // Native method PreventBubble // @@ -409,10 +457,11 @@ static JSPropertySpec EventProperties[] = { {"type", EVENT_TYPE, JSPROP_ENUMERATE | JSPROP_READONLY}, {"target", EVENT_TARGET, JSPROP_ENUMERATE | JSPROP_READONLY}, - {"currentNode", EVENT_CURRENTNODE, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"currentTarget", EVENT_CURRENTTARGET, 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}, + {"timeStamp", EVENT_TIMESTAMP, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; @@ -422,6 +471,7 @@ static JSPropertySpec EventProperties[] = // static JSFunctionSpec EventMethods[] = { + {"stopPropagation", EventStopPropagation, 0}, {"preventBubble", EventPreventBubble, 0}, {"preventCapture", EventPreventCapture, 0}, {"preventDefault", EventPreventDefault, 0}, diff --git a/mozilla/dom/src/events/nsJSKeyEvent.cpp b/mozilla/dom/src/events/nsJSKeyEvent.cpp index 3b4625ef52f..8e5a5e717dd 100644 --- a/mozilla/dom/src/events/nsJSKeyEvent.cpp +++ b/mozilla/dom/src/events/nsJSKeyEvent.cpp @@ -37,7 +37,7 @@ #include "nsIDOMMouseEvent.h" #include "nsIDOMKeyEvent.h" #include "nsIDOMAbstractView.h" -#include "nsIDOMNode.h" +#include "nsIDOMEventTarget.h" static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); @@ -46,7 +46,7 @@ static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); static NS_DEFINE_IID(kIMouseEventIID, NS_IDOMMOUSEEVENT_IID); static NS_DEFINE_IID(kIKeyEventIID, NS_IDOMKEYEVENT_IID); static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID); -static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID); // // KeyEvent property ids @@ -63,8 +63,7 @@ enum KeyEvent_slots { MOUSEEVENT_CLIENTX = -9, MOUSEEVENT_CLIENTY = -10, MOUSEEVENT_BUTTON = -11, - MOUSEEVENT_CLICKCOUNT = -12, - MOUSEEVENT_RELATEDNODE = -13 + MOUSEEVENT_RELATEDTARGET = -12 }; /***********************************************************************/ @@ -254,33 +253,14 @@ GetKeyEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } break; } - case MOUSEEVENT_CLICKCOUNT: + case MOUSEEVENT_RELATEDTARGET: { - rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MOUSEEVENT_CLICKCOUNT, PR_FALSE); + rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MOUSEEVENT_RELATEDTARGET, PR_FALSE); if (NS_SUCCEEDED(rv)) { - PRUint16 prop; + nsIDOMEventTarget* prop; nsIDOMMouseEvent* b; if (NS_OK == a->QueryInterface(kIMouseEventIID, (void **)&b)) { - rv = b->GetClickCount(&prop); - if(NS_SUCCEEDED(rv)) { - *vp = INT_TO_JSVAL(prop); - } - NS_RELEASE(b); - } - else { - rv = NS_ERROR_DOM_WRONG_TYPE_ERR; - } - } - break; - } - case MOUSEEVENT_RELATEDNODE: - { - rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MOUSEEVENT_RELATEDNODE, PR_FALSE); - if (NS_SUCCEEDED(rv)) { - nsIDOMNode* prop; - nsIDOMMouseEvent* b; - if (NS_OK == a->QueryInterface(kIMouseEventIID, (void **)&b)) { - rv = b->GetRelatedNode(&prop); + rv = b->GetRelatedTarget(&prop); if(NS_SUCCEEDED(rv)) { // get the js object nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp); @@ -574,8 +554,7 @@ static JSPropertySpec KeyEventProperties[] = {"clientX", MOUSEEVENT_CLIENTX, JSPROP_ENUMERATE | JSPROP_READONLY}, {"clientY", MOUSEEVENT_CLIENTY, JSPROP_ENUMERATE | JSPROP_READONLY}, {"button", MOUSEEVENT_BUTTON, JSPROP_ENUMERATE | JSPROP_READONLY}, - {"clickCount", MOUSEEVENT_CLICKCOUNT, JSPROP_ENUMERATE | JSPROP_READONLY}, - {"relatedNode", MOUSEEVENT_RELATEDNODE, JSPROP_ENUMERATE | JSPROP_READONLY}, + {"relatedTarget", MOUSEEVENT_RELATEDTARGET, JSPROP_ENUMERATE | JSPROP_READONLY}, {0} }; diff --git a/mozilla/dom/tools/FileGen.cpp b/mozilla/dom/tools/FileGen.cpp index b4558220188..a6b546e8eb6 100644 --- a/mozilla/dom/tools/FileGen.cpp +++ b/mozilla/dom/tools/FileGen.cpp @@ -125,12 +125,18 @@ FileGen::GetVariableTypeForMethodLocal(char *aBuffer, IdlVariable &aVariable) case TYPE_LONG: strcpy(aBuffer, "PRInt32"); break; + case TYPE_LONG_LONG: + strcpy(aBuffer, "PRInt64"); + break; case TYPE_SHORT: strcpy(aBuffer, "PRInt32"); break; case TYPE_ULONG: strcpy(aBuffer, "PRUint32"); break; + case TYPE_ULONG_LONG: + strcpy(aBuffer, "PRUint64"); + break; case TYPE_USHORT: strcpy(aBuffer, "PRUint32"); break; @@ -177,12 +183,18 @@ FileGen::GetVariableTypeForLocal(char *aBuffer, IdlVariable &aVariable) case TYPE_LONG: strcpy(aBuffer, "PRInt32"); break; + case TYPE_LONG_LONG: + strcpy(aBuffer, "PRInt64"); + break; case TYPE_SHORT: strcpy(aBuffer, "PRInt16"); break; case TYPE_ULONG: strcpy(aBuffer, "PRUint32"); break; + case TYPE_ULONG_LONG: + strcpy(aBuffer, "PRUint64"); + break; case TYPE_USHORT: strcpy(aBuffer, "PRUint16"); break; @@ -229,12 +241,18 @@ FileGen::GetVariableTypeForParameter(char *aBuffer, IdlVariable &aVariable) case TYPE_LONG: strcpy(aBuffer, "PRInt32"); break; + case TYPE_LONG_LONG: + strcpy(aBuffer, "PRInt64"); + break; case TYPE_SHORT: strcpy(aBuffer, "PRInt16"); break; case TYPE_ULONG: strcpy(aBuffer, "PRUint32"); break; + case TYPE_ULONG_LONG: + strcpy(aBuffer, "PRUint64"); + break; case TYPE_USHORT: strcpy(aBuffer, "PRUint16"); break; diff --git a/mozilla/dom/tools/IdlInterface.cpp b/mozilla/dom/tools/IdlInterface.cpp index ea4ab1cfd8e..e5e36ba96ec 100644 --- a/mozilla/dom/tools/IdlInterface.cpp +++ b/mozilla/dom/tools/IdlInterface.cpp @@ -56,9 +56,11 @@ ostream& operator<<(ostream &s, IdlInterface &aInterface) Type constType = constObj->GetType(); if (constType == TYPE_INT || constType == TYPE_LONG || + constType == TYPE_LONG_LONG || constType == TYPE_SHORT || constType == TYPE_UINT || constType == TYPE_ULONG || + constType == TYPE_ULONG_LONG || constType == TYPE_USHORT) { s << constObj->GetLongValue() << ";\n"; } diff --git a/mozilla/dom/tools/IdlParser.cpp b/mozilla/dom/tools/IdlParser.cpp index 43d46e25f2d..722f10d41f6 100644 --- a/mozilla/dom/tools/IdlParser.cpp +++ b/mozilla/dom/tools/IdlParser.cpp @@ -468,12 +468,18 @@ IdlVariable* IdlParser::ParseConst(IdlSpecification &aSpecification) case LONG_TOKEN: constObj->SetType(TYPE_LONG); break; + case LONG_LONG_TOKEN: + constObj->SetType(TYPE_LONG_LONG); + break; case SHORT_TOKEN: constObj->SetType(TYPE_SHORT); break; case ULONG_TOKEN: constObj->SetType(TYPE_ULONG); break; + case ULONG_LONG_TOKEN: + constObj->SetType(TYPE_ULONG_LONG); + break; case USHORT_TOKEN: constObj->SetType(TYPE_USHORT); break; @@ -625,12 +631,18 @@ IdlAttribute* IdlParser::ParseAttribute(IdlSpecification &aSpecification, int aT case LONG_TOKEN: attrObj->SetType(TYPE_LONG); break; + case LONG_LONG_TOKEN: + attrObj->SetType(TYPE_LONG_LONG); + break; case SHORT_TOKEN: attrObj->SetType(TYPE_SHORT); break; case ULONG_TOKEN: attrObj->SetType(TYPE_ULONG); break; + case ULONG_LONG_TOKEN: + attrObj->SetType(TYPE_ULONG_LONG); + break; case USHORT_TOKEN: attrObj->SetType(TYPE_USHORT); break; @@ -717,12 +729,18 @@ IdlFunction* IdlParser::ParseFunction(IdlSpecification &aSpecification, Token *a case LONG_TOKEN: funcObj->SetReturnValue(TYPE_LONG); break; + case LONG_LONG_TOKEN: + funcObj->SetReturnValue(TYPE_LONG_LONG); + break; case SHORT_TOKEN: funcObj->SetReturnValue(TYPE_SHORT); break; case ULONG_TOKEN: funcObj->SetReturnValue(TYPE_ULONG); break; + case ULONG_LONG_TOKEN: + funcObj->SetReturnValue(TYPE_ULONG_LONG); + break; case USHORT_TOKEN: funcObj->SetReturnValue(TYPE_USHORT); break; @@ -969,12 +987,18 @@ IdlParameter* IdlParser::ParseFunctionParameter(IdlSpecification &aSpecification case LONG_TOKEN: argObj->SetType(TYPE_LONG); break; + case LONG_LONG_TOKEN: + argObj->SetType(TYPE_LONG_LONG); + break; case SHORT_TOKEN: argObj->SetType(TYPE_SHORT); break; case ULONG_TOKEN: argObj->SetType(TYPE_ULONG); break; + case ULONG_LONG_TOKEN: + argObj->SetType(TYPE_ULONG_LONG); + break; case USHORT_TOKEN: argObj->SetType(TYPE_USHORT); break; diff --git a/mozilla/dom/tools/IdlScanner.cpp b/mozilla/dom/tools/IdlScanner.cpp index bbccc729e48..3eb0620e4c3 100644 --- a/mozilla/dom/tools/IdlScanner.cpp +++ b/mozilla/dom/tools/IdlScanner.cpp @@ -800,7 +800,29 @@ void IdlScanner::LKeywords(char *aCurrentPos, Token *aToken) // if terminated is a keyword c = mInputFile->get(); if (c != EOF) { - if (isalpha(c) || isdigit(c) || c == '_') { + if (c == 'l' && (*aCurrentPos++ = c) && (c = mInputFile->get()) && + c != EOF && c == 'o' && (*aCurrentPos++ = c) && (c = mInputFile->get()) && + c != EOF && c == 'n' && (*aCurrentPos++ = c) && (c = mInputFile->get()) && + c != EOF && c == 'g' && (*aCurrentPos++ = c)) { + // if terminated is a keyword + c = mInputFile->get(); + if (c != EOF) { + if (isalpha(c) || isdigit(c) || c == '_') { + // more characters, it must be an identifier + *aCurrentPos++ = c; + Identifier(aCurrentPos, aToken); + } + else { + // it is a keyword + aToken->SetToken(LONG_LONG_TOKEN); + mInputFile->putback(c); + } + } + else { + aToken->SetToken(LONG_LONG_TOKEN); + } + } + else if (isalpha(c) || isdigit(c) || c == '_') { // more characters, it must be an identifier *aCurrentPos++ = c; Identifier(aCurrentPos, aToken); @@ -1166,6 +1188,9 @@ void IdlScanner::UKeywords(char *aCurrentPos, Token *aToken) else if (LONG_TOKEN == mCurrentToken->id) { aToken->SetToken(ULONG_TOKEN); } + else if (LONG_LONG_TOKEN == mCurrentToken->id) { + aToken->SetToken(ULONG_LONG_TOKEN); + } } } } diff --git a/mozilla/dom/tools/IdlScanner.h b/mozilla/dom/tools/IdlScanner.h index 673b4ff69a9..b295cd93488 100644 --- a/mozilla/dom/tools/IdlScanner.h +++ b/mozilla/dom/tools/IdlScanner.h @@ -56,8 +56,10 @@ enum EIDLTokenType { FLOAT_TOKEN, DOUBLE_TOKEN, LONG_TOKEN, + LONG_LONG_TOKEN, SHORT_TOKEN, ULONG_TOKEN, + ULONG_LONG_TOKEN, USHORT_TOKEN, CHAR_TOKEN, INT_TOKEN, diff --git a/mozilla/dom/tools/IdlVariable.cpp b/mozilla/dom/tools/IdlVariable.cpp index 05cefc115ac..fbddaebe3bf 100644 --- a/mozilla/dom/tools/IdlVariable.cpp +++ b/mozilla/dom/tools/IdlVariable.cpp @@ -94,6 +94,11 @@ void IdlVariable::GetTypeAsString(char *aString, size_t aStringSize) strcpy(aString, "long"); } break; + case TYPE_LONG_LONG: + if (aStringSize > 9) { + strcpy(aString, "long long"); + } + break; case TYPE_SHORT: if (aStringSize > 5) { strcpy(aString, "short"); @@ -104,6 +109,11 @@ void IdlVariable::GetTypeAsString(char *aString, size_t aStringSize) strcpy(aString, "unsigned long"); } break; + case TYPE_ULONG_LONG: + if (aStringSize > 18) { + strcpy(aString, "unsigned long long"); + } + break; case TYPE_USHORT: if (aStringSize > 14) { strcpy(aString, "unsigned short"); diff --git a/mozilla/dom/tools/IdlVariable.h b/mozilla/dom/tools/IdlVariable.h index 8776dba01ae..645a41d0b4e 100644 --- a/mozilla/dom/tools/IdlVariable.h +++ b/mozilla/dom/tools/IdlVariable.h @@ -34,8 +34,10 @@ enum Type { TYPE_FLOAT, TYPE_DOUBLE, TYPE_LONG, + TYPE_LONG_LONG, TYPE_SHORT, TYPE_ULONG, + TYPE_ULONG_LONG, TYPE_USHORT, TYPE_CHAR, TYPE_INT, diff --git a/mozilla/dom/tools/JSStubGen.cpp b/mozilla/dom/tools/JSStubGen.cpp index 114efdf3dde..505f630cd3f 100644 --- a/mozilla/dom/tools/JSStubGen.cpp +++ b/mozilla/dom/tools/JSStubGen.cpp @@ -744,8 +744,10 @@ JSStubGen::GeneratePropGetter(ofstream *file, case_str = kBoolGetCaseStr; break; case TYPE_LONG: + case TYPE_LONG_LONG: case TYPE_SHORT: case TYPE_ULONG: + case TYPE_ULONG_LONG: case TYPE_USHORT: case TYPE_CHAR: case TYPE_INT: @@ -904,8 +906,10 @@ JSStubGen::GeneratePropSetter(ofstream *file, sprintf(case_buf, kBoolSetCaseStr); break; case TYPE_LONG: + case TYPE_LONG_LONG: case TYPE_SHORT: case TYPE_ULONG: + case TYPE_ULONG_LONG: case TYPE_USHORT: case TYPE_CHAR: case TYPE_INT: @@ -1423,8 +1427,10 @@ JSStubGen::GenerateMethods(IdlSpecification &aSpec) JSGEN_GENERATE_BOOLPARAM(buf, p); break; case TYPE_LONG: + case TYPE_LONG_LONG: case TYPE_SHORT: case TYPE_ULONG: + case TYPE_ULONG_LONG: case TYPE_USHORT: case TYPE_CHAR: case TYPE_INT: @@ -1494,8 +1500,10 @@ JSStubGen::GenerateMethods(IdlSpecification &aSpec) *file << kMethodBoolRetStr; break; case TYPE_LONG: + case TYPE_LONG_LONG: case TYPE_SHORT: case TYPE_ULONG: + case TYPE_ULONG_LONG: case TYPE_USHORT: case TYPE_CHAR: case TYPE_INT: diff --git a/mozilla/editor/base/nsEditorShellMouseListener.cpp b/mozilla/editor/base/nsEditorShellMouseListener.cpp index 2350ac26948..79d186172ea 100644 --- a/mozilla/editor/base/nsEditorShellMouseListener.cpp +++ b/mozilla/editor/base/nsEditorShellMouseListener.cpp @@ -30,6 +30,7 @@ #include "nsIDOMElement.h" #include "nsIDOMMouseEvent.h" #include "nsIDOMSelection.h" +#include "nsIDOMEventTarget.h" /* * nsEditorShellMouseListener implementation @@ -100,11 +101,11 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) // What about Mac? if (mEditorShell && buttonNumber == 3) { - nsCOMPtr node; - if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node) + nsCOMPtr target; + if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target) { // We are only interested in elements, not text nodes - nsCOMPtr element = do_QueryInterface(node); + nsCOMPtr element = do_QueryInterface(target); if (element) { // Set selection to node clicked on @@ -125,11 +126,11 @@ nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent) return NS_OK; } // Detect double click message: - PRUint16 clickCount; - nsresult res = mouseEvent->GetClickCount(&clickCount); + PRInt32 clickCount; + nsresult res = mouseEvent->GetDetail(&clickCount); if (NS_FAILED(res)) return res; - nsCOMPtr node; + nsCOMPtr node; if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node) { // We are only interested in elements, not text nodes diff --git a/mozilla/editor/composer/src/nsEditorShellMouseListener.cpp b/mozilla/editor/composer/src/nsEditorShellMouseListener.cpp index 2350ac26948..79d186172ea 100644 --- a/mozilla/editor/composer/src/nsEditorShellMouseListener.cpp +++ b/mozilla/editor/composer/src/nsEditorShellMouseListener.cpp @@ -30,6 +30,7 @@ #include "nsIDOMElement.h" #include "nsIDOMMouseEvent.h" #include "nsIDOMSelection.h" +#include "nsIDOMEventTarget.h" /* * nsEditorShellMouseListener implementation @@ -100,11 +101,11 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) // What about Mac? if (mEditorShell && buttonNumber == 3) { - nsCOMPtr node; - if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node) + nsCOMPtr target; + if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target) { // We are only interested in elements, not text nodes - nsCOMPtr element = do_QueryInterface(node); + nsCOMPtr element = do_QueryInterface(target); if (element) { // Set selection to node clicked on @@ -125,11 +126,11 @@ nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent) return NS_OK; } // Detect double click message: - PRUint16 clickCount; - nsresult res = mouseEvent->GetClickCount(&clickCount); + PRInt32 clickCount; + nsresult res = mouseEvent->GetDetail(&clickCount); if (NS_FAILED(res)) return res; - nsCOMPtr node; + nsCOMPtr node; if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node) { // We are only interested in elements, not text nodes diff --git a/mozilla/editor/ui/dialogs/content/EdImageMapShapes.js b/mozilla/editor/ui/dialogs/content/EdImageMapShapes.js index 83345ed8488..e88d34d1480 100644 --- a/mozilla/editor/ui/dialogs/content/EdImageMapShapes.js +++ b/mozilla/editor/ui/dialogs/content/EdImageMapShapes.js @@ -198,7 +198,7 @@ function addPoint(event, pointX, pointY, start){ pointX = event.clientX; pointY = event.clientY; event.preventBubble(); - if (event.clickCount == 2){ + if (event.detail == 2){ polyFinish(); return; } @@ -636,7 +636,7 @@ function clickMouse(event){ startX = event.clientX; startY = event.clientY; if (currentTool == "poly"){ - //dump(event.clickCount+"\n"); + //dump(event.detail+"\n"); if (event.target != currentPoly){ //else if (event.target.getAttribute("class").indexOf("point") == -1) Poly(); diff --git a/mozilla/extensions/xmlterm/ui/XMLTermCommands.js b/mozilla/extensions/xmlterm/ui/XMLTermCommands.js index 2a7633fa666..a1f4b10d8f2 100644 --- a/mozilla/extensions/xmlterm/ui/XMLTermCommands.js +++ b/mozilla/extensions/xmlterm/ui/XMLTermCommands.js @@ -418,10 +418,10 @@ function HandleEvent(eventObj, eventType, targetType, entryNumber, } else if (eventType === "click") { - dump("clickCount="+eventObj.clickCount+"\n"); + dump("clickCount="+eventObj.detail+"\n"); var shiftClick = eventObj.shiftKey; - var dblClick = (eventObj.clickCount == 2); + var dblClick = (eventObj.detail == 2); // Execute shell commands only on double-click for safety // Use single click for "selection" and prompt expansion only diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 9897a6667b5..58b59cf526f 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -1995,7 +1995,7 @@ PresShell::ScrollLine(PRBool aForward) result = viewManager->GetRootScrollableView(&scrollView); if (NS_SUCCEEDED(result) && scrollView) { - scrollView->ScrollByLines(aForward ? 1 : -1); + scrollView->ScrollByLines(0, aForward ? 1 : -1); //NEW FOR LINES // force the update to happen now, otherwise multiple scrolls can // occur before the update is processed. (bug #7354) @@ -2012,7 +2012,26 @@ PresShell::ScrollLine(PRBool aForward) NS_IMETHODIMP PresShell::ScrollHorizontal(PRBool aLeft) { - return NS_ERROR_NOT_IMPLEMENTED; + nsCOMPtr viewManager; + nsresult result = GetViewManager(getter_AddRefs(viewManager)); + if (NS_SUCCEEDED(result) && viewManager) + { + nsIScrollableView *scrollView; + result = viewManager->GetRootScrollableView(&scrollView); + if (NS_SUCCEEDED(result) && scrollView) + { + scrollView->ScrollByLines(aLeft ? -1 : 1, 0); +//NEW FOR LINES + // force the update to happen now, otherwise multiple scrolls can + // occur before the update is processed. (bug #7354) + + // I'd use Composite here, but it doesn't always work. + // vm->Composite(); + viewManager->ForceUpdate(); + } + } + + return result; } NS_IMETHODIMP diff --git a/mozilla/layout/base/src/nsDocument.cpp b/mozilla/layout/base/src/nsDocument.cpp index f287b576077..742c2982c76 100644 --- a/mozilla/layout/base/src/nsDocument.cpp +++ b/mozilla/layout/base/src/nsDocument.cpp @@ -688,6 +688,12 @@ nsresult nsDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_ADDREF_THIS(); return NS_OK; } + if (aIID.Equals(NS_GET_IID(nsIDOMDocumentEvent))) { + nsIDOMDocumentEvent* tmp = this; + *aInstancePtr = (void*) tmp; + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(NS_GET_IID(nsIDOMDocumentStyle))) { nsIDOMDocumentStyle* tmp = this; *aInstancePtr = (void*) tmp; @@ -2628,7 +2634,7 @@ nsresult nsDocument::GetNewListenerManager(nsIEventListenerManager **aInstancePt nsresult nsDocument::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, @@ -2640,9 +2646,10 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, nsresult mRet = NS_OK; nsIDOMEvent* mDOMEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &mDOMEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); } //Capturing stage @@ -2651,9 +2658,10 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, } //Local handling stage - if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { + if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && + !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -2662,7 +2670,7 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, release here. if (nsnull != *aDOMEvent) { nsrefcnt rc; @@ -2731,6 +2739,52 @@ nsresult nsDocument::RemoveEventListener(const nsString& aType, nsIDOMEventListe return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsDocument::DispatchEvent(nsIDOMEvent* aEvent) +{ + // Obtain a presentation context + PRInt32 count = GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(GetShellAt(0)); + + // Retrieve the context + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent((nsISupports *)(nsIDOMDocument *)this, aEvent); + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsDocument::CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn) +{ + // Obtain a presentation context + PRInt32 count = GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(GetShellAt(0)); + + // Retrieve the context + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + + if (presContext) { + nsCOMPtr lm; + if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(lm)))) { + return lm->CreateEvent(presContext, nsnull, aEventType, aReturn); + } + } + + return NS_ERROR_FAILURE; +} + PRBool nsDocument::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) { return PR_TRUE; diff --git a/mozilla/layout/base/src/nsDocument.h b/mozilla/layout/base/src/nsDocument.h index 5004723cfa8..0d184090494 100644 --- a/mozilla/layout/base/src/nsDocument.h +++ b/mozilla/layout/base/src/nsDocument.h @@ -42,6 +42,7 @@ #include "nsIPrincipal.h" #include "nsIBindingManager.h" #include "nsINodeInfo.h" +#include "nsIDOMDocumentEvent.h" class nsIEventListenerManager; class nsDOMStyleSheetList; @@ -113,6 +114,7 @@ protected: class nsDocument : public nsIDocument, public nsIDOMDocument, public nsIDOMNSDocument, + public nsIDOMDocumentEvent, public nsIDOMDocumentStyle, public nsIDOMDocumentView, public nsIDiskDocument, @@ -371,6 +373,9 @@ public: // nsIDOMDocumentView NS_DECL_IDOMDOCUMENTVIEW + // nsIDOMDocumentEvent + NS_DECL_IDOMDOCUMENTEVENT + // nsIDOMEventReceiver interface NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); @@ -397,6 +402,7 @@ public: PRBool aUseCapture); NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, diff --git a/mozilla/layout/base/src/nsGenericDOMDataNode.cpp b/mozilla/layout/base/src/nsGenericDOMDataNode.cpp index d296e2e6766..21e76bf7f81 100644 --- a/mozilla/layout/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/layout/base/src/nsGenericDOMDataNode.cpp @@ -71,7 +71,10 @@ nsGenericDOMDataNode::nsGenericDOMDataNode() nsGenericDOMDataNode::~nsGenericDOMDataNode() { - NS_IF_RELEASE(mListenerManager); + if (mListenerManager) { + mListenerManager->SetListenerTarget(nsnull); + NS_RELEASE(mListenerManager); + } delete mRangeList; } @@ -529,7 +532,7 @@ nsGenericDOMDataNode::SetScriptObject(void *aScriptObject) //---------------------------------------------------------------------- nsresult -nsGenericDOMDataNode::GetListenerManager(nsIEventListenerManager** aResult) +nsGenericDOMDataNode::GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aResult) { if (nsnull != mListenerManager) { NS_ADDREF(mListenerManager); @@ -540,6 +543,7 @@ nsGenericDOMDataNode::GetListenerManager(nsIEventListenerManager** aResult) if (NS_OK == rv) { mListenerManager = *aResult; NS_ADDREF(mListenerManager); + mListenerManager->SetListenerTarget(aOuterContent); } return rv; } @@ -748,9 +752,10 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext, nsresult ret = NS_OK; nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); //Initiate capturing phase. Special case first call to document if (nsnull != mDocument) { @@ -765,9 +770,10 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext, } //Local handling stage - if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { + if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && + !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, nsnull, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -777,7 +783,7 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext, NS_EVENT_FLAG_BUBBLE, aEventStatus); } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, // release here. if (nsnull != *aDOMEvent) { diff --git a/mozilla/layout/base/src/nsGenericDOMDataNode.h b/mozilla/layout/base/src/nsGenericDOMDataNode.h index ca18ec5c68f..df1383235c2 100644 --- a/mozilla/layout/base/src/nsGenericDOMDataNode.h +++ b/mozilla/layout/base/src/nsGenericDOMDataNode.h @@ -260,7 +260,7 @@ struct nsGenericDOMDataNode { //---------------------------------------- - nsresult GetListenerManager(nsIEventListenerManager** aInstancePtrResult); + nsresult GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aInstancePtrResult); void ToCString(nsString& aBuf, PRInt32 aOffset, PRInt32 aLen) const; @@ -609,14 +609,14 @@ struct nsGenericDOMDataNode { } \ if (_id.Equals(kIDOMEventReceiverIID)) { \ nsCOMPtr man; \ - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ \ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ return man->QueryInterface(kIDOMEventReceiverIID, (void**)_iptr); \ } \ return NS_NOINTERFACE; \ } \ if (_id.Equals(kIDOMEventTargetIID)) { \ nsCOMPtr man; \ - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ \ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ return man->QueryInterface(kIDOMEventTargetIID, (void**)_iptr); \ } \ return NS_NOINTERFACE; \ diff --git a/mozilla/layout/base/src/nsGenericElement.cpp b/mozilla/layout/base/src/nsGenericElement.cpp index 501d053b535..983741df8ff 100644 --- a/mozilla/layout/base/src/nsGenericElement.cpp +++ b/mozilla/layout/base/src/nsGenericElement.cpp @@ -401,7 +401,10 @@ nsGenericElement::~nsGenericElement() mDOMSlots->mAttributeMap->DropReference(); NS_RELEASE(mDOMSlots->mAttributeMap); } - NS_IF_RELEASE(mDOMSlots->mListenerManager); + if (nsnull != mDOMSlots->mListenerManager) { + mDOMSlots->mListenerManager->SetListenerTarget(nsnull); + NS_RELEASE(mDOMSlots->mListenerManager); + } // XXX Should really be arena managed PR_DELETE(mDOMSlots); } @@ -1284,9 +1287,10 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext, nsresult ret = NS_OK; nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); } //Capturing stage evaluation @@ -1310,9 +1314,11 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext, } //Local handling stage - if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { + if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && + !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { aEvent->flags |= aFlags; - mDOMSlots->mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + nsCOMPtr curTarg(do_QueryInterface(mContent)); + mDOMSlots->mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, curTarg, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -1334,7 +1340,7 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext, } } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, // release here. if (nsnull != *aDOMEvent) { @@ -1557,6 +1563,7 @@ nsGenericElement::GetListenerManager(nsIEventListenerManager** aResult) if (NS_OK == rv) { slots->mListenerManager = *aResult; NS_ADDREF(slots->mListenerManager); + slots->mListenerManager->SetListenerTarget(mContent); } return rv; } diff --git a/mozilla/layout/events/public/nsIEventListenerManager.h b/mozilla/layout/events/public/nsIEventListenerManager.h index 0b717c5bcde..81a2113843f 100644 --- a/mozilla/layout/events/public/nsIEventListenerManager.h +++ b/mozilla/layout/events/public/nsIEventListenerManager.h @@ -30,6 +30,7 @@ class nsIPresContext; class nsIDOMEventListener; class nsIScriptObjectOwner; +class nsIDOMEventTarget; /* * Event listener manager interface. @@ -104,6 +105,7 @@ public: virtual nsresult HandleEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aFlags, nsEventStatus* aEventStatus) = 0; @@ -114,6 +116,7 @@ public: */ virtual nsresult CreateEvent(nsIPresContext* aPresContext, nsEvent* aEvent, + const nsString& aEventType, nsIDOMEvent** aDOMEvent) = 0; /** @@ -133,6 +136,12 @@ public: * manager. */ virtual nsresult RemoveAllListeners(PRBool aScriptOnly) = 0; + + /** + * Removes all event listeners registered by this instance of the listener + * manager. + */ + virtual nsresult SetListenerTarget(nsISupports* aTarget) = 0; }; extern NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult); diff --git a/mozilla/layout/events/public/nsIEventStateManager.h b/mozilla/layout/events/public/nsIEventStateManager.h index cfe62177e5e..96f94d7cc1a 100644 --- a/mozilla/layout/events/public/nsIEventStateManager.h +++ b/mozilla/layout/events/public/nsIEventStateManager.h @@ -83,6 +83,8 @@ public: NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor) = 0; + //Method for centralized distribution of new DOM events + NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent) = 0; }; #define NS_EVENT_STATE_UNSPECIFIED 0x0000 diff --git a/mozilla/layout/events/public/nsIPrivateDOMEvent.h b/mozilla/layout/events/public/nsIPrivateDOMEvent.h index 62c0f15d886..f3b4f5d6987 100644 --- a/mozilla/layout/events/public/nsIPrivateDOMEvent.h +++ b/mozilla/layout/events/public/nsIPrivateDOMEvent.h @@ -36,7 +36,7 @@ class nsIPresContext; 0x80a98c80, 0x2036, 0x11d2, \ {0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} } -class nsIDOMNode; +class nsIDOMEventTarget; class nsIDOMEvent; class nsIPrivateDOMEvent : public nsISupports { @@ -45,11 +45,15 @@ public: static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATEDOMEVENT_IID; return iid; } NS_IMETHOD DuplicatePrivateData() = 0; - NS_IMETHOD SetTarget(nsIDOMNode* aNode) = 0; + NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) = 0; + NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aTarget) = 0; NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0; }; extern nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent); -extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent); +extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, + nsIPresContext* aPresContext, + const nsString& aEventType, + nsEvent *aEvent); #endif // nsIPrivateDOMEvent_h__ diff --git a/mozilla/layout/events/src/nsDOMEvent.cpp b/mozilla/layout/events/src/nsDOMEvent.cpp index 1bed17d560b..e1f4f9fd41c 100644 --- a/mozilla/layout/events/src/nsDOMEvent.cpp +++ b/mozilla/layout/events/src/nsDOMEvent.cpp @@ -34,6 +34,12 @@ #include "nsIViewManager.h" #include "nsIPrivateCompositionEvent.h" #include "nsIScrollableView.h" +#include "nsIDOMEventTarget.h" +#include "nsIInterfaceRequestor.h" +#include "nsIDOMWindow.h" +#include "nsIDOMAbstractView.h" +#include "prmem.h" +#include "nsLayoutAtoms.h" static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID); @@ -46,16 +52,39 @@ static char* mEventNames[] = { "dragenter", "dragover", "dragexit", "dragdrop", "draggesture" }; -nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) { +nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsString& aEventType) { mPresContext = aPresContext; if (mPresContext) NS_ADDREF(mPresContext); - mEvent = aEvent; + if (aEvent) { + mEventIsInternal = PR_FALSE; + mEvent = aEvent; + } + else { + //Allocate internal event + if (aEventType.EqualsIgnoreCase("MouseEvent")) { + mEvent = PR_NEWZAP(nsMouseEvent); + mEvent->eventStructType = NS_MOUSE_EVENT; + } + else if (aEventType.EqualsIgnoreCase("KeyEvent")) { + mEvent = PR_NEWZAP(nsKeyEvent); + mEvent->eventStructType = NS_KEY_EVENT; + } + else if (aEventType.EqualsIgnoreCase("HTMLEvent")) { + mEvent = PR_NEWZAP(nsEvent); + mEvent->eventStructType = NS_EVENT; + } + else { + mEvent = PR_NEWZAP(nsEvent); + mEvent->eventStructType = NS_EVENT; + } + } mTarget = nsnull; + mCurrentTarget = nsnull; mText = nsnull; mTextRange = nsnull; - if (aEvent->eventStructType ==NS_TEXT_EVENT) { + if (aEvent->eventStructType == NS_TEXT_EVENT) { // // extract the IME composition string // @@ -87,8 +116,13 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) { nsDOMEvent::~nsDOMEvent() { NS_IF_RELEASE(mPresContext); NS_IF_RELEASE(mTarget); + NS_IF_RELEASE(mCurrentTarget); NS_IF_RELEASE(mTextRange); + if (mEventIsInternal) { + PR_DELETE(mEvent); + } + if (mText!=nsnull) delete mText; } @@ -121,7 +155,7 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType) return NS_ERROR_FAILURE; } -NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) +NS_METHOD nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget) { if (nsnull != mTarget) { *aTarget = mTarget; @@ -138,7 +172,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) } if (targetContent) { - if (NS_OK == targetContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&mTarget)) { + if (NS_OK == targetContent->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)&mTarget)) { *aTarget = mTarget; NS_ADDREF(mTarget); } @@ -154,7 +188,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) } if (doc) { - if (NS_OK == doc->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&mTarget)) { + if (NS_OK == doc->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)&mTarget)) { *aTarget = mTarget; NS_ADDREF(mTarget); } @@ -166,9 +200,9 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget) } NS_IMETHODIMP -nsDOMEvent::GetCurrentNode(nsIDOMNode** aCurrentNode) +nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) { - *aCurrentNode = nsnull; + *aCurrentTarget = nsnull; return NS_OK; } @@ -194,13 +228,29 @@ nsDOMEvent::GetEventPhase(PRUint16* aEventPhase) NS_IMETHODIMP nsDOMEvent::GetBubbles(PRBool* aBubbles) { - return NS_ERROR_NOT_IMPLEMENTED; + *aBubbles = mEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE; + return NS_OK; } NS_IMETHODIMP nsDOMEvent::GetCancelable(PRBool* aCancelable) { - return NS_ERROR_NOT_IMPLEMENTED; + *aCancelable = mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMEvent::GetTimeStamp(PRUint64* aTimeStamp) +{ + *aTimeStamp = mEvent->time; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMEvent::StopPropagation() +{ + mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH; + return NS_OK; } NS_IMETHODIMP @@ -224,20 +274,64 @@ nsDOMEvent::PreventCapture() NS_IMETHODIMP nsDOMEvent::PreventDefault() { - mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT; + if (!(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL)) { + mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT; + } return NS_OK; } NS_IMETHODIMP nsDOMEvent::GetView(nsIDOMAbstractView** aView) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_ARG_POINTER(aView); + *aView = nsnull; + nsresult rv = NS_OK; + + nsCOMPtr container; + rv = mPresContext->GetContainer(getter_AddRefs(container)); + NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv); + + nsCOMPtr ifrq(do_QueryInterface(container)); + NS_ENSURE_TRUE(ifrq, NS_OK); + + nsCOMPtr window; + ifrq->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(window)); + NS_ENSURE_TRUE(window, NS_OK); + + window->QueryInterface(NS_GET_IID(nsIDOMAbstractView), (void **)aView); + + return rv; } NS_IMETHODIMP nsDOMEvent::GetDetail(PRInt32* aDetail) { - return NS_ERROR_NOT_IMPLEMENTED; + //detail is valid for more than just mouseevents but we don't + //use it for anything else right now + if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) { + *aDetail = 0; + return NS_OK; + } + + switch (mEvent->message) { + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_LEFT_CLICK: + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_CLICK: + case NS_MOUSE_MIDDLE_DOUBLECLICK: + case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_RIGHT_CLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + *aDetail = ((nsMouseEvent*)mEvent)->clickCount; + break; + default: + break; + } + return NS_OK; } NS_METHOD nsDOMEvent::GetText(nsString& aText) @@ -515,35 +609,7 @@ NS_METHOD nsDOMEvent::GetButton(PRUint16* aButton) return NS_OK; } -NS_METHOD nsDOMEvent::GetClickCount(PRUint16* aClickCount) -{ - if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) { - *aClickCount = 0; - return NS_OK; - } - - switch (mEvent->message) { - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_LEFT_CLICK: - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_CLICK: - case NS_MOUSE_MIDDLE_DOUBLECLICK: - case NS_MOUSE_RIGHT_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - case NS_MOUSE_RIGHT_CLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - *aClickCount = ((nsMouseEvent*)mEvent)->clickCount; - break; - default: - break; - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetRelatedNode(nsIDOMNode** aRelatedNode) +NS_METHOD nsDOMEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) { nsIEventStateManager *manager; nsIContent *relatedContent = nsnull; @@ -555,11 +621,11 @@ NS_METHOD nsDOMEvent::GetRelatedNode(nsIDOMNode** aRelatedNode) } if (relatedContent) { - ret = relatedContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aRelatedNode); + ret = relatedContent->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)aRelatedTarget); NS_RELEASE(relatedContent); } else { - *aRelatedNode = nsnull; + *aRelatedTarget = nsnull; } return ret; @@ -793,30 +859,109 @@ NS_METHOD nsDOMEvent::GetPreventDefault(PRBool* aReturn) return NS_OK; } -//XXX The following four methods are for custom event dispatch inside the DOM. -//They will be implemented post-beta +nsresult +nsDOMEvent::SetEventType(const nsString& aEventTypeArg) +{ + nsAutoString str; str.AssignWithConversion("on"); + nsIAtom* atom; + + str.Append(aEventTypeArg); + atom = NS_NewAtom(str); + + if (atom == nsLayoutAtoms::onmousedown && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_LEFT_BUTTON_DOWN; + } + else if (atom == nsLayoutAtoms::onmouseup && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_LEFT_BUTTON_UP; + } + else if (atom == nsLayoutAtoms::onclick && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_LEFT_CLICK; + } + else if (atom == nsLayoutAtoms::onmouseover && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_ENTER_SYNTH; + } + else if (atom == nsLayoutAtoms::onmouseout && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_EXIT_SYNTH; + } + else if (atom == nsLayoutAtoms::onmousemove && mEvent->eventStructType == NS_MOUSE_EVENT) { + mEvent->message = NS_MOUSE_MOVE; + } + else if (atom == nsLayoutAtoms::onkeydown && mEvent->eventStructType == NS_KEY_EVENT) { + mEvent->message = NS_KEY_DOWN; + } + else if (atom == nsLayoutAtoms::onkeyup && mEvent->eventStructType == NS_KEY_EVENT) { + mEvent->message = NS_KEY_UP; + } + else if (atom == nsLayoutAtoms::onkeypress && mEvent->eventStructType == NS_KEY_EVENT) { + mEvent->message = NS_KEY_PRESS; + } + else if (atom == nsLayoutAtoms::onfocus && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FOCUS_CONTENT; + } + else if (atom == nsLayoutAtoms::onblur && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_BLUR_CONTENT; + } + else if (atom == nsLayoutAtoms::onsubmit && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FORM_SUBMIT; + } + else if (atom == nsLayoutAtoms::onreset && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FORM_RESET; + } + else if (atom == nsLayoutAtoms::onchange && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FORM_CHANGE; + } + else if (atom == nsLayoutAtoms::onselect && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_FORM_SELECTED; + } + else if (atom == nsLayoutAtoms::onload && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_PAGE_LOAD; + } + else if (atom == nsLayoutAtoms::onunload && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_PAGE_UNLOAD; + } + else if (atom == nsLayoutAtoms::onabort && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_IMAGE_ABORT; + } + else if (atom == nsLayoutAtoms::onerror && mEvent->eventStructType == NS_EVENT) { + mEvent->message = NS_IMAGE_ERROR; + } + else { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::InitEvent(const nsString& aEventTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg), NS_ERROR_FAILURE); + mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE; + mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL; + return NS_OK; } NS_IMETHODIMP nsDOMEvent::InitUIEvent(const nsString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIDOMAbstractView* aViewArg, PRInt32 aDetailArg) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_FAILURE; } NS_IMETHODIMP nsDOMEvent::InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE); + //mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE; + //mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL; + return NS_OK; } NS_IMETHODIMP nsDOMEvent::InitKeyEvent(const nsString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg, nsIDOMAbstractView* aViewArg) { - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE); + mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE; + mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL; + return NS_OK; } @@ -828,7 +973,7 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData() return NS_OK; } -NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget) +NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget) { if (mTarget != aTarget) { NS_IF_RELEASE(mTarget); @@ -838,6 +983,16 @@ NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget) return NS_OK; } +NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget) +{ + if (mCurrentTarget != aCurrentTarget) { + NS_IF_RELEASE(mCurrentTarget); + NS_IF_ADDREF(aCurrentTarget); + mCurrentTarget = aCurrentTarget; + } + return NS_OK; +} + NS_IMETHODIMP nsDOMEvent::IsDispatchStopped(PRBool* aIsDispatchStopped) { @@ -936,9 +1091,12 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return nsnull; } -nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent) +nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, + nsIPresContext* aPresContext, + const nsString& aEventType, + nsEvent *aEvent) { - nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent); + nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent, aEventType); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/layout/events/src/nsDOMEvent.h b/mozilla/layout/events/src/nsDOMEvent.h index a5818713cfe..90be2ae6253 100644 --- a/mozilla/layout/events/src/nsDOMEvent.h +++ b/mozilla/layout/events/src/nsDOMEvent.h @@ -85,18 +85,20 @@ public: eDOMEvents_draggesture }; - nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent); + nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsString& aEventType); virtual ~nsDOMEvent(); NS_DECL_ISUPPORTS // nsIDOMEvent Interface NS_IMETHOD GetType(nsString& aType); - NS_IMETHOD GetTarget(nsIDOMNode** aTarget); - NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode); + NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget); + NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget); NS_IMETHOD GetEventPhase(PRUint16* aEventPhase); NS_IMETHOD GetBubbles(PRBool* aBubbles); NS_IMETHOD GetCancelable(PRBool* aCancelable); + NS_IMETHOD GetTimeStamp(PRUint64* aTimestamp); + NS_IMETHOD StopPropagation(); NS_IMETHOD PreventBubble(); NS_IMETHOD PreventCapture(); NS_IMETHOD PreventDefault(); @@ -117,8 +119,7 @@ public: NS_IMETHOD GetShiftKey(PRBool* aShiftKey); NS_IMETHOD GetMetaKey(PRBool* aMetaKey); NS_IMETHOD GetButton(PRUint16* aButton); - NS_IMETHOD GetClickCount(PRUint16* aClickCount); - NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode); + NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget); NS_IMETHOD GetCharCode(PRUint32* aCharCode); NS_IMETHOD GetKeyCode(PRUint32* aKeyCode); NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg); @@ -139,7 +140,8 @@ public: // nsIPrivateDOMEvent interface NS_IMETHOD DuplicatePrivateData(); - NS_IMETHOD SetTarget(nsIDOMNode* aNode); + NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget); + NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget); NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped); // nsIPrivateTextEvent interface @@ -154,10 +156,13 @@ protected: //Internal helper funcs nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, float* aT2P); + nsresult SetEventType(const nsString& aEventTypeArg); nsEvent* mEvent; + PRBool mEventIsInternal; nsIPresContext* mPresContext; - nsIDOMNode* mTarget; + nsIDOMEventTarget* mTarget; + nsIDOMEventTarget* mCurrentTarget; nsString* mText; nsIPrivateTextRangeList* mTextRange; const char* GetEventName(PRUint32 aEventType); diff --git a/mozilla/layout/events/src/nsEventListenerManager.cpp b/mozilla/layout/events/src/nsEventListenerManager.cpp index 50676b07a8c..bae5cab6ef9 100644 --- a/mozilla/layout/events/src/nsEventListenerManager.cpp +++ b/mozilla/layout/events/src/nsEventListenerManager.cpp @@ -22,7 +22,6 @@ #include "nsISupports.h" #include "nsGUIEvent.h" -#include "nsIPresContext.h" #include "nsDOMEvent.h" #include "nsEventListenerManager.h" #include "nsIDOMEventListener.h" @@ -54,6 +53,8 @@ #include "nsDOMPropEnums.h" #include "nsDOMError.h" #include "nsIJSContextStack.h" +#include "nsIDocument.h" +#include "nsIPresShell.h" static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID); static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID); @@ -75,6 +76,7 @@ nsEventListenerManager::nsEventListenerManager() mCompositionListeners = nsnull; mMenuListeners = nsnull; mDestroyed = PR_FALSE; + mTarget = nsnull; NS_INIT_REFCNT(); } @@ -616,6 +618,7 @@ nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *a nsresult nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, nsIDOMEvent* aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aSubType, PRUint32 aPhaseFlags) { @@ -700,7 +703,10 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, } if (NS_SUCCEEDED(result)) { + nsCOMPtr aPrivDOMEvent(do_QueryInterface(aDOMEvent)); + aPrivDOMEvent->SetCurrentTarget(aCurrentTarget); result = aListenerStruct->mListener->HandleEvent(aDOMEvent); + aPrivDOMEvent->SetCurrentTarget(nsnull); } return result; @@ -714,6 +720,7 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aFlags, nsEventStatus* aEventStatus) { @@ -727,6 +734,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, keys which cause window deletion, can destroy this object before we're ready. */ nsCOMPtr kungFuDeathGrip(this); + nsAutoString empty; switch(aEvent->message) { case NS_MOUSE_LEFT_BUTTON_DOWN: @@ -745,7 +753,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_MOUSE_EXIT_SYNTH: if (nsnull != mMouseListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mMouseListeners && iCount(); i++) { @@ -840,7 +848,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -852,7 +860,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_MOUSE_MOVE: if (nsnull != mMouseMotionListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mMouseMotionListeners && iCount(); i++) { @@ -886,7 +894,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -903,7 +911,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, #endif if (nsnull != mCompositionListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,empty,aEvent); } if (NS_OK == ret) { for(int i=0; mTextListeners && iCount();i++) { @@ -951,7 +959,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -965,7 +973,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, #endif if (nsnull != mTextListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,empty,aEvent); } if (NS_OK == ret) { for (int i=0; mTextListeners && iCount(); i++) { @@ -986,7 +994,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, correctSubType = PR_TRUE; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1000,7 +1008,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_KEY_PRESS: if (nsnull != mKeyListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mKeyListeners && iCount(); i++) { @@ -1052,7 +1060,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1065,7 +1073,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_BLUR_CONTENT: if (nsnull != mFocusListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mFocusListeners && iCount(); i++) { @@ -1108,7 +1116,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1124,7 +1132,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_FORM_INPUT: if (nsnull != mFormListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mFormListeners && iCount(); i++) { @@ -1194,7 +1202,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1211,7 +1219,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, if (nsnull != mLoadListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mLoadListeners && iCount(); i++) { @@ -1266,7 +1274,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1278,7 +1286,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_PAINT: if (nsnull != mPaintListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mPaintListeners && iCount(); i++) { @@ -1300,7 +1308,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, correctSubType = PR_TRUE; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1316,7 +1324,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_DRAGDROP_GESTURE: if (nsnull != mDragListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { @@ -1379,7 +1387,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || dragStruct->mSubType == NS_EVENT_BITS_DRAG_NONE) - ret = HandleEventSubType(dragStruct, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(dragStruct, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1395,7 +1403,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, case NS_XUL_COMMAND_UPDATE: if (nsnull != mMenuListeners) { if (nsnull == *aDOMEvent) { - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent); } if (NS_OK == ret) { for (int i=0; mMenuListeners && iCount(); i++) { @@ -1474,7 +1482,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, break; } if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) { - ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags); + ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags); } } } @@ -1505,9 +1513,15 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext, nsresult nsEventListenerManager::CreateEvent(nsIPresContext* aPresContext, nsEvent* aEvent, + const nsString& aEventType, nsIDOMEvent** aDOMEvent) { - return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent); + if (!aEvent && !aEventType.EqualsIgnoreCase("MouseEvent") && !aEventType.EqualsIgnoreCase("KeyEvent") && + !aEventType.EqualsIgnoreCase("HTMLEvent")) { + return NS_ERROR_FAILURE; + } + + return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEventType, aEvent); } /** @@ -1753,6 +1767,13 @@ nsresult nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly) return NS_OK; } +nsresult nsEventListenerManager::SetListenerTarget(nsISupports* aTarget) +{ + //WEAK reference, must be set back to nsnull when done + mTarget = aTarget; + return NS_OK; +} + // nsIDOMEventTarget interface NS_IMETHODIMP nsEventListenerManager::AddEventListener(const nsString& aType, @@ -1774,6 +1795,38 @@ nsEventListenerManager::RemoveEventListener(const nsString& aType, return RemoveEventListenerByType(aListener, aType, flags); } +NS_IMETHODIMP +nsEventListenerManager::DispatchEvent(nsIDOMEvent* aEvent) +{ + //If we don't have a target set this doesn't work. + if (mTarget) { + nsCOMPtr targetContent(do_QueryInterface(mTarget)); + if (targetContent) { + nsCOMPtr document; + targetContent->GetDocument(*getter_AddRefs(document)); + + if (document) { + // Obtain a presentation context + PRInt32 count = document->GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(document->GetShellAt(0)); + + // Retrieve the context + nsCOMPtr aPresContext; + shell->GetPresContext(getter_AddRefs(aPresContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent(mTarget, aEvent); + } + } + } + } + return NS_ERROR_FAILURE; +} + // nsIDOMEventReceiver interface NS_IMETHODIMP nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener, @@ -1806,7 +1859,7 @@ nsEventListenerManager::GetNewListenerManager(nsIEventListenerManager **aInstanc NS_IMETHODIMP nsEventListenerManager::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult) diff --git a/mozilla/layout/events/src/nsEventListenerManager.h b/mozilla/layout/events/src/nsEventListenerManager.h index d9662e7fcfc..5ac323c0042 100644 --- a/mozilla/layout/events/src/nsEventListenerManager.h +++ b/mozilla/layout/events/src/nsEventListenerManager.h @@ -41,7 +41,7 @@ typedef struct { } nsListenerStruct; //Flag must live higher than all event flags in nsGUIEvent.h -#define NS_PRIV_EVENT_FLAG_SCRIPT 0x20 +#define NS_PRIV_EVENT_FLAG_SCRIPT 0x80 /* * Event listener manager @@ -94,15 +94,19 @@ public: virtual nsresult HandleEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aFlags, nsEventStatus* aEventStatus); virtual nsresult CreateEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, + nsEvent* aEvent, + const nsString& aEventType, nsIDOMEvent** aDOMEvent); virtual nsresult RemoveAllListeners(PRBool aScriptOnly); + virtual nsresult SetListenerTarget(nsISupports* aTarget); + static nsresult GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aSubType); // nsIDOMEventTarget interface @@ -112,6 +116,7 @@ public: NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMEventReceiver interface NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); @@ -123,6 +128,7 @@ public: protected: nsresult HandleEventSubType(nsListenerStruct* aListenerStruct, nsIDOMEvent* aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, PRUint32 aSubType, PRUint32 aPhaseFlags); nsListenerStruct* FindJSEventListener(REFNSIID aIID); @@ -146,6 +152,8 @@ protected: nsVoidArray* mMenuListeners; nsCOMPtr mPrincipal; PRBool mDestroyed; + + nsISupports* mTarget; //WEAK }; diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp index aeac88d34eb..68f55779927 100644 --- a/mozilla/layout/events/src/nsEventStateManager.cpp +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -899,7 +899,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, { if (sv) { if (action == MOUSE_SCROLL_N_LINES) - sv->ScrollByLines(numLines); + sv->ScrollByLines(0, numLines); else sv->ScrollByPages((numLines > 0) ? 1 : -1); ForceViewUpdate(focusView); @@ -996,7 +996,27 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, nsIScrollableView* sv = GetNearestScrollingView(aView); if (sv) { nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; - sv->ScrollByLines((keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1); + sv->ScrollByLines(0, (keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1); + + // force the update to happen now, otherwise multiple scrolls can + // occur before the update is processed. (bug #7354) + nsIViewManager* vm = nsnull; + if (NS_OK == aView->GetViewManager(vm) && nsnull != vm) { + // I'd use Composite here, but it doesn't always work. + // vm->Composite(); + vm->ForceUpdate(); + NS_RELEASE(vm); + } + } + } + break; + case NS_VK_LEFT: + case NS_VK_RIGHT: + if (!mCurrentFocus) { + nsIScrollableView* sv = GetNearestScrollingView(aView); + if (sv) { + nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent; + sv->ScrollByLines((keyEvent->keyCode == NS_VK_RIGHT) ? 1 : -1, 0); // force the update to happen now, otherwise multiple scrolls can // occur before the update is processed. (bug #7354) @@ -2579,6 +2599,12 @@ void nsEventStateManager::ForceViewUpdate(nsIView* aView) } } +NS_IMETHODIMP +nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent) +{ + return NS_OK; +} + nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult) { nsresult rv; diff --git a/mozilla/layout/events/src/nsEventStateManager.h b/mozilla/layout/events/src/nsEventStateManager.h index 70e9a34ae59..470f63741b8 100644 --- a/mozilla/layout/events/src/nsEventStateManager.h +++ b/mozilla/layout/events/src/nsEventStateManager.h @@ -99,6 +99,9 @@ public: NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor); + //Method for centralized distribution of new DOM events + NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent); + protected: void UpdateCursor(nsIPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus); void GenerateMouseEnterExit(nsIPresContext* aPresContext, nsGUIEvent* aEvent); diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index ce18893c202..ef670abc7c4 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -57,6 +57,7 @@ #include "nsIFontMetrics.h" #include "nsVoidArray.h" #include "nsIScrollableFrame.h" +#include "nsIDOMEventTarget.h" #include "nsISelectElement.h" @@ -2381,15 +2382,16 @@ nsListControlFrame::SelectionChanged(nsIContent* aContent) // Here we create our own DOM event and set the target to the Select // We'll pass this DOM event in, in hopes that the target is used. nsIDOMEvent* DOMEvent = nsnull; - nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, &event); + nsAutoString empty; + nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, empty, &event); if (NS_SUCCEEDED(res) && DOMEvent && mContent) { - nsCOMPtr node; - res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(node)); - if (NS_SUCCEEDED(res) && node) { + nsCOMPtr target; + res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(target)); + if (NS_SUCCEEDED(res) && target) { nsCOMPtr pDOMEvent; res = DOMEvent->QueryInterface(kIPrivateDOMEventIID, (void**)getter_AddRefs(pDOMEvent)); if (NS_SUCCEEDED(res) && pDOMEvent) { - res = pDOMEvent->SetTarget(node); + res = pDOMEvent->SetTarget(target); if (NS_SUCCEEDED(res)) { // Have the content handle the event. res = mContent->HandleDOMEvent(mPresContext, &event, &DOMEvent, NS_EVENT_FLAG_BUBBLE, &status); diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 9897a6667b5..58b59cf526f 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -1995,7 +1995,7 @@ PresShell::ScrollLine(PRBool aForward) result = viewManager->GetRootScrollableView(&scrollView); if (NS_SUCCEEDED(result) && scrollView) { - scrollView->ScrollByLines(aForward ? 1 : -1); + scrollView->ScrollByLines(0, aForward ? 1 : -1); //NEW FOR LINES // force the update to happen now, otherwise multiple scrolls can // occur before the update is processed. (bug #7354) @@ -2012,7 +2012,26 @@ PresShell::ScrollLine(PRBool aForward) NS_IMETHODIMP PresShell::ScrollHorizontal(PRBool aLeft) { - return NS_ERROR_NOT_IMPLEMENTED; + nsCOMPtr viewManager; + nsresult result = GetViewManager(getter_AddRefs(viewManager)); + if (NS_SUCCEEDED(result) && viewManager) + { + nsIScrollableView *scrollView; + result = viewManager->GetRootScrollableView(&scrollView); + if (NS_SUCCEEDED(result) && scrollView) + { + scrollView->ScrollByLines(aLeft ? -1 : 1, 0); +//NEW FOR LINES + // force the update to happen now, otherwise multiple scrolls can + // occur before the update is processed. (bug #7354) + + // I'd use Composite here, but it doesn't always work. + // vm->Composite(); + viewManager->ForceUpdate(); + } + } + + return result; } NS_IMETHODIMP diff --git a/mozilla/layout/html/content/src/nsHTMLLabelElement.cpp b/mozilla/layout/html/content/src/nsHTMLLabelElement.cpp index 50c36ea6e41..31a5f89f254 100644 --- a/mozilla/layout/html/content/src/nsHTMLLabelElement.cpp +++ b/mozilla/layout/html/content/src/nsHTMLLabelElement.cpp @@ -389,7 +389,7 @@ nsHTMLLabelElement::HandleDOMEvent(nsIPresContext* aPresContext, // Now a little special trickery because we are a label: // We need to pass this event on to our child iff it is a focus, // keypress/up/dn, mouseclick/dblclick/up/down. - if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT == aFlags) && + if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT & aFlags) && ((nsEventStatus_eIgnore == *aEventStatus) || (nsEventStatus_eConsumeNoDefault == *aEventStatus)) ) { PRBool isFormElement = PR_FALSE; diff --git a/mozilla/layout/html/forms/src/nsGfxListControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxListControlFrame.cpp index 7ad591aa926..40a5b28a8a6 100644 --- a/mozilla/layout/html/forms/src/nsGfxListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxListControlFrame.cpp @@ -56,6 +56,7 @@ #include "nsLayoutAtoms.h" #include "nsIFontMetrics.h" #include "nsVoidArray.h" +#include "nsIDOMEventTarget.h" #include "nsISelectElement.h" #include "nsIScrollableFrame.h" @@ -2537,15 +2538,16 @@ nsGfxListControlFrame::SelectionChanged(nsIContent* aContent) // Here we create our own DOM event and set the target to the Select // We'll pass this DOM event in, in hopes that the target is used. nsIDOMEvent* DOMEvent = nsnull; - nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, &event); + nsAutoString empty; + nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, empty, &event); if (NS_SUCCEEDED(res) && DOMEvent && mContent) { - nsCOMPtr node; - res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(node)); - if (NS_SUCCEEDED(res) && node) { + nsCOMPtr target; + res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(target)); + if (NS_SUCCEEDED(res) && target) { nsCOMPtr pDOMEvent; res = DOMEvent->QueryInterface(kIPrivateDOMEventIID, (void**)getter_AddRefs(pDOMEvent)); if (NS_SUCCEEDED(res) && pDOMEvent) { - res = pDOMEvent->SetTarget(node); + res = pDOMEvent->SetTarget(target); if (NS_SUCCEEDED(res)) { // Have the content handle the event. res = mContent->HandleDOMEvent(mPresContext, &event, &DOMEvent, NS_EVENT_FLAG_BUBBLE, &status); diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp index 2473b21079a..ac0967b2c9d 100644 --- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp @@ -4184,8 +4184,8 @@ nsEnderEventListener::DispatchMouseEvent(nsIDOMMouseEvent *aEvent, PRInt32 aEven aEvent->GetScreenX(&(event.point.x)); aEvent->GetScreenY(&(event.point.y)); - PRUint16 clickCount; - aEvent->GetClickCount(&clickCount); + PRInt32 clickCount; + aEvent->GetDetail(&clickCount); event.clickCount = clickCount; event.message = aEventType; GetWidgetForView(mView, event.widget); diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index ce18893c202..ef670abc7c4 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -57,6 +57,7 @@ #include "nsIFontMetrics.h" #include "nsVoidArray.h" #include "nsIScrollableFrame.h" +#include "nsIDOMEventTarget.h" #include "nsISelectElement.h" @@ -2381,15 +2382,16 @@ nsListControlFrame::SelectionChanged(nsIContent* aContent) // Here we create our own DOM event and set the target to the Select // We'll pass this DOM event in, in hopes that the target is used. nsIDOMEvent* DOMEvent = nsnull; - nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, &event); + nsAutoString empty; + nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, empty, &event); if (NS_SUCCEEDED(res) && DOMEvent && mContent) { - nsCOMPtr node; - res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(node)); - if (NS_SUCCEEDED(res) && node) { + nsCOMPtr target; + res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(target)); + if (NS_SUCCEEDED(res) && target) { nsCOMPtr pDOMEvent; res = DOMEvent->QueryInterface(kIPrivateDOMEventIID, (void**)getter_AddRefs(pDOMEvent)); if (NS_SUCCEEDED(res) && pDOMEvent) { - res = pDOMEvent->SetTarget(node); + res = pDOMEvent->SetTarget(target); if (NS_SUCCEEDED(res)) { // Have the content handle the event. res = mContent->HandleDOMEvent(mPresContext, &event, &DOMEvent, NS_EVENT_FLAG_BUBBLE, &status); diff --git a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp index 45d7cc21d43..98037821ea8 100644 --- a/mozilla/layout/html/table/src/nsTableOuterFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableOuterFrame.cpp @@ -365,6 +365,15 @@ nsTableOuterFrame::GetFrameForPoint(nsIPresContext* aPresContext, nsFramePaintLayer aWhichLayer, nsIFrame** aFrame) { + nsresult rv; + + // caption frames live in a different list which we need to check separately + if (mCaptionFrame) { + rv = GetFrameForPointUsing(aPresContext, aPoint, nsLayoutAtoms::captionList, NS_FRAME_PAINT_LAYER_FOREGROUND, PR_FALSE, aFrame); + if (NS_OK == rv) { + return NS_OK; + } + } // this should act like a block, so we need to override return GetFrameForPointUsing(aPresContext, aPoint, nsnull, aWhichLayer, (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND), aFrame); } diff --git a/mozilla/layout/tables/nsTableOuterFrame.cpp b/mozilla/layout/tables/nsTableOuterFrame.cpp index 45d7cc21d43..98037821ea8 100644 --- a/mozilla/layout/tables/nsTableOuterFrame.cpp +++ b/mozilla/layout/tables/nsTableOuterFrame.cpp @@ -365,6 +365,15 @@ nsTableOuterFrame::GetFrameForPoint(nsIPresContext* aPresContext, nsFramePaintLayer aWhichLayer, nsIFrame** aFrame) { + nsresult rv; + + // caption frames live in a different list which we need to check separately + if (mCaptionFrame) { + rv = GetFrameForPointUsing(aPresContext, aPoint, nsLayoutAtoms::captionList, NS_FRAME_PAINT_LAYER_FOREGROUND, PR_FALSE, aFrame); + if (NS_OK == rv) { + return NS_OK; + } + } // this should act like a block, so we need to override return GetFrameForPointUsing(aPresContext, aPoint, nsnull, aWhichLayer, (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND), aFrame); } diff --git a/mozilla/layout/xml/content/src/nsXMLDocumentType.cpp b/mozilla/layout/xml/content/src/nsXMLDocumentType.cpp index dd936f930a8..deb0319075c 100644 --- a/mozilla/layout/xml/content/src/nsXMLDocumentType.cpp +++ b/mozilla/layout/xml/content/src/nsXMLDocumentType.cpp @@ -157,7 +157,7 @@ nsXMLDocumentType::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) } if (aIID.Equals(kIDOMEventReceiverIID)) { nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ return man->QueryInterface(kIDOMEventReceiverIID, (void**)aInstancePtrResult); } return NS_NOINTERFACE; diff --git a/mozilla/layout/xml/content/src/nsXMLEntity.cpp b/mozilla/layout/xml/content/src/nsXMLEntity.cpp index b37c163f0c2..ec221cab34e 100644 --- a/mozilla/layout/xml/content/src/nsXMLEntity.cpp +++ b/mozilla/layout/xml/content/src/nsXMLEntity.cpp @@ -134,7 +134,7 @@ nsXMLEntity::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) } if (aIID.Equals(kIDOMEventReceiverIID)) { nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ return man->QueryInterface(kIDOMEventReceiverIID, (void**)aInstancePtrResult); } return NS_NOINTERFACE; diff --git a/mozilla/layout/xml/content/src/nsXMLNotation.cpp b/mozilla/layout/xml/content/src/nsXMLNotation.cpp index 35a88bf474c..55377b96cc6 100644 --- a/mozilla/layout/xml/content/src/nsXMLNotation.cpp +++ b/mozilla/layout/xml/content/src/nsXMLNotation.cpp @@ -131,7 +131,7 @@ nsXMLNotation::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) } if (aIID.Equals(kIDOMEventReceiverIID)) { nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ return man->QueryInterface(kIDOMEventReceiverIID, (void**)aInstancePtrResult); } return NS_NOINTERFACE; diff --git a/mozilla/layout/xml/content/src/nsXMLProcessingInstruction.cpp b/mozilla/layout/xml/content/src/nsXMLProcessingInstruction.cpp index 1566a1ef5c4..d265d6e2d01 100644 --- a/mozilla/layout/xml/content/src/nsXMLProcessingInstruction.cpp +++ b/mozilla/layout/xml/content/src/nsXMLProcessingInstruction.cpp @@ -137,7 +137,7 @@ nsXMLProcessingInstruction::QueryInterface(REFNSIID aIID, void** aInstancePtrRes } if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver))) { nsCOMPtr man; - if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ + if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ return man->QueryInterface(kIDOMEventReceiverIID, (void**)aInstancePtrResult); } return NS_NOINTERFACE; diff --git a/mozilla/layout/xul/base/src/nsToolbarDragListener.cpp b/mozilla/layout/xul/base/src/nsToolbarDragListener.cpp index 0a789b8006e..9067cede204 100644 --- a/mozilla/layout/xul/base/src/nsToolbarDragListener.cpp +++ b/mozilla/layout/xul/base/src/nsToolbarDragListener.cpp @@ -35,6 +35,7 @@ #include "nsIDOMXULDocument.h" #include "nsIDocument.h" #include "nsIPresShell.h" +#include "nsIDOMEventTarget.h" NS_IMPL_ADDREF(nsToolbarDragListener) @@ -323,15 +324,20 @@ nsToolbarDragListener::DragExit(nsIDOMEvent* aDragEvent) if ( !mouseEvent ) return NS_OK; + nsCOMPtr relatedTarget; + mouseEvent->GetRelatedTarget ( getter_AddRefs(relatedTarget) ); nsCOMPtr relatedNode; - mouseEvent->GetRelatedNode ( getter_AddRefs(relatedNode) ); - nsCOMPtr target; + if (relatedTarget) relatedNode = do_QueryInterface(relatedTarget); + + nsCOMPtr target; aDragEvent->GetTarget ( getter_AddRefs(target) ); + nsCOMPtr targetNode = nsnull; + if (target) targetNode = do_QueryInterface(target); // we only care about the case where the toolbar or one of its children // is the target of this dragExit event. Recall we get all exit events because // they will bubble up to us. - if ( !IsNodeAChild(target) ) + if ( !IsNodeAChild(targetNode) ) return NS_OK; if ( ! IsNodeAChild(relatedNode) ) { diff --git a/mozilla/layout/xul/base/src/nsToolbarDragListener.h b/mozilla/layout/xul/base/src/nsToolbarDragListener.h index 005ddec8fe3..ce4e4395ca8 100644 --- a/mozilla/layout/xul/base/src/nsToolbarDragListener.h +++ b/mozilla/layout/xul/base/src/nsToolbarDragListener.h @@ -31,6 +31,7 @@ class nsToolbarFrame; class nsIPresContext; class nsIDOMEvent; class nsIFrame; +class nsIDOMNode; class nsToolbarDragListener : public nsIDOMDragListener diff --git a/mozilla/layout/xul/base/src/nsTreeItemDragCapturer.cpp b/mozilla/layout/xul/base/src/nsTreeItemDragCapturer.cpp index 1c7139fbc7e..c4cbe6edc23 100644 --- a/mozilla/layout/xul/base/src/nsTreeItemDragCapturer.cpp +++ b/mozilla/layout/xul/base/src/nsTreeItemDragCapturer.cpp @@ -35,6 +35,7 @@ #include "nsIDOMXULDocument.h" #include "nsIDocument.h" #include "nsIPresShell.h" +#include "nsIDOMEventTarget.h" NS_IMPL_ADDREF(nsTreeItemDragCapturer) @@ -306,17 +307,21 @@ nsTreeItemDragCapturer :: IsEventTargetMyTreeItem ( nsIDOMEvent* inEvent ) // get the treeItem associated with the target. Remember that the tree cell is the // actual target, so we have to go up two levels to get to its treeItem. + nsCOMPtr target; nsCOMPtr targetCell; - inEvent->GetTarget ( getter_AddRefs(targetCell) ); nsCOMPtr targetRow; nsCOMPtr targetTreeItem; - if ( targetCell ) { - targetCell->GetParentNode(getter_AddRefs(targetRow)); - if ( targetRow ) { - targetRow->GetParentNode(getter_AddRefs(targetTreeItem)); - // the critical comparison. are - if ( myDomNode == targetTreeItem ) - retVal = PR_TRUE; + inEvent->GetTarget ( getter_AddRefs(target) ); + if ( target ) { + targetCell = do_QueryInterface( target ); + if ( targetCell ) { + targetCell->GetParentNode(getter_AddRefs(targetRow)); + if ( targetRow ) { + targetRow->GetParentNode(getter_AddRefs(targetTreeItem)); + // the critical comparison. are + if ( myDomNode == targetTreeItem ) + retVal = PR_TRUE; + } } } diff --git a/mozilla/layout/xul/base/src/nsTreeTwistyListener.cpp b/mozilla/layout/xul/base/src/nsTreeTwistyListener.cpp index 6d5e1033875..c8f61709115 100644 --- a/mozilla/layout/xul/base/src/nsTreeTwistyListener.cpp +++ b/mozilla/layout/xul/base/src/nsTreeTwistyListener.cpp @@ -31,6 +31,7 @@ #include "nsIDOMNode.h" #include "nsIDOMElement.h" #include "nsXULAtoms.h" +#include "nsIDOMEventListener.h" /* * nsTreeTwistyListener implementation @@ -79,7 +80,7 @@ nsresult nsTreeTwistyListener::MouseDown(nsIDOMEvent* aEvent) { // Get the target of the event. If it's a titledbutton, we care. - nsCOMPtr target; + nsCOMPtr target; aEvent->GetTarget(getter_AddRefs(target)); nsCOMPtr element = do_QueryInterface(target); diff --git a/mozilla/mailnews/addrbook/resources/content/abResultsTreeOverlay.xul b/mozilla/mailnews/addrbook/resources/content/abResultsTreeOverlay.xul index 47395dc7970..5108b047751 100644 --- a/mozilla/mailnews/addrbook/resources/content/abResultsTreeOverlay.xul +++ b/mozilla/mailnews/addrbook/resources/content/abResultsTreeOverlay.xul @@ -31,7 +31,7 @@ Rights Reserved. datasources="rdf:addressdirectory rdf:addresscard" onselect="top.ResultsPaneSelectionChange(); document.commandDispatcher.updateCommands('tree-select');" onblur="goOnEvent(this,'blur')" - onclick="if ( event.clickCount == 2 ) top.AbEditCard();" + onclick="if ( event.detail == 2 ) top.AbEditCard();" containment="http://home.netscape.com/NC-rdf#CardChild" allownegativeassertions="false" coalesceduplicatearcs="false" diff --git a/mozilla/mailnews/base/resources/content/msgMail3PaneWindow.js b/mozilla/mailnews/base/resources/content/msgMail3PaneWindow.js index ea30c33abf6..75496775a11 100644 --- a/mozilla/mailnews/base/resources/content/msgMail3PaneWindow.js +++ b/mozilla/mailnews/base/resources/content/msgMail3PaneWindow.js @@ -608,7 +608,7 @@ function ThreadPaneOnClick(event) msgNavigationService.OpenTreeitemAndDescendants(treeitem); } } - else if(event.clickCount == 2) + else if(event.detail == 2) { ThreadPaneDoubleClick(event.target.parentNode.parentNode); } @@ -681,7 +681,7 @@ function FolderPaneOnClick(event) } } } - else if(event.clickCount == 2) + else if(event.detail == 2) { var item = event.target.parentNode.parentNode; if (item.nodeName == "treeitem") diff --git a/mozilla/mailnews/base/resources/content/subscribe.js b/mozilla/mailnews/base/resources/content/subscribe.js index 6b15f5f1b3a..86716e6c2da 100644 --- a/mozilla/mailnews/base/resources/content/subscribe.js +++ b/mozilla/mailnews/base/resources/content/subscribe.js @@ -277,7 +277,7 @@ function ReverseState(uri) function SubscribeOnClick(event) { - if (event.clickCount == 2) { + if (event.detail == 2) { ReverseStateFromNode(event.target.parentNode.parentNode); } else { diff --git a/mozilla/profile/resources/content/profileManager.js b/mozilla/profile/resources/content/profileManager.js index 5fdab3b8a00..38c05aa0b67 100644 --- a/mozilla/profile/resources/content/profileManager.js +++ b/mozilla/profile/resources/content/profileManager.js @@ -268,7 +268,7 @@ function HandleKeyEvent( aEvent ) function HandleClickEvent( aEvent ) { - if( aEvent.clickCount == 2 && aEvent.which == 1 ) { + if( aEvent.detail == 2 && aEvent.which == 1 ) { if( aEvent.target.nodeName.toLowerCase() == "treecell" && aEvent.target.parentNode.parentNode.nodeName.toLowerCase() != "treehead" ) return onStart(); diff --git a/mozilla/rdf/content/src/nsXULCommandDispatcher.cpp b/mozilla/rdf/content/src/nsXULCommandDispatcher.cpp index ded65ac062e..3be627c63eb 100644 --- a/mozilla/rdf/content/src/nsXULCommandDispatcher.cpp +++ b/mozilla/rdf/content/src/nsXULCommandDispatcher.cpp @@ -47,6 +47,7 @@ #include "nsRDFCID.h" #include "nsXULCommandDispatcher.h" #include "prlog.h" +#include "nsIDOMEventTarget.h" #ifdef PR_LOGGING static PRLogModuleInfo* gLog; @@ -350,7 +351,7 @@ nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent) if (mSuppressFocus) return NS_OK; - nsCOMPtr t; + nsCOMPtr t; aEvent->GetTarget(getter_AddRefs(t)); #ifdef DEBUG_hyatt @@ -419,7 +420,7 @@ nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent) if (mSuppressFocus) return NS_OK; - nsCOMPtr t; + nsCOMPtr t; aEvent->GetTarget(getter_AddRefs(t)); #ifdef DEBUG_hyatt diff --git a/mozilla/rdf/content/src/nsXULDocument.cpp b/mozilla/rdf/content/src/nsXULDocument.cpp index 4d0b6711db1..b1df4da3d78 100644 --- a/mozilla/rdf/content/src/nsXULDocument.cpp +++ b/mozilla/rdf/content/src/nsXULDocument.cpp @@ -76,6 +76,7 @@ #include "nsIFormControl.h" #include "nsIHTMLContent.h" #include "nsIElementFactory.h" +#include "nsIEventStateManager.h" #include "nsIInputStream.h" #include "nsILoadGroup.h" #include "nsINameSpace.h" @@ -573,6 +574,9 @@ nsXULDocument::QueryInterface(REFNSIID iid, void** result) else if (iid.Equals(NS_GET_IID(nsIDOMNSDocument))) { *result = NS_STATIC_CAST(nsIDOMNSDocument*, this); } + else if (iid.Equals(NS_GET_IID(nsIDOMDocumentEvent))) { + *result = NS_STATIC_CAST(nsIDOMDocumentEvent*, this); + } else if (iid.Equals(NS_GET_IID(nsIDOMDocumentView))) { *result = NS_STATIC_CAST(nsIDOMDocumentView*, this); } @@ -1952,9 +1956,10 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, nsresult ret = NS_OK; nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); } //Capturing stage @@ -1965,7 +1970,7 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, //Local handling stage if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -1974,7 +1979,7 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext, mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, release here. if (nsnull != *aDOMEvent) { nsrefcnt rc; @@ -4002,6 +4007,52 @@ nsXULDocument::RemoveEventListener(const nsString& aType, nsIDOMEventListener* a return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsXULDocument::DispatchEvent(nsIDOMEvent* aEvent) +{ + // Obtain a presentation context + PRInt32 count = GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(GetShellAt(0)); + + // Retrieve the context + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent(NS_STATIC_CAST(nsIDocument*, this), aEvent); + } + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsXULDocument::CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn) +{ + // Obtain a presentation context + PRInt32 count = GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(GetShellAt(0)); + + // Retrieve the context + nsCOMPtr presContext; + shell->GetPresContext(getter_AddRefs(presContext)); + + if (presContext) { + nsCOMPtr lm; + if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(lm)))) { + return lm->CreateEvent(presContext, nsnull, aEventType, aReturn); + } + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsXULDocument::GetListenerManager(nsIEventListenerManager** aResult) { @@ -4031,7 +4082,7 @@ nsXULDocument::GetNewListenerManager(nsIEventListenerManager **aResult) NS_IMETHODIMP nsXULDocument::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } nsresult diff --git a/mozilla/rdf/content/src/nsXULDocument.h b/mozilla/rdf/content/src/nsXULDocument.h index c11b52b06a9..6bf9aa88ba8 100644 --- a/mozilla/rdf/content/src/nsXULDocument.h +++ b/mozilla/rdf/content/src/nsXULDocument.h @@ -67,6 +67,7 @@ #include "nsIStreamLoader.h" #include "nsIBindingManager.h" #include "nsINodeInfo.h" +#include "nsIDOMDocumentEvent.h" class nsIAtom; class nsIElementFactory; @@ -93,6 +94,7 @@ class nsXULDocument : public nsIDocument, public nsIXULDocument, public nsIStreamLoadableDocument, public nsIDOMXULDocument, + public nsIDOMDocumentEvent, public nsIDOMDocumentView, public nsIDOMNSDocument, public nsIDOMEventCapturer, @@ -335,10 +337,14 @@ public: PRBool aUseCapture); NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMDocument interface NS_DECL_IDOMDOCUMENT + // nsIDOMDocumentEvent interface + NS_DECL_IDOMDOCUMENTEVENT + // nsIDOMDocumentView interface NS_DECL_IDOMDOCUMENTVIEW diff --git a/mozilla/rdf/content/src/nsXULElement.cpp b/mozilla/rdf/content/src/nsXULElement.cpp index 99892a8d79b..6d8a4f53777 100644 --- a/mozilla/rdf/content/src/nsXULElement.cpp +++ b/mozilla/rdf/content/src/nsXULElement.cpp @@ -2060,6 +2060,28 @@ nsXULElement::RemoveEventListener(const nsString& aType, nsIDOMEventListener* aL return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsXULElement::DispatchEvent(nsIDOMEvent* aEvent) +{ + // Obtain a presentation context + PRInt32 count = mDocument->GetNumberOfShells(); + if (count == 0) + return NS_OK; + + nsCOMPtr shell = getter_AddRefs(mDocument->GetShellAt(0)); + + // Retrieve the context + nsCOMPtr aPresContext; + shell->GetPresContext(getter_AddRefs(aPresContext)); + + nsCOMPtr esm; + if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) { + return esm->DispatchNewEvent(NS_STATIC_CAST(nsIStyledContent*, this), aEvent); + } + + return NS_ERROR_FAILURE; +} + NS_IMETHODIMP nsXULElement::GetListenerManager(nsIEventListenerManager** aResult) { @@ -2090,7 +2112,7 @@ nsXULElement::GetNewListenerManager(nsIEventListenerManager **aResult) NS_IMETHODIMP nsXULElement::HandleEvent(nsIDOMEvent *aEvent) { - return NS_ERROR_FAILURE; + return DispatchEvent(aEvent); } @@ -3449,9 +3471,10 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, nsresult ret = NS_OK; nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { aDOMEvent = &domEvent; - aEvent->flags = NS_EVENT_FLAG_NONE; + aEvent->flags = aFlags; + aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); // In order for the event to have a proper target for events that don't go through // the presshell (onselect, oncommand, oncreate, ondestroy) we need to set our target // ourselves. Also, key sets and menus don't have frames and therefore need their @@ -3474,7 +3497,8 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, NS_ERROR("Unable to instantiate a listener manager on this event."); return ret; } - if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, aDOMEvent))) { + nsAutoString empty; + if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent))) { NS_ERROR("This event will fail without the ability to create the event early."); return ret; } @@ -3522,7 +3546,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, //Local handling stage if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus); + mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus); aEvent->flags &= ~aFlags; } @@ -3556,7 +3580,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, } } - if (NS_EVENT_FLAG_INIT == aFlags) { + if (NS_EVENT_FLAG_INIT & aFlags) { // We're leaving the DOM event loop so if we created a DOM event, // release here. if (nsnull != *aDOMEvent) { diff --git a/mozilla/rdf/content/src/nsXULElement.h b/mozilla/rdf/content/src/nsXULElement.h index b2198266922..3a6e280421f 100644 --- a/mozilla/rdf/content/src/nsXULElement.h +++ b/mozilla/rdf/content/src/nsXULElement.h @@ -465,6 +465,7 @@ public: PRBool aUseCapture); NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); + NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); // nsIDOMEventReceiver NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); diff --git a/mozilla/rdf/content/src/nsXULKeyListener.cpp b/mozilla/rdf/content/src/nsXULKeyListener.cpp index f9fcf8359a3..76f52f4c64f 100644 --- a/mozilla/rdf/content/src/nsXULKeyListener.cpp +++ b/mozilla/rdf/content/src/nsXULKeyListener.cpp @@ -62,6 +62,7 @@ #include "nsIContentViewer.h" #include "nsIDocumentViewer.h" #include "nsIPresContext.h" +#include "nsIDOMEventTarget.h" enum { VK_CANCEL = 3, @@ -491,7 +492,7 @@ nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventTy return ret; // Get DOMEvent target - nsCOMPtr target = nsnull; + nsCOMPtr target = nsnull; aKeyEvent->GetTarget(getter_AddRefs(target)); nsCOMPtr piWindow; diff --git a/mozilla/rdf/content/src/nsXULPopupListener.cpp b/mozilla/rdf/content/src/nsXULPopupListener.cpp index dbaa1452112..839785f4fc4 100644 --- a/mozilla/rdf/content/src/nsXULPopupListener.cpp +++ b/mozilla/rdf/content/src/nsXULPopupListener.cpp @@ -47,7 +47,7 @@ #include "nsIDOMMouseEvent.h" #include "nsITimer.h" #include "nsIDOMNSUIEvent.h" - +#include "nsIDOMEventTarget.h" //////////////////////////////////////////////////////////////////////// @@ -193,8 +193,10 @@ XULPopupListenerImpl::MouseDown(nsIDOMEvent* aMouseEvent) } // Get the node that was clicked on. + nsCOMPtr target; + mouseEvent->GetTarget( getter_AddRefs( target ) ); nsCOMPtr targetNode; - mouseEvent->GetTarget( getter_AddRefs( targetNode ) ); + if (target) targetNode = do_QueryInterface(target); // Get the document with the popup. nsCOMPtr document; @@ -279,9 +281,11 @@ XULPopupListenerImpl::MouseMove(nsIDOMEvent* aMouseEvent) NS_NewTimer ( getter_AddRefs(mTooltipTimer) ); if ( mTooltipTimer ) { - nsCOMPtr eventTarget; + nsCOMPtr eventTarget; + nsCOMPtr eventTargetNode; aMouseEvent->GetTarget(getter_AddRefs(eventTarget)); - mPossibleTooltipNode = eventTarget.get(); + if (eventTarget) eventTargetNode = do_QueryInterface(eventTarget); + mPossibleTooltipNode = eventTargetNode.get(); mTooltipTimer->Init(sTooltipCallback, this, 500, NS_PRIORITY_HIGH); // 500 ms delay } else @@ -317,10 +321,12 @@ XULPopupListenerImpl::MouseOut(nsIDOMEvent* aMouseEvent) mPopupContent = nsnull; // release the popup // clear out the tooltip node on the document - nsCOMPtr eventTarget; + nsCOMPtr eventTarget; + nsCOMPtr eventTargetNode; aMouseEvent->GetTarget(getter_AddRefs(eventTarget)); + if (eventTarget) eventTargetNode = do_QueryInterface(eventTarget); nsCOMPtr doc; - FindDocumentForNode ( eventTarget, getter_AddRefs(doc) ); + FindDocumentForNode ( eventTargetNode, getter_AddRefs(doc) ); if ( doc ) doc->SetTooltipNode(nsnull); } diff --git a/mozilla/view/public/nsIScrollableView.h b/mozilla/view/public/nsIScrollableView.h index dae7a89c11c..9713506a9b5 100644 --- a/mozilla/view/public/nsIScrollableView.h +++ b/mozilla/view/public/nsIScrollableView.h @@ -196,7 +196,7 @@ public: * @param aNumLines number of lines to scroll the view by * @return error status */ - NS_IMETHOD ScrollByLines(PRInt32 aNumLines) = 0; + NS_IMETHOD ScrollByLines(PRInt32 aNumLinesX, PRInt32 aNumLinexY) = 0; /** * Scroll the view up or down by aNumPages pages. a page diff --git a/mozilla/view/src/nsScrollPortView.cpp b/mozilla/view/src/nsScrollPortView.cpp index e5de244e887..b9722223089 100644 --- a/mozilla/view/src/nsScrollPortView.cpp +++ b/mozilla/view/src/nsScrollPortView.cpp @@ -460,11 +460,12 @@ NS_IMETHODIMP nsScrollPortView::GetLineHeight(nscoord *aHeight) return NS_OK; } -NS_IMETHODIMP nsScrollPortView::ScrollByLines(PRInt32 aNumLines) +NS_IMETHODIMP nsScrollPortView::ScrollByLines(PRInt32 aNumLinesX, PRInt32 aNumLinesY) { - nscoord dy = mLineHeight*aNumLines; + nscoord dx = mLineHeight*aNumLinesX; + nscoord dy = mLineHeight*aNumLinesY; - ScrollTo(mOffsetX, mOffsetY + dy, 0); + ScrollTo(mOffsetX + dx, mOffsetY + dy, 0); return NS_OK; } diff --git a/mozilla/view/src/nsScrollPortView.h b/mozilla/view/src/nsScrollPortView.h index 0cb065208eb..082feda9821 100644 --- a/mozilla/view/src/nsScrollPortView.h +++ b/mozilla/view/src/nsScrollPortView.h @@ -74,7 +74,7 @@ public: NS_IMETHOD GetScrollProperties(PRUint32 *aProperties); NS_IMETHOD SetLineHeight(nscoord aHeight); NS_IMETHOD GetLineHeight(nscoord *aHeight); - NS_IMETHOD ScrollByLines(PRInt32 aNumLines); + NS_IMETHOD ScrollByLines(PRInt32 aNumLinesX, PRInt32 aNumLinesY); NS_IMETHOD ScrollByPages(PRInt32 aNumPages); NS_IMETHOD ScrollByWhole(PRBool aTop); diff --git a/mozilla/view/src/nsScrollingView.cpp b/mozilla/view/src/nsScrollingView.cpp index 832d922cb4f..6f26f790a9b 100644 --- a/mozilla/view/src/nsScrollingView.cpp +++ b/mozilla/view/src/nsScrollingView.cpp @@ -1557,36 +1557,62 @@ NS_IMETHODIMP nsScrollingView::GetLineHeight(nscoord *aHeight) return NS_OK; } -NS_IMETHODIMP nsScrollingView::ScrollByLines(PRInt32 aNumLines) +NS_IMETHODIMP nsScrollingView::ScrollByLines(PRInt32 aNumLinesX, PRInt32 aNumLinesY) { nsIWidget* widget = nsnull; - if (mVScrollBarView->GetWidget(widget) == NS_OK) { - nsIScrollbar* scrollv = nsnull; - if (widget->QueryInterface(NS_GET_IID(nsIScrollbar), (void **)&scrollv) == NS_OK) { - PRUint32 oldPos = 0; - PRUint32 lineInc; - nscoord newPos = 0; - nsSize clipSize; + PRUint32 newPosX = 0, newPosY = 0; - scrollv->GetPosition(oldPos); - scrollv->GetLineIncrement(lineInc); - NS_RELEASE(scrollv); - - mClipView->GetDimensions(&clipSize.width, &clipSize.height); + if (aNumLinesX != 0) { + if (mHScrollBarView->GetWidget(widget) == NS_OK) { + nsIScrollbar* scrollh = nsnull; + if (widget->QueryInterface(NS_GET_IID(nsIScrollbar), (void **)&scrollh) == NS_OK) { + PRUint32 oldPos = 0; + PRUint32 lineInc; - newPos = oldPos + lineInc * aNumLines; + scrollh->GetPosition(oldPos); + scrollh->GetLineIncrement(lineInc); + NS_RELEASE(scrollh); + + newPosX = oldPos + lineInc * aNumLinesX; + } + NS_RELEASE(widget); + } + } + if (aNumLinesY != 0) { + if (mVScrollBarView->GetWidget(widget) == NS_OK) { + nsIScrollbar* scrollv = nsnull; + if (widget->QueryInterface(NS_GET_IID(nsIScrollbar), (void **)&scrollv) == NS_OK) { + PRUint32 oldPos = 0; + PRUint32 lineInc; - if (newPos > (mSizeY - clipSize.height)) - newPos = mSizeY - clipSize.height; + scrollv->GetPosition(oldPos); + scrollv->GetLineIncrement(lineInc); + NS_RELEASE(scrollv); + + newPosY = oldPos + lineInc * aNumLinesY; + } + NS_RELEASE(widget); + } + } - if (newPos < 0) - newPos = 0; - - ScrollTo(0, newPos, 0); - } - NS_RELEASE(widget); - } + nsSize clipSize; + mClipView->GetDimensions(&clipSize.width, &clipSize.height); + //sanity check values + if (newPosX > (mSizeX - clipSize.height)) + newPosX = mSizeX - clipSize.height; + if (newPosX < 0) + newPosX = 0; + + if (newPosY > (mSizeY - clipSize.height)) + newPosY = mSizeY - clipSize.height; + if (newPosY < 0) + newPosY = 0; + + if (newPosX || newPosY) { + ScrollTo(newPosX, newPosY, 0); + } + return NS_OK; } diff --git a/mozilla/view/src/nsScrollingView.h b/mozilla/view/src/nsScrollingView.h index dda60157e66..5e8130028b7 100644 --- a/mozilla/view/src/nsScrollingView.h +++ b/mozilla/view/src/nsScrollingView.h @@ -78,7 +78,7 @@ public: NS_IMETHOD GetScrollProperties(PRUint32 *aProperties); NS_IMETHOD SetLineHeight(nscoord aHeight); NS_IMETHOD GetLineHeight(nscoord *aHeight); - NS_IMETHOD ScrollByLines(PRInt32 aNumLines); + NS_IMETHOD ScrollByLines(PRInt32 aNumLinesX, PRInt32 aNumLinesY); NS_IMETHOD ScrollByPages(PRInt32 aNumPages); NS_IMETHOD ScrollByWhole(PRBool aTop); diff --git a/mozilla/webshell/tests/viewer/nsBaseDialog.cpp b/mozilla/webshell/tests/viewer/nsBaseDialog.cpp index 3acc85082dc..aa3615f7541 100644 --- a/mozilla/webshell/tests/viewer/nsBaseDialog.cpp +++ b/mozilla/webshell/tests/viewer/nsBaseDialog.cpp @@ -23,6 +23,8 @@ #include "nsBaseDialog.h" #include "nsIDOMEvent.h" #include "nsIXPBaseWindow.h" +#include "nsCOMPtr.h" +#include "nsIDOMEventTarget.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLDocument.h" @@ -89,14 +91,15 @@ void nsBaseDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindo aStatus = PR_FALSE; - nsIDOMNode * node; - aMouseEvent->GetTarget(&node); - if (node == mCancelBtn) { - DoClose(); - aStatus = PR_TRUE; + nsCOMPtr target; + aMouseEvent->GetTarget(getter_AddRefs(target)); + if (target) { + nsCOMPtr node(do_QueryInterface(target)); + if (node.get() == mCancelBtn) { + DoClose(); + aStatus = PR_TRUE; + } } - NS_RELEASE(node); - } //--------------------------------------------------------------- diff --git a/mozilla/webshell/tests/viewer/nsFindDialog.cpp b/mozilla/webshell/tests/viewer/nsFindDialog.cpp index 7837a08e35d..b06170b9440 100644 --- a/mozilla/webshell/tests/viewer/nsFindDialog.cpp +++ b/mozilla/webshell/tests/viewer/nsFindDialog.cpp @@ -20,9 +20,11 @@ * Contributor(s): */ +#include "nsCOMPtr.h" #include "nsFindDialog.h" #include "nsIDOMEvent.h" #include "nsIXPBaseWindow.h" +#include "nsIDOMEventTarget.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLDocument.h" @@ -81,12 +83,14 @@ void nsFindDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindo nsBaseDialog::MouseClick(aMouseEvent, aWindow, aStatus); if (!aStatus) { // is not consumed - nsIDOMNode * node; - aMouseEvent->GetTarget(&node); - if (node == mFindBtn) { - DoFind(); + nsCOMPtr target; + aMouseEvent->GetTarget(getter_AddRefs(target)); + if (target) { + nsCOMPtr node(do_QueryInterface(target)); + if (node.get() == mFindBtn) { + DoFind(); + } } - NS_RELEASE(node); } } diff --git a/mozilla/webshell/tests/viewer/nsImageInspectorDialog.cpp b/mozilla/webshell/tests/viewer/nsImageInspectorDialog.cpp index d4b531a137d..5edef72ef39 100644 --- a/mozilla/webshell/tests/viewer/nsImageInspectorDialog.cpp +++ b/mozilla/webshell/tests/viewer/nsImageInspectorDialog.cpp @@ -20,11 +20,12 @@ * Contributor(s): */ +#include "nsCOMPtr.h" #include "nsImageInspectorDialog.h" #include "nsIDOMEvent.h" #include "nsIXPBaseWindow.h" #include "nsBrowserWindow.h" - +#include "nsIDOMEventTarget.h" #include "nsIDOMDocument.h" #include "nsIDOMHTMLInputElement.h" @@ -168,14 +169,16 @@ void nsImageInspectorDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindo nsBaseDialog::MouseClick(aMouseEvent, aWindow, aStatus); if (!aStatus) { // is not consumed - nsIDOMNode * node; - aMouseEvent->GetTarget(&node); - if (node == mOKBtn) { - nsString str; - GetText(NS_ConvertASCIItoUCS2("url"), str); - //DoClose(); - } - NS_RELEASE(node); + nsCOMPtr target; + aMouseEvent->GetTarget(getter_AddRefs(target)); + if (target) { + nsCOMPtr node(do_QueryInterface(target)); + if (node.get() == mOKBtn) { + nsString str; + GetText(NS_ConvertASCIItoUCS2("url"), str); + //DoClose(); + } + } } } diff --git a/mozilla/webshell/tests/viewer/nsPrintSetupDialog.cpp b/mozilla/webshell/tests/viewer/nsPrintSetupDialog.cpp index 70d0f1fdb5e..9a62f407bdf 100644 --- a/mozilla/webshell/tests/viewer/nsPrintSetupDialog.cpp +++ b/mozilla/webshell/tests/viewer/nsPrintSetupDialog.cpp @@ -20,10 +20,12 @@ * Contributor(s): */ +#include "nsCOMPtr.h" #include "nsPrintSetupDialog.h" #include "nsIDOMEvent.h" #include "nsIXPBaseWindow.h" #include "nsBrowserWindow.h" +#include "nsIDOMEventTarget.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLDocument.h" @@ -191,13 +193,15 @@ void nsPrintSetupDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * nsBaseDialog::MouseClick(aMouseEvent, aWindow, aStatus); if (!aStatus) { // is not consumed - nsIDOMNode * node; - aMouseEvent->GetTarget(&node); - if (node == mOKBtn) { - GetSetupInfo(mBrowserWindow->mPrintSetupInfo); - DoClose(); - } - NS_RELEASE(node); + nsCOMPtr target; + aMouseEvent->GetTarget(getter_AddRefs(target)); + if (target) { + nsCOMPtr node(do_QueryInterface(target)); + if (node.get() == mOKBtn) { + GetSetupInfo(mBrowserWindow->mPrintSetupInfo); + DoClose(); + } + } } } diff --git a/mozilla/webshell/tests/viewer/nsTableInspectorDialog.cpp b/mozilla/webshell/tests/viewer/nsTableInspectorDialog.cpp index c6f54385b22..bd0df902b7b 100644 --- a/mozilla/webshell/tests/viewer/nsTableInspectorDialog.cpp +++ b/mozilla/webshell/tests/viewer/nsTableInspectorDialog.cpp @@ -20,11 +20,12 @@ * Contributor(s): */ +#include "nsCOMPtr.h" #include "nsTableInspectorDialog.h" #include "nsIDOMEvent.h" #include "nsIXPBaseWindow.h" #include "nsBrowserWindow.h" - +#include "nsIDOMEventTarget.h" #include "nsIDOMDocument.h" #include "nsIDOMHTMLInputElement.h" @@ -168,13 +169,15 @@ void nsTableInspectorDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindo nsBaseDialog::MouseClick(aMouseEvent, aWindow, aStatus); if (!aStatus) { // is not consumed - nsIDOMNode * node; - aMouseEvent->GetTarget(&node); - if (node == mOKBtn) { - ///GetSetupInfo(mBrowserWindow->mPrintSetupInfo); - DoClose(); - } - NS_RELEASE(node); + nsCOMPtr target; + aMouseEvent->GetTarget(getter_AddRefs(target)); + if (target) { + nsCOMPtr node(do_QueryInterface(target)); + if (node.get() == mOKBtn) { + ///GetSetupInfo(mBrowserWindow->mPrintSetupInfo); + DoClose(); + } + } } } diff --git a/mozilla/widget/public/nsGUIEvent.h b/mozilla/widget/public/nsGUIEvent.h index acdf10d19bb..3f44303334c 100644 --- a/mozilla/widget/public/nsGUIEvent.h +++ b/mozilla/widget/public/nsGUIEvent.h @@ -563,6 +563,8 @@ enum nsDragDropEventStatus { #define NS_EVENT_FLAG_CAPTURE 0x0004 #define NS_EVENT_FLAG_STOP_DISPATCH 0x0008 #define NS_EVENT_FLAG_NO_DEFAULT 0x0010 +#define NS_EVENT_FLAG_CANT_CANCEL 0x0020 +#define NS_EVENT_FLAG_CANT_BUBBLE 0x0040 // IME Constants -- keep in synch with nsIDOMTextRange.h #define NS_TEXTRANGE_CARETPOSITION 0x01 diff --git a/mozilla/xpfe/components/bookmarks/resources/bm-find.js b/mozilla/xpfe/components/bookmarks/resources/bm-find.js index 180c0ec1ace..defb40d26ae 100755 --- a/mozilla/xpfe/components/bookmarks/resources/bm-find.js +++ b/mozilla/xpfe/components/bookmarks/resources/bm-find.js @@ -196,7 +196,7 @@ function getAbsoluteID(root, node) function OpenURL(event, node, root) { - if ((event.button != 1) || (event.clickCount != 2) || (node.nodeName != "treeitem")) + if ((event.button != 1) || (event.detail != 2) || (node.nodeName != "treeitem")) return(false); if (node.getAttribute("container") == "true") diff --git a/mozilla/xpfe/components/bookmarks/resources/bm-panel.js b/mozilla/xpfe/components/bookmarks/resources/bm-panel.js index 54893418736..92be875958c 100644 --- a/mozilla/xpfe/components/bookmarks/resources/bm-panel.js +++ b/mozilla/xpfe/components/bookmarks/resources/bm-panel.js @@ -31,7 +31,7 @@ var appCore = window.content.appCore; function clicked(event, target) { - if ((event.button != 1) || (event.clickCount != 2) || (target.nodeName != "treeitem")) + if ((event.button != 1) || (event.detail != 2) || (target.nodeName != "treeitem")) return(false); if (target.getAttribute("container") == "true") diff --git a/mozilla/xpfe/components/bookmarks/resources/bookmarks.js b/mozilla/xpfe/components/bookmarks/resources/bookmarks.js index 9b7382f9924..3d07afc4107 100644 --- a/mozilla/xpfe/components/bookmarks/resources/bookmarks.js +++ b/mozilla/xpfe/components/bookmarks/resources/bookmarks.js @@ -587,7 +587,7 @@ function getAbsoluteID(root, node) function OpenURL(event, node, root) { - if ((event.button != 1) || (event.clickCount != 2) + if ((event.button != 1) || (event.detail != 2) || (node.nodeName != "treeitem")) return false; diff --git a/mozilla/xpfe/components/directory/directory.js b/mozilla/xpfe/components/directory/directory.js index 9085a0f0db4..49b85518338 100644 --- a/mozilla/xpfe/components/directory/directory.js +++ b/mozilla/xpfe/components/directory/directory.js @@ -62,7 +62,7 @@ function Init() function OnClick(event) { if( event.type == "click" && - ( event.button != 1 || event.clickCount != 2 ) ) + ( event.button != 1 || event.detail != 2 ) ) return false; if( event.type == "keypress" && event.which != 13 ) return false; diff --git a/mozilla/xpfe/components/filepicker/res/content/filepicker.js b/mozilla/xpfe/components/filepicker/res/content/filepicker.js index 9ccb93c54c8..b0006ff02ae 100644 --- a/mozilla/xpfe/components/filepicker/res/content/filepicker.js +++ b/mozilla/xpfe/components/filepicker/res/content/filepicker.js @@ -164,7 +164,7 @@ function onClick(e) { textInput = document.getElementById("textInput"); textInput.value = file.path; - if (e.clickCount == 2) { + if (e.detail == 2) { if (file.isDirectory()) { gotoDirectory(file.path); } diff --git a/mozilla/xpfe/components/history/resources/history.xul b/mozilla/xpfe/components/history/resources/history.xul index 3f357ee3aba..095dc0b8ab3 100644 --- a/mozilla/xpfe/components/history/resources/history.xul +++ b/mozilla/xpfe/components/history/resources/history.xul @@ -78,7 +78,7 @@