Bug 1373857 - Part 2: Add some AsyncEventDispatcher helpers for dispatching WidgetEvents directly; r=smaug

This commit is contained in:
Ehsan Akhgari 2017-06-16 23:38:30 -04:00
Родитель 9d4ea70f49
Коммит 580222cb8e
2 изменённых файлов: 46 добавлений и 2 удалений

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

@ -22,12 +22,14 @@ using namespace dom;
AsyncEventDispatcher::AsyncEventDispatcher(EventTarget* aTarget,
WidgetEvent& aEvent)
: mTarget(aTarget)
: mTarget(aTarget),
mEventMessage(eUnidentifiedEvent)
{
MOZ_ASSERT(mTarget);
RefPtr<Event> event =
EventDispatcher::CreateEvent(aTarget, nullptr, &aEvent, EmptyString());
mEvent = event.forget();
mEventType.SetIsVoid(true);
NS_ASSERTION(mEvent, "Should never fail to create an event");
mEvent->DuplicatePrivateData();
mEvent->SetTrusted(aEvent.IsTrusted());
@ -39,14 +41,20 @@ AsyncEventDispatcher::Run()
if (mCanceled) {
return NS_OK;
}
nsCOMPtr<nsINode> node = do_QueryInterface(mTarget);
if (mCheckStillInDoc) {
nsCOMPtr<nsINode> node = do_QueryInterface(mTarget);
MOZ_ASSERT(node);
if (!node->IsInComposedDoc()) {
return NS_OK;
}
}
mTarget->AsyncEventRunning(this);
if (mEventMessage != eUnidentifiedEvent) {
return nsContentUtils::DispatchTrustedEvent<WidgetEvent>
(node->OwnerDoc(), mTarget, mEventMessage, mBubbles,
false /* aCancelable */, nullptr /* aDefaultAction */,
mOnlyChromeDispatch);
}
RefPtr<Event> event = mEvent ? mEvent->InternalDOMEvent() : nullptr;
if (!event) {
event = NS_NewDOMEvent(mTarget, nullptr, nullptr);

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

@ -38,22 +38,54 @@ public:
bool aBubbles, bool aOnlyChromeDispatch)
: mTarget(aTarget)
, mEventType(aEventType)
, mEventMessage(eUnidentifiedEvent)
, mBubbles(aBubbles)
, mOnlyChromeDispatch(aOnlyChromeDispatch)
{
}
/**
* If aOnlyChromeDispatch is true, the event is dispatched to only
* chrome node. In that case, if aTarget is already a chrome node,
* the event is dispatched to it, otherwise the dispatch path starts
* at the first chrome ancestor of that target.
*/
AsyncEventDispatcher(nsINode* aTarget,
mozilla::EventMessage aEventMessage,
bool aBubbles, bool aOnlyChromeDispatch)
: mTarget(aTarget)
, mEventMessage(aEventMessage)
, mBubbles(aBubbles)
, mOnlyChromeDispatch(aOnlyChromeDispatch)
{
mEventType.SetIsVoid(true);
MOZ_ASSERT(mEventMessage != eUnidentifiedEvent);
}
AsyncEventDispatcher(dom::EventTarget* aTarget, const nsAString& aEventType,
bool aBubbles)
: mTarget(aTarget)
, mEventType(aEventType)
, mEventMessage(eUnidentifiedEvent)
, mBubbles(aBubbles)
{
}
AsyncEventDispatcher(dom::EventTarget* aTarget,
mozilla::EventMessage aEventMessage,
bool aBubbles)
: mTarget(aTarget)
, mEventMessage(aEventMessage)
, mBubbles(aBubbles)
{
mEventType.SetIsVoid(true);
MOZ_ASSERT(mEventMessage != eUnidentifiedEvent);
}
AsyncEventDispatcher(dom::EventTarget* aTarget, nsIDOMEvent* aEvent)
: mTarget(aTarget)
, mEvent(aEvent)
, mEventMessage(eUnidentifiedEvent)
{
}
@ -71,7 +103,11 @@ public:
nsCOMPtr<dom::EventTarget> mTarget;
nsCOMPtr<nsIDOMEvent> mEvent;
// If mEventType is set, mEventMessage will be eUnidentifiedEvent.
// 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;
bool mCanceled = false;