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_
|
|
|
|
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2013-05-09 21:07:16 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
|
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
|
|
|
|
|
|
|
class ErrorResult;
|
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;
|
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)
|
|
|
|
|
|
|
|
// WebIDL API
|
|
|
|
using nsIDOMEventTarget::AddEventListener;
|
|
|
|
using nsIDOMEventTarget::RemoveEventListener;
|
|
|
|
using nsIDOMEventTarget::DispatchEvent;
|
2013-04-17 01:16:08 +04:00
|
|
|
virtual void AddEventListener(const nsAString& aType,
|
2013-09-24 04:25:17 +04:00
|
|
|
EventListener* aCallback,
|
2016-04-26 11:23:17 +03:00
|
|
|
const AddEventListenerOptionsOrBoolean& aOptions,
|
2013-04-17 01:16:08 +04:00
|
|
|
const Nullable<bool>& aWantsUntrusted,
|
|
|
|
ErrorResult& aRv) = 0;
|
|
|
|
virtual void RemoveEventListener(const nsAString& aType,
|
2013-09-24 04:25:17 +04:00
|
|
|
EventListener* aCallback,
|
2016-04-26 11:23:17 +03:00
|
|
|
const EventListenerOptionsOrBoolean& aOptions,
|
2013-04-17 01:16:08 +04:00
|
|
|
ErrorResult& aRv);
|
2016-04-07 15:49:12 +03:00
|
|
|
bool DispatchEvent(JSContext* aCx, Event& aEvent, ErrorResult& aRv);
|
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
|
|
|
EventHandlerNonNull* GetEventHandler(const nsAString& aType)
|
|
|
|
{
|
2016-03-29 02:09:43 +03:00
|
|
|
nsCOMPtr<nsIAtom> 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
|
|
|
|
2013-05-23 15:41:00 +04:00
|
|
|
// Note, for an event 'foo' aType will be 'onfoo'.
|
|
|
|
virtual void EventListenerAdded(nsIAtom* aType) {}
|
|
|
|
virtual void EventListenerRemoved(nsIAtom* aType) {}
|
|
|
|
|
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-05-06 13:39:10 +03:00
|
|
|
virtual bool IsApzAware() const;
|
2015-09-17 13:16:20 +03:00
|
|
|
|
2013-05-09 21:07:16 +04:00
|
|
|
protected:
|
2013-08-16 14:06:24 +04:00
|
|
|
EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
|
|
|
|
const nsAString& aTypeString);
|
|
|
|
void SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
|
2013-09-17 15:01:28 +04:00
|
|
|
EventHandlerNonNull* aHandler);
|
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_
|