Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / events / EventListenerService.h
blob8b0b95f13003658d16c8cbbd958a5a54c07e25de
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/. */
7 #ifndef mozilla_EventListenerService_h_
8 #define mozilla_EventListenerService_h_
10 #include "jsapi.h"
11 #include "mozilla/Attributes.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "EventListenerManager.h"
14 #include "nsIEventListenerService.h"
15 #include "nsString.h"
16 #include "nsTObserverArray.h"
17 #include "nsTHashMap.h"
18 #include "nsGkAtoms.h"
20 class nsIMutableArray;
22 namespace mozilla {
23 namespace dom {
24 class EventTarget;
25 } // namespace dom
27 template <typename T>
28 class Maybe;
30 class EventListenerChange final : public nsIEventListenerChange {
31 public:
32 explicit EventListenerChange(dom::EventTarget* aTarget);
34 void AddChangedListenerName(nsAtom* aEventName);
36 NS_DECL_ISUPPORTS
37 NS_DECL_NSIEVENTLISTENERCHANGE
39 protected:
40 virtual ~EventListenerChange();
41 nsCOMPtr<dom::EventTarget> mTarget;
42 nsTArray<RefPtr<nsAtom>> mChangedListenerNames;
45 class EventListenerInfo final : public nsIEventListenerInfo {
46 public:
47 EventListenerInfo(EventListenerManager* aListenerManager,
48 const nsAString& aType,
49 JS::Handle<JSObject*> aScriptedListener,
50 JS::Handle<JSObject*> aScriptedListenerGlobal,
51 bool aCapturing, bool aAllowsUntrusted,
52 bool aInSystemEventGroup, bool aIsHandler);
54 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
55 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(EventListenerInfo)
56 NS_DECL_NSIEVENTLISTENERINFO
58 protected:
59 virtual ~EventListenerInfo();
61 bool GetJSVal(JSContext* aCx, Maybe<JSAutoRealm>& aAr,
62 JS::MutableHandle<JS::Value> aJSVal);
64 RefPtr<EventListenerManager> mListenerManager;
65 nsString mType;
66 JS::Heap<JSObject*> mScriptedListener; // May be null.
67 // mScriptedListener may be a cross-compartment wrapper so we cannot use it
68 // with JSAutoRealm because CCWs are not associated with a single realm. We
69 // use this global instead (must be same-compartment with mScriptedListener
70 // and must be non-null if mScriptedListener is non-null).
71 JS::Heap<JSObject*> mScriptedListenerGlobal;
72 bool mCapturing;
73 bool mAllowsUntrusted;
74 bool mInSystemEventGroup;
75 bool mIsHandler;
78 class EventListenerService final : public nsIEventListenerService {
79 ~EventListenerService();
81 public:
82 EventListenerService();
83 NS_DECL_ISUPPORTS
84 NS_DECL_NSIEVENTLISTENERSERVICE
86 static void NotifyAboutMainThreadListenerChange(dom::EventTarget* aTarget,
87 nsAtom* aName) {
88 if (sInstance) {
89 sInstance->NotifyAboutMainThreadListenerChangeInternal(aTarget, aName);
93 void NotifyPendingChanges();
95 private:
96 void NotifyAboutMainThreadListenerChangeInternal(dom::EventTarget* aTarget,
97 nsAtom* aName);
98 nsTObserverArray<nsCOMPtr<nsIListenerChangeListener>> mChangeListeners;
99 nsCOMPtr<nsIMutableArray> mPendingListenerChanges;
100 nsTHashMap<nsISupportsHashKey, RefPtr<EventListenerChange>>
101 mPendingListenerChangesSet;
103 static EventListenerService* sInstance;
106 } // namespace mozilla
108 #endif // mozilla_EventListenerService_h_