Bug 984271 part.2 Rename nsEventStateManager to mozilla::EventStateManager r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 01 Apr 2014 13:09:23 +0900
changeset 194959 77b2c81993b5b00b90ce4359b50bf3cd418552e1
parent 194958 df1a290b1c22a6bae9bdb636322d0c235de9308a
child 194960 6e171e00a903a9857fbb72ed4a0143ad2fe9b692
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs984271
milestone31.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
Bug 984271 part.2 Rename nsEventStateManager to mozilla::EventStateManager r=smaug
accessible/src/base/AccEvent.cpp
accessible/src/base/FocusManager.cpp
accessible/src/base/nsCoreUtils.cpp
accessible/src/base/nsCoreUtils.h
accessible/src/generic/DocAccessible.cpp
accessible/src/xul/XULMenuAccessible.cpp
b2g/app/b2g.js
browser/base/content/browser-fullZoom.js
browser/metro/profile/metro.js
content/base/public/Element.h
content/base/public/nsContentUtils.h
content/base/public/nsIFrameLoader.idl
content/base/src/Element.cpp
content/base/src/FragmentOrElement.cpp
content/base/src/nsContentUtils.cpp
content/base/src/nsDocument.cpp
content/base/src/nsINode.cpp
content/html/content/src/HTMLButtonElement.cpp
content/html/content/src/HTMLFormElement.cpp
content/html/content/src/HTMLMeterElement.h
content/html/content/src/HTMLProgressElement.h
content/html/content/src/nsGenericHTMLElement.cpp
content/xul/content/src/nsXULElement.cpp
content/xul/content/src/nsXULPopupListener.cpp
docshell/base/nsDocShell.cpp
dom/base/nsDOMWindowUtils.cpp
dom/base/nsFocusManager.cpp
dom/base/nsGlobalWindow.cpp
dom/events/ContentEventHandler.h
dom/events/DataTransfer.h
dom/events/Event.cpp
dom/events/EventStateManager.cpp
dom/events/EventStateManager.h
dom/events/UIEvent.cpp
dom/events/WheelHandlingHelper.cpp
dom/events/WheelHandlingHelper.h
dom/events/moz.build
dom/events/nsEventStateManager.cpp
dom/events/nsEventStateManager.h
dom/interfaces/base/nsIDOMWindowUtils.idl
dom/ipc/TabParent.cpp
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/xbl/nsXBLWindowKeyHandler.cpp
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
layout/base/nsPresShell.cpp
layout/forms/nsFormControlFrame.cpp
layout/forms/nsListControlFrame.cpp
layout/generic/nsFrame.cpp
layout/inspector/inDOMUtils.cpp
layout/inspector/inLayoutUtils.cpp
layout/inspector/inLayoutUtils.h
layout/xul/nsBoxFrame.cpp
layout/xul/nsButtonBoxFrame.cpp
layout/xul/nsMenuFrame.cpp
layout/xul/nsMenuPopupFrame.cpp
layout/xul/nsTextBoxFrame.cpp
layout/xul/nsXULLabelFrame.cpp
layout/xul/nsXULPopupManager.cpp
mobile/android/app/mobile.js
modules/libpref/src/init/all.js
view/src/nsViewManager.cpp
widget/MouseEvents.h
widget/android/nsLookAndFeel.cpp
widget/cocoa/nsLookAndFeel.mm
widget/gonk/nsLookAndFeel.cpp
widget/qt/nsLookAndFeel.cpp
widget/shared/WidgetEventImpl.cpp
widget/windows/nsLookAndFeel.cpp
widget/windows/winrt/MetroInput.cpp
widget/xpwidgets/nsBaseWidget.cpp
widget/xpwidgets/nsNativeTheme.cpp
widget/xpwidgets/nsNativeTheme.h
--- a/accessible/src/base/AccEvent.cpp
+++ b/accessible/src/base/AccEvent.cpp
@@ -6,17 +6,17 @@
 
 #include "AccEvent.h"
 
 #include "nsAccUtils.h"
 #include "DocAccessible.h"
 #include "xpcAccEvents.h"
 #include "States.h"
 
-#include "nsEventStateManager.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/Selection.h"
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 static_assert(static_cast<bool>(eNoUserInput) == false &&
               static_cast<bool>(eFromUserInput) == true,
               "EIsFromUserInput cannot be casted to bool");
