Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / content / events / public / nsEventDispatcher.h
blob982a77a1493f7ff5a34f3e1bf60ab93ebc3a96e4
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 = nsEventStatus_eIgnore)
133 : nsEventChainVisitor(aPresContext, aEvent, aDOMEvent, aEventStatus),
134 mCanHandle(PR_TRUE), mForceContentDispatch(PR_FALSE),
135 mRelatedTargetIsInAnon(PR_FALSE), mWantsWillHandleEvent(PR_FALSE),
136 mParentTarget(nsnull), mEventTargetAtParent(nsnull) {}
138 void Reset() {
139 mItemFlags = 0;
140 mItemData = nsnull;
141 mCanHandle = PR_TRUE;
142 mForceContentDispatch = PR_FALSE;
143 mWantsWillHandleEvent = PR_FALSE;
144 mParentTarget = nsnull;
145 mEventTargetAtParent = nsnull;
149 * Member that must be set in PreHandleEvent by event targets. If set to false,
150 * indicates that this event target will not be handling the event and
151 * construction of the event target chain is complete. The target that sets
152 * mCanHandle to false is NOT included in the event target chain.
154 PRPackedBool mCanHandle;
157 * If mForceContentDispatch is set to PR_TRUE,
158 * content dispatching is not disabled for this event target.
159 * FIXME! This is here for backward compatibility. Bug 329119
161 PRPackedBool mForceContentDispatch;
164 * PR_TRUE if it is known that related target is or is a descendant of an
165 * element which is anonymous for events.
167 PRPackedBool mRelatedTargetIsInAnon;
171 * Whether or not nsPIDOMEventTarget::WillHandleEvent will be
172 * called. Default is PR_FALSE;
174 PRPackedBool mWantsWillHandleEvent;
177 * Parent item in the event target chain.
179 nsPIDOMEventTarget* mParentTarget;
182 * If the event needs to be retargeted, this is the event target,
183 * which should be used when the event is handled at mParentTarget.
185 nsPIDOMEventTarget* mEventTargetAtParent;
188 class nsEventChainPostVisitor : public nsEventChainVisitor {
189 public:
190 nsEventChainPostVisitor(nsEventChainVisitor& aOther)
191 : nsEventChainVisitor(aOther.mPresContext, aOther.mEvent, aOther.mDOMEvent,
192 aOther.mEventStatus)
197 * If an nsDispatchingCallback object is passed to Dispatch,
198 * its HandleEvent method is called after handling the default event group,
199 * before handling the system event group.
200 * This is used in nsPresShell.
202 class NS_STACK_CLASS nsDispatchingCallback {
203 public:
204 virtual void HandleEvent(nsEventChainPostVisitor& aVisitor) = 0;
208 * The generic class for event dispatching.
209 * Must not be used outside Gecko!
211 class nsEventDispatcher
213 public:
215 * aTarget should QI to nsPIDOMEventTarget.
216 * If the target of aEvent is set before calling this method, the target of
217 * aEvent is used as the target (unless there is event
218 * retargeting) and the originalTarget of the DOM Event.
219 * aTarget is always used as the starting point for constructing the event
220 * target chain, no matter what the value of aEvent->target is.
221 * In other words, aEvent->target is only a property of the event and it has
222 * nothing to do with the construction of the event target chain.
223 * Neither aTarget nor aEvent is allowed to be nsnull.
224 * @note Use this method when dispatching an nsEvent.
226 static nsresult Dispatch(nsISupports* aTarget,
227 nsPresContext* aPresContext,
228 nsEvent* aEvent,
229 nsIDOMEvent* aDOMEvent = nsnull,
230 nsEventStatus* aEventStatus = nsnull,
231 nsDispatchingCallback* aCallback = nsnull);
234 * Dispatches an event.
235 * If aDOMEvent is not nsnull, it is used for dispatching
236 * (aEvent can then be nsnull) and (if aDOMEvent is not |trusted| already),
237 * the |trusted| flag is set based on the UniversalBrowserWrite capability.
238 * Otherwise this works like nsEventDispatcher::Dispatch.
239 * @note Use this method when dispatching nsIDOMEvent.
241 static nsresult DispatchDOMEvent(nsISupports* aTarget,
242 nsEvent* aEvent, nsIDOMEvent* aDOMEvent,
243 nsPresContext* aPresContext,
244 nsEventStatus* aEventStatus);
247 * Creates a DOM Event.
249 static nsresult CreateEvent(nsPresContext* aPresContext,
250 nsEvent* aEvent,
251 const nsAString& aEventType,
252 nsIDOMEvent** aDOMEvent);
256 #endif
257 #endif