Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_EventListenerService_h_
8 : #define mozilla_EventListenerService_h_
9 :
10 : #include "jsapi.h"
11 : #include "mozilla/Attributes.h"
12 : #include "nsAutoPtr.h"
13 : #include "nsCycleCollectionParticipant.h"
14 : #include "nsIDOMEventListener.h"
15 : #include "nsIEventListenerService.h"
16 : #include "nsString.h"
17 : #include "nsTObserverArray.h"
18 : #include "nsDataHashtable.h"
19 : #include "nsGkAtoms.h"
20 :
21 : class nsIMutableArray;
22 :
23 : namespace mozilla {
24 : namespace dom {
25 : class EventTarget;
26 : } // namespace dom
27 :
28 : template<typename T>
29 : class Maybe;
30 :
31 : class EventListenerChange final : public nsIEventListenerChange
32 : {
33 : public:
34 : explicit EventListenerChange(dom::EventTarget* aTarget);
35 :
36 : void AddChangedListenerName(nsIAtom* aEventName);
37 :
38 : NS_DECL_ISUPPORTS
39 : NS_DECL_NSIEVENTLISTENERCHANGE
40 :
41 : protected:
42 : virtual ~EventListenerChange();
43 : nsCOMPtr<dom::EventTarget> mTarget;
44 : nsCOMPtr<nsIMutableArray> mChangedListenerNames;
45 :
46 : };
47 :
48 : class EventListenerInfo final : public nsIEventListenerInfo
49 : {
50 : public:
51 0 : EventListenerInfo(const nsAString& aType,
52 : already_AddRefed<nsIDOMEventListener> aListener,
53 : bool aCapturing,
54 : bool aAllowsUntrusted,
55 : bool aInSystemEventGroup)
56 0 : : mType(aType)
57 : , mListener(aListener)
58 : , mCapturing(aCapturing)
59 : , mAllowsUntrusted(aAllowsUntrusted)
60 0 : , mInSystemEventGroup(aInSystemEventGroup)
61 : {
62 0 : }
63 :
64 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
65 0 : NS_DECL_CYCLE_COLLECTION_CLASS(EventListenerInfo)
66 : NS_DECL_NSIEVENTLISTENERINFO
67 :
68 : protected:
69 0 : virtual ~EventListenerInfo() {}
70 :
71 : bool GetJSVal(JSContext* aCx,
72 : Maybe<JSAutoCompartment>& aAc,
73 : JS::MutableHandle<JS::Value> aJSVal);
74 :
75 : nsString mType;
76 : // nsReftPtr because that is what nsListenerStruct uses too.
77 : RefPtr<nsIDOMEventListener> mListener;
78 : bool mCapturing;
79 : bool mAllowsUntrusted;
80 : bool mInSystemEventGroup;
81 : };
82 :
83 : class EventListenerService final : public nsIEventListenerService
84 : {
85 : ~EventListenerService();
86 : public:
87 : EventListenerService();
88 : NS_DECL_ISUPPORTS
89 : NS_DECL_NSIEVENTLISTENERSERVICE
90 :
91 2092 : static void NotifyAboutMainThreadListenerChange(dom::EventTarget* aTarget,
92 : nsIAtom* aName)
93 : {
94 2092 : if (sInstance) {
95 892 : sInstance->NotifyAboutMainThreadListenerChangeInternal(aTarget, aName);
96 : }
97 2092 : }
98 :
99 : void NotifyPendingChanges();
100 : private:
101 : void NotifyAboutMainThreadListenerChangeInternal(dom::EventTarget* aTarget,
102 : nsIAtom* aName);
103 : nsTObserverArray<nsCOMPtr<nsIListenerChangeListener>> mChangeListeners;
104 : nsCOMPtr<nsIMutableArray> mPendingListenerChanges;
105 : nsDataHashtable<nsISupportsHashKey, RefPtr<EventListenerChange>> mPendingListenerChangesSet;
106 :
107 : static EventListenerService* sInstance;
108 : };
109 :
110 : } // namespace mozilla
111 :
112 : #endif // mozilla_EventListenerService_h_
|