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"
|
2019-06-17 07:36:29 +03:00
|
|
|
#include "mozilla/dom/DebuggerNotificationBinding.h"
|
2018-04-05 20:42:42 +03:00
|
|
|
#include "mozilla/dom/Nullable.h"
|
2018-04-20 07:49:30 +03:00
|
|
|
#include "nsISupports.h"
|
2012-12-07 05:39:51 +04:00
|
|
|
#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;
|
2018-04-20 07:49:30 +03:00
|
|
|
class nsIDOMEventListener;
|
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;
|
2019-05-25 02:53:49 +03:00
|
|
|
class WindowProxyHolder;
|
2016-04-26 11:23:17 +03: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 \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2015-09-17 13:16:20 +03:00
|
|
|
0xde651c36, 0x0053, 0x4c67, { \
|
|
|
|
0xb1, 0x3d, 0x67, 0xb9, 0x40, 0xfc, 0x82, 0xe4 \
|
|
|
|
} \
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-20 07:49:30 +03:00
|
|
|
class EventTarget : public nsISupports, public nsWrapperCache {
|
2012-12-07 05:39:51 +04:00
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
|
|
|
|
|
|
|
|
// 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-09-07 17:47:51 +03:00
|
|
|
|
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:42 +03:00
|
|
|
/**
|
|
|
|
* Add a system event listener with the default wantsUntrusted value.
|
|
|
|
*/
|
|
|
|
nsresult AddSystemEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture) {
|
|
|
|
return AddSystemEventListener(aType, aListener, aUseCapture,
|
|
|
|
Nullable<bool>());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a system event listener with the given wantsUntrusted value.
|
|
|
|
*/
|
|
|
|
nsresult AddSystemEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture, bool aWantsUntrusted) {
|
|
|
|
return AddSystemEventListener(aType, aListener, aUseCapture,
|
|
|
|
Nullable<bool>(aWantsUntrusted));
|
|
|
|
}
|
|
|
|
|
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);
|
2018-07-25 01:15:19 +03:00
|
|
|
return GetEventHandler(type);
|
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-07-25 01:15:19 +03:00
|
|
|
// For an event 'foo' aType will be 'onfoo'.
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual void EventListenerAdded(nsAtom* aType) {}
|
2017-04-18 14:51:27 +03:00
|
|
|
|
2018-07-25 01:15:19 +03:00
|
|
|
// For an event 'foo' aType will be 'onfoo'.
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual void EventListenerRemoved(nsAtom* 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.
|
2019-01-02 16:26:56 +03:00
|
|
|
Nullable<WindowProxyHolder> GetOwnerGlobalForBindings();
|
|
|
|
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindingsInternal() = 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
|
|
|
|
2019-06-17 07:36:29 +03:00
|
|
|
virtual Maybe<EventCallbackDebuggerNotificationType>
|
|
|
|
GetDebuggerNotificationType() const {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2019-04-02 22:06:11 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT
|
2018-04-05 20:42:41 +03:00
|
|
|
virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) = 0;
|
2018-09-07 17:47:51 +03:00
|
|
|
|
2013-05-09 21:07:16 +04:00
|
|
|
protected:
|
2018-07-25 01:15:19 +03:00
|
|
|
EventHandlerNonNull* GetEventHandler(nsAtom* aType);
|
|
|
|
void SetEventHandler(nsAtom* aType, 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.
|
2018-07-30 04:51:00 +03:00
|
|
|
*
|
|
|
|
* If aOptions is non-null, and it contains a value for mWantUntrusted, that
|
|
|
|
* value takes precedence over aWantsUntrusted.
|
2018-04-05 20:42:42 +03:00
|
|
|
*/
|
|
|
|
bool ComputeWantsUntrusted(const Nullable<bool>& aWantsUntrusted,
|
2018-07-30 04:51:00 +03:00
|
|
|
const AddEventListenerOptionsOrBoolean* aOptions,
|
2018-04-05 20:42:42 +03:00
|
|
|
ErrorResult& aRv);
|
2018-04-05 20:42:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* addSystemEventListener() adds an event listener of aType to the system
|
|
|
|
* group. Typically, core code should use the system group for listening to
|
|
|
|
* content (i.e., non-chrome) element's events. If core code uses
|
|
|
|
* EventTarget::AddEventListener for a content node, it means
|
|
|
|
* that the listener cannot listen to the event when web content calls
|
|
|
|
* stopPropagation() of the event.
|
|
|
|
*
|
|
|
|
* @param aType An event name you're going to handle.
|
|
|
|
* @param aListener An event listener.
|
|
|
|
* @param aUseCapture true if you want to listen the event in capturing
|
|
|
|
* phase. Otherwise, false.
|
|
|
|
* @param aWantsUntrusted true if you want to handle untrusted events.
|
|
|
|
* false if not.
|
|
|
|
* Null if you want the default behavior.
|
|
|
|
*/
|
|
|
|
nsresult AddSystemEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
|
|
|
bool aUseCapture,
|
|
|
|
const Nullable<bool>& aWantsUntrusted);
|
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_
|