dom/events/EventTarget.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:3bbf7ecf8f99
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/. */
5
6 #ifndef mozilla_dom_EventTarget_h_
7 #define mozilla_dom_EventTarget_h_
8
9 #include "nsIDOMEventTarget.h"
10 #include "nsWrapperCache.h"
11 #include "nsIAtom.h"
12
13 class nsIDOMWindow;
14 class nsIDOMEventListener;
15
16 namespace mozilla {
17
18 class ErrorResult;
19 class EventListenerManager;
20
21 namespace dom {
22
23 class Event;
24 class EventListener;
25 class EventHandlerNonNull;
26 template <class T> struct Nullable;
27
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 } }
32
33 class EventTarget : public nsIDOMEventTarget,
34 public nsWrapperCache
35 {
36 public:
37 NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
38
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);
53
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 }
60
61 // Note, this takes the type in onfoo form!
62 void SetEventHandler(const nsAString& aType, EventHandlerNonNull* aHandler,
63 ErrorResult& rv);
64
65 // Note, for an event 'foo' aType will be 'onfoo'.
66 virtual void EventListenerAdded(nsIAtom* aType) {}
67 virtual void EventListenerRemoved(nsIAtom* aType) {}
68
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;
73
74 /**
75 * Get the event listener manager, creating it if it does not already exist.
76 */
77 virtual EventListenerManager* GetOrCreateListenerManager() = 0;
78
79 /**
80 * Get the event listener manager, returning null if it does not already
81 * exist.
82 */
83 virtual EventListenerManager* GetExistingListenerManager() const = 0;
84
85 protected:
86 EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
87 const nsAString& aTypeString);
88 void SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
89 EventHandlerNonNull* aHandler);
90 };
91
92 NS_DEFINE_STATIC_IID_ACCESSOR(EventTarget, NS_EVENTTARGET_IID)
93
94 } // namespace dom
95 } // namespace mozilla
96
97 #endif // mozilla_dom_EventTarget_h_

mercurial