Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / events / src / nsEventListenerManager.h
blob2542b1a1ff01365451d88517ce426ebc5f3288ff
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsEventListenerManager_h__
39 #define nsEventListenerManager_h__
41 #include "nsIEventListenerManager.h"
42 #include "jsapi.h"
43 #include "nsCOMPtr.h"
44 #include "nsIDOMEventTarget.h"
45 #include "nsIDOM3EventTarget.h"
46 #include "nsHashtable.h"
47 #include "nsIScriptContext.h"
48 #include "nsCycleCollectionParticipant.h"
50 class nsIDOMEvent;
51 class nsIAtom;
52 class nsIWidget;
53 struct nsPoint;
54 struct EventTypeData;
55 class nsEventTargetChainItem;
57 typedef struct {
58 nsRefPtr<nsIDOMEventListener> mListener;
59 PRUint32 mEventType;
60 nsCOMPtr<nsIAtom> mTypeAtom;
61 PRUint16 mFlags;
62 PRUint16 mGroupFlags;
63 PRBool mHandlerIsString;
64 const EventTypeData* mTypeData;
65 } nsListenerStruct;
68 * Event listener manager
71 class nsEventListenerManager : public nsIEventListenerManager,
72 public nsIDOMEventTarget,
73 public nsIDOM3EventTarget
76 public:
77 nsEventListenerManager();
78 virtual ~nsEventListenerManager();
80 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
82 /**
83 * Sets events listeners of all types.
84 * @param an event listener
86 NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
87 const nsIID& aIID, PRInt32 aFlags);
88 NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
89 const nsIID& aIID, PRInt32 aFlags);
90 NS_IMETHOD AddEventListenerByType(nsIDOMEventListener *aListener,
91 const nsAString& type,
92 PRInt32 aFlags,
93 nsIDOMEventGroup* aEvtGroup);
94 NS_IMETHOD RemoveEventListenerByType(nsIDOMEventListener *aListener,
95 const nsAString& type,
96 PRInt32 aFlags,
97 nsIDOMEventGroup* aEvtGroup);
98 NS_IMETHOD AddScriptEventListener(nsISupports *aObject,
99 nsIAtom *aName,
100 const nsAString& aFunc,
101 PRUint32 aLanguage,
102 PRBool aDeferCompilation,
103 PRBool aPermitUntrustedEvents);
104 NS_IMETHOD RegisterScriptEventListener(nsIScriptContext *aContext,
105 void *aScopeObject,
106 nsISupports *aObject,
107 nsIAtom* aName);
108 NS_IMETHOD RemoveScriptEventListener(nsIAtom *aName);
109 NS_IMETHOD CompileScriptEventListener(nsIScriptContext *aContext,
110 void *aScopeObject,
111 nsISupports *aObject,
112 nsIAtom* aName, PRBool *aDidCompile);
114 NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
115 nsEvent* aEvent,
116 nsIDOMEvent** aDOMEvent,
117 nsPIDOMEventTarget* aCurrentTarget,
118 PRUint32 aFlags,
119 nsEventStatus* aEventStatus);
121 NS_IMETHOD Disconnect();
123 NS_IMETHOD SetListenerTarget(nsISupports* aTarget);
125 NS_IMETHOD HasMutationListeners(PRBool* aListener);
127 NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
129 virtual PRBool HasUnloadListeners();
131 virtual PRUint32 MutationListenerBits();
133 virtual PRBool HasListenersFor(const nsAString& aEventName);
135 virtual PRBool HasListeners();
137 static PRUint32 GetIdentifierForEvent(nsIAtom* aEvent);
139 // nsIDOMEventTarget
140 NS_DECL_NSIDOMEVENTTARGET
142 // nsIDOM3EventTarget
143 NS_DECL_NSIDOM3EVENTTARGET
145 static void Shutdown();
147 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEventListenerManager,
148 nsIEventListenerManager)
150 protected:
151 nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
152 nsIDOMEventListener* aListener,
153 nsIDOMEvent* aDOMEvent,
154 nsPIDOMEventTarget* aCurrentTarget,
155 PRUint32 aPhaseFlags);
156 nsresult CompileEventHandlerInternal(nsIScriptContext *aContext,
157 void *aScopeObject,
158 nsISupports *aObject,
159 nsIAtom *aName,
160 nsListenerStruct *aListenerStruct,
161 nsISupports* aCurrentTarget);
162 nsListenerStruct* FindJSEventListener(PRUint32 aEventType, nsIAtom* aTypeAtom);
163 nsresult SetJSEventListener(nsIScriptContext *aContext,
164 void *aScopeGlobal,
165 nsISupports *aObject,
166 nsIAtom* aName, PRBool aIsString,
167 PRBool aPermitUntrustedEvents);
168 nsresult AddEventListener(nsIDOMEventListener *aListener,
169 PRUint32 aType,
170 nsIAtom* aTypeAtom,
171 const EventTypeData* aTypeData,
172 PRInt32 aFlags,
173 nsIDOMEventGroup* aEvtGrp);
174 nsresult RemoveEventListener(nsIDOMEventListener *aListener,
175 PRUint32 aType,
176 nsIAtom* aUserType,
177 const EventTypeData* aTypeData,
178 PRInt32 aFlags,
179 nsIDOMEventGroup* aEvtGrp);
180 nsresult RemoveAllListeners();
181 const EventTypeData* GetTypeDataForIID(const nsIID& aIID);
182 const EventTypeData* GetTypeDataForEventName(nsIAtom* aName);
183 nsresult FixContextMenuEvent(nsPresContext* aPresContext,
184 nsISupports* aCurrentTarget,
185 nsEvent* aEvent,
186 nsIDOMEvent** aDOMEvent);
187 PRBool PrepareToUseCaretPosition(nsIWidget* aEventWidget,
188 nsIPresShell* aShell,
189 nsPoint& aTargetPt);
190 void GetCoordinatesFor(nsIDOMElement *aCurrentEl, nsPresContext *aPresContext,
191 nsIPresShell *aPresShell, nsPoint& aTargetPt);
192 nsresult GetDOM2EventGroup(nsIDOMEventGroup** aGroup);
193 PRBool ListenerCanHandle(nsListenerStruct* aLs, nsEvent* aEvent);
194 nsPIDOMWindow* GetInnerWindowForTarget();
196 nsAutoTObserverArray<nsListenerStruct, 2> mListeners;
197 nsISupports* mTarget; //WEAK
198 nsCOMPtr<nsIAtom> mNoListenerForEventAtom;
200 static PRUint32 mInstanceCount;
201 static jsval sAddListenerID;
203 friend class nsEventTargetChainItem;
204 static PRUint32 sCreatedCount;
207 #endif // nsEventListenerManager_h__