2015-05-03 22:32:37 +03: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-12-07 05:39:51 +04: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_EventTarget_h_
|
|
|
|
#define mozilla_dom_EventTarget_h_
|
|
|
|
|
2016-11-16 22:10:22 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2012-12-07 05:39:51 +04:00
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2013-05-09 21:07:16 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowOuter;
|
2015-05-12 22:56:39 +03:00
|
|
|
class nsIGlobalObject;
|
2012-12-07 05:39:51 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-08-30 01:18:25 +04:00
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
class AsyncEventDispatcher;
|
2013-08-30 01:18:25 +04:00
|
|
|
class ErrorResult;
|
2018-04-05 20:42:41 +03:00
|
|
|
class EventChainPostVisitor;
|
2018-04-05 20:42:41 +03:00
|
|
|
class EventChainPreVisitor;
|
2018-04-05 20:42:41 +03:00
|
|
|
class EventChainVisitor;
|
2014-03-17 10:56:53 +04:00
|
|
|
class EventListenerManager;
|
2013-08-30 01:18:25 +04:00
|
|
|
|
2012-12-07 05:39:51 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2016-04-26 11:23:17 +03:00
|
|
|
class AddEventListenerOptionsOrBoolean;
|
2014-03-05 04:37:43 +04:00
|
|
|
class Event;
|
2013-04-17 01:16:08 +04:00
|
|
|
class EventListener;
|
2016-04-26 11:23:17 +03:00
|
|
|
class EventListenerOptionsOrBoolean;
|
2013-05-09 21:07:16 +04:00
|
|
|
class EventHandlerNonNull;
|
2017-11-20 21:59:22 +03:00
|
|
|
class GlobalObject;
|
2016-04-26 11:23:17 +03:00
|
|
|
|
2013-09-09 13:43:52 +04:00
|
|
|
template <class T> struct Nullable;
|
2013-04-17 01:16:08 +04:00
|
|
|
|
2012-12-15 17:10:46 +04:00
|
|
|
// IID for the dom::EventTarget interface
|
2012-12-07 05:39:51 +04:00
|
|
|
#define NS_EVENTTARGET_IID \
|
2015-09-17 13:16:20 +03:00
|
|
|
{ 0xde651c36, 0x0053, 0x4c67, \
|
|
|
|
{ 0xb1, 0x3d, 0x67, 0xb9, 0x40, 0xfc, 0x82, 0xe4 } }
|
2012-12-07 05:39:51 +04:00
|
|
|
|
|
|
|
class EventTarget : public nsIDOMEventTarget,
|
|
|
|
public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
static EventTarget* From(nsIDOMEventTarget* aTarget)
|
|
|
|
{
|
|
|
|
return static_cast<EventTarget*>(aTarget);
|
|
|
|
}
|
|
|
|
|
2012-12-07 05:39:51 +04:00
|
|
|
// WebIDL API
|
2017-11-20 21:59:22 +03:00
|
|
|
static already_AddRefed<EventTarget> Constructor(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
2018-04-05 20:42:42 +03:00
|
|
|
void AddEventListener(const nsAString& aType,
|
|
|
|
EventListener* aCallback,
|
|
|
|
const AddEventListenerOptionsOrBoolean& aOptions,
|
|
|
|
const Nullable<bool>& aWantsUntrusted,
|
|
|
|
ErrorResult& aRv);
|
2018-04-05 20:42:40 +03:00
|
|
|
void RemoveEventListener(const nsAString& aType,
|
|
|
|
EventListener* aCallback,
|
|
|
|
const EventListenerOptionsOrBoolean& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2018-04-05 20:42:42 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* This method allows addition of event listeners represented by
|
|
|
|
* nsIDOMEventListener, with almost the same semantics as the
|
|
|
|
* standard AddEventListener. The one difference is that it just
|
|
|
|
* has a "use capture" boolean, not an EventListenerOptions.
|
|
|
|
*/
|
2018-04-05 20:42:42 +03:00
|
|
|
nsresult AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
const Nullable<bool>& aWantsUntrusted);
|
2018-04-05 20:42:42 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Helper methods to make the nsIDOMEventListener version of
|
|
|
|
* AddEventListener simpler to call for consumers.
|
|
|
|
*/
|
|
|
|
nsresult AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture)
|
|
|
|
{
|
|
|
|
return AddEventListener(aType, aListener, aUseCapture, Nullable<bool>());
|
|
|
|
}
|
|
|
|
nsresult AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
bool aWantsUntrusted)
|
|
|
|
{
|
|
|
|
return AddEventListener(aType, aListener, aUseCapture,
|
|
|
|
Nullable<bool>(aWantsUntrusted));
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:42:40 +03:00
|
|
|
/**
|
|
|
|
* This method allows the removal of event listeners represented by
|
|
|
|
* nsIDOMEventListener from the event target, with the same semantics as the
|
|
|
|
* standard RemoveEventListener.
|
|
|
|
*/
|
|
|
|
void RemoveEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture);
|
2018-04-05 20:42:40 +03:00
|
|
|
/**
|
|
|
|
* RemoveSystemEventListener() should be used if you have used
|
|
|
|
* AddSystemEventListener().
|
|
|
|
*/
|
|
|
|
void RemoveSystemEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture);
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
/**
|
|
|
|
* Returns the EventTarget object which should be used as the target
|
|
|
|
* of DOMEvents.
|
|
|
|
* Usually |this| is returned, but for example Window (inner windw) returns
|
|
|
|
* the WindowProxy (outer window).
|
|
|
|
*/
|
|
|
|
virtual EventTarget* GetTargetForDOMEvent()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the EventTarget object which should be used as the target
|
|
|
|
* of the event and when constructing event target chain.
|
|
|
|
* Usually |this| is returned, but for example WindowProxy (outer window) returns
|
|
|
|
* the Window (inner window).
|
|
|
|
*/
|
|
|
|
virtual EventTarget* GetTargetForEventTargetChain()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
/**
|
|
|
|
* The most general DispatchEvent method. This is the one the bindings call.
|
|
|
|
*/
|
|
|
|
virtual bool DispatchEvent(Event& aEvent, CallerType aCallerType,
|
|
|
|
ErrorResult& aRv) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A version of DispatchEvent you can use if you really don't care whether it
|
|
|
|
* succeeds or not and whether default is prevented or not.
|
|
|
|
*/
|
|
|
|
void DispatchEvent(Event& aEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A version of DispatchEvent you can use if you really don't care whether
|
|
|
|
* default is prevented or not.
|
|
|
|
*/
|
|
|
|
void DispatchEvent(Event& aEvent, ErrorResult& aRv);
|
2013-05-09 21:07:16 +04:00
|
|
|
|
2017-11-20 21:59:22 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const
|
|
|
|
{
|
|
|
|
return GetOwnerGlobal();
|
|
|
|
}
|
|
|
|
|
2013-08-16 14:06:24 +04:00
|
|
|
// Note, this takes the type in onfoo form!
|
2013-05-09 21:07:16 +04:00
|
|
|
EventHandlerNonNull* GetEventHandler(const nsAString& aType)
|
|
|
|
{
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> type = NS_Atomize(aType);
|
2013-08-16 14:06:24 +04:00
|
|
|
return GetEventHandler(type, EmptyString());
|
2013-05-09 21:07:16 +04:00
|
|
|
}
|
|
|
|
|
2013-08-16 14:06:24 +04:00
|
|
|
// Note, this takes the type in onfoo form!
|
2013-05-09 21:07:16 +04:00
|
|
|
void SetEventHandler(const nsAString& aType, EventHandlerNonNull* aHandler,
|
2013-08-16 14:06:24 +04:00
|
|
|
ErrorResult& rv);
|
2013-05-09 21:07:16 +04:00
|
|
|
|
2018-04-04 22:32:19 +03:00
|
|
|
// The nsAtom version of EventListenerAdded is called on the main
|
|
|
|
// thread. The string version is called on workers.
|
|
|
|
//
|
|
|
|
// For an event 'foo' aType will be 'onfoo' when it's an atom and
|
|
|
|
// 'foo' when it's a string..
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual void EventListenerAdded(nsAtom* aType) {}
|
2017-04-18 14:51:27 +03:00
|
|
|
virtual void EventListenerAdded(const nsAString& aType) {}
|
|
|
|
|
2018-04-04 22:32:19 +03:00
|
|
|
// The nsAtom version of EventListenerRemoved is called on the main
|
|
|
|
// thread. The string version is called on workers.
|
|
|
|
//
|
|
|
|
// For an event 'foo' aType will be 'onfoo' when it's an atom and
|
|
|
|
// 'foo' when it's a string..
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual void EventListenerRemoved(nsAtom* aType) {}
|
2017-04-18 14:51:27 +03:00
|
|
|
virtual void EventListenerRemoved(const nsAString& aType) {}
|
2013-05-23 15:41:00 +04:00
|
|
|
|
2013-05-31 01:46:39 +04:00
|
|
|
// Returns an outer window that corresponds to the inner window this event
|
|
|
|
// target is associated with. Will return null if the inner window is not the
|
|
|
|
// current inner or if there is no window around at all.
|
2016-01-30 20:05:36 +03:00
|
|
|
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() = 0;
|
2015-05-12 22:56:39 +03:00
|
|
|
|
|
|
|
// The global object this event target is associated with, if any.
|
|
|
|
// This may be an inner window or some other global object. This
|
|
|
|
// will never be an outer window.
|
|
|
|
virtual nsIGlobalObject* GetOwnerGlobal() const = 0;
|
2013-05-31 01:46:39 +04:00
|
|
|
|
2013-10-23 03:32:04 +04:00
|
|
|
/**
|
|
|
|
* Get the event listener manager, creating it if it does not already exist.
|
|
|
|
*/
|
2014-03-17 10:56:53 +04:00
|
|
|
virtual EventListenerManager* GetOrCreateListenerManager() = 0;
|
2013-10-23 03:32:04 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the event listener manager, returning null if it does not already
|
|
|
|
* exist.
|
|
|
|
*/
|
2014-03-17 10:56:53 +04:00
|
|
|
virtual EventListenerManager* GetExistingListenerManager() const = 0;
|
2013-10-23 03:32:04 +04:00
|
|
|
|
2016-10-06 07:30:35 +03:00
|
|
|
// Called from AsyncEventDispatcher to notify it is running.
|
|
|
|
virtual void AsyncEventRunning(AsyncEventDispatcher* aEvent) {}
|
|
|
|
|
2017-07-28 02:46:44 +03:00
|
|
|
// Used by APZ to determine whether this event target has non-chrome event
|
|
|
|
// listeners for untrusted key events.
|
|
|
|
bool HasNonSystemGroupListenersForUntrustedKeyEvents() const;
|
|
|
|
|
|
|
|
// Used by APZ to determine whether this event target has non-chrome and
|
|
|
|
// non-passive event listeners for untrusted key events.
|
|
|
|
bool HasNonPassiveNonSystemGroupListenersForUntrustedKeyEvents() const;
|
2017-06-06 03:22:16 +03:00
|
|
|
|
2016-05-06 13:39:10 +03:00
|
|
|
virtual bool IsApzAware() const;
|
2015-09-17 13:16:20 +03:00
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
/**
|
|
|
|
* Called before the capture phase of the event flow.
|
|
|
|
* This is used to create the event target chain and implementations
|
|
|
|
* should set the necessary members of EventChainPreVisitor.
|
|
|
|
* At least aVisitor.mCanHandle must be set,
|
|
|
|
* usually also aVisitor.mParentTarget if mCanHandle is true.
|
|
|
|
* mCanHandle says that this object can handle the aVisitor.mEvent event and
|
|
|
|
* the mParentTarget is the possible parent object for the event target chain.
|
|
|
|
* @see EventDispatcher.h for more documentation about aVisitor.
|
|
|
|
*
|
|
|
|
* @param aVisitor the visitor object which is used to create the
|
|
|
|
* event target chain for event dispatching.
|
|
|
|
*
|
|
|
|
* @note Only EventDispatcher should call this method.
|
|
|
|
*/
|
|
|
|
virtual void GetEventTargetParent(EventChainPreVisitor& aVisitor) = 0;
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
/**
|
|
|
|
* Called before the capture phase of the event flow and after event target
|
|
|
|
* chain creation. This is used to handle things that must be executed before
|
|
|
|
* dispatching the event to DOM.
|
|
|
|
*/
|
|
|
|
virtual nsresult PreHandleEvent(EventChainVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If EventChainPreVisitor.mWantsWillHandleEvent is set true,
|
|
|
|
* called just before possible event handlers on this object will be called.
|
|
|
|
*/
|
|
|
|
virtual void WillHandleEvent(EventChainPostVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after the bubble phase of the system event group.
|
|
|
|
* The default handling of the event should happen here.
|
|
|
|
* @param aVisitor the visitor object which is used during post handling.
|
|
|
|
*
|
|
|
|
* @see EventDispatcher.h for documentation about aVisitor.
|
|
|
|
* @note Only EventDispatcher should call this method.
|
|
|
|
*/
|
|
|
|
virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) = 0;
|
|
|
|
|
2013-05-09 21:07:16 +04:00
|
|
|
protected:
|
2017-10-03 01:05:19 +03:00
|
|
|
EventHandlerNonNull* GetEventHandler(nsAtom* aType,
|
2013-08-16 14:06:24 +04:00
|
|
|
const nsAString& aTypeString);
|
2017-10-03 01:05:19 +03:00
|
|
|
void SetEventHandler(nsAtom* aType, const nsAString& aTypeString,
|
2013-09-17 15:01:28 +04:00
|
|
|
EventHandlerNonNull* aHandler);
|
2018-04-05 20:42:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook for AddEventListener that allows it to compute the right
|
|
|
|
* wantsUntrusted boolean when one is not provided. If this returns failure,
|
|
|
|
* the listener will not be added.
|
|
|
|
*
|
|
|
|
* This hook will NOT be called unless aWantsUntrusted is null in
|
|
|
|
* AddEventListener. If you need to take action when event listeners are
|
|
|
|
* added, use EventListenerAdded. Especially because not all event listener
|
|
|
|
* additions go through AddEventListener!
|
|
|
|
*/
|
|
|
|
virtual bool ComputeDefaultWantsUntrusted(ErrorResult& aRv) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A method to compute the right wantsUntrusted value for AddEventListener.
|
|
|
|
* This will call the above hook as needed.
|
|
|
|
*/
|
|
|
|
bool ComputeWantsUntrusted(const Nullable<bool>& aWantsUntrusted,
|
|
|
|
ErrorResult& aRv);
|
2012-12-07 05:39:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(EventTarget, NS_EVENTTARGET_IID)
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_EventTarget_h_
|