2015-05-03 19:32:37 +00: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 01:39:51 +00: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_
|
|
|
|
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2013-05-09 17:07:16 +00:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
class nsPIDOMWindowOuter;
|
2015-05-12 19:56:39 +00:00
|
|
|
class nsIGlobalObject;
|
2012-12-07 01:39:51 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-08-29 21:18:25 +00:00
|
|
|
|
|
|
|
class ErrorResult;
|
2014-03-17 06:56:53 +00:00
|
|
|
class EventListenerManager;
|
2013-08-29 21:18:25 +00:00
|
|
|
|
2012-12-07 01:39:51 +00:00
|
|
|
namespace dom {
|
|
|
|
|
2016-04-26 08:23:17 +00:00
|
|
|
class AddEventListenerOptionsOrBoolean;
|
2014-03-05 00:37:43 +00:00
|
|
|
class Event;
|
2013-04-16 21:16:08 +00:00
|
|
|
class EventListener;
|
2016-04-26 08:23:17 +00:00
|
|
|
class EventListenerOptionsOrBoolean;
|
2013-05-09 17:07:16 +00:00
|
|
|
class EventHandlerNonNull;
|
2016-04-26 08:23:17 +00:00
|
|
|
|
2013-09-09 09:43:52 +00:00
|
|
|
template <class T> struct Nullable;
|
2013-04-16 21:16:08 +00:00
|
|
|
|
2012-12-15 13:10:46 +00:00
|
|
|
// IID for the dom::EventTarget interface
|
2012-12-07 01:39:51 +00:00
|
|
|
#define NS_EVENTTARGET_IID \
|
2015-09-17 10:16:20 +00:00
|
|
|
{ 0xde651c36, 0x0053, 0x4c67, \
|
|
|
|
{ 0xb1, 0x3d, 0x67, 0xb9, 0x40, 0xfc, 0x82, 0xe4 } }
|
2012-12-07 01:39:51 +00:00
|
|
|
|
|
|
|
class EventTarget : public nsIDOMEventTarget,
|
|
|
|
public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
|
|
|
|
|
|
|
|
// WebIDL API
|
|
|
|
using nsIDOMEventTarget::AddEventListener;
|
|
|
|
using nsIDOMEventTarget::RemoveEventListener;
|
|
|
|
using nsIDOMEventTarget::DispatchEvent;
|
2013-04-16 21:16:08 +00:00
|
|
|
virtual void AddEventListener(const nsAString& aType,
|
2013-09-24 00:25:17 +00:00
|
|
|
EventListener* aCallback,
|
2016-04-26 08:23:17 +00:00
|
|
|
const AddEventListenerOptionsOrBoolean& aOptions,
|
2013-04-16 21:16:08 +00:00
|
|
|
const Nullable<bool>& aWantsUntrusted,
|
|
|
|
ErrorResult& aRv) = 0;
|
|
|
|
virtual void RemoveEventListener(const nsAString& aType,
|
2013-09-24 00:25:17 +00:00
|
|
|
EventListener* aCallback,
|
2016-04-26 08:23:17 +00:00
|
|
|
const EventListenerOptionsOrBoolean& aOptions,
|
2013-04-16 21:16:08 +00:00
|
|
|
ErrorResult& aRv);
|
2016-04-07 12:49:12 +00:00
|
|
|
bool DispatchEvent(JSContext* aCx, Event& aEvent, ErrorResult& aRv);
|
2013-05-09 17:07:16 +00:00
|
|
|
|
2013-08-16 10:06:24 +00:00
|
|
|
// Note, this takes the type in onfoo form!
|
2013-05-09 17:07:16 +00:00
|
|
|
EventHandlerNonNull* GetEventHandler(const nsAString& aType)
|
|
|
|
{
|
2016-03-28 23:09:43 +00:00
|
|
|
nsCOMPtr<nsIAtom> type = NS_Atomize(aType);
|
2013-08-16 10:06:24 +00:00
|
|
|
return GetEventHandler(type, EmptyString());
|
2013-05-09 17:07:16 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 10:06:24 +00:00
|
|
|
// Note, this takes the type in onfoo form!
|
2013-05-09 17:07:16 +00:00
|
|
|
void SetEventHandler(const nsAString& aType, EventHandlerNonNull* aHandler,
|
2013-08-16 10:06:24 +00:00
|
|
|
ErrorResult& rv);
|
2013-05-09 17:07:16 +00:00
|
|
|
|
2013-05-23 11:41:00 +00:00
|
|
|
// Note, for an event 'foo' aType will be 'onfoo'.
|
|
|
|
virtual void EventListenerAdded(nsIAtom* aType) {}
|
|
|
|
virtual void EventListenerRemoved(nsIAtom* aType) {}
|
|
|
|
|
2013-05-30 21:46:39 +00: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 17:05:36 +00:00
|
|
|
virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() = 0;
|
2015-05-12 19:56:39 +00: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-30 21:46:39 +00:00
|
|
|
|
2013-10-22 23:32:04 +00:00
|
|
|
/**
|
|
|
|
* Get the event listener manager, creating it if it does not already exist.
|
|
|
|
*/
|
2014-03-17 06:56:53 +00:00
|
|
|
virtual EventListenerManager* GetOrCreateListenerManager() = 0;
|
2013-10-22 23:32:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the event listener manager, returning null if it does not already
|
|
|
|
* exist.
|
|
|
|
*/
|
2014-03-17 06:56:53 +00:00
|
|
|
virtual EventListenerManager* GetExistingListenerManager() const = 0;
|
2013-10-22 23:32:04 +00:00
|
|
|
|
2016-05-06 10:39:10 +00:00
|
|
|
virtual bool IsApzAware() const;
|
2015-09-17 10:16:20 +00:00
|
|
|
|
2013-05-09 17:07:16 +00:00
|
|
|
protected:
|
2013-08-16 10:06:24 +00:00
|
|
|
EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
|
|
|
|
const nsAString& aTypeString);
|
|
|
|
void SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
|
2013-09-17 11:01:28 +00:00
|
|
|
EventHandlerNonNull* aHandler);
|
2012-12-07 01:39:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(EventTarget, NS_EVENTTARGET_IID)
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_EventTarget_h_
|