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"
|
|
|
|
|
2013-05-31 01:46:39 +04:00
|
|
|
class nsIDOMWindow;
|
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 {
|
|
|
|
|
2014-03-05 04:37:43 +04:00
|
|
|
class Event;
|
2013-04-17 01:16:08 +04:00
|
|
|
class EventListener;
|
2013-05-09 21:07:16 +04:00
|
|
|
class EventHandlerNonNull;
|
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-05-12 22:56:39 +03:00
|
|
|
{ 0x605158a9, 0xe229, 0x45b1, \
|
|
|
|
{ 0xbc, 0x12, 0x02, 0x9f, 0xa3, 0xa9, 0x3f, 0xcb } }
|
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,
|
2013-04-17 01:16:08 +04:00
|
|
|
bool aCapture,
|
|
|
|
const Nullable<bool>& aWantsUntrusted,
|
|
|
|
ErrorResult& aRv) = 0;
|
|
|
|
virtual void RemoveEventListener(const nsAString& aType,
|
2013-09-24 04:25:17 +04:00
|
|
|
EventListener* aCallback,
|
2013-04-17 01:16:08 +04:00
|
|
|
bool aCapture,
|
|
|
|
ErrorResult& aRv);
|
2014-03-05 04:37:43 +04:00
|
|
|
bool DispatchEvent(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)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> type = do_GetAtom(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.
|
2015-05-12 22:56:39 +03:00
|
|
|
virtual nsIDOMWindow* GetOwnerGlobalForBindings() = 0;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
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_
|