dom/interfaces/events/nsIDOMEventTarget.idl

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "domstubs.idl"
michael@0 7
michael@0 8 %{C++
michael@0 9 #include "mozilla/EventForwards.h"
michael@0 10 #include "mozilla/dom/Nullable.h"
michael@0 11 #include "js/TypeDecls.h"
michael@0 12
michael@0 13 using mozilla::dom::Nullable;
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 class EventChainPostVisitor;
michael@0 17 class EventChainPreVisitor;
michael@0 18 class EventListenerManager;
michael@0 19 namespace dom {
michael@0 20 class EventTarget;
michael@0 21 } // namespace dom
michael@0 22 } // namespace mozilla
michael@0 23
michael@0 24 class nsPresContext;
michael@0 25 %}
michael@0 26
michael@0 27 /**
michael@0 28 * The nsIDOMEventTarget interface is the interface implemented by all
michael@0 29 * event targets in the Document Object Model.
michael@0 30 *
michael@0 31 * For more information on this interface please see
michael@0 32 * http://www.w3.org/TR/DOM-Level-2-Events/
michael@0 33 */
michael@0 34
michael@0 35 [ptr] native WidgetEventPtr(mozilla::WidgetEvent);
michael@0 36 [ptr] native nsPresContextPtr(nsPresContext);
michael@0 37 [ptr] native nsEventStatusPtr(nsEventStatus);
michael@0 38 [ptr] native JSContextPtr(JSContext);
michael@0 39 [ref] native EventChainPostVisitorRef(mozilla::EventChainPostVisitor);
michael@0 40 [ref] native EventChainPreVisitorRef(mozilla::EventChainPreVisitor);
michael@0 41 [ptr] native EventListenerManagerPtr(mozilla::EventListenerManager);
michael@0 42 [ptr] native EventTargetPtr(mozilla::dom::EventTarget);
michael@0 43
michael@0 44 interface nsIScriptContext;
michael@0 45 interface nsIDOMEventListener;
michael@0 46 interface nsIDOMEvent;
michael@0 47
michael@0 48 [scriptable, builtinclass, uuid(b128448c-7b53-4769-92cb-cd6eafee676c)]
michael@0 49 interface nsIDOMEventTarget : nsISupports
michael@0 50 {
michael@0 51 /**
michael@0 52 * This method allows the registration of event listeners on the event target.
michael@0 53 * If an EventListener is added to an EventTarget while it is processing an
michael@0 54 * event, it will not be triggered by the current actions but may be
michael@0 55 * triggered during a later stage of event flow, such as the bubbling phase.
michael@0 56 *
michael@0 57 * If multiple identical EventListeners are registered on the same
michael@0 58 * EventTarget with the same parameters the duplicate instances are
michael@0 59 * discarded. They do not cause the EventListener to be called twice
michael@0 60 * and since they are discarded they do not need to be removed with the
michael@0 61 * removeEventListener method.
michael@0 62 *
michael@0 63 * @param type The event type for which the user is registering
michael@0 64 * @param listener The listener parameter takes an interface
michael@0 65 * implemented by the user which contains the methods
michael@0 66 * to be called when the event occurs.
michael@0 67 * @param useCapture If true, useCapture indicates that the user
michael@0 68 * wishes to initiate capture. After initiating
michael@0 69 * capture, all events of the specified type will be
michael@0 70 * dispatched to the registered EventListener before
michael@0 71 * being dispatched to any EventTargets beneath them
michael@0 72 * in the tree. Events which are bubbling upward
michael@0 73 * through the tree will not trigger an
michael@0 74 * EventListener designated to use capture.
michael@0 75 * @param wantsUntrusted If false, the listener will not receive any
michael@0 76 * untrusted events (see above), if true, the
michael@0 77 * listener will receive events whether or not
michael@0 78 * they're trusted
michael@0 79 */
michael@0 80 [optional_argc] void addEventListener(in DOMString type,
michael@0 81 in nsIDOMEventListener listener,
michael@0 82 [optional] in boolean useCapture,
michael@0 83 [optional] in boolean wantsUntrusted);
michael@0 84
michael@0 85 /**
michael@0 86 * addSystemEventListener() adds an event listener of aType to the system
michael@0 87 * group. Typically, core code should use system group for listening to
michael@0 88 * content (i.e., non-chrome) element's events. If core code uses
michael@0 89 * nsIDOMEventTarget::AddEventListener for a content node, it means
michael@0 90 * that the listener cannot listen the event when web content calls
michael@0 91 * stopPropagation() of the event.
michael@0 92 *
michael@0 93 * @param aType An event name you're going to handle.
michael@0 94 * @param aListener An event listener.
michael@0 95 * @param aUseCapture TRUE if you want to listen the event in capturing
michael@0 96 * phase. Otherwise, FALSE.
michael@0 97 * @param aWantsUntrusted TRUE if you want to handle untrusted events.
michael@0 98 * Otherwise, FALSE.
michael@0 99 * @return NS_OK if succeed. Otherwise, NS_ERROR_*.
michael@0 100 */
michael@0 101 [noscript, optional_argc] void addSystemEventListener(
michael@0 102 in DOMString type,
michael@0 103 in nsIDOMEventListener listener,
michael@0 104 [optional] in boolean aUseCapture,
michael@0 105 [optional] in boolean aWantsUntrusted);
michael@0 106
michael@0 107 %{C++
michael@0 108 // non-virtual so it won't affect the vtable
michael@0 109 nsresult AddEventListener(const nsAString& aType,
michael@0 110 nsIDOMEventListener* aListener,
michael@0 111 bool aUseCapture)
michael@0 112 {
michael@0 113 return AddEventListener(aType, aListener, aUseCapture, false, 1);
michael@0 114 }
michael@0 115 // non-virtual so it won't affect the vtable
michael@0 116 nsresult AddEventListener(const nsAString& aType,
michael@0 117 nsIDOMEventListener* aListener,
michael@0 118 bool aUseCapture,
michael@0 119 bool aWantsUntrusted)
michael@0 120 {
michael@0 121 return AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted, 2);
michael@0 122 }
michael@0 123 // non-virtual so it won't affect the vtable
michael@0 124 nsresult AddSystemEventListener(const nsAString& aType,
michael@0 125 nsIDOMEventListener* aListener,
michael@0 126 bool aUseCapture)
michael@0 127 {
michael@0 128 return AddSystemEventListener(aType, aListener, aUseCapture, false, 1);
michael@0 129 }
michael@0 130 // non-virtual so it won't affect the vtable
michael@0 131 nsresult AddSystemEventListener(const nsAString& aType,
michael@0 132 nsIDOMEventListener* aListener,
michael@0 133 bool aUseCapture,
michael@0 134 bool aWantsUntrusted)
michael@0 135 {
michael@0 136 return AddSystemEventListener(aType, aListener, aUseCapture,
michael@0 137 aWantsUntrusted, 2);
michael@0 138 }
michael@0 139 %}
michael@0 140
michael@0 141 /**
michael@0 142 * This method allows the removal of event listeners from the event
michael@0 143 * target. If an EventListener is removed from an EventTarget while it
michael@0 144 * is processing an event, it will not be triggered by the current actions.
michael@0 145 * EventListeners can never be invoked after being removed.
michael@0 146 * Calling removeEventListener with arguments which do not identify any
michael@0 147 * currently registered EventListener on the EventTarget has no effect.
michael@0 148 *
michael@0 149 * @param type Specifies the event type of the EventListener being
michael@0 150 * removed.
michael@0 151 * @param listener The EventListener parameter indicates the
michael@0 152 * EventListener to be removed.
michael@0 153 * @param useCapture Specifies whether the EventListener being
michael@0 154 * removed was registered as a capturing listener or
michael@0 155 * not. If a listener was registered twice, one with
michael@0 156 * capture and one without, each must be removed
michael@0 157 * separately. Removal of a capturing listener does
michael@0 158 * not affect a non-capturing version of the same
michael@0 159 * listener, and vice versa.
michael@0 160 */
michael@0 161 void removeEventListener(in DOMString type,
michael@0 162 in nsIDOMEventListener listener,
michael@0 163 [optional] in boolean useCapture);
michael@0 164
michael@0 165 /**
michael@0 166 * removeSystemEventListener() should be used if you have used
michael@0 167 * addSystemEventListener().
michael@0 168 */
michael@0 169 [noscript] void removeSystemEventListener(
michael@0 170 in DOMString type,
michael@0 171 in nsIDOMEventListener listener,
michael@0 172 [optional] in boolean aUseCapture);
michael@0 173
michael@0 174 /**
michael@0 175 * This method allows the dispatch of events into the implementations
michael@0 176 * event model. Events dispatched in this manner will have the same
michael@0 177 * capturing and bubbling behavior as events dispatched directly by the
michael@0 178 * implementation. The target of the event is the EventTarget on which
michael@0 179 * dispatchEvent is called.
michael@0 180 *
michael@0 181 * @param evt Specifies the event type, behavior, and contextual
michael@0 182 * information to be used in processing the event.
michael@0 183 * @return Indicates whether any of the listeners which handled the
michael@0 184 * event called preventDefault. If preventDefault was called
michael@0 185 * the value is false, else the value is true.
michael@0 186 * @throws INVALID_STATE_ERR: Raised if the Event's type was
michael@0 187 * not specified by initializing the event before
michael@0 188 * dispatchEvent was called. Specification of the Event's
michael@0 189 * type as null or an empty string will also trigger this
michael@0 190 * exception.
michael@0 191 */
michael@0 192 boolean dispatchEvent(in nsIDOMEvent evt)
michael@0 193 raises(DOMException);
michael@0 194
michael@0 195 /**
michael@0 196 * Returns the nsIDOMEventTarget object which should be used as the target
michael@0 197 * of DOMEvents.
michael@0 198 * Usually |this| is returned, but for example global object returns
michael@0 199 * the outer object.
michael@0 200 */
michael@0 201 [notxpcom, nostdcall] EventTargetPtr GetTargetForDOMEvent();
michael@0 202
michael@0 203 /**
michael@0 204 * Returns the nsIDOMEventTarget object which should be used as the target
michael@0 205 * of the event and when constructing event target chain.
michael@0 206 * Usually |this| is returned, but for example global object returns
michael@0 207 * the inner object.
michael@0 208 */
michael@0 209 [notxpcom, nostdcall] EventTargetPtr GetTargetForEventTargetChain();
michael@0 210
michael@0 211 /**
michael@0 212 * Called before the capture phase of the event flow.
michael@0 213 * This is used to create the event target chain and implementations
michael@0 214 * should set the necessary members of EventChainPreVisitor.
michael@0 215 * At least aVisitor.mCanHandle must be set,
michael@0 216 * usually also aVisitor.mParentTarget if mCanHandle is PR_TRUE.
michael@0 217 * First one tells that this object can handle the aVisitor.mEvent event and
michael@0 218 * the latter one is the possible parent object for the event target chain.
michael@0 219 * @see EventDispatcher.h for more documentation about aVisitor.
michael@0 220 *
michael@0 221 * @param aVisitor the visitor object which is used to create the
michael@0 222 * event target chain for event dispatching.
michael@0 223 *
michael@0 224 * @note Only EventDispatcher should call this method.
michael@0 225 */
michael@0 226 [noscript, nostdcall]
michael@0 227 void PreHandleEvent(in EventChainPreVisitorRef aVisitor);
michael@0 228
michael@0 229 /**
michael@0 230 * If EventChainPreVisitor.mWantsWillHandleEvent is set PR_TRUE,
michael@0 231 * called just before possible event handlers on this object will be called.
michael@0 232 */
michael@0 233 [noscript, nostdcall]
michael@0 234 void WillHandleEvent(in EventChainPostVisitorRef aVisitor);
michael@0 235
michael@0 236 /**
michael@0 237 * Called after the bubble phase of the system event group.
michael@0 238 * The default handling of the event should happen here.
michael@0 239 * @param aVisitor the visitor object which is used during post handling.
michael@0 240 *
michael@0 241 * @see EventDispatcher.h for documentation about aVisitor.
michael@0 242 * @note Only EventDispatcher should call this method.
michael@0 243 */
michael@0 244 [noscript, nostdcall]
michael@0 245 void PostHandleEvent(in EventChainPostVisitorRef aVisitor);
michael@0 246
michael@0 247 /**
michael@0 248 * Dispatch an event.
michael@0 249 * @param aEvent the event that is being dispatched.
michael@0 250 * @param aDOMEvent the event that is being dispatched, use if you want to
michael@0 251 * dispatch nsIDOMEvent, not only WidgetEvent.
michael@0 252 * @param aPresContext the current presentation context, can be nullptr.
michael@0 253 * @param aEventStatus the status returned from the function, can be nullptr.
michael@0 254 *
michael@0 255 * @note If both aEvent and aDOMEvent are used, aEvent must be the internal
michael@0 256 * event of the aDOMEvent.
michael@0 257 *
michael@0 258 * If aDOMEvent is not nullptr (in which case aEvent can be nullptr) it is used
michael@0 259 * for dispatching, otherwise aEvent is used.
michael@0 260 *
michael@0 261 * @deprecated This method is here just until all the callers outside Gecko
michael@0 262 * have been converted to use nsIDOMEventTarget::dispatchEvent.
michael@0 263 */
michael@0 264 [noscript, nostdcall]
michael@0 265 void DispatchDOMEvent(in WidgetEventPtr aEvent,
michael@0 266 in nsIDOMEvent aDOMEvent,
michael@0 267 in nsPresContextPtr aPresContext,
michael@0 268 in nsEventStatusPtr aEventStatus);
michael@0 269
michael@0 270 /**
michael@0 271 * Get the script context in which the event handlers should be run.
michael@0 272 * May return null.
michael@0 273 * @note Caller *must* check the value of aRv.
michael@0 274 */
michael@0 275 [notxpcom, nostdcall]
michael@0 276 nsIScriptContext GetContextForEventHandlers(out nsresult aRv);
michael@0 277
michael@0 278 /**
michael@0 279 * If the method above returns null, but a success code, this method
michael@0 280 * is called.
michael@0 281 */
michael@0 282 [notxpcom, nostdcall] JSContextPtr GetJSContextForEventHandlers();
michael@0 283 };
michael@0 284
michael@0 285 %{C++
michael@0 286
michael@0 287 #define NS_IMPL_DOMTARGET_DEFAULTS(_class) \
michael@0 288 mozilla::dom::EventTarget* _class::GetTargetForDOMEvent() { return this; } \
michael@0 289 mozilla::dom::EventTarget* _class::GetTargetForEventTargetChain() { return this; } \
michael@0 290 nsresult _class::WillHandleEvent(mozilla::EventChainPostVisitor& aVisitor) { return NS_OK; } \
michael@0 291 JSContext* _class::GetJSContextForEventHandlers() { return nullptr; }
michael@0 292
michael@0 293 #define NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(aClass) \
michael@0 294 NS_IMETHODIMP \
michael@0 295 aClass::RemoveSystemEventListener(const nsAString& aType, \
michael@0 296 nsIDOMEventListener *aListener, \
michael@0 297 bool aUseCapture) \
michael@0 298 { \
michael@0 299 mozilla::EventListenerManager* listenerManager = \
michael@0 300 GetExistingListenerManager(); \
michael@0 301 if (!listenerManager) { \
michael@0 302 return NS_OK; \
michael@0 303 } \
michael@0 304 mozilla::EventListenerFlags flags; \
michael@0 305 flags.mInSystemGroup = true; \
michael@0 306 flags.mCapture = aUseCapture; \
michael@0 307 listenerManager->RemoveEventListenerByType(aListener, aType, flags); \
michael@0 308 return NS_OK; \
michael@0 309 }
michael@0 310
michael@0 311 %}

mercurial