2012-12-07 01:39:51 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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"
|
|
|
|
|
2013-05-30 21:46:39 +00:00
|
|
|
class nsIDOMWindow;
|
2013-08-29 21:18:25 +00:00
|
|
|
class nsIDOMEventListener;
|
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 {
|
|
|
|
|
2014-03-05 00:37:43 +00:00
|
|
|
class Event;
|
2013-04-16 21:16:08 +00:00
|
|
|
class EventListener;
|
2013-05-09 17:07:16 +00:00
|
|
|
class EventHandlerNonNull;
|
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 \
|
2013-10-22 23:32:04 +00:00
|
|
|
{ 0xce3817d0, 0x177b, 0x402f, \
|
|
|
|
{ 0xae, 0x75, 0xf8, 0x4e, 0xbe, 0x5a, 0x07, 0xc3 } }
|
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,
|
2013-04-16 21:16:08 +00:00
|
|
|
bool aCapture,
|
|
|
|
const Nullable<bool>& aWantsUntrusted,
|
|
|
|
ErrorResult& aRv) = 0;
|
|
|
|
virtual void RemoveEventListener(const nsAString& aType,
|
2013-09-24 00:25:17 +00:00
|
|
|
EventListener* aCallback,
|
2013-04-16 21:16:08 +00:00
|
|
|
bool aCapture,
|
|
|
|
ErrorResult& aRv);
|
2014-03-05 00:37:43 +00:00
|
|
|
bool DispatchEvent(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)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> type = do_GetAtom(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.
|
|
|
|
virtual nsIDOMWindow* GetOwnerGlobal() = 0;
|
|
|
|
|
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
|
|
|
|
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_
|