diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 12df916dac1a..6f58a4c21d0b 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -4371,6 +4371,7 @@ nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, CanBubble aCanBubble, Cancelable aCancelable, + Composed aComposed, Trusted aTrusted, Event** aEvent, EventTarget** aTargetOut) @@ -4385,7 +4386,7 @@ nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget, return err.StealNSResult(); } - event->InitEvent(aEventName, aCanBubble, aCancelable); + event->InitEvent(aEventName, aCanBubble, aCancelable, aComposed); event->SetTrusted(aTrusted == Trusted::eYes); event->SetTarget(target); @@ -4401,10 +4402,11 @@ nsContentUtils::DispatchTrustedEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, CanBubble aCanBubble, Cancelable aCancelable, + Composed aComposed, bool* aDefaultAction) { return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, - Trusted::eYes, aDefaultAction); + aComposed, Trusted::eYes, aDefaultAction); } // static @@ -4416,7 +4418,7 @@ nsContentUtils::DispatchUntrustedEvent(nsIDocument* aDoc, nsISupports* aTarget, bool* aDefaultAction) { return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, - Trusted::eNo, aDefaultAction); + Composed::eDefault, Trusted::eNo, aDefaultAction); } // static @@ -4425,6 +4427,7 @@ nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, const nsAString& aEventName, CanBubble aCanBubble, Cancelable aCancelable, + Composed aComposed, Trusted aTrusted, bool* aDefaultAction, ChromeOnlyDispatch aOnlyChromeDispatch) @@ -4432,7 +4435,8 @@ nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget, RefPtr event; nsCOMPtr target; nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble, - aCancelable, aTrusted, getter_AddRefs(event), + aCancelable, aComposed, aTrusted, + getter_AddRefs(event), getter_AddRefs(target)); NS_ENSURE_SUCCESS(rv, rv); event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = @@ -4496,7 +4500,8 @@ nsContentUtils::DispatchChromeEvent(nsIDocument *aDoc, RefPtr event; nsCOMPtr target; nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble, - aCancelable, Trusted::eYes, + aCancelable, Composed::eDefault, + Trusted::eYes, getter_AddRefs(event), getter_AddRefs(target)); NS_ENSURE_SUCCESS(rv, rv); @@ -4543,7 +4548,8 @@ nsContentUtils::DispatchEventOnlyToChrome(nsIDocument* aDoc, bool* aDefaultAction) { return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, - Trusted::eYes, aDefaultAction, ChromeOnlyDispatch::eYes); + Composed::eDefault, Trusted::eYes, aDefaultAction, + ChromeOnlyDispatch::eYes); } /* static */ diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index bc3a8f76b0d7..299c61427bbc 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -203,6 +203,7 @@ class nsContentUtils typedef mozilla::dom::Element Element; typedef mozilla::Cancelable Cancelable; typedef mozilla::CanBubble CanBubble; + typedef mozilla::Composed Composed; typedef mozilla::ChromeOnlyDispatch ChromeOnlyDispatch; typedef mozilla::EventMessage EventMessage; typedef mozilla::TimeDuration TimeDuration; @@ -1345,6 +1346,7 @@ public: * @param aEventName The name of the event. * @param aCanBubble Whether the event can bubble. * @param aCancelable Is the event cancelable. + * @param aCopmosed Is the event composed. * @param aDefaultAction Set to true if default action should be taken, * see EventTarget::DispatchEvent. */ @@ -1353,8 +1355,21 @@ public: const nsAString& aEventName, CanBubble, Cancelable, + Composed aComposed = Composed::eDefault, bool* aDefaultAction = nullptr); + static nsresult DispatchTrustedEvent(nsIDocument* aDoc, + nsISupports* aTarget, + const nsAString& aEventName, + CanBubble aCanBubble, + Cancelable aCancelable, + bool* aDefaultAction) + { + return DispatchTrustedEvent(aDoc, aTarget, aEventName, + aCanBubble, aCancelable, + Composed::eDefault, aDefaultAction); + } + /** * This method creates and dispatches a trusted event using an event message. * @param aDoc The document which will be used to create the event. @@ -3339,6 +3354,7 @@ private: const nsAString& aEventName, CanBubble, Cancelable, + Composed, Trusted, bool* aDefaultAction = nullptr, ChromeOnlyDispatch = ChromeOnlyDispatch::eNo); diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index 663716ac3973..900929cffc1b 100644 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -491,7 +491,8 @@ Event::EnsureWebAccessibleRelatedTarget(EventTarget* aRelatedTarget) void Event::InitEvent(const nsAString& aEventTypeArg, mozilla::CanBubble aCanBubbleArg, - mozilla::Cancelable aCancelableArg) + mozilla::Cancelable aCancelableArg, + mozilla::Composed aComposedArg) { // Make sure this event isn't already being dispatched. NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); @@ -507,6 +508,9 @@ Event::InitEvent(const nsAString& aEventTypeArg, mEvent->mFlags.mBubbles = aCanBubbleArg == CanBubble::eYes; mEvent->mFlags.mCancelable = aCancelableArg == Cancelable::eYes; + if (aComposedArg != Composed::eDefault) { + mEvent->mFlags.mComposed = aComposedArg == Composed::eYes; + } mEvent->mFlags.mDefaultPrevented = false; mEvent->mFlags.mDefaultPreventedByContent = false; diff --git a/dom/events/Event.h b/dom/events/Event.h index 7b849c4b8eaa..31f4ae0322a6 100755 --- a/dom/events/Event.h +++ b/dom/events/Event.h @@ -158,7 +158,8 @@ public: void InitEvent(const nsAString& aEventTypeArg, mozilla::CanBubble, - mozilla::Cancelable); + mozilla::Cancelable, + mozilla::Composed = mozilla::Composed::eDefault); void SetTarget(EventTarget* aTarget); virtual void DuplicatePrivateData(); diff --git a/dom/events/PendingFullscreenEvent.h b/dom/events/PendingFullscreenEvent.h index 673507a024bd..9eb35d0aa0a7 100644 --- a/dom/events/PendingFullscreenEvent.h +++ b/dom/events/PendingFullscreenEvent.h @@ -52,7 +52,7 @@ public: } Unused << nsContentUtils::DispatchTrustedEvent( mDocument, mDocument, name, - CanBubble::eYes, Cancelable::eNo, nullptr); + CanBubble::eYes, Cancelable::eNo, Composed::eYes); } private: