2012-12-07 05:39:51 +04: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 21:07:16 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
|
2013-05-31 01:46:39 +04:00
|
|
|
class nsIDOMWindow;
|
2013-08-30 01:18:25 +04:00
|
|
|
class nsIDOMEventListener;
|
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 \
|
2013-10-23 03:32:04 +04:00
|
|
|
{ 0xce3817d0, 0x177b, 0x402f, \
|
|
|
|
{ 0xae, 0x75, 0xf8, 0x4e, 0xbe, 0x5a, 0x07, 0xc3 } }
|
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.
|
|
|
|
virtual nsIDOMWindow* GetOwnerGlobal() = 0;
|
|
|
|
|
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_
|