merge fx-team to mozilla-central
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Mon, 17 Mar 2014 12:35:37 +0100
changeset 192086 28a725269bfa2e32c029fe9c3d4eca20292f6793
parent 192083 db2c6e0b798efe86895743f5e476bea406e1036a (diff)
parent 192085 309dd572373ba60e9878f9f89a60da5aa34784d3 (current diff)
child 192099 a1592db51b9a31b938050d95ef586ce6fb16f3c0
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
merge fx-team to mozilla-central
--- a/accessible/src/base/DocManager.cpp
+++ b/accessible/src/base/DocManager.cpp
@@ -10,22 +10,22 @@
 #include "DocAccessible-inl.h"
 #include "nsAccessibilityService.h"
 #include "RootAccessibleWrap.h"
 
 #ifdef A11Y_LOG
 #include "Logging.h"
 #endif
 
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 #include "nsCURILoader.h"
 #include "nsDocShellLoadTypes.h"
 #include "nsIChannel.h"
 #include "nsIDOMDocument.h"
-#include "nsEventListenerManager.h"
 #include "nsIDOMWindow.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIWebNavigation.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIWebProgress.h"
 #include "nsCoreUtils.h"
 
 using namespace mozilla;
@@ -324,28 +324,28 @@ DocManager::HandleDOMDocumentLoad(nsIDoc
 }
 
 void
 DocManager::AddListeners(nsIDocument* aDocument,
                          bool aAddDOMContentLoadedListener)
 {
   nsPIDOMWindow* window = aDocument->GetWindow();
   EventTarget* target = window->GetChromeEventHandler();
-  nsEventListenerManager* elm = target->GetOrCreateListenerManager();
+  EventListenerManager* elm = target->GetOrCreateListenerManager();
   elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
-                              dom::TrustedEventsAtCapture());
+                              TrustedEventsAtCapture());
 
 #ifdef A11Y_LOG
   if (logging::IsEnabled(logging::eDocCreate))
     logging::Text("added 'pagehide' listener");
 #endif
 
   if (aAddDOMContentLoadedListener) {
     elm->AddEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"),
-                                dom::TrustedEventsAtCapture());
+                                TrustedEventsAtCapture());
 #ifdef A11Y_LOG
     if (logging::IsEnabled(logging::eDocCreate))
       logging::Text("added 'DOMContentLoaded' listener");
 #endif
   }
 }
 
 void
@@ -354,22 +354,22 @@ DocManager::RemoveListeners(nsIDocument*
   nsPIDOMWindow* window = aDocument->GetWindow();
   if (!window)
     return;
 
   EventTarget* target = window->GetChromeEventHandler();
   if (!target)
     return;
 
-  nsEventListenerManager* elm = target->GetOrCreateListenerManager();
+  EventListenerManager* elm = target->GetOrCreateListenerManager();
   elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
-                                 dom::TrustedEventsAtCapture());
+                                 TrustedEventsAtCapture());
 
   elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("DOMContentLoaded"),
-                                 dom::TrustedEventsAtCapture());
+                                 TrustedEventsAtCapture());
 }
 
 DocAccessible*
 DocManager::CreateDocOrRootAccessible(nsIDocument* aDocument)
 {
   // Ignore temporary, hiding, resource documents and documents without
   // docshell.
   if (aDocument->IsInitialDocument() ||
--- a/accessible/src/base/nsCoreUtils.cpp
+++ b/accessible/src/base/nsCoreUtils.cpp
@@ -11,24 +11,24 @@
 #include "nsIDocShellTreeOwner.h"
 #include "nsIDocument.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsRange.h"
 #include "nsIBoxObject.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDocShell.h"
-#include "nsEventListenerManager.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsIScrollableFrame.h"
 #include "nsEventStateManager.h"
 #include "nsISelectionPrivate.h"
 #include "nsISelectionController.h"
 #include "mozilla/dom/TouchEvent.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "nsView.h"
 #include "nsGkAtoms.h"
 
 #include "nsComponentManagerUtils.h"
 
 #include "nsITreeBoxObject.h"
@@ -40,17 +40,17 @@ using namespace mozilla;
 ////////////////////////////////////////////////////////////////////////////////
 // nsCoreUtils
 ////////////////////////////////////////////////////////////////////////////////
 
 bool
 nsCoreUtils::HasClickListener(nsIContent *aContent)
 {
   NS_ENSURE_TRUE(aContent, false);
-  nsEventListenerManager* listenerManager =
+  EventListenerManager* listenerManager =
     aContent->GetExistingListenerManager();
 
   return listenerManager &&
     (listenerManager->HasListenersFor(nsGkAtoms::onclick) ||
      listenerManager->HasListenersFor(nsGkAtoms::onmousedown) ||
      listenerManager->HasListenersFor(nsGkAtoms::onmouseup));
 }
 
--- a/accessible/src/generic/RootAccessible.cpp
+++ b/accessible/src/generic/RootAccessible.cpp
@@ -28,17 +28,16 @@
 #include "nsIAccessibleRelation.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDocShellTreeOwner.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/EventTarget.h"
 #include "nsIDOMDataContainerEvent.h"
 #include "nsIDOMXULMultSelectCntrlEl.h"
 #include "nsIDocument.h"
-#include "nsEventListenerManager.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIServiceManager.h"
 #include "nsPIDOMWindow.h"
 #include "nsIWebBrowserChrome.h"
 #include "nsReadableUtils.h"
 #include "nsFocusManager.h"
 
 #ifdef MOZ_XUL
--- a/accessible/src/windows/msaa/RootAccessibleWrap.cpp
+++ b/accessible/src/windows/msaa/RootAccessibleWrap.cpp
@@ -4,18 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "RootAccessibleWrap.h"
 
 #include "Compatibility.h"
 #include "nsCoreUtils.h"
 #include "nsWinUtils.h"
 
-#include "nsEventListenerManager.h"
-
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Constructor/desctructor
 
 RootAccessibleWrap::
   RootAccessibleWrap(nsIDocument* aDocument, nsIContent* aRootContent,
                      nsIPresShell* aPresShell) :
--- a/browser/devtools/markupview/test/browser_inspector_markup_add_attributes.js
+++ b/browser/devtools/markupview/test/browser_inspector_markup_add_attributes.js
@@ -9,16 +9,17 @@ http://creativecommons.org/publicdomain/
  * redoable. For each step in the test, we:
  * - Create a new DIV
  * - Make the change, check that the change was made as we expect
  * - Undo the change, check that the node is back in its original state
  * - Redo the change, check that the node change was made again correctly.
  */
 
 waitForExplicitFinish();
+requestLongerTimeout(2);
 
 let TEST_URL = "data:text/html,<div>markup-view attributes addition test</div>";
 let TEST_DATA = [{
   desc: "Add an attribute value without closing \"",
   enteredText: 'style="display: block;',
   expectedAttributes: {
     style: "display: block;"
   }
--- a/browser/devtools/webconsole/webconsole.js
+++ b/browser/devtools/webconsole/webconsole.js
@@ -4552,21 +4552,23 @@ var Utils = {
    * @param nsIScriptError aScriptError
    *        The script error you want to determine the category for.
    * @return CATEGORY_JS|CATEGORY_CSS|CATEGORY_SECURITY
    *         Depending on the script error CATEGORY_JS, CATEGORY_CSS, or
    *         CATEGORY_SECURITY can be returned.
    */
   categoryForScriptError: function Utils_categoryForScriptError(aScriptError)
   {
-    switch (aScriptError.category) {
-      case "CSS Parser":
-      case "CSS Loader":
-        return CATEGORY_CSS;
-
+    let category = aScriptError.category;
+
+    if (/^(?:CSS|Layout)\b/.test(category)) {
+      return CATEGORY_CSS;
+    }
+
+    switch (category) {
       case "Mixed Content Blocker":
       case "Mixed Content Message":
       case "CSP":
       case "Invalid HSTS Headers":
       case "Insecure Password Field":
       case "SSL":
       case "CORS":
         return CATEGORY_SECURITY;
--- a/browser/locales/en-US/chrome/browser/devtools/webConsole.dtd
+++ b/browser/locales/en-US/chrome/browser/devtools/webConsole.dtd
@@ -48,17 +48,17 @@
 <!ENTITY btnPageNet.accesskey "N">
 <!-- LOCALIZATION NOTE (btnPageNet.accesskeyMacOSX): This string is used as
   -  access key for the menu button that allows users to toggle the network
   -  logging output. On MacOSX accesskeys are available with Ctrl-*. Please make
   -  sure you do not use the following letters: A, E, N and P. These are used
   -  for editing commands in text inputs. -->
 <!ENTITY btnPageNet.accesskeyMacOSX "t">
 <!ENTITY btnPageCSS.label   "CSS">
-<!ENTITY btnPageCSS.tooltip "Log CSS parsing errors">
+<!ENTITY btnPageCSS.tooltip "Log CSS errors and warnings">
 <!ENTITY btnPageCSS.accesskey "C">
 <!ENTITY btnPageJS.label    "JS">
 <!ENTITY btnPageJS.tooltip  "Log JavaScript exceptions">
 <!ENTITY btnPageJS.accesskey  "J">
 <!ENTITY btnPageSecurity.label "Security">
 <!ENTITY btnPageSecurity.tooltip "Log security errors and warnings">
 <!ENTITY btnPageSecurity.accesskey "u">
 
--- a/content/base/public/Element.h
+++ b/content/base/public/Element.h
@@ -40,17 +40,16 @@
 class nsIDOMEventListener;
 class nsIFrame;
 class nsIDOMMozNamedAttrMap;
 class nsIDOMCSSStyleDeclaration;
 class nsIURI;
 class nsINodeInfo;
 class nsIControllers;
 class nsEventChainVisitor;
-class nsEventListenerManager;
 class nsIScrollableFrame;
 class nsAttrValueOrString;
 class ContentUnbinder;
 class nsContentList;
 class nsDOMTokenList;
 struct nsRect;
 class nsEventStateManager;
 class nsFocusManager;
@@ -98,16 +97,18 @@ enum {
 };
 
 #undef ELEMENT_FLAG_BIT
 
 // Make sure we have space for our bits
 ASSERT_NODE_FLAGS_SPACE(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET);
 
 namespace mozilla {
+class EventListenerManager;
+
 namespace dom {
 
 class Link;
 class UndoManager;
 class DOMRect;
 class DOMRectList;
 
 // IID for the dom::Element interface
@@ -1055,20 +1056,20 @@ protected:
   // inlined.  Those calls don't go through a vtable.
   virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
                                 const nsAttrValue* aValue, bool aNotify)
   {
     return NS_OK;
   }
 
   /**
-   * Hook to allow subclasses to produce a different nsEventListenerManager if
+   * Hook to allow subclasses to produce a different EventListenerManager if
    * needed for attachment of attribute-defined handlers
    */
-  virtual nsEventListenerManager*
+  virtual EventListenerManager*
     GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer);
 
   /**
    * Internal hook for converting an attribute name-string to an atomized name
    */
   virtual const nsAttrName* InternalGetExistingAttrNameFromQName(const nsAString& aStr) const;
 
   nsIFrame* GetStyledFrame();
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -35,17 +35,16 @@
 
 class imgICache;
 class imgIContainer;
 class imgINotificationObserver;
 class imgIRequest;
 class imgLoader;
 class imgRequestProxy;
 class nsAutoScriptBlockerSuppressNodeRemoved;
-class nsEventListenerManager;
 class nsHtml5StringParser;
 class nsIChannel;
 class nsIConsoleService;
 class nsIContent;
 class nsIContentPolicy;
 class nsIContentSecurityPolicy;
 class nsIDocShell;
 class nsIDocument;
@@ -104,16 +103,17 @@ struct nsIntMargin;
 
 template<class E> class nsCOMArray;
 template<class K, class V> class nsDataHashtable;
 template<class K, class V> class nsRefPtrHashtable;
 template<class T> class nsReadingIterator;
 
 namespace mozilla {
 class ErrorResult;
+class EventListenerManager;
 class Selection;
 
 namespace dom {
 class DocumentFragment;
 class Element;
 class EventTarget;
 } // namespace dom
 
@@ -1069,24 +1069,26 @@ public:
                                       nsCycleCollectionTraversalCallback &cb);
 
   /**
    * Get the eventlistener manager for aNode, creating it if it does not
    * already exist.
    *
    * @param aNode The node for which to get the eventlistener manager.
    */
-  static nsEventListenerManager* GetListenerManagerForNode(nsINode* aNode);
+  static mozilla::EventListenerManager*
+    GetListenerManagerForNode(nsINode* aNode);
   /**
    * Get the eventlistener manager for aNode, returning null if it does not
    * already exist.
    *
    * @param aNode The node for which to get the eventlistener manager.
    */
-  static nsEventListenerManager* GetExistingListenerManagerForNode(const nsINode* aNode);
+  static mozilla::EventListenerManager*
+    GetExistingListenerManagerForNode(const nsINode* aNode);
 
   static void UnmarkGrayJSListenersInCCGenerationDocuments(uint32_t aGeneration);
 
   /**
    * Remove the eventlistener manager for aNode.
    *
    * @param aNode The node for which to remove the eventlistener manager.
    */
--- a/content/base/public/nsINode.h
+++ b/content/base/public/nsINode.h
@@ -45,16 +45,17 @@ class nsIPresShell;
 class nsIPrincipal;
 class nsIURI;
 class nsNodeSupportsWeakRefTearoff;
 class nsNodeWeakReference;
 class nsXPCClassInfo;
 class nsDOMMutationObserver;
 
 namespace mozilla {
+class EventListenerManager;
 namespace dom {
 /**
  * @return true if aChar is what the DOM spec defines as 'space character'.
  * http://dom.spec.whatwg.org/#space-character
  */
 inline bool IsSpaceCharacter(char16_t aChar) {
   return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
          aChar == '\f';
@@ -800,20 +801,20 @@ public:
     return node;
   }
 
   /**
    * See nsIDOMEventTarget
    */
   NS_DECL_NSIDOMEVENTTARGET
 
-  virtual nsEventListenerManager*
-  GetExistingListenerManager() const MOZ_OVERRIDE;
-  virtual nsEventListenerManager*
-  GetOrCreateListenerManager() MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetExistingListenerManager() const MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetOrCreateListenerManager() MOZ_OVERRIDE;
 
   using mozilla::dom::EventTarget::RemoveEventListener;
   using nsIDOMEventTarget::AddEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 bool aUseCapture,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
--- a/content/base/src/Attr.cpp
+++ b/content/base/src/Attr.cpp
@@ -18,20 +18,18 @@
 #include "nsIContentInlines.h"
 #include "nsIDocument.h"
 #include "nsIDOMUserDataHandler.h"
 #include "nsEventDispatcher.h"
 #include "nsGkAtoms.h"
 #include "nsCOMArray.h"
 #include "nsNameSpaceManager.h"
 #include "nsNodeUtils.h"
-#include "nsEventListenerManager.h"
 #include "nsTextNode.h"
 #include "mozAutoDocUpdate.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsWrapperCacheInlines.h"
 
 nsIAttribute::nsIAttribute(nsDOMAttributeMap* aAttrMap,
                            already_AddRefed<nsINodeInfo>& aNodeInfo,
                            bool aNsAware)
 : nsINode(aNodeInfo), mAttrMap(aAttrMap), mNsAware(aNsAware)
 {
 }
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -17,17 +17,16 @@
 #include "nsDOMAttributeMap.h"
 #include "nsIAtom.h"
 #include "nsIContentInlines.h"
 #include "nsINodeInfo.h"
 #include "nsIDocumentInlines.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMDocument.h"
 #include "nsIContentIterator.h"
-#include "nsEventListenerManager.h"
 #include "nsFocusManager.h"
 #include "nsILinkHandler.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsIFrame.h"
 #include "nsIAnonymousContentCreator.h"
 #include "nsIPresShell.h"
@@ -44,17 +43,19 @@
 #include "nsNameSpaceManager.h"
 #include "nsContentList.h"
 #include "nsDOMTokenList.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsError.h"
 #include "nsDOMString.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIDOMMutationEvent.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/ContentEvents.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "nsNodeUtils.h"
 #include "mozilla/dom/DirectionalityUtils.h"
 #include "nsDocument.h"
 #include "nsAttrValueOrString.h"
 #include "nsAttrValueInlines.h"
@@ -94,17 +95,16 @@
 #include "nsContentCreatorFunctions.h"
 #include "nsIControllers.h"
 #include "nsView.h"
 #include "nsViewManager.h"
 #include "nsIScrollableFrame.h"
 #include "mozilla/css/StyleRule.h" /* For nsCSSSelectorList */
 #include "nsCSSRuleProcessor.h"
 #include "nsRuleProcessorData.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsTextNode.h"
 
 #ifdef MOZ_XUL
 #include "nsIXULDocument.h"
 #endif /* MOZ_XUL */
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsCCUncollectableMarker.h"
@@ -1655,18 +1655,18 @@ Element::SetEventHandler(nsIAtom* aEvent
   if (ownerDoc->IsLoadedAsData()) {
     // Make this a no-op rather than throwing an error to avoid
     // the error causing problems setting the attribute.
     return NS_OK;
   }
 
   NS_PRECONDITION(aEventName, "Must have event name!");
   bool defer = true;
-  nsEventListenerManager* manager = GetEventListenerManagerForAttr(aEventName,
-                                                                   &defer);
+  EventListenerManager* manager =
+    GetEventListenerManagerForAttr(aEventName, &defer);
   if (!manager) {
     return NS_OK;
   }
 
   defer = defer && aDefer; // only defer if everyone agrees...
   manager->SetEventHandler(aEventName, aValue,
                            nsIProgrammingLanguage::JAVASCRIPT,
                            defer, !nsContentUtils::IsChromeDoc(ownerDoc),
@@ -1941,17 +1941,17 @@ Element::SetAttrAndNotify(int32_t aNames
       mutation.mNewAttrValue = do_GetAtom(newValue);
     }
     if (!aOldValue.IsEmptyString()) {
       mutation.mPrevAttrValue = aOldValue.GetAsAtom();
     }
     mutation.mAttrChange = aModType;
 
     mozAutoSubtreeModified subtree(OwnerDoc(), this);
-    (new nsAsyncDOMEvent(this, mutation))->RunDOMEventWhenSafe();
+    (new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
   }
 
   return NS_OK;
 }
 
 bool
 Element::ParseAttribute(int32_t aNamespaceID,
                         nsIAtom* aAttribute,
@@ -1966,17 +1966,17 @@ Element::SetMappedAttribute(nsIDocument*
                             nsIAtom* aName,
                             nsAttrValue& aValue,
                             nsresult* aRetval)
 {
   *aRetval = NS_OK;
   return false;
 }
 
-nsEventListenerManager*
+EventListenerManager*
 Element::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
                                         bool* aDefer)
 {
   *aDefer = true;
   return GetOrCreateListenerManager();
 }
 
 Element::nsAttrInfo
@@ -2126,17 +2126,17 @@ Element::UnsetAttr(int32_t aNameSpaceID,
 
     nsAutoString value;
     oldValue.ToString(value);
     if (!value.IsEmpty())
       mutation.mPrevAttrValue = do_GetAtom(value);
     mutation.mAttrChange = nsIDOMMutationEvent::REMOVAL;
 
     mozAutoSubtreeModified subtree(OwnerDoc(), this);
-    (new nsAsyncDOMEvent(this, mutation))->RunDOMEventWhenSafe();
+    (new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
   }
 
   return NS_OK;
 }
 
 const nsAttrName*
 Element::GetAttrNameAt(uint32_t aIndex) const
 {
@@ -2613,22 +2613,22 @@ Element::MozRequestFullScreen()
   // Note that requests for fullscreen inside a web app's origin are exempt
   // from this restriction.
   const char* error = GetFullScreenError(OwnerDoc());
   if (error) {
     nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                     NS_LITERAL_CSTRING("DOM"), OwnerDoc(),
                                     nsContentUtils::eDOM_PROPERTIES,
                                     error);
-    nsRefPtr<nsAsyncDOMEvent> e =
-      new nsAsyncDOMEvent(OwnerDoc(),
-                          NS_LITERAL_STRING("mozfullscreenerror"),
-                          true,
-                          false);
-    e->PostDOMEvent();
+    nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+      new AsyncEventDispatcher(OwnerDoc(),
+                               NS_LITERAL_STRING("mozfullscreenerror"),
+                               true,
+                               false);
+    asyncDispatcher->PostDOMEvent();
     return;
   }
 
   OwnerDoc()->AsyncRequestFullScreen(this);
 
   return;
 }
 
--- a/content/base/src/FragmentOrElement.cpp
+++ b/content/base/src/FragmentOrElement.cpp
@@ -12,25 +12,26 @@
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/StaticPtr.h"
 
 #include "mozilla/dom/FragmentOrElement.h"
 
+#include "mozilla/AsyncEventDispatcher.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/Attr.h"
 #include "nsDOMAttributeMap.h"
 #include "nsIAtom.h"
 #include "nsINodeInfo.h"
 #include "nsIDocumentInlines.h"
 #include "nsIDocumentEncoder.h"
 #include "nsIDOMNodeList.h"
 #include "nsIContentIterator.h"
-#include "nsEventListenerManager.h"
 #include "nsFocusManager.h"
 #include "nsILinkHandler.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsIFrame.h"
 #include "nsIAnonymousContentCreator.h"
 #include "nsIPresShell.h"
@@ -94,17 +95,16 @@
 #include "nsContentCreatorFunctions.h"
 #include "nsIControllers.h"
 #include "nsView.h"
 #include "nsViewManager.h"
 #include "nsIScrollableFrame.h"
 #include "ChildIterator.h"
 #include "mozilla/css/StyleRule.h" /* For nsCSSSelectorList */
 #include "nsRuleProcessorData.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsTextNode.h"
 #include "mozilla/dom/NodeListBinding.h"
 #include "mozilla/dom/UndoManager.h"
 
 #ifdef MOZ_XUL
 #include "nsIXULDocument.h"
 #endif /* MOZ_XUL */
 
@@ -1118,17 +1118,17 @@ FragmentOrElement::FireNodeInserted(nsID
     nsIContent* childContent = aNodes[i];
 
     if (nsContentUtils::HasMutationListeners(childContent,
           NS_EVENT_BITS_MUTATION_NODEINSERTED, aParent)) {
       InternalMutationEvent mutation(true, NS_MUTATION_NODEINSERTED);
       mutation.mRelatedNode = do_QueryInterface(aParent);
 
       mozAutoSubtreeModified subtree(aDoc, aParent);
-      (new nsAsyncDOMEvent(childContent, mutation))->RunDOMEventWhenSafe();
+      (new AsyncEventDispatcher(childContent, mutation))->RunDOMEventWhenSafe();
     }
   }
 }
 
 //----------------------------------------------------------------------
 
 // nsISupports implementation
 
@@ -1319,17 +1319,17 @@ FragmentOrElement::MarkUserDataHandler(v
 void
 FragmentOrElement::MarkNodeChildren(nsINode* aNode)
 {
   JSObject* o = GetJSObjectChild(aNode);
   if (o) {
     JS::ExposeObjectToActiveJS(o);
   }
 
-  nsEventListenerManager* elm = aNode->GetExistingListenerManager();
+  EventListenerManager* elm = aNode->GetExistingListenerManager();
   if (elm) {
     elm->MarkForCC();
   }
 
   if (aNode->HasProperties()) {
     nsIDocument* ownerDoc = aNode->OwnerDoc();
     ownerDoc->PropertyTable(DOM_USER_DATA)->
       Enumerate(aNode, FragmentOrElement::MarkUserData,
--- a/content/base/src/nsCCUncollectableMarker.cpp
+++ b/content/base/src/nsCCUncollectableMarker.cpp
@@ -16,27 +16,28 @@
 #include "nsISHistory.h"
 #include "nsISHEntry.h"
 #include "nsISHContainer.h"
 #include "nsIWindowWatcher.h"
 #include "mozilla/Services.h"
 #include "nsIXULWindow.h"
 #include "nsIAppShellService.h"
 #include "nsAppShellCID.h"
-#include "nsEventListenerManager.h"
 #include "nsContentUtils.h"
 #include "nsGlobalWindow.h"
 #include "nsJSEnvironment.h"
 #include "nsInProcessTabChildGlobal.h"
 #include "nsFrameLoader.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/Element.h"
 #include "xpcpublic.h"
 #include "nsObserverService.h"
 #include "nsFocusManager.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 static bool sInited = 0;
 uint32_t nsCCUncollectableMarker::sGeneration = 0;
 #ifdef MOZ_XUL
 #include "nsXULPrototypeCache.h"
 #endif
 
@@ -140,17 +141,17 @@ MarkMessageManagers()
         static_cast<nsFrameMessageManager*>(tabMM)->GetCallback();
       if (cb) {
         nsFrameLoader* fl = static_cast<nsFrameLoader*>(cb);
         EventTarget* et = fl->GetTabChildGlobalAsEventTarget();
         if (!et) {
           continue;
         }
         static_cast<nsInProcessTabChildGlobal*>(et)->MarkForCC();
-        nsEventListenerManager* elm = et->GetExistingListenerManager();
+        EventListenerManager* elm = et->GetExistingListenerManager();
         if (elm) {
           elm->MarkForCC();
         }
       }
     }
   }
   if (nsFrameMessageManager::sParentProcessManager) {
     nsFrameMessageManager::sParentProcessManager->MarkForCC();
@@ -184,17 +185,17 @@ MarkContentViewer(nsIContentViewer* aVie
     return;
   }
 
   nsIDocument *doc = aViewer->GetDocument();
   if (doc &&
       doc->GetMarkedCCGeneration() != nsCCUncollectableMarker::sGeneration) {
     doc->MarkUncollectableForCCGeneration(nsCCUncollectableMarker::sGeneration);
     if (aCleanupJS) {
-      nsEventListenerManager* elm = doc->GetExistingListenerManager();
+      EventListenerManager* elm = doc->GetExistingListenerManager();
       if (elm) {
         elm->MarkForCC();
       }
       nsCOMPtr<EventTarget> win = do_QueryInterface(doc->GetInnerWindow());
       if (win) {
         elm = win->GetExistingListenerManager();
         if (elm) {
           elm->MarkForCC();
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -36,16 +36,17 @@
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "mozilla/dom/HTMLTemplateElement.h"
 #include "mozilla/dom/HTMLContentElement.h"
 #include "mozilla/dom/TextDecoder.h"
 #include "mozilla/dom/TouchEvent.h"
 #include "mozilla/dom/ShadowRoot.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Selection.h"
 #include "mozilla/TextEvents.h"
 #include "nsAString.h"
@@ -69,17 +70,16 @@
 #include "nsDocShellCID.h"
 #include "nsDocument.h"
 #include "nsDOMCID.h"
 #include "mozilla/dom/DataTransfer.h"
 #include "nsDOMJSUtils.h"
 #include "nsDOMMutationObserver.h"
 #include "nsError.h"
 #include "nsEventDispatcher.h"
-#include "nsEventListenerManager.h"
 #include "nsEventStateManager.h"
 #include "nsFocusManager.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGenericHTMLFrameElement.h"
 #include "nsGkAtoms.h"
 #include "nsHostObjectProtocolHandler.h"
 #include "nsHtml5Module.h"
 #include "nsHtml5StringParser.h"
@@ -264,17 +264,17 @@ class DOMEventListenerManagersHashReport
   MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
 
 public:
   NS_DECL_ISUPPORTS
 
   NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
                             nsISupports* aData)
   {
-    // We don't measure the |nsEventListenerManager| objects pointed to by the
+    // We don't measure the |EventListenerManager| objects pointed to by the
     // entries because those references are non-owning.
     int64_t amount = sEventListenerManagersHash.ops
                    ? PL_DHashTableSizeOfExcludingThis(
                        &sEventListenerManagersHash, nullptr, MallocSizeOf)
                    : 0;
 
     return MOZ_COLLECT_REPORT(
       "explicit/dom/event-listener-managers-hash", KIND_HEAP, UNITS_BYTES,
@@ -297,17 +297,17 @@ public:
   {
     NS_ASSERTION(!mListenerManager, "caller must release and disconnect ELM");
   }
 
 protected:          // declared protected to silence clang warnings
   const void *mKey; // must be first, to look like PLDHashEntryStub
 
 public:
-  nsRefPtr<nsEventListenerManager> mListenerManager;
+  nsRefPtr<EventListenerManager> mListenerManager;
 };
 
 static bool
 EventListenerManagerHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
                                   const void *key)
 {
   // Initialize the entry with placement new
   new (entry) EventListenerManagerMapEntry(key);
@@ -3556,45 +3556,45 @@ bool
 nsContentUtils::HasMutationListeners(nsINode* aNode,
                                      uint32_t aType,
                                      nsINode* aTargetForSubtreeModified)
 {
   nsIDocument* doc = aNode->OwnerDoc();
 
   // global object will be null for documents that don't have windows.
   nsPIDOMWindow* window = doc->GetInnerWindow();
-  // This relies on nsEventListenerManager::AddEventListener, which sets
+  // This relies on EventListenerManager::AddEventListener, which sets
   // all mutation bits when there is a listener for DOMSubtreeModified event.
   if (window && !window->HasMutationListeners(aType)) {
     return false;
   }
 
   if (aNode->IsNodeOfType(nsINode::eCONTENT) &&
       static_cast<nsIContent*>(aNode)->ChromeOnlyAccess()) {
     return false;
   }
 
   doc->MayDispatchMutationEvent(aTargetForSubtreeModified);
 
   // If we have a window, we can check it for mutation listeners now.
   if (aNode->IsInDoc()) {
     nsCOMPtr<EventTarget> piTarget(do_QueryInterface(window));
     if (piTarget) {
-      nsEventListenerManager* manager = piTarget->GetExistingListenerManager();
+      EventListenerManager* manager = piTarget->GetExistingListenerManager();
       if (manager && manager->HasMutationListeners()) {
         return true;
       }
     }
   }
 
   // If we have a window, we know a mutation listener is registered, but it
   // might not be in our chain.  If we don't have a window, we might have a
   // mutation listener.  Check quickly to see.
   while (aNode) {
-    nsEventListenerManager* manager = aNode->GetExistingListenerManager();
+    EventListenerManager* manager = aNode->GetExistingListenerManager();
     if (manager && manager->HasMutationListeners()) {
       return true;
     }
 
     if (aNode->IsNodeOfType(nsINode::eCONTENT)) {
       nsIContent* content = static_cast<nsIContent*>(aNode);
       nsIContent* insertionParent = content->GetXBLInsertionParent();
       if (insertionParent) {
@@ -3611,17 +3611,17 @@ nsContentUtils::HasMutationListeners(nsI
 /* static */
 bool
 nsContentUtils::HasMutationListeners(nsIDocument* aDocument,
                                      uint32_t aType)
 {
   nsPIDOMWindow* window = aDocument ?
     aDocument->GetInnerWindow() : nullptr;
 
-  // This relies on nsEventListenerManager::AddEventListener, which sets
+  // This relies on EventListenerManager::AddEventListener, which sets
   // all mutation bits when there is a listener for DOMSubtreeModified event.
   return !window || window->HasMutationListeners(aType);
 }
 
 void
 nsContentUtils::MaybeFireNodeRemoved(nsINode* aChild, nsINode* aParent,
                                      nsIDocument* aOwnerDoc)
 {
@@ -3705,17 +3705,17 @@ nsContentUtils::TraverseListenerManager(
                (PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
                                         PL_DHASH_LOOKUP));
   if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
     CycleCollectionNoteChild(cb, entry->mListenerManager.get(),
                              "[via hash] mListenerManager");
   }
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsContentUtils::GetListenerManagerForNode(nsINode *aNode)
 {
   if (!sEventListenerManagersHash.ops) {
     // We're already shut down, don't bother creating an event listener
     // manager.
 
     return nullptr;
   }
@@ -3725,25 +3725,25 @@ nsContentUtils::GetListenerManagerForNod
                (PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
                                         PL_DHASH_ADD));
 
   if (!entry) {
     return nullptr;
   }
 
   if (!entry->mListenerManager) {
-    entry->mListenerManager = new nsEventListenerManager(aNode);
+    entry->mListenerManager = new EventListenerManager(aNode);
 
     aNode->SetFlags(NODE_HAS_LISTENERMANAGER);
   }
 
   return entry->mListenerManager;
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsContentUtils::GetExistingListenerManagerForNode(const nsINode *aNode)
 {
   if (!aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
     return nullptr;
   }
   
   if (!sEventListenerManagersHash.ops) {
     // We're already shut down, don't bother creating an event listener
@@ -3768,17 +3768,17 @@ void
 nsContentUtils::RemoveListenerManager(nsINode *aNode)
 {
   if (sEventListenerManagersHash.ops) {
     EventListenerManagerMapEntry *entry =
       static_cast<EventListenerManagerMapEntry *>
                  (PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
                                           PL_DHASH_LOOKUP));
     if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
-      nsRefPtr<nsEventListenerManager> listenerManager;
+      nsRefPtr<EventListenerManager> listenerManager;
       listenerManager.swap(entry->mListenerManager);
       // Remove the entry and *then* do operations that could cause further
       // modification of sEventListenerManagersHash.  See bug 334177.
       PL_DHashTableRawRemove(&sEventListenerManagersHash, entry);
       if (listenerManager) {
         listenerManager->Disconnect();
       }
     }
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -35,18 +35,19 @@
 #include "mozilla/css/Loader.h"
 #include "mozilla/css/ImageLoader.h"
 #include "nsDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsCOMArray.h"
 #include "nsDOMClassInfo.h"
 #include "nsCxPusher.h"
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/BasicEvents.h"
-#include "nsAsyncDOMEvent.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsIDOMNodeFilter.h"
 
 #include "nsIDOMStyleSheet.h"
 #include "mozilla/dom/Attr.h"
 #include "nsIDOMDOMImplementation.h"
 #include "nsIDOMDocumentXBL.h"
 #include "mozilla/dom/Element.h"
 #include "nsGenericHTMLElement.h"
@@ -1708,17 +1709,17 @@ nsDocument::Release()
 NS_IMETHODIMP_(void)
 nsDocument::DeleteCycleCollectable()
 {
   delete this;
 }
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDocument)
   if (Element::CanSkip(tmp, aRemovingAllowed)) {
-    nsEventListenerManager* elm = tmp->GetExistingListenerManager();
+    EventListenerManager* elm = tmp->GetExistingListenerManager();
     if (elm) {
       elm->MarkForCC();
     }
     return true;
   }
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsDocument)
@@ -3975,19 +3976,20 @@ nsDocument::AddStyleSheetToStyleSets(nsI
       return;                                                           \
     }                                                                   \
     nsCOMPtr<concreteInterface> ssEvent(do_QueryInterface(event));      \
     MOZ_ASSERT(ssEvent);                                                \
     ssEvent->initMethod(NS_LITERAL_STRING(type), true, true,            \
                         cssSheet, __VA_ARGS__);                         \
     event->SetTrusted(true);                                            \
     event->SetTarget(this);                                             \
-    nsRefPtr<nsAsyncDOMEvent> asyncEvent = new nsAsyncDOMEvent(this, event); \
-    asyncEvent->mDispatchChromeOnly = true;                             \
-    asyncEvent->PostDOMEvent();                                         \
+    nsRefPtr<AsyncEventDispatcher> asyncDispatcher =                    \
+      new AsyncEventDispatcher(this, event);                            \
+    asyncDispatcher->mDispatchChromeOnly = true;                        \
+    asyncDispatcher->PostDOMEvent();                                    \
   } while (0);
 
 void
 nsDocument::NotifyStyleSheetAdded(nsIStyleSheet* aSheet, bool aDocumentSheet)
 {
   NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (this, aSheet, aDocumentSheet));
 
   if (StyleSheetChangeEventsEnabled()) {
@@ -7610,29 +7612,29 @@ nsDocument::GetViewportInfo(const Screen
       size.height = std::max(size.height, displaySize.height);
     }
 
     return nsViewportInfo(scaleFloat, scaleMinFloat, scaleMaxFloat, size,
                           mAutoSize, mAllowZoom, mAllowDoubleTapZoom);
   }
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsDocument::GetOrCreateListenerManager()
 {
   if (!mListenerManager) {
     mListenerManager =
-      new nsEventListenerManager(static_cast<EventTarget*>(this));
+      new EventListenerManager(static_cast<EventTarget*>(this));
     SetFlags(NODE_HAS_LISTENERMANAGER);
   }
 
   return mListenerManager;
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsDocument::GetExistingListenerManager() const
 {
   return mListenerManager;
 }
 
 nsresult
 nsDocument::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
 {
@@ -8316,17 +8318,17 @@ nsDocument::CanSavePresentation(nsIReque
   nsPIDOMWindow* win = GetInnerWindow();
   if (win && win->TimeoutSuspendCount()) {
     return false;
   }
 
   // Check our event listener manager for unload/beforeunload listeners.
   nsCOMPtr<EventTarget> piTarget = do_QueryInterface(mScriptGlobalObject);
   if (piTarget) {
-    nsEventListenerManager* manager = piTarget->GetExistingListenerManager();
+    EventListenerManager* manager = piTarget->GetExistingListenerManager();
     if (manager && manager->HasUnloadListeners()) {
       return false;
     }
   }
 
   // Check if we have pending network requests
   nsCOMPtr<nsILoadGroup> loadGroup = GetDocumentLoadGroup();
   if (loadGroup) {
@@ -8561,22 +8563,22 @@ nsDocument::UnblockOnload(bool aFireSync
       }
     } else if (mIsBeingUsedAsImage) {
       // To correctly unblock onload for a document that contains an SVG
       // image, we need to know when all of the SVG document's resources are
       // done loading, in a way comparable to |window.onload|. We fire this
       // event to indicate that the SVG should be considered fully loaded.
       // Because scripting is disabled on SVG-as-image documents, this event
       // is not accessible to content authors. (See bug 837135.)
-      nsRefPtr<nsAsyncDOMEvent> e =
-        new nsAsyncDOMEvent(this,
-                            NS_LITERAL_STRING("MozSVGAsImageDocumentLoad"),
-                            false,
-                            false);
-      e->PostDOMEvent();
+      nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+        new AsyncEventDispatcher(this,
+                                 NS_LITERAL_STRING("MozSVGAsImageDocumentLoad"),
+                                 false,
+                                 false);
+      asyncDispatcher->PostDOMEvent();
     }
   }
 }
 
 class nsUnblockOnloadEvent : public nsRunnable {
 public:
   nsUnblockOnloadEvent(nsDocument *doc) : mDoc(doc) {}
   NS_IMETHOD Run() {
@@ -8744,22 +8746,22 @@ NotifyPageHide(nsIDocument* aDocument, v
   const bool* aPersistedPtr = static_cast<const bool*>(aData);
   aDocument->OnPageHide(*aPersistedPtr, nullptr);
   return true;
 }
 
 static void
 DispatchFullScreenChange(nsIDocument* aTarget)
 {
-  nsRefPtr<nsAsyncDOMEvent> e =
-    new nsAsyncDOMEvent(aTarget,
-                        NS_LITERAL_STRING("mozfullscreenchange"),
-                        true,
-                        false);
-  e->PostDOMEvent();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(aTarget,
+                             NS_LITERAL_STRING("mozfullscreenchange"),
+                             true,
+                             false);
+  asyncDispatcher->PostDOMEvent();
 }
 
 void
 nsDocument::OnPageHide(bool aPersisted,
                        EventTarget* aDispatchStartTarget)
 {
   // Send out notifications that our <link> elements are detached,
   // but only if this is not a full unload.
@@ -8902,17 +8904,18 @@ nsDocument::MutationEventDispatched(nsIN
       }
     }
 
     mSubtreeModifiedTargets.Clear();
 
     int32_t realTargetCount = realTargets.Count();
     for (int32_t k = 0; k < realTargetCount; ++k) {
       InternalMutationEvent mutation(true, NS_MUTATION_SUBTREEMODIFIED);
-      (new nsAsyncDOMEvent(realTargets[k], mutation))->RunDOMEventWhenSafe();
+      (new AsyncEventDispatcher(realTargets[k], mutation))->
+        RunDOMEventWhenSafe();
     }
   }
 }
 
 void
 nsDocument::AddStyleRelevantLink(Link* aLink)
 {
   NS_ASSERTION(aLink, "Passing in a null link.  Expect crashes RSN!");
@@ -9065,21 +9068,20 @@ nsDocument::SetReadyStateInternal(ReadyS
         break;
     }
   }
   // At the time of loading start, we don't have timing object, record time.
   if (READYSTATE_LOADING == rs) {
     mLoadingTimeStamp = mozilla::TimeStamp::Now();
   }
 
-  nsRefPtr<nsAsyncDOMEvent> plevent =
-    new nsAsyncDOMEvent(this, NS_LITERAL_STRING("readystatechange"), false, false);
-  if (plevent) {
-    plevent->RunDOMEventWhenSafe();
-  }
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(this, NS_LITERAL_STRING("readystatechange"),
+                             false, false);
+  asyncDispatcher->RunDOMEventWhenSafe();
 }
 
 NS_IMETHODIMP
 nsDocument::GetReadyState(nsAString& aReadyState)
 {
   nsIDocument::GetReadyState(aReadyState);
   return NS_OK;
 }
@@ -10665,22 +10667,22 @@ nsDocument::RestorePreviousFullScreenSta
       if (fullScreenDoc != doc) {
         // We've popped so enough off the stack that we've rolled back to
         // a fullscreen element in a parent document. If this document isn't
         // approved for fullscreen, or if it's cross origin, dispatch an
         // event to chrome so it knows to show the authorization/warning UI.
         if (!nsContentUtils::HaveEqualPrincipals(fullScreenDoc, doc) ||
             (!nsContentUtils::IsSitePermAllow(doc->NodePrincipal(), "fullscreen") &&
              !static_cast<nsDocument*>(doc)->mIsApprovedForFullscreen)) {
-          nsRefPtr<nsAsyncDOMEvent> e =
-            new nsAsyncDOMEvent(doc,
-                                NS_LITERAL_STRING("MozEnteredDomFullscreen"),
-                                true,
-                                true);
-          e->PostDOMEvent();
+          nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+            new AsyncEventDispatcher(doc,
+                  NS_LITERAL_STRING("MozEnteredDomFullscreen"),
+                  true,
+                  true);
+          asyncDispatcher->PostDOMEvent();
         }
       }
 
       if (!nsContentUtils::HaveEqualPrincipals(doc, fullScreenDoc)) {
         // The origin which is fullscreen changed. Send a notification to
         // the root process so that a warning or approval UI can be shown
         // as necessary.
         nsAutoString origin;
@@ -10754,22 +10756,22 @@ nsDocument::AsyncRequestFullScreen(Eleme
 }
 
 static void
 LogFullScreenDenied(bool aLogFailure, const char* aMessage, nsIDocument* aDoc)
 {
   if (!aLogFailure) {
     return;
   }
-  nsRefPtr<nsAsyncDOMEvent> e =
-    new nsAsyncDOMEvent(aDoc,
-                        NS_LITERAL_STRING("mozfullscreenerror"),
-                        true,
-                        false);
-  e->PostDOMEvent();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(aDoc,
+                             NS_LITERAL_STRING("mozfullscreenerror"),
+                             true,
+                             false);
+  asyncDispatcher->PostDOMEvent();
   nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
                                   NS_LITERAL_CSTRING("DOM"), aDoc,
                                   nsContentUtils::eDOM_PROPERTIES,
                                   aMessage);
 }
 
 nsresult
 nsDocument::AddFullscreenApprovedObserver()
@@ -11115,22 +11117,22 @@ nsDocument::RequestFullScreen(Element* a
   // If this document, or a document with the same principal has not
   // already been approved for fullscreen this fullscreen-session, dispatch
   // an event so that chrome knows to pop up a warning/approval UI.
   // Note previousFullscreenDoc=nullptr upon first entry, so we always
   // take this path on the first time we enter fullscreen in a fullscreen
   // session.
   if (!mIsApprovedForFullscreen ||
       !nsContentUtils::HaveEqualPrincipals(previousFullscreenDoc, this)) {
-    nsRefPtr<nsAsyncDOMEvent> e =
-      new nsAsyncDOMEvent(this,
-                          NS_LITERAL_STRING("MozEnteredDomFullscreen"),
-                          true,
-                          true);
-    e->PostDOMEvent();
+    nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+      new AsyncEventDispatcher(this,
+                               NS_LITERAL_STRING("MozEnteredDomFullscreen"),
+                               true,
+                               true);
+    asyncDispatcher->PostDOMEvent();
   }
 
 #ifdef DEBUG
   // Note assertions must run before SetWindowFullScreen() as that does
   // synchronous event dispatch which can run script which exits full-screen!
   NS_ASSERTION(GetFullScreenElement() == aElement,
                "Full-screen element should be the requested element!");
   NS_ASSERTION(IsFullScreenDoc(), "Should be full-screen doc");
@@ -11272,37 +11274,37 @@ nsDocument::IsFullScreenEnabled(bool aCa
 
 static void
 DispatchPointerLockChange(nsIDocument* aTarget)
 {
   if (!aTarget) {
     return;
   }
 
-  nsRefPtr<nsAsyncDOMEvent> e =
-    new nsAsyncDOMEvent(aTarget,
-                        NS_LITERAL_STRING("mozpointerlockchange"),
-                        true,
-                        false);
-  e->PostDOMEvent();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(aTarget,
+                             NS_LITERAL_STRING("mozpointerlockchange"),
+                             true,
+                             false);
+  asyncDispatcher->PostDOMEvent();
 }
 
 static void
 DispatchPointerLockError(nsIDocument* aTarget)
 {
   if (!aTarget) {
     return;
   }
 
-  nsRefPtr<nsAsyncDOMEvent> e =
-    new nsAsyncDOMEvent(aTarget,
-                        NS_LITERAL_STRING("mozpointerlockerror"),
-                        true,
-                        false);
-  e->PostDOMEvent();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(aTarget,
+                             NS_LITERAL_STRING("mozpointerlockerror"),
+                             true,
+                             false);
+  asyncDispatcher->PostDOMEvent();
 }
 
 mozilla::StaticRefPtr<nsPointerLockPermissionRequest> gPendingPointerLockRequest;
 
 class nsPointerLockPermissionRequest : public nsRunnable,
                                        public nsIContentPermissionRequest
 {
 public:
@@ -11833,17 +11835,17 @@ nsIDocument::DocAddSizeOfExcludingThis(n
   aWindowSizes->mPropertyTablesSize +=
     mPropertyTable.SizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
   for (uint32_t i = 0, count = mExtraPropertyTables.Length();
        i < count; ++i) {
     aWindowSizes->mPropertyTablesSize +=
       mExtraPropertyTables[i]->SizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
   }
 
-  if (nsEventListenerManager* elm = GetExistingListenerManager()) {
+  if (EventListenerManager* elm = GetExistingListenerManager()) {
     aWindowSizes->mDOMEventListenersCount += elm->ListenerCount();
   }
 
   // Measurement of the following members may be added later if DMD finds it
   // is worthwhile:
   // - many!
 }
 
@@ -11899,17 +11901,17 @@ nsDocument::DocAddSizeOfExcludingThis(ns
       break;
     default:
       p = &aWindowSizes->mDOMOtherSize;
       break;
     }
 
     *p += nodeSize;
 
-    if (nsEventListenerManager* elm = node->GetExistingListenerManager()) {
+    if (EventListenerManager* elm = node->GetExistingListenerManager()) {
       aWindowSizes->mDOMEventListenersCount += elm->ListenerCount();
     }
   }
 
   aWindowSizes->mStyleSheetsSize +=
     mStyleSheets.SizeOfExcludingThis(SizeOfStyleSheetsElementIncludingThis,
                                      aWindowSizes->mMallocSizeOf);
   aWindowSizes->mStyleSheetsSize +=
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -56,32 +56,32 @@
 #include "nsIContentViewer.h"
 #include "nsIDOMXPathNSResolver.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsILoadContext.h"
 #include "nsIProgressEventSink.h"
 #include "nsISecurityEventSink.h"
 #include "nsIChannelEventSink.h"
 #include "imgIRequest.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/DOMImplementation.h"
 #include "nsIDOMTouchEvent.h"
 #include "nsDataHashtable.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Attributes.h"
 #include "nsIDOMXPathEvaluator.h"
 #include "jsfriendapi.h"
 
 #define XML_DECLARATION_BITS_DECLARATION_EXISTS   (1 << 0)
 #define XML_DECLARATION_BITS_ENCODING_EXISTS      (1 << 1)
 #define XML_DECLARATION_BITS_STANDALONE_EXISTS    (1 << 2)
 #define XML_DECLARATION_BITS_STANDALONE_YES       (1 << 3)
 
 
-class nsEventListenerManager;
 class nsDOMStyleSheetList;
 class nsDOMStyleSheetSetList;
 class nsIOutputStream;
 class nsDocument;
 class nsIDTD;
 class nsIRadioVisitor;
 class nsIFormControl;
 struct nsRadioGroupStruct;
@@ -898,18 +898,20 @@ public:
   // nsIDOMXMLDocument
   NS_DECL_NSIDOMXMLDOCUMENT
 
   // nsIDOMDocumentXBL
   NS_DECL_NSIDOMDOCUMENTXBL
 
   // nsIDOMEventTarget
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
-  virtual nsEventListenerManager* GetOrCreateListenerManager() MOZ_OVERRIDE;
-  virtual nsEventListenerManager* GetExistingListenerManager() const MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetOrCreateListenerManager() MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetExistingListenerManager() const MOZ_OVERRIDE;
 
   // nsIScriptObjectPrincipal
   virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE;
 
   // nsIApplicationCacheContainer
   NS_DECL_NSIAPPLICATIONCACHECONTAINER
 
   // nsIObserver
@@ -1415,17 +1417,17 @@ public:
   virtual void SwizzleCustomElement(Element* aElement,
                                     const nsAString& aTypeExtension,
                                     uint32_t aNamespaceID,
                                     mozilla::ErrorResult& rv);
 
   // The "registry" from the web components spec.
   nsRefPtr<Registry> mRegistry;
 
-  nsRefPtr<nsEventListenerManager> mListenerManager;
+  nsRefPtr<mozilla::EventListenerManager> mListenerManager;
   nsCOMPtr<nsIDOMStyleSheetList> mDOMStyleSheets;
   nsRefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
   nsRefPtr<nsScriptLoader> mScriptLoader;
   nsDocHeaderData* mHeaderData;
   /* mIdentifierMap works as follows for IDs:
    * 1) Attribute changes affect the table immediately (removing and adding
    *    entries as needed).
    * 2) Removals from the DOM affect the table immediately
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -52,17 +52,16 @@
 #include "nsIXULWindow.h"
 #include "nsIEditor.h"
 #include "nsIMozBrowserFrame.h"
 #include "nsIPermissionManager.h"
 #include "nsISHistory.h"
 
 #include "nsLayoutUtils.h"
 #include "nsView.h"
-#include "nsAsyncDOMEvent.h"
 
 #include "nsIURI.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 
 #include "nsGkAtoms.h"
 #include "nsNameSpaceManager.h"
 
@@ -71,16 +70,17 @@
 #include "nsIDOMChromeWindow.h"
 #include "nsInProcessTabChildGlobal.h"
 
 #include "Layers.h"
 
 #include "AppProcessChecker.h"
 #include "ContentParent.h"
 #include "TabParent.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/GuardObjects.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/unused.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/layout/RenderFrameParent.h"
 #include "nsIAppsService.h"
 #include "GeckoProfiler.h"
 
@@ -370,22 +370,24 @@ nsFrameLoader::LoadFrame()
   }
 
   return NS_OK;
 }
 
 void
 nsFrameLoader::FireErrorEvent()
 {
-  if (mOwnerContent) {
-    nsRefPtr<nsAsyncDOMEvent> event =
-      new nsLoadBlockingAsyncDOMEvent(mOwnerContent, NS_LITERAL_STRING("error"),
-                                      false, false);
-    event->PostDOMEvent();
+  if (!mOwnerContent) {
+    return;
   }
+  nsRefPtr<AsyncEventDispatcher > loadBlockingAsyncDispatcher =
+    new LoadBlockingAsyncEventDispatcher(mOwnerContent,
+                                         NS_LITERAL_STRING("error"),
+                                         false, false);
+  loadBlockingAsyncDispatcher->PostDOMEvent();
 }
 
 NS_IMETHODIMP
 nsFrameLoader::LoadURI(nsIURI* aURI)
 {
   if (!aURI)
     return NS_ERROR_INVALID_POINTER;
   NS_ENSURE_STATE(!mDestroyCalled && mOwnerContent);
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -6,21 +6,21 @@
 /*
  * Base class for DOM Core's nsIDOMComment, nsIDOMDocumentType, nsIDOMText,
  * nsIDOMCDATASection, and nsIDOMProcessingInstruction nodes.
  */
 
 #include "mozilla/DebugOnly.h"
 
 #include "nsGenericDOMDataNode.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "nsIDocument.h"
-#include "nsEventListenerManager.h"
 #include "nsIDOMDocument.h"
 #include "nsReadableUtils.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "nsIURI.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMText.h"
 #include "nsCOMPtr.h"
 #include "nsDOMString.h"
@@ -28,17 +28,16 @@
 #include "nsChangeHint.h"
 #include "nsEventDispatcher.h"
 #include "nsCOMArray.h"
 #include "nsNodeUtils.h"
 #include "mozilla/dom/DirectionalityUtils.h"
 #include "nsBindingManager.h"
 #include "nsCCUncollectableMarker.h"
 #include "mozAutoDocUpdate.h"
-#include "nsAsyncDOMEvent.h"
 
 #include "pldhash.h"
 #include "prprf.h"
 #include "nsWrapperCacheInlines.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
@@ -383,17 +382,17 @@ nsGenericDOMDataNode::SetTextInternal(ui
       mutation.mPrevAttrValue = oldValue;
       if (aLength > 0) {
         nsAutoString val;
         mText.AppendTo(val);
         mutation.mNewAttrValue = do_GetAtom(val);
       }
 
       mozAutoSubtreeModified subtree(OwnerDoc(), this);
-      (new nsAsyncDOMEvent(this, mutation))->RunDOMEventWhenSafe();
+      (new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
     }
   }
 
   return NS_OK;
 }
 
 //----------------------------------------------------------------------
 
--- a/content/base/src/nsGenericDOMDataNode.h
+++ b/content/base/src/nsGenericDOMDataNode.h
@@ -11,17 +11,16 @@
 #ifndef nsGenericDOMDataNode_h___
 #define nsGenericDOMDataNode_h___
 
 #include "mozilla/Attributes.h"
 #include "nsIContent.h"
 
 #include "nsTextFragment.h"
 #include "nsError.h"
-#include "nsEventListenerManager.h"
 #include "mozilla/dom/Element.h"
 #include "nsCycleCollectionParticipant.h"
 
 #include "nsISMILAttr.h"
 #include "nsIDocument.h"
 
 class nsIDOMAttr;
 class nsIDOMEventListener;
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -8,25 +8,26 @@
  * Base class for all DOM nodes.
  */
 
 #include "nsINode.h"
 
 #include "AccessCheck.h"
 #include "jsapi.h"
 #include "mozAutoDocUpdate.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/CORSMode.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/ShadowRoot.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsAttrValueOrString.h"
 #include "nsBindingManager.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentList.h"
 #include "nsContentUtils.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsDocument.h"
@@ -34,17 +35,16 @@
 #include "nsDOMAttributeMap.h"
 #include "nsDOMCID.h"
 #include "nsDOMCSSAttrDeclaration.h"
 #include "nsError.h"
 #include "nsDOMMutationObserver.h"
 #include "nsDOMString.h"
 #include "nsDOMTokenList.h"
 #include "nsEventDispatcher.h"
-#include "nsEventListenerManager.h"
 #include "nsEventStateManager.h"
 #include "nsFocusManager.h"
 #include "nsFrameManager.h"
 #include "nsFrameSelection.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsIAnonymousContentCreator.h"
 #include "nsIAtom.h"
@@ -1061,17 +1061,17 @@ nsINode::AddEventListener(const nsAStrin
                "explicit by making aOptionalArgc non-zero.");
 
   if (!aWantsUntrusted &&
       (aOptionalArgc < 2 &&
        !nsContentUtils::IsChromeDoc(OwnerDoc()))) {
     aWantsUntrusted = true;
   }
 
-  nsEventListenerManager* listener_manager = GetOrCreateListenerManager();
+  EventListenerManager* listener_manager = GetOrCreateListenerManager();
   NS_ENSURE_STATE(listener_manager);
   listener_manager->AddEventListener(aType, aListener, aUseCapture,
                                      aWantsUntrusted);
   return NS_OK;
 }
 
 void
 nsINode::AddEventListener(const nsAString& aType,
@@ -1082,17 +1082,17 @@ nsINode::AddEventListener(const nsAStrin
 {
   bool wantsUntrusted;
   if (aWantsUntrusted.IsNull()) {
     wantsUntrusted = !nsContentUtils::IsChromeDoc(OwnerDoc());
   } else {
     wantsUntrusted = aWantsUntrusted.Value();
   }
 
-  nsEventListenerManager* listener_manager = GetOrCreateListenerManager();
+  EventListenerManager* listener_manager = GetOrCreateListenerManager();
   if (!listener_manager) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
   listener_manager->AddEventListener(aType, aListener, aUseCapture,
                                      wantsUntrusted);
 }
 
@@ -1118,17 +1118,17 @@ nsINode::AddSystemEventListener(const ns
                                    aWantsUntrusted);
 }
 
 NS_IMETHODIMP
 nsINode::RemoveEventListener(const nsAString& aType,
                              nsIDOMEventListener* aListener,
                              bool aUseCapture)
 {
-  nsEventListenerManager* elm = GetExistingListenerManager();
+  EventListenerManager* elm = GetExistingListenerManager();
   if (elm) {
     elm->RemoveEventListener(aType, aListener, aUseCapture);
   }
   return NS_OK;
 }
 
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsINode)
 
@@ -1179,23 +1179,23 @@ nsINode::DispatchDOMEvent(WidgetEvent* a
                           nsIDOMEvent* aDOMEvent,
                           nsPresContext* aPresContext,
                           nsEventStatus* aEventStatus)
 {
   return nsEventDispatcher::DispatchDOMEvent(this, aEvent, aDOMEvent,
                                              aPresContext, aEventStatus);
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsINode::GetOrCreateListenerManager()
 {
   return nsContentUtils::GetListenerManagerForNode(this);
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsINode::GetExistingListenerManager() const
 {
   return nsContentUtils::GetExistingListenerManagerForNode(this);
 }
 
 nsIScriptContext*
 nsINode::GetContextForEventHandlers(nsresult* aRv)
 {
@@ -1437,17 +1437,17 @@ nsINode::doInsertChildAt(nsIContent* aKi
     }
 
     if (nsContentUtils::HasMutationListeners(aKid,
           NS_EVENT_BITS_MUTATION_NODEINSERTED, this)) {
       InternalMutationEvent mutation(true, NS_MUTATION_NODEINSERTED);
       mutation.mRelatedNode = do_QueryInterface(this);
 
       mozAutoSubtreeModified subtree(OwnerDoc(), this);
-      (new nsAsyncDOMEvent(aKid, mutation))->RunDOMEventWhenSafe();
+      (new AsyncEventDispatcher(aKid, mutation))->RunDOMEventWhenSafe();
     }
   }
 
   return NS_OK;
 }
 
 Element*
 nsINode::GetPreviousElementSibling() const
@@ -2197,17 +2197,17 @@ nsINode::GetBoundMutationObservers(nsTAr
     }
   }
 }
 
 size_t
 nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t n = 0;
-  nsEventListenerManager* elm = GetExistingListenerManager();
+  EventListenerManager* elm = GetExistingListenerManager();
   if (elm) {
     n += elm->SizeOfIncludingThis(aMallocSizeOf);
   }
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
   // - mNodeInfo
   // - mSlots
@@ -2215,23 +2215,23 @@ nsINode::SizeOfExcludingThis(MallocSizeO
   // The following members are not measured:
   // - mParent, mNextSibling, mPreviousSibling, mFirstChild: because they're
   //   non-owning
   return n;
 }
 
 #define EVENT(name_, id_, type_, struct_)                                    \
   EventHandlerNonNull* nsINode::GetOn##name_() {                             \
-    nsEventListenerManager *elm = GetExistingListenerManager();              \
+    EventListenerManager *elm = GetExistingListenerManager();                \
     return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString())   \
                : nullptr;                                                    \
   }                                                                          \
   void nsINode::SetOn##name_(EventHandlerNonNull* handler)                   \
   {                                                                          \
-    nsEventListenerManager *elm = GetOrCreateListenerManager();              \
+    EventListenerManager *elm = GetOrCreateListenerManager();                \
     if (elm) {                                                               \
       elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler);    \
     }                                                                        \
   }
 #define TOUCH_EVENT EVENT
 #define DOCUMENT_ONLY_EVENT EVENT
 #include "nsEventNameList.h"
 #undef DOCUMENT_ONLY_EVENT
--- a/content/base/src/nsImageLoadingContent.cpp
+++ b/content/base/src/nsImageLoadingContent.cpp
@@ -21,17 +21,16 @@
 #include "nsContentPolicyUtils.h"
 #include "nsIURI.h"
 #include "nsILoadGroup.h"
 #include "imgIContainer.h"
 #include "imgLoader.h"
 #include "imgRequestProxy.h"
 #include "nsThreadUtils.h"
 #include "nsNetUtil.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsImageFrame.h"
 
 #include "nsIPresShell.h"
 #include "nsEventStates.h"
 
 #include "nsIChannel.h"
 #include "nsIStreamListener.h"
 
@@ -40,16 +39,17 @@
 
 #include "nsContentUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsIContentPolicy.h"
 #include "nsEventDispatcher.h"
 #include "nsSVGEffects.h"
 
 #include "mozAutoDocUpdate.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/ScriptSettings.h"
 
 #if defined(XP_WIN)
 // Undefine LoadImage to prevent naming conflict with Windows.
 #undef LoadImage
 #endif
 
@@ -1034,20 +1034,20 @@ nsresult
 nsImageLoadingContent::FireEvent(const nsAString& aEventType)
 {
   // We have to fire the event asynchronously so that we won't go into infinite
   // loops in cases when onLoad handlers reset the src and the new src is in
   // cache.
 
   nsCOMPtr<nsINode> thisNode = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
 
-  nsRefPtr<nsAsyncDOMEvent> event =
-    new nsLoadBlockingAsyncDOMEvent(thisNode, aEventType, false, false);
-  event->PostDOMEvent();
-  
+  nsRefPtr<AsyncEventDispatcher> loadBlockingAsyncDispatcher =
+    new LoadBlockingAsyncEventDispatcher(thisNode, aEventType, false, false);
+  loadBlockingAsyncDispatcher->PostDOMEvent();
+
   return NS_OK;
 }
 
 nsRefPtr<imgRequestProxy>&
 nsImageLoadingContent::PrepareNextRequest()
 {
   // If we don't have a usable current request, get rid of any half-baked
   // request that might be sitting there and make this one current.
--- a/content/base/src/nsNodeUtils.cpp
+++ b/content/base/src/nsNodeUtils.cpp
@@ -8,17 +8,17 @@
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 #include "nsINode.h"
 #include "nsIContent.h"
 #include "mozilla/dom/Element.h"
 #include "nsIMutationObserver.h"
 #include "nsIDocument.h"
 #include "nsIDOMUserDataHandler.h"
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsIXPConnect.h"
 #include "pldhash.h"
 #include "nsIDOMAttr.h"
 #include "nsCOMArray.h"
 #include "nsPIDOMWindow.h"
 #include "nsDocument.h"
 #ifdef MOZ_XUL
 #include "nsXULElement.h"
@@ -29,16 +29,17 @@
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "nsWrapperCacheInlines.h"
 #include "nsObjectLoadingContent.h"
 #include "nsDOMMutationObserver.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/HTMLTemplateElement.h"
 #include "mozilla/dom/ShadowRoot.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 using mozilla::AutoJSContext;
 
 // This macro expects the ownerDocument of content_ to be in scope as
 // |nsIDocument* doc|
 #define IMPL_MUTATION_NOTIFICATION(func_, content_, params_)      \
   PR_BEGIN_MACRO                                                  \
   bool needsEnterLeave = doc->MayHaveDOMMutationObservers();      \
@@ -231,17 +232,17 @@ nsNodeUtils::LastRelease(nsINode* aNode)
     }
   }
   aNode->UnsetFlags(NODE_HAS_PROPERTIES);
 
   if (aNode->NodeType() != nsIDOMNode::DOCUMENT_NODE &&
       aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
 #ifdef DEBUG
     if (nsContentUtils::IsInitialized()) {
-      nsEventListenerManager* manager =
+      EventListenerManager* manager =
         nsContentUtils::GetExistingListenerManagerForNode(aNode);
       if (!manager) {
         NS_ERROR("Huh, our bit says we have a listener manager list, "
                  "but there's nothing in the hash!?!!");
       }
     }
 #endif
 
@@ -483,17 +484,17 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNod
       // XXX what if oldDoc is null, we don't know if this should be
       // registered or not! Can that really happen?
       if (wasRegistered) {
         newDoc->RegisterFreezableElement(aNode->AsElement());
       }
 
       nsPIDOMWindow* window = newDoc->GetInnerWindow();
       if (window) {
-        nsEventListenerManager* elm = aNode->GetExistingListenerManager();
+        EventListenerManager* elm = aNode->GetExistingListenerManager();
         if (elm) {
           window->SetMutationListeners(elm->MutationListenerBits());
           if (elm->MayHavePaintEventListener()) {
             window->SetHasPaintEventListeners();
           }
           if (elm->MayHaveAudioAvailableEventListener()) {
             window->SetHasAudioAvailableEventListeners();
           }
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -3,16 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsXMLHttpRequest.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/dom/XMLHttpRequestUploadBinding.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsDOMBlobBuilder.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMProgressEvent.h"
 #include "nsIJARChannel.h"
 #include "nsLayoutCID.h"
 #include "nsReadableUtils.h"
 
@@ -2152,21 +2153,21 @@ nsXMLHttpRequest::OnStopRequest(nsIReque
   if (!mResponseXML) {
     ChangeStateToDone();
     return NS_OK;
   }
   if (mIsHtml) {
     NS_ASSERTION(!(mState & XML_HTTP_REQUEST_SYNCLOOPING),
       "We weren't supposed to support HTML parsing with XHR!");
     nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(mResponseXML);
-    nsEventListenerManager* manager =
+    EventListenerManager* manager =
       eventTarget->GetOrCreateListenerManager();
     manager->AddEventListenerByType(new nsXHRParseEndListener(this),
                                     NS_LITERAL_STRING("DOMContentLoaded"),
-                                    dom::TrustedEventsAtSystemGroupBubble());
+                                    TrustedEventsAtSystemGroupBubble());
     return NS_OK;
   }
   // We might have been sent non-XML data. If that was the case,
   // we should null out the document member. The idea in this
   // check here is that if there is no document element it is not
   // an XML document. We might need a fancier check...
   if (!mResponseXML->GetRootElement()) {
     mResponseXML = nullptr;
--- a/content/html/content/src/HTMLCanvasElement.cpp
+++ b/content/html/content/src/HTMLCanvasElement.cpp
@@ -13,17 +13,16 @@
 #include "mozilla/Base64.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/dom/CanvasRenderingContext2D.h"
 #include "mozilla/dom/HTMLCanvasElementBinding.h"
 #include "mozilla/dom/UnionTypes.h"
 #include "mozilla/gfx/Rect.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsAttrValueInlines.h"
 #include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsDOMFile.h"
 #include "nsDOMJSUtils.h"
 #include "nsFrameManager.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsITimer.h"
--- a/content/html/content/src/HTMLFormElement.cpp
+++ b/content/html/content/src/HTMLFormElement.cpp
@@ -1051,24 +1051,24 @@ HTMLFormElement::AssertDocumentOrder(
   }
 }
 #endif
 
 void
 HTMLFormElement::PostPasswordEvent()
 {
   // Don't fire another add event if we have a pending add event.
-  if (mFormPasswordEvent.get()) {
+  if (mFormPasswordEventDispatcher.get()) {
     return;
   }
 
-  nsRefPtr<FormPasswordEvent> event =
-    new FormPasswordEvent(this, NS_LITERAL_STRING("DOMFormHasPassword"));
-  mFormPasswordEvent = event;
-  event->PostDOMEvent();
+  mFormPasswordEventDispatcher =
+    new FormPasswordEventDispatcher(this,
+                                    NS_LITERAL_STRING("DOMFormHasPassword"));
+  mFormPasswordEventDispatcher->PostDOMEvent();
 }
 
 // This function return true if the element, once appended, is the last one in
 // the array.
 template<typename ElementType>
 static bool
 AddElementToList(nsTArray<ElementType*>& aList, ElementType* aChild,
                  HTMLFormElement* aForm)
--- a/content/html/content/src/HTMLFormElement.h
+++ b/content/html/content/src/HTMLFormElement.h
@@ -1,31 +1,31 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_HTMLFormElement_h
 #define mozilla_dom_HTMLFormElement_h
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/Attributes.h"
 #include "nsCOMPtr.h"
 #include "nsIForm.h"
 #include "nsIFormControl.h"
 #include "nsFormSubmission.h"
 #include "nsGenericHTMLElement.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsIWebProgressListener.h"
 #include "nsIRadioGroupContainer.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsThreadUtils.h"
 #include "nsInterfaceHashtable.h"
 #include "nsRefPtrHashtable.h"
 #include "nsDataHashtable.h"
-#include "nsAsyncDOMEvent.h"
 #include "jsfriendapi.h" // For js::ExpandoAndGeneration
 
 class nsIMutableArray;
 class nsIURI;
 
 namespace mozilla {
 namespace dom {
 class HTMLFormControlsCollection;
@@ -404,34 +404,34 @@ public:
 
   js::ExpandoAndGeneration mExpandoAndGeneration;
 
 protected:
   virtual JSObject* WrapNode(JSContext* aCx,
                              JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
   void PostPasswordEvent();
-  void EventHandled() { mFormPasswordEvent = nullptr; }
+  void EventHandled() { mFormPasswordEventDispatcher = nullptr; }
 
-  class FormPasswordEvent : public nsAsyncDOMEvent
+  class FormPasswordEventDispatcher MOZ_FINAL : public AsyncEventDispatcher
   {
   public:
-    FormPasswordEvent(HTMLFormElement* aEventNode,
-                      const nsAString& aEventType)
-      : nsAsyncDOMEvent(aEventNode, aEventType, true, true)
+    FormPasswordEventDispatcher(HTMLFormElement* aEventNode,
+                                const nsAString& aEventType)
+      : AsyncEventDispatcher(aEventNode, aEventType, true, true)
     {}
 
     NS_IMETHOD Run() MOZ_OVERRIDE
     {
       static_cast<HTMLFormElement*>(mEventNode.get())->EventHandled();
-      return nsAsyncDOMEvent::Run();
+      return AsyncEventDispatcher::Run();
     }
   };
 
-  nsRefPtr<FormPasswordEvent> mFormPasswordEvent;
+  nsRefPtr<FormPasswordEventDispatcher> mFormPasswordEventDispatcher;
 
   class RemoveElementRunnable;
   friend class RemoveElementRunnable;
 
   class RemoveElementRunnable : public nsRunnable {
   public:
     RemoveElementRunnable(HTMLFormElement* aForm)
       : mForm(aForm)
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -1,19 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/HTMLInputElement.h"
 
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/dom/Date.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsAttrValueInlines.h"
 
 #include "nsIDOMHTMLInputElement.h"
 #include "nsITextControlElement.h"
 #include "nsIDOMNSEditableElement.h"
 #include "nsIRadioVisitor.h"
 #include "nsIPhonetic.h"
 
@@ -60,17 +60,16 @@
 #include "nsEventDispatcher.h"
 #include "nsLayoutUtils.h"
 
 #include "nsIDOMMutationEvent.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
-#include "nsEventListenerManager.h"
 
 #include "nsRuleData.h"
 #include <algorithm>
 
 // input type=radio
 #include "nsIRadioGroupContainer.h"
 
 // input type=file
@@ -3572,19 +3571,19 @@ HTMLInputElement::CancelRangeThumbDrag(b
     // TODO: decide what we should do here - bug 851782.
     nsAutoString val;
     ConvertNumberToString(mRangeThumbDragStartValue, val);
     SetValueInternal(val, true, true);
     nsRangeFrame* frame = do_QueryFrame(GetPrimaryFrame());
     if (frame) {
       frame->UpdateForValueChange();
     }
-    nsRefPtr<nsAsyncDOMEvent> event =
-      new nsAsyncDOMEvent(this, NS_LITERAL_STRING("input"), true, false);
-    event->RunDOMEventWhenSafe();
+    nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+      new AsyncEventDispatcher(this, NS_LITERAL_STRING("input"), true, false);
+    asyncDispatcher->RunDOMEventWhenSafe();
   }
 }
 
 void
 HTMLInputElement::SetValueOfRangeForUserEvent(Decimal aValue)
 {
   MOZ_ASSERT(aValue.isFinite());
 
@@ -5073,19 +5072,20 @@ HTMLInputElement::SetSelectionRange(int3
       nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eForward;
       if (aDirection.WasPassed() && aDirection.Value().EqualsLiteral("backward")) {
         dir = nsITextControlFrame::eBackward;
       }
 
       aRv = textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd, dir);
       if (!aRv.Failed()) {
         aRv = textControlFrame->ScrollSelectionIntoView();
-        nsRefPtr<nsAsyncDOMEvent> event =
-          new nsAsyncDOMEvent(this, NS_LITERAL_STRING("select"), true, false);
-        event->PostDOMEvent();
+        nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+          new AsyncEventDispatcher(this, NS_LITERAL_STRING("select"),
+                                   true, false);
+        asyncDispatcher->PostDOMEvent();
       }
     }
   }
 }
 
 NS_IMETHODIMP
 HTMLInputElement::SetSelectionRange(int32_t aSelectionStart,
                                     int32_t aSelectionEnd,
--- a/content/html/content/src/HTMLLinkElement.cpp
+++ b/content/html/content/src/HTMLLinkElement.cpp
@@ -1,20 +1,20 @@
 
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/HTMLLinkElement.h"
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/HTMLLinkElementBinding.h"
 #include "mozilla/MemoryReporting.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsContentUtils.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsDOMTokenList.h"
 #include "nsIDocument.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMStyleSheet.h"
 #include "nsIStyleSheet.h"
@@ -221,21 +221,21 @@ HTMLLinkElement::CreateAndDispatchEvent(
     {&nsGkAtoms::_empty, &nsGkAtoms::stylesheet, nullptr};
 
   if (!nsContentUtils::HasNonEmptyAttr(this, kNameSpaceID_None,
                                        nsGkAtoms::rev) &&
       FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::rel,
                       strings, eIgnoreCase) != ATTR_VALUE_NO_MATCH)
     return;
 
-  nsRefPtr<nsAsyncDOMEvent> event = new nsAsyncDOMEvent(this, aEventName, true,
-                                                        true);
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(this, aEventName, true, true);
   // Always run async in order to avoid running script when the content
   // sink isn't expecting it.
-  event->PostDOMEvent();
+  asyncDispatcher->PostDOMEvent();
 }
 
 nsresult
 HTMLLinkElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
                          nsIAtom* aPrefix, const nsAString& aValue,
                          bool aNotify)
 {
   nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
--- a/content/html/content/src/HTMLMetaElement.cpp
+++ b/content/html/content/src/HTMLMetaElement.cpp
@@ -1,18 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/dom/HTMLMetaElement.h"
 #include "mozilla/dom/HTMLMetaElementBinding.h"
+#include "nsContentUtils.h"
 #include "nsStyleConsts.h"
-#include "nsAsyncDOMEvent.h"
-#include "nsContentUtils.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Meta)
 
 namespace mozilla {
 namespace dom {
 
 HTMLMetaElement::HTMLMetaElement(already_AddRefed<nsINodeInfo>& aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
@@ -78,19 +78,19 @@ HTMLMetaElement::UnbindFromTree(bool aDe
 
 void
 HTMLMetaElement::CreateAndDispatchEvent(nsIDocument* aDoc,
                                         const nsAString& aEventName)
 {
   if (!aDoc)
     return;
 
-  nsRefPtr<nsAsyncDOMEvent> event = new nsAsyncDOMEvent(this, aEventName, true,
-                                                        true);
-  event->PostDOMEvent();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(this, aEventName, true, true);
+  asyncDispatcher->PostDOMEvent();
 }
 
 JSObject*
 HTMLMetaElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return HTMLMetaElementBinding::Wrap(aCx, aScope, this);
 }
 
--- a/content/html/content/src/HTMLSelectElement.cpp
+++ b/content/html/content/src/HTMLSelectElement.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/HTMLSelectElement.h"
 
 #include "mozAutoDocUpdate.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/BasicEvents.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/HTMLOptGroupElement.h"
 #include "mozilla/dom/HTMLOptionElement.h"
 #include "mozilla/dom/HTMLSelectElementBinding.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentList.h"
 #include "nsError.h"
 #include "nsEventDispatcher.h"
--- a/content/html/content/src/HTMLTextAreaElement.cpp
+++ b/content/html/content/src/HTMLTextAreaElement.cpp
@@ -2,16 +2,17 @@
 /* vim: set sw=2 ts=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/HTMLTextAreaElement.h"
 
 #include "mozAutoDocUpdate.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/HTMLTextAreaElementBinding.h"
 #include "mozilla/MouseEvents.h"
 #include "nsAttrValueInlines.h"
 #include "nsContentCID.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsError.h"
 #include "nsEventDispatcher.h"
@@ -882,19 +883,20 @@ HTMLTextAreaElement::SetSelectionRange(u
       nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eForward;
       if (aDirection.WasPassed() && aDirection.Value().EqualsLiteral("backward")) {
         dir = nsITextControlFrame::eBackward;
       }
 
       rv = textControlFrame->SetSelectionRange(aSelectionStart, aSelectionEnd, dir);
       if (NS_SUCCEEDED(rv)) {
         rv = textControlFrame->ScrollSelectionIntoView();
-        nsRefPtr<nsAsyncDOMEvent> event =
-          new nsAsyncDOMEvent(this, NS_LITERAL_STRING("select"), true, false);
-        event->PostDOMEvent();
+        nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+          new AsyncEventDispatcher(this, NS_LITERAL_STRING("select"),
+                                   true, false);
+        asyncDispatcher->PostDOMEvent();
       }
     }
   }
 
   if (NS_FAILED(rv)) {
     aError.Throw(rv);
   }
 }
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Likely.h"
 
 #include "nscore.h"
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValueInlines.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
@@ -21,17 +22,16 @@
 #include "nsIDOMHTMLDocument.h"
 #include "nsIDOMAttr.h"
 #include "nsIDOMDocumentFragment.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIDOMHTMLMenuElement.h"
 #include "nsIDOMElementCSSInlineStyle.h"
 #include "nsIDOMWindow.h"
 #include "nsIDOMDocument.h"
-#include "nsEventListenerManager.h"
 #include "nsMappedAttributes.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsIHTMLDocument.h"
 #include "nsPIDOMWindow.h"
 #include "nsIStyleRule.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsEscape.h"
@@ -78,17 +78,16 @@
 #include "nsEventDispatcher.h"
 #include "nsLayoutUtils.h"
 #include "mozAutoDocUpdate.h"
 #include "nsHtml5Module.h"
 #include "nsITextControlElement.h"
 #include "mozilla/dom/Element.h"
 #include "HTMLFieldSetElement.h"
 #include "HTMLMenuElement.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsDOMMutationObserver.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/FromParser.h"
 #include "mozilla/dom/Link.h"
 #include "mozilla/dom/UndoManager.h"
 #include "mozilla/BloomFilter.h"
 
 #include "HTMLPropertiesCollection.h"
@@ -806,17 +805,17 @@ nsGenericHTMLElement::AfterSetAttr(int32
       SetDirectionalityOnDescendants(this, dir, aNotify);
     }
   }
 
   return nsGenericHTMLElementBase::AfterSetAttr(aNamespaceID, aName,
                                                 aValue, aNotify);
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsGenericHTMLElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
                                                      bool* aDefer)
 {
   // Attributes on the body and frameset tags get set on the global object
   if ((mNodeInfo->Equals(nsGkAtoms::body) ||
        mNodeInfo->Equals(nsGkAtoms::frameset)) &&
       // We only forward some event attributes from body/frameset to window
       (0
@@ -1005,17 +1004,17 @@ nsGenericHTMLElement::UnsetAttr(int32_t 
       NS_ENSURE_SUCCESS(rv, rv);
     }
     else if (aAttribute == nsGkAtoms::accesskey) {
       // Have to unregister before clearing flag. See UnregAccessKey
       UnregAccessKey();
       UnsetFlags(NODE_HAS_ACCESSKEY);
     }
     else if (IsEventAttributeName(aAttribute)) {
-      if (nsEventListenerManager* manager = GetExistingListenerManager()) {
+      if (EventListenerManager* manager = GetExistingListenerManager()) {
         manager->RemoveEventHandler(aAttribute, EmptyString());
       }
     }
   }
 
   nsresult rv = nsGenericHTMLElementBase::UnsetAttr(aNameSpaceID, aAttribute,
                                                     aNotify);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -35,16 +35,17 @@ class nsILayoutHistoryState;
 class nsIEditor;
 struct nsRect;
 struct nsSize;
 class nsIDOMHTMLMenuElement;
 class nsIDOMHTMLCollection;
 class nsDOMSettableTokenList;
 
 namespace mozilla {
+class EventListenerManager;
 namespace dom {
 class HTMLFormElement;
 class HTMLPropertiesCollection;
 class HTMLMenuElement;
 }
 }
 
 typedef nsMappedAttributeElement nsGenericHTMLElementBase;
@@ -982,18 +983,19 @@ protected:
 
 private:
   void RegUnRegAccessKey(bool aDoReg);
 
 protected:
   virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
                                 const nsAttrValue* aValue, bool aNotify) MOZ_OVERRIDE;
 
-  virtual nsEventListenerManager*
-    GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer) MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetEventListenerManagerForAttr(nsIAtom* aAttrName,
+                                   bool* aDefer) MOZ_OVERRIDE;
 
   virtual const nsAttrName* InternalGetExistingAttrNameFromQName(const nsAString& aStr) const MOZ_OVERRIDE;
 
   /**
    * Create a URI for the given aURISpec string.
    * Returns INVALID_STATE_ERR and nulls *aURI if aURISpec is empty
    * and the document's URI matches the element's base URI.
    */
--- a/content/html/content/src/nsTextEditorState.cpp
+++ b/content/html/content/src/nsTextEditorState.cpp
@@ -31,17 +31,17 @@
 #include "nsIWidget.h"
 #include "nsIDocumentEncoder.h"
 #include "nsISelectionPrivate.h"
 #include "nsPIDOMWindow.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIEditor.h"
 #include "nsTextEditRules.h"
 #include "mozilla/Selection.h"
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsContentUtils.h"
 #include "mozilla/Preferences.h"
 #include "nsTextNode.h"
 #include "nsIController.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/ScriptSettings.h"
 
 using namespace mozilla;
@@ -1520,27 +1520,27 @@ nsTextEditorState::UnbindFromFrame(nsTex
     mSelCon = nullptr;
   }
 
   if (mTextListener)
   {
     mTextListener->SetFrame(nullptr);
 
     nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement);
-    nsEventListenerManager* manager = target->GetExistingListenerManager();
+    EventListenerManager* manager = target->GetExistingListenerManager();
     if (manager) {
       manager->RemoveEventListenerByType(mTextListener,
         NS_LITERAL_STRING("keydown"),
-        dom::TrustedEventsAtSystemGroupBubble());
+        TrustedEventsAtSystemGroupBubble());
       manager->RemoveEventListenerByType(mTextListener,
         NS_LITERAL_STRING("keypress"),
-        dom::TrustedEventsAtSystemGroupBubble());
+        TrustedEventsAtSystemGroupBubble());
       manager->RemoveEventListenerByType(mTextListener,
         NS_LITERAL_STRING("keyup"),
-        dom::TrustedEventsAtSystemGroupBubble());
+        TrustedEventsAtSystemGroupBubble());
     }
 
     NS_RELEASE(mTextListener);
     mTextListener = nullptr;
   }
 
   mBoundFrame = nullptr;
 
@@ -1925,27 +1925,27 @@ nsTextEditorState::SetValue(const nsAStr
   mTextCtrlElement->OnValueChanged(!!mRootNode);
 }
 
 void
 nsTextEditorState::InitializeKeyboardEventListeners()
 {
   //register key listeners
   nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement);
-  nsEventListenerManager* manager = target->GetOrCreateListenerManager();
+  EventListenerManager* manager = target->GetOrCreateListenerManager();
   if (manager) {
     manager->AddEventListenerByType(mTextListener,
                                     NS_LITERAL_STRING("keydown"),
-                                    dom::TrustedEventsAtSystemGroupBubble());
+                                    TrustedEventsAtSystemGroupBubble());
     manager->AddEventListenerByType(mTextListener,
                                     NS_LITERAL_STRING("keypress"),
-                                    dom::TrustedEventsAtSystemGroupBubble());
+                                    TrustedEventsAtSystemGroupBubble());
     manager->AddEventListenerByType(mTextListener,
                                     NS_LITERAL_STRING("keyup"),
-                                    dom::TrustedEventsAtSystemGroupBubble());
+                                    TrustedEventsAtSystemGroupBubble());
   }
 
   mSelCon->SetScrollableFrame(do_QueryFrame(mBoundFrame->GetFirstPrincipalChild()));
 }
 
 void
 nsTextEditorState::ValueWasChanged(bool aNotify)
 {
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -56,17 +56,16 @@
 #include "nsParserCIID.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIDOMHTMLHeadElement.h"
 #include "nsNameSpaceManager.h"
 #include "nsGenericHTMLElement.h"
 #include "mozilla/css/Loader.h"
 #include "nsIHttpChannel.h"
 #include "nsIFile.h"
-#include "nsEventListenerManager.h"
 #include "nsFrameSelection.h"
 #include "nsISelectionPrivate.h"//for toStringwithformat code
 
 #include "nsContentUtils.h"
 #include "nsJSUtils.h"
 #include "nsIDocumentInlines.h"
 #include "nsIDocumentEncoder.h" //for outputting selection
 #include "nsICachingChannel.h"
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -19,17 +19,17 @@
 #include "nsError.h"
 #include "nsIPresShell.h"
 #include "nsGkAtoms.h"
 #include "mozilla/css/StyleRule.h"
 #include "nsRuleWalker.h"
 #include "mozilla/css/Declaration.h"
 #include "nsCSSProps.h"
 #include "nsCSSParser.h"
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsLayoutUtils.h"
 #include "nsSVGAnimatedTransformList.h"
 #include "nsSVGLength2.h"
 #include "nsSVGNumber2.h"
 #include "nsSVGNumberPair.h"
 #include "nsSVGInteger.h"
 #include "nsSVGIntegerPair.h"
 #include "nsSVGAngle.h"
@@ -662,17 +662,17 @@ nsSVGElement::UnsetAttrInternal(int32_t 
   // Maybe consolidate?
 
   if (aNamespaceID == kNameSpaceID_None) {
     // If this is an svg presentation attribute, remove rule to force an update
     if (IsAttributeMapped(aName))
       mContentStyleRule = nullptr;
 
     if (IsEventAttributeName(aName)) {
-      nsEventListenerManager* manager = GetExistingListenerManager();
+      EventListenerManager* manager = GetExistingListenerManager();
       if (manager) {
         nsIAtom* eventName = GetEventNameForAttr(aName);
         manager->RemoveEventHandler(eventName, EmptyString());
       }
       return;
     }
     
     // Check if this is a length attribute going away
--- a/content/xml/content/src/XMLStylesheetProcessingInstruction.cpp
+++ b/content/xml/content/src/XMLStylesheetProcessingInstruction.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "XMLStylesheetProcessingInstruction.h"
 #include "mozilla/dom/XMLStylesheetProcessingInstructionBinding.h"
+#include "nsContentUtils.h"
 #include "nsNetUtil.h"
 
 namespace mozilla {
 namespace dom {
 
 // nsISupports implementation
 
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(XMLStylesheetProcessingInstruction)
--- a/content/xml/content/src/XMLStylesheetProcessingInstruction.h
+++ b/content/xml/content/src/XMLStylesheetProcessingInstruction.h
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_XMLStylesheetProcessingInstruction_h
 #define mozilla_dom_XMLStylesheetProcessingInstruction_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/ProcessingInstruction.h"
+#include "nsIURI.h"
 #include "nsStyleLinkElement.h"
 
 namespace mozilla {
 namespace dom {
 
 class XMLStylesheetProcessingInstruction MOZ_FINAL
 : public ProcessingInstruction
 , public nsStyleLinkElement
--- a/content/xml/document/src/XMLDocument.cpp
+++ b/content/xml/document/src/XMLDocument.cpp
@@ -28,17 +28,17 @@
 #include "nsNetUtil.h"
 #include "nsError.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrincipal.h"
 #include "nsLayoutCID.h"
 #include "mozilla/dom/Attr.h"
 #include "nsCExternalHandlerService.h"
 #include "nsMimeTypes.h"
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsContentUtils.h"
 #include "nsThreadUtils.h"
 #include "nsJSUtils.h"
 #include "nsCRT.h"
 #include "nsIAuthPrompt.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentPolicyUtils.h"
 #include "nsIDOMUserDataHandler.h"
@@ -394,17 +394,17 @@ XMLDocument::Load(const nsAString& aUrl,
 
   // Partial Reset, need to restore principal for security reasons and
   // event listener manager so that load listeners etc. will
   // remain. This should be done before the security check is done to
   // ensure that the document is reset even if the new document can't
   // be loaded.  Note that we need to hold a strong ref to |principal|
   // here, because ResetToURI will null out our node principal before
   // setting the new one.
-  nsRefPtr<nsEventListenerManager> elm(mListenerManager);
+  nsRefPtr<EventListenerManager> elm(mListenerManager);
   mListenerManager = nullptr;
 
   // When we are called from JS we can find the load group for the page,
   // and add ourselves to it. This way any pending requests
   // will be automatically aborted if the user leaves the page.
 
   nsCOMPtr<nsILoadGroup> loadGroup;
   if (callingDoc) {
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -28,17 +28,17 @@
 #include "nsIDOMElement.h"
 #include "nsIDOMEventListener.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMXULCommandDispatcher.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMElementCSSInlineStyle.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsIDocument.h"
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsEventStateManager.h"
 #include "nsFocusManager.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsIJSRuntimeService.h"
 #include "nsNameSpaceManager.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIPresShell.h"
@@ -70,17 +70,16 @@
 #include "nsRuleWalker.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsCSSParser.h"
 #include "nsIListBoxObject.h"
 #include "nsContentUtils.h"
 #include "nsContentList.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/MouseEvents.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsPIDOMWindow.h"
 #include "nsJSPrincipals.h"
 #include "nsDOMAttributeMap.h"
 #include "nsGkAtoms.h"
 #include "nsXULContentUtils.h"
 #include "nsNodeUtils.h"
 #include "nsFrameLoader.h"
@@ -478,17 +477,17 @@ nsXULElement::GetElementsByAttributeNS(c
                           attrValue,
                           true,
                           attrAtom,
                           nameSpaceId);
 
     return list.forget();
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsXULElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer)
 {
     // XXXbz sXBL/XBL2 issue: should we instead use GetCurrentDoc()
     // here, override BindToTree for those classes and munge event
     // listeners there?
     nsIDocument* doc = OwnerDoc();
 
     nsPIDOMWindow *window;
@@ -1675,27 +1674,27 @@ nsXULElement::AddPopupListener(nsIAtom* 
     if (HasFlag(listenerFlag)) {
         return NS_OK;
     }
 
     nsCOMPtr<nsIDOMEventListener> listener =
       new nsXULPopupListener(this, isContext);
 
     // Add the popup as a listener on this element.
-    nsEventListenerManager* manager = GetOrCreateListenerManager();
+    EventListenerManager* manager = GetOrCreateListenerManager();
     SetFlags(listenerFlag);
 
     if (isContext) {
       manager->AddEventListenerByType(listener,
                                       NS_LITERAL_STRING("contextmenu"),
-                                      dom::TrustedEventsAtSystemGroupBubble());
+                                      TrustedEventsAtSystemGroupBubble());
     } else {
       manager->AddEventListenerByType(listener,
                                       NS_LITERAL_STRING("mousedown"),
-                                      dom::TrustedEventsAtSystemGroupBubble());
+                                      TrustedEventsAtSystemGroupBubble());
     }
     return NS_OK;
 }
 
 nsEventStates
 nsXULElement::IntrinsicState() const
 {
     nsEventStates state = nsStyledElement::IntrinsicState();
--- a/content/xul/content/src/nsXULElement.h
+++ b/content/xul/content/src/nsXULElement.h
@@ -7,27 +7,26 @@
 
   The base XUL element class and associates.
 
 */
 
 #ifndef nsXULElement_h__
 #define nsXULElement_h__
 
-// XXX because nsEventListenerManager has broken includes
+#include "js/Tracer.h"
 #include "mozilla/Attributes.h"
 #include "nsIDOMEvent.h"
 #include "nsIServiceManager.h"
 #include "nsIAtom.h"
 #include "nsINodeInfo.h"
 #include "nsIControllers.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMXULMultSelectCntrlEl.h"
-#include "nsEventListenerManager.h"
 #include "nsIRDFCompositeDataSource.h"
 #include "nsIRDFResource.h"
 #include "nsIURI.h"
 #include "nsIXULTemplateBuilder.h"
 #include "nsIBoxObject.h"
 #include "nsLayoutCID.h"
 #include "nsAttrAndChildArray.h"
 #include "nsGkAtoms.h"
@@ -40,20 +39,22 @@
 
 class nsIDocument;
 class nsString;
 class nsIDocShell;
 class nsXULPrototypeDocument;
 
 class nsIObjectInputStream;
 class nsIObjectOutputStream;
+class nsIOffThreadScriptReceiver;
 class nsXULPrototypeNode;
 typedef nsTArray<nsRefPtr<nsXULPrototypeNode> > nsPrototypeArray;
 
 namespace mozilla {
+class EventListenerManager;
 namespace css {
 class StyleRule;
 }
 }
 
 ////////////////////////////////////////////////////////////////////////
 
 #ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING
@@ -656,18 +657,19 @@ protected:
 
     virtual void UpdateEditableState(bool aNotify) MOZ_OVERRIDE;
 
     virtual bool ParseAttribute(int32_t aNamespaceID,
                                   nsIAtom* aAttribute,
                                   const nsAString& aValue,
                                   nsAttrValue& aResult) MOZ_OVERRIDE;
 
-    virtual nsEventListenerManager*
-      GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer) MOZ_OVERRIDE;
+    virtual mozilla::EventListenerManager*
+      GetEventListenerManagerForAttr(nsIAtom* aAttrName,
+                                     bool* aDefer) MOZ_OVERRIDE;
   
     /**
      * Add a listener for the specified attribute, if appropriate.
      */
     void AddListenerFor(const nsAttrName& aName,
                         bool aCompileEventHandlers);
     void MaybeAddPopupListener(nsIAtom* aLocalName);
 
--- a/content/xul/templates/src/nsXULTemplateBuilder.cpp
+++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp
@@ -32,16 +32,17 @@
 #include "nsIRDFCompositeDataSource.h"
 #include "nsIRDFInferDataSource.h"
 #include "nsIRDFContainerUtils.h"
 #include "nsIXULDocument.h"
 #include "nsIXULTemplateBuilder.h"
 #include "nsIXULBuilderListener.h"
 #include "nsIRDFRemoteDataSource.h"
 #include "nsIRDFService.h"
+#include "nsIScriptContext.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIServiceManager.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIMutableArray.h"
 #include "nsIURL.h"
 #include "nsIXPConnect.h"
 #include "nsContentCID.h"
 #include "nsNameSpaceManager.h"
--- a/dom/activities/interfaces/moz.build
+++ b/dom/activities/interfaces/moz.build
@@ -2,16 +2,14 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPIDL_SOURCES += [
     'nsIActivityProxy.idl',
     'nsIActivityUIGlue.idl',
-    'nsIDOMActivityHandlerDescription.idl',
     'nsIDOMActivityOptions.idl',
     'nsIDOMActivityRequestHandler.idl',
-    'nsIDOMNavigatorActivities.idl',
 ]
 
 XPIDL_MODULE = 'dom_activities'
 
deleted file mode 100644
--- a/dom/activities/interfaces/nsIDOMActivityHandlerDescription.idl
+++ /dev/null
@@ -1,19 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "domstubs.idl"
-
-/**
-  * The constructor will accept the name as a parameter.
-  */
-[scriptable, uuid(1601d370-08d9-47b7-8802-d4291533b843)]
-interface nsIDOMMozActivityHandlerDescription : nsISupports
-{
-    attribute DOMString name;
-    attribute DOMString href;
-    attribute DOMString disposition;
-    attribute boolean   returnValue;
-    // The |filters| property can be null.
-    attribute jsval     filters;
-};
deleted file mode 100644
--- a/dom/activities/interfaces/nsIDOMNavigatorActivities.idl
+++ /dev/null
@@ -1,20 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "domstubs.idl"
-
-interface nsIDOMMozActivityHandlerDescription;
-interface nsIDOMDOMRequest;
-
-/**
-  * This interface is implemented by the Navigator object.
-  */
-[scriptable, uuid(e7cb7d2f-11d2-4783-a8b0-bddabb4a5c03)]
-interface nsIDOMMozNavigatorActivities : nsISupports
-{
-    nsIDOMDOMRequest mozRegisterActivityHandler(in nsIDOMMozActivityHandlerDescription description);
-    void mozUnregisterActivityHandler(in nsIDOMMozActivityHandlerDescription description);
-
-    bool mozIsActivityHandlerRegistered(in nsIDOMMozActivityHandlerDescription description);
-};
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -46,25 +46,25 @@
 #include "nsDOMClassInfo.h"
 #include "nsJSEnvironment.h"
 #include "ScriptSettings.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Likely.h"
 #include "mozilla/unused.h"
 
 // Other Classes
-#include "nsEventListenerManager.h"
 #include "mozilla/dom/BarProps.h"
 #include "nsContentCID.h"
 #include "nsLayoutStatics.h"
 #include "nsCCUncollectableMarker.h"
 #include "mozilla/dom/workers/Workers.h"
 #include "nsJSPrincipals.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Debug.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/MouseEvents.h"
 #include "AudioChannelService.h"
 
 // Interfaces Needed
 #include "nsIFrame.h"
 #include "nsCanvasFrame.h"
 #include "nsIWidget.h"
 #include "nsIWidgetListener.h"
@@ -1669,17 +1669,17 @@ MarkXBLHandlers(nsXBLPrototypeHandler* a
   return PL_DHASH_NEXT;
 }
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsGlobalWindow)
   if (tmp->IsBlackForCC(false)) {
     if (tmp->mCachedXBLPrototypeHandlers) {
       tmp->mCachedXBLPrototypeHandlers->Enumerate(MarkXBLHandlers, nullptr);
     }
-    if (nsEventListenerManager* elm = tmp->GetExistingListenerManager()) {
+    if (EventListenerManager* elm = tmp->GetExistingListenerManager()) {
       elm->MarkForCC();
     }
     tmp->UnmarkGrayTimers();
     return true;
   }
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsGlobalWindow)
@@ -9154,17 +9154,17 @@ nsGlobalWindow::Btoa(const nsAString& aB
 // nsGlobalWindow::nsIDOMEventTarget
 //*****************************************************************************
 
 NS_IMETHODIMP
 nsGlobalWindow::RemoveEventListener(const nsAString& aType,
                                     nsIDOMEventListener* aListener,
                                     bool aUseCapture)
 {
-  if (nsRefPtr<nsEventListenerManager> elm = GetExistingListenerManager()) {
+  if (nsRefPtr<EventListenerManager> elm = GetExistingListenerManager()) {
     elm->RemoveEventListener(aType, aListener, aUseCapture);
   }
   return NS_OK;
 }
 
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsGlobalWindow)
 
 NS_IMETHODIMP
@@ -9215,17 +9215,17 @@ nsGlobalWindow::AddEventListener(const n
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   if (!aWantsUntrusted &&
       (aOptionalArgc < 2 && !nsContentUtils::IsChromeDoc(mDoc))) {
     aWantsUntrusted = true;
   }
 
-  nsEventListenerManager* manager = GetOrCreateListenerManager();
+  EventListenerManager* manager = GetOrCreateListenerManager();
   NS_ENSURE_STATE(manager);
   manager->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
   return NS_OK;
 }
 
 void
 nsGlobalWindow::AddEventListener(const nsAString& aType,
                                  EventListener* aListener,
@@ -9241,17 +9241,17 @@ nsGlobalWindow::AddEventListener(const n
 
   bool wantsUntrusted;
   if (aWantsUntrusted.IsNull()) {
     wantsUntrusted = !nsContentUtils::IsChromeDoc(mDoc);
   } else {
     wantsUntrusted = aWantsUntrusted.Value();
   }
 
-  nsEventListenerManager* manager = GetOrCreateListenerManager();
+  EventListenerManager* manager = GetOrCreateListenerManager();
   if (!manager) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
   manager->AddEventListener(aType, aListener, aUseCapture, wantsUntrusted);
 }
 
 NS_IMETHODIMP
@@ -9275,30 +9275,30 @@ nsGlobalWindow::AddSystemEventListener(c
       (aOptionalArgc < 2 && !nsContentUtils::IsChromeDoc(mDoc))) {
     aWantsUntrusted = true;
   }
 
   return NS_AddSystemEventListener(this, aType, aListener, aUseCapture,
                                    aWantsUntrusted);
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsGlobalWindow::GetOrCreateListenerManager()
 {
   FORWARD_TO_INNER_CREATE(GetOrCreateListenerManager, (), nullptr);
 
   if (!mListenerManager) {
     mListenerManager =
-      new nsEventListenerManager(static_cast<EventTarget*>(this));
+      new EventListenerManager(static_cast<EventTarget*>(this));
   }
 
   return mListenerManager;
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsGlobalWindow::GetExistingListenerManager() const
 {
   FORWARD_TO_INNER(GetExistingListenerManager, (), nullptr);
 
   return mListenerManager;
 }
 
 nsIScriptContext*
@@ -12864,30 +12864,30 @@ CollectSizeAndListenerCount(
 
   nsDOMEventTargetHelper* et = aEntry->GetKey();
 
   if (nsCOMPtr<nsISizeOfEventTarget> iSizeOf = do_QueryObject(et)) {
     windowSizes->mDOMEventTargetsSize +=
       iSizeOf->SizeOfEventTargetIncludingThis(windowSizes->mMallocSizeOf);
   }
 
-  if (nsEventListenerManager* elm = et->GetExistingListenerManager()) {
+  if (EventListenerManager* elm = et->GetExistingListenerManager()) {
     windowSizes->mDOMEventListenersCount += elm->ListenerCount();
   }
 
   return PL_DHASH_NEXT;
 }
 
 void
 nsGlobalWindow::AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
 {
   aWindowSizes->mDOMOtherSize += aWindowSizes->mMallocSizeOf(this);
 
   if (IsInnerWindow()) {
-    nsEventListenerManager* elm = GetExistingListenerManager();
+    EventListenerManager* elm = GetExistingListenerManager();
     if (elm) {
       aWindowSizes->mDOMOtherSize +=
         elm->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf);
       aWindowSizes->mDOMEventListenersCount +=
         elm->ListenerCount();
     }
     if (mDoc) {
       mDoc->DocAddSizeOfIncludingThis(aWindowSizes);
@@ -13592,61 +13592,61 @@ nsGlobalWindow::DisableNetworkEvent(uint
       handler = new EventHandlerNonNull(callable, GetIncumbentGlobal());     \
     }                                                                        \
     SetOn##name_(handler);                                                   \
     return NS_OK;                                                            \
   }
 #define ERROR_EVENT(name_, id_, type_, struct_)                              \
   NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx,                  \
                                              JS::MutableHandle<JS::Value> vp) { \
-    nsEventListenerManager *elm = GetExistingListenerManager();              \
+    EventListenerManager *elm = GetExistingListenerManager();                \
     if (elm) {                                                               \
       OnErrorEventHandlerNonNull* h = elm->GetOnErrorEventHandler();         \
       if (h) {                                                               \
         vp.setObject(*h->Callable());                                        \
         return NS_OK;                                                        \
       }                                                                      \
     }                                                                        \
     vp.setNull();                                                            \
     return NS_OK;                                                            \
   }                                                                          \
   NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx,                  \
                                              JS::Handle<JS::Value> v) {      \
-    nsEventListenerManager *elm = GetOrCreateListenerManager();              \
+    EventListenerManager *elm = GetOrCreateListenerManager();                \
     if (!elm) {                                                              \
       return NS_ERROR_OUT_OF_MEMORY;                                         \
     }                                                                        \
                                                                              \
     nsRefPtr<OnErrorEventHandlerNonNull> handler;                            \
     JS::Rooted<JSObject*> callable(cx);                                      \
     if (v.isObject() &&                                                      \
         JS_ObjectIsCallable(cx, callable = &v.toObject())) {                 \
       handler = new OnErrorEventHandlerNonNull(callable, GetIncumbentGlobal()); \
     }                                                                        \
     elm->SetEventHandler(handler);                                           \
     return NS_OK;                                                            \
   }
 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_)                       \
   NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx,                  \
                                              JS::MutableHandle<JS::Value> vp) { \
-    nsEventListenerManager *elm = GetExistingListenerManager();              \
+    EventListenerManager *elm = GetExistingListenerManager();                \
     if (elm) {                                                               \
       OnBeforeUnloadEventHandlerNonNull* h =                                 \
         elm->GetOnBeforeUnloadEventHandler();                                \
       if (h) {                                                               \
         vp.setObject(*h->Callable());                                        \
         return NS_OK;                                                        \
       }                                                                      \
     }                                                                        \
     vp.setNull();                                                            \
     return NS_OK;                                                            \
   }                                                                          \
   NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx,                  \
                                              JS::Handle<JS::Value> v) {      \
-    nsEventListenerManager *elm = GetOrCreateListenerManager();              \
+    EventListenerManager *elm = GetOrCreateListenerManager();                \
     if (!elm) {                                                              \
       return NS_ERROR_OUT_OF_MEMORY;                                         \
     }                                                                        \
                                                                              \
     nsRefPtr<OnBeforeUnloadEventHandlerNonNull> handler;                     \
     JS::Rooted<JSObject*> callable(cx);                                      \
     if (v.isObject() &&                                                      \
         JS_ObjectIsCallable(cx, callable = &v.toObject())) {                 \
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -27,17 +27,17 @@
 #include "nsIDOMEventTarget.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIDOMJSWindow.h"
 #include "nsIDOMChromeWindow.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsITimer.h"
 #include "nsIDOMModalContentWindow.h"
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsIPrincipal.h"
 #include "nsSize.h"
 #include "mozFlushType.h"
 #include "prclist.h"
 #include "nsIDOMStorageEvent.h"
 #include "nsFrameMessageManager.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/TimeStamp.h"
@@ -379,21 +379,21 @@ public:
   NS_DECL_NSIDOMWINDOWPERFORMANCE
 
   // nsIDOMJSWindow
   NS_DECL_NSIDOMJSWINDOW
 
   // nsIDOMEventTarget
   NS_DECL_NSIDOMEVENTTARGET
 
-  virtual nsEventListenerManager*
-  GetExistingListenerManager() const MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetExistingListenerManager() const MOZ_OVERRIDE;
 
-  virtual nsEventListenerManager*
-  GetOrCreateListenerManager() MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetOrCreateListenerManager() MOZ_OVERRIDE;
 
   using mozilla::dom::EventTarget::RemoveEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 bool aUseCapture,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
   virtual nsIDOMWindow* GetOwnerGlobal() MOZ_OVERRIDE
@@ -722,49 +722,49 @@ public:
   // Enable/disable updates for gamepad input.
   void EnableGamepadUpdates();
   void DisableGamepadUpdates();
 
 
 #define EVENT(name_, id_, type_, struct_)                                     \
   mozilla::dom::EventHandlerNonNull* GetOn##name_()                           \
   {                                                                           \
-    nsEventListenerManager *elm = GetExistingListenerManager();               \
+    mozilla::EventListenerManager* elm = GetExistingListenerManager();        \
     return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString())    \
                : nullptr;                                                     \
   }                                                                           \
   void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler)               \
   {                                                                           \
-    nsEventListenerManager *elm = GetOrCreateListenerManager();               \
+    mozilla::EventListenerManager* elm = GetOrCreateListenerManager();        \
     if (elm) {                                                                \
       elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler);     \
     }                                                                         \
   }
 #define ERROR_EVENT(name_, id_, type_, struct_)                               \
   mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_()                    \
   {                                                                           \
-    nsEventListenerManager *elm = GetExistingListenerManager();               \
+    mozilla::EventListenerManager* elm = GetExistingListenerManager();        \
     return elm ? elm->GetOnErrorEventHandler() : nullptr;                     \
   }                                                                           \
   void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler)        \
   {                                                                           \
-    nsEventListenerManager *elm = GetOrCreateListenerManager();               \
+    mozilla::EventListenerManager* elm = GetOrCreateListenerManager();        \
     if (elm) {                                                                \
       elm->SetEventHandler(handler);                                          \
     }                                                                         \
   }
 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_)                        \
   mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOn##name_()             \
   {                                                                           \
-    nsEventListenerManager *elm = GetExistingListenerManager();               \
+    mozilla::EventListenerManager* elm = GetExistingListenerManager();        \
     return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr;              \
   }                                                                           \
   void SetOn##name_(mozilla::dom::OnBeforeUnloadEventHandlerNonNull* handler) \
   {                                                                           \
-    nsEventListenerManager *elm = GetOrCreateListenerManager();               \
+    mozilla::EventListenerManager* elm = GetOrCreateListenerManager();        \
     if (elm) {                                                                \
       elm->SetEventHandler(handler);                                          \
     }                                                                         \
   }
 #define WINDOW_ONLY_EVENT EVENT
 #define TOUCH_EVENT EVENT
 #include "nsEventNameList.h"
 #undef TOUCH_EVENT
@@ -1459,17 +1459,17 @@ protected:
   nsRefPtr<mozilla::dom::Console> mConsole;
 
   nsCOMPtr<nsIDOMStorage>      mLocalStorage;
   nsCOMPtr<nsIDOMStorage>      mSessionStorage;
 
   nsCOMPtr<nsIXPConnectJSObjectHolder> mInnerWindowHolder;
 
   // These member variable are used only on inner windows.
-  nsRefPtr<nsEventListenerManager> mListenerManager;
+  nsRefPtr<mozilla::EventListenerManager> mListenerManager;
   // mTimeouts is generally sorted by mWhen, unless mTimeoutInsertionPoint is
   // non-null.  In that case, the dummy timeout pointed to by
   // mTimeoutInsertionPoint may have a later mWhen than some of the timeouts
   // that come after it.
   mozilla::LinkedList<nsTimeout> mTimeouts;
   // If mTimeoutInsertionPoint is non-null, insertions should happen after it.
   // This is a dummy timeout at the moment; if that ever changes, the logic in
   // ResetTimersForNonBackgroundWindow needs to change.
--- a/dom/base/nsWindowRoot.cpp
+++ b/dom/base/nsWindowRoot.cpp
@@ -1,18 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/BasicEvents.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsCOMPtr.h"
 #include "nsWindowRoot.h"
 #include "nsPIDOMWindow.h"
-#include "nsEventListenerManager.h"
 #include "nsPresContext.h"
 #include "nsLayoutCID.h"
 #include "nsContentCID.h"
 #include "nsString.h"
 #include "nsEventDispatcher.h"
 #include "nsGlobalWindow.h"
 #include "nsFocusManager.h"
 #include "nsIContent.h"
@@ -59,17 +59,17 @@ NS_INTERFACE_MAP_END
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsWindowRoot)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsWindowRoot)
 
 NS_IMPL_DOMTARGET_DEFAULTS(nsWindowRoot)
 
 NS_IMETHODIMP
 nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture)
 {
-  if (nsRefPtr<nsEventListenerManager> elm = GetExistingListenerManager()) {
+  if (nsRefPtr<EventListenerManager> elm = GetExistingListenerManager()) {
     elm->RemoveEventListener(aType, aListener, aUseCapture);
   }
   return NS_OK;
 }
 
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsWindowRoot)
 
 NS_IMETHODIMP
@@ -99,31 +99,31 @@ nsWindowRoot::AddEventListener(const nsA
                                bool aUseCapture, bool aWantsUntrusted,
                                uint8_t aOptionalArgc)
 {
   NS_ASSERTION(!aWantsUntrusted || aOptionalArgc > 1,
                "Won't check if this is chrome, you want to set "
                "aWantsUntrusted to false or make the aWantsUntrusted "
                "explicit by making optional_argc non-zero.");
 
-  nsEventListenerManager* elm = GetOrCreateListenerManager();
+  EventListenerManager* elm = GetOrCreateListenerManager();
   NS_ENSURE_STATE(elm);
   elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
   return NS_OK;
 }
 
 void
 nsWindowRoot::AddEventListener(const nsAString& aType,
                                 EventListener* aListener,
                                 bool aUseCapture,
                                 const Nullable<bool>& aWantsUntrusted,
                                 ErrorResult& aRv)
 {
   bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value();
-  nsEventListenerManager* elm = GetOrCreateListenerManager();
+  EventListenerManager* elm = GetOrCreateListenerManager();
   if (!elm) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
   elm->AddEventListener(aType, aListener, aUseCapture, wantsUntrusted);
 }
 
 
@@ -138,28 +138,28 @@ nsWindowRoot::AddSystemEventListener(con
                "Won't check if this is chrome, you want to set "
                "aWantsUntrusted to false or make the aWantsUntrusted "
                "explicit by making optional_argc non-zero.");
 
   return NS_AddSystemEventListener(this, aType, aListener, aUseCapture,
                                    aWantsUntrusted);
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsWindowRoot::GetOrCreateListenerManager()
 {
   if (!mListenerManager) {
     mListenerManager =
-      new nsEventListenerManager(static_cast<EventTarget*>(this));
+      new EventListenerManager(static_cast<EventTarget*>(this));
   }
 
   return mListenerManager;
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsWindowRoot::GetExistingListenerManager() const
 {
   return mListenerManager;
 }
 
 nsIScriptContext*
 nsWindowRoot::GetContextForEventHandlers(nsresult* aRv)
 {
--- a/dom/base/nsWindowRoot.h
+++ b/dom/base/nsWindowRoot.h
@@ -4,40 +4,40 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsWindowRoot_h__
 #define nsWindowRoot_h__
 
 class nsPIDOMWindow;
 class nsIDOMEventListener;
-class nsEventListenerManager;
 class nsIDOMEvent;
 class nsEventChainPreVisitor;
 class nsEventChainPostVisitor;
 
 #include "mozilla/Attributes.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsIDOMEventTarget.h"
 #include "nsPIWindowRoot.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsAutoPtr.h"
 
 class nsWindowRoot : public nsPIWindowRoot
 {
 public:
   nsWindowRoot(nsPIDOMWindow* aWindow);
   virtual ~nsWindowRoot();
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIDOMEVENTTARGET
 
-  virtual nsEventListenerManager*
-  GetExistingListenerManager() const MOZ_OVERRIDE;
-  virtual nsEventListenerManager*
-  GetOrCreateListenerManager() MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetExistingListenerManager() const MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetOrCreateListenerManager() MOZ_OVERRIDE;
 
   using mozilla::dom::EventTarget::RemoveEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 bool aUseCapture,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
 
@@ -60,19 +60,18 @@ public:
   virtual nsIDOMWindow* GetOwnerGlobal() MOZ_OVERRIDE;
 
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsWindowRoot,
                                                          nsIDOMEventTarget)
 
 protected:
   // Members
   nsCOMPtr<nsPIDOMWindow> mWindow;
-  nsRefPtr<nsEventListenerManager> mListenerManager; // [Strong]. We own the manager, which owns event listeners attached
-                                                      // to us.
-
+  // We own the manager, which owns event listeners attached to us.
+  nsRefPtr<mozilla::EventListenerManager> mListenerManager; // [Strong]
   nsCOMPtr<nsIDOMNode> mPopupNode; // [OWNER]
 
   nsCOMPtr<mozilla::dom::EventTarget> mParent;
 };
 
 extern already_AddRefed<mozilla::dom::EventTarget>
 NS_NewWindowRoot(nsPIDOMWindow* aWindow);
 
--- a/dom/devicestorage/DeviceStorage.h
+++ b/dom/devicestorage/DeviceStorage.h
@@ -22,16 +22,17 @@
 #define DEVICESTORAGE_APPS       "apps"
 #define DEVICESTORAGE_SDCARD     "sdcard"
 #define DEVICESTORAGE_CRASHES    "crashes"
 
 class DeviceStorageFile;
 class nsIInputStream;
 
 namespace mozilla {
+class EventListenerManager;
 namespace dom {
 class DeviceStorageEnumerationParameters;
 class DOMCursor;
 class DOMRequest;
 class Promise;
 class DeviceStorageFileSystem;
 } // namespace dom
 namespace ipc {
@@ -165,20 +166,20 @@ public:
   typedef nsTArray<nsString> VolumeNameArray;
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIDOMDEVICESTORAGE
 
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIDOMEVENTTARGET
 
-  virtual nsEventListenerManager*
-  GetExistingListenerManager() const MOZ_OVERRIDE;
-  virtual nsEventListenerManager*
-  GetOrCreateListenerManager() MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetExistingListenerManager() const MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetOrCreateListenerManager() MOZ_OVERRIDE;
 
   virtual void
   AddEventListener(const nsAString& aType,
                    mozilla::dom::EventListener* aListener,
                    bool aUseCapture,
                    const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                    ErrorResult& aRv) MOZ_OVERRIDE;
 
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -15,16 +15,17 @@
 #include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
 #include "mozilla/dom/Directory.h"
 #include "mozilla/dom/FileSystemUtils.h"
 #include "mozilla/dom/ipc/Blob.h"
 #include "mozilla/dom/PBrowserChild.h"
 #include "mozilla/dom/PContentPermissionRequestChild.h"
 #include "mozilla/dom/PermissionMessageUtils.h"
 #include "mozilla/dom/Promise.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/LazyIdleThread.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Scoped.h"
 #include "mozilla/Services.h"
 
 #include "nsAutoPtr.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIFile.h"
@@ -4298,23 +4299,23 @@ nsDOMDeviceStorage::DispatchDOMEvent(Wid
                                      nsEventStatus* aEventStatus)
 {
   return nsDOMEventTargetHelper::DispatchDOMEvent(aEvent,
                                                   aDOMEvent,
                                                   aPresContext,
                                                   aEventStatus);
 }
 
-nsEventListenerManager *
+EventListenerManager*
 nsDOMDeviceStorage::GetOrCreateListenerManager()
 {
   return nsDOMEventTargetHelper::GetOrCreateListenerManager();
 }
 
-nsEventListenerManager *
+EventListenerManager*
 nsDOMDeviceStorage::GetExistingListenerManager() const
 {
   return nsDOMEventTargetHelper::GetExistingListenerManager();
 }
 
 nsIScriptContext *
 nsDOMDeviceStorage::GetContextForEventHandlers(nsresult *aRv)
 {
rename from dom/events/nsAsyncDOMEvent.cpp
rename to dom/events/AsyncEventDispatcher.cpp
--- a/dom/events/nsAsyncDOMEvent.cpp
+++ b/dom/events/AsyncEventDispatcher.cpp
@@ -1,36 +1,44 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsAsyncDOMEvent.h"
-#include "nsIDOMEvent.h"
-#include "nsContentUtils.h"
-#include "nsEventDispatcher.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 #include "mozilla/dom/EventTarget.h"
+#include "nsContentUtils.h"
+#include "nsEventDispatcher.h"
+#include "nsIDOMEvent.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
+
+using namespace dom;
 
-nsAsyncDOMEvent::nsAsyncDOMEvent(nsINode* aEventNode, WidgetEvent& aEvent)
-  : mEventNode(aEventNode), mDispatchChromeOnly(false)
+/******************************************************************************
+ * mozilla::AsyncEventDispatcher
+ ******************************************************************************/
+
+AsyncEventDispatcher::AsyncEventDispatcher(nsINode* aEventNode,
+                                           WidgetEvent& aEvent)
+  : mEventNode(aEventNode)
+  , mDispatchChromeOnly(false)
 {
   MOZ_ASSERT(mEventNode);
   nsEventDispatcher::CreateEvent(aEventNode, nullptr, &aEvent, EmptyString(),
                                  getter_AddRefs(mEvent));
   NS_ASSERTION(mEvent, "Should never fail to create an event");
   mEvent->DuplicatePrivateData();
   mEvent->SetTrusted(aEvent.mFlags.mIsTrusted);
 }
 
-NS_IMETHODIMP nsAsyncDOMEvent::Run()
+NS_IMETHODIMP
+AsyncEventDispatcher::Run()
 {
   if (mEvent) {
     if (mDispatchChromeOnly) {
       MOZ_ASSERT(mEvent->InternalDOMEvent()->IsTrusted());
 
       nsCOMPtr<nsIDocument> ownerDoc = mEventNode->OwnerDoc();
       nsPIDOMWindow* window = ownerDoc->GetWindow();
       if (!window) {
@@ -57,24 +65,32 @@ NS_IMETHODIMP nsAsyncDOMEvent::Run()
       nsContentUtils::DispatchTrustedEvent(doc, mEventNode, mEventType,
                                            mBubbles, false);
     }
   }
 
   return NS_OK;
 }
 
-nsresult nsAsyncDOMEvent::PostDOMEvent()
+nsresult
+AsyncEventDispatcher::PostDOMEvent()
 {
   return NS_DispatchToCurrentThread(this);
 }
 
-void nsAsyncDOMEvent::RunDOMEventWhenSafe()
+void
+AsyncEventDispatcher::RunDOMEventWhenSafe()
 {
   nsContentUtils::AddScriptRunner(this);
 }
 
-nsLoadBlockingAsyncDOMEvent::~nsLoadBlockingAsyncDOMEvent()
+/******************************************************************************
+ * mozilla::LoadBlockingAsyncEventDispatcher
+ ******************************************************************************/
+
+LoadBlockingAsyncEventDispatcher::~LoadBlockingAsyncEventDispatcher()
 {
   if (mBlockedDoc) {
     mBlockedDoc->UnblockOnload(true);
   }
 }
+
+} // namespace mozilla
rename from dom/events/nsAsyncDOMEvent.h
rename to dom/events/AsyncEventDispatcher.h
--- a/dom/events/nsAsyncDOMEvent.h
+++ b/dom/events/AsyncEventDispatcher.h
@@ -1,76 +1,90 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef nsAsyncDOMEvent_h___
-#define nsAsyncDOMEvent_h___
+#ifndef mozilla_AsyncEventDispatcher_h_
+#define mozilla_AsyncEventDispatcher_h_
 
 #include "mozilla/Attributes.h"
 #include "nsCOMPtr.h"
-#include "nsThreadUtils.h"
-#include "nsINode.h"
+#include "nsIDocument.h"
 #include "nsIDOMEvent.h"
+#include "nsINode.h"
 #include "nsString.h"
-#include "nsIDocument.h"
+#include "nsThreadUtils.h"
+
+namespace mozilla {
 
 /**
  * Use nsAsyncDOMEvent to fire a DOM event that requires safe a stable DOM.
  * For example, you may need to fire an event from within layout, but
  * want to ensure that the event handler doesn't mutate the DOM at
  * the wrong time, in order to avoid resulting instability.
  */
  
-class nsAsyncDOMEvent : public nsRunnable {
+class AsyncEventDispatcher : public nsRunnable
+{
 public:
-  nsAsyncDOMEvent(nsINode *aEventNode, const nsAString& aEventType,
-                  bool aBubbles, bool aDispatchChromeOnly)
-    : mEventNode(aEventNode), mEventType(aEventType),
-      mBubbles(aBubbles),
-      mDispatchChromeOnly(aDispatchChromeOnly)
-  { }
+  AsyncEventDispatcher(nsINode* aEventNode, const nsAString& aEventType,
+                       bool aBubbles, bool aDispatchChromeOnly)
+    : mEventNode(aEventNode)
+    , mEventType(aEventType)
+    , mBubbles(aBubbles)
+    , mDispatchChromeOnly(aDispatchChromeOnly)
+  {
+  }
 
-  nsAsyncDOMEvent(nsINode *aEventNode, nsIDOMEvent *aEvent)
-    : mEventNode(aEventNode), mEvent(aEvent), mDispatchChromeOnly(false)
-  { }
+  AsyncEventDispatcher(nsINode* aEventNode, nsIDOMEvent* aEvent)
+    : mEventNode(aEventNode)
+    , mEvent(aEvent)
+    , mDispatchChromeOnly(false)
+  {
+  }
 
-  nsAsyncDOMEvent(nsINode* aEventNode, mozilla::WidgetEvent& aEvent);
+  AsyncEventDispatcher(nsINode* aEventNode, WidgetEvent& aEvent);
 
   NS_IMETHOD Run() MOZ_OVERRIDE;
   nsresult PostDOMEvent();
   void RunDOMEventWhenSafe();
 
   nsCOMPtr<nsINode>     mEventNode;
   nsCOMPtr<nsIDOMEvent> mEvent;
   nsString              mEventType;
   bool                  mBubbles;
   bool                  mDispatchChromeOnly;
 };
 
-class nsLoadBlockingAsyncDOMEvent : public nsAsyncDOMEvent {
+class LoadBlockingAsyncEventDispatcher MOZ_FINAL : public AsyncEventDispatcher
+{
 public:
-  nsLoadBlockingAsyncDOMEvent(nsINode *aEventNode, const nsAString& aEventType,
-                              bool aBubbles, bool aDispatchChromeOnly)
-    : nsAsyncDOMEvent(aEventNode, aEventType, aBubbles, aDispatchChromeOnly),
-      mBlockedDoc(aEventNode->OwnerDoc())
+  LoadBlockingAsyncEventDispatcher(nsINode* aEventNode,
+                                   const nsAString& aEventType,
+                                   bool aBubbles, bool aDispatchChromeOnly)
+    : AsyncEventDispatcher(aEventNode, aEventType,
+                           aBubbles, aDispatchChromeOnly)
+    , mBlockedDoc(aEventNode->OwnerDoc())
   {
     if (mBlockedDoc) {
       mBlockedDoc->BlockOnload();
     }
   }
 
-  nsLoadBlockingAsyncDOMEvent(nsINode *aEventNode, nsIDOMEvent *aEvent)
-    : nsAsyncDOMEvent(aEventNode, aEvent),
-      mBlockedDoc(aEventNode->OwnerDoc())
+  LoadBlockingAsyncEventDispatcher(nsINode* aEventNode, nsIDOMEvent* aEvent)
+    : AsyncEventDispatcher(aEventNode, aEvent)
+    , mBlockedDoc(aEventNode->OwnerDoc())
   {
     if (mBlockedDoc) {
       mBlockedDoc->BlockOnload();
     }
   }
   
-  ~nsLoadBlockingAsyncDOMEvent();
+  ~LoadBlockingAsyncEventDispatcher();
 
+private:
   nsCOMPtr<nsIDocument> mBlockedDoc;
 };
 
-#endif
+} // namespace mozilla
+
+#endif // mozilla_AsyncEventDispatcher_h_
rename from dom/events/nsEventListenerManager.cpp
rename to dom/events/EventListenerManager.cpp
--- a/dom/events/nsEventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -1,53 +1,54 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "mozilla/BasicEvents.h"
-#ifdef MOZ_B2G
-#include "mozilla/Hal.h"
-#endif
-#include "mozilla/HalSensor.h"
-
 // Microsoft's API Name hackery sucks
 #undef CreateEvent
 
-#include "nsISupports.h"
+#include "mozilla/BasicEvents.h"
+#include "mozilla/EventListenerManager.h"
+#ifdef MOZ_B2G
+#include "mozilla/Hal.h"
+#endif // #ifdef MOZ_B2G
+#include "mozilla/HalSensor.h"
+#include "mozilla/InternalMutationEvent.h"
+#include "mozilla/MemoryReporting.h"
+#include "mozilla/dom/BindingUtils.h"
+#include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
-#include "nsEventListenerManager.h"
+
+#include "EventListenerService.h"
+#include "nsCOMArray.h"
+#include "nsCOMPtr.h"
+#include "nsContentUtils.h"
+#include "nsDOMCID.h"
+#include "nsError.h"
+#include "nsEventDispatcher.h"
+#include "nsGkAtoms.h"
+#include "nsIContent.h"
+#include "nsIContentSecurityPolicy.h"
+#include "nsIDocument.h"
 #include "nsIDOMEventListener.h"
-#include "nsGkAtoms.h"
-#include "nsPIDOMWindow.h"
 #include "nsIJSEventListener.h"
 #include "nsIScriptGlobalObject.h"
-#include "nsNameSpaceManager.h"
-#include "nsIContent.h"
-#include "mozilla/MemoryReporting.h"
-#include "nsCOMPtr.h"
-#include "nsError.h"
-#include "nsIDocument.h"
-#include "mozilla/InternalMutationEvent.h"
+#include "nsISupports.h"
 #include "nsIXPConnect.h"
-#include "nsDOMCID.h"
-#include "nsContentUtils.h"
 #include "nsJSUtils.h"
-#include "nsEventDispatcher.h"
-#include "nsCOMArray.h"
-#include "nsEventListenerService.h"
-#include "nsIContentSecurityPolicy.h"
-#include "xpcpublic.h"
+#include "nsNameSpaceManager.h"
+#include "nsPIDOMWindow.h"
 #include "nsSandboxFlags.h"
-#include "mozilla/dom/Element.h"
-#include "mozilla/dom/BindingUtils.h"
+#include "xpcpublic.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
-using namespace mozilla::hal;
+namespace mozilla {
+
+using namespace dom;
+using namespace hal;
 
 #define EVENT_TYPE_EQUALS(ls, type, userType, typeString, allEvents) \
   ((ls->mEventType == type &&                                        \
     (ls->mEventType != NS_USER_DEFINED_EVENT ||                      \
     (mIsMainThreadELM && ls->mTypeAtom == userType) ||               \
     (!mIsMainThreadELM && ls->mTypeString.Equals(typeString)))) ||   \
    (allEvents && ls->mAllEvents))
 
@@ -79,78 +80,77 @@ MutationBitForEventType(uint32_t aEventT
     case NS_MUTATION_CHARACTERDATAMODIFIED:
       return NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED;
     default:
       break;
   }
   return 0;
 }
 
-uint32_t nsEventListenerManager::sMainThreadCreatedCount = 0;
+uint32_t EventListenerManager::sMainThreadCreatedCount = 0;
 
-nsEventListenerManager::nsEventListenerManager(EventTarget* aTarget) :
-  mMayHavePaintEventListener(false),
-  mMayHaveMutationListeners(false),
-  mMayHaveCapturingListeners(false),
-  mMayHaveSystemGroupListeners(false),
-  mMayHaveAudioAvailableEventListener(false),
-  mMayHaveTouchEventListener(false),
-  mMayHaveMouseEnterLeaveEventListener(false),
-  mMayHavePointerEnterLeaveEventListener(false),
-  mClearingListeners(false),
-  mIsMainThreadELM(NS_IsMainThread()),
-  mNoListenerForEvent(0),
-  mTarget(aTarget)
+EventListenerManager::EventListenerManager(EventTarget* aTarget)
+  : mMayHavePaintEventListener(false)
+  , mMayHaveMutationListeners(false)
+  , mMayHaveCapturingListeners(false)
+  , mMayHaveSystemGroupListeners(false)
+  , mMayHaveAudioAvailableEventListener(false)
+  , mMayHaveTouchEventListener(false)
+  , mMayHaveMouseEnterLeaveEventListener(false)
+  , mMayHavePointerEnterLeaveEventListener(false)
+  , mClearingListeners(false)
+  , mIsMainThreadELM(NS_IsMainThread())
+  , mNoListenerForEvent(0)
+  , mTarget(aTarget)
 {
   NS_ASSERTION(aTarget, "unexpected null pointer");
 
   if (mIsMainThreadELM) {
     ++sMainThreadCreatedCount;
   }
 }
 
-nsEventListenerManager::~nsEventListenerManager() 
+EventListenerManager::~EventListenerManager()
 {
   // If your code fails this assertion, a possible reason is that
   // a class did not call our Disconnect() manually. Note that
   // this class can have Disconnect called in one of two ways:
   // if it is part of a cycle, then in Unlink() (such a cycle
   // would be with one of the listeners, not mTarget which is weak).
   // If not part of a cycle, then Disconnect must be called manually,
   // typically from the destructor of the owner class (mTarget).
   // XXX azakai: Is there any reason to not just call Disconnect
   //             from right here, if not previously called?
   NS_ASSERTION(!mTarget, "didn't call Disconnect");
   RemoveAllListeners();
-
 }
 
 void
-nsEventListenerManager::RemoveAllListeners()
+EventListenerManager::RemoveAllListeners()
 {
   if (mClearingListeners) {
     return;
   }
   mClearingListeners = true;
   mListeners.Clear();
   mClearingListeners = false;
 }
 
 void
-nsEventListenerManager::Shutdown()
+EventListenerManager::Shutdown()
 {
   Event::Shutdown();
 }
 
-NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsEventListenerManager, AddRef)
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsEventListenerManager, Release)
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(EventListenerManager, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(EventListenerManager, Release)
 
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
-                            nsListenerStruct& aField,
+                            EventListenerManager::Listener& aField,
                             const char* aName,
                             unsigned aFlags)
 {
   if (MOZ_UNLIKELY(aCallback.WantDebugInfo())) {
     nsAutoCString name;
     name.AppendASCII(aName);
     if (aField.mTypeAtom) {
       name.AppendASCII(" event=");
@@ -162,113 +162,115 @@ ImplCycleCollectionTraverse(nsCycleColle
     CycleCollectionNoteChild(aCallback, aField.mListener.GetISupports(), name.get(),
                              aFlags);
   } else {
     CycleCollectionNoteChild(aCallback, aField.mListener.GetISupports(), aName,
                              aFlags);
   }
 }
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsEventListenerManager)
+NS_IMPL_CYCLE_COLLECTION_CLASS(EventListenerManager)
 
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEventListenerManager)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(EventListenerManager)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListeners)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsEventListenerManager)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(EventListenerManager)
   tmp->Disconnect();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 
 nsPIDOMWindow*
-nsEventListenerManager::GetInnerWindowForTarget()
+EventListenerManager::GetInnerWindowForTarget()
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(mTarget);
   if (node) {
     // XXX sXBL/XBL2 issue -- do we really want the owner here?  What
     // if that's the XBL document?
     return node->OwnerDoc()->GetInnerWindow();
   }
 
   nsCOMPtr<nsPIDOMWindow> window = GetTargetAsInnerWindow();
   return window;
 }
 
 already_AddRefed<nsPIDOMWindow>
-nsEventListenerManager::GetTargetAsInnerWindow() const
+EventListenerManager::GetTargetAsInnerWindow() const
 {
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mTarget);
   if (!window) {
     return nullptr;
   }
 
   NS_ASSERTION(window->IsInnerWindow(), "Target should not be an outer window");
   return window.forget();
 }
 
 void
-nsEventListenerManager::AddEventListenerInternal(
-                          const EventListenerHolder& aListener,
-                          uint32_t aType,
-                          nsIAtom* aTypeAtom,
-                          const nsAString& aTypeString,
-                          const EventListenerFlags& aFlags,
-                          bool aHandler,
-                          bool aAllEvents)
+EventListenerManager::AddEventListenerInternal(
+                        const EventListenerHolder& aListenerHolder,
+                        uint32_t aType,
+                        nsIAtom* aTypeAtom,
+                        const nsAString& aTypeString,
+                        const EventListenerFlags& aFlags,
+                        bool aHandler,
+                        bool aAllEvents)
 {
   MOZ_ASSERT((NS_IsMainThread() && aType && aTypeAtom) || // Main thread
              (!NS_IsMainThread() && aType && !aTypeString.IsEmpty()) || // non-main-thread
              aAllEvents, "Missing type"); // all-events listener
 
-  if (!aListener || mClearingListeners) {
+  if (!aListenerHolder || mClearingListeners) {
     return;
   }
 
   // Since there is no public API to call us with an EventListenerHolder, we
   // know that there's an EventListenerHolder on the stack holding a strong ref
   // to the listener.
 
-  nsListenerStruct* ls;
+  Listener* listener;
   uint32_t count = mListeners.Length();
   for (uint32_t i = 0; i < count; i++) {
-    ls = &mListeners.ElementAt(i);
-    // mListener == aListener is the last one, since it can be a bit slow.
-    if (ls->mListenerIsHandler == aHandler &&
-        ls->mFlags == aFlags &&
-        EVENT_TYPE_EQUALS(ls, aType, aTypeAtom, aTypeString, aAllEvents) &&
-        ls->mListener == aListener) {
+    listener = &mListeners.ElementAt(i);
+    // mListener == aListenerHolder is the last one, since it can be a bit slow.
+    if (listener->mListenerIsHandler == aHandler &&
+        listener->mFlags == aFlags &&
+        EVENT_TYPE_EQUALS(listener, aType, aTypeAtom, aTypeString,
+                          aAllEvents) &&
+        listener->mListener == aListenerHolder) {
       return;
     }
   }
 
   mNoListenerForEvent = NS_EVENT_NULL;
   mNoListenerForEventAtom = nullptr;
 
-  ls = aAllEvents ? mListeners.InsertElementAt(0) : mListeners.AppendElement();
-  ls->mListener = aListener;
+  listener = aAllEvents ? mListeners.InsertElementAt(0) :
+                          mListeners.AppendElement();
+  listener->mListener = aListenerHolder;
   MOZ_ASSERT(aType < PR_UINT16_MAX);
-  ls->mEventType = aType;
-  ls->mTypeString = aTypeString;
-  ls->mTypeAtom = aTypeAtom;
-  ls->mFlags = aFlags;
-  ls->mListenerIsHandler = aHandler;
-  ls->mHandlerIsString = false;
-  ls->mAllEvents = aAllEvents;
+  listener->mEventType = aType;
+  listener->mTypeString = aTypeString;
+  listener->mTypeAtom = aTypeAtom;
+  listener->mFlags = aFlags;
+  listener->mListenerIsHandler = aHandler;
+  listener->mHandlerIsString = false;
+  listener->mAllEvents = aAllEvents;
 
   // Detect the type of event listener.
   nsCOMPtr<nsIXPConnectWrappedJS> wjs;
   if (aFlags.mListenerIsJSListener) {
-    MOZ_ASSERT(!aListener.HasWebIDLCallback());
-    ls->mListenerType = eJSEventListener;
-  } else if (aListener.HasWebIDLCallback()) {
-    ls->mListenerType = eWebIDLListener;
-  } else if ((wjs = do_QueryInterface(aListener.GetXPCOMCallback()))) {
-    ls->mListenerType = eWrappedJSListener;
+    MOZ_ASSERT(!aListenerHolder.HasWebIDLCallback());
+    listener->mListenerType = Listener::eJSEventListener;
+  } else if (aListenerHolder.HasWebIDLCallback()) {
+    listener->mListenerType = Listener::eWebIDLListener;
+  } else if ((wjs = do_QueryInterface(aListenerHolder.GetXPCOMCallback()))) {
+    listener->mListenerType = Listener::eWrappedJSListener;
   } else {
-    ls->mListenerType = eNativeListener;
+    listener->mListenerType = Listener::eNativeListener;
   }
 
 
   if (aFlags.mInSystemGroup) {
     mMayHaveSystemGroupListeners = true;
   }
   if (aFlags.mCapture) {
     mMayHaveCapturingListeners = true;
@@ -379,33 +381,33 @@ nsEventListenerManager::AddEventListener
 #endif
   }
   if (aTypeAtom && mTarget) {
     mTarget->EventListenerAdded(aTypeAtom);
   }
 }
 
 bool
-nsEventListenerManager::IsDeviceType(uint32_t aType)
+EventListenerManager::IsDeviceType(uint32_t aType)
 {
   switch (aType) {
     case NS_DEVICE_ORIENTATION:
     case NS_DEVICE_MOTION:
     case NS_DEVICE_LIGHT:
     case NS_DEVICE_PROXIMITY:
     case NS_USER_PROXIMITY:
       return true;
     default:
       break;
   }
   return false;
 }
 
 void
-nsEventListenerManager::EnableDevice(uint32_t aType)
+EventListenerManager::EnableDevice(uint32_t aType)
 {
   nsCOMPtr<nsPIDOMWindow> window = GetTargetAsInnerWindow();
   if (!window) {
     return;
   }
 
   switch (aType) {
     case NS_DEVICE_ORIENTATION:
@@ -425,17 +427,17 @@ nsEventListenerManager::EnableDevice(uin
       break;
     default:
       NS_WARNING("Enabling an unknown device sensor.");
       break;
   }
 }
 
 void
-nsEventListenerManager::DisableDevice(uint32_t aType)
+EventListenerManager::DisableDevice(uint32_t aType)
 {
   nsCOMPtr<nsPIDOMWindow> window = GetTargetAsInnerWindow();
   if (!window) {
     return;
   }
 
   switch (aType) {
     case NS_DEVICE_ORIENTATION:
@@ -455,46 +457,47 @@ nsEventListenerManager::DisableDevice(ui
       break;
     default:
       NS_WARNING("Disabling an unknown device sensor.");
       break;
   }
 }
 
 void
-nsEventListenerManager::RemoveEventListenerInternal(
-                          const EventListenerHolder& aListener, 
-                          uint32_t aType,
-                          nsIAtom* aUserType,
-                          const nsAString& aTypeString,
-                          const EventListenerFlags& aFlags,
-                          bool aAllEvents)
+EventListenerManager::RemoveEventListenerInternal(
+                        const EventListenerHolder& aListenerHolder,
+                        uint32_t aType,
+                        nsIAtom* aUserType,
+                        const nsAString& aTypeString,
+                        const EventListenerFlags& aFlags,
+                        bool aAllEvents)
 {
-  if (!aListener || !aType || mClearingListeners) {
+  if (!aListenerHolder || !aType || mClearingListeners) {
     return;
   }
 
-  nsListenerStruct* ls;
+  Listener* listener;
 
   uint32_t count = mListeners.Length();
   uint32_t typeCount = 0;
   bool deviceType = IsDeviceType(aType);
 #ifdef MOZ_B2G
   bool timeChangeEvent = (aType == NS_MOZ_TIME_CHANGE_EVENT);
   bool networkEvent = (aType == NS_NETWORK_UPLOAD_EVENT ||
                        aType == NS_NETWORK_DOWNLOAD_EVENT);
 #endif // MOZ_B2G
 
   for (uint32_t i = 0; i < count; ++i) {
-    ls = &mListeners.ElementAt(i);
-    if (EVENT_TYPE_EQUALS(ls, aType, aUserType, aTypeString, aAllEvents)) {
+    listener = &mListeners.ElementAt(i);
+    if (EVENT_TYPE_EQUALS(listener, aType, aUserType, aTypeString,
+                          aAllEvents)) {
       ++typeCount;
-      if (ls->mListener == aListener &&
-          ls->mFlags.EqualsIgnoringTrustness(aFlags)) {
-        nsRefPtr<nsEventListenerManager> kungFuDeathGrip = this;
+      if (listener->mListener == aListenerHolder &&
+          listener->mFlags.EqualsIgnoringTrustness(aFlags)) {
+        nsRefPtr<EventListenerManager> kungFuDeathGrip(this);
         mListeners.RemoveElementAt(i);
         --count;
         mNoListenerForEvent = NS_EVENT_NULL;
         mNoListenerForEventAtom = nullptr;
         if (mTarget && aUserType) {
           mTarget->EventListenerRemoved(aUserType);
         }
 
@@ -523,135 +526,139 @@ nsEventListenerManager::RemoveEventListe
     if (window) {
       window->DisableNetworkEvent(aType);
     }
 #endif // MOZ_B2G
   }
 }
 
 bool
-nsEventListenerManager::ListenerCanHandle(nsListenerStruct* aLs,
-                                          WidgetEvent* aEvent)
+EventListenerManager::ListenerCanHandle(Listener* aListener,
+                                        WidgetEvent* aEvent)
 {
   // This is slightly different from EVENT_TYPE_EQUALS in that it returns
   // true even when aEvent->message == NS_USER_DEFINED_EVENT and
-  // aLs=>mEventType != NS_USER_DEFINED_EVENT as long as the atoms are the same
-  if (aLs->mAllEvents) {
+  // aListener=>mEventType != NS_USER_DEFINED_EVENT as long as the atoms are
+  // the same
+  if (aListener->mAllEvents) {
     return true;
   }
   if (aEvent->message == NS_USER_DEFINED_EVENT) {
     if (mIsMainThreadELM) {
-      return aLs->mTypeAtom == aEvent->userType;
+      return aListener->mTypeAtom == aEvent->userType;
     }
-    return aLs->mTypeString.Equals(aEvent->typeString);
+    return aListener->mTypeString.Equals(aEvent->typeString);
   }
   MOZ_ASSERT(mIsMainThreadELM);
-  return aLs->mEventType == aEvent->message;
+  return aListener->mEventType == aEvent->message;
 }
 
 void
-nsEventListenerManager::AddEventListenerByType(const EventListenerHolder& aListener, 
-                                               const nsAString& aType,
-                                               const EventListenerFlags& aFlags)
+EventListenerManager::AddEventListenerByType(
+                        const EventListenerHolder& aListenerHolder,
+                        const nsAString& aType,
+                        const EventListenerFlags& aFlags)
 {
   nsCOMPtr<nsIAtom> atom =
     mIsMainThreadELM ? do_GetAtom(NS_LITERAL_STRING("on") + aType) : nullptr;
   uint32_t type = nsContentUtils::GetEventId(atom);
-  AddEventListenerInternal(aListener, type, atom, aType, aFlags);
+  AddEventListenerInternal(aListenerHolder, type, atom, aType, aFlags);
 }
 
 void
-nsEventListenerManager::RemoveEventListenerByType(
-                          const EventListenerHolder& aListener,
-                          const nsAString& aType,
-                          const EventListenerFlags& aFlags)
+EventListenerManager::RemoveEventListenerByType(
+                        const EventListenerHolder& aListenerHolder,
+                        const nsAString& aType,
+                        const EventListenerFlags& aFlags)
 {
   nsCOMPtr<nsIAtom> atom =
     mIsMainThreadELM ? do_GetAtom(NS_LITERAL_STRING("on") + aType) : nullptr;
   uint32_t type = nsContentUtils::GetEventId(atom);
-  RemoveEventListenerInternal(aListener, type, atom, aType, aFlags);
+  RemoveEventListenerInternal(aListenerHolder, type, atom, aType, aFlags);
 }
 
-nsListenerStruct*
-nsEventListenerManager::FindEventHandler(uint32_t aEventType,
-                                         nsIAtom* aTypeAtom,
-                                         const nsAString& aTypeString)
+EventListenerManager::Listener*
+EventListenerManager::FindEventHandler(uint32_t aEventType,
+                                       nsIAtom* aTypeAtom,
+                                       const nsAString& aTypeString)
 {
   // Run through the listeners for this type and see if a script
   // listener is registered
-  nsListenerStruct *ls;
+  Listener* listener;
   uint32_t count = mListeners.Length();
   for (uint32_t i = 0; i < count; ++i) {
-    ls = &mListeners.ElementAt(i);
-    if (ls->mListenerIsHandler &&
-        EVENT_TYPE_EQUALS(ls, aEventType, aTypeAtom, aTypeString, false)) {
-      return ls;
+    listener = &mListeners.ElementAt(i);
+    if (listener->mListenerIsHandler &&
+        EVENT_TYPE_EQUALS(listener, aEventType, aTypeAtom, aTypeString,
+                          false)) {
+      return listener;
     }
   }
   return nullptr;
 }
 
-nsListenerStruct*
-nsEventListenerManager::SetEventHandlerInternal(JS::Handle<JSObject*> aScopeObject,
-                                                nsIAtom* aName,
-                                                const nsAString& aTypeString,
-                                                const nsEventHandler& aHandler,
-                                                bool aPermitUntrustedEvents)
+EventListenerManager::Listener*
+EventListenerManager::SetEventHandlerInternal(
+                        JS::Handle<JSObject*> aScopeObject,
+                        nsIAtom* aName,
+                        const nsAString& aTypeString,
+                        const nsEventHandler& aHandler,
+                        bool aPermitUntrustedEvents)
 {
   MOZ_ASSERT(aScopeObject || aHandler.HasEventHandler(),
              "Must have one or the other!");
   MOZ_ASSERT(aName || !aTypeString.IsEmpty());
 
   uint32_t eventType = nsContentUtils::GetEventId(aName);
-  nsListenerStruct* ls = FindEventHandler(eventType, aName, aTypeString);
+  Listener* listener = FindEventHandler(eventType, aName, aTypeString);
 
-  if (!ls) {
+  if (!listener) {
     // If we didn't find a script listener or no listeners existed
     // create and add a new one.
     EventListenerFlags flags;
     flags.mListenerIsJSListener = true;
 
-    nsCOMPtr<nsIJSEventListener> scriptListener;
+    nsCOMPtr<nsIJSEventListener> jsListener;
     NS_NewJSEventListener(aScopeObject, mTarget, aName,
-                          aHandler, getter_AddRefs(scriptListener));
-    EventListenerHolder holder(scriptListener);
-    AddEventListenerInternal(holder, eventType, aName, aTypeString, flags,
-                             true);
+                          aHandler, getter_AddRefs(jsListener));
+    EventListenerHolder listenerHolder(jsListener);
+    AddEventListenerInternal(listenerHolder, eventType, aName, aTypeString,
+                             flags, true);
 
-    ls = FindEventHandler(eventType, aName, aTypeString);
+    listener = FindEventHandler(eventType, aName, aTypeString);
   } else {
-    nsIJSEventListener* scriptListener = ls->GetJSListener();
-    MOZ_ASSERT(scriptListener,
+    nsIJSEventListener* jsListener = listener->GetJSListener();
+    MOZ_ASSERT(jsListener,
                "How can we have an event handler with no nsIJSEventListener?");
 
-    bool same = scriptListener->GetHandler() == aHandler;
+    bool same = jsListener->GetHandler() == aHandler;
     // Possibly the same listener, but update still the context and scope.
-    scriptListener->SetHandler(aHandler, aScopeObject);
+    jsListener->SetHandler(aHandler, aScopeObject);
     if (mTarget && !same && aName) {
       mTarget->EventListenerRemoved(aName);
       mTarget->EventListenerAdded(aName);
     }
   }
 
   // Set flag to indicate possible need for compilation later
-  ls->mHandlerIsString = !aHandler.HasEventHandler();
+  listener->mHandlerIsString = !aHandler.HasEventHandler();
   if (aPermitUntrustedEvents) {
-    ls->mFlags.mAllowUntrustedEvents = true;
+    listener->mFlags.mAllowUntrustedEvents = true;
   }
 
-  return ls;
+  return listener;
 }
 
 nsresult
-nsEventListenerManager::SetEventHandler(nsIAtom *aName,
-                                        const nsAString& aBody,
-                                        uint32_t aLanguage,
-                                        bool aDeferCompilation,
-                                        bool aPermitUntrustedEvents,
-                                        Element* aElement)
+EventListenerManager::SetEventHandler(nsIAtom* aName,
+                                      const nsAString& aBody,
+                                      uint32_t aLanguage,
+                                      bool aDeferCompilation,
+                                      bool aPermitUntrustedEvents,
+                                      Element* aElement)
 {
   NS_PRECONDITION(aLanguage != nsIProgrammingLanguage::UNKNOWN,
                   "Must know the language for the script event listener");
 
   // |aPermitUntrustedEvents| is set to False for chrome - events
   // *generated* from an unknown source are not allowed.
   // However, for script languages with no 'sandbox', we want to reject
   // such scripts based on the source of their code, not just the source
@@ -741,122 +748,123 @@ nsEventListenerManager::SetEventHandler(
   NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
 
   NS_ENSURE_STATE(global->GetGlobalJSObject());
 
   JSAutoRequest ar(context->GetNativeContext());
   JS::Rooted<JSObject*> scope(context->GetNativeContext(),
                               global->GetGlobalJSObject());
 
-  nsListenerStruct* ls = SetEventHandlerInternal(scope, aName,
-                                                 EmptyString(),
-                                                 nsEventHandler(),
-                                                 aPermitUntrustedEvents);
+  Listener* listener = SetEventHandlerInternal(scope, aName,
+                                               EmptyString(),
+                                               nsEventHandler(),
+                                               aPermitUntrustedEvents);
 
   if (!aDeferCompilation) {
-    return CompileEventHandlerInternal(ls, &aBody, aElement);
+    return CompileEventHandlerInternal(listener, &aBody, aElement);
   }
 
   return NS_OK;
 }
 
 void
-nsEventListenerManager::RemoveEventHandler(nsIAtom* aName,
-                                           const nsAString& aTypeString)
+EventListenerManager::RemoveEventHandler(nsIAtom* aName,
+                                         const nsAString& aTypeString)
 {
   if (mClearingListeners) {
     return;
   }
 
   uint32_t eventType = nsContentUtils::GetEventId(aName);
-  nsListenerStruct* ls = FindEventHandler(eventType, aName, aTypeString);
+  Listener* listener = FindEventHandler(eventType, aName, aTypeString);
 
-  if (ls) {
-    mListeners.RemoveElementAt(uint32_t(ls - &mListeners.ElementAt(0)));
+  if (listener) {
+    mListeners.RemoveElementAt(uint32_t(listener - &mListeners.ElementAt(0)));
     mNoListenerForEvent = NS_EVENT_NULL;
     mNoListenerForEventAtom = nullptr;
     if (mTarget && aName) {
       mTarget->EventListenerRemoved(aName);
     }
   }
 }
 
 nsresult
-nsEventListenerManager::CompileEventHandlerInternal(nsListenerStruct *aListenerStruct,
-                                                    const nsAString* aBody,
-                                                    Element* aElement)
+EventListenerManager::CompileEventHandlerInternal(Listener* aListener,
+                                                  const nsAString* aBody,
+                                                  Element* aElement)
 {
-  NS_PRECONDITION(aListenerStruct->GetJSListener(),
+  NS_PRECONDITION(aListener->GetJSListener(),
                   "Why do we not have a JS listener?");
-  NS_PRECONDITION(aListenerStruct->mHandlerIsString,
+  NS_PRECONDITION(aListener->mHandlerIsString,
                   "Why are we compiling a non-string JS listener?");
 
   nsresult result = NS_OK;
 
-  nsIJSEventListener *listener = aListenerStruct->GetJSListener();
-  NS_ASSERTION(!listener->GetHandler().HasEventHandler(),
+  nsIJSEventListener* jsListener = aListener->GetJSListener();
+  NS_ASSERTION(!jsListener->GetHandler().HasEventHandler(),
                "What is there to compile?");
 
   nsCOMPtr<nsIDocument> doc;
   nsCOMPtr<nsIScriptGlobalObject> global =
     GetScriptGlobalAndDocument(getter_AddRefs(doc));
   NS_ENSURE_STATE(global);
 
   nsIScriptContext* context = global->GetScriptContext();
   NS_ENSURE_STATE(context);
 
   // Push a context to make sure exceptions are reported in the right place.
   AutoPushJSContext cx(context->GetNativeContext());
   JS::Rooted<JSObject*> handler(cx);
 
-  JS::Rooted<JSObject*> scope(cx, listener->GetEventScope());
+  JS::Rooted<JSObject*> scope(cx, jsListener->GetEventScope());
 
-  nsCOMPtr<nsIAtom> typeAtom = aListenerStruct->mTypeAtom;
+  nsCOMPtr<nsIAtom> typeAtom = aListener->mTypeAtom;
   nsIAtom* attrName = typeAtom;
 
-  if (aListenerStruct->mHandlerIsString) {
+  if (aListener->mHandlerIsString) {
     // OK, we didn't find an existing compiled event handler.  Flag us
     // as not a string so we don't keep trying to compile strings
     // which can't be compiled
-    aListenerStruct->mHandlerIsString = false;
+    aListener->mHandlerIsString = false;
 
     // mTarget may not be an Element if it's a window and we're
     // getting an inline event listener forwarded from <html:body> or
     // <html:frameset> or <xul:window> or the like.
     // XXX I don't like that we have to reference content from
     // here. The alternative is to store the event handler string on
     // the nsIJSEventListener itself, and that still doesn't address
     // the arg names issue.
     nsCOMPtr<Element> element = do_QueryInterface(mTarget);
     MOZ_ASSERT(element || aBody, "Where will we get our body?");
     nsAutoString handlerBody;
     const nsAString* body = aBody;
     if (!aBody) {
-      if (aListenerStruct->mTypeAtom == nsGkAtoms::onSVGLoad)
+      if (aListener->mTypeAtom == nsGkAtoms::onSVGLoad) {
         attrName = nsGkAtoms::onload;
-      else if (aListenerStruct->mTypeAtom == nsGkAtoms::onSVGUnload)
+      } else if (aListener->mTypeAtom == nsGkAtoms::onSVGUnload) {
         attrName = nsGkAtoms::onunload;
-      else if (aListenerStruct->mTypeAtom == nsGkAtoms::onSVGResize)
+      } else if (aListener->mTypeAtom == nsGkAtoms::onSVGResize) {
         attrName = nsGkAtoms::onresize;
-      else if (aListenerStruct->mTypeAtom == nsGkAtoms::onSVGScroll)
+      } else if (aListener->mTypeAtom == nsGkAtoms::onSVGScroll) {
         attrName = nsGkAtoms::onscroll;
-      else if (aListenerStruct->mTypeAtom == nsGkAtoms::onSVGZoom)
+      } else if (aListener->mTypeAtom == nsGkAtoms::onSVGZoom) {
         attrName = nsGkAtoms::onzoom;
-      else if (aListenerStruct->mTypeAtom == nsGkAtoms::onbeginEvent)
+      } else if (aListener->mTypeAtom == nsGkAtoms::onbeginEvent) {
         attrName = nsGkAtoms::onbegin;
-      else if (aListenerStruct->mTypeAtom == nsGkAtoms::onrepeatEvent)
+      } else if (aListener->mTypeAtom == nsGkAtoms::onrepeatEvent) {
         attrName = nsGkAtoms::onrepeat;
-      else if (aListenerStruct->mTypeAtom == nsGkAtoms::onendEvent)
+      } else if (aListener->mTypeAtom == nsGkAtoms::onendEvent) {
         attrName = nsGkAtoms::onend;
+      }
 
       element->GetAttr(kNameSpaceID_None, attrName, handlerBody);
       body = &handlerBody;
       aElement = element;
     }
-    aListenerStruct = nullptr;
+    aListener = nullptr;
 
     uint32_t lineNo = 0;
     nsAutoCString url (NS_LITERAL_CSTRING("-moz-evil:lying-event-listener"));
     MOZ_ASSERT(body);
     MOZ_ASSERT(aElement);
     nsIURI *uri = aElement->OwnerDoc()->GetDocumentURI();
     if (uri) {
       uri->GetSpec(url);
@@ -897,136 +905,138 @@ nsEventListenerManager::CompileEventHand
     JS::Rooted<JSObject*> handlerFun(cx);
     result = nsJSUtils::CompileFunction(cx, JS::NullPtr(), options,
                                         nsAtomCString(typeAtom),
                                         argCount, argNames, *body, handlerFun.address());
     NS_ENSURE_SUCCESS(result, result);
     handler = handlerFun;
     NS_ENSURE_TRUE(handler, NS_ERROR_FAILURE);
   } else {
-    aListenerStruct = nullptr;
+    aListener = nullptr;
   }
 
   if (handler) {
     nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mTarget);
     // Bind it
     JS::Rooted<JSObject*> boundHandler(cx);
     context->BindCompiledEventHandler(mTarget, scope, handler, &boundHandler);
     // Note - We pass null for aIncumbentGlobal below. We could also pass the
     // compilation global, but since the handler is guaranteed to be scripted,
     // there's no need to use an override, since the JS engine will always give
     // us the right answer.
     if (!boundHandler) {
-      listener->ForgetHandler();
-    } else if (listener->EventName() == nsGkAtoms::onerror && win) {
+      jsListener->ForgetHandler();
+    } else if (jsListener->EventName() == nsGkAtoms::onerror && win) {
       nsRefPtr<OnErrorEventHandlerNonNull> handlerCallback =
         new OnErrorEventHandlerNonNull(boundHandler, /* aIncumbentGlobal = */ nullptr);
-      listener->SetHandler(handlerCallback);
-    } else if (listener->EventName() == nsGkAtoms::onbeforeunload && win) {
+      jsListener->SetHandler(handlerCallback);
+    } else if (jsListener->EventName() == nsGkAtoms::onbeforeunload && win) {
       nsRefPtr<OnBeforeUnloadEventHandlerNonNull> handlerCallback =
         new OnBeforeUnloadEventHandlerNonNull(boundHandler, /* aIncumbentGlobal = */ nullptr);
-      listener->SetHandler(handlerCallback);
+      jsListener->SetHandler(handlerCallback);
     } else {
       nsRefPtr<EventHandlerNonNull> handlerCallback =
         new EventHandlerNonNull(boundHandler, /* aIncumbentGlobal = */ nullptr);
-      listener->SetHandler(handlerCallback);
+      jsListener->SetHandler(handlerCallback);
     }
   }
 
   return result;
 }
 
 nsresult
-nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
-                                           nsIDOMEvent* aDOMEvent,
-                                           EventTarget* aCurrentTarget)
+EventListenerManager::HandleEventSubType(Listener* aListener,
+                                         nsIDOMEvent* aDOMEvent,
+                                         EventTarget* aCurrentTarget)
 {
   nsresult result = NS_OK;
-  EventListenerHolder listener(aListenerStruct->mListener);  // strong ref
+  EventListenerHolder listenerHolder(aListener->mListener);  // strong ref
 
   // If this is a script handler and we haven't yet
   // compiled the event handler itself
-  if ((aListenerStruct->mListenerType == eJSEventListener) &&
-      aListenerStruct->mHandlerIsString) {
-    result = CompileEventHandlerInternal(aListenerStruct, nullptr, nullptr);
-    aListenerStruct = nullptr;
+  if ((aListener->mListenerType == Listener::eJSEventListener) &&
+      aListener->mHandlerIsString) {
+    result = CompileEventHandlerInternal(aListener, nullptr, nullptr);
+    aListener = nullptr;
   }
 
   if (NS_SUCCEEDED(result)) {
     if (mIsMainThreadELM) {
       nsContentUtils::EnterMicroTask();
     }
     // nsIDOMEvent::currentTarget is set in nsEventDispatcher.
-    if (listener.HasWebIDLCallback()) {
+    if (listenerHolder.HasWebIDLCallback()) {
       ErrorResult rv;
-      listener.GetWebIDLCallback()->
+      listenerHolder.GetWebIDLCallback()->
         HandleEvent(aCurrentTarget, *(aDOMEvent->InternalDOMEvent()), rv);
       result = rv.ErrorCode();
     } else {
-      result = listener.GetXPCOMCallback()->HandleEvent(aDOMEvent);
+      result = listenerHolder.GetXPCOMCallback()->HandleEvent(aDOMEvent);
     }
     if (mIsMainThreadELM) {
       nsContentUtils::LeaveMicroTask();
     }
   }
 
   return result;
 }
 
 /**
 * Causes a check for event listeners and processing by them if they exist.
 * @param an event listener
 */
 
 void
-nsEventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
-                                            WidgetEvent* aEvent,
-                                            nsIDOMEvent** aDOMEvent,
-                                            EventTarget* aCurrentTarget,
-                                            nsEventStatus* aEventStatus)
+EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
+                                          WidgetEvent* aEvent,
+                                          nsIDOMEvent** aDOMEvent,
+                                          EventTarget* aCurrentTarget,
+                                          nsEventStatus* aEventStatus)
 {
   //Set the value of the internal PreventDefault flag properly based on aEventStatus
   if (*aEventStatus == nsEventStatus_eConsumeNoDefault) {
     aEvent->mFlags.mDefaultPrevented = true;
   }
 
-  nsAutoTObserverArray<nsListenerStruct, 2>::EndLimitedIterator iter(mListeners);
+  nsAutoTObserverArray<Listener, 2>::EndLimitedIterator iter(mListeners);
   Maybe<nsAutoPopupStatePusher> popupStatePusher;
   if (mIsMainThreadELM) {
     popupStatePusher.construct(Event::GetEventPopupControlState(aEvent));
   }
 
   bool hasListener = false;
   while (iter.HasMore()) {
     if (aEvent->mFlags.mImmediatePropagationStopped) {
       break;
     }
-    nsListenerStruct* ls = &iter.GetNext();
+    Listener* listener = &iter.GetNext();
     // Check that the phase is same in event and event listener.
     // Handle only trusted events, except when listener permits untrusted events.
-    if (ListenerCanHandle(ls, aEvent)) {
+    if (ListenerCanHandle(listener, aEvent)) {
       hasListener = true;
-      if (ls->IsListening(aEvent) &&
-          (aEvent->mFlags.mIsTrusted || ls->mFlags.mAllowUntrustedEvents)) {
+      if (listener->IsListening(aEvent) &&
+          (aEvent->mFlags.mIsTrusted ||
+           listener->mFlags.mAllowUntrustedEvents)) {
         if (!*aDOMEvent) {
           // This is tiny bit slow, but happens only once per event.
-          nsCOMPtr<mozilla::dom::EventTarget> et =
+          nsCOMPtr<EventTarget> et =
             do_QueryInterface(aEvent->originalTarget);
           nsEventDispatcher::CreateEvent(et, aPresContext,
                                          aEvent, EmptyString(), aDOMEvent);
         }
         if (*aDOMEvent) {
           if (!aEvent->currentTarget) {
             aEvent->currentTarget = aCurrentTarget->GetTargetForDOMEvent();
             if (!aEvent->currentTarget) {
               break;
             }
           }
 
-          if (NS_FAILED(HandleEventSubType(ls, *aDOMEvent, aCurrentTarget))) {
+          if (NS_FAILED(HandleEventSubType(listener, *aDOMEvent,
+                                           aCurrentTarget))) {
             aEvent->mFlags.mExceptionHasBeenRisen = true;
           }
         }
       }
     }
   }
 
   aEvent->currentTarget = nullptr;
@@ -1037,208 +1047,212 @@ nsEventListenerManager::HandleEventInter
   }
 
   if (aEvent->mFlags.mDefaultPrevented) {
     *aEventStatus = nsEventStatus_eConsumeNoDefault;
   }
 }
 
 void
-nsEventListenerManager::Disconnect()
+EventListenerManager::Disconnect()
 {
   mTarget = nullptr;
   RemoveAllListeners();
 }
 
 void
-nsEventListenerManager::AddEventListener(const nsAString& aType,
-                                         const EventListenerHolder& aListener,
-                                         bool aUseCapture,
-                                         bool aWantsUntrusted)
+EventListenerManager::AddEventListener(
+                        const nsAString& aType,
+                        const EventListenerHolder& aListenerHolder,
+                        bool aUseCapture,
+                        bool aWantsUntrusted)
 {
   EventListenerFlags flags;
   flags.mCapture = aUseCapture;
   flags.mAllowUntrustedEvents = aWantsUntrusted;
-  return AddEventListenerByType(aListener, aType, flags);
+  return AddEventListenerByType(aListenerHolder, aType, flags);
 }
 
 void
-nsEventListenerManager::RemoveEventListener(const nsAString& aType, 
-                                            const EventListenerHolder& aListener, 
-                                            bool aUseCapture)
+EventListenerManager::RemoveEventListener(
+                        const nsAString& aType,
+                        const EventListenerHolder& aListenerHolder,
+                        bool aUseCapture)
 {
   EventListenerFlags flags;
   flags.mCapture = aUseCapture;
-  RemoveEventListenerByType(aListener, aType, flags);
+  RemoveEventListenerByType(aListenerHolder, aType, flags);
 }
 
 void
-nsEventListenerManager::AddListenerForAllEvents(nsIDOMEventListener* aListener,
-                                                bool aUseCapture,
-                                                bool aWantsUntrusted,
-                                                bool aSystemEventGroup)
+EventListenerManager::AddListenerForAllEvents(nsIDOMEventListener* aDOMListener,
+                                              bool aUseCapture,
+                                              bool aWantsUntrusted,
+                                              bool aSystemEventGroup)
 {
   EventListenerFlags flags;
   flags.mCapture = aUseCapture;
   flags.mAllowUntrustedEvents = aWantsUntrusted;
   flags.mInSystemGroup = aSystemEventGroup;
-  EventListenerHolder holder(aListener);
-  AddEventListenerInternal(holder, NS_EVENT_ALL, nullptr, EmptyString(),
+  EventListenerHolder listenerHolder(aDOMListener);
+  AddEventListenerInternal(listenerHolder, NS_EVENT_ALL, nullptr, EmptyString(),
                            flags, false, true);
 }
 
 void
-nsEventListenerManager::RemoveListenerForAllEvents(nsIDOMEventListener* aListener, 
-                                                   bool aUseCapture,
-                                                   bool aSystemEventGroup)
+EventListenerManager::RemoveListenerForAllEvents(
+                        nsIDOMEventListener* aDOMListener,
+                        bool aUseCapture,
+                        bool aSystemEventGroup)
 {
   EventListenerFlags flags;
   flags.mCapture = aUseCapture;
   flags.mInSystemGroup = aSystemEventGroup;
-  EventListenerHolder holder(aListener);
-  RemoveEventListenerInternal(holder, NS_EVENT_ALL, nullptr, EmptyString(),
-                              flags, true);
+  EventListenerHolder listenerHolder(aDOMListener);
+  RemoveEventListenerInternal(listenerHolder, NS_EVENT_ALL, nullptr,
+                              EmptyString(), flags, true);
 }
 
 bool
-nsEventListenerManager::HasMutationListeners()
+EventListenerManager::HasMutationListeners()
 {
   if (mMayHaveMutationListeners) {
     uint32_t count = mListeners.Length();
     for (uint32_t i = 0; i < count; ++i) {
-      nsListenerStruct* ls = &mListeners.ElementAt(i);
-      if (ls->mEventType >= NS_MUTATION_START &&
-          ls->mEventType <= NS_MUTATION_END) {
+      Listener* listener = &mListeners.ElementAt(i);
+      if (listener->mEventType >= NS_MUTATION_START &&
+          listener->mEventType <= NS_MUTATION_END) {
         return true;
       }
     }
   }
 
   return false;
 }
 
 uint32_t
-nsEventListenerManager::MutationListenerBits()
+EventListenerManager::MutationListenerBits()
 {
   uint32_t bits = 0;
   if (mMayHaveMutationListeners) {
     uint32_t count = mListeners.Length();
     for (uint32_t i = 0; i < count; ++i) {
-      nsListenerStruct* ls = &mListeners.ElementAt(i);
-      if (ls->mEventType >= NS_MUTATION_START &&
-          ls->mEventType <= NS_MUTATION_END) {
-        if (ls->mEventType == NS_MUTATION_SUBTREEMODIFIED) {
+      Listener* listener = &mListeners.ElementAt(i);
+      if (listener->mEventType >= NS_MUTATION_START &&
+          listener->mEventType <= NS_MUTATION_END) {
+        if (listener->mEventType == NS_MUTATION_SUBTREEMODIFIED) {
           return kAllMutationBits;
         }
-        bits |= MutationBitForEventType(ls->mEventType);
+        bits |= MutationBitForEventType(listener->mEventType);
       }
     }
   }
   return bits;
 }
 
 bool
-nsEventListenerManager::HasListenersFor(const nsAString& aEventName)
+EventListenerManager::HasListenersFor(const nsAString& aEventName)
 {
   nsCOMPtr<nsIAtom> atom = do_GetAtom(NS_LITERAL_STRING("on") + aEventName);
   return HasListenersFor(atom);
 }
 
 bool
-nsEventListenerManager::HasListenersFor(nsIAtom* aEventNameWithOn)
+EventListenerManager::HasListenersFor(nsIAtom* aEventNameWithOn)
 {
 #ifdef DEBUG
   nsAutoString name;
   aEventNameWithOn->ToString(name);
 #endif
   NS_ASSERTION(StringBeginsWith(name, NS_LITERAL_STRING("on")),
                "Event name does not start with 'on'");
   uint32_t count = mListeners.Length();
   for (uint32_t i = 0; i < count; ++i) {
-    nsListenerStruct* ls = &mListeners.ElementAt(i);
-    if (ls->mTypeAtom == aEventNameWithOn) {
+    Listener* listener = &mListeners.ElementAt(i);
+    if (listener->mTypeAtom == aEventNameWithOn) {
       return true;
     }
   }
   return false;
 }
 
 bool
-nsEventListenerManager::HasListeners()
+EventListenerManager::HasListeners()
 {
   return !mListeners.IsEmpty();
 }
 
 nsresult
-nsEventListenerManager::GetListenerInfo(nsCOMArray<nsIEventListenerInfo>* aList)
+EventListenerManager::GetListenerInfo(nsCOMArray<nsIEventListenerInfo>* aList)
 {
   nsCOMPtr<EventTarget> target = do_QueryInterface(mTarget);
   NS_ENSURE_STATE(target);
   aList->Clear();
   uint32_t count = mListeners.Length();
   for (uint32_t i = 0; i < count; ++i) {
-    const nsListenerStruct& ls = mListeners.ElementAt(i);
+    const Listener& listener = mListeners.ElementAt(i);
     // If this is a script handler and we haven't yet
     // compiled the event handler itself go ahead and compile it
-    if ((ls.mListenerType == eJSEventListener) && ls.mHandlerIsString) {
-      CompileEventHandlerInternal(const_cast<nsListenerStruct*>(&ls), nullptr,
+    if (listener.mListenerType == Listener::eJSEventListener &&
+        listener.mHandlerIsString) {
+      CompileEventHandlerInternal(const_cast<Listener*>(&listener), nullptr,
                                   nullptr);
     }
     nsAutoString eventType;
-    if (ls.mAllEvents) {
+    if (listener.mAllEvents) {
       eventType.SetIsVoid(true);
     } else {
-      eventType.Assign(Substring(nsDependentAtomString(ls.mTypeAtom), 2));
+      eventType.Assign(Substring(nsDependentAtomString(listener.mTypeAtom), 2));
     }
     // EventListenerInfo is defined in XPCOM, so we have to go ahead
     // and convert to an XPCOM callback here...
-    nsRefPtr<nsEventListenerInfo> info =
-      new nsEventListenerInfo(eventType, ls.mListener.ToXPCOMCallback(),
-                              ls.mFlags.mCapture,
-                              ls.mFlags.mAllowUntrustedEvents,
-                              ls.mFlags.mInSystemGroup);
+    nsRefPtr<EventListenerInfo> info =
+      new EventListenerInfo(eventType, listener.mListener.ToXPCOMCallback(),
+                            listener.mFlags.mCapture,
+                            listener.mFlags.mAllowUntrustedEvents,
+                            listener.mFlags.mInSystemGroup);
     aList->AppendObject(info);
   }
   return NS_OK;
 }
 
 bool
-nsEventListenerManager::HasUnloadListeners()
+EventListenerManager::HasUnloadListeners()
 {
   uint32_t count = mListeners.Length();
   for (uint32_t i = 0; i < count; ++i) {
-    nsListenerStruct* ls = &mListeners.ElementAt(i);
-    if (ls->mEventType == NS_PAGE_UNLOAD ||
-        ls->mEventType == NS_BEFORE_PAGE_UNLOAD) {
+    Listener* listener = &mListeners.ElementAt(i);
+    if (listener->mEventType == NS_PAGE_UNLOAD ||
+        listener->mEventType == NS_BEFORE_PAGE_UNLOAD) {
       return true;
     }
   }
   return false;
 }
 
 void
-nsEventListenerManager::SetEventHandler(nsIAtom* aEventName,
-                                        const nsAString& aTypeString,
-                                        EventHandlerNonNull* aHandler)
+EventListenerManager::SetEventHandler(nsIAtom* aEventName,
+                                      const nsAString& aTypeString,
+                                      EventHandlerNonNull* aHandler)
 {
   if (!aHandler) {
     RemoveEventHandler(aEventName, aTypeString);
     return;
   }
 
   // Untrusted events are always permitted for non-chrome script
   // handlers.
   SetEventHandlerInternal(JS::NullPtr(), aEventName,
                           aTypeString, nsEventHandler(aHandler),
                           !mIsMainThreadELM ||
                           !nsContentUtils::IsCallerChrome());
 }
 
 void
-nsEventListenerManager::SetEventHandler(OnErrorEventHandlerNonNull* aHandler)
+EventListenerManager::SetEventHandler(OnErrorEventHandlerNonNull* aHandler)
 {
   if (mIsMainThreadELM) {
     if (!aHandler) {
       RemoveEventHandler(nsGkAtoms::onerror, EmptyString());
       return;
     }
 
     // Untrusted events are always permitted for non-chrome script
@@ -1255,100 +1269,100 @@ nsEventListenerManager::SetEventHandler(
     // Untrusted events are always permitted.
     SetEventHandlerInternal(JS::NullPtr(), nullptr,
                             NS_LITERAL_STRING("error"),
                             nsEventHandler(aHandler), true);
   }
 }
 
 void
-nsEventListenerManager::SetEventHandler(OnBeforeUnloadEventHandlerNonNull* aHandler)
+EventListenerManager::SetEventHandler(
+                        OnBeforeUnloadEventHandlerNonNull* aHandler)
 {
   if (!aHandler) {
     RemoveEventHandler(nsGkAtoms::onbeforeunload, EmptyString());
     return;
   }
 
   // Untrusted events are always permitted for non-chrome script
   // handlers.
   SetEventHandlerInternal(JS::NullPtr(), nsGkAtoms::onbeforeunload,
                           EmptyString(), nsEventHandler(aHandler),
                           !mIsMainThreadELM ||
                           !nsContentUtils::IsCallerChrome());
 }
 
 const nsEventHandler*
-nsEventListenerManager::GetEventHandlerInternal(nsIAtom *aEventName,
-                                                const nsAString& aTypeString)
+EventListenerManager::GetEventHandlerInternal(nsIAtom* aEventName,
+                                              const nsAString& aTypeString)
 {
   uint32_t eventType = nsContentUtils::GetEventId(aEventName);
-  nsListenerStruct* ls = FindEventHandler(eventType, aEventName, aTypeString);
+  Listener* listener = FindEventHandler(eventType, aEventName, aTypeString);
 
-  if (!ls) {
+  if (!listener) {
     return nullptr;
   }
 
-  nsIJSEventListener *listener = ls->GetJSListener();
-    
-  if (ls->mHandlerIsString) {
-    CompileEventHandlerInternal(ls, nullptr, nullptr);
+  nsIJSEventListener* jsListener = listener->GetJSListener();
+
+  if (listener->mHandlerIsString) {
+    CompileEventHandlerInternal(listener, nullptr, nullptr);
   }
 
-  const nsEventHandler& handler = listener->GetHandler();
+  const nsEventHandler& handler = jsListener->GetHandler();
   if (handler.HasEventHandler()) {
     return &handler;
   }
 
   return nullptr;
 }
 
 size_t
-nsEventListenerManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
-  const
+EventListenerManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t n = aMallocSizeOf(this);
   n += mListeners.SizeOfExcludingThis(aMallocSizeOf);
   uint32_t count = mListeners.Length();
   for (uint32_t i = 0; i < count; ++i) {
     nsIJSEventListener* jsl = mListeners.ElementAt(i).GetJSListener();
     if (jsl) {
       n += jsl->SizeOfIncludingThis(aMallocSizeOf);
     }
   }
   return n;
 }
 
 void
-nsEventListenerManager::MarkForCC()
+EventListenerManager::MarkForCC()
 {
   uint32_t count = mListeners.Length();
   for (uint32_t i = 0; i < count; ++i) {
-    const nsListenerStruct& ls = mListeners.ElementAt(i);
-    nsIJSEventListener* jsl = ls.GetJSListener();
-    if (jsl) {
-      if (jsl->GetHandler().HasEventHandler()) {
-        JS::ExposeObjectToActiveJS(jsl->GetHandler().Ptr()->Callable());
+    const Listener& listener = mListeners.ElementAt(i);
+    nsIJSEventListener* jsListener = listener.GetJSListener();
+    if (jsListener) {
+      if (jsListener->GetHandler().HasEventHandler()) {
+        JS::ExposeObjectToActiveJS(jsListener->GetHandler().Ptr()->Callable());
       }
-      if (JSObject* scope = jsl->GetEventScope()) {
+      if (JSObject* scope = jsListener->GetEventScope()) {
         JS::ExposeObjectToActiveJS(scope);
       }
-    } else if (ls.mListenerType == eWrappedJSListener) {
-      xpc_TryUnmarkWrappedGrayObject(ls.mListener.GetXPCOMCallback());
-    } else if (ls.mListenerType == eWebIDLListener) {
+    } else if (listener.mListenerType == Listener::eWrappedJSListener) {
+      xpc_TryUnmarkWrappedGrayObject(listener.mListener.GetXPCOMCallback());
+    } else if (listener.mListenerType == Listener::eWebIDLListener) {
       // Callback() unmarks gray
-      ls.mListener.GetWebIDLCallback()->Callback();
+      listener.mListener.GetWebIDLCallback()->Callback();
     }
   }
   if (mRefCnt.IsPurple()) {
     mRefCnt.RemovePurple();
   }
 }
 
 already_AddRefed<nsIScriptGlobalObject>
-nsEventListenerManager::GetScriptGlobalAndDocument(nsIDocument** aDoc)
+EventListenerManager::GetScriptGlobalAndDocument(nsIDocument** aDoc)
 {
   nsCOMPtr<nsINode> node(do_QueryInterface(mTarget));
   nsCOMPtr<nsIDocument> doc;
   nsCOMPtr<nsIScriptGlobalObject> global;
   if (node) {
     // Try to get context from doc
     // XXX sXBL/XBL2 issue -- do we really want the owner here?  What
     // if that's the XBL document?
@@ -1368,8 +1382,10 @@ nsEventListenerManager::GetScriptGlobalA
     } else {
       global = do_QueryInterface(mTarget);
     }
   }
 
   doc.forget(aDoc);
   return global.forget();
 }
+
+} // namespace mozilla
rename from dom/events/nsEventListenerManager.h
rename to dom/events/EventListenerManager.h
--- a/dom/events/nsEventListenerManager.h
+++ b/dom/events/EventListenerManager.h
@@ -1,51 +1,52 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef nsEventListenerManager_h__
-#define nsEventListenerManager_h__
+#ifndef mozilla_EventListenerManager_h_
+#define mozilla_EventListenerManager_h_
 
 #include "mozilla/BasicEvents.h"
 #include "mozilla/dom/EventListenerBinding.h"
 #include "mozilla/MemoryReporting.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMEventListener.h"
 #include "nsIJSEventListener.h"
 #include "nsTObserverArray.h"
 
+class ELMCreationDetector;
+class nsEventTargetChainItem;
 class nsIDOMEvent;
-struct EventTypeData;
-class nsEventTargetChainItem;
-class nsPIDOMWindow;
 class nsIEventListenerInfo;
 class nsIScriptContext;
+class nsPIDOMWindow;
 
-struct nsListenerStruct;
-class nsEventListenerManager;
+struct EventTypeData;
 
 template<class T> class nsCOMArray;
 
 namespace mozilla {
+
+class EventListenerManager;
+
 namespace dom {
-
 class EventTarget;
 class Element;
+} // namespace dom
 
-typedef CallbackObjectHolder<EventListener, nsIDOMEventListener>
-  EventListenerHolder;
+typedef dom::CallbackObjectHolder<dom::EventListener,
+                                  nsIDOMEventListener> EventListenerHolder;
 
 struct EventListenerFlags
 {
-  friend struct ::nsListenerStruct;
-  friend class  ::nsEventListenerManager;
+  friend class EventListenerManager;
 private:
   // If mListenerIsJSListener is true, the listener is implemented by JS.
   // Otherwise, it's implemented by native code or JS but it's wrapped.
   bool mListenerIsJSListener : 1;
 
 public:
   // If mCapture is true, it means the listener captures the event.  Otherwise,
   // it's listening at bubbling phase.
@@ -139,115 +140,115 @@ inline EventListenerFlags AllEventsAtSys
 {
   EventListenerFlags flags;
   flags.mCapture = true;
   flags.mInSystemGroup = true;
   flags.mAllowUntrustedEvents = true;
   return flags;
 }
 
-} // namespace dom
-} // namespace mozilla
-
-typedef enum
-{
-    eNativeListener = 0,
-    eJSEventListener,
-    eWrappedJSListener,
-    eWebIDLListener,
-    eListenerTypeCount
-} nsListenerType;
-
-struct nsListenerStruct
-{
-  mozilla::dom::EventListenerHolder mListener;
-  nsCOMPtr<nsIAtom>             mTypeAtom;   // for the main thread
-  nsString                      mTypeString; // for non-main-threads
-  uint16_t                      mEventType;
-  uint8_t                       mListenerType;
-  bool                          mListenerIsHandler : 1;
-  bool                          mHandlerIsString : 1;
-  bool                          mAllEvents : 1;
-
-  mozilla::dom::EventListenerFlags mFlags;
-
-  nsIJSEventListener* GetJSListener() const {
-    return (mListenerType == eJSEventListener) ?
-      static_cast<nsIJSEventListener *>(mListener.GetXPCOMCallback()) : nullptr;
-  }
-
-  nsListenerStruct()
-  {
-    MOZ_ASSERT(sizeof(mListenerType) == 1);
-    MOZ_ASSERT(eListenerTypeCount < 255);
-  }
-
-  ~nsListenerStruct()
-  {
-    if ((mListenerType == eJSEventListener) && mListener) {
-      static_cast<nsIJSEventListener*>(mListener.GetXPCOMCallback())->Disconnect();
-    }
-  }
-
-  MOZ_ALWAYS_INLINE bool IsListening(const mozilla::WidgetEvent* aEvent) const
-  {
-    if (mFlags.mInSystemGroup != aEvent->mFlags.mInSystemGroup) {
-      return false;
-    }
-    // FIXME Should check !mFlags.mCapture when the event is in target
-    //       phase because capture phase event listeners should not be fired.
-    //       But it breaks at least <xul:dialog>'s buttons. Bug 235441.
-    return ((mFlags.mCapture && aEvent->mFlags.mInCapturePhase) ||
-            (!mFlags.mCapture && aEvent->mFlags.mInBubblingPhase));
-  }
-};
-
 /*
  * Event listener manager
  */
 
-class nsEventListenerManager
+class EventListenerManager MOZ_FINAL
 {
-
 public:
-  nsEventListenerManager(mozilla::dom::EventTarget* aTarget);
-  virtual ~nsEventListenerManager();
+  struct Listener
+  {
+    EventListenerHolder mListener;
+    nsCOMPtr<nsIAtom> mTypeAtom; // for the main thread
+    nsString mTypeString; // for non-main-threads
+    uint16_t mEventType;
+
+    enum ListenerType MOZ_ENUM_TYPE(uint8_t)
+    {
+      eNativeListener = 0,
+      eJSEventListener,
+      eWrappedJSListener,
+      eWebIDLListener,
+      eListenerTypeCount
+    };
+    uint8_t mListenerType;
+
+    bool mListenerIsHandler : 1;
+    bool mHandlerIsString : 1;
+    bool mAllEvents : 1;
+
+    EventListenerFlags mFlags;
+
+    nsIJSEventListener* GetJSListener() const
+    {
+      return (mListenerType == eJSEventListener) ?
+        static_cast<nsIJSEventListener *>(mListener.GetXPCOMCallback()) :
+        nullptr;
+    }
 
-  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsEventListenerManager)
+    Listener()
+    {
+      MOZ_ASSERT(sizeof(mListenerType) == 1);
+      MOZ_ASSERT(eListenerTypeCount < 255);
+    }
+
+    ~Listener()
+    {
+      if ((mListenerType == eJSEventListener) && mListener) {
+        static_cast<nsIJSEventListener*>(
+          mListener.GetXPCOMCallback())->Disconnect();
+      }
+    }
 
-  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsEventListenerManager)
+    MOZ_ALWAYS_INLINE bool IsListening(const WidgetEvent* aEvent) const
+    {
+      if (mFlags.mInSystemGroup != aEvent->mFlags.mInSystemGroup) {
+        return false;
+      }
+      // FIXME Should check !mFlags.mCapture when the event is in target
+      //       phase because capture phase event listeners should not be fired.
+      //       But it breaks at least <xul:dialog>'s buttons. Bug 235441.
+      return ((mFlags.mCapture && aEvent->mFlags.mInCapturePhase) ||
+              (!mFlags.mCapture && aEvent->mFlags.mInBubblingPhase));
+    }
+  };
+
+  EventListenerManager(dom::EventTarget* aTarget);
+  virtual ~EventListenerManager();
+
+  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(EventListenerManager)
+
+  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(EventListenerManager)
 
   void AddEventListener(const nsAString& aType,
                         nsIDOMEventListener* aListener,
                         bool aUseCapture,
                         bool aWantsUntrusted)
   {
-    mozilla::dom::EventListenerHolder holder(aListener);
+    EventListenerHolder holder(aListener);
     AddEventListener(aType, holder, aUseCapture, aWantsUntrusted);
   }
   void AddEventListener(const nsAString& aType,
-                        mozilla::dom::EventListener* aListener,
+                        dom::EventListener* aListener,
                         bool aUseCapture,
                         bool aWantsUntrusted)
   {
-    mozilla::dom::EventListenerHolder holder(aListener);
+    EventListenerHolder holder(aListener);
     AddEventListener(aType, holder, aUseCapture, aWantsUntrusted);
   }
   void RemoveEventListener(const nsAString& aType,
                            nsIDOMEventListener* aListener,
                            bool aUseCapture)
   {
-    mozilla::dom::EventListenerHolder holder(aListener);
+    EventListenerHolder holder(aListener);
     RemoveEventListener(aType, holder, aUseCapture);
   }
   void RemoveEventListener(const nsAString& aType,
-                           mozilla::dom::EventListener* aListener,
+                           dom::EventListener* aListener,
                            bool aUseCapture)
   {
-    mozilla::dom::EventListenerHolder holder(aListener);
+    EventListenerHolder holder(aListener);
     RemoveEventListener(aType, holder, aUseCapture);
   }
 
   void AddListenerForAllEvents(nsIDOMEventListener* aListener,
                                bool aUseCapture,
                                bool aWantsUntrusted,
                                bool aSystemEventGroup);
   void RemoveListenerForAllEvents(nsIDOMEventListener* aListener,
@@ -255,60 +256,60 @@ public:
                                   bool aSystemEventGroup);
 
   /**
   * Sets events listeners of all types. 
   * @param an event listener
   */
   void AddEventListenerByType(nsIDOMEventListener *aListener,
                               const nsAString& type,
-                              const mozilla::dom::EventListenerFlags& aFlags)
+                              const EventListenerFlags& aFlags)
   {
-    mozilla::dom::EventListenerHolder holder(aListener);
+    EventListenerHolder holder(aListener);
     AddEventListenerByType(holder, type, aFlags);
   }
-  void AddEventListenerByType(const mozilla::dom::EventListenerHolder& aListener,
+  void AddEventListenerByType(const EventListenerHolder& aListener,
                               const nsAString& type,
-                              const mozilla::dom::EventListenerFlags& aFlags);
+                              const EventListenerFlags& aFlags);
   void RemoveEventListenerByType(nsIDOMEventListener *aListener,
                                  const nsAString& type,
-                                 const mozilla::dom::EventListenerFlags& aFlags)
+                                 const EventListenerFlags& aFlags)
   {
-    mozilla::dom::EventListenerHolder holder(aListener);
+    EventListenerHolder holder(aListener);
     RemoveEventListenerByType(holder, type, aFlags);
   }
-  void RemoveEventListenerByType(const mozilla::dom::EventListenerHolder& aListener,
+  void RemoveEventListenerByType(const EventListenerHolder& aListener,
                                  const nsAString& type,
-                                 const mozilla::dom::EventListenerFlags& aFlags);
+                                 const EventListenerFlags& aFlags);
 
   /**
    * Sets the current "inline" event listener for aName to be a
    * function compiled from aFunc if !aDeferCompilation.  If
    * aDeferCompilation, then we assume that we can get the string from
    * mTarget later and compile lazily.
    *
    * aElement, if not null, is the element the string is associated with.
    */
   // XXXbz does that play correctly with nodes being adopted across
   // documents?  Need to double-check the spec here.
   nsresult SetEventHandler(nsIAtom *aName,
                            const nsAString& aFunc,
                            uint32_t aLanguage,
                            bool aDeferCompilation,
                            bool aPermitUntrustedEvents,
-                           mozilla::dom::Element* aElement);
+                           dom::Element* aElement);
   /**
    * Remove the current "inline" event listener for aName.
    */
   void RemoveEventHandler(nsIAtom *aName, const nsAString& aTypeString);
 
   void HandleEvent(nsPresContext* aPresContext,
-                   mozilla::WidgetEvent* aEvent, 
+                   WidgetEvent* aEvent, 
                    nsIDOMEvent** aDOMEvent,
-                   mozilla::dom::EventTarget* aCurrentTarget,
+                   dom::EventTarget* aCurrentTarget,
                    nsEventStatus* aEventStatus)
   {
     if (mListeners.IsEmpty() || aEvent->mFlags.mPropagationStopped) {
       return;
     }
 
     if (!mMayHaveCapturingListeners && !aEvent->mFlags.mInBubblingPhase) {
       return;
@@ -396,192 +397,195 @@ public:
    * Returns true if there may be a touch event listener registered,
    * false if there definitely isn't.
    */
   bool MayHaveTouchEventListener() { return mMayHaveTouchEventListener; }
 
   bool MayHaveMouseEnterLeaveEventListener() { return mMayHaveMouseEnterLeaveEventListener; }
   bool MayHavePointerEnterLeaveEventListener() { return mMayHavePointerEnterLeaveEventListener; }
 
-  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
 
   uint32_t ListenerCount() const
   {
     return mListeners.Length();
   }
 
   void MarkForCC();
 
-  mozilla::dom::EventTarget* GetTarget() { return mTarget; }
+  dom::EventTarget* GetTarget() { return mTarget; }
+
 protected:
   void HandleEventInternal(nsPresContext* aPresContext,
-                           mozilla::WidgetEvent* aEvent,
+                           WidgetEvent* aEvent,
                            nsIDOMEvent** aDOMEvent,
-                           mozilla::dom::EventTarget* aCurrentTarget,
+                           dom::EventTarget* aCurrentTarget,
                            nsEventStatus* aEventStatus);
 
-  nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
+  nsresult HandleEventSubType(Listener* aListener,
                               nsIDOMEvent* aDOMEvent,
-                              mozilla::dom::EventTarget* aCurrentTarget);
+                              dom::EventTarget* aCurrentTarget);
 
   /**
-   * Compile the "inline" event listener for aListenerStruct.  The
+   * Compile the "inline" event listener for aListener.  The
    * body of the listener can be provided in aBody; if this is null we
    * will look for it on mTarget.  If aBody is provided, aElement should be
    * as well; otherwise it will also be inferred from mTarget.
    */
-  nsresult CompileEventHandlerInternal(nsListenerStruct *aListenerStruct,
+  nsresult CompileEventHandlerInternal(Listener* aListener,
                                        const nsAString* aBody,
-                                       mozilla::dom::Element* aElement);
+                                       dom::Element* aElement);
 
   /**
-   * Find the nsListenerStruct for the "inline" event listener for aTypeAtom.
+   * Find the Listener for the "inline" event listener for aTypeAtom.
    */
-  nsListenerStruct* FindEventHandler(uint32_t aEventType, nsIAtom* aTypeAtom,
-                                     const nsAString& aTypeString);
+  Listener* FindEventHandler(uint32_t aEventType,
+                             nsIAtom* aTypeAtom,
+                             const nsAString& aTypeString);
 
   /**
    * Set the "inline" event listener for aName to aHandler.  aHandler may be
    * have no actual handler set to indicate that we should lazily get and
    * compile the string for this listener, but in that case aContext and
    * aScopeGlobal must be non-null.  Otherwise, aContext and aScopeGlobal are
-   * allowed to be null.  The nsListenerStruct that results, if any, is returned
-   * in aListenerStruct.
+   * allowed to be null.
    */
-  nsListenerStruct* SetEventHandlerInternal(JS::Handle<JSObject*> aScopeGlobal,
-                                            nsIAtom* aName,
-                                            const nsAString& aTypeString,
-                                            const nsEventHandler& aHandler,
-                                            bool aPermitUntrustedEvents);
+  Listener* SetEventHandlerInternal(JS::Handle<JSObject*> aScopeGlobal,
+                                    nsIAtom* aName,
+                                    const nsAString& aTypeString,
+                                    const nsEventHandler& aHandler,
+                                    bool aPermitUntrustedEvents);
 
   bool IsDeviceType(uint32_t aType);
   void EnableDevice(uint32_t aType);
   void DisableDevice(uint32_t aType);
 
 public:
   /**
    * Set the "inline" event listener for aEventName to aHandler.  If
    * aHandler is null, this will actually remove the event listener
    */
   void SetEventHandler(nsIAtom* aEventName,
                        const nsAString& aTypeString,
-                       mozilla::dom::EventHandlerNonNull* aHandler);
-  void SetEventHandler(mozilla::dom::OnErrorEventHandlerNonNull* aHandler);
-  void SetEventHandler(mozilla::dom::OnBeforeUnloadEventHandlerNonNull* aHandler);
+                       dom::EventHandlerNonNull* aHandler);
+  void SetEventHandler(dom::OnErrorEventHandlerNonNull* aHandler);
+  void SetEventHandler(dom::OnBeforeUnloadEventHandlerNonNull* aHandler);
 
   /**
    * Get the value of the "inline" event listener for aEventName.
    * This may cause lazy compilation if the listener is uncompiled.
    *
    * Note: It's the caller's responsibility to make sure to call the right one
    * of these methods.  In particular, "onerror" events use
    * OnErrorEventHandlerNonNull for some event targets and EventHandlerNonNull
    * for others.
    */
-  mozilla::dom::EventHandlerNonNull* GetEventHandler(nsIAtom *aEventName,
-                                                     const nsAString& aTypeString)
+  dom::EventHandlerNonNull* GetEventHandler(nsIAtom* aEventName,
+                                            const nsAString& aTypeString)
   {
     const nsEventHandler* handler =
       GetEventHandlerInternal(aEventName, aTypeString);
     return handler ? handler->EventHandler() : nullptr;
   }
-  mozilla::dom::OnErrorEventHandlerNonNull* GetOnErrorEventHandler()
+
+  dom::OnErrorEventHandlerNonNull* GetOnErrorEventHandler()
   {
     const nsEventHandler* handler;
     if (mIsMainThreadELM) {
       handler = GetEventHandlerInternal(nsGkAtoms::onerror, EmptyString());
     } else {
       handler = GetEventHandlerInternal(nullptr, NS_LITERAL_STRING("error"));
     }
     return handler ? handler->OnErrorEventHandler() : nullptr;
   }
-  mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOnBeforeUnloadEventHandler()
+
+  dom::OnBeforeUnloadEventHandlerNonNull* GetOnBeforeUnloadEventHandler()
   {
     const nsEventHandler* handler =
       GetEventHandlerInternal(nsGkAtoms::onbeforeunload, EmptyString());
     return handler ? handler->OnBeforeUnloadEventHandler() : nullptr;
   }
 
 protected:
   /**
    * Helper method for implementing the various Get*EventHandler above.  Will
    * return null if we don't have an event handler for this event name.
    */
   const nsEventHandler* GetEventHandlerInternal(nsIAtom* aEventName,
                                                 const nsAString& aTypeString);
 
   void AddEventListener(const nsAString& aType,
-                        const mozilla::dom::EventListenerHolder& aListener,
+                        const EventListenerHolder& aListener,
                         bool aUseCapture,
                         bool aWantsUntrusted);
   void RemoveEventListener(const nsAString& aType,
-                           const mozilla::dom::EventListenerHolder& aListener,
+                           const EventListenerHolder& aListener,
                            bool aUseCapture);
 
-  void AddEventListenerInternal(
-         const mozilla::dom::EventListenerHolder& aListener,
-         uint32_t aType,
-         nsIAtom* aTypeAtom,
-         const nsAString& aTypeString,
-         const mozilla::dom::EventListenerFlags& aFlags,
-         bool aHandler = false,
-         bool aAllEvents = false);
-  void RemoveEventListenerInternal(
-         const mozilla::dom::EventListenerHolder& aListener,
-         uint32_t aType,
-         nsIAtom* aUserType,
-         const nsAString& aTypeString,
-         const mozilla::dom::EventListenerFlags& aFlags,
-         bool aAllEvents = false);
+  void AddEventListenerInternal(const EventListenerHolder& aListener,
+                                uint32_t aType,
+                                nsIAtom* aTypeAtom,
+                                const nsAString& aTypeString,
+                                const EventListenerFlags& aFlags,
+                                bool aHandler = false,
+                                bool aAllEvents = false);
+  void RemoveEventListenerInternal(const EventListenerHolder& aListener,
+                                   uint32_t aType,
+                                   nsIAtom* aUserType,
+                                   const nsAString& aTypeString,
+                                   const EventListenerFlags& aFlags,
+                                   bool aAllEvents = false);
   void RemoveAllListeners();
   const EventTypeData* GetTypeDataForIID(const nsIID& aIID);
   const EventTypeData* GetTypeDataForEventName(nsIAtom* aName);
   nsPIDOMWindow* GetInnerWindowForTarget();
   already_AddRefed<nsPIDOMWindow> GetTargetAsInnerWindow() const;
 
-  bool ListenerCanHandle(nsListenerStruct* aLs, mozilla::WidgetEvent* aEvent);
+  bool ListenerCanHandle(Listener* aListener, WidgetEvent* aEvent);
 
   already_AddRefed<nsIScriptGlobalObject>
   GetScriptGlobalAndDocument(nsIDocument** aDoc);
 
   uint32_t mMayHavePaintEventListener : 1;
   uint32_t mMayHaveMutationListeners : 1;
   uint32_t mMayHaveCapturingListeners : 1;
   uint32_t mMayHaveSystemGroupListeners : 1;
   uint32_t mMayHaveAudioAvailableEventListener : 1;
   uint32_t mMayHaveTouchEventListener : 1;
   uint32_t mMayHaveMouseEnterLeaveEventListener : 1;
   uint32_t mMayHavePointerEnterLeaveEventListener : 1;
   uint32_t mClearingListeners : 1;
   uint32_t mIsMainThreadELM : 1;
   uint32_t mNoListenerForEvent : 22;
 
-  nsAutoTObserverArray<nsListenerStruct, 2> mListeners;
-  mozilla::dom::EventTarget*                mTarget;  //WEAK
-  nsCOMPtr<nsIAtom>                         mNoListenerForEventAtom;
+  nsAutoTObserverArray<Listener, 2> mListeners;
+  dom::EventTarget* mTarget;  // WEAK
+  nsCOMPtr<nsIAtom> mNoListenerForEventAtom;
 
-  friend class ELMCreationDetector;
-  static uint32_t                           sMainThreadCreatedCount;
+  friend class ::ELMCreationDetector;
+  static uint32_t sMainThreadCreatedCount;
 };
 
+} // namespace mozilla
+
 /**
  * NS_AddSystemEventListener() is a helper function for implementing
  * EventTarget::AddSystemEventListener().
  */
 inline nsresult
 NS_AddSystemEventListener(mozilla::dom::EventTarget* aTarget,
                           const nsAString& aType,
                           nsIDOMEventListener *aListener,
                           bool aUseCapture,
                           bool aWantsUntrusted)
 {
-  nsEventListenerManager* listenerManager =
+  mozilla::EventListenerManager* listenerManager =
     aTarget->GetOrCreateListenerManager();
   NS_ENSURE_STATE(listenerManager);
-  mozilla::dom::EventListenerFlags flags;
+  mozilla::EventListenerFlags flags;
   flags.mInSystemGroup = true;
   flags.mCapture = aUseCapture;
   flags.mAllowUntrustedEvents = aWantsUntrusted;
   listenerManager->AddEventListenerByType(aListener, aType, flags);
   return NS_OK;
 }
 
-#endif // nsEventListenerManager_h__
+#endif // mozilla_EventListenerManager_h_
rename from dom/events/nsEventListenerService.cpp
rename to dom/events/EventListenerService.cpp
--- a/dom/events/nsEventListenerService.cpp
+++ b/dom/events/EventListenerService.cpp
@@ -1,89 +1,98 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "nsEventListenerService.h"
-#include "nsCOMArray.h"
-#include "nsEventListenerManager.h"
-#include "nsMemory.h"
-#include "nsCxPusher.h"
-#include "nsIXPConnect.h"
-#include "nsJSUtils.h"
-#include "nsEventDispatcher.h"
-#include "nsIJSEventListener.h"
+
+#include "EventListenerService.h"
 #ifdef MOZ_JSDEBUGGER
 #include "jsdIDebuggerService.h"
 #endif
+#include "mozilla/BasicEvents.h"
+#include "mozilla/EventListenerManager.h"
+#include "mozilla/Maybe.h"
+#include "nsCOMArray.h"
+#include "nsCxPusher.h"
 #include "nsDOMClassInfoID.h"
-#include "mozilla/BasicEvents.h"
-#include "mozilla/Maybe.h"
+#include "nsEventDispatcher.h"
+#include "nsIJSEventListener.h"
+#include "nsIXPConnect.h"
+#include "nsJSUtils.h"
+#include "nsMemory.h"
 #include "nsServiceManagerUtils.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
-using mozilla::AutoSafeJSContext;
+DOMCI_DATA(EventListenerInfo, mozilla::EventListenerInfo)
+
+namespace mozilla {
+
+using namespace dom;
 
-NS_IMPL_CYCLE_COLLECTION_1(nsEventListenerInfo, mListener)
+/******************************************************************************
+ * mozilla::EventListenerInfo
+ ******************************************************************************/
 
-DOMCI_DATA(EventListenerInfo, nsEventListenerInfo)
+NS_IMPL_CYCLE_COLLECTION_1(EventListenerInfo, mListener)
 
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsEventListenerInfo)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EventListenerInfo)
   NS_INTERFACE_MAP_ENTRY(nsIEventListenerInfo)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(EventListenerInfo)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsEventListenerInfo)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsEventListenerInfo)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(EventListenerInfo)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(EventListenerInfo)
 
 NS_IMETHODIMP
-nsEventListenerInfo::GetType(nsAString& aType)
+EventListenerInfo::GetType(nsAString& aType)
 {
   aType = mType;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerInfo::GetCapturing(bool* aCapturing)
+EventListenerInfo::GetCapturing(bool* aCapturing)
 {
   *aCapturing = mCapturing;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerInfo::GetAllowsUntrusted(bool* aAllowsUntrusted)
+EventListenerInfo::GetAllowsUntrusted(bool* aAllowsUntrusted)
 {
   *aAllowsUntrusted = mAllowsUntrusted;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerInfo::GetInSystemEventGroup(bool* aInSystemEventGroup)
+EventListenerInfo::GetInSystemEventGroup(bool* aInSystemEventGroup)
 {
   *aInSystemEventGroup = mInSystemEventGroup;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerInfo::GetListenerObject(JSContext* aCx,
-                                       JS::MutableHandle<JS::Value> aObject)
+EventListenerInfo::GetListenerObject(JSContext* aCx,
+                                     JS::MutableHandle<JS::Value> aObject)
 {
-  mozilla::Maybe<JSAutoCompartment> ac;
+  Maybe<JSAutoCompartment> ac;
   GetJSVal(aCx, ac, aObject);
   return NS_OK;
 }
 
-NS_IMPL_ISUPPORTS1(nsEventListenerService, nsIEventListenerService)
+/******************************************************************************
+ * mozilla::EventListenerService
+ ******************************************************************************/
+
+NS_IMPL_ISUPPORTS1(EventListenerService, nsIEventListenerService)
 
 bool
-nsEventListenerInfo::GetJSVal(JSContext* aCx,
-                              mozilla::Maybe<JSAutoCompartment>& aAc,
-                              JS::MutableHandle<JS::Value> aJSVal)
+EventListenerInfo::GetJSVal(JSContext* aCx,
+                            Maybe<JSAutoCompartment>& aAc,
+                            JS::MutableHandle<JS::Value> aJSVal)
 {
   aJSVal.setNull();
   nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS = do_QueryInterface(mListener);
   if (wrappedJS) {
     JS::Rooted<JSObject*> object(aCx, wrappedJS->GetJSObject());
     if (!object) {
       return false;
     }
@@ -100,78 +109,78 @@ nsEventListenerInfo::GetJSVal(JSContext*
       aJSVal.setObject(*handler);
       return true;
     }
   }
   return false;
 }
 
 NS_IMETHODIMP
-nsEventListenerInfo::ToSource(nsAString& aResult)
+EventListenerInfo::ToSource(nsAString& aResult)
 {
   aResult.SetIsVoid(true);
 
   AutoSafeJSContext cx;
-  mozilla::Maybe<JSAutoCompartment> ac;
+  Maybe<JSAutoCompartment> ac;
   JS::Rooted<JS::Value> v(cx);
   if (GetJSVal(cx, ac, &v)) {
     JSString* str = JS_ValueToSource(cx, v);
     if (str) {
       nsDependentJSString depStr;
       if (depStr.init(cx, str)) {
         aResult.Assign(depStr);
       }
     }
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerInfo::GetDebugObject(nsISupports** aRetVal)
+EventListenerInfo::GetDebugObject(nsISupports** aRetVal)
 {
   *aRetVal = nullptr;
 
 #ifdef MOZ_JSDEBUGGER
   nsresult rv = NS_OK;
   nsCOMPtr<jsdIDebuggerService> jsd =
     do_GetService("@mozilla.org/js/jsd/debugger-service;1", &rv);
   NS_ENSURE_SUCCESS(rv, NS_OK);
 
   bool isOn = false;
   jsd->GetIsOn(&isOn);
   NS_ENSURE_TRUE(isOn, NS_OK);
 
   AutoSafeJSContext cx;
-  mozilla::Maybe<JSAutoCompartment> ac;
+  Maybe<JSAutoCompartment> ac;
   JS::Rooted<JS::Value> v(cx);
   if (GetJSVal(cx, ac, &v)) {
     nsCOMPtr<jsdIValue> jsdValue;
     rv = jsd->WrapValue(v, getter_AddRefs(jsdValue));
     NS_ENSURE_SUCCESS(rv, rv);
     jsdValue.forget(aRetVal);
   }
 #endif
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerService::GetListenerInfoFor(nsIDOMEventTarget* aEventTarget,
-                                           uint32_t* aCount,
-                                           nsIEventListenerInfo*** aOutArray)
+EventListenerService::GetListenerInfoFor(nsIDOMEventTarget* aEventTarget,
+                                         uint32_t* aCount,
+                                         nsIEventListenerInfo*** aOutArray)
 {
   NS_ENSURE_ARG_POINTER(aEventTarget);
   *aCount = 0;
   *aOutArray = nullptr;
   nsCOMArray<nsIEventListenerInfo> listenerInfos;
 
   nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aEventTarget);
   NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
 
-  nsEventListenerManager* elm = eventTarget->GetExistingListenerManager();
+  EventListenerManager* elm = eventTarget->GetExistingListenerManager();
   if (elm) {
     elm->GetListenerInfo(&listenerInfos);
   }
 
   int32_t count = listenerInfos.Count();
   if (count == 0) {
     return NS_OK;
   }
@@ -184,19 +193,19 @@ nsEventListenerService::GetListenerInfoF
   for (int32_t i = 0; i < count; ++i) {
     NS_ADDREF((*aOutArray)[i] = listenerInfos[i]);
   }
   *aCount = count;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerService::GetEventTargetChainFor(nsIDOMEventTarget* aEventTarget,
-                                               uint32_t* aCount,
-                                               nsIDOMEventTarget*** aOutArray)
+EventListenerService::GetEventTargetChainFor(nsIDOMEventTarget* aEventTarget,
+                                             uint32_t* aCount,
+                                             nsIDOMEventTarget*** aOutArray)
 {
   *aCount = 0;
   *aOutArray = nullptr;
   NS_ENSURE_ARG(aEventTarget);
   WidgetEvent event(true, NS_EVENT_NULL);
   nsCOMArray<EventTarget> targets;
   nsresult rv = nsEventDispatcher::Dispatch(aEventTarget, nullptr, &event,
                                             nullptr, nullptr, nullptr, &targets);
@@ -215,109 +224,111 @@ nsEventListenerService::GetEventTargetCh
     NS_ADDREF((*aOutArray)[i] = targets[i]);
   }
   *aCount = count;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerService::HasListenersFor(nsIDOMEventTarget* aEventTarget,
-                                        const nsAString& aType,
-                                        bool* aRetVal)
+EventListenerService::HasListenersFor(nsIDOMEventTarget* aEventTarget,
+                                      const nsAString& aType,
+                                      bool* aRetVal)
 {
   nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aEventTarget);
   NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
 
-  nsEventListenerManager* elm = eventTarget->GetExistingListenerManager();
+  EventListenerManager* elm = eventTarget->GetExistingListenerManager();
   *aRetVal = elm && elm->HasListenersFor(aType);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerService::AddSystemEventListener(nsIDOMEventTarget *aTarget,
-                                               const nsAString& aType,
-                                               nsIDOMEventListener* aListener,
-                                               bool aUseCapture)
+EventListenerService::AddSystemEventListener(nsIDOMEventTarget *aTarget,
+                                             const nsAString& aType,
+                                             nsIDOMEventListener* aListener,
+                                             bool aUseCapture)
 {
   NS_PRECONDITION(aTarget, "Missing target");
   NS_PRECONDITION(aListener, "Missing listener");
 
   nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
   NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
 
-  nsEventListenerManager* manager = eventTarget->GetOrCreateListenerManager();
+  EventListenerManager* manager = eventTarget->GetOrCreateListenerManager();
   NS_ENSURE_STATE(manager);
 
   EventListenerFlags flags =
     aUseCapture ? TrustedEventsAtSystemGroupCapture() :
                   TrustedEventsAtSystemGroupBubble();
   manager->AddEventListenerByType(aListener, aType, flags);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerService::RemoveSystemEventListener(nsIDOMEventTarget *aTarget,
-                                                  const nsAString& aType,
-                                                  nsIDOMEventListener* aListener,
-                                                  bool aUseCapture)
+EventListenerService::RemoveSystemEventListener(nsIDOMEventTarget *aTarget,
+                                                const nsAString& aType,
+                                                nsIDOMEventListener* aListener,
+                                                bool aUseCapture)
 {
   NS_PRECONDITION(aTarget, "Missing target");
   NS_PRECONDITION(aListener, "Missing listener");
 
   nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
   NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
 
-  nsEventListenerManager* manager = eventTarget->GetExistingListenerManager();
+  EventListenerManager* manager = eventTarget->GetExistingListenerManager();
   if (manager) {
     EventListenerFlags flags =
       aUseCapture ? TrustedEventsAtSystemGroupCapture() :
                     TrustedEventsAtSystemGroupBubble();
     manager->RemoveEventListenerByType(aListener, aType, flags);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerService::AddListenerForAllEvents(nsIDOMEventTarget* aTarget,
-                                                nsIDOMEventListener* aListener,
-                                                bool aUseCapture,
-                                                bool aWantsUntrusted,
-                                                bool aSystemEventGroup)
+EventListenerService::AddListenerForAllEvents(nsIDOMEventTarget* aTarget,
+                                              nsIDOMEventListener* aListener,
+                                              bool aUseCapture,
+                                              bool aWantsUntrusted,
+                                              bool aSystemEventGroup)
 {
   NS_ENSURE_STATE(aTarget && aListener);
 
   nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
   NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
 
-  nsEventListenerManager* manager = eventTarget->GetOrCreateListenerManager();
+  EventListenerManager* manager = eventTarget->GetOrCreateListenerManager();
   NS_ENSURE_STATE(manager);
   manager->AddListenerForAllEvents(aListener, aUseCapture, aWantsUntrusted,
                                aSystemEventGroup);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventListenerService::RemoveListenerForAllEvents(nsIDOMEventTarget* aTarget,
-                                                   nsIDOMEventListener* aListener,
-                                                   bool aUseCapture,
-                                                   bool aSystemEventGroup)
+EventListenerService::RemoveListenerForAllEvents(nsIDOMEventTarget* aTarget,
+                                                 nsIDOMEventListener* aListener,
+                                                 bool aUseCapture,
+                                                 bool aSystemEventGroup)
 {
   NS_ENSURE_STATE(aTarget && aListener);
 
   nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
   NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
 
-  nsEventListenerManager* manager = eventTarget->GetExistingListenerManager();
+  EventListenerManager* manager = eventTarget->GetExistingListenerManager();
   if (manager) {
     manager->RemoveListenerForAllEvents(aListener, aUseCapture, aSystemEventGroup);
   }
   return NS_OK;
 }
 
+} // namespace mozilla
+
 nsresult
 NS_NewEventListenerService(nsIEventListenerService** aResult)
 {
-  *aResult = new nsEventListenerService();
+  *aResult = new mozilla::EventListenerService();
   NS_ADDREF(*aResult);
   return NS_OK;
 }
rename from dom/events/nsEventListenerService.h
rename to dom/events/EventListenerService.h
--- a/dom/events/nsEventListenerService.h
+++ b/dom/events/EventListenerService.h
@@ -1,53 +1,66 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef nsEventListenerService_h__
-#define nsEventListenerService_h__
-#include "nsIEventListenerService.h"
-#include "nsAutoPtr.h"
-#include "nsIDOMEventListener.h"
-#include "nsString.h"
-#include "nsCycleCollectionParticipant.h"
+#ifndef mozilla_EventListenerService_h_
+#define mozilla_EventListenerService_h_
+
 #include "jsapi.h"
 #include "mozilla/Attributes.h"
+#include "nsAutoPtr.h"
+#include "nsCycleCollectionParticipant.h"
+#include "nsIDOMEventListener.h"
+#include "nsIEventListenerService.h"
+#include "nsString.h"
 
 namespace mozilla {
+
 template<typename T>
 class Maybe;
-} // namespace mozilla
 
-class nsEventListenerInfo : public nsIEventListenerInfo
+class EventListenerInfo MOZ_FINAL : public nsIEventListenerInfo
 {
 public:
-  nsEventListenerInfo(const nsAString& aType,
-                      already_AddRefed<nsIDOMEventListener> aListener,
-                      bool aCapturing, bool aAllowsUntrusted,
-                      bool aInSystemEventGroup)
-  : mType(aType), mListener(aListener), mCapturing(aCapturing),
-    mAllowsUntrusted(aAllowsUntrusted),
-    mInSystemEventGroup(aInSystemEventGroup) {}
-  virtual ~nsEventListenerInfo() {}
+  EventListenerInfo(const nsAString& aType,
+                    already_AddRefed<nsIDOMEventListener> aListener,
+                    bool aCapturing,
+                    bool aAllowsUntrusted,
+                    bool aInSystemEventGroup)
+    : mType(aType)
+    , mListener(aListener)
+    , mCapturing(aCapturing)
+    , mAllowsUntrusted(aAllowsUntrusted)
+    , mInSystemEventGroup(aInSystemEventGroup)
+  {
+  }
+
+  virtual ~EventListenerInfo() {}
+
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS(nsEventListenerInfo)
+  NS_DECL_CYCLE_COLLECTION_CLASS(EventListenerInfo)
   NS_DECL_NSIEVENTLISTENERINFO
+
 protected:
-  bool GetJSVal(JSContext* aCx, mozilla::Maybe<JSAutoCompartment>& aAc,
+  bool GetJSVal(JSContext* aCx,
+                Maybe<JSAutoCompartment>& aAc,
                 JS::MutableHandle<JS::Value> aJSVal);
 
-  nsString                      mType;
+  nsString mType;
   // nsReftPtr because that is what nsListenerStruct uses too.
   nsRefPtr<nsIDOMEventListener> mListener;
-  bool                          mCapturing;
-  bool                          mAllowsUntrusted;
-  bool                          mInSystemEventGroup;
+  bool mCapturing;
+  bool mAllowsUntrusted;
+  bool mInSystemEventGroup;
 };
 
-class nsEventListenerService MOZ_FINAL : public nsIEventListenerService
+class EventListenerService MOZ_FINAL : public nsIEventListenerService
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIEVENTLISTENERSERVICE
 };
-#endif
+
+} // namespace mozilla
+
+#endif // mozilla_EventListenerService_h_
--- a/dom/events/EventTarget.cpp
+++ b/dom/events/EventTarget.cpp
@@ -1,36 +1,36 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/EventTarget.h"
-#include "nsEventListenerManager.h"
 #include "nsThreadUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 void
 EventTarget::RemoveEventListener(const nsAString& aType,
                                  EventListener* aListener,
                                  bool aUseCapture,
                                  ErrorResult& aRv)
 {
-  nsEventListenerManager* elm = GetExistingListenerManager();
+  EventListenerManager* elm = GetExistingListenerManager();
   if (elm) {
     elm->RemoveEventListener(aType, aListener, aUseCapture);
   }
 }
 
 EventHandlerNonNull*
 EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
 {
-  nsEventListenerManager* elm = GetExistingListenerManager();
+  EventListenerManager* elm = GetExistingListenerManager();
   return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
 }
 
 void
 EventTarget::SetEventHandler(const nsAString& aType,
                              EventHandlerNonNull* aHandler,
                              ErrorResult& aRv)
 {
--- a/dom/events/EventTarget.h
+++ b/dom/events/EventTarget.h
@@ -11,16 +11,17 @@
 #include "nsIAtom.h"
 
 class nsIDOMWindow;
 class nsIDOMEventListener;
 
 namespace mozilla {
 
 class ErrorResult;
+class EventListenerManager;
 
 namespace dom {
 
 class Event;
 class EventListener;
 class EventHandlerNonNull;
 template <class T> struct Nullable;
 
@@ -68,23 +69,23 @@ public:
   // Returns an outer window that corresponds to the inner window this event
   // target is associated with.  Will return null if the inner window is not the
   // current inner or if there is no window around at all.
   virtual nsIDOMWindow* GetOwnerGlobal() = 0;
 
   /**
    * Get the event listener manager, creating it if it does not already exist.
    */
-  virtual nsEventListenerManager* GetOrCreateListenerManager() = 0;
+  virtual EventListenerManager* GetOrCreateListenerManager() = 0;
 
   /**
    * Get the event listener manager, returning null if it does not already
    * exist.
    */
-  virtual nsEventListenerManager* GetExistingListenerManager() const = 0;
+  virtual EventListenerManager* GetExistingListenerManager() const = 0;
 
 protected:
   EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
                                        const nsAString& aTypeString);
   void SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
                        EventHandlerNonNull* aHandler);
 };
 
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -1,20 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ContentEventHandler.h"
 #include "IMEContentObserver.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/dom/Element.h"
 #include "nsAutoPtr.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsContentUtils.h"
 #include "nsGkAtoms.h"
 #include "nsIAtom.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMRange.h"
 #include "nsIFrame.h"
@@ -90,18 +90,18 @@ IMEContentObserver::Init(nsIWidget* aWid
     // The document node is editable, but there are no contents, this document
     // is not editable.
     return;
   }
   NS_ENSURE_TRUE_VOID(mRootContent);
 
   if (IMEStateManager::IsTestingIME()) {
     nsIDocument* doc = aPresContext->Document();
-    (new nsAsyncDOMEvent(doc, NS_LITERAL_STRING("MozIMEFocusIn"),
-                         false, false))->RunDOMEventWhenSafe();
+    (new AsyncEventDispatcher(doc, NS_LITERAL_STRING("MozIMEFocusIn"),
+                              false, false))->RunDOMEventWhenSafe();
   }
 
   aWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_FOCUS));
 
   // NOTIFY_IME_OF_FOCUS might cause recreating IMEContentObserver
   // instance via IMEStateManager::UpdateIMEState().  So, this
   // instance might already have been destroyed, check it.
   if (!mRootContent) {
@@ -144,18 +144,18 @@ IMEContentObserver::ObserveEditableNode(
 void
 IMEContentObserver::Destroy()
 {
   // If CreateTextStateManager failed, mRootContent will be null,
   // and we should not call NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR))
   if (mRootContent) {
     if (IMEStateManager::IsTestingIME() && mEditableNode) {
       nsIDocument* doc = mEditableNode->OwnerDoc();
-      (new nsAsyncDOMEvent(doc, NS_LITERAL_STRING("MozIMEFocusOut"),
-                           false, false))->RunDOMEventWhenSafe();
+      (new AsyncEventDispatcher(doc, NS_LITERAL_STRING("MozIMEFocusOut"),
+                                false, false))->RunDOMEventWhenSafe();
     }
     mWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR));
   }
   // Even if there are some pending notification, it'll never notify the widget.
   mWidget = nullptr;
   if (mUpdatePreference.WantSelectionChange() && mSelection) {
     nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(mSelection));
     if (selPrivate) {
--- a/dom/events/moz.build
+++ b/dom/events/moz.build
@@ -9,29 +9,29 @@ MOCHITEST_CHROME_MANIFESTS += ['test/chr
 
 XPIDL_SOURCES += [
     'nsIEventListenerService.idl',
 ]
 
 XPIDL_MODULE = 'content_events'
 
 EXPORTS += [
-    'nsAsyncDOMEvent.h',
     'nsDOMEventTargetHelper.h',
     'nsDOMKeyNameList.h',
     'nsEventDispatcher.h',
-    'nsEventListenerManager.h',
     'nsEventNameList.h',
     'nsEventStateManager.h',
     'nsEventStates.h',
     'nsIJSEventListener.h',
     'nsVKList.h',
 ]
 
 EXPORTS.mozilla += [
+    'AsyncEventDispatcher.h',
+    'EventListenerManager.h',
     'IMEStateManager.h',
     'InternalMutationEvent.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'AnimationEvent.h',
     'BeforeUnloadEvent.h',
     'ClipboardEvent.h',
@@ -62,42 +62,42 @@ EXPORTS.mozilla.dom += [
     'XULCommandEvent.h',
 ]
 
 if CONFIG['MOZ_WEBSPEECH']:
     EXPORTS.mozilla.dom += ['SpeechRecognitionError.h']
 
 UNIFIED_SOURCES += [
     'AnimationEvent.cpp',
+    'AsyncEventDispatcher.cpp',
     'BeforeUnloadEvent.cpp',
     'ClipboardEvent.cpp',
     'CommandEvent.cpp',
     'CompositionEvent.cpp',
     'ContentEventHandler.cpp',
     'DataContainerEvent.cpp',
     'DataTransfer.cpp',
     'DeviceMotionEvent.cpp',
     'DragEvent.cpp',
     'Event.cpp',
+    'EventListenerManager.cpp',
+    'EventListenerService.cpp',
     'EventTarget.cpp',
     'FocusEvent.cpp',
     'IMEContentObserver.cpp',
     'IMEStateManager.cpp',
     'KeyboardEvent.cpp',
     'MessageEvent.cpp',
     'MouseEvent.cpp',
     'MouseScrollEvent.cpp',
     'MutationEvent.cpp',
     'NotifyAudioAvailableEvent.cpp',
     'NotifyPaintEvent.cpp',
-    'nsAsyncDOMEvent.cpp',
     'nsDOMEventTargetHelper.cpp',
     'nsEventDispatcher.cpp',
-    'nsEventListenerManager.cpp',
-    'nsEventListenerService.cpp',
     'nsJSEventListener.cpp',
     'nsPaintRequest.cpp',
     'PointerEvent.cpp',
     'ScrollAreaEvent.cpp',
     'SimpleGestureEvent.cpp',
     'TextComposition.cpp',
     'Touch.cpp',
     'TouchEvent.cpp',
--- a/dom/events/nsDOMEventTargetHelper.cpp
+++ b/dom/events/nsDOMEventTargetHelper.cpp
@@ -5,16 +5,17 @@
 
 #include "nsDOMEventTargetHelper.h"
 #include "nsContentUtils.h"
 #include "nsEventDispatcher.h"
 #include "nsIDocument.h"
 #include "prprf.h"
 #include "nsGlobalWindow.h"
 #include "ScriptSettings.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/Likely.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMEventTargetHelper)
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMEventTargetHelper)
@@ -151,17 +152,17 @@ nsDOMEventTargetHelper::DisconnectFromOw
   }
 }
 
 NS_IMETHODIMP
 nsDOMEventTargetHelper::RemoveEventListener(const nsAString& aType,
                                             nsIDOMEventListener* aListener,
                                             bool aUseCapture)
 {
-  nsEventListenerManager* elm = GetExistingListenerManager();
+  EventListenerManager* elm = GetExistingListenerManager();
   if (elm) {
     elm->RemoveEventListener(aType, aListener, aUseCapture);
   }
 
   return NS_OK;
 }
 
 NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsDOMEventTargetHelper)
@@ -178,17 +179,17 @@ nsDOMEventTargetHelper::AddEventListener
                "aWantsUntrusted to false or make the aWantsUntrusted "
                "explicit by making aOptionalArgc non-zero.");
 
   if (aOptionalArgc < 2) {
     nsresult rv = WantsUntrusted(&aWantsUntrusted);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  nsEventListenerManager* elm = GetOrCreateListenerManager();
+  EventListenerManager* elm = GetOrCreateListenerManager();
   NS_ENSURE_STATE(elm);
   elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
   return NS_OK;
 }
 
 void
 nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
                                          EventListener* aListener,
@@ -202,17 +203,17 @@ nsDOMEventTargetHelper::AddEventListener
     if (NS_FAILED(rv)) {
       aRv.Throw(rv);
       return;
     }
   } else {
     wantsUntrusted = aWantsUntrusted.Value();
   }
 
-  nsEventListenerManager* elm = GetOrCreateListenerManager();
+  EventListenerManager* elm = GetOrCreateListenerManager();
   if (!elm) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
   elm->AddEventListener(aType, aListener, aUseCapture, wantsUntrusted);
 }
 
 NS_IMETHODIMP
@@ -315,27 +316,27 @@ nsDOMEventTargetHelper::DispatchDOMEvent
                                          nsPresContext* aPresContext,
                                          nsEventStatus* aEventStatus)
 {
   return
     nsEventDispatcher::DispatchDOMEvent(this, aEvent, aDOMEvent, aPresContext,
                                         aEventStatus);
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsDOMEventTargetHelper::GetOrCreateListenerManager()
 {
   if (!mListenerManager) {
-    mListenerManager = new nsEventListenerManager(this);
+    mListenerManager = new EventListenerManager(this);
   }
 
   return mListenerManager;
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsDOMEventTargetHelper::GetExistingListenerManager() const
 {
   return mListenerManager;
 }
 
 nsIScriptContext*
 nsDOMEventTargetHelper::GetContextForEventHandlers(nsresult* aRv)
 {
--- a/dom/events/nsDOMEventTargetHelper.h
+++ b/dom/events/nsDOMEventTargetHelper.h
@@ -6,20 +6,20 @@
 #ifndef nsDOMEventTargetHelper_h_
 #define nsDOMEventTargetHelper_h_
 
 #include "nsCOMPtr.h"
 #include "nsGkAtoms.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsPIDOMWindow.h"
 #include "nsIScriptGlobalObject.h"
-#include "nsEventListenerManager.h"
 #include "nsIScriptContext.h"
 #include "MainThreadUtils.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/EventTarget.h"
 
 class JSCompartment;
 namespace mozilla {
 class ErrorResult;
 }
 
 #define NS_DOMEVENTTARGETHELPER_IID \
@@ -54,20 +54,20 @@ public:
   }
 
   virtual ~nsDOMEventTargetHelper();
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsDOMEventTargetHelper)
 
   NS_DECL_NSIDOMEVENTTARGET
 
-  virtual nsEventListenerManager*
-  GetExistingListenerManager() const MOZ_OVERRIDE;
-  virtual nsEventListenerManager*
-  GetOrCreateListenerManager() MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetExistingListenerManager() const MOZ_OVERRIDE;
+  virtual mozilla::EventListenerManager*
+    GetOrCreateListenerManager() MOZ_OVERRIDE;
 
   using mozilla::dom::EventTarget::RemoveEventListener;
   virtual void AddEventListener(const nsAString& aType,
                                 mozilla::dom::EventListener* aListener,
                                 bool aCapture,
                                 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
                                 mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
 
@@ -146,17 +146,17 @@ public:
                                      mozilla::ErrorResult& aRv,
                                      JSCompartment* aCompartment = nullptr) {}
   virtual void EventListenerWasRemoved(const nsAString& aType,
                                        mozilla::ErrorResult& aRv,
                                        JSCompartment* aCompartment = nullptr) {}
 protected:
   nsresult WantsUntrusted(bool* aRetVal);
 
-  nsRefPtr<nsEventListenerManager> mListenerManager;
+  nsRefPtr<mozilla::EventListenerManager> mListenerManager;
   // Dispatch a trusted, non-cancellable and non-bubbling event to |this|.
   nsresult DispatchTrustedEvent(const nsAString& aEventName);
   // Make |event| trusted and dispatch |aEvent| to |this|.
   nsresult DispatchTrustedEvent(nsIDOMEvent* aEvent);
 
   virtual void LastRelease() {}
 private:
   // Inner window or sandbox.
@@ -245,35 +245,35 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMEvent
     return _to WillHandleEvent(aVisitor); \
   } \
   virtual nsresult PostHandleEvent(nsEventChainPostVisitor & aVisitor) { \
     return _to PostHandleEvent(aVisitor); \
   } \
   virtual nsresult DispatchDOMEvent(mozilla::WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent, nsPresContext* aPresContext, nsEventStatus* aEventStatus) { \
     return _to DispatchDOMEvent(aEvent, aDOMEvent, aPresContext, aEventStatus); \
   } \
-  virtual nsEventListenerManager * GetOrCreateListenerManager() { \
+  virtual mozilla::EventListenerManager* GetOrCreateListenerManager() { \
     return _to GetOrCreateListenerManager(); \
   } \
-  virtual nsEventListenerManager * GetExistingListenerManager() const { \
+  virtual mozilla::EventListenerManager* GetExistingListenerManager() const { \
     return _to GetExistingListenerManager(); \
   } \
   virtual nsIScriptContext * GetContextForEventHandlers(nsresult *aRv) { \
     return _to GetContextForEventHandlers(aRv); \
   } \
   virtual JSContext * GetJSContextForEventHandlers(void) { \
     return _to GetJSContextForEventHandlers(); \
   }
 
 #define NS_REALLY_FORWARD_NSIDOMEVENTTARGET(_class) \
   using _class::AddEventListener;                   \
   using _class::RemoveEventListener;                \
   NS_FORWARD_NSIDOMEVENTTARGET(_class::)            \
-  virtual nsEventListenerManager*                   \
+  virtual mozilla::EventListenerManager*            \
   GetOrCreateListenerManager() {                    \
     return _class::GetOrCreateListenerManager();    \
   }                                                 \
-  virtual nsEventListenerManager*                   \
+  virtual mozilla::EventListenerManager*            \
   GetExistingListenerManager() const {              \
     return _class::GetExistingListenerManager();    \
   }
 
 #endif // nsDOMEventTargetHelper_h_
--- a/dom/events/nsEventDispatcher.cpp
+++ b/dom/events/nsEventDispatcher.cpp
@@ -1,29 +1,29 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsEventDispatcher.h"
 #include "nsPresContext.h"
-#include "nsEventListenerManager.h"
 #include "nsContentUtils.h"
 #include "nsError.h"
 #include <new>
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsINode.h"
 #include "nsPIDOMWindow.h"
 #include "GeckoProfiler.h"
 #include "GeneratedEvents.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/dom/EventTarget.h"
 #include "mozilla/dom/TouchEvent.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/unused.h"
 
 using namespace mozilla;
@@ -31,24 +31,24 @@ using namespace mozilla::dom;
 
 class ELMCreationDetector
 {
 public:
   ELMCreationDetector() :
     // We can do this optimization only in the main thread.
     mNonMainThread(!NS_IsMainThread()),
     mInitialCount(mNonMainThread ?
-                    0 : nsEventListenerManager::sMainThreadCreatedCount)
+                    0 : EventListenerManager::sMainThreadCreatedCount)
   {
   }
 
   bool MayHaveNewListenerManager()
   {
     return mNonMainThread ||
-           mInitialCount != nsEventListenerManager::sMainThreadCreatedCount;
+           mInitialCount != EventListenerManager::sMainThreadCreatedCount;
   }
 
   bool IsMainThread()
   {
     return !mNonMainThread;
   }
 private:
   bool mNonMainThread;
@@ -163,17 +163,17 @@ public:
   /**
    * Resets aVisitor object and calls PreHandleEvent.
    * Copies mItemFlags and mItemData to the current nsEventTargetChainItem.
    */
   void PreHandleEvent(nsEventChainPreVisitor& aVisitor);
 
   /**
    * If the current item in the event target chain has an event listener
-   * manager, this method calls nsEventListenerManager::HandleEvent().
+   * manager, this method calls EventListenerManager::HandleEvent().
    */
   void HandleEvent(nsEventChainPostVisitor& aVisitor,
                    ELMCreationDetector& aCd)
   {
     if (WantsWillHandleEvent()) {
       mTarget->WillHandleEvent(aVisitor);
     }
     if (aVisitor.mEvent->mFlags.mPropagationStopped) {
@@ -204,17 +204,17 @@ public:
 
   nsCOMPtr<EventTarget>             mTarget;
   uint16_t                          mFlags;
   uint16_t                          mItemFlags;
   nsCOMPtr<nsISupports>             mItemData;
   // Event retargeting must happen whenever mNewTarget is non-null.
   nsCOMPtr<EventTarget>             mNewTarget;
   // Cache mTarget's event listener manager.
-  nsRefPtr<nsEventListenerManager>  mManager;
+  nsRefPtr<EventListenerManager>    mManager;
 };
 
 nsEventTargetChainItem::nsEventTargetChainItem(EventTarget* aTarget)
 : mTarget(aTarget), mFlags(0), mItemFlags(0)
 {
   MOZ_ASSERT(!aTarget || mTarget == aTarget->GetTargetForEventTargetChain());
 }
 
--- a/dom/interfaces/events/nsIDOMEventTarget.idl
+++ b/dom/interfaces/events/nsIDOMEventTarget.idl
@@ -8,42 +8,42 @@
 %{C++
 #include "mozilla/EventForwards.h"
 #include "mozilla/dom/Nullable.h"
 #include "js/TypeDecls.h"
 
 using mozilla::dom::Nullable;
 
 namespace mozilla {
+class EventListenerManager;
 namespace dom {
 class EventTarget;
 } // namespace dom
 } // namespace mozilla
 
 class nsPresContext;
 class nsEventChainPreVisitor;
 class nsEventChainPostVisitor;
-class nsEventListenerManager;
 %}
 
 /**
  * The nsIDOMEventTarget interface is the interface implemented by all
  * event targets in the Document Object Model.
  *
  * For more information on this interface please see 
  * http://www.w3.org/TR/DOM-Level-2-Events/
  */
 
 [ref] native nsEventChainPreVisitorRef(nsEventChainPreVisitor);
 [ref] native nsEventChainPostVisitorRef(nsEventChainPostVisitor);
 [ptr] native WidgetEventPtr(mozilla::WidgetEvent);
 [ptr] native nsPresContextPtr(nsPresContext);
 [ptr] native nsEventStatusPtr(nsEventStatus);
 [ptr] native JSContextPtr(JSContext);
-[ptr] native nsEventListenerManagerPtr(nsEventListenerManager);
+[ptr] native EventListenerManagerPtr(mozilla::EventListenerManager);
 [ptr] native EventTargetPtr(mozilla::dom::EventTarget);
 
 interface nsIScriptContext;
 interface nsIDOMEventListener;
 interface nsIDOMEvent;
 
 [scriptable, builtinclass, uuid(b128448c-7b53-4769-92cb-cd6eafee676c)]
 interface nsIDOMEventTarget : nsISupports
@@ -291,20 +291,21 @@ nsresult _class::WillHandleEvent(nsEvent
 JSContext* _class::GetJSContextForEventHandlers() { return nullptr; }
 
 #define NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(aClass) \
 NS_IMETHODIMP \
 aClass::RemoveSystemEventListener(const nsAString& aType, \
                                   nsIDOMEventListener *aListener, \
                                   bool aUseCapture) \
 { \
-  nsEventListenerManager* listenerManager = GetExistingListenerManager(); \
+  mozilla::EventListenerManager* listenerManager = \
+    GetExistingListenerManager(); \
   if (!listenerManager) { \
     return NS_OK; \
   } \
-  mozilla::dom::EventListenerFlags flags; \
+  mozilla::EventListenerFlags flags; \
   flags.mInSystemGroup = true; \
   flags.mCapture = aUseCapture; \
   listenerManager->RemoveEventListenerByType(aListener, aType, flags); \
   return NS_OK; \
 }
 
 %}
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -8,16 +8,17 @@
 
 #include "TabChild.h"
 
 #include "Layers.h"
 #include "ContentChild.h"
 #include "IndexedDBChild.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ClearOnShutdown.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/IntentionalCrash.h"
 #include "mozilla/docshell/OfflineCacheUpdateChild.h"
 #include "mozilla/ipc/DocumentRendererChild.h"
 #include "mozilla/ipc/FileDescriptorUtils.h"
 #include "mozilla/layers/AsyncPanZoomController.h"
 #include "mozilla/layers/CompositorChild.h"
 #include "mozilla/layers/ImageBridgeChild.h"
 #include "mozilla/layers/ShadowLayers.h"
@@ -27,17 +28,16 @@
 #include "mozilla/StaticPtr.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/unused.h"
 #include "mozIApplication.h"
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 #include "nsEmbedCID.h"
-#include "nsEventListenerManager.h"
 #include <algorithm>
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #endif
 #include "nsFilePickerProxy.h"
 #include "mozilla/dom/Element.h"
 #include "nsIBaseWindow.h"
 #include "nsICachedFileDescriptorListener.h"
@@ -1152,17 +1152,17 @@ TabChild::~TabChild()
 
     nsCOMPtr<nsIWebBrowser> webBrowser = do_QueryInterface(mWebNav);
     if (webBrowser) {
       webBrowser->SetContainerWindow(nullptr);
     }
     mGlobal = nullptr;
 
     if (mTabChildGlobal) {
-      nsEventListenerManager* elm = mTabChildGlobal->GetExistingListenerManager();
+      EventListenerManager* elm = mTabChildGlobal->GetExistingListenerManager();
       if (elm) {
         elm->Disconnect();
       }
       mTabChildGlobal->mTabChild = nullptr;
     }
 }
 
 void
--- a/dom/smil/nsSMILTimeValueSpec.cpp
+++ b/dom/smil/nsSMILTimeValueSpec.cpp
@@ -1,27 +1,28 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/SVGAnimationElement.h"
 #include "nsSMILTimeValueSpec.h"
 #include "nsSMILInterval.h"
 #include "nsSMILTimeContainer.h"
 #include "nsSMILTimeValue.h"
 #include "nsSMILTimedElement.h"
 #include "nsSMILInstanceTime.h"
 #include "nsSMILParserUtils.h"
-#include "nsEventListenerManager.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsIDOMTimeEvent.h"
 #include "nsString.h"
 #include <limits>
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 //----------------------------------------------------------------------
 // Nested class: EventListener
 
 NS_IMPL_ISUPPORTS1(nsSMILTimeValueSpec::EventListener, nsIDOMEventListener)
 
 NS_IMETHODIMP
@@ -310,41 +311,41 @@ nsSMILTimeValueSpec::RegisterEventListen
       !IsWhitelistedEvent()) {
     return;
   }
 
   if (!mEventListener) {
     mEventListener = new EventListener(this);
   }
 
-  nsEventListenerManager* elm = GetEventListenerManager(aTarget);
+  EventListenerManager* elm = GetEventListenerManager(aTarget);
   if (!elm)
     return;
 
   elm->AddEventListenerByType(mEventListener,
                               nsDependentAtomString(mParams.mEventSymbol),
                               AllEventsAtSystemGroupBubble());
 }
 
 void
 nsSMILTimeValueSpec::UnregisterEventListener(Element* aTarget)
 {
   if (!aTarget || !mEventListener)
     return;
 
-  nsEventListenerManager* elm = GetEventListenerManager(aTarget);
+  EventListenerManager* elm = GetEventListenerManager(aTarget);
   if (!elm)
     return;
 
   elm->RemoveEventListenerByType(mEventListener,
                                  nsDependentAtomString(mParams.mEventSymbol),
                                  AllEventsAtSystemGroupBubble());
 }
 
-nsEventListenerManager*
+EventListenerManager*
 nsSMILTimeValueSpec::GetEventListenerManager(Element* aTarget)
 {
   NS_ABORT_IF_FALSE(aTarget, "null target; can't get EventListenerManager");
 
   nsCOMPtr<EventTarget> target;
 
   if (mParams.mType == nsSMILTimeValueSpecParams::ACCESSKEY) {
     nsIDocument* doc = aTarget->GetCurrentDoc();
--- a/dom/smil/nsSMILTimeValueSpec.h
+++ b/dom/smil/nsSMILTimeValueSpec.h
@@ -14,16 +14,20 @@
 
 class nsAString;
 class nsSMILTimeValue;
 class nsSMILTimedElement;
 class nsSMILTimeContainer;
 class nsSMILInstanceTime;
 class nsSMILInterval;
 
+namespace mozilla {
+class EventListenerManager;
+} // namespace mozilla
+
 //----------------------------------------------------------------------
 // nsSMILTimeValueSpec class
 //
 // An individual element of a 'begin' or 'end' attribute, e.g. '5s', 'a.end'.
 // This class handles the parsing of such specifications and performs the
 // necessary event handling (for event, repeat, and accesskey specifications)
 // and synchronisation (for syncbase specifications).
 //
@@ -60,17 +64,17 @@ public:
 
 protected:
   void UpdateReferencedElement(Element* aFrom, Element* aTo);
   void UnregisterFromReferencedElement(Element* aElement);
   nsSMILTimedElement* GetTimedElement(Element* aElement);
   bool IsWhitelistedEvent();
   void RegisterEventListener(Element* aElement);
   void UnregisterEventListener(Element* aElement);
-  nsEventListenerManager* GetEventListenerManager(Element* aElement);
+  mozilla::EventListenerManager* GetEventListenerManager(Element* aElement);
   void HandleEvent(nsIDOMEvent* aEvent);
   bool CheckEventDetail(nsIDOMEvent* aEvent);
   bool CheckRepeatEventDetail(nsIDOMEvent* aEvent);
   bool CheckAccessKeyEventDetail(nsIDOMEvent* aEvent);
   nsSMILTimeValue ConvertBetweenTimeContainers(const nsSMILTimeValue& aSrcTime,
                                       const nsSMILTimeContainer* aSrcContainer);
   bool ApplyOffset(nsSMILTimeValue& aTime) const;
 
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WorkerScope.h"
 
 #include "jsapi.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/FunctionBinding.h"
 #include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h"
 #include "mozilla/dom/SharedWorkerGlobalScopeBinding.h"
 #include "mozilla/dom/Console.h"
 
 #ifdef ANDROID
 #include <android/log.h>
 #endif
@@ -137,26 +138,26 @@ WorkerGlobalScope::Close(JSContext* aCx)
   mWorkerPrivate->CloseInternal(aCx);
 }
 
 OnErrorEventHandlerNonNull*
 WorkerGlobalScope::GetOnerror()
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
-  nsEventListenerManager *elm = GetExistingListenerManager();
+  EventListenerManager* elm = GetExistingListenerManager();
   return elm ? elm->GetOnErrorEventHandler() : nullptr;
 }
 
 void
 WorkerGlobalScope::SetOnerror(OnErrorEventHandlerNonNull* aHandler)
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
-  nsEventListenerManager *elm = GetOrCreateListenerManager();
+  EventListenerManager* elm = GetOrCreateListenerManager();
   if (elm) {
     elm->SetEventHandler(aHandler);
   }
 }
 
 void
 WorkerGlobalScope::ImportScripts(JSContext* aCx,
                                  const Sequence<nsString>& aScriptURLs,
--- a/dom/xbl/nsXBLBinding.cpp
+++ b/dom/xbl/nsXBLBinding.cpp
@@ -30,17 +30,17 @@
 #include "mozilla/dom/XMLDocument.h"
 #include "jsapi.h"
 #include "nsXBLService.h"
 #include "nsIXPConnect.h"
 #include "nsIScriptContext.h"
 #include "nsCRT.h"
 
 // Event listeners
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsIDOMEventListener.h"
 #include "nsAttrName.h"
 
 #include "nsGkAtoms.h"
 
 #include "nsXBLPrototypeHandler.h"
 
 #include "nsXBLPrototypeBinding.h"
@@ -526,17 +526,17 @@ void
 nsXBLBinding::InstallEventHandlers()
 {
   // Don't install handlers if scripts aren't allowed.
   if (AllowScripts()) {
     // Fetch the handlers prototypes for this binding.
     nsXBLPrototypeHandler* handlerChain = mPrototypeBinding->GetPrototypeHandlers();
 
     if (handlerChain) {
-      nsEventListenerManager* manager = mBoundElement->GetOrCreateListenerManager();
+      EventListenerManager* manager = mBoundElement->GetOrCreateListenerManager();
       if (!manager)
         return;
 
       bool isChromeDoc =
         nsContentUtils::IsChromeDoc(mBoundElement->OwnerDoc());
       bool isChromeBinding = mPrototypeBinding->IsChrome();
       nsXBLPrototypeHandler* curr;
       for (curr = handlerChain; curr; curr = curr->GetNextHandler()) {
@@ -546,17 +546,17 @@ nsXBLBinding::InstallEventHandlers()
             eventAtom == nsGkAtoms::keyup ||
             eventAtom == nsGkAtoms::keydown ||
             eventAtom == nsGkAtoms::keypress)
           continue;
 
         nsXBLEventHandler* handler = curr->GetEventHandler();
         if (handler) {
           // Figure out if we're using capturing or not.
-          dom::EventListenerFlags flags;
+          EventListenerFlags flags;
           flags.mCapture = (curr->GetPhase() == NS_PHASE_CAPTURING);
 
           // If this is a command, add it in the system event group
           if ((curr->GetType() & (NS_HANDLER_TYPE_XBL_COMMAND |
                                   NS_HANDLER_TYPE_SYSTEM)) &&
               (isChromeBinding || mBoundElement->IsInNativeAnonymousSubtree())) {
             flags.mInSystemGroup = true;
           }
@@ -583,17 +583,17 @@ nsXBLBinding::InstallEventHandlers()
 
         nsAutoString type;
         handler->GetEventName(type);
 
         // If this is a command, add it in the system event group, otherwise 
         // add it to the standard event group.
 
         // Figure out if we're using capturing or not.
-        dom::EventListenerFlags flags;
+        EventListenerFlags flags;
         flags.mCapture = (handler->GetPhase() == NS_PHASE_CAPTURING);
 
         if ((handler->GetType() & (NS_HANDLER_TYPE_XBL_COMMAND |
                                    NS_HANDLER_TYPE_SYSTEM)) &&
             (isChromeBinding || mBoundElement->IsInNativeAnonymousSubtree())) {
           flags.mInSystemGroup = true;
         }
 
@@ -675,18 +675,17 @@ nsXBLBinding::ExecuteDetachedHandler()
 }
 
 void
 nsXBLBinding::UnhookEventHandlers()
 {
   nsXBLPrototypeHandler* handlerChain = mPrototypeBinding->GetPrototypeHandlers();
 
   if (handlerChain) {
-    nsEventListenerManager* manager =
-      mBoundElement->GetExistingListenerManager();
+    EventListenerManager* manager = mBoundElement->GetExistingListenerManager();
     if (!manager) {
       return;
     }
                                       
     bool isChromeBinding = mPrototypeBinding->IsChrome();
     nsXBLPrototypeHandler* curr;
     for (curr = handlerChain; curr; curr = curr->GetNextHandler()) {
       nsXBLEventHandler* handler = curr->GetCachedEventHandler();
@@ -697,17 +696,17 @@ nsXBLBinding::UnhookEventHandlers()
       nsCOMPtr<nsIAtom> eventAtom = curr->GetEventName();
       if (!eventAtom ||
           eventAtom == nsGkAtoms::keyup ||
           eventAtom == nsGkAtoms::keydown ||
           eventAtom == nsGkAtoms::keypress)
         continue;
 
       // Figure out if we're using capturing or not.
-      dom::EventListenerFlags flags;
+      EventListenerFlags flags;
       flags.mCapture = (curr->GetPhase() == NS_PHASE_CAPTURING);
 
       // If this is a command, remove it from the system event group,
       // otherwise remove it from the standard event group.
 
       if ((curr->GetType() & (NS_HANDLER_TYPE_XBL_COMMAND |
                               NS_HANDLER_TYPE_SYSTEM)) &&
           (isChromeBinding || mBoundElement->IsInNativeAnonymousSubtree())) {
@@ -724,17 +723,17 @@ nsXBLBinding::UnhookEventHandlers()
     int32_t i;
     for (i = 0; i < keyHandlers->Count(); ++i) {
       nsXBLKeyEventHandler* handler = keyHandlers->ObjectAt(i);
 
       nsAutoString type;
       handler->GetEventName(type);
 
       // Figure out if we're using capturing or not.
-      dom::EventListenerFlags flags;
+      EventListenerFlags flags;
       flags.mCapture = (handler->GetPhase() == NS_PHASE_CAPTURING);
 
       // If this is a command, remove it from the system event group, otherwise 
       // remove it from the standard event group.
 
       if ((handler->GetType() & (NS_HANDLER_TYPE_XBL_COMMAND | NS_HANDLER_TYPE_SYSTEM)) &&
           (isChromeBinding || mBoundElement->IsInNativeAnonymousSubtree())) {
         flags.mInSystemGroup = true;
--- a/dom/xbl/nsXBLPrototypeHandler.cpp
+++ b/dom/xbl/nsXBLPrototypeHandler.cpp
@@ -20,17 +20,16 @@
 #include "nsIJSEventListener.h"
 #include "nsIController.h"
 #include "nsIControllers.h"
 #include "nsIDOMXULElement.h"
 #include "nsIURI.h"
 #include "nsIDOMHTMLTextAreaElement.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsFocusManager.h"
-#include "nsEventListenerManager.h"
 #include "nsIDOMEventListener.h"
 #include "nsPIDOMWindow.h"
 #include "nsPIWindowRoot.h"
 #include "nsIDOMWindow.h"
 #include "nsIServiceManager.h"
 #include "nsIScriptError.h"
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
--- a/dom/xbl/nsXBLService.cpp
+++ b/dom/xbl/nsXBLService.cpp
@@ -40,23 +40,23 @@
 
 #include "nsIPresShell.h"
 #include "nsIDocumentObserver.h"
 #include "nsFrameManager.h"
 #include "nsStyleContext.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIScriptError.h"
 #include "nsXBLSerialize.h"
-#include "nsEventListenerManager.h"
 
 #ifdef MOZ_XUL
 #include "nsXULPrototypeCache.h"
 #endif
 #include "nsIDOMEventListener.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/Element.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #define NS_MAX_XBL_BINDING_RECURSION 20
@@ -557,38 +557,38 @@ nsXBLService::AttachGlobalKeyHandler(Eve
   nsCOMPtr<nsIContent> contentNode(do_QueryInterface(aTarget));
   if (contentNode) {
     // Only attach if we're really in a document
     nsCOMPtr<nsIDocument> doc = contentNode->GetCurrentDoc();
     if (doc)
       piTarget = doc; // We're a XUL keyset. Attach to our document.
   }
 
-  nsEventListenerManager* manager = piTarget->GetOrCreateListenerManager();
+  EventListenerManager* manager = piTarget->GetOrCreateListenerManager();
 
   if (!piTarget || !manager)
     return NS_ERROR_FAILURE;
 
   // the listener already exists, so skip this
   if (contentNode && contentNode->GetProperty(nsGkAtoms::listener))
     return NS_OK;
 
   nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(contentNode));
 
   // Create the key handler
   nsRefPtr<nsXBLWindowKeyHandler> handler =
     NS_NewXBLWindowKeyHandler(elt, piTarget);
 
   // listen to these events
   manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keydown"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keyup"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   manager->AddEventListenerByType(handler, NS_LITERAL_STRING("keypress"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
 
   if (contentNode)
     return contentNode->SetProperty(nsGkAtoms::listener,
                                     handler.forget().take(),
                                     nsPropertyTable::SupportsDtorFunc, true);
 
   // The reference to the handler will be maintained by the event target,
   // and, if there is a content node, the property.
@@ -608,32 +608,32 @@ nsXBLService::DetachGlobalKeyHandler(Eve
   if (!contentNode) // detaching is only supported for content nodes
     return NS_ERROR_FAILURE;
 
   // Only attach if we're really in a document
   nsCOMPtr<nsIDocument> doc = contentNode->GetCurrentDoc();
   if (doc)
     piTarget = do_QueryInterface(doc);
 
-  nsEventListenerManager* manager = piTarget->GetOrCreateListenerManager();
+  EventListenerManager* manager = piTarget->GetOrCreateListenerManager();
 
   if (!piTarget || !manager)
     return NS_ERROR_FAILURE;
 
   nsIDOMEventListener* handler =
     static_cast<nsIDOMEventListener*>(contentNode->GetProperty(nsGkAtoms::listener));
   if (!handler)
     return NS_ERROR_FAILURE;
 
   manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keydown"),
-                                     dom::TrustedEventsAtSystemGroupBubble());
+                                     TrustedEventsAtSystemGroupBubble());
   manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keyup"),
-                                     dom::TrustedEventsAtSystemGroupBubble());
+                                     TrustedEventsAtSystemGroupBubble());
   manager->RemoveEventListenerByType(handler, NS_LITERAL_STRING("keypress"),
-                                     dom::TrustedEventsAtSystemGroupBubble());
+                                     TrustedEventsAtSystemGroupBubble());
 
   contentNode->DeleteProperty(nsGkAtoms::listener);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXBLService::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aSomeData)
--- a/dom/xslt/xslt/txEXSLTFunctions.cpp
+++ b/dom/xslt/xslt/txEXSLTFunctions.cpp
@@ -19,16 +19,17 @@
 #include "nsComponentManagerUtils.h"
 #include "nsContentCID.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsIContent.h"
 #include "nsIDOMDocumentFragment.h"
 #include "txMozillaXMLOutput.h"
 #include "nsTextNode.h"
 #include "mozilla/dom/DocumentFragment.h"
+#include "prtime.h" 
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 class txStylesheetCompilerState;
 
 // ------------------------------------------------------------------
 // Utility functions
--- a/editor/libeditor/base/nsEditorEventListener.cpp
+++ b/editor/libeditor/base/nsEditorEventListener.cpp
@@ -1,25 +1,25 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=4 sw=2 et tw=78: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
+#include "mozilla/EventListenerManager.h" // for EventListenerManager
 #include "mozilla/IMEStateManager.h"    // for IMEStateManager
 #include "mozilla/Preferences.h"        // for Preferences
 #include "mozilla/TextEvents.h"         // for WidgetCompositionEvent
 #include "mozilla/dom/Element.h"        // for Element
 #include "mozilla/dom/EventTarget.h"    // for EventTarget
 #include "nsAString.h"
 #include "nsCaret.h"                    // for nsCaret
 #include "nsDebug.h"                    // for NS_ENSURE_TRUE, etc
 #include "nsEditor.h"                   // for nsEditor, etc
 #include "nsEditorEventListener.h"
-#include "nsEventListenerManager.h"     // for nsEventListenerManager
 #include "nsFocusManager.h"             // for nsFocusManager
 #include "nsGkAtoms.h"                  // for nsGkAtoms, nsGkAtoms::input
 #include "nsIClipboard.h"               // for nsIClipboard, etc
 #include "nsIContent.h"                 // for nsIContent
 #include "nsIController.h"              // for nsIController
 #include "nsID.h"
 #include "mozilla/dom/DOMStringList.h"
 #include "mozilla/dom/DataTransfer.h"
@@ -136,73 +136,73 @@ nsresult
 nsEditorEventListener::InstallToEditor()
 {
   NS_PRECONDITION(mEditor, "The caller must set mEditor");
 
   nsCOMPtr<EventTarget> piTarget = mEditor->GetDOMEventTarget();
   NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE);
 
   // register the event listeners with the listener manager
-  nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
+  EventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
   NS_ENSURE_STATE(elmP);
 
 #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("keydown"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("keyup"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
 #endif
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("keypress"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("dragenter"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("dragover"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("dragexit"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("drop"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
   // XXX We should add the mouse event listeners as system event group.
   //     E.g., web applications cannot prevent middle mouse paste by
   //     preventDefault() of click event at bubble phase.
   //     However, if we do so, all click handlers in any frames and frontend
   //     code need to check if it's editable.  It makes easier create new bugs.
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("mousedown"),
-                               dom::TrustedEventsAtCapture());
+                               TrustedEventsAtCapture());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("mouseup"),
-                               dom::TrustedEventsAtCapture());
+                               TrustedEventsAtCapture());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("click"),
-                               dom::TrustedEventsAtCapture());
+                               TrustedEventsAtCapture());
 // Focus event doesn't bubble so adding the listener to capturing phase.
 // Make sure this works after bug 235441 gets fixed.
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("blur"),
-                               dom::TrustedEventsAtCapture());
+                               TrustedEventsAtCapture());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("focus"),
-                               dom::TrustedEventsAtCapture());
+                               TrustedEventsAtCapture());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("text"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("compositionstart"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
   elmP->AddEventListenerByType(this,
                                NS_LITERAL_STRING("compositionend"),
-                               dom::TrustedEventsAtSystemGroupBubble());
+                               TrustedEventsAtSystemGroupBubble());
 
   return NS_OK;
 }
 
 void
 nsEditorEventListener::Disconnect()
 {
   if (!mEditor) {
@@ -230,68 +230,68 @@ nsEditorEventListener::Disconnect()
 void
 nsEditorEventListener::UninstallFromEditor()
 {
   nsCOMPtr<EventTarget> piTarget = mEditor->GetDOMEventTarget();
   if (!piTarget) {
     return;
   }
 
-  nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
+  EventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
   if (!elmP) {
     return;
   }
 
 #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("keydown"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("keyup"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
 #endif
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("keypress"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("dragenter"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("dragover"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("dragexit"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("drop"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("mousedown"),
-                                  dom::TrustedEventsAtCapture());
+                                  TrustedEventsAtCapture());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("mouseup"),
-                                  dom::TrustedEventsAtCapture());
+                                  TrustedEventsAtCapture());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("click"),
-                                  dom::TrustedEventsAtCapture());
+                                  TrustedEventsAtCapture());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("blur"),
-                                  dom::TrustedEventsAtCapture());
+                                  TrustedEventsAtCapture());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("focus"),
-                                  dom::TrustedEventsAtCapture());
+                                  TrustedEventsAtCapture());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("text"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("compositionstart"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
   elmP->RemoveEventListenerByType(this,
                                   NS_LITERAL_STRING("compositionend"),
-                                  dom::TrustedEventsAtSystemGroupBubble());
+                                  TrustedEventsAtSystemGroupBubble());
 }
 
 already_AddRefed<nsIPresShell>
 nsEditorEventListener::GetPresShell()
 {
   NS_PRECONDITION(mEditor,
     "The caller must check whether this is connected to an editor");
   return mEditor->GetPresShell();
--- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
@@ -56,20 +56,20 @@
 #include "nsRect.h"
 #include "nsIWebBrowserChromeFocus.h"
 #include "nsIContent.h"
 #include "imgIContainer.h"
 #include "nsContextMenuInfo.h"
 #include "nsPresContext.h"
 #include "nsViewManager.h"
 #include "nsView.h"
-#include "nsEventListenerManager.h"
 #include "nsIDOMDragEvent.h"
 #include "nsIConstraintValidation.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 //
 // GetEventReceiver
 //
@@ -861,22 +861,22 @@ nsDocShellTreeOwner::AddChromeListeners(
         rv = NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   // register dragover and drop event listeners with the listener manager
   nsCOMPtr<EventTarget> target;
   GetDOMEventTarget(mWebBrowser, getter_AddRefs(target));
 
-  nsEventListenerManager* elmP = target->GetOrCreateListenerManager();
+  EventListenerManager* elmP = target->GetOrCreateListenerManager();
   if (elmP) {
     elmP->AddEventListenerByType(this, NS_LITERAL_STRING("dragover"),
-                                 dom::TrustedEventsAtSystemGroupBubble());
+                                 TrustedEventsAtSystemGroupBubble());
     elmP->AddEventListenerByType(this, NS_LITERAL_STRING("drop"),
-                                 dom::TrustedEventsAtSystemGroupBubble());
+                                 TrustedEventsAtSystemGroupBubble());
   }
 
   return rv;
 
 } // AddChromeListeners
 
 
 NS_IMETHODIMP
@@ -891,23 +891,23 @@ nsDocShellTreeOwner::RemoveChromeListene
     NS_RELEASE(mChromeContextMenuListener);
   }
 
   nsCOMPtr<EventTarget> piTarget;
   GetDOMEventTarget(mWebBrowser, getter_AddRefs(piTarget));
   if (!piTarget)
     return NS_OK;
 
-  nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
+  EventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
   if (elmP)
   {
     elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("dragover"),
-                                    dom::TrustedEventsAtSystemGroupBubble());
+                                    TrustedEventsAtSystemGroupBubble());
     elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("drop"),
-                                    dom::TrustedEventsAtSystemGroupBubble());
+                                    TrustedEventsAtSystemGroupBubble());
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDocShellTreeOwner::HandleEvent(nsIDOMEvent* aEvent)
 {
--- a/extensions/spellcheck/src/mozInlineSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozInlineSpellChecker.cpp
@@ -53,23 +53,23 @@
 #include "nsISelectionPrivate.h"
 #include "nsISelectionController.h"
 #include "nsIServiceManager.h"
 #include "nsITextServicesFilter.h"
 #include "nsString.h"
 #include "nsThreadUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIContent.h"
-#include "nsEventListenerManager.h"
 #include "nsRange.h"
 #include "nsContentUtils.h"
 #include "nsEditor.h"
 #include "mozilla/Services.h"
 #include "nsIObserverService.h"
 #include "nsITextControlElement.h"
+#include "prtime.h" 
 
 using namespace mozilla::dom;
 
 // Set to spew messages to the console about what is happening.
 //#define DEBUG_INLINESPELL
 
 // the number of milliseconds that we will take at once to do spellchecking
 #define INLINESPELL_CHECK_TIMEOUT 50
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -595,17 +595,17 @@ CompileFunctionBody(JSContext *cx, Mutab
         if (!script)
             return false;
 
         script->bindings = fn->pn_funbox->bindings;
 
         /*
          * The reason for checking fun->environment() below is that certain
          * consumers of JS::CompileFunction, namely
-         * nsEventListenerManager::CompileEventHandlerInternal, passes in a
+         * EventListenerManager::CompileEventHandlerInternal, passes in a
          * nullptr environment. This compiled function is never used, but
          * instead is cloned immediately onto the right scope chain.
          */
         BytecodeEmitter funbce(/* parent = */ nullptr, &parser, fn->pn_funbox, script,
                                /* insideEval = */ false, /* evalCaller = */ js::NullPtr(),
                                fun->environment() && fun->environment()->is<GlobalObject>(),
                                options.lineno);
         if (!funbce.init())
--- a/js/src/jit/BacktrackingAllocator.cpp
+++ b/js/src/jit/BacktrackingAllocator.cpp
@@ -474,17 +474,17 @@ BacktrackingAllocator::processInterval(L
     // In general, we want to minimize the amount of interval splitting
     // (which generally necessitates spills), so allocate longer lived, lower
     // weight intervals first and evict and split them later if they prevent
     // allocation for higher weight intervals.
 
     bool canAllocate = setIntervalRequirement(interval);
 
     bool fixed;
-    LiveInterval *conflict;
+    LiveInterval *conflict = nullptr;
     for (size_t attempt = 0;; attempt++) {
         if (canAllocate) {
             bool success = false;
             fixed = false;
             conflict = nullptr;
 
             // Ok, let's try allocating for this interval.
             if (interval->requirement()->kind() == Requirement::FIXED) {
@@ -515,17 +515,17 @@ BacktrackingAllocator::processInterval(L
         // A minimal interval cannot be split any further. If we try to split
         // it at this point we will just end up with the same interval and will
         // enter an infinite loop. Weights and the initial live intervals must
         // be constructed so that any minimal interval is allocatable.
         JS_ASSERT(!minimalInterval(interval));
 
         if (canAllocate && fixed)
             return splitAcrossCalls(interval);
-        return chooseIntervalSplit(interval);
+        return chooseIntervalSplit(interval, conflict);
     }
 }
 
 bool
 BacktrackingAllocator::processGroup(VirtualRegisterGroup *group)
 {
     if (IonSpewEnabled(IonSpew_RegAlloc)) {
         IonSpew(IonSpew_RegAlloc, "Allocating group v%u [priority %lu] [weight %lu]",
@@ -578,27 +578,36 @@ BacktrackingAllocator::setIntervalRequir
     // require the interval to be split.
     interval->setHint(Requirement());
     interval->setRequirement(Requirement());
 
     BacktrackingVirtualRegister *reg = &vregs[interval->vreg()];
 
     // Set a hint if another interval in the same group is in a register.
     if (VirtualRegisterGroup *group = reg->group()) {
-        if (group->allocation.isRegister())
+        if (group->allocation.isRegister()) {
+            if (IonSpewEnabled(IonSpew_RegAlloc)) {
+                IonSpew(IonSpew_RegAlloc, "Hint %s, used by group allocation",
+                        group->allocation.toString());
+            }
             interval->setHint(Requirement(group->allocation));
+        }
     }
 
     if (interval->index() == 0) {
         // The first interval is the definition, so deal with any definition
         // constraints/hints.
 
         LDefinition::Policy policy = reg->def()->policy();
         if (policy == LDefinition::PRESET) {
             // Preset policies get a FIXED requirement.
+            if (IonSpewEnabled(IonSpew_RegAlloc)) {
+                IonSpew(IonSpew_RegAlloc, "Requirement %s, preset by definition",
+                        reg->def()->output()->toString());
+            }
             interval->setRequirement(Requirement(*reg->def()->output()));
         } else if (reg->ins()->isPhi()) {
             // Phis don't have any requirements, but they should prefer their
             // input allocations. This is captured by the group hints above.
         } else {
             // Non-phis get a REGISTER requirement.
             interval->setRequirement(Requirement(Requirement::REGISTER));
         }
@@ -608,16 +617,21 @@ BacktrackingAllocator::setIntervalRequir
     for (UsePositionIterator iter = interval->usesBegin();
          iter != interval->usesEnd();
          iter++)
     {
         LUse::Policy policy = iter->use->policy();
         if (policy == LUse::FIXED) {
             AnyRegister required = GetFixedRegister(reg->def(), iter->use);
 
+            if (IonSpewEnabled(IonSpew_RegAlloc)) {
+                IonSpew(IonSpew_RegAlloc, "Requirement %s, due to use at %u",
+                        required.name(), iter->pos.pos());
+            }
+
             // If there are multiple fixed registers which the interval is
             // required to use, fail. The interval will need to be split before
             // it can be allocated.
             if (!interval->addRequirement(Requirement(LAllocation(required))))
                 return false;
         } else if (policy == LUse::REGISTER) {
             if (!interval->addRequirement(Requirement(Requirement::REGISTER)))
                 return false;
@@ -1510,37 +1524,40 @@ BacktrackingAllocator::trySplitAcrossHot
     SplitPositionVector splitPositions;
     if (!splitPositions.append(hotRange->from) || !splitPositions.append(hotRange->to))
         return false;
     *success = true;
     return splitAt(interval, splitPositions);
 }
 
 bool
-BacktrackingAllocator::trySplitAfterLastRegisterUse(LiveInterval *interval, bool *success)
+BacktrackingAllocator::trySplitAfterLastRegisterUse(LiveInterval *interval, LiveInterval *conflict, bool *success)
 {
     // If this interval's later uses do not require it to be in a register,
-    // split it after the last use which does require a register.
+    // split it after the last use which does require a register. If conflict
+    // is specified, only consider register uses before the conflict starts.
 
     CodePosition lastRegisterFrom, lastRegisterTo, lastUse;
 
     for (UsePositionIterator iter(interval->usesBegin());
          iter != interval->usesEnd();
          iter++)
     {
         LUse *use = iter->use;
         LInstruction *ins = insData[iter->pos].ins();
 
         // Uses in the interval should be sorted.
         JS_ASSERT(iter->pos >= lastUse);
         lastUse = inputOf(ins);
 
-        if (isRegisterUse(use, ins, /* considerCopy = */ true)) {
-            lastRegisterFrom = inputOf(ins);
-            lastRegisterTo = iter->pos.next();
+        if (!conflict || outputOf(ins) < conflict->start()) {
+            if (isRegisterUse(use, ins, /* considerCopy = */ true)) {
+                lastRegisterFrom = inputOf(ins);
+                lastRegisterTo = iter->pos.next();
+            }
         }
     }
 
     if (!lastRegisterFrom.pos() || lastRegisterFrom == lastUse) {
         // Can't trim non-register uses off the end by splitting.
         return true;
     }
 
@@ -1776,24 +1793,24 @@ BacktrackingAllocator::splitAcrossCalls(
         }
     }
     JS_ASSERT(callPositions.length());
 
     return splitAt(interval, callPositions);
 }
 
 bool
-BacktrackingAllocator::chooseIntervalSplit(LiveInterval *interval)
+BacktrackingAllocator::chooseIntervalSplit(LiveInterval *interval, LiveInterval *conflict)
 {
     bool success = false;
 
     if (!trySplitAcrossHotcode(interval, &success))
         return false;
     if (success)
         return true;
 
-    if (!trySplitAfterLastRegisterUse(interval, &success))
+    if (!trySplitAfterLastRegisterUse(interval, conflict, &success))
         return false;
     if (success)
         return true;
 
     return splitAtAllRegisterUses(interval);
 }
--- a/js/src/jit/BacktrackingAllocator.h
+++ b/js/src/jit/BacktrackingAllocator.h
@@ -231,22 +231,22 @@ class BacktrackingAllocator
     // Heuristic methods.
 
     size_t computePriority(const LiveInterval *interval);
     size_t computeSpillWeight(const LiveInterval *interval);
 
     size_t computePriority(const VirtualRegisterGroup *group);
     size_t computeSpillWeight(const VirtualRegisterGroup *group);
 
-    bool chooseIntervalSplit(LiveInterval *interval);
+    bool chooseIntervalSplit(LiveInterval *interval, LiveInterval *conflict);
 
     bool splitAt(LiveInterval *interval,
                  const SplitPositionVector &splitPositions);
     bool trySplitAcrossHotcode(LiveInterval *interval, bool *success);
-    bool trySplitAfterLastRegisterUse(LiveInterval *interval, bool *success);
+    bool trySplitAfterLastRegisterUse(LiveInterval *interval, LiveInterval *conflict, bool *success);
     bool splitAtAllRegisterUses(LiveInterval *interval);
     bool splitAcrossCalls(LiveInterval *interval);
 };
 
 } // namespace jit
 } // namespace js
 
 #endif /* jit_BacktrackingAllocator_h */
--- a/layout/base/PositionedEventTargeting.cpp
+++ b/layout/base/PositionedEventTargeting.cpp
@@ -1,19 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "PositionedEventTargeting.h"
 
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "nsLayoutUtils.h"
 #include "nsGkAtoms.h"
-#include "nsEventListenerManager.h"
 #include "nsPrintfCString.h"
 #include "mozilla/dom/Element.h"
 #include "nsRegion.h"
 #include "nsDeviceContext.h"
 #include "nsIFrame.h"
 #include <algorithm>
 
 namespace mozilla {
@@ -113,32 +113,32 @@ GetPrefsFor(nsEventStructType aEventStru
   }
 
   return prefs;
 }
 
 static bool
 HasMouseListener(nsIContent* aContent)
 {
-  if (nsEventListenerManager* elm = aContent->GetExistingListenerManager()) {
+  if (EventListenerManager* elm = aContent->GetExistingListenerManager()) {
     return elm->HasListenersFor(nsGkAtoms::onclick) ||
            elm->HasListenersFor(nsGkAtoms::onmousedown) ||
            elm->HasListenersFor(nsGkAtoms::onmouseup);
   }
 
   return false;
 }
 
 static bool gTouchEventsRegistered = false;
 static int32_t gTouchEventsEnabled = 0;
 
 static bool
 HasTouchListener(nsIContent* aContent)
 {
-  nsEventListenerManager* elm = aContent->GetExistingListenerManager();
+  EventListenerManager* elm = aContent->GetExistingListenerManager();
   if (!elm) {
     return false;
   }
 
   if (!gTouchEventsRegistered) {
     Preferences::AddIntVarCache(&gTouchEventsEnabled,
       "dom.w3c_touch_events.enabled", gTouchEventsEnabled);
     gTouchEventsRegistered = true;
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -33,17 +33,17 @@
 #include "nsViewManager.h"
 #include "RestyleManager.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsRuleNode.h"
 #include "nsEventDispatcher.h"
 #include "gfxPlatform.h"
 #include "nsCSSRules.h"
 #include "nsFontFaceLoader.h"
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "prenv.h"
 #include "nsObjectFrame.h"
 #include "nsTransitionManager.h"
 #include "nsAnimationManager.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/Element.h"
 #include "nsIMessageManager.h"
 #include "mozilla/dom/MediaQueryList.h"
@@ -2300,17 +2300,17 @@ MayHavePaintEventListener(nsPIDOMWindow*
     return false;
   if (aInnerWindow->HasPaintEventListeners())
     return true;
 
   EventTarget* parentTarget = aInnerWindow->GetParentTarget();
   if (!parentTarget)
     return false;
 
-  nsEventListenerManager* manager = nullptr;
+  EventListenerManager* manager = nullptr;
   if ((manager = parentTarget->GetExistingListenerManager()) &&
       manager->MayHavePaintEventListener()) {
     return true;
   }
 
   nsCOMPtr<nsINode> node;
   if (parentTarget != aInnerWindow->GetChromeEventHandler()) {
     nsCOMPtr<nsIInProcessContentFrameMessageManager> mm =
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -19,17 +19,17 @@
 #include "nsCSSParser.h"
 #include "nsCSSProps.h"
 #include "nsCSSPseudoClasses.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCSSRendering.h"
 #include "mozilla/dom/Attr.h"
 #include "nsDOMClassInfo.h"
 #include "nsEditorEventListener.h"
-#include "nsEventListenerManager.h"
+#include "mozilla/EventListenerManager.h"
 #include "nsFrame.h"
 #include "nsGlobalWindow.h"
 #include "nsGkAtoms.h"
 #include "nsImageFrame.h"
 #include "nsLayoutStylesheetCache.h"
 #include "nsNodeInfo.h"
 #include "nsRange.h"
 #include "nsRegion.h"
@@ -301,17 +301,17 @@ nsLayoutStatics::Shutdown()
   nsFrameScriptExecutor::Shutdown();
   nsFocusManager::Shutdown();
 #ifdef MOZ_XUL
   nsXULPopupManager::Shutdown();
 #endif
   DOMStorageObserver::Shutdown();
   txMozillaXSLTProcessor::Shutdown();
   Attr::Shutdown();
-  nsEventListenerManager::Shutdown();
+  EventListenerManager::Shutdown();
   IMEStateManager::Shutdown();
   nsComputedDOMStyle::Shutdown();
   nsCSSParser::Shutdown();
   nsCSSRuleProcessor::Shutdown();
   nsTextFrameTextRunCache::Shutdown();
   nsHTMLDNSPrefetch::Shutdown();
   nsCSSRendering::Shutdown();
 #ifdef DEBUG
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -12,35 +12,36 @@
 #include "nsIFormControl.h"
 #include "nsNameSpaceManager.h"
 #include "nsIListControlFrame.h"
 #include "nsPIDOMWindow.h"
 #include "nsIPresShell.h"
 #include "nsContentList.h"
 #include "nsView.h"
 #include "nsViewManager.h"
+#include "nsIDOMEventListener.h"
 #include "nsIDOMNode.h"
 #include "nsISelectControlFrame.h"
 #include "nsContentUtils.h"
 #include "nsIDocument.h"
 #include "nsINodeInfo.h"
 #include "nsIScrollableFrame.h"
 #include "nsListControlFrame.h"
 #include "nsAutoPtr.h"
 #include "nsStyleSet.h"
 #include "nsNodeInfoManager.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsLayoutUtils.h"
 #include "nsDisplayList.h"
 #include "nsITheme.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsRenderingContext.h"
 #include "mozilla/Likely.h"
 #include <algorithm>
 #include "nsTextNode.h"
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/unused.h"
 
 using namespace mozilla;
 
 NS_IMETHODIMP
 nsComboboxControlFrame::RedisplayTextEvent::Run()
@@ -1546,18 +1547,18 @@ nsComboboxControlFrame::OnOptionSelected
 
   return NS_OK;
 }
 
 void nsComboboxControlFrame::FireValueChangeEvent()
 {
   // Fire ValueChange event to indicate data value of combo box has changed
   nsContentUtils::AddScriptRunner(
-    new nsAsyncDOMEvent(mContent, NS_LITERAL_STRING("ValueChange"), true,
-                        false));
+    new AsyncEventDispatcher(mContent, NS_LITERAL_STRING("ValueChange"), true,
+                             false));
 }
 
 void
 nsComboboxControlFrame::OnContentReset()
 {
   if (mListControlFrame) {
     mListControlFrame->OnContentReset();
   }
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -20,17 +20,16 @@
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsStyleContext.h"
 #include "nsTableOuterFrame.h"
 #include "nsView.h"
 #include "nsViewManager.h"
 #include "nsIScrollableFrame.h"
 #include "nsPresContext.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsStyleConsts.h"
 #include "nsIPresShell.h"
 #include "prlog.h"
 #include "prprf.h"
 #include <stdarg.h>
 #include "nsFrameManager.h"
 #include "nsLayoutUtils.h"
 
@@ -72,18 +71,19 @@
 #include "gfxContext.h"
 #include "nsRenderingContext.h"
 #include "nsAbsoluteContainingBlock.h"
 #include "StickyScrollContainer.h"
 #include "nsFontInflationData.h"
 #include "gfxASurface.h"
 #include "nsRegion.h"
 #include "nsIFrameInlines.h"
-#include "nsEventListenerManager.h"
-
+
+#include "mozilla/AsyncEventDispatcher.h"
+#include "mozilla/EventListenerManager.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/css/ImageLoader.h"
 #include "mozilla/gfx/Tools.h"
 #include "nsPrintfCString.h"
 
 using namespace mozilla;
@@ -1866,17 +1866,17 @@ public:
 
 static void
 CheckForTouchEventHandler(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
 {
   nsIContent* content = aFrame->GetContent();
   if (!content) {
     return;
   }
-  nsEventListenerManager* elm = nsContentUtils::GetExistingListenerManagerForNode(content);
+  EventListenerManager* elm = nsContentUtils::GetExistingListenerManagerForNode(content);
   if (!elm) {
     return;
   }
   if (elm->HasListenersFor(nsGkAtoms::ontouchstart) ||
       elm->HasListenersFor(nsGkAtoms::ontouchmove)) {
     aBuilder->SetAncestorHasTouchEventHandler(true);
   }
 }
@@ -2438,20 +2438,20 @@ nsFrame::GetContentForEvent(WidgetEvent*
 }
 
 void
 nsFrame::FireDOMEvent(const nsAString& aDOMEventName, nsIContent *aContent)
 {
   nsIContent* target = aContent ? aContent : mContent;
 
   if (target) {
-    nsRefPtr<nsAsyncDOMEvent> event =
-      new nsAsyncDOMEvent(target, aDOMEventName, true, false);
-    if (NS_FAILED(event->PostDOMEvent()))
-      NS_WARNING("Failed to dispatch nsAsyncDOMEvent");
+    nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+      new AsyncEventDispatcher(target, aDOMEventName, true, false);
+    DebugOnly<nsresult> rv = asyncDispatcher->PostDOMEvent();
+    NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncEventDispatcher failed to dispatch");
   }
 }
 
 nsresult
 nsFrame::HandleEvent(nsPresContext* aPresContext, 
                      WidgetGUIEvent* aEvent,
                      nsEventStatus* aEventStatus)
 {
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -4,27 +4,27 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsPrintEngine.h"
 
 #include "nsIStringBundle.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/Selection.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIFrame.h"
 #include "nsIURI.h"
 #include "nsITextToSubURI.h"
 #include "nsError.h"
 
 #include "nsView.h"
-#include "nsAsyncDOMEvent.h"
 #include <algorithm>
 
 // Print Options
 #include "nsIPrintSettings.h"
 #include "nsIPrintSettingsService.h"
 #include "nsIPrintOptions.h"
 #include "nsIPrintSession.h"
 #include "nsGfxCIID.h"
@@ -1853,17 +1853,17 @@ nsPrintEngine::ReflowDocList(nsPrintObje
 
 void
 nsPrintEngine::FirePrintPreviewUpdateEvent()
 {
   // Dispatch the event only while in PrintPreview. When printing, there is no
   // listener bound to this event and therefore no need to dispatch it.
   if (mIsDoingPrintPreview && !mIsDoingPrinting) {
     nsCOMPtr<nsIContentViewer> cv = do_QueryInterface(mDocViewerPrint);
-    (new nsAsyncDOMEvent(
+    (new AsyncEventDispatcher(
        cv->GetDocument(), NS_LITERAL_STRING("printPreviewUpdate"), true, true)
     )->RunDOMEventWhenSafe();
   }
 }
 
 nsresult
 nsPrintEngine::InitPrintDocConstruction(bool aHandleError)
 {
--- a/layout/xul/nsSliderFrame.cpp
+++ b/layout/xul/nsSliderFrame.cpp
@@ -15,17 +15,16 @@
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsCOMPtr.h"
 #include "nsNameSpaceManager.h"
 #include "nsGkAtoms.h"
 #include "nsHTMLParts.h"
 #include "nsIPresShell.h"
 #include "nsCSSRendering.h"
-#include "nsEventListenerManager.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsScrollbarButtonFrame.h"
 #include "nsISliderListener.h"
 #include "nsIScrollbarMediator.h"
 #include "nsScrollbarFrame.h"
 #include "nsRepeatService.h"
 #include "nsBoxLayoutState.h"
 #include "nsSprocketLayout.h"
--- a/layout/xul/tree/nsTreeBodyFrame.cpp
+++ b/layout/xul/tree/nsTreeBodyFrame.cpp
@@ -1,13 +1,14 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Likely.h"
 
 #include "nsCOMPtr.h"
 #include "nsPresContext.h"
@@ -18,17 +19,16 @@
 #include "nsTreeImageListener.h"
 
 #include "nsGkAtoms.h"
 #include "nsCSSAnonBoxes.h"
 
 #include "nsIContent.h"
 #include "nsStyleContext.h"
 #include "nsIBoxObject.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsIDOMDataContainerEvent.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDocument.h"
 #include "mozilla/css/StyleRule.h"
@@ -4557,21 +4557,19 @@ nsTreeBodyFrame::FireRowCountChangedEven
   if (!countVariant)
     return;
 
   countVariant->SetAsInt32(aCount);
   treeEvent->SetData(NS_LITERAL_STRING("count"), countVariant);
 
   event->SetTrusted(true);
 
-  nsRefPtr<nsAsyncDOMEvent> plevent = new nsAsyncDOMEvent(content, event);
-  if (!plevent)
-    return;
-
-  plevent->PostDOMEvent();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(content, event);
+  asyncDispatcher->PostDOMEvent();
 }
 
 void
 nsTreeBodyFrame::FireInvalidateEvent(int32_t aStartRowIdx, int32_t aEndRowIdx,
                                      nsITreeColumn *aStartCol,
                                      nsITreeColumn *aEndCol)
 {
   nsCOMPtr<nsIContent> content(GetBaseElement());
@@ -4639,19 +4637,19 @@ nsTreeBodyFrame::FireInvalidateEvent(int
       return;
 
     endColVariant->SetAsInt32(endColIdx);
     treeEvent->SetData(NS_LITERAL_STRING("endcolumn"), endColVariant);
   }
 
   event->SetTrusted(true);
 
-  nsRefPtr<nsAsyncDOMEvent> plevent = new nsAsyncDOMEvent(content, event);
-  if (plevent)
-    plevent->PostDOMEvent();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(content, event);
+  asyncDispatcher->PostDOMEvent();
 }
 #endif
 
 class nsOverflowChecker : public nsRunnable
 {
 public:
   nsOverflowChecker(nsTreeBodyFrame* aFrame) : mFrame(aFrame) {}
   NS_IMETHOD Run() MOZ_OVERRIDE
--- a/layout/xul/tree/nsTreeSelection.cpp
+++ b/layout/xul/tree/nsTreeSelection.cpp
@@ -1,29 +1,31 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "nsCOMPtr.h"
 #include "nsTreeSelection.h"
 #include "nsIBoxObject.h"
 #include "nsITreeBoxObject.h"
 #include "nsITreeView.h"
 #include "nsString.h"
 #include "nsIDOMElement.h"
 #include "nsDOMClassInfoID.h"
 #include "nsIContent.h"
 #include "nsNameSpaceManager.h"
 #include "nsGkAtoms.h"
-#include "nsAsyncDOMEvent.h"
 #include "nsEventDispatcher.h"
 #include "nsAutoPtr.h"
 #include "nsComponentManagerUtils.h"
 
+using namespace mozilla;
+
 // A helper class for managing our ranges of selection.
 struct nsTreeRange
 {
   nsTreeSelection* mSelection;
 
   nsTreeRange* mPrev;
   nsTreeRange* mNext;
 
@@ -645,21 +647,22 @@ NS_IMETHODIMP nsTreeSelection::SetCurren
   boxObject->GetElement(getter_AddRefs(treeElt));
 
   nsCOMPtr<nsINode> treeDOMNode(do_QueryInterface(treeElt));
   NS_ENSURE_STATE(treeDOMNode);
 
   NS_NAMED_LITERAL_STRING(DOMMenuItemActive, "DOMMenuItemActive");
   NS_NAMED_LITERAL_STRING(DOMMenuItemInactive, "DOMMenuItemInactive");
 
-  nsRefPtr<nsAsyncDOMEvent> event =
-    new nsAsyncDOMEvent(treeDOMNode,
-                     (aIndex != -1 ? DOMMenuItemActive : DOMMenuItemInactive),
-                      true, false);
-  return event->PostDOMEvent();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(treeDOMNode,
+                             (aIndex != -1 ? DOMMenuItemActive :
+                                             DOMMenuItemInactive),
+                             true, false);
+  return asyncDispatcher->PostDOMEvent();
 }
 
 NS_IMETHODIMP nsTreeSelection::GetCurrentColumn(nsITreeColumn** aCurrentColumn)
 {
   NS_IF_ADDREF(*aCurrentColumn = mCurrentColumn);
   return NS_OK;
 }
 
@@ -833,19 +836,19 @@ nsTreeSelection::FireOnSelectHandler()
      return NS_ERROR_UNEXPECTED;
   nsCOMPtr<nsIDOMElement> elt;
   boxObject->GetElement(getter_AddRefs(elt));
   NS_ENSURE_STATE(elt);
 
   nsCOMPtr<nsINode> node(do_QueryInterface(elt));
   NS_ENSURE_STATE(node);
 
-  nsRefPtr<nsAsyncDOMEvent> event =
-    new nsAsyncDOMEvent(node, NS_LITERAL_STRING("select"), true, false);
-  event->RunDOMEventWhenSafe();
+  nsRefPtr<AsyncEventDispatcher> asyncDispatcher =
+    new AsyncEventDispatcher(node, NS_LITERAL_STRING("select"), true, false);
+  asyncDispatcher->RunDOMEventWhenSafe();
   return NS_OK;
 }
 
 void
 nsTreeSelection::SelectCallback(nsITimer *aTimer, void *aClosure)
 {
   nsRefPtr<nsTreeSelection> self = static_cast<nsTreeSelection*>(aClosure);
   if (self) {
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -76,17 +76,17 @@ enum nsEventStructType
  * Messages
  *
  * TODO: Make them enum.
  ******************************************************************************/
 
 #define NS_EVENT_NULL                   0
 
 // This is a dummy event message for all event listener implementation in
-// nsEventListenerManager.
+// EventListenerManager.
 #define NS_EVENT_ALL                    1
 
 #define NS_WINDOW_START                 100
 
 // Widget may be destroyed
 #define NS_XUL_CLOSE                    (NS_WINDOW_START + 1)
 // Key is pressed within a window
 #define NS_KEY_PRESS                    (NS_WINDOW_START + 31)
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3978,17 +3978,17 @@ bool nsWindow::DispatchMouseEvent(uint32
     }
 
     result = DispatchWindowEvent(&event);
 
     if (nsToolkit::gMouseTrailer)
       nsToolkit::gMouseTrailer->Enable();
 
     // Release the widget with NS_IF_RELEASE() just in case
-    // the context menu key code in nsEventListenerManager::HandleEvent()
+    // the context menu key code in EventListenerManager::HandleEvent()
     // released it already.
     return result;
   }
 
   return result;
 }
 
 void nsWindow::DispatchFocusToTopLevelWindow(bool aIsActivate)