Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / events / public / nsEventDispatcher.h
blob6647d1a3bc5f998239cfefd8f9c84bddc5872bb7
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 * Olli Pettay (Olli.Pettay@helsinki.fi)
19 * Portions created by the Initial Developer are Copyright (C) 2006
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 #ifdef MOZILLA_INTERNAL_API
39 #ifndef nsEventDispatcher_h___
40 #define nsEventDispatcher_h___
42 #include "nsGUIEvent.h"
44 class nsIContent;
45 class nsIDocument;
46 class nsPresContext;
47 class nsPIDOMEventTarget;
48 class nsIScriptGlobalObject;
49 class nsEventTargetChainItem;
52 /**
53 * About event dispatching:
54 * When either nsEventDispatcher::Dispatch or
55 * nsEventDispatcher::DispatchDOMEvent is called an event target chain is
56 * created. nsEventDispatcher creates the chain by calling PreHandleEvent
57 * on each event target and the creation continues until either the mCanHandle
58 * member of the nsEventChainPreVisitor object is PR_FALSE or the mParentTarget
59 * does not point to a new target. The event target chain is created in the
60 * heap.
62 * If the event needs retargeting, mEventTargetAtParent must be set in
63 * PreHandleEvent.
65 * The capture, target and bubble phases of the event dispatch are handled
66 * by iterating through the event target chain. Iteration happens twice,
67 * first for the default event group and then for the system event group.
68 * While dispatching the event for the system event group PostHandleEvent
69 * is called right after calling event listener for the current event target.
72 class nsEventChainVisitor {
73 public:
74 nsEventChainVisitor(nsPresContext* aPresContext,
75 nsEvent* aEvent,
76 nsIDOMEvent* aDOMEvent,
77 nsEventStatus aEventStatus = nsEventStatus_eIgnore)
78 : mPresContext(aPresContext), mEvent(aEvent), mDOMEvent(aDOMEvent),
79 mEventStatus(aEventStatus), mItemFlags(0)
82 /**
83 * The prescontext, possibly nsnull.
85 nsPresContext* const mPresContext;
87 /**
88 * The nsEvent which is being dispatched. Never nsnull.
90 nsEvent* const mEvent;
92 /**
93 * The DOM Event assiciated with the mEvent. Possibly nsnull if a DOM Event
94 * is not (yet) created.
96 nsIDOMEvent* mDOMEvent;
98 /**
99 * The status of the event.
100 * @see nsEventStatus.h
102 nsEventStatus mEventStatus;
105 * Bits for items in the event target chain.
106 * Set in PreHandleEvent() and used in PostHandleEvent().
108 * @note These bits are different for each item in the event target chain.
109 * It is up to the Pre/PostHandleEvent implementation to decide how to
110 * use these bits.
112 * @note Using PRUint16 because that is used also in nsEventTargetChainItem.
114 PRUint16 mItemFlags;
117 * Data for items in the event target chain.
118 * Set in PreHandleEvent() and used in PostHandleEvent().
120 * @note This data is different for each item in the event target chain.
121 * It is up to the Pre/PostHandleEvent implementation to decide how to
122 * use this.
124 nsCOMPtr<nsISupports> mItemData;
127 class nsEventChainPreVisitor : public nsEventChainVisitor {
128 public:
129 nsEventChainPreVisitor(nsPresContext* aPresContext,
130 nsEvent* aEvent,
131 nsIDOMEvent* aDOMEvent,
132 nsEventStatus aEventStatus,
133 PRBool aIsInAnon)
134 : nsEventChainVisitor(aPresContext, aEvent, aDOMEvent, aEventStatus),
135 mCanHandle(PR_TRUE), mForceContentDispatch(PR_FALSE),
136 mRelatedTargetIsInAnon(PR_FALSE), mOriginalTargetIsInAnon(aIsInAnon),
137 mWantsWillHandleEvent(PR_FALSE), mParentTarget(nsnull),
138 mEventTargetAtParent(nsnull) {}
140 void Reset() {
141 mItemFlags = 0;
142 mItemData = nsnull;
143 mCanHandle = PR_TRUE;
144 mForceContentDispatch = PR_FALSE;
145 mWantsWillHandleEvent = PR_FALSE;
146 mParentTarget = nsnull;
147 mEventTargetAtParent = nsnull;
151 * Member that must be set in PreHandleEvent by event targets. If set to false,
152 * indicates that this event target will not be handling the event and
153 * construction of the event target chain is complete. The target that sets
154 * mCanHandle to false is NOT included in the event target chain.
156 PRPackedBool mCanHandle;
159 * If mForceContentDispatch is set to PR_TRUE,
160 * content dispatching is not disabled for this event target.
161 * FIXME! This is here for backward compatibility. Bug 329119
163 PRPackedBool mForceContentDispatch;
166 * PR_TRUE if it is known that related target is or is a descendant of an
167 * element which is anonymous for events.
169 PRPackedBool mRelatedTargetIsInAnon;
172 * PR_TRUE if the original target of the event is inside anonymous content.
173 * This is set before calling PreHandleEvent on event targets.
175 PRPackedBool mOriginalTargetIsInAnon;
178 * Whether or not nsPIDOMEventTarget::WillHandleEvent will be
179 * called. Default is PR_FALSE;
181 PRPackedBool mWantsWillHandleEvent;
184 * Parent item in the event target chain.
186 nsPIDOMEventTarget* mParentTarget;
189 * If the event needs to be retargeted, this is the event target,
190 * which should be used when the event is handled at mParentTarget.
192 nsPIDOMEventTarget* mEventTargetAtParent;
195 class nsEventChainPostVisitor : public nsEventChainVisitor {
196 public:
197 nsEventChainPostVisitor(nsEventChainVisitor& aOther)
198 : nsEventChainVisitor(aOther.mPresContext, aOther.mEvent, aOther.mDOMEvent,
199 aOther.mEventStatus)
204 * If an nsDispatchingCallback object is passed to Dispatch,
205 * its HandleEvent method is called after handling the default event group,
206 * before handling the system event group.
207 * This is used in nsPresShell.
209 class NS_STACK_CLASS nsDispatchingCallback {
210 public:
211 virtual void HandleEvent(nsEventChainPostVisitor& aVisitor) = 0;
215 * The generic class for event dispatching.
216 * Must not be used outside Gecko!
218 class nsEventDispatcher
220 public:
222 * aTarget should QI to nsPIDOMEventTarget.
223 * If the target of aEvent is set before calling this method, the target of
224 * aEvent is used as the target (unless there is event
225 * retargeting) and the originalTarget of the DOM Event.
226 * aTarget is always used as the starting point for constructing the event
227 * target chain, no matter what the value of aEvent->target is.
228 * In other words, aEvent->target is only a property of the event and it has
229 * nothing to do with the construction of the event target chain.
230 * Neither aTarget nor aEvent is allowed to be nsnull.
231 * @note Use this method when dispatching an nsEvent.
233 static nsresult Dispatch(nsISupports* aTarget,
234 nsPresContext* aPresContext,
235 nsEvent* aEvent,
236 nsIDOMEvent* aDOMEvent = nsnull,
237 nsEventStatus* aEventStatus = nsnull,
238 nsDispatchingCallback* aCallback = nsnull);
241 * Dispatches an event.
242 * If aDOMEvent is not nsnull, it is used for dispatching
243 * (aEvent can then be nsnull) and (if aDOMEvent is not |trusted| already),
244 * the |trusted| flag is set based on the UniversalBrowserWrite capability.
245 * Otherwise this works like nsEventDispatcher::Dispatch.
246 * @note Use this method when dispatching nsIDOMEvent.
248 static nsresult DispatchDOMEvent(nsISupports* aTarget,
249 nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
250 nsPresContext* aPresContext,
251 nsEventStatus* aEventStatus);
254 * Creates a DOM Event.
256 static nsresult CreateEvent(nsPresContext* aPresContext,
257 nsEvent* aEvent,
258 const nsAString& aEventType,
259 nsIDOMEvent** aDOMEvent);
263 #endif
264 #endif