Bug 1375319 part 1 - Make DispatchTrustedEvent able to dispatch composed event and have fullscreen events composed. r=smaug

Depends on D5394

Differential Revision: https://phabricator.services.mozilla.com/D5414

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Xidorn Quan 2018-09-14 00:05:39 +00:00
Родитель 956bb2d407
Коммит 35bf576e96
5 изменённых файлов: 36 добавлений и 9 удалений

Просмотреть файл

@ -4371,6 +4371,7 @@ nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget,
const nsAString& aEventName, const nsAString& aEventName,
CanBubble aCanBubble, CanBubble aCanBubble,
Cancelable aCancelable, Cancelable aCancelable,
Composed aComposed,
Trusted aTrusted, Trusted aTrusted,
Event** aEvent, Event** aEvent,
EventTarget** aTargetOut) EventTarget** aTargetOut)
@ -4385,7 +4386,7 @@ nsresult GetEventAndTarget(nsIDocument* aDoc, nsISupports* aTarget,
return err.StealNSResult(); return err.StealNSResult();
} }
event->InitEvent(aEventName, aCanBubble, aCancelable); event->InitEvent(aEventName, aCanBubble, aCancelable, aComposed);
event->SetTrusted(aTrusted == Trusted::eYes); event->SetTrusted(aTrusted == Trusted::eYes);
event->SetTarget(target); event->SetTarget(target);
@ -4401,10 +4402,11 @@ nsContentUtils::DispatchTrustedEvent(nsIDocument* aDoc, nsISupports* aTarget,
const nsAString& aEventName, const nsAString& aEventName,
CanBubble aCanBubble, CanBubble aCanBubble,
Cancelable aCancelable, Cancelable aCancelable,
Composed aComposed,
bool* aDefaultAction) bool* aDefaultAction)
{ {
return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable,
Trusted::eYes, aDefaultAction); aComposed, Trusted::eYes, aDefaultAction);
} }
// static // static
@ -4416,7 +4418,7 @@ nsContentUtils::DispatchUntrustedEvent(nsIDocument* aDoc, nsISupports* aTarget,
bool* aDefaultAction) bool* aDefaultAction)
{ {
return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable,
Trusted::eNo, aDefaultAction); Composed::eDefault, Trusted::eNo, aDefaultAction);
} }
// static // static
@ -4425,6 +4427,7 @@ nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget,
const nsAString& aEventName, const nsAString& aEventName,
CanBubble aCanBubble, CanBubble aCanBubble,
Cancelable aCancelable, Cancelable aCancelable,
Composed aComposed,
Trusted aTrusted, Trusted aTrusted,
bool* aDefaultAction, bool* aDefaultAction,
ChromeOnlyDispatch aOnlyChromeDispatch) ChromeOnlyDispatch aOnlyChromeDispatch)
@ -4432,7 +4435,8 @@ nsContentUtils::DispatchEvent(nsIDocument* aDoc, nsISupports* aTarget,
RefPtr<Event> event; RefPtr<Event> event;
nsCOMPtr<EventTarget> target; nsCOMPtr<EventTarget> target;
nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble, nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble,
aCancelable, aTrusted, getter_AddRefs(event), aCancelable, aComposed, aTrusted,
getter_AddRefs(event),
getter_AddRefs(target)); getter_AddRefs(target));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch =
@ -4496,7 +4500,8 @@ nsContentUtils::DispatchChromeEvent(nsIDocument *aDoc,
RefPtr<Event> event; RefPtr<Event> event;
nsCOMPtr<EventTarget> target; nsCOMPtr<EventTarget> target;
nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble, nsresult rv = GetEventAndTarget(aDoc, aTarget, aEventName, aCanBubble,
aCancelable, Trusted::eYes, aCancelable, Composed::eDefault,
Trusted::eYes,
getter_AddRefs(event), getter_AddRefs(event),
getter_AddRefs(target)); getter_AddRefs(target));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -4543,7 +4548,8 @@ nsContentUtils::DispatchEventOnlyToChrome(nsIDocument* aDoc,
bool* aDefaultAction) bool* aDefaultAction)
{ {
return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable, return DispatchEvent(aDoc, aTarget, aEventName, aCanBubble, aCancelable,
Trusted::eYes, aDefaultAction, ChromeOnlyDispatch::eYes); Composed::eDefault, Trusted::eYes, aDefaultAction,
ChromeOnlyDispatch::eYes);
} }
/* static */ /* static */

Просмотреть файл

