From 50de4a3e1dc4b6cf6a5f68502d83dddc7bd469a3 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Thu, 28 Apr 2005 23:48:28 +0000 Subject: [PATCH] Fixing bug 289940. Make chrome event handlers only receive trusted events by default. r=jonas@sicking.cc, sr=peterv@propagandism.org, a=chofmann@mozilla.org --- .../src/base/nsBaseWidgetAccessible.cpp | 5 +- accessible/src/xul/nsXULMenuAccessible.cpp | 3 +- content/base/src/nsDocument.cpp | 36 ++- content/base/src/nsDocument.h | 5 + content/base/src/nsGenericDOMDataNode.cpp | 10 +- content/base/src/nsGenericElement.cpp | 56 +++- content/base/src/nsGenericElement.h | 7 +- content/base/src/nsImageLoadingContent.cpp | 2 +- .../events/public/nsIEventListenerManager.h | 9 +- content/events/public/nsIPrivateDOMEvent.h | 22 +- content/events/public/nsMutationEvent.h | 21 +- content/events/src/nsDOMBeforeUnloadEvent.cpp | 4 +- content/events/src/nsDOMEvent.cpp | 8 +- content/events/src/nsDOMKeyboardEvent.cpp | 6 +- content/events/src/nsDOMMouseEvent.cpp | 8 +- content/events/src/nsDOMMutationEvent.cpp | 6 +- content/events/src/nsDOMPopupBlockedEvent.cpp | 6 +- content/events/src/nsDOMTextEvent.cpp | 6 +- content/events/src/nsDOMUIEvent.cpp | 13 +- content/events/src/nsEventListenerManager.cpp | 93 +++--- content/events/src/nsEventListenerManager.h | 5 +- content/events/src/nsEventStateManager.cpp | 114 +++---- content/events/src/nsEventStateManager.h | 3 +- .../html/content/src/nsGenericHTMLElement.cpp | 10 +- .../html/content/src/nsHTMLButtonElement.cpp | 45 +-- .../html/content/src/nsHTMLFormElement.cpp | 2 +- .../html/content/src/nsHTMLInputElement.cpp | 40 ++- .../html/content/src/nsHTMLLabelElement.cpp | 2 +- .../html/content/src/nsHTMLScriptElement.cpp | 5 +- .../html/content/src/nsHTMLSelectElement.cpp | 11 +- .../content/src/nsHTMLTextAreaElement.cpp | 5 +- content/svg/content/src/nsSVGElement.cpp | 15 +- .../svg/content/src/nsSVGScriptElement.cpp | 5 +- content/xml/content/src/nsXMLElement.cpp | 3 +- content/xml/document/src/nsXMLContentSink.cpp | 2 +- content/xml/document/src/nsXMLDocument.cpp | 7 +- content/xul/content/src/nsXULElement.cpp | 54 ++-- .../document/src/nsXULCommandDispatcher.cpp | 4 +- content/xul/document/src/nsXULDocument.cpp | 2 +- dom/public/idl/events/Makefile.in | 1 + dom/public/idl/events/nsIDOMNSEventTarget.idl | 71 +++++ dom/src/base/nsDOMClassInfo.cpp | 133 +++++++- dom/src/base/nsDOMClassInfo.h | 8 +- dom/src/base/nsGlobalWindow.cpp | 26 +- dom/src/base/nsGlobalWindow.h | 5 + dom/src/base/nsJSEnvironment.cpp | 2 +- dom/src/base/nsWindowRoot.cpp | 26 +- dom/src/base/nsWindowRoot.h | 8 +- extensions/xforms/nsXFormsDispatchElement.cpp | 4 + extensions/xforms/nsXFormsTriggerElement.cpp | 3 + extensions/xforms/nsXFormsUtils.cpp | 3 + .../xmlextras/base/src/nsXMLHttpRequest.cpp | 13 +- layout/base/nsDocumentViewer.cpp | 6 +- layout/base/nsPresShell.cpp | 2 +- layout/forms/nsComboboxControlFrame.cpp | 18 +- layout/forms/nsComboboxControlFrame.h | 3 - layout/forms/nsFileControlFrame.h | 2 - layout/forms/nsFormControlFrame.cpp | 7 - layout/forms/nsFormControlFrame.h | 5 - layout/forms/nsGfxButtonControlFrame.cpp | 3 - layout/forms/nsHTMLButtonControlFrame.cpp | 8 - layout/forms/nsHTMLButtonControlFrame.h | 1 - layout/forms/nsIFormControlFrame.h | 2 - layout/forms/nsImageControlFrame.cpp | 9 - layout/forms/nsListControlFrame.cpp | 14 +- layout/forms/nsListControlFrame.h | 1 - layout/forms/nsTextControlFrame.cpp | 8 +- layout/forms/nsTextControlFrame.h | 1 - layout/generic/nsFrameSetFrame.h | 2 +- layout/generic/nsGfxScrollFrame.cpp | 7 +- layout/generic/nsObjectFrame.cpp | 7 +- layout/generic/nsSelection.cpp | 3 +- layout/xul/base/src/nsBoxFrame.cpp | 5 + layout/xul/base/src/nsButtonBoxFrame.cpp | 5 +- layout/xul/base/src/nsImageBoxFrame.cpp | 2 +- layout/xul/base/src/nsMenuFrame.cpp | 27 +- layout/xul/base/src/nsPopupSetFrame.cpp | 14 +- layout/xul/base/src/nsResizerFrame.cpp | 12 +- layout/xul/base/src/nsResizerFrame.h | 2 +- .../xul/base/src/nsScrollbarButtonFrame.cpp | 12 +- layout/xul/base/src/nsTitleBarFrame.cpp | 12 +- layout/xul/base/src/nsTitleBarFrame.h | 2 +- .../xul/base/src/tree/src/nsTreeBodyFrame.cpp | 4 +- .../xul/base/src/tree/src/nsTreeSelection.cpp | 2 +- .../satchel/src/nsFormFillController.cpp | 10 + view/public/nsIViewObserver.h | 2 +- view/src/nsViewManager.cpp | 7 +- webshell/public/nsILinkHandler.h | 2 +- widget/public/nsEvent.h | 36 +-- widget/public/nsGUIEvent.h | 287 ++++++++++-------- widget/public/nsIEventListener.h | 2 +- widget/public/nsIWidget.h | 2 +- widget/src/beos/nsWindow.cpp | 14 +- widget/src/cocoa/nsChildView.mm | 49 +-- widget/src/cocoa/nsCocoaWindow.mm | 7 +- widget/src/cocoa/nsMenuBarX.cpp | 4 +- widget/src/cocoa/nsMenuItemX.cpp | 2 +- widget/src/cocoa/nsMenuX.cpp | 15 +- widget/src/gtk/nsGtkEventHandler.cpp | 14 +- widget/src/gtk/nsWidget.cpp | 29 +- widget/src/gtk/nsWindow.cpp | 40 +-- widget/src/gtk2/nsCommonWidget.cpp | 12 +- widget/src/gtk2/nsWindow.cpp | 53 ++-- widget/src/mac/nsMacControl.cpp | 2 +- widget/src/mac/nsMacEventHandler.cpp | 51 ++-- widget/src/mac/nsMacWindow.cpp | 2 +- widget/src/mac/nsMenuBarX.cpp | 4 +- widget/src/mac/nsMenuX.cpp | 13 +- widget/src/mac/nsWindow.cpp | 8 +- widget/src/os2/nsFrameWindow.cpp | 2 +- widget/src/os2/nsWindow.cpp | 33 +- widget/src/photon/nsWidget.cpp | 34 ++- widget/src/photon/nsWidget.h | 2 +- widget/src/photon/nsWindow.cpp | 6 +- widget/src/qt/nsCommonWidget.cpp | 43 +-- widget/src/qt/nsScrollbar.cpp | 4 +- widget/src/windows/nsNativeDragTarget.cpp | 2 +- widget/src/windows/nsWindow.cpp | 43 +-- widget/src/xlib/nsAppShell.cpp | 40 +-- widget/src/xlib/nsWidget.cpp | 2 +- widget/src/xlib/nsWindow.cpp | 10 +- xpfe/appshell/src/nsWebShellWindow.cpp | 5 +- xpfe/appshell/src/nsXULWindow.cpp | 5 + 123 files changed, 1288 insertions(+), 781 deletions(-) create mode 100644 dom/public/idl/events/nsIDOMNSEventTarget.idl diff --git a/accessible/src/base/nsBaseWidgetAccessible.cpp b/accessible/src/base/nsBaseWidgetAccessible.cpp index 75ed025e1bf2..646859e555ea 100644 --- a/accessible/src/base/nsBaseWidgetAccessible.cpp +++ b/accessible/src/base/nsBaseWidgetAccessible.cpp @@ -252,9 +252,10 @@ NS_IMETHODIMP nsLinkableAccessible::DoAction(PRUint8 index) if (IsALink()) { nsCOMPtr presContext(GetPresContext()); if (presContext) { - nsMouseEvent linkClickEvent(NS_MOUSE_LEFT_CLICK); + nsMouseEvent linkClickEvent(PR_TRUE, NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eReal); - nsEventStatus eventStatus = nsEventStatus_eIgnore; + nsEventStatus eventStatus = nsEventStatus_eIgnore; mLinkContent->HandleDOMEvent(presContext, &linkClickEvent, nsnull, diff --git a/accessible/src/xul/nsXULMenuAccessible.cpp b/accessible/src/xul/nsXULMenuAccessible.cpp index c8bcdc757573..4e27a5aa8ffd 100644 --- a/accessible/src/xul/nsXULMenuAccessible.cpp +++ b/accessible/src/xul/nsXULMenuAccessible.cpp @@ -217,7 +217,8 @@ NS_IMETHODIMP nsXULMenuitemAccessible::GetChildCount(PRInt32 *aAccChildCount) } // fire a popup dom event nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWING); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull, + nsMouseEvent::eReal); nsCOMPtr presShell(do_QueryReferent(mWeakShell)); nsCOMPtr content(do_QueryInterface(childNode)); diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 7876f6c92a90..d1ecf8ce94d0 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -629,6 +629,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver) NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget) NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSEventTarget) NS_INTERFACE_MAP_ENTRY(nsIDOMNode) NS_INTERFACE_MAP_ENTRY(nsIDOM3Node) NS_INTERFACE_MAP_ENTRY(nsIDOM3Document) @@ -1989,8 +1990,12 @@ nsDocument::EndLoad() nsCOMPtr event; CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); - if (event) { + nsCOMPtr privateEvent(do_QueryInterface(event)); + + if (privateEvent) { event->InitEvent(NS_LITERAL_STRING("DOMContentLoaded"), PR_TRUE, PR_TRUE); + privateEvent->SetTrusted(PR_TRUE); + PRBool defaultActionEnabled; DispatchEvent(event, &defaultActionEnabled); } @@ -2036,8 +2041,6 @@ nsDocument::EndLoad() break; } - nsCOMPtr private_event; - nsCOMPtr document_event = do_QueryInterface(ancestor_doc); @@ -2045,14 +2048,15 @@ nsDocument::EndLoad() document_event->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); - private_event = do_QueryInterface(event); + privateEvent = do_QueryInterface(event); } - if (event && private_event) { + if (event && privateEvent) { event->InitEvent(NS_LITERAL_STRING("DOMFrameContentLoaded"), PR_TRUE, PR_TRUE); - private_event->SetTarget(target_frame); + privateEvent->SetTarget(target_frame); + privateEvent->SetTrusted(PR_TRUE); // To dispatch this event we must manually call // HandleDOMEvent() on the ancestor document since the target @@ -2061,7 +2065,7 @@ nsDocument::EndLoad() // dispatching code. nsEvent* innerEvent; - private_event->GetInternalNSEvent(&innerEvent); + privateEvent->GetInternalNSEvent(&innerEvent); if (innerEvent) { nsEventStatus status = nsEventStatus_eIgnore; @@ -4044,6 +4048,24 @@ nsDocument::IsRegisteredHere(const nsAString & type, PRBool *_retval) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +nsDocument::AddEventListener(const nsAString& aType, + nsIDOMEventListener *aListener, + PRBool aUseCapture, PRBool aWantsUntrusted) +{ + nsCOMPtr manager; + nsresult rv = GetListenerManager(getter_AddRefs(manager)); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE; + + if (aWantsUntrusted) { + flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED; + } + + return manager->AddEventListenerByType(aListener, aType, flags, nsnull); +} + NS_IMETHODIMP nsDocument::CreateEvent(const nsAString& aEventType, nsIDOMEvent** aReturn) { diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index d5b02d290fc8..087dffe1c3f9 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -55,6 +55,7 @@ #include "nsStubDocumentObserver.h" #include "nsIDOMEventReceiver.h" #include "nsIDOM3EventTarget.h" +#include "nsIDOMNSEventTarget.h" #include "nsIDOMStyleSheetList.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMEventTarget.h" @@ -194,6 +195,7 @@ class nsDocument : public nsIDocument, public nsSupportsWeakReference, public nsIDOMEventReceiver, public nsIDOM3EventTarget, + public nsIDOMNSEventTarget, public nsIScriptObjectPrincipal, public nsIRadioGroupContainer { @@ -500,6 +502,9 @@ public: // nsIDOM3EventTarget NS_DECL_NSIDOM3EVENTTARGET + // nsIDOMNSEventTarget + NS_DECL_NSIDOMNSEVENTTARGET + // nsIScriptObjectPrincipal // virtual nsIPrincipal* GetPrincipal(); // Already declared in nsIDocument diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index fb5fc7c76229..74d79ab0abe0 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -87,6 +87,8 @@ NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode) nsDOMEventRTTearoff::Create(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3EventTarget, nsDOMEventRTTearoff::Create(this)) + NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSEventTarget, + nsDOMEventRTTearoff::Create(this)) NS_INTERFACE_MAP_ENTRY(nsIContent) // No nsITextContent since all subclasses might not want that. NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this)) @@ -1095,7 +1097,7 @@ nsGenericDOMDataNode::SetText(const PRUnichar* aBuffer, if (haveMutationListeners) { nsCOMPtr node(do_QueryInterface(this)); - nsMutationEvent mutation(NS_MUTATION_CHARACTERDATAMODIFIED, node); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_CHARACTERDATAMODIFIED, node); mutation.mPrevAttrValue = oldValue; if (aLength > 0) { @@ -1141,7 +1143,7 @@ nsGenericDOMDataNode::SetText(const char* aBuffer, PRUint32 aLength, if (haveMutationListeners) { nsCOMPtr node(do_QueryInterface(this)); - nsMutationEvent mutation(NS_MUTATION_CHARACTERDATAMODIFIED, node); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_CHARACTERDATAMODIFIED, node); mutation.mPrevAttrValue = oldValue; if (aLength > 0) { @@ -1176,14 +1178,14 @@ nsGenericDOMDataNode::SetText(const nsAString& aStr, if (haveMutationListeners) { oldValue = GetCurrentValueAtom(); } - + mText = aStr; SetBidiStatus(); if (haveMutationListeners) { nsCOMPtr node(do_QueryInterface(this)); - nsMutationEvent mutation(NS_MUTATION_CHARACTERDATAMODIFIED, node); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_CHARACTERDATAMODIFIED, node); mutation.mPrevAttrValue = oldValue; if (!aStr.IsEmpty()) diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 21e811564403..9e542097abc2 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -498,6 +498,7 @@ NS_INTERFACE_MAP_BEGIN(nsDOMEventRTTearoff) NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget) NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver) NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSEventTarget) NS_INTERFACE_MAP_END_AGGREGATED(mContent) NS_IMPL_ADDREF(nsDOMEventRTTearoff) @@ -700,6 +701,27 @@ nsDOMEventRTTearoff::IsRegisteredHere(const nsAString & type, PRBool *_retval) return NS_ERROR_NOT_IMPLEMENTED; } +// nsIDOMNSEventTarget +NS_IMETHODIMP +nsDOMEventRTTearoff::AddEventListener(const nsAString& aType, + nsIDOMEventListener *aListener, + PRBool aUseCapture, + PRBool aWantsUntrusted) +{ + nsCOMPtr listener_manager; + nsresult rv = mContent->GetListenerManager(getter_AddRefs(listener_manager)); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE; + + if (aWantsUntrusted) { + flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED; + } + + return listener_manager->AddEventListenerByType(aListener, aType, flags, + nsnull); +} + //---------------------------------------------------------------------- nsDOMSlots::nsDOMSlots(PtrBits aFlags) @@ -2680,7 +2702,7 @@ nsGenericElement::InsertChildAt(nsIContent* aKid, } if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEINSERTED)) { - nsMutationEvent mutation(NS_MUTATION_NODEINSERTED, aKid); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_NODEINSERTED, aKid); mutation.mRelatedNode = do_QueryInterface(this); nsEventStatus status = nsEventStatus_eIgnore; @@ -2722,7 +2744,7 @@ nsGenericElement::AppendChildTo(nsIContent* aKid, PRBool aNotify) } if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEINSERTED)) { - nsMutationEvent mutation(NS_MUTATION_NODEINSERTED, aKid); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_NODEINSERTED, aKid); mutation.mRelatedNode = do_QueryInterface(this); nsEventStatus status = nsEventStatus_eIgnore; @@ -2742,7 +2764,7 @@ nsGenericElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify) mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify); if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEREMOVED)) { - nsMutationEvent mutation(NS_MUTATION_NODEREMOVED, oldKid); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_NODEREMOVED, oldKid); mutation.mRelatedNode = do_QueryInterface(this); nsEventStatus status = nsEventStatus_eIgnore; @@ -3241,6 +3263,8 @@ NS_INTERFACE_MAP_BEGIN(nsGenericElement) nsDOMEventRTTearoff::Create(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3EventTarget, nsDOMEventRTTearoff::Create(this)) + NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSEventTarget, + nsDOMEventRTTearoff::Create(this)) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent) NS_INTERFACE_MAP_END @@ -3342,7 +3366,21 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, } if (manager) { - rv = manager->AddScriptEventListener(target, aAttribute, aValue, defer); + nsIDocument *ownerDoc = GetOwnerDoc(); + + PRBool permitUntrustedEvents = PR_FALSE; + + nsIURI *docUri; + if (ownerDoc && (docUri = ownerDoc->GetDocumentURI())) { + PRBool isChrome = PR_TRUE; + rv = docUri->SchemeIs("chrome", &isChrome); + NS_ENSURE_SUCCESS(rv, rv); + + permitUntrustedEvents = !isChrome; + } + + rv = manager->AddScriptEventListener(target, aAttribute, aValue, defer, + permitUntrustedEvents); } return rv; @@ -3512,8 +3550,9 @@ nsGenericElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, binding->AttributeChanged(aName, aNamespaceID, PR_FALSE, aNotify); if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED)) { - nsCOMPtr node(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); - nsMutationEvent mutation(NS_MUTATION_ATTRMODIFIED, node); + nsCOMPtr node = + do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED, node); nsAutoString attrName; aName->ToString(attrName); @@ -3609,8 +3648,9 @@ nsGenericElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, } if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED)) { - nsCOMPtr node(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); - nsMutationEvent mutation(NS_MUTATION_ATTRMODIFIED, node); + nsCOMPtr node = + do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED, node); nsAutoString attrName; aName->ToString(attrName); diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index 6078050a1be1..d75afd06233b 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -45,6 +45,7 @@ #include "nsIDOMEventReceiver.h" #include "nsIDOM3EventTarget.h" #include "nsIDOM3Node.h" +#include "nsIDOMNSEventTarget.h" #include "nsILinkHandler.h" #include "nsGenericDOMNodeList.h" #include "nsIEventListenerManager.h" @@ -281,7 +282,8 @@ private: */ class nsDOMEventRTTearoff : public nsIDOMEventReceiver, - public nsIDOM3EventTarget + public nsIDOM3EventTarget, + public nsIDOMNSEventTarget { private: // This class uses a caching scheme so we don't let users of this @@ -337,6 +339,9 @@ public: NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent); NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup); + // nsIDOMNSEventTarget + NS_DECL_NSIDOMNSEVENTTARGET + private: /** * Strong reference back to the content object from where an instance of this diff --git a/content/base/src/nsImageLoadingContent.cpp b/content/base/src/nsImageLoadingContent.cpp index 1d25a7d4a703..2e1d4c067dc8 100644 --- a/content/base/src/nsImageLoadingContent.cpp +++ b/content/base/src/nsImageLoadingContent.cpp @@ -642,7 +642,7 @@ HandleImagePLEvent(PLEvent* aEvent) eventMsg = NS_IMAGE_ERROR; } - nsEvent event(eventMsg); + nsEvent event(PR_TRUE, eventMsg); evt->mContent->HandleDOMEvent(evt->mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &estatus); diff --git a/content/events/public/nsIEventListenerManager.h b/content/events/public/nsIEventListenerManager.h index 14504df3898e..a1f8e7155155 100644 --- a/content/events/public/nsIEventListenerManager.h +++ b/content/events/public/nsIEventListenerManager.h @@ -102,15 +102,18 @@ public: NS_IMETHOD AddScriptEventListener(nsISupports *aObject, nsIAtom *aName, const nsAString& aFunc, - PRBool aDeferCompilation) = 0; + PRBool aDeferCompilation, + PRBool aPermitUntrustedEvents) = 0; NS_IMETHOD RemoveScriptEventListener(nsIAtom *aName) = 0; /** * Registers an event listener that already exists on the given - * script object with the event listener manager. - * @param an event listener + * script object with the event listener manager. If the event + * listener is registerd from chrome code, the event listener will + * only ever receive trusted events. + * @param the name of an event listener */ NS_IMETHOD RegisterScriptEventListener(nsIScriptContext *aContext, nsISupports *aObject, diff --git a/content/events/public/nsIPrivateDOMEvent.h b/content/events/public/nsIPrivateDOMEvent.h index 3536c47da31e..2f35be0ccbe3 100644 --- a/content/events/public/nsIPrivateDOMEvent.h +++ b/content/events/public/nsIPrivateDOMEvent.h @@ -52,10 +52,10 @@ class nsPresContext; class nsIDOMEventTarget; class nsIDOMEvent; -struct nsEvent; - -class nsIPrivateDOMEvent : public nsISupports { +class nsEvent; +class nsIPrivateDOMEvent : public nsISupports +{ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPRIVATEDOMEVENT_IID) @@ -70,20 +70,20 @@ public: }; nsresult -NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, struct nsEvent *aEvent); +NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, nsEvent *aEvent); nsresult -NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, struct nsGUIEvent *aEvent); +NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsGUIEvent *aEvent); nsresult -NS_NewDOMMouseEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, struct nsInputEvent *aEvent); +NS_NewDOMMouseEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsInputEvent *aEvent); nsresult -NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, struct nsKeyEvent *aEvent); +NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsKeyEvent *aEvent); nsresult -NS_NewDOMMutationEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, struct nsMutationEvent* aEvent); +NS_NewDOMMutationEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsMutationEvent* aEvent); nsresult -NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, struct nsPopupBlockedEvent* aEvent); +NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsPopupBlockedEvent* aEvent); nsresult -NS_NewDOMTextEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, struct nsTextEvent* aEvent); +NS_NewDOMTextEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsTextEvent* aEvent); nsresult -NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, struct nsBeforePageUnloadEvent* aEvent); +NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsBeforePageUnloadEvent* aEvent); #endif // nsIPrivateDOMEvent_h__ diff --git a/content/events/public/nsMutationEvent.h b/content/events/public/nsMutationEvent.h index bc668475401c..1a893a987e45 100644 --- a/content/events/public/nsMutationEvent.h +++ b/content/events/public/nsMutationEvent.h @@ -44,29 +44,26 @@ #include "nsIDOMEventTarget.h" #include "nsIContent.h" -struct nsMutationEvent : public nsEvent -{ - nsMutationEvent(PRUint32 msg = 0, PRUint8 structType = NS_MUTATION_EVENT) - : nsEvent(msg, structType), +class nsMutationEvent : public nsEvent +{ +public: + nsMutationEvent(PRBool isTrusted, PRUint32 msg) + : nsEvent(isTrusted, msg, NS_MUTATION_EVENT), mAttrChange(0) { flags |= NS_EVENT_FLAG_CANT_CANCEL; } - nsMutationEvent(PRUint32 msg, - nsIDOMEventTarget *target, - PRUint8 structType = NS_MUTATION_EVENT) - : nsEvent(msg, structType), + nsMutationEvent(PRBool isTrusted, PRUint32 msg, nsIDOMEventTarget *target) + : nsEvent(isTrusted, msg, NS_MUTATION_EVENT), mTarget(target), mAttrChange(0) { flags |= NS_EVENT_FLAG_CANT_CANCEL; } - nsMutationEvent(PRUint32 msg, - nsIContent *target, - PRUint8 structType = NS_MUTATION_EVENT) - : nsEvent(msg, structType), + nsMutationEvent(PRBool isTrusted, PRUint32 msg, nsIContent *target) + : nsEvent(isTrusted, msg, NS_MUTATION_EVENT), mTarget(do_QueryInterface(target)), mAttrChange(0) { diff --git a/content/events/src/nsDOMBeforeUnloadEvent.cpp b/content/events/src/nsDOMBeforeUnloadEvent.cpp index e3a2c696abd9..3a51500e5917 100644 --- a/content/events/src/nsDOMBeforeUnloadEvent.cpp +++ b/content/events/src/nsDOMBeforeUnloadEvent.cpp @@ -41,7 +41,9 @@ nsDOMBeforeUnloadEvent::nsDOMBeforeUnloadEvent(nsPresContext* aPresContext, nsBeforePageUnloadEvent* aEvent) - : nsDOMEvent(aPresContext, aEvent ? aEvent : new nsBeforePageUnloadEvent(NS_BEFORE_PAGE_UNLOAD)) + : nsDOMEvent(aPresContext, aEvent ? aEvent : + new nsBeforePageUnloadEvent(PR_FALSE, + NS_BEFORE_PAGE_UNLOAD_EVENT)) { NS_ASSERTION(mEvent->eventStructType == NS_BEFORE_PAGE_UNLOAD_EVENT, "event type mismatch"); diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 62d28919ee06..c11c32e2ebb6 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -106,7 +106,7 @@ nsDOMEvent::nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent) ... } */ - mEvent = new nsEvent(); + mEvent = new nsEvent(PR_FALSE, 0); mEvent->time = PR_Now(); } @@ -364,7 +364,7 @@ nsDOMEvent::PreventCapture() NS_IMETHODIMP nsDOMEvent::GetIsTrusted(PRBool *aIsTrusted) { - *aIsTrusted = (mEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED) != 0; + *aIsTrusted = NS_IS_TRUSTED_EVENT(mEvent); return NS_OK; } @@ -633,7 +633,7 @@ nsDOMEvent::GetEventPopupControlState(nsEvent *aEvent) } break; case NS_KEY_EVENT : - if (aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED) { + if (NS_IS_TRUSTED_EVENT(aEvent)) { PRUint32 key = NS_STATIC_CAST(nsKeyEvent *, aEvent)->keyCode; switch(aEvent->message) { case NS_KEY_PRESS : @@ -658,7 +658,7 @@ nsDOMEvent::GetEventPopupControlState(nsEvent *aEvent) } break; case NS_MOUSE_EVENT : - if (aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED) { + if (NS_IS_TRUSTED_EVENT(aEvent)) { switch(aEvent->message) { case NS_MOUSE_LEFT_BUTTON_UP : if (::PopupAllowedForEvent("mouseup")) diff --git a/content/events/src/nsDOMKeyboardEvent.cpp b/content/events/src/nsDOMKeyboardEvent.cpp index d358a0f9b892..314e19408840 100644 --- a/content/events/src/nsDOMKeyboardEvent.cpp +++ b/content/events/src/nsDOMKeyboardEvent.cpp @@ -41,8 +41,10 @@ #include "nsContentUtils.h" -nsDOMKeyboardEvent::nsDOMKeyboardEvent(nsPresContext* aPresContext, nsKeyEvent* aEvent) -: nsDOMUIEvent(aPresContext, aEvent ? aEvent : new nsKeyEvent()) +nsDOMKeyboardEvent::nsDOMKeyboardEvent(nsPresContext* aPresContext, + nsKeyEvent* aEvent) + : nsDOMUIEvent(aPresContext, aEvent ? aEvent : + new nsKeyEvent(PR_FALSE, 0, nsnull)) { NS_ASSERTION(mEvent->eventStructType == NS_KEY_EVENT, "event type mismatch"); diff --git a/content/events/src/nsDOMMouseEvent.cpp b/content/events/src/nsDOMMouseEvent.cpp index 233e14aa6533..858a89e1e8c9 100644 --- a/content/events/src/nsDOMMouseEvent.cpp +++ b/content/events/src/nsDOMMouseEvent.cpp @@ -43,8 +43,12 @@ #include "nsIEventStateManager.h" #include "nsContentUtils.h" -nsDOMMouseEvent::nsDOMMouseEvent(nsPresContext* aPresContext, nsInputEvent* aEvent) -: nsDOMUIEvent(aPresContext, aEvent ? aEvent : new nsMouseEvent()), mButton(-1) +nsDOMMouseEvent::nsDOMMouseEvent(nsPresContext* aPresContext, + nsInputEvent* aEvent) + : nsDOMUIEvent(aPresContext, aEvent ? aEvent : + new nsMouseEvent(PR_FALSE, 0, nsnull, + nsMouseEvent::eReal)), + mButton(-1) { // There's no way to make this class' ctor allocate an nsMouseScrollEvent. // It's not that important, though, since a scroll event is not a real diff --git a/content/events/src/nsDOMMutationEvent.cpp b/content/events/src/nsDOMMutationEvent.cpp index 3512b3c389a4..0147bb1496ea 100644 --- a/content/events/src/nsDOMMutationEvent.cpp +++ b/content/events/src/nsDOMMutationEvent.cpp @@ -42,8 +42,10 @@ class nsPresContext; -nsDOMMutationEvent::nsDOMMutationEvent(nsPresContext* aPresContext, nsMutationEvent* aEvent) - :nsDOMEvent(aPresContext, aEvent ? aEvent : new nsMutationEvent()) +nsDOMMutationEvent::nsDOMMutationEvent(nsPresContext* aPresContext, + nsMutationEvent* aEvent) + : nsDOMEvent(aPresContext, aEvent ? aEvent : + new nsMutationEvent(PR_FALSE, 0)) { if ( aEvent ) { mEventIsInternal = PR_FALSE; diff --git a/content/events/src/nsDOMPopupBlockedEvent.cpp b/content/events/src/nsDOMPopupBlockedEvent.cpp index c942123c0c9d..a40de2ab6953 100644 --- a/content/events/src/nsDOMPopupBlockedEvent.cpp +++ b/content/events/src/nsDOMPopupBlockedEvent.cpp @@ -41,8 +41,10 @@ #include "nsIURI.h" #include "nsContentUtils.h" -nsDOMPopupBlockedEvent::nsDOMPopupBlockedEvent(nsPresContext* aPresContext, nsPopupBlockedEvent* aEvent) -: nsDOMEvent(aPresContext, aEvent ? aEvent : new nsPopupBlockedEvent()) +nsDOMPopupBlockedEvent::nsDOMPopupBlockedEvent(nsPresContext* aPresContext, + nsPopupBlockedEvent* aEvent) + : nsDOMEvent(aPresContext, aEvent ? aEvent : + new nsPopupBlockedEvent(PR_FALSE, 0)) { NS_ASSERTION(mEvent->eventStructType == NS_POPUPBLOCKED_EVENT, "event type mismatch"); diff --git a/content/events/src/nsDOMTextEvent.cpp b/content/events/src/nsDOMTextEvent.cpp index 9f175365c588..469775cbd5cd 100644 --- a/content/events/src/nsDOMTextEvent.cpp +++ b/content/events/src/nsDOMTextEvent.cpp @@ -40,8 +40,10 @@ #include "nsContentUtils.h" #include "nsPrivateTextRange.h" -nsDOMTextEvent::nsDOMTextEvent(nsPresContext* aPresContext, nsTextEvent* aEvent) -: nsDOMUIEvent(aPresContext, aEvent ? aEvent : new nsTextEvent()) +nsDOMTextEvent::nsDOMTextEvent(nsPresContext* aPresContext, + nsTextEvent* aEvent) + : nsDOMUIEvent(aPresContext, aEvent ? aEvent : + new nsTextEvent(PR_FALSE, 0, nsnull)) { NS_ASSERTION(mEvent->eventStructType == NS_TEXT_EVENT, "event type mismatch"); diff --git a/content/events/src/nsDOMUIEvent.cpp b/content/events/src/nsDOMUIEvent.cpp index c0011e5fd745..a4de3081992e 100644 --- a/content/events/src/nsDOMUIEvent.cpp +++ b/content/events/src/nsDOMUIEvent.cpp @@ -53,8 +53,9 @@ #include "nsIFrame.h" nsDOMUIEvent::nsDOMUIEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent) - : nsDOMEvent(aPresContext, aEvent ? NS_STATIC_CAST(nsEvent*, aEvent) - : NS_STATIC_CAST(nsEvent*, new nsUIEvent())) + : nsDOMEvent(aPresContext, aEvent ? + NS_STATIC_CAST(nsEvent *, aEvent) : + NS_STATIC_CAST(nsEvent *, new nsUIEvent(PR_FALSE, 0, 0))) { if (aEvent) { mEventIsInternal = PR_FALSE; @@ -64,7 +65,8 @@ nsDOMUIEvent::nsDOMUIEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent) mEvent->time = PR_Now(); } - // Fill mDetail and mView according to the mEvent (widget-generated event) we've got + // Fill mDetail and mView according to the mEvent (widget-generated + // event) we've got switch(mEvent->eventStructType) { case NS_UI_EVENT: @@ -413,9 +415,8 @@ NS_IMETHODIMP nsDOMUIEvent::GetPreventDefault(PRBool* aReturn) { NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = mEvent ? - ((mEvent->flags & NS_EVENT_FLAG_NO_DEFAULT) ? PR_TRUE : PR_FALSE) : - PR_FALSE; + *aReturn = mEvent && (mEvent->flags & NS_EVENT_FLAG_NO_DEFAULT); + return NS_OK; } diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 1f996a51d764..2d185ceea387 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -407,7 +407,8 @@ nsEventListenerManager::~nsEventListenerManager() } } -nsresult nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly) +nsresult +nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly) { if (!aScriptOnly) { mListenersRemoved = PR_TRUE; @@ -421,7 +422,7 @@ nsresult nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly) if (mMultiListeners) { // XXX probably should just be i < Count() - for (int i=0; iCount(); i++) { + for (PRInt32 i=0; iCount(); i++) { nsVoidArray* listeners; listeners = NS_STATIC_CAST(nsVoidArray*, mMultiListeners->ElementAt(i)); ReleaseListeners(&listeners, aScriptOnly); @@ -447,7 +448,8 @@ nsresult nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly) return NS_OK; } -void nsEventListenerManager::Shutdown() +void +nsEventListenerManager::Shutdown() { sAddListenerID = JSVAL_VOID; @@ -467,9 +469,9 @@ NS_INTERFACE_MAP_BEGIN(nsEventListenerManager) NS_INTERFACE_MAP_END -nsVoidArray* nsEventListenerManager::GetListenersByType(EventArrayType aType, - nsHashKey* aKey, - PRBool aCreate) +nsVoidArray* +nsEventListenerManager::GetListenersByType(EventArrayType aType, + nsHashKey* aKey, PRBool aCreate) { NS_ASSERTION(aType >= 0,"Negative EventListenerType?"); //Look for existing listeners @@ -571,7 +573,8 @@ nsVoidArray* nsEventListenerManager::GetListenersByType(EventArrayType aType, return nsnull; } -EventArrayType nsEventListenerManager::GetTypeForIID(const nsIID& aIID) +EventArrayType +nsEventListenerManager::GetTypeForIID(const nsIID& aIID) { if (aIID.Equals(NS_GET_IID(nsIDOMMouseListener))) return eEventArrayType_Mouse; @@ -621,7 +624,9 @@ EventArrayType nsEventListenerManager::GetTypeForIID(const nsIID& aIID) return eEventArrayType_None; } -void nsEventListenerManager::ReleaseListeners(nsVoidArray** aListeners, PRBool aScriptOnly) +void +nsEventListenerManager::ReleaseListeners(nsVoidArray** aListeners, + PRBool aScriptOnly) { if (nsnull != *aListeners) { PRInt32 i, count = (*aListeners)->Count(); @@ -707,7 +712,7 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, PRBool found = PR_FALSE; nsListenerStruct* ls; - for (int i=0; iCount(); i++) { + for (PRInt32 i=0; iCount(); i++) { ls = (nsListenerStruct*)listeners->ElementAt(i); if (ls->mListener == aListener && ls->mFlags == aFlags && ls->mGroupFlags == group) { @@ -751,7 +756,7 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener, nsListenerStruct* ls; PRBool listenerRemoved = PR_FALSE; - for (int i=0; iCount(); i++) { + for (PRInt32 i=0; iCount(); i++) { ls = (nsListenerStruct*)listeners->ElementAt(i); if (ls->mListener == aListener && ls->mFlags == aFlags) { ls->mSubType &= ~aSubType; @@ -1064,9 +1069,10 @@ nsEventListenerManager::FindJSEventListener(EventArrayType aType) { nsVoidArray *listeners = GetListenersByType(aType, nsnull, PR_FALSE); if (listeners) { - //Run through the listeners for this IID and see if a script listener is registered + // Run through the listeners for this type and see if a script + // listener is registered nsListenerStruct *ls; - for (int i=0; iCount(); i++) { + for (PRInt32 i=0; i < listeners->Count(); i++) { ls = (nsListenerStruct*)listeners->ElementAt(i); if (ls->mFlags & NS_PRIV_EVENT_FLAG_SCRIPT) { return ls; @@ -1081,7 +1087,8 @@ nsresult nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, nsISupports *aObject, nsIAtom* aName, - PRBool aIsString) + PRBool aIsString, + PRBool aPermitUntrustedEvents) { nsresult rv = NS_OK; nsListenerStruct *ls; @@ -1094,8 +1101,8 @@ nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, ls = FindJSEventListener(arrayType); if (nsnull == ls) { - //If we didn't find a script listener or no listeners existed - //create and add a new one. + // If we didn't find a script listener or no listeners existed + // create and add a new one. nsCOMPtr factory = do_GetService(kDOMScriptObjectFactoryCID); NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); @@ -1120,8 +1127,12 @@ nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, ls->mHandlerIsString &= ~flags; } - //Set subtype flags based on event + // Set subtype flags based on event ls->mSubType |= flags; + + if (aPermitUntrustedEvents) { + ls->mFlags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED; + } } return rv; @@ -1131,7 +1142,8 @@ NS_IMETHODIMP nsEventListenerManager::AddScriptEventListener(nsISupports *aObject, nsIAtom *aName, const nsAString& aBody, - PRBool aDeferCompilation) + PRBool aDeferCompilation, + PRBool aPermitUntrustedEvents) { nsIScriptContext *context = nsnull; JSContext* cx = nsnull; @@ -1267,7 +1279,8 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject, } } - return SetJSEventListener(context, objiSupp, aName, aDeferCompilation); + return SetJSEventListener(context, objiSupp, aName, aDeferCompilation, + aPermitUntrustedEvents); } nsresult @@ -1344,7 +1357,8 @@ nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, nsCOMPtr classInfo = do_QueryInterface(aObject); if (sAddListenerID == JSVAL_VOID && cx) { - sAddListenerID = STRING_TO_JSVAL(::JS_InternString(cx, "addEventListener")); + sAddListenerID = + STRING_TO_JSVAL(::JS_InternString(cx, "addEventListener")); rv = nsContentUtils::GetSecurityManager()-> CheckPropertyAccess(cx, jsobj, @@ -1357,7 +1371,10 @@ nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, } } - return SetJSEventListener(aContext, wrapper->Native(), aName, PR_FALSE); + // Untrusted events are always permitted for non-chrome script + // handlers. + return SetJSEventListener(aContext, wrapper->Native(), aName, PR_FALSE, + !nsContentUtils::IsCallerChrome()); } nsresult @@ -1554,12 +1571,12 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, * @param an event listener */ -nsresult nsEventListenerManager::HandleEvent(nsPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - nsIDOMEventTarget* aCurrentTarget, - PRUint32 aFlags, - nsEventStatus* aEventStatus) +nsresult +nsEventListenerManager::HandleEvent(nsPresContext* aPresContext, + nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + nsIDOMEventTarget* aCurrentTarget, + PRUint32 aFlags, + nsEventStatus* aEventStatus) { NS_ENSURE_ARG_POINTER(aEventStatus); nsresult ret = NS_OK; @@ -1598,9 +1615,9 @@ nsresult nsEventListenerManager::HandleEvent(nsPresContext* aPresContext, if (aEvent->message == NS_USER_DEFINED_EVENT) { listeners = GetListenersByType(eEventArrayType_Hash, aEvent->userType, PR_FALSE); } else { - for (int i = 0; i < eEventArrayType_Hash; ++i) { + for (PRInt32 i = 0; i < eEventArrayType_Hash; ++i) { typeData = &sEventTypes[i]; - for (int j = 0; j < typeData->numEvents; ++j) { + for (PRInt32 j = 0; j < typeData->numEvents; ++j) { dispData = &(typeData->events[j]); if (aEvent->message == dispData->message) { listeners = GetListenersByType((EventArrayType)i, nsnull, PR_FALSE); @@ -1623,10 +1640,14 @@ nsresult nsEventListenerManager::HandleEvent(nsPresContext* aPresContext, nsAutoPopupStatePusher popupStatePusher(nsDOMEvent::GetEventPopupControlState(aEvent)); - for (int k = 0; !mListenersRemoved && listeners && k < count; ++k) { + for (PRInt32 k = 0; !mListenersRemoved && listeners && k < count; ++k) { nsListenerStruct* ls = NS_STATIC_CAST(nsListenerStruct*, originalListeners.FastElementAt(k)); // Don't fire the listener if it's been removed - if (listeners->IndexOf(ls) != -1 && ls->mFlags & aFlags && ls->mGroupFlags == currentGroup) { + + if (listeners->IndexOf(ls) != -1 && ls->mFlags & aFlags && + ls->mGroupFlags == currentGroup && + (NS_IS_TRUSTED_EVENT(aEvent) || + ls->mFlags & NS_PRIV_EVENT_UNTRUSTED_PERMITTED)) { // Try the type-specific listener interface PRBool hasInterface = PR_FALSE; if (typeData) @@ -1636,10 +1657,11 @@ nsresult nsEventListenerManager::HandleEvent(nsPresContext* aPresContext, // If it doesn't implement that, call the generic HandleEvent() if (!hasInterface && (ls->mSubType == NS_EVENT_BITS_NONE || - ls->mSubType & dispData->bits)) + ls->mSubType & dispData->bits)) { HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, dispData ? dispData->bits : NS_EVENT_BITS_NONE, aFlags); + } } } } @@ -2106,10 +2128,11 @@ nsEventListenerManager::FixContextMenuEvent(nsPresContext* aPresContext, // Get coordinates relative to root view for element, // first ensuring the element is onscreen -void nsEventListenerManager::GetCoordinatesFor(nsIDOMElement *aCurrentEl, - nsPresContext *aPresContext, - nsIPresShell *aPresShell, - nsPoint& aTargetPt) +void +nsEventListenerManager::GetCoordinatesFor(nsIDOMElement *aCurrentEl, + nsPresContext *aPresContext, + nsIPresShell *aPresShell, + nsPoint& aTargetPt) { nsCOMPtr focusedContent(do_QueryInterface(aCurrentEl)); nsIFrame *frame = nsnull; diff --git a/content/events/src/nsEventListenerManager.h b/content/events/src/nsEventListenerManager.h index 8c273fc4682b..92ac572f505e 100644 --- a/content/events/src/nsEventListenerManager.h +++ b/content/events/src/nsEventListenerManager.h @@ -126,7 +126,8 @@ public: NS_IMETHOD AddScriptEventListener(nsISupports *aObject, nsIAtom *aName, const nsAString& aFunc, - PRBool aDeferCompilation); + PRBool aDeferCompilation, + PRBool aPermitUntrustedEvents); NS_IMETHOD RegisterScriptEventListener(nsIScriptContext *aContext, nsISupports *aObject, nsIAtom* aName); @@ -199,7 +200,7 @@ protected: nsListenerStruct* FindJSEventListener(EventArrayType aType); nsresult SetJSEventListener(nsIScriptContext *aContext, nsISupports *aObject, nsIAtom* aName, - PRBool aIsString); + PRBool aIsString, PRBool aPermitUntrustedEvents); nsresult AddEventListener(nsIDOMEventListener *aListener, EventArrayType aType, PRInt32 aSubType, diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index ddc5aead4879..1bb07e17bee6 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -530,7 +530,7 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, // Fire the blur event on the previously focused document. nsEventStatus blurstatus = nsEventStatus_eIgnore; - nsEvent blurevent(NS_BLUR_CONTENT); + nsEvent blurevent(PR_TRUE, NS_BLUR_CONTENT); gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &blurevent, @@ -582,10 +582,9 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, // Now we should fire the focus event. We fire it on the document, // then the content node, then the window. - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent focusevent(NS_FOCUS_CONTENT); + nsCOMPtr globalObject = + mDocument->GetScriptGlobalObject(); - nsCOMPtr globalObject = mDocument->GetScriptGlobalObject(); if (globalObject) { // We don't want there to be a focused content node while we're // dispatching the focus event. @@ -594,6 +593,9 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, // "leak" this reference, but we take it back later SetFocusedContent(nsnull); + nsEventStatus status = nsEventStatus_eIgnore; + nsEvent focusevent(PR_TRUE, NS_FOCUS_CONTENT); + if (gLastFocusedDocument != mDocument) { mDocument->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -681,7 +683,7 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, // and window. nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_BLUR_CONTENT); + nsEvent event(PR_TRUE, NS_BLUR_CONTENT); if (gLastFocusedDocument && gLastFocusedPresContext) { if (gLastFocusedContent) { @@ -837,7 +839,7 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, if (gLastFocusedDocument && gLastFocusedDocument == mDocument) { nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_BLUR_CONTENT); + nsEvent event(PR_TRUE, NS_BLUR_CONTENT); if (gLastFocusedContent) { nsIPresShell *shell = gLastFocusedDocument->GetShellAt(0); @@ -999,14 +1001,14 @@ nsEventStateManager::HandleAccessKey(nsPresContext* aPresContext, if (sKeyCausesActivation) { // B) Click on it if the users prefs indicate to do so. - nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_MOUSE_LEFT_CLICK); // Propagate trusted state to the new event. - event.internalAppFlags |= - aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED; + nsEventStatus status = nsEventStatus_eIgnore; + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_MOUSE_LEFT_CLICK, + nsnull, nsMouseEvent::eReal); - nsAutoPopupStatePusher popupStatePusher(aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED ? openAllowed : openAbused); + nsAutoPopupStatePusher popupStatePusher(NS_IS_TRUSTED_EVENT(aEvent) ? + openAllowed : openAbused); nsCOMPtr oldTargetContent = mCurrentTargetContent; mCurrentTargetContent = content; @@ -1114,7 +1116,7 @@ nsEventStateManager::CreateClickHoldTimer(nsPresContext* inPresContext, nsIFrame* inDownFrame, nsGUIEvent* inMouseDownEvent) { - if (!(inMouseDownEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED)) + if (!NS_IS_TRUSTED_EVENT(inMouseDownEvent)) return; // just to be anal (er, safe) @@ -1273,9 +1275,11 @@ nsEventStateManager::FireContextClick() frameSel->SetMouseDownState(PR_FALSE); } - nsMouseEvent event(NS_CONTEXTMENU, mCurrentTarget->GetWindow()); + nsMouseEvent event(PR_TRUE, NS_CONTEXTMENU, + mCurrentTarget->GetWindow(), + nsMouseEvent::eReal); event.clickCount = 1; - FillInEventFromGestureDown(&event, PR_TRUE); + FillInEventFromGestureDown(&event); // dispatch to DOM mGestureDownContent->HandleDOMEvent(mPresContext, &event, nsnull, @@ -1387,8 +1391,7 @@ nsEventStateManager::GetSelection(nsIFrame* inFrame, } // GetSelection void -nsEventStateManager::FillInEventFromGestureDown(nsMouseEvent* aEvent, - PRBool aIsTrusted) +nsEventStateManager::FillInEventFromGestureDown(nsMouseEvent* aEvent) { NS_ASSERTION(aEvent->widget == mCurrentTarget->GetWindow(), "Incorrect widget in event"); @@ -1424,9 +1427,6 @@ nsEventStateManager::FillInEventFromGestureDown(nsMouseEvent* aEvent, aEvent->isControl = mGestureDownControl; aEvent->isAlt = mGestureDownAlt; aEvent->isMeta = mGestureDownMeta; - if (aIsTrusted) { - aEvent->internalAppFlags |= NS_APP_EVENT_FLAG_TRUSTED; - } } // @@ -1502,9 +1502,9 @@ nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext, // get the widget from the target frame nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_DRAGDROP_GESTURE, mCurrentTarget->GetWindow()); - FillInEventFromGestureDown(&event, - (aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED) != 0); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_GESTURE, + mCurrentTarget->GetWindow(), nsMouseEvent::eReal); + FillInEventFromGestureDown(&event); // Dispatch to the DOM. By setting mCurrentTarget we are faking // out the ESM and telling it that the current target frame is @@ -1660,6 +1660,13 @@ nsEventStateManager::DoScrollText(nsPresContext* aPresContext, aEvent->isControl, aEvent->isAlt, aEvent->isShift, aEvent->isMeta, 0, nsnull); + + nsCOMPtr privateEvent(do_QueryInterface(mouseEvent)); + + if (privateEvent && NS_IS_TRUSTED_EVENT(aEvent)) { + privateEvent->SetTrusted(PR_TRUE); + } + nsCOMPtr target(do_QueryInterface(targetContent)); if (target) { PRBool defaultActionEnabled; @@ -2489,7 +2496,8 @@ nsEventStateManager::DispatchMouseEvent(nsGUIEvent* aEvent, PRUint32 aMessage, nsIContent* aRelatedContent) { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(aMessage, aEvent->widget); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), aMessage, aEvent->widget, + nsMouseEvent::eReal); event.point = aEvent->point; event.refPoint = aEvent->refPoint; event.isShift = ((nsMouseEvent*)aEvent)->isShift; @@ -2497,8 +2505,6 @@ nsEventStateManager::DispatchMouseEvent(nsGUIEvent* aEvent, PRUint32 aMessage, event.isAlt = ((nsMouseEvent*)aEvent)->isAlt; event.isMeta = ((nsMouseEvent*)aEvent)->isMeta; event.nativeMsg = ((nsMouseEvent*)aEvent)->nativeMsg; - event.internalAppFlags |= - aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED; mCurrentTargetContent = aTargetContent; mCurrentRelatedContent = aRelatedContent; @@ -2603,13 +2609,14 @@ nsEventStateManager::NotifyMouseOver(nsGUIEvent* aEvent, nsIContent* aContent) nsIPresShell *parentShell = parentDoc->GetShellAt(0); if (parentShell) { nsEventStateManager* parentESM = - NS_STATIC_CAST(nsEventStateManager*, parentShell->GetPresContext()->EventStateManager()); + NS_STATIC_CAST(nsEventStateManager*, + parentShell->GetPresContext()->EventStateManager()); parentESM->NotifyMouseOver(aEvent, docContent); } } } - // Firing the DOM event in the parent document could cause all kinds of havoc. - // Reverify and take care. + // Firing the DOM event in the parent document could cause all kinds + // of havoc. Reverify and take care. if (mLastMouseOverElement == aContent) return; @@ -2690,15 +2697,15 @@ nsEventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext, if ( mLastDragOverFrame ) { //fire drag exit nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_DRAGDROP_EXIT_SYNTH, aEvent->widget); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), + NS_DRAGDROP_EXIT_SYNTH, aEvent->widget, + nsMouseEvent::eReal); event.point = aEvent->point; event.refPoint = aEvent->refPoint; event.isShift = ((nsMouseEvent*)aEvent)->isShift; event.isControl = ((nsMouseEvent*)aEvent)->isControl; event.isAlt = ((nsMouseEvent*)aEvent)->isAlt; event.isMeta = ((nsMouseEvent*)aEvent)->isMeta; - event.internalAppFlags |= - aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED; //The frame has change but the content may not have. Check before dispatching to content mLastDragOverFrame->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(lastContent)); @@ -2725,15 +2732,14 @@ nsEventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext, //fire drag enter nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_DRAGDROP_ENTER, aEvent->widget); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_ENTER, + aEvent->widget, nsMouseEvent::eReal); event.point = aEvent->point; event.refPoint = aEvent->refPoint; event.isShift = ((nsMouseEvent*)aEvent)->isShift; event.isControl = ((nsMouseEvent*)aEvent)->isControl; event.isAlt = ((nsMouseEvent*)aEvent)->isAlt; event.isMeta = ((nsMouseEvent*)aEvent)->isMeta; - event.internalAppFlags |= - aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED; mCurrentTargetContent = targetContent; mCurrentRelatedContent = lastContent; @@ -2768,15 +2774,14 @@ nsEventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext, // fire mouseout nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_DRAGDROP_EXIT_SYNTH, aEvent->widget); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_EXIT_SYNTH, + aEvent->widget, nsMouseEvent::eReal); event.point = aEvent->point; event.refPoint = aEvent->refPoint; event.isShift = ((nsMouseEvent*)aEvent)->isShift; event.isControl = ((nsMouseEvent*)aEvent)->isControl; event.isAlt = ((nsMouseEvent*)aEvent)->isAlt; event.isMeta = ((nsMouseEvent*)aEvent)->isMeta; - event.internalAppFlags |= - aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED; // dispatch to content via DOM nsCOMPtr lastContent; @@ -2894,7 +2899,8 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, break; } - nsMouseEvent event(eventMsg, aEvent->widget); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), eventMsg, aEvent->widget, + nsMouseEvent::eReal); event.point = aEvent->point; event.refPoint = aEvent->refPoint; event.clickCount = aEvent->clickCount; @@ -2902,8 +2908,6 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, event.isControl = aEvent->isControl; event.isAlt = aEvent->isAlt; event.isMeta = aEvent->isMeta; - event.internalAppFlags |= - aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED; nsCOMPtr presShell = mPresContext->GetPresShell(); if (presShell) { @@ -2926,7 +2930,8 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, break; } - nsMouseEvent event2(eventMsg, aEvent->widget); + nsMouseEvent event2(NS_IS_TRUSTED_EVENT(aEvent), eventMsg, + aEvent->widget, nsMouseEvent::eReal); event2.point = aEvent->point; event2.refPoint = aEvent->refPoint; event2.clickCount = aEvent->clickCount; @@ -2934,10 +2939,9 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, event2.isControl = aEvent->isControl; event2.isAlt = aEvent->isAlt; event2.isMeta = aEvent->isMeta; - event2.internalAppFlags |= - aEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED; - ret = presShell->HandleEventWithTarget(&event2, mCurrentTarget, mouseContent, flags, aStatus); + ret = presShell->HandleEventWithTarget(&event2, mCurrentTarget, + mouseContent, flags, aStatus); } } } @@ -3473,7 +3477,7 @@ nsEventStateManager::GetNextTabbableMapArea(PRBool aForward, // We skip the case where mCurrentFocus has tabindex == mCurrentTabIndex // since the next tab ordered element might be before it // (or after for backwards) in the child list. - index = aForward? -1 : count; + index = aForward ? -1 : (PRInt32)count; } // GetChildAt will return nsnull if our index < 0 or index >= count @@ -3990,16 +3994,19 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, //fire blur nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_BLUR_CONTENT); + nsEvent event(PR_TRUE, NS_BLUR_CONTENT); EnsureDocument(presShell); - // Make sure we're not switching command dispatchers, if so, surpress the blurred one + // Make sure we're not switching command dispatchers, if so, + // surpress the blurred one if(gLastFocusedDocument && mDocument) { nsIFocusController *newFocusController = nsnull; nsIFocusController *oldFocusController = nsnull; - nsCOMPtr newWindow = do_QueryInterface(mDocument->GetScriptGlobalObject()); - nsCOMPtr oldWindow = do_QueryInterface(gLastFocusedDocument->GetScriptGlobalObject()); + nsCOMPtr newWindow = + do_QueryInterface(mDocument->GetScriptGlobalObject()); + nsCOMPtr oldWindow = + do_QueryInterface(gLastFocusedDocument->GetScriptGlobalObject()); if(newWindow) newFocusController = newWindow->GetRootFocusController(); if(oldWindow) @@ -4045,9 +4052,10 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, if (gLastFocusedDocument && (gLastFocusedDocument != mDocument) && globalObject) { nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_BLUR_CONTENT); + nsEvent event(PR_TRUE, NS_BLUR_CONTENT); - // Make sure we're not switching command dispatchers, if so, surpress the blurred one + // Make sure we're not switching command dispatchers, if so, + // surpress the blurred one if (mDocument) { nsIFocusController *newFocusController = nsnull; nsIFocusController *oldFocusController = nsnull; @@ -4129,7 +4137,7 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, //fire focus nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_FOCUS_CONTENT); + nsEvent event(PR_TRUE, NS_FOCUS_CONTENT); if (nsnull != mPresContext) { nsCxPusher pusher(aContent); @@ -4150,7 +4158,7 @@ nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext, //fire focus on document even if the content isn't focusable (ie. text) //see bugzilla bug 93521 nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_FOCUS_CONTENT); + nsEvent event(PR_TRUE, NS_FOCUS_CONTENT); if (nsnull != mPresContext && mDocument) { nsCxPusher pusher(mDocument); diff --git a/content/events/src/nsEventStateManager.h b/content/events/src/nsEventStateManager.h index b5db4f2f4b16..bb4bd26198ee 100644 --- a/content/events/src/nsEventStateManager.h +++ b/content/events/src/nsEventStateManager.h @@ -252,9 +252,8 @@ protected: * that were set when the user first pressed the mouse button (stored by * BeginTrackingDragGesture). aEvent->widget must be * mCurrentTarget->GetWindow(). - * @param aIsTrusted if true, we set the trusted flag in the event */ - void FillInEventFromGestureDown(nsMouseEvent* aEvent, PRBool aIsTrusted); + void FillInEventFromGestureDown(nsMouseEvent* aEvent); PRBool mSuppressFocusChange; // Used only for Ender text fields to suppress a focus firing on mouse down diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 32366e13ec20..dc38326bc910 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -1426,7 +1426,8 @@ nsGenericHTMLElement::DispatchClickEvent(nsPresContext* aPresContext, NS_PRECONDITION(aSourceEvent, "Must have source event"); NS_PRECONDITION(aStatus, "Null out param?"); - nsMouseEvent event(NS_MOUSE_LEFT_CLICK, aSourceEvent->widget); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aSourceEvent), NS_MOUSE_LEFT_CLICK, + aSourceEvent->widget, nsMouseEvent::eReal); event.point = aSourceEvent->point; event.refPoint = aSourceEvent->refPoint; PRUint32 clickCount = 1; @@ -1438,8 +1439,6 @@ nsGenericHTMLElement::DispatchClickEvent(nsPresContext* aPresContext, event.isControl = aSourceEvent->isControl; event.isAlt = aSourceEvent->isAlt; event.isMeta = aSourceEvent->isMeta; - event.internalAppFlags |= - aSourceEvent->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED; return DispatchEvent(aPresContext, &event, aTarget, aFullDispatch, aStatus); } @@ -1555,7 +1554,8 @@ nsGenericHTMLElement::HandleDOMEventForAnchors(nsPresContext* aPresContext, // The default action is simply to dispatch DOMActivate nsIPresShell *shell = aPresContext->GetPresShell(); if (shell) { - nsUIEvent actEvent(NS_UI_ACTIVATE, 1); // single-click + // single-click + nsUIEvent actEvent(NS_IS_TRUSTED_EVENT(aEvent), NS_UI_ACTIVATE, 1); nsEventStatus status = nsEventStatus_eIgnore; ret = shell->HandleDOMEventWithTarget(this, &actEvent, &status); @@ -1766,7 +1766,7 @@ nsGenericHTMLElement::SetAttrAndNotify(PRInt32 aNamespaceID, if (aFireMutation) { nsCOMPtr node = do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)); - nsMutationEvent mutation(NS_MUTATION_ATTRMODIFIED, node); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED, node); nsAutoString attrName; aAttribute->ToString(attrName); diff --git a/content/html/content/src/nsHTMLButtonElement.cpp b/content/html/content/src/nsHTMLButtonElement.cpp index c290d761704a..a14fcf55702e 100644 --- a/content/html/content/src/nsHTMLButtonElement.cpp +++ b/content/html/content/src/nsHTMLButtonElement.cpp @@ -203,8 +203,13 @@ nsHTMLButtonElement::Click() if (shell) { nsCOMPtr context = shell->GetPresContext(); if (context) { + // Click() is never called from native code, but it may be + // called from chrome JS. Mark this event trusted if Click() + // is called from chrome code. + nsMouseEvent event(nsContentUtils::IsCallerChrome(), + NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_MOUSE_LEFT_CLICK); HandleDOMEvent(context, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } @@ -349,7 +354,10 @@ nsHTMLButtonElement::HandleDOMEvent(nsPresContext* aPresContext, if ((keyEvent->keyCode == NS_VK_RETURN && NS_KEY_PRESS == aEvent->message) || keyEvent->keyCode == NS_VK_SPACE && NS_KEY_UP == aEvent->message) { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_MOUSE_LEFT_CLICK); + + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), + NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eReal); rv = HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } @@ -360,7 +368,8 @@ nsHTMLButtonElement::HandleDOMEvent(nsPresContext* aPresContext, { nsIPresShell *presShell = aPresContext->GetPresShell(); if (presShell) { - nsUIEvent event(NS_UI_ACTIVATE, 1); // single-click + // single-click + nsUIEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_UI_ACTIVATE, 1); nsEventStatus status = nsEventStatus_eIgnore; presShell->HandleDOMEventWithTarget(this, &event, &status); @@ -371,22 +380,22 @@ nsHTMLButtonElement::HandleDOMEvent(nsPresContext* aPresContext, case NS_UI_ACTIVATE: { - if (mForm) { - if (mType == NS_FORM_BUTTON_SUBMIT || mType == NS_FORM_BUTTON_RESET) { - nsFormEvent event((mType == NS_FORM_BUTTON_RESET) - ? NS_FORM_RESET : NS_FORM_SUBMIT); - event.originator = this; - nsEventStatus status = nsEventStatus_eIgnore; + if (mForm && (mType == NS_FORM_BUTTON_SUBMIT || + mType == NS_FORM_BUTTON_RESET)) { + nsFormEvent event(PR_TRUE, + (mType == NS_FORM_BUTTON_RESET) + ? NS_FORM_RESET : NS_FORM_SUBMIT); + event.originator = this; + nsEventStatus status = nsEventStatus_eIgnore; - nsIPresShell *presShell = aPresContext->GetPresShell(); - // If |nsIPresShell::Destroy| has been called due to - // handling the event (base class HandleDOMEvent, above), - // the pres context will return a null pres shell. See - // bug 125624. - if (presShell) { - nsCOMPtr form(do_QueryInterface(mForm)); - presShell->HandleDOMEventWithTarget(form, &event, &status); - } + nsIPresShell *presShell = aPresContext->GetPresShell(); + // If |nsIPresShell::Destroy| has been called due to + // handling the event (base class HandleDOMEvent, above), + // the pres context will return a null pres shell. See + // bug 125624. + if (presShell) { + nsCOMPtr form(do_QueryInterface(mForm)); + presShell->HandleDOMEventWithTarget(form, &event, &status); } } } diff --git a/content/html/content/src/nsHTMLFormElement.cpp b/content/html/content/src/nsHTMLFormElement.cpp index 20a9e1851a6e..4a76af84400f 100644 --- a/content/html/content/src/nsHTMLFormElement.cpp +++ b/content/html/content/src/nsHTMLFormElement.cpp @@ -582,7 +582,7 @@ nsHTMLFormElement::Reset() // the frame does not exist. This does not have an effect right now, but // If PresShell::HandleEventWithTarget() ever starts to work for elements // without frames, that should be called instead. - nsFormEvent event(NS_FORM_RESET); + nsFormEvent event(PR_TRUE, NS_FORM_RESET); nsEventStatus status = nsEventStatus_eIgnore; HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 2766415531a8..48bbfadbf7b8 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -957,13 +957,14 @@ nsHTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext) if (submitControl) { // Fire the button's onclick handler and let the button handle // submitting the form. - nsMouseEvent event(NS_MOUSE_LEFT_CLICK); + nsMouseEvent event(PR_TRUE, NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; shell->HandleDOMEventWithTarget(submitControl, &event, &status); } else if (numTextControlsFound == 1) { // If there's only one text control, just submit the form nsCOMPtr form = do_QueryInterface(mForm); - nsFormEvent event(NS_FORM_SUBMIT); + nsFormEvent event(PR_TRUE, NS_FORM_SUBMIT); nsEventStatus status = nsEventStatus_eIgnore; shell->HandleDOMEventWithTarget(form, &event, &status); } @@ -1023,7 +1024,7 @@ nsHTMLInputElement::FireOnChange() // Since the value is changing, send out an onchange event (bug 23571) // nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_FORM_CHANGE); + nsEvent event(PR_TRUE, NS_FORM_CHANGE); nsCOMPtr presContext = GetPresContext(); HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } @@ -1134,8 +1135,8 @@ nsHTMLInputElement::Select() //If already handling select event, don't dispatch a second. if (!GET_BOOLBIT(mBitField, BF_HANDLING_SELECT_EVENT)) { - nsEvent event(NS_FORM_SELECTED); - + nsEvent event(nsContentUtils::IsCallerChrome(), NS_FORM_SELECTED); + SET_BOOLBIT(mBitField, BF_HANDLING_SELECT_EVENT, PR_TRUE); rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -1223,8 +1224,13 @@ nsHTMLInputElement::Click() nsCOMPtr context = shell->GetPresContext(); if (context) { + // Click() is never called from native code, but it may be + // called from chrome JS. Mark this event trusted if Click() + // is called from chrome code. + nsMouseEvent event(nsContentUtils::IsCallerChrome(), + NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_MOUSE_LEFT_CLICK); SET_BOOLBIT(mBitField, BF_HANDLING_CLICK, PR_TRUE); @@ -1379,7 +1385,7 @@ nsHTMLInputElement::HandleDOMEvent(nsPresContext* aPresContext, if (*aEventStatus != nsEventStatus_eConsumeNoDefault && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT) && aEvent->message == NS_MOUSE_LEFT_CLICK && mType != NS_FORM_INPUT_TEXT) { - nsUIEvent actEvent(NS_UI_ACTIVATE, 1); + nsUIEvent actEvent(NS_IS_TRUSTED_EVENT(aEvent), NS_UI_ACTIVATE, 1); nsIPresShell *shell = aPresContext->GetPresShell(); if (shell) { @@ -1490,8 +1496,11 @@ nsHTMLInputElement::HandleDOMEvent(nsPresContext* aPresContext, case NS_FORM_INPUT_SUBMIT: case NS_FORM_INPUT_IMAGE: // Bug 34418 { + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), + NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_MOUSE_LEFT_CLICK); + rv = HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } // case @@ -1519,7 +1528,9 @@ nsHTMLInputElement::HandleDOMEvent(nsPresContext* aPresContext, rv = selectedRadioButton->Focus(); if (NS_SUCCEEDED(rv)) { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_MOUSE_LEFT_CLICK); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), + NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent::eReal); rv = radioContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -1635,7 +1646,7 @@ nsHTMLInputElement::HandleDOMEvent(nsPresContext* aPresContext, case NS_FORM_INPUT_SUBMIT: case NS_FORM_INPUT_IMAGE: if (mForm) { - nsFormEvent event((mType == NS_FORM_INPUT_RESET) ? + nsFormEvent event(PR_TRUE, (mType == NS_FORM_INPUT_RESET) ? NS_FORM_RESET : NS_FORM_SUBMIT); event.originator = this; nsEventStatus status = nsEventStatus_eIgnore; @@ -2045,9 +2056,16 @@ nsHTMLInputElement::FireEventForAccessibility(nsPresContext* aPresContext, nsCOMPtr manager; GetListenerManager(getter_AddRefs(manager)); if (manager && - NS_SUCCEEDED(manager->CreateEvent(aPresContext, nsnull, NS_LITERAL_STRING("Events"), getter_AddRefs(event)))) { + NS_SUCCEEDED(manager->CreateEvent(aPresContext, nsnull, + NS_LITERAL_STRING("Events"), + getter_AddRefs(event)))) { event->InitEvent(aEventType, PR_TRUE, PR_TRUE); + nsCOMPtr privateEvent(do_QueryInterface(event)); + if (privateEvent) { + privateEvent->SetTrusted(PR_TRUE); + } + nsISupports *target = NS_STATIC_CAST(nsIDOMHTMLInputElement*, this); PRBool defaultActionEnabled; aPresContext->EventStateManager()->DispatchNewEvent(target, event, diff --git a/content/html/content/src/nsHTMLLabelElement.cpp b/content/html/content/src/nsHTMLLabelElement.cpp index e647c52f81b2..4e9db709806f 100644 --- a/content/html/content/src/nsHTMLLabelElement.cpp +++ b/content/html/content/src/nsHTMLLabelElement.cpp @@ -261,7 +261,7 @@ nsHTMLLabelElement::HandleDOMEvent(nsPresContext* aPresContext, // Since focus doesn't bubble, this is basically the second part // of redirecting |SetFocus|. { - nsEvent event(NS_FOCUS_CONTENT); + nsEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_FOCUS_CONTENT); nsEventStatus status = *aEventStatus; rv = DispatchEvent(aPresContext, &event, content, PR_TRUE, &status); // Do we care about the status this returned? I don't think we do... diff --git a/content/html/content/src/nsHTMLScriptElement.cpp b/content/html/content/src/nsHTMLScriptElement.cpp index d92a81c534a9..9b605ab8d6b5 100644 --- a/content/html/content/src/nsHTMLScriptElement.cpp +++ b/content/html/content/src/nsHTMLScriptElement.cpp @@ -552,7 +552,7 @@ nsHTMLScriptElement::ScriptAvailable(nsresult aResult, { if (!aIsInline && NS_FAILED(aResult)) { nsEventStatus status = nsEventStatus_eIgnore; - nsScriptErrorEvent event(NS_SCRIPT_ERROR); + nsScriptErrorEvent event(PR_TRUE, NS_SCRIPT_ERROR); event.lineNr = aLineNo; @@ -585,7 +585,8 @@ nsHTMLScriptElement::ScriptEvaluated(nsresult aResult, nsresult rv = NS_OK; if (!aIsInline) { nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_SUCCEEDED(aResult) ? NS_SCRIPT_LOAD : NS_SCRIPT_ERROR); + nsEvent event(PR_TRUE, + NS_SUCCEEDED(aResult) ? NS_SCRIPT_LOAD : NS_SCRIPT_ERROR); nsCOMPtr presContext = GetPresContext(); rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp index 10aa0b5def83..b8201a628ecf 100644 --- a/content/html/content/src/nsHTMLSelectElement.cpp +++ b/content/html/content/src/nsHTMLSelectElement.cpp @@ -61,6 +61,7 @@ #include "nsIDOMHTMLOptionsCollection.h" #include "nsIDOMNSHTMLOptionCollectn.h" #include "nsGUIEvent.h" +#include "nsIPrivateDOMEvent.h" #include "nsIBoxObject.h" #include "nsIDOMNSDocument.h" #include "nsIDOMDocumentEvent.h" @@ -2002,9 +2003,15 @@ nsHTMLSelectElement::DispatchDOMEvent(const nsAString& aName) nsCOMPtr domDoc = do_QueryInterface(GetOwnerDoc()); if (domDoc) { nsCOMPtr selectEvent; - domDoc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(selectEvent)); - if (selectEvent) { + domDoc->CreateEvent(NS_LITERAL_STRING("Events"), + getter_AddRefs(selectEvent)); + + nsCOMPtr privateEvent(do_QueryInterface(selectEvent)); + + if (privateEvent) { selectEvent->InitEvent(aName, PR_TRUE, PR_TRUE); + privateEvent->SetTrusted(PR_TRUE); + nsCOMPtr target = do_QueryInterface(NS_STATIC_CAST(nsIDOMNode*, this)); PRBool defaultActionEnabled; diff --git a/content/html/content/src/nsHTMLTextAreaElement.cpp b/content/html/content/src/nsHTMLTextAreaElement.cpp index bd80b9ba2cf8..ff97e19a2ce8 100644 --- a/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -278,8 +278,9 @@ nsHTMLTextAreaElement::Select() nsCOMPtr presContext = GetPresContext(); nsEventStatus status = nsEventStatus_eIgnore; - nsGUIEvent event(NS_FORM_SELECTED); - rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + nsGUIEvent event(PR_TRUE, NS_FORM_SELECTED, nsnull); + rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, + &status); // If the DOM event was not canceled (e.g. by a JS event handler // returning false) diff --git a/content/svg/content/src/nsSVGElement.cpp b/content/svg/content/src/nsSVGElement.cpp index fa753473887d..8b20c1194b2e 100644 --- a/content/svg/content/src/nsSVGElement.cpp +++ b/content/svg/content/src/nsSVGElement.cpp @@ -230,8 +230,19 @@ nsSVGElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, nsIAtom* aPrefix, nsCOMPtr manager; GetListenerManager(getter_AddRefs(manager)); if (manager) { + nsIDocument *ownerDoc = GetOwnerDoc(); + + PRBool permitUntrustedEvents = PR_FALSE; + + nsIURI *docUri; + if (ownerDoc && (docUri = ownerDoc->GetDocumentURI())) { + PRBool isChrome = PR_TRUE; + rv = docUri->SchemeIs("chrome", &isChrome); + permitUntrustedEvents = NS_SUCCEEDED(rv) && !isChrome; + } + manager->AddScriptEventListener(NS_STATIC_CAST(nsIContent*, this), aName, - aValue, PR_TRUE); + aValue, PR_TRUE, permitUntrustedEvents); } } @@ -665,7 +676,7 @@ nsSVGElement::SetAttrAndNotify(PRInt32 aNamespaceID, nsIAtom* aAttribute, if (aFireMutation) { nsCOMPtr node = do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)); - nsMutationEvent mutation(NS_MUTATION_ATTRMODIFIED, node); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED, node); nsAutoString attrName; aAttribute->ToString(attrName); diff --git a/content/svg/content/src/nsSVGScriptElement.cpp b/content/svg/content/src/nsSVGScriptElement.cpp index 99a3ffe2ac3a..fa3472d648e0 100644 --- a/content/svg/content/src/nsSVGScriptElement.cpp +++ b/content/svg/content/src/nsSVGScriptElement.cpp @@ -238,7 +238,7 @@ nsSVGScriptElement::ScriptAvailable(nsresult aResult, } nsEventStatus status = nsEventStatus_eIgnore; - nsScriptErrorEvent event(NS_SCRIPT_ERROR); + nsScriptErrorEvent event(PR_TRUE, NS_SCRIPT_ERROR); event.lineNr = aLineNo; @@ -279,7 +279,8 @@ nsSVGScriptElement::ScriptEvaluated(nsresult aResult, } nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_SUCCEEDED(aResult) ? NS_SCRIPT_LOAD : NS_SCRIPT_ERROR); + nsEvent event(PR_TRUE, + NS_SUCCEEDED(aResult) ? NS_SCRIPT_LOAD : NS_SCRIPT_ERROR); rv = HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } diff --git a/content/xml/content/src/nsXMLElement.cpp b/content/xml/content/src/nsXMLElement.cpp index de851867c401..014efb92d14c 100644 --- a/content/xml/content/src/nsXMLElement.cpp +++ b/content/xml/content/src/nsXMLElement.cpp @@ -357,7 +357,8 @@ nsXMLElement::HandleDOMEvent(nsPresContext* aPresContext, //fire click nsGUIEvent* guiEvent = NS_STATIC_CAST(nsGUIEvent*, aEvent); - nsMouseEvent event(NS_MOUSE_LEFT_CLICK, guiEvent->widget); + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_MOUSE_LEFT_CLICK, + guiEvent->widget, nsMouseEvent::eReal); event.point = aEvent->point; event.refPoint = aEvent->refPoint; event.clickCount = 1; diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index 641879f876bc..c3209639cb77 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -1003,7 +1003,7 @@ nsXMLContentSink::HandleEndElement(const PRUnichar *aName) if (content->GetNameSpaceID() == kNameSpaceID_SVG && content->HasAttr(kNameSpaceID_None, nsSVGAtoms::onload)) { nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_PAGE_LOAD); + nsEvent event(PR_TRUE, NS_PAGE_LOAD); nsIPresShell *presShell = mDocument->GetShellAt(0); if (presShell) presShell->HandleDOMEventWithTarget(content, &event, &status); diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index 52f3500a1d61..5d0818f52da8 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -632,10 +632,11 @@ nsXMLDocument::EndLoad() mLoopingForSyncLoad = PR_FALSE; if (mLoadedAsData || mLoadedAsInteractiveData) { - // Generate a document load event for the case when an XML document was loaded - // as pure data without any presentation attached to it. + // Generate a document load event for the case when an XML + // document was loaded as pure data without any presentation + // attached to it. + nsEvent event(PR_TRUE, NS_PAGE_LOAD); nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_PAGE_LOAD); nsIScriptGlobalObject* sgo = nsnull; nsCOMPtr container = diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 49c5b4aaa305..c9cdf34c5016 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -188,9 +188,6 @@ nsICSSOMFactory* nsXULElement::gCSSOMFactory = nsnull; //---------------------------------------------------------------------- -static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID); -static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); - static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID); static NS_DEFINE_CID(kCSSOMFactoryCID, NS_CSSOMFACTORY_CID); @@ -674,7 +671,19 @@ nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsAString& aValue) if (NS_FAILED(rv)) return rv; - return manager->AddScriptEventListener(target, aName, aValue, defer); + nsIURI *uri = doc->GetDocumentURI(); + PRBool isChromeElement; + + if (uri) { + if (NS_FAILED(uri->SchemeIs("chrome", &isChromeElement))) { + isChromeElement = PR_FALSE; + } + } else { + isChromeElement = PR_FALSE; + } + + return manager->AddScriptEventListener(target, aName, aValue, defer, + !isChromeElement); } nsresult @@ -1177,7 +1186,7 @@ nsXULElement::InsertChildAt(nsIContent* aKid, PRUint32 aIndex, PRBool aNotify) if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEINSERTED)) { - nsMutationEvent mutation(NS_MUTATION_NODEINSERTED, aKid); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_NODEINSERTED, aKid); mutation.mRelatedNode = do_QueryInterface(NS_STATIC_CAST(nsIStyledContent*, this)); @@ -1227,7 +1236,7 @@ nsXULElement::AppendChildTo(nsIContent* aKid, PRBool aNotify) if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEINSERTED)) { - nsMutationEvent mutation(NS_MUTATION_NODEINSERTED, aKid); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_NODEINSERTED, aKid); mutation.mRelatedNode = do_QueryInterface(NS_STATIC_CAST(nsIStyledContent*, this)); @@ -1252,7 +1261,7 @@ nsXULElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify) mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, aNotify); if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEREMOVED)) { - nsMutationEvent mutation(NS_MUTATION_NODEREMOVED, oldKid); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_NODEREMOVED, oldKid); mutation.mRelatedNode = do_QueryInterface(NS_STATIC_CAST(nsIStyledContent*, this)); @@ -1349,8 +1358,12 @@ nsXULElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify) nsCOMPtr docEvent(do_QueryInterface(doc)); nsCOMPtr event; docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); - if (event) { + nsCOMPtr privateEvent(do_QueryInterface(event)); + + if (privateEvent) { event->InitEvent(NS_LITERAL_STRING("select"), PR_FALSE, PR_TRUE); + privateEvent->SetTrusted(PR_TRUE); + nsCOMPtr target = do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)); NS_ENSURE_TRUE(target, NS_ERROR_FAILURE); @@ -1540,7 +1553,7 @@ nsXULElement::SetAttrAndNotify(PRInt32 aNamespaceID, if (aFireMutation) { nsCOMPtr node = do_QueryInterface(NS_STATIC_CAST(nsIContent *, this)); - nsMutationEvent mutation(NS_MUTATION_ATTRMODIFIED, node); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED, node); nsAutoString attrName; aAttribute->ToString(attrName); @@ -1728,7 +1741,7 @@ nsXULElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, PRBool aNotify) if (doc) { if (hasMutationListeners) { nsCOMPtr node(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); - nsMutationEvent mutation(NS_MUTATION_ATTRMODIFIED, node); + nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED, node); mutation.mRelatedNode = attrNode; mutation.mAttrName = aName; @@ -2138,11 +2151,12 @@ nsXULElement::HandleDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, nsAutoString empty; if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent))) return ret; + + if (!*aDOMEvent) { + return NS_ERROR_FAILURE; + } } - if (!*aDOMEvent) { - return NS_ERROR_FAILURE; - } nsCOMPtr privateEvent = do_QueryInterface(*aDOMEvent); if (!privateEvent) { return NS_ERROR_FAILURE; @@ -2738,9 +2752,14 @@ nsXULElement::Click() nsIPresShell *shell = doc->GetShellAt(i); context = shell->GetPresContext(); - nsMouseEvent eventDown(NS_MOUSE_LEFT_BUTTON_DOWN), - eventUp(NS_MOUSE_LEFT_BUTTON_UP), - eventClick(NS_XUL_CLICK); + PRBool isCallerChrome = nsContentUtils::IsCallerChrome(); + + nsMouseEvent eventDown(isCallerChrome, NS_MOUSE_LEFT_BUTTON_DOWN, + nsnull, nsMouseEvent::eReal); + nsMouseEvent eventUp(isCallerChrome, NS_MOUSE_LEFT_BUTTON_UP, + nsnull, nsMouseEvent::eReal); + nsMouseEvent eventClick(isCallerChrome, NS_XUL_CLICK, nsnull, + nsMouseEvent::eReal); // send mouse down nsEventStatus status = nsEventStatus_eIgnore; @@ -2776,7 +2795,8 @@ nsXULElement::DoCommand() context = shell->GetPresContext(); nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_COMMAND); + nsMouseEvent event(PR_TRUE, NS_XUL_COMMAND, nsnull, + nsMouseEvent::eReal); HandleDOMEvent(context, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } diff --git a/content/xul/document/src/nsXULCommandDispatcher.cpp b/content/xul/document/src/nsXULCommandDispatcher.cpp index 3fcb9ba92fee..86460506f1b6 100644 --- a/content/xul/document/src/nsXULCommandDispatcher.cpp +++ b/content/xul/document/src/nsXULCommandDispatcher.cpp @@ -379,7 +379,9 @@ nsXULCommandDispatcher::UpdateCommands(const nsAString& aEventName) // Handle the DOM event nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_XUL_COMMAND_UPDATE); + + nsEvent event(PR_TRUE, NS_XUL_COMMAND_UPDATE); + content->HandleDOMEvent(context, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } } diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 00d4d00ecd44..8eb58aff7185 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -1052,7 +1052,7 @@ nsXULDocument::ExecuteOnBroadcastHandlerFor(nsIContent* aBroadcaster, // This is the right element. Execute the // |onbroadcast| event handler - nsEvent event(NS_XUL_BROADCAST); + nsEvent event(PR_TRUE, NS_XUL_BROADCAST); PRInt32 j = mPresShells.Count(); while (--j >= 0) { diff --git a/dom/public/idl/events/Makefile.in b/dom/public/idl/events/Makefile.in index a7bd5885430d..f318ce93360e 100644 --- a/dom/public/idl/events/Makefile.in +++ b/dom/public/idl/events/Makefile.in @@ -66,6 +66,7 @@ XPIDLSRCS = \ nsIDOMNSUIEvent.idl \ nsIDOMPopupBlockedEvent.idl \ nsIDOMBeforeUnloadEvent.idl \ + nsIDOMNSEventTarget.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/dom/public/idl/events/nsIDOMNSEventTarget.idl b/dom/public/idl/events/nsIDOMNSEventTarget.idl new file mode 100644 index 000000000000..df5d66be9a2e --- /dev/null +++ b/dom/public/idl/events/nsIDOMNSEventTarget.idl @@ -0,0 +1,71 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 + * The Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Johnny Stenback (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "domstubs.idl" + +/** + * The nsIDOMNSEventTarget interface is an extension to the standard + * nsIDOMEventTarget interface, implemented by all event targets in + * the Document Object Model. + */ + +[scriptable, uuid(6cbbbf64-212f-4ef8-9ad4-7240dbb8d6ac)] +interface nsIDOMNSEventTarget : nsISupports +{ + /** + * This method is the same as the addEventListener() method defined + * in nsIDOMEventTarget, but it takes one additional argument which + * lets callers control whether or not they want to receive + * untrusted events (synthetic events generated by untrusted code) + * + * @param type See the type argument to the same method in + * nsIDOMEventTarget. + * @param listener See the listener argument to the same method in + * nsIDOMEventTarget. + * @param useCapture See the listener argument to the same method in + * nsIDOMEventTarget. + * @param wantsUntrusted If false, the listener will not receive any + * untrusted events (see above), if true, the + * listener will receive events whether or not + * they're trusted + */ + void addEventListener(in DOMString type, + in nsIDOMEventListener listener, + in boolean useCapture, + in boolean wantsUntrusted); +}; diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 45dcb59eb05a..1ba9b99f88ea 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -158,6 +158,7 @@ // Event related includes #include "nsIEventListenerManager.h" #include "nsIDOMEventReceiver.h" +#include "nsIDOMNSEventTarget.h" // CSS related includes #include "nsIDOMStyleSheet.h" @@ -1074,6 +1075,7 @@ jsval nsDOMClassInfo::sOpener_id = JSVAL_VOID; jsval nsDOMClassInfo::sAdd_id = JSVAL_VOID; jsval nsDOMClassInfo::sAll_id = JSVAL_VOID; jsval nsDOMClassInfo::sTags_id = JSVAL_VOID; +jsval nsDOMClassInfo::sAddEventListener_id= JSVAL_VOID; const JSClass *nsDOMClassInfo::sObjectClass = nsnull; @@ -1169,7 +1171,6 @@ GetInternedJSVal(JSContext *cx, const char *str) return STRING_TO_JSVAL(s); } - // static nsresult nsDOMClassInfo::DefineStaticJSVals(JSContext *cx) @@ -1247,6 +1248,7 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx) SET_JSVAL_TO_STRING(sAdd_id, cx, "add"); SET_JSVAL_TO_STRING(sAll_id, cx, "all"); SET_JSVAL_TO_STRING(sTags_id, cx, "tags"); + SET_JSVAL_TO_STRING(sAddEventListener_id,cx, "addEventListener"); return NS_OK; } @@ -1507,7 +1509,6 @@ nsDOMClassInfo::RegisterExternalClasses() DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Document) \ DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node) - #define DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES \ DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSHTMLElement) \ DOM_CLASSINFO_MAP_ENTRY(nsIDOMElementCSSInlineStyle) \ @@ -5561,15 +5562,116 @@ nsEventReceiverSH::ReallyIsEventName(jsval id, jschar aFirstChar) return PR_FALSE; } +// static +JSBool JS_DLL_CALLBACK +nsEventReceiverSH::AddEventListenerHelper(JSContext *cx, JSObject *obj, + uintN argc, jsval *argv, jsval *rval) +{ + if (argc < 3 || argc > 4) { + ThrowJSException(cx, NS_ERROR_XPC_NOT_ENOUGH_ARGS); + + return JS_FALSE; + } + + nsCOMPtr wrapper; + nsresult rv = + sXPConnect->GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrapper)); + if (NS_FAILED(rv)) { + nsDOMClassInfo::ThrowJSException(cx, rv); + + return JS_FALSE; + } + + if (JSVAL_IS_PRIMITIVE(argv[1])) { + // The second argument must be a function, or a + // nsIDOMEventListener. Throw an error. + ThrowJSException(cx, NS_ERROR_XPC_BAD_CONVERT_JS); + + return JS_FALSE; + } + + JSString* jsstr = JS_ValueToString(cx, argv[0]); + if (!jsstr) { + nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_OUT_OF_MEMORY); + + return JS_FALSE; + } + + nsDependentJSString type(jsstr); + + nsCOMPtr listener; + + { + nsCOMPtr tmp; + sXPConnect->WrapJS(cx, JSVAL_TO_OBJECT(argv[1]), + NS_GET_IID(nsIDOMEventListener), getter_AddRefs(tmp)); + + listener = do_QueryInterface(tmp, &rv); + if (NS_FAILED(rv)) { + ThrowJSException(cx, rv); + + return JS_FALSE; + } + } + + JSBool useCapture; + if (!JS_ValueToBoolean(cx, argv[2], &useCapture)) { + return JS_FALSE; + } + + if (argc == 4) { + JSBool wantsUntrusted; + if (!JS_ValueToBoolean(cx, argv[3], &wantsUntrusted)) { + return JS_FALSE; + } + + nsresult rv; + nsCOMPtr eventTarget(do_QueryWrappedNative(wrapper, + &rv)); + if (NS_FAILED(rv)) { + ThrowJSException(cx, rv); + + return JS_FALSE; + } + + rv = eventTarget->AddEventListener(type, listener, useCapture, + wantsUntrusted); + if (NS_FAILED(rv)) { + ThrowJSException(cx, rv); + + return JS_FALSE; + } + } else { + nsresult rv; + nsCOMPtr eventTarget(do_QueryWrappedNative(wrapper, + &rv)); + if (NS_FAILED(rv)) { + ThrowJSException(cx, rv); + + return JS_FALSE; + } + + rv = eventTarget->AddEventListener(type, listener, useCapture); + if (NS_FAILED(rv)) { + ThrowJSException(cx, rv); + + return JS_FALSE; + } + } + + return JS_TRUE; +} + nsresult nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, PRBool compile, PRBool remove, - PRBool *did_compile) + PRBool *did_define) { - NS_PRECONDITION(!compile || !remove, "Can't both compile and remove at the same time"); - *did_compile = PR_FALSE; + NS_PRECONDITION(!compile || !remove, + "Can't both compile and remove at the same time"); + *did_define = PR_FALSE; if (!IsEventName(id)) { return NS_OK; @@ -5582,7 +5684,6 @@ nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper, NS_ENSURE_TRUE(receiver, NS_ERROR_UNEXPECTED); nsCOMPtr manager; - receiver->GetListenerManager(getter_AddRefs(manager)); NS_ENSURE_TRUE(manager, NS_ERROR_UNEXPECTED); @@ -5593,7 +5694,7 @@ nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper, if (compile) { rv = manager->CompileScriptEventListener(script_cx, receiver, atom, - did_compile); + did_define); } else if (remove) { rv = manager->RemoveScriptEventListener(atom); } else { @@ -5614,13 +5715,23 @@ nsEventReceiverSH::NewResolve(nsIXPConnectWrappedNative *wrapper, return NS_OK; } - PRBool did_compile = PR_FALSE; + if (id == sAddEventListener_id && !(flags & JSRESOLVE_ASSIGNING)) { + JSString *str = JSVAL_TO_STRING(id); + JSFunction *fnc = + ::JS_DefineFunction(cx, obj, ::JS_GetStringBytes(str), + AddEventListenerHelper, 0, JSPROP_ENUMERATE); + *objp = obj; + + return fnc ? NS_OK : NS_ERROR_UNEXPECTED; + } + + PRBool did_define = PR_FALSE; nsresult rv = RegisterCompileHandler(wrapper, cx, obj, id, PR_TRUE, PR_FALSE, - &did_compile); + &did_define); NS_ENSURE_SUCCESS(rv, rv); - if (did_compile) { + if (did_define) { *objp = obj; } @@ -5634,7 +5745,7 @@ nsEventReceiverSH::SetProperty(nsIXPConnectWrappedNative *wrapper, jsval *vp, PRBool *_retval) { if ((::JS_TypeOfValue(cx, *vp) != JSTYPE_FUNCTION && !JSVAL_IS_NULL(*vp)) || - !JSVAL_IS_STRING(id)) { + !JSVAL_IS_STRING(id) || id == sAddEventListener_id) { return NS_OK; } diff --git a/dom/src/base/nsDOMClassInfo.h b/dom/src/base/nsDOMClassInfo.h index aa644692627b..55d60bc08001 100644 --- a/dom/src/base/nsDOMClassInfo.h +++ b/dom/src/base/nsDOMClassInfo.h @@ -300,6 +300,7 @@ protected: static jsval sAdd_id; static jsval sAll_id; static jsval sTags_id; + static jsval sAddEventListener_id; static const JSClass *sObjectClass; @@ -339,10 +340,15 @@ protected: return PR_FALSE; } + static JSBool JS_DLL_CALLBACK AddEventListenerHelper(JSContext *cx, + JSObject *obj, + uintN argc, jsval *argv, + jsval *rval); + nsresult RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject *obj, jsval id, PRBool compile, PRBool remove, - PRBool *did_compile); + PRBool *did_define); public: NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 25a73ebb1840..54a932a59944 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -327,6 +327,7 @@ NS_INTERFACE_MAP_BEGIN(nsGlobalWindow) NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver) NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget) NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSEventTarget) NS_INTERFACE_MAP_ENTRY(nsPIDOMWindow) NS_INTERFACE_MAP_ENTRY(nsIDOMViewCSS) NS_INTERFACE_MAP_ENTRY(nsIDOMAbstractView) @@ -949,7 +950,7 @@ nsGlobalWindow::HandleDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, // onload event for the frame element. nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_PAGE_LOAD); + nsEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_PAGE_LOAD); // Most of the time we could get a pres context to pass in here, // but not always (i.e. if this window is not shown there won't @@ -4153,6 +4154,25 @@ nsGlobalWindow::IsRegisteredHere(const nsAString & type, PRBool *_retval) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +nsGlobalWindow::AddEventListener(const nsAString& aType, + nsIDOMEventListener *aListener, + PRBool aUseCapture, PRBool aWantsUntrusted) +{ + nsCOMPtr manager; + nsresult rv = GetListenerManager(getter_AddRefs(manager)); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE; + + if (aWantsUntrusted) { + flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED; + } + + return manager->AddEventListenerByType(aListener, aType, flags, nsnull); +} + + //***************************************************************************** // nsGlobalWindow::nsIDOMEventReceiver //***************************************************************************** @@ -4398,7 +4418,7 @@ nsGlobalWindow::Activate() nsEventStatus status; - nsGUIEvent guiEvent(NS_ACTIVATE, widget); + nsGUIEvent guiEvent(PR_TRUE, NS_ACTIVATE, widget); guiEvent.time = PR_IntervalNow(); vm->DispatchEvent(&guiEvent, &status); @@ -4426,7 +4446,7 @@ nsGlobalWindow::Deactivate() nsEventStatus status; - nsGUIEvent guiEvent(NS_DEACTIVATE, widget); + nsGUIEvent guiEvent(PR_TRUE, NS_DEACTIVATE, widget); guiEvent.time = PR_IntervalNow(); vm->DispatchEvent(&guiEvent, &status); diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index d01f7d9649b8..4eb413357a8b 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -61,6 +61,7 @@ #include "nsIDOMViewCSS.h" #include "nsIDOMEventReceiver.h" #include "nsIDOM3EventTarget.h" +#include "nsIDOMNSEventTarget.h" #include "nsIDOMNavigator.h" #include "nsIDOMNSLocation.h" #include "nsIDOMWindowInternal.h" @@ -121,6 +122,7 @@ class nsGlobalWindow : public nsIScriptGlobalObject, public nsIScriptObjectPrincipal, public nsIDOMEventReceiver, public nsIDOM3EventTarget, + public nsIDOMNSEventTarget, public nsIDOMViewCSS, public nsSupportsWeakReference, public nsIInterfaceRequestor @@ -174,6 +176,9 @@ public: // nsIDOM3EventTarget NS_DECL_NSIDOM3EVENTTARGET + // nsIDOMNSEventTarget + NS_DECL_NSIDOMNSEVENTTARGET + // nsIDOMEventReceiver NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index da2f00cbc720..9f25696b8c89 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -191,7 +191,7 @@ NS_ScriptErrorReporter(JSContext *cx, docShell->GetPresContext(getter_AddRefs(presContext)); if (presContext && errorDepth < 2) { - nsScriptErrorEvent errorevent(NS_SCRIPT_ERROR); + nsScriptErrorEvent errorevent(PR_TRUE, NS_SCRIPT_ERROR); errorevent.fileName = fileName.get(); errorevent.errorMsg = msg.get(); diff --git a/dom/src/base/nsWindowRoot.cpp b/dom/src/base/nsWindowRoot.cpp index e201c1e8e5f6..c1474d7e2f72 100644 --- a/dom/src/base/nsWindowRoot.cpp +++ b/dom/src/base/nsWindowRoot.cpp @@ -71,7 +71,13 @@ nsWindowRoot::~nsWindowRoot() { } -NS_IMPL_ISUPPORTS5(nsWindowRoot, nsIDOMEventReceiver, nsIChromeEventHandler, nsPIWindowRoot, nsIDOMEventTarget, nsIDOM3EventTarget) +NS_IMPL_ISUPPORTS6(nsWindowRoot, + nsIDOMEventReceiver, + nsIChromeEventHandler, + nsPIWindowRoot, + nsIDOMEventTarget, + nsIDOM3EventTarget, + nsIDOMNSEventTarget) NS_IMETHODIMP nsWindowRoot::AddEventListener(const nsAString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture) @@ -147,6 +153,24 @@ nsWindowRoot::IsRegisteredHere(const nsAString & type, PRBool *_retval) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +nsWindowRoot::AddEventListener(const nsAString& aType, + nsIDOMEventListener *aListener, + PRBool aUseCapture, PRBool aWantsUntrusted) +{ + nsCOMPtr manager; + nsresult rv = GetListenerManager(getter_AddRefs(manager)); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE; + + if (aWantsUntrusted) { + flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED; + } + + return manager->AddEventListenerByType(aListener, aType, flags, nsnull); +} + NS_IMETHODIMP nsWindowRoot::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID) { diff --git a/dom/src/base/nsWindowRoot.h b/dom/src/base/nsWindowRoot.h index e8c3556b3e3a..577b257f3546 100644 --- a/dom/src/base/nsWindowRoot.h +++ b/dom/src/base/nsWindowRoot.h @@ -48,13 +48,18 @@ class nsIDOMEvent; #include "nsGUIEvent.h" #include "nsIDOMEventReceiver.h" #include "nsIDOM3EventTarget.h" +#include "nsIDOMNSEventTarget.h" #include "nsIChromeEventHandler.h" #include "nsIEventListenerManager.h" #include "nsPIWindowRoot.h" #include "nsIFocusController.h" #include "nsIDOMEventTarget.h" -class nsWindowRoot : public nsIDOMEventReceiver, public nsIDOM3EventTarget, public nsIChromeEventHandler, public nsPIWindowRoot +class nsWindowRoot : public nsIDOMEventReceiver, + public nsIDOM3EventTarget, + public nsIDOMNSEventTarget, + public nsIChromeEventHandler, + public nsPIWindowRoot { public: nsWindowRoot(nsIDOMWindow* aWindow); @@ -63,6 +68,7 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIDOMEVENTTARGET NS_DECL_NSIDOM3EVENTTARGET + NS_DECL_NSIDOMNSEVENTTARGET NS_IMETHOD HandleChromeEvent(nsPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, diff --git a/extensions/xforms/nsXFormsDispatchElement.cpp b/extensions/xforms/nsXFormsDispatchElement.cpp index da97b45f0904..4be44f0598cf 100644 --- a/extensions/xforms/nsXFormsDispatchElement.cpp +++ b/extensions/xforms/nsXFormsDispatchElement.cpp @@ -107,6 +107,10 @@ nsXFormsDispatchElement::HandleAction(nsIDOMEvent* aEvent, nsCOMPtr event; docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); event->InitEvent(name, bubbles, cancelable); + + // XXX: What about uiEvent->SetTrusted(?), should these events be + // trusted or not? + nsCOMPtr targetEl = do_QueryInterface(el); if (targetEl) { PRBool defaultActionEnabled; diff --git a/extensions/xforms/nsXFormsTriggerElement.cpp b/extensions/xforms/nsXFormsTriggerElement.cpp index 023aef90bb34..c43022969fad 100644 --- a/extensions/xforms/nsXFormsTriggerElement.cpp +++ b/extensions/xforms/nsXFormsTriggerElement.cpp @@ -276,6 +276,9 @@ nsXFormsTriggerElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled) aView, 1); // Simple click + // XXX: What about uiEvent->SetTrusted(?), should these events be + // trusted or not? + PRBool cancelled; return target->DispatchEvent(uiEvent, &cancelled); } diff --git a/extensions/xforms/nsXFormsUtils.cpp b/extensions/xforms/nsXFormsUtils.cpp index 2473b8fb3482..bc87ccd8d785 100644 --- a/extensions/xforms/nsXFormsUtils.cpp +++ b/extensions/xforms/nsXFormsUtils.cpp @@ -720,6 +720,9 @@ nsXFormsUtils::DispatchEvent(nsIDOMNode* aTarget, nsXFormsEvent aEvent) event->InitEvent(NS_ConvertUTF8toUTF16(data->name), data->canBubble, data->canCancel); + // XXX: What about event->SetTrusted(?) here? Should all these + // events be trusted? Right now they're never trusted. + nsCOMPtr target = do_QueryInterface(aTarget); NS_ENSURE_STATE(target); diff --git a/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp b/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp index 248edc9c1f10..17c63dba1bab 100644 --- a/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp +++ b/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp @@ -777,6 +777,13 @@ nsXMLHttpRequest::CreateEvent(nsEvent* aEvent, nsIDOMEvent** aDOMEvent) privevent->SetCurrentTarget(this); privevent->SetOriginalTarget(this); + // We're not marking these events trusted as there is no way for us + // to tell if we're called through the code that normally calls us + // (i.e. necko) or if script on a webpage QI'd this object to say, + // nsIProgressEventSink and called onProgress(...). + // + // privevent->SetTrusted(?); + return NS_OK; } @@ -1339,7 +1346,7 @@ nsXMLHttpRequest::RequestCompleted() } // We need to create the event before nulling out mDocument - nsEvent evt(NS_PAGE_LOAD); + nsEvent evt(PR_TRUE, NS_PAGE_LOAD); nsCOMPtr domevent; rv = CreateEvent(&evt, getter_AddRefs(domevent)); @@ -1711,7 +1718,7 @@ nsXMLHttpRequest::Error(nsIDOMEvent* aEvent) // We need to create the event before nulling out mDocument nsCOMPtr event(do_QueryInterface(aEvent)); // There is no NS_PAGE_ERROR event but NS_SCRIPT_ERROR should be ok. - nsEvent evt(NS_SCRIPT_ERROR); + nsEvent evt(PR_TRUE, NS_SCRIPT_ERROR); if (!event) { CreateEvent(&evt, getter_AddRefs(event)); } @@ -1836,7 +1843,7 @@ nsXMLHttpRequest::OnProgress(nsIRequest *aRequest, nsISupports *aContext, PRUint if (mOnProgressListener) { nsCOMPtr event; - nsEvent evt(NS_EVENT_NULL ); // what name do we make up here? + nsEvent evt(PR_TRUE, NS_EVENT_NULL); // what name do we make up here? nsresult rv = CreateEvent(&evt, getter_AddRefs(event)); NS_ENSURE_SUCCESS(rv, rv); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 13b493cd292e..2f449032dc68 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -981,7 +981,7 @@ DocumentViewerImpl::LoadComplete(nsresult aStatus) // Now, fire either an OnLoad or OnError event to the document... if(NS_SUCCEEDED(aStatus)) { nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_PAGE_LOAD); + nsEvent event(PR_TRUE, NS_PAGE_LOAD); rv = global->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); @@ -1060,7 +1060,7 @@ DocumentViewerImpl::PermitUnload(PRBool *aPermitUnload) // Now, fire an BeforeUnload event to the document and see if it's ok // to unload... nsEventStatus status = nsEventStatus_eIgnore; - nsBeforePageUnloadEvent event(NS_BEFORE_PAGE_UNLOAD); + nsBeforePageUnloadEvent event(PR_TRUE, NS_BEFORE_PAGE_UNLOAD); nsresult rv = NS_OK; { @@ -1160,7 +1160,7 @@ DocumentViewerImpl::Unload() // Now, fire an Unload event to the document... nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_PAGE_UNLOAD); + nsEvent event(PR_TRUE, NS_PAGE_UNLOAD); // Never permit popups from the unload handler, no matter how we get // here. diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index fad2e95ca04f..4908930e19f1 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -3079,7 +3079,7 @@ PresShell::FireResizeEvent() return; //Send resize event from here. - nsEvent event(NS_RESIZE_EVENT); + nsEvent event(PR_TRUE, NS_RESIZE_EVENT); nsEventStatus status = nsEventStatus_eIgnore; nsCOMPtr globalObj = mDocument->GetScriptGlobalObject(); diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index f75d47d138aa..9284b74e024a 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -590,7 +590,9 @@ nsComboboxControlFrame::ShowPopup(PRBool aShowPopup) // fire a popup dom event nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(aShowPopup ? NS_XUL_POPUP_SHOWING : NS_XUL_POPUP_HIDING); + nsMouseEvent event(PR_TRUE, aShowPopup ? + NS_XUL_POPUP_SHOWING : NS_XUL_POPUP_HIDING, nsnull, + nsMouseEvent::eReal); nsIPresShell *shell = mPresContext->GetPresShell(); if (shell) @@ -637,16 +639,6 @@ nsComboboxControlFrame::ShowList(nsPresContext* aPresContext, PRBool aShowList) } - -//------------------------------------------------------------- -// this is in response to the MouseClick from the containing browse button -// XXX: TODO still need to get filters from accept attribute -void -nsComboboxControlFrame::MouseClicked(nsPresContext* aPresContext) -{ - //ToggleList(aPresContext); -} - nsresult nsComboboxControlFrame::ReflowComboChildFrame(nsIFrame* aFrame, nsPresContext* aPresContext, @@ -2490,6 +2482,10 @@ void nsComboboxControlFrame::FireValueChangeEvent() if (manager && NS_SUCCEEDED(manager->CreateEvent(presContext, nsnull, NS_LITERAL_STRING("Events"), getter_AddRefs(event)))) { event->InitEvent(NS_LITERAL_STRING("ValueChange"), PR_TRUE, PR_TRUE); + + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + PRBool defaultActionEnabled; presContext->EventStateManager()->DispatchNewEvent(mContent, event, &defaultActionEnabled); diff --git a/layout/forms/nsComboboxControlFrame.h b/layout/forms/nsComboboxControlFrame.h index f9fc2f9fc8e2..e564311b5067 100644 --- a/layout/forms/nsComboboxControlFrame.h +++ b/layout/forms/nsComboboxControlFrame.h @@ -163,9 +163,6 @@ public: nscoord aInnerWidth, nscoord aCharWidth) const; - // nsIFormMouseListener - virtual void MouseClicked(nsPresContext* aPresContext); - //nsIComboboxControlFrame NS_IMETHOD IsDroppedDown(PRBool * aDoDropDown) { *aDoDropDown = mDroppedDown; return NS_OK; } NS_IMETHOD ShowDropDown(PRBool aDoDropDown); diff --git a/layout/forms/nsFileControlFrame.h b/layout/forms/nsFileControlFrame.h index b9d7a37fada6..1532c2e09d51 100644 --- a/layout/forms/nsFileControlFrame.h +++ b/layout/forms/nsFileControlFrame.h @@ -69,8 +69,6 @@ public: return nsAreaFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); } - virtual void MouseClicked(nsPresContext* aPresContext) {} - NS_IMETHOD Paint(nsPresContext* aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect, diff --git a/layout/forms/nsFormControlFrame.cpp b/layout/forms/nsFormControlFrame.cpp index a3957c59dac5..81824fea35d4 100644 --- a/layout/forms/nsFormControlFrame.cpp +++ b/layout/forms/nsFormControlFrame.cpp @@ -697,19 +697,12 @@ nsFormControlFrame::HandleEvent(nsPresContext* aPresContext, // unfortunately native widgets don't seem to handle this right. // so use the old code for native stuff. -EDV switch (aEvent->message) { - case NS_MOUSE_LEFT_CLICK: - MouseClicked(aPresContext); - break; - case NS_KEY_DOWN: if (NS_KEY_EVENT == aEvent->eventStructType) { nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; if (NS_VK_RETURN == keyEvent->keyCode) { EnterPressed(aPresContext); } - //else if (NS_VK_SPACE == keyEvent->keyCode) { - // MouseClicked(aPresContext); - //} } break; } diff --git a/layout/forms/nsFormControlFrame.h b/layout/forms/nsFormControlFrame.h index 6b390d96c644..a7c09b510380 100644 --- a/layout/forms/nsFormControlFrame.h +++ b/layout/forms/nsFormControlFrame.h @@ -160,11 +160,6 @@ public: */ virtual void EnterPressed(nsPresContext* aPresContext) {} - /** - * Respond to a mouse click (e.g. mouse enter, mouse down, mouse up) - */ - virtual void MouseClicked(nsPresContext* aPresContext) {} - /** * Respond to a control change (e.g. combo box close-up) */ diff --git a/layout/forms/nsGfxButtonControlFrame.cpp b/layout/forms/nsGfxButtonControlFrame.cpp index 05734c45fcd4..941a5bf0b6e4 100644 --- a/layout/forms/nsGfxButtonControlFrame.cpp +++ b/layout/forms/nsGfxButtonControlFrame.cpp @@ -384,9 +384,6 @@ nsGfxButtonControlFrame::HandleEvent(nsPresContext* aPresContext, // Override the HandleEvent to prevent the nsFrame::HandleEvent // from being called. The nsFrame::HandleEvent causes the button label // to be selected (Drawn with an XOR rectangle over the label) - - // Do nothing here, nsHTMLInputElement::HandleDOMEvent - // takes cares of calling MouseClicked for us. // do we have user-input style? const nsStyleUserInterface* uiStyle = GetStyleUserInterface(); diff --git a/layout/forms/nsHTMLButtonControlFrame.cpp b/layout/forms/nsHTMLButtonControlFrame.cpp index 4bab1ebced6c..c90bb77138c2 100644 --- a/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/layout/forms/nsHTMLButtonControlFrame.cpp @@ -244,14 +244,6 @@ nsHTMLButtonControlFrame::IsSubmit(PRInt32 type) } } - -void -nsHTMLButtonControlFrame::MouseClicked(nsPresContext* aPresContext) -{ -// This is no longer called; click events are handled in -// nsHTMLInputElement::HandleDOMEvent(). -} - void nsHTMLButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint) { diff --git a/layout/forms/nsHTMLButtonControlFrame.h b/layout/forms/nsHTMLButtonControlFrame.h index 8088f875c662..294f1d688ebb 100644 --- a/layout/forms/nsHTMLButtonControlFrame.h +++ b/layout/forms/nsHTMLButtonControlFrame.h @@ -128,7 +128,6 @@ public: NS_IMETHOD_(PRInt32) GetFormControlType() const; NS_IMETHOD GetName(nsAString* aName); NS_IMETHOD GetValue(nsAString* aName); - virtual void MouseClicked(nsPresContext* aPresContext); NS_IMETHOD OnContentReset(); void SetFocus(PRBool aOn, PRBool aRepaint); diff --git a/layout/forms/nsIFormControlFrame.h b/layout/forms/nsIFormControlFrame.h index ca9822bf430b..990dd3c72aee 100644 --- a/layout/forms/nsIFormControlFrame.h +++ b/layout/forms/nsIFormControlFrame.h @@ -69,8 +69,6 @@ public: virtual void ScrollIntoView(nsPresContext* aPresContext) = 0; - virtual void MouseClicked(nsPresContext* aPresContext) = 0; - /** * Set the suggested size for the form element. * This is used to control the size of the element during reflow if it hasn't had it's size diff --git a/layout/forms/nsImageControlFrame.cpp b/layout/forms/nsImageControlFrame.cpp index ccd2f16880dd..99faee0d7aef 100644 --- a/layout/forms/nsImageControlFrame.cpp +++ b/layout/forms/nsImageControlFrame.cpp @@ -98,8 +98,6 @@ public: NS_IMETHOD GetCursor(const nsPoint& aPoint, nsIFrame::Cursor& aCursor); - virtual void MouseClicked(nsPresContext* aPresContext); - NS_IMETHOD_(PRInt32) GetFormControlType() const; NS_IMETHOD GetName(nsAString* aName); @@ -317,13 +315,6 @@ nsImageControlFrame::GetCursor(const nsPoint& aPoint, return NS_OK; } -void -nsImageControlFrame::MouseClicked(nsPresContext* aPresContext) -{ -// This is no longer called; click events are handled in -// nsHTMLInputElement::HandleDOMEvent(). -} - NS_IMETHODIMP nsImageControlFrame::GetFormContent(nsIContent*& aContent) const { diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 47b3855c8226..3d131a67930d 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -1748,14 +1748,6 @@ nsListControlFrame::GetFormControlType() const return NS_FORM_SELECT; } - -//--------------------------------------------------------- -void -nsListControlFrame::MouseClicked(nsPresContext* aPresContext) -{ -} - - NS_IMETHODIMP nsListControlFrame::OnContentReset() { @@ -2153,7 +2145,7 @@ nsListControlFrame::FireOnChange() // Dispatch the NS_FORM_CHANGE event nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_FORM_CHANGE); + nsEvent event(PR_TRUE, NS_FORM_CHANGE); nsIPresShell *presShell = GetPresContext()->GetPresShell(); if (presShell) { @@ -2561,6 +2553,10 @@ nsListControlFrame::FireMenuItemActiveEvent() if (manager && NS_SUCCEEDED(manager->CreateEvent(presContext, nsnull, NS_LITERAL_STRING("Events"), getter_AddRefs(event)))) { event->InitEvent(NS_LITERAL_STRING("DOMMenuItemActive"), PR_TRUE, PR_TRUE); + + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + PRBool defaultActionEnabled; presContext->EventStateManager()->DispatchNewEvent(optionContent, event, &defaultActionEnabled); diff --git a/layout/forms/nsListControlFrame.h b/layout/forms/nsListControlFrame.h index 234a96f77b97..e57ab031c275 100644 --- a/layout/forms/nsListControlFrame.h +++ b/layout/forms/nsListControlFrame.h @@ -139,7 +139,6 @@ public: virtual void SetFocus(PRBool aOn = PR_TRUE, PRBool aRepaint = PR_FALSE); virtual void ScrollIntoView(nsPresContext* aPresContext); - virtual void MouseClicked(nsPresContext* aPresContext); virtual nscoord GetVerticalInsidePadding(nsPresContext* aPresContext, float aPixToTwip, nscoord aInnerHeight) const; diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 3aba126bd941..f779a768fa22 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -278,7 +278,7 @@ nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsISelection* if (presShell) { nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_FORM_SELECTED); + nsEvent event(PR_TRUE, NS_FORM_SELECTED); presShell->HandleEventWithTarget(&event,mFrame,content,NS_EVENT_FLAG_INIT,&status); } @@ -2275,8 +2275,6 @@ void nsTextControlFrame::ScrollIntoView(nsPresContext* aPresContext) } } -void nsTextControlFrame::MouseClicked(nsPresContext* aPresContext){} - nscoord nsTextControlFrame::GetVerticalInsidePadding(nsPresContext* aPresContext, float aPixToTwip, @@ -2943,7 +2941,7 @@ nsTextControlFrame::FireOnInput() // Dispatch the "input" event nsEventStatus status = nsEventStatus_eIgnore; - nsGUIEvent event(NS_FORM_INPUT); + nsGUIEvent event(PR_TRUE, NS_FORM_INPUT, nsnull); // Have the content handle the event, propagating it according to normal // DOM rules. @@ -2985,7 +2983,7 @@ nsTextControlFrame::FireOnChange() if (NS_SUCCEEDED(GetFormContent(*getter_AddRefs(content)))) { nsEventStatus status = nsEventStatus_eIgnore; - nsInputEvent event(NS_FORM_CHANGE); + nsInputEvent event(PR_TRUE, NS_FORM_CHANGE, nsnull); // Have the content handle the event. nsWeakPtr &shell = mTextSelImpl->GetPresShell(); diff --git a/layout/forms/nsTextControlFrame.h b/layout/forms/nsTextControlFrame.h index 7ef757dcccfb..4c66c7c1e7ff 100644 --- a/layout/forms/nsTextControlFrame.h +++ b/layout/forms/nsTextControlFrame.h @@ -132,7 +132,6 @@ public: NS_IMETHOD GetName(nsAString* aName);//* virtual void SetFocus(PRBool aOn , PRBool aRepaint); virtual void ScrollIntoView(nsPresContext* aPresContext); - virtual void MouseClicked(nsPresContext* aPresContext); virtual nscoord GetVerticalInsidePadding(nsPresContext* aPresContext, float aPixToTwip, nscoord aInnerHeight) const; diff --git a/layout/generic/nsFrameSetFrame.h b/layout/generic/nsFrameSetFrame.h index d42a3bea3f99..a765bdf8856b 100644 --- a/layout/generic/nsFrameSetFrame.h +++ b/layout/generic/nsFrameSetFrame.h @@ -53,7 +53,7 @@ struct nsHTMLReflowState; struct nsSize; class nsIAtom; class nsHTMLFramesetBorderFrame; -struct nsGUIEvent; +class nsGUIEvent; class nsHTMLFramesetFrame; #define NS_IFRAMESETFRAME_IID \ diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 12ce7ed2f567..628c28d5e8b1 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1463,9 +1463,10 @@ nsGfxScrollFrameInner::ScrollToRestoredPosition() void nsGfxScrollFrameInner::PostScrollPortEvent(PRBool aOverflow, nsScrollPortEvent::orientType aType) { - nsScrollPortEvent* event = new nsScrollPortEvent(aOverflow ? + nsScrollPortEvent* event = new nsScrollPortEvent(PR_TRUE, aOverflow ? NS_SCROLLPORT_OVERFLOW : - NS_SCROLLPORT_UNDERFLOW); + NS_SCROLLPORT_UNDERFLOW, + nsnull); event->orient = aType; mOuter->GetPresContext()->PresShell()->PostDOMEvent(mOuter->GetContent(), event); } @@ -1713,7 +1714,7 @@ void nsGfxScrollFrameInner::CurPosAttributeChanged(nsIContent* aContent, PRInt32 // Fire the onScroll event now that we have scrolled nsIPresShell *presShell = mOuter->GetPresContext()->GetPresShell(); if (presShell) { - nsScrollbarEvent event(NS_SCROLL_EVENT); + nsScrollbarEvent event(PR_TRUE, NS_SCROLL_EVENT, nsnull); nsEventStatus status = nsEventStatus_eIgnore; // note if hcontent is non-null then hframe must be non-null. // likewise for vcontent and vframe. Thus targetFrame will always diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index 2b3f979830dc..29635ef51674 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -600,6 +600,9 @@ FirePluginNotFoundEvent(nsIContent *aTarget) rv = event->InitEvent(NS_LITERAL_STRING("PluginNotFound"), PR_TRUE, PR_TRUE); if (NS_SUCCEEDED(rv)) { + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + PRBool defaultActionEnabled; target->DispatchEvent(event, &defaultActionEnabled); } @@ -3504,7 +3507,9 @@ nsresult nsPluginInstanceOwner::DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent) nsEvent * theEvent; privateEvent->GetInternalNSEvent(&theEvent); if (theEvent) { - nsGUIEvent focusEvent(theEvent->message); // we only care about the message in ProcessEvent + // we only care about the message in ProcessEvent + nsGUIEvent focusEvent(NS_IS_TRUSTED_EVENT(theEvent), theEvent->message, + nsnull); nsEventStatus rv = ProcessEvent(focusEvent); if (nsEventStatus_eConsumeNoDefault == rv) { aFocusEvent->PreventDefault(); diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 0255992b1c9c..7736938acf2b 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -890,6 +890,7 @@ nsSelectionIterator::IsDone() ////////////BEGIN nsSelection methods nsSelection::nsSelection() + : mDelayedMouseEvent(PR_FALSE, 0, nsnull, nsMouseEvent::eReal) { PRInt32 i; for (i = 0;i parent; nsCOMPtr parentContent; - nsMouseEvent event; + nsMouseEvent event(PR_FALSE, 0, nsnull, nsMouseEvent::eReal); nsresult result; // Start selecting in the cell we were in before diff --git a/layout/xul/base/src/nsBoxFrame.cpp b/layout/xul/base/src/nsBoxFrame.cpp index 5610d766071d..83a86224780a 100644 --- a/layout/xul/base/src/nsBoxFrame.cpp +++ b/layout/xul/base/src/nsBoxFrame.cpp @@ -100,6 +100,7 @@ #include "nsIEventListenerManager.h" #include "nsIEventStateManager.h" #include "nsIDOMEvent.h" +#include "nsIPrivateDOMEvent.h" #include "nsContentUtils.h" // Needed for Print Preview @@ -2573,6 +2574,10 @@ nsBoxFrame::FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent) NS_LITERAL_STRING("Events"), getter_AddRefs(event)))) { event->InitEvent(aDOMEventName, PR_TRUE, PR_TRUE); + + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + PRBool defaultActionEnabled; mPresContext->EventStateManager()-> DispatchNewEvent(content, event, &defaultActionEnabled); diff --git a/layout/xul/base/src/nsButtonBoxFrame.cpp b/layout/xul/base/src/nsButtonBoxFrame.cpp index 8f0bbeb6392c..ed6546b227b9 100644 --- a/layout/xul/base/src/nsButtonBoxFrame.cpp +++ b/layout/xul/base/src/nsButtonBoxFrame.cpp @@ -150,7 +150,7 @@ nsButtonBoxFrame::HandleEvent(nsPresContext* aPresContext, } void -nsButtonBoxFrame::MouseClicked (nsPresContext* aPresContext, nsGUIEvent* aEvent) +nsButtonBoxFrame::MouseClicked(nsPresContext* aPresContext, nsGUIEvent* aEvent) { // Don't execute if we're disabled. nsAutoString disabled; @@ -160,7 +160,8 @@ nsButtonBoxFrame::MouseClicked (nsPresContext* aPresContext, nsGUIEvent* aEvent) // Execute the oncommand event handler. nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_COMMAND); + nsMouseEvent event(aEvent ? NS_IS_TRUSTED_EVENT(aEvent) : PR_FALSE, + NS_XUL_COMMAND, nsnull, nsMouseEvent::eReal); if(aEvent) { event.isShift = ((nsInputEvent*)(aEvent))->isShift; event.isControl = ((nsInputEvent*)(aEvent))->isControl; diff --git a/layout/xul/base/src/nsImageBoxFrame.cpp b/layout/xul/base/src/nsImageBoxFrame.cpp index 28eff46ec322..9462a7f3649d 100644 --- a/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/layout/xul/base/src/nsImageBoxFrame.cpp @@ -122,7 +122,7 @@ HandleImagePLEvent(nsIContent *aContent, PRUint32 aMessage, PRUint32 aFlags) } nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(aMessage); + nsEvent event(PR_TRUE, aMessage); aContent->HandleDOMEvent(pres_context, &event, nsnull, aFlags, &status); } diff --git a/layout/xul/base/src/nsMenuFrame.cpp b/layout/xul/base/src/nsMenuFrame.cpp index 6340029f5969..263cf8008a20 100644 --- a/layout/xul/base/src/nsMenuFrame.cpp +++ b/layout/xul/base/src/nsMenuFrame.cpp @@ -1606,7 +1606,12 @@ nsMenuFrame::Execute(nsGUIEvent *aEvent) nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_COMMAND); + // Create a trusted event if the triggering event was trusted, or if + // we're called from chrome code (since at least one of our caller + // passes in a null event). + nsMouseEvent event(aEvent ? NS_IS_TRUSTED_EVENT(aEvent) : + nsContentUtils::IsCallerChrome(), NS_XUL_COMMAND, nsnull, + nsMouseEvent::eReal); if (aEvent && (aEvent->eventStructType == NS_MOUSE_EVENT || aEvent->eventStructType == NS_KEY_EVENT || aEvent->eventStructType == NS_ACCESSIBLE_EVENT)) { @@ -1651,8 +1656,9 @@ PRBool nsMenuFrame::OnCreate() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWING); - + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull, + nsMouseEvent::eReal); + nsCOMPtr child; GetMenuChildrenElement(getter_AddRefs(child)); @@ -1740,8 +1746,9 @@ PRBool nsMenuFrame::OnCreated() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWN); - + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWN, nsnull, + nsMouseEvent::eReal); + nsCOMPtr child; GetMenuChildrenElement(getter_AddRefs(child)); @@ -1766,8 +1773,9 @@ PRBool nsMenuFrame::OnDestroy() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_HIDING); - + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDING, nsnull, + nsMouseEvent::eReal); + nsCOMPtr child; GetMenuChildrenElement(getter_AddRefs(child)); @@ -1792,8 +1800,9 @@ PRBool nsMenuFrame::OnDestroyed() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_HIDDEN); - + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDDEN, nsnull, + nsMouseEvent::eReal); + nsCOMPtr child; GetMenuChildrenElement(getter_AddRefs(child)); diff --git a/layout/xul/base/src/nsPopupSetFrame.cpp b/layout/xul/base/src/nsPopupSetFrame.cpp index 170a424a5f67..e2710350c216 100644 --- a/layout/xul/base/src/nsPopupSetFrame.cpp +++ b/layout/xul/base/src/nsPopupSetFrame.cpp @@ -583,7 +583,8 @@ PRBool nsPopupSetFrame::OnCreate(PRInt32 aX, PRInt32 aY, nsIContent* aPopupContent) { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWING); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull, + nsMouseEvent::eReal); event.point.x = aX; event.point.y = aY; @@ -660,7 +661,8 @@ PRBool nsPopupSetFrame::OnCreated(PRInt32 aX, PRInt32 aY, nsIContent* aPopupContent) { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWN); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWN, nsnull, + nsMouseEvent::eReal); event.point.x = aX; event.point.y = aY; @@ -682,8 +684,9 @@ PRBool nsPopupSetFrame::OnDestroy(nsIContent* aPopupContent) { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_HIDING); - + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDING, nsnull, + nsMouseEvent::eReal); + if (aPopupContent) { nsIPresShell *shell = mPresContext->GetPresShell(); if (shell) { @@ -701,7 +704,8 @@ PRBool nsPopupSetFrame::OnDestroyed(nsIContent* aPopupContent) { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_HIDDEN); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDDEN, nsnull, + nsMouseEvent::eReal); if (aPopupContent) { nsIPresShell *shell = mPresContext->GetPresShell(); diff --git a/layout/xul/base/src/nsResizerFrame.cpp b/layout/xul/base/src/nsResizerFrame.cpp index 4e3071d0408e..2704e04dca0a 100644 --- a/layout/xul/base/src/nsResizerFrame.cpp +++ b/layout/xul/base/src/nsResizerFrame.cpp @@ -245,7 +245,7 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, case NS_MOUSE_LEFT_CLICK: - MouseClicked(aPresContext); + MouseClicked(aPresContext, aEvent); break; } @@ -349,10 +349,14 @@ nsResizerFrame::AttributeChanged(nsIContent* aChild, void -nsResizerFrame::MouseClicked (nsPresContext* aPresContext) +nsResizerFrame::MouseClicked(nsPresContext* aPresContext, nsGUIEvent *aEvent) { // Execute the oncommand event handler. nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_COMMAND); - mContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + + nsMouseEvent event(aEvent ? NS_IS_TRUSTED_EVENT(aEvent) : PR_FALSE, + NS_XUL_COMMAND, nsnull, nsMouseEvent::eReal); + + mContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, + &status); } diff --git a/layout/xul/base/src/nsResizerFrame.h b/layout/xul/base/src/nsResizerFrame.h index eace46c3df40..0e2c30f212b4 100644 --- a/layout/xul/base/src/nsResizerFrame.h +++ b/layout/xul/base/src/nsResizerFrame.h @@ -77,7 +77,7 @@ public: nsIAtom* aAttribute, PRInt32 aModType); - virtual void MouseClicked (nsPresContext* aPresContext); + virtual void MouseClicked(nsPresContext* aPresContext, nsGUIEvent *aEvent); protected: PRBool GetInitialDirection(eDirection& aDirection); diff --git a/layout/xul/base/src/nsScrollbarButtonFrame.cpp b/layout/xul/base/src/nsScrollbarButtonFrame.cpp index d831cfc9f13c..18470ec19a42 100644 --- a/layout/xul/base/src/nsScrollbarButtonFrame.cpp +++ b/layout/xul/base/src/nsScrollbarButtonFrame.cpp @@ -99,8 +99,8 @@ nsScrollbarButtonFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_IMETHODIMP nsScrollbarButtonFrame::HandleEvent(nsPresContext* aPresContext, - nsGUIEvent* aEvent, - nsEventStatus* aEventStatus) + nsGUIEvent* aEvent, + nsEventStatus* aEventStatus) { // XXX hack until handle release is actually called in nsframe. if (aEvent->message == NS_MOUSE_EXIT_SYNTH|| aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP || aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) @@ -112,8 +112,8 @@ nsScrollbarButtonFrame::HandleEvent(nsPresContext* aPresContext, NS_IMETHODIMP nsScrollbarButtonFrame::HandlePress(nsPresContext* aPresContext, - nsGUIEvent* aEvent, - nsEventStatus* aEventStatus) + nsGUIEvent* aEvent, + nsEventStatus* aEventStatus) { MouseClicked(); nsRepeatService::GetInstance()->Start(this); @@ -122,8 +122,8 @@ nsScrollbarButtonFrame::HandlePress(nsPresContext* aPresContext, NS_IMETHODIMP nsScrollbarButtonFrame::HandleRelease(nsPresContext* aPresContext, - nsGUIEvent* aEvent, - nsEventStatus* aEventStatus) + nsGUIEvent* aEvent, + nsEventStatus* aEventStatus) { nsRepeatService::GetInstance()->Stop(); return NS_OK; diff --git a/layout/xul/base/src/nsTitleBarFrame.cpp b/layout/xul/base/src/nsTitleBarFrame.cpp index c73fc4f17cb3..aac390a39cf4 100644 --- a/layout/xul/base/src/nsTitleBarFrame.cpp +++ b/layout/xul/base/src/nsTitleBarFrame.cpp @@ -189,7 +189,7 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, case NS_MOUSE_LEFT_CLICK: - MouseClicked(aPresContext); + MouseClicked(aPresContext, aEvent); break; } @@ -229,10 +229,14 @@ nsTitleBarFrame::CaptureMouseEvents(nsPresContext* aPresContext,PRBool aGrabMous void -nsTitleBarFrame::MouseClicked (nsPresContext* aPresContext) +nsTitleBarFrame::MouseClicked(nsPresContext* aPresContext, nsGUIEvent* aEvent) { // Execute the oncommand event handler. nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_COMMAND); - mContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); + + nsMouseEvent event(aEvent ? NS_IS_TRUSTED_EVENT(aEvent) : PR_FALSE, + NS_XUL_COMMAND, nsnull, nsMouseEvent::eReal); + + mContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, + &status); } diff --git a/layout/xul/base/src/nsTitleBarFrame.h b/layout/xul/base/src/nsTitleBarFrame.h index 21f1694bf8c5..5d175f79685a 100644 --- a/layout/xul/base/src/nsTitleBarFrame.h +++ b/layout/xul/base/src/nsTitleBarFrame.h @@ -64,7 +64,7 @@ public: NS_IMETHOD GetMouseThrough(PRBool& aMouseThrough); - virtual void MouseClicked (nsPresContext* aPresContext); + virtual void MouseClicked(nsPresContext* aPresContext, nsGUIEvent* aEvent); protected: diff --git a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 8f75d4441763..08951c835c9c 100644 --- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -775,8 +775,8 @@ nsTreeBodyFrame::CheckVerticalOverflow() } if (verticalOverflowChanged) { - nsScrollPortEvent event(mVerticalOverflow ? NS_SCROLLPORT_OVERFLOW - : NS_SCROLLPORT_UNDERFLOW); + nsScrollPortEvent event(PR_TRUE, mVerticalOverflow ? NS_SCROLLPORT_OVERFLOW + : NS_SCROLLPORT_UNDERFLOW, nsnull); event.orient = nsScrollPortEvent::vertical; nsEventStatus status = nsEventStatus_eIgnore; diff --git a/layout/xul/base/src/tree/src/nsTreeSelection.cpp b/layout/xul/base/src/tree/src/nsTreeSelection.cpp index f99e57b8b276..efe1c872b073 100644 --- a/layout/xul/base/src/tree/src/nsTreeSelection.cpp +++ b/layout/xul/base/src/tree/src/nsTreeSelection.cpp @@ -753,7 +753,7 @@ nsTreeSelection::FireOnSelectHandler() nsCOMPtr aPresContext = shell->GetPresContext(); nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event(NS_FORM_SELECTED); + nsEvent event(PR_TRUE, NS_FORM_SELECTED); content->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); diff --git a/toolkit/components/satchel/src/nsFormFillController.cpp b/toolkit/components/satchel/src/nsFormFillController.cpp index 342f38af955a..08baa0107364 100644 --- a/toolkit/components/satchel/src/nsFormFillController.cpp +++ b/toolkit/components/satchel/src/nsFormFillController.cpp @@ -53,6 +53,7 @@ #include "nsIContentViewer.h" #include "nsIDOMEventTarget.h" #include "nsIDOMKeyEvent.h" +#include "nsIPrivateDOMEvent.h" #include "nsIDOMCompositionListener.h" #include "nsIDOMDocument.h" #include "nsIDOMElement.h" @@ -453,6 +454,15 @@ nsFormFillController::OnTextEntered(PRBool *_retval) } event->InitEvent(NS_LITERAL_STRING("DOMAutoComplete"), PR_TRUE, PR_TRUE); + + nsCOMPtr privateEvent(do_QueryInterface(event)); + if (privateEvent) { + // XXXjst: We mark this event as a trusted event, it's up to the + // callers of this to ensure that it's only called from trusted + // code. + privateEvent->SetTrusted(PR_TRUE); + } + nsCOMPtr targ = do_QueryInterface(mFocusedInput); PRBool defaultActionEnabled; diff --git a/view/public/nsIViewObserver.h b/view/public/nsIViewObserver.h index ba5604842cd9..3dab113de75b 100644 --- a/view/public/nsIViewObserver.h +++ b/view/public/nsIViewObserver.h @@ -43,7 +43,7 @@ class nsIRenderingContext; struct nsRect; -struct nsGUIEvent; +class nsGUIEvent; #define NS_IVIEWOBSERVER_IID \ { 0x0f4bc34a, 0xc93b, 0x4699, \ diff --git a/view/src/nsViewManager.cpp b/view/src/nsViewManager.cpp index 5ed3dfee0f1e..927b84f83214 100644 --- a/view/src/nsViewManager.cpp +++ b/view/src/nsViewManager.cpp @@ -1915,11 +1915,6 @@ NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus *aS { *aStatus = nsEventStatus_eIgnore; - // Mark all events coming through here as trusted events, as the - // only code that calls this is the widget code that translates OS - // events into mozilla events. - aEvent->internalAppFlags |= NS_APP_EVENT_FLAG_TRUSTED; - switch(aEvent->message) { case NS_SIZE: @@ -4424,7 +4419,7 @@ nsViewManager::ProcessSynthMouseMoveEvent(PRBool aFromScroll) this, mMouseLocation.x, mMouseLocation.y); #endif - nsMouseEvent event(NS_MOUSE_MOVE, mRootView->GetWidget(), + nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, mRootView->GetWidget(), nsMouseEvent::eSynthesized); event.point = mMouseLocation; event.time = PR_IntervalNow(); diff --git a/webshell/public/nsILinkHandler.h b/webshell/public/nsILinkHandler.h index c94448c3defa..dc2d51d1e076 100644 --- a/webshell/public/nsILinkHandler.h +++ b/webshell/public/nsILinkHandler.h @@ -44,7 +44,7 @@ class nsIDocShell; class nsIRequest; class nsIContent; class nsString; -struct nsGUIEvent; +class nsGUIEvent; // Interface ID for nsILinkHandler #define NS_ILINKHANDLER_IID \ diff --git a/widget/public/nsEvent.h b/widget/public/nsEvent.h index 9e80c7409825..67e1ae479470 100644 --- a/widget/public/nsEvent.h +++ b/widget/public/nsEvent.h @@ -57,25 +57,25 @@ enum nsEventStatus { nsEventStatus_eConsumeDoDefault }; -struct nsEvent; +class nsEvent; -struct nsGUIEvent; -struct nsSizeEvent; -struct nsSizeModeEvent; -struct nsZLevelEvent; -struct nsPaintEvent; -struct nsScrollbarEvent; -struct nsScrollPortEvent; -struct nsInputEvent; -struct nsMouseEvent; -struct nsAccessibleEvent; -struct nsKeyEvent; -struct nsTextEvent; -struct nsCompositionEvent; -struct nsMouseScrollEvent; -struct nsReconversionEvent; -struct nsTooltipEvent; -struct nsMenuEvent; +class nsGUIEvent; +class nsSizeEvent; +class nsSizeModeEvent; +class nsZLevelEvent; +class nsPaintEvent; +class nsScrollbarEvent; +class nsScrollPortEvent; +class nsInputEvent; +class nsMouseEvent; +class nsAccessibleEvent; +class nsKeyEvent; +class nsTextEvent; +class nsCompositionEvent; +class nsMouseScrollEvent; +class nsReconversionEvent; +class nsTooltipEvent; +class nsMenuEvent; struct nsTextEventReply; struct nsReconversionEventReply; diff --git a/widget/public/nsGUIEvent.h b/widget/public/nsGUIEvent.h index 5fac6630aeaf..4149db29ac4a 100644 --- a/widget/public/nsGUIEvent.h +++ b/widget/public/nsGUIEvent.h @@ -105,6 +105,7 @@ class nsIURI; #define NS_EVENT_FLAG_NO_CONTENT_DISPATCH 0x0100 #define NS_EVENT_FLAG_SYSTEM_EVENT 0x0200 #define NS_EVENT_FLAG_STOP_DISPATCH_IMMEDIATELY 0x0400 // @see nsIDOM3Event::stopImmediatePropagation() +#define NS_PRIV_EVENT_UNTRUSTED_PERMITTED 0x0800 #define NS_EVENT_CAPTURE_MASK (~(NS_EVENT_FLAG_INIT | NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) #define NS_EVENT_BUBBLE_MASK (~(NS_EVENT_FLAG_INIT | NS_EVENT_FLAG_CAPTURE | NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) @@ -349,34 +350,54 @@ enum nsWindowZ { * General event */ -struct nsEvent { - nsEvent(PRUint32 msg = 0, PRUint8 structType = NS_EVENT) +class nsEvent +{ +protected: + nsEvent(PRBool isTrusted, PRUint32 msg, PRUint8 structType) : eventStructType(structType), message(msg), point(0, 0), refPoint(0, 0), time(0), flags(0), - internalAppFlags(NS_APP_EVENT_FLAG_NONE), + internalAppFlags(isTrusted ? NS_APP_EVENT_FLAG_TRUSTED : + NS_APP_EVENT_FLAG_NONE), userType(0) { } - /// See event struct types +public: + nsEvent(PRBool isTrusted, PRUint32 msg) + : eventStructType(NS_EVENT), + message(msg), + point(0, 0), + refPoint(0, 0), + time(0), + flags(0), + internalAppFlags(isTrusted ? NS_APP_EVENT_FLAG_TRUSTED : + NS_APP_EVENT_FLAG_NONE), + userType(0) + { + } + + // See event struct types PRUint8 eventStructType; - /// See GUI MESSAGES, + // See GUI MESSAGES, PRUint32 message; - /// in widget relative coordinates, modified to be relative to current view in layout. + // In widget relative coordinates, modified to be relative to + // current view in layout. nsPoint point; - // in widget relative coordinates, not modified by layout code. + // In widget relative coordinates, not modified by layout code. nsPoint refPoint; - /// elapsed time, in milliseconds, from the time the system was started to the time the message was created + // Elapsed time, in milliseconds, from the time the system was + // started to the time the message was created PRUint32 time; - // flags to hold event flow stage and capture/bubble cancellation status + // Flags to hold event flow stage and capture/bubble cancellation + // status PRUint32 flags; - // flags for indicating more event state for Mozilla applications. + // Flags for indicating more event state for Mozilla applications. PRUint32 internalAppFlags; - // additional type info for user defined events + // Additional type info for user defined events nsHashKey* userType; }; @@ -384,12 +405,18 @@ struct nsEvent { * General graphic user interface event */ -struct nsGUIEvent : public nsEvent +class nsGUIEvent : public nsEvent { - nsGUIEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_GUI_EVENT) - : nsEvent(msg, structType), +protected: + nsGUIEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w, PRUint8 structType) + : nsEvent(isTrusted, msg, structType), + widget(w), nativeMsg(nsnull) + { + } + +public: + nsGUIEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsEvent(isTrusted, msg, NS_GUI_EVENT), widget(w), nativeMsg(nsnull) { } @@ -404,11 +431,11 @@ struct nsGUIEvent : public nsEvent * Script error event */ -struct nsScriptErrorEvent : public nsEvent +class nsScriptErrorEvent : public nsEvent { - nsScriptErrorEvent(PRUint32 msg = 0, - PRUint8 structType = NS_SCRIPT_ERROR_EVENT) - : nsEvent(msg, structType), +public: + nsScriptErrorEvent(PRBool isTrusted, PRUint32 msg) + : nsEvent(isTrusted, msg, NS_SCRIPT_ERROR_EVENT), lineNr(0), errorMsg(nsnull), fileName(nsnull) { } @@ -418,10 +445,11 @@ struct nsScriptErrorEvent : public nsEvent const PRUnichar* fileName; }; -struct nsBeforePageUnloadEvent : public nsEvent +class nsBeforePageUnloadEvent : public nsEvent { - nsBeforePageUnloadEvent(PRUint32 msg) - : nsEvent(msg, NS_BEFORE_PAGE_UNLOAD_EVENT) +public: + nsBeforePageUnloadEvent(PRBool isTrusted, PRUint32 msg) + : nsEvent(isTrusted, msg, NS_BEFORE_PAGE_UNLOAD_EVENT) { } @@ -432,12 +460,11 @@ struct nsBeforePageUnloadEvent : public nsEvent * Window resize event */ -struct nsSizeEvent : public nsGUIEvent +class nsSizeEvent : public nsGUIEvent { - nsSizeEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_SIZE_EVENT) - : nsGUIEvent(msg, w, structType), +public: + nsSizeEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_SIZE_EVENT), windowSize(nsnull), mWinWidth(0), mWinHeight(0) { } @@ -454,12 +481,11 @@ struct nsSizeEvent : public nsGUIEvent * Window size mode event */ -struct nsSizeModeEvent : public nsGUIEvent +class nsSizeModeEvent : public nsGUIEvent { - nsSizeModeEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_SIZEMODE_EVENT) - : nsGUIEvent(msg, w, structType), +public: + nsSizeModeEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_SIZEMODE_EVENT), mSizeMode(nsSizeMode_Normal) { } @@ -471,12 +497,11 @@ struct nsSizeModeEvent : public nsGUIEvent * Window z-level event */ -struct nsZLevelEvent : public nsGUIEvent +class nsZLevelEvent : public nsGUIEvent { - nsZLevelEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_ZLEVEL_EVENT) - : nsGUIEvent(msg, w, structType), +public: + nsZLevelEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_ZLEVEL_EVENT), mPlacement(nsWindowZTop), mReqBelow(nsnull), mActualBelow(nsnull), mImmediate(PR_FALSE), mAdjusted(PR_FALSE) { @@ -493,12 +518,11 @@ struct nsZLevelEvent : public nsGUIEvent * Window repaint event */ -struct nsPaintEvent : public nsGUIEvent +class nsPaintEvent : public nsGUIEvent { - nsPaintEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_PAINT_EVENT) - : nsGUIEvent(msg, w, structType), +public: + nsPaintEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_PAINT_EVENT), renderingContext(nsnull), region(nsnull), rect(nsnull) { } @@ -515,12 +539,11 @@ struct nsPaintEvent : public nsGUIEvent * Scrollbar event */ -struct nsScrollbarEvent : public nsGUIEvent +class nsScrollbarEvent : public nsGUIEvent { - nsScrollbarEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_SCROLLBAR_EVENT) - : nsGUIEvent(msg, w, structType), +public: + nsScrollbarEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_SCROLLBAR_EVENT), position(0) { } @@ -529,18 +552,17 @@ struct nsScrollbarEvent : public nsGUIEvent PRUint32 position; }; -struct nsScrollPortEvent : public nsGUIEvent +class nsScrollPortEvent : public nsGUIEvent { +public: enum orientType { vertical = 0, horizontal = 1, both = 2 }; - nsScrollPortEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_SCROLLPORT_EVENT) - : nsGUIEvent(msg, w, structType), + nsScrollPortEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_SCROLLPORT_EVENT), orient(vertical) { } @@ -548,12 +570,19 @@ struct nsScrollPortEvent : public nsGUIEvent orientType orient; }; -struct nsInputEvent : public nsGUIEvent +class nsInputEvent : public nsGUIEvent { - nsInputEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_INPUT_EVENT) - : nsGUIEvent(msg, w, structType), +protected: + nsInputEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w, + PRUint8 structType) + : nsGUIEvent(isTrusted, msg, w, structType), + isShift(PR_FALSE), isControl(PR_FALSE), isAlt(PR_FALSE), isMeta(PR_FALSE) + { + } + +public: + nsInputEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_INPUT_EVENT), isShift(PR_FALSE), isControl(PR_FALSE), isAlt(PR_FALSE), isMeta(PR_FALSE) { } @@ -572,15 +601,14 @@ struct nsInputEvent : public nsGUIEvent * Mouse event */ -struct nsMouseEvent : public nsInputEvent +class nsMouseEvent : public nsInputEvent { +public: enum reasonType { eReal, eSynthesized }; - nsMouseEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - reasonType aReason = eReal, - PRUint8 structType = NS_MOUSE_EVENT) - : nsInputEvent(msg, w, structType), + nsMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w, + reasonType aReason) + : nsInputEvent(isTrusted, msg, w, NS_MOUSE_EVENT), clickCount(0), acceptActivation(PR_FALSE), reason(aReason) { if (msg == NS_MOUSE_MOVE) { @@ -600,29 +628,27 @@ struct nsMouseEvent : public nsInputEvent * Accessible event */ -struct nsAccessibleEvent : public nsInputEvent +class nsAccessibleEvent : public nsInputEvent { - nsAccessibleEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_ACCESSIBLE_EVENT) - : nsInputEvent(msg, w, structType), +public: + nsAccessibleEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsInputEvent(isTrusted, msg, w, NS_ACCESSIBLE_EVENT), accessible(nsnull) { } - nsIAccessible* accessible; + nsIAccessible* accessible; }; /** * Keyboard event */ -struct nsKeyEvent : public nsInputEvent +class nsKeyEvent : public nsInputEvent { - nsKeyEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_KEY_EVENT) - : nsInputEvent(msg, w, structType), +public: + nsKeyEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsInputEvent(isTrusted, msg, w, NS_KEY_EVENT), keyCode(0), charCode(0), isChar(0) { } @@ -638,7 +664,8 @@ struct nsKeyEvent : public nsInputEvent /** * IME Related Events */ -struct nsTextRange { +struct nsTextRange +{ nsTextRange() : mStartOffset(0), mEndOffset(0), mRangeType(0) { @@ -651,7 +678,8 @@ struct nsTextRange { typedef nsTextRange* nsTextRangeArray; -struct nsTextEventReply { +struct nsTextEventReply +{ nsTextEventReply() : mCursorIsCollapsed(PR_FALSE) { @@ -663,12 +691,11 @@ struct nsTextEventReply { typedef struct nsTextEventReply nsTextEventReply; -struct nsTextEvent : public nsInputEvent +class nsTextEvent : public nsInputEvent { - nsTextEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_TEXT_EVENT) - : nsInputEvent(msg, w, structType), +public: + nsTextEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsInputEvent(isTrusted, msg, w, NS_TEXT_EVENT), theText(nsnull), rangeCount(0), rangeArray(nsnull), isChar(PR_FALSE) { } @@ -680,30 +707,28 @@ struct nsTextEvent : public nsInputEvent PRBool isChar; }; -struct nsCompositionEvent : public nsInputEvent +class nsCompositionEvent : public nsInputEvent { - nsCompositionEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_COMPOSITION_EVENT) - : nsInputEvent(msg, w, structType) +public: + nsCompositionEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsInputEvent(isTrusted, msg, w, NS_COMPOSITION_EVENT) { } nsTextEventReply theReply; }; -struct nsMouseScrollEvent : public nsInputEvent +class nsMouseScrollEvent : public nsInputEvent { +public: enum nsMouseScrollFlags { kIsFullPage = 1 << 0, kIsVertical = 1 << 1, kIsHorizontal = 1 << 2 }; - nsMouseScrollEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_MOUSE_SCROLL_EVENT) - : nsInputEvent(msg, w, structType), + nsMouseScrollEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsInputEvent(isTrusted, msg, w, NS_MOUSE_SCROLL_EVENT), scrollFlags(0), delta(0) { } @@ -721,19 +746,19 @@ struct nsReconversionEventReply { PRUnichar *mReconversionString; }; -struct nsReconversionEvent : public nsInputEvent +class nsReconversionEvent : public nsInputEvent { - nsReconversionEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_RECONVERSION_EVENT) - : nsInputEvent(msg, w, structType) +public: + nsReconversionEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsInputEvent(isTrusted, msg, w, NS_RECONVERSION_EVENT) { } nsReconversionEventReply theReply; }; -struct nsQueryCaretRectEventReply { +struct nsQueryCaretRectEventReply +{ nsQueryCaretRectEventReply() : mRectIsValid(PR_FALSE) { @@ -743,12 +768,11 @@ struct nsQueryCaretRectEventReply { nsRect mCaretRect; }; -struct nsQueryCaretRectEvent : public nsInputEvent +class nsQueryCaretRectEvent : public nsInputEvent { - nsQueryCaretRectEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_QUERYCARETRECT_EVENT) - : nsInputEvent(msg, w, structType) +public: + nsQueryCaretRectEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsInputEvent(isTrusted, msg, w, NS_QUERYCARETRECT_EVENT) { } @@ -762,12 +786,11 @@ struct nsQueryCaretRectEvent : public nsInputEvent * for the event */ -struct nsMenuEvent : public nsGUIEvent +class nsMenuEvent : public nsGUIEvent { - nsMenuEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_MENU_EVENT) - : nsGUIEvent(msg, w, structType), +public: + nsMenuEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_MENU_EVENT), mMenuItem(nsnull), mCommand(0) { } @@ -783,10 +806,11 @@ struct nsMenuEvent : public nsGUIEvent * originator is a weak pointer (does not hold a strong reference). */ -struct nsFormEvent : public nsEvent +class nsFormEvent : public nsEvent { - nsFormEvent(PRUint32 msg = 0, PRUint8 structType = NS_FORM_EVENT) - : nsEvent(msg, structType), +public: + nsFormEvent(PRBool isTrusted, PRUint32 msg) + : nsEvent(isTrusted, msg, NS_FORM_EVENT), originator(nsnull) { } @@ -797,12 +821,11 @@ struct nsFormEvent : public nsEvent /** * Focus event */ -struct nsFocusEvent : public nsGUIEvent +class nsFocusEvent : public nsGUIEvent { - nsFocusEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_FOCUS_EVENT) - : nsGUIEvent(msg, w, structType), +public: + nsFocusEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsGUIEvent(isTrusted, msg, w, NS_FOCUS_EVENT), isMozWindowTakingFocus(PR_FALSE) { } @@ -816,12 +839,11 @@ struct nsFocusEvent : public nsGUIEvent * Custom commands from the operating system. eg. WM_APPCOMMAND on Windows */ -struct nsAppCommandEvent : public nsInputEvent +class nsAppCommandEvent : public nsInputEvent { - nsAppCommandEvent(PRUint32 msg = 0, - nsIWidget *w = nsnull, - PRUint8 structType = NS_APPCOMMAND_EVENT) - : nsInputEvent(msg, w, structType), +public: + nsAppCommandEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) + : nsInputEvent(isTrusted, msg, w, NS_APPCOMMAND_EVENT), appCommand(0) { } @@ -832,11 +854,11 @@ struct nsAppCommandEvent : public nsInputEvent /** * blocked popup window event */ -struct nsPopupBlockedEvent : public nsEvent +class nsPopupBlockedEvent : public nsEvent { - nsPopupBlockedEvent(PRUint32 msg = 0, - PRUint8 structType = NS_POPUPBLOCKED_EVENT) - : nsEvent(msg, structType), +public: + nsPopupBlockedEvent(PRBool isTrusted, PRUint32 msg) + : nsEvent(isTrusted, msg, NS_POPUPBLOCKED_EVENT), mRequestingWindowURI(nsnull), mPopupWindowURI(nsnull) { } @@ -849,11 +871,11 @@ struct nsPopupBlockedEvent : public nsEvent /** * DOM UIEvent */ -struct nsUIEvent : public nsEvent { - nsUIEvent(PRUint32 msg = 0, - PRInt32 d = 0, - PRUint8 structType = NS_UI_EVENT) - : nsEvent(msg, structType), +class nsUIEvent : public nsEvent +{ +public: + nsUIEvent(PRBool isTrusted, PRUint32 msg, PRInt32 d) + : nsEvent(isTrusted, msg, NS_UI_EVENT), detail(d) { } @@ -924,6 +946,11 @@ enum nsDragDropEventStatus { ((evnt)->message == NS_DEACTIVATE) || \ ((evnt)->message == NS_PLUGIN_ACTIVATE)) +#define NS_IS_TRUSTED_EVENT(event) \ + (((event)->internalAppFlags & NS_APP_EVENT_FLAG_TRUSTED) != 0) + + + /* * Virtual key bindings for keyboard events. * These come from nsIDOMKeyEvent.h, which is generated from MouseKeyEvent.idl. diff --git a/widget/public/nsIEventListener.h b/widget/public/nsIEventListener.h index 3b670881e6b5..2d66d3a19194 100644 --- a/widget/public/nsIEventListener.h +++ b/widget/public/nsIEventListener.h @@ -40,7 +40,7 @@ #include "nsISupports.h" -struct nsGUIEvent; +class nsGUIEvent; /** * Event listener interface. diff --git a/widget/public/nsIWidget.h b/widget/public/nsIWidget.h index 9d9ac041c08c..9090dca745d6 100644 --- a/widget/public/nsIWidget.h +++ b/widget/public/nsIWidget.h @@ -62,7 +62,7 @@ struct nsFont; class nsIMenuBar; class nsIEventListener; class nsIRollupListener; -struct nsGUIEvent; +class nsGUIEvent; struct nsColorMap; class imgIContainer; diff --git a/widget/src/beos/nsWindow.cpp b/widget/src/beos/nsWindow.cpp index 0417efa7ab51..c5c405036bbd 100644 --- a/widget/src/beos/nsWindow.cpp +++ b/widget/src/beos/nsWindow.cpp @@ -305,7 +305,7 @@ PRBool nsWindow::DispatchWindowEvent(nsGUIEvent* event) PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg) { - nsGUIEvent event(aMsg, this); + nsGUIEvent event(PR_TRUE, aMsg, this); InitEvent(event); PRBool result = DispatchWindowEvent(&event); @@ -1797,7 +1797,7 @@ bool nsWindow::CallMethod(MethodInfo *info) return false; NS_ASSERTION(info->nArgs == 1, "Wrong number of arguments to CallMethod"); - nsMouseScrollEvent scrollEvent(NS_MOUSE_SCROLL, this); + nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this); scrollEvent.scrollFlags = nsMouseScrollEvent::kIsVertical; @@ -2264,7 +2264,7 @@ PRBool nsWindow::OnKeyUp(PRUint32 aEventType, const char *bytes, PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, PRUint32 aCharCode, PRUint32 aKeyCode, PRUint32 aFlags) { - nsKeyEvent event(aEventType, this); + nsKeyEvent event(PR_TRUE, aEventType, this); nsPoint point; point.x = 0; @@ -2341,7 +2341,7 @@ void nsWindow::OnDestroy() //------------------------------------------------------------------------- PRBool nsWindow::OnMove(PRInt32 aX, PRInt32 aY) { - nsGUIEvent event(NS_MOVE, this); + nsGUIEvent event(PR_TRUE, NS_MOVE, this); InitEvent(event); event.point.x = aX; event.point.y = aY; @@ -2370,7 +2370,7 @@ PRBool nsWindow::OnPaint(nsRect &r) mView->ConstrainClippingRegion(&invalid); mView->Flush(); mView->UnlockLooper(); - nsPaintEvent event(NS_PAINT, this); + nsPaintEvent event(PR_TRUE, NS_PAINT, this); InitEvent(event); event.region = nsnull; @@ -2408,7 +2408,7 @@ PRBool nsWindow::OnResize(nsRect &aWindowRect) // call the event callback if (mEventCallback) { - nsSizeEvent event(NS_SIZE, this); + nsSizeEvent event(PR_TRUE, NS_SIZE, this); InitEvent(event); event.windowSize = &aWindowRect; if(mView && mView->LockLooper()) @@ -2441,7 +2441,7 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint3 PRBool result = PR_FALSE; if(nsnull != mEventCallback || nsnull != mMouseListener) { - nsMouseEvent event(aEventType, this); + nsMouseEvent event(PR_TRUE, aEventType, this, nsMouseEvent::eReal); InitEvent (event, &aPoint); event.isShift = mod & B_SHIFT_KEY; event.isControl = mod & B_CONTROL_KEY; diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index da3a3b86315b..3e7900349409 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -1500,7 +1500,7 @@ nsChildView::UpdateWidget(nsRect& aRect, nsIRenderingContext* aContext) StPortSetter port(curPort); // initialize the paint event - nsPaintEvent paintEvent(NS_PAINT, this); + nsPaintEvent paintEvent(PR_TRUE, NS_PAINT, this); paintEvent.renderingContext = aContext; // nsPaintEvent paintEvent.rect = &aRect; @@ -1791,7 +1791,7 @@ PRBool nsChildView::DispatchMouseEvent(nsMouseEvent &aEvent) PRBool nsChildView::ReportDestroyEvent() { // nsEvent - nsGUIEvent event(NS_DESTROY, this); + nsGUIEvent event(PR_TRUE, NS_DESTROY, this); event.time = PR_IntervalNow(); // dispatch event @@ -1805,7 +1805,7 @@ PRBool nsChildView::ReportDestroyEvent() PRBool nsChildView::ReportMoveEvent() { // nsEvent - nsGUIEvent moveEvent(NS_MOVE, this); + nsGUIEvent moveEvent(PR_TRUE, NS_MOVE, this); moveEvent.point.x = mBounds.x; moveEvent.point.y = mBounds.y; moveEvent.time = PR_IntervalNow(); @@ -1821,7 +1821,7 @@ PRBool nsChildView::ReportMoveEvent() PRBool nsChildView::ReportSizeEvent() { // nsEvent - nsSizeEvent sizeEvent(NS_SIZE, this); + nsSizeEvent sizeEvent(PR_TRUE, NS_SIZE, this); sizeEvent.time = PR_IntervalNow(); // nsSizeEvent @@ -2131,7 +2131,7 @@ nsChildView::DragEvent(PRUint32 aMessage, PRInt16 aMouseGlobalX, PRInt16 aMouseG return NS_OK; } - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); // we're given the point in global coordinates. We need to convert it to // window coordinates for convert:message:toGeckoEvent @@ -2192,7 +2192,7 @@ nsChildView::Idle() -(NSMenu*)menuForEvent:(NSEvent*)theEvent { // Fire the context menu event into Gecko. - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert:theEvent message:NS_CONTEXTMENU toGeckoEvent:&geckoEvent]; // send event into Gecko by going directly to the @@ -2580,7 +2580,7 @@ nsChildView::Idle() [self performSelector:@selector(clickHoldCallback:) withObject:theEvent afterDelay:2.0]; #endif - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert:theEvent message:NS_MOUSE_LEFT_BUTTON_DOWN toGeckoEvent:&geckoEvent]; geckoEvent.clickCount = [theEvent clickCount]; @@ -2610,7 +2610,7 @@ nsChildView::Idle() [self stopHandScroll:theEvent]; return; } - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert:theEvent message:NS_MOUSE_LEFT_BUTTON_UP toGeckoEvent:&geckoEvent]; NSPoint mouseLoc = [theEvent locationInWindow]; @@ -2645,7 +2645,7 @@ nsChildView::Idle() if ([ChildView areHandScrollModifiers:[theEvent modifierFlags]]) { return; } - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert:theEvent message:NS_MOUSE_MOVE toGeckoEvent:&geckoEvent]; NSPoint mouseLoc = [theEvent locationInWindow]; @@ -2673,7 +2673,7 @@ nsChildView::Idle() [self updateHandScroll:theEvent]; return; } - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert:theEvent message:NS_MOUSE_MOVE toGeckoEvent:&geckoEvent]; EventRecord macEvent; @@ -2717,7 +2717,7 @@ nsChildView::Idle() { // The right mouse went down. Fire off a right mouse down and // then send the context menu event. - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert: theEvent message: NS_MOUSE_RIGHT_BUTTON_DOWN toGeckoEvent:&geckoEvent]; @@ -2738,7 +2738,7 @@ nsChildView::Idle() - (void)rightMouseUp:(NSEvent *)theEvent { - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert: theEvent message: NS_MOUSE_RIGHT_BUTTON_UP toGeckoEvent:&geckoEvent]; @@ -2759,7 +2759,7 @@ nsChildView::Idle() - (void)otherMouseDown:(NSEvent *)theEvent { - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert:theEvent message:NS_MOUSE_MIDDLE_BUTTON_DOWN toGeckoEvent:&geckoEvent]; geckoEvent.clickCount = [theEvent clickCount]; @@ -2772,7 +2772,7 @@ nsChildView::Idle() - (void)otherMouseUp:(NSEvent *)theEvent { - nsMouseEvent geckoEvent; + nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convert:theEvent message:NS_MOUSE_MIDDLE_BUTTON_UP toGeckoEvent:&geckoEvent]; // send event into Gecko by going directly to the @@ -2789,7 +2789,7 @@ const PRInt32 kNumLines = 4; // Gecko as the number of lines to scroll. We go ahead and use a // default kNumLines of 4 for now (until I learn how we can get settings from // the OS). --dwh - nsMouseScrollEvent geckoEvent; + nsMouseScrollEvent geckoEvent(PR_TRUE, 0, nsnull); [self convert:theEvent message:NS_MOUSE_SCROLL toGeckoEvent:&geckoEvent]; PRInt32 incomingDeltaX = (PRInt32)[theEvent deltaX]; @@ -2930,7 +2930,7 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac #endif // static void init_composition_event( *aEvent, int aType) - nsCompositionEvent event(aEventType, mGeckoChild); + nsCompositionEvent event(PR_TRUE, aEventType, mGeckoChild); event.time = PR_IntervalNow(); mGeckoChild->DispatchWindowEvent(event); return event.theReply.mCursorPosition; @@ -2947,7 +2947,7 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac NSLog(@" markRange = %d, %d; selRange = %d, %d\n", markRange.location, markRange.length, selRange.location, selRange.length); #endif - nsTextEvent textEvent(NS_TEXT_TEXT, mGeckoChild); + nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, mGeckoChild); textEvent.time = PR_IntervalNow(); textEvent.theText = aBuffer; if (!doCommit) @@ -2981,7 +2981,7 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac if (len == 1 && !mInComposition) { // dispatch keypress event with char instead of textEvent - nsKeyEvent geckoEvent(NS_KEY_PRESS, mGeckoChild); + nsKeyEvent geckoEvent(PR_TRUE, NS_KEY_PRESS, mGeckoChild); geckoEvent.time = PR_IntervalNow(); geckoEvent.charCode = bufPtr[0]; // gecko expects OS-translated unicode geckoEvent.isChar = PR_TRUE; @@ -3116,7 +3116,8 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac NSLog(@" selectedRange = %d, %d\n", mSelectedRange.location, mSelectedRange.length); #endif - nsReconversionEvent reconversionEvent(NS_RECONVERSION_QUERY, mGeckoChild); + nsReconversionEvent reconversionEvent(PR_TRUE, NS_RECONVERSION_QUERY, + mGeckoChild); reconversionEvent.time = PR_IntervalNow(); nsresult rv = mGeckoChild->DispatchWindowEvent(reconversionEvent); @@ -3235,7 +3236,7 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac if (!isARepeat && nonDeadKeyPress) { // Fire a key down. - nsKeyEvent geckoEvent; + nsKeyEvent geckoEvent(PR_TRUE, 0, nsnull); geckoEvent.point.x = geckoEvent.point.y = 0; [self convert: theEvent message: NS_KEY_DOWN isChar: &isChar @@ -3264,7 +3265,7 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac if (nonDeadKeyPress) { // Fire a key press. - nsKeyEvent geckoEvent; + nsKeyEvent geckoEvent(PR_TRUE, 0, nsnull); geckoEvent.point.x = geckoEvent.point.y = 0; isChar = PR_FALSE; [self convert: theEvent message: NS_KEY_PRESS @@ -3319,7 +3320,7 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac return; // Fire a key up. - nsKeyEvent geckoEvent; + nsKeyEvent geckoEvent(PR_TRUE, 0, nsnull); geckoEvent.point.x = geckoEvent.point.y = 0; PRBool isChar; [self convert: theEvent message: NS_KEY_UP @@ -3363,7 +3364,7 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac // This method is called when we are about to be focused. - (BOOL)becomeFirstResponder { - nsFocusEvent event(NS_GOTFOCUS, mGeckoChild); + nsFocusEvent event(PR_TRUE, NS_GOTFOCUS, mGeckoChild); mGeckoChild->DispatchWindowEvent(event); return [super becomeFirstResponder]; @@ -3372,7 +3373,7 @@ static void ConvertCocoaKeyEventToMacEvent(NSEvent* cocoaEvent, EventRecord& mac // This method is called when are are about to lose focus. - (BOOL)resignFirstResponder { - nsFocusEvent event(NS_LOSTFOCUS, mGeckoChild); + nsFocusEvent event(PR_TRUE, NS_LOSTFOCUS, mGeckoChild); mGeckoChild->DispatchWindowEvent(event); diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 80c4f1edc9a1..2ff0bae5eb4a 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -1498,7 +1498,7 @@ PRBool nsCocoaWindow::DragEvent ( unsigned int aMessage, Point aMouseGlobal, UIn //------------------------------------------------------------------------- void nsCocoaWindow::ComeToFront() { #if 0 - nsZLevelEvent event(NS_SETZLEVEL, this); + nsZLevelEvent event(PR_TRUE, NS_SETZLEVEL, this); event.point.x = mBounds.x; event.point.y = mBounds.y; @@ -1564,7 +1564,8 @@ nsCocoaWindow::DispatchEvent ( void* anEvent, void* aView, PRBool *_retval ) ChildView* view = NS_REINTERPRET_CAST(ChildView*, aView); - nsMouseEvent geckoEvent(0, view ? [view widget] : this) + nsMouseEvent geckoEvent(PR_TRUE, 0, view ? [view widget] : this, + nsMouseEvent::eReal) geckoEvent.nativeMsg = anEvent; geckoEvent.time = PR_IntervalNow(); @@ -1660,7 +1661,7 @@ void nsCocoaWindow::ReportSizeEvent() { // nsEvent - nsSizeEvent sizeEvent(NS_SIZE, this); + nsSizeEvent sizeEvent(PR_TRUE, NS_SIZE, this); sizeEvent.time = PR_IntervalNow(); // nsSizeEvent diff --git a/widget/src/cocoa/nsMenuBarX.cpp b/widget/src/cocoa/nsMenuBarX.cpp index 7bbb0da18075..f2854d8b03e3 100644 --- a/widget/src/cocoa/nsMenuBarX.cpp +++ b/widget/src/cocoa/nsMenuBarX.cpp @@ -401,7 +401,7 @@ nsMenuBarX :: ExecuteCommand ( nsIContent* inDispatchTo ) nsCOMPtr presContext; MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext)); - nsMouseEvent event(NS_XUL_COMMAND); + nsMouseEvent event(PR_TRUE, NS_XUL_COMMAND, nsnull, nsMouseEvent::eReal); inDispatchTo->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); } @@ -489,7 +489,7 @@ nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWin nsAutoString menuIDstring; menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::id, menuIDstring); if ( menuIDstring.EqualsLiteral("menu_Help") ) { - nsMenuEvent event; + nsMenuEvent event(PR_TRUE, 0, nsnull); MenuHandle handle = nsnull; #if !TARGET_CARBON ::HMGetHelpMenuHandle(&handle); diff --git a/widget/src/cocoa/nsMenuItemX.cpp b/widget/src/cocoa/nsMenuItemX.cpp index ba48c021646a..65542a03f8b7 100644 --- a/widget/src/cocoa/nsMenuItemX.cpp +++ b/widget/src/cocoa/nsMenuItemX.cpp @@ -261,7 +261,7 @@ NS_METHOD nsMenuItemX::DoCommand() MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext)); nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_COMMAND); + nsMouseEvent event(PR_TRUE, NS_XUL_COMMAND, nsnull, nsMouseEvent::eReal); // See if we have a command element. If so, we execute on the command instead // of on our content element. diff --git a/widget/src/cocoa/nsMenuX.cpp b/widget/src/cocoa/nsMenuX.cpp index 32f9b0b21865..01c55288ead5 100644 --- a/widget/src/cocoa/nsMenuX.cpp +++ b/widget/src/cocoa/nsMenuX.cpp @@ -747,7 +747,7 @@ static pascal OSStatus MyMenuEventHandler(EventHandlerCallRef myHandler, EventRe if (listener) { MenuRef menuRef; ::GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL, sizeof(menuRef), NULL, &menuRef); - nsMenuEvent menuEvent(NS_MENU_SELECTED); + nsMenuEvent menuEvent(PR_TRUE, NS_MENU_SELECTED, nsnull); menuEvent.time = PR_IntervalNow(); menuEvent.mCommand = (PRUint32) menuRef; if (kind == kEventMenuOpening) { @@ -973,8 +973,9 @@ PRBool nsMenuX::OnCreate() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWING); - + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull, + nsMouseEvent::eReal); + nsCOMPtr popupContent; GetMenuPopupContent(getter_AddRefs(popupContent)); @@ -1056,7 +1057,7 @@ PRBool nsMenuX::OnCreated() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWN); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWN, nsnull, nsMouseEvent::eReal); nsCOMPtr popupContent; GetMenuPopupContent(getter_AddRefs(popupContent)); @@ -1092,7 +1093,8 @@ nsMenuX::OnDestroy() return PR_TRUE; nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_HIDING); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDING, nsnull, + nsMouseEvent::eReal); nsCOMPtr docShell = do_QueryReferent(mDocShellWeakRef); if (!docShell) { @@ -1122,7 +1124,8 @@ PRBool nsMenuX::OnDestroyed() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_HIDDEN); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDDEN, nsnull, + nsMouseEvent::eReal); nsCOMPtr docShell = do_QueryReferent(mDocShellWeakRef); if (!docShell) { diff --git a/widget/src/gtk/nsGtkEventHandler.cpp b/widget/src/gtk/nsGtkEventHandler.cpp index 2e2f5cf0923a..aebf0bae1f55 100644 --- a/widget/src/gtk/nsGtkEventHandler.cpp +++ b/widget/src/gtk/nsGtkEventHandler.cpp @@ -452,7 +452,7 @@ void InitKeyPressEvent(GdkEventKey *aGEK, void handle_size_allocate(GtkWidget *w, GtkAllocation *alloc, gpointer p) { nsWindow *widget = (nsWindow *)p; - nsSizeEvent event(NS_SIZE, widget); + nsSizeEvent event(PR_TRUE, NS_SIZE, widget); InitAllocationEvent(alloc, event); NS_ADDREF(widget); @@ -475,7 +475,7 @@ gint handle_key_press_event_for_text(GtkObject *w, GdkEventKey* event, return PR_FALSE; NS_ADDREF(win); - nsKeyEvent keyDownEvent(NS_KEY_DOWN, win); + nsKeyEvent keyDownEvent(PR_TRUE, NS_KEY_DOWN, win); InitKeyEvent(event, keyDownEvent); PRBool noDefault = win->OnKey(keyDownEvent); @@ -496,7 +496,7 @@ gint handle_key_press_event_for_text(GtkObject *w, GdkEventKey* event, // character code. Note we have to check for modifier keys, since // gtk returns a character value for them // - nsKeyEvent keyPressEvent(NS_KEY_PRESS, win); + nsKeyEvent keyPressEvent(PR_TRUE, NS_KEY_PRESS, win); InitKeyPressEvent(event, keyPressEvent); if (noDefault) { // If prevent default set for onkeydown, do the same for onkeypress keyPressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT; @@ -518,7 +518,7 @@ gint handle_key_release_event_for_text(GtkObject *w, GdkEventKey* event, gpointer p) { nsTextWidget* win = (nsTextWidget*)p; - nsKeyEvent kevent(NS_KEY_UP, win); + nsKeyEvent kevent(PR_TRUE, NS_KEY_UP, win); InitKeyEvent(event, kevent); NS_ADDREF(win); win->OnKey(kevent); @@ -557,7 +557,7 @@ gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p) // window that currently has focus inside our app... // PRBool noDefault = PR_FALSE; - nsKeyEvent keyDownEvent(NS_KEY_DOWN, win); + nsKeyEvent keyDownEvent(PR_TRUE, NS_KEY_DOWN, win); InitKeyEvent(event, keyDownEvent); // if we need to suppress this NS_KEY_DOWN event, reset the flag if (suppressNextKeyDown == PR_TRUE) @@ -583,7 +583,7 @@ gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p) // // Call nsConvertCharCodeToUnicode() here to get kevent.charCode - nsKeyEvent keyPressEvent(NS_KEY_PRESS, win); + nsKeyEvent keyPressEvent(PR_TRUE, NS_KEY_PRESS, win); InitKeyPressEvent(event, keyPressEvent); if (noDefault) { // If prevent default set for onkeydown, do the same for onkeypress keyPressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT; @@ -652,7 +652,7 @@ gint handle_key_release_event(GtkObject *w, GdkEventKey* event, gpointer p) if (nsWidget::sFocusWindow) win = nsWidget::sFocusWindow; - nsKeyEvent kevent(NS_KEY_UP, win); + nsKeyEvent kevent(PR_TRUE, NS_KEY_UP, win); InitKeyEvent(event, kevent); NS_ADDREF(win); diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index 201d1ca93258..62a0a48c0f55 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -96,7 +96,7 @@ PRBool nsWidget::OnKey(nsKeyEvent &aEvent) // before we dispatch a key, check if it's the context menu key. // If so, send a context menu key event instead. if (IsContextMenuKey(aEvent)) { - nsMouseEvent contextMenuEvent; + nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); ConvertKeyEventToContextMenuEvent(&aEvent, &contextMenuEvent); ret = DispatchWindowEvent(&contextMenuEvent); } @@ -678,7 +678,7 @@ PRBool nsWidget::OnResize(nsSizeEvent *event) PRBool nsWidget::OnResize(nsRect &aRect) { - nsSizeEvent event(NS_SIZE, this); + nsSizeEvent event(PR_TRUE, NS_SIZE, this); InitEvent(event); @@ -718,7 +718,7 @@ PRBool nsWidget::OnMove(PRInt32 aX, PRInt32 aY) ResetInternalVisibility(); - nsGUIEvent event(NS_MOVE, this); + nsGUIEvent event(PR_TRUE, NS_MOVE, this); InitEvent(event); event.point.x = aX; event.point.y = aY; @@ -1456,7 +1456,7 @@ PRBool nsWidget::DispatchWindowEvent(nsGUIEvent* event) PRBool nsWidget::DispatchStandardEvent(PRUint32 aMsg) { - nsGUIEvent event(aMsg, this); + nsGUIEvent event(PR_TRUE, aMsg, this); InitEvent(event); PRBool result = DispatchWindowEvent(&event); return result; @@ -1727,7 +1727,7 @@ nsWidget::OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent) if (mIsDestroying) return; - nsMouseEvent event(NS_MOUSE_MOVE); + nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, nsnull, nsMouseEvent::eReal); // If there is a button motion target, use that instead of the // current widget @@ -1822,7 +1822,7 @@ nsWidget::OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent) return; } - nsMouseEvent event(NS_MOUSE_ENTER, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_ENTER, this, nsMouseEvent::eReal); if (aGdkCrossingEvent != NULL) { @@ -1856,7 +1856,7 @@ nsWidget::OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent) return; } - nsMouseEvent event(NS_MOUSE_EXIT, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_EXIT, this, nsMouseEvent::eReal); if (aGdkCrossingEvent != NULL) { @@ -1877,7 +1877,7 @@ nsWidget::OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent) /* virtual */ void nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) { - nsMouseScrollEvent scrollEvent(NS_MOUSE_SCROLL, this); + nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this); PRUint32 eventType = 0; // If you double click in GDK, it will actually generate a single @@ -1958,7 +1958,7 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) break; } - nsMouseEvent event(eventType, this); + nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); InitMouseEvent(aGdkButtonEvent, event); // Set the button motion target and remeber the widget and root coords @@ -1984,7 +1984,8 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) // if we're a right-button-down on linux, we're trying to // popup a context menu. send that event to gecko also. if (eventType == NS_MOUSE_RIGHT_BUTTON_DOWN) { - nsMouseEvent contextMenuEvent(NS_CONTEXTMENU, this); + nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this, + nsMouseEvent::eReal); InitMouseEvent(aGdkButtonEvent, contextMenuEvent); DispatchMouseEvent(contextMenuEvent); } @@ -2025,7 +2026,7 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent) break; } - nsMouseEvent event(eventType, this); + nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); InitMouseEvent(aGdkButtonEvent, event); if (sButtonMotionTarget) { @@ -2064,7 +2065,7 @@ nsWidget::OnFocusInSignal(GdkEventFocus * aGdkFocusEvent) GTK_WIDGET_SET_FLAGS(mWidget, GTK_HAS_FOCUS); - nsFocusEvent event(NS_GOTFOCUS, this); + nsFocusEvent event(PR_TRUE, NS_GOTFOCUS, this); // event.time = aGdkFocusEvent->time;; // event.time = PR_Now(); @@ -2084,7 +2085,7 @@ nsWidget::OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent) GTK_WIDGET_UNSET_FLAGS(mWidget, GTK_HAS_FOCUS); - nsFocusEvent event(NS_LOSTFOCUS, this); + nsFocusEvent event(PR_TRUE, NS_LOSTFOCUS, this); // event.time = aGdkFocusEvent->time;; // event.time = PR_Now(); @@ -2128,7 +2129,7 @@ nsWidget::InstallSignal(GtkWidget * aWidget, ////////////////////////////////////////////////////////////////// void nsWidget::InitMouseEvent(GdkEventButton * aGdkButtonEvent, - nsMouseEvent &anEvent) + nsMouseEvent &anEvent) { if (aGdkButtonEvent != NULL) { anEvent.point.x = nscoord(aGdkButtonEvent->x); diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index d2aa4a47e95d..3bcb87f21c15 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -844,7 +844,7 @@ nsWindow::DoPaint (nsIRegion *aClipRegion) aClipRegion->GetBoundingBox(&boundsRect.x, &boundsRect.y, &boundsRect.width, &boundsRect.height); #endif - nsPaintEvent event(NS_PAINT, this); + nsPaintEvent event(PR_TRUE, NS_PAINT, this); event.renderingContext = rc; event.time = GDK_CURRENT_TIME; // No time in EXPOSE events event.rect = &boundsRect; @@ -1398,7 +1398,7 @@ void nsWindow::DispatchSetFocusEvent(void) printf("nsWindow::DispatchSetFocusEvent %p\n", NS_STATIC_CAST(void *, this)); #endif /* DEBUG_FOCUS */ - nsGUIEvent event(NS_GOTFOCUS, this); + nsGUIEvent event(PR_TRUE, NS_GOTFOCUS, this); NS_ADDREF_THIS(); DispatchFocus(event); @@ -1418,7 +1418,7 @@ void nsWindow::DispatchLostFocusEvent(void) printf("nsWindow::DispatchLostFocusEvent %p\n", NS_STATIC_CAST(void *, this)); #endif /* DEBUG_FOCUS */ - nsGUIEvent event(NS_LOSTFOCUS, this); + nsGUIEvent event(PR_TRUE, NS_LOSTFOCUS, this); NS_ADDREF_THIS(); @@ -1439,7 +1439,7 @@ void nsWindow::DispatchActivateEvent(void) gJustGotDeactivate = PR_FALSE; - nsGUIEvent event(NS_ACTIVATE, this); + nsGUIEvent event(PR_TRUE, NS_ACTIVATE, this); NS_ADDREF_THIS(); DispatchFocus(event); @@ -1460,7 +1460,7 @@ void nsWindow::DispatchDeactivateEvent(void) IMEBeingActivate(PR_TRUE); #endif // USE_XIM - nsGUIEvent event(NS_DEACTIVATE, this); + nsGUIEvent event(PR_TRUE, NS_DEACTIVATE, this); NS_ADDREF_THIS(); DispatchFocus(event); @@ -1653,7 +1653,7 @@ nsWindow::OnFocusInSignal(GdkEventFocus * aGdkFocusEvent) GTK_WIDGET_SET_FLAGS(mMozArea, GTK_HAS_FOCUS); - nsFocusEvent event(NS_GOTFOCUS, this); + nsFocusEvent event(PR_TRUE, NS_GOTFOCUS, this); #ifdef DEBUG printf("send NS_GOTFOCUS from nsWindow::OnFocusInSignal\n"); #endif @@ -1674,7 +1674,7 @@ nsWindow::OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent) GTK_WIDGET_UNSET_FLAGS(mMozArea, GTK_HAS_FOCUS); - nsFocusEvent event(NS_LOSTFOCUS, this); + nsFocusEvent event(PR_TRUE, NS_LOSTFOCUS, this); // event.time = aGdkFocusEvent->time;; // event.time = PR_Now(); @@ -1769,7 +1769,7 @@ gint handle_delete_event(GtkWidget *w, GdkEventAny *e, nsWindow *win) NS_ADDREF(win); // dispatch an "onclose" event. to delete immediately, call win->Destroy() - nsGUIEvent event(NS_XUL_CLOSE, win); + nsGUIEvent event(PR_TRUE, NS_XUL_CLOSE, win); nsEventStatus status; win->DispatchEvent(&event, status); @@ -2723,7 +2723,7 @@ NS_IMETHODIMP nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint) } if (mIsToplevel || mListenForResizes) { //g_print("sending resize event\n"); - nsSizeEvent sevent(NS_SIZE, this); + nsSizeEvent sevent(PR_TRUE, NS_SIZE, this); sevent.windowSize = new nsRect (0, 0, sizeWidth, sizeHeight); sevent.mWinWidth = sizeWidth; sevent.mWinHeight = sizeHeight; @@ -2898,7 +2898,7 @@ nsWindow::HandleXlibConfigureNotifyEvent(XEvent *event) #endif if (mIsToplevel) { - nsSizeEvent sevent(NS_SIZE, this); + nsSizeEvent sevent(PR_TRUE, NS_SIZE, this); sevent.windowSize = new nsRect (event->xconfigure.x, event->xconfigure.y, event->xconfigure.width, event->xconfigure.height); sevent.point.x = event->xconfigure.x; @@ -3051,7 +3051,7 @@ GtkWindow *nsWindow::GetTopLevelWindow(void) // These are all of our drag and drop operations void -nsWindow::InitDragEvent (nsMouseEvent &aEvent) +nsWindow::InitDragEvent(nsMouseEvent &aEvent) { // set the keyboard modifiers gint x, y; @@ -3176,7 +3176,8 @@ gint nsWindow::OnDragMotionSignal (GtkWidget * aWidget, // notify the drag service that we are starting a drag motion. dragSessionGTK->TargetStartDragMotion(); - nsMouseEvent event(NS_DRAGDROP_OVER, innerMostWidget); + nsMouseEvent event(PR_TRUE, NS_DRAGDROP_OVER, innerMostWidget, + nsMouseEvent::eReal); InitDragEvent(event); @@ -3315,7 +3316,8 @@ nsWindow::OnDragDropSignal (GtkWidget *aWidget, innerMostWidget->AddRef(); - nsMouseEvent event(NS_DRAGDROP_OVER, innerMostWidget); + nsMouseEvent event(PR_TRUE, NS_DRAGDROP_OVER, innerMostWidget, + nsMouseEvent::eReal); InitDragEvent(event); @@ -3405,7 +3407,7 @@ nsWindow::OnDragLeave(void) g_print("nsWindow::OnDragLeave\n"); #endif /* DEBUG_DND_EVENTS */ - nsMouseEvent event(NS_DRAGDROP_EXIT, this); + nsMouseEvent event(PR_TRUE, NS_DRAGDROP_EXIT, this, nsMouseEvent::eReal); AddRef(); @@ -3441,7 +3443,7 @@ nsWindow::OnDragEnter(nscoord aX, nscoord aY) g_print("nsWindow::OnDragEnter\n"); #endif /* DEBUG_DND_EVENTS */ - nsMouseEvent event(NS_DRAGDROP_ENTER, this); + nsMouseEvent event(PR_TRUE, NS_DRAGDROP_ENTER, this, nsMouseEvent::eReal); event.point.x = aX; event.point.y = aY; @@ -3662,7 +3664,7 @@ void nsWindow::ICSpotCallback(nsITimer * aTimer, void * aClosure) nsresult nsWindow::UpdateICSpot(nsIMEGtkIC *aXIC) { // set spot location - nsCompositionEvent compEvent(NS_COMPOSITION_QUERY, this); + nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_QUERY, this); static gint oldx =0; static gint oldy =0; static gint oldw =0; @@ -3925,7 +3927,7 @@ nsWindow::IMEComposeStart(guint aTime) return; } #endif // USE_XIM - nsCompositionEvent compEvent(NS_COMPOSITION_START, this); + nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_START, this); compEvent.time = aTime; OnComposition(compEvent); @@ -3998,7 +4000,7 @@ void nsWindow::IMEComposeText(GdkEventKey *aEvent, const PRUnichar *aText, const PRInt32 aLen, const char *aFeedback) { - nsTextEvent textEvent(NS_TEXT_TEXT, this); + nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, this); if (aEvent) { textEvent.isShift = (aEvent->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE; textEvent.isControl = (aEvent->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE; @@ -4036,7 +4038,7 @@ nsWindow::IMEComposeEnd(guint aTime) } #endif // USE_XIM - nsCompositionEvent compEvent(NS_COMPOSITION_END, this); + nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_END, this); compEvent.time = aTime; OnComposition(compEvent); diff --git a/widget/src/gtk2/nsCommonWidget.cpp b/widget/src/gtk2/nsCommonWidget.cpp index 0d6f26f04446..977b626c8bbe 100644 --- a/widget/src/gtk2/nsCommonWidget.cpp +++ b/widget/src/gtk2/nsCommonWidget.cpp @@ -160,7 +160,7 @@ nsCommonWidget::InitKeyEvent(nsKeyEvent &aEvent, GdkEventKey *aGdkEvent) void nsCommonWidget::DispatchGotFocusEvent(void) { - nsGUIEvent event(NS_GOTFOCUS, this); + nsGUIEvent event(PR_TRUE, NS_GOTFOCUS, this); nsEventStatus status; DispatchEvent(&event, status); } @@ -168,7 +168,7 @@ nsCommonWidget::DispatchGotFocusEvent(void) void nsCommonWidget::DispatchLostFocusEvent(void) { - nsGUIEvent event(NS_LOSTFOCUS, this); + nsGUIEvent event(PR_TRUE, NS_LOSTFOCUS, this); nsEventStatus status; DispatchEvent(&event, status); } @@ -176,7 +176,7 @@ nsCommonWidget::DispatchLostFocusEvent(void) void nsCommonWidget::DispatchActivateEvent(void) { - nsGUIEvent event(NS_ACTIVATE, this); + nsGUIEvent event(PR_TRUE, NS_ACTIVATE, this); nsEventStatus status; DispatchEvent(&event, status); } @@ -184,7 +184,7 @@ nsCommonWidget::DispatchActivateEvent(void) void nsCommonWidget::DispatchDeactivateEvent(void) { - nsGUIEvent event(NS_DEACTIVATE, this); + nsGUIEvent event(PR_TRUE, NS_DEACTIVATE, this); nsEventStatus status; DispatchEvent(&event, status); } @@ -192,7 +192,7 @@ nsCommonWidget::DispatchDeactivateEvent(void) void nsCommonWidget::DispatchResizeEvent(nsRect &aRect, nsEventStatus &aStatus) { - nsSizeEvent event(NS_SIZE, this); + nsSizeEvent event(PR_TRUE, NS_SIZE, this); event.windowSize = &aRect; event.point.x = aRect.x; @@ -446,7 +446,7 @@ nsCommonWidget::OnDestroy(void) nsCOMPtr kungFuDeathGrip = this; - nsGUIEvent event(NS_DESTROY, this); + nsGUIEvent event(PR_TRUE, NS_DESTROY, this); nsEventStatus status; DispatchEvent(&event, status); } diff --git a/widget/src/gtk2/nsWindow.cpp b/widget/src/gtk2/nsWindow.cpp index 9f57275f4475..7d7c3ac9ebed 100644 --- a/widget/src/gtk2/nsWindow.cpp +++ b/widget/src/gtk2/nsWindow.cpp @@ -1316,7 +1316,7 @@ nsWindow::OnExposeEvent(GtkWidget *aWidget, GdkEventExpose *aEvent) LOGDRAW(("\t%d %d %d %d\n", r->x, r->y, r->width, r->height)); } - nsPaintEvent event(NS_PAINT, this); + nsPaintEvent event(PR_TRUE, NS_PAINT, this); event.point.x = aEvent->area.x; event.point.y = aEvent->area.y; event.rect = nsnull; @@ -1355,7 +1355,7 @@ nsWindow::OnConfigureEvent(GtkWidget *aWidget, GdkEventConfigure *aEvent) mBounds.y = newrect.y; } - nsGUIEvent event(NS_MOVE, this); + nsGUIEvent event(PR_TRUE, NS_MOVE, this); event.point.x = aEvent->x; event.point.y = aEvent->y; @@ -1395,7 +1395,7 @@ nsWindow::OnSizeAllocate(GtkWidget *aWidget, GtkAllocation *aAllocation) void nsWindow::OnDeleteEvent(GtkWidget *aWidget, GdkEventAny *aEvent) { - nsGUIEvent event(NS_XUL_CLOSE, this); + nsGUIEvent event(PR_TRUE, NS_XUL_CLOSE, this); event.point.x = 0; event.point.y = 0; @@ -1410,7 +1410,7 @@ nsWindow::OnEnterNotifyEvent(GtkWidget *aWidget, GdkEventCrossing *aEvent) if (aEvent->subwindow != NULL) return; - nsMouseEvent event(NS_MOUSE_ENTER, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_ENTER, this, nsMouseEvent::eReal); event.point.x = nscoord(aEvent->x); event.point.y = nscoord(aEvent->y); @@ -1427,7 +1427,7 @@ nsWindow::OnLeaveNotifyEvent(GtkWidget *aWidget, GdkEventCrossing *aEvent) if (aEvent->subwindow != NULL) return; - nsMouseEvent event(NS_MOUSE_EXIT, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_EXIT, this, nsMouseEvent::eReal); event.point.x = nscoord(aEvent->x); event.point.y = nscoord(aEvent->y); @@ -1459,7 +1459,7 @@ nsWindow::OnMotionNotifyEvent(GtkWidget *aWidget, GdkEventMotion *aEvent) gPluginFocusWindow->LoseNonXEmbedPluginFocus(); } - nsMouseEvent event(NS_MOUSE_MOVE, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, this, nsMouseEvent::eReal); if (synthEvent) { event.point.x = nscoord(xevent.xmotion.x); @@ -1537,14 +1537,15 @@ nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEventButton *aEvent) nsCOMPtr kungFuDeathGrip = this; - nsMouseEvent event(eventType, this); + nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); InitButtonEvent(event, aEvent); DispatchEvent(&event, status); // right menu click on linux should also pop up a context menu if (eventType == NS_MOUSE_RIGHT_BUTTON_DOWN) { - nsMouseEvent contextMenuEvent(NS_CONTEXTMENU, this); + nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this, + nsMouseEvent::eReal); InitButtonEvent(contextMenuEvent, aEvent); DispatchEvent(&contextMenuEvent, status); } @@ -1573,7 +1574,7 @@ nsWindow::OnButtonReleaseEvent(GtkWidget *aWidget, GdkEventButton *aEvent) break; } - nsMouseEvent event(eventType, this); + nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); InitButtonEvent(event, aEvent); nsEventStatus status; @@ -1701,7 +1702,7 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent) mInKeyRepeat = PR_TRUE; // send the key down event - nsKeyEvent downEvent(NS_KEY_DOWN, this); + nsKeyEvent downEvent(PR_TRUE, NS_KEY_DOWN, this); InitKeyEvent(downEvent, aEvent); DispatchEvent(&downEvent, status); isKeyDownCancelled = (status == nsEventStatus_eConsumeNoDefault); @@ -1724,7 +1725,7 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent) mInKeyRepeat = PR_FALSE; return TRUE; } - nsKeyEvent event(NS_KEY_PRESS, this); + nsKeyEvent event(PR_TRUE, NS_KEY_PRESS, this); InitKeyEvent(event, aEvent); if (isKeyDownCancelled) { // If prevent default set for onkeydown, do the same for onkeypress @@ -1756,7 +1757,7 @@ nsWindow::OnKeyPressEvent(GtkWidget *aWidget, GdkEventKey *aEvent) // before we dispatch a key, check if it's the context menu key. // If so, send a context menu key event instead. if (is_context_menu_key(event)) { - nsMouseEvent contextMenuEvent; + nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); key_event_to_context_menu_event(&event, &contextMenuEvent); DispatchEvent(&contextMenuEvent, status); } @@ -1791,7 +1792,7 @@ nsWindow::OnKeyReleaseEvent(GtkWidget *aWidget, GdkEventKey *aEvent) mInKeyRepeat = PR_FALSE; // send the key event as a key up event - nsKeyEvent event(NS_KEY_UP, this); + nsKeyEvent event(PR_TRUE, NS_KEY_UP, this); InitKeyEvent(event, aEvent); DispatchEvent(&event, status); @@ -1808,7 +1809,7 @@ nsWindow::OnKeyReleaseEvent(GtkWidget *aWidget, GdkEventKey *aEvent) void nsWindow::OnScrollEvent(GtkWidget *aWidget, GdkEventScroll *aEvent) { - nsMouseScrollEvent event(NS_MOUSE_SCROLL, this); + nsMouseScrollEvent event(PR_TRUE, NS_MOUSE_SCROLL, this); InitMouseScrollEvent(event, aEvent); // check to see if we should rollup @@ -1844,7 +1845,7 @@ nsWindow::OnWindowStateEvent(GtkWidget *aWidget, GdkEventWindowState *aEvent) LOG(("nsWindow::OnWindowStateEvent [%p] changed %d new_window_state %d\n", (void *)this, aEvent->changed_mask, aEvent->new_window_state)); - nsSizeModeEvent event(NS_SIZEMODE, this); + nsSizeModeEvent event(PR_TRUE, NS_SIZEMODE, this); // We don't care about anything but changes in the maximized/icon // states @@ -1876,7 +1877,7 @@ nsWindow::OnWindowStateEvent(GtkWidget *aWidget, GdkEventWindowState *aEvent) void nsWindow::ThemeChanged() { - nsGUIEvent event(NS_THEMECHANGED, this); + nsGUIEvent event(PR_TRUE, NS_THEMECHANGED, this); nsEventStatus status = nsEventStatus_eIgnore; DispatchEvent(&event, status); @@ -1959,7 +1960,8 @@ nsWindow::OnDragMotionEvent(GtkWidget *aWidget, // notify the drag service that we are starting a drag motion. dragSessionGTK->TargetStartDragMotion(); - nsMouseEvent event(NS_DRAGDROP_OVER, innerMostWidget); + nsMouseEvent event(PR_TRUE, NS_DRAGDROP_OVER, innerMostWidget, + nsMouseEvent::eReal); InitDragEvent(event); @@ -2074,7 +2076,8 @@ nsWindow::OnDragDropEvent(GtkWidget *aWidget, innerMostWidget->AddRef(); - nsMouseEvent event(NS_DRAGDROP_OVER, innerMostWidget); + nsMouseEvent event(PR_TRUE, NS_DRAGDROP_OVER, innerMostWidget, + nsMouseEvent::eReal); InitDragEvent(event); @@ -2143,7 +2146,7 @@ nsWindow::OnDragLeave(void) { LOG(("nsWindow::OnDragLeave(%p)\n", this)); - nsMouseEvent event(NS_DRAGDROP_EXIT, this); + nsMouseEvent event(PR_TRUE, NS_DRAGDROP_EXIT, this, nsMouseEvent::eReal); AddRef(); @@ -2180,7 +2183,7 @@ nsWindow::OnDragEnter(nscoord aX, nscoord aY) LOG(("nsWindow::OnDragEnter(%p)\n", this)); - nsMouseEvent event(NS_DRAGDROP_ENTER, this); + nsMouseEvent event(PR_TRUE, NS_DRAGDROP_ENTER, this, nsMouseEvent::eReal); event.point.x = aX; event.point.y = aY; @@ -4249,7 +4252,7 @@ PRBool nsWindow::DispatchAccessibleEvent(nsIAccessible** aAccessible) { PRBool result = PR_FALSE; - nsAccessibleEvent event(NS_GETACCESSIBLE, this); + nsAccessibleEvent event(PR_TRUE, NS_GETACCESSIBLE, this); *aAccessible = nsnull; @@ -4365,7 +4368,7 @@ nsWindow::IMEComposeStart(void) mComposingText = PR_TRUE; - nsCompositionEvent compEvent(NS_COMPOSITION_START, this); + nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_START, this); nsEventStatus status; DispatchEvent(&compEvent, status); @@ -4398,7 +4401,7 @@ nsWindow::IMEComposeText (const PRUnichar *aText, IMEComposeStart(); LOGIM(("IMEComposeText\n")); - nsTextEvent textEvent(NS_TEXT_TEXT, this); + nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, this); if (aLen != 0) { textEvent.theText = (PRUnichar*)aText; @@ -4445,7 +4448,7 @@ nsWindow::IMEComposeEnd(void) mComposingText = PR_FALSE; - nsCompositionEvent compEvent(NS_COMPOSITION_END, this); + nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_END, this); nsEventStatus status; DispatchEvent(&compEvent, status); @@ -4693,7 +4696,7 @@ IM_set_text_range(const PRInt32 aLen, // Get the range of the current attribute(s) pango_attr_iterator_range(aFeedbackIterator, &start, &end); - PRUint32 feedbackType; + PRUint32 feedbackType = 0; // XIMReverse | XIMUnderline if (aPangoAttrUnderline && aPangoAttrReverse) { feedbackType = NS_TEXTRANGE_SELECTEDCONVERTEDTEXT; diff --git a/widget/src/mac/nsMacControl.cpp b/widget/src/mac/nsMacControl.cpp index b886a92fdd4e..ae6f9f66f117 100644 --- a/widget/src/mac/nsMacControl.cpp +++ b/widget/src/mac/nsMacControl.cpp @@ -259,7 +259,7 @@ void nsMacControl::ControlChanged(PRInt32 aNewValue) mValue = aNewValue; mLastValue = mValue; // safely assume that the control has been repainted already - nsGUIEvent guiEvent(NS_CONTROL_CHANGE, this); + nsGUIEvent guiEvent(PR_TRUE, NS_CONTROL_CHANGE, this); guiEvent.time = PR_IntervalNow(); Inherited::DispatchWindowEvent(guiEvent); } diff --git a/widget/src/mac/nsMacEventHandler.cpp b/widget/src/mac/nsMacEventHandler.cpp index 290780e0ef2b..e563dde06bc0 100644 --- a/widget/src/mac/nsMacEventHandler.cpp +++ b/widget/src/mac/nsMacEventHandler.cpp @@ -110,7 +110,7 @@ HandleScrollEvent ( EventMouseWheelAxis inAxis, PRBool inByLine, PRInt32 inDelta if (!inWidget) return nsEventStatus_eIgnore; - nsMouseScrollEvent scrollEvent(NS_MOUSE_SCROLL, inWidget); + nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, inWidget); scrollEvent.scrollFlags = (inAxis == kEventMouseWheelAxisX) ? nsMouseScrollEvent::kIsHorizontal : nsMouseScrollEvent::kIsVertical; @@ -187,7 +187,7 @@ void nsMacEventDispatchHandler::DispatchGuiEvent(nsWindow *aWidget, PRUint32 aEv if (!aWidget) return; - nsGUIEvent guiEvent(aEventType, aWidget); + nsGUIEvent guiEvent(PR_TRUE, aEventType, aWidget); guiEvent.time = PR_IntervalNow(); aWidget->DispatchWindowEvent(guiEvent); } @@ -201,7 +201,7 @@ void nsMacEventDispatchHandler::DispatchSizeModeEvent(nsWindow *aWidget, nsSizeM if (!aWidget) return; - nsSizeModeEvent event(NS_SIZEMODE, aWidget); + nsSizeModeEvent event(PR_TRUE, NS_SIZEMODE, aWidget); event.time = PR_IntervalNow(); event.mSizeMode = aMode; aWidget->DispatchWindowEvent(event); @@ -524,7 +524,7 @@ PRBool nsMacEventHandler::HandleMenuCommand( focusedWidget = mTopLevelWidget; // nsEvent - nsMenuEvent menuEvent(NS_MENU_SELECTED, focusedWidget); + nsMenuEvent menuEvent(PR_TRUE, NS_MENU_SELECTED, focusedWidget); menuEvent.point.x = aOSEvent.where.h; menuEvent.point.y = aOSEvent.where.v; menuEvent.time = PR_IntervalNow(); @@ -619,7 +619,7 @@ PRBool nsMacEventHandler::DragEvent ( unsigned int aMessage, Point aMouseGlobal, // update the tracking of which widget the mouse is now over. gEventDispatchHandler.SetWidgetPointed(widgetHit); - nsMouseEvent geckoEvent(aMessage, widgetHit); + nsMouseEvent geckoEvent(PR_TRUE, aMessage, widgetHit, nsMouseEvent::eReal); // nsEvent geckoEvent.point = widgetHitPoint; @@ -1096,7 +1096,7 @@ PRBool nsMacEventHandler::HandleKeyEvent(EventRecord& aOSEvent) { case keyUp: { - nsKeyEvent keyUpEvent(NS_KEY_UP); + nsKeyEvent keyUpEvent(PR_TRUE, NS_KEY_UP, nsnull); InitializeKeyEvent(keyUpEvent, aOSEvent, focusedWidget, NS_KEY_UP); result = focusedWidget->DispatchWindowEvent(keyUpEvent); break; @@ -1104,7 +1104,8 @@ PRBool nsMacEventHandler::HandleKeyEvent(EventRecord& aOSEvent) case keyDown: { - nsKeyEvent keyDownEvent(NS_KEY_DOWN), keyPressEvent(NS_KEY_PRESS); + nsKeyEvent keyDownEvent(PR_TRUE, NS_KEY_DOWN, nsnull); + nsKeyEvent keyPressEvent(PR_TRUE, NS_KEY_PRESS, nsnull); InitializeKeyEvent(keyDownEvent, aOSEvent, focusedWidget, NS_KEY_DOWN); result = focusedWidget->DispatchWindowEvent(keyDownEvent); @@ -1126,7 +1127,8 @@ PRBool nsMacEventHandler::HandleKeyEvent(EventRecord& aOSEvent) // before we dispatch this key, check if it's the contextmenu key. // If so, send a context menu event instead. if ( IsContextMenuKey(keyPressEvent) ) { - nsMouseEvent contextMenuEvent; + nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, + nsMouseEvent::eReal); ConvertKeyEventToContextMenuEvent(&keyPressEvent, &contextMenuEvent); result = focusedWidget->DispatchWindowEvent(contextMenuEvent); NS_ASSERTION(NS_SUCCEEDED(result), "cannot DispatchWindowEvent"); @@ -1140,7 +1142,7 @@ PRBool nsMacEventHandler::HandleKeyEvent(EventRecord& aOSEvent) case autoKey: { - nsKeyEvent keyPressEvent(NS_KEY_PRESS); + nsKeyEvent keyPressEvent(PR_TRUE, NS_KEY_PRESS, nsnull); InitializeKeyEvent(keyPressEvent, aOSEvent, focusedWidget, NS_KEY_PRESS); result = focusedWidget->DispatchWindowEvent(keyPressEvent); break; @@ -1207,7 +1209,7 @@ PRBool nsMacEventHandler::HandleUKeyEvent(const PRUnichar* text, long charCount, // simulate key down event if this isn't an autoKey event if (aOSEvent.what == keyDown) { - nsKeyEvent keyDownEvent(NS_KEY_DOWN); + nsKeyEvent keyDownEvent(PR_TRUE, NS_KEY_DOWN, nsnull); InitializeKeyEvent(keyDownEvent, aOSEvent, focusedWidget, NS_KEY_DOWN, &isCharacter, PR_FALSE); result = focusedWidget->DispatchWindowEvent(keyDownEvent); NS_ASSERTION(NS_SUCCEEDED(result), "cannot DispatchWindowEvent keydown"); @@ -1221,7 +1223,7 @@ PRBool nsMacEventHandler::HandleUKeyEvent(const PRUnichar* text, long charCount, } // simulate key press events - nsKeyEvent keyPressEvent(NS_KEY_PRESS); + nsKeyEvent keyPressEvent(PR_TRUE, NS_KEY_PRESS, nsnull); InitializeKeyEvent(keyPressEvent, aOSEvent, focusedWidget, NS_KEY_PRESS, &isCharacter, PR_FALSE); if (isCharacter) @@ -1255,7 +1257,7 @@ PRBool nsMacEventHandler::HandleUKeyEvent(const PRUnichar* text, long charCount, // before we dispatch a key, check if it's the context menu key. // If so, send a context menu event instead. if ( IsContextMenuKey(keyPressEvent) ) { - nsMouseEvent contextMenuEvent; + nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); ConvertKeyEventToContextMenuEvent(&keyPressEvent, &contextMenuEvent); result = focusedWidget->DispatchWindowEvent(contextMenuEvent); NS_ASSERTION(NS_SUCCEEDED(result), "cannot DispatchWindowEvent"); @@ -1534,7 +1536,7 @@ PRBool nsMacEventHandler::HandleMouseDownEvent(EventRecord& aOSEvent) if ( ignoreClickInContent ) break; - nsMouseEvent mouseEvent; + nsMouseEvent mouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); PRUint32 mouseButton = NS_MOUSE_LEFT_BUTTON_DOWN; if ( aOSEvent.modifiers & controlKey ) mouseButton = NS_MOUSE_RIGHT_BUTTON_DOWN; @@ -1554,8 +1556,9 @@ PRBool nsMacEventHandler::HandleMouseDownEvent(EventRecord& aOSEvent) { // set the activation and focus on the widget hit, if it accepts it { - nsMouseEvent mouseActivateEvent; - ConvertOSEventToMouseEvent(aOSEvent, mouseActivateEvent, NS_MOUSE_ACTIVATE); + nsMouseEvent mouseActivateEvent(PR_TRUE, 0, nsnull, + nsMouseEvent::eReal); + ConvertOSEventToMouseEvent(aOSEvent, mouseActivateEvent, NS_MOUSE_ACTIVATE); widgetHit->DispatchMouseEvent(mouseActivateEvent); } @@ -1565,7 +1568,8 @@ PRBool nsMacEventHandler::HandleMouseDownEvent(EventRecord& aOSEvent) // if we're a control-click, send in an additional NS_CONTEXTMENU event // after the mouse down. if ( mouseButton == NS_MOUSE_RIGHT_BUTTON_DOWN ) { - nsMouseEvent contextMenuEvent; + nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, + nsMouseEvent::eReal); ConvertOSEventToMouseEvent(aOSEvent, contextMenuEvent, NS_CONTEXTMENU); contextMenuEvent.isControl = PR_FALSE; widgetHit->DispatchMouseEvent(contextMenuEvent); @@ -1613,7 +1617,7 @@ PRBool nsMacEventHandler::HandleMouseUpEvent( { PRBool retVal = PR_FALSE; - nsMouseEvent mouseEvent; + nsMouseEvent mouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); PRUint32 mouseButton = NS_MOUSE_LEFT_BUTTON_UP; // We've hacked our events to include the button. @@ -1661,7 +1665,7 @@ PRBool nsMacEventHandler::HandleMouseMoveEvent( EventRecord& aOSEvent ) PRBool retVal = PR_FALSE; - nsMouseEvent mouseEvent; + nsMouseEvent mouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); ConvertOSEventToMouseEvent(aOSEvent, mouseEvent, NS_MOUSE_MOVE); if (lastWidgetHit) { @@ -2468,7 +2472,8 @@ nsresult nsMacEventHandler::HandleUnicodeGetSelectedText(nsAString& outString) if (!focusedWidget) focusedWidget = mTopLevelWidget; - nsReconversionEvent reconversionEvent(NS_RECONVERSION_QUERY, focusedWidget); + nsReconversionEvent reconversionEvent(PR_TRUE, NS_RECONVERSION_QUERY, + focusedWidget); reconversionEvent.time = PR_IntervalNow(); nsresult res = focusedWidget->DispatchWindowEvent(reconversionEvent); @@ -2508,7 +2513,8 @@ nsresult nsMacEventHandler::HandleStartComposition(void) // // create the nsCompositionEvent // - nsCompositionEvent compositionEvent(NS_COMPOSITION_START, focusedWidget); + nsCompositionEvent compositionEvent(PR_TRUE, NS_COMPOSITION_START, + focusedWidget); compositionEvent.time = PR_IntervalNow(); nsresult res = focusedWidget->DispatchWindowEvent(compositionEvent); @@ -2545,7 +2551,8 @@ nsresult nsMacEventHandler::HandleEndComposition(void) // // create the nsCompositionEvent // - nsCompositionEvent compositionEvent(NS_COMPOSITION_END, focusedWidget); + nsCompositionEvent compositionEvent(PR_TRUE, NS_COMPOSITION_END, + focusedWidget); compositionEvent.time = PR_IntervalNow(); return(focusedWidget->DispatchWindowEvent(compositionEvent)); @@ -2608,7 +2615,7 @@ nsresult nsMacEventHandler::HandleTextEvent(PRUint32 textRangeCount, nsTextRange // // create the nsTextEvent // - nsTextEvent textEvent(NS_TEXT_TEXT, focusedWidget); + nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, focusedWidget); textEvent.time = PR_IntervalNow(); textEvent.theText = mIMECompositionStr->get(); textEvent.rangeCount = textRangeCount; diff --git a/widget/src/mac/nsMacWindow.cpp b/widget/src/mac/nsMacWindow.cpp index 32a27986de1e..a07df3555584 100644 --- a/widget/src/mac/nsMacWindow.cpp +++ b/widget/src/mac/nsMacWindow.cpp @@ -1694,7 +1694,7 @@ nsMacWindow::Idle() NS_IMETHODIMP nsMacWindow::ComeToFront() { - nsZLevelEvent event(NS_SETZLEVEL, this); + nsZLevelEvent event(PR_TRUE, NS_SETZLEVEL, this); event.point.x = mBounds.x; event.point.y = mBounds.y; diff --git a/widget/src/mac/nsMenuBarX.cpp b/widget/src/mac/nsMenuBarX.cpp index 3777029a3f67..813bab7dc5c2 100644 --- a/widget/src/mac/nsMenuBarX.cpp +++ b/widget/src/mac/nsMenuBarX.cpp @@ -492,7 +492,7 @@ nsMenuBarX::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWin nsAutoString menuIDstring; menu->GetAttr(kNameSpaceID_None, nsWidgetAtoms::id, menuIDstring); if ( menuIDstring.EqualsLiteral("menu_Help") ) { - nsMenuEvent event; + nsMenuEvent event(PR_TRUE, 0, nsnull); MenuHandle handle = nsnull; event.mCommand = (unsigned int) handle; nsCOMPtr listener(do_QueryInterface(pnsMenu)); @@ -970,7 +970,7 @@ MenuHelpersX::DispatchCommandTo(nsIWeakReference* aDocShellWeakRef, MenuHelpersX::DocShellToPresContext(docShell, getter_AddRefs(presContext)); nsEventStatus status = nsEventStatus_eConsumeNoDefault; - nsMouseEvent event(NS_XUL_COMMAND); + nsMouseEvent event(PR_TRUE, NS_XUL_COMMAND, nsnull, nsMouseEvent::eReal); // FIXME: Should probably figure out how to init this with the actual // pressed keys, but this is a big old edge case anyway. -dwh diff --git a/widget/src/mac/nsMenuX.cpp b/widget/src/mac/nsMenuX.cpp index c99613ad7879..cedc7d891749 100644 --- a/widget/src/mac/nsMenuX.cpp +++ b/widget/src/mac/nsMenuX.cpp @@ -752,7 +752,7 @@ static pascal OSStatus MyMenuEventHandler(EventHandlerCallRef myHandler, EventRe if (listener) { MenuRef menuRef; ::GetEventParameter(event, kEventParamDirectObject, typeMenuRef, NULL, sizeof(menuRef), NULL, &menuRef); - nsMenuEvent menuEvent(NS_MENU_SELECTED); + nsMenuEvent menuEvent(PR_TRUE, NS_MENU_SELECTED, nsnull); menuEvent.time = PR_IntervalNow(); menuEvent.mCommand = (PRUint32) menuRef; if (kind == kEventMenuOpening) { @@ -984,7 +984,8 @@ PRBool nsMenuX::OnCreate() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWING); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWING, nsnull, + nsMouseEvent::eReal); nsCOMPtr popupContent; GetMenuPopupContent(getter_AddRefs(popupContent)); @@ -1066,7 +1067,7 @@ PRBool nsMenuX::OnCreated() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_SHOWN); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_SHOWN, nsnull, nsMouseEvent::eReal); nsCOMPtr popupContent; GetMenuPopupContent(getter_AddRefs(popupContent)); @@ -1102,7 +1103,8 @@ nsMenuX::OnDestroy() return PR_TRUE; nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_HIDING); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDING, nsnull, + nsMouseEvent::eReal); nsCOMPtr docShell = do_QueryReferent(mDocShellWeakRef); if (!docShell) { @@ -1132,7 +1134,8 @@ PRBool nsMenuX::OnDestroyed() { nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_POPUP_HIDDEN); + nsMouseEvent event(PR_TRUE, NS_XUL_POPUP_HIDDEN, nsnull, + nsMouseEvent::eReal); nsCOMPtr docShell = do_QueryReferent(mDocShellWeakRef); if (!docShell) { diff --git a/widget/src/mac/nsWindow.cpp b/widget/src/mac/nsWindow.cpp index 44f5ac5a3041..6c836500fb50 100644 --- a/widget/src/mac/nsWindow.cpp +++ b/widget/src/mac/nsWindow.cpp @@ -1681,7 +1681,7 @@ void nsWindow::UpdateWidget(nsRect& aRect, nsIRenderingContext* aContext) return; // initialize the paint event - nsPaintEvent paintEvent(NS_PAINT, this); + nsPaintEvent paintEvent(PR_TRUE, NS_PAINT, this); paintEvent.renderingContext = aContext; // nsPaintEvent paintEvent.rect = &aRect; @@ -1949,7 +1949,7 @@ PRBool nsWindow::DispatchMouseEvent(nsMouseEvent &aEvent) PRBool nsWindow::ReportDestroyEvent() { // nsEvent - nsGUIEvent moveEvent(NS_DESTROY, this); + nsGUIEvent moveEvent(PR_TRUE, NS_DESTROY, this); moveEvent.message = NS_DESTROY; moveEvent.time = PR_IntervalNow(); @@ -1964,7 +1964,7 @@ PRBool nsWindow::ReportDestroyEvent() PRBool nsWindow::ReportMoveEvent() { // nsEvent - nsGUIEvent moveEvent(NS_MOVE, this); + nsGUIEvent moveEvent(PR_TRUE, NS_MOVE, this); moveEvent.point.x = mBounds.x; moveEvent.point.y = mBounds.y; moveEvent.time = PR_IntervalNow(); @@ -1980,7 +1980,7 @@ PRBool nsWindow::ReportMoveEvent() PRBool nsWindow::ReportSizeEvent() { // nsEvent - nsSizeEvent sizeEvent(NS_SIZE, this); + nsSizeEvent sizeEvent(PR_TRUE, NS_SIZE, this); sizeEvent.time = PR_IntervalNow(); // nsSizeEvent diff --git a/widget/src/os2/nsFrameWindow.cpp b/widget/src/os2/nsFrameWindow.cpp index 16216d20e3f1..719ab67c3b7a 100644 --- a/widget/src/os2/nsFrameWindow.cpp +++ b/widget/src/os2/nsFrameWindow.cpp @@ -374,7 +374,7 @@ MRESULT nsFrameWindow::FrameMessage( ULONG msg, MPARAM mp1, MPARAM mp2) } if (pSwp->fl & (SWP_MAXIMIZE | SWP_MINIMIZE | SWP_RESTORE)) { - nsSizeModeEvent event(NS_SIZEMODE, this); + nsSizeModeEvent event(PR_TRUE, NS_SIZEMODE, this); if (pSwp->fl & SWP_MAXIMIZE) event.mSizeMode = nsSizeMode_Maximized; else if (pSwp->fl & SWP_MINIMIZE) diff --git a/widget/src/os2/nsWindow.cpp b/widget/src/os2/nsWindow.cpp index 792a7a1ca407..56849a2a6b7f 100644 --- a/widget/src/os2/nsWindow.cpp +++ b/widget/src/os2/nsWindow.cpp @@ -532,7 +532,7 @@ PRBool nsWindow::DispatchWindowEvent(nsGUIEvent*event, nsEventStatus &aStatus) { PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg) { - nsGUIEvent event(aMsg, this); + nsGUIEvent event(PR_TRUE, aMsg, this); InitEvent(event); PRBool result = DispatchWindowEvent(&event); @@ -547,7 +547,7 @@ PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg) //------------------------------------------------------------------------- PRBool nsWindow::DispatchAppCommandEvent(PRUint32 aEventCommand) { - nsAppCommandEvent event(NS_APPCOMMAND_START, this); + nsAppCommandEvent event(PR_TRUE, NS_APPCOMMAND_START, this); InitEvent(event); event.appCommand = NS_APPCOMMAND_START + aEventCommand; @@ -2464,7 +2464,7 @@ BOOL nsWindow::CallMethod(MethodInfo *info) // PRBool nsWindow::OnKey( MPARAM mp1, MPARAM mp2) { - nsKeyEvent pressEvent; + nsKeyEvent pressEvent(PR_TRUE, 0, nsnull); USHORT fsFlags = SHORT1FROMMP(mp1); USHORT usVKey = SHORT2FROMMP(mp2); USHORT usChar = SHORT1FROMMP(mp2); @@ -2504,7 +2504,8 @@ PRBool nsWindow::OnKey( MPARAM mp1, MPARAM mp2) // have the unicode charcode in. nsPoint point(0,0); - nsKeyEvent event((fsFlags & KC_KEYUP) ? NS_KEY_UP : NS_KEY_DOWN, this); + nsKeyEvent event(PR_TRUE, (fsFlags & KC_KEYUP) ? NS_KEY_UP : NS_KEY_DOWN, + this); InitEvent( event, &point); event.keyCode = WMChar2KeyCode( mp1, mp2); event.isShift = (fsFlags & KC_SHIFT) ? PR_TRUE : PR_FALSE; @@ -2611,7 +2612,7 @@ PRBool nsWindow::OnKey( MPARAM mp1, MPARAM mp2) void nsWindow::ConstrainZLevel(HWND *aAfter) { - nsZLevelEvent event(NS_SETZLEVEL, this); + nsZLevelEvent event(PR_TRUE, NS_SETZLEVEL, this); nsWindow *aboveWindow = 0; InitEvent(event); @@ -2659,7 +2660,7 @@ PRBool nsWindow::ProcessMessage( ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &rc) //#if 0 case WM_COMMAND: // fire off menu selections { - nsMenuEvent event(NS_MENU_SELECTED, this); + nsMenuEvent event(PR_TRUE, NS_MENU_SELECTED, this); event.mCommand = SHORT1FROMMP(mp1); InitEvent(event); result = DispatchWindowEvent(&event); @@ -2684,7 +2685,7 @@ PRBool nsWindow::ProcessMessage( ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &rc) #if 0 // Tooltips appear to be gone case WMU_SHOW_TOOLTIP: { - nsTooltipEvent event(NS_SHOW_TOOLTIP, this); + nsTooltipEvent event(PR_TRUE, NS_SHOW_TOOLTIP, this); InitEvent( event ); event.tipIndex = LONGFROMMP(mp1); result = DispatchWindowEvent(&event); @@ -2761,7 +2762,7 @@ PRBool nsWindow::ProcessMessage( ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &rc) case WM_QUERYCONVERTPOS: { PRECTL pCursorRect = (PRECTL)mp1; - nsCompositionEvent event(NS_COMPOSITION_QUERY, this); + nsCompositionEvent event(PR_TRUE, NS_COMPOSITION_QUERY, this); nsPoint point; point.x = 0; point.y = 0; @@ -2850,7 +2851,7 @@ PRBool nsWindow::ProcessMessage( ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &rc) (WinQuerySysValue(HWND_DESKTOP, SV_CYMOTIONSTART) / 2)) isCopy = TRUE; - nsKeyEvent event(NS_KEY_PRESS, this); + nsKeyEvent event(PR_TRUE, NS_KEY_PRESS, this); nsPoint point(0,0); InitEvent( event, &point); @@ -3163,7 +3164,7 @@ void nsWindow::OnDestroy() PRBool nsWindow::OnMove(PRInt32 aX, PRInt32 aY) { // Params here are in XP-space for the desktop - nsGUIEvent event(NS_MOVE, this); + nsGUIEvent event(PR_TRUE, NS_MOVE, this); InitEvent( event); event.point.x = aX; event.point.y = aY; @@ -3214,7 +3215,7 @@ PRBool nsWindow::OnPaint() // call the event callback if (mEventCallback) { - nsPaintEvent event(NS_PAINT, this); + nsPaintEvent event(PR_TRUE, NS_PAINT, this); InitEvent(event); // build XP rect from in-ex window rect @@ -3312,7 +3313,7 @@ PRBool nsWindow::DispatchResizeEvent( PRInt32 aX, PRInt32 aY) { PRBool result; // call the event callback - nsSizeEvent event(NS_SIZE, this); + nsSizeEvent event(PR_TRUE, NS_SIZE, this); nsRect rect( 0, 0, aX, aY); InitEvent( event); @@ -3338,7 +3339,7 @@ PRBool nsWindow::DispatchMouseEvent( PRUint32 aEventType, MPARAM mp1, MPARAM mp2 return result; } - nsMouseEvent event(aEventType, this); + nsMouseEvent event(PR_TRUE, aEventType, this, nsMouseEvent::eReal); // Mouse leave & enter messages don't seem to have position built in. if( aEventType && aEventType != NS_MOUSE_ENTER && aEventType != NS_MOUSE_EXIT) @@ -3563,7 +3564,7 @@ PRBool nsWindow::DispatchFocus(PRUint32 aEventType, PRBool isMozWindowTakingFocu { // call the event callback if (mEventCallback) { - nsFocusEvent event(aEventType, this); + nsFocusEvent event(PR_TRUE, aEventType, this); InitEvent(event); //focus and blur event should go to their base widget loc, not current mouse pos @@ -3612,7 +3613,7 @@ PRBool nsWindow::OnScroll( ULONG msgid, MPARAM mp1, MPARAM mp2) PRBool nsWindow::OnVScroll( MPARAM mp1, MPARAM mp2) { if (nsnull != mEventCallback) { - nsMouseScrollEvent scrollEvent(NS_MOUSE_SCROLL, this); + nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this); InitEvent(scrollEvent); scrollEvent.isShift = WinIsKeyDown( VK_SHIFT); scrollEvent.isControl = WinIsKeyDown( VK_CTRL); @@ -3647,7 +3648,7 @@ PRBool nsWindow::OnVScroll( MPARAM mp1, MPARAM mp2) PRBool nsWindow::OnHScroll( MPARAM mp1, MPARAM mp2) { if (nsnull != mEventCallback) { - nsMouseScrollEvent scrollEvent(NS_MOUSE_SCROLL, this); + nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this); InitEvent(scrollEvent); scrollEvent.isShift = WinIsKeyDown( VK_SHIFT); scrollEvent.isControl = WinIsKeyDown( VK_CTRL); diff --git a/widget/src/photon/nsWidget.cpp b/widget/src/photon/nsWidget.cpp index 503569449874..f580fd3591f4 100644 --- a/widget/src/photon/nsWidget.cpp +++ b/widget/src/photon/nsWidget.cpp @@ -373,7 +373,7 @@ PRBool nsWidget::OnResize( nsRect &aRect ) { // call the event callback if( mEventCallback ) { - nsSizeEvent event; + nsSizeEvent event(PR_TRUE, 0, nsnull); InitEvent(event, NS_SIZE); @@ -398,7 +398,7 @@ PRBool nsWidget::OnResize( nsRect &aRect ) { // Move //------ PRBool nsWidget::OnMove( PRInt32 aX, PRInt32 aY ) { - nsGUIEvent event; + nsGUIEvent event(PR_TRUE, 0, nsnull); InitEvent(event, NS_MOVE); event.point.x = aX; event.point.y = aY; @@ -893,11 +893,11 @@ PRBool nsWidget::DispatchKeyEvent( PhKeyEvent_t *aPhKeyEvent ) { w->AddRef(); if (aPhKeyEvent->key_flags & Pk_KF_Key_Down) { - nsKeyEvent keyDownEvent(NS_KEY_DOWN, w); + nsKeyEvent keyDownEvent(PR_TRUE, NS_KEY_DOWN, w); InitKeyEvent(aPhKeyEvent, keyDownEvent); PRBool noDefault = w->OnKey(keyDownEvent); - nsKeyEvent keyPressEvent(NS_KEY_PRESS, w); + nsKeyEvent keyPressEvent(PR_TRUE, NS_KEY_PRESS, w); InitKeyPressEvent(aPhKeyEvent, keyPressEvent); if (noDefault) { // If prevent default set for keydown, do same for keypress keyPressEvent.flags = NS_EVENT_FLAG_NO_DEFAULT; @@ -905,12 +905,12 @@ PRBool nsWidget::DispatchKeyEvent( PhKeyEvent_t *aPhKeyEvent ) { w->OnKey(keyPressEvent); } else if (aPhKeyEvent->key_flags & Pk_KF_Key_Repeat) { - nsKeyEvent keyPressEvent(NS_KEY_PRESS, w); + nsKeyEvent keyPressEvent(PR_TRUE, NS_KEY_PRESS, w); InitKeyPressEvent(aPhKeyEvent, keyPressEvent); w->OnKey(keyPressEvent); } else if (PkIsKeyDown(aPhKeyEvent->key_flags) == 0) { - nsKeyEvent kevent(NS_KEY_UP, w); + nsKeyEvent kevent(PR_TRUE, NS_KEY_UP, w); InitKeyEvent(aPhKeyEvent, kevent); w->OnKey(kevent); } @@ -987,7 +987,7 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn case Ph_EV_PTR_MOTION_NOBUTTON: { PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); - nsMouseEvent theMouseEvent; + nsMouseEvent theMouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); if( ptrev ) { @@ -1006,7 +1006,7 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn { PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); - nsMouseEvent theMouseEvent; + nsMouseEvent theMouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); /* there should be no reason to do this - mozilla should figure out how to call SetFocus */ /* this though fixes the problem with the plugins capturing the focus */ @@ -1028,7 +1028,8 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn // if we're a right-button-up we're trying to popup a context menu. send that event to gecko also if( ptrev->buttons & Ph_BUTTON_MENU ) { - nsMouseEvent contextMenuEvent; + nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, + nsMouseEvent::eReal); InitMouseEvent( ptrev, this, contextMenuEvent, NS_CONTEXTMENU ); result = DispatchMouseEvent( contextMenuEvent ); } @@ -1040,7 +1041,8 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn case Ph_EV_BUT_RELEASE: { PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); - nsMouseEvent theMouseEvent; + nsMouseEvent theMouseEvent(PR_TRUE, 0, nsnull, + nsMouseEvent::eReal); // Update the current input group for clipboard mouse events // (mozilla only). Note that for mozserver the mouse based @@ -1074,7 +1076,7 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn case Ph_EV_PTR_MOTION_BUTTON: { PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); - nsMouseEvent theMouseEvent; + nsMouseEvent theMouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal; if( ptrev ) { @@ -1106,13 +1108,14 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn case Ph_EV_DRAG: { - nsMouseEvent theMouseEvent; + nsMouseEvent theMouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); switch(event->subtype) { case Ph_EV_DRAG_COMPLETE: { - nsMouseEvent theMouseEvent; + nsMouseEvent theMouseEvent(PR_TRUE, 0, nsnull, + nsMouseEvent::eReal); PhPointerEvent_t* ptrev2 = (PhPointerEvent_t*) PhGetData( event ); ScreenToWidgetPos( ptrev2->pos ); InitMouseEvent(ptrev2, this, theMouseEvent, NS_MOUSE_LEFT_BUTTON_UP ); @@ -1149,7 +1152,8 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn if( evtype != 0 ) { PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); - nsMouseEvent theMouseEvent; + nsMouseEvent theMouseEvent(PR_TRUE, 0, nsnull, + nsMouseEvent::eReal); ScreenToWidgetPos( ptrev->pos ); InitMouseEvent( ptrev, this, theMouseEvent, evtype ); result = DispatchMouseEvent( theMouseEvent ); @@ -1251,7 +1255,7 @@ void nsWidget::ProcessDrag( PhEvent_t *event, PRUint32 aEventType, PhPoint_t *po void nsWidget::DispatchDragDropEvent( PhEvent_t *phevent, PRUint32 aEventType, PhPoint_t *pos ) { nsEventStatus status; - nsMouseEvent event; + nsMouseEvent event(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); InitEvent( event, aEventType ); diff --git a/widget/src/photon/nsWidget.h b/widget/src/photon/nsWidget.h index 2620cb3f355f..333cf99e2f4f 100644 --- a/widget/src/photon/nsWidget.h +++ b/widget/src/photon/nsWidget.h @@ -251,7 +251,7 @@ public: PRBool DispatchMouseEvent(nsMouseEvent& aEvent); inline PRBool DispatchStandardEvent(PRUint32 aMsg) { - nsGUIEvent event; + nsGUIEvent event(PR_TRUE, 0, nsnull); InitEvent(event, aMsg); return DispatchWindowEvent(&event); } diff --git a/widget/src/photon/nsWindow.cpp b/widget/src/photon/nsWindow.cpp index e7387e2efebb..81832b80d326 100644 --- a/widget/src/photon/nsWindow.cpp +++ b/widget/src/photon/nsWindow.cpp @@ -600,7 +600,7 @@ NS_IMETHODIMP nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint) } if( mIsToplevel || mListenForResizes ) { - nsSizeEvent sevent; + nsSizeEvent sevent(PR_TRUE, 0, nsnull); sevent.message = NS_SIZE; sevent.widget = this; @@ -631,7 +631,7 @@ int nsWindow::WindowWMHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t NS_ADDREF(win); // dispatch an "onclose" event. to delete immediately, call win->Destroy() - nsGUIEvent event; + nsGUIEvent event(PR_TRUE, 0, nsnull); nsEventStatus status; event.message = NS_XUL_CLOSE; @@ -671,7 +671,7 @@ void nsWindow::RawDrawFunc( PtWidget_t * pWidget, PhTile_t * damage ) nsWindow * pWin = (nsWindow*) GetInstance( pWidget ); nsresult result; PhTile_t * dmg = NULL; - nsPaintEvent pev; + nsPaintEvent pev(PR_TRUE, 0, nsnull); PhRect_t extent; if( !pWin || !pWin->mContext ) return; diff --git a/widget/src/qt/nsCommonWidget.cpp b/widget/src/qt/nsCommonWidget.cpp index deee0003a904..45c3c9b9c0d0 100644 --- a/widget/src/qt/nsCommonWidget.cpp +++ b/widget/src/qt/nsCommonWidget.cpp @@ -822,7 +822,7 @@ nsCommonWidget::CaptureRollupEvents(nsIRollupListener*, PRBool, PRBool) void nsCommonWidget::DispatchGotFocusEvent(void) { - nsGUIEvent event(NS_GOTFOCUS, this); + nsGUIEvent event(PR_TRUE, NS_GOTFOCUS, this); nsEventStatus status; DispatchEvent(&event, status); } @@ -830,7 +830,7 @@ nsCommonWidget::DispatchGotFocusEvent(void) void nsCommonWidget::DispatchLostFocusEvent(void) { - nsGUIEvent event(NS_LOSTFOCUS, this); + nsGUIEvent event(PR_TRUE, NS_LOSTFOCUS, this); nsEventStatus status; DispatchEvent(&event, status); } @@ -838,7 +838,7 @@ nsCommonWidget::DispatchLostFocusEvent(void) void nsCommonWidget::DispatchActivateEvent(void) { - nsGUIEvent event(NS_ACTIVATE, this); + nsGUIEvent event(PR_TRUE, NS_ACTIVATE, this); nsEventStatus status; DispatchEvent(&event, status); } @@ -846,7 +846,7 @@ nsCommonWidget::DispatchActivateEvent(void) void nsCommonWidget::DispatchDeactivateEvent(void) { - nsGUIEvent event(NS_DEACTIVATE, this); + nsGUIEvent event(PR_TRUE, NS_DEACTIVATE, this); nsEventStatus status; DispatchEvent(&event, status); } @@ -854,7 +854,7 @@ nsCommonWidget::DispatchDeactivateEvent(void) void nsCommonWidget::DispatchResizeEvent(nsRect &aRect, nsEventStatus &aStatus) { - nsSizeEvent event(NS_SIZE, this); + nsSizeEvent event(PR_TRUE, NS_SIZE, this); event.windowSize = &aRect; event.point.x = aRect.x; @@ -884,7 +884,7 @@ nsCommonWidget::mousePressEvent(QMouseEvent *e) break; } - nsMouseEvent event(eventType, this); + nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); InitMouseEvent(&event, e, 1); @@ -893,7 +893,8 @@ nsCommonWidget::mousePressEvent(QMouseEvent *e) // right menu click on linux should also pop up a context menu if (eventType == NS_MOUSE_RIGHT_BUTTON_DOWN) { - nsMouseEvent contextMenuEvent(NS_CONTEXTMENU, this); + nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this, + nsMouseEvent::eReal); InitMouseEvent(&contextMenuEvent, e, 1); DispatchEvent(&contextMenuEvent, status); } @@ -919,7 +920,7 @@ nsCommonWidget::mouseReleaseEvent(QMouseEvent *e) break; } - nsMouseEvent event(eventType, this); + nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); InitMouseEvent(&event, e, 1); @@ -946,7 +947,7 @@ nsCommonWidget::mouseDoubleClickEvent(QMouseEvent *e) break; } - nsMouseEvent event(eventType, this); + nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); InitMouseEvent(&event, e, 2); //pressed @@ -958,7 +959,7 @@ nsCommonWidget::mouseDoubleClickEvent(QMouseEvent *e) bool nsCommonWidget::mouseMoveEvent(QMouseEvent *e) { - nsMouseEvent event(NS_MOUSE_MOVE, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, this, nsMouseEvent::eReal); InitMouseEvent(&event, e, 0); nsEventStatus status; @@ -969,7 +970,7 @@ nsCommonWidget::mouseMoveEvent(QMouseEvent *e) bool nsCommonWidget::wheelEvent(QWheelEvent *e) { - nsMouseScrollEvent nsEvent(NS_MOUSE_SCROLL, this); + nsMouseScrollEvent nsEvent(PR_TRUE, NS_MOUSE_SCROLL, this); InitMouseWheelEvent(&nsEvent, e); @@ -991,14 +992,14 @@ nsCommonWidget::keyPressEvent(QKeyEvent *e) // release. gtk2 already filters the extra key release events for // us. - nsKeyEvent pressEvent(NS_KEY_PRESS, this); + nsKeyEvent pressEvent(PR_TRUE, NS_KEY_PRESS, this); InitKeyEvent(&pressEvent, e); pressEvent.charCode = (PRInt32)e->text()[0].unicode(); if (!e->isAutoRepeat()) { // send the key down event - nsKeyEvent downEvent(NS_KEY_DOWN, this); + nsKeyEvent downEvent(PR_TRUE, NS_KEY_DOWN, this); InitKeyEvent(&downEvent, e); DispatchEvent(&downEvent, status); if (ignoreEvent(status)) { // If prevent default on keydown, do same for keypress @@ -1009,7 +1010,7 @@ nsCommonWidget::keyPressEvent(QKeyEvent *e) // before we dispatch a key, check if it's the context menu key. // If so, send a context menu key event instead. if (isContextMenuKey(pressEvent)) { - nsMouseEvent contextMenuEvent; + nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); keyEventToContextMenuEvent(&pressEvent, &contextMenuEvent); DispatchEvent(&contextMenuEvent, status); } @@ -1024,7 +1025,7 @@ nsCommonWidget::keyPressEvent(QKeyEvent *e) bool nsCommonWidget::keyReleaseEvent(QKeyEvent *e) { - nsKeyEvent event(NS_KEY_UP, this); + nsKeyEvent event(PR_TRUE, NS_KEY_UP, this); InitKeyEvent(&event, e); @@ -1067,7 +1068,7 @@ nsCommonWidget::focusOutEvent(QFocusEvent *) bool nsCommonWidget::enterEvent(QEvent *) { - nsMouseEvent event(NS_MOUSE_ENTER, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_ENTER, this); QPoint pt = QCursor::pos(); @@ -1082,7 +1083,7 @@ nsCommonWidget::enterEvent(QEvent *) bool nsCommonWidget::leaveEvent(QEvent *aEvent) { - nsMouseEvent event(NS_MOUSE_EXIT, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_EXIT, this); QPoint pt = QCursor::pos(); @@ -1110,7 +1111,7 @@ nsCommonWidget::paintEvent(QPaintEvent *e) nsCOMPtr rc = getter_AddRefs(GetRenderingContext()); // Generate XPFE paint event - nsPaintEvent event(NS_PAINT, this); + nsPaintEvent event(PR_TRUE, NS_PAINT, this); event.point.x = 0; event.point.y = 0; event.rect = ▭ @@ -1156,7 +1157,7 @@ nsCommonWidget::moveEvent(QMoveEvent *e) #endif } - nsGUIEvent event(NS_MOVE, this); + nsGUIEvent event(PR_TRUE, NS_MOVE, this); event.point.x = pos.x(); event.point.y = pos.y(); @@ -1193,7 +1194,7 @@ nsCommonWidget::resizeEvent(QResizeEvent *e) bool nsCommonWidget::closeEvent(QCloseEvent *) { - nsGUIEvent event(NS_XUL_CLOSE, this); + nsGUIEvent event(PR_TRUE, NS_XUL_CLOSE, this); event.point.x = 0; event.point.y = 0; @@ -1272,7 +1273,7 @@ nsCommonWidget::showEvent(QShowEvent *) nsCOMPtr rc = getter_AddRefs(GetRenderingContext()); // Generate XPFE paint event - nsPaintEvent event(NS_PAINT, this); + nsPaintEvent event(PR_TRUE, NS_PAINT, this); event.point.x = 0; event.point.y = 0; event.rect = ▭ diff --git a/widget/src/qt/nsScrollbar.cpp b/widget/src/qt/nsScrollbar.cpp index ffb3e5291d97..c2257100ffec 100644 --- a/widget/src/qt/nsScrollbar.cpp +++ b/widget/src/qt/nsScrollbar.cpp @@ -60,10 +60,8 @@ void nsQScrollBar::slotValueChanged(int aValue) void nsQScrollBar::ScrollBarMoved(int aMessage,int aValue) { - nsScrollbarEvent nsEvent; + nsScrollbarEvent nsEvent(PR_TRUE, aMessage, nsnull); - nsEvent.message = aMessage; - nsEvent.widget = 0; nsEvent.eventStructType = NS_SCROLLBAR_EVENT; nsEvent.position = aValue; diff --git a/widget/src/windows/nsNativeDragTarget.cpp b/widget/src/windows/nsNativeDragTarget.cpp index 411fa97ed15b..6034e8b6911c 100644 --- a/widget/src/windows/nsNativeDragTarget.cpp +++ b/widget/src/windows/nsNativeDragTarget.cpp @@ -184,7 +184,7 @@ void nsNativeDragTarget::DispatchDragDropEvent(PRUint32 aEventType, POINTL aPT) { nsEventStatus status; - nsMouseEvent event(aEventType, mWindow); + nsMouseEvent event(PR_TRUE, aEventType, mWindow, nsMouseEvent::eReal); nsWindow * win = NS_STATIC_CAST(nsWindow *, mWindow); win->InitEvent(event); diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 2fc63c8f9904..9c28c83adfd6 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -1214,7 +1214,7 @@ PRBool nsWindow::DispatchWindowEvent(nsGUIEvent* event, nsEventStatus &aStatus) PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg) { - nsGUIEvent event(aMsg, this); + nsGUIEvent event(PR_TRUE, aMsg, this); InitEvent(event); PRBool result = DispatchWindowEvent(&event); @@ -1229,7 +1229,7 @@ PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg) //------------------------------------------------------------------------- PRBool nsWindow::DispatchAppCommandEvent(PRUint32 aEventCommand) { - nsAppCommandEvent event(NS_APPCOMMAND_START, this); + nsAppCommandEvent event(PR_TRUE, NS_APPCOMMAND_START, this); InitEvent(event); event.appCommand = NS_APPCOMMAND_START + aEventCommand; @@ -3433,7 +3433,7 @@ UINT nsWindow::MapFromNativeToDOM(UINT aNativeKeyCode) PRBool nsWindow::DispatchKeyEvent(PRUint32 aEventType, WORD aCharCode, UINT aVirtualCharCode, LPARAM aKeyData, PRUint32 aFlags) { - nsKeyEvent event(aEventType, this); + nsKeyEvent event(PR_TRUE, aEventType, this); nsPoint point(0, 0); InitEvent(event, &point); // this add ref's event.widget @@ -3728,7 +3728,7 @@ BOOL nsWindow::OnChar(UINT charCode, PRUint32 aFlags) void nsWindow::ConstrainZLevel(HWND *aAfter) { - nsZLevelEvent event(NS_SETZLEVEL, this); + nsZLevelEvent event(PR_TRUE, NS_SETZLEVEL, this); nsWindow *aboveWindow = 0; InitEvent(event); @@ -4267,13 +4267,13 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT { WORD wNotifyCode = HIWORD(wParam); // notification code if ((CBN_SELENDOK == wNotifyCode) || (CBN_SELENDCANCEL == wNotifyCode)) { // Combo box change - nsGUIEvent event(NS_CONTROL_CHANGE, this); + nsGUIEvent event(PR_TRUE, NS_CONTROL_CHANGE, this); nsPoint point(0,0); InitEvent(event, &point); // this add ref's event.widget result = DispatchWindowEvent(&event); NS_RELEASE(event.widget); } else if (wNotifyCode == 0) { // Menu selection - nsMenuEvent event(NS_MENU_SELECTED, this); + nsMenuEvent event(PR_TRUE, NS_MENU_SELECTED, this); event.mCommand = LOWORD(wParam); InitEvent(event); result = DispatchWindowEvent(&event); @@ -4661,7 +4661,8 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT mLastKeyboardLayout = gKeyboardLayout; } else { gJustGotActivate = PR_TRUE; - nsMouseEvent event(NS_MOUSE_ACTIVATE, this); + nsMouseEvent event(PR_TRUE, NS_MOUSE_ACTIVATE, this, + nsMouseEvent::eReal); InitEvent(event); event.acceptActivation = PR_TRUE; @@ -4828,7 +4829,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT pl.length = sizeof(pl); ::GetWindowPlacement(mWnd, &pl); - nsSizeModeEvent event(NS_SIZEMODE, this); + nsSizeModeEvent event(PR_TRUE, NS_SIZEMODE, this); if (pl.showCmd == SW_SHOWMAXIMIZED) event.mSizeMode = nsSizeMode_Maximized; else if (pl.showCmd == SW_SHOWMINIMIZED) @@ -5161,7 +5162,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT #endif } - nsMouseScrollEvent scrollEvent(NS_MOUSE_SCROLL, this); + nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this); scrollEvent.scrollFlags = nsMouseScrollEvent::kIsVertical; if (ulScrollLines == WHEEL_PAGESCROLL) { scrollEvent.scrollFlags |= nsMouseScrollEvent::kIsFullPage; @@ -5563,7 +5564,7 @@ PRBool nsWindow::OnMove(PRInt32 aX, PRInt32 aY) mBounds.x = aX; mBounds.y = aY; - nsGUIEvent event(NS_MOVE, this); + nsGUIEvent event(PR_TRUE, NS_MOVE, this); InitEvent(event); event.point.x = aX; event.point.y = aY; @@ -5618,7 +5619,7 @@ PRBool nsWindow::OnPaint(HDC aDC) // call the event callback if (mEventCallback) { - nsPaintEvent event(NS_PAINT, this); + nsPaintEvent event(PR_TRUE, NS_PAINT, this); InitEvent(event); @@ -5714,7 +5715,7 @@ PRBool nsWindow::OnResize(nsRect &aWindowRect) { // call the event callback if (mEventCallback) { - nsSizeEvent event(NS_SIZE, this); + nsSizeEvent event(PR_TRUE, NS_SIZE, this); InitEvent(event); event.windowSize = &aWindowRect; RECT r; @@ -5746,7 +5747,7 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, nsPoint* return result; } - nsMouseEvent event(aEventType, this); + nsMouseEvent event(PR_TRUE, aEventType, this, nsMouseEvent::eReal); if (aEventType == NS_CONTEXTMENU_KEY) { nsPoint zero(0, 0); InitEvent(event, &zero); @@ -6032,7 +6033,7 @@ PRBool nsWindow::DispatchAccessibleEvent(PRUint32 aEventType, nsIAccessible** aA *aAcc = nsnull; - nsAccessibleEvent event(aEventType, this); + nsAccessibleEvent event(PR_TRUE, aEventType, this); InitEvent(event, aPoint); event.isShift = IS_VK_DOWN(NS_VK_SHIFT); @@ -6062,7 +6063,7 @@ PRBool nsWindow::DispatchFocus(PRUint32 aEventType, PRBool isMozWindowTakingFocu { // call the event callback if (mEventCallback) { - nsFocusEvent event(aEventType, this); + nsFocusEvent event(PR_TRUE, aEventType, this); InitEvent(event); //focus and blur event should go to their base widget loc, not current mouse pos @@ -6288,7 +6289,7 @@ nsWindow::HandleTextEvent(HIMC hIMEContext,PRBool aCheckAttr) if (!sIMECompUnicode) return; - nsTextEvent event(NS_TEXT_TEXT, this); + nsTextEvent event(PR_TRUE, NS_TEXT_TEXT, this); nsPoint point(0, 0); InitEvent(event, &point); @@ -6379,7 +6380,7 @@ nsWindow::HandleStartComposition(HIMC hIMEContext) if (sIMEIsComposing) return PR_TRUE; - nsCompositionEvent event(NS_COMPOSITION_START, this); + nsCompositionEvent event(PR_TRUE, NS_COMPOSITION_START, this); nsPoint point(0, 0); CANDIDATEFORM candForm; @@ -6439,7 +6440,7 @@ void nsWindow::HandleEndComposition(void) { NS_ASSERTION(sIMEIsComposing, "conflict state"); - nsCompositionEvent event(NS_COMPOSITION_END, this); + nsCompositionEvent event(PR_TRUE, NS_COMPOSITION_END, this); nsPoint point(0, 0); if (gPinYinIMECaretCreated) @@ -7005,7 +7006,7 @@ PRBool nsWindow::OnIMEReconvert(LPARAM aData, LRESULT *oResult, PRBool aUseUnico } // Get reconversion string - nsReconversionEvent event(NS_RECONVERSION_QUERY, this); + nsReconversionEvent event(PR_TRUE, NS_RECONVERSION_QUERY, this); nsPoint point(0, 0); InitEvent(event, &point); @@ -7096,7 +7097,7 @@ PRBool nsWindow::OnIMEQueryCharPosition(LPARAM aData, LRESULT *oResult, PRBool a return PR_FALSE; } nsPoint point(0, 0); - nsQueryCaretRectEvent event(NS_QUERYCARETRECT, this); + nsQueryCaretRectEvent event(PR_TRUE, NS_QUERYCARETRECT, this); InitEvent(event, &point); DispatchWindowEvent(&event); // The active widget doesn't support this event. @@ -7407,7 +7408,7 @@ PRBool nsWindow::IMECompositionHitTest(PRUint32 aEventType, POINT * ptPos) void nsWindow::GetCompositionWindowPos(HIMC hIMC, PRUint32 aEventType, COMPOSITIONFORM *cpForm) { - nsTextEvent event; + nsTextEvent event(PR_TRUE, 0, this); POINT point; point.x = 0; point.y = 0; diff --git a/widget/src/xlib/nsAppShell.cpp b/widget/src/xlib/nsAppShell.cpp index 1a4ad6b2b999..80e8187e6485 100644 --- a/widget/src/xlib/nsAppShell.cpp +++ b/widget/src/xlib/nsAppShell.cpp @@ -592,7 +592,7 @@ nsAppShell::HandleMotionNotifyEvent(XEvent *event, nsWidget *aWidget) HandleDragMotionEvent(event, aWidget); } - nsMouseEvent mevent(NS_MOUSE_MOVE, aWidget); + nsMouseEvent mevent(PR_TRUE, NS_MOUSE_MOVE, aWidget, nsMouseEvent::eReal); XEvent aEvent; mevent.point.x = event->xmotion.x; @@ -623,7 +623,7 @@ nsAppShell::HandleButtonEvent(XEvent *event, nsWidget *aWidget) { PRUint32 eventType = 0; PRBool currentlyDragging = mDragging; - nsMouseScrollEvent scrollEvent(NS_MOUSE_SCROLL, aWidget); + nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, aWidget); PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Button event for window 0x%lx button %d type %s\n", event->xany.window, @@ -682,7 +682,7 @@ nsAppShell::HandleButtonEvent(XEvent *event, nsWidget *aWidget) break; } - nsMouseEvent mevent(eventType, aWidget); + nsMouseEvent mevent(PR_TRUE, eventType, aWidget, nsMouseEvent::eReal); mevent.isShift = mShiftDown; mevent.isControl = mCtrlDown; mevent.isAlt = mAltDown; @@ -775,7 +775,7 @@ nsAppShell::HandleConfigureNotifyEvent(XEvent *event, nsWidget *aWidget) } } - nsSizeEvent sevent(NS_SIZE, aWidget); + nsSizeEvent sevent(PR_TRUE, NS_SIZE, aWidget); sevent.windowSize = new nsRect (event->xconfigure.x, event->xconfigure.y, event->xconfigure.width, event->xconfigure.height); sevent.point.x = event->xconfigure.x; @@ -875,7 +875,7 @@ nsAppShell::HandleKeyPressEvent(XEvent *event, nsWidget *aWidget) return; } - nsKeyEvent keyEvent(NS_KEY_DOWN, focusWidget); + nsKeyEvent keyEvent(PR_TRUE, NS_KEY_DOWN, focusWidget); XComposeStatus compose; @@ -897,7 +897,7 @@ nsAppShell::HandleKeyPressEvent(XEvent *event, nsWidget *aWidget) PRBool noDefault = focusWidget->DispatchKeyEvent(keyEvent); - nsKeyEvent pressEvent(NS_KEY_PRESS, focusWidget); + nsKeyEvent pressEvent(PR_TRUE, NS_KEY_PRESS, focusWidget); pressEvent.keyCode = nsKeyCode::ConvertKeySymToVirtualKey(keysym); pressEvent.charCode = nsConvertCharCodeToUnicode(&event->xkey); pressEvent.time = event->xkey.time; @@ -948,7 +948,7 @@ nsAppShell::HandleKeyReleaseEvent(XEvent *event, nsWidget *aWidget) return; } - nsKeyEvent keyEvent(NS_KEY_UP, aWidget); + nsKeyEvent keyEvent(PR_TRUE, NS_KEY_UP, aWidget); keyEvent.keyCode = nsKeyCode::ConvertKeySymToVirtualKey(keysym); keyEvent.time = event->xkey.time; @@ -971,7 +971,7 @@ nsAppShell::HandleFocusInEvent(XEvent *event, nsWidget *aWidget) { PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("FocusIn event for window 0x%lx\n", event->xfocus.window)); - nsFocusEvent focusEvent(NS_GOTFOCUS, aWidget); + nsFocusEvent focusEvent(PR_TRUE, NS_GOTFOCUS, aWidget); NS_ADDREF(aWidget); aWidget->DispatchWindowEvent(focusEvent); @@ -983,7 +983,7 @@ nsAppShell::HandleFocusOutEvent(XEvent *event, nsWidget *aWidget) { PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("FocusOut event for window 0x%lx\n", event->xfocus.window)); - nsFocusEvent focusEvent(NS_LOSTFOCUS, aWidget); + nsFocusEvent focusEvent(PR_TRUE, NS_LOSTFOCUS, aWidget); NS_ADDREF(aWidget); aWidget->DispatchWindowEvent(focusEvent); @@ -1023,7 +1023,8 @@ nsAppShell::HandleEnterEvent(XEvent *event, nsWidget *aWidget) HandleDragEnterEvent(event, aWidget); } - nsMouseEvent enterEvent(NS_MOUSE_ENTER, aWidget); + nsMouseEvent enterEvent(PR_TRUE, NS_MOUSE_ENTER, aWidget, + nsMouseEvent::eReal); enterEvent.time = event->xcrossing.time; enterEvent.point.x = nscoord(event->xcrossing.x); @@ -1054,7 +1055,8 @@ nsAppShell::HandleLeaveEvent(XEvent *event, nsWidget *aWidget) HandleDragLeaveEvent(event, aWidget); } - nsMouseEvent leaveEvent(NS_MOUSE_EXIT, aWidget); + nsMouseEvent leaveEvent(PR_TRUE, NS_MOUSE_EXIT, aWidget, + nsMouseEvent::eReal); leaveEvent.time = event->xcrossing.time; leaveEvent.point.x = nscoord(event->xcrossing.x); @@ -1118,7 +1120,7 @@ void nsAppShell::HandleClientMessageEvent(XEvent *event, nsWidget *aWidget) void nsAppShell::HandleSelectionRequestEvent(XEvent *event, nsWidget *aWidget) { - nsGUIEvent ev(0, aWidget); + nsGUIEvent ev(PR_TRUE, 0, aWidget); ev.nativeMsg = (void *)event; @@ -1141,7 +1143,8 @@ void nsAppShell::HandleDragMotionEvent(XEvent *event, nsWidget *aWidget) { if (currentlyDragging) { dragServiceXlib->UpdatePosition(event->xmotion.x, event->xmotion.y); - nsMouseEvent mevent(NS_DRAGDROP_OVER, aWidget); + nsMouseEvent mevent(PR_TRUE, NS_DRAGDROP_OVER, aWidget, + nsMouseEvent::eReal); mevent.point.x = event->xmotion.x; mevent.point.y = event->xmotion.y; @@ -1165,7 +1168,8 @@ void nsAppShell::HandleDragEnterEvent(XEvent *event, nsWidget *aWidget) { } if (currentlyDragging) { - nsMouseEvent enterEvent(NS_DRAGDROP_ENTER, aWidget); + nsMouseEvent enterEvent(PR_TRUE, NS_DRAGDROP_ENTER, aWidget, + nsMouseEvent::eReal); enterEvent.point.x = event->xcrossing.x; enterEvent.point.y = event->xcrossing.y; @@ -1192,7 +1196,8 @@ void nsAppShell::HandleDragLeaveEvent(XEvent *event, nsWidget *aWidget) { } if (currentlyDragging) { - nsMouseEvent leaveEvent(NS_DRAGDROP_EXIT, aWidget); + nsMouseEvent leaveEvent(PR_TRUE, NS_DRAGDROP_EXIT, aWidget, + nsMouseEvent::eReal); leaveEvent.point.x = event->xcrossing.x; leaveEvent.point.y = event->xcrossing.y; @@ -1219,7 +1224,8 @@ void nsAppShell::HandleDragDropEvent(XEvent *event, nsWidget *aWidget) { } if (currentlyDragging) { - nsMouseEvent mevent(NS_DRAGDROP_DROP, aWidget); + nsMouseEvent mevent(PR_TRUE, NS_DRAGDROP_DROP, aWidget, + nsMouseEvent::eReal); mevent.point.x = event->xbutton.x; mevent.point.y = event->xbutton.y; @@ -1233,7 +1239,7 @@ void nsAppShell::HandleDragDropEvent(XEvent *event, nsWidget *aWidget) { void nsAppShell::ForwardEvent(XEvent *event, nsWidget *aWidget) { - nsGUIEvent ev(0, aWidget); + nsGUIEvent ev(PR_TRUE, 0, aWidget); ev.nativeMsg = (void *)event; aWidget->DispatchWindowEvent(ev); diff --git a/widget/src/xlib/nsWidget.cpp b/widget/src/xlib/nsWidget.cpp index ee1c8e9c22fb..c18da74af960 100644 --- a/widget/src/xlib/nsWidget.cpp +++ b/widget/src/xlib/nsWidget.cpp @@ -1064,7 +1064,7 @@ PRBool nsWidget::OnDeleteWindow(void) PRBool nsWidget::DispatchDestroyEvent(void) { PRBool result = PR_FALSE; if (nsnull != mEventCallback) { - nsGUIEvent event(NS_DESTROY, this); + nsGUIEvent event(PR_TRUE, NS_DESTROY, this); AddRef(); result = DispatchWindowEvent(event); Release(); diff --git a/widget/src/xlib/nsWindow.cpp b/widget/src/xlib/nsWindow.cpp index 486055bee2ac..deac8bc301eb 100644 --- a/widget/src/xlib/nsWindow.cpp +++ b/widget/src/xlib/nsWindow.cpp @@ -381,7 +381,7 @@ NS_IMETHODIMP nsWindow::InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSyn NS_IMETHODIMP nsWindow::SetFocus(PRBool aRaise) { nsEventStatus status; - nsFocusEvent event(NS_GOTFOCUS, this); + nsFocusEvent event(PR_TRUE, NS_GOTFOCUS, this); // nsGUIEvent eventActivate; if (mBaseWindow) @@ -396,7 +396,7 @@ NS_IMETHODIMP nsWindow::SetFocus(PRBool aRaise) DispatchEvent(&event, status); Release(); - nsGUIEvent actEvent(NS_ACTIVATE, this); + nsGUIEvent actEvent(PR_TRUE, NS_ACTIVATE, this); AddRef(); DispatchWindowEvent(actEvent); @@ -448,7 +448,7 @@ NS_IMETHODIMP nsWindow::Resize(PRInt32 aWidth, } nsWidget::Resize(aWidth, aHeight, aRepaint); - nsSizeEvent sevent(NS_SIZE, this); + nsSizeEvent sevent(PR_TRUE, NS_SIZE, this); nsRect sevent_windowSize(0, 0, aWidth, aHeight); sevent.windowSize = &sevent_windowSize; sevent.mWinWidth = aWidth; @@ -481,7 +481,7 @@ NS_IMETHODIMP nsWindow::Resize(PRInt32 aX, nsWidget::Resize(aX, aY, aWidth, aHeight, aRepaint); - nsSizeEvent sevent(NS_SIZE, this); + nsSizeEvent sevent(PR_TRUE, NS_SIZE, this); nsRect sevent_windowSize(0, 0, aWidth, aHeight); sevent.windowSize = &sevent_windowSize; sevent.mWinWidth = aWidth; @@ -548,7 +548,7 @@ nsWindow::DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, nsIRegion *aClipRegion) { if (mEventCallback) { - nsPaintEvent event(NS_PAINT, this); + nsPaintEvent event(PR_TRUE, NS_PAINT, this); nsRect rect(aX, aY, aWidth, aHeight); event.point.x = aX; event.point.y = aY; diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 77afb596aa74..4df49af8b95e 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -543,7 +543,7 @@ void nsWebShellWindow::LoadNativeMenus(nsIDOMDocument *aDOMDoc, nsCOMPtr menuListener = do_QueryInterface(pnsMenuBar); // fake event - nsMenuEvent fake; + nsMenuEvent fake(PR_TRUE, 0, nsnull); menuListener->MenuConstruct(fake, aParentWindow, menubarNode, mDocShell); } @@ -810,7 +810,8 @@ PRBool nsWebShellWindow::ExecuteCloseHandler() docViewer->GetPresContext(getter_AddRefs(presContext)); nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_XUL_CLOSE); + nsMouseEvent event(PR_TRUE, NS_XUL_CLOSE, nsnull, + nsMouseEvent::eReal); nsresult rv = globalObject->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); diff --git a/xpfe/appshell/src/nsXULWindow.cpp b/xpfe/appshell/src/nsXULWindow.cpp index 60096bc30a4f..4a6ee791f533 100644 --- a/xpfe/appshell/src/nsXULWindow.cpp +++ b/xpfe/appshell/src/nsXULWindow.cpp @@ -59,6 +59,7 @@ #include "nsIDOMDocumentEvent.h" #include "nsIDOMXULDocument.h" #include "nsIDOMElement.h" +#include "nsIPrivateDOMEvent.h" #include "nsIDOMEventTarget.h" #include "nsIDOMXULElement.h" #include "nsIDOMWindowInternal.h" @@ -257,6 +258,10 @@ NS_IMETHODIMP nsXULWindow::SetZLevel(PRUint32 aLevel) docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); if (event) { event->InitEvent(NS_LITERAL_STRING("windowZLevel"), PR_TRUE, PR_FALSE); + + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + nsCOMPtr targ(do_QueryInterface(doc)); if (targ) { PRBool defaultActionEnabled;