~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/content/events/src/nsEventListenerManager.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 *
 
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.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#ifndef nsEventListenerManager_h__
 
40
#define nsEventListenerManager_h__
 
41
 
 
42
#include "nsIEventListenerManager.h"
 
43
#include "jsapi.h"
 
44
#include "nsCOMPtr.h"
 
45
#include "nsIDOMEventReceiver.h"
 
46
#include "nsIDOM3EventTarget.h"
 
47
#include "nsHashtable.h"
 
48
#include "nsIScriptContext.h"
 
49
 
 
50
class nsIDOMEvent;
 
51
class nsIAtom;
 
52
 
 
53
typedef struct {
 
54
  nsIDOMEventListener* mListener;
 
55
  PRUint8 mFlags;
 
56
  PRUint8 mSubType;
 
57
  PRUint8 mHandlerIsString;
 
58
  PRUint8 mSubTypeCapture;
 
59
  PRUint16 mGroupFlags;
 
60
} nsListenerStruct;
 
61
 
 
62
//These define the internal type of the EventListenerManager
 
63
//No listener type defined, should happen only at creation
 
64
#define NS_ELM_NONE   0
 
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
 
70
#define NS_ELM_HASH   4
 
71
 
 
72
enum EventArrayType {
 
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,
 
87
  eEventArrayType_Hash,
 
88
  eEventArrayType_None
 
89
};
 
90
 
 
91
//Keep this in line with event array types, not counting
 
92
//types HASH and NONE
 
93
#define EVENT_ARRAY_TYPE_LENGTH 14
 
94
 
 
95
/*
 
96
 * Event listener manager
 
97
 */
 
98
 
 
99
class nsEventListenerManager : public nsIEventListenerManager,
 
100
                               public nsIDOMEventReceiver,
 
101
                               public nsIDOM3EventTarget
 
102
{
 
103
 
 
104
public:
 
105
  nsEventListenerManager();
 
106
  virtual ~nsEventListenerManager();
 
107
 
 
108
  NS_DECL_ISUPPORTS
 
109
 
 
110
  /**
 
111
  * Sets events listeners of all types. 
 
112
  * @param an event listener
 
113
  */
 
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,
 
120
                                    PRInt32 aFlags,
 
121
                                    nsIDOMEventGroup* aEvtGroup);
 
122
  NS_IMETHOD RemoveEventListenerByType(nsIDOMEventListener *aListener,
 
123
                                       const nsAString& type,
 
124
                                       PRInt32 aFlags,
 
125
                                       nsIDOMEventGroup* aEvtGroup);
 
126
  NS_IMETHOD AddScriptEventListener(nsISupports *aObject,
 
127
                                    nsIAtom *aName,
 
128
                                    const nsAString& aFunc,
 
129
                                    PRBool aDeferCompilation); 
 
130
  NS_IMETHOD RegisterScriptEventListener(nsIScriptContext *aContext,
 
131
                                         nsISupports *aObject,
 
132
                                         nsIAtom* aName);
 
133
  NS_IMETHOD RemoveScriptEventListener(nsIAtom *aName);
 
134
  NS_IMETHOD CompileScriptEventListener(nsIScriptContext *aContext,
 
135
                                        nsISupports *aObject,
 
136
                                        nsIAtom* aName, PRBool *aDidCompile);
 
137
 
 
138
  NS_IMETHOD CaptureEvent(PRInt32 aEventTypes);
 
139
  NS_IMETHOD ReleaseEvent(PRInt32 aEventTypes);
 
140
 
 
141
  NS_IMETHOD HandleEvent(nsIPresContext* aPresContext, 
 
142
                         nsEvent* aEvent, 
 
143
                         nsIDOMEvent** aDOMEvent,
 
144
                         nsIDOMEventTarget* aCurrentTarget,
 
145
                         PRUint32 aFlags,
 
146
                         nsEventStatus* aEventStatus);
 
147
 
 
148
  NS_IMETHOD CreateEvent(nsIPresContext* aPresContext, 
 
149
                         nsEvent* aEvent,
 
150
                         const nsAString& aEventType,
 
151
                         nsIDOMEvent** aDOMEvent);
 
152
 
 
153
  NS_IMETHOD RemoveAllListeners(PRBool aScriptOnly);
 
154
 
 
155
  NS_IMETHOD SetListenerTarget(nsISupports* aTarget);
 
156
 
 
157
  NS_IMETHOD HasMutationListeners(PRBool* aListener)
 
158
  {
 
159
    *aListener = (GetListenersByType(eEventArrayType_Mutation, nsnull,
 
160
                                     PR_FALSE) != nsnull);
 
161
    return NS_OK;
 
162
  }
 
163
 
 
164
  NS_IMETHOD GetSystemEventGroupLM(nsIDOMEventGroup** aGroup);
 