@ -203,6 +203,7 @@ class nsContentUtils
typedef mozilla::dom::Element Element; typedef mozilla::dom::Element Element;
typedef mozilla::Cancelable Cancelable; typedef mozilla::Cancelable Cancelable;
typedef mozilla::CanBubble CanBubble; typedef mozilla::CanBubble CanBubble;
typedef mozilla::Composed Composed;
typedef mozilla::ChromeOnlyDispatch ChromeOnlyDispatch; typedef mozilla::ChromeOnlyDispatch ChromeOnlyDispatch;
typedef mozilla::EventMessage EventMessage; typedef mozilla::EventMessage EventMessage;
typedef mozilla::TimeDuration TimeDuration; typedef mozilla::TimeDuration TimeDuration;
@ -1345,6 +1346,7 @@ public:
* @param aEventName The name of the event. * @param aEventName The name of the event.
* @param aCanBubble Whether the event can bubble. * @param aCanBubble Whether the event can bubble.
* @param aCancelable Is the event cancelable. * @param aCancelable Is the event cancelable.
* @param aCopmosed Is the event composed.
* @param aDefaultAction Set to true if default action should be taken, * @param aDefaultAction Set to true if default action should be taken,
* see EventTarget::DispatchEvent. * see EventTarget::DispatchEvent.
*/ */
@ -1353,8 +1355,21 @@ public:
const nsAString& aEventName, const nsAString& aEventName,
CanBubble, CanBubble,
Cancelable, Cancelable,
Composed aComposed = Composed::eDefault,
bool* aDefaultAction = nullptr); 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. * This method creates and dispatches a trusted event using an event message.
* @param aDoc The document which will be used to create the event. * @param aDoc The document which will be used to create the event.
@ -3339,6 +3354,7 @@ private:
const nsAString& aEventName, const nsAString& aEventName,
CanBubble, CanBubble,
Cancelable, Cancelable,
Composed,
Trusted, Trusted,
bool* aDefaultAction = nullptr, bool* aDefaultAction = nullptr,
ChromeOnlyDispatch = ChromeOnlyDispatch::eNo); ChromeOnlyDispatch = ChromeOnlyDispatch::eNo);

Просмотреть файл

@ -491,7 +491,8 @@ Event::EnsureWebAccessibleRelatedTarget(EventTarget* aRelatedTarget)
void void
Event::InitEvent(const nsAString& aEventTypeArg, Event::InitEvent(const nsAString& aEventTypeArg,
mozilla::CanBubble aCanBubbleArg, mozilla::CanBubble aCanBubbleArg,
mozilla::Cancelable aCancelableArg) mozilla::Cancelable aCancelableArg,
mozilla::Composed aComposedArg)
{ {
// Make sure this event isn't already being dispatched. // Make sure this event isn't already being dispatched.
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
@ -507,6 +508,9 @@ Event::InitEvent(const nsAString& aEventTypeArg,
mEvent->mFlags.mBubbles = aCanBubbleArg == CanBubble::eYes; mEvent->mFlags.mBubbles = aCanBubbleArg == CanBubble::eYes;
mEvent->mFlags.mCancelable = aCancelableArg == Cancelable::eYes; mEvent->mFlags.mCancelable = aCancelableArg == Cancelable::eYes;
if (aComposedArg != Composed::eDefault) {
mEvent->mFlags.mComposed = aComposedArg == Composed::eYes;
}
mEvent->mFlags.mDefaultPrevented = false; mEvent->mFlags.mDefaultPrevented = false;
mEvent->mFlags.mDefaultPreventedByContent = false; mEvent->mFlags.mDefaultPreventedByContent = false;

Просмотреть файл

@ -158,7 +158,8 @@ public:
void InitEvent(const nsAString& aEventTypeArg, void InitEvent(const nsAString& aEventTypeArg,
mozilla::CanBubble, mozilla::CanBubble,
mozilla::Cancelable); mozilla::Cancelable,
mozilla::Composed = mozilla::Composed::eDefault);
void SetTarget(EventTarget* aTarget); void SetTarget(EventTarget* aTarget);
virtual void DuplicatePrivateData(); virtual void DuplicatePrivateData();

Просмотреть файл

@ -52,7 +52,7 @@ public:
} }
Unused << nsContentUtils::DispatchTrustedEvent( Unused << nsContentUtils::DispatchTrustedEvent(
mDocument, mDocument, name, mDocument, mDocument, name,
CanBubble::eYes, Cancelable::eNo, nullptr); CanBubble::eYes, Cancelable::eNo, Composed::eYes);
} }
private: private: