dom/events/EventListenerManager.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; 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 #ifndef mozilla_EventListenerManager_h_
michael@0 7 #define mozilla_EventListenerManager_h_
michael@0 8
michael@0 9 #include "mozilla/BasicEvents.h"
michael@0 10 #include "mozilla/dom/EventListenerBinding.h"
michael@0 11 #include "mozilla/JSEventHandler.h"
michael@0 12 #include "mozilla/MemoryReporting.h"
michael@0 13 #include "nsCOMPtr.h"
michael@0 14 #include "nsCycleCollectionParticipant.h"
michael@0 15 #include "nsGkAtoms.h"
michael@0 16 #include "nsIDOMEventListener.h"
michael@0 17 #include "nsTObserverArray.h"
michael@0 18
michael@0 19 class nsIDOMEvent;
michael@0 20 class nsIEventListenerInfo;
michael@0 21 class nsIScriptContext;
michael@0 22 class nsPIDOMWindow;
michael@0 23
michael@0 24 struct EventTypeData;
michael@0 25
michael@0 26 template<class T> class nsCOMArray;
michael@0 27
michael@0 28 namespace mozilla {
michael@0 29
michael@0 30 class ELMCreationDetector;
michael@0 31 class EventListenerManager;
michael@0 32
michael@0 33 namespace dom {
michael@0 34 class EventTarget;
michael@0 35 class Element;
michael@0 36 } // namespace dom
michael@0 37
michael@0 38 typedef dom::CallbackObjectHolder<dom::EventListener,
michael@0 39 nsIDOMEventListener> EventListenerHolder;
michael@0 40
michael@0 41 struct EventListenerFlags
michael@0 42 {
michael@0 43 friend class EventListenerManager;
michael@0 44 private:
michael@0 45 // If mListenerIsJSListener is true, the listener is implemented by JS.
michael@0 46 // Otherwise, it's implemented by native code or JS but it's wrapped.
michael@0 47 bool mListenerIsJSListener : 1;
michael@0 48
michael@0 49 public:
michael@0 50 // If mCapture is true, it means the listener captures the event. Otherwise,
michael@0 51 // it's listening at bubbling phase.
michael@0 52 bool mCapture : 1;
michael@0 53 // If mInSystemGroup is true, the listener is listening to the events in the
michael@0 54 // system group.
michael@0 55 bool mInSystemGroup : 1;
michael@0 56 // If mAllowUntrustedEvents is true, the listener is listening to the
michael@0 57 // untrusted events too.
michael@0 58 bool mAllowUntrustedEvents : 1;
michael@0 59
michael@0 60 EventListenerFlags() :
michael@0 61 mListenerIsJSListener(false),
michael@0 62 mCapture(false), mInSystemGroup(false), mAllowUntrustedEvents(false)
michael@0 63 {
michael@0 64 }
michael@0 65
michael@0 66 bool Equals(const EventListenerFlags& aOther) const
michael@0 67 {
michael@0 68 return (mCapture == aOther.mCapture &&
michael@0 69 mInSystemGroup == aOther.mInSystemGroup &&
michael@0 70 mListenerIsJSListener == aOther.mListenerIsJSListener &&
michael@0 71 mAllowUntrustedEvents == aOther.mAllowUntrustedEvents);
michael@0 72 }
michael@0 73
michael@0 74 bool EqualsIgnoringTrustness(const EventListenerFlags& aOther) const
michael@0 75 {
michael@0 76 return (mCapture == aOther.mCapture &&
michael@0 77 mInSystemGroup == aOther.mInSystemGroup &&
michael@0 78 mListenerIsJSListener == aOther.mListenerIsJSListener);
michael@0 79 }
michael@0 80
michael@0 81 bool operator==(const EventListenerFlags& aOther) const
michael@0 82 {
michael@0 83 return Equals(aOther);
michael@0 84 }
michael@0 85 };
michael@0 86
michael@0 87 inline EventListenerFlags TrustedEventsAtBubble()
michael@0 88 {
michael@0 89 EventListenerFlags flags;
michael@0 90 return flags;
michael@0 91 }
michael@0 92
michael@0 93 inline EventListenerFlags TrustedEventsAtCapture()
michael@0 94 {
michael@0 95 EventListenerFlags flags;
michael@0 96 flags.mCapture = true;
michael@0 97 return flags;
michael@0 98 }
michael@0 99
michael@0 100 inline EventListenerFlags AllEventsAtBubbe()
michael@0 101 {
michael@0 102 EventListenerFlags flags;
michael@0 103 flags.mAllowUntrustedEvents = true;
michael@0 104 return flags;
michael@0 105 }
michael@0 106
michael@0 107 inline EventListenerFlags AllEventsAtCapture()
michael@0 108 {
michael@0 109 EventListenerFlags flags;
michael@0 110 flags.mCapture = true;
michael@0 111 flags.mAllowUntrustedEvents = true;
michael@0 112 return flags;
michael@0 113 }
michael@0 114
michael@0 115 inline EventListenerFlags TrustedEventsAtSystemGroupBubble()
michael@0 116 {
michael@0 117 EventListenerFlags flags;
michael@0 118 flags.mInSystemGroup = true;
michael@0 119 return flags;
michael@0 120 }
michael@0 121
michael@0 122 inline EventListenerFlags TrustedEventsAtSystemGroupCapture()
michael@0 123 {
michael@0 124 EventListenerFlags flags;
michael@0 125 flags.mCapture = true;
michael@0 126 flags.mInSystemGroup = true;
michael@0 127 return flags;
michael@0 128 }
michael@0 129
michael@0 130 inline EventListenerFlags AllEventsAtSystemGroupBubble()
michael@0 131 {
michael@0 132 EventListenerFlags flags;
michael@0 133 flags.mInSystemGroup = true;
michael@0 134 flags.mAllowUntrustedEvents = true;
michael@0 135 return flags;
michael@0 136 }
michael@0 137
michael@0 138 inline EventListenerFlags AllEventsAtSystemGroupCapture()
michael@0 139 {
michael@0 140 EventListenerFlags flags;
michael@0 141 flags.mCapture = true;
michael@0 142 flags.mInSystemGroup = true;
michael@0 143 flags.mAllowUntrustedEvents = true;
michael@0 144 return flags;
michael@0 145 }
michael@0 146
michael@0 147 /*
michael@0 148 * Event listener manager
michael@0 149 */
michael@0 150
michael@0 151 class EventListenerManager MOZ_FINAL
michael@0 152 {
michael@0 153 public:
michael@0 154 struct Listener
michael@0 155 {
michael@0 156 EventListenerHolder mListener;
michael@0 157 nsCOMPtr<nsIAtom> mTypeAtom; // for the main thread
michael@0 158 nsString mTypeString; // for non-main-threads
michael@0 159 uint16_t mEventType;
michael@0 160
michael@0 161 enum ListenerType MOZ_ENUM_TYPE(uint8_t)
michael@0 162 {
michael@0 163 eNativeListener = 0,
michael@0 164 eJSEventListener,
michael@0 165 eWrappedJSListener,
michael@0 166 eWebIDLListener,
michael@0 167 eListenerTypeCount
michael@0 168 };
michael@0 169 uint8_t mListenerType;
michael@0 170
michael@0 171 bool mListenerIsHandler : 1;
michael@0 172 bool mHandlerIsString : 1;
michael@0 173 bool mAllEvents : 1;
michael@0 174
michael@0 175 EventListenerFlags mFlags;
michael@0 176
michael@0 177 JSEventHandler* GetJSEventHandler() const
michael@0 178 {
michael@0 179 return (mListenerType == eJSEventListener) ?
michael@0 180 static_cast<JSEventHandler*>(mListener.GetXPCOMCallback()) :
michael@0 181 nullptr;
michael@0 182 }
michael@0 183
michael@0 184 Listener()
michael@0 185 {
michael@0 186 MOZ_ASSERT(sizeof(mListenerType) == 1);
michael@0 187 MOZ_ASSERT(eListenerTypeCount < 255);
michael@0 188 }
michael@0 189
michael@0 190 ~Listener()
michael@0 191 {
michael@0 192 if ((mListenerType == eJSEventListener) && mListener) {
michael@0 193 static_cast<JSEventHandler*>(
michael@0 194 mListener.GetXPCOMCallback())->Disconnect();
michael@0 195 }
michael@0 196 }
michael@0 197
michael@0 198 MOZ_ALWAYS_INLINE bool IsListening(const WidgetEvent* aEvent) const
michael@0 199 {
michael@0 200 if (mFlags.mInSystemGroup != aEvent->mFlags.mInSystemGroup) {
michael@0 201 return false;
michael@0 202 }
michael@0 203 // FIXME Should check !mFlags.mCapture when the event is in target
michael@0 204 // phase because capture phase event listeners should not be fired.
michael@0 205 // But it breaks at least <xul:dialog>'s buttons. Bug 235441.
michael@0 206 return ((mFlags.mCapture && aEvent->mFlags.mInCapturePhase) ||
michael@0 207 (!mFlags.mCapture && aEvent->mFlags.mInBubblingPhase));
michael@0 208 }
michael@0 209 };
michael@0 210
michael@0 211 EventListenerManager(dom::EventTarget* aTarget);
michael@0 212 virtual ~EventListenerManager();
michael@0 213
michael@0 214 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(EventListenerManager)
michael@0 215
michael@0 216 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(EventListenerManager)
michael@0 217
michael@0 218 void AddEventListener(const nsAString& aType,
michael@0 219 nsIDOMEventListener* aListener,
michael@0 220 bool aUseCapture,
michael@0 221 bool aWantsUntrusted)
michael@0 222 {
michael@0 223 EventListenerHolder holder(aListener);
michael@0 224 AddEventListener(aType, holder, aUseCapture, aWantsUntrusted);
michael@0 225 }
michael@0 226 void AddEventListener(const nsAString& aType,
michael@0 227 dom::EventListener* aListener,
michael@0 228 bool aUseCapture,
michael@0 229 bool aWantsUntrusted)
michael@0 230 {
michael@0 231 EventListenerHolder holder(aListener);
michael@0 232 AddEventListener(aType, holder, aUseCapture, aWantsUntrusted);
michael@0 233 }
michael@0 234 void RemoveEventListener(const nsAString& aType,
michael@0 235 nsIDOMEventListener* aListener,
michael@0 236 bool aUseCapture)
michael@0 237 {
michael@0 238 EventListenerHolder holder(aListener);
michael@0 239 RemoveEventListener(aType, holder, aUseCapture);
michael@0 240 }
michael@0 241 void RemoveEventListener(const nsAString& aType,
michael@0 242 dom::EventListener* aListener,
michael@0 243 bool aUseCapture)
michael@0 244 {
michael@0 245 EventListenerHolder holder(aListener);
michael@0 246 RemoveEventListener(aType, holder, aUseCapture);
michael@0 247 }
michael@0 248
michael@0 249 void AddListenerForAllEvents(nsIDOMEventListener* aListener,
michael@0 250 bool aUseCapture,
michael@0 251 bool aWantsUntrusted,
michael@0 252 bool aSystemEventGroup);
michael@0 253 void RemoveListenerForAllEvents(nsIDOMEventListener* aListener,
michael@0 254 bool aUseCapture,
michael@0 255 bool aSystemEventGroup);
michael@0 256
michael@0 257 /**
michael@0 258 * Sets events listeners of all types.
michael@0 259 * @param an event listener
michael@0 260 */
michael@0 261 void AddEventListenerByType(nsIDOMEventListener *aListener,
michael@0 262 const nsAString& type,
michael@0 263 const EventListenerFlags& aFlags)
michael@0 264 {
michael@0 265 EventListenerHolder holder(aListener);
michael@0 266 AddEventListenerByType(holder, type, aFlags);
michael@0 267 }
michael@0 268 void AddEventListenerByType(const EventListenerHolder& aListener,
michael@0 269 const nsAString& type,
michael@0 270 const EventListenerFlags& aFlags);
michael@0 271 void RemoveEventListenerByType(nsIDOMEventListener *aListener,
michael@0 272 const nsAString& type,
michael@0 273 const EventListenerFlags& aFlags)
michael@0 274 {
michael@0 275 EventListenerHolder holder(aListener);
michael@0 276 RemoveEventListenerByType(holder, type, aFlags);
michael@0 277 }
michael@0 278 void RemoveEventListenerByType(const EventListenerHolder& aListener,
michael@0 279 const nsAString& type,
michael@0 280 const EventListenerFlags& aFlags);
michael@0 281
michael@0 282 /**
michael@0 283 * Sets the current "inline" event listener for aName to be a
michael@0 284 * function compiled from aFunc if !aDeferCompilation. If
michael@0 285 * aDeferCompilation, then we assume that we can get the string from
michael@0 286 * mTarget later and compile lazily.
michael@0 287 *
michael@0 288 * aElement, if not null, is the element the string is associated with.
michael@0 289 */
michael@0 290 // XXXbz does that play correctly with nodes being adopted across
michael@0 291 // documents? Need to double-check the spec here.
michael@0 292 nsresult SetEventHandler(nsIAtom *aName,
michael@0 293 const nsAString& aFunc,
michael@0 294 uint32_t aLanguage,
michael@0 295 bool aDeferCompilation,
michael@0 296 bool aPermitUntrustedEvents,
michael@0 297 dom::Element* aElement);
michael@0 298 /**
michael@0 299 * Remove the current "inline" event listener for aName.
michael@0 300 */
michael@0 301 void RemoveEventHandler(nsIAtom *aName, const nsAString& aTypeString);
michael@0 302
michael@0 303 void HandleEvent(nsPresContext* aPresContext,
michael@0 304 WidgetEvent* aEvent,
michael@0 305 nsIDOMEvent** aDOMEvent,
michael@0 306 dom::EventTarget* aCurrentTarget,
michael@0 307 nsEventStatus* aEventStatus)
michael@0 308 {
michael@0 309 if (mListeners.IsEmpty() || aEvent->mFlags.mPropagationStopped) {
michael@0 310 return;
michael@0 311 }
michael@0 312
michael@0 313 if (!mMayHaveCapturingListeners && !aEvent->mFlags.mInBubblingPhase) {
michael@0 314 return;
michael@0 315 }
michael@0 316
michael@0 317 if (!mMayHaveSystemGroupListeners && aEvent->mFlags.mInSystemGroup) {
michael@0 318 return;
michael@0 319 }
michael@0 320
michael@0 321 // Check if we already know that there is no event listener for the event.
michael@0 322 if (mNoListenerForEvent == aEvent->message &&
michael@0 323 (mNoListenerForEvent != NS_USER_DEFINED_EVENT ||
michael@0 324 mNoListenerForEventAtom == aEvent->userType)) {
michael@0 325 return;
michael@0 326 }
michael@0 327 HandleEventInternal(aPresContext, aEvent, aDOMEvent, aCurrentTarget,
michael@0 328 aEventStatus);
michael@0 329 }
michael@0 330
michael@0 331 /**
michael@0 332 * Tells the event listener manager that its target (which owns it) is
michael@0 333 * no longer using it (and could go away).
michael@0 334 */
michael@0 335 void Disconnect();
michael@0 336
michael@0 337 /**
michael@0 338 * Allows us to quickly determine if we have mutation listeners registered.
michael@0 339 */
michael@0 340 bool HasMutationListeners();
michael@0 341
michael@0 342 /**
michael@0 343 * Allows us to quickly determine whether we have unload or beforeunload
michael@0 344 * listeners registered.
michael@0 345 */
michael@0 346 bool HasUnloadListeners();
michael@0 347
michael@0 348 /**
michael@0 349 * Returns the mutation bits depending on which mutation listeners are
michael@0 350 * registered to this listener manager.
michael@0 351 * @note If a listener is an nsIDOMMutationListener, all possible mutation
michael@0 352 * event bits are returned. All bits are also returned if one of the
michael@0 353 * event listeners is registered to handle DOMSubtreeModified events.
michael@0 354 */
michael@0 355 uint32_t MutationListenerBits();
michael@0 356
michael@0 357 /**
michael@0 358 * Returns true if there is at least one event listener for aEventName.
michael@0 359 */
michael@0 360 bool HasListenersFor(const nsAString& aEventName);
michael@0 361
michael@0 362 /**
michael@0 363 * Returns true if there is at least one event listener for aEventNameWithOn.
michael@0 364 * Note that aEventNameWithOn must start with "on"!
michael@0 365 */
michael@0 366 bool HasListenersFor(nsIAtom* aEventNameWithOn);
michael@0 367
michael@0 368 /**
michael@0 369 * Returns true if there is at least one event listener.
michael@0 370 */
michael@0 371 bool HasListeners();
michael@0 372
michael@0 373 /**
michael@0 374 * Sets aList to the list of nsIEventListenerInfo objects representing the
michael@0 375 * listeners managed by this listener manager.
michael@0 376 */
michael@0 377 nsresult GetListenerInfo(nsCOMArray<nsIEventListenerInfo>* aList);
michael@0 378
michael@0 379 uint32_t GetIdentifierForEvent(nsIAtom* aEvent);
michael@0 380
michael@0 381 static void Shutdown();
michael@0 382
michael@0 383 /**
michael@0 384 * Returns true if there may be a paint event listener registered,
michael@0 385 * false if there definitely isn't.
michael@0 386 */
michael@0 387 bool MayHavePaintEventListener() { return mMayHavePaintEventListener; }
michael@0 388
michael@0 389 /**
michael@0 390 * Returns true if there may be a touch event listener registered,
michael@0 391 * false if there definitely isn't.
michael@0 392 */
michael@0 393 bool MayHaveTouchEventListener() { return mMayHaveTouchEventListener; }
michael@0 394
michael@0 395 bool MayHaveMouseEnterLeaveEventListener() { return mMayHaveMouseEnterLeaveEventListener; }
michael@0 396 bool MayHavePointerEnterLeaveEventListener() { return mMayHavePointerEnterLeaveEventListener; }
michael@0 397
michael@0 398 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
michael@0 399
michael@0 400 uint32_t ListenerCount() const
michael@0 401 {
michael@0 402 return mListeners.Length();
michael@0 403 }
michael@0 404
michael@0 405 void MarkForCC();
michael@0 406
michael@0 407 dom::EventTarget* GetTarget() { return mTarget; }
michael@0 408
michael@0 409 protected:
michael@0 410 void HandleEventInternal(nsPresContext* aPresContext,
michael@0 411 WidgetEvent* aEvent,
michael@0 412 nsIDOMEvent** aDOMEvent,
michael@0 413 dom::EventTarget* aCurrentTarget,
michael@0 414 nsEventStatus* aEventStatus);
michael@0 415
michael@0 416 nsresult HandleEventSubType(Listener* aListener,
michael@0 417 nsIDOMEvent* aDOMEvent,
michael@0 418 dom::EventTarget* aCurrentTarget);
michael@0 419
michael@0 420 /**
michael@0 421 * Compile the "inline" event listener for aListener. The
michael@0 422 * body of the listener can be provided in aBody; if this is null we
michael@0 423 * will look for it on mTarget. If aBody is provided, aElement should be
michael@0 424 * as well; otherwise it will also be inferred from mTarget.
michael@0 425 */
michael@0 426 nsresult CompileEventHandlerInternal(Listener* aListener,
michael@0 427 const nsAString* aBody,
michael@0 428 dom::Element* aElement);
michael@0 429
michael@0 430 /**
michael@0 431 * Find the Listener for the "inline" event listener for aTypeAtom.
michael@0 432 */
michael@0 433 Listener* FindEventHandler(uint32_t aEventType,
michael@0 434 nsIAtom* aTypeAtom,
michael@0 435 const nsAString& aTypeString);
michael@0 436
michael@0 437 /**
michael@0 438 * Set the "inline" event listener for aName to aHandler. aHandler may be
michael@0 439 * have no actual handler set to indicate that we should lazily get and
michael@0 440 * compile the string for this listener, but in that case aContext and
michael@0 441 * aScopeGlobal must be non-null. Otherwise, aContext and aScopeGlobal are
michael@0 442 * allowed to be null.
michael@0 443 */
michael@0 444 Listener* SetEventHandlerInternal(nsIAtom* aName,
michael@0 445 const nsAString& aTypeString,
michael@0 446 const TypedEventHandler& aHandler,
michael@0 447 bool aPermitUntrustedEvents);
michael@0 448
michael@0 449 bool IsDeviceType(uint32_t aType);
michael@0 450 void EnableDevice(uint32_t aType);
michael@0 451 void DisableDevice(uint32_t aType);
michael@0 452
michael@0 453 public:
michael@0 454 /**
michael@0 455 * Set the "inline" event listener for aEventName to aHandler. If
michael@0 456 * aHandler is null, this will actually remove the event listener
michael@0 457 */
michael@0 458 void SetEventHandler(nsIAtom* aEventName,
michael@0 459 const nsAString& aTypeString,
michael@0 460 dom::EventHandlerNonNull* aHandler);
michael@0 461 void SetEventHandler(dom::OnErrorEventHandlerNonNull* aHandler);
michael@0 462 void SetEventHandler(dom::OnBeforeUnloadEventHandlerNonNull* aHandler);
michael@0 463
michael@0 464 /**
michael@0 465 * Get the value of the "inline" event listener for aEventName.
michael@0 466 * This may cause lazy compilation if the listener is uncompiled.
michael@0 467 *
michael@0 468 * Note: It's the caller's responsibility to make sure to call the right one
michael@0 469 * of these methods. In particular, "onerror" events use
michael@0 470 * OnErrorEventHandlerNonNull for some event targets and EventHandlerNonNull
michael@0 471 * for others.
michael@0 472 */
michael@0 473 dom::EventHandlerNonNull* GetEventHandler(nsIAtom* aEventName,
michael@0 474 const nsAString& aTypeString)
michael@0 475 {
michael@0 476 const TypedEventHandler* typedHandler =
michael@0 477 GetTypedEventHandler(aEventName, aTypeString);
michael@0 478 return typedHandler ? typedHandler->NormalEventHandler() : nullptr;
michael@0 479 }
michael@0 480
michael@0 481 dom::OnErrorEventHandlerNonNull* GetOnErrorEventHandler()
michael@0 482 {
michael@0 483 const TypedEventHandler* typedHandler = mIsMainThreadELM ?
michael@0 484 GetTypedEventHandler(nsGkAtoms::onerror, EmptyString()) :
michael@0 485 GetTypedEventHandler(nullptr, NS_LITERAL_STRING("error"));
michael@0 486 return typedHandler ? typedHandler->OnErrorEventHandler() : nullptr;
michael@0 487 }
michael@0 488
michael@0 489 dom::OnBeforeUnloadEventHandlerNonNull* GetOnBeforeUnloadEventHandler()
michael@0 490 {
michael@0 491 const TypedEventHandler* typedHandler =
michael@0 492 GetTypedEventHandler(nsGkAtoms::onbeforeunload, EmptyString());
michael@0 493 return typedHandler ? typedHandler->OnBeforeUnloadEventHandler() : nullptr;
michael@0 494 }
michael@0 495
michael@0 496 protected:
michael@0 497 /**
michael@0 498 * Helper method for implementing the various Get*EventHandler above. Will
michael@0 499 * return null if we don't have an event handler for this event name.
michael@0 500 */
michael@0 501 const TypedEventHandler* GetTypedEventHandler(nsIAtom* aEventName,
michael@0 502 const nsAString& aTypeString);
michael@0 503
michael@0 504 void AddEventListener(const nsAString& aType,
michael@0 505 const EventListenerHolder& aListener,
michael@0 506 bool aUseCapture,
michael@0 507 bool aWantsUntrusted);
michael@0 508 void RemoveEventListener(const nsAString& aType,
michael@0 509 const EventListenerHolder& aListener,
michael@0 510 bool aUseCapture);
michael@0 511
michael@0 512 void AddEventListenerInternal(const EventListenerHolder& aListener,
michael@0 513 uint32_t aType,
michael@0 514 nsIAtom* aTypeAtom,
michael@0 515 const nsAString& aTypeString,
michael@0 516 const EventListenerFlags& aFlags,
michael@0 517 bool aHandler = false,
michael@0 518 bool aAllEvents = false);
michael@0 519 void RemoveEventListenerInternal(const EventListenerHolder& aListener,
michael@0 520 uint32_t aType,
michael@0 521 nsIAtom* aUserType,
michael@0 522 const nsAString& aTypeString,
michael@0 523 const EventListenerFlags& aFlags,
michael@0 524 bool aAllEvents = false);
michael@0 525 void RemoveAllListeners();
michael@0 526 const EventTypeData* GetTypeDataForIID(const nsIID& aIID);
michael@0 527 const EventTypeData* GetTypeDataForEventName(nsIAtom* aName);
michael@0 528 nsPIDOMWindow* GetInnerWindowForTarget();
michael@0 529 already_AddRefed<nsPIDOMWindow> GetTargetAsInnerWindow() const;
michael@0 530
michael@0 531 bool ListenerCanHandle(Listener* aListener, WidgetEvent* aEvent);
michael@0 532
michael@0 533 already_AddRefed<nsIScriptGlobalObject>
michael@0 534 GetScriptGlobalAndDocument(nsIDocument** aDoc);
michael@0 535
michael@0 536 uint32_t mMayHavePaintEventListener : 1;
michael@0 537 uint32_t mMayHaveMutationListeners : 1;
michael@0 538 uint32_t mMayHaveCapturingListeners : 1;
michael@0 539 uint32_t mMayHaveSystemGroupListeners : 1;
michael@0 540 uint32_t mMayHaveTouchEventListener : 1;
michael@0 541 uint32_t mMayHaveMouseEnterLeaveEventListener : 1;
michael@0 542 uint32_t mMayHavePointerEnterLeaveEventListener : 1;
michael@0 543 uint32_t mClearingListeners : 1;
michael@0 544 uint32_t mIsMainThreadELM : 1;
michael@0 545 uint32_t mNoListenerForEvent : 23;
michael@0 546
michael@0 547 nsAutoTObserverArray<Listener, 2> mListeners;
michael@0 548 dom::EventTarget* mTarget; // WEAK
michael@0 549 nsCOMPtr<nsIAtom> mNoListenerForEventAtom;
michael@0 550
michael@0 551 friend class ELMCreationDetector;
michael@0 552 static uint32_t sMainThreadCreatedCount;
michael@0 553 };
michael@0 554
michael@0 555 } // namespace mozilla
michael@0 556
michael@0 557 /**
michael@0 558 * NS_AddSystemEventListener() is a helper function for implementing
michael@0 559 * EventTarget::AddSystemEventListener().
michael@0 560 */
michael@0 561 inline nsresult
michael@0 562 NS_AddSystemEventListener(mozilla::dom::EventTarget* aTarget,
michael@0 563 const nsAString& aType,
michael@0 564 nsIDOMEventListener *aListener,
michael@0 565 bool aUseCapture,
michael@0 566 bool aWantsUntrusted)
michael@0 567 {
michael@0 568 mozilla::EventListenerManager* listenerManager =
michael@0 569 aTarget->GetOrCreateListenerManager();
michael@0 570 NS_ENSURE_STATE(listenerManager);
michael@0 571 mozilla::EventListenerFlags flags;
michael@0 572 flags.mInSystemGroup = true;
michael@0 573 flags.mCapture = aUseCapture;
michael@0 574 flags.mAllowUntrustedEvents = aWantsUntrusted;
michael@0 575 listenerManager->AddEventListenerByType(aListener, aType, flags);
michael@0 576 return NS_OK;
michael@0 577 }
michael@0 578
michael@0 579 #endif // mozilla_EventListenerManager_h_

mercurial