Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_EventTarget_h_
7 #define mozilla_dom_EventTarget_h_
9 #include "nsIDOMEventTarget.h"
10 #include "nsWrapperCache.h"
11 #include "nsIAtom.h"
13 class nsIDOMWindow;
14 class nsIDOMEventListener;
16 namespace mozilla {
18 class ErrorResult;
19 class EventListenerManager;
21 namespace dom {
23 class Event;
24 class EventListener;
25 class EventHandlerNonNull;
26 template <class T> struct Nullable;
28 // IID for the dom::EventTarget interface
29 #define NS_EVENTTARGET_IID \
30 { 0xce3817d0, 0x177b, 0x402f, \
31 { 0xae, 0x75, 0xf8, 0x4e, 0xbe, 0x5a, 0x07, 0xc3 } }
33 class EventTarget : public nsIDOMEventTarget,
34 public nsWrapperCache
35 {
36 public:
37 NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
39 // WebIDL API
40 using nsIDOMEventTarget::AddEventListener;
41 using nsIDOMEventTarget::RemoveEventListener;
42 using nsIDOMEventTarget::DispatchEvent;
43 virtual void AddEventListener(const nsAString& aType,
44 EventListener* aCallback,
45 bool aCapture,
46 const Nullable<bool>& aWantsUntrusted,
47 ErrorResult& aRv) = 0;
48 virtual void RemoveEventListener(const nsAString& aType,
49 EventListener* aCallback,
50 bool aCapture,
51 ErrorResult& aRv);
52 bool DispatchEvent(Event& aEvent, ErrorResult& aRv);
54 // Note, this takes the type in onfoo form!
55 EventHandlerNonNull* GetEventHandler(const nsAString& aType)
56 {
57 nsCOMPtr<nsIAtom> type = do_GetAtom(aType);
58 return GetEventHandler(type, EmptyString());
59 }
61 // Note, this takes the type in onfoo form!
62 void SetEventHandler(const nsAString& aType, EventHandlerNonNull* aHandler,
63 ErrorResult& rv);
65 // Note, for an event 'foo' aType will be 'onfoo'.
66 virtual void EventListenerAdded(nsIAtom* aType) {}
67 virtual void EventListenerRemoved(nsIAtom* aType) {}
69 // Returns an outer window that corresponds to the inner window this event
70 // target is associated with. Will return null if the inner window is not the
71 // current inner or if there is no window around at all.
72 virtual nsIDOMWindow* GetOwnerGlobal() = 0;
74 /**
75 * Get the event listener manager, creating it if it does not already exist.
76 */
77 virtual EventListenerManager* GetOrCreateListenerManager() = 0;
79 /**
80 * Get the event listener manager, returning null if it does not already
81 * exist.
82 */
83 virtual EventListenerManager* GetExistingListenerManager() const = 0;
85 protected:
86 EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
87 const nsAString& aTypeString);
88 void SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
89 EventHandlerNonNull* aHandler);
90 };
92 NS_DEFINE_STATIC_IID_ACCESSOR(EventTarget, NS_EVENTTARGET_IID)
94 } // namespace dom
95 } // namespace mozilla
97 #endif // mozilla_dom_EventTarget_h_