1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
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.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
#ifndef nsEventListenerManager_h__
40
#define nsEventListenerManager_h__
42
#include "nsIEventListenerManager.h"
45
#include "nsIDOMEventReceiver.h"
46
#include "nsIDOM3EventTarget.h"
47
#include "nsHashtable.h"
48
#include "nsIScriptContext.h"
54
nsIDOMEventListener* mListener;
57
PRUint8 mHandlerIsString;
58
PRUint8 mSubTypeCapture;
62
//These define the internal type of the EventListenerManager
63
//No listener type defined, should happen only at creation
65
//Simple indicates only a single event listener group type (i.e. mouse, key)
66
#define NS_ELM_SINGLE 1
67
//Multi indicates any number of listener group types accessed as member vars
68
#define NS_ELM_MULTI 2
69
//Hash indicates any number of listener group types accessed out of a hash
73
eEventArrayType_Mouse = 0,
74
eEventArrayType_MouseMotion = 1,
75
eEventArrayType_ContextMenu = 2,
76
eEventArrayType_Key = 3,
77
eEventArrayType_Load = 4,
78
eEventArrayType_Focus = 5,
79
eEventArrayType_Form = 6,
80
eEventArrayType_Drag = 7,
81
eEventArrayType_Paint = 8,
82
eEventArrayType_Text = 9,
83
eEventArrayType_Composition = 10,
84
eEventArrayType_XUL = 11,
85
eEventArrayType_Scroll = 12,
86
eEventArrayType_Mutation = 13,
91
//Keep this in line with event array types, not counting
93
#define EVENT_ARRAY_TYPE_LENGTH 14
96
* Event listener manager
99
class nsEventListenerManager : public nsIEventListenerManager,
100
public nsIDOMEventReceiver,
101
public nsIDOM3EventTarget
105
nsEventListenerManager();
106
virtual ~nsEventListenerManager();
111
* Sets events listeners of all types.
112
* @param an event listener
114
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
115
const nsIID& aIID, PRInt32 aFlags);
116
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
117
const nsIID& aIID, PRInt32 aFlags);
118
NS_IMETHOD AddEventListenerByType(nsIDOMEventListener *aListener,
119
const nsAString& type,
121
nsIDOMEventGroup* aEvtGroup);
122
NS_IMETHOD RemoveEventListenerByType(nsIDOMEventListener *aListener,
123
const nsAString& type,
125
nsIDOMEventGroup* aEvtGroup);
126
NS_IMETHOD AddScriptEventListener(nsISupports *aObject,
128
const nsAString& aFunc,
129
PRBool aDeferCompilation);
130
NS_IMETHOD RegisterScriptEventListener(nsIScriptContext *aContext,
131
nsISupports *aObject,
133
NS_IMETHOD RemoveScriptEventListener(nsIAtom *aName);
134
NS_IMETHOD CompileScriptEventListener(nsIScriptContext *aContext,
135
nsISupports *aObject,
136
nsIAtom* aName, PRBool *aDidCompile);
138
NS_IMETHOD CaptureEvent(PRInt32 aEventTypes);
139
NS_IMETHOD ReleaseEvent(PRInt32 aEventTypes);
141
NS_IMETHOD HandleEvent(nsIPresContext* aPresContext,
143
nsIDOMEvent** aDOMEvent,
144
nsIDOMEventTarget* aCurrentTarget,
146
nsEventStatus* aEventStatus);
148
NS_IMETHOD CreateEvent(nsIPresContext* aPresContext,
150
const nsAString& aEventType,
151
nsIDOMEvent** aDOMEvent);
153
NS_IMETHOD RemoveAllListeners(PRBool aScriptOnly);
155
NS_IMETHOD SetListenerTarget(nsISupports* aTarget);
157
NS_IMETHOD HasMutationListeners(PRBool* aListener)
159
*aListener = (GetListenersByType(eEventArrayType_Mutation, nsnull,
160
PR_FALSE) != nsnull);
164
NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
166
static nsresult GetIdentifiersForType(nsIAtom* aType,
167
EventArrayType* aArrayType,
171
NS_DECL_NSIDOMEVENTTARGET
173
// nsIDOM3EventTarget
174
NS_DECL_NSIDOM3EVENTTARGET
176
// nsIDOMEventReceiver interface
177
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
179
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
181
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
182
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
183
NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
185
static void Shutdown();
188
nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
189
nsIDOMEvent* aDOMEvent,
190
nsIDOMEventTarget* aCurrentTarget,
192
PRUint32 aPhaseFlags);
193
nsresult CompileEventHandlerInternal(nsIScriptContext *aContext,
194
nsISupports *aObject,
196
nsListenerStruct *aListenerStruct,
198
nsListenerStruct* FindJSEventListener(EventArrayType aType);
199
nsresult SetJSEventListener(nsIScriptContext *aContext,
200
nsISupports *aObject, nsIAtom* aName,
202
nsresult AddEventListener(nsIDOMEventListener *aListener,
203
EventArrayType aType,
207
nsIDOMEventGroup* aEvtGrp);
208
nsresult RemoveEventListener(nsIDOMEventListener *aListener,
209
EventArrayType aType,
213
nsIDOMEventGroup* aEvtGrp);
214
void ReleaseListeners(nsVoidArray** aListeners, PRBool aScriptOnly);
215
nsresult FlipCaptureBit(PRInt32 aEventTypes, PRBool aInitCapture);
216
nsVoidArray* GetListenersByType(EventArrayType aType, nsHashKey* aKey, PRBool aCreate);
217
EventArrayType GetTypeForIID(const nsIID& aIID);
218
nsresult FixContextMenuEvent(nsIPresContext* aPresContext,
219
nsIDOMEventTarget* aCurrentTarget,
221
nsIDOMEvent** aDOMEvent);
222
void GetCoordinatesFor(nsIDOMElement *aCurrentEl, nsIPresContext *aPresContext,
223
nsIPresShell *aPresShell, nsPoint& aTargetPt);
224
nsresult GetDOM2EventGroup(nsIDOMEventGroup** aGroup);
226
PRUint8 mManagerType;
227
PRPackedBool mListenersRemoved;
229
EventArrayType mSingleListenerType;
230
nsVoidArray* mSingleListener;
231
nsVoidArray* mMultiListeners;
232
nsHashtable* mGenericListeners;
233
static PRUint32 mInstanceCount;
235
nsISupports* mTarget; //WEAK
237
static jsval sAddListenerID;
241
//Set of defines for distinguishing event handlers within listener groupings
242
//XXX Current usage allows no more than 7 types per listener grouping
244
#define NS_EVENT_BITS_NONE 0x00
246
//nsIDOMMouseListener
247
#define NS_EVENT_BITS_MOUSE_NONE 0x00
248
#define NS_EVENT_BITS_MOUSE_MOUSEDOWN 0x01
249
#define NS_EVENT_BITS_MOUSE_MOUSEUP 0x02
250
#define NS_EVENT_BITS_MOUSE_CLICK 0x04
251
#define NS_EVENT_BITS_MOUSE_DBLCLICK 0x08
252
#define NS_EVENT_BITS_MOUSE_MOUSEOVER 0x10
253
#define NS_EVENT_BITS_MOUSE_MOUSEOUT 0x20
255
//nsIDOMMouseMotionListener
256
#define NS_EVENT_BITS_MOUSEMOTION_NONE 0x00
257
#define NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE 0x01
258
#define NS_EVENT_BITS_MOUSEMOTION_DRAGMOVE 0x02
260
//nsIDOMContextMenuListener
261
#define NS_EVENT_BITS_CONTEXTMENU_NONE 0x00
262
#define NS_EVENT_BITS_CONTEXTMENU 0x01
265
#define NS_EVENT_BITS_KEY_NONE 0x00
266
#define NS_EVENT_BITS_KEY_KEYDOWN 0x01
267
#define NS_EVENT_BITS_KEY_KEYUP 0x02
268
#define NS_EVENT_BITS_KEY_KEYPRESS 0x04
271
#define NS_EVENT_BITS_TEXT_NONE 0x00
272
#define NS_EVENT_BITS_TEXT_TEXT 0x01
274
//nsIDOMCompositionListener
275
#define NS_EVENT_BITS_COMPOSITION_NONE 0x00
276
#define NS_EVENT_BITS_COMPOSITION_START 0x01
277
#define NS_EVENT_BITS_COMPOSITION_END 0x02
278
#define NS_EVENT_BITS_COMPOSITION_QUERY 0x04
279
#define NS_EVENT_BITS_COMPOSITION_RECONVERSION 0x08
281
//nsIDOMFocusListener
282
#define NS_EVENT_BITS_FOCUS_NONE 0x00
283
#define NS_EVENT_BITS_FOCUS_FOCUS 0x01
284
#define NS_EVENT_BITS_FOCUS_BLUR 0x02
287
#define NS_EVENT_BITS_FORM_NONE 0x00
288
#define NS_EVENT_BITS_FORM_SUBMIT 0x01
289
#define NS_EVENT_BITS_FORM_RESET 0x02
290
#define NS_EVENT_BITS_FORM_CHANGE 0x04
291
#define NS_EVENT_BITS_FORM_SELECT 0x08
292
#define NS_EVENT_BITS_FORM_INPUT 0x10
295
#define NS_EVENT_BITS_LOAD_NONE 0x00
296
#define NS_EVENT_BITS_LOAD_LOAD 0x01
297
#define NS_EVENT_BITS_LOAD_UNLOAD 0x02
298
#define NS_EVENT_BITS_LOAD_ABORT 0x04
299
#define NS_EVENT_BITS_LOAD_ERROR 0x08
300
#define NS_EVENT_BITS_LOAD_BEFORE_UNLOAD 0x10
303
#define NS_EVENT_BITS_XUL_NONE 0x00
304
#define NS_EVENT_BITS_XUL_POPUP_SHOWING 0x01
305
#define NS_EVENT_BITS_XUL_CLOSE 0x02
306
#define NS_EVENT_BITS_XUL_POPUP_HIDING 0x04
307
#define NS_EVENT_BITS_XUL_COMMAND 0x08
308
#define NS_EVENT_BITS_XUL_BROADCAST 0x10
309
#define NS_EVENT_BITS_XUL_COMMAND_UPDATE 0x20
310
#define NS_EVENT_BITS_XUL_POPUP_SHOWN 0x40
311
#define NS_EVENT_BITS_XUL_POPUP_HIDDEN 0x80
314
#define NS_EVENT_BITS_SCROLLPORT_NONE 0x00
315
#define NS_EVENT_BITS_SCROLLPORT_OVERFLOW 0x01
316
#define NS_EVENT_BITS_SCROLLPORT_UNDERFLOW 0x02
317
#define NS_EVENT_BITS_SCROLLPORT_OVERFLOWCHANGED 0x04
320
#define NS_EVENT_BITS_DRAG_NONE 0x00
321
#define NS_EVENT_BITS_DRAG_ENTER 0x01
322
#define NS_EVENT_BITS_DRAG_OVER 0x02
323
#define NS_EVENT_BITS_DRAG_EXIT 0x04
324
#define NS_EVENT_BITS_DRAG_DROP 0x08
325
#define NS_EVENT_BITS_DRAG_GESTURE 0x10
327
//nsIDOMPaintListener
328
#define NS_EVENT_BITS_PAINT_NONE 0x00
329
#define NS_EVENT_BITS_PAINT_PAINT 0x01
330
#define NS_EVENT_BITS_PAINT_RESIZE 0x02
331
#define NS_EVENT_BITS_PAINT_SCROLL 0x04
333
//nsIDOMMutationListener
334
// These bits are found in nsMutationEvent.h.
336
//nsIDOMContextMenuListener
337
#define NS_EVENT_BITS_CONTEXT_NONE 0x00
338
#define NS_EVENT_BITS_CONTEXT_MENU 0x01
341
#endif // nsEventListenerManager_h__