michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_EventTarget_h_ michael@0: #define mozilla_dom_EventTarget_h_ michael@0: michael@0: #include "nsIDOMEventTarget.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsIAtom.h" michael@0: michael@0: class nsIDOMWindow; michael@0: class nsIDOMEventListener; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class ErrorResult; michael@0: class EventListenerManager; michael@0: michael@0: namespace dom { michael@0: michael@0: class Event; michael@0: class EventListener; michael@0: class EventHandlerNonNull; michael@0: template struct Nullable; michael@0: michael@0: // IID for the dom::EventTarget interface michael@0: #define NS_EVENTTARGET_IID \ michael@0: { 0xce3817d0, 0x177b, 0x402f, \ michael@0: { 0xae, 0x75, 0xf8, 0x4e, 0xbe, 0x5a, 0x07, 0xc3 } } michael@0: michael@0: class EventTarget : public nsIDOMEventTarget, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID) michael@0: michael@0: // WebIDL API michael@0: using nsIDOMEventTarget::AddEventListener; michael@0: using nsIDOMEventTarget::RemoveEventListener; michael@0: using nsIDOMEventTarget::DispatchEvent; michael@0: virtual void AddEventListener(const nsAString& aType, michael@0: EventListener* aCallback, michael@0: bool aCapture, michael@0: const Nullable& aWantsUntrusted, michael@0: ErrorResult& aRv) = 0; michael@0: virtual void RemoveEventListener(const nsAString& aType, michael@0: EventListener* aCallback, michael@0: bool aCapture, michael@0: ErrorResult& aRv); michael@0: bool DispatchEvent(Event& aEvent, ErrorResult& aRv); michael@0: michael@0: // Note, this takes the type in onfoo form! michael@0: EventHandlerNonNull* GetEventHandler(const nsAString& aType) michael@0: { michael@0: nsCOMPtr type = do_GetAtom(aType); michael@0: return GetEventHandler(type, EmptyString()); michael@0: } michael@0: michael@0: // Note, this takes the type in onfoo form! michael@0: void SetEventHandler(const nsAString& aType, EventHandlerNonNull* aHandler, michael@0: ErrorResult& rv); michael@0: michael@0: // Note, for an event 'foo' aType will be 'onfoo'. michael@0: virtual void EventListenerAdded(nsIAtom* aType) {} michael@0: virtual void EventListenerRemoved(nsIAtom* aType) {} michael@0: michael@0: // Returns an outer window that corresponds to the inner window this event michael@0: // target is associated with. Will return null if the inner window is not the michael@0: // current inner or if there is no window around at all. michael@0: virtual nsIDOMWindow* GetOwnerGlobal() = 0; michael@0: michael@0: /** michael@0: * Get the event listener manager, creating it if it does not already exist. michael@0: */ michael@0: virtual EventListenerManager* GetOrCreateListenerManager() = 0; michael@0: michael@0: /** michael@0: * Get the event listener manager, returning null if it does not already michael@0: * exist. michael@0: */ michael@0: virtual EventListenerManager* GetExistingListenerManager() const = 0; michael@0: michael@0: protected: michael@0: EventHandlerNonNull* GetEventHandler(nsIAtom* aType, michael@0: const nsAString& aTypeString); michael@0: void SetEventHandler(nsIAtom* aType, const nsAString& aTypeString, michael@0: EventHandlerNonNull* aHandler); michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(EventTarget, NS_EVENTTARGET_IID) michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_EventTarget_h_