165
 
 
166
  static nsresult GetIdentifiersForType(nsIAtom* aType,
 
167
                                        EventArrayType* aArrayType,
 
168
                                        PRInt32* aSubType);
 
169
 
 
170
  // nsIDOMEventTarget
 
171
  NS_DECL_NSIDOMEVENTTARGET
 
172
 
 
173
  // nsIDOM3EventTarget
 
174
  NS_DECL_NSIDOM3EVENTTARGET
 
175
 
 
176
  // nsIDOMEventReceiver interface
 
177
  NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener,
 
178
                                   const nsIID& aIID);
 
179
  NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener,
 
180
                                      const nsIID& aIID);
 
181
  NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
 
182
  NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
 
183
  NS_IMETHOD GetSystemEventGroup(nsIDOMEventGroup** aGroup);
 
184
 
 
185
  static void Shutdown();
 
186
 
 
187
protected:
 
188
  nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
 
189
                              nsIDOMEvent* aDOMEvent,
 
190
                              nsIDOMEventTarget* aCurrentTarget,
 
191
                              PRUint32 aSubType,
 
192
                              PRUint32 aPhaseFlags);
 
193
  nsresult CompileEventHandlerInternal(nsIScriptContext *aContext,
 
194
                                       nsISupports *aObject,
 
195
                                       nsIAtom *aName,
 
196
                                       nsListenerStruct *aListenerStruct,
 
197
                                       PRUint32 aSubType);
 
198
  nsListenerStruct* FindJSEventListener(EventArrayType aType);
 
199
  nsresult SetJSEventListener(nsIScriptContext *aContext,
 
200
                              nsISupports *aObject, nsIAtom* aName,
 
201
                              PRBool aIsString);
 
202
  nsresult AddEventListener(nsIDOMEventListener *aListener, 
 
203
                            EventArrayType aType, 
 
204
                            PRInt32 aSubType,
 
205
                            nsHashKey* aKey,
 
206
                            PRInt32 aFlags,
 
207
                            nsIDOMEventGroup* aEvtGrp);
 
208
  nsresult RemoveEventListener(nsIDOMEventListener *aListener,
 
209
                               EventArrayType aType,
 
210
                               PRInt32 aSubType,
 
211
                               nsHashKey* aKey,
 
212
                               PRInt32 aFlags,
 
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,
 
220
                               nsEvent* aEvent,
 
221
                               nsIDOMEvent** aDOMEvent);
 
222
  void GetCoordinatesFor(nsIDOMElement *aCurrentEl, nsIPresContext *aPresContext,
 
223
                         nsIPresShell *aPresShell, nsPoint& aTargetPt);
 
224
  nsresult GetDOM2EventGroup(nsIDOMEventGroup** aGroup);
 
225
 
 
226
  PRUint8 mManagerType;
 
227
  PRPackedBool mListenersRemoved;
 
228
 
 
229
  EventArrayType mSingleListenerType;
 
230
  nsVoidArray* mSingleListener;
 
231
  nsVoidArray* mMultiListeners;
 
232
  nsHashtable* mGenericListeners;
 
233
  static PRUint32 mInstanceCount;
 
234
 
 
235
  nsISupports* mTarget;  //WEAK
 
236
 
 
237
  static jsval sAddListenerID;
 
238
};
 
239
 
 
240
 
 
241
//Set of defines for distinguishing event handlers within listener groupings
 
242
//XXX Current usage allows no more than 7 types per listener grouping
 
243
 
 
244
#define NS_EVENT_BITS_NONE    0x00
 
245
 
 
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
 
254
 
 
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
 
259
 
 
260
//nsIDOMContextMenuListener
 
261
#define NS_EVENT_BITS_CONTEXTMENU_NONE   0x00
 
262
#define NS_EVENT_BITS_CONTEXTMENU        0x01
 
263
 
 
264
//nsIDOMKeyListener
 
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
 
269
 
 
270
//nsIDOMTextListener
 
271
#define NS_EVENT_BITS_TEXT_NONE      0x00
 
272
#define NS_EVENT_BITS_TEXT_TEXT      0x01
 
273
 
 
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
 
280
 
 
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
 
285
 
 
286
//nsIDOMFormListener
 
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
 
293
 
 
294
//nsIDOMLoadListener
 
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
 
301
 
 
302
//nsIDOMXULListener
 
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
 
312
 
 
313
//nsIScrollListener
 
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
 
318
 
 
319
//nsIDOMDragListener
 
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
 
326
 
 
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
 
332
 
 
333
//nsIDOMMutationListener
 
334
// These bits are found in nsMutationEvent.h.
 
335
 
 
336
//nsIDOMContextMenuListener
 
337
#define NS_EVENT_BITS_CONTEXT_NONE  0x00
 
338
#define NS_EVENT_BITS_CONTEXT_MENU  0x01
 
339
 
 
340
 
 
341
#endif // nsEventListenerManager_h__