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
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.
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"
44 #include "nsIDOMEventTarget.h"
45 #include "nsIDOM3EventTarget.h"
46 #include "nsHashtable.h"
47 #include "nsIScriptContext.h"
48 #include "nsCycleCollectionParticipant.h"
55 class nsEventTargetChainItem
;
58 nsRefPtr
<nsIDOMEventListener
> mListener
;
60 nsCOMPtr
<nsIAtom
> mTypeAtom
;
63 PRBool mHandlerIsString
;
64 const EventTypeData
* mTypeData
;
68 * Event listener manager
71 class nsEventListenerManager
: public nsIEventListenerManager
,
72 public nsIDOMEventTarget
,
73 public nsIDOM3EventTarget
77 nsEventListenerManager();
78 virtual ~nsEventListenerManager();
80 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
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
,
93 nsIDOMEventGroup
* aEvtGroup
);
94 NS_IMETHOD
RemoveEventListenerByType(nsIDOMEventListener
*aListener
,
95 const nsAString
& type
,
97 nsIDOMEventGroup
* aEvtGroup
);
98 NS_IMETHOD
AddScriptEventListener(nsISupports
*aObject
,
100 const nsAString
& aFunc
,
102 PRBool aDeferCompilation
,
103 PRBool aPermitUntrustedEvents
);
104 NS_IMETHOD
RegisterScriptEventListener(nsIScriptContext
*aContext
,
106 nsISupports
*aObject
,
108 NS_IMETHOD
RemoveScriptEventListener(nsIAtom
*aName
);
109 NS_IMETHOD
CompileScriptEventListener(nsIScriptContext
*aContext
,
111 nsISupports
*aObject
,
112 nsIAtom
* aName
, PRBool
*aDidCompile
);
114 NS_IMETHOD
HandleEvent(nsPresContext
* aPresContext
,
116 nsIDOMEvent
** aDOMEvent
,
117 nsPIDOMEventTarget
* aCurrentTarget
,
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
);
140 NS_DECL_NSIDOMEVENTTARGET
142 // nsIDOM3EventTarget
143 NS_DECL_NSIDOM3EVENTTARGET
145 static void Shutdown();
147 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEventListenerManager
,
148 nsIEventListenerManager
)
151 nsresult
HandleEventSubType(nsListenerStruct
* aListenerStruct
,
152 nsIDOMEventListener
* aListener
,
153 nsIDOMEvent
* aDOMEvent
,
154 nsPIDOMEventTarget
* aCurrentTarget
,
155 PRUint32 aPhaseFlags
);
156 nsresult
CompileEventHandlerInternal(nsIScriptContext
*aContext
,
158 nsISupports
*aObject
,
160 nsListenerStruct
*aListenerStruct
,
161 nsISupports
* aCurrentTarget
);
162 nsListenerStruct
* FindJSEventListener(PRUint32 aEventType
, nsIAtom
* aTypeAtom
);
163 nsresult
SetJSEventListener(nsIScriptContext
*aContext
,
165 nsISupports
*aObject
,
166 nsIAtom
* aName
, PRBool aIsString
,
167 PRBool aPermitUntrustedEvents
);
168 nsresult
AddEventListener(nsIDOMEventListener
*aListener
,
171 const EventTypeData
* aTypeData
,
173 nsIDOMEventGroup
* aEvtGrp
);
174 nsresult
RemoveEventListener(nsIDOMEventListener
*aListener
,
177 const EventTypeData
* aTypeData
,
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
,
186 nsIDOMEvent
** aDOMEvent
);
187 PRBool
PrepareToUseCaretPosition(nsIWidget
* aEventWidget
,
188 nsIPresShell
* aShell
,
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__