Bug 451504 js/src/jslock.cpp failed to compile on Solaris x86 r=igor
[wine-gecko.git] / content / events / src / nsEventListenerManager.h
blobf78eac05b9ebb7a397d8f0b4162054762663de24
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 struct EventTypeData;
54 typedef struct {
55 nsRefPtr<nsIDOMEventListener> mListener;
56 PRUint32 mEventType;
57 nsCOMPtr<nsIAtom> mTypeAtom;
58 PRUint16 mFlags;
59 PRUint16 mGroupFlags;
60 PRBool mHandlerIsString;
61 const EventTypeData* mTypeData;
62 } nsListenerStruct;
65 * Event listener manager
68 class nsEventListenerManager : public nsIEventListenerManager,
69 public nsIDOMEventTarget,
70 public nsIDOM3EventTarget
73 public:
74 nsEventListenerManager();
75 virtual ~nsEventListenerManager();
77 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
79 /**
80 * Sets events listeners of all types.
81 * @param an event listener
83 NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
84 const nsIID& aIID, PRInt32 aFlags);
85 NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
86 const nsIID& aIID, PRInt32 aFlags);
87 NS_IMETHOD AddEventListenerByType(nsIDOMEventListener *aListener,
88 const nsAString& type,
89 PRInt32 aFlags,
90 nsIDOMEventGroup* aEvtGroup);
91 NS_IMETHOD RemoveEventListenerByType(nsIDOMEventListener *aListener,
92 const nsAString& type,
93 PRInt32 aFlags,
94 nsIDOMEventGroup* aEvtGroup);
95 NS_IMETHOD AddScriptEventListener(nsISupports *aObject,
96 nsIAtom *aName,
97 const nsAString& aFunc,
98 PRUint32 aLanguage,
99 PRBool aDeferCompilation,
100 PRBool aPermitUntrustedEvents);
101 NS_IMETHOD RegisterScriptEventListener(nsIScriptContext *aContext,
102 void *aScopeObject,
103 nsISupports *aObject,
104 nsIAtom* aName);
105 NS_IMETHOD RemoveScriptEventListener(nsIAtom *aName);
106 NS_IMETHOD CompileScriptEventListener(nsIScriptContext *aContext,
107 void *aScopeObject,
108 nsISupports *aObject,
109 nsIAtom* aName, PRBool *aDidCompile);
111 NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
112 nsEvent* aEvent,
113 nsIDOMEvent** aDOMEvent,
114 nsISupports* aCurrentTarget,
115 PRUint32 aFlags,
116 nsEventStatus* aEventStatus);
118 NS_IMETHOD Disconnect();
120 NS_IMETHOD SetListenerTarget(nsISupports* aTarget);
122 NS_IMETHOD HasMutationListeners(PRBool* aListener);
124 NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
126 virtual PRBool HasUnloadListeners();
128 virtual PRUint32 MutationListenerBits();
130 virtual PRBool HasListenersFor(const nsAString& aEventName);
132 static PRUint32 GetIdentifierForEvent(nsIAtom* aEvent);
134 // nsIDOMEventTarget
135 NS_DECL_NSIDOMEVENTTARGET
137 // nsIDOM3EventTarget
138 NS_DECL_NSIDOM3EVENTTARGET
140 static void Shutdown();
142 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEventListenerManager,
143 nsIEventListenerManager)
145 protected:
146 nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
147 nsIDOMEventListener* aListener,
148 nsIDOMEvent* aDOMEvent,
149 nsISupports* aCurrentTarget,
150 PRUint32 aPhaseFlags);
151 nsresult CompileEventHandlerInternal(nsIScriptContext *aContext,
152 void *aScopeObject,
153 nsISupports *aObject,
154 nsIAtom *aName,
155 nsListenerStruct *aListenerStruct,
156 nsISupports* aCurrentTarget);
157 nsListenerStruct* FindJSEventListener(PRUint32 aEventType, nsIAtom* aTypeAtom);
158 nsresult SetJSEventListener(nsIScriptContext *aContext,
159 void *aScopeGlobal,
160 nsISupports *aObject,
161 nsIAtom* aName, PRBool aIsString,
162 PRBool aPermitUntrustedEvents);
163 nsresult AddEventListener(nsIDOMEventListener *aListener,
164 PRUint32 aType,
165 nsIAtom* aTypeAtom,
166 const EventTypeData* aTypeData,
167 PRInt32 aFlags,
168 nsIDOMEventGroup* aEvtGrp);
169 nsresult RemoveEventListener(nsIDOMEventListener *aListener,
170 PRUint32 aType,
171 nsIAtom* aUserType,
172 const EventTypeData* aTypeData,
173 PRInt32 aFlags,
174 nsIDOMEventGroup* aEvtGrp);
175 nsresult RemoveAllListeners();
176 const EventTypeData* GetTypeDataForIID(const nsIID& aIID);
177 const EventTypeData* GetTypeDataForEventName(nsIAtom* aName);
178 nsresult FixContextMenuEvent(nsPresContext* aPresContext,
179 nsISupports* aCurrentTarget,
180 nsEvent* aEvent,
181 nsIDOMEvent** aDOMEvent);
182 PRBool PrepareToUseCaretPosition(nsIWidget* aEventWidget,
183 nsIPresShell* aShell,
184 nsPoint& aTargetPt);
185 void GetCoordinatesFor(nsIDOMElement *aCurrentEl, nsPresContext *aPresContext,
186 nsIPresShell *aPresShell, nsPoint& aTargetPt);
187 nsresult GetDOM2EventGroup(nsIDOMEventGroup** aGroup);
188 PRBool ListenerCanHandle(nsListenerStruct* aLs, nsEvent* aEvent);
190 nsAutoTObserverArray<nsListenerStruct, 2> mListeners;
191 nsISupports* mTarget; //WEAK
192 PRUint32 mMayHaveMutationListeners : 1;
193 // These two member variables are used to cache the information
194 // about the last event which was handled but for which event listener manager
195 // didn't have event listeners.
196 PRUint32 mNoListenerForEvent : 31;
197 nsCOMPtr<nsIAtom> mNoListenerForEventAtom;
199 static PRUint32 mInstanceCount;
200 static jsval sAddListenerID;
203 #endif // nsEventListenerManager_h__