@@ -28,17 +28,17 @@ static_assert(static_cast<bool>(eNoUserI
 ////////////////////////////////////////////////////////////////////////////////
 // AccEvent constructors
 
 AccEvent::AccEvent(uint32_t aEventType, Accessible* aAccessible,
                    EIsFromUserInput aIsFromUserInput, EEventRule aEventRule) :
   mEventType(aEventType), mEventRule(aEventRule), mAccessible(aAccessible)
 {
   if (aIsFromUserInput == eAutoDetect)
-    mIsFromUserInput = nsEventStateManager::IsHandlingUserInput();
+    mIsFromUserInput = EventStateManager::IsHandlingUserInput();
   else
     mIsFromUserInput = aIsFromUserInput == eFromUserInput ? true : false;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // AccEvent cycle collection
 
 NS_IMPL_CYCLE_COLLECTION_1(AccEvent, mAccessible)
--- a/accessible/src/base/FocusManager.cpp
+++ b/accessible/src/base/FocusManager.cpp
@@ -7,22 +7,22 @@
 #include "Accessible-inl.h"
 #include "AccIterator.h"
 #include "DocAccessible-inl.h"
 #include "nsAccessibilityService.h"
 #include "nsAccUtils.h"
 #include "nsEventShell.h"
 #include "Role.h"
 
-#include "nsEventStateManager.h"
 #include "nsFocusManager.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/dom/Element.h"
 
-namespace dom = mozilla::dom;
-using namespace mozilla::a11y;
+namespace mozilla {
+namespace a11y {
 
 FocusManager::FocusManager()
 {
 }
 
 FocusManager::~FocusManager()
 {
 }
@@ -389,24 +389,28 @@ FocusManager::FocusedDOMNode() const
 {
   nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
   nsIContent* focusedElm = DOMFocusManager->GetFocusedContent();
 
   // No focus on remote target elements like xul:browser having DOM focus and
   // residing in chrome process because it means an element in content process
   // keeps the focus.
   if (focusedElm) {
-    if (nsEventStateManager::IsRemoteTarget(focusedElm))
+    if (EventStateManager::IsRemoteTarget(focusedElm)) {
       return nullptr;
+    }
     return focusedElm;
   }
 
   // Otherwise the focus can be on DOM document.
   nsPIDOMWindow* focusedWnd = DOMFocusManager->GetFocusedWindow();
   return focusedWnd ? focusedWnd->GetExtantDoc() : nullptr;
 }
 
 nsIDocument*
 FocusManager::FocusedDOMDocument() const
 {
   nsINode* focusedNode = FocusedDOMNode();
   return focusedNode ? focusedNode->OwnerDoc() : nullptr;
 }
+
+} // namespace a11y
+} // namespace mozilla
--- a/accessible/src/base/nsCoreUtils.cpp
+++ b/accessible/src/base/nsCoreUtils.cpp
@@ -14,21 +14,21 @@
 #include "nsIDOMHTMLElement.h"
 #include "nsRange.h"
 #include "nsIBoxObject.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDocShell.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/EventStateManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "nsView.h"
 #include "nsGkAtoms.h"
 
 #include "nsComponentManagerUtils.h"
 
 #include "nsITreeBoxObject.h"
@@ -157,29 +157,29 @@ nsCoreUtils::DispatchTouchEvent(uint32_t
   aPresShell->HandleEventWithTarget(&event, aFrame, aContent, &status);
 }
 
 uint32_t
 nsCoreUtils::GetAccessKeyFor(nsIContent* aContent)
 {
   // Accesskeys are registered by @accesskey attribute only. At first check
   // whether it is presented on the given element to avoid the slow
-  // nsEventStateManager::GetRegisteredAccessKey() method.
+  // EventStateManager::GetRegisteredAccessKey() method.
   if (!aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::accesskey))
     return 0;
 
   nsIPresShell* presShell = aContent->OwnerDoc()->GetShell();
   if (!presShell)
     return 0;
 
   nsPresContext *presContext = presShell->GetPresContext();
   if (!presContext)
     return 0;
 
-  nsEventStateManager *esm = presContext->EventStateManager();
+  EventStateManager *esm = presContext->EventStateManager();
   if (!esm)
     return 0;
 
   return esm->GetRegisteredAccessKey(aContent);
 }
 
 nsIContent *
 nsCoreUtils::GetDOMElementFor(nsIContent *aContent)
--- a/accessible/src/base/nsCoreUtils.h
+++ b/accessible/src/base/nsCoreUtils.h
@@ -73,17 +73,17 @@ public:
    * @param aRootWidget  [in] the root widget of the element
    */
   static void DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY,
                                  nsIContent* aContent, nsIFrame* aFrame,
                                  nsIPresShell* aPresShell, nsIWidget* aRootWidget);
 
   /**
    * Return an accesskey registered on the given element by
-   * nsEventStateManager or 0 if there is no registered accesskey.
+   * EventStateManager or 0 if there is no registered accesskey.
    *
    * @param aContent - the given element.
    */
   static uint32_t GetAccessKeyFor(nsIContent *aContent);
 
   /**
    * Return DOM element related with the given node, i.e.
    * a) itself if it is DOM element
--- a/accessible/src/generic/DocAccessible.cpp
+++ b/accessible/src/generic/DocAccessible.cpp
@@ -23,17 +23,16 @@
 #include "nsIDOMAttr.h"
 #include "nsIDOMCharacterData.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMXULDocument.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMXULPopupElement.h"
 #include "nsIEditingSession.h"
-#include "nsEventStateManager.h"
 #include "nsIFrame.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsImageFrame.h"
 #include "nsIPersistentProperties2.h"
 #include "nsIPresShell.h"
 #include "nsIServiceManager.h"
 #include "nsViewManager.h"
 #include "nsIScrollableFrame.h"
--- a/accessible/src/xul/XULMenuAccessible.cpp
+++ b/accessible/src/xul/XULMenuAccessible.cpp
@@ -149,17 +149,17 @@ XULMenuitemAccessible::Description(nsStr
 
 KeyBinding
 XULMenuitemAccessible::AccessKey() const
 {
   // Return menu accesskey: N or Alt+F.
   static int32_t gMenuAccesskeyModifier = -1;  // magic value of -1 indicates unitialized state
 
   // We do not use nsCoreUtils::GetAccesskeyFor() because accesskeys for
-  // menu are't registered by nsEventStateManager.
+  // menu are't registered by EventStateManager.
   nsAutoString accesskey;
   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey,
                     accesskey);
   if (accesskey.IsEmpty())
     return KeyBinding();
 
   uint32_t modifierKey = 0;
 
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -260,17 +260,17 @@ pref("ui.infotext", "#686868");
 pref("ui.window", "#ffffff");
 pref("ui.windowtext", "#000000");
 pref("ui.highlight", "#b2f2ff");
 
 // replace newlines with spaces on paste into single-line text boxes
 pref("editor.singleLine.pasteNewlines", 2);
 
 // threshold where a tap becomes a drag, in 1/240" reference pixels
-// The names of the preferences are to be in sync with nsEventStateManager.cpp
+// The names of the preferences are to be in sync with EventStateManager.cpp
 pref("ui.dragThresholdX", 25);
 pref("ui.dragThresholdY", 25);
 
 // Layers Acceleration.  We can only have nice things on gonk, because
 // they're not maintained anywhere else.
 pref("layers.offmainthreadcomposition.enabled", true);
 #ifndef MOZ_WIDGET_GONK
 pref("dom.ipc.tabs.disabled", true);
--- a/browser/base/content/browser-fullZoom.js
+++ b/browser/base/content/browser-fullZoom.js
@@ -15,17 +15,17 @@ var FullZoom = {
 
   // browser.zoom.siteSpecific preference cache
   _siteSpecificPref: undefined,
 
   // browser.zoom.updateBackgroundTabs preference cache
   updateBackgroundTabs: undefined,
 
   // One of the possible values for the mousewheel.* preferences.
-  // From nsEventStateManager.h.
+  // From EventStateManager.h.
   ACTION_ZOOM: 3,
 
   // This maps the browser to monotonically increasing integer
   // tokens. _browserTokenMap[browser] is increased each time the zoom is
   // changed in the browser. See _getBrowserToken and _ignorePendingZoomAccesses.
   _browserTokenMap: new WeakMap(),
 
   get siteSpecific() {
@@ -79,17 +79,17 @@ var FullZoom = {
       case "DOMMouseScroll":
         this._handleMouseScrolled(event);
         break;
     }
   },
 
   _handleMouseScrolled: function FullZoom__handleMouseScrolled(event) {
     // Construct the "mousewheel action" pref key corresponding to this event.
-    // Based on nsEventStateManager::WheelPrefs::GetBasePrefName().
+    // Based on EventStateManager::WheelPrefs::GetBasePrefName().
     var pref = "mousewheel.";
 
     var pressedModifierCount = event.shiftKey + event.ctrlKey + event.altKey +
                                  event.metaKey + event.getModifierState("OS");
     if (pressedModifierCount != 1) {
       pref += "default.";
     } else if (event.shiftKey) {
       pref += "with_shift.";
@@ -114,17 +114,17 @@ var FullZoom = {
       return;
 
     // XXX Lazily cache all the possible action prefs so we don't have to get
     // them anew from the pref service for every scroll event?  We'd have to
     // make sure to observe them so we can update the cache when they change.
 
     // We have to call _applyZoomToPref in a timeout because we handle the
     // event before the event state manager has a chance to apply the zoom
-    // during nsEventStateManager::PostHandleEvent.
+    // during EventStateManager::PostHandleEvent.
     let browser = gBrowser.selectedBrowser;
     let token = this._getBrowserToken(browser);
     window.setTimeout(function () {
       if (token.isCurrent)
         this._applyZoomToPref(browser);
     }.bind(this), 0);
   },
 
--- a/browser/metro/profile/metro.js
+++ b/browser/metro/profile/metro.js
@@ -546,17 +546,17 @@ pref("services.sync.prefs.sync.devtools.
 pref("services.sync.prefs.sync.lightweightThemes.isThemeSelected", true);
 pref("services.sync.prefs.sync.lightweightThemes.usedThemes", true);
 pref("services.sync.prefs.sync.privacy.donottrackheader.enabled", true);
 pref("services.sync.prefs.sync.privacy.donottrackheader.value", true);
 pref("services.sync.prefs.sync.signon.rememberSignons", true);
 #endif
 
 // threshold where a tap becomes a drag, in 1/240" reference pixels
-// The names of the preferences are to be in sync with nsEventStateManager.cpp
+// The names of the preferences are to be in sync with EventStateManager.cpp
 pref("ui.dragThresholdX", 50);
 pref("ui.dragThresholdY", 50);
 
 // prevent tooltips from showing up
 pref("browser.chrome.toolbar_tips", false);
 
 #ifdef NIGHTLY_BUILD
 // Completely disable pdf.js as an option to preview pdfs within firefox.
--- a/content/base/public/Element.h
+++ b/content/base/public/Element.h
@@ -46,17 +46,16 @@ class nsINodeInfo;
 class nsIControllers;
 class nsEventChainVisitor;
 class nsIScrollableFrame;
 class nsAttrValueOrString;
 class ContentUnbinder;
 class nsContentList;
 class nsDOMTokenList;
 struct nsRect;
-class nsEventStateManager;
 class nsFocusManager;
 class nsGlobalWindow;
 class nsICSSDeclaration;
 class nsISMILAttr;
 
 already_AddRefed<nsContentList>
 NS_GetContentList(nsINode* aRootNode,
                   int32_t  aMatchNameSpaceId,
@@ -101,16 +100,17 @@ enum {
 // Make sure we have space for our bits
 ASSERT_NODE_FLAGS_SPACE(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET);
 
 namespace mozilla {
 class EventChainPostVisitor;
 class EventChainPreVisitor;
 class EventChainVisitor;
 class EventListenerManager;
+class EventStateManager;
 
 namespace dom {
 
 class Link;
 class UndoManager;
 class DOMRect;
 class DOMRectList;
 
@@ -369,17 +369,17 @@ protected:
    */
   void RemoveStatesSilently(nsEventStates aStates) {
     mState &= ~aStates;
   }
 
 private:
   // Need to allow the ESM, nsGlobalWindow, and the focus manager to
   // set our state
-  friend class ::nsEventStateManager;
+  friend class mozilla::EventStateManager;
   friend class ::nsGlobalWindow;
   friend class ::nsFocusManager;
 
   // Also need to allow Link to call UpdateLinkState.
   friend class Link;
 
   void NotifyStateChange(nsEventStates aStates);
 
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -1876,17 +1876,17 @@ public:
   /**
    * Returns true if aWin and the current pointer lock document
    * have common scriptable top window.
    */
   static bool IsInPointerLockContext(nsIDOMWindow* aWin);
 
   /**
    * Returns the time limit on handling user input before
-   * nsEventStateManager::IsHandlingUserInput() stops returning true.
+   * EventStateManager::IsHandlingUserInput() stops returning true.
    * This enables us to detect long running user-generated event handlers.
    */
   static TimeDuration HandlingUserInputTimeout();
 
   static void GetShiftText(nsAString& text);
   static void GetControlText(nsAString& text);
   static void GetMetaText(nsAString& text);
   static void GetOSText(nsAString& text);
--- a/content/base/public/nsIFrameLoader.idl
+++ b/content/base/public/nsIFrameLoader.idl
@@ -220,17 +220,17 @@ interface nsIFrameLoader : nsISupports
    * the platform hands over control of scroll offset to the user.
    */
   const unsigned long RENDER_MODE_ASYNC_SCROLL   = 0x00000001;
 
   attribute unsigned long renderMode;
 
   /**
    * The default event mode automatically forwards the events
-   * handled in nsEventStateManager::HandleCrossProcessEvent to
+   * handled in EventStateManager::HandleCrossProcessEvent to
    * the child content process when these events are targeted to
    * the remote browser element.
    *
    * Used primarly for input events (mouse, keyboard)
    */
   const unsigned long EVENT_MODE_NORMAL_DISPATCH = 0x00000000;
 
   /**
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -29,17 +29,16 @@
 #include "nsNetUtil.h"
 #include "nsIFrame.h"
 #include "nsIAnonymousContentCreator.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsStyleConsts.h"
 #include "nsString.h"
 #include "nsUnicharUtils.h"
-#include "nsEventStateManager.h"
 #include "nsIDOMEvent.h"
 #include "nsDOMCID.h"
 #include "nsIServiceManager.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsDOMCSSAttrDeclaration.h"
 #include "nsNameSpaceManager.h"
 #include "nsContentList.h"
 #include "nsDOMTokenList.h"
@@ -47,16 +46,17 @@
 #include "nsError.h"
 #include "nsDOMString.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIDOMMutationEvent.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventListenerManager.h"
+#include "mozilla/EventStateManager.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"
@@ -2425,17 +2425,17 @@ Element::PostHandleEventForLinks(EventCh
           nsIFocusManager* fm = nsFocusManager::GetFocusManager();
           if (fm) {
             aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
             nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(this);
             fm->SetFocus(elem, nsIFocusManager::FLAG_BYMOUSE |
                                nsIFocusManager::FLAG_NOSCROLL);
           }
 
-          nsEventStateManager::SetActiveManager(
+          EventStateManager::SetActiveManager(
             aVisitor.mPresContext->EventStateManager(), this);
         }
       }
     }
     break;
 
   case NS_MOUSE_CLICK: {
     WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
--- a/content/base/src/FragmentOrElement.cpp
+++ b/content/base/src/FragmentOrElement.cpp
@@ -35,17 +35,16 @@
 #include "nsNetUtil.h"
 #include "nsIFrame.h"
 #include "nsIAnonymousContentCreator.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsStyleConsts.h"
 #include "nsString.h"
 #include "nsUnicharUtils.h"
-#include "nsEventStateManager.h"
 #include "nsIDOMEvent.h"
 #include "nsDOMCID.h"
 #include "nsIServiceManager.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsDOMCSSAttrDeclaration.h"
 #include "nsNameSpaceManager.h"
 #include "nsContentList.h"
 #include "nsDOMTokenList.h"
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -38,16 +38,17 @@
 #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/EventDispatcher.h"
 #include "mozilla/EventListenerManager.h"
+#include "mozilla/EventStateManager.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"
@@ -70,17 +71,16 @@
 #include "nsDataHashtable.h"
 #include "nsDocShellCID.h"
 #include "nsDocument.h"
 #include "nsDOMCID.h"
 #include "mozilla/dom/DataTransfer.h"
 #include "nsDOMJSUtils.h"
 #include "nsDOMMutationObserver.h"
 #include "nsError.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"
 #include "nsIAsyncVerifyRedirectCallback.h"
@@ -5026,17 +5026,17 @@ nsContentUtils::SetDataTransferInEvent(W
     aDragEvent->dataTransfer->GetEffectAllowedInt(&effectAllowed);
     aDragEvent->dataTransfer->SetDropEffectInt(FilterDropEffect(action, effectAllowed));
   }
   else if (aDragEvent->message == NS_DRAGDROP_DROP ||
            aDragEvent->message == NS_DRAGDROP_DRAGDROP ||
            aDragEvent->message == NS_DRAGDROP_END) {
     // For the drop and dragend events, set the drop effect based on the
     // last value that the dropEffect had. This will have been set in
-    // nsEventStateManager::PostHandleEvent for the last dragenter or
+    // EventStateManager::PostHandleEvent for the last dragenter or
     // dragover event.
     uint32_t dropEffect;
     initialDataTransfer->GetDropEffectInt(&dropEffect);
     aDragEvent->dataTransfer->SetDropEffectInt(dropEffect);
   }
 
   return NS_OK;
 }
@@ -5839,17 +5839,17 @@ nsContentUtils::IsSubDocumentTabbable(ns
 {
   nsIDocument* doc = aContent->GetCurrentDoc();
   if (!doc) {
     return false;
   }
 
   // If the subdocument lives in another process, the frame is
   // tabbable.
-  if (nsEventStateManager::IsRemoteTarget(aContent)) {
+  if (EventStateManager::IsRemoteTarget(aContent)) {
     return true;
   }
 
   // XXXbz should this use OwnerDoc() for GetSubDocumentFor?
   // sXBL/XBL2 issue!
   nsIDocument* subDoc = doc->GetSubDocumentFor(aContent);
   if (!subDoc) {
     return false;
@@ -6273,17 +6273,17 @@ nsContentUtils::IsFullScreenApiEnabled()
   return sIsFullScreenApiEnabled;
 }
 
 /* static */
 bool
 nsContentUtils::IsRequestFullScreenAllowed()
 {
   return !sTrustedFullScreenOnly ||
-         nsEventStateManager::IsHandlingUserInput() ||
+         EventStateManager::IsHandlingUserInput() ||
          IsCallerChrome();
 }
 
 /* static */
 bool
 nsContentUtils::IsFullscreenApiContentOnly()
 {
   return sFullscreenApiIsContentOnly;
@@ -6414,17 +6414,17 @@ nsContentUtils::GetFullscreenAncestor(ns
 bool
 nsContentUtils::IsInPointerLockContext(nsIDOMWindow* aWin)
 {
   if (!aWin) {
     return false;
   }
 
   nsCOMPtr<nsIDocument> pointerLockedDoc =
-    do_QueryReferent(nsEventStateManager::sPointerLockedDoc);
+    do_QueryReferent(EventStateManager::sPointerLockedDoc);
   if (!pointerLockedDoc || !pointerLockedDoc->GetWindow()) {
     return false;
   }
 
   nsCOMPtr<nsIDOMWindow> lockTop;
   pointerLockedDoc->GetWindow()->GetScriptableTop(getter_AddRefs(lockTop));
 
   nsCOMPtr<nsIDOMWindow> top;
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -38,16 +38,17 @@
 #include "nsIDocShellTreeItem.h"
 #include "nsCOMArray.h"
 #include "nsDOMClassInfo.h"
 #include "nsCxPusher.h"
 
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/EventListenerManager.h"
+#include "mozilla/EventStateManager.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"
@@ -153,17 +154,16 @@
 #include "IPeerConnection.h"
 #endif // MOZ_WEBRTC
 
 #include "mozAutoDocUpdate.h"
 #include "nsGlobalWindow.h"
 #include "mozilla/dom/EncodingUtils.h"
 #include "mozilla/dom/quota/QuotaManager.h"
 #include "nsDOMNavigationTiming.h"
-#include "nsEventStateManager.h"
 
 #include "nsSMILAnimationController.h"
 #include "imgIContainer.h"
 #include "nsSVGUtils.h"
 #include "SVGElementFactory.h"
 
 #include "nsRefreshDriver.h"
 
@@ -10588,17 +10588,17 @@ ExitFullscreenInDocTree(nsIDocument* aMa
 }
 
 /* static */
 void
 nsDocument::ExitFullscreen(nsIDocument* aDoc)
 {
   // Unlock the pointer, if it's locked.
   nsCOMPtr<Element> pointerLockedElement =
-    do_QueryReferent(nsEventStateManager::sPointerLockedElement);
+    do_QueryReferent(EventStateManager::sPointerLockedElement);
   if (pointerLockedElement) {
     UnlockPointer();
   }
 
   if (aDoc)  {
     ExitFullscreenInDocTree(aDoc);
     return;
   }
@@ -10653,17 +10653,17 @@ nsDocument::RestorePreviousFullScreenSta
                "chrome document when fullscreen is content only");
 
   if (!IsFullScreenDoc() || !GetWindow() || FullscreenRoots::IsEmpty()) {
     return;
   }
 
   // If fullscreen mode is updated the pointer should be unlocked
   nsCOMPtr<Element> pointerLockedElement =
-    do_QueryReferent(nsEventStateManager::sPointerLockedElement);
+    do_QueryReferent(EventStateManager::sPointerLockedElement);
   if (pointerLockedElement) {
     UnlockPointer();
   }
 
   nsCOMPtr<nsIDocument> fullScreenDoc = GetFullscreenLeaf(this);
 
   // The fullscreen document may contain a <iframe mozbrowser> element which
   // has a cross process child. So send a notification so that its browser
@@ -10852,17 +10852,17 @@ nsDocument::CleanupFullscreenState()
 {
   if (!mFullScreenStack.IsEmpty()) {
     // The top element in the full-screen stack will have full-screen
     // style bits set on it and its ancestors. Remove the style bits.
     // Note the non-top elements won't have the style bits set.
     Element* top = FullScreenStackTop();
     NS_ASSERTION(top, "Should have a top when full-screen stack isn't empty");
     if (top) {
-      nsEventStateManager::SetFullScreenState(top, false);
+      EventStateManager::SetFullScreenState(top, false);
     }
     mFullScreenStack.Clear();
   }
   SetApprovedForFullscreen(false);
   RemoveFullscreenApprovedObserver();
   mFullscreenRoot = nullptr;
 }
 
@@ -10873,35 +10873,35 @@ nsDocument::FullScreenStackPush(Element*
   Element* top = FullScreenStackTop();
   if (top == aElement || !aElement) {
     return false;
   }
   if (top) {
     // We're pushing a new element onto the full-screen stack, so we must
     // remove the ancestor and full-screen styles from the former top of the
     // stack.
-    nsEventStateManager::SetFullScreenState(top, false);
-  }
-  nsEventStateManager::SetFullScreenState(aElement, true);
+    EventStateManager::SetFullScreenState(top, false);
+  }
+  EventStateManager::SetFullScreenState(aElement, true);
   nsWeakPtr weakElement = do_GetWeakReference(aElement);
   mFullScreenStack.AppendElement(weakElement);
   NS_ASSERTION(GetFullScreenElement() == aElement, "Should match");
   return true;
 }
 
 void
 nsDocument::FullScreenStackPop()
 {
   if (mFullScreenStack.IsEmpty()) {
     return;
   }
 
   // Remove styles from existing top element.
   Element* top = FullScreenStackTop();
-  nsEventStateManager::SetFullScreenState(top, false);
+  EventStateManager::SetFullScreenState(top, false);
 
   // Remove top element. Note the remaining top element in the stack
   // will not have full-screen style bits set, so we will need to restore
   // them on the new top element before returning.
   uint32_t last = mFullScreenStack.Length() - 1;
   mFullScreenStack.RemoveElementAt(last);
 
   // Pop from the stack null elements (references to elements which have
@@ -10912,17 +10912,17 @@ nsDocument::FullScreenStackPop()
     if (!element || !element->IsInDoc() || element->OwnerDoc() != this) {
       NS_ASSERTION(!element->IsFullScreenAncestor(),
                    "Should have already removed full-screen styles");
       uint32_t last = mFullScreenStack.Length() - 1;
       mFullScreenStack.RemoveElementAt(last);
     } else {
       // The top element of the stack is now an in-doc element. Apply the
       // full-screen styles and return.
-      nsEventStateManager::SetFullScreenState(element, true);
+      EventStateManager::SetFullScreenState(element, true);
       break;
     }
   }
 }
 
 Element*
 nsDocument::FullScreenStackTop()
 {
@@ -11089,17 +11089,17 @@ nsDocument::RequestFullScreen(Element* a
     // A document is already in fullscreen, unlock the mouse pointer
     // before setting a new document to fullscreen
     UnlockPointer();
   }
 
   // If a document is already in fullscreen, then unlock the mouse pointer
   // before setting a new document to fullscreen
   nsCOMPtr<Element> pointerLockedElement =
-    do_QueryReferent(nsEventStateManager::sPointerLockedElement);
+    do_QueryReferent(EventStateManager::sPointerLockedElement);
   if (pointerLockedElement) {
     UnlockPointer();
   }
 
   // Set the full-screen element. This sets the full-screen style on the
   // element, and the full-screen-ancestor styles on ancestors of the element
   // in this document.
   DebugOnly<bool> x = FullScreenStackPush(aElement);
@@ -11483,17 +11483,17 @@ nsPointerLockPermissionRequest::Allow(JS
     DispatchPointerLockError(d);
     return NS_OK;
   }
 
   // Mark handled here so that we don't need to call it everywhere below.
   Handled();
 
   nsCOMPtr<Element> pointerLockedElement =
-    do_QueryReferent(nsEventStateManager::sPointerLockedElement);
+    do_QueryReferent(EventStateManager::sPointerLockedElement);
   if (e == pointerLockedElement) {
     DispatchPointerLockChange(d);
     return NS_OK;
   }
 
   // Note, we must bypass focus change, so pass true as the last parameter!
   if (!d->ShouldLockPointer(e, pointerLockedElement, true)) {
     DispatchPointerLockError(d);
@@ -11502,20 +11502,20 @@ nsPointerLockPermissionRequest::Allow(JS
 
   if (!d->SetPointerLock(e, NS_STYLE_CURSOR_NONE)) {
     DispatchPointerLockError(d);
     return NS_OK;
   }
 
   d->mCancelledPointerLockRequests = 0;
   e->SetPointerLock();
-  nsEventStateManager::sPointerLockedElement = do_GetWeakReference(e);
-  nsEventStateManager::sPointerLockedDoc = do_GetWeakReference(doc);
-  NS_ASSERTION(nsEventStateManager::sPointerLockedElement &&
-               nsEventStateManager::sPointerLockedDoc,
+  EventStateManager::sPointerLockedElement = do_GetWeakReference(e);
+  EventStateManager::sPointerLockedDoc = do_GetWeakReference(doc);
+  NS_ASSERTION(EventStateManager::sPointerLockedElement &&
+               EventStateManager::sPointerLockedDoc,
                "aElement and this should support weak references!");
 
   DispatchPointerLockChange(d);
   return NS_OK;
 }
 
 void
 nsDocument::SetApprovedForFullscreen(bool aIsApproved)
@@ -11558,28 +11558,28 @@ nsDocument::Observe(nsISupports *aSubjec
 
 void
 nsDocument::RequestPointerLock(Element* aElement)
 {
   NS_ASSERTION(aElement,
     "Must pass non-null element to nsDocument::RequestPointerLock");
 
   nsCOMPtr<Element> pointerLockedElement =
-    do_QueryReferent(nsEventStateManager::sPointerLockedElement);
+    do_QueryReferent(EventStateManager::sPointerLockedElement);
   if (aElement == pointerLockedElement) {
     DispatchPointerLockChange(this);
     return;
   }
 
   if (!ShouldLockPointer(aElement, pointerLockedElement)) {
     DispatchPointerLockError(this);
     return;
   }
 
-  bool userInputOrChromeCaller = nsEventStateManager::IsHandlingUserInput() ||
+  bool userInputOrChromeCaller = EventStateManager::IsHandlingUserInput() ||
                                  nsContentUtils::IsCallerChrome();
 
   gPendingPointerLockRequest =
     new nsPointerLockPermissionRequest(aElement, userInputOrChromeCaller);
   nsCOMPtr<nsIRunnable> r = gPendingPointerLockRequest.get();
   NS_DispatchToMainThread(r);
 }
 
@@ -11689,49 +11689,49 @@ nsDocument::SetPointerLock(Element* aEle
   }
 
   if (aElement && (aElement->OwnerDoc() != this)) {
     NS_WARNING("SetPointerLock(): Element not in this document.");
     return false;
   }
 
   // Hide the cursor and set pointer lock for future mouse events
-  nsRefPtr<nsEventStateManager> esm = presContext->EventStateManager();
+  nsRefPtr<EventStateManager> esm = presContext->EventStateManager();
   esm->SetCursor(aCursorStyle, nullptr, false,
                  0.0f, 0.0f, widget, true);
   esm->SetPointerLock(widget, aElement);
 
   return true;
 }
 
 void
 nsDocument::UnlockPointer(nsIDocument* aDoc)
 {
-  if (!nsEventStateManager::sIsPointerLocked) {
+  if (!EventStateManager::sIsPointerLocked) {
     return;
   }
 
   nsCOMPtr<nsIDocument> pointerLockedDoc =
-    do_QueryReferent(nsEventStateManager::sPointerLockedDoc);
+    do_QueryReferent(EventStateManager::sPointerLockedDoc);
   if (!pointerLockedDoc || (aDoc && aDoc != pointerLockedDoc)) {
     return;
   }
   nsDocument* doc = static_cast<nsDocument*>(pointerLockedDoc.get());
   if (!doc->SetPointerLock(nullptr, NS_STYLE_CURSOR_AUTO)) {
     return;
   }
 
   nsCOMPtr<Element> pointerLockedElement =
-    do_QueryReferent(nsEventStateManager::sPointerLockedElement);
+    do_QueryReferent(EventStateManager::sPointerLockedElement);
   if (pointerLockedElement) {
     pointerLockedElement->ClearPointerLock();
   }
 
-  nsEventStateManager::sPointerLockedElement = nullptr;
-  nsEventStateManager::sPointerLockedDoc = nullptr;
+  EventStateManager::sPointerLockedElement = nullptr;
+  EventStateManager::sPointerLockedDoc = nullptr;
   static_cast<nsDocument*>(pointerLockedDoc.get())->mAllowRelocking = !!aDoc;
   gPendingPointerLockRequest = nullptr;
   DispatchPointerLockChange(pointerLockedDoc);
 }
 
 void
 nsIDocument::UnlockPointer(nsIDocument* aDoc)
 {
@@ -11753,24 +11753,24 @@ nsDocument::GetMozPointerLockElement(nsI
   retval.forget(aPointerLockedElement);
   return NS_OK;
 }
 
 Element*
 nsIDocument::GetMozPointerLockElement()
 {
   nsCOMPtr<Element> pointerLockedElement =
-    do_QueryReferent(nsEventStateManager::sPointerLockedElement);
+    do_QueryReferent(EventStateManager::sPointerLockedElement);
   if (!pointerLockedElement) {
     return nullptr;
   }
 
   // Make sure pointer locked element is in the same document.
   nsCOMPtr<nsIDocument> pointerLockedDoc =
-    do_QueryReferent(nsEventStateManager::sPointerLockedDoc);
+    do_QueryReferent(EventStateManager::sPointerLockedDoc);
   if (pointerLockedDoc != this) {
     return nullptr;
   }
 
   return pointerLockedElement;
 }
 
 void
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -35,17 +35,16 @@
 #include "mozilla/dom/Attr.h"
 #include "nsDOMAttributeMap.h"
 #include "nsDOMCID.h"
 #include "nsDOMCSSAttrDeclaration.h"
 #include "nsError.h"
 #include "nsDOMMutationObserver.h"
 #include "nsDOMString.h"
 #include "nsDOMTokenList.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"
 #include "nsIBaseWindow.h"
--- a/content/html/content/src/HTMLButtonElement.cpp
+++ b/content/html/content/src/HTMLButtonElement.cpp
@@ -12,23 +12,23 @@
 #include "nsIPresShell.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsIFormControl.h"
 #include "nsIForm.h"
 #include "nsFormSubmission.h"
 #include "nsFormSubmissionConstants.h"
 #include "nsIURL.h"
-#include "nsEventStateManager.h"
 #include "nsIFrame.h"
 #include "nsIFormControlFrame.h"
 #include "nsIDOMEvent.h"
 #include "nsIDocument.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "nsUnicharUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsPresState.h"
 #include "nsError.h"
 #include "nsFocusManager.h"
 #include "mozilla/dom/HTMLFormElement.h"
@@ -283,20 +283,20 @@ HTMLButtonElement::PostHandleEvent(Event
         }
         break;// NS_KEY_PRESS
 
       case NS_MOUSE_BUTTON_DOWN:
         {
           WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
           if (mouseEvent->button == WidgetMouseEvent::eLeftButton) {
             if (mouseEvent->mFlags.mIsTrusted) {
-              nsEventStateManager* esm =
+              EventStateManager* esm =
                 aVisitor.mPresContext->EventStateManager();
-              nsEventStateManager::SetActiveManager(
-                static_cast<nsEventStateManager*>(esm), this);
+              EventStateManager::SetActiveManager(
+                static_cast<EventStateManager*>(esm), this);
             }
             nsIFocusManager* fm = nsFocusManager::GetFocusManager();
             if (fm)
               fm->SetFocus(this, nsIFocusManager::FLAG_BYMOUSE |
                                  nsIFocusManager::FLAG_NOSCROLL);
             mouseEvent->mFlags.mMultipleActionsPrevented = true;
           } else if (mouseEvent->button == WidgetMouseEvent::eMiddleButton ||
                      mouseEvent->button == WidgetMouseEvent::eRightButton) {
--- a/content/html/content/src/HTMLFormElement.cpp
+++ b/content/html/content/src/HTMLFormElement.cpp
@@ -3,20 +3,20 @@
  * 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/HTMLFormElement.h"
 
 #include "jsapi.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/dom/HTMLFormControlsCollection.h"
 #include "mozilla/dom/HTMLFormElementBinding.h"
 #include "nsIHTMLDocument.h"
-#include "nsEventStateManager.h"
 #include "nsEventStates.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsIDocument.h"
 #include "nsIFormControlFrame.h"
 #include "nsISecureBrowserUI.h"
 #include "nsError.h"
@@ -653,17 +653,17 @@ HTMLFormElement::DoSubmit(WidgetEvent* a
   nsPIDOMWindow *window = OwnerDoc()->GetWindow();
 
   if (window) {
     mSubmitPopupState = window->GetPopupControlState();
   } else {
     mSubmitPopupState = openAbused;
   }
 
-  mSubmitInitiatedFromUserInput = nsEventStateManager::IsHandlingUserInput();
+  mSubmitInitiatedFromUserInput = EventStateManager::IsHandlingUserInput();
 
   if(mDeferSubmission) { 
     // we are in an event handler, JS submitted so we have to
     // defer this submission. let's remember it and return
     // without submitting
     mPendingSubmission = submission;
     // ensure reentrancy
     mIsSubmitting = false;
--- a/content/html/content/src/HTMLMeterElement.h
+++ b/content/html/content/src/HTMLMeterElement.h
@@ -5,17 +5,16 @@
 
 #ifndef mozilla_dom_HTMLMeterElement_h
 #define mozilla_dom_HTMLMeterElement_h
 
 #include "mozilla/Attributes.h"
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValue.h"
 #include "nsAttrValueInlines.h"
-#include "nsEventStateManager.h"
 #include "nsAlgorithm.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace dom {
 
 class HTMLMeterElement MOZ_FINAL : public nsGenericHTMLElement
 {
--- a/content/html/content/src/HTMLProgressElement.h
+++ b/content/html/content/src/HTMLProgressElement.h
@@ -5,17 +5,16 @@
 
 #ifndef mozilla_dom_HTMLProgressElement_h
 #define mozilla_dom_HTMLProgressElement_h
 
 #include "mozilla/Attributes.h"
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValue.h"
 #include "nsAttrValueInlines.h"
-#include "nsEventStateManager.h"
 #include <algorithm>
 
 namespace mozilla {
 namespace dom {
 
 class HTMLProgressElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -2,16 +2,17 @@
 /* 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/EventDispatcher.h"
 #include "mozilla/EventListenerManager.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Likely.h"
 
 #include "nscore.h"
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValueInlines.h"
 #include "nsCOMPtr.h"
 #include "nsIAtom.h"
@@ -55,17 +56,16 @@
 #include "nsILayoutHistoryState.h"
 
 #include "nsHTMLParts.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/DirectionalityUtils.h"
 #include "nsString.h"
 #include "nsUnicharUtils.h"
 #include "nsGkAtoms.h"
-#include "nsEventStateManager.h"
 #include "nsIDOMEvent.h"
 #include "nsDOMCSSDeclaration.h"
 #include "nsITextControlFrame.h"
 #include "nsIForm.h"
 #include "nsIFormControl.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "mozilla/dom/HTMLFormElement.h"
 #include "nsFocusManager.h"
@@ -2706,17 +2706,17 @@ nsGenericHTMLElement::RegUnRegAccessKey(
   if (accessKey.IsEmpty()) {
     return;
   }
 
   // We have an access key, so get the ESM from the pres context.
   nsPresContext *presContext = GetPresContext();
 
   if (presContext) {
-    nsEventStateManager *esm = presContext->EventStateManager();
+    EventStateManager* esm = presContext->EventStateManager();
 
     // Register or unregister as appropriate.
     if (aDoReg) {
       esm->RegisterAccessKey(this, (uint32_t)accessKey.First());
     } else {
       esm->UnregisterAccessKey(this, (uint32_t)accessKey.First());
     }
   }
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -29,17 +29,17 @@
 #include "nsIDOMEventListener.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMXULCommandDispatcher.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMElementCSSInlineStyle.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsIDocument.h"
 #include "mozilla/EventListenerManager.h"
-#include "nsEventStateManager.h"
+#include "mozilla/EventStateManager.h"
 #include "nsFocusManager.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsIJSRuntimeService.h"
 #include "nsNameSpaceManager.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsIPresShell.h"
 #include "nsIPrincipal.h"
@@ -547,17 +547,17 @@ nsXULElement::IsFocusableInternal(int32_
   bool shouldFocus = false;
 
 #ifdef XP_MACOSX
   // on Mac, mouse interactions only focus the element if it's a list,
   // or if it's a remote target, since the remote target must handle
   // the focus.
   if (aWithMouse &&
       IsNonList(mNodeInfo) && 
-      !nsEventStateManager::IsRemoteTarget(this))
+      !EventStateManager::IsRemoteTarget(this))
   {
     return false;
   }
 #endif
 
   nsCOMPtr<nsIDOMXULControlElement> xulControl = do_QueryObject(this);
   if (xulControl) {
     // a disabled element cannot be focused and is not part of the tab order
--- a/content/xul/content/src/nsXULPopupListener.cpp
+++ b/content/xul/content/src/nsXULPopupListener.cpp
@@ -14,28 +14,28 @@
 #include "nsIDOMElement.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMDocumentXBL.h"
 #include "nsContentCID.h"
 #include "nsContentUtils.h"
 #include "nsXULPopupManager.h"
-#include "nsEventStateManager.h"
 #include "nsIScriptContext.h"
 #include "nsIDOMWindow.h"
 #include "nsIDOMXULDocument.h"
 #include "nsIDocument.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIPrincipal.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsLayoutUtils.h"
 #include "nsFrameManager.h"
 #include "nsHTMLReflowState.h"
 #include "nsIObjectLoadingContent.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 #include "mozilla/dom/EventTarget.h"
 #include "mozilla/dom/FragmentOrElement.h"
 
 // for event firing in context menus
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
@@ -137,17 +137,17 @@ nsXULPopupListener::HandleEvent(nsIDOMEv
   }
 
   nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);
   if (!targetContent) {
     return NS_OK;
   }
   if (targetContent->Tag() == nsGkAtoms::browser &&
       targetContent->IsXUL() &&
-      nsEventStateManager::IsRemoteTarget(targetContent)) {
+      EventStateManager::IsRemoteTarget(targetContent)) {
     return NS_OK;
   }
 
   bool preventDefault;
   mouseEvent->GetDefaultPrevented(&preventDefault);
   if (preventDefault && targetNode && mIsContext) {
     // Someone called preventDefault on a context menu.
     // Let's make sure they are allowed to do so.
@@ -268,17 +268,17 @@ nsXULPopupListener::FireFocusOnTargetCon
         fm->SetFocus(element, nsIFocusManager::FLAG_BYMOUSE |
                               nsIFocusManager::FLAG_NOSCROLL);
       } else if (!suppressBlur) {
         nsPIDOMWindow *window = doc->GetWindow();
         fm->ClearFocus(window);
       }
     }
 
-    nsEventStateManager *esm = context->EventStateManager();
+    EventStateManager* esm = context->EventStateManager();
     nsCOMPtr<nsIContent> focusableContent = do_QueryInterface(element);
     esm->SetContentState(focusableContent, NS_EVENT_STATE_ACTIVE);
   }
   return rv;
 }
 #endif
 
 // ClosePopup
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -10,16 +10,17 @@
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/Casting.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/TabChild.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/StartupTimeline.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/unused.h"
 #include "mozilla/VisualEventTracer.h"
 
 #ifdef MOZ_LOGGING
@@ -145,18 +146,16 @@
 #include "nsIJARChannel.h"
 
 #include "prlog.h"
 
 #include "nsISelectionDisplay.h"
 
 #include "nsIGlobalHistory2.h"
 
-#include "nsEventStateManager.h"
-
 #include "nsIFrame.h"
 #include "nsSubDocumentFrame.h"
 
 // for embedding
 #include "nsIWebBrowserChromeFocus.h"
 
 #if NS_PRINT_PREVIEW
 #include "nsIDocumentViewerPrint.h"
@@ -12777,17 +12776,17 @@ nsDocShell::OnLeaveLink()
   }
   return rv;
 }
 
 bool
 nsDocShell::ShouldBlockLoadingForBackButton()
 {
   if (!(mLoadType & LOAD_CMD_HISTORY) ||
-      nsEventStateManager::IsHandlingUserInput() ||
+      EventStateManager::IsHandlingUserInput() ||
       !Preferences::GetBool("accessibility.blockjsredirection")) {
     return false;
   }
 
   bool canGoForward = false;
   GetCanGoForward(&canGoForward);
   return canGoForward;
 }
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -11,17 +11,16 @@
 #include "nsDOMClassInfoID.h"
 #include "nsError.h"
 #include "nsIDOMEvent.h"
 #include "nsQueryContentEventResult.h"
 #include "CompositionStringSynthesizer.h"
 #include "nsGlobalWindow.h"
 #include "nsIDocument.h"
 #include "nsFocusManager.h"
-#include "nsEventStateManager.h"
 #include "nsFrameManager.h"
 #include "nsRefreshDriver.h"
 #include "mozilla/dom/Touch.h"
 #include "nsIObjectLoadingContent.h"
 #include "nsFrame.h"
 #include "mozilla/layers/ShadowLayers.h"
 
 #include "nsIScrollableFrame.h"
@@ -29,16 +28,17 @@
 #include "nsContentUtils.h"
 
 #include "nsIFrame.h"
 #include "nsIWidget.h"
 #include "nsCharsetSource.h"
 #include "nsJSEnvironment.h"
 #include "nsJSUtils.h"
 
+#include "mozilla/EventStateManager.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 
 #include "nsViewManager.h"
 
 #include "nsIDOMHTMLCanvasElement.h"
@@ -2771,17 +2771,17 @@ nsDOMWindowUtils::GetCursorType(int16_t 
 
   NS_ENSURE_ARG_POINTER(aCursor);
 
   nsIDocument* doc = GetDocument();
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   bool isSameDoc = false;
   do {
-    if (nsEventStateManager::sMouseOverDocument == doc) {
+    if (EventStateManager::sMouseOverDocument == doc) {
       isSameDoc = true;
       break;
     }
   } while ((doc = doc->GetParentDocument()));
 
   if (!isSameDoc) {
     *aCursor = eCursor_none;
     return NS_OK;
@@ -3587,17 +3587,17 @@ nsDOMWindowUtils::RemoveSheet(nsIURI *aS
 
 NS_IMETHODIMP
 nsDOMWindowUtils::GetIsHandlingUserInput(bool* aHandlingUserInput)
 {
   if (!nsContentUtils::IsCallerChrome()) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
-  *aHandlingUserInput = nsEventStateManager::IsHandlingUserInput();
+  *aHandlingUserInput = EventStateManager::IsHandlingUserInput();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::AllowScriptsToClose()
 {
   if (!nsContentUtils::IsCallerChrome()) {
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -17,17 +17,16 @@
 #include "nsIDOMDocument.h"
 #include "nsIDOMRange.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsLayoutUtils.h"
 #include "nsIPresShell.h"
 #include "nsFrameTraversal.h"
-#include "nsEventStateManager.h"
 #include "nsIWebNavigation.h"
 #include "nsCaret.h"
 #include "nsIBaseWindow.h"
 #include "nsViewManager.h"
 #include "nsFrameSelection.h"
 #include "mozilla/Selection.h"
 #include "nsXULPopupManager.h"
 #include "nsIScriptObjectPrincipal.h"
@@ -35,16 +34,17 @@
 #include "nsIObserverService.h"
 #include "nsIObjectFrame.h"
 #include "nsBindingManager.h"
 #include "nsStyleCoord.h"
 
 #include "mozilla/ContentEvents.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include <algorithm>
 
 #ifdef MOZ_XUL
 #include "nsIDOMXULTextboxElement.h"
@@ -3409,17 +3409,17 @@ public:
   {
     if (PointerUnlocker::sActiveUnlocker == this) {
       PointerUnlocker::sActiveUnlocker = nullptr;
     }
     NS_ENSURE_STATE(nsFocusManager::GetFocusManager());
     nsPIDOMWindow* focused =
       nsFocusManager::GetFocusManager()->GetFocusedWindow();
     nsCOMPtr<nsIDocument> pointerLockedDoc =
-      do_QueryReferent(nsEventStateManager::sPointerLockedDoc);
+      do_QueryReferent(EventStateManager::sPointerLockedDoc);
     if (pointerLockedDoc &&
         !nsContentUtils::IsInPointerLockContext(focused)) {
       nsIDocument::UnlockPointer();
     }
     return NS_OK;
   }
 
   static PointerUnlocker* sActiveUnlocker;
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -126,20 +126,20 @@
 #include "nsIDOMFileList.h"
 #include "nsIURIFixup.h"
 #ifndef DEBUG
 #include "nsIAppStartup.h"
 #include "nsToolkitCompsCID.h"
 #endif
 #include "nsCDefaultURIFixup.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "nsIObserverService.h"
 #include "nsFocusManager.h"
 #include "nsIXULWindow.h"
-#include "nsEventStateManager.h"
 #include "nsITimedChannel.h"
 #include "nsServiceManagerUtils.h"
 #ifdef MOZ_XUL
 #include "nsIDOMXULControlElement.h"
 #include "nsMenuPopupFrame.h"
 #endif
 #include "nsIDOMCustomEvent.h"
 #include "nsIFrameRequestCallback.h"
@@ -8335,24 +8335,25 @@ nsGlobalWindow::EnterModalState()
 
   if (!topWin) {
     NS_ERROR("Uh, EnterModalState() called w/o a reachable top window?");
     return;
   }
 
   // If there is an active ESM in this window, clear it. Otherwise, this can
   // cause a problem if a modal state is entered during a mouseup event.
-  nsEventStateManager* activeESM =
-    static_cast<nsEventStateManager*>(nsEventStateManager::GetActiveEventStateManager());
+  EventStateManager* activeESM =
+    static_cast<EventStateManager*>(
+      EventStateManager::GetActiveEventStateManager());
   if (activeESM && activeESM->GetPresContext()) {
     nsIPresShell* activeShell = activeESM->GetPresContext()->GetPresShell();
     if (activeShell && (
         nsContentUtils::ContentIsCrossDocDescendantOf(activeShell->GetDocument(), mDoc) ||
         nsContentUtils::ContentIsCrossDocDescendantOf(mDoc, activeShell->GetDocument()))) {
-      nsEventStateManager::ClearGlobalActiveContent(activeESM);
+      EventStateManager::ClearGlobalActiveContent(activeESM);
 
       activeShell->SetCapturingContent(nullptr, 0);
 
       if (activeShell) {
         nsRefPtr<nsFrameSelection> frameSelection = activeShell->FrameSelection();
         frameSelection->SetMouseDownState(false);
       }
     }
--- a/dom/events/ContentEventHandler.h
+++ b/dom/events/ContentEventHandler.h
@@ -14,17 +14,17 @@
 class nsPresContext;
 
 struct nsRect;
 
 namespace mozilla {
 
 /*
  * Query Content Event Handler
- *   ContentEventHandler is a helper class for nsEventStateManager.
+ *   ContentEventHandler is a helper class for EventStateManager.
  *   The platforms request some content informations, e.g., the selected text,
  *   the offset of the selected text and the text for specified range.
  *   This class answers to NS_QUERY_* events from actual contents.
  */
 
 class MOZ_STACK_CLASS ContentEventHandler
 {
 public:
--- a/dom/events/DataTransfer.h
+++ b/dom/events/DataTransfer.h
@@ -14,23 +14,25 @@
 #include "nsIDOMElement.h"
 #include "nsIDragService.h"
 #include "nsCycleCollectionParticipant.h"
 
 #include "nsAutoPtr.h"
 #include "nsDOMFile.h"
 #include "mozilla/Attributes.h"
 
-class nsEventStateManager;
 class nsINode;
 class nsITransferable;
 class nsISupportsArray;
 class nsILoadContext;
 
 namespace mozilla {
+
+class EventStateManager;
+
 namespace dom {
 
 class DOMStringList;
 class Element;
 template<typename T> class Optional;
 
 /**
  * TransferItem is used to hold data for a particular format. Each piece of
@@ -55,17 +57,17 @@ class DataTransfer MOZ_FINAL : public ns
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_DATATRANSFER_IID)
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIDOMDATATRANSFER
 
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DataTransfer)
 
-  friend class ::nsEventStateManager;
+  friend class mozilla::EventStateManager;
 
 protected:
 
   // hide the default constructor
   DataTransfer();
 
   // this constructor is used only by the Clone method to copy the fields as
   // needed to a new data transfer.
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -3,28 +3,28 @@
  * 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 "AccessCheck.h"
 #include "base/basictypes.h"
 #include "ipc/IPCMessageUtils.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/ContentEvents.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "nsContentUtils.h"
 #include "nsCOMPtr.h"
 #include "nsDeviceContext.h"
 #include "nsDOMEventTargetHelper.h"
 #include "nsError.h"
-#include "nsEventStateManager.h"
 #include "nsGlobalWindow.h"
 #include "nsIFrame.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIPresShell.h"
 #include "nsIScrollableFrame.h"
 #include "nsJSEnvironment.h"
 #include "nsLayoutUtils.h"
@@ -648,17 +648,17 @@ Event::GetEventPopupControlState(WidgetE
   // check for exceptions:
   PopupControlState abuse = openAbused;
 
   switch(aEvent->eventStructType) {
   case NS_EVENT :
     // For these following events only allow popups if they're
     // triggered while handling user input. See
     // nsPresShell::HandleEventInternal() for details.
-    if (nsEventStateManager::IsHandlingUserInput()) {
+    if (EventStateManager::IsHandlingUserInput()) {
       switch(aEvent->message) {
       case NS_FORM_SELECTED :
         if (PopupAllowedForEvent("select")) {
           abuse = openControlled;
         }
         break;
       case NS_FORM_CHANGE :
         if (PopupAllowedForEvent("change")) {
@@ -667,31 +667,31 @@ Event::GetEventPopupControlState(WidgetE
         break;
       }
     }
     break;
   case NS_GUI_EVENT :
     // For this following event only allow popups if it's triggered
     // while handling user input. See
     // nsPresShell::HandleEventInternal() for details.
-    if (nsEventStateManager::IsHandlingUserInput()) {
+    if (EventStateManager::IsHandlingUserInput()) {
       switch(aEvent->message) {
       case NS_FORM_INPUT :
         if (PopupAllowedForEvent("input")) {
           abuse = openControlled;
         }
         break;
       }
     }
     break;
   case NS_INPUT_EVENT :
     // For this following event only allow popups if it's triggered
     // while handling user input. See
     // nsPresShell::HandleEventInternal() for details.
-    if (nsEventStateManager::IsHandlingUserInput()) {
+    if (EventStateManager::IsHandlingUserInput()) {
       switch(aEvent->message) {
       case NS_FORM_CHANGE :
         if (PopupAllowedForEvent("change")) {
           abuse = openControlled;
         }
         break;
       case NS_XUL_COMMAND:
         abuse = openControlled;
@@ -773,17 +773,17 @@ Event::GetEventPopupControlState(WidgetE
         break;
       }
     }
     break;
   case NS_FORM_EVENT :
     // For these following events only allow popups if they're
     // triggered while handling user input. See
     // nsPresShell::HandleEventInternal() for details.
-    if (nsEventStateManager::IsHandlingUserInput()) {
+    if (EventStateManager::IsHandlingUserInput()) {
       switch(aEvent->message) {
       case NS_FORM_SUBMIT :
         if (PopupAllowedForEvent("submit")) {
           abuse = openControlled;
         }
         break;
       case NS_FORM_RESET :
         if (PopupAllowedForEvent("reset")) {
@@ -824,18 +824,18 @@ Event::Shutdown()
   }
 }
 
 nsIntPoint
 Event::GetScreenCoords(nsPresContext* aPresContext,
                        WidgetEvent* aEvent,
                        LayoutDeviceIntPoint aPoint)
 {
-  if (nsEventStateManager::sIsPointerLocked) {
-    return nsEventStateManager::sLastScreenPoint;
+  if (EventStateManager::sIsPointerLocked) {
+    return EventStateManager::sLastScreenPoint;
   }
 
   if (!aEvent || 
        (aEvent->eventStructType != NS_MOUSE_EVENT &&
         aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
         aEvent->eventStructType != NS_WHEEL_EVENT &&
         aEvent->eventStructType != NS_POINTER_EVENT &&
         aEvent->eventStructType != NS_TOUCH_EVENT &&
@@ -880,18 +880,18 @@ Event::GetPageCoords(nsPresContext* aPre
 
 // static
 CSSIntPoint
 Event::GetClientCoords(nsPresContext* aPresContext,
                        WidgetEvent* aEvent,
                        LayoutDeviceIntPoint aPoint,
                        CSSIntPoint aDefaultPoint)
 {
-  if (nsEventStateManager::sIsPointerLocked) {
-    return nsEventStateManager::sLastClientPoint;
+  if (EventStateManager::sIsPointerLocked) {
+    return EventStateManager::sLastClientPoint;
   }
 
   if (!aEvent ||
       (aEvent->eventStructType != NS_MOUSE_EVENT &&
        aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
        aEvent->eventStructType != NS_WHEEL_EVENT &&
        aEvent->eventStructType != NS_TOUCH_EVENT &&
        aEvent->eventStructType != NS_DRAG_EVENT &&
rename from dom/events/nsEventStateManager.cpp
rename to dom/events/EventStateManager.cpp
--- a/dom/events/nsEventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -1,31 +1,31 @@
 /* -*- 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 "mozilla/Attributes.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/MiscEvents.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/dom/UIEvent.h"
 
 #include "ContentEventHandler.h"
 #include "WheelHandlingHelper.h"
 
 #include "nsCOMPtr.h"
-#include "nsEventStateManager.h"
 #include "nsFocusManager.h"
 #include "nsIContent.h"
 #include "nsINodeInfo.h"
 #include "nsIDocument.h"
 #include "nsIFrame.h"
 #include "nsIWidget.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
@@ -95,44 +95,20 @@ using namespace mozilla;
 using namespace mozilla::dom;
 
 //#define DEBUG_DOCSHELL_FOCUS
 
 #define NS_USER_INTERACTION_INTERVAL 5000 // ms
 
 static const LayoutDeviceIntPoint kInvalidRefPoint = LayoutDeviceIntPoint(-1,-1);
 
-static uint32_t sESMInstanceCount = 0;
-int32_t nsEventStateManager::sUserInputEventDepth = 0;
-bool nsEventStateManager::sNormalLMouseEventInProcess = false;
-nsEventStateManager* nsEventStateManager::sActiveESM = nullptr;
-nsIDocument* nsEventStateManager::sMouseOverDocument = nullptr;
-nsWeakFrame nsEventStateManager::sLastDragOverFrame = nullptr;
-LayoutDeviceIntPoint nsEventStateManager::sLastRefPoint = kInvalidRefPoint;
-nsIntPoint nsEventStateManager::sLastScreenPoint = nsIntPoint(0, 0);
-LayoutDeviceIntPoint nsEventStateManager::sSynthCenteringPoint = kInvalidRefPoint;
-CSSIntPoint nsEventStateManager::sLastClientPoint = CSSIntPoint(0, 0);
-bool nsEventStateManager::sIsPointerLocked = false;
-// Reference to the pointer locked element.
-nsWeakPtr nsEventStateManager::sPointerLockedElement;
-// Reference to the document which requested pointer lock.
-nsWeakPtr nsEventStateManager::sPointerLockedDoc;
-nsCOMPtr<nsIContent> nsEventStateManager::sDragOverContent = nullptr;
-
 static uint32_t gMouseOrKeyboardEventCounter = 0;
 static nsITimer* gUserInteractionTimer = nullptr;
 static nsITimerCallback* gUserInteractionTimerCallback = nullptr;
 
-TimeStamp nsEventStateManager::sHandlingInputStart;
-
-nsEventStateManager::WheelPrefs*
-  nsEventStateManager::WheelPrefs::sInstance = nullptr;
-nsEventStateManager::DeltaAccumulator*
-  nsEventStateManager::DeltaAccumulator::sInstance = nullptr;
-
 static inline int32_t
 RoundDown(double aDouble)
 {
   return (aDouble > 0) ? static_cast<int32_t>(floor(aDouble)) :
                          static_cast<int32_t>(ceil(aDouble));
 }
 
 #ifdef DEBUG_DOCSHELL_FOCUS
@@ -220,17 +196,17 @@ nsUITimerCallback::Notify(nsITimer* aTim
     gMouseOrKeyboardEventCounter = 0;
     obs->NotifyObservers(nullptr, "user-interaction-inactive", nullptr);
     if (gUserInteractionTimer) {
       gUserInteractionTimer->Cancel();
       NS_RELEASE(gUserInteractionTimer);
     }
   } else {
     obs->NotifyObservers(nullptr, "user-interaction-active", nullptr);
-    nsEventStateManager::UpdateUserActivityTimer();
+    EventStateManager::UpdateUserActivityTimer();
   }
   mPreviousCount = gMouseOrKeyboardEventCounter;
   return NS_OK;
 }
 
 // mask values for ui.key.chromeAccess and ui.key.contentAccess
 #define NS_MODIFIER_SHIFT    1
 #define NS_MODIFIER_CONTROL  2
@@ -244,89 +220,122 @@ GetDocumentFromWindow(nsIDOMWindow *aWin
   nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aWindow);
   return win ? win->GetExtantDoc() : nullptr;
 }
 
 /******************************************************************/
 /* OverOutElementsWrapper                                         */
 /******************************************************************/
 
+OverOutElementsWrapper::OverOutElementsWrapper()
+  : mLastOverFrame(nullptr)
+{
+}
+
+OverOutElementsWrapper::~OverOutElementsWrapper()
+{
+}
+
 NS_IMPL_CYCLE_COLLECTION_3(OverOutElementsWrapper,
                            mLastOverElement,
                            mFirstOverEventElement,
                            mFirstOutEventElement)
 NS_IMPL_CYCLE_COLLECTING_ADDREF(OverOutElementsWrapper)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(OverOutElementsWrapper)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(OverOutElementsWrapper)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 /******************************************************************/
-
-/******************************************************************/
-/* nsEventStateManager                                            */
+/* mozilla::EventStateManager                                     */
 /******************************************************************/
 
-nsEventStateManager::nsEventStateManager()
-  : mLockCursor(0),
-    mPreLockPoint(0,0),
-    mCurrentTarget(nullptr),
+namespace mozilla {
+
+static uint32_t sESMInstanceCount = 0;
+
+int32_t EventStateManager::sUserInputEventDepth = 0;
+bool EventStateManager::sNormalLMouseEventInProcess = false;
+EventStateManager* EventStateManager::sActiveESM = nullptr;
+nsIDocument* EventStateManager::sMouseOverDocument = nullptr;
+nsWeakFrame EventStateManager::sLastDragOverFrame = nullptr;
+LayoutDeviceIntPoint EventStateManager::sLastRefPoint = kInvalidRefPoint;
+nsIntPoint EventStateManager::sLastScreenPoint = nsIntPoint(0, 0);
+LayoutDeviceIntPoint EventStateManager::sSynthCenteringPoint = kInvalidRefPoint;
+CSSIntPoint EventStateManager::sLastClientPoint = CSSIntPoint(0, 0);
+bool EventStateManager::sIsPointerLocked = false;
+// Reference to the pointer locked element.
+nsWeakPtr EventStateManager::sPointerLockedElement;
+// Reference to the document which requested pointer lock.
+nsWeakPtr EventStateManager::sPointerLockedDoc;
+nsCOMPtr<nsIContent> EventStateManager::sDragOverContent = nullptr;
+TimeStamp EventStateManager::sHandlingInputStart;
+
+EventStateManager::WheelPrefs*
+  EventStateManager::WheelPrefs::sInstance = nullptr;
+EventStateManager::DeltaAccumulator*
+  EventStateManager::DeltaAccumulator::sInstance = nullptr;
+
+EventStateManager::EventStateManager()
+  : mLockCursor(0)
+  , mPreLockPoint(0,0)
+  , mCurrentTarget(nullptr)
     // init d&d gesture state machine variables
-    mGestureDownPoint(0,0),
-    mPresContext(nullptr),
-    mLClickCount(0),
-    mMClickCount(0),
-    mRClickCount(0),
-    m_haveShutdown(false)
+  , mGestureDownPoint(0,0)
+  , mPresContext(nullptr)
+  , mLClickCount(0)
+  , mMClickCount(0)
+  , mRClickCount(0)
+  , m_haveShutdown(false)
 {
   if (sESMInstanceCount == 0) {
     gUserInteractionTimerCallback = new nsUITimerCallback();
     if (gUserInteractionTimerCallback)
       NS_ADDREF(gUserInteractionTimerCallback);
     UpdateUserActivityTimer();
   }
   ++sESMInstanceCount;
 }
 
 nsresult
-nsEventStateManager::UpdateUserActivityTimer(void)
+EventStateManager::UpdateUserActivityTimer()
 {
   if (!gUserInteractionTimerCallback)
     return NS_OK;
 
   if (!gUserInteractionTimer)
     CallCreateInstance("@mozilla.org/timer;1", &gUserInteractionTimer);
 
   if (gUserInteractionTimer) {
     gUserInteractionTimer->InitWithCallback(gUserInteractionTimerCallback,
                                             NS_USER_INTERACTION_INTERVAL,
                                             nsITimer::TYPE_ONE_SHOT);
   }
   return NS_OK;
 }
 
 nsresult
-nsEventStateManager::Init()
+EventStateManager::Init()
 {
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   if (!observerService)
     return NS_ERROR_FAILURE;
 
   observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
 
   if (sESMInstanceCount == 1) {
     Prefs::Init();
   }
 
   return NS_OK;
 }
 
-nsEventStateManager::~nsEventStateManager()
+EventStateManager::~EventStateManager()
 {
   if (sActiveESM == this) {
     sActiveESM = nullptr;
   }
   if (Prefs::ClickHoldContextMenu())
     KillClickHoldTimer();
 
   if (mDocument == sMouseOverDocument)
@@ -364,44 +373,44 @@ nsEventStateManager::~nsEventStateManage
     if (observerService) {
       observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
     }
   }
 
 }
 
 nsresult
-nsEventStateManager::Shutdown()
+EventStateManager::Shutdown()
 {
   m_haveShutdown = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsEventStateManager::Observe(nsISupports *aSubject,
-                             const char *aTopic,
-                             const char16_t *someData)
+EventStateManager::Observe(nsISupports* aSubject,
+                           const char* aTopic,
+                           const char16_t *someData)
 {
   if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
     Shutdown();
   }
 
   return NS_OK;
 }
 
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsEventStateManager)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EventStateManager)
    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
    NS_INTERFACE_MAP_ENTRY(nsIObserver)
    NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsEventStateManager)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsEventStateManager)
-
-NS_IMPL_CYCLE_COLLECTION_16(nsEventStateManager,
+NS_IMPL_CYCLE_COLLECTING_ADDREF(EventStateManager)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(EventStateManager)
+
+NS_IMPL_CYCLE_COLLECTION_16(EventStateManager,
                             mCurrentTargetContent,
                             mGestureDownContent,
                             mGestureDownFrameOwner,
                             mLastLeftMouseDownContent,
                             mLastLeftMouseDownContentParent,
                             mLastMiddleMouseDownContent,
                             mLastMiddleMouseDownContentParent,
                             mLastRightMouseDownContent,
@@ -410,20 +419,20 @@ NS_IMPL_CYCLE_COLLECTION_16(nsEventState
                             mHoverContent,
                             mURLTargetContent,
                             mMouseEnterLeaveHelper,
                             mPointersEnterLeaveHelper,
                             mDocument,
                             mAccessKeys)
 
 nsresult
-nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
-                                    WidgetEvent* aEvent,
-                                    nsIFrame* aTargetFrame,
-                                    nsEventStatus* aStatus)
+EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
+                                  WidgetEvent* aEvent,
+                                  nsIFrame* aTargetFrame,
+                                  nsEventStatus* aStatus)
 {
   NS_ENSURE_ARG_POINTER(aStatus);
   NS_ENSURE_ARG(aPresContext);
   if (!aEvent) {
     NS_ERROR("aEvent is null.  This should never happen.");
     return NS_ERROR_NULL_POINTER;
   }
 
@@ -763,17 +772,17 @@ nsEventStateManager::PreHandleEvent(nsPr
     }
     break;
   }
   return NS_OK;
 }
 
 // static
 int32_t
-nsEventStateManager::GetAccessModifierMaskFor(nsISupports* aDocShell)
+EventStateManager::GetAccessModifierMaskFor(nsISupports* aDocShell)
 {
   nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(aDocShell));
   if (!treeItem)
     return -1; // invalid modifier
 
   switch (treeItem->ItemType()) {
   case nsIDocShellTreeItem::typeChrome:
     return Prefs::ChromeAccessModifierMask();
@@ -832,18 +841,18 @@ IsAccessKeyTarget(nsIContent* aContent, 
     if (aContent->Tag() == nsGkAtoms::label)
       return true;
   }
 
   return false;
 }
 
 bool
-nsEventStateManager::ExecuteAccessKey(nsTArray<uint32_t>& aAccessCharCodes,
-                                      bool aIsTrustedEvent)
+EventStateManager::ExecuteAccessKey(nsTArray<uint32_t>& aAccessCharCodes,
+                                    bool aIsTrustedEvent)
 {
   int32_t count, start = -1;
   nsIContent* focusedContent = GetFocusedContent();
   if (focusedContent) {
     start = mAccessKeys.IndexOf(focusedContent);
     if (start == -1 && focusedContent->GetBindingParent())
       start = mAccessKeys.IndexOf(focusedContent->GetBindingParent());
   }
@@ -877,17 +886,17 @@ nsEventStateManager::ExecuteAccessKey(ns
         return true;
       }
     }
   }
   return false;
 }
 
 bool
-nsEventStateManager::GetAccessKeyLabelPrefix(nsAString& aPrefix)
+EventStateManager::GetAccessKeyLabelPrefix(nsAString& aPrefix)
 {
   aPrefix.Truncate();
   nsAutoString separator, modifierText;
   nsContentUtils::GetModifierSeparatorText(separator);
 
   nsCOMPtr<nsISupports> container = mPresContext->GetContainerWeak();
   int32_t modifierMask = GetAccessModifierMaskFor(container);
 
@@ -910,22 +919,22 @@ nsEventStateManager::GetAccessKeyLabelPr
   if (modifierMask & NS_MODIFIER_SHIFT) {
     nsContentUtils::GetShiftText(modifierText);
     aPrefix.Append(modifierText + separator);
   }
   return !aPrefix.IsEmpty();
 }
 
 void
-nsEventStateManager::HandleAccessKey(nsPresContext* aPresContext,
-                                     WidgetKeyboardEvent* aEvent,
-                                     nsEventStatus* aStatus,
-                                     nsIDocShellTreeItem* aBubbledFrom,
-                                     ProcessingAccessKeyState aAccessKeyState,
-                                     int32_t aModifierMask)
+EventStateManager::HandleAccessKey(nsPresContext* aPresContext,
+                                   WidgetKeyboardEvent* aEvent,
+                                   nsEventStatus* aStatus,
+                                   nsIDocShellTreeItem* aBubbledFrom,
+                                   ProcessingAccessKeyState aAccessKeyState,
+                                   int32_t aModifierMask)
 {
   nsCOMPtr<nsIDocShell> docShell = aPresContext->GetDocShell();
 
   // Alt or other accesskey modifier is down, we may need to do an accesskey
   if (mAccessKeys.Count() > 0 &&
       aModifierMask == GetAccessModifierMaskFor(docShell)) {
     // Someone registered an accesskey.  Find and activate it.
     nsAutoTArray<uint32_t, 10> accessCharCodes;
@@ -963,18 +972,18 @@ nsEventStateManager::HandleAccessKey(nsP
         // iframes, docshells in transition between documents, etc).
         if (!subPS) {
           // Oh, well.  Just move on to the next child
           continue;
         }
 
         nsPresContext *subPC = subPS->GetPresContext();
 
-        nsEventStateManager* esm =
-          static_cast<nsEventStateManager *>(subPC->EventStateManager());
+        EventStateManager* esm =
+          static_cast<EventStateManager*>(subPC->EventStateManager());
 
         if (esm)
           esm->HandleAccessKey(subPC, aEvent, aStatus, nullptr,
                                eAccessKeyProcessingDown, aModifierMask);
 
         if (nsEventStatus_eConsumeNoDefault == *aStatus)
           break;
       }
@@ -993,30 +1002,30 @@ nsEventStateManager::HandleAccessKey(nsP
     nsCOMPtr<nsIDocShell> parentDS = do_QueryInterface(parentShellItem);
     if (parentDS) {
       nsCOMPtr<nsIPresShell> parentPS = parentDS->GetPresShell();
       NS_ASSERTION(parentPS, "Our PresShell exists but the parent's does not?");
 
       nsPresContext *parentPC = parentPS->GetPresContext();
       NS_ASSERTION(parentPC, "PresShell without PresContext");
 
-      nsEventStateManager* esm =
-        static_cast<nsEventStateManager *>(parentPC->EventStateManager());
+      EventStateManager* esm =
+        static_cast<EventStateManager*>(parentPC->EventStateManager());
 
       if (esm)
         esm->HandleAccessKey(parentPC, aEvent, aStatus, docShell,
                              eAccessKeyProcessingUp, aModifierMask);
     }
   }// if end. bubble up process
 }// end of HandleAccessKey
 
 bool
-nsEventStateManager::DispatchCrossProcessEvent(WidgetEvent* aEvent,
-                                               nsFrameLoader* aFrameLoader,
-                                               nsEventStatus *aStatus) {
+EventStateManager::DispatchCrossProcessEvent(WidgetEvent* aEvent,
+                                             nsFrameLoader* aFrameLoader,
+                                             nsEventStatus *aStatus) {
   PBrowserParent* remoteBrowser = aFrameLoader->GetRemoteBrowser();
   TabParent* remote = static_cast<TabParent*>(remoteBrowser);
   if (!remote) {
     return false;
   }
 
   switch (aEvent->eventStructType) {
   case NS_MOUSE_EVENT: {
@@ -1036,17 +1045,17 @@ nsEventStateManager::DispatchCrossProces
   }
   default: {
     MOZ_CRASH("Attempt to send non-whitelisted event?");
   }
   }
 }
 
 bool
-nsEventStateManager::IsRemoteTarget(nsIContent* target) {
+EventStateManager::IsRemoteTarget(nsIContent* target) {
   if (!target) {
     return false;
   }
 
   // <browser/iframe remote=true> from XUL
   if ((target->Tag() == nsGkAtoms::browser ||
        target->Tag() == nsGkAtoms::iframe) &&
       target->IsXUL() &&
@@ -1060,18 +1069,18 @@ nsEventStateManager::IsRemoteTarget(nsIC
   if (browserFrame && browserFrame->GetReallyIsBrowserOrApp()) {
     return !!TabParent::GetFrom(target);
   }
 
   return false;
 }
 
 /*static*/ LayoutDeviceIntPoint
-nsEventStateManager::GetChildProcessOffset(nsFrameLoader* aFrameLoader,
-                                           const WidgetEvent& aEvent)
+EventStateManager::GetChildProcessOffset(nsFrameLoader* aFrameLoader,
+                                         const WidgetEvent& aEvent)
 {
   // The "toplevel widget" in child processes is always at position
   // 0,0.  Map the event coordinates to match that.
   nsIFrame* targetFrame = aFrameLoader->GetPrimaryFrameOfOwningContent();
   if (!targetFrame) {
     return LayoutDeviceIntPoint();
   }
   nsPresContext* presContext = targetFrame->PresContext();
@@ -1110,19 +1119,19 @@ CrossProcessSafeEvent(const WidgetEvent&
       return false;
     }
   default:
     return false;
   }
 }
 
 bool
-nsEventStateManager::HandleCrossProcessEvent(WidgetEvent* aEvent,
-                                             nsIFrame* aTargetFrame,
-                                             nsEventStatus *aStatus) {
+EventStateManager::HandleCrossProcessEvent(WidgetEvent* aEvent,
+                                           nsIFrame* aTargetFrame,
+                                           nsEventStatus *aStatus) {
   if (*aStatus == nsEventStatus_eConsumeNoDefault ||
       aEvent->mFlags.mNoCrossProcessBoundaryForwarding ||
       !CrossProcessSafeEvent(*aEvent)) {
     return false;
   }
 
   // Collect the remote event targets we're going to forward this
   // event to.
@@ -1201,19 +1210,19 @@ nsEventStateManager::HandleCrossProcessE
 //
 // CreateClickHoldTimer
 //
 // Fire off a timer for determining if the user wants click-hold. This timer
 // is a one-shot that will be cancelled when the user moves enough to fire
 // a drag.
 //
 void
-nsEventStateManager::CreateClickHoldTimer(nsPresContext* inPresContext,
-                                          nsIFrame* inDownFrame,
-                                          WidgetGUIEvent* inMouseDownEvent)
+EventStateManager::CreateClickHoldTimer(nsPresContext* inPresContext,
+                                        nsIFrame* inDownFrame,
+                                        WidgetGUIEvent* inMouseDownEvent)
 {
   if (!inMouseDownEvent->mFlags.mIsTrusted || IsRemoteTarget(mGestureDownContent))
     return;
 
   // just to be anal (er, safe)
   if (mClickHoldTimer) {
     mClickHoldTimer->Cancel();
     mClickHoldTimer = nullptr;
@@ -1244,34 +1253,34 @@ nsEventStateManager::CreateClickHoldTime
 
 
 //
 // KillClickHoldTimer
 //
 // Stop the timer that would show the context menu dead in its tracks
 //
 void
-nsEventStateManager::KillClickHoldTimer()
+EventStateManager::KillClickHoldTimer()
 {
   if (mClickHoldTimer) {
     mClickHoldTimer->Cancel();
     mClickHoldTimer = nullptr;
   }
 }
 
 
 //
 // sClickHoldCallback
 //
 // This fires after the mouse has been down for a certain length of time.
 //
 void
-nsEventStateManager::sClickHoldCallback(nsITimer *aTimer, void* aESM)
+EventStateManager::sClickHoldCallback(nsITimer* aTimer, void* aESM)
 {
-  nsRefPtr<nsEventStateManager> self = static_cast<nsEventStateManager*>(aESM);
+  nsRefPtr<EventStateManager> self = static_cast<EventStateManager*>(aESM);
   if (self) {
     self->FireContextClick();
   }
 
   // NOTE: |aTimer| and |self->mAutoHideTimer| are invalid after calling ClosePopup();
 
 } // sAutoHideCallback
 
@@ -1286,17 +1295,17 @@ nsEventStateManager::sClickHoldCallback(
 //
 // After the event fires, check if PreventDefault() has been set on the event which
 // means that someone either ate the event or put up a context menu. This is our cue
 // to stop tracking the drag gesture. If we always did this, draggable items w/out
 // a context menu wouldn't be draggable after a certain length of time, which is
 // _not_ what we want.
 //
 void
-nsEventStateManager::FireContextClick()
+EventStateManager::FireContextClick()
 {
   if (!mGestureDownContent || !mPresContext) {
     return;
   }
 
 #ifdef XP_MACOSX
   // Hack to ensure that we don't show a context menu when the user
   // let go of the mouse after a long cpu-hogging operation prevented
@@ -1412,19 +1421,19 @@ nsEventStateManager::FireContextClick()
 //
 // We also use this to track click-hold context menus. When the mouse goes down,
 // fire off a short timer. If the timer goes off and we have yet to fire the
 // drag gesture (ie, the mouse hasn't moved a certain distance), then we can
 // assume the user wants a click-hold, so fire a context-click event. We only
 // want to cancel the drag gesture if the context-click event is handled.
 //
 void
-nsEventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext,
-                                              WidgetMouseEvent* inDownEvent,
-                                              nsIFrame* inDownFrame)
+EventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext,
+                                            WidgetMouseEvent* inDownEvent,
+                                            nsIFrame* inDownFrame)
 {
   if (!inDownEvent->widget)
     return;
 
   // Note that |inDownEvent| could be either a mouse down event or a
   // synthesized mouse move event.
   mGestureDownPoint = inDownEvent->refPoint +
     LayoutDeviceIntPoint::FromUntyped(inDownEvent->widget->WidgetToScreenOffset());
@@ -1445,24 +1454,24 @@ nsEventStateManager::BeginTrackingDragGe
 
 //
 // StopTrackingDragGesture
 //
 // Record that the mouse has gone back up so that we should leave the TRACKING
 // state of d&d gesture tracker and return to the START state.
 //
 void
-nsEventStateManager::StopTrackingDragGesture()
+EventStateManager::StopTrackingDragGesture()
 {
   mGestureDownContent = nullptr;
   mGestureDownFrameOwner = nullptr;
 }
 
 void
-nsEventStateManager::FillInEventFromGestureDown(WidgetMouseEvent* aEvent)
+EventStateManager::FillInEventFromGestureDown(WidgetMouseEvent* aEvent)
 {
   NS_ASSERTION(aEvent->widget == mCurrentTarget->GetNearestWidget(),
                "Incorrect widget in event");
 
   // Set the coordinates in the new event to the coordinates of
   // the old event, adjusted for the fact that the widget might be
   // different
   aEvent->refPoint = mGestureDownPoint -
@@ -1473,18 +1482,18 @@ nsEventStateManager::FillInEventFromGest
 
 //
 // GenerateDragGesture
 //
 // If we're in the TRACKING state of the d&d gesture tracker, check the current position
 // of the mouse in relation to the old one. If we've moved a sufficient amount from
 // the mouse down, then fire off a drag gesture event.
 void
-nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
-                                         WidgetMouseEvent* aEvent)
+EventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
+                                       WidgetMouseEvent* aEvent)
 {
   NS_ASSERTION(aPresContext, "This shouldn't happen.");
   if (IsTrackingDragGesture()) {
     mCurrentTarget = mGestureDownFrameOwner->GetPrimaryFrame();
 
     if (!mCurrentTarget) {
       StopTrackingDragGesture();
       return;
@@ -1636,21 +1645,21 @@ nsEventStateManager::GenerateDragGesture
 
     // Now flush all pending notifications, for better responsiveness
     // while dragging.
     FlushPendingEvents(aPresContext);
   }
 } // GenerateDragGesture
 
 void
-nsEventStateManager::DetermineDragTarget(nsPIDOMWindow* aWindow,
-                                         nsIContent* aSelectionTarget,
-                                         DataTransfer* aDataTransfer,
-                                         nsISelection** aSelection,
-                                         nsIContent** aTargetNode)
+EventStateManager::DetermineDragTarget(nsPIDOMWindow* aWindow,
+                                       nsIContent* aSelectionTarget,
+                                       DataTransfer* aDataTransfer,
+                                       nsISelection** aSelection,
+                                       nsIContent** aTargetNode)
 {
   *aTargetNode = nullptr;
 
   // GetDragData determines if a selection, link or image in the content
   // should be dragged, and places the data associated with the drag in the
   // data transfer.
   // mGestureDownContent is the node where the mousedown event for the drag
   // occurred, and aSelectionTarget is the node to use when a selection is used
@@ -1718,21 +1727,21 @@ nsEventStateManager::DetermineDragTarget
     if (dragContent != originalDragContent)
       aDataTransfer->ClearAll();
     *aTargetNode = dragContent;
     NS_ADDREF(*aTargetNode);
   }
 }
 
 bool
-nsEventStateManager::DoDefaultDragStart(nsPresContext* aPresContext,
-                                        WidgetDragEvent* aDragEvent,
-                                        DataTransfer* aDataTransfer,
-                                        nsIContent* aDragTarget,
-                                        nsISelection* aSelection)
+EventStateManager::DoDefaultDragStart(nsPresContext* aPresContext,
+                                      WidgetDragEvent* aDragEvent,
+                                      DataTransfer* aDataTransfer,
+                                      nsIContent* aDragTarget,
+                                      nsISelection* aSelection)
 {
   nsCOMPtr<nsIDragService> dragService =
     do_GetService("@mozilla.org/widget/dragservice;1");
   if (!dragService)
     return false;
 
   // Default handling for the draggesture/dragstart event.
   //
@@ -1831,17 +1840,17 @@ nsEventStateManager::DoDefaultDragStart(
                                             imageY, domDragEvent,
                                             aDataTransfer);
   }
 
   return true;
 }
 
 nsresult
-nsEventStateManager::GetMarkupDocumentViewer(nsIMarkupDocumentViewer** aMv)
+EventStateManager::GetMarkupDocumentViewer(nsIMarkupDocumentViewer** aMv)
 {
   *aMv = nullptr;
 
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   if(!fm) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDOMWindow> focusedWindow;
   fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
@@ -1876,17 +1885,17 @@ nsEventStateManager::GetMarkupDocumentVi
 
   *aMv = mv;
   NS_IF_ADDREF(*aMv);
 
   return NS_OK;
 }
 
 nsresult
-nsEventStateManager::ChangeTextSize(int32_t change)
+EventStateManager::ChangeTextSize(int32_t change)
 {
   nsCOMPtr<nsIMarkupDocumentViewer> mv;
   nsresult rv = GetMarkupDocumentViewer(getter_AddRefs(mv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   float textzoom;
   float zoomMin = ((float)Preferences::GetInt("zoom.minPercent", 50)) / 100;
   float zoomMax = ((float)Preferences::GetInt("zoom.maxPercent", 300)) / 100;
@@ -1897,17 +1906,17 @@ nsEventStateManager::ChangeTextSize(int3
   else if (textzoom > zoomMax)
     textzoom = zoomMax;
   mv->SetTextZoom(textzoom);
 
   return NS_OK;
 }
 
 nsresult
-nsEventStateManager::ChangeFullZoom(int32_t change)
+EventStateManager::ChangeFullZoom(int32_t change)
 {
   nsCOMPtr<nsIMarkupDocumentViewer> mv;
   nsresult rv = GetMarkupDocumentViewer(getter_AddRefs(mv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   float fullzoom;
   float zoomMin = ((float)Preferences::GetInt("zoom.minPercent", 50)) / 100;
   float zoomMax = ((float)Preferences::GetInt("zoom.maxPercent", 300)) / 100;
@@ -1918,34 +1927,34 @@ nsEventStateManager::ChangeFullZoom(int3
   else if (fullzoom > zoomMax)
     fullzoom = zoomMax;
   mv->SetFullZoom(fullzoom);
 
   return NS_OK;
 }
 
 void
-nsEventStateManager::DoScrollHistory(int32_t direction)
+EventStateManager::DoScrollHistory(int32_t direction)
 {
   nsCOMPtr<nsISupports> pcContainer(mPresContext->GetContainerWeak());
   if (pcContainer) {
     nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(pcContainer));
     if (webNav) {
       // positive direction to go back one step, nonpositive to go forward
       if (direction > 0)
         webNav->GoBack();
       else
         webNav->GoForward();
     }
   }
 }
 
 void
-nsEventStateManager::DoScrollZoom(nsIFrame *aTargetFrame,
-                                  int32_t adjustment)
+EventStateManager::DoScrollZoom(nsIFrame* aTargetFrame,
+                                int32_t adjustment)
 {
   // Exclude form controls and content in chrome docshells.
   nsIContent *content = aTargetFrame->GetContent();
   if (content &&
       !content->IsNodeOfType(nsINode::eHTML_FORM_CONTROL) &&
       !nsContentUtils::IsInChromeDocshell(content->OwnerDoc()))
     {
       // positive adjustment to decrease zoom, negative to increase
@@ -1968,19 +1977,19 @@ GetParentFrameToScroll(nsIFrame* aFrame)
   if (aFrame->StyleDisplay()->mPosition == NS_STYLE_POSITION_FIXED &&
       nsLayoutUtils::IsReallyFixedPos(aFrame))
     return aFrame->PresContext()->GetPresShell()->GetRootScrollFrame();
 
   return aFrame->GetParent();
 }
 
 void
-nsEventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
-                                                     WidgetWheelEvent* aEvent,
-                                                     nsEventStatus* aStatus)
+EventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
+                                                   WidgetWheelEvent* aEvent,
+                                                   nsEventStatus* aStatus)
 {
   MOZ_ASSERT(aEvent);
   MOZ_ASSERT(aStatus);
 
   if (!aTargetFrame || *aStatus == nsEventStatus_eConsumeNoDefault) {
     return;
   }
 
@@ -2093,21 +2102,21 @@ nsEventStateManager::DispatchLegacyMouse
     *aStatus = nsEventStatus_eConsumeNoDefault;
     aEvent->mFlags.mDefaultPrevented = true;
     aEvent->mFlags.mDefaultPreventedByContent |=
       stateY.mDefaultPreventedByContent || stateX.mDefaultPreventedByContent;
   }
 }
 
 void
-nsEventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
-                                         WidgetWheelEvent* aEvent,
-                                         EventState& aState,
-                                         int32_t aDelta,
-                                         DeltaDirection aDeltaDirection)
+EventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
+                                       WidgetWheelEvent* aEvent,
+                                       EventState& aState,
+                                       int32_t aDelta,
+                                       DeltaDirection aDeltaDirection)
 {
   nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent();
   if (!targetContent)
     targetContent = GetFocusedContent();
   if (!targetContent)
     return;
 
   while (targetContent->IsNodeOfType(nsINode::eTEXT)) {
@@ -2131,21 +2140,21 @@ nsEventStateManager::SendLineScrollEvent
   EventDispatcher::Dispatch(targetContent, aTargetFrame->PresContext(),
                             &event, nullptr, &status);
   aState.mDefaultPrevented =
     event.mFlags.mDefaultPrevented || status == nsEventStatus_eConsumeNoDefault;
   aState.mDefaultPreventedByContent = event.mFlags.mDefaultPreventedByContent;
 }
 
 void
-nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
-                                          WidgetWheelEvent* aEvent,
-                                          EventState& aState,
-                                          int32_t aPixelDelta,
-                                          DeltaDirection aDeltaDirection)
+EventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
+                                        WidgetWheelEvent* aEvent,
+                                        EventState& aState,
+                                        int32_t aPixelDelta,
+                                        DeltaDirection aDeltaDirection)
 {
   nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent();
   if (!targetContent) {
     targetContent = GetFocusedContent();
     if (!targetContent)
       return;
   }
 
@@ -2170,33 +2179,33 @@ nsEventStateManager::SendPixelScrollEven
   EventDispatcher::Dispatch(targetContent, aTargetFrame->PresContext(),
                             &event, nullptr, &status);
   aState.mDefaultPrevented =
     event.mFlags.mDefaultPrevented || status == nsEventStatus_eConsumeNoDefault;
   aState.mDefaultPreventedByContent = event.mFlags.mDefaultPreventedByContent;
 }
 
 nsIScrollableFrame*
-nsEventStateManager::ComputeScrollTarget(nsIFrame* aTargetFrame,
-                                         WidgetWheelEvent* aEvent,
-                                         ComputeScrollTargetOptions aOptions)
+EventStateManager::ComputeScrollTarget(nsIFrame* aTargetFrame,
+                                       WidgetWheelEvent* aEvent,
+                                       ComputeScrollTargetOptions aOptions)
 {
   return ComputeScrollTarget(aTargetFrame, aEvent->deltaX, aEvent->deltaY,
                              aEvent, aOptions);
 }
 
 // Overload ComputeScrollTarget method to allow passing "test" dx and dy when looking
 // for which scrollbarowners to activate when two finger down on trackpad
 // and before any actual motion
 nsIScrollableFrame*
-nsEventStateManager::ComputeScrollTarget(nsIFrame* aTargetFrame,
-                                         double aDirectionX,
-                                         double aDirectionY,
-                                         WidgetWheelEvent* aEvent,
-                                         ComputeScrollTargetOptions aOptions)
+EventStateManager::ComputeScrollTarget(nsIFrame* aTargetFrame,
+                                       double aDirectionX,
+                                       double aDirectionY,
+                                       WidgetWheelEvent* aEvent,
+                                       ComputeScrollTargetOptions aOptions)
 {
   if (aOptions & PREFER_MOUSE_WHEEL_TRANSACTION) {
     // If the user recently scrolled with the mousewheel, then they probably
     // want to scroll the same view as before instead of the view under the
     // cursor.  WheelTransaction tracks the frame currently being
     // scrolled with the mousewheel. We consider the transaction ended when the
     // mouse moves more than "mousewheel.transaction.ignoremovedelay"
     // milliseconds after the last scroll operation, or any time the mouse moves
@@ -2282,19 +2291,19 @@ nsEventStateManager::ComputeScrollTarget
   nsIFrame* newFrame = nsLayoutUtils::GetCrossDocParentFrame(
       aTargetFrame->PresContext()->FrameManager()->GetRootFrame());
   aOptions =
     static_cast<ComputeScrollTargetOptions>(aOptions & ~START_FROM_PARENT);
   return newFrame ? ComputeScrollTarget(newFrame, aEvent, aOptions) : nullptr;
 }
 
 nsSize
-nsEventStateManager::GetScrollAmount(nsPresContext* aPresContext,
-                                     WidgetWheelEvent* aEvent,
-                                     nsIScrollableFrame* aScrollableFrame)
+EventStateManager::GetScrollAmount(nsPresContext* aPresContext,
+                                   WidgetWheelEvent* aEvent,
+                                   nsIScrollableFrame* aScrollableFrame)
 {
   MOZ_ASSERT(aPresContext);
   MOZ_ASSERT(aEvent);
 
   bool isPage = (aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_PAGE);
   if (aScrollableFrame) {
     return isPage ? aScrollableFrame->GetPageScrollAmount() :
                     aScrollableFrame->GetLineScrollAmount();
@@ -2313,18 +2322,18 @@ nsEventStateManager::GetScrollAmount(nsP
   nsRefPtr<nsFontMetrics> fm;
   nsLayoutUtils::GetFontMetricsForFrame(rootFrame, getter_AddRefs(fm),
     nsLayoutUtils::FontSizeInflationFor(rootFrame));
   NS_ENSURE_TRUE(fm, nsSize(0, 0));
   return nsSize(fm->AveCharWidth(), fm->MaxHeight());
 }
 
 void
-nsEventStateManager::DoScrollText(nsIScrollableFrame* aScrollableFrame,
-                                  WidgetWheelEvent* aEvent)
+EventStateManager::DoScrollText(nsIScrollableFrame* aScrollableFrame,
+                                WidgetWheelEvent* aEvent)
 {
   MOZ_ASSERT(aScrollableFrame);
   MOZ_ASSERT(aEvent);
 
   nsIFrame* scrollFrame = do_QueryFrame(aScrollableFrame);
   MOZ_ASSERT(scrollFrame);
   nsWeakFrame scrollFrameWeak(scrollFrame);
 
@@ -2473,18 +2482,18 @@ nsEventStateManager::DoScrollText(nsIScr
   NS_ASSERTION(aEvent->overflowDeltaY == 0 ||
     (aEvent->overflowDeltaY > 0) == (aEvent->deltaY > 0),
     "The sign of overflowDeltaY is different from the scroll direction");
 
   WheelPrefs::GetInstance()->CancelApplyingUserPrefsFromOverflowDelta(aEvent);
 }
 
 void
-nsEventStateManager::DecideGestureEvent(WidgetGestureNotifyEvent* aEvent,
-                                        nsIFrame* targetFrame)
+EventStateManager::DecideGestureEvent(WidgetGestureNotifyEvent* aEvent,
+                                      nsIFrame* targetFrame)
 {
 
   NS_ASSERTION(aEvent->message == NS_GESTURENOTIFY_EVENT_START,
                "DecideGestureEvent called with a non-gesture event");
 
   /* Check the ancestor tree to decide if any frame is willing* to receive
    * a MozPixelScroll event. If that's the case, the current touch gesture
    * will be used as a pan gesture; otherwise it will be a regular
@@ -2592,20 +2601,20 @@ NodeAllowsClickThrough(nsINode* aNode)
     }
     aNode = nsContentUtils::GetCrossDocParentNode(aNode);
   }
   return true;
 }
 #endif
 
 nsresult
-nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
-                                     WidgetEvent* aEvent,
-                                     nsIFrame* aTargetFrame,
-                                     nsEventStatus* aStatus)
+EventStateManager::PostHandleEvent(nsPresContext* aPresContext,
+                                   WidgetEvent* aEvent,
+                                   nsIFrame* aTargetFrame,
+                                   nsEventStatus* aStatus)
 {
   NS_ENSURE_ARG(aPresContext);
   NS_ENSURE_ARG_POINTER(aStatus);
 
   bool dispatchedToContentProcess = HandleCrossProcessEvent(aEvent,
                                                             aTargetFrame,
                                                             aStatus);
 
@@ -3151,77 +3160,77 @@ nsEventStateManager::PostHandleEvent(nsP
   //Reset target frame to null to avoid mistargeting after reentrant event
   mCurrentTarget = nullptr;
   mCurrentTargetContent = nullptr;
 
   return ret;
 }
 
 bool
-nsEventStateManager::RemoteQueryContentEvent(WidgetEvent* aEvent)
+EventStateManager::RemoteQueryContentEvent(WidgetEvent* aEvent)
 {
   WidgetQueryContentEvent* queryEvent = aEvent->AsQueryContentEvent();
   if (!IsTargetCrossProcess(queryEvent)) {
     return false;
   }
   // Will not be handled locally, remote the event
   GetCrossProcessTarget()->HandleQueryContentEvent(*queryEvent);
   return true;
 }
 
 TabParent*
-nsEventStateManager::GetCrossProcessTarget()
+EventStateManager::GetCrossProcessTarget()
 {
   return TabParent::GetIMETabParent();
 }
 
 bool
-nsEventStateManager::IsTargetCrossProcess(WidgetGUIEvent* aEvent)
+EventStateManager::IsTargetCrossProcess(WidgetGUIEvent* aEvent)
 {
   // Check to see if there is a focused, editable content in chrome,
   // in that case, do not forward IME events to content
   nsIContent *focusedContent = GetFocusedContent();
   if (focusedContent && focusedContent->IsEditable())
     return false;
   return TabParent::GetIMETabParent() != nullptr;
 }
 
 void
-nsEventStateManager::NotifyDestroyPresContext(nsPresContext* aPresContext)
+EventStateManager::NotifyDestroyPresContext(nsPresContext* aPresContext)
 {
   IMEStateManager::OnDestroyPresContext(aPresContext);
   if (mHoverContent) {
     // Bug 70855: Presentation is going away, possibly for a reframe.
     // Reset the hover state so that if we're recreating the presentation,
     // we won't have the old hover state still set in the new presentation,
     // as if the new presentation is resized, a new element may be hovered. 
     SetContentState(nullptr, NS_EVENT_STATE_HOVER);
   }
   mPointersEnterLeaveHelper.Clear();
 }
 
 void
-nsEventStateManager::SetPresContext(nsPresContext* aPresContext)
+EventStateManager::SetPresContext(nsPresContext* aPresContext)
 {
   mPresContext = aPresContext;
 }
 
 void
-nsEventStateManager::ClearFrameRefs(nsIFrame* aFrame)
+EventStateManager::ClearFrameRefs(nsIFrame* aFrame)
 {
   if (aFrame && aFrame == mCurrentTarget) {
     mCurrentTargetContent = aFrame->GetContent();
   }
 }
 
 void
-nsEventStateManager::UpdateCursor(nsPresContext* aPresContext,
-                                  WidgetEvent* aEvent,
-                                  nsIFrame* aTargetFrame,
-                                  nsEventStatus* aStatus)
+EventStateManager::UpdateCursor(nsPresContext* aPresContext,
+                                WidgetEvent* aEvent,
+                                nsIFrame* aTargetFrame,
+                                nsEventStatus* aStatus)
 {
   if (aTargetFrame && IsRemoteTarget(aTargetFrame->GetContent())) {
     return;
   }
 
   int32_t cursor = NS_STYLE_CURSOR_DEFAULT;
   imgIContainer* container = nullptr;
   bool haveHotspot = false;
@@ -3268,20 +3277,20 @@ nsEventStateManager::UpdateCursor(nsPres
   }
 
   if (mLockCursor || NS_STYLE_CURSOR_AUTO != cursor) {
     *aStatus = nsEventStatus_eConsumeDoDefault;
   }
 }
 
 nsresult
-nsEventStateManager::SetCursor(int32_t aCursor, imgIContainer* aContainer,
-                               bool aHaveHotspot,
-                               float aHotspotX, float aHotspotY,
-                               nsIWidget* aWidget, bool aLockCursor)
+EventStateManager::SetCursor(int32_t aCursor, imgIContainer* aContainer,
+                             bool aHaveHotspot,
+                             float aHotspotX, float aHotspotY,
+                             nsIWidget* aWidget, bool aLockCursor)
 {
   EnsureDocument(mPresContext);
   NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
   sMouseOverDocument = mDocument.get();
 
   nsCursor c;
 
   NS_ENSURE_TRUE(aWidget, NS_ERROR_FAILURE);
@@ -3447,20 +3456,20 @@ nsEventStateManager::SetCursor(int32_t a
   }
 
   if (NS_FAILED(rv))
     aWidget->SetCursor(c);
 
   return NS_OK;
 }
 
-class MOZ_STACK_CLASS nsESMEventCB : public EventDispatchingCallback
+class MOZ_STACK_CLASS ESMEventCB : public EventDispatchingCallback
 {
 public:
-  nsESMEventCB(nsIContent* aTarget) : mTarget(aTarget) {}
+  ESMEventCB(nsIContent* aTarget) : mTarget(aTarget) {}
 
   virtual void HandleEvent(EventChainPostVisitor& aVisitor)
   {
     if (aVisitor.mPresContext) {
       nsIFrame* frame = aVisitor.mPresContext->GetPrimaryFrameFor(mTarget);
       if (frame) {
         frame->HandleEvent(aVisitor.mPresContext,
                            aVisitor.mEvent->AsGUIEvent(),
@@ -3468,44 +3477,44 @@ public:
       }
     }
   }
 
   nsCOMPtr<nsIContent> mTarget;
 };
 
 /*static*/ bool
-nsEventStateManager::IsHandlingUserInput()
+EventStateManager::IsHandlingUserInput()
 {
   if (sUserInputEventDepth <= 0) {
     return false;
   }
 
   TimeDuration timeout = nsContentUtils::HandlingUserInputTimeout();
   return timeout <= TimeDuration(0) ||
          (TimeStamp::Now() - sHandlingInputStart) <= timeout;
 }
 
 nsIFrame*
-nsEventStateManager::DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent,
-                                                 uint32_t aMessage,
-                                                 nsIContent* aTargetContent,
-                                                 nsIContent* aRelatedContent)
+EventStateManager::DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent,
+                                               uint32_t aMessage,
+                                               nsIContent* aTargetContent,
+                                               nsIContent* aRelatedContent)
 {
   // http://dvcs.w3.org/hg/webevents/raw-file/default/mouse-lock.html#methods
   // "[When the mouse is locked on an element...e]vents that require the concept
   // of a mouse cursor must not be dispatched (for example: mouseover, mouseout).
   if (sIsPointerLocked &&
       (aMessage == NS_MOUSELEAVE ||
        aMessage == NS_MOUSEENTER ||
        aMessage == NS_MOUSE_ENTER_SYNTH ||
        aMessage == NS_MOUSE_EXIT_SYNTH)) {
     mCurrentTargetContent = nullptr;
     nsCOMPtr<Element> pointerLockedElement =
-      do_QueryReferent(nsEventStateManager::sPointerLockedElement);
+      do_QueryReferent(EventStateManager::sPointerLockedElement);
     if (!pointerLockedElement) {
       NS_WARNING("Should have pointer locked element, but didn't.");
       return nullptr;
     }
     nsCOMPtr<nsIContent> content = do_QueryInterface(pointerLockedElement);
     return mPresContext->GetPrimaryFrameFor(content);
   }
 
@@ -3541,17 +3550,17 @@ nsEventStateManager::DispatchMouseOrPoin
   event->inputSource = aMouseEvent->inputSource;
 
   nsWeakFrame previousTarget = mCurrentTarget;
 
   mCurrentTargetContent = aTargetContent;
 
   nsIFrame* targetFrame = nullptr;
   if (aTargetContent) {
-    nsESMEventCB callback(aTargetContent);
+    ESMEventCB callback(aTargetContent);
     EventDispatcher::Dispatch(aTargetContent, mPresContext, event, nullptr,
                               &status, &callback);
 
     // Although the primary frame was checked in event callback, 
     // it may not be the same object after event dispatching and handling.
     // So we need to refetch it.
     if (mPresContext) {
       targetFrame = mPresContext->GetPrimaryFrameFor(aTargetContent);
@@ -3562,20 +3571,22 @@ nsEventStateManager::DispatchMouseOrPoin
   mCurrentTarget = previousTarget;
 
   return targetFrame;
 }
 
 class EnterLeaveDispatcher
 {
 public:
-  EnterLeaveDispatcher(nsEventStateManager* aESM,
+  EnterLeaveDispatcher(EventStateManager* aESM,
                        nsIContent* aTarget, nsIContent* aRelatedTarget,
                        WidgetMouseEvent* aMouseEvent, uint32_t aType)
-  : mESM(aESM), mMouseEvent(aMouseEvent), mType(aType)
+    : mESM(aESM)
+    , mMouseEvent(aMouseEvent)
+    , mType(aType)
   {
     nsPIDOMWindow* win =
       aTarget ? aTarget->OwnerDoc()->GetInnerWindow() : nullptr;
     if (aMouseEvent->AsPointerEvent() ? win && win->HasPointerEnterLeaveEventListeners() :
                                         win && win->HasMouseEnterLeaveEventListeners()) {
       mRelatedTarget = aRelatedTarget ?
         aRelatedTarget->FindFirstNonChromeOnlyAccessContent() : nullptr;
       nsINode* commonParent = nullptr;
@@ -3606,26 +3617,26 @@ public:
     } else {
       for (int32_t i = 0; i < mTargets.Count(); ++i) {
         mESM->DispatchMouseOrPointerEvent(mMouseEvent, mType, mTargets[i],
                                           mRelatedTarget);
       }
     }
   }
 
-  nsEventStateManager*   mESM;
+  EventStateManager* mESM;
   nsCOMArray<nsIContent> mTargets;
-  nsCOMPtr<nsIContent>   mRelatedTarget;
-  WidgetMouseEvent*      mMouseEvent;
-  uint32_t               mType;
+  nsCOMPtr<nsIContent> mRelatedTarget;
+  WidgetMouseEvent* mMouseEvent;
+  uint32_t mType;
 };
 
 void
-nsEventStateManager::NotifyMouseOut(WidgetMouseEvent* aMouseEvent,
-                                    nsIContent* aMovingInto)
+EventStateManager::NotifyMouseOut(WidgetMouseEvent* aMouseEvent,
+                                  nsIContent* aMovingInto)
 {
   OverOutElementsWrapper* wrapper = GetWrapperByEventID(aMouseEvent);
 
   if (!wrapper->mLastOverElement)
     return;
   // Before firing mouseout, check for recursion
   if (wrapper->mLastOverElement == wrapper->mFirstOutEventElement)
     return;
@@ -3637,17 +3648,17 @@ nsEventStateManager::NotifyMouseOut(Widg
     if (subdocFrame) {
       nsCOMPtr<nsIDocShell> docshell;
       subdocFrame->GetDocShell(getter_AddRefs(docshell));
       if (docshell) {
         nsRefPtr<nsPresContext> presContext;
         docshell->GetPresContext(getter_AddRefs(presContext));
 
         if (presContext) {
-          nsEventStateManager* kidESM = presContext->EventStateManager();
+          EventStateManager* kidESM = presContext->EventStateManager();
           // Not moving into any element in this subdocument
           kidESM->NotifyMouseOut(aMouseEvent, nullptr);
         }
       }
     }
   }
   // That could have caused DOM events which could wreak havoc. Reverify
   // things and be careful.
@@ -3680,18 +3691,18 @@ nsEventStateManager::NotifyMouseOut(Widg
   wrapper->mLastOverFrame = nullptr;
   wrapper->mLastOverElement = nullptr;
 
   // Turn recursion protection back off
   wrapper->mFirstOutEventElement = nullptr;
 }
 
 void
-nsEventStateManager::NotifyMouseOver(WidgetMouseEvent* aMouseEvent,
-                                     nsIContent* aContent)
+EventStateManager::NotifyMouseOver(WidgetMouseEvent* aMouseEvent,
+                                   nsIContent* aContent)
 {
   NS_ASSERTION(aContent, "Mouse must be over something");
 
   OverOutElementsWrapper* wrapper = GetWrapperByEventID(aMouseEvent);
 
   if (wrapper->mLastOverElement == aContent)
     return;
 
@@ -3704,17 +3715,18 @@ nsEventStateManager::NotifyMouseOver(Wid
   // content associated with our subdocument.
   EnsureDocument(mPresContext);
   nsIDocument *parentDoc = mDocument->GetParentDocument();
   if (parentDoc) {
     nsIContent *docContent = parentDoc->FindContentForSubDocument(mDocument);
     if (docContent) {
       nsIPresShell *parentShell = parentDoc->GetShell();
       if (parentShell) {
-        nsEventStateManager* parentESM = parentShell->GetPresContext()->EventStateManager();
+        EventStateManager* parentESM =
+          parentShell->GetPresContext()->EventStateManager();
         parentESM->NotifyMouseOver(aMouseEvent, docContent);
       }
     }
   }
   // Firing the DOM event in the parent document could cause all kinds
   // of havoc.  Reverify and take care.
   if (wrapper->mLastOverElement == aContent)
     return;
@@ -3790,17 +3802,17 @@ GetWindowInnerRectCenter(nsPIDOMWindow* 
   int32_t cssScreenY = aContext->DevPixelsToIntCSSPixels(screen.y);
 
   return LayoutDeviceIntPoint(
     aContext->CSSPixelsToDevPixels(innerX - cssScreenX + innerWidth / 2),
     aContext->CSSPixelsToDevPixels(innerY - cssScreenY + innerHeight / 2));
 }
 
 void
-nsEventStateManager::GenerateMouseEnterExit(WidgetMouseEvent* aMouseEvent)
+EventStateManager::GenerateMouseEnterExit(WidgetMouseEvent* aMouseEvent)
 {
   EnsureDocument(mPresContext);
   if (!mDocument)
     return;
 
   // Hold onto old target content through the event and reset after.
   nsCOMPtr<nsIContent> targetBeforeEvent = mCurrentTargetContent;
 
@@ -3894,17 +3906,17 @@ nsEventStateManager::GenerateMouseEnterE
     break;
   }
 
   // reset mCurretTargetContent to what it was
   mCurrentTargetContent = targetBeforeEvent;
 }
 
 OverOutElementsWrapper*
-nsEventStateManager::GetWrapperByEventID(WidgetMouseEvent* aEvent)
+EventStateManager::GetWrapperByEventID(WidgetMouseEvent* aEvent)
 {
   WidgetPointerEvent* pointer = aEvent->AsPointerEvent();
   if (!pointer) {
     MOZ_ASSERT(aEvent->AsMouseEvent() != nullptr);
     if (!mMouseEnterLeaveHelper) {
       mMouseEnterLeaveHelper = new OverOutElementsWrapper();
     }
     return mMouseEnterLeaveHelper;
@@ -3914,18 +3926,18 @@ nsEventStateManager::GetWrapperByEventID
     helper = new OverOutElementsWrapper();
     mPointersEnterLeaveHelper.Put(pointer->pointerId, helper);
   }
 
   return helper;
 }
 
 void
-nsEventStateManager::SetPointerLock(nsIWidget* aWidget,
-                                    nsIContent* aElement)
+EventStateManager::SetPointerLock(nsIWidget* aWidget,
+                                  nsIContent* aElement)
 {
   // NOTE: aElement will be nullptr when unlocking.
   sIsPointerLocked = !!aElement;
 
   if (!aWidget) {
     return;
   }
 
@@ -3971,18 +3983,18 @@ nsEventStateManager::SetPointerLock(nsIW
     // Unsuppress DnD
     if (dragService) {
       dragService->Unsuppress();
     }
   }
 }
 
 void
-nsEventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext,
-                                               WidgetDragEvent* aDragEvent)
+EventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext,
+                                             WidgetDragEvent* aDragEvent)
 {
   //Hold onto old target content through the event and reset after.
   nsCOMPtr<nsIContent> targetBeforeEvent = mCurrentTargetContent;
 
   switch(aDragEvent->message) {
   case NS_DRAGDROP_OVER:
     {
       // when dragging from one frame to another, events are fired in the
@@ -4043,22 +4055,22 @@ nsEventStateManager::GenerateDragDropEnt
   //reset mCurretTargetContent to what it was
   mCurrentTargetContent = targetBeforeEvent;
 
   // Now flush all pending notifications, for better responsiveness.
   FlushPendingEvents(aPresContext);
 }
 
 void
-nsEventStateManager::FireDragEnterOrExit(nsPresContext* aPresContext,
-                                         WidgetDragEvent* aDragEvent,
-                                         uint32_t aMsg,
-                                         nsIContent* aRelatedTarget,
-                                         nsIContent* aTargetContent,
-                                         nsWeakFrame& aTargetFrame)
+EventStateManager::FireDragEnterOrExit(nsPresContext* aPresContext,
+                                       WidgetDragEvent* aDragEvent,
+                                       uint32_t aMsg,
+                                       nsIContent* aRelatedTarget,
+                                       nsIContent* aTargetContent,
+                                       nsWeakFrame& aTargetFrame)
 {
   nsEventStatus status = nsEventStatus_eIgnore;
   WidgetDragEvent event(aDragEvent->mFlags.mIsTrusted, aMsg,
                         aDragEvent->widget);
   event.refPoint = aDragEvent->refPoint;
   event.modifiers = aDragEvent->modifiers;
   event.buttons = aDragEvent->buttons;
   event.relatedTarget = aRelatedTarget;
@@ -4086,17 +4098,17 @@ nsEventStateManager::FireDragEnterOrExit
   }
 
   // Finally dispatch the event to the frame
   if (aTargetFrame)
     aTargetFrame->HandleEvent(aPresContext, &event, &status);
 }
 
 void
-nsEventStateManager::UpdateDragDataTransfer(WidgetDragEvent* dragEvent)
+EventStateManager::UpdateDragDataTransfer(WidgetDragEvent* dragEvent)
 {
   NS_ASSERTION(dragEvent, "drag event is null in UpdateDragDataTransfer!");
   if (!dragEvent->dataTransfer)
     return;
 
   nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
 
   if (dragSession) {
@@ -4109,19 +4121,19 @@ nsEventStateManager::UpdateDragDataTrans
       nsAutoString mozCursor;
       dragEvent->dataTransfer->GetMozCursor(mozCursor);
       initialDataTransfer->SetMozCursor(mozCursor);
     }
   }
 }
 
 nsresult
-nsEventStateManager::SetClickCount(nsPresContext* aPresContext,
-                                   WidgetMouseEvent* aEvent,
-                                   nsEventStatus* aStatus)
+EventStateManager::SetClickCount(nsPresContext* aPresContext,
+                                 WidgetMouseEvent* aEvent,
+                                 nsEventStatus* aStatus)
 {
   nsCOMPtr<nsIContent> mouseContent;
   nsIContent* mouseContentParent = nullptr;
   mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(mouseContent));
   if (mouseContent) {
     if (mouseContent->IsNodeOfType(nsINode::eTEXT)) {
       mouseContent = mouseContent->GetParent();
     }
@@ -4185,19 +4197,19 @@ nsEventStateManager::SetClickCount(nsPre
     }
     break;
   }
 
   return NS_OK;
 }
 
 nsresult
-nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext,
-                                              WidgetMouseEvent* aEvent,
-                                              nsEventStatus* aStatus)
+EventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext,
+                                            WidgetMouseEvent* aEvent,
+                                            nsEventStatus* aStatus)
 {
   nsresult ret = NS_OK;
 
   //If mouse is still over same element, clickcount will be > 1.
   //If it has moved it will be zero, so no click.
   if (0 != aEvent->clickCount) {
     //Check that the window isn't disabled before firing a click
     //(see bug 366544).
@@ -4247,17 +4259,17 @@ nsEventStateManager::CheckForAndDispatch
                                                mouseContent, aStatus);
       }
     }
   }
   return ret;
 }
 
 nsIFrame*
-nsEventStateManager::GetEventTarget()
+EventStateManager::GetEventTarget()
 {
   nsIPresShell *shell;
   if (mCurrentTarget ||
       !mPresContext ||
       !(shell = mPresContext->GetPresShell())) {
     return mCurrentTarget;
   }
 
@@ -4268,17 +4280,17 @@ nsEventStateManager::GetEventTarget()
     }
   }
 
   nsIFrame* frame = shell->GetEventTargetFrame();
   return (mCurrentTarget = frame);
 }
 
 already_AddRefed<nsIContent>
-nsEventStateManager::GetEventTargetContent(WidgetEvent* aEvent)
+EventStateManager::GetEventTargetContent(WidgetEvent* aEvent)
 {
   if (aEvent &&
       (aEvent->message == NS_FOCUS_CONTENT ||
        aEvent->message == NS_BLUR_CONTENT)) {
     nsCOMPtr<nsIContent> content = GetFocusedContent();
     return content.forget();
   }
 
@@ -4362,53 +4374,53 @@ static Element*
 GetParentElement(Element* aElement)
 {
   nsIContent* p = aElement->GetParent();
   return (p && p->IsElement()) ? p->AsElement() : nullptr;
 }
 
 /* static */
 void
-nsEventStateManager::SetFullScreenState(Element* aElement, bool aIsFullScreen)
+EventStateManager::SetFullScreenState(Element* aElement, bool aIsFullScreen)
 {
   DoStateChange(aElement, NS_EVENT_STATE_FULL_SCREEN, aIsFullScreen);
   Element* ancestor = aElement;
   while ((ancestor = GetParentElement(ancestor))) {
     DoStateChange(ancestor, NS_EVENT_STATE_FULL_SCREEN_ANCESTOR, aIsFullScreen);
   }
 }
 
 /* static */
 inline void
-nsEventStateManager::DoStateChange(Element* aElement, nsEventStates aState,
-                                   bool aAddState)
+EventStateManager::DoStateChange(Element* aElement, nsEventStates aState,
+                                 bool aAddState)
 {
   if (aAddState) {
     aElement->AddStates(aState);
   } else {
     aElement->RemoveStates(aState);
   }
 }
 
 /* static */
 inline void
-nsEventStateManager::DoStateChange(nsIContent* aContent, nsEventStates aState,
-                                   bool aStateAdded)
+EventStateManager::DoStateChange(nsIContent* aContent, nsEventStates aState,
+                                 bool aStateAdded)
 {
   if (aContent->IsElement()) {
     DoStateChange(aContent->AsElement(), aState, aStateAdded);
   }
 }
 
 /* static */
 void
-nsEventStateManager::UpdateAncestorState(nsIContent* aStartNode,
-                                         nsIContent* aStopBefore,
-                                         nsEventStates aState,
-                                         bool aAddState)
+EventStateManager::UpdateAncestorState(nsIContent* aStartNode,
+                                       nsIContent* aStopBefore,
+                                       nsEventStates aState,
+                                       bool aAddState)
 {
   for (; aStartNode && aStartNode != aStopBefore;
        aStartNode = aStartNode->GetParent()) {
     // We might be starting with a non-element (e.g. a text node) and
     // if someone is doing something weird might be ending with a
     // non-element too (e.g. a document fragment)
     if (!aStartNode->IsElement()) {
       continue;
@@ -4443,17 +4455,17 @@ nsEventStateManager::UpdateAncestorState
       if (labelTarget && !labelTarget->State().HasState(aState)) {
         DoStateChange(labelTarget, aState, true);
       }
     }
   }
 }
 
 bool
-nsEventStateManager::SetContentState(nsIContent *aContent, nsEventStates aState)
+EventStateManager::SetContentState(nsIContent *aContent, nsEventStates aState)
 {
   // We manage 4 states here: ACTIVE, HOVER, DRAGOVER, URLTARGET
   // The input must be exactly one of them.
   NS_PRECONDITION(aState == NS_EVENT_STATE_ACTIVE ||
                   aState == NS_EVENT_STATE_HOVER ||
                   aState == NS_EVENT_STATE_DRAGOVER ||
                   aState == NS_EVENT_STATE_URLTARGET,
                   "Unexpected state");
@@ -4565,31 +4577,32 @@ nsEventStateManager::SetContentState(nsI
       }
     }
   }
 
   return true;
 }
 
 PLDHashOperator
-nsEventStateManager::ResetLastOverForContent(const uint32_t& aIdx,
-                                             nsRefPtr<OverOutElementsWrapper>& aElemWrapper,
-                                             void* aClosure)
+EventStateManager::ResetLastOverForContent(
+                     const uint32_t& aIdx,
+                     nsRefPtr<OverOutElementsWrapper>& aElemWrapper,
+                     void* aClosure)
 {
   nsIContent* content = static_cast<nsIContent*>(aClosure);
   if (aElemWrapper && aElemWrapper->mLastOverElement &&
       nsContentUtils::ContentIsDescendantOf(aElemWrapper->mLastOverElement, content)) {
     aElemWrapper->mLastOverElement = nullptr;
   }
 
   return PL_DHASH_NEXT;
 }
 
 void
-nsEventStateManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent)
+EventStateManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent)
 {
   /*
    * Anchor and area elements when focused or hovered might make the UI to show
    * the current link. We want to make sure that the UI gets informed when they
    * are actually removed from the DOM.
    */
   if (aContent->IsHTML() &&
       (aContent->Tag() == nsGkAtoms::a || aContent->Tag() == nsGkAtoms::area) &&
@@ -4624,91 +4637,92 @@ nsEventStateManager::ContentRemoved(nsID
   if (sDragOverContent &&
       sDragOverContent->OwnerDoc() == aContent->OwnerDoc() &&
       nsContentUtils::ContentIsDescendantOf(sDragOverContent, aContent)) {
     sDragOverContent = nullptr;
   }
 
   // See bug 292146 for why we want to null this out
   ResetLastOverForContent(0, mMouseEnterLeaveHelper, aContent);
-  mPointersEnterLeaveHelper.Enumerate(&nsEventStateManager::ResetLastOverForContent, aContent);
+  mPointersEnterLeaveHelper.Enumerate(
+    &EventStateManager::ResetLastOverForContent, aContent);
 }
 
 bool
-nsEventStateManager::EventStatusOK(WidgetGUIEvent* aEvent)
+EventStateManager::EventStatusOK(WidgetGUIEvent* aEvent)
 {
   return !(aEvent->message == NS_MOUSE_BUTTON_DOWN &&
            aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton &&
            !sNormalLMouseEventInProcess);
 }
 
 //-------------------------------------------
 // Access Key Registration
 //-------------------------------------------
 void
-nsEventStateManager::RegisterAccessKey(nsIContent* aContent, uint32_t aKey)
+EventStateManager::RegisterAccessKey(nsIContent* aContent, uint32_t aKey)
 {
   if (aContent && mAccessKeys.IndexOf(aContent) == -1)
     mAccessKeys.AppendObject(aContent);
 }
 
 void
-nsEventStateManager::UnregisterAccessKey(nsIContent* aContent, uint32_t aKey)
+EventStateManager::UnregisterAccessKey(nsIContent* aContent, uint32_t aKey)
 {
   if (aContent)
     mAccessKeys.RemoveObject(aContent);
 }
 
 uint32_t
-nsEventStateManager::GetRegisteredAccessKey(nsIContent* aContent)
+EventStateManager::GetRegisteredAccessKey(nsIContent* aContent)
 {
   MOZ_ASSERT(aContent);
 
   if (mAccessKeys.IndexOf(aContent) == -1)
     return 0;
 
   nsAutoString accessKey;
   aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
   return accessKey.First();
 }
 
 void
-nsEventStateManager::EnsureDocument(nsPresContext* aPresContext)
+EventStateManager::EnsureDocument(nsPresContext* aPresContext)
 {
   if (!mDocument)
     mDocument = aPresContext->Document();
 }
 
 void
-nsEventStateManager::FlushPendingEvents(nsPresContext* aPresContext)
+EventStateManager::FlushPendingEvents(nsPresContext* aPresContext)
 {
   NS_PRECONDITION(nullptr != aPresContext, "nullptr ptr");
   nsIPresShell *shell = aPresContext->GetPresShell();
   if (shell) {
     shell->FlushPendingNotifications(Flush_InterruptibleLayout);
   }
 }
 
 nsIContent*
-nsEventStateManager::GetFocusedContent()
+EventStateManager::GetFocusedContent()
 {
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   if (!fm || !mDocument)
     return nullptr;
 
   nsCOMPtr<nsPIDOMWindow> focusedWindow;
   return nsFocusManager::GetFocusedDescendant(mDocument->GetWindow(), false,
                                               getter_AddRefs(focusedWindow));
 }
 
 //-------------------------------------------------------
 // Return true if the docshell is visible
 
 bool
-nsEventStateManager::IsShellVisible(nsIDocShell* aShell)
+EventStateManager::IsShellVisible(nsIDocShell* aShell)
 {
   NS_ASSERTION(aShell, "docshell is null");
 
   nsCOMPtr<nsIBaseWindow> basewin = do_QueryInterface(aShell);
   if (!basewin)
     return true;
 
   bool isVisible = true;
@@ -4716,17 +4730,17 @@ nsEventStateManager::IsShellVisible(nsID
 
   // We should be doing some additional checks here so that
   // we don't tab into hidden tabs of tabbrowser.  -bryner
 
   return isVisible;
 }
 
 nsresult
-nsEventStateManager::DoContentCommandEvent(WidgetContentCommandEvent* aEvent)
+EventStateManager::DoContentCommandEvent(WidgetContentCommandEvent* aEvent)
 {
   EnsureDocument(mPresContext);
   NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
   nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
   NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
 
   nsCOMPtr<nsPIWindowRoot> root = window->GetTopWindowRoot();
   NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
@@ -4791,18 +4805,18 @@ nsEventStateManager::DoContentCommandEve
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult
-nsEventStateManager::DoContentCommandScrollEvent(
-                       WidgetContentCommandEvent* aEvent)
+EventStateManager::DoContentCommandScrollEvent(
+                     WidgetContentCommandEvent* aEvent)
 {
   NS_ENSURE_TRUE(mPresContext, NS_ERROR_NOT_AVAILABLE);
   nsIPresShell* ps = mPresContext->GetPresShell();
   NS_ENSURE_TRUE(ps, NS_ERROR_NOT_AVAILABLE);
   NS_ENSURE_TRUE(aEvent->mScroll.mAmount != 0, NS_ERROR_INVALID_ARG);
 
   nsIScrollableFrame::ScrollUnit scrollUnit;
   switch (aEvent->mScroll.mUnit) {
@@ -4840,62 +4854,62 @@ nsEventStateManager::DoContentCommandScr
   }
 
   // The caller may want synchronous scrolling.
   sf->ScrollBy(pt, scrollUnit, nsIScrollableFrame::INSTANT);
   return NS_OK;
 }
 
 void
-nsEventStateManager::DoQuerySelectedText(WidgetQueryContentEvent* aEvent)
+EventStateManager::DoQuerySelectedText(WidgetQueryContentEvent* aEvent)
 {
   if (RemoteQueryContentEvent(aEvent)) {
     return;
   }
   ContentEventHandler handler(mPresContext);
   handler.OnQuerySelectedText(aEvent);
 }
 
 void
-nsEventStateManager::SetActiveManager(nsEventStateManager* aNewESM,
-                                      nsIContent* aContent)
+EventStateManager::SetActiveManager(EventStateManager* aNewESM,
+                                    nsIContent* aContent)
 {
   if (sActiveESM && aNewESM != sActiveESM) {
     sActiveESM->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE);
   }
   sActiveESM = aNewESM;
   if (sActiveESM && aContent) {
     sActiveESM->SetContentState(aContent, NS_EVENT_STATE_ACTIVE);
   }
 }
 
 void
-nsEventStateManager::ClearGlobalActiveContent(nsEventStateManager* aClearer)
+EventStateManager::ClearGlobalActiveContent(EventStateManager* aClearer)
 {
   if (aClearer) {
     aClearer->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE);
     if (sDragOverContent) {
       aClearer->SetContentState(nullptr, NS_EVENT_STATE_DRAGOVER);
     }
   }
   if (sActiveESM && aClearer != sActiveESM) {
     sActiveESM->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE);
   }
   sActiveESM = nullptr;
 }
 
 /******************************************************************/
-/* nsEventStateManager::DeltaAccumulator                          */
+/* mozilla::EventStateManager::DeltaAccumulator                   */
 /******************************************************************/
 
 void
-nsEventStateManager::DeltaAccumulator::InitLineOrPageDelta(
-                                         nsIFrame* aTargetFrame,
-                                         nsEventStateManager* aESM,
-                                         WidgetWheelEvent* aEvent)
+EventStateManager::DeltaAccumulator::InitLineOrPageDelta(
+                                       nsIFrame* aTargetFrame,
+                                       EventStateManager* aESM,
+                                       WidgetWheelEvent* aEvent)
 {
   MOZ_ASSERT(aESM);
   MOZ_ASSERT(aEvent);
 
   // Reset if the previous wheel event is too old.
   if (!mLastTime.IsNull()) {
     TimeDuration duration = TimeStamp::Now() - mLastTime;
     if (duration.ToMilliseconds() > WheelTransaction::GetTimeoutTime()) {
@@ -4923,17 +4937,17 @@ nsEventStateManager::DeltaAccumulator::I
   mHandlingDeltaMode = aEvent->deltaMode;
   mHandlingPixelOnlyDevice = aEvent->isPixelOnlyDevice;
 
   // If it's handling neither pixel scroll mode for pixel only device nor
   // delta values multiplied by prefs, we must not modify lineOrPageDelta
   // values.
   if (!(mHandlingDeltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL &&
         mHandlingPixelOnlyDevice) &&
-      !nsEventStateManager::WheelPrefs::GetInstance()->
+      !EventStateManager::WheelPrefs::GetInstance()->
         NeedToComputeLineOrPageDelta(aEvent)) {
     // Set the delta values to mX and mY.  They would be used when above block
     // resets mX/mY/mPendingScrollAmountX/mPendingScrollAmountY if the direction
     // is changed.
     // NOTE: We shouldn't accumulate the delta values, it might could cause
     //       overflow even though it's not a realistic situation.
     if (aEvent->deltaX) {
       mX = aEvent->deltaX;
@@ -4978,28 +4992,28 @@ nsEventStateManager::DeltaAccumulator::I
     mX -= aEvent->lineOrPageDeltaX;
     mY -= aEvent->lineOrPageDeltaY;
   }
 
   mLastTime = TimeStamp::Now();
 }
 
 void
-nsEventStateManager::DeltaAccumulator::Reset()
+EventStateManager::DeltaAccumulator::Reset()
 {
   mX = mY = 0.0;
   mPendingScrollAmountX = mPendingScrollAmountY = 0.0;
   mHandlingDeltaMode = UINT32_MAX;
   mHandlingPixelOnlyDevice = false;
 }
 
 nsIntPoint
-nsEventStateManager::DeltaAccumulator::ComputeScrollAmountForDefaultAction(
-                       WidgetWheelEvent* aEvent,
-                       const nsIntSize& aScrollAmountInDevPixels)
+EventStateManager::DeltaAccumulator::ComputeScrollAmountForDefaultAction(
+                     WidgetWheelEvent* aEvent,
+                     const nsIntSize& aScrollAmountInDevPixels)
 {
   MOZ_ASSERT(aEvent);
 
   // If the wheel event is line scroll and the delta value is computed from
   // system settings, allow to override the system speed.
   bool allowScrollSpeedOverride =
     (!aEvent->customizedByUserPrefs &&
      aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE);
@@ -5020,67 +5034,67 @@ nsEventStateManager::DeltaAccumulator::C
   result.y = RoundDown(mPendingScrollAmountY);
   mPendingScrollAmountX -= result.x;
   mPendingScrollAmountY -= result.y;
 
   return result;
 }
 
 /******************************************************************/
-/* nsEventStateManager::WheelPrefs                                */
+/* mozilla::EventStateManager::WheelPrefs                         */
 /******************************************************************/
 
 // static
-nsEventStateManager::WheelPrefs*
-nsEventStateManager::WheelPrefs::GetInstance()
+EventStateManager::WheelPrefs*
+EventStateManager::WheelPrefs::GetInstance()
 {
   if (!sInstance) {
     sInstance = new WheelPrefs();
   }
   return sInstance;
 }
 
 // static
 void
-nsEventStateManager::WheelPrefs::Shutdown()
+EventStateManager::WheelPrefs::Shutdown()
 {
   delete sInstance;
   sInstance = nullptr;
 }
 
 // static
 void
-nsEventStateManager::WheelPrefs::OnPrefChanged(const char* aPrefName,
-                                               void* aClosure)
+EventStateManager::WheelPrefs::OnPrefChanged(const char* aPrefName,
+                                             void* aClosure)
 {
   // forget all prefs, it's not problem for performance.
   sInstance->Reset();
   DeltaAccumulator::GetInstance()->Reset();
 }
 
-nsEventStateManager::WheelPrefs::WheelPrefs()
+EventStateManager::WheelPrefs::WheelPrefs()
 {
   Reset();
   Preferences::RegisterCallback(OnPrefChanged, "mousewheel.", nullptr);
 }
 
-nsEventStateManager::WheelPrefs::~WheelPrefs()
+EventStateManager::WheelPrefs::~WheelPrefs()
 {
   Preferences::UnregisterCallback(OnPrefChanged, "mousewheel.", nullptr);
 }
 
 void
-nsEventStateManager::WheelPrefs::Reset()
+EventStateManager::WheelPrefs::Reset()
 {
   memset(mInit, 0, sizeof(mInit));
 
 }
 
-nsEventStateManager::WheelPrefs::Index
-nsEventStateManager::WheelPrefs::GetIndexFor(WidgetWheelEvent* aEvent)
+EventStateManager::WheelPrefs::Index
+EventStateManager::WheelPrefs::GetIndexFor(WidgetWheelEvent* aEvent)
 {
   if (!aEvent) {
     return INDEX_DEFAULT;
   }
 
   Modifiers modifiers =
     (aEvent->modifiers & (MODIFIER_ALT |
                           MODIFIER_CONTROL |
@@ -5102,19 +5116,19 @@ nsEventStateManager::WheelPrefs::GetInde
     default:
       // If two or more modifier keys are pressed, we should use default
       // settings.
       return INDEX_DEFAULT;
   }
 }
 
 void
-nsEventStateManager::WheelPrefs::GetBasePrefName(
-                       nsEventStateManager::WheelPrefs::Index aIndex,
-                       nsACString& aBasePrefName)
+EventStateManager::WheelPrefs::GetBasePrefName(
+                     EventStateManager::WheelPrefs::Index aIndex,
+                     nsACString& aBasePrefName)
 {
   aBasePrefName.AssignLiteral("mousewheel.");
   switch (aIndex) {
     case INDEX_ALT:
       aBasePrefName.AppendLiteral("with_alt.");
       break;
     case INDEX_CONTROL:
       aBasePrefName.AppendLiteral("with_control.");
@@ -5131,18 +5145,17 @@ nsEventStateManager::WheelPrefs::GetBase
     case INDEX_DEFAULT:
     default:
       aBasePrefName.AppendLiteral("default.");
       break;
   }
 }
 
 void
-nsEventStateManager::WheelPrefs::Init(
-                       nsEventStateManager::WheelPrefs::Index aIndex)
+EventStateManager::WheelPrefs::Init(EventStateManager::WheelPrefs::Index aIndex)
 {
   if (mInit[aIndex]) {
     return;
   }
   mInit[aIndex] = true;
 
   nsAutoCString basePrefName;
   GetBasePrefName(aIndex, basePrefName);
@@ -5181,17 +5194,17 @@ nsEventStateManager::WheelPrefs::Init(
     actionOverrideX = -1;
   }
   mOverriddenActionsX[aIndex] = (actionOverrideX == -1)
                               ? static_cast<Action>(action)
                               : static_cast<Action>(actionOverrideX);
 }
 
 void
-nsEventStateManager::WheelPrefs::ApplyUserPrefsToDelta(WidgetWheelEvent* aEvent)
+EventStateManager::WheelPrefs::ApplyUserPrefsToDelta(WidgetWheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
 
   aEvent->deltaX *= mMultiplierX[index];
   aEvent->deltaY *= mMultiplierY[index];
   aEvent->deltaZ *= mMultiplierZ[index];
 
@@ -5207,18 +5220,18 @@ nsEventStateManager::WheelPrefs::ApplyUs
   }
 
   aEvent->customizedByUserPrefs =
     ((mMultiplierX[index] != 1.0) || (mMultiplierY[index] != 1.0) ||
      (mMultiplierZ[index] != 1.0));
 }
 
 void
-nsEventStateManager::WheelPrefs::CancelApplyingUserPrefsFromOverflowDelta(
-                                                   WidgetWheelEvent* aEvent)
+EventStateManager::WheelPrefs::CancelApplyingUserPrefsFromOverflowDelta(
+                                 WidgetWheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
 
   // XXX If the multiplier pref value is negative, the scroll direction was
   //     changed and caused to scroll different direction.  In such case,
   //     this method reverts the sign of overflowDelta.  Does it make widget
   //     happy?  Although, widget can know the pref applied delta values by
@@ -5227,18 +5240,18 @@ nsEventStateManager::WheelPrefs::CancelA
   if (mMultiplierX[index]) {
     aEvent->overflowDeltaX /= mMultiplierX[index];
   }
   if (mMultiplierY[index]) {
     aEvent->overflowDeltaY /= mMultiplierY[index];
   }
 }
 
-nsEventStateManager::WheelPrefs::Action
-nsEventStateManager::WheelPrefs::ComputeActionFor(WidgetWheelEvent* aEvent)
+EventStateManager::WheelPrefs::Action
+EventStateManager::WheelPrefs::ComputeActionFor(WidgetWheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
 
   bool deltaXPreferred =
     (Abs(aEvent->deltaX) > Abs(aEvent->deltaY) &&
      Abs(aEvent->deltaX) > Abs(aEvent->deltaZ));
   Action* actions = deltaXPreferred ? mOverriddenActionsX : mActions;
@@ -5253,59 +5266,59 @@ nsEventStateManager::WheelPrefs::Compute
     return (actions[INDEX_DEFAULT] == ACTION_SCROLL) ? ACTION_SCROLL :
                                                        ACTION_NONE;
   }
 
   return actions[index];
 }
 
 bool
-nsEventStateManager::WheelPrefs::NeedToComputeLineOrPageDelta(
-                                   WidgetWheelEvent* aEvent)
+EventStateManager::WheelPrefs::NeedToComputeLineOrPageDelta(
+                                 WidgetWheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
 
   return (mMultiplierX[index] != 1.0 && mMultiplierX[index] != -1.0) ||
          (mMultiplierY[index] != 1.0 && mMultiplierY[index] != -1.0);
 }
 
 bool
-nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedX(
-                                   WidgetWheelEvent* aEvent)
+EventStateManager::WheelPrefs::IsOverOnePageScrollAllowedX(
+                                 WidgetWheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
   return Abs(mMultiplierX[index]) >=
            MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
 }
 
 bool
-nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedY(
-                                   WidgetWheelEvent* aEvent)
+EventStateManager::WheelPrefs::IsOverOnePageScrollAllowedY(
+                                 WidgetWheelEvent* aEvent)
 {
   Index index = GetIndexFor(aEvent);
   Init(index);
   return Abs(mMultiplierY[index]) >=
            MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
 }
 
 /******************************************************************/
-/* nsEventStateManager::Prefs                                     */
+/* mozilla::EventStateManager::Prefs                              */
 /******************************************************************/
 
-bool nsEventStateManager::Prefs::sKeyCausesActivation = true;
-bool nsEventStateManager::Prefs::sClickHoldContextMenu = false;
-int32_t nsEventStateManager::Prefs::sGenericAccessModifierKey = -1;
-int32_t nsEventStateManager::Prefs::sChromeAccessModifierMask = 0;
-int32_t nsEventStateManager::Prefs::sContentAccessModifierMask = 0;
+bool EventStateManager::Prefs::sKeyCausesActivation = true;
+bool EventStateManager::Prefs::sClickHoldContextMenu = false;
+int32_t EventStateManager::Prefs::sGenericAccessModifierKey = -1;
+int32_t EventStateManager::Prefs::sChromeAccessModifierMask = 0;
+int32_t EventStateManager::Prefs::sContentAccessModifierMask = 0;
 
 // static
 void
-nsEventStateManager::Prefs::Init()
+EventStateManager::Prefs::Init()
 {
   DebugOnly<nsresult> rv =
     Preferences::AddBoolVarCache(&sKeyCausesActivation,
                                  "accessibility.accesskeycausesactivation",
                                  sKeyCausesActivation);
   MOZ_ASSERT(NS_SUCCEEDED(rv),
              "Failed to observe \"accessibility.accesskeycausesactivation\"");
   rv = Preferences::AddBoolVarCache(&sClickHoldContextMenu,
@@ -5331,48 +5344,48 @@ nsEventStateManager::Prefs::Init()
 
   rv = Preferences::RegisterCallback(OnChange, "dom.popup_allowed_events");
   MOZ_ASSERT(NS_SUCCEEDED(rv),
              "Failed to observe \"dom.popup_allowed_events\"");
 }
 
 // static
 void
-nsEventStateManager::Prefs::OnChange(const char* aPrefName, void*)
+EventStateManager::Prefs::OnChange(const char* aPrefName, void*)
 {
   nsDependentCString prefName(aPrefName);
   if (prefName.EqualsLiteral("dom.popup_allowed_events")) {
     Event::PopupAllowedEventsChanged();
   }
 }
 
 // static
 void
-nsEventStateManager::Prefs::Shutdown()
+EventStateManager::Prefs::Shutdown()
 {
   Preferences::UnregisterCallback(OnChange, "dom.popup_allowed_events");
 }
 
 // static
 int32_t
-nsEventStateManager::Prefs::ChromeAccessModifierMask()
+EventStateManager::Prefs::ChromeAccessModifierMask()
 {
   return GetAccessModifierMask(nsIDocShellTreeItem::typeChrome);
 }
 
 // static
 int32_t
-nsEventStateManager::Prefs::ContentAccessModifierMask()
+EventStateManager::Prefs::ContentAccessModifierMask()
 {
   return GetAccessModifierMask(nsIDocShellTreeItem::typeContent);
 }
 
 // static
 int32_t
-nsEventStateManager::Prefs::GetAccessModifierMask(int32_t aItemType)
+EventStateManager::Prefs::GetAccessModifierMask(int32_t aItemType)
 {
   switch (sGenericAccessModifierKey) {
     case -1:                             break; // use the individual prefs
     case nsIDOMKeyEvent::DOM_VK_SHIFT:   return NS_MODIFIER_SHIFT;
     case nsIDOMKeyEvent::DOM_VK_CONTROL: return NS_MODIFIER_CONTROL;
     case nsIDOMKeyEvent::DOM_VK_ALT:     return NS_MODIFIER_ALT;
     case nsIDOMKeyEvent::DOM_VK_META:    return NS_MODIFIER_META;
     case nsIDOMKeyEvent::DOM_VK_WIN:     return NS_MODIFIER_OS;
@@ -5399,17 +5412,17 @@ AutoHandlingUserInputStatePusher::AutoHa
                                     nsIDocument* aDocument) :
   mIsHandlingUserInput(aIsHandlingUserInput),
   mIsMouseDown(aEvent && aEvent->message == NS_MOUSE_BUTTON_DOWN),
   mResetFMMouseDownState(false)
 {
   if (!aIsHandlingUserInput) {
     return;
   }
-  nsEventStateManager::StartHandlingUserInput();
+  EventStateManager::StartHandlingUserInput();
   if (!mIsMouseDown) {
     return;
   }
   nsIPresShell::SetCapturingContent(nullptr, 0);
   nsIPresShell::AllowMouseCapture(true);
   if (!aDocument || !aEvent->mFlags.mIsTrusted) {
     return;
   }
@@ -5419,21 +5432,23 @@ AutoHandlingUserInputStatePusher::AutoHa
   mResetFMMouseDownState = true;
 }
 
 AutoHandlingUserInputStatePusher::~AutoHandlingUserInputStatePusher()
 {
   if (!mIsHandlingUserInput) {
     return;
   }
-  nsEventStateManager::StopHandlingUserInput();
+  EventStateManager::StopHandlingUserInput();
   if (!mIsMouseDown) {
     return;
   }
   nsIPresShell::AllowMouseCapture(false);
   if (!mResetFMMouseDownState) {
     return;
   }
   nsFocusManager* fm = nsFocusManager::GetFocusManager();
   NS_ENSURE_TRUE_VOID(fm);
   fm->SetMouseButtonDownHandlingDocument(nullptr);
 }
 
+} // namespace mozilla
+
rename from dom/events/nsEventStateManager.h
rename to dom/events/EventStateManager.h
--- a/dom/events/nsEventStateManager.h
+++ b/dom/events/EventStateManager.h
@@ -1,15 +1,15 @@
 /* -*- 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 nsEventStateManager_h__
-#define nsEventStateManager_h__
+#ifndef mozilla_EventStateManager_h_
+#define mozilla_EventStateManager_h_
 
 #include "mozilla/EventForwards.h"
 #include "mozilla/TypedEnum.h"
 
 #include "nsIObserver.h"
 #include "nsWeakReference.h"
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
@@ -23,31 +23,33 @@ class nsIContent;
 class nsIDocument;
 class nsIDocShell;
 class nsIDocShellTreeItem;
 class imgIContainer;
 class EnterLeaveDispatcher;
 class nsIMarkupDocumentViewer;
 class nsIScrollableFrame;
 class nsITimer;
+class nsPresContext;
 
 namespace mozilla {
+class EnterLeaveDispatcher;
 class ScrollbarsForWheel;
 class WheelTransaction;
 namespace dom {
 class DataTransfer;
 class TabParent;
 }
 }
 
 class OverOutElementsWrapper MOZ_FINAL : public nsISupports
 {
 public:
-  OverOutElementsWrapper() : mLastOverFrame(nullptr) {}
-  ~OverOutElementsWrapper() {}
+  OverOutElementsWrapper();
+  ~OverOutElementsWrapper();
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(OverOutElementsWrapper)
 
   nsWeakFrame mLastOverFrame;
 
   nsCOMPtr<nsIContent> mLastOverElement;
 
@@ -55,93 +57,86 @@ public:
   // the last over event we fired has finished processing.
   nsCOMPtr<nsIContent> mFirstOverEventElement;
 
   // The last element on which we fired a out event, or null if
   // the last out event we fired has finished processing.
   nsCOMPtr<nsIContent> mFirstOutEventElement;
 };
 
-/*
- * Event listener manager
- */
+namespace mozilla {
 
-class nsEventStateManager : public nsSupportsWeakReference,
-                            public nsIObserver
+class EventStateManager : public nsSupportsWeakReference,
+                          public nsIObserver
 {
+  friend class mozilla::EnterLeaveDispatcher;
   friend class mozilla::ScrollbarsForWheel;
   friend class mozilla::WheelTransaction;
 
 public:
-
-  typedef mozilla::TimeStamp TimeStamp;
-  typedef mozilla::TimeDuration TimeDuration;
-  typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint;
-
-  nsEventStateManager();
-  virtual ~nsEventStateManager();
+  EventStateManager();
+  virtual ~EventStateManager();
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   nsresult Init();
   nsresult Shutdown();
 
   /* The PreHandleEvent method is called before event dispatch to either
    * the DOM or frames.  Any processing which must not be prevented or
    * cancelled should occur here.  Any processing which is intended to
    * be conditional based on either DOM or frame processing should occur in
    * PostHandleEvent.  Any centralized event processing which must occur before
    * DOM or frame event handling should occur here as well.
    */
   nsresult PreHandleEvent(nsPresContext* aPresContext,
-                          mozilla::WidgetEvent* aEvent,
+                          WidgetEvent* aEvent,
                           nsIFrame* aTargetFrame,
                           nsEventStatus* aStatus);
 
   /* The PostHandleEvent method should contain all system processing which
    * should occur conditionally based on DOM or frame processing.  It should
    * also contain any centralized event processing which must occur after
    * DOM and frame processing.
    */
   nsresult PostHandleEvent(nsPresContext* aPresContext,
-                           mozilla::WidgetEvent* aEvent,
+                           WidgetEvent* aEvent,
                            nsIFrame* aTargetFrame,
                            nsEventStatus* aStatus);
 
   /**
    * DispatchLegacyMouseScrollEvents() dispatches NS_MOUSE_SCROLL event and
    * NS_MOUSE_PIXEL_SCROLL event for compatiblity with old Gecko.
    */
   void DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
-                                       mozilla::WidgetWheelEvent* aEvent,
+                                       WidgetWheelEvent* aEvent,
                                        nsEventStatus* aStatus);
 
   void NotifyDestroyPresContext(nsPresContext* aPresContext);
   void SetPresContext(nsPresContext* aPresContext);
   void ClearFrameRefs(nsIFrame* aFrame);
 
   nsIFrame* GetEventTarget();
-  already_AddRefed<nsIContent> GetEventTargetContent(
-                                 mozilla::WidgetEvent* aEvent);
+  already_AddRefed<nsIContent> GetEventTargetContent(WidgetEvent* aEvent);
 
   /**
    * Notify that the given NS_EVENT_STATE_* bit has changed for this content.
    * @param aContent Content which has changed states
    * @param aState   Corresponding state flags such as NS_EVENT_STATE_FOCUS
    * @return  Whether the content was able to change all states. Returns false
    *                  if a resulting DOM event causes the content node passed in
    *                  to not change states. Note, the frame for the content may
    *                  change as a result of the content state change, because of
    *                  frame reconstructions that may occur, but this does not
    *                  affect the return value.
    */
   bool SetContentState(nsIContent *aContent, nsEventStates aState);
   void ContentRemoved(nsIDocument* aDocument, nsIContent* aContent);
-  bool EventStatusOK(mozilla::WidgetGUIEvent* aEvent);
+  bool EventStatusOK(WidgetGUIEvent* aEvent);
 
   /**
    * Register accesskey on the given element. When accesskey is activated then
    * the element will be notified via nsIContent::PerformAccesskey() method.
    *
    * @param  aContent  the given element
    * @param  aKey      accesskey
    */
@@ -194,56 +189,53 @@ public:
    * since the user input than is specified by the
    * dom.event.handling-user-input-time-limit pref (default 1 second), this
    * function also returns false.
    */
   static bool IsHandlingUserInput();
 
   nsPresContext* GetPresContext() { return mPresContext; }
 
-  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEventStateManager,
+  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(EventStateManager,
                                            nsIObserver)
 
   static nsIDocument* sMouseOverDocument;
 
-  static nsEventStateManager* GetActiveEventStateManager() { return sActiveESM; }
+  static EventStateManager* GetActiveEventStateManager() { return sActiveESM; }
 
   // Sets aNewESM to be the active event state manager, and
   // if aContent is non-null, marks the object as active.
-  static void SetActiveManager(nsEventStateManager* aNewESM,
+  static void SetActiveManager(EventStateManager* aNewESM,
                                nsIContent* aContent);
 
   // Sets the full-screen event state on aElement to aIsFullScreen.
-  static void SetFullScreenState(mozilla::dom::Element* aElement, bool aIsFullScreen);
+  static void SetFullScreenState(dom::Element* aElement, bool aIsFullScreen);
 
   static bool IsRemoteTarget(nsIContent* aTarget);
-  static LayoutDeviceIntPoint GetChildProcessOffset(
-                                nsFrameLoader* aFrameLoader,
-                                const mozilla::WidgetEvent& aEvent);
+  static LayoutDeviceIntPoint GetChildProcessOffset(nsFrameLoader* aFrameLoader,
+                                                    const WidgetEvent& aEvent);
 
   // Holds the point in screen coords that a mouse event was dispatched to,
   // before we went into pointer lock mode. This is constantly updated while
   // the pointer is not locked, but we don't update it while the pointer is
   // locked. This is used by dom::Event::GetScreenCoords() to make mouse
   // events' screen coord appear frozen at the last mouse position while
   // the pointer is locked.
   static nsIntPoint sLastScreenPoint;
 
   // Holds the point in client coords of the last mouse event. Used by
   // dom::Event::GetClientCoords() to make mouse events' client coords appear
   // frozen at the last mouse position while the pointer is locked.
-  static mozilla::CSSIntPoint sLastClientPoint;
+  static CSSIntPoint sLastClientPoint;
 
   static bool sIsPointerLocked;
   static nsWeakPtr sPointerLockedElement;
   static nsWeakPtr sPointerLockedDoc;
 
 protected:
-  friend class EnterLeaveDispatcher;
-
   /**
    * Prefs class capsules preference management.
    */
   class Prefs
   {
   public:
     static bool KeyCausesActivation() { return sKeyCausesActivation; }
     static bool ClickHoldContextMenu() { return sClickHoldContextMenu; }
@@ -266,85 +258,84 @@ protected:
 
   /**
    * Get appropriate access modifier mask for the aDocShell.  Returns -1 if
    * access key isn't available.
    */
   static int32_t GetAccessModifierMaskFor(nsISupports* aDocShell);
 
   void UpdateCursor(nsPresContext* aPresContext,
-                    mozilla::WidgetEvent* aEvent,
+                    WidgetEvent* aEvent,
                     nsIFrame* aTargetFrame,
                     nsEventStatus* aStatus);
   /**
    * Turn a GUI mouse/pointer event into a mouse/pointer event targeted at the specified
    * content.  This returns the primary frame for the content (or null
    * if it goes away during the event).
    */
-  nsIFrame* DispatchMouseOrPointerEvent(mozilla::WidgetMouseEvent* aMouseEvent,
+  nsIFrame* DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent,
                                         uint32_t aMessage,
                                         nsIContent* aTargetContent,
                                         nsIContent* aRelatedContent);
   /**
    * Synthesize DOM and frame mouseover and mouseout events from this
    * MOUSE_MOVE or MOUSE_EXIT event.
    */
-  void GenerateMouseEnterExit(mozilla::WidgetMouseEvent* aMouseEvent);
+  void GenerateMouseEnterExit(WidgetMouseEvent* aMouseEvent);
   /**
    * Tell this ESM and ESMs in parent documents that the mouse is
    * over some content in this document.
    */
-  void NotifyMouseOver(mozilla::WidgetMouseEvent* aMouseEvent,
+  void NotifyMouseOver(WidgetMouseEvent* aMouseEvent,
                        nsIContent* aContent);
   /**
    * Tell this ESM and ESMs in affected child documents that the mouse
    * has exited this document's currently hovered content.
    * @param aMouseEvent the event that triggered the mouseout
    * @param aMovingInto the content node we've moved into.  This is used to set
    *        the relatedTarget for mouseout events.  Also, if it's non-null
    *        NotifyMouseOut will NOT change the current hover content to null;
    *        in that case the caller is responsible for updating hover state.
    */
-  void NotifyMouseOut(mozilla::WidgetMouseEvent* aMouseEvent,
+  void NotifyMouseOut(WidgetMouseEvent* aMouseEvent,
                       nsIContent* aMovingInto);
   void GenerateDragDropEnterExit(nsPresContext* aPresContext,
-                                 mozilla::WidgetDragEvent* aDragEvent);
+                                 WidgetDragEvent* aDragEvent);
 
   /**
    * Return mMouseEnterLeaveHelper or relevant mPointersEnterLeaveHelper elements wrapper.
    * If mPointersEnterLeaveHelper does not contain wrapper for pointerId it create new one
    */
-  OverOutElementsWrapper*
-  GetWrapperByEventID(mozilla::WidgetMouseEvent* aMouseEvent);
+  OverOutElementsWrapper* GetWrapperByEventID(WidgetMouseEvent* aMouseEvent);
 
   /**
    * Fire the dragenter and dragexit/dragleave events when the mouse moves to a
    * new target.
    *
    * @param aRelatedTarget relatedTarget to set for the event
    * @param aTargetContent target to set for the event
    * @param aTargetFrame target frame for the event
    */
   void FireDragEnterOrExit(nsPresContext* aPresContext,
-                           mozilla::WidgetDragEvent* aDragEvent,
+                           WidgetDragEvent* aDragEvent,
                            uint32_t aMsg,
                            nsIContent* aRelatedTarget,
                            nsIContent* aTargetContent,
                            nsWeakFrame& aTargetFrame);
   /**
    * Update the initial drag session data transfer with any changes that occur
    * on cloned data transfer objects used for events.
    */
-  void UpdateDragDataTransfer(mozilla::WidgetDragEvent* dragEvent);
+  void UpdateDragDataTransfer(WidgetDragEvent* dragEvent);
 
   nsresult SetClickCount(nsPresContext* aPresContext,
-                         mozilla::WidgetMouseEvent* aEvent,
+                         WidgetMouseEvent* aEvent,
                          nsEventStatus* aStatus);
   nsresult CheckForAndDispatchClick(nsPresContext* aPresContext,
-                                    mozilla::WidgetMouseEvent* aEvent,
+                                    WidgetMouseEvent* aEvent,
                                     nsEventStatus* aStatus);
   void EnsureDocument(nsPresContext* aPresContext);
   void FlushPendingEvents(nsPresContext* aPresContext);
 
   /**
    * The phases of HandleAccessKey processing. See below.
    */
   typedef enum {
@@ -368,17 +359,17 @@ protected:
    *        that recursively called us in its Up phase. The initial caller
    *        passes |nullptr| here. This is to avoid an infinite loop.
    * @param aAccessKeyState Normal, Down or Up processing phase (see enums
    *        above). The initial event receiver uses 'normal', then 'down' when
    *        processing children and Up when recursively calling its ancestor.
    * @param aModifierMask modifier mask for the key event
    */
   void HandleAccessKey(nsPresContext* aPresContext,
-                       mozilla::WidgetKeyboardEvent* aEvent,
+                       WidgetKeyboardEvent* aEvent,
                        nsEventStatus* aStatus,
                        nsIDocShellTreeItem* aBubbledFrom,
                        ProcessingAccessKeyState aAccessKeyState,
                        int32_t aModifierMask);
 
   bool ExecuteAccessKey(nsTArray<uint32_t>& aAccessCharCodes,
                           bool aIsTrustedEvent);
 
@@ -396,51 +387,50 @@ protected:
   public:
     static WheelPrefs* GetInstance();
     static void Shutdown();
 
     /**
      * ApplyUserPrefsToDelta() overrides the wheel event's delta values with
      * user prefs.
      */
-    void ApplyUserPrefsToDelta(mozilla::WidgetWheelEvent* aEvent);
+    void ApplyUserPrefsToDelta(WidgetWheelEvent* aEvent);
 
     /**
      * If ApplyUserPrefsToDelta() changed the delta values with customized
      * prefs, the overflowDelta values would be inflated.
      * CancelApplyingUserPrefsFromOverflowDelta() cancels the inflation.
      */
-    void CancelApplyingUserPrefsFromOverflowDelta(
-                                    mozilla::WidgetWheelEvent* aEvent);
+    void CancelApplyingUserPrefsFromOverflowDelta(WidgetWheelEvent* aEvent);
 
     /**
      * Computes the default action for the aEvent with the prefs.
      */
     enum Action MOZ_ENUM_TYPE(uint8_t)
     {
       ACTION_NONE = 0,
       ACTION_SCROLL,
       ACTION_HISTORY,
       ACTION_ZOOM,
       ACTION_LAST = ACTION_ZOOM
     };
-    Action ComputeActionFor(mozilla::WidgetWheelEvent* aEvent);
+    Action ComputeActionFor(WidgetWheelEvent* aEvent);
 
     /**
      * NeedToComputeLineOrPageDelta() returns if the aEvent needs to be
      * computed the lineOrPageDelta values.
      */
-    bool NeedToComputeLineOrPageDelta(mozilla::WidgetWheelEvent* aEvent);
+    bool NeedToComputeLineOrPageDelta(WidgetWheelEvent* aEvent);
 
     /**
      * IsOverOnePageScrollAllowed*() checks whether wheel scroll amount should
      * be rounded down to the page width/height (false) or not (true).
      */
-    bool IsOverOnePageScrollAllowedX(mozilla::WidgetWheelEvent* aEvent);
-    bool IsOverOnePageScrollAllowedY(mozilla::WidgetWheelEvent* aEvent);
+    bool IsOverOnePageScrollAllowedX(WidgetWheelEvent* aEvent);
+    bool IsOverOnePageScrollAllowedY(WidgetWheelEvent* aEvent);
 
   private:
     WheelPrefs();
     ~WheelPrefs();
 
     static void OnPrefChanged(const char* aPrefName, void* aClosure);
 
     enum Index
@@ -457,17 +447,17 @@ protected:
     /**
      * GetIndexFor() returns the index of the members which should be used for
      * the aEvent.  When only one modifier key of MODIFIER_ALT,
      * MODIFIER_CONTROL, MODIFIER_META, MODIFIER_SHIFT or MODIFIER_OS is
      * pressed, returns the index for the modifier.  Otherwise, this return the
      * default index which is used at either no modifier key is pressed or
      * two or modifier keys are pressed.
      */
-    Index GetIndexFor(mozilla::WidgetWheelEvent* aEvent);
+    Index GetIndexFor(WidgetWheelEvent* aEvent);
 
     /**
      * GetPrefNameBase() returns the base pref name for aEvent.
      * It's decided by GetModifierForPref() which modifier should be used for
      * the aEvent.
      *
      * @param aBasePrefName The result, must be "mousewheel.with_*." or
      *                      "mousewheel.default.".
@@ -533,17 +523,17 @@ protected:
    * @param aEvent              The original Wheel event.
    * @param aState              The event which should be set to the dispatching
    *                            event.  This also returns the dispatched event
    *                            state.
    * @param aDelta              The delta value of the event.
    * @param aDeltaDirection     The X/Y direction of dispatching event.
    */
   void SendLineScrollEvent(nsIFrame* aTargetFrame,
-                           mozilla::WidgetWheelEvent* aEvent,
+                           WidgetWheelEvent* aEvent,
                            EventState& aState,
                            int32_t aDelta,
                            DeltaDirection aDeltaDirection);
 
   /**
    * SendPixelScrollEvent() dispatches a MozMousePixelScroll event for the
    * WidgetWheelEvent.  This method shouldn't be called for non-trusted
    * wheel event because it's not necessary for compatiblity.
@@ -552,17 +542,17 @@ protected:
    * @param aEvent              The original Wheel event.
    * @param aState              The event which should be set to the dispatching
    *                            event.  This also returns the dispatched event
    *                            state.
    * @param aPixelDelta         The delta value of the event.
    * @param aDeltaDirection     The X/Y direction of dispatching event.
    */
   void SendPixelScrollEvent(nsIFrame* aTargetFrame,
-                            mozilla::WidgetWheelEvent* aEvent,
+                            WidgetWheelEvent* aEvent,
                             EventState& aState,
                             int32_t aPixelDelta,
                             DeltaDirection aDeltaDirection);
 
   /**
    * ComputeScrollTarget() returns the scrollable frame which should be
    * scrolled.
    *
@@ -596,46 +586,46 @@ protected:
     // Look for the nearest scrollable ancestor which can be scrollable with
     // aEvent.
     COMPUTE_SCROLLABLE_ANCESTOR_ALONG_X_AXIS     =
       (PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_X_AXIS | START_FROM_PARENT),
     COMPUTE_SCROLLABLE_ANCESTOR_ALONG_Y_AXIS     =
       (PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_Y_AXIS | START_FROM_PARENT)
   };
   nsIScrollableFrame* ComputeScrollTarget(nsIFrame* aTargetFrame,
-                                          mozilla::WidgetWheelEvent* aEvent,
+                                          WidgetWheelEvent* aEvent,
                                           ComputeScrollTargetOptions aOptions);
 
   nsIScrollableFrame* ComputeScrollTarget(nsIFrame* aTargetFrame,
                                           double aDirectionX,
                                           double aDirectionY,
-                                          mozilla::WidgetWheelEvent* aEvent,
+                                          WidgetWheelEvent* aEvent,
                                           ComputeScrollTargetOptions aOptions);
 
   /**
    * GetScrollAmount() returns the scroll amount in app uints of one line or
    * one page.  If the wheel event scrolls a page, returns the page width and
    * height.  Otherwise, returns line height for both its width and height.
    *
    * @param aScrollableFrame    A frame which will be scrolled by the event.
    *                            The result of ComputeScrollTarget() is
    *                            expected for this value.
    *                            This can be nullptr if there is no scrollable
    *                            frame.  Then, this method uses root frame's
    *                            line height or visible area's width and height.
    */
   nsSize GetScrollAmount(nsPresContext* aPresContext,
-                         mozilla::WidgetWheelEvent* aEvent,
+                         WidgetWheelEvent* aEvent,
                          nsIScrollableFrame* aScrollableFrame);
 
   /**
    * DoScrollText() scrolls the scrollable frame for aEvent.
    */
   void DoScrollText(nsIScrollableFrame* aScrollableFrame,
-                    mozilla::WidgetWheelEvent* aEvent);
+                    WidgetWheelEvent* aEvent);
 
   void DoScrollHistory(int32_t direction);
   void DoScrollZoom(nsIFrame *aTargetFrame, int32_t adjustment);
   nsresult GetMarkupDocumentViewer(nsIMarkupDocumentViewer** aMv);
   nsresult ChangeTextSize(int32_t change);
   nsresult ChangeFullZoom(int32_t change);
 
   /**
@@ -664,30 +654,30 @@ protected:
     bool IsInTransaction() { return mHandlingDeltaMode != UINT32_MAX; }
 
     /**
      * InitLineOrPageDelta() stores pixel delta values of WidgetWheelEvents
      * which are caused if it's needed.  And if the accumulated delta becomes a
      * line height, sets lineOrPageDeltaX and lineOrPageDeltaY automatically.
      */
     void InitLineOrPageDelta(nsIFrame* aTargetFrame,
-                             nsEventStateManager* aESM,
-                             mozilla::WidgetWheelEvent* aEvent);
+                             EventStateManager* aESM,
+                             WidgetWheelEvent* aEvent);
 
     /**
      * Reset() resets all members.
      */
     void Reset();
 
     /**
      * ComputeScrollAmountForDefaultAction() computes the default action's
      * scroll amount in device pixels with mPendingScrollAmount*.
      */
     nsIntPoint ComputeScrollAmountForDefaultAction(
-                 mozilla::WidgetWheelEvent* aEvent,
+                 WidgetWheelEvent* aEvent,
                  const nsIntSize& aScrollAmountInDevPixels);
 
   private:
     DeltaAccumulator() :
       mX(0.0), mY(0.0), mPendingScrollAmountX(0.0), mPendingScrollAmountY(0.0),
       mHandlingDeltaMode(UINT32_MAX), mHandlingPixelOnlyDevice(false)
     {
     }
@@ -714,130 +704,129 @@ protected:
   /*
    * When a touch gesture is about to start, this function determines what
    * kind of gesture interaction we will want to use, based on what is
    * underneath the initial touch point.
    * Currently it decides between panning (finger scrolling) or dragging
    * the target element, as well as the orientation to trigger panning and
    * display visual boundary feedback. The decision is stored back in aEvent.
    */
-  void DecideGestureEvent(mozilla::WidgetGestureNotifyEvent* aEvent,
+  void DecideGestureEvent(WidgetGestureNotifyEvent* aEvent,
                           nsIFrame* targetFrame);
 
   // routines for the d&d gesture tracking state machine
   void BeginTrackingDragGesture(nsPresContext* aPresContext,
-                                mozilla::WidgetMouseEvent* aDownEvent,
+                                WidgetMouseEvent* aDownEvent,
                                 nsIFrame* aDownFrame);
   void StopTrackingDragGesture();
   void GenerateDragGesture(nsPresContext* aPresContext,
-                           mozilla::WidgetMouseEvent* aEvent);
+                           WidgetMouseEvent* aEvent);
 
   /**
    * Determine which node the drag should be targeted at.
    * This is either the node clicked when there is a selection, or, for HTML,
    * the element with a draggable property set to true.
    *
    * aSelectionTarget - target to check for selection
    * aDataTransfer - data transfer object that will contain the data to drag
    * aSelection - [out] set to the selection to be dragged
    * aTargetNode - [out] the draggable node, or null if there isn't one
    */
   void DetermineDragTarget(nsPIDOMWindow* aWindow,
                            nsIContent* aSelectionTarget,
-                           mozilla::dom::DataTransfer* aDataTransfer,
+                           dom::DataTransfer* aDataTransfer,
                            nsISelection** aSelection,
                            nsIContent** aTargetNode);
 
   /*
    * Perform the default handling for the dragstart/draggesture event and set up a
    * drag for aDataTransfer if it contains any data. Returns true if a drag has
    * started.
    *
    * aDragEvent - the dragstart/draggesture event
    * aDataTransfer - the data transfer that holds the data to be dragged
    * aDragTarget - the target of the drag
    * aSelection - the selection to be dragged
    */
   bool DoDefaultDragStart(nsPresContext* aPresContext,
-                          mozilla::WidgetDragEvent* aDragEvent,
-                          mozilla::dom::DataTransfer* aDataTransfer,
+                          WidgetDragEvent* aDragEvent,
+                          dom::DataTransfer* aDataTransfer,
                           nsIContent* aDragTarget,
                           nsISelection* aSelection);
 
   bool IsTrackingDragGesture ( ) const { return mGestureDownContent != nullptr; }
   /**
    * Set the fields of aEvent to reflect the mouse position and modifier keys
    * that were set when the user first pressed the mouse button (stored by
    * BeginTrackingDragGesture). aEvent->widget must be
    * mCurrentTarget->GetNearestWidget().
    */
-  void FillInEventFromGestureDown(mozilla::WidgetMouseEvent* aEvent);
+  void FillInEventFromGestureDown(WidgetMouseEvent* aEvent);
 
-  nsresult DoContentCommandEvent(mozilla::WidgetContentCommandEvent* aEvent);
-  nsresult DoContentCommandScrollEvent(
-             mozilla::WidgetContentCommandEvent* aEvent);
+  nsresult DoContentCommandEvent(WidgetContentCommandEvent* aEvent);
+  nsresult DoContentCommandScrollEvent(WidgetContentCommandEvent* aEvent);
 
-  void DoQuerySelectedText(mozilla::WidgetQueryContentEvent* aEvent);
+  void DoQuerySelectedText(WidgetQueryContentEvent* aEvent);
 
-  bool RemoteQueryContentEvent(mozilla::WidgetEvent* aEvent);
-  mozilla::dom::TabParent *GetCrossProcessTarget();
-  bool IsTargetCrossProcess(mozilla::WidgetGUIEvent* aEvent);
+  bool RemoteQueryContentEvent(WidgetEvent* aEvent);
+  dom::TabParent *GetCrossProcessTarget();
+  bool IsTargetCrossProcess(WidgetGUIEvent* aEvent);
 
-  bool DispatchCrossProcessEvent(mozilla::WidgetEvent* aEvent,
+  bool DispatchCrossProcessEvent(WidgetEvent* aEvent,
                                  nsFrameLoader* aRemote,
                                  nsEventStatus *aStatus);
-  bool HandleCrossProcessEvent(mozilla::WidgetEvent* aEvent,
+  bool HandleCrossProcessEvent(WidgetEvent* aEvent,
                                nsIFrame* aTargetFrame,
                                nsEventStatus* aStatus);
 
 private:
-  static inline void DoStateChange(mozilla::dom::Element* aElement,
+  static inline void DoStateChange(dom::Element* aElement,
                                    nsEventStates aState, bool aAddState);
   static inline void DoStateChange(nsIContent* aContent, nsEventStates aState,
                                    bool aAddState);
   static void UpdateAncestorState(nsIContent* aStartNode,
                                   nsIContent* aStopBefore,
                                   nsEventStates aState,
                                   bool aAddState);
   static PLDHashOperator ResetLastOverForContent(const uint32_t& aIdx,
                                                  nsRefPtr<OverOutElementsWrapper>& aChunk,
                                                  void* aClosure);
 
   int32_t     mLockCursor;
 
   // Last mouse event refPoint (the offset from the widget's origin in
   // device pixels) when mouse was locked, used to restore mouse position
   // after unlocking.
-  mozilla::LayoutDeviceIntPoint mPreLockPoint;
+  LayoutDeviceIntPoint mPreLockPoint;
 
   // Stores the refPoint of the last synthetic mouse move we dispatched
   // to re-center the mouse when we were pointer locked. If this is (-1,-1) it
   // means we've not recently dispatched a centering event. We use this to
   // detect when we receive the synth event, so we can cancel and not send it
   // to content.
-  static mozilla::LayoutDeviceIntPoint sSynthCenteringPoint;
+  static LayoutDeviceIntPoint sSynthCenteringPoint;
 
   nsWeakFrame mCurrentTarget;
   nsCOMPtr<nsIContent> mCurrentTargetContent;
   static nsWeakFrame sLastDragOverFrame;
 
   // Stores the refPoint (the offset from the widget's origin in device
   // pixels) of the last mouse event.
-  static mozilla::LayoutDeviceIntPoint sLastRefPoint;
+  static LayoutDeviceIntPoint sLastRefPoint;
 
   // member variables for the d&d gesture state machine
-  mozilla::LayoutDeviceIntPoint mGestureDownPoint; // screen coordinates
+  LayoutDeviceIntPoint mGestureDownPoint; // screen coordinates
   // The content to use as target if we start a d&d (what we drag).
   nsCOMPtr<nsIContent> mGestureDownContent;
   // The content of the frame where the mouse-down event occurred. It's the same
   // as the target in most cases but not always - for example when dragging
   // an <area> of an image map this is the image. (bug 289667)
   nsCOMPtr<nsIContent> mGestureDownFrameOwner;
   // State of keys when the original gesture-down happened
-  mozilla::Modifiers mGestureModifiers;
+  Modifiers mGestureModifiers;
   uint16_t mGestureDownButtons;
 
   nsCOMPtr<nsIContent> mLastLeftMouseDownContent;
   nsCOMPtr<nsIContent> mLastLeftMouseDownContentParent;
   nsCOMPtr<nsIContent> mLastMiddleMouseDownContent;
   nsCOMPtr<nsIContent> mLastMiddleMouseDownContentParent;
   nsCOMPtr<nsIContent> mLastRightMouseDownContent;
   nsCOMPtr<nsIContent> mLastRightMouseDownContentParent;
@@ -866,34 +855,32 @@ public:
   static nsresult UpdateUserActivityTimer(void);
   // Array for accesskey support
   nsCOMArray<nsIContent> mAccessKeys;
 
   static int32_t sUserInputEventDepth;
   
   static bool sNormalLMouseEventInProcess;
 
-  static nsEventStateManager* sActiveESM;
+  static EventStateManager* sActiveESM;
   
-  static void ClearGlobalActiveContent(nsEventStateManager* aClearer);
+  static void ClearGlobalActiveContent(EventStateManager* aClearer);
 
   // Functions used for click hold context menus
   nsCOMPtr<nsITimer> mClickHoldTimer;
   void CreateClickHoldTimer(nsPresContext* aPresContext,
                             nsIFrame* aDownFrame,
-                            mozilla::WidgetGUIEvent* aMouseDownEvent);
+                            WidgetGUIEvent* aMouseDownEvent);
   void KillClickHoldTimer();
   void FireContextClick();
 
   void SetPointerLock(nsIWidget* aWidget, nsIContent* aElement) ;
   static void sClickHoldCallback ( nsITimer* aTimer, void* aESM ) ;
 };
 
-namespace mozilla {
-
 /**
  * This class is used while processing real user input. During this time, popups
  * are allowed. For mousedown events, mouse capturing is also permitted.
  */
 class AutoHandlingUserInputStatePusher
 {
 public:
   AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
@@ -916,9 +903,9 @@ private:
 
 // Click and double-click events need to be handled even for content that
 // has no frame. This is required for Web compatibility.
 #define NS_EVENT_NEEDS_FRAME(event) \
     (!(event)->HasPluginActivationEventMessage() && \
      (event)->message != NS_MOUSE_CLICK && \
      (event)->message != NS_MOUSE_DOUBLECLICK)
 
-#endif // nsEventStateManager_h__
+#endif // mozilla_EventStateManager_h_
--- a/dom/events/UIEvent.cpp
+++ b/dom/events/UIEvent.cpp
@@ -4,20 +4,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "base/basictypes.h"
 #include "ipc/IPCMessageUtils.h"
 #include "mozilla/dom/UIEvent.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/ContentEvents.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/TextEvents.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
-#include "nsEventStateManager.h"
 #include "nsIContent.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIDOMWindow.h"
 #include "nsIDOMNode.h"
 #include "nsIFrame.h"
 #include "prtime.h"
 
 namespace mozilla {
@@ -27,18 +27,18 @@ UIEvent::UIEvent(EventTarget* aOwner,
                  nsPresContext* aPresContext,
                  WidgetGUIEvent* aEvent)
   : Event(aOwner, aPresContext,
           aEvent ? aEvent : new InternalUIEvent(false, 0))
   , mClientPoint(0, 0)
   , mLayerPoint(0, 0)
   , mPagePoint(0, 0)
   , mMovementPoint(0, 0)
-  , mIsPointerLocked(nsEventStateManager::sIsPointerLocked)
-  , mLastClientPoint(nsEventStateManager::sLastClientPoint)
+  , mIsPointerLocked(EventStateManager::sIsPointerLocked)
+  , mLastClientPoint(EventStateManager::sLastClientPoint)
 {
   if (aEvent) {
     mEventIsInternal = false;
   }
   else {
     mEventIsInternal = true;
     mEvent->time = PR_Now();
   }
--- a/dom/events/WheelHandlingHelper.cpp
+++ b/dom/events/WheelHandlingHelper.cpp
@@ -2,21 +2,21 @@
 /* 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 "WheelHandlingHelper.h"
 
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
-#include "nsEventStateManager.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIPresShell.h"
 #include "nsIScrollableFrame.h"
 #include "nsITimer.h"
 #include "nsPresContext.h"
 #include "prtime.h"
 #include "Units.h"
@@ -404,17 +404,17 @@ nsWeakFrame ScrollbarsForWheel::sActiveO
 nsWeakFrame ScrollbarsForWheel::sActivatedScrollTargets[kNumberOfTargets] = {
   nullptr, nullptr, nullptr, nullptr
 };
 
 bool ScrollbarsForWheel::sHadWheelStart = false;
 bool ScrollbarsForWheel::sOwnWheelTransaction = false;
 
 /* static */ void
-ScrollbarsForWheel::PrepareToScrollText(nsEventStateManager* aESM,
+ScrollbarsForWheel::PrepareToScrollText(EventStateManager* aESM,
                                         nsIFrame* aTargetFrame,
                                         WidgetWheelEvent* aEvent)
 {
   if (aEvent->message == NS_WHEEL_START) {
     WheelTransaction::OwnScrollbars(false);
     if (!IsActive()) {
       TemporarilyActivateAllPossibleScrollTargets(aESM, aTargetFrame, aEvent);
       sHadWheelStart = true;
@@ -482,27 +482,27 @@ ScrollbarsForWheel::IsActive()
 /* static */ void
 ScrollbarsForWheel::OwnWheelTransaction(bool aOwn)
 {
   sOwnWheelTransaction = aOwn;
 }
 
 /* static */ void
 ScrollbarsForWheel::TemporarilyActivateAllPossibleScrollTargets(
-                      nsEventStateManager* aESM,
+                      EventStateManager* aESM,
                       nsIFrame* aTargetFrame,
                       WidgetWheelEvent* aEvent)
 {
   for (size_t i = 0; i < kNumberOfTargets; i++) {
     const DeltaValues *dir = &directions[i];
     nsWeakFrame* scrollTarget = &sActivatedScrollTargets[i];
     MOZ_ASSERT(!*scrollTarget, "scroll target still temporarily activated!");
     nsIScrollableFrame* target =
       aESM->ComputeScrollTarget(aTargetFrame, dir->deltaX, dir->deltaY, aEvent,
-              nsEventStateManager::COMPUTE_DEFAULT_ACTION_TARGET);
+              EventStateManager::COMPUTE_DEFAULT_ACTION_TARGET);
     nsIScrollbarOwner* scrollbarOwner = do_QueryFrame(target);
     if (scrollbarOwner) {
       nsIFrame* targetFrame = do_QueryFrame(target);
       *scrollTarget = targetFrame;
       scrollbarOwner->ScrollbarActivityStarted();
     }
   }
 }
--- a/dom/events/WheelHandlingHelper.h
+++ b/dom/events/WheelHandlingHelper.h
@@ -7,24 +7,25 @@
 #ifndef mozilla_WheelHandlingHelper_h_
 #define mozilla_WheelHandlingHelper_h_
 
 #include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
 #include "nsCoord.h"
 #include "nsIFrame.h"
 
-class nsEventStateManager;
 class nsIScrollableFrame;
 class nsITimer;
 
 struct nsIntPoint;
 
 namespace mozilla {
 
+class EventStateManager;
+
 /**
  * DeltaValues stores two delta values which are along X and Y axis.  This is
  * useful for arguments and results of some methods.
  */
 
 struct DeltaValues
 {
   DeltaValues()
@@ -70,17 +71,17 @@ private:
  * E.g., on some platforms, scrollbars should show only while user attempts to
  * scroll.  At that time, scrollbars which may be possible to scroll by
  * operation of wheel at the point should show temporarily.
  */
 
 class ScrollbarsForWheel
 {
 public:
-  static void PrepareToScrollText(nsEventStateManager* aESM,
+  static void PrepareToScrollText(EventStateManager* aESM,
                                   nsIFrame* aTargetFrame,
                                   WidgetWheelEvent* aEvent);
   static void SetActiveScrollTarget(nsIScrollableFrame* aScrollTarget);
   // Hide all scrollbars (both mActiveOwner's and mActivatedScrollTargets')
   static void MayInactivate();
   static void Inactivate();
   static bool IsActive();
   static void OwnWheelTransaction(bool aOwn);
@@ -94,17 +95,17 @@ protected:
   static bool sOwnWheelTransaction;
 
 
   /**
    * These two methods are called upon NS_WHEEL_START/NS_WHEEL_STOP events
    * to show/hide the right scrollbars.
    */
   static void TemporarilyActivateAllPossibleScrollTargets(
-                nsEventStateManager* aESM,
+                EventStateManager* aESM,
                 nsIFrame* aTargetFrame,
                 WidgetWheelEvent* aEvent);
   static void DeactivateAllTemporarilyActivatedScrollTargets();
 };
 
 /**
  * WheelTransaction manages a series of wheel events as a transaction.
  * While in a transaction, every wheel event should scroll the same scrollable
--- a/dom/events/moz.build
+++ b/dom/events/moz.build
@@ -12,26 +12,26 @@ XPIDL_SOURCES += [
 ]
 
 XPIDL_MODULE = 'content_events'
 
 EXPORTS += [
     'nsDOMEventTargetHelper.h',
     'nsDOMKeyNameList.h',
     'nsEventNameList.h',
-    'nsEventStateManager.h',
     'nsEventStates.h',
     'nsIJSEventListener.h',
     'nsVKList.h',
 ]
 
 EXPORTS.mozilla += [
     'AsyncEventDispatcher.h',
     'EventDispatcher.h',
     'EventListenerManager.h',
+    'EventStateManager.h',
     'IMEStateManager.h',
     'InternalMutationEvent.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'AnimationEvent.h',
     'BeforeUnloadEvent.h',
     'ClipboardEvent.h',
@@ -105,17 +105,17 @@ UNIFIED_SOURCES += [
     'UIEvent.cpp',
     'WheelEvent.cpp',
     'WheelHandlingHelper.cpp',
     'XULCommandEvent.cpp',
 ]
 
 # nsEventStateManager.cpp should be built separately because of Mac OS X headers.
 SOURCES += [
-    'nsEventStateManager.cpp',
+    'EventStateManager.cpp',
 ]
 
 if CONFIG['MOZ_WEBSPEECH']:
     UNIFIED_SOURCES += ['SpeechRecognitionError.cpp']
 
 FAIL_ON_WARNINGS = True
 
 MSVC_ENABLE_PGO = True
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -451,21 +451,21 @@ interface nsIDOMWindowUtils : nsISupport
    * @param aDeltaX            deltaX value.
    * @param aDeltaY            deltaY value.
    * @param aDeltaZ            deltaZ value.
    * @param aDeltaMode         deltaMode value which must be one of
    *                           nsIDOMWheelEvent::DOM_DELTA_*.
    * @param aModifiers         modifiers pressed, using constants defined as
    *                           MODIFIER_*
    * @param aLineOrPageDeltaX  If you set this value non-zero for
-   *                           DOM_DELTA_PIXEL event, nsEventStateManager will
+   *                           DOM_DELTA_PIXEL event, EventStateManager will
    *                           dispatch NS_MOUSE_SCROLL event for horizontal
    *                           scroll.
    * @param aLineOrPageDeltaY  If you set this value non-zero for
-   *                           DOM_DELTA_PIXEL event, nsEventStateManager will
+   *                           DOM_DELTA_PIXEL event, EventStateManager will
    *                           dispatch NS_MOUSE_SCROLL event for vertical
    *                           scroll.
    * @param aOptions           Set following flags.
    */
    const unsigned long WHEEL_EVENT_CAUSED_BY_PIXEL_ONLY_DEVICE = 0x0001;
    const unsigned long WHEEL_EVENT_CAUSED_BY_MOMENTUM          = 0x0002;
    const unsigned long WHEEL_EVENT_CUSTOMIZED_BY_USER_PREFS    = 0x0004;
    // If any of the following flags is specified this method will throw an
@@ -1538,17 +1538,17 @@ interface nsIDOMWindowUtils : nsISupport
    * style sheets of the document.  The removal takes effect immediately.
    */
   void removeSheet(in nsIURI sheetURI,
                                 in unsigned long type);
 
   /**
    * Returns true if a user input is being handled.
    *
-   * This calls nsEventStateManager::IsHandlingUserInput().
+   * This calls EventStateManager::IsHandlingUserInput().
    */
   readonly attribute boolean isHandlingUserInput;
 
   /**
    * After calling the method, the window for which this DOMWindowUtils
    * was created can be closed using scripts.
    */
    void allowScriptsToClose();
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -11,30 +11,30 @@
 #include "AppProcessChecker.h"
 #include "IDBFactory.h"
 #include "IndexedDBParent.h"
 #include "mozIApplication.h"
 #include "mozilla/BrowserElementParent.h"
 #include "mozilla/docshell/OfflineCacheUpdateParent.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/PContentPermissionRequestParent.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/Hal.h"
 #include "mozilla/ipc/DocumentRendererParent.h"
 #include "mozilla/layers/CompositorParent.h"
 #include "mozilla/layout/RenderFrameParent.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/unused.h"
 #include "nsCOMPtr.h"
 #include "nsContentPermissionHelper.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
-#include "nsEventStateManager.h"
 #include "nsFocusManager.h"
 #include "nsFrameLoader.h"
 #include "nsIContent.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMWindow.h"
@@ -678,17 +678,18 @@ TabParent::SendKeyEvent(const nsAString&
 
 bool
 TabParent::MapEventCoordinatesForChildProcess(WidgetEvent* aEvent)
 {
   nsRefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
   if (!frameLoader) {
     return false;
   }
-  LayoutDeviceIntPoint offset = nsEventStateManager::GetChildProcessOffset(frameLoader, *aEvent);
+  LayoutDeviceIntPoint offset =
+    EventStateManager::GetChildProcessOffset(frameLoader, *aEvent);
   MapEventCoordinatesForChildProcess(offset, aEvent);
   return true;
 }
 
 void
 TabParent::MapEventCoordinatesForChildProcess(
   const LayoutDeviceIntPoint& aOffset, WidgetEvent* aEvent)
 {
@@ -839,18 +840,17 @@ bool TabParent::SendRealTouchEvent(Widge
     nsRefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
     if (!frameLoader) {
       // No frame anymore?
       sEventCapturer = nullptr;
       return false;
     }
 
     mChildProcessOffsetAtTouchStart =
-        nsEventStateManager::GetChildProcessOffset(frameLoader,
-                                                   event);
+      EventStateManager::GetChildProcessOffset(frameLoader, event);
 
     MOZ_ASSERT((!sEventCapturer && mEventCaptureDepth == 0) ||
                (sEventCapturer == this && mEventCaptureDepth > 0));
     // We want to capture all remaining touch events in this series
     // for fast-path dispatch.
     sEventCapturer = this;
     ++mEventCaptureDepth;
   }
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -1892,17 +1892,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
   }
 
   pluginWidget->EndDrawPlugin();
 #endif
 
 #ifdef XP_WIN
   // this code supports windowless plugins
   NPEvent *pPluginEvent = (NPEvent*)anEvent.pluginEvent;
-  // we can get synthetic events from the nsEventStateManager... these
+  // we can get synthetic events from the EventStateManager... these
   // have no pluginEvent
   NPEvent pluginEvent;
   if (anEvent.eventStructType == NS_MOUSE_EVENT) {
     if (!pPluginEvent) {
       // XXX Should extend this list to synthesize events for more event
       // types
       pluginEvent.event = 0;
       const WidgetMouseEvent* mouseEvent = anEvent.AsMouseEvent();
--- a/dom/xbl/nsXBLWindowKeyHandler.cpp
+++ b/dom/xbl/nsXBLWindowKeyHandler.cpp
@@ -17,22 +17,22 @@
 #include "nsFocusManager.h"
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 #include "nsContentUtils.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIPresShell.h"
+#include "mozilla/EventStateManager.h"
 #include "nsISelectionController.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
-#include "nsEventStateManager.h"
 #include "nsIEditor.h"
 #include "nsIHTMLEditor.h"
 #include "nsIDOMDocument.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 class nsXBLSpecialDocInfo : public nsIObserver
@@ -326,17 +326,17 @@ nsXBLWindowKeyHandler::HandleEventOnCapt
     aEvent->GetInternalNSEvent()->AsKeyboardEvent();
 
   if (widgetEvent->mFlags.mNoCrossProcessBoundaryForwarding) {
     return;
   }
 
   nsCOMPtr<mozilla::dom::Element> originalTarget =
     do_QueryInterface(aEvent->GetInternalNSEvent()->originalTarget);
-  if (!nsEventStateManager::IsRemoteTarget(originalTarget)) {
+  if (!EventStateManager::IsRemoteTarget(originalTarget)) {
     return;
   }
 
   if (!HasHandlerForEvent(aEvent)) {
     return;
   }
 
   // If this event hasn't been marked as mNoCrossProcessBoundaryForwarding
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -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/. */
 
 /* a presentation of a document, part 1 */
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 
 #include "base/basictypes.h"
 
 #include "nsCOMPtr.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsDocShell.h"
 #include "nsIContentViewer.h"
@@ -22,17 +23,16 @@
 #include "nsIFrame.h"
 #include "nsIDocument.h"
 #include "nsIPrintSettings.h"
 #include "nsILanguageAtomService.h"
 #include "mozilla/LookAndFeel.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsAutoPtr.h"
-#include "nsEventStateManager.h"
 #include "nsThreadUtils.h"
 #include "nsFrameManager.h"
 #include "nsLayoutUtils.h"
 #include "nsViewManager.h"
 #include "RestyleManager.h"
 #include "nsCSSRuleProcessor.h"
 #include "nsRuleNode.h"
 #include "gfxPlatform.h"
@@ -1012,17 +1012,17 @@ nsPresContext::Init(nsDeviceContext* aDe
   NS_ENSURE_ARG(aDeviceContext);
 
   mDeviceContext = aDeviceContext;
 
   if (mDeviceContext->SetPixelScale(mFullZoom))
     mDeviceContext->FlushFontCache();
   mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
 
-  mEventManager = new nsEventStateManager();
+  mEventManager = new mozilla::EventStateManager();
 
   mTransitionManager = new nsTransitionManager(this);
 
   mAnimationManager = new nsAnimationManager(this);
 
   // FIXME: Why is mozilla:: needed?
   mRestyleManager = new mozilla::RestyleManager(this);
 
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -48,33 +48,33 @@ class nsIDocShell;
 class nsIDocument;
 class nsILanguageAtomService;
 class nsITheme;
 class nsIContent;
 class nsIFrame;
 class nsFrameManager;
 class nsILinkHandler;
 class nsIAtom;
-class nsEventStateManager;
 class nsICSSPseudoComparator;
 struct nsStyleBackground;
 struct nsStyleBorder;
 class nsIRunnable;
 class gfxUserFontSet;
 class gfxTextPerfMetrics;
 class nsUserFontSet;
 struct nsFontFaceRuleContainer;
 class nsObjectFrame;
 class nsTransitionManager;
 class nsAnimationManager;
 class nsRefreshDriver;
 class nsIWidget;
 class nsDeviceContext;
 
 namespace mozilla {
+class EventStateManager;
 class RestyleManager;
 namespace dom {
 class MediaQueryList;
 }
 namespace layers {
 class ContainerLayer;
 }
 }
@@ -512,17 +512,17 @@ public:
   * does not affect layout.  It only affects the size of the onscreen pages
   * in print preview.
   * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
   */
   float GetPrintPreviewScale() { return mPPScale; }
   void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }
 
   nsDeviceContext* DeviceContext() { return mDeviceContext; }
-  nsEventStateManager* EventStateManager() { return mEventManager; }
+  mozilla::EventStateManager* EventStateManager() { return mEventManager; }
   nsIAtom* GetLanguageFromCharset() { return mLanguage; }
 
   float TextZoom() { return mTextZoom; }
   void SetTextZoom(float aZoom) {
     if (aZoom == mTextZoom)
       return;
 
     mTextZoom = aZoom;
@@ -1165,17 +1165,17 @@ protected:
   nsPresContextType     mType;
   nsIPresShell*         mShell;         // [WEAK]
   nsCOMPtr<nsIDocument> mDocument;
   nsRefPtr<nsDeviceContext> mDeviceContext; // [STRONG] could be weak, but
                                             // better safe than sorry.
                                             // Cannot reintroduce cycles
                                             // since there is no dependency
                                             // from gfx back to layout.
-  nsRefPtr<nsEventStateManager> mEventManager;
+  nsRefPtr<mozilla::EventStateManager> mEventManager;
   nsRefPtr<nsRefreshDriver> mRefreshDriver;
   nsRefPtr<nsTransitionManager> mTransitionManager;
   nsRefPtr<nsAnimationManager> mAnimationManager;
   nsRefPtr<mozilla::RestyleManager> mRestyleManager;
   nsIAtom*              mMedium;        // initialized by subclass ctors;
                                         // weak pointer to static atom
   nsCOMPtr<nsIAtom> mMediaEmulated;
 
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -20,16 +20,17 @@
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif
 #include "prlog.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include <algorithm>
@@ -69,17 +70,16 @@
 #include "nsRange.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsReadableUtils.h"
 #include "nsIPageSequenceFrame.h"
 #include "nsCaret.h"
 #include "nsIDOMHTMLDocument.h"
 #include "nsFrameManager.h"
-#include "nsEventStateManager.h"
 #include "nsXPCOM.h"
 #include "nsILayoutHistoryState.h"
 #include "nsILineIterator.h" // for ScrollContentIntoView
 #include "pldhash.h"
 #include "mozilla/dom/Touch.h"
 #include "nsIObserverService.h"
 #include "nsDocShell.h"        // for reflow observation
 #include "nsIBaseWindow.h"
@@ -463,17 +463,17 @@ public:
       } else if (aVisitor.mEvent->message == NS_WHEEL_WHEEL &&
                  aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault) {
         nsIFrame* frame = mPresShell->GetCurrentEventFrame();
         if (frame) {
           // chrome (including addons) should be able to know if content
           // handles both D3E "wheel" event and legacy mouse scroll events.
           // We should dispatch legacy mouse events before dispatching the
           // "wheel" event into system group.
-          nsRefPtr<nsEventStateManager> esm =
+          nsRefPtr<EventStateManager> esm =
             aVisitor.mPresContext->EventStateManager();
           esm->DispatchLegacyMouseScrollEvents(frame,
                                                aVisitor.mEvent->AsWheelEvent(),
                                                &aVisitor.mEventStatus);
         }
       }
       nsIFrame* frame = mPresShell->GetCurrentEventFrame();
       if (!frame &&
@@ -2919,17 +2919,17 @@ PresShell::GoToAnchor(const nsAString& a
     // We need to execute this even if there is an empty anchor name
     // so that any existing SVG fragment identifier effect is removed
     if (SVGFragmentIdentifier::ProcessFragmentIdentifier(mDocument, aAnchorName)) {
       return NS_OK;
     }
   }
 
   // Hold a reference to the ESM in case event dispatch tears us down.
-  nsRefPtr<nsEventStateManager> esm = mPresContext->EventStateManager();
+  nsRefPtr<EventStateManager> esm = mPresContext->EventStateManager();
 
   if (aAnchorName.IsEmpty()) {
     NS_ASSERTION(!aScroll, "can't scroll to empty anchor name");
     esm->SetContentState(nullptr, NS_EVENT_STATE_URLTARGET);
     return NS_OK;
   }
 
   nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
@@ -6740,23 +6740,24 @@ PresShell::HandleEvent(nsIFrame* aFrame,
     // EventStateManager of the current PresContext.
     // If that is the case, and mouse is over some ancestor document,
     // forward event handling to the active document.
     // This way content can get mouse events even when
     // mouse is over the chrome or outside the window.
     //
     // Note, currently for backwards compatibility we don't forward mouse events
     // to the active document when mouse is over some subdocument.
-    nsEventStateManager* activeESM =
-      nsEventStateManager::GetActiveEventStateManager();
+    EventStateManager* activeESM =
+      EventStateManager::GetActiveEventStateManager();
     if (activeESM && aEvent->HasMouseEventMessage() &&
         activeESM != shell->GetPresContext()->EventStateManager() &&
-        static_cast<nsEventStateManager*>(activeESM)->GetPresContext()) {
+        static_cast<EventStateManager*>(activeESM)->GetPresContext()) {
       nsIPresShell* activeShell =
-        static_cast<nsEventStateManager*>(activeESM)->GetPresContext()->GetPresShell();
+        static_cast<EventStateManager*>(activeESM)->GetPresContext()->
+          GetPresShell();
       if (activeShell &&
           nsContentUtils::ContentIsCrossDocDescendantOf(activeShell->GetDocument(),
                                                         shell->GetDocument())) {
         shell = static_cast<PresShell*>(activeShell);
         frame = shell->GetRootFrame();
       }
     }
 
@@ -6997,17 +6998,17 @@ PresShell::HandleEventWithTarget(WidgetE
   nsresult rv = HandleEventInternal(aEvent, aStatus);
   PopCurrentEventInfo();
   return rv;
 }
 
 nsresult
 PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus)
 {
-  nsRefPtr<nsEventStateManager> manager = mPresContext->EventStateManager();
+  nsRefPtr<EventStateManager> manager = mPresContext->EventStateManager();
   nsresult rv = NS_OK;
 
   if (!NS_EVENT_NEEDS_FRAME(aEvent) || GetCurrentEventFrame()) {
     bool touchIsNew = false;
     bool isHandlingUserInput = false;
 
     // XXX How about IME events and input events for plugins?
     if (aEvent->mFlags.mIsTrusted) {
@@ -7037,17 +7038,17 @@ PresShell::HandleEventInternal(WidgetEve
               // here, and ExitFullscreen() has no affect when passed a
               // non-fullscreen document.
               nsIDocument::ExitFullscreen(
                 nsContentUtils::IsFullscreenApiContentOnly() ? fullscreenAncestor : nullptr,
                 /* async */ true);
             }
           }
           nsCOMPtr<nsIDocument> pointerLockedDoc =
-            do_QueryReferent(nsEventStateManager::sPointerLockedDoc);
+            do_QueryReferent(EventStateManager::sPointerLockedDoc);
           if (pointerLockedDoc) {
             aEvent->mFlags.mDefaultPrevented = true;
             aEvent->mFlags.mOnlyChromeDispatch = true;
             if (aEvent->message == NS_KEY_UP) {
               nsIDocument::UnlockPointer();
             }
           }
         }
@@ -7184,17 +7185,17 @@ PresShell::HandleEventInternal(WidgetEve
       }
     }
 
     AutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput,
                                                         aEvent, mDocument);
 
     if (aEvent->mFlags.mIsTrusted && aEvent->message == NS_MOUSE_MOVE) {
       nsIPresShell::AllowMouseCapture(
-        nsEventStateManager::GetActiveEventStateManager() == manager);
+        EventStateManager::GetActiveEventStateManager() == manager);
     }
 
     nsAutoPopupStatePusher popupStatePusher(
                              Event::GetEventPopupControlState(aEvent));
 
     // FIXME. If the event was reused, we need to clear the old target,
     // bug 329430
     aEvent->target = nullptr;
@@ -8486,17 +8487,17 @@ PresShell::ProcessReflowCommands(bool aI
 
   return !interrupted;
 }
 
 void
 PresShell::WindowSizeMoveDone()
 {
   if (mPresContext) {
-    nsEventStateManager::ClearGlobalActiveContent(nullptr);
+    EventStateManager::ClearGlobalActiveContent(nullptr);
     ClearMouseCapture(nullptr);
   }
 }
 
 #ifdef MOZ_XUL
 /*
  * It's better to add stuff to the |DidSetStyleContext| method of the
  * relevant frames than adding it here.  These methods should (ideally,
--- a/layout/forms/nsFormControlFrame.cpp
+++ b/layout/forms/nsFormControlFrame.cpp
@@ -2,17 +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 "nsFormControlFrame.h"
 #include "nsGkAtoms.h"
 #include "nsLayoutUtils.h"
 #include "nsIDOMHTMLInputElement.h"
-#include "nsEventStateManager.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/LookAndFeel.h"
 #include "nsDeviceContext.h"
 
 using namespace mozilla;
 
 //#define FCF_NOISY
 
 nsFormControlFrame::nsFormControlFrame(nsStyleContext* aContext) :
@@ -111,17 +111,17 @@ nsFormControlFrame::RegUnRegAccessKey(ns
   
   NS_ASSERTION(presContext, "aPresContext is NULL in RegUnRegAccessKey!");
 
   nsAutoString accessKey;
 
   nsIContent* content = aFrame->GetContent();
   content->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
   if (!accessKey.IsEmpty()) {
-    nsEventStateManager *stateManager = presContext->EventStateManager();
+    EventStateManager* stateManager = presContext->EventStateManager();
     if (aDoReg) {
       stateManager->RegisterAccessKey(content, (uint32_t)accessKey.First());
     } else {
       stateManager->UnregisterAccessKey(content, (uint32_t)accessKey.First());
     }
     return NS_OK;
   }
   return NS_ERROR_FAILURE;
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -9,29 +9,29 @@
 #include "nsListControlFrame.h"
 #include "nsFormControlFrame.h" // for COMPARE macro
 #include "nsGkAtoms.h"
 #include "nsIDOMHTMLSelectElement.h"
 #include "nsIDOMHTMLOptionElement.h"
 #include "nsComboboxControlFrame.h"
 #include "nsIDOMHTMLOptGroupElement.h"
 #include "nsIPresShell.h"
-#include "nsEventStateManager.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsIXULRuntime.h"
 #include "nsFontMetrics.h"
 #include "nsIScrollableFrame.h"
 #include "nsCSSRendering.h"
 #include "nsIDOMEventListener.h"
 #include "nsLayoutUtils.h"
 #include "nsDisplayList.h"
 #include "nsContentUtils.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/HTMLOptionsCollection.h"
 #include "mozilla/dom/HTMLSelectElement.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TextEvents.h"
 #include <algorithm>
 
 using namespace mozilla;
 
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -29,17 +29,16 @@
 #include "nsIPresShell.h"
 #include "prlog.h"
 #include "prprf.h"
 #include <stdarg.h>
 #include "nsFrameManager.h"
 #include "nsLayoutUtils.h"
 
 #include "nsIDOMNode.h"
-#include "nsEventStateManager.h"
 #include "nsISelection.h"
 #include "nsISelectionPrivate.h"
 #include "nsFrameSelection.h"
 #include "nsGkAtoms.h"
 #include "nsCSSAnonBoxes.h"
 
 #include "nsFrameTraversal.h"
 #include "nsRange.h"
@@ -74,16 +73,17 @@
 #include "StickyScrollContainer.h"
 #include "nsFontInflationData.h"
 #include "gfxASurface.h"
 #include "nsRegion.h"
 #include "nsIFrameInlines.h"
 
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/EventListenerManager.h"
+#include "mozilla/EventStateManager.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;
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -22,17 +22,17 @@
 #include "nsICSSStyleRuleDOMWrapper.h"
 #include "nsIDOMWindow.h"
 #include "nsXBLBinding.h"
 #include "nsXBLPrototypeBinding.h"
 #include "nsIMutableArray.h"
 #include "nsBindingManager.h"
 #include "ChildIterator.h"
 #include "nsComputedDOMStyle.h"
-#include "nsEventStateManager.h"
+#include "mozilla/EventStateManager.h"
 #include "nsIAtom.h"
 #include "nsRange.h"
 #include "nsContentList.h"
 #include "mozilla/dom/Element.h"
 #include "nsCSSStyleSheet.h"
 #include "nsRuleWalker.h"
 #include "nsRuleProcessorData.h"
 #include "nsCSSRuleProcessor.h"
@@ -687,17 +687,18 @@ inDOMUtils::GetBindingURLs(nsIDOMElement
   return NS_OK;
 }
 
 NS_IMETHODIMP
 inDOMUtils::SetContentState(nsIDOMElement *aElement, nsEventStates::InternalType aState)
 {
   NS_ENSURE_ARG_POINTER(aElement);
 
-  nsRefPtr<nsEventStateManager> esm = inLayoutUtils::GetEventStateManagerFor(aElement);
+  nsRefPtr<EventStateManager> esm =
+    inLayoutUtils::GetEventStateManagerFor(aElement);
   if (esm) {
     nsCOMPtr<nsIContent> content;
     content = do_QueryInterface(aElement);
 
     // XXX Invalid cast of bool to nsresult (bug 778108)
     return (nsresult)esm->SetContentState(content, nsEventStates(aState));
   }
 
--- a/layout/inspector/inLayoutUtils.cpp
+++ b/layout/inspector/inLayoutUtils.cpp
@@ -8,18 +8,21 @@
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIContent.h"
 #include "nsIContentViewer.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/dom/Element.h"
 
+using namespace mozilla;
+
 ///////////////////////////////////////////////////////////////////////////////
 
 nsIDOMWindow*
 inLayoutUtils::GetWindowFor(nsIDOMNode* aNode)
 {
   nsCOMPtr<nsIDOMDocument> doc1;
   aNode->GetOwnerDocument(getter_AddRefs(doc1));
   return GetWindowFor(doc1.get());
@@ -44,17 +47,17 @@ inLayoutUtils::GetPresShellFor(nsISuppor
 /*static*/
 nsIFrame*
 inLayoutUtils::GetFrameFor(nsIDOMElement* aElement)
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
   return content->GetPrimaryFrame();
 }
 
-nsEventStateManager*
+EventStateManager*
 inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
 {
   NS_PRECONDITION(aElement, "Passing in a null element is bad");
 
   nsCOMPtr<nsIDOMDocument> domDoc;
   aElement->GetOwnerDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
 
--- a/layout/inspector/inLayoutUtils.h
+++ b/layout/inspector/inLayoutUtils.h
@@ -6,26 +6,30 @@
 #ifndef __inLayoutUtils_h__
 #define __inLayoutUtils_h__
 
 class nsIDocument;
 class nsIDOMDocument;
 class nsIDOMElement;
 class nsIDOMNode;
 class nsIDOMWindow;
-class nsEventStateManager;
 class nsIFrame;
 class nsIPresShell;
 class nsISupports;
 
+namespace mozilla {
+class EventStateManager;
+}
+
 class inLayoutUtils
 {
 public:
   static nsIDOMWindow* GetWindowFor(nsIDOMNode* aNode);
   static nsIDOMWindow* GetWindowFor(nsIDOMDocument* aDoc);
   static nsIPresShell* GetPresShellFor(nsISupports* aThing);
   static nsIFrame* GetFrameFor(nsIDOMElement* aElement);
-  static nsEventStateManager* GetEventStateManagerFor(nsIDOMElement *aElement);
+  static mozilla::EventStateManager*
+           GetEventStateManagerFor(nsIDOMElement *aElement);
   static nsIDOMDocument* GetSubDocumentFor(nsIDOMNode* aNode);
   static nsIDOMNode* GetContainerFor(const nsIDocument& aDoc);
 };
 
 #endif // __inLayoutUtils_h__
--- a/layout/xul/nsBoxFrame.cpp
+++ b/layout/xul/nsBoxFrame.cpp
@@ -51,17 +51,17 @@
 #include "nsSprocketLayout.h"
 #include "nsIScrollableFrame.h"
 #include "nsWidgetsCID.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsContainerFrame.h"
 #include "nsIDOMElement.h"
 #include "nsITheme.h"
 #include "nsTransform2D.h"
-#include "nsEventStateManager.h"
+#include "mozilla/EventStateManager.h"
 #include "nsIDOMEvent.h"
 #include "nsDisplayList.h"
 #include "mozilla/Preferences.h"
 #include "nsThemeConstants.h"
 #include "nsLayoutUtils.h"
 #include <algorithm>
 
 // Needed for Print Preview
@@ -1882,17 +1882,17 @@ nsBoxFrame::RegUnregAccessKey(bool aDoRe
   nsAutoString accessKey;
   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
 
   if (accessKey.IsEmpty())
     return;
 
   // With a valid PresContext we can get the ESM 
   // and register the access key
-  nsEventStateManager *esm = PresContext()->EventStateManager();
+  EventStateManager* esm = PresContext()->EventStateManager();
 
   uint32_t key = accessKey.First();
   if (aDoReg)
     esm->RegisterAccessKey(mContent, key);
   else
     esm->UnregisterAccessKey(mContent, key);
 }
 
--- a/layout/xul/nsButtonBoxFrame.cpp
+++ b/layout/xul/nsButtonBoxFrame.cpp
@@ -6,21 +6,21 @@
 #include "nsButtonBoxFrame.h"
 #include "nsIContent.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMXULButtonElement.h"
 #include "nsGkAtoms.h"
 #include "nsNameSpaceManager.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
-#include "nsEventStateManager.h"
 #include "nsIDOMElement.h"
 #include "nsDisplayList.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 
 using namespace mozilla;
 
 //
 // NS_NewXULButtonFrame
 //
@@ -57,17 +57,17 @@ nsButtonBoxFrame::HandleEvent(nsPresCont
 
   switch (aEvent->message) {
     case NS_KEY_DOWN: {
       WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
       if (!keyEvent) {
         break;
       }
       if (NS_VK_SPACE == keyEvent->keyCode) {
-        nsEventStateManager* esm = aPresContext->EventStateManager();
+        EventStateManager* esm = aPresContext->EventStateManager();
         // :hover:active state
         esm->SetContentState(mContent, NS_EVENT_STATE_HOVER);
         esm->SetContentState(mContent, NS_EVENT_STATE_ACTIVE);
       }
       break;
     }
 
 // On mac, Return fires the default button, not the focused one.
@@ -95,17 +95,17 @@ nsButtonBoxFrame::HandleEvent(nsPresCont
       }
       if (NS_VK_SPACE == keyEvent->keyCode) {
         // only activate on keyup if we're already in the :hover:active state
         NS_ASSERTION(mContent->IsElement(), "How do we have a non-element?");
         nsEventStates buttonState = mContent->AsElement()->State();
         if (buttonState.HasAllStates(NS_EVENT_STATE_ACTIVE |
                                      NS_EVENT_STATE_HOVER)) {
           // return to normal state
-          nsEventStateManager *esm = aPresContext->EventStateManager();
+          EventStateManager* esm = aPresContext->EventStateManager();
           esm->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE);
           esm->SetContentState(nullptr, NS_EVENT_STATE_HOVER);
           MouseClicked(aPresContext, aEvent);
         }
       }
       break;
     }
 
--- a/layout/xul/nsMenuFrame.cpp
+++ b/layout/xul/nsMenuFrame.cpp
@@ -28,20 +28,20 @@
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIStringBundle.h"
 #include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsIReflowCallback.h"
 #include "nsISound.h"
-#include "nsEventStateManager.h"
 #include "nsIDOMXULMenuListElement.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/Likely.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/Element.h"
 #include <algorithm>
@@ -1262,17 +1262,17 @@ nsMenuFrame::CreateMenuCommandEvent(Widg
     control = inputEvent->IsControl();
     alt = inputEvent->IsAlt();
     meta = inputEvent->IsMeta();
   }
 
   // Because the command event is firing asynchronously, a flag is needed to
   // indicate whether user input is being handled. This ensures that a popup
   // window won't get blocked.
-  bool userinput = nsEventStateManager::IsHandlingUserInput();
+  bool userinput = EventStateManager::IsHandlingUserInput();
 
   mDelayedMenuCommandEvent =
     new nsXULMenuCommandEvent(mContent, isTrusted, shift, control, alt, meta,
                               userinput, aFlipChecked);
 }
 
 void
 nsMenuFrame::PassMenuCommandEventToPopupManager()
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -29,29 +29,29 @@
 #include "nsIScrollableFrame.h"
 #include "nsIRootBox.h"
 #include "nsIDocShell.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsContentUtils.h"
 #include "nsCSSFrameConstructor.h"
-#include "nsEventStateManager.h"
 #include "nsIPopupBoxObject.h"
 #include "nsPIWindowRoot.h"
 #include "nsIReflowCallback.h"
 #include "nsBindingManager.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIBaseWindow.h"
 #include "nsISound.h"
 #include "nsIScreenManager.h"
 #include "nsIServiceManager.h"
 #include "nsThemeConstants.h"
 #include "nsDisplayList.h"
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/dom/Element.h"
 #include <algorithm>
 
 using namespace mozilla;
 
@@ -836,17 +836,17 @@ nsMenuPopupFrame::HidePopup(bool aDesele
 
   // XXX, bug 137033, In Windows, if mouse is outside the window when the menupopup closes, no
   // mouse_enter/mouse_exit event will be fired to clear current hover state, we should clear it manually.
   // This code may not the best solution, but we can leave it here until we find the better approach.
   NS_ASSERTION(mContent->IsElement(), "How do we have a non-element?");
   nsEventStates state = mContent->AsElement()->State();
 
   if (state.HasState(NS_EVENT_STATE_HOVER)) {
-    nsEventStateManager *esm = PresContext()->EventStateManager();
+    EventStateManager* esm = PresContext()->EventStateManager();
     esm->SetContentState(nullptr, NS_EVENT_STATE_HOVER);
   }
 
   nsMenuFrame* menuFrame = do_QueryFrame(GetParent());
   if (menuFrame) {
     menuFrame->PopupClosed(aDeselectMenu);
   }
 }
--- a/layout/xul/nsTextBoxFrame.cpp
+++ b/layout/xul/nsTextBoxFrame.cpp
@@ -14,17 +14,17 @@
 #include "nsIContent.h"
 #include "nsNameSpaceManager.h"
 #include "nsBoxLayoutState.h"
 #include "nsMenuBarListener.h"
 #include "nsXPIDLString.h"
 #include "nsIServiceManager.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMXULLabelElement.h"
-#include "nsEventStateManager.h"
+#include "mozilla/EventStateManager.h"
 #include "nsITheme.h"
 #include "nsUnicharUtils.h"
 #include "nsContentUtils.h"
 #include "nsCxPusher.h"
 #include "nsDisplayList.h"
 #include "nsCSSRendering.h"
 #include "nsIReflowCallback.h"
 #include "nsBoxFrame.h"
@@ -1126,17 +1126,17 @@ nsTextBoxFrame::RegUnregAccessKey(bool a
     nsAutoString accessKey;
     mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
 
     if (accessKey.IsEmpty())
         return NS_OK;
 
     // With a valid PresContext we can get the ESM 
     // and (un)register the access key
-    nsEventStateManager *esm = PresContext()->EventStateManager();
+    EventStateManager* esm = PresContext()->EventStateManager();
 
     uint32_t key = accessKey.First();
     if (aDoReg)
         esm->RegisterAccessKey(mContent, key);
     else
         esm->UnregisterAccessKey(mContent, key);
 
     return NS_OK;
--- a/layout/xul/nsXULLabelFrame.cpp
+++ b/layout/xul/nsXULLabelFrame.cpp
@@ -1,19 +1,21 @@
 /* -*- 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/. */
 
 /* derived class of nsBlockFrame used for xul:label elements */
 
+#include "mozilla/EventStateManager.h"
 #include "nsXULLabelFrame.h"
 #include "nsHTMLParts.h"
 #include "nsNameSpaceManager.h"
-#include "nsEventStateManager.h"
+
+using namespace mozilla;
 
 nsIFrame*
 NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext);
   
   it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
 
@@ -42,17 +44,17 @@ nsXULLabelFrame::RegUnregAccessKey(bool 
   nsAutoString accessKey;
   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
 
   if (accessKey.IsEmpty())
     return NS_OK;
 
   // With a valid PresContext we can get the ESM 
   // and register the access key
-  nsEventStateManager *esm = PresContext()->EventStateManager();
+  EventStateManager* esm = PresContext()->EventStateManager();
 
   uint32_t key = accessKey.First();
   if (aDoReg)
     esm->RegisterAccessKey(mContent, key);
   else
     esm->UnregisterAccessKey(mContent, key);
 
   return NS_OK;
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -11,17 +11,16 @@
 #include "nsIPopupBoxObject.h"
 #include "nsMenuBarListener.h"
 #include "nsContentUtils.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMXULElement.h"
 #include "nsIXULDocument.h"
 #include "nsIXULTemplateBuilder.h"
-#include "nsEventStateManager.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsLayoutUtils.h"
 #include "nsViewManager.h"
 #include "nsIComponentManager.h"
 #include "nsITimer.h"
 #include "nsFocusManager.h"
 #include "nsIDocShell.h"
 #include "nsPIDOMWindow.h"
@@ -32,16 +31,17 @@
 #include "nsCaret.h"
 #include "nsIDocument.h"
 #include "nsPIWindowRoot.h"
 #include "nsFrameManager.h"
 #include "nsIObserverService.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 #include "mozilla/EventDispatcher.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Services.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static_assert(nsIDOMKeyEvent::DOM_VK_HOME  == nsIDOMKeyEvent::DOM_VK_END + 1 &&
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -542,17 +542,17 @@ pref("app.update.channel", "@MOZ_UPDATE_
 // If you are looking for app.update.url, we no longer use it.
 // See mobile/android/base/UpdateServiceHelper.java.in
 #endif
 
 // replace newlines with spaces on paste into single-line text boxes
 pref("editor.singleLine.pasteNewlines", 2);
 
 // threshold where a tap becomes a drag, in 1/240" reference pixels
-// The names of the preferences are to be in sync with nsEventStateManager.cpp
+// The names of the preferences are to be in sync with EventStateManager.cpp
 pref("ui.dragThresholdX", 25);
 pref("ui.dragThresholdY", 25);
 
 pref("layers.acceleration.disabled", false);
 pref("layers.offmainthreadcomposition.enabled", true);
 pref("layers.async-video.enabled", true);
 pref("layers.progressive-paint", true);
 pref("layers.low-precision-buffer", true);
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -4115,17 +4115,17 @@ pref("alerts.disableSlidingEffect", fals
 pref("full-screen-api.enabled", false);
 pref("full-screen-api.allow-trusted-requests-only", true);
 pref("full-screen-api.content-only", false);
 pref("full-screen-api.pointer-lock.enabled", true);
 
 // DOM idle observers API
 pref("dom.idle-observers-api.enabled", true);
 
-// Time limit, in milliseconds, for nsEventStateManager::IsHandlingUserInput().
+// Time limit, in milliseconds, for EventStateManager::IsHandlingUserInput().
 // Used to detect long running handlers of user-generated events.
 pref("dom.event.handling-user-input-time-limit", 1000);
 
 // Whether we should layerize all animated images (if otherwise possible).
 pref("layout.animated-image-layers.enabled", false);
 
 pref("dom.vibrator.enabled", true);
 pref("dom.vibrator.max_vibrate_ms", 10000);
--- a/view/src/nsViewManager.cpp
+++ b/view/src/nsViewManager.cpp
@@ -13,17 +13,16 @@
 #include "nsCOMPtr.h"
 #include "mozilla/MouseEvents.h"
 #include "nsRegion.h"
 #include "nsCOMArray.h"
 #include "nsIPluginWidget.h"
 #include "nsXULPopupManager.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
-#include "nsEventStateManager.h"
 #include "mozilla/StartupTimeline.h"
 #include "GeckoProfiler.h"
 #include "nsRefreshDriver.h"
 #include "mozilla/Preferences.h"
 #include "nsContentUtils.h" // for nsAutoScriptBlocker
 #include "nsLayoutUtils.h"
 #include "Layers.h"
 #include "gfxPlatform.h"
--- a/widget/MouseEvents.h
+++ b/widget/MouseEvents.h
@@ -436,17 +436,17 @@ public:
     WidgetWheelEvent* result = new WidgetWheelEvent(false, message, nullptr);
     result->AssignWheelEventData(*this, true);
     result->mFlags = mFlags;
     return result;
   }
 
   // NOTE: deltaX, deltaY and deltaZ may be customized by
   //       mousewheel.*.delta_multiplier_* prefs which are applied by
-  //       nsEventStateManager.  So, after widget dispatches this event,
+  //       EventStateManager.  So, after widget dispatches this event,
   //       these delta values may have different values than before.
   double deltaX;
   double deltaY;
   double deltaZ;
 
   // Should be one of nsIDOMWheelEvent::DOM_DELTA_*
   uint32_t deltaMode;
 
@@ -460,17 +460,17 @@ public:
   bool isMomentum;
 
   // If device event handlers don't know when they should set lineOrPageDeltaX
   // and lineOrPageDeltaY, this is true.  Otherwise, false.
   // If isPixelOnlyDevice is true, ESM will generate NS_MOUSE_SCROLL events
   // when accumulated pixel delta values reach a line height.
   bool isPixelOnlyDevice;
 
-  // If widget sets lineOrPageDelta, nsEventStateManager will dispatch
+  // If widget sets lineOrPageDelta, EventStateManager will dispatch
   // NS_MOUSE_SCROLL event for compatibility.  Note that the delta value means
   // pages if the deltaMode is DOM_DELTA_PAGE, otherwise, lines.
   int32_t lineOrPageDeltaX;
   int32_t lineOrPageDeltaY;
 
   // When the default action for an wheel event is moving history or zooming,
   // need to chose a delta value for doing it.
   int32_t GetPreferredIntDelta()
@@ -488,32 +488,32 @@ public:
         (lineOrPageDeltaX > 0 && lineOrPageDeltaY < 0)) {
       return 0; // We cannot guess the answer in this case.
     }
     return (Abs(lineOrPageDeltaX) > Abs(lineOrPageDeltaY)) ?
              lineOrPageDeltaX : lineOrPageDeltaY;
   }
 
   // Scroll type
-  // The default value is SCROLL_DEFAULT, which means nsEventStateManager will
+  // The default value is SCROLL_DEFAULT, which means EventStateManager will
   // select preferred scroll type automatically.
   enum ScrollType
   {
     SCROLL_DEFAULT,
     SCROLL_SYNCHRONOUSLY,
     SCROLL_ASYNCHRONOUSELY,
     SCROLL_SMOOTHLY
   };
   ScrollType scrollType;
 
   // overflowed delta values for scroll, these values are set by
   // nsEventStateManger.  If the default action of the wheel event isn't scroll,
   // these values always zero.  Otherwise, remaning delta values which are
   // not used by scroll are set.
-  // NOTE: deltaX, deltaY and deltaZ may be modified by nsEventStateManager.
+  // NOTE: deltaX, deltaY and deltaZ may be modified by EventStateManager.
   //       However, overflowDeltaX and overflowDeltaY indicate unused original
   //       delta values which are not applied the delta_multiplier prefs.
   //       So, if widget wanted to know the actual direction to be scrolled,
   //       it would need to check the deltaX and deltaY.
   double overflowDeltaX;
   double overflowDeltaY;
 
   // Whether or not the parent of the currently overscrolled frame is the
--- a/widget/android/nsLookAndFeel.cpp
+++ b/widget/android/nsLookAndFeel.cpp
@@ -363,17 +363,17 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
             break;
 
         case eIntID_ShowCaretDuringSelection:
             aResult = 0;
             break;
 
         case eIntID_SelectTextfieldsOnKeyFocus:
             // Select textfield content when focused by kbd
-            // used by nsEventStateManager::sTextfieldSelectModel
+            // used by EventStateManager::sTextfieldSelectModel
             aResult = 1;
             break;
 
         case eIntID_SubmenuDelay:
             aResult = 200;
             break;
 
         case eIntID_TooltipDelay:
--- a/widget/cocoa/nsLookAndFeel.mm
+++ b/widget/cocoa/nsLookAndFeel.mm
@@ -306,17 +306,17 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
     case eIntID_CaretWidth:
       aResult = 1;
       break;
     case eIntID_ShowCaretDuringSelection:
       aResult = 0;
       break;
     case eIntID_SelectTextfieldsOnKeyFocus:
       // Select textfield content when focused by kbd
-      // used by nsEventStateManager::sTextfieldSelectModel
+      // used by EventStateManager::sTextfieldSelectModel
       aResult = 1;
       break;
     case eIntID_SubmenuDelay:
       aResult = 200;
       break;
     case eIntID_TooltipDelay:
       aResult = 500;
       break;
--- a/widget/gonk/nsLookAndFeel.cpp
+++ b/widget/gonk/nsLookAndFeel.cpp
@@ -320,17 +320,17 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
             break;
 
         case eIntID_ShowCaretDuringSelection:
             aResult = 0;
             break;
 
         case eIntID_SelectTextfieldsOnKeyFocus:
             // Select textfield content when focused by kbd
-            // used by nsEventStateManager::sTextfieldSelectModel
+            // used by EventStateManager::sTextfieldSelectModel
             aResult = 1;
             break;
 
         case eIntID_SubmenuDelay:
             aResult = 200;
             break;
 
         case eIntID_TooltipDelay:
--- a/widget/qt/nsLookAndFeel.cpp
+++ b/widget/qt/nsLookAndFeel.cpp
@@ -323,17 +323,17 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
             break;
 
         case eIntID_ShowCaretDuringSelection:
             aResult = 0;
             break;
 
         case eIntID_SelectTextfieldsOnKeyFocus:
             // Select textfield content when focused by kbd
-            // used by nsEventStateManager::sTextfieldSelectModel
+            // used by EventStateManager::sTextfieldSelectModel
             aResult = 1;
             break;
 
         case eIntID_SubmenuDelay:
             aResult = 200;
             break;
 
         case eIntID_TooltipDelay:
--- a/widget/shared/WidgetEventImpl.cpp
+++ b/widget/shared/WidgetEventImpl.cpp
@@ -213,17 +213,17 @@ WidgetEvent::IsTargetedAtFocusedContent(
 
 bool
 WidgetEvent::IsAllowedToDispatchDOMEvent() const
 {
   switch (eventStructType) {
     case NS_MOUSE_EVENT:
     case NS_POINTER_EVENT:
       // We want synthesized mouse moves to cause mouseover and mouseout
-      // DOM events (nsEventStateManager::PreHandleEvent), but not mousemove
+      // DOM events (EventStateManager::PreHandleEvent), but not mousemove
       // DOM events.
       // Synthesized button up events also do not cause DOM events because they
       // do not have a reliable refPoint.
       return AsMouseEvent()->reason == WidgetMouseEvent::eReal;
 
     case NS_WHEEL_EVENT: {
       // wheel event whose all delta values are zero by user pref applied, it
       // shouldn't cause a DOM event.
--- a/widget/windows/nsLookAndFeel.cpp
+++ b/widget/windows/nsLookAndFeel.cpp
@@ -335,17 +335,17 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
     case eIntID_CaretWidth:
         aResult = 1;
         break;
     case eIntID_ShowCaretDuringSelection:
         aResult = 0;
         break;
     case eIntID_SelectTextfieldsOnKeyFocus:
         // Select textfield content when focused by kbd
-        // used by nsEventStateManager::sTextfieldSelectModel
+        // used by EventStateManager::sTextfieldSelectModel
         aResult = 1;
         break;
     case eIntID_SubmenuDelay:
         // This will default to the Windows' default
         // (400ms) on error.
         aResult = GetSystemParam(SPI_GETMENUSHOWDELAY, 400);
         break;
     case eIntID_TooltipDelay:
--- a/widget/windows/winrt/MetroInput.cpp
+++ b/widget/windows/winrt/MetroInput.cpp
@@ -8,22 +8,22 @@
 #include "MetroUtils.h" // Logging, POINT_CEIL_*, ActivateGenericInstance, etc
 #include "MetroWidget.h" // MetroInput::mWidget
 #include "mozilla/dom/Touch.h"  // Touch
 #include "nsTArray.h" // Touch lists
 #include "nsIDOMSimpleGestureEvent.h" // Constants for gesture events
 #include "InputData.h"
 #include "UIABridgePrivate.h"
 #include "MetroAppShell.h"
+#include "mozilla/EventStateManager.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/Preferences.h"  // for Preferences
 #include "WinUtils.h"
 #include "nsIPresShell.h"
-#include "nsEventStateManager.h"
 
 // System headers (alphabetical)
 #include <windows.ui.core.h> // ABI::Window::UI::Core namespace
 #include <windows.ui.input.h> // ABI::Window::UI::Input namespace
 
 //#define DEBUG_INPUT
 
 // Using declarations
@@ -1123,17 +1123,17 @@ MetroInput::DeliverNextQueuedEventIgnore
     return;
   }
   if (mouseEvent->message != NS_MOUSE_BUTTON_UP ||
       mouseEvent->inputSource != nsIDOMMouseEvent::MOZ_SOURCE_TOUCH) {
     return;
   }
   nsCOMPtr<nsIPresShell> presShell = mWidget->GetPresShell();
   if (presShell) {
-    nsEventStateManager* esm = presShell->GetPresContext()->EventStateManager();
+    EventStateManager* esm = presShell->GetPresContext()->EventStateManager();
     if (esm) {
       esm->SetContentState(nullptr, NS_EVENT_STATE_HOVER);
     }
   }
 }
 
 void
 MetroInput::DispatchAsyncTouchEvent(WidgetTouchEvent* aEvent)
--- a/widget/xpwidgets/nsBaseWidget.cpp
+++ b/widget/xpwidgets/nsBaseWidget.cpp
@@ -23,17 +23,16 @@
 #include "mozilla/Preferences.h"
 #include "BasicLayers.h"
 #include "ClientLayerManager.h"
 #include "mozilla/layers/Compositor.h"
 #include "nsIXULRuntime.h"
 #include "nsIXULWindow.h"
 #include "nsIBaseWindow.h"
 #include "nsXULPopupManager.h"
-#include "nsEventStateManager.h"
 #include "nsIWidgetListener.h"
 #include "nsIGfxInfo.h"
 #include "npapi.h"
 #include "base/thread.h"
 #include "prdtoa.h"
 #include "prenv.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/unused.h"
--- a/widget/xpwidgets/nsNativeTheme.cpp
+++ b/widget/xpwidgets/nsNativeTheme.cpp
@@ -6,17 +6,16 @@
 #include "nsNativeTheme.h"
 #include "nsIWidget.h"
 #include "nsIDocument.h"
 #include "nsIContent.h"
 #include "nsIFrame.h"
 #include "nsIPresShell.h"
 #include "nsNumberControlFrame.h"
 #include "nsPresContext.h"
-#include "nsEventStateManager.h"
 #include "nsString.h"
 #include "nsNameSpaceManager.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMXULMenuListElement.h"
 #include "nsThemeConstants.h"
 #include "nsIComponentManager.h"
 #include "nsPIDOMWindow.h"
 #include "nsProgressFrame.h"
--- a/widget/xpwidgets/nsNativeTheme.h
+++ b/widget/xpwidgets/nsNativeTheme.h
@@ -38,17 +38,17 @@ class nsNativeTheme : public nsITimerCal
     eTreeSortDirection_Descending,
     eTreeSortDirection_Natural,
     eTreeSortDirection_Ascending
   };
 
   nsNativeTheme();
   virtual ~nsNativeTheme() {}
 
-  // Returns the content state (hover, focus, etc), see nsEventStateManager.h
+  // Returns the content state (hover, focus, etc), see EventStateManager.h
   nsEventStates GetContentState(nsIFrame* aFrame, uint8_t aWidgetType);
 
   // Returns whether the widget is already styled by content
   // Normally called from ThemeSupportsWidget to turn off native theming
   // for elements that are already styled.
   bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
                         uint8_t aWidgetType);