From 0348c342b8d97d5905eea6933f80f33a0674104a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 25 Jun 2018 18:23:50 +0200 Subject: [PATCH] Bug 1470930: Use enums for passing arguments for event dispatch. r=smaug MozReview-Commit-ID: DsNuF7GAflJ --- dom/base/EventSource.cpp | 5 +- dom/base/PostMessageEvent.cpp | 2 +- dom/base/Selection.cpp | 3 +- dom/base/SelectionChangeListener.cpp | 4 +- dom/base/nsContentSink.cpp | 2 +- dom/base/nsContentUtils.cpp | 60 +++++++----- dom/base/nsContentUtils.h | 95 ++++++++++--------- dom/base/nsDOMDataChannel.cpp | 8 +- dom/base/nsDocument.cpp | 52 +++++----- dom/base/nsFocusManager.cpp | 4 +- dom/base/nsFrameLoader.cpp | 5 +- dom/base/nsGlobalWindowInner.cpp | 4 +- dom/base/nsGlobalWindowOuter.cpp | 7 +- dom/base/nsImageLoadingContent.cpp | 5 +- dom/base/nsObjectLoadingContent.cpp | 6 +- dom/canvas/WebGLContext.cpp | 12 ++- dom/events/AsyncEventDispatcher.cpp | 9 +- dom/events/AsyncEventDispatcher.h | 38 ++++---- dom/events/Event.cpp | 8 +- dom/events/Event.h | 14 ++- dom/events/EventStateManager.cpp | 2 +- dom/events/MessageEvent.cpp | 3 +- dom/events/MessageEvent.h | 20 +++- dom/events/WheelHandlingHelper.cpp | 4 +- dom/html/HTMLDetailsElement.cpp | 4 +- dom/html/HTMLDialogElement.cpp | 2 +- dom/html/HTMLFormElement.cpp | 9 +- dom/html/HTMLInputElement.cpp | 70 ++++++++------ dom/html/HTMLLinkElement.cpp | 5 +- dom/html/HTMLMediaElement.cpp | 15 +-- dom/html/HTMLMetaElement.cpp | 5 +- dom/html/HTMLSlotElement.cpp | 5 +- dom/html/HTMLTextAreaElement.cpp | 5 +- dom/html/HTMLTrackElement.cpp | 2 +- dom/html/ImageDocument.cpp | 2 +- dom/html/nsIConstraintValidation.cpp | 10 +- dom/html/nsTextEditorState.cpp | 5 +- dom/ipc/TabParent.cpp | 6 +- ...kgroundVideoDecodingPermissionObserver.cpp | 8 +- dom/media/MediaTrackList.cpp | 4 +- dom/media/eme/MediaEncryptedEvent.cpp | 4 +- dom/media/eme/MediaKeyError.cpp | 2 +- dom/media/eme/MediaKeySession.cpp | 4 +- dom/media/webaudio/AudioContext.cpp | 2 +- dom/media/webaudio/AudioProcessingEvent.h | 2 +- dom/messagechannel/MessagePort.cpp | 3 +- dom/permission/PermissionStatus.cpp | 2 +- dom/plugins/base/nsPluginInstanceOwner.cpp | 4 +- dom/presentation/PresentationConnection.cpp | 10 +- dom/script/ScriptElement.cpp | 4 +- dom/script/ScriptLoader.cpp | 4 +- dom/script/ScriptTrace.cpp | 5 +- dom/websocket/WebSocket.cpp | 5 +- dom/workers/MessageEventRunnable.cpp | 4 +- dom/workers/RuntimeService.cpp | 4 +- dom/workers/WorkerDebugger.cpp | 4 +- dom/xul/XULDocument.cpp | 4 +- dom/xul/nsXULElement.cpp | 6 +- gfx/layers/apz/util/APZCCallbackHelper.cpp | 3 +- layout/base/nsDocumentViewer.cpp | 9 +- layout/forms/nsComboboxControlFrame.cpp | 4 +- layout/forms/nsFileControlFrame.cpp | 10 +- layout/forms/nsListControlFrame.cpp | 18 ++-- layout/generic/nsFrame.cpp | 5 +- layout/generic/nsGfxScrollFrame.cpp | 4 +- layout/generic/nsVideoFrame.cpp | 2 +- layout/printing/nsPrintJob.cpp | 7 +- layout/style/FontFaceSet.cpp | 2 +- layout/style/Loader.cpp | 5 +- layout/xul/tree/nsTreeSelection.cpp | 5 +- uriloader/prefetch/nsPrefetchService.cpp | 13 ++- widget/EventForwards.h | 24 +++++ xpfe/appshell/nsWebShellWindow.cpp | 2 +- 73 files changed, 438 insertions(+), 277 deletions(-) diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index 69f8db238d8b..eb69238b9cce 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -1518,8 +1518,9 @@ EventSourceImpl::DispatchAllMessageEvents() RefPtr event = new MessageEvent(mEventSource, nullptr, nullptr); - event->InitMessageEvent(nullptr, message->mEventName, false, false, jsData, - mOrigin, message->mLastEventID, nullptr, + event->InitMessageEvent(nullptr, message->mEventName, CanBubble::eNo, + Cancelable::eNo, jsData, mOrigin, + message->mLastEventID, nullptr, Sequence>()); event->SetTrusted(true); diff --git a/dom/base/PostMessageEvent.cpp b/dom/base/PostMessageEvent.cpp index 7eeb5fe48a6f..d766c2d6fd01 100644 --- a/dom/base/PostMessageEvent.cpp +++ b/dom/base/PostMessageEvent.cpp @@ -160,7 +160,7 @@ PostMessageEvent::Run() } event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), - false /*non-bubbling */, false /*cancelable */, + CanBubble::eNo, Cancelable::eNo, messageData, mCallerOrigin, EmptyString(), source, ports); diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index cd3e20194c4f..e7f7025edc48 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -1038,7 +1038,8 @@ Selection::AddItem(nsRange* aItem, int32_t* aOutIndex, bool aNoStartSelect) if (dispatchEvent) { nsContentUtils::DispatchTrustedEvent(GetParentObject(), target, NS_LITERAL_STRING("selectstart"), - true, true, &defaultAction); + CanBubble::eYes, Cancelable::eYes, + &defaultAction); if (!defaultAction) { return NS_OK; diff --git a/dom/base/SelectionChangeListener.cpp b/dom/base/SelectionChangeListener.cpp index 24d012050b91..965a78b01d0d 100644 --- a/dom/base/SelectionChangeListener.cpp +++ b/dom/base/SelectionChangeListener.cpp @@ -156,7 +156,7 @@ SelectionChangeListener::NotifySelectionChanged(nsIDocument* aDoc, if (target) { RefPtr asyncDispatcher = - new AsyncEventDispatcher(target, eSelectionChange, false); + new AsyncEventDispatcher(target, eSelectionChange, CanBubble::eNo); asyncDispatcher->PostDOMEvent(); } } else { @@ -170,7 +170,7 @@ SelectionChangeListener::NotifySelectionChanged(nsIDocument* aDoc, if (aDoc) { RefPtr asyncDispatcher = - new AsyncEventDispatcher(aDoc, eSelectionChange, false); + new AsyncEventDispatcher(aDoc, eSelectionChange, CanBubble::eNo); asyncDispatcher->PostDOMEvent(); } } diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp index f4260397328b..107b05df862e 100644 --- a/dom/base/nsContentSink.cpp +++ b/dom/base/nsContentSink.cpp @@ -1663,7 +1663,7 @@ nsContentSink::NotifyDocElementCreated(nsIDocument* aDoc) nsContentUtils::DispatchChromeEvent(aDoc, aDoc, NS_LITERAL_STRING("DOMDocElementInserted"), - true, false); + CanBubble::eYes, Cancelable::eNo); } NS_IMETHODIMP diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index bb360d971e6c..5e57c03037a5 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -4423,8 +4423,10 @@ nsContentUtils::GetEventMessageAndAtomForListener(const nsAString& aName, static nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, bool aCancelable, - bool aTrusted, Event** aEvent, + CanBubble aCanBubble, + Cancelable aCancelable, + Trusted aTrusted, + Event** aEvent, EventTarget** aTargetOut) { nsCOMPtr target(do_QueryInterface(aTarget)); @@ -4438,7 +4440,7 @@ nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget, } event->InitEvent(aEventName, aCanBubble, aCancelable); - event->SetTrusted(aTrusted); + event->SetTrusted(aTrusted == Trusted::eYes); event->SetTarget(target); @@ -4451,31 +4453,35 @@ nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget, nsresult nsContentUtils::DispatchTrustedEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, bool aCancelable, + CanBubble aCanBubble, + Cancelable aCancelable, bool* aDefaultAction) { return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, - true, aDefaultAction); + Trusted::eYes, aDefaultAction); } // static nsresult nsContentUtils::DispatchUntrustedEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, bool aCancelable, + CanBubble aCanBubble, + Cancelable aCancelable, bool* aDefaultAction) { return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, - false, aDefaultAction); + Trusted::eNo, aDefaultAction); } // static nsresult nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, bool aCancelable, - bool aTrusted, bool* aDefaultAction, - bool aOnlyChromeDispatch) + CanBubble aCanBubble, + Cancelable aCancelable, + Trusted aTrusted, + bool* aDefaultAction, + ChromeOnlyDispatch aOnlyChromeDispatch) { RefPtr event; nsCOMPtr target; @@ -4483,7 +4489,8 @@ nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, aCancelable, aTrusted, getter_AddRefs(event), getter_AddRefs(target)); NS_ENSURE_SUCCESS(rv, rv); - event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = aOnlyChromeDispatch; + event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = + aOnlyChromeDispatch == ChromeOnlyDispatch::eYes; ErrorResult err; bool doDefault = target->DispatchEvent(*event, CallerType::System, err); @@ -4498,11 +4505,14 @@ nsresult nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, WidgetEvent& aEvent, EventMessage aEventMessage, - bool aCanBubble, bool aCancelable, - bool aTrusted, bool *aDefaultAction, - bool aOnlyChromeDispatch) + CanBubble aCanBubble, + Cancelable aCancelable, + Trusted aTrusted, + bool* aDefaultAction, + ChromeOnlyDispatch aOnlyChromeDispatch) { - MOZ_ASSERT_IF(aOnlyChromeDispatch, aTrusted); + MOZ_ASSERT_IF(aOnlyChromeDispatch == ChromeOnlyDispatch::eYes, + aTrusted == Trusted::eYes); nsCOMPtr target(do_QueryInterface(aTarget)); @@ -4512,9 +4522,10 @@ nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, aEvent.SetDefaultComposed(); aEvent.SetDefaultComposedInNativeAnonymousContent(); - aEvent.mFlags.mBubbles = aCanBubble; - aEvent.mFlags.mCancelable = aCancelable; - aEvent.mFlags.mOnlyChromeDispatch = aOnlyChromeDispatch; + aEvent.mFlags.mBubbles = aCanBubble == CanBubble::eYes; + aEvent.mFlags.mCancelable = aCancelable == Cancelable::eYes; + aEvent.mFlags.mOnlyChromeDispatch = + aOnlyChromeDispatch == ChromeOnlyDispatch::eYes; aEvent.mTarget = target; @@ -4531,14 +4542,16 @@ nsresult nsContentUtils::DispatchChromeEvent(nsIDocument *aDoc, nsISupports *aTarget, const nsAString& aEventName, - bool aCanBubble, bool aCancelable, + CanBubble aCanBubble, + Cancelable aCancelable, bool* aDefaultAction) { RefPtr event; nsCOMPtr target; nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble, - aCancelable, true, getter_AddRefs(event), + aCancelable, Trusted::eYes, + getter_AddRefs(event), getter_AddRefs(target)); NS_ENSURE_SUCCESS(rv, rv); @@ -4572,18 +4585,19 @@ nsContentUtils::DispatchFocusChromeEvent(nsPIDOMWindowOuter* aWindow) return DispatchChromeEvent(doc, aWindow, NS_LITERAL_STRING("DOMWindowFocus"), - true, true); + CanBubble::eYes, Cancelable::eYes); } nsresult nsContentUtils::DispatchEventOnlyToChrome(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, bool aCancelable, + CanBubble aCanBubble, + Cancelable aCancelable, bool* aDefaultAction) { return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, - true, aDefaultAction, true); + Trusted::eYes, aDefaultAction, ChromeOnlyDispatch::eYes); } /* static */ diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index cf48a5c9c76f..40bc32e40876 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -200,7 +200,12 @@ class nsContentUtils { friend class nsAutoScriptBlockerSuppressNodeRemoved; typedef mozilla::dom::Element Element; + typedef mozilla::Cancelable Cancelable; + typedef mozilla::CanBubble CanBubble; + typedef mozilla::ChromeOnlyDispatch ChromeOnlyDispatch; + typedef mozilla::EventMessage EventMessage; typedef mozilla::TimeDuration TimeDuration; + typedef mozilla::Trusted Trusted; public: static nsresult Init(); @@ -1349,9 +1354,9 @@ public: static nsresult DispatchTrustedEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, - bool aCancelable, - bool *aDefaultAction = nullptr); + CanBubble, + Cancelable, + bool* aDefaultAction = nullptr); /** * This method creates and dispatches a trusted event using an event message. @@ -1365,18 +1370,19 @@ public: * see EventTarget::DispatchEvent. */ template - static nsresult DispatchTrustedEvent(nsIDocument* aDoc, - nsISupports* aTarget, - mozilla::EventMessage aEventMessage, - bool aCanBubble, - bool aCancelable, - bool *aDefaultAction = nullptr, - bool aOnlyChromeDispatch = false) + static nsresult DispatchTrustedEvent( + nsIDocument* aDoc, + nsISupports* aTarget, + EventMessage aEventMessage, + CanBubble aCanBubble, + Cancelable aCancelable, + bool* aDefaultAction = nullptr, + ChromeOnlyDispatch aOnlyChromeDispatch = ChromeOnlyDispatch::eNo) { WidgetEventType event(true, aEventMessage); MOZ_ASSERT(GetEventClassIDFromMessage(aEventMessage) == event.mClass); return DispatchEvent(aDoc, aTarget, event, aEventMessage, - aCanBubble, aCancelable, true, + aCanBubble, aCancelable, Trusted::eYes, aDefaultAction, aOnlyChromeDispatch); } @@ -1396,9 +1402,9 @@ public: static nsresult DispatchUntrustedEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, - bool aCancelable, - bool *aDefaultAction = nullptr); + CanBubble, + Cancelable, + bool* aDefaultAction = nullptr); /** @@ -1413,18 +1419,19 @@ public: * see EventTarget::DispatchEvent. */ template - static nsresult DispatchUntrustedEvent(nsIDocument* aDoc, - nsISupports* aTarget, - mozilla::EventMessage aEventMessage, - bool aCanBubble, - bool aCancelable, - bool *aDefaultAction = nullptr, - bool aOnlyChromeDispatch = false) + static nsresult DispatchUntrustedEvent( + nsIDocument* aDoc, + nsISupports* aTarget, + EventMessage aEventMessage, + CanBubble aCanBubble, + Cancelable aCancelable, + bool* aDefaultAction = nullptr, + ChromeOnlyDispatch aOnlyChromeDispatch = ChromeOnlyDispatch::eNo) { WidgetEventType event(false, aEventMessage); MOZ_ASSERT(GetEventClassIDFromMessage(aEventMessage) == event.mClass); return DispatchEvent(aDoc, aTarget, event, aEventMessage, - aCanBubble, aCancelable, false, + aCanBubble, aCancelable, Trusted::eNo, aDefaultAction, aOnlyChromeDispatch); } @@ -1449,9 +1456,9 @@ public: static nsresult DispatchChromeEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, - bool aCancelable, - bool *aDefaultAction = nullptr); + CanBubble, + Cancelable, + bool* aDefaultAction = nullptr); /** * Helper function for dispatching a "DOMWindowFocus" event to @@ -1482,9 +1489,9 @@ public: static nsresult DispatchEventOnlyToChrome(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, - bool aCancelable, - bool *aDefaultAction = nullptr); + CanBubble, + Cancelable, + bool* aDefaultAction = nullptr); /** * Determines if an event attribute name (such as onclick) is valid for @@ -1503,13 +1510,13 @@ public: * * @param aName the event name to look up */ - static mozilla::EventMessage GetEventMessage(nsAtom* aName); + static EventMessage GetEventMessage(nsAtom* aName); /** * Returns the EventMessage and nsAtom to be used for event listener * registration. */ - static mozilla::EventMessage + static EventMessage GetEventMessageAndAtomForListener(const nsAString& aName, nsAtom** aOnName); /** @@ -1531,8 +1538,8 @@ public: * @param aEventClassID only return event id for aEventClassID */ static nsAtom* GetEventMessageAndAtom(const nsAString& aName, - mozilla::EventClassID aEventClassID, - mozilla::EventMessage* aEventMessage); + mozilla::EventClassID aEventClassID, + EventMessage* aEventMessage); /** * Used only during traversal of the XPCOM graph by the cycle @@ -3278,21 +3285,21 @@ private: static nsresult DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, - bool aCanBubble, - bool aCancelable, - bool aTrusted, - bool *aDefaultAction = nullptr, - bool aOnlyChromeDispatch = false); + CanBubble, + Cancelable, + Trusted, + bool* aDefaultAction = nullptr, + ChromeOnlyDispatch = ChromeOnlyDispatch::eNo); static nsresult DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, mozilla::WidgetEvent& aWidgetEvent, - mozilla::EventMessage aEventMessage, - bool aCanBubble, - bool aCancelable, - bool aTrusted, - bool *aDefaultAction = nullptr, - bool aOnlyChromeDispatch = false); + EventMessage aEventMessage, + CanBubble, + Cancelable, + Trusted, + bool* aDefaultAction = nullptr, + ChromeOnlyDispatch = ChromeOnlyDispatch::eNo); static void InitializeModifierStrings(); @@ -3306,7 +3313,7 @@ private: const nsString* aClasses); static mozilla::EventClassID - GetEventClassIDFromMessage(mozilla::EventMessage aEventMessage); + GetEventClassIDFromMessage(EventMessage aEventMessage); // Fills in aInfo with the tokens from the supplied autocomplete attribute. static AutocompleteAttrState InternalSerializeAutocompleteAttribute(const nsAttrValue* aAttrVal, diff --git a/dom/base/nsDOMDataChannel.cpp b/dom/base/nsDOMDataChannel.cpp index 19509a0605be..962160c399c6 100644 --- a/dom/base/nsDOMDataChannel.cpp +++ b/dom/base/nsDOMDataChannel.cpp @@ -340,9 +340,9 @@ nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData, RefPtr event = new MessageEvent(this, nullptr, nullptr); - event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), false, false, - jsData, mOrigin, EmptyString(), nullptr, - Sequence>()); + event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), CanBubble::eNo, + Cancelable::eNo, jsData, mOrigin, EmptyString(), + nullptr, Sequence>()); event->SetTrusted(true); LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__)); @@ -382,7 +382,7 @@ nsDOMDataChannel::OnSimpleEvent(nsISupports* aContext, const nsAString& aName) RefPtr event = NS_NewDOMEvent(this, nullptr, nullptr); - event->InitEvent(aName, false, false); + event->InitEvent(aName, CanBubble::eNo, Cancelable::eNo); event->SetTrusted(true); ErrorResult err; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 12e52d24446e..c82ad7a52ca6 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -4137,13 +4137,13 @@ nsIDocument::AddStyleSheetToStyleSets(StyleSheet* aSheet) init.mStylesheet = aSheet; \ init.memberName = argName; \ \ - RefPtr event = \ + RefPtr event = \ className::Constructor(this, NS_LITERAL_STRING(type), init); \ event->SetTrusted(true); \ event->SetTarget(this); \ - RefPtr asyncDispatcher = \ + RefPtr asyncDispatcher = \ new AsyncEventDispatcher(this, event); \ - asyncDispatcher->mOnlyChromeDispatch = true; \ + asyncDispatcher->mOnlyChromeDispatch = ChromeOnlyDispatch::eYes; \ asyncDispatcher->PostDOMEvent(); \ } while (0); @@ -4967,7 +4967,7 @@ nsIDocument::DispatchContentLoadedEvents() // document). nsContentUtils::DispatchTrustedEvent(this, this, NS_LITERAL_STRING("DOMContentLoaded"), - true, false); + CanBubble::eYes, Cancelable::eNo); if (MayStartLayout()) { MaybeResolveReadyForIdle(); @@ -5046,7 +5046,7 @@ nsIDocument::DispatchContentLoadedEvents() if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::manifest)) { nsContentUtils::DispatchChromeEvent(this, this, NS_LITERAL_STRING("MozApplicationManifest"), - true, true); + CanBubble::eYes, Cancelable::eYes); } nsPIDOMWindowInner* inner = GetInnerWindow(); @@ -6296,7 +6296,7 @@ nsIDocument::DoNotifyPossibleTitleChange() // Fire a DOM event for the title change. nsContentUtils::DispatchChromeEvent(this, static_cast(this), NS_LITERAL_STRING("DOMTitleChanged"), - true, true); + CanBubble::eYes, Cancelable::eYes); } already_AddRefed @@ -8184,8 +8184,8 @@ nsDocument::UnblockOnload(bool aFireSync) RefPtr asyncDispatcher = new AsyncEventDispatcher(this, NS_LITERAL_STRING("MozSVGAsImageDocumentLoad"), - false, - false); + CanBubble::eNo, + ChromeOnlyDispatch::eNo); asyncDispatcher->PostDOMEvent(); } } @@ -8726,8 +8726,10 @@ nsIDocument::SetReadyStateInternal(ReadyState rs) RecordNavigationTiming(rs); RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("readystatechange"), - false, false); + new AsyncEventDispatcher(this, + NS_LITERAL_STRING("readystatechange"), + CanBubble::eNo, + ChromeOnlyDispatch::eNo); asyncDispatcher->RunDOMEventWhenSafe(); } @@ -10282,8 +10284,7 @@ AskWindowToExitFullscreen(nsIDocument* aDoc) if (XRE_GetProcessType() == GeckoProcessType_Content) { nsContentUtils::DispatchEventOnlyToChrome( aDoc, ToSupports(aDoc), NS_LITERAL_STRING("MozDOMFullscreen:Exit"), - /* Bubbles */ true, /* Cancelable */ false, - /* DefaultAction */ nullptr); + CanBubble::eYes, Cancelable::eNo, /* DefaultAction */ nullptr); } else { if (nsPIDOMWindowOuter* win = aDoc->GetWindow()) { win->SetFullscreenInternal(FullscreenReason::ForFullscreenAPI, false); @@ -10392,7 +10393,7 @@ public: nsContentUtils::DispatchEventOnlyToChrome( lastDocument, ToSupports(lastDocument), NS_LITERAL_STRING("MozDOMFullscreen:Exited"), - /* Bubbles */ true, /* Cancelable */ false, /* DefaultAction */ nullptr); + CanBubble::eYes, Cancelable::eNo, /* DefaultAction */ nullptr); // Ensure the window exits fullscreen. if (nsPIDOMWindowOuter* win = mDocuments[0]->GetWindow()) { win->SetFullscreenInternal(FullscreenReason::ForForceExitFullscreen, false); @@ -10609,8 +10610,8 @@ nsIDocument::DispatchFullscreenError(const char* aMessage) RefPtr asyncDispatcher = new AsyncEventDispatcher(this, NS_LITERAL_STRING("fullscreenerror"), - true, - false); + CanBubble::eYes, + ChromeOnlyDispatch::eNo); asyncDispatcher->PostDOMEvent(); nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DOM"), this, @@ -11082,7 +11083,7 @@ nsIDocument::RequestFullScreen(UniquePtr&& aRequest) // our parent process go fullscreen first. nsContentUtils::DispatchEventOnlyToChrome( this, ToSupports(this), NS_LITERAL_STRING("MozDOMFullscreen:Request"), - /* Bubbles */ true, /* Cancelable */ false, /* DefaultAction */ nullptr); + CanBubble::eYes, Cancelable::eNo, /* DefaultAction */ nullptr); } else { // Make the window fullscreen. rootWin->SetFullscreenInternal(FullscreenReason::ForFullscreenAPI, true); @@ -11190,7 +11191,7 @@ nsIDocument::ApplyFullscreen(const FullscreenRequest& aRequest) if (!previousFullscreenDoc) { nsContentUtils::DispatchEventOnlyToChrome( this, ToSupports(elem), NS_LITERAL_STRING("MozDOMFullscreen:Entered"), - /* Bubbles */ true, /* Cancelable */ false, /* DefaultAction */ nullptr); + CanBubble::eYes, Cancelable::eNo, /* DefaultAction */ nullptr); } // The origin which is fullscreen gets changed. Trigger an event so @@ -11238,8 +11239,8 @@ DispatchPointerLockChange(nsIDocument* aTarget) RefPtr asyncDispatcher = new AsyncEventDispatcher(aTarget, NS_LITERAL_STRING("pointerlockchange"), - true, - false); + CanBubble::eYes, + ChromeOnlyDispatch::eNo); asyncDispatcher->PostDOMEvent(); } @@ -11253,8 +11254,8 @@ DispatchPointerLockError(nsIDocument* aTarget, const char* aMessage) RefPtr asyncDispatcher = new AsyncEventDispatcher(aTarget, NS_LITERAL_STRING("pointerlockerror"), - true, - false); + CanBubble::eYes, + ChromeOnlyDispatch::eNo); asyncDispatcher->PostDOMEvent(); nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, NS_LITERAL_CSTRING("DOM"), aTarget, @@ -11410,7 +11411,7 @@ PointerLockRequest::Run() ChangePointerLockedElement(e, d, nullptr); nsContentUtils::DispatchEventOnlyToChrome( doc, ToSupports(e), NS_LITERAL_STRING("MozDOMPointerLock:Entered"), - /* Bubbles */ true, /* Cancelable */ false, /* DefaultAction */ nullptr); + CanBubble::eYes, Cancelable::eNo, /* DefaultAction */ nullptr); return NS_OK; } @@ -11516,7 +11517,8 @@ nsIDocument::UnlockPointer(nsIDocument* aDoc) RefPtr asyncDispatcher = new AsyncEventDispatcher(pointerLockedElement, NS_LITERAL_STRING("MozDOMPointerLock:Exited"), - true, true); + CanBubble::eYes, + ChromeOnlyDispatch::eYes); asyncDispatcher->RunDOMEventWhenSafe(); } @@ -11528,8 +11530,8 @@ nsIDocument::UpdateVisibilityState() if (oldState != mVisibilityState) { nsContentUtils::DispatchTrustedEvent(this, static_cast(this), NS_LITERAL_STRING("visibilitychange"), - /* bubbles = */ true, - /* cancelable = */ false); + CanBubble::eYes, + Cancelable::eNo); EnumerateActivityObservers(NotifyActivityChanged, nullptr); } diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index eddf05fe821e..3e75519d5fc2 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -1189,7 +1189,9 @@ nsFocusManager::ActivateOrDeactivate(nsPIDOMWindowOuter* aWindow, bool aActive) aActive ? NS_LITERAL_STRING("activate") : NS_LITERAL_STRING("deactivate"), - true, true, nullptr); + CanBubble::eYes, + Cancelable::eYes, + nullptr); } // Look for any remote child frames, iterate over them and send the activation notification. diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index 47c6af2e771a..7b1929026b74 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -301,10 +301,11 @@ nsFrameLoader::FireErrorEvent() if (!mOwnerContent) { return; } - RefPtr loadBlockingAsyncDispatcher = + RefPtr loadBlockingAsyncDispatcher = new LoadBlockingAsyncEventDispatcher(mOwnerContent, NS_LITERAL_STRING("error"), - false, false); + CanBubble::eNo, + ChromeOnlyDispatch::eNo); loadBlockingAsyncDispatcher->PostDOMEvent(); } diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 4dd1bb2de309..eb641bfb751b 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -5220,8 +5220,8 @@ nsGlobalWindowInner::FireOfflineStatusEventIfChanged() nsContentUtils::DispatchTrustedEvent(mDoc, static_cast(this), name, - false, - false); + CanBubble::eNo, + Cancelable::eNo); } class NotifyIdleObserverRunnable : public Runnable diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index f77b94915a45..64cd974c1199 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -2069,8 +2069,8 @@ nsGlobalWindowOuter::DispatchDOMWindowCreated() // Fire DOMWindowCreated at chrome event listeners nsContentUtils::DispatchChromeEvent(mDoc, mDoc, NS_LITERAL_STRING("DOMWindowCreated"), - true /* bubbles */, - false /* not cancellable */); + CanBubble::eYes, + Cancelable::eNo); nsCOMPtr observerService = mozilla::services::GetObserverService(); @@ -3772,7 +3772,8 @@ nsGlobalWindowOuter::DispatchCustomEvent(const nsAString& aEventName) { bool defaultActionEnabled = true; nsContentUtils::DispatchTrustedEvent(mDoc, ToSupports(this), aEventName, - true, true, &defaultActionEnabled); + CanBubble::eYes, Cancelable::eYes, + &defaultActionEnabled); return defaultActionEnabled; } diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp index a388cf3a6500..9f8b180442a4 100644 --- a/dom/base/nsImageLoadingContent.cpp +++ b/dom/base/nsImageLoadingContent.cpp @@ -1256,7 +1256,10 @@ nsImageLoadingContent::FireEvent(const nsAString& aEventType, bool aIsCancelable nsCOMPtr thisNode = do_QueryInterface(static_cast(this)); RefPtr loadBlockingAsyncDispatcher = - new LoadBlockingAsyncEventDispatcher(thisNode, aEventType, false, false); + new LoadBlockingAsyncEventDispatcher(thisNode, + aEventType, + CanBubble::eNo, + ChromeOnlyDispatch::eNo); loadBlockingAsyncDispatcher->PostDOMEvent(); if (aIsCancelable) { diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 217e0c1f6d8c..8582e4ebcfad 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -307,7 +307,8 @@ nsSimplePluginEvent::Run() LOG(("OBJLC [%p]: nsSimplePluginEvent firing event \"%s\"", mTarget.get(), NS_ConvertUTF16toUTF8(mEvent).get())); nsContentUtils::DispatchTrustedEvent(mDocument, mTarget, - mEvent, true, true); + mEvent, CanBubble::eYes, + Cancelable::eYes); } return NS_OK; } @@ -3784,7 +3785,8 @@ nsObjectLoadingContent::MaybeFireErrorEvent() RefPtr loadBlockingAsyncDispatcher = new LoadBlockingAsyncEventDispatcher(thisContent, NS_LITERAL_STRING("error"), - false, false); + CanBubble::eNo, + ChromeOnlyDispatch::eNo); loadBlockingAsyncDispatcher->PostDOMEvent(); } } diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index a45933b6c11b..ad534a019e9e 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -1778,8 +1778,8 @@ WebGLContext::UpdateContextLossStatus() // The context has been lost and we haven't yet triggered the // callback, so do that now. const auto kEventName = NS_LITERAL_STRING("webglcontextlost"); - const bool kCanBubble = true; - const bool kIsCancelable = true; + const auto kCanBubble = CanBubble::eYes; + const auto kIsCancelable = Cancelable::eYes; bool useDefaultHandler; if (mCanvasElement) { @@ -1857,11 +1857,13 @@ WebGLContext::UpdateContextLossStatus() mCanvasElement->OwnerDoc(), static_cast(mCanvasElement), NS_LITERAL_STRING("webglcontextrestored"), - true, - true); + CanBubble::eYes, + Cancelable::eYes); } else { RefPtr event = new Event(mOffscreenCanvas, nullptr, nullptr); - event->InitEvent(NS_LITERAL_STRING("webglcontextrestored"), true, true); + event->InitEvent(NS_LITERAL_STRING("webglcontextrestored"), + CanBubble::eYes, + Cancelable::eYes); event->SetTrusted(true); mOffscreenCanvas->DispatchEvent(*event); } diff --git a/dom/events/AsyncEventDispatcher.cpp b/dom/events/AsyncEventDispatcher.cpp index 683d811d48b4..cdf33d38091e 100644 --- a/dom/events/AsyncEventDispatcher.cpp +++ b/dom/events/AsyncEventDispatcher.cpp @@ -51,17 +51,16 @@ AsyncEventDispatcher::Run() mTarget->AsyncEventRunning(this); if (mEventMessage != eUnidentifiedEvent) { return nsContentUtils::DispatchTrustedEvent - (node->OwnerDoc(), mTarget, mEventMessage, mBubbles, - false /* aCancelable */, nullptr /* aDefaultAction */, - mOnlyChromeDispatch); + (node->OwnerDoc(), mTarget, mEventMessage, mCanBubble, + Cancelable::eNo, nullptr /* aDefaultAction */, mOnlyChromeDispatch); } RefPtr event = mEvent; if (!event) { event = NS_NewDOMEvent(mTarget, nullptr, nullptr); - event->InitEvent(mEventType, mBubbles, false); + event->InitEvent(mEventType, mCanBubble, Cancelable::eNo); event->SetTrusted(true); } - if (mOnlyChromeDispatch) { + if (mOnlyChromeDispatch == ChromeOnlyDispatch::eYes) { MOZ_ASSERT(event->IsTrusted()); event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true; } diff --git a/dom/events/AsyncEventDispatcher.h b/dom/events/AsyncEventDispatcher.h index fb75fbb586a9..c8ae0ccf2cce 100644 --- a/dom/events/AsyncEventDispatcher.h +++ b/dom/events/AsyncEventDispatcher.h @@ -8,6 +8,7 @@ #define mozilla_AsyncEventDispatcher_h_ #include "mozilla/Attributes.h" +#include "mozilla/EventForwards.h" #include "mozilla/RefPtr.h" #include "mozilla/dom/Event.h" #include "nsCOMPtr.h" @@ -37,13 +38,13 @@ public: */ AsyncEventDispatcher(nsINode* aTarget, const nsAString& aEventType, - bool aBubbles, - bool aOnlyChromeDispatch) + CanBubble aCanBubble, + ChromeOnlyDispatch aOnlyChromeDispatch) : CancelableRunnable("AsyncEventDispatcher") , mTarget(aTarget) , mEventType(aEventType) , mEventMessage(eUnidentifiedEvent) - , mBubbles(aBubbles) + , mCanBubble(aCanBubble) , mOnlyChromeDispatch(aOnlyChromeDispatch) { } @@ -56,34 +57,36 @@ public: */ AsyncEventDispatcher(nsINode* aTarget, mozilla::EventMessage aEventMessage, - bool aBubbles, bool aOnlyChromeDispatch) + CanBubble aCanBubble, + ChromeOnlyDispatch aOnlyChromeDispatch) : CancelableRunnable("AsyncEventDispatcher") , mTarget(aTarget) , mEventMessage(aEventMessage) - , mBubbles(aBubbles) + , mCanBubble(aCanBubble) , mOnlyChromeDispatch(aOnlyChromeDispatch) { mEventType.SetIsVoid(true); MOZ_ASSERT(mEventMessage != eUnidentifiedEvent); } - AsyncEventDispatcher(dom::EventTarget* aTarget, const nsAString& aEventType, - bool aBubbles) + AsyncEventDispatcher(dom::EventTarget* aTarget, + const nsAString& aEventType, + CanBubble aCanBubble) : CancelableRunnable("AsyncEventDispatcher") , mTarget(aTarget) , mEventType(aEventType) , mEventMessage(eUnidentifiedEvent) - , mBubbles(aBubbles) + , mCanBubble(aCanBubble) { } AsyncEventDispatcher(dom::EventTarget* aTarget, mozilla::EventMessage aEventMessage, - bool aBubbles) + CanBubble aCanBubble) : CancelableRunnable("AsyncEventDispatcher") , mTarget(aTarget) , mEventMessage(aEventMessage) - , mBubbles(aBubbles) + , mCanBubble(aCanBubble) { mEventType.SetIsVoid(true); MOZ_ASSERT(mEventMessage != eUnidentifiedEvent); @@ -115,9 +118,9 @@ public: // If mEventMessage is set, mEventType will be void. // They can never both be set at the same time. nsString mEventType; - mozilla::EventMessage mEventMessage; - bool mBubbles = false; - bool mOnlyChromeDispatch = false; + EventMessage mEventMessage; + CanBubble mCanBubble = CanBubble::eNo; + ChromeOnlyDispatch mOnlyChromeDispatch = ChromeOnlyDispatch::eNo; bool mCanceled = false; bool mCheckStillInDoc = false; }; @@ -127,9 +130,12 @@ class LoadBlockingAsyncEventDispatcher final : public AsyncEventDispatcher public: LoadBlockingAsyncEventDispatcher(nsINode* aEventNode, const nsAString& aEventType, - bool aBubbles, bool aDispatchChromeOnly) - : AsyncEventDispatcher(aEventNode, aEventType, - aBubbles, aDispatchChromeOnly) + CanBubble aBubbles, + ChromeOnlyDispatch aDispatchChromeOnly) + : AsyncEventDispatcher(aEventNode, + aEventType, + aBubbles, + aDispatchChromeOnly) , mBlockedDoc(aEventNode->OwnerDoc()) { if (mBlockedDoc) { diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index 45b3767d28bc..a97e09a1ee9d 100644 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -493,8 +493,8 @@ Event::EnsureWebAccessibleRelatedTarget(EventTarget* aRelatedTarget) void Event::InitEvent(const nsAString& aEventTypeArg, - bool aCanBubbleArg, - bool aCancelableArg) + mozilla::CanBubble aCanBubbleArg, + mozilla::Cancelable aCancelableArg) { // Make sure this event isn't already being dispatched. NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); @@ -508,8 +508,8 @@ Event::InitEvent(const nsAString& aEventTypeArg, SetEventType(aEventTypeArg); - mEvent->mFlags.mBubbles = aCanBubbleArg; - mEvent->mFlags.mCancelable = aCancelableArg; + mEvent->mFlags.mBubbles = aCanBubbleArg == CanBubble::eYes; + mEvent->mFlags.mCancelable = aCancelableArg == Cancelable::eYes; mEvent->mFlags.mDefaultPrevented = false; mEvent->mFlags.mDefaultPreventedByContent = false; diff --git a/dom/events/Event.h b/dom/events/Event.h index a56f156413da..4bc72b1a5a20 100755 --- a/dom/events/Event.h +++ b/dom/events/Event.h @@ -148,8 +148,18 @@ public: } void InitEvent(const nsAString& aEventTypeArg, - bool aCanBubbleArg, - bool aCancelableArg); + bool aCanBubble, + bool aCancelable) + { + InitEvent(aEventTypeArg, + aCanBubble ? CanBubble::eYes : CanBubble::eNo, + aCancelable ? Cancelable::eYes : Cancelable::eNo); + } + + void InitEvent(const nsAString& aEventTypeArg, + mozilla::CanBubble, + mozilla::Cancelable); + void SetTarget(EventTarget* aTarget); virtual void DuplicatePrivateData(); bool IsDispatchStopped(); diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 3dca0ec4bfad..ab3fe9e7ecfb 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -2291,7 +2291,7 @@ EventStateManager::DoScrollZoom(nsIFrame* aTargetFrame, } nsContentUtils::DispatchChromeEvent(mDocument, static_cast(mDocument), NS_LITERAL_STRING("ZoomChangeUsingMouseWheel"), - true, true); + CanBubble::eYes, Cancelable::eYes); } } diff --git a/dom/events/MessageEvent.cpp b/dom/events/MessageEvent.cpp index cb6c5655cebd..848c4217b594 100644 --- a/dom/events/MessageEvent.cpp +++ b/dom/events/MessageEvent.cpp @@ -145,7 +145,8 @@ MessageEvent::Constructor(EventTarget* aEventTarget, void MessageEvent::InitMessageEvent(JSContext* aCx, const nsAString& aType, - bool aCanBubble, bool aCancelable, + mozilla::CanBubble aCanBubble, + mozilla::Cancelable aCancelable, JS::Handle aData, const nsAString& aOrigin, const nsAString& aLastEventId, diff --git a/dom/events/MessageEvent.h b/dom/events/MessageEvent.h index bf9991c9aab1..6347be793d95 100644 --- a/dom/events/MessageEvent.h +++ b/dom/events/MessageEvent.h @@ -58,8 +58,24 @@ public: const nsAString& aType, const MessageEventInit& aEventInit); - void InitMessageEvent(JSContext* aCx, const nsAString& aType, bool aCanBubble, - bool aCancelable, JS::Handle aData, + void InitMessageEvent(JSContext* aCx, const nsAString& aType, + bool aCanBubble, bool aCancelable, + JS::Handle aData, + const nsAString& aOrigin, const nsAString& aLastEventId, + const Nullable& aSource, + const Sequence>& aPorts) + { + InitMessageEvent(aCx, aType, + aCanBubble ? CanBubble::eYes : CanBubble::eNo, + aCancelable ? Cancelable::eYes : Cancelable::eNo, + aData, + aOrigin, aLastEventId, + aSource, aPorts); + } + + void InitMessageEvent(JSContext* aCx, const nsAString& aType, + mozilla::CanBubble, mozilla::Cancelable, + JS::Handle aData, const nsAString& aOrigin, const nsAString& aLastEventId, const Nullable& aSource, const Sequence>& aPorts); diff --git a/dom/events/WheelHandlingHelper.cpp b/dom/events/WheelHandlingHelper.cpp index e75edb2aa9ec..d418b58a21f3 100644 --- a/dom/events/WheelHandlingHelper.cpp +++ b/dom/events/WheelHandlingHelper.cpp @@ -318,7 +318,7 @@ WheelTransaction::OnFailToScrollTarget() sTargetFrame->GetContent()->OwnerDoc(), sTargetFrame->GetContent(), NS_LITERAL_STRING("MozMouseScrollFailed"), - true, true); + CanBubble::eYes, Cancelable::eYes); } // The target frame might be destroyed in the event handler, at that time, // we need to finish the current transaction @@ -347,7 +347,7 @@ WheelTransaction::OnTimeout(nsITimer* aTimer, void* aClosure) frame->GetContent()->OwnerDoc(), frame->GetContent(), NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"), - true, true); + CanBubble::eYes, Cancelable::eYes); } } diff --git a/dom/html/HTMLDetailsElement.cpp b/dom/html/HTMLDetailsElement.cpp index 44531605c9e9..af96b39a0947 100644 --- a/dom/html/HTMLDetailsElement.cpp +++ b/dom/html/HTMLDetailsElement.cpp @@ -58,7 +58,9 @@ HTMLDetailsElement::BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName, // According to the html spec, a 'toggle' event is a simple event which // does not bubble. mToggleEventDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("toggle"), false); + new AsyncEventDispatcher(this, + NS_LITERAL_STRING("toggle"), + CanBubble::eNo); mToggleEventDispatcher->PostDOMEvent(); } } diff --git a/dom/html/HTMLDialogElement.cpp b/dom/html/HTMLDialogElement.cpp index 48666628e551..04584be5a0c8 100644 --- a/dom/html/HTMLDialogElement.cpp +++ b/dom/html/HTMLDialogElement.cpp @@ -58,7 +58,7 @@ HTMLDialogElement::Close(const mozilla::dom::Optional& aReturnValue) SetOpen(false, ignored); ignored.SuppressException(); RefPtr eventDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("close"), false); + new AsyncEventDispatcher(this, NS_LITERAL_STRING("close"), CanBubble::eNo); eventDispatcher->PostDOMEvent(); } diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp index 3ab3eaaa2eb9..71bd8f0afb75 100644 --- a/dom/html/HTMLFormElement.cpp +++ b/dom/html/HTMLFormElement.cpp @@ -1141,8 +1141,10 @@ HTMLFormElement::PostPasswordEvent() } mFormPasswordEventDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("DOMFormHasPassword"), - true, true); + new AsyncEventDispatcher(this, + NS_LITERAL_STRING("DOMFormHasPassword"), + CanBubble::eYes, + ChromeOnlyDispatch::eYes); mFormPasswordEventDispatcher->PostDOMEvent(); } @@ -1871,7 +1873,8 @@ HTMLFormElement::CheckFormValidity(nsIMutableArray* aInvalidElements) const nsContentUtils::DispatchTrustedEvent(sortedControls[i]->OwnerDoc(), static_cast(sortedControls[i]), NS_LITERAL_STRING("invalid"), - false, true, &defaultAction); + CanBubble::eNo, Cancelable::eYes, + &defaultAction); // Add all unhandled invalid controls to aInvalidElements if the caller // requested them. diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index fb620dc14db7..7a9607853bdd 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -257,14 +257,16 @@ public: nsresult rv = NS_OK; rv = nsContentUtils::DispatchTrustedEvent(mInputElement->OwnerDoc(), static_cast(mInputElement.get()), - NS_LITERAL_STRING("input"), true, - false); + NS_LITERAL_STRING("input"), + CanBubble::eYes, + Cancelable::eNo); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "DispatchTrustedEvent failed"); rv = nsContentUtils::DispatchTrustedEvent(mInputElement->OwnerDoc(), static_cast(mInputElement.get()), - NS_LITERAL_STRING("change"), true, - false); + NS_LITERAL_STRING("change"), + CanBubble::eYes, + Cancelable::eNo); return rv; } @@ -636,8 +638,9 @@ nsColorPickerShownCallback::UpdateInternal(const nsAString& aColor, mValueChanged = true; return nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(), static_cast(mInput.get()), - NS_LITERAL_STRING("input"), true, - false); + NS_LITERAL_STRING("input"), + CanBubble::eYes, + Cancelable::eNo); } return NS_OK; @@ -670,8 +673,9 @@ nsColorPickerShownCallback::Done(const nsAString& aColor) if (mValueChanged) { rv = nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(), static_cast(mInput.get()), - NS_LITERAL_STRING("change"), true, - false); + NS_LITERAL_STRING("change"), + CanBubble::eYes, + Cancelable::eNo); } return rv; @@ -2254,7 +2258,8 @@ HTMLInputElement::OpenDateTimePicker(const DateTimeValue& aInitialValue) nsContentUtils::DispatchChromeEvent(OwnerDoc(), static_cast(this), NS_LITERAL_STRING("MozOpenDateTimePicker"), - true, true); + CanBubble::eYes, + Cancelable::eYes); } void @@ -2268,7 +2273,8 @@ HTMLInputElement::UpdateDateTimePicker(const DateTimeValue& aValue) nsContentUtils::DispatchChromeEvent(OwnerDoc(), static_cast(this), NS_LITERAL_STRING("MozUpdateDateTimePicker"), - true, true); + CanBubble::eYes, + Cancelable::eYes); } void @@ -2281,7 +2287,7 @@ HTMLInputElement::CloseDateTimePicker() nsContentUtils::DispatchChromeEvent(OwnerDoc(), static_cast(this), NS_LITERAL_STRING("MozCloseDateTimePicker"), - true, true); + CanBubble::eYes, Cancelable::eYes); } void @@ -2365,10 +2371,13 @@ HTMLInputElement::SetUserInput(const nsAString& aValue, nsTextEditorState::eSetValue_MoveCursorToEndIfValueChanged); NS_ENSURE_SUCCESS_VOID(rv); + // FIXME: We're inconsistent about whether "input" events are cancelable or + // not. nsContentUtils::DispatchTrustedEvent(OwnerDoc(), static_cast(this), - NS_LITERAL_STRING("input"), true, - true); + NS_LITERAL_STRING("input"), + CanBubble::eYes, + Cancelable::eYes); // If this element is not currently focused, it won't receive a change event for this // update through the normal channels. So fire a change event immediately, instead. @@ -2695,8 +2704,9 @@ HTMLInputElement::FireChangeEventIfNeeded() mFocusedValue = value; nsContentUtils::DispatchTrustedEvent(OwnerDoc(), static_cast(this), - NS_LITERAL_STRING("change"), true, - false); + NS_LITERAL_STRING("change"), + CanBubble::eYes, + Cancelable::eNo); } FileList* @@ -3753,7 +3763,10 @@ HTMLInputElement::CancelRangeThumbDrag(bool aIsForUserEvent) frame->UpdateForValueChange(); } RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("input"), true, false); + new AsyncEventDispatcher(this, + NS_LITERAL_STRING("input"), + CanBubble::eYes, + ChromeOnlyDispatch::eNo); asyncDispatcher->RunDOMEventWhenSafe(); } } @@ -3779,8 +3792,9 @@ HTMLInputElement::SetValueOfRangeForUserEvent(Decimal aValue) if (GetValueAsDecimal() != oldValue) { nsContentUtils::DispatchTrustedEvent(OwnerDoc(), static_cast(this), - NS_LITERAL_STRING("input"), true, - false); + NS_LITERAL_STRING("input"), + CanBubble::eYes, + Cancelable::eNo); } } @@ -3877,8 +3891,9 @@ HTMLInputElement::StepNumberControlForUserEvent(int32_t aDirection) nsContentUtils::DispatchTrustedEvent(OwnerDoc(), static_cast(this), - NS_LITERAL_STRING("input"), true, - false); + NS_LITERAL_STRING("input"), + CanBubble::eYes, + Cancelable::eNo); } static bool @@ -4089,11 +4104,11 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) // Fire input event and then change event. nsContentUtils::DispatchTrustedEvent (OwnerDoc(), static_cast(this), - eEditorInput, true, false); + eEditorInput, CanBubble::eYes, Cancelable::eNo); nsContentUtils::DispatchTrustedEvent (OwnerDoc(), static_cast(this), - eFormChange, true, false); + eFormChange, CanBubble::eYes, Cancelable::eNo); #ifdef ACCESSIBILITY // Fire an event to notify accessibility if (mType == NS_FORM_INPUT_CHECKBOX) { @@ -4646,8 +4661,8 @@ HTMLInputElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(this, NS_LITERAL_STRING("DOMInputPasswordAdded"), - true, - true); + CanBubble::eYes, + ChromeOnlyDispatch::eYes); dispatcher->PostDOMEvent(); } @@ -4835,8 +4850,8 @@ HTMLInputElement::HandleTypeChange(uint8_t aNewType, bool aNotify) AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(this, NS_LITERAL_STRING("DOMInputPasswordAdded"), - true, - true); + CanBubble::eYes, + ChromeOnlyDispatch::eYes); dispatcher->PostDOMEvent(); } } @@ -6005,7 +6020,8 @@ FireEventForAccessibility(HTMLInputElement* aTarget, { Element* element = static_cast(aTarget); return nsContentUtils::DispatchTrustedEvent - (element->OwnerDoc(), element, aEventMessage, true, true); + (element->OwnerDoc(), element, aEventMessage, + CanBubble::eYes, Cancelable::eYes); } #endif diff --git a/dom/html/HTMLLinkElement.cpp b/dom/html/HTMLLinkElement.cpp index 2e561cefd88d..2088e481e3ef 100644 --- a/dom/html/HTMLLinkElement.cpp +++ b/dom/html/HTMLLinkElement.cpp @@ -244,7 +244,10 @@ HTMLLinkElement::CreateAndDispatchEvent(nsIDocument* aDoc, return; RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, aEventName, true, true); + new AsyncEventDispatcher(this, + aEventName, + CanBubble::eYes, + ChromeOnlyDispatch::eYes); // Always run async in order to avoid running script when the content // sink isn't expecting it. asyncDispatcher->PostDOMEvent(); diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index d1a969571097..3f48bfa2dce4 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -364,7 +364,8 @@ public: LOG_EVENT(LogLevel::Debug, ("%p Dispatching simple event source error", mElement.get())); return nsContentUtils::DispatchTrustedEvent( - mElement->OwnerDoc(), mSource, NS_LITERAL_STRING("error"), false, false); + mElement->OwnerDoc(), mSource, NS_LITERAL_STRING("error"), + CanBubble::eNo, Cancelable::eNo); } }; @@ -1434,8 +1435,7 @@ public: mOwner->OwnerDoc(), static_cast(mOwner), NS_LITERAL_STRING("OpenMediaWithExternalApp"), - true, - true); + CanBubble::eYes, Cancelable::eYes); } RefPtr mError; @@ -6308,7 +6308,9 @@ HTMLMediaElement::DispatchEvent(const nsAString& aName) } return nsContentUtils::DispatchTrustedEvent( - OwnerDoc(), static_cast(this), aName, false, false); + OwnerDoc(), static_cast(this), aName, + CanBubble::eNo, + Cancelable::eNo); } void @@ -6956,12 +6958,13 @@ HTMLMediaElement::IsAllowedToPlay() { if (!AutoplayPolicy::IsMediaElementAllowedToPlay(WrapNotNull(this))) { #if defined(MOZ_WIDGET_ANDROID) + // FIXME: This should be chrome-only. nsContentUtils::DispatchTrustedEvent( OwnerDoc(), static_cast(this), NS_LITERAL_STRING("MozAutoplayMediaBlocked"), - false, - false); + CanBubble::eNo, + Cancelable::eNo); #endif LOG(LogLevel::Debug, ("%p %s AutoplayPolicy blocked autoplay.", this, __func__)); diff --git a/dom/html/HTMLMetaElement.cpp b/dom/html/HTMLMetaElement.cpp index c4d3c48f612e..80b10af6c8f9 100644 --- a/dom/html/HTMLMetaElement.cpp +++ b/dom/html/HTMLMetaElement.cpp @@ -156,7 +156,10 @@ HTMLMetaElement::CreateAndDispatchEvent(nsIDocument* aDoc, return; RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, aEventName, true, true); + new AsyncEventDispatcher(this, + aEventName, + CanBubble::eYes, + ChromeOnlyDispatch::eYes); asyncDispatcher->RunDOMEventWhenSafe(); } diff --git a/dom/html/HTMLSlotElement.cpp b/dom/html/HTMLSlotElement.cpp index fa946dbe6bc1..0f0fb52dcf5c 100644 --- a/dom/html/HTMLSlotElement.cpp +++ b/dom/html/HTMLSlotElement.cpp @@ -238,8 +238,9 @@ HTMLSlotElement::FireSlotChangeEvent() { nsContentUtils::DispatchTrustedEvent(OwnerDoc(), static_cast(this), - NS_LITERAL_STRING("slotchange"), true, - false); + NS_LITERAL_STRING("slotchange"), + CanBubble::eYes, + Cancelable::eNo); } JSObject* diff --git a/dom/html/HTMLTextAreaElement.cpp b/dom/html/HTMLTextAreaElement.cpp index 97e1692c38af..aa33d742ce88 100644 --- a/dom/html/HTMLTextAreaElement.cpp +++ b/dom/html/HTMLTextAreaElement.cpp @@ -552,8 +552,9 @@ HTMLTextAreaElement::FireChangeEventIfNeeded() mFocusedValue = value; nsContentUtils::DispatchTrustedEvent(OwnerDoc(), static_cast(this), - NS_LITERAL_STRING("change"), true, - false); + NS_LITERAL_STRING("change"), + CanBubble::eYes, + Cancelable::eNo); } nsresult diff --git a/dom/html/HTMLTrackElement.cpp b/dom/html/HTMLTrackElement.cpp index 1b98af2b10a6..2a53299ab650 100644 --- a/dom/html/HTMLTrackElement.cpp +++ b/dom/html/HTMLTrackElement.cpp @@ -454,7 +454,7 @@ HTMLTrackElement::DispatchTrustedEvent(const nsAString& aName) return; } nsContentUtils::DispatchTrustedEvent(doc, static_cast(this), - aName, false, false); + aName, CanBubble::eNo, Cancelable::eNo); } void diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index b902609cccee..9dd14ec4f499 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -143,7 +143,7 @@ ImageListener::OnStopRequest(nsIRequest* aRequest, nsISupports* aCtxt, nsresult ImageDocument* imgDoc = static_cast(mDocument.get()); nsContentUtils::DispatchChromeEvent(imgDoc, static_cast(imgDoc), NS_LITERAL_STRING("ImageContentLoaded"), - true, true); + CanBubble::eYes, Cancelable::eYes); return MediaDocumentStreamListener::OnStopRequest(aRequest, aCtxt, aStatus); } diff --git a/dom/html/nsIConstraintValidation.cpp b/dom/html/nsIConstraintValidation.cpp index e63f031ac03a..0a8939f13dac 100644 --- a/dom/html/nsIConstraintValidation.cpp +++ b/dom/html/nsIConstraintValidation.cpp @@ -107,9 +107,11 @@ nsIConstraintValidation::CheckValidity() nsCOMPtr content = do_QueryInterface(this); NS_ASSERTION(content, "This class should be inherited by HTML elements only!"); - nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), content, + nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), + content, NS_LITERAL_STRING("invalid"), - false, true); + CanBubble::eNo, + Cancelable::eYes); return false; } @@ -136,7 +138,9 @@ nsIConstraintValidation::ReportValidity() bool defaultAction = true; nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), content, NS_LITERAL_STRING("invalid"), - false, true, &defaultAction); + CanBubble::eNo, + Cancelable::eYes, + &defaultAction); if (!defaultAction) { return false; } diff --git a/dom/html/nsTextEditorState.cpp b/dom/html/nsTextEditorState.cpp index bedba39a7add..9b40b90636d0 100644 --- a/dom/html/nsTextEditorState.cpp +++ b/dom/html/nsTextEditorState.cpp @@ -1724,7 +1724,10 @@ nsTextEditorState::SetSelectionRange(uint32_t aStart, uint32_t aEnd, // It sure would be nice if we had an existing Element* or so to work with. nsCOMPtr node = do_QueryInterface(mTextCtrlElement); RefPtr asyncDispatcher = - new AsyncEventDispatcher(node, NS_LITERAL_STRING("select"), true, false); + new AsyncEventDispatcher(node, + NS_LITERAL_STRING("select"), + CanBubble::eYes, + ChromeOnlyDispatch::eNo); asyncDispatcher->PostDOMEvent(); } diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index c397c5c3646e..3ceac8fbbea4 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -470,11 +470,13 @@ TabParent::ActorDestroy(ActorDestroyReason why) if (channel && !channel->DoBuildIDsMatch()) { nsContentUtils::DispatchTrustedEvent( frameElement->OwnerDoc(), frameElement, - NS_LITERAL_STRING("oop-browser-buildid-mismatch"), true, true); + NS_LITERAL_STRING("oop-browser-buildid-mismatch"), + CanBubble::eYes, Cancelable::eYes); } else { nsContentUtils::DispatchTrustedEvent( frameElement->OwnerDoc(), frameElement, - NS_LITERAL_STRING("oop-browser-crashed"), true, true); + NS_LITERAL_STRING("oop-browser-crashed"), + CanBubble::eYes, Cancelable::eYes); } } } diff --git a/dom/media/BackgroundVideoDecodingPermissionObserver.cpp b/dom/media/BackgroundVideoDecodingPermissionObserver.cpp index e8485109e81b..7b5a17cede81 100644 --- a/dom/media/BackgroundVideoDecodingPermissionObserver.cpp +++ b/dom/media/BackgroundVideoDecodingPermissionObserver.cpp @@ -113,8 +113,8 @@ BackgroundVideoDecodingPermissionObserver::EnableEvent() const RefPtr asyncDispatcher = new AsyncEventDispatcher(doc, NS_LITERAL_STRING("UnselectedTabHover:Enable"), - /* Bubbles */ true, - /* OnlyChromeDispatch */ true); + CanBubble::eYes, + ChromeOnlyDispatch::eYes); asyncDispatcher->PostDOMEvent(); } @@ -129,8 +129,8 @@ BackgroundVideoDecodingPermissionObserver::DisableEvent() const RefPtr asyncDispatcher = new AsyncEventDispatcher(doc, NS_LITERAL_STRING("UnselectedTabHover:Disable"), - /* Bubbles */ true, - /* OnlyChromeDispatch */ true); + CanBubble::eYes, + ChromeOnlyDispatch::eYes); asyncDispatcher->PostDOMEvent(); } diff --git a/dom/media/MediaTrackList.cpp b/dom/media/MediaTrackList.cpp index 703deca10267..7d207413bc77 100644 --- a/dom/media/MediaTrackList.cpp +++ b/dom/media/MediaTrackList.cpp @@ -144,7 +144,9 @@ void MediaTrackList::CreateAndDispatchChangeEvent() { RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("change"), false); + new AsyncEventDispatcher(this, + NS_LITERAL_STRING("change"), + CanBubble::eNo); asyncDispatcher->PostDOMEvent(); } diff --git a/dom/media/eme/MediaEncryptedEvent.cpp b/dom/media/eme/MediaEncryptedEvent.cpp index 5261538052c8..b3f1e8fc93fc 100644 --- a/dom/media/eme/MediaEncryptedEvent.cpp +++ b/dom/media/eme/MediaEncryptedEvent.cpp @@ -56,7 +56,7 @@ already_AddRefed MediaEncryptedEvent::Constructor(EventTarget* aOwner) { RefPtr e = new MediaEncryptedEvent(aOwner); - e->InitEvent(NS_LITERAL_STRING("encrypted"), false, false); + e->InitEvent(NS_LITERAL_STRING("encrypted"), CanBubble::eNo, Cancelable::eNo); e->SetTrusted(true); return e.forget(); } @@ -67,7 +67,7 @@ MediaEncryptedEvent::Constructor(EventTarget* aOwner, const nsTArray& aInitData) { RefPtr e = new MediaEncryptedEvent(aOwner); - e->InitEvent(NS_LITERAL_STRING("encrypted"), false, false); + e->InitEvent(NS_LITERAL_STRING("encrypted"), CanBubble::eNo, Cancelable::eNo); e->mInitDataType = aInitDataType; e->mRawInitData = aInitData; e->SetTrusted(true); diff --git a/dom/media/eme/MediaKeyError.cpp b/dom/media/eme/MediaKeyError.cpp index 635c343642c5..40868b24219b 100644 --- a/dom/media/eme/MediaKeyError.cpp +++ b/dom/media/eme/MediaKeyError.cpp @@ -15,7 +15,7 @@ MediaKeyError::MediaKeyError(EventTarget* aOwner, uint32_t aSystemCode) : Event(aOwner, nullptr, nullptr) , mSystemCode(aSystemCode) { - InitEvent(NS_LITERAL_STRING("error"), false, false); + InitEvent(NS_LITERAL_STRING("error"), CanBubble::eNo, Cancelable::eNo); } MediaKeyError::~MediaKeyError() diff --git a/dom/media/eme/MediaKeySession.cpp b/dom/media/eme/MediaKeySession.cpp index c10ad1c3cf1e..f038d97bba61 100644 --- a/dom/media/eme/MediaKeySession.cpp +++ b/dom/media/eme/MediaKeySession.cpp @@ -607,7 +607,9 @@ MediaKeySession::DispatchKeyStatusesChange() UpdateKeyStatusMap(); RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("keystatuseschange"), false); + new AsyncEventDispatcher(this, + NS_LITERAL_STRING("keystatuseschange"), + CanBubble::eNo); asyncDispatcher->PostDOMEvent(); } diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index 40bff3ad5f00..56fe85f98132 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -841,7 +841,7 @@ public: return nsContentUtils::DispatchTrustedEvent(doc, static_cast(mAudioContext), NS_LITERAL_STRING("statechange"), - false, false); + CanBubble::eNo, Cancelable::eNo); } private: diff --git a/dom/media/webaudio/AudioProcessingEvent.h b/dom/media/webaudio/AudioProcessingEvent.h index 41bfbb594370..ec9b1a57738d 100644 --- a/dom/media/webaudio/AudioProcessingEvent.h +++ b/dom/media/webaudio/AudioProcessingEvent.h @@ -31,7 +31,7 @@ public: uint32_t aNumberOfInputChannels, double aPlaybackTime) { - InitEvent(NS_LITERAL_STRING("audioprocess"), false, false); + InitEvent(NS_LITERAL_STRING("audioprocess"), CanBubble::eNo, Cancelable::eNo); mInputBuffer = aInputBuffer; mNumberOfInputChannels = aNumberOfInputChannels; mPlaybackTime = aPlaybackTime; diff --git a/dom/messagechannel/MessagePort.cpp b/dom/messagechannel/MessagePort.cpp index 76d0b7287e3c..0cf11cf2e88a 100644 --- a/dom/messagechannel/MessagePort.cpp +++ b/dom/messagechannel/MessagePort.cpp @@ -151,8 +151,7 @@ private: } event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), - false /* non-bubbling */, - false /* cancelable */, value, EmptyString(), + CanBubble::eNo, Cancelable::eNo, value, EmptyString(), EmptyString(), nullptr, ports); event->SetTrusted(true); diff --git a/dom/permission/PermissionStatus.cpp b/dom/permission/PermissionStatus.cpp index 680ece1d0f26..5502c9cea421 100644 --- a/dom/permission/PermissionStatus.cpp +++ b/dom/permission/PermissionStatus.cpp @@ -120,7 +120,7 @@ PermissionStatus::PermissionChanged() UpdateState(); if (mState != oldState) { RefPtr eventDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("change"), false); + new AsyncEventDispatcher(this, NS_LITERAL_STRING("change"), CanBubble::eNo); eventDispatcher->PostDOMEvent(); } } diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index e4fe71a1ae09..d7b5f19a65bb 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -123,7 +123,7 @@ public: { nsContentUtils::DispatchTrustedEvent(mContent->OwnerDoc(), mContent, mFinished ? NS_LITERAL_STRING("MozPaintWaitFinished") : NS_LITERAL_STRING("MozPaintWait"), - true, true); + CanBubble::eYes, Cancelable::eYes); return NS_OK; } @@ -2003,7 +2003,7 @@ void nsPluginInstanceOwner::PerformDelayedBlurs() nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), windowRoot, NS_LITERAL_STRING("MozPerformDelayedBlur"), - false, false, nullptr); + CanBuble::No, Cancelable::eNo, nullptr); } #endif diff --git a/dom/presentation/PresentationConnection.cpp b/dom/presentation/PresentationConnection.cpp index 684b93539d16..a183033d0c4f 100644 --- a/dom/presentation/PresentationConnection.cpp +++ b/dom/presentation/PresentationConnection.cpp @@ -463,7 +463,9 @@ PresentationConnection::ProcessStateChanged(nsresult aReason) } RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("connect"), false); + new AsyncEventDispatcher(this, + NS_LITERAL_STRING("connect"), + CanBubble::eNo); return asyncDispatcher->PostDOMEvent(); } case PresentationConnectionState::Closed: { @@ -494,7 +496,9 @@ PresentationConnection::ProcessStateChanged(nsresult aReason) if (!nsContentUtils::ShouldResistFingerprinting()) { // Ensure onterminate event is fired. RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, NS_LITERAL_STRING("terminate"), false); + new AsyncEventDispatcher(this, + NS_LITERAL_STRING("terminate"), + CanBubble::eNo); Unused << NS_WARN_IF(NS_FAILED(asyncDispatcher->PostDOMEvent())); } @@ -644,7 +648,7 @@ PresentationConnection::DispatchMessageEvent(JS::Handle aData) messageEvent->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), - false, false, aData, origin, + CanBubble::eNo, Cancelable::eNo, aData, origin, EmptyString(), nullptr, Sequence>()); messageEvent->SetTrusted(true); diff --git a/dom/script/ScriptElement.cpp b/dom/script/ScriptElement.cpp index 1812e5512e34..390700af771d 100644 --- a/dom/script/ScriptElement.cpp +++ b/dom/script/ScriptElement.cpp @@ -48,8 +48,8 @@ ScriptElement::FireErrorEvent() return nsContentUtils::DispatchTrustedEvent(cont->OwnerDoc(), cont, NS_LITERAL_STRING("error"), - false /* bubbles */, - false /* cancelable */); + CanBubble::eNo, + Cancelable::eNo); } NS_IMETHODIMP diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 286f9a6f0715..bdd91ba586eb 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -1960,7 +1960,7 @@ ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest) nsContentUtils::DispatchTrustedEvent(scriptElem->OwnerDoc(), scriptElem, NS_LITERAL_STRING("beforescriptexecute"), - true, true, &runScript); + CanBubble::eYes, Cancelable::eYes, &runScript); } // Inner window could have gone away after firing beforescriptexecute @@ -1982,7 +1982,7 @@ ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest) nsContentUtils::DispatchTrustedEvent(scriptElem->OwnerDoc(), scriptElem, NS_LITERAL_STRING("afterscriptexecute"), - true, false); + CanBubble::eYes, Cancelable::eNo); } FireScriptEvaluated(rv, aRequest); diff --git a/dom/script/ScriptTrace.cpp b/dom/script/ScriptTrace.cpp index 1c2078d5ce42..2c6ff3101cc7 100644 --- a/dom/script/ScriptTrace.cpp +++ b/dom/script/ScriptTrace.cpp @@ -32,7 +32,10 @@ TestingDispatchEvent(nsIScriptElement* aScriptElement, } RefPtr dispatcher = - new AsyncEventDispatcher(target, aEventType, true, false); + new AsyncEventDispatcher(target, + aEventType, + CanBubble::eYes, + ChromeOnlyDispatch::eNo); return dispatcher->PostDOMEvent(); } diff --git a/dom/websocket/WebSocket.cpp b/dom/websocket/WebSocket.cpp index 661f8b32a90b..2148fac16d40 100644 --- a/dom/websocket/WebSocket.cpp +++ b/dom/websocket/WebSocket.cpp @@ -2024,8 +2024,9 @@ WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData, RefPtr event = new MessageEvent(this, nullptr, nullptr); - event->InitMessageEvent(nullptr, MESSAGE_EVENT_STRING, false, false, - jsData, mImpl->mUTF16Origin, EmptyString(), nullptr, + event->InitMessageEvent(nullptr, MESSAGE_EVENT_STRING, CanBubble::eNo, + Cancelable::eNo, jsData, mImpl->mUTF16Origin, + EmptyString(), nullptr, Sequence>()); event->SetTrusted(true); diff --git a/dom/workers/MessageEventRunnable.cpp b/dom/workers/MessageEventRunnable.cpp index c13add728565..99329442beef 100644 --- a/dom/workers/MessageEventRunnable.cpp +++ b/dom/workers/MessageEventRunnable.cpp @@ -89,8 +89,8 @@ MessageEventRunnable::DispatchDOMEvent(JSContext* aCx, RefPtr event = new MessageEvent(aTarget, nullptr, nullptr); event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), - false /* non-bubbling */, - false /* cancelable */, + CanBubble::eNo, + Cancelable::eNo, messageData, EmptyString(), EmptyString(), diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 918fb5d6f1b0..f2f52f5c64b6 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -2370,7 +2370,9 @@ RuntimeService::CreateSharedWorkerFromLoadInfo(JSContext* aCx, // We're done here. Just queue up our error event and return our // dead-on-arrival SharedWorker. RefPtr errorEvent = - new AsyncEventDispatcher(sharedWorker, NS_LITERAL_STRING("error"), false); + new AsyncEventDispatcher(sharedWorker, + NS_LITERAL_STRING("error"), + CanBubble::eNo); errorEvent->PostDOMEvent(); sharedWorker.forget(aSharedWorker); return NS_OK; diff --git a/dom/workers/WorkerDebugger.cpp b/dom/workers/WorkerDebugger.cpp index 66395492ba7d..cc69715a2b45 100644 --- a/dom/workers/WorkerDebugger.cpp +++ b/dom/workers/WorkerDebugger.cpp @@ -58,8 +58,8 @@ private: nullptr); event->InitMessageEvent(nullptr, NS_LITERAL_STRING("message"), - false, // canBubble - true, // cancelable + CanBubble::eNo, + Cancelable::eYes, data, EmptyString(), EmptyString(), diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index e1b25795240b..786852d8ff7b 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -2649,8 +2649,8 @@ XULDocument::DoneWalking() this, static_cast(this), NS_LITERAL_STRING("MozBeforeInitialXULLayout"), - true, - false); + CanBubble::eYes, + Cancelable::eNo); // Before starting layout, check whether we're a toplevel chrome // window. If we are, setup some state so that we don't have to restyle diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index c0b60173cbdf..400f058b9494 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -911,8 +911,8 @@ nsXULElement::RemoveChildNode(nsIContent* aKid, bool aNotify) nsContentUtils::DispatchTrustedEvent(doc, static_cast(this), NS_LITERAL_STRING("select"), - false, - true); + CanBubble::eNo, + Cancelable::eYes); } } @@ -1398,7 +1398,7 @@ nsXULElement::LoadSrc() (new AsyncEventDispatcher(this, NS_LITERAL_STRING("XULFrameLoaderCreated"), - /* aBubbles */ true))->RunDOMEventWhenSafe(); + CanBubble::eYes))->RunDOMEventWhenSafe(); } frameLoader->LoadFrame(false); diff --git a/gfx/layers/apz/util/APZCCallbackHelper.cpp b/gfx/layers/apz/util/APZCCallbackHelper.cpp index 4d0cdb0c5edf..c01e121f36ce 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.cpp +++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp @@ -862,7 +862,8 @@ APZCCallbackHelper::NotifyMozMouseScrollEvent(const FrameMetrics::ViewID& aScrol nsContentUtils::DispatchTrustedEvent( ownerDoc, targetContent, aEvent, - true, true); + CanBubble::eYes, + Cancelable::eYes); } void diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 33220992cdda..016423d83d81 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -531,7 +531,10 @@ private: for (int32_t i = 0; i < targets.Count(); ++i) { nsIDocument* d = targets[i]; nsContentUtils::DispatchTrustedEvent(d, d->GetWindow(), - aEvent, false, false, nullptr); + aEvent, + CanBubble::eNo, + Cancelable::eNo, + nullptr); } } @@ -3055,7 +3058,7 @@ nsDocumentViewer::SetTextZoom(float aTextZoom) if (textZoomChange) { nsContentUtils::DispatchChromeEvent(mDocument, static_cast(mDocument), NS_LITERAL_STRING("TextZoomChange"), - true, true); + CanBubble::eYes, Cancelable::eYes); } return NS_OK; @@ -3175,7 +3178,7 @@ nsDocumentViewer::SetFullZoom(float aFullZoom) if (fullZoomChange) { nsContentUtils::DispatchChromeEvent(mDocument, static_cast(mDocument), NS_LITERAL_STRING("FullZoomChange"), - true, true); + CanBubble::eYes, Cancelable::eYes); } return NS_OK; diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index 1c05796fbdd0..8e7e4855c7bd 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -1678,8 +1678,8 @@ void nsComboboxControlFrame::FireValueChangeEvent() { // Fire ValueChange event to indicate data value of combo box has changed nsContentUtils::AddScriptRunner( - new AsyncEventDispatcher(mContent, NS_LITERAL_STRING("ValueChange"), true, - false)); + new AsyncEventDispatcher(mContent, NS_LITERAL_STRING("ValueChange"), + CanBubble::eYes, ChromeOnlyDispatch::eNo)); } void diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index 2f2240a3f366..ee931863a435 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -328,12 +328,14 @@ nsFileControlFrame::DnDListener::HandleEvent(Event* aEvent) nsContentUtils::DispatchTrustedEvent(inputElement->OwnerDoc(), static_cast(inputElement), - NS_LITERAL_STRING("input"), true, - false); + NS_LITERAL_STRING("input"), + CanBubble::eYes, + Cancelable::eNo); nsContentUtils::DispatchTrustedEvent(inputElement->OwnerDoc(), static_cast(inputElement), - NS_LITERAL_STRING("change"), true, - false); + NS_LITERAL_STRING("change"), + CanBubble::eYes, + Cancelable::eNo); } } diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 67f13fa2fd9d..ff64eb0f73df 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -158,8 +158,9 @@ nsListControlFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostD if (ShouldFireDropDownEvent()) { nsContentUtils::AddScriptRunner( new AsyncEventDispatcher(mContent, - NS_LITERAL_STRING("mozhidedropdown"), true, - true)); + NS_LITERAL_STRING("mozhidedropdown"), + CanBubble::eYes, + ChromeOnlyDispatch::eYes)); } nsCheckboxRadioFrame::RegUnRegAccessKey(static_cast(this), false); @@ -1387,12 +1388,14 @@ nsListControlFrame::FireOnInputAndOnChange() nsCOMPtr content = mContent; // Dispatch the input event. nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), content, - NS_LITERAL_STRING("input"), true, - false); + NS_LITERAL_STRING("input"), + CanBubble::eYes, + Cancelable::eNo); // Dispatch the change event. nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), content, - NS_LITERAL_STRING("change"), true, - false); + NS_LITERAL_STRING("change"), + CanBubble::eYes, + Cancelable::eNo); } NS_IMETHODIMP @@ -1785,7 +1788,8 @@ FireShowDropDownEvent(nsIContent* aContent, bool aShow, bool aIsSourceTouchEvent eventName = NS_LITERAL_STRING("mozhidedropdown"); } nsContentUtils::DispatchChromeEvent(aContent->OwnerDoc(), aContent, - eventName, true, false); + eventName, CanBubble::eYes, + Cancelable::eNo); return true; } diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 61aa69338a1b..05092e80e062 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -3870,7 +3870,10 @@ nsFrame::FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent) if (target) { RefPtr asyncDispatcher = - new AsyncEventDispatcher(target, aDOMEventName, true, false); + new AsyncEventDispatcher(target, + aDOMEventName, + CanBubble::eYes, + ChromeOnlyDispatch::eNo); DebugOnly rv = asyncDispatcher->PostDOMEvent(); NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncEventDispatcher failed to dispatch"); } diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 71e467412b96..9fad047689ef 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -4537,8 +4537,8 @@ ScrollFrameHelper::FireScrollEndEvent() nsContentUtils::DispatchEventOnlyToChrome(mOuter->GetContent()->OwnerDoc(), mOuter->GetContent(), NS_LITERAL_STRING("scrollend"), - true /* aCanBubble */, - false /* aCancelable */); + CanBubble::eYes, + Cancelable::eNo); } void diff --git a/layout/generic/nsVideoFrame.cpp b/layout/generic/nsVideoFrame.cpp index e2841822c063..f09df439a76b 100644 --- a/layout/generic/nsVideoFrame.cpp +++ b/layout/generic/nsVideoFrame.cpp @@ -269,7 +269,7 @@ public: NS_IMETHOD Run() override { nsContentUtils::DispatchTrustedEvent(mContent->OwnerDoc(), mContent, NS_LITERAL_STRING("resizevideocontrols"), - false, false); + CanBubble::eNo, Cancelable::eNo); return NS_OK; } nsCOMPtr mContent; diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index 9ace2047c10d..f07f77be598a 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -1641,7 +1641,7 @@ nsPrintJob::FirePrintingErrorEvent(nsresult aPrintError) RefPtr asyncDispatcher = new AsyncEventDispatcher(doc, event); - asyncDispatcher->mOnlyChromeDispatch = true; + asyncDispatcher->mOnlyChromeDispatch = ChromeOnlyDispatch::eYes; asyncDispatcher->RunDOMEventWhenSafe(); // Inform any progress listeners of the Error. @@ -1992,8 +1992,9 @@ nsPrintJob::FirePrintPreviewUpdateEvent() if (mIsDoingPrintPreview && !mIsDoingPrinting) { nsCOMPtr cv = do_QueryInterface(mDocViewerPrint); (new AsyncEventDispatcher( - cv->GetDocument(), NS_LITERAL_STRING("printPreviewUpdate"), true, true) - )->RunDOMEventWhenSafe(); + cv->GetDocument(), NS_LITERAL_STRING("printPreviewUpdate"), + CanBubble::eYes, ChromeOnlyDispatch::eYes + ))->RunDOMEventWhenSafe(); } } diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index c8ff59855121..2b890cc87572 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -1689,7 +1689,7 @@ FontFaceSet::DispatchLoadingEventAndReplaceReadyPromise() } (new AsyncEventDispatcher(this, NS_LITERAL_STRING("loading"), - false))->PostDOMEvent(); + CanBubble::eNo))->PostDOMEvent(); if (PrefEnabled()) { if (mReady && diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 2a1ad375b8fd..896b7289c679 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -322,7 +322,7 @@ SheetLoadData::FireLoadEvent(nsIThreadInternal* aThread) mLoadFailed ? NS_LITERAL_STRING("error") : NS_LITERAL_STRING("load"), - false, false); + CanBubble::eNo, Cancelable::eNo); // And unblock onload mLoader->UnblockOnload(true); @@ -1989,7 +1989,8 @@ Loader::LoadStyleLink(const SheetInfo& aInfo, nsICSSLoaderObserver* aObserver) RefPtr loadBlockingAsyncDispatcher = new LoadBlockingAsyncEventDispatcher(aInfo.mContent, NS_LITERAL_STRING("error"), - false, false); + CanBubble::eNo, + ChromeOnlyDispatch::eNo); loadBlockingAsyncDispatcher->PostDOMEvent(); } return Err(rv); diff --git a/layout/xul/tree/nsTreeSelection.cpp b/layout/xul/tree/nsTreeSelection.cpp index 7b91502911ea..ae3a8b0a6053 100644 --- a/layout/xul/tree/nsTreeSelection.cpp +++ b/layout/xul/tree/nsTreeSelection.cpp @@ -652,7 +652,7 @@ NS_IMETHODIMP nsTreeSelection::SetCurrentIndex(int32_t aIndex) new AsyncEventDispatcher(treeElt, (aIndex != -1 ? DOMMenuItemActive : DOMMenuItemInactive), - true, false); + CanBubble::eYes, ChromeOnlyDispatch::eNo); return asyncDispatcher->PostDOMEvent(); } @@ -835,7 +835,8 @@ nsTreeSelection::FireOnSelectHandler() NS_ENSURE_STATE(elt); RefPtr asyncDispatcher = - new AsyncEventDispatcher(elt, NS_LITERAL_STRING("select"), true, false); + new AsyncEventDispatcher(elt, NS_LITERAL_STRING("select"), + CanBubble::eYes, ChromeOnlyDispatch::eNo); asyncDispatcher->RunDOMEventWhenSafe(); return NS_OK; } diff --git a/uriloader/prefetch/nsPrefetchService.cpp b/uriloader/prefetch/nsPrefetchService.cpp index d2eeb7343601..a33577c56698 100644 --- a/uriloader/prefetch/nsPrefetchService.cpp +++ b/uriloader/prefetch/nsPrefetchService.cpp @@ -532,7 +532,7 @@ nsPrefetchService::DispatchEvent(nsPrefetchNode *node, bool aSuccess) aSuccess ? NS_LITERAL_STRING("load") : NS_LITERAL_STRING("error"), - /* aCanBubble = */ false); + CanBubble::eNo); dispatcher->RequireNodeInDocument(); dispatcher->PostDOMEvent(); } @@ -731,11 +731,10 @@ nsPrefetchService::Preload(nsIURI *aURI, nsCOMPtr domNode = do_QueryInterface(aSource); if (domNode && domNode->IsInComposedDoc()) { RefPtr asyncDispatcher = - new AsyncEventDispatcher(//domNode->OwnerDoc(), - domNode, + new AsyncEventDispatcher(domNode, NS_LITERAL_STRING("error"), - /* aCanBubble = */ false, - /* aCancelable = */ false); + CanBubble::eNo, + ChromeOnlyDispatch::eNo); asyncDispatcher->RunDOMEventWhenSafe(); } return NS_OK; @@ -778,8 +777,8 @@ nsPrefetchService::Preload(nsIURI *aURI, RefPtr asyncDispatcher = new AsyncEventDispatcher(domNode, NS_LITERAL_STRING("error"), - /* aCanBubble = */ false, - /* aCancelable = */ false); + CanBubble::eNo, + ChromeOnlyDispatch::eNo); asyncDispatcher->RunDOMEventWhenSafe(); } } diff --git a/widget/EventForwards.h b/widget/EventForwards.h index ed2496750b0d..b7338c93bca1 100644 --- a/widget/EventForwards.h +++ b/widget/EventForwards.h @@ -33,6 +33,30 @@ enum nsEventStatus namespace mozilla { +enum class CanBubble +{ + eYes, + eNo +}; + +enum class Cancelable +{ + eYes, + eNo +}; + +enum class ChromeOnlyDispatch +{ + eYes, + eNo +}; + +enum class Trusted +{ + eYes, + eNo +}; + /** * Event messages */ diff --git a/xpfe/appshell/nsWebShellWindow.cpp b/xpfe/appshell/nsWebShellWindow.cpp index 187d68f20d36..0592adc6b591 100644 --- a/xpfe/appshell/nsWebShellWindow.cpp +++ b/xpfe/appshell/nsWebShellWindow.cpp @@ -283,7 +283,7 @@ nsWebShellWindow::WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) nsContentUtils::DispatchChromeEvent(mDocShell->GetDocument(), eventTarget, NS_LITERAL_STRING("MozUpdateWindowPos"), - false, false, nullptr); + CanBubble::eNo, Cancelable::eNo, nullptr); } // Persist position, but not immediately, in case this OS is firing