2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
#ifndef mozilla_EventListenerManager_h_
|
|
|
|
#define mozilla_EventListenerManager_h_
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-09-25 04:21:22 -07:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2013-07-24 00:31:06 -07:00
|
|
|
#include "mozilla/dom/EventListenerBinding.h"
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-07-24 00:31:06 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
2011-08-24 12:49:25 -07:00
|
|
|
#include "nsIJSEventListener.h"
|
2013-07-24 00:31:06 -07:00
|
|
|
#include "nsTObserverArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
class nsIDOMEvent;
|
2011-06-23 19:18:01 -07:00
|
|
|
class nsIEventListenerInfo;
|
2013-08-29 14:18:25 -07:00
|
|
|
class nsIScriptContext;
|
2014-03-16 23:56:53 -07:00
|
|
|
class nsPIDOMWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
struct EventTypeData;
|
2012-12-15 17:26:05 -08:00
|
|
|
|
2013-08-29 14:18:25 -07:00
|
|
|
template<class T> class nsCOMArray;
|
|
|
|
|
2012-12-15 17:26:05 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
class ELMCreationDetector;
|
2014-03-16 23:56:53 -07:00
|
|
|
class EventListenerManager;
|
|
|
|
|
2014-03-16 23:56:52 -07:00
|
|
|
namespace dom {
|
2013-08-19 03:15:55 -07:00
|
|
|
class EventTarget;
|
2013-11-26 08:44:37 -08:00
|
|
|
class Element;
|
2014-03-16 23:56:52 -07:00
|
|
|
} // namespace dom
|
2013-08-19 03:15:55 -07:00
|
|
|
|
2014-03-16 23:56:52 -07:00
|
|
|
typedef dom::CallbackObjectHolder<dom::EventListener,
|
|
|
|
nsIDOMEventListener> EventListenerHolder;
|
2013-04-16 14:15:57 -07:00
|
|
|
|
2012-12-15 17:26:05 -08:00
|
|
|
struct EventListenerFlags
|
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
friend class EventListenerManager;
|
2012-12-15 17:26:05 -08:00
|
|
|
private:
|
|
|
|
// If mListenerIsJSListener is true, the listener is implemented by JS.
|
|
|
|
// Otherwise, it's implemented by native code or JS but it's wrapped.
|
|
|
|
bool mListenerIsJSListener : 1;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// If mCapture is true, it means the listener captures the event. Otherwise,
|
|
|
|
// it's listening at bubbling phase.
|
|
|
|
bool mCapture : 1;
|
|
|
|
// If mInSystemGroup is true, the listener is listening to the events in the
|
|
|
|
// system group.
|
|
|
|
bool mInSystemGroup : 1;
|
|
|
|
// If mAllowUntrustedEvents is true, the listener is listening to the
|
|
|
|
// untrusted events too.
|
|
|
|
bool mAllowUntrustedEvents : 1;
|
|
|
|
|
|
|
|
EventListenerFlags() :
|
|
|
|
mListenerIsJSListener(false),
|
|
|
|
mCapture(false), mInSystemGroup(false), mAllowUntrustedEvents(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Equals(const EventListenerFlags& aOther) const
|
|
|
|
{
|
|
|
|
return (mCapture == aOther.mCapture &&
|
|
|
|
mInSystemGroup == aOther.mInSystemGroup &&
|
|
|
|
mListenerIsJSListener == aOther.mListenerIsJSListener &&
|
|
|
|
mAllowUntrustedEvents == aOther.mAllowUntrustedEvents);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EqualsIgnoringTrustness(const EventListenerFlags& aOther) const
|
|
|
|
{
|
|
|
|
return (mCapture == aOther.mCapture &&
|
|
|
|
mInSystemGroup == aOther.mInSystemGroup &&
|
|
|
|
mListenerIsJSListener == aOther.mListenerIsJSListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const EventListenerFlags& aOther) const
|
|
|
|
{
|
|
|
|
return Equals(aOther);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline EventListenerFlags TrustedEventsAtBubble()
|
|
|
|
{
|
|
|
|
EventListenerFlags flags;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EventListenerFlags TrustedEventsAtCapture()
|
|
|
|
{
|
|
|
|
EventListenerFlags flags;
|
|
|
|
flags.mCapture = true;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EventListenerFlags AllEventsAtBubbe()
|
|
|
|
{
|
|
|
|
EventListenerFlags flags;
|
|
|
|
flags.mAllowUntrustedEvents = true;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EventListenerFlags AllEventsAtCapture()
|
|
|
|
{
|
|
|
|
EventListenerFlags flags;
|
|
|
|
flags.mCapture = true;
|
|
|
|
flags.mAllowUntrustedEvents = true;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EventListenerFlags TrustedEventsAtSystemGroupBubble()
|
|
|
|
{
|
|
|
|
EventListenerFlags flags;
|
|
|
|
flags.mInSystemGroup = true;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EventListenerFlags TrustedEventsAtSystemGroupCapture()
|
|
|
|
{
|
|
|
|
EventListenerFlags flags;
|
|
|
|
flags.mCapture = true;
|
|
|
|
flags.mInSystemGroup = true;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EventListenerFlags AllEventsAtSystemGroupBubble()
|
|
|
|
{
|
|
|
|
EventListenerFlags flags;
|
|
|
|
flags.mInSystemGroup = true;
|
|
|
|
flags.mAllowUntrustedEvents = true;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EventListenerFlags AllEventsAtSystemGroupCapture()
|
|
|
|
{
|
|
|
|
EventListenerFlags flags;
|
|
|
|
flags.mCapture = true;
|
|
|
|
flags.mInSystemGroup = true;
|
|
|
|
flags.mAllowUntrustedEvents = true;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2014-03-16 23:56:51 -07:00
|
|
|
/*
|
|
|
|
* Event listener manager
|
|
|
|
*/
|
2011-11-29 01:44:06 -08:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
class EventListenerManager MOZ_FINAL
|
2014-03-16 23:56:51 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Listener
|
2011-11-29 01:44:06 -08:00
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerHolder mListener;
|
2014-03-16 23:56:51 -07:00
|
|
|
nsCOMPtr<nsIAtom> mTypeAtom; // for the main thread
|
|
|
|
nsString mTypeString; // for non-main-threads
|
|
|
|
uint16_t mEventType;
|
2014-03-16 23:56:51 -07:00
|
|
|
|
|
|
|
enum ListenerType MOZ_ENUM_TYPE(uint8_t)
|
|
|
|
{
|
|
|
|
eNativeListener = 0,
|
|
|
|
eJSEventListener,
|
|
|
|
eWrappedJSListener,
|
|
|
|
eWebIDLListener,
|
|
|
|
eListenerTypeCount
|
|
|
|
};
|
2014-03-16 23:56:51 -07:00
|
|
|
uint8_t mListenerType;
|
2014-03-16 23:56:51 -07:00
|
|
|
|
2014-03-16 23:56:51 -07:00
|
|
|
bool mListenerIsHandler : 1;
|
|
|
|
bool mHandlerIsString : 1;
|
|
|
|
bool mAllEvents : 1;
|
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerFlags mFlags;
|
2014-03-16 23:56:51 -07:00
|
|
|
|
|
|
|
nsIJSEventListener* GetJSListener() const
|
|
|
|
{
|
|
|
|
return (mListenerType == eJSEventListener) ?
|
|
|
|
static_cast<nsIJSEventListener *>(mListener.GetXPCOMCallback()) :
|
|
|
|
nullptr;
|
2011-11-29 01:44:06 -08:00
|
|
|
}
|
2012-12-15 17:26:05 -08:00
|
|
|
|
2014-03-16 23:56:51 -07:00
|
|
|
Listener()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(sizeof(mListenerType) == 1);
|
|
|
|
MOZ_ASSERT(eListenerTypeCount < 255);
|
2012-12-15 17:26:05 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:51 -07:00
|
|
|
~Listener()
|
|
|
|
{
|
|
|
|
if ((mListenerType == eJSEventListener) && mListener) {
|
|
|
|
static_cast<nsIJSEventListener*>(
|
|
|
|
mListener.GetXPCOMCallback())->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
MOZ_ALWAYS_INLINE bool IsListening(const WidgetEvent* aEvent) const
|
2014-03-16 23:56:51 -07:00
|
|
|
{
|
|
|
|
if (mFlags.mInSystemGroup != aEvent->mFlags.mInSystemGroup) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// FIXME Should check !mFlags.mCapture when the event is in target
|
|
|
|
// phase because capture phase event listeners should not be fired.
|
|
|
|
// But it breaks at least <xul:dialog>'s buttons. Bug 235441.
|
|
|
|
return ((mFlags.mCapture && aEvent->mFlags.mInCapturePhase) ||
|
|
|
|
(!mFlags.mCapture && aEvent->mFlags.mInBubblingPhase));
|
|
|
|
}
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerManager(dom::EventTarget* aTarget);
|
|
|
|
virtual ~EventListenerManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(EventListenerManager)
|
2011-06-23 19:18:01 -07:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(EventListenerManager)
|
2011-06-23 19:18:01 -07:00
|
|
|
|
2011-08-18 02:45:00 -07:00
|
|
|
void AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aUseCapture,
|
2013-04-16 14:16:08 -07:00
|
|
|
bool aWantsUntrusted)
|
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerHolder holder(aListener);
|
2013-04-16 14:16:08 -07:00
|
|
|
AddEventListener(aType, holder, aUseCapture, aWantsUntrusted);
|
|
|
|
}
|
|
|
|
void AddEventListener(const nsAString& aType,
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventListener* aListener,
|
2013-04-16 14:16:08 -07:00
|
|
|
bool aUseCapture,
|
|
|
|
bool aWantsUntrusted)
|
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerHolder holder(aListener);
|
2013-04-16 14:16:08 -07:00
|
|
|
AddEventListener(aType, holder, aUseCapture, aWantsUntrusted);
|
|
|
|
}
|
2011-06-23 19:18:02 -07:00
|
|
|
void RemoveEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
2013-04-16 14:16:08 -07:00
|
|
|
bool aUseCapture)
|
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerHolder holder(aListener);
|
2013-04-16 14:16:08 -07:00
|
|
|
RemoveEventListener(aType, holder, aUseCapture);
|
|
|
|
}
|
|
|
|
void RemoveEventListener(const nsAString& aType,
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventListener* aListener,
|
2013-04-16 14:16:08 -07:00
|
|
|
bool aUseCapture)
|
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerHolder holder(aListener);
|
2013-04-16 14:16:08 -07:00
|
|
|
RemoveEventListener(aType, holder, aUseCapture);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-01 05:42:29 -07:00
|
|
|
void AddListenerForAllEvents(nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
bool aWantsUntrusted,
|
|
|
|
bool aSystemEventGroup);
|
|
|
|
void RemoveListenerForAllEvents(nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
bool aSystemEventGroup);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Sets events listeners of all types.
|
|
|
|
* @param an event listener
|
|
|
|
*/
|
2011-08-18 02:45:00 -07:00
|
|
|
void AddEventListenerByType(nsIDOMEventListener *aListener,
|
2013-04-16 14:16:08 -07:00
|
|
|
const nsAString& type,
|
2014-03-16 23:56:53 -07:00
|
|
|
const EventListenerFlags& aFlags)
|
2013-04-16 14:16:08 -07:00
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerHolder holder(aListener);
|
2013-04-16 14:16:08 -07:00
|
|
|
AddEventListenerByType(holder, type, aFlags);
|
|
|
|
}
|
2014-03-16 23:56:53 -07:00
|
|
|
void AddEventListenerByType(const EventListenerHolder& aListener,
|
2011-08-18 02:45:00 -07:00
|
|
|
const nsAString& type,
|
2014-03-16 23:56:53 -07:00
|
|
|
const EventListenerFlags& aFlags);
|
2011-06-23 19:18:02 -07:00
|
|
|
void RemoveEventListenerByType(nsIDOMEventListener *aListener,
|
2013-04-16 14:16:08 -07:00
|
|
|
const nsAString& type,
|
2014-03-16 23:56:53 -07:00
|
|
|
const EventListenerFlags& aFlags)
|
2013-04-16 14:16:08 -07:00
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerHolder holder(aListener);
|
2013-04-16 14:16:08 -07:00
|
|
|
RemoveEventListenerByType(holder, type, aFlags);
|
|
|
|
}
|
2014-03-16 23:56:53 -07:00
|
|
|
void RemoveEventListenerByType(const EventListenerHolder& aListener,
|
2011-06-23 19:18:02 -07:00
|
|
|
const nsAString& type,
|
2014-03-16 23:56:53 -07:00
|
|
|
const EventListenerFlags& aFlags);
|
2011-08-24 12:49:25 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the current "inline" event listener for aName to be a
|
|
|
|
* function compiled from aFunc if !aDeferCompilation. If
|
|
|
|
* aDeferCompilation, then we assume that we can get the string from
|
|
|
|
* mTarget later and compile lazily.
|
2013-11-26 08:44:37 -08:00
|
|
|
*
|
|
|
|
* aElement, if not null, is the element the string is associated with.
|
2011-08-24 12:49:25 -07:00
|
|
|
*/
|
|
|
|
// XXXbz does that play correctly with nodes being adopted across
|
|
|
|
// documents? Need to double-check the spec here.
|
2012-08-30 09:25:10 -07:00
|
|
|
nsresult SetEventHandler(nsIAtom *aName,
|
|
|
|
const nsAString& aFunc,
|
|
|
|
uint32_t aLanguage,
|
|
|
|
bool aDeferCompilation,
|
2013-11-26 08:44:37 -08:00
|
|
|
bool aPermitUntrustedEvents,
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::Element* aElement);
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
|
|
|
* Remove the current "inline" event listener for aName.
|
|
|
|
*/
|
2013-08-16 03:06:24 -07:00
|
|
|
void RemoveEventHandler(nsIAtom *aName, const nsAString& aTypeString);
|
2011-06-23 19:18:02 -07:00
|
|
|
|
|
|
|
void HandleEvent(nsPresContext* aPresContext,
|
2014-03-16 23:56:53 -07:00
|
|
|
WidgetEvent* aEvent,
|
2011-06-23 19:18:02 -07:00
|
|
|
nsIDOMEvent** aDOMEvent,
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventTarget* aCurrentTarget,
|
2013-12-13 18:22:18 -08:00
|
|
|
nsEventStatus* aEventStatus)
|
2010-04-16 02:04:41 -07:00
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
if (mListeners.IsEmpty() || aEvent->mFlags.mPropagationStopped) {
|
2011-06-23 19:18:02 -07:00
|
|
|
return;
|
2010-04-16 02:04:41 -07:00
|
|
|
}
|
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
if (!mMayHaveCapturingListeners && !aEvent->mFlags.mInBubblingPhase) {
|
2011-06-23 19:18:02 -07:00
|
|
|
return;
|
2010-04-16 02:04:41 -07:00
|
|
|
}
|
|
|
|
|
2012-12-15 17:26:05 -08:00
|
|
|
if (!mMayHaveSystemGroupListeners && aEvent->mFlags.mInSystemGroup) {
|
2011-06-23 19:18:02 -07:00
|
|
|
return;
|
2010-04-16 02:04:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we already know that there is no event listener for the event.
|
|
|
|
if (mNoListenerForEvent == aEvent->message &&
|
|
|
|
(mNoListenerForEvent != NS_USER_DEFINED_EVENT ||
|
|
|
|
mNoListenerForEventAtom == aEvent->userType)) {
|
2011-06-23 19:18:02 -07:00
|
|
|
return;
|
2010-04-16 02:04:41 -07:00
|
|
|
}
|
2011-06-23 19:18:02 -07:00
|
|
|
HandleEventInternal(aPresContext, aEvent, aDOMEvent, aCurrentTarget,
|
2013-12-13 18:22:18 -08:00
|
|
|
aEventStatus);
|
2010-04-16 02:04:41 -07:00
|
|
|
}
|
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
|
|
|
* Tells the event listener manager that its target (which owns it) is
|
|
|
|
* no longer using it (and could go away).
|
|
|
|
*/
|
2011-06-23 19:18:02 -07:00
|
|
|
void Disconnect();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
|
|
|
* Allows us to quickly determine if we have mutation listeners registered.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasMutationListeners();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
|
|
|
* Allows us to quickly determine whether we have unload or beforeunload
|
|
|
|
* listeners registered.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasUnloadListeners();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
|
|
|
* Returns the mutation bits depending on which mutation listeners are
|
|
|
|
* registered to this listener manager.
|
|
|
|
* @note If a listener is an nsIDOMMutationListener, all possible mutation
|
|
|
|
* event bits are returned. All bits are also returned if one of the
|
|
|
|
* event listeners is registered to handle DOMSubtreeModified events.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t MutationListenerBits();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true if there is at least one event listener for aEventName.
|
2011-08-24 12:49:25 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasListenersFor(const nsAString& aEventName);
|
2007-05-08 14:13:13 -07:00
|
|
|
|
2012-08-17 07:12:58 -07:00
|
|
|
/**
|
|
|
|
* Returns true if there is at least one event listener for aEventNameWithOn.
|
|
|
|
* Note that aEventNameWithOn must start with "on"!
|
|
|
|
*/
|
|
|
|
bool HasListenersFor(nsIAtom* aEventNameWithOn);
|
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true if there is at least one event listener.
|
2011-08-24 12:49:25 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasListeners();
|
2008-09-30 17:51:53 -07:00
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
|
|
|
* Sets aList to the list of nsIEventListenerInfo objects representing the
|
|
|
|
* listeners managed by this listener manager.
|
|
|
|
*/
|
2011-06-23 19:18:02 -07:00
|
|
|
nsresult GetListenerInfo(nsCOMArray<nsIEventListenerInfo>* aList);
|
2009-10-16 01:57:32 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t GetIdentifierForEvent(nsIAtom* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
2011-06-23 19:18:01 -07:00
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true if there may be a paint event listener registered,
|
|
|
|
* false if there definitely isn't.
|
2011-06-23 19:18:01 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool MayHavePaintEventListener() { return mMayHavePaintEventListener; }
|
2011-06-23 19:18:01 -07:00
|
|
|
|
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true if there may be a MozAudioAvailable event listener registered,
|
|
|
|
* false if there definitely isn't.
|
2011-06-23 19:18:01 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool MayHaveAudioAvailableEventListener() { return mMayHaveAudioAvailableEventListener; }
|
2011-06-23 19:18:01 -07:00
|
|
|
|
|
|
|
/**
|
2011-10-17 07:59:28 -07:00
|
|
|
* Returns true if there may be a touch event listener registered,
|
|
|
|
* false if there definitely isn't.
|
2011-06-23 19:18:01 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool MayHaveTouchEventListener() { return mMayHaveTouchEventListener; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool MayHaveMouseEnterLeaveEventListener() { return mMayHaveMouseEnterLeaveEventListener; }
|
2014-02-10 22:33:29 -08:00
|
|
|
bool MayHavePointerEnterLeaveEventListener() { return mMayHavePointerEnterLeaveEventListener; }
|
2011-09-18 00:45:14 -07:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
|
2012-01-26 06:45:12 -08:00
|
|
|
|
2013-10-28 02:47:18 -07:00
|
|
|
uint32_t ListenerCount() const
|
|
|
|
{
|
|
|
|
return mListeners.Length();
|
|
|
|
}
|
|
|
|
|
2012-10-16 18:22:02 -07:00
|
|
|
void MarkForCC();
|
2012-01-26 06:45:12 -08:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventTarget* GetTarget() { return mTarget; }
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2012-12-15 17:26:05 -08:00
|
|
|
void HandleEventInternal(nsPresContext* aPresContext,
|
2014-03-16 23:56:53 -07:00
|
|
|
WidgetEvent* aEvent,
|
2012-12-15 17:26:05 -08:00
|
|
|
nsIDOMEvent** aDOMEvent,
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventTarget* aCurrentTarget,
|
2013-12-13 18:22:18 -08:00
|
|
|
nsEventStatus* aEventStatus);
|
2012-12-15 17:26:05 -08:00
|
|
|
|
2014-03-16 23:56:51 -07:00
|
|
|
nsresult HandleEventSubType(Listener* aListener,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMEvent* aDOMEvent,
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventTarget* aCurrentTarget);
|
2011-08-24 12:49:25 -07:00
|
|
|
|
|
|
|
/**
|
2014-03-16 23:56:51 -07:00
|
|
|
* Compile the "inline" event listener for aListener. The
|
2011-08-24 12:49:25 -07:00
|
|
|
* body of the listener can be provided in aBody; if this is null we
|
2013-11-26 08:44:37 -08:00
|
|
|
* will look for it on mTarget. If aBody is provided, aElement should be
|
|
|
|
* as well; otherwise it will also be inferred from mTarget.
|
2011-08-24 12:49:25 -07:00
|
|
|
*/
|
2014-03-16 23:56:51 -07:00
|
|
|
nsresult CompileEventHandlerInternal(Listener* aListener,
|
2013-11-26 08:44:37 -08:00
|
|
|
const nsAString* aBody,
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::Element* aElement);
|
2011-08-24 12:49:25 -07:00
|
|
|
|
|
|
|
/**
|
2014-03-16 23:56:51 -07:00
|
|
|
* Find the Listener for the "inline" event listener for aTypeAtom.
|
2011-08-24 12:49:25 -07:00
|
|
|
*/
|
2014-03-16 23:56:51 -07:00
|
|
|
Listener* FindEventHandler(uint32_t aEventType,
|
|
|
|
nsIAtom* aTypeAtom,
|
|
|
|
const nsAString& aTypeString);
|
2011-08-24 12:49:25 -07:00
|
|
|
|
|
|
|
/**
|
2012-11-09 08:00:25 -08:00
|
|
|
* Set the "inline" event listener for aName to aHandler. aHandler may be
|
|
|
|
* have no actual handler set to indicate that we should lazily get and
|
2012-11-09 08:00:25 -08:00
|
|
|
* compile the string for this listener, but in that case aContext and
|
|
|
|
* aScopeGlobal must be non-null. Otherwise, aContext and aScopeGlobal are
|
2014-03-16 23:56:51 -07:00
|
|
|
* allowed to be null.
|
2011-08-24 12:49:25 -07:00
|
|
|
*/
|
2014-03-16 23:56:51 -07:00
|
|
|
Listener* SetEventHandlerInternal(JS::Handle<JSObject*> aScopeGlobal,
|
|
|
|
nsIAtom* aName,
|
|
|
|
const nsAString& aTypeString,
|
|
|
|
const nsEventHandler& aHandler,
|
|
|
|
bool aPermitUntrustedEvents);
|
2011-08-24 12:49:25 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool IsDeviceType(uint32_t aType);
|
|
|
|
void EnableDevice(uint32_t aType);
|
|
|
|
void DisableDevice(uint32_t aType);
|
2012-03-29 10:23:27 -07:00
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
public:
|
|
|
|
/**
|
2012-11-09 08:00:25 -08:00
|
|
|
* Set the "inline" event listener for aEventName to aHandler. If
|
|
|
|
* aHandler is null, this will actually remove the event listener
|
2011-08-24 12:49:25 -07:00
|
|
|
*/
|
2013-09-17 04:01:28 -07:00
|
|
|
void SetEventHandler(nsIAtom* aEventName,
|
|
|
|
const nsAString& aTypeString,
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventHandlerNonNull* aHandler);
|
|
|
|
void SetEventHandler(dom::OnErrorEventHandlerNonNull* aHandler);
|
|
|
|
void SetEventHandler(dom::OnBeforeUnloadEventHandlerNonNull* aHandler);
|
2012-11-09 08:00:25 -08:00
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
/**
|
|
|
|
* Get the value of the "inline" event listener for aEventName.
|
|
|
|
* This may cause lazy compilation if the listener is uncompiled.
|
2012-11-09 08:00:25 -08:00
|
|
|
*
|
|
|
|
* Note: It's the caller's responsibility to make sure to call the right one
|
|
|
|
* of these methods. In particular, "onerror" events use
|
|
|
|
* OnErrorEventHandlerNonNull for some event targets and EventHandlerNonNull
|
|
|
|
* for others.
|
2011-08-24 12:49:25 -07:00
|
|
|
*/
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventHandlerNonNull* GetEventHandler(nsIAtom* aEventName,
|
|
|
|
const nsAString& aTypeString)
|
2012-11-09 08:00:25 -08:00
|
|
|
{
|
2013-08-16 03:06:24 -07:00
|
|
|
const nsEventHandler* handler =
|
|
|
|
GetEventHandlerInternal(aEventName, aTypeString);
|
2012-11-09 08:00:25 -08:00
|
|
|
return handler ? handler->EventHandler() : nullptr;
|
|
|
|
}
|
2014-03-16 23:56:53 -07:00
|
|
|
|
|
|
|
dom::OnErrorEventHandlerNonNull* GetOnErrorEventHandler()
|
2012-11-09 08:00:25 -08:00
|
|
|
{
|
2013-11-05 06:16:26 -08:00
|
|
|
const nsEventHandler* handler;
|
|
|
|
if (mIsMainThreadELM) {
|
|
|
|
handler = GetEventHandlerInternal(nsGkAtoms::onerror, EmptyString());
|
|
|
|
} else {
|
2013-12-20 16:22:13 -08:00
|
|
|
handler = GetEventHandlerInternal(nullptr, NS_LITERAL_STRING("error"));
|
2013-11-05 06:16:26 -08:00
|
|
|
}
|
2012-11-09 08:00:25 -08:00
|
|
|
return handler ? handler->OnErrorEventHandler() : nullptr;
|
|
|
|
}
|
2014-03-16 23:56:53 -07:00
|
|
|
|
|
|
|
dom::OnBeforeUnloadEventHandlerNonNull* GetOnBeforeUnloadEventHandler()
|
2012-11-09 08:00:25 -08:00
|
|
|
{
|
|
|
|
const nsEventHandler* handler =
|
2013-08-16 03:06:24 -07:00
|
|
|
GetEventHandlerInternal(nsGkAtoms::onbeforeunload, EmptyString());
|
2013-10-08 08:51:15 -07:00
|
|
|
return handler ? handler->OnBeforeUnloadEventHandler() : nullptr;
|
2012-11-09 08:00:25 -08:00
|
|
|
}
|
2011-08-24 12:49:25 -07:00
|
|
|
|
|
|
|
protected:
|
2012-11-09 08:00:25 -08:00
|
|
|
/**
|
|
|
|
* Helper method for implementing the various Get*EventHandler above. Will
|
|
|
|
* return null if we don't have an event handler for this event name.
|
|
|
|
*/
|
2013-08-16 03:06:24 -07:00
|
|
|
const nsEventHandler* GetEventHandlerInternal(nsIAtom* aEventName,
|
|
|
|
const nsAString& aTypeString);
|
2012-11-09 08:00:25 -08:00
|
|
|
|
2013-04-16 14:16:08 -07:00
|
|
|
void AddEventListener(const nsAString& aType,
|
2014-03-16 23:56:53 -07:00
|
|
|
const EventListenerHolder& aListener,
|
2013-04-16 14:16:08 -07:00
|
|
|
bool aUseCapture,
|
|
|
|
bool aWantsUntrusted);
|
|
|
|
void RemoveEventListener(const nsAString& aType,
|
2014-03-16 23:56:53 -07:00
|
|
|
const EventListenerHolder& aListener,
|
2013-04-16 14:16:08 -07:00
|
|
|
bool aUseCapture);
|
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
void AddEventListenerInternal(const EventListenerHolder& aListener,
|
|
|
|
uint32_t aType,
|
|
|
|
nsIAtom* aTypeAtom,
|
|
|
|
const nsAString& aTypeString,
|
|
|
|
const EventListenerFlags& aFlags,
|
|
|
|
bool aHandler = false,
|
|
|
|
bool aAllEvents = false);
|
|
|
|
void RemoveEventListenerInternal(const EventListenerHolder& aListener,
|
|
|
|
uint32_t aType,
|
|
|
|
nsIAtom* aUserType,
|
|
|
|
const nsAString& aTypeString,
|
|
|
|
const EventListenerFlags& aFlags,
|
|
|
|
bool aAllEvents = false);
|
2011-06-23 19:18:02 -07:00
|
|
|
void RemoveAllListeners();
|
2007-03-22 10:30:00 -07:00
|
|
|
const EventTypeData* GetTypeDataForIID(const nsIID& aIID);
|
|
|
|
const EventTypeData* GetTypeDataForEventName(nsIAtom* aName);
|
2008-10-15 14:06:32 -07:00
|
|
|
nsPIDOMWindow* GetInnerWindowForTarget();
|
2012-09-30 06:47:48 -07:00
|
|
|
already_AddRefed<nsPIDOMWindow> GetTargetAsInnerWindow() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
bool ListenerCanHandle(Listener* aListener, WidgetEvent* aEvent);
|
2013-08-16 03:06:24 -07:00
|
|
|
|
2013-11-27 01:12:41 -08:00
|
|
|
already_AddRefed<nsIScriptGlobalObject>
|
|
|
|
GetScriptGlobalAndDocument(nsIDocument** aDoc);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mMayHavePaintEventListener : 1;
|
|
|
|
uint32_t mMayHaveMutationListeners : 1;
|
|
|
|
uint32_t mMayHaveCapturingListeners : 1;
|
|
|
|
uint32_t mMayHaveSystemGroupListeners : 1;
|
|
|
|
uint32_t mMayHaveAudioAvailableEventListener : 1;
|
|
|
|
uint32_t mMayHaveTouchEventListener : 1;
|
|
|
|
uint32_t mMayHaveMouseEnterLeaveEventListener : 1;
|
2014-02-10 22:33:29 -08:00
|
|
|
uint32_t mMayHavePointerEnterLeaveEventListener : 1;
|
2012-11-30 01:13:16 -08:00
|
|
|
uint32_t mClearingListeners : 1;
|
2013-08-16 03:06:24 -07:00
|
|
|
uint32_t mIsMainThreadELM : 1;
|
2014-02-10 22:33:29 -08:00
|
|
|
uint32_t mNoListenerForEvent : 22;
|
2011-06-23 19:18:01 -07:00
|
|
|
|
2014-03-16 23:56:51 -07:00
|
|
|
nsAutoTObserverArray<Listener, 2> mListeners;
|
2014-03-16 23:56:53 -07:00
|
|
|
dom::EventTarget* mTarget; // WEAK
|
|
|
|
nsCOMPtr<nsIAtom> mNoListenerForEventAtom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-17 21:48:22 -07:00
|
|
|
friend class ELMCreationDetector;
|
2014-03-16 23:56:53 -07:00
|
|
|
static uint32_t sMainThreadCreatedCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-11-24 17:09:58 -08:00
|
|
|
/**
|
|
|
|
* NS_AddSystemEventListener() is a helper function for implementing
|
2013-04-05 17:44:15 -07:00
|
|
|
* EventTarget::AddSystemEventListener().
|
2011-11-24 17:09:58 -08:00
|
|
|
*/
|
|
|
|
inline nsresult
|
2013-04-05 17:44:15 -07:00
|
|
|
NS_AddSystemEventListener(mozilla::dom::EventTarget* aTarget,
|
2011-11-24 17:09:58 -08:00
|
|
|
const nsAString& aType,
|
|
|
|
nsIDOMEventListener *aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
bool aWantsUntrusted)
|
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
mozilla::EventListenerManager* listenerManager =
|
2013-10-22 16:32:04 -07:00
|
|
|
aTarget->GetOrCreateListenerManager();
|
2011-11-24 17:09:58 -08:00
|
|
|
NS_ENSURE_STATE(listenerManager);
|
2014-03-16 23:56:52 -07:00
|
|
|
mozilla::EventListenerFlags flags;
|
2012-12-15 17:26:05 -08:00
|
|
|
flags.mInSystemGroup = true;
|
|
|
|
flags.mCapture = aUseCapture;
|
|
|
|
flags.mAllowUntrustedEvents = aWantsUntrusted;
|
2011-11-24 17:09:58 -08:00
|
|
|
listenerManager->AddEventListenerByType(aListener, aType, flags);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
#endif // mozilla_EventListenerManager_h_
|