2013-03-04 20:59:29 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2013-07-11 17:16:41 -07:00
|
|
|
#include <new>
|
2013-09-30 14:26:04 -07:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
2009-10-29 04:11:02 -07:00
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2012-07-20 09:42:08 -07:00
|
|
|
#include "GeneratedEvents.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2013-04-05 17:44:15 -07:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2014-02-28 06:58:42 -08:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-16 23:56:53 -07:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-02-27 02:51:15 -08:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-09-25 04:21:16 -07:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2014-02-09 00:04:38 -08:00
|
|
|
#include "mozilla/unused.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace dom;
|
2012-08-11 18:42:34 -07:00
|
|
|
|
2013-06-28 02:53:37 -07:00
|
|
|
class ELMCreationDetector
|
|
|
|
{
|
|
|
|
public:
|
2014-03-17 21:48:22 -07:00
|
|
|
ELMCreationDetector()
|
2013-06-28 02:53:37 -07:00
|
|
|
// We can do this optimization only in the main thread.
|
2014-03-17 21:48:22 -07:00
|
|
|
: mNonMainThread(!NS_IsMainThread())
|
|
|
|
, mInitialCount(mNonMainThread ?
|
|
|
|
0 : EventListenerManager::sMainThreadCreatedCount)
|
2013-06-28 02:53:37 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MayHaveNewListenerManager()
|
|
|
|
{
|
2013-08-27 02:01:37 -07:00
|
|
|
return mNonMainThread ||
|
2014-03-16 23:56:53 -07:00
|
|
|
mInitialCount != EventListenerManager::sMainThreadCreatedCount;
|
2013-06-28 02:53:37 -07:00
|
|
|
}
|
2013-08-27 02:01:37 -07:00
|
|
|
|
|
|
|
bool IsMainThread()
|
|
|
|
{
|
|
|
|
return !mNonMainThread;
|
|
|
|
}
|
2014-03-17 21:48:22 -07:00
|
|
|
|
2013-06-28 02:53:37 -07:00
|
|
|
private:
|
2013-08-27 02:01:37 -07:00
|
|
|
bool mNonMainThread;
|
2013-06-28 02:53:37 -07:00
|
|
|
uint32_t mInitialCount;
|
|
|
|
};
|
|
|
|
|
2008-10-08 04:35:29 -07:00
|
|
|
#define NS_TARGET_CHAIN_FORCE_CONTENT_DISPATCH (1 << 0)
|
|
|
|
#define NS_TARGET_CHAIN_WANTS_WILL_HANDLE_EVENT (1 << 1)
|
2009-12-18 10:50:49 -08:00
|
|
|
#define NS_TARGET_CHAIN_MAY_HAVE_MANAGER (1 << 2)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
// EventTargetChainItem represents a single item in the event target chain.
|
|
|
|
class EventTargetChainItem
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
private:
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem(EventTarget* aTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem()
|
|
|
|
: mFlags(0)
|
|
|
|
, mItemFlags(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
static EventTargetChainItem* Create(nsTArray<EventTargetChainItem>& aChain,
|
|
|
|
EventTarget* aTarget,
|
|
|
|
EventTargetChainItem* aChild = nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-08-16 03:00:00 -07:00
|
|
|
MOZ_ASSERT(!aChild || &aChain.ElementAt(aChain.Length() - 1) == aChild);
|
2014-03-17 21:48:22 -07:00
|
|
|
return new (aChain.AppendElement()) EventTargetChainItem(aTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
static void DestroyLast(nsTArray<EventTargetChainItem>& aChain,
|
|
|
|
EventTargetChainItem* aItem)
|
2013-03-04 20:59:29 -08:00
|
|
|
{
|
2013-08-16 03:00:00 -07:00
|
|
|
uint32_t lastIndex = aChain.Length() - 1;
|
|
|
|
MOZ_ASSERT(&aChain[lastIndex] == aItem);
|
|
|
|
aChain.RemoveElementAt(lastIndex);
|
2013-03-04 20:59:29 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsValid()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-08-14 04:04:43 -07:00
|
|
|
NS_WARN_IF_FALSE(!!(mTarget), "Event target is not valid!");
|
2007-03-22 10:30:00 -07:00
|
|
|
return !!(mTarget);
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:44:15 -07:00
|
|
|
EventTarget* GetNewTarget()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mNewTarget;
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:44:15 -07:00
|
|
|
void SetNewTarget(EventTarget* aNewTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mNewTarget = aNewTarget;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetForceContentDispatch(bool aForce)
|
2008-10-08 04:35:29 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aForce) {
|
|
|
|
mFlags |= NS_TARGET_CHAIN_FORCE_CONTENT_DISPATCH;
|
|
|
|
} else {
|
|
|
|
mFlags &= ~NS_TARGET_CHAIN_FORCE_CONTENT_DISPATCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ForceContentDispatch()
|
2008-10-08 04:35:29 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
return !!(mFlags & NS_TARGET_CHAIN_FORCE_CONTENT_DISPATCH);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetWantsWillHandleEvent(bool aWants)
|
2008-10-08 04:35:29 -07:00
|
|
|
{
|
|
|
|
if (aWants) {
|
|
|
|
mFlags |= NS_TARGET_CHAIN_WANTS_WILL_HANDLE_EVENT;
|
|
|
|
} else {
|
|
|
|
mFlags &= ~NS_TARGET_CHAIN_WANTS_WILL_HANDLE_EVENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool WantsWillHandleEvent()
|
2008-10-08 04:35:29 -07:00
|
|
|
{
|
|
|
|
return !!(mFlags & NS_TARGET_CHAIN_WANTS_WILL_HANDLE_EVENT);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetMayHaveListenerManager(bool aMayHave)
|
2009-12-18 10:50:49 -08:00
|
|
|
{
|
|
|
|
if (aMayHave) {
|
|
|
|
mFlags |= NS_TARGET_CHAIN_MAY_HAVE_MANAGER;
|
|
|
|
} else {
|
|
|
|
mFlags &= ~NS_TARGET_CHAIN_MAY_HAVE_MANAGER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool MayHaveListenerManager()
|
2009-12-18 10:50:49 -08:00
|
|
|
{
|
|
|
|
return !!(mFlags & NS_TARGET_CHAIN_MAY_HAVE_MANAGER);
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:44:15 -07:00
|
|
|
EventTarget* CurrentTarget()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatches event through the event target chain.
|
|
|
|
* Handles capture, target and bubble phases both in default
|
|
|
|
* and system event group and calls also PostHandleEvent for each
|
|
|
|
* item in the chain.
|
|
|
|
*/
|
2014-03-17 21:48:22 -07:00
|
|
|
static void HandleEventTargetChain(nsTArray<EventTargetChainItem>& aChain,
|
2014-03-17 21:48:20 -07:00
|
|
|
EventChainPostVisitor& aVisitor,
|
2014-03-17 21:48:20 -07:00
|
|
|
EventDispatchingCallback* aCallback,
|
2013-12-13 18:22:18 -08:00
|
|
|
ELMCreationDetector& aCd);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets aVisitor object and calls PreHandleEvent.
|
2014-03-17 21:48:22 -07:00
|
|
|
* Copies mItemFlags and mItemData to the current EventTargetChainItem.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-03-17 21:48:19 -07:00
|
|
|
void PreHandleEvent(EventChainPreVisitor& aVisitor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If the current item in the event target chain has an event listener
|
2014-03-16 23:56:53 -07:00
|
|
|
* manager, this method calls EventListenerManager::HandleEvent().
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2014-03-17 21:48:20 -07:00
|
|
|
void HandleEvent(EventChainPostVisitor& aVisitor,
|
2014-02-09 00:04:39 -08:00
|
|
|
ELMCreationDetector& aCd)
|
2009-12-18 10:50:49 -08:00
|
|
|
{
|
|
|
|
if (WantsWillHandleEvent()) {
|
|
|
|
mTarget->WillHandleEvent(aVisitor);
|
|
|
|
}
|
2012-12-15 17:26:03 -08:00
|
|
|
if (aVisitor.mEvent->mFlags.mPropagationStopped) {
|
2014-02-09 00:04:39 -08:00
|
|
|
return;
|
2009-12-18 10:50:49 -08:00
|
|
|
}
|
|
|
|
if (!mManager) {
|
2013-06-28 02:53:37 -07:00
|
|
|
if (!MayHaveListenerManager() && !aCd.MayHaveNewListenerManager()) {
|
2014-02-09 00:04:39 -08:00
|
|
|
return;
|
2009-12-18 10:50:49 -08:00
|
|
|
}
|
2013-10-22 16:32:04 -07:00
|
|
|
mManager = mTarget->GetExistingListenerManager();
|
2009-12-18 10:50:49 -08:00
|
|
|
}
|
|
|
|
if (mManager) {
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(aVisitor.mEvent->currentTarget == nullptr,
|
2009-12-18 10:50:49 -08:00
|
|
|
"CurrentTarget should be null!");
|
|
|
|
mManager->HandleEvent(aVisitor.mPresContext, aVisitor.mEvent,
|
|
|
|
&aVisitor.mDOMEvent,
|
2012-12-15 17:26:05 -08:00
|
|
|
CurrentTarget(),
|
2013-12-13 18:22:18 -08:00
|
|
|
&aVisitor.mEventStatus);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(aVisitor.mEvent->currentTarget == nullptr,
|
2009-12-18 10:50:49 -08:00
|
|
|
"CurrentTarget should be null!");
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies mItemFlags and mItemData to aVisitor and calls PostHandleEvent.
|
|
|
|
*/
|
2014-03-17 21:48:20 -07:00
|
|
|
void PostHandleEvent(EventChainPostVisitor& aVisitor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-05 17:44:15 -07:00
|
|
|
nsCOMPtr<EventTarget> mTarget;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mFlags;
|
|
|
|
uint16_t mItemFlags;
|
2007-09-05 02:02:23 -07:00
|
|
|
nsCOMPtr<nsISupports> mItemData;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Event retargeting must happen whenever mNewTarget is non-null.
|
2013-04-05 17:44:15 -07:00
|
|
|
nsCOMPtr<EventTarget> mNewTarget;
|
2007-09-05 02:02:23 -07:00
|
|
|
// Cache mTarget's event listener manager.
|
2014-03-16 23:56:53 -07:00
|
|
|
nsRefPtr<EventListenerManager> mManager;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::EventTargetChainItem(EventTarget* aTarget)
|
|
|
|
: mTarget(aTarget)
|
|
|
|
, mFlags(0)
|
|
|
|
, mItemFlags(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-27 16:15:29 -07:00
|
|
|
MOZ_ASSERT(!aTarget || mTarget == aTarget->GetTargetForEventTargetChain());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-09 00:04:38 -08:00
|
|
|
void
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aVisitor.Reset();
|
2014-02-09 00:04:38 -08:00
|
|
|
unused << mTarget->PreHandleEvent(aVisitor);
|
2007-03-22 10:30:00 -07:00
|
|
|
SetForceContentDispatch(aVisitor.mForceContentDispatch);
|
2008-10-08 04:35:29 -07:00
|
|
|
SetWantsWillHandleEvent(aVisitor.mWantsWillHandleEvent);
|
2009-12-18 10:50:49 -08:00
|
|
|
SetMayHaveListenerManager(aVisitor.mMayHaveListenerManager);
|
2007-03-22 10:30:00 -07:00
|
|
|
mItemFlags = aVisitor.mItemFlags;
|
|
|
|
mItemData = aVisitor.mItemData;
|
|
|
|
}
|
|
|
|
|
2014-02-09 00:04:39 -08:00
|
|
|
void
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aVisitor.mItemFlags = mItemFlags;
|
|
|
|
aVisitor.mItemData = mItemData;
|
|
|
|
mTarget->PostHandleEvent(aVisitor);
|
|
|
|
}
|
|
|
|
|
2013-08-16 03:00:00 -07:00
|
|
|
void
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::HandleEventTargetChain(
|
|
|
|
nsTArray<EventTargetChainItem>& aChain,
|
|
|
|
EventChainPostVisitor& aVisitor,
|
|
|
|
EventDispatchingCallback* aCallback,
|
|
|
|
ELMCreationDetector& aCd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Save the target so that it can be restored later.
|
2013-04-05 17:44:26 -07:00
|
|
|
nsCOMPtr<EventTarget> firstTarget = aVisitor.mEvent->target;
|
2013-08-16 03:00:00 -07:00
|
|
|
uint32_t chainLength = aChain.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Capture
|
2012-12-15 17:26:03 -08:00
|
|
|
aVisitor.mEvent->mFlags.mInCapturePhase = true;
|
|
|
|
aVisitor.mEvent->mFlags.mInBubblingPhase = false;
|
2013-08-16 03:00:00 -07:00
|
|
|
for (uint32_t i = chainLength - 1; i > 0; --i) {
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem& item = aChain[i];
|
2012-12-15 17:26:05 -08:00
|
|
|
if ((!aVisitor.mEvent->mFlags.mNoContentDispatch ||
|
2013-08-16 03:00:00 -07:00
|
|
|
item.ForceContentDispatch()) &&
|
2012-12-15 17:26:03 -08:00
|
|
|
!aVisitor.mEvent->mFlags.mPropagationStopped) {
|
2013-12-13 18:22:18 -08:00
|
|
|
item.HandleEvent(aVisitor, aCd);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-08-16 03:00:00 -07:00
|
|
|
if (item.GetNewTarget()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// item is at anonymous boundary. Need to retarget for the child items.
|
2013-08-16 03:00:00 -07:00
|
|
|
for (uint32_t j = i; j > 0; --j) {
|
|
|
|
uint32_t childIndex = j - 1;
|
|
|
|
EventTarget* newTarget = aChain[childIndex].GetNewTarget();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (newTarget) {
|
|
|
|
aVisitor.mEvent->target = newTarget;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Target
|
2012-12-15 17:26:03 -08:00
|
|
|
aVisitor.mEvent->mFlags.mInBubblingPhase = true;
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem& targetItem = aChain[0];
|
2012-12-15 17:26:03 -08:00
|
|
|
if (!aVisitor.mEvent->mFlags.mPropagationStopped &&
|
2012-12-15 17:26:05 -08:00
|
|
|
(!aVisitor.mEvent->mFlags.mNoContentDispatch ||
|
2013-08-16 03:00:00 -07:00
|
|
|
targetItem.ForceContentDispatch())) {
|
2013-12-13 18:22:18 -08:00
|
|
|
targetItem.HandleEvent(aVisitor, aCd);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-12-15 17:26:05 -08:00
|
|
|
if (aVisitor.mEvent->mFlags.mInSystemGroup) {
|
2013-12-13 18:22:18 -08:00
|
|
|
targetItem.PostHandleEvent(aVisitor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bubble
|
2012-12-15 17:26:03 -08:00
|
|
|
aVisitor.mEvent->mFlags.mInCapturePhase = false;
|
2013-08-16 03:00:00 -07:00
|
|
|
for (uint32_t i = 1; i < chainLength; ++i) {
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem& item = aChain[i];
|
2013-08-16 03:00:00 -07:00
|
|
|
EventTarget* newTarget = item.GetNewTarget();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (newTarget) {
|
|
|
|
// Item is at anonymous boundary. Need to retarget for the current item
|
|
|
|
// and for parent items.
|
|
|
|
aVisitor.mEvent->target = newTarget;
|
|
|
|
}
|
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
if (aVisitor.mEvent->mFlags.mBubbles || newTarget) {
|
2012-12-15 17:26:05 -08:00
|
|
|
if ((!aVisitor.mEvent->mFlags.mNoContentDispatch ||
|
2013-08-16 03:00:00 -07:00
|
|
|
item.ForceContentDispatch()) &&
|
2012-12-15 17:26:03 -08:00
|
|
|
!aVisitor.mEvent->mFlags.mPropagationStopped) {
|
2013-12-13 18:22:18 -08:00
|
|
|
item.HandleEvent(aVisitor, aCd);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-12-15 17:26:05 -08:00
|
|
|
if (aVisitor.mEvent->mFlags.mInSystemGroup) {
|
2013-12-13 18:22:18 -08:00
|
|
|
item.PostHandleEvent(aVisitor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-15 17:26:03 -08:00
|
|
|
aVisitor.mEvent->mFlags.mInBubblingPhase = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-15 17:26:05 -08:00
|
|
|
if (!aVisitor.mEvent->mFlags.mInSystemGroup) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Dispatch to the system event group. Make sure to clear the
|
2011-11-04 10:17:19 -07:00
|
|
|
// STOP_DISPATCH flag since this resets for each event group.
|
2012-12-15 17:26:03 -08:00
|
|
|
aVisitor.mEvent->mFlags.mPropagationStopped = false;
|
|
|
|
aVisitor.mEvent->mFlags.mImmediatePropagationStopped = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Setting back the original target of the event.
|
|
|
|
aVisitor.mEvent->target = aVisitor.mEvent->originalTarget;
|
|
|
|
|
|
|
|
// Special handling if PresShell (or some other caller)
|
|
|
|
// used a callback object.
|
|
|
|
if (aCallback) {
|
|
|
|
aCallback->HandleEvent(aVisitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retarget for system event group (which does the default handling too).
|
|
|
|
// Setting back the target which was used also for default event group.
|
|
|
|
aVisitor.mEvent->target = firstTarget;
|
2012-12-15 17:26:05 -08:00
|
|
|
aVisitor.mEvent->mFlags.mInSystemGroup = true;
|
2013-08-16 03:00:00 -07:00
|
|
|
HandleEventTargetChain(aChain,
|
|
|
|
aVisitor,
|
2008-10-08 04:35:29 -07:00
|
|
|
aCallback,
|
2013-12-13 18:22:18 -08:00
|
|
|
aCd);
|
2012-12-15 17:26:05 -08:00
|
|
|
aVisitor.mEvent->mFlags.mInSystemGroup = false;
|
2011-11-04 10:17:19 -07:00
|
|
|
|
|
|
|
// After dispatch, clear all the propagation flags so that
|
|
|
|
// system group listeners don't affect to the event.
|
2012-12-15 17:26:03 -08:00
|
|
|
aVisitor.mEvent->mFlags.mPropagationStopped = false;
|
|
|
|
aVisitor.mEvent->mFlags.mImmediatePropagationStopped = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-08-10 02:24:09 -07:00
|
|
|
}
|
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
static nsTArray<EventTargetChainItem>* sCachedMainThreadChain = nullptr;
|
2013-08-27 02:01:37 -07:00
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
/* static */ void
|
|
|
|
EventDispatcher::Shutdown()
|
2013-08-27 02:01:37 -07:00
|
|
|
{
|
|
|
|
delete sCachedMainThreadChain;
|
|
|
|
sCachedMainThreadChain = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem*
|
|
|
|
EventTargetChainItemForChromeTarget(nsTArray<EventTargetChainItem>& aChain,
|
2013-08-16 03:00:00 -07:00
|
|
|
nsINode* aNode,
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem* aChild = nullptr)
|
2013-01-03 07:17:36 -08:00
|
|
|
{
|
|
|
|
if (!aNode->IsInDoc()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsPIDOMWindow* win = aNode->OwnerDoc()->GetInnerWindow();
|
2013-04-05 17:44:15 -07:00
|
|
|
EventTarget* piTarget = win ? win->GetParentTarget() : nullptr;
|
2013-01-03 07:17:36 -08:00
|
|
|
NS_ENSURE_TRUE(piTarget, nullptr);
|
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem* etci =
|
|
|
|
EventTargetChainItem::Create(aChain,
|
|
|
|
piTarget->GetTargetForEventTargetChain(),
|
|
|
|
aChild);
|
2013-01-03 07:17:36 -08:00
|
|
|
if (!etci->IsValid()) {
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::DestroyLast(aChain, etci);
|
2013-01-03 07:17:36 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return etci;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* static */ nsresult
|
2014-03-17 21:48:21 -07:00
|
|
|
EventDispatcher::Dispatch(nsISupports* aTarget,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
nsIDOMEvent* aDOMEvent,
|
|
|
|
nsEventStatus* aEventStatus,
|
|
|
|
EventDispatchingCallback* aCallback,
|
|
|
|
nsCOMArray<EventTarget>* aTargets)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-03-17 21:48:21 -07:00
|
|
|
PROFILER_LABEL("EventDispatcher", "Dispatch");
|
2013-10-01 20:46:04 -07:00
|
|
|
NS_ASSERTION(aEvent, "Trying to dispatch without WidgetEvent!");
|
2012-12-15 17:26:04 -08:00
|
|
|
NS_ENSURE_TRUE(!aEvent->mFlags.mIsBeingDispatched,
|
2013-04-02 07:10:45 -07:00
|
|
|
NS_ERROR_DOM_INVALID_STATE_ERR);
|
2009-10-16 01:57:32 -07:00
|
|
|
NS_ASSERTION(!aTargets || !aEvent->message, "Wrong parameters!");
|
2010-04-30 12:40:59 -07:00
|
|
|
|
2011-03-24 04:34:03 -07:00
|
|
|
// If we're dispatching an already created DOMEvent object, make
|
|
|
|
// sure it is initialized!
|
|
|
|
// If aTargets is non-null, the event isn't going to be dispatched.
|
|
|
|
NS_ENSURE_TRUE(aEvent->message || !aDOMEvent || aTargets,
|
2011-10-09 11:23:13 -07:00
|
|
|
NS_ERROR_DOM_INVALID_STATE_ERR);
|
2011-03-24 04:34:03 -07:00
|
|
|
|
2013-04-05 17:44:15 -07:00
|
|
|
nsCOMPtr<EventTarget> target = do_QueryInterface(aTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool retargeted = false;
|
2011-06-19 02:23:12 -07:00
|
|
|
|
2012-12-15 17:26:05 -08:00
|
|
|
if (aEvent->mFlags.mRetargetToNonNativeAnonymous) {
|
2011-06-19 02:23:12 -07:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(target);
|
|
|
|
if (content && content->IsInNativeAnonymousSubtree()) {
|
2013-04-05 17:44:15 -07:00
|
|
|
nsCOMPtr<EventTarget> newTarget =
|
2012-10-10 12:04:42 -07:00
|
|
|
do_QueryInterface(content->FindFirstNonChromeOnlyAccessContent());
|
2011-06-19 02:23:12 -07:00
|
|
|
NS_ENSURE_STATE(newTarget);
|
|
|
|
|
|
|
|
aEvent->originalTarget = target;
|
|
|
|
target = newTarget;
|
2011-10-17 07:59:28 -07:00
|
|
|
retargeted = true;
|
2011-06-19 02:23:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-15 17:26:05 -08:00
|
|
|
if (aEvent->mFlags.mOnlyChromeDispatch) {
|
2009-10-29 04:11:02 -07:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aTarget);
|
|
|
|
if (!node) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aTarget);
|
|
|
|
if (win) {
|
2013-04-23 21:22:37 -07:00
|
|
|
node = win->GetExtantDoc();
|
2009-10-29 04:11:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(node);
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* doc = node->OwnerDoc();
|
2009-10-29 04:11:02 -07:00
|
|
|
if (!nsContentUtils::IsChromeDoc(doc)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
nsPIDOMWindow* win = doc ? doc->GetInnerWindow() : nullptr;
|
2009-10-29 04:11:02 -07:00
|
|
|
// If we can't dispatch the event to chrome, do nothing.
|
2013-04-05 17:44:15 -07:00
|
|
|
EventTarget* piTarget = win ? win->GetParentTarget() : nullptr;
|
2011-03-25 06:39:58 -07:00
|
|
|
NS_ENSURE_TRUE(piTarget, NS_OK);
|
2013-04-05 17:44:15 -07:00
|
|
|
|
2009-10-29 04:11:02 -07:00
|
|
|
// Set the target to be the original dispatch target,
|
2010-03-31 05:44:18 -07:00
|
|
|
aEvent->target = target;
|
2011-03-25 06:39:58 -07:00
|
|
|
// but use chrome event handler or TabChildGlobal for event target chain.
|
|
|
|
target = piTarget;
|
2009-10-29 04:11:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2009-12-18 11:27:57 -08:00
|
|
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (target->GetContextForEventHandlers(&rv) ||
|
|
|
|
NS_FAILED(rv)) {
|
2010-03-19 03:52:48 -07:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(target);
|
2011-10-18 03:53:36 -07:00
|
|
|
if (node && nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
|
2010-03-19 03:52:48 -07:00
|
|
|
NS_WARNING("Fix the caller!");
|
|
|
|
} else {
|
|
|
|
NS_ERROR("This is unsafe! Fix the caller!");
|
|
|
|
}
|
2009-12-18 11:27:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aDOMEvent) {
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* innerEvent = aDOMEvent->GetInternalNSEvent();
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_ASSERTION(innerEvent == aEvent,
|
|
|
|
"The inner event of aDOMEvent is not the same as aEvent!");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool externalDOMEvent = !!(aDOMEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If we have a PresContext, make sure it doesn't die before
|
|
|
|
// event dispatching is finished.
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> kungFuDeathGrip(aPresContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-27 02:01:37 -07:00
|
|
|
ELMCreationDetector cd;
|
2014-03-17 21:48:22 -07:00
|
|
|
nsTArray<EventTargetChainItem> chain;
|
2013-08-27 02:01:37 -07:00
|
|
|
if (cd.IsMainThread()) {
|
|
|
|
if (!sCachedMainThreadChain) {
|
2014-03-17 21:48:22 -07:00
|
|
|
sCachedMainThreadChain = new nsTArray<EventTargetChainItem>();
|
2013-08-27 02:01:37 -07:00
|
|
|
}
|
|
|
|
chain.SwapElements(*sCachedMainThreadChain);
|
|
|
|
chain.SetCapacity(128);
|
|
|
|
}
|
2013-08-16 03:00:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Create the event target chain item for the event target.
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem* targetEtci =
|
|
|
|
EventTargetChainItem::Create(chain, target->GetTargetForEventTargetChain());
|
2013-08-19 14:12:56 -07:00
|
|
|
MOZ_ASSERT(&chain[0] == targetEtci);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!targetEtci->IsValid()) {
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::DestroyLast(chain, targetEtci);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-04 00:44:00 -07:00
|
|
|
// Make sure that nsIDOMEvent::target and nsIDOMEvent::originalTarget
|
2007-03-22 10:30:00 -07:00
|
|
|
// point to the last item in the chain.
|
|
|
|
if (!aEvent->target) {
|
2007-04-17 02:18:36 -07:00
|
|
|
// Note, CurrentTarget() points always to the object returned by
|
|
|
|
// GetTargetForEventTargetChain().
|
|
|
|
aEvent->target = targetEtci->CurrentTarget();
|
|
|
|
} else {
|
|
|
|
// XXX But if the target is already set, use that. This is a hack
|
|
|
|
// for the 'load', 'beforeunload' and 'unload' events,
|
|
|
|
// which are dispatched to |window| but have document as their target.
|
|
|
|
//
|
|
|
|
// Make sure that the event target points to the right object.
|
2010-03-31 05:44:18 -07:00
|
|
|
aEvent->target = aEvent->target->GetTargetForEventTargetChain();
|
2007-04-17 02:18:36 -07:00
|
|
|
NS_ENSURE_STATE(aEvent->target);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-06-19 02:23:12 -07:00
|
|
|
|
|
|
|
if (retargeted) {
|
|
|
|
aEvent->originalTarget =
|
|
|
|
aEvent->originalTarget->GetTargetForEventTargetChain();
|
|
|
|
NS_ENSURE_STATE(aEvent->originalTarget);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aEvent->originalTarget = aEvent->target;
|
|
|
|
}
|
|
|
|
|
2008-12-03 01:26:38 -08:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aEvent->originalTarget);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isInAnon = (content && content->IsInAnonymousSubtree());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-15 17:26:04 -08:00
|
|
|
aEvent->mFlags.mIsBeingDispatched = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Create visitor object and start event dispatching.
|
|
|
|
// PreHandleEvent for the original target.
|
|
|
|
nsEventStatus status = aEventStatus ? *aEventStatus : nsEventStatus_eIgnore;
|
2014-03-17 21:48:19 -07:00
|
|
|
EventChainPreVisitor preVisitor(aPresContext, aEvent, aDOMEvent, status,
|
|
|
|
isInAnon);
|
2007-03-22 10:30:00 -07:00
|
|
|
targetEtci->PreHandleEvent(preVisitor);
|
|
|
|
|
2013-01-03 07:17:36 -08:00
|
|
|
if (!preVisitor.mCanHandle && preVisitor.mAutomaticChromeDispatch && content) {
|
|
|
|
// Event target couldn't handle the event. Try to propagate to chrome.
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::DestroyLast(chain, targetEtci);
|
2013-08-16 03:00:00 -07:00
|
|
|
targetEtci = EventTargetChainItemForChromeTarget(chain, content);
|
2013-01-03 07:17:36 -08:00
|
|
|
NS_ENSURE_STATE(targetEtci);
|
2013-08-19 14:12:56 -07:00
|
|
|
MOZ_ASSERT(&chain[0] == targetEtci);
|
2013-01-03 07:17:36 -08:00
|
|
|
targetEtci->PreHandleEvent(preVisitor);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (preVisitor.mCanHandle) {
|
|
|
|
// At least the original target can handle the event.
|
|
|
|
// Setting the retarget to the |target| simplifies retargeting code.
|
2013-04-05 17:44:15 -07:00
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aEvent->target);
|
2008-10-08 04:35:29 -07:00
|
|
|
targetEtci->SetNewTarget(t);
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem* topEtci = targetEtci;
|
2013-08-19 14:12:56 -07:00
|
|
|
targetEtci = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (preVisitor.mParentTarget) {
|
2013-04-05 17:44:15 -07:00
|
|
|
EventTarget* parentTarget = preVisitor.mParentTarget;
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem* parentEtci =
|
|
|
|
EventTargetChainItem::Create(chain, preVisitor.mParentTarget, topEtci);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!parentEtci->IsValid()) {
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::DestroyLast(chain, parentEtci);
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Item needs event retargetting.
|
|
|
|
if (preVisitor.mEventTargetAtParent) {
|
|
|
|
// Need to set the target of the event
|
|
|
|
// so that also the next retargeting works.
|
|
|
|
preVisitor.mEvent->target = preVisitor.mEventTargetAtParent;
|
|
|
|
parentEtci->SetNewTarget(preVisitor.mEventTargetAtParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
parentEtci->PreHandleEvent(preVisitor);
|
|
|
|
if (preVisitor.mCanHandle) {
|
|
|
|
topEtci = parentEtci;
|
|
|
|
} else {
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::DestroyLast(chain, parentEtci);
|
2012-07-30 07:20:58 -07:00
|
|
|
parentEtci = nullptr;
|
2013-01-03 07:17:36 -08:00
|
|
|
if (preVisitor.mAutomaticChromeDispatch && content) {
|
|
|
|
// Even if the current target can't handle the event, try to
|
|
|
|
// propagate to chrome.
|
|
|
|
nsCOMPtr<nsINode> disabledTarget = do_QueryInterface(parentTarget);
|
|
|
|
if (disabledTarget) {
|
2013-08-16 03:00:00 -07:00
|
|
|
parentEtci = EventTargetChainItemForChromeTarget(chain,
|
|
|
|
disabledTarget,
|
2013-01-03 07:17:36 -08:00
|
|
|
topEtci);
|
|
|
|
if (parentEtci) {
|
|
|
|
parentEtci->PreHandleEvent(preVisitor);
|
|
|
|
if (preVisitor.mCanHandle) {
|
2013-08-19 14:12:56 -07:00
|
|
|
chain[0].SetNewTarget(parentTarget);
|
2013-01-03 07:17:36 -08:00
|
|
|
topEtci = parentEtci;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2009-10-16 01:57:32 -07:00
|
|
|
if (aTargets) {
|
|
|
|
aTargets->Clear();
|
2013-08-16 03:00:00 -07:00
|
|
|
aTargets->SetCapacity(chain.Length());
|
|
|
|
for (uint32_t i = 0; i < chain.Length(); ++i) {
|
|
|
|
aTargets->AppendObject(chain[i].CurrentTarget()->GetTargetForDOMEvent());
|
2009-10-16 01:57:32 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Event target chain is created. Handle the chain.
|
2014-03-17 21:48:20 -07:00
|
|
|
EventChainPostVisitor postVisitor(preVisitor);
|
2014-03-17 21:48:22 -07:00
|
|
|
EventTargetChainItem::HandleEventTargetChain(chain, postVisitor,
|
|
|
|
aCallback, cd);
|
2013-03-04 20:59:29 -08:00
|
|
|
|
2009-10-16 01:57:32 -07:00
|
|
|
preVisitor.mEventStatus = postVisitor.mEventStatus;
|
|
|
|
// If the DOM event was created during event flow.
|
|
|
|
if (!preVisitor.mDOMEvent && postVisitor.mDOMEvent) {
|
|
|
|
preVisitor.mDOMEvent = postVisitor.mDOMEvent;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
// Note, EventTargetChainItem objects are deleted when the chain goes out of
|
2013-08-16 03:00:00 -07:00
|
|
|
// the scope.
|
|
|
|
|
2012-12-15 17:26:04 -08:00
|
|
|
aEvent->mFlags.mIsBeingDispatched = false;
|
|
|
|
aEvent->mFlags.mDispatchedAtLeastOnce = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!externalDOMEvent && preVisitor.mDOMEvent) {
|
2014-03-04 16:37:43 -08:00
|
|
|
// An dom::Event was created while dispatching the event.
|
2007-03-22 10:30:00 -07:00
|
|
|
// Duplicate private data if someone holds a pointer to it.
|
|
|
|
nsrefcnt rc = 0;
|
|
|
|
NS_RELEASE2(preVisitor.mDOMEvent, rc);
|
2012-06-10 16:44:50 -07:00
|
|
|
if (preVisitor.mDOMEvent) {
|
|
|
|
preVisitor.mDOMEvent->DuplicatePrivateData();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEventStatus) {
|
|
|
|
*aEventStatus = preVisitor.mEventStatus;
|
|
|
|
}
|
2013-08-27 02:01:37 -07:00
|
|
|
|
|
|
|
if (cd.IsMainThread() && chain.Capacity() == 128 && sCachedMainThreadChain) {
|
|
|
|
chain.ClearAndRetainStorage();
|
|
|
|
chain.SwapElements(*sCachedMainThreadChain);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-03-17 21:48:21 -07:00
|
|
|
EventDispatcher::DispatchDOMEvent(nsISupports* aTarget,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
nsIDOMEvent* aDOMEvent,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsEventStatus* aEventStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aDOMEvent) {
|
2013-10-01 20:46:04 -07:00
|
|
|
WidgetEvent* innerEvent = aDOMEvent->GetInternalNSEvent();
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_ENSURE_TRUE(innerEvent, NS_ERROR_ILLEGAL_VALUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
bool dontResetTrusted = false;
|
2012-12-15 17:26:04 -08:00
|
|
|
if (innerEvent->mFlags.mDispatchedAtLeastOnce) {
|
2012-07-30 07:20:58 -07:00
|
|
|
innerEvent->target = nullptr;
|
|
|
|
innerEvent->originalTarget = nullptr;
|
2012-08-04 00:44:00 -07:00
|
|
|
} else {
|
|
|
|
aDOMEvent->GetIsTrusted(&dontResetTrusted);
|
2012-06-10 16:44:50 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
if (!dontResetTrusted) {
|
|
|
|
//Check security state to determine if dispatcher is trusted
|
2013-08-30 02:47:19 -07:00
|
|
|
aDOMEvent->SetTrusted(nsContentUtils::ThreadsafeIsCallerChrome());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2014-03-17 21:48:21 -07:00
|
|
|
return EventDispatcher::Dispatch(aTarget, aPresContext, innerEvent,
|
|
|
|
aDOMEvent, aEventStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aEvent) {
|
2014-03-17 21:48:21 -07:00
|
|
|
return EventDispatcher::Dispatch(aTarget, aPresContext, aEvent,
|
|
|
|
aDOMEvent, aEventStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2014-03-17 21:48:21 -07:00
|
|
|
EventDispatcher::CreateEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetEvent* aEvent,
|
|
|
|
const nsAString& aEventType,
|
|
|
|
nsIDOMEvent** aDOMEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aDOMEvent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aEvent) {
|
|
|
|
switch(aEvent->eventStructType) {
|
|
|
|
case NS_MUTATION_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMMutationEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:22 -07:00
|
|
|
aEvent->AsMutationEvent());
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_GUI_EVENT:
|
|
|
|
case NS_SCROLLPORT_EVENT:
|
2011-05-19 06:40:52 -07:00
|
|
|
case NS_UI_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-22 01:55:20 -07:00
|
|
|
aEvent->AsGUIEvent());
|
2009-09-11 16:13:56 -07:00
|
|
|
case NS_SCROLLAREA_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMScrollAreaEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:21 -07:00
|
|
|
aEvent->AsScrollAreaEvent());
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_KEY_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMKeyboardEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:24 -07:00
|
|
|
aEvent->AsKeyboardEvent());
|
2011-09-22 02:17:40 -07:00
|
|
|
case NS_COMPOSITION_EVENT:
|
2013-10-17 23:10:25 -07:00
|
|
|
return NS_NewDOMCompositionEvent(aDOMEvent, aOwner, aPresContext,
|
|
|
|
aEvent->AsCompositionEvent());
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_MOUSE_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMMouseEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:26 -07:00
|
|
|
aEvent->AsMouseEvent());
|
2013-06-05 05:02:51 -07:00
|
|
|
case NS_FOCUS_EVENT:
|
|
|
|
return NS_NewDOMFocusEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:22 -07:00
|
|
|
aEvent->AsFocusEvent());
|
2008-08-12 20:08:59 -07:00
|
|
|
case NS_MOUSE_SCROLL_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMMouseScrollEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:25 -07:00
|
|
|
aEvent->AsMouseScrollEvent());
|
2012-08-11 18:42:34 -07:00
|
|
|
case NS_WHEEL_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMWheelEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-22 01:55:21 -07:00
|
|
|
aEvent->AsWheelEvent());
|
2008-08-27 05:07:27 -07:00
|
|
|
case NS_DRAG_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMDragEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:26 -07:00
|
|
|
aEvent->AsDragEvent());
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_TEXT_EVENT:
|
2014-03-04 05:48:27 -08:00
|
|
|
return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext,
|
|
|
|
aEvent->AsTextEvent());
|
2013-03-11 08:49:48 -07:00
|
|
|
case NS_CLIPBOARD_EVENT:
|
2013-03-11 08:49:56 -07:00
|
|
|
return NS_NewDOMClipboardEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:22 -07:00
|
|
|
aEvent->AsClipboardEvent());
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_SVGZOOM_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMSVGZoomEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-22 01:55:20 -07:00
|
|
|
aEvent->AsGUIEvent());
|
2010-07-31 00:02:52 -07:00
|
|
|
case NS_SMIL_TIME_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMTimeEvent(aDOMEvent, aOwner, aPresContext, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
case NS_COMMAND_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMCommandEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:23 -07:00
|
|
|
aEvent->AsCommandEvent());
|
2008-10-23 13:15:20 -07:00
|
|
|
case NS_SIMPLE_GESTURE_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMSimpleGestureEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:23 -07:00
|
|
|
aEvent->AsSimpleGestureEvent());
|
2013-11-20 21:44:22 -08:00
|
|
|
case NS_POINTER_EVENT:
|
|
|
|
return NS_NewDOMPointerEvent(aDOMEvent, aOwner, aPresContext,
|
|
|
|
aEvent->AsPointerEvent());
|
2011-12-16 16:24:11 -08:00
|
|
|
case NS_TOUCH_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMTouchEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:23 -07:00
|
|
|
aEvent->AsTouchEvent());
|
2009-12-23 11:10:31 -08:00
|
|
|
case NS_TRANSITION_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMTransitionEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:22 -07:00
|
|
|
aEvent->AsTransitionEvent());
|
2011-04-11 23:18:44 -07:00
|
|
|
case NS_ANIMATION_EVENT:
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMAnimationEvent(aDOMEvent, aOwner, aPresContext,
|
2013-10-17 23:10:22 -07:00
|
|
|
aEvent->AsAnimationEvent());
|
2012-11-19 22:05:56 -08:00
|
|
|
default:
|
|
|
|
// For all other types of events, create a vanilla event object.
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMEvent(aDOMEvent, aOwner, aPresContext, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// And if we didn't get an event, check the type argument.
|
|
|
|
|
|
|
|
if (aEventType.LowerCaseEqualsLiteral("mouseevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("mouseevents") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("popupevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMMouseEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2008-08-12 20:08:59 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("mousescrollevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMMouseScrollEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2008-08-27 05:07:27 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("dragevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("dragevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMDragEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("keyboardevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("keyevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMKeyboardEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2011-09-22 02:17:40 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("compositionevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMCompositionEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("mutationevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("mutationevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMMutationEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("textevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("textevents"))
|
2014-03-04 05:48:27 -08:00
|
|
|
return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("popupblockedevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMPopupBlockedEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2011-04-29 16:49:20 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("deviceorientationevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMDeviceOrientationEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2011-06-19 22:36:17 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("devicemotionevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMDeviceMotionEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("uievent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("uievents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("event") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("events") ||
|
2013-03-11 11:57:08 -07:00
|
|
|
aEventType.LowerCaseEqualsLiteral("htmlevents") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("svgevent") ||
|
2007-03-22 10:30:00 -07:00
|
|
|
aEventType.LowerCaseEqualsLiteral("svgevents"))
|
2013-03-11 11:57:08 -07:00
|
|
|
return NS_NewDOMEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("svgzoomevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("svgzoomevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMSVGZoomEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2010-07-31 00:02:52 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("timeevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("timeevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMTimeEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("xulcommandevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("xulcommandevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMXULCommandEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("commandevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("commandevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMCommandEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2012-11-01 11:18:08 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("elementreplace"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMElementReplaceEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2007-12-11 00:18:04 -08:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("datacontainerevent") ||
|
|
|
|
aEventType.LowerCaseEqualsLiteral("datacontainerevents"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMDataContainerEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2008-01-29 17:31:29 -08:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("messageevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMMessageEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2008-09-18 02:47:21 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("notifypaintevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMNotifyPaintEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2008-10-23 13:15:20 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("simplegestureevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMSimpleGestureEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2009-06-24 01:42:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("beforeunloadevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMBeforeUnloadEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2009-06-24 06:33:02 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("pagetransition"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMPageTransitionEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2013-01-03 22:54:26 -08:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("domtransaction"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMDOMTransactionEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2009-09-11 16:13:56 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("scrollareaevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMScrollAreaEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2009-09-01 09:45:05 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("popstateevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMPopStateEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2010-08-25 06:10:00 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("mozaudioavailableevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMAudioAvailableEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2010-06-17 11:36:01 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("closeevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMCloseEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2011-04-26 05:30:17 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("touchevent") &&
|
2014-02-28 06:58:42 -08:00
|
|
|
TouchEvent::PrefEnabled())
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMTouchEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2011-03-31 13:30:32 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("hashchangeevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMHashChangeEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2011-05-10 23:33:11 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("customevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMCustomEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2011-11-21 08:57:26 -08:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("mozsmsevent"))
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMMozSmsEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2013-03-08 23:22:42 -08:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("mozmmsevent"))
|
|
|
|
return NS_NewDOMMozMmsEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2012-03-18 11:55:46 -07:00
|
|
|
if (aEventType.LowerCaseEqualsLiteral("storageevent")) {
|
2013-03-09 03:34:29 -08:00
|
|
|
return NS_NewDOMStorageEvent(aDOMEvent, aOwner, aPresContext, nullptr);
|
2012-03-18 11:55:46 -07:00
|
|
|
}
|
2013-05-08 13:45:35 -07:00
|
|
|
// NEW EVENT TYPES SHOULD NOT BE ADDED HERE; THEY SHOULD USE ONLY EVENT
|
|
|
|
// CONSTRUCTORS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
|
|
|
}
|
2014-03-17 21:48:21 -07:00
|
|
|
|
|
|
|
} // namespace mozilla
|