Backed out 9 changesets (bug 602787) on suspicion of breaking mochitest-metro on a CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Tue, 22 Oct 2013 13:11:53 -0400
changeset 166473 3c5efc154d58075cb9313eaff2b4987a609ecff6
parent 166472 1ae5d58532ad1ed31995d40c27a48e6c6be313c3
child 166474 dcd45c8ba5ff2fc43ded8b9dd52d347309b5704a
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs602787
milestone27.0a1
backs out1730bcae2c4508df2610db74e45e38207fbd8687
70606b9b1e4200eff4239bb224f64d38d1cf8cd7
57ca2861ea307d39f596cd3e06d4f168c028119f
3b9f1062d915eac40ae1d14dd56d7f262e60ab65
3ee56eacc84b198ee48ef65125c776d79542d452
1c35693be3d3c785e6c57bddc5a391ba72a06122
ef095c3aef98e1cc6cc2eaa573b5214d1eac2b1a
4827bdae97fdca3e04d1a6390500975c0901f1a7
fa0f355e78718f385c78b15125be040b0a588bad
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
Backed out 9 changesets (bug 602787) on suspicion of breaking mochitest-metro on a CLOSED TREE Backed out changeset 1730bcae2c45 (bug 602787) Backed out changeset 70606b9b1e42 (bug 602787) Backed out changeset 57ca2861ea30 (bug 602787) Backed out changeset 3b9f1062d915 (bug 602787) Backed out changeset 3ee56eacc84b (bug 602787) Backed out changeset 1c35693be3d3 (bug 602787) Backed out changeset ef095c3aef98 (bug 602787) Backed out changeset 4827bdae97fd (bug 602787) Backed out changeset fa0f355e7871 (bug 602787)
accessible/src/generic/Accessible.cpp
content/base/src/nsObjectLoadingContent.cpp
content/events/src/nsContentEventHandler.cpp
content/events/src/nsEventStateManager.cpp
content/events/src/nsEventStateManager.h
content/events/src/nsPrivateTextRange.h
content/html/content/src/HTMLFormElement.cpp
dom/base/CompositionStringSynthesizer.h
dom/ipc/TabParent.h
editor/libeditor/html/nsHTMLDataTransfer.cpp
layout/base/nsPresShell.cpp
layout/base/nsPresShell.h
layout/generic/Selection.h
layout/generic/nsFrameSelection.h
layout/generic/nsObjectFrame.cpp
layout/xul/base/src/nsMenuPopupFrame.cpp
layout/xul/base/src/nsXULPopupManager.cpp
view/public/nsView.h
view/src/nsViewManager.cpp
widget/EventForwards.h
widget/TextEvents.h
widget/TextRange.h
widget/android/nsWindow.h
widget/gtk/nsDragService.cpp
widget/gtk/nsWindow.h
widget/moz.build
widget/nsIWidgetListener.h
widget/qt/nsWindow.cpp
widget/qt/nsWindow.h
widget/windows/KeyboardLayout.cpp
widget/windows/KeyboardLayout.h
widget/windows/moz.build
widget/windows/nsTextStore.h
widget/windows/nsWindow.cpp
widget/windows/nsWindowBase.cpp
widget/windows/nsWindowBase.h
widget/xpwidgets/moz.build
widget/xpwidgets/nsIWidgetListener.cpp
xpfe/appshell/src/nsAppShellService.cpp
xpfe/appshell/src/nsChromeTreeOwner.cpp
xpfe/appshell/src/nsContentTreeOwner.cpp
xpfe/appshell/src/nsWebShellWindow.cpp
xpfe/appshell/src/nsWebShellWindow.h
xpfe/appshell/src/nsXULWindow.h
--- a/accessible/src/generic/Accessible.cpp
+++ b/accessible/src/generic/Accessible.cpp
@@ -25,17 +25,16 @@
 #include "TableAccessible.h"
 #include "TableCellAccessible.h"
 #include "TreeWalker.h"
 
 #include "nsIDOMElement.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMNodeFilter.h"
 #include "nsIDOMHTMLElement.h"
-#include "nsIDOMKeyEvent.h"
 #include "nsIDOMTreeWalker.h"
 #include "nsIDOMXULButtonElement.h"
 #include "nsIDOMXULDocument.h"
 #include "nsIDOMXULElement.h"
 #include "nsIDOMXULLabelElement.h"
 #include "nsIDOMXULSelectCntrlEl.h"
 #include "nsIDOMXULSelectCntrlItemEl.h"
 #include "nsPIDOMWindow.h"
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -73,17 +73,16 @@
 #include "GeckoProfiler.h"
 #include "nsObjectFrame.h"
 #include "nsDOMClassInfo.h"
 #include "nsWrapperCacheInlines.h"
 #include "nsDOMJSUtils.h"
 
 #include "nsWidgetsCID.h"
 #include "nsContentCID.h"
-#include "mozilla/BasicEvents.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/Telemetry.h"
 
 #ifdef XP_WIN
 // Thanks so much, Microsoft! :(
 #ifdef CreateEvent
 #undef CreateEvent
 #endif
--- a/content/events/src/nsContentEventHandler.cpp
+++ b/content/events/src/nsContentEventHandler.cpp
@@ -21,17 +21,16 @@
 #include "nsTextFrame.h"
 #include "nsISelectionController.h"
 #include "nsISelectionPrivate.h"
 #include "nsContentUtils.h"
 #include "nsLayoutUtils.h"
 #include "nsIMEStateManager.h"
 #include "nsIObjectFrame.h"
 #include "mozilla/dom/Element.h"
-#include "mozilla/TextEvents.h"
 #include <algorithm>
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 /******************************************************************/
 /* nsContentEventHandler                                          */
 /******************************************************************/
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -9,17 +9,16 @@
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/dom/TabParent.h"
 
 #include "nsCOMPtr.h"
 #include "nsEventStateManager.h"
-#include "nsFocusManager.h"
 #include "nsIMEStateManager.h"
 #include "nsContentEventHandler.h"
 #include "nsIContent.h"
 #include "nsINodeInfo.h"
 #include "nsIDocument.h"
 #include "nsIFrame.h"
 #include "nsIWidget.h"
 #include "nsPresContext.h"
@@ -1951,17 +1950,17 @@ nsEventStateManager::FireContextClick()
         if (frameSel && frameSel->GetMouseDownState()) {
           // note that this can cause selection changed events to fire if we're in
           // a text field, which will null out mCurrentTarget
           frameSel->SetMouseDownState(false);
         }
       }
 
       nsIDocument* doc = mGestureDownContent->GetCurrentDoc();
-      AutoHandlingUserInputStatePusher userInpStatePusher(true, &event, doc);
+      nsAutoHandlingUserInputStatePusher userInpStatePusher(true, &event, doc);
 
       // dispatch to DOM
       nsEventDispatcher::Dispatch(mGestureDownContent, mPresContext, &event,
                                   nullptr, &status);
 
       // We don't need to dispatch to frame handling because no frames
       // watch NS_CONTEXTMENU except for nsMenuFrame and that's only for
       // dismissal. That's just as well since we don't really know
@@ -5844,56 +5843,9 @@ nsEventStateManager::Prefs::GetAccessMod
       return sChromeAccessModifierMask;
     case nsIDocShellTreeItem::typeContent:
       return sContentAccessModifierMask;
     default:
       return 0;
   }
 }
 
-/******************************************************************/
-/* mozilla::AutoHandlingUserInputStatePusher                      */
-/******************************************************************/
-
-AutoHandlingUserInputStatePusher::AutoHandlingUserInputStatePusher(
-                                    bool aIsHandlingUserInput,
-                                    WidgetEvent* aEvent,
-                                    nsIDocument* aDocument) :
-  mIsHandlingUserInput(aIsHandlingUserInput),
-  mIsMouseDown(aEvent && aEvent->message == NS_MOUSE_BUTTON_DOWN),
-  mResetFMMouseDownState(false)
-{
-  if (!aIsHandlingUserInput) {
-    return;
-  }
-  nsEventStateManager::StartHandlingUserInput();
-  if (!mIsMouseDown) {
-    return;
-  }
-  nsIPresShell::SetCapturingContent(nullptr, 0);
-  nsIPresShell::AllowMouseCapture(true);
-  if (!aDocument || !aEvent->mFlags.mIsTrusted) {
-    return;
-  }
-  nsFocusManager* fm = nsFocusManager::GetFocusManager();
-  NS_ENSURE_TRUE_VOID(fm);
-  fm->SetMouseButtonDownHandlingDocument(aDocument);
-  mResetFMMouseDownState = true;
-}
-
-AutoHandlingUserInputStatePusher::~AutoHandlingUserInputStatePusher()
-{
-  if (!mIsHandlingUserInput) {
-    return;
-  }
-  nsEventStateManager::StopHandlingUserInput();
-  if (!mIsMouseDown) {
-    return;
-  }
-  nsIPresShell::AllowMouseCapture(false);
-  if (!mResetFMMouseDownState) {
-    return;
-  }
-  nsFocusManager* fm = nsFocusManager::GetFocusManager();
-  NS_ENSURE_TRUE_VOID(fm);
-  fm->SetMouseButtonDownHandlingDocument(nullptr);
-}
-
+
--- a/content/events/src/nsEventStateManager.h
+++ b/content/events/src/nsEventStateManager.h
@@ -1,29 +1,30 @@
 /* -*- 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__
 
+#include "mozilla/BasicEvents.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/TypedEnum.h"
 
 #include "nsIObserver.h"
 #include "nsWeakReference.h"
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "nsCycleCollectionParticipant.h"
+#include "nsFocusManager.h"
 #include "mozilla/TimeStamp.h"
 #include "nsIFrame.h"
 #include "Units.h"
 
-class nsFrameLoader;
 class nsIContent;
 class nsIDocument;
 class nsIDocShell;
 class nsIDocShellTreeNode;
 class nsIDocShellTreeItem;
 class imgIContainer;
 class nsDOMDataTransfer;
 class MouseEnterLeaveDispatcher;
@@ -841,43 +842,73 @@ public:
                             mozilla::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
+class nsAutoHandlingUserInputStatePusher
 {
 public:
-  AutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
-                                   WidgetEvent* aEvent,
-                                   nsIDocument* aDocument);
-  ~AutoHandlingUserInputStatePusher();
+  nsAutoHandlingUserInputStatePusher(bool aIsHandlingUserInput,
+                                     mozilla::WidgetEvent* aEvent,
+                                     nsIDocument* aDocument)
+    : mIsHandlingUserInput(aIsHandlingUserInput),
+      mIsMouseDown(aEvent && aEvent->message == NS_MOUSE_BUTTON_DOWN),
+      mResetFMMouseDownState(false)
+  {
+    if (aIsHandlingUserInput) {
+      nsEventStateManager::StartHandlingUserInput();
+      if (mIsMouseDown) {
+        nsIPresShell::SetCapturingContent(nullptr, 0);
+        nsIPresShell::AllowMouseCapture(true);
+        if (aDocument && aEvent->mFlags.mIsTrusted) {
+          nsFocusManager* fm = nsFocusManager::GetFocusManager();
+          if (fm) {
+            fm->SetMouseButtonDownHandlingDocument(aDocument);
+            mResetFMMouseDownState = true;
+          }
+        }
+      }
+    }
+  }
+
+  ~nsAutoHandlingUserInputStatePusher()
+  {
+    if (mIsHandlingUserInput) {
+      nsEventStateManager::StopHandlingUserInput();
+      if (mIsMouseDown) {
+        nsIPresShell::AllowMouseCapture(false);
+        if (mResetFMMouseDownState) {
+          nsFocusManager* fm = nsFocusManager::GetFocusManager();
+          if (fm) {
+            fm->SetMouseButtonDownHandlingDocument(nullptr);
+          }
+        }
+      }
+    }
+  }
 
 protected:
   bool mIsHandlingUserInput;
   bool mIsMouseDown;
   bool mResetFMMouseDownState;
 
 private:
   // Hide so that this class can only be stack-allocated
   static void* operator new(size_t /*size*/) CPP_THROW_NEW { return nullptr; }
   static void operator delete(void* /*memory*/) {}
 };
 
-} // namespace mozilla
-
 // 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__
--- a/content/events/src/nsPrivateTextRange.h
+++ b/content/events/src/nsPrivateTextRange.h
@@ -5,17 +5,17 @@
 
 #ifndef nsPrivateTextRange_h__
 #define nsPrivateTextRange_h__
 
 #include "nsIPrivateTextRange.h"
 #include "nsTArray.h"
 #include "nsAutoPtr.h"
 #include "mozilla/Attributes.h"
-#include "mozilla/TextRange.h"
+#include "mozilla/TextEvents.h"
 
 class nsPrivateTextRange MOZ_FINAL : public nsIPrivateTextRange
 {
 	NS_DECL_ISUPPORTS
 public:
 
 	nsPrivateTextRange(const mozilla::TextRange &aTextRange);
 	virtual ~nsPrivateTextRange(void);
--- a/content/html/content/src/HTMLFormElement.cpp
+++ b/content/html/content/src/HTMLFormElement.cpp
@@ -802,19 +802,19 @@ HTMLFormElement::SubmitSubmission(nsForm
   //
   // Submit
   //
   nsCOMPtr<nsIDocShell> docShell;
 
   {
     nsAutoPopupStatePusher popupStatePusher(mSubmitPopupState);
 
-    AutoHandlingUserInputStatePusher userInpStatePusher(
-                                       mSubmitInitiatedFromUserInput,
-                                       nullptr, doc);
+    nsAutoHandlingUserInputStatePusher userInpStatePusher(
+                                         mSubmitInitiatedFromUserInput,
+                                         nullptr, doc);
 
     nsCOMPtr<nsIInputStream> postDataStream;
     rv = aFormSubmission->GetEncodedSubmission(actionURI,
                                                getter_AddRefs(postDataStream));
     NS_ENSURE_SUBMIT_SUCCESS(rv);
 
     rv = linkHandler->OnLinkClickSync(this, actionURI,
                                       target.get(),
--- a/dom/base/CompositionStringSynthesizer.h
+++ b/dom/base/CompositionStringSynthesizer.h
@@ -6,17 +6,17 @@
 #ifndef mozilla_dom_compositionstringsynthesizer_h__
 #define mozilla_dom_compositionstringsynthesizer_h__
 
 #include "nsICompositionStringSynthesizer.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsWeakReference.h"
 #include "mozilla/Attributes.h"
-#include "mozilla/TextRange.h"
+#include "mozilla/TextEvents.h"
 
 class nsIWidget;
 class nsPIDOMWindow;
 
 namespace mozilla {
 namespace dom {
 
 class CompositionStringSynthesizer MOZ_FINAL :
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -2,20 +2,20 @@
 /* vim: set sw=4 ts=8 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/. */
 
 #ifndef mozilla_tabs_TabParent_h
 #define mozilla_tabs_TabParent_h
 
-#include "mozilla/EventForwards.h"
 #include "mozilla/dom/PBrowserParent.h"
 #include "mozilla/dom/PContentDialogParent.h"
 #include "mozilla/dom/TabContext.h"
+#include "mozilla/TouchEvents.h"
 #include "nsCOMPtr.h"
 #include "nsIAuthPromptProvider.h"
 #include "nsIBrowserDOMWindow.h"
 #include "nsIDialogParamBlock.h"
 #include "nsISecureBrowserUI.h"
 #include "nsITabParent.h"
 #include "Units.h"
 #include "js/TypeDecls.h"
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -3,17 +3,16 @@
 /* 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 <string.h>
 
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/Base64.h"
-#include "mozilla/BasicEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Selection.h"
 #include "mozilla/Util.h"
 #include "nsAString.h"
 #include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -6101,17 +6101,18 @@ PresShell::HandleEvent(nsIFrame* aFrame,
     }
   }
 
   if (aEvent->eventStructType == NS_KEY_EVENT &&
       mDocument && mDocument->EventHandlingSuppressed()) {
     if (aEvent->message == NS_KEY_DOWN) {
       mNoDelayedKeyEvents = true;
     } else if (!mNoDelayedKeyEvents) {
-      DelayedEvent* event = new DelayedKeyEvent(aEvent->AsKeyboardEvent());
+      nsDelayedEvent* event =
+        new nsDelayedKeyEvent(aEvent->AsKeyboardEvent());
       if (!mDelayedEvents.AppendElement(event)) {
         delete event;
       }
     }
     return NS_OK;
   }
 
   nsIFrame* frame = aFrame;
@@ -6329,17 +6330,17 @@ PresShell::HandleEvent(nsIFrame* aFrame,
 
     // Suppress mouse event if it's being targeted at an element inside
     // a document which needs events suppressed
     if (aEvent->eventStructType == NS_MOUSE_EVENT &&
         frame->PresContext()->Document()->EventHandlingSuppressed()) {
       if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
         mNoDelayedMouseEvents = true;
       } else if (!mNoDelayedMouseEvents && aEvent->message == NS_MOUSE_BUTTON_UP) {
-        DelayedEvent* event = new DelayedMouseEvent(aEvent->AsMouseEvent());
+        nsDelayedEvent* event = new nsDelayedMouseEvent(aEvent->AsMouseEvent());
         if (!mDelayedEvents.AppendElement(event)) {
           delete event;
         }
       }
 
       return NS_OK;
     }
 
@@ -6862,18 +6863,18 @@ PresShell::HandleEventInternal(WidgetEve
         return NS_OK;
       }
       if (mouseEvent->IsShift()) {
         aEvent->mFlags.mOnlyChromeDispatch = true;
         aEvent->mFlags.mRetargetToNonNativeAnonymous = true;
       }
     }
 
-    AutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput,
-                                                        aEvent, mDocument);
+    nsAutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput,
+                                                          aEvent, mDocument);
 
     if (aEvent->mFlags.mIsTrusted && aEvent->message == NS_MOUSE_MOVE) {
       nsIPresShell::AllowMouseCapture(
         nsEventStateManager::GetActiveEventStateManager() == manager);
     }
 
     nsAutoPopupStatePusher popupStatePusher(nsDOMEvent::GetEventPopupControlState(aEvent));
 
@@ -7622,19 +7623,19 @@ PresShell::FireOrClearDelayedEvents(bool
     mDelayedEvents.Clear();
     return;
   }
 
   if (mDocument) {
     nsCOMPtr<nsIDocument> doc = mDocument;
     while (!mIsDestroying && mDelayedEvents.Length() &&
            !doc->EventHandlingSuppressed()) {
-      nsAutoPtr<DelayedEvent> ev(mDelayedEvents[0].forget());
+      nsAutoPtr<nsDelayedEvent> ev(mDelayedEvents[0].forget());
       mDelayedEvents.RemoveElementAt(0);
-      ev->Dispatch();
+      ev->Dispatch(this);
     }
     if (!doc->EventHandlingSuppressed()) {
       mDelayedEvents.Clear();
     }
   }
 }
 
 static void
@@ -8335,66 +8336,16 @@ nsIPresShell::RemovePostRefreshObserver(
   presContext->RefreshDriver()->RemovePostRefreshObserver(aObserver);
   return true;
 }
 
 //------------------------------------------------------
 // End of protected and private methods on the PresShell
 //------------------------------------------------------
 
-//------------------------------------------------------------------
-//-- Delayed event Classes Impls
-//------------------------------------------------------------------
-
-PresShell::DelayedInputEvent::DelayedInputEvent() :
-  DelayedEvent(),
-  mEvent(nullptr)
-{
-}
-
-PresShell::DelayedInputEvent::~DelayedInputEvent()
-{
-  delete mEvent;
-}
-
-void
-PresShell::DelayedInputEvent::Dispatch()
-{
-  if (!mEvent || !mEvent->widget) {
-    return;
-  }
-  nsCOMPtr<nsIWidget> widget = mEvent->widget;
-  nsEventStatus status;
-  widget->DispatchEvent(mEvent, status);
-}
-
-PresShell::DelayedMouseEvent::DelayedMouseEvent(WidgetMouseEvent* aEvent) :
-  DelayedInputEvent()
-{
-  WidgetMouseEvent* mouseEvent =
-    new WidgetMouseEvent(aEvent->mFlags.mIsTrusted,
-                         aEvent->message,
-                         aEvent->widget,
-                         aEvent->reason,
-                         aEvent->context);
-  mouseEvent->AssignMouseEventData(*aEvent, false);
-  mEvent = mouseEvent;
-}
-
-PresShell::DelayedKeyEvent::DelayedKeyEvent(WidgetKeyboardEvent* aEvent) :
-  DelayedInputEvent()
-{
-  WidgetKeyboardEvent* keyEvent =
-    new WidgetKeyboardEvent(aEvent->mFlags.mIsTrusted,
-                            aEvent->message,
-                            aEvent->widget);
-  keyEvent->AssignKeyEventData(*aEvent, false);
-  mEvent = keyEvent;
-}
-
 // Start of DEBUG only code
 
 #ifdef DEBUG
 
 static void
 LogVerifyMessage(nsIFrame* k1, nsIFrame* k2, const char* aMsg)
 {
   nsAutoString n1, n2;
--- a/layout/base/nsPresShell.h
+++ b/layout/base/nsPresShell.h
@@ -29,18 +29,19 @@
 #include "nsCRT.h"
 #include "nsAutoPtr.h"
 #include "nsIWidget.h"
 #include "nsStyleSet.h"
 #include "nsFrameSelection.h"
 #include "nsContentUtils.h" // For AddScriptBlocker().
 #include "nsRefreshDriver.h"
 #include "mozilla/Attributes.h"
-#include "mozilla/EventForwards.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/MouseEvents.h"
+#include "mozilla/TextEvents.h"
 
 class nsRange;
 class nsIDragService;
 class nsCSSStyleSheet;
 
 struct RangePaintInfo;
 struct nsCallbackEventRequest;
 #ifdef MOZ_REFLOW_PERF
@@ -541,45 +542,77 @@ protected:
     nsresult rv = NS_OK;
     if (GetCurrentEventFrame()) {
       rv = HandleEventInternal(aEvent, aStatus);
     }
     PopCurrentEventInfo();
     return rv;
   }
 
-  class DelayedEvent
+  class nsDelayedEvent
   {
   public:
-    virtual ~DelayedEvent() { }
-    virtual void Dispatch() { }
+    virtual ~nsDelayedEvent() {};
+    virtual void Dispatch(PresShell* aShell) {}
   };
 
-  class DelayedInputEvent : public DelayedEvent
+  class nsDelayedInputEvent : public nsDelayedEvent
   {
   public:
-    virtual void Dispatch() MOZ_OVERRIDE;
+    virtual void Dispatch(PresShell* aShell)
+    {
+      if (mEvent && mEvent->widget) {
+        nsCOMPtr<nsIWidget> w = mEvent->widget;
+        nsEventStatus status;
+        w->DispatchEvent(mEvent, status);
+      }
+    }
 
   protected:
-    DelayedInputEvent();
-    virtual ~DelayedInputEvent();
+    nsDelayedInputEvent()
+    : nsDelayedEvent(), mEvent(nullptr) {}
+
+    virtual ~nsDelayedInputEvent()
+    {
+      delete mEvent;
+    }
 
     mozilla::WidgetInputEvent* mEvent;
   };
 
-  class DelayedMouseEvent : public DelayedInputEvent
+  class nsDelayedMouseEvent : public nsDelayedInputEvent
   {
   public:
-    DelayedMouseEvent(mozilla::WidgetMouseEvent* aEvent);
+    nsDelayedMouseEvent(mozilla::WidgetMouseEvent* aEvent) :
+      nsDelayedInputEvent()
+    {
+      mozilla::WidgetMouseEvent* mouseEvent =
+        new mozilla::WidgetMouseEvent(aEvent->mFlags.mIsTrusted,
+                                      aEvent->message,
+                                      aEvent->widget,
+                                      aEvent->reason,
+                                      aEvent->context);
+      mouseEvent->AssignMouseEventData(*aEvent, false);
+      mEvent = mouseEvent;
+    }
   };
 
-  class DelayedKeyEvent : public DelayedInputEvent
+  class nsDelayedKeyEvent : public nsDelayedInputEvent
   {
   public:
-    DelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent);
+    nsDelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent) :
+      nsDelayedInputEvent()
+    {
+      mozilla::WidgetKeyboardEvent* keyEvent =
+        new mozilla::WidgetKeyboardEvent(aEvent->mFlags.mIsTrusted,
+                                         aEvent->message,
+                                         aEvent->widget);
+      keyEvent->AssignKeyEventData(*aEvent, false);
+      mEvent = keyEvent;
+    }
   };
 
   // Check if aEvent is a mouse event and record the mouse location for later
   // synth mouse moves.
   void RecordMouseLocation(mozilla::WidgetGUIEvent* aEvent);
   class nsSynthMouseMoveEvent MOZ_FINAL : public nsARefreshObserver {
   public:
     nsSynthMouseMoveEvent(PresShell* aPresShell, bool aFromScroll)
@@ -721,17 +754,17 @@ protected:
 
   // Set of frames that we should mark with NS_FRAME_HAS_DIRTY_CHILDREN after
   // we finish reflowing mCurrentReflowRoot.
   nsTHashtable<nsPtrHashKey<nsIFrame> > mFramesToDirty;
 
   // Reflow roots that need to be reflowed.
   nsTArray<nsIFrame*>       mDirtyRoots;
 
-  nsTArray<nsAutoPtr<DelayedEvent> > mDelayedEvents;
+  nsTArray<nsAutoPtr<nsDelayedEvent> > mDelayedEvents;
   nsRevocableEventPtr<nsRunnableMethod<PresShell> > mResizeEvent;
   nsCOMPtr<nsITimer>        mAsyncResizeEventTimer;
 private:
   nsIFrame*                 mCurrentEventFrame;
   nsCOMPtr<nsIContent>      mCurrentEventContent;
   nsTArray<nsIFrame*>       mCurrentEventFrameStack;
   nsCOMArray<nsIContent>    mCurrentEventContentStack;
 protected:
--- a/layout/generic/Selection.h
+++ b/layout/generic/Selection.h
@@ -9,17 +9,17 @@
 
 #include "nsIWeakReference.h"
 
 #include "nsISelection.h"
 #include "nsISelectionController.h"
 #include "nsISelectionPrivate.h"
 #include "nsRange.h"
 #include "nsThreadUtils.h"
-#include "mozilla/TextRange.h"
+#include "mozilla/TextEvents.h"
 
 struct CachedOffsetForFrame;
 class nsAutoScrollTimer;
 class nsIContentIterator;
 class nsIFrame;
 class nsFrameSelection;
 struct SelectionDetails;
 
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsFrameSelection_h___
 #define nsFrameSelection_h___
 
 #include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/Selection.h"
-#include "mozilla/TextRange.h"
+#include "mozilla/TextEvents.h"
 #include "nsIFrame.h"
 #include "nsIContent.h"
 #include "nsISelectionController.h"
 #include "nsITableCellLayout.h"
 #include "nsIDOMElement.h"
 #include "nsRange.h"
 
 class nsTableOuterFrame;
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -140,16 +140,17 @@ extern "C" {
   extern void DisposeGWorld(GWorldPtr offscreenGWorld)
     __attribute__((weak_import));
   #endif /* __QDOFFSCREEN__ */
 }
 
 #endif /* #if defined(XP_MACOSX) && !defined(__LP64__) */
 
 using namespace mozilla;
+using namespace mozilla::plugins;
 using namespace mozilla::layers;
 
 class PluginBackgroundSink : public ReadbackSink {
 public:
   PluginBackgroundSink(nsObjectFrame* aFrame, uint64_t aStartSequenceNumber)
     : mLastSequenceNumber(aStartSequenceNumber), mFrame(aFrame) {}
   ~PluginBackgroundSink()
   {
@@ -1785,17 +1786,17 @@ nsObjectFrame::PaintPlugin(nsDisplayList
       nsPoint origin;
 
       gfxWindowsNativeDrawing nativeDraw(ctx, frameGfxRect);
       if (nativeDraw.IsDoublePass()) {
         // OOP plugin specific: let the shim know before we paint if we are doing a
         // double pass render. If this plugin isn't oop, the register window message
         // will be ignored.
         NPEvent pluginEvent;
-        pluginEvent.event = plugins::DoublePassRenderingEvent();
+        pluginEvent.event = DoublePassRenderingEvent();
         pluginEvent.wParam = 0;
         pluginEvent.lParam = 0;
         if (pluginEvent.event)
           inst->HandleEvent(&pluginEvent, nullptr);
       }
       do {
         HDC hdc = nativeDraw.BeginNativeDrawing();
         if (!hdc)
--- a/layout/xul/base/src/nsMenuPopupFrame.cpp
+++ b/layout/xul/base/src/nsMenuPopupFrame.cpp
@@ -14,17 +14,16 @@
 #include "nsINameSpaceManager.h"
 #include "nsViewManager.h"
 #include "nsWidgetsCID.h"
 #include "nsMenuFrame.h"
 #include "nsMenuBarFrame.h"
 #include "nsPopupSetFrame.h"
 #include "nsEventDispatcher.h"
 #include "nsPIDOMWindow.h"
-#include "nsIDOMKeyEvent.h"
 #include "nsIDOMScreen.h"
 #include "nsIPresShell.h"
 #include "nsFrameManager.h"
 #include "nsIDocument.h"
 #include "nsRect.h"
 #include "nsIComponentManager.h"
 #include "nsBoxLayoutState.h"
 #include "nsIScrollableFrame.h"
@@ -1646,17 +1645,17 @@ nsMenuPopupFrame::FindMenuWithShortcut(n
   bool isMenu = parentContent &&
                   !parentContent->NodeInfo()->Equals(nsGkAtoms::menulist, kNameSpaceID_XUL);
 
   static DOMTimeStamp lastKeyTime = 0;
   DOMTimeStamp keyTime;
   aKeyEvent->GetTimeStamp(&keyTime);
 
   if (charCode == 0) {
-    if (keyCode == nsIDOMKeyEvent::DOM_VK_BACK_SPACE) {
+    if (keyCode == NS_VK_BACK) {
       if (!isMenu && !mIncrementalString.IsEmpty()) {
         mIncrementalString.SetLength(mIncrementalString.Length() - 1);
         return nullptr;
       }
       else {
 #ifdef XP_WIN
         nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
         if (soundInterface)
--- a/layout/xul/base/src/nsXULPopupManager.cpp
+++ b/layout/xul/base/src/nsXULPopupManager.cpp
@@ -1841,18 +1841,17 @@ nsXULPopupManager::HandleKeyboardNavigat
   if (item)
     itemFrame = item->Frame();
   else if (mActiveMenuBar)
     itemFrame = mActiveMenuBar;
   else
     return false;
 
   nsNavigationDirection theDirection;
-  NS_ASSERTION(aKeyCode >= nsIDOMKeyEvent::DOM_VK_END &&
-                 aKeyCode <= nsIDOMKeyEvent::DOM_VK_DOWN, "Illegal key code");
+  NS_ASSERTION(aKeyCode >= NS_VK_END && aKeyCode <= NS_VK_DOWN, "Illegal key code");
   theDirection = NS_DIRECTION_FROM_KEY_CODE(itemFrame, aKeyCode);
 
   // if a popup is open, first check for navigation within the popup
   if (item && HandleKeyboardNavigationInPopup(item, theDirection))
     return true;
 
   // no popup handled the key, so check the active menubar, if any
   if (mActiveMenuBar) {
@@ -2350,18 +2349,18 @@ nsXULMenuCommandEvent::Run()
     nsPresContext* presContext = menuFrame->PresContext();
     nsCOMPtr<nsIPresShell> shell = presContext->PresShell();
     nsRefPtr<nsViewManager> kungFuDeathGrip = shell->GetViewManager();
 
     // Deselect ourselves.
     if (mCloseMenuMode != CloseMenuMode_None)
       menuFrame->SelectMenu(false);
 
-    AutoHandlingUserInputStatePusher userInpStatePusher(mUserInput, nullptr,
-                                                        shell->GetDocument());
+    nsAutoHandlingUserInputStatePusher userInpStatePusher(mUserInput, nullptr,
+                                                          shell->GetDocument());
     nsContentUtils::DispatchXULCommand(mMenu, mIsTrusted, nullptr, shell,
                                        mControl, mAlt, mShift, mMeta);
   }
 
   if (popup && mCloseMenuMode != CloseMenuMode_None)
     pm->HidePopup(popup, mCloseMenuMode == CloseMenuMode_Auto, true, false);
 
   return NS_OK;
--- a/view/public/nsView.h
+++ b/view/public/nsView.h
@@ -6,17 +6,16 @@
 #ifndef nsView_h__
 #define nsView_h__
 
 #include "nsCoord.h"
 #include "nsRect.h"
 #include "nsPoint.h"
 #include "nsRegion.h"
 #include "nsCRT.h"
-#include "nsWidgetInitData.h" // for nsWindowType
 #include "nsIWidgetListener.h"
 #include "mozilla/EventForwards.h"
 
 class nsViewManager;
 class nsIWidget;
 class nsIFrame;
 
 // Enumerated type to indicate the visibility of a layer.
--- a/view/src/nsViewManager.cpp
+++ b/view/src/nsViewManager.cpp
@@ -22,17 +22,16 @@
 #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"
-#include "nsIDocument.h"
 
 /**
    XXX TODO XXX
 
    DeCOMify newly private methods
    Optimize view storage
 */
 
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -59,18 +59,16 @@ namespace mozilla {
 #undef NS_EVENT_CLASS
 #undef NS_ROOT_EVENT_CLASS
 
 // BasicEvents.h
 struct EventFlags;
 
 // TextEvents.h
 struct AlternativeCharCode;
-
-// TextRange.h
 struct TextRangeStyle;
 struct TextRange;
 
 typedef TextRange* TextRangeArray;
 
 } // namespace mozilla
 
 #endif // mozilla_EventForwards_h__
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -6,22 +6,23 @@
 #ifndef mozilla_TextEvents_h__
 #define mozilla_TextEvents_h__
 
 #include <stdint.h>
 
 #include "mozilla/Assertions.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/EventForwards.h" // for KeyNameIndex, temporarily
-#include "mozilla/TextRange.h"
+#include "nsColor.h"
 #include "nsCOMPtr.h"
 #include "nsIDOMKeyEvent.h"
 #include "nsITransferable.h"
 #include "nsRect.h"
 #include "nsStringGlue.h"
+#include "nsStyleConsts.h"
 #include "nsTArray.h"
 
 /******************************************************************************
  * virtual keycode values
  ******************************************************************************/
 
 #define NS_DEFINE_VK(aDOMKeyName, aDOMKeyCode) NS_##aDOMKeyName = aDOMKeyCode
 
@@ -144,16 +145,158 @@ public:
     // Don't copy mNativeKeyEvent because it may be referred after its instance
     // is destroyed.
     mNativeKeyEvent = nullptr;
     mUniqueId = aEvent.mUniqueId;
   }
 };
 
 /******************************************************************************
+ * mozilla::TextRangeStyle
+ ******************************************************************************/
+
+struct TextRangeStyle
+{
+  enum {
+    LINESTYLE_NONE   = NS_STYLE_TEXT_DECORATION_STYLE_NONE,
+    LINESTYLE_SOLID  = NS_STYLE_TEXT_DECORATION_STYLE_SOLID,
+    LINESTYLE_DOTTED = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED,
+    LINESTYLE_DASHED = NS_STYLE_TEXT_DECORATION_STYLE_DASHED,
+    LINESTYLE_DOUBLE = NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE,
+    LINESTYLE_WAVY   = NS_STYLE_TEXT_DECORATION_STYLE_WAVY
+  };
+
+  enum {
+    DEFINED_NONE             = 0x00,
+    DEFINED_LINESTYLE        = 0x01,
+    DEFINED_FOREGROUND_COLOR = 0x02,
+    DEFINED_BACKGROUND_COLOR = 0x04,
+    DEFINED_UNDERLINE_COLOR  = 0x08
+  };
+
+  // Initialize all members, because TextRange instances may be compared by
+  // memcomp.
+  TextRangeStyle()
+  {
+    Clear();
+  }
+
+  void Clear()
+  {
+    mDefinedStyles = DEFINED_NONE;
+    mLineStyle = LINESTYLE_NONE;
+    mIsBoldLine = false;
+    mForegroundColor = mBackgroundColor = mUnderlineColor = NS_RGBA(0, 0, 0, 0);
+  }
+
+  bool IsDefined() const { return mDefinedStyles != DEFINED_NONE; }
+
+  bool IsLineStyleDefined() const
+  {
+    return (mDefinedStyles & DEFINED_LINESTYLE) != 0;
+  }
+
+  bool IsForegroundColorDefined() const
+  {
+    return (mDefinedStyles & DEFINED_FOREGROUND_COLOR) != 0;
+  }
+
+  bool IsBackgroundColorDefined() const
+  {
+    return (mDefinedStyles & DEFINED_BACKGROUND_COLOR) != 0;
+  }
+
+  bool IsUnderlineColorDefined() const
+  {
+    return (mDefinedStyles & DEFINED_UNDERLINE_COLOR) != 0;
+  }
+
+  bool IsNoChangeStyle() const
+  {
+    return !IsForegroundColorDefined() && !IsBackgroundColorDefined() &&
+           IsLineStyleDefined() && mLineStyle == LINESTYLE_NONE;
+  }
+
+  bool Equals(const TextRangeStyle& aOther)
+  {
+    if (mDefinedStyles != aOther.mDefinedStyles)
+      return false;
+    if (IsLineStyleDefined() && (mLineStyle != aOther.mLineStyle ||
+                                 !mIsBoldLine != !aOther.mIsBoldLine))
+      return false;
+    if (IsForegroundColorDefined() &&
+        (mForegroundColor != aOther.mForegroundColor))
+      return false;
+    if (IsBackgroundColorDefined() &&
+        (mBackgroundColor != aOther.mBackgroundColor))
+      return false;
+    if (IsUnderlineColorDefined() &&
+        (mUnderlineColor != aOther.mUnderlineColor))
+      return false;
+    return true;
+  }
+
+  bool operator !=(const TextRangeStyle &aOther)
+  {
+    return !Equals(aOther);
+  }
+
+  bool operator ==(const TextRangeStyle &aOther)
+  {
+    return Equals(aOther);
+  }
+
+  uint8_t mDefinedStyles;
+  uint8_t mLineStyle;        // DEFINED_LINESTYLE
+
+  bool mIsBoldLine;  // DEFINED_LINESTYLE
+
+  nscolor mForegroundColor;  // DEFINED_FOREGROUND_COLOR
+  nscolor mBackgroundColor;  // DEFINED_BACKGROUND_COLOR
+  nscolor mUnderlineColor;   // DEFINED_UNDERLINE_COLOR
+};
+
+/******************************************************************************
+ * mozilla::TextRange
+ ******************************************************************************/
+
+// Sync with nsIPrivateTextRange.h when you change these constants.
+#define NS_TEXTRANGE_CARETPOSITION         0x01
+#define NS_TEXTRANGE_RAWINPUT              0x02
+#define NS_TEXTRANGE_SELECTEDRAWTEXT       0x03
+#define NS_TEXTRANGE_CONVERTEDTEXT         0x04
+#define NS_TEXTRANGE_SELECTEDCONVERTEDTEXT 0x05
+
+struct TextRange
+{
+  TextRange() :
+    mStartOffset(0), mEndOffset(0), mRangeType(0)
+  {
+  }
+
+  uint32_t mStartOffset;
+  // XXX Storing end offset makes the initializing code very complicated.
+  //     We should replace it with mLength.
+  uint32_t mEndOffset;
+  uint32_t mRangeType;
+
+  TextRangeStyle mRangeStyle;
+
+  uint32_t Length() const { return mEndOffset - mStartOffset; }
+};
+
+/******************************************************************************
+ * mozilla::TextRangeArray
+ *
+ * XXX This should be replaced with nsTArray<TextRange>.
+ ******************************************************************************/
+
+typedef TextRange* TextRangeArray;
+
+/******************************************************************************
  * mozilla::WidgetTextEvent
  *
  * XXX WidgetTextEvent is fired with compositionupdate event almost every time.
  *     This wastes performance and the cost of mantaining each platform's
  *     implementation.  Therefore, we should merge WidgetTextEvent and
  *     WidgetCompositionEvent.  Then, DOM compositionupdate should be fired
  *     from TextComposition automatically.
  ******************************************************************************/
deleted file mode 100644
--- a/widget/TextRange.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_TextRage_h_
-#define mozilla_TextRage_h_
-
-#include <stdint.h>
-
-#include "nsColor.h"
-#include "nsStyleConsts.h"
-
-namespace mozilla {
-
-/******************************************************************************
- * mozilla::TextRangeStyle
- ******************************************************************************/
-
-struct TextRangeStyle
-{
-  enum
-  {
-    LINESTYLE_NONE   = NS_STYLE_TEXT_DECORATION_STYLE_NONE,
-    LINESTYLE_SOLID  = NS_STYLE_TEXT_DECORATION_STYLE_SOLID,
-    LINESTYLE_DOTTED = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED,
-    LINESTYLE_DASHED = NS_STYLE_TEXT_DECORATION_STYLE_DASHED,
-    LINESTYLE_DOUBLE = NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE,
-    LINESTYLE_WAVY   = NS_STYLE_TEXT_DECORATION_STYLE_WAVY
-  };
-
-  enum
-  {
-    DEFINED_NONE             = 0x00,
-    DEFINED_LINESTYLE        = 0x01,
-    DEFINED_FOREGROUND_COLOR = 0x02,
-    DEFINED_BACKGROUND_COLOR = 0x04,
-    DEFINED_UNDERLINE_COLOR  = 0x08
-  };
-
-  // Initialize all members, because TextRange instances may be compared by
-  // memcomp.
-  TextRangeStyle()
-  {
-    Clear();
-  }
-
-  void Clear()
-  {
-    mDefinedStyles = DEFINED_NONE;
-    mLineStyle = LINESTYLE_NONE;
-    mIsBoldLine = false;
-    mForegroundColor = mBackgroundColor = mUnderlineColor = NS_RGBA(0, 0, 0, 0);
-  }
-
-  bool IsDefined() const { return mDefinedStyles != DEFINED_NONE; }
-
-  bool IsLineStyleDefined() const
-  {
-    return (mDefinedStyles & DEFINED_LINESTYLE) != 0;
-  }
-
-  bool IsForegroundColorDefined() const
-  {
-    return (mDefinedStyles & DEFINED_FOREGROUND_COLOR) != 0;
-  }
-
-  bool IsBackgroundColorDefined() const
-  {
-    return (mDefinedStyles & DEFINED_BACKGROUND_COLOR) != 0;
-  }
-
-  bool IsUnderlineColorDefined() const
-  {
-    return (mDefinedStyles & DEFINED_UNDERLINE_COLOR) != 0;
-  }
-
-  bool IsNoChangeStyle() const
-  {
-    return !IsForegroundColorDefined() && !IsBackgroundColorDefined() &&
-           IsLineStyleDefined() && mLineStyle == LINESTYLE_NONE;
-  }
-
-  bool Equals(const TextRangeStyle& aOther)
-  {
-    if (mDefinedStyles != aOther.mDefinedStyles)
-      return false;
-    if (IsLineStyleDefined() && (mLineStyle != aOther.mLineStyle ||
-                                 !mIsBoldLine != !aOther.mIsBoldLine))
-      return false;
-    if (IsForegroundColorDefined() &&
-        (mForegroundColor != aOther.mForegroundColor))
-      return false;
-    if (IsBackgroundColorDefined() &&
-        (mBackgroundColor != aOther.mBackgroundColor))
-      return false;
-    if (IsUnderlineColorDefined() &&
-        (mUnderlineColor != aOther.mUnderlineColor))
-      return false;
-    return true;
-  }
-
-  bool operator !=(const TextRangeStyle &aOther)
-  {
-    return !Equals(aOther);
-  }
-
-  bool operator ==(const TextRangeStyle &aOther)
-  {
-    return Equals(aOther);
-  }
-
-  uint8_t mDefinedStyles;
-  uint8_t mLineStyle;        // DEFINED_LINESTYLE
-
-  bool mIsBoldLine;  // DEFINED_LINESTYLE
-
-  nscolor mForegroundColor;  // DEFINED_FOREGROUND_COLOR
-  nscolor mBackgroundColor;  // DEFINED_BACKGROUND_COLOR
-  nscolor mUnderlineColor;   // DEFINED_UNDERLINE_COLOR
-};
-
-/******************************************************************************
- * mozilla::TextRange
- ******************************************************************************/
-
-// Sync with nsIPrivateTextRange.h when you change these constants.
-#define NS_TEXTRANGE_CARETPOSITION         0x01
-#define NS_TEXTRANGE_RAWINPUT              0x02
-#define NS_TEXTRANGE_SELECTEDRAWTEXT       0x03
-#define NS_TEXTRANGE_CONVERTEDTEXT         0x04
-#define NS_TEXTRANGE_SELECTEDCONVERTEDTEXT 0x05
-
-struct TextRange
-{
-  TextRange() :
-    mStartOffset(0), mEndOffset(0), mRangeType(0)
-  {
-  }
-
-  uint32_t mStartOffset;
-  // XXX Storing end offset makes the initializing code very complicated.
-  //     We should replace it with mLength.
-  uint32_t mEndOffset;
-  uint32_t mRangeType;
-
-  TextRangeStyle mRangeStyle;
-
-  uint32_t Length() const { return mEndOffset - mStartOffset; }
-};
-
-/******************************************************************************
- * mozilla::TextRangeArray
- *
- * XXX This should be replaced with nsTArray<TextRange>.
- ******************************************************************************/
-
-typedef TextRange* TextRangeArray;
-
-} // namespace mozilla
-
-#endif // mozilla_TextRage_h_
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -6,19 +6,18 @@
 #ifndef NSWINDOW_H_
 #define NSWINDOW_H_
 
 #include "nsBaseWidget.h"
 #include "gfxPoint.h"
 #include "nsIIdleServiceInternal.h"
 #include "nsTArray.h"
 #include "AndroidJavaWrappers.h"
-#include "mozilla/EventForwards.h"
 #include "mozilla/StaticPtr.h"
-#include "mozilla/TextRange.h"
+#include "mozilla/TextEvents.h"
 
 class gfxASurface;
 
 struct ANPEvent;
 
 namespace mozilla {
     class AndroidGeckoEvent;
 
--- a/widget/gtk/nsDragService.cpp
+++ b/widget/gtk/nsDragService.cpp
@@ -17,17 +17,16 @@
 #include "prlog.h"
 #include "nsTArray.h"
 #include "nsPrimitiveHelpers.h"
 #include "prtime.h"
 #include "prthread.h"
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include "nsCRT.h"
-#include "mozilla/BasicEvents.h"
 #include "mozilla/Services.h"
 
 #include "gfxASurface.h"
 #include "gfxXlibSurface.h"
 #include "gfxContext.h"
 #include "nsImageToPixbuf.h"
 #include "nsPresContext.h"
 #include "nsIContent.h"
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -25,17 +25,17 @@
 
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #endif /* MOZ_X11 */
 
 #ifdef ACCESSIBILITY
 #include "mozilla/a11y/Accessible.h"
 #endif
-#include "mozilla/EventForwards.h"
+#include "mozilla/MouseEvents.h"
 
 #include "nsGtkIMModule.h"
 
 #undef LOG
 #ifdef MOZ_LOGGING
 
 // make sure that logging is enabled before including prlog.h
 #define FORCE_PR_LOG
--- a/widget/moz.build
+++ b/widget/moz.build
@@ -113,17 +113,16 @@ EXPORTS.mozilla += [
     'BasicEvents.h',
     'ContentEvents.h',
     'EventClassList.h',
     'EventForwards.h',
     'LookAndFeel.h',
     'MiscEvents.h',
     'MouseEvents.h',
     'TextEvents.h',
-    'TextRange.h',
     'TouchEvents.h',
     'WidgetUtils.h',
 ]
 
 if CONFIG['MOZ_INSTRUMENT_EVENT_LOOP']:
     EXPORTS.mozilla += [
         'WidgetTraceEvent.h',
     ]
--- a/widget/nsIWidgetListener.h
+++ b/widget/nsIWidgetListener.h
@@ -1,24 +1,22 @@
 /* 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 nsIWidgetListener_h__
 #define nsIWidgetListener_h__
 
-#include <stdint.h>
-
-#include "mozilla/EventForwards.h"
+#include "nscore.h"
+#include "nsIXULWindow.h"
+#include "nsRegion.h"
+#include "mozilla/BasicEvents.h"
 
 class nsView;
-class nsIntRegion;
 class nsIPresShell;
-class nsIWidget;
-class nsIXULWindow;
 
 /**
  * sizemode is an adjunct to widget size
  */
 enum nsSizeMode
 {
   nsSizeMode_Normal = 0,
   nsSizeMode_Minimized,
@@ -40,106 +38,107 @@ class nsIWidgetListener
 {
 public:
 
   /**
    * If this listener is for an nsIXULWindow, return it. If this is null, then
    * this is likely a listener for a view, which can be determined using
    * GetView. If both methods return null, this will be an nsWebBrowser.
    */
-  virtual nsIXULWindow* GetXULWindow();
+  virtual nsIXULWindow* GetXULWindow() { return nullptr; }
 
   /**
    * If this listener is for an nsView, return it.
    */
-  virtual nsView* GetView();
+  virtual nsView* GetView() { return nullptr; }
 
   /**
    * Return the presshell for this widget listener.
    */
-  virtual nsIPresShell* GetPresShell();
+  virtual nsIPresShell* GetPresShell() { return nullptr; }
 
   /**
    * Called when a window is moved to location (x, y). Returns true if the
    * notification was handled. Coordinates are outer window screen coordinates.
    */
-  virtual bool WindowMoved(nsIWidget* aWidget, int32_t aX, int32_t aY);
+  virtual bool WindowMoved(nsIWidget* aWidget, int32_t aX, int32_t aY) { return false; }
 
   /**
    * Called when a window is resized to (width, height). Returns true if the
    * notification was handled. Coordinates are outer window screen coordinates.
    */
-  virtual bool WindowResized(nsIWidget* aWidget,
-                             int32_t aWidth, int32_t aHeight);
+  virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight) { return false; }
 
   /**
    * Called when the size mode (minimized, maximized, fullscreen) is changed.
    */
-  virtual void SizeModeChanged(nsSizeMode aSizeMode);
+  virtual void SizeModeChanged(nsSizeMode sizeMode) { }
 
   /**
    * Called when the z-order of the window is changed. Returns true if the
    * notification was handled. aPlacement indicates the new z order. If
    * placement is nsWindowZRelative, then aRequestBelow should be the
    * window to place below. On return, aActualBelow will be set to the
    * window actually behind. This generally only applies to Windows.
    */
-  virtual bool ZLevelChanged(bool aImmediate, nsWindowZ* aPlacement,
-                             nsIWidget* aRequestBelow,
-                             nsIWidget** aActualBelow);
+  virtual bool ZLevelChanged(bool aImmediate, nsWindowZ *aPlacement,
+                             nsIWidget* aRequestBelow, nsIWidget** aActualBelow) { return false; }
 
   /**
    * Called when the window is activated and focused.
    */
-  virtual void WindowActivated();
+  virtual void WindowActivated() { }
 
   /**
    * Called when the window is deactivated and no longer focused.
    */
-  virtual void WindowDeactivated();
+  virtual void WindowDeactivated() { }
 
   /**
    * Called when the show/hide toolbar button on the Mac titlebar is pressed.
    */
-  virtual void OSToolbarButtonPressed();
+  virtual void OSToolbarButtonPressed() { }
 
   /**
    * Called when a request is made to close the window. Returns true if the
    * notification was handled. Returns true if the notification was handled.
    */
-  virtual bool RequestWindowClose(nsIWidget* aWidget);
+  virtual bool RequestWindowClose(nsIWidget* aWidget) { return false; }
 
   /*
    * Indicate that a paint is about to occur on this window. This is called
    * at a time when it's OK to change the geometry of this widget or of
    * other widgets. Must be called before every call to PaintWindow.
    */
-  virtual void WillPaintWindow(nsIWidget* aWidget);
+  virtual void WillPaintWindow(nsIWidget* aWidget) { }
 
   /**
    * Paint the specified region of the window. Returns true if the
    * notification was handled.
    * This is called at a time when it is not OK to change the geometry of
    * this widget or of other widgets.
    */
-  virtual bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion);
+  virtual bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) { return false; }
 
   /**
    * Indicates that a paint occurred.
    * This is called at a time when it is OK to change the geometry of
    * this widget or of other widgets.
    * Must be called after every call to PaintWindow.
    */
-  virtual void DidPaintWindow();
+  virtual void DidPaintWindow() { }
 
   /**
    * Request that layout schedules a repaint on the next refresh driver tick.
    */
-  virtual void RequestRepaint();
+  virtual void RequestRepaint() { }
 
   /**
    * Handle an event.
    */
   virtual nsEventStatus HandleEvent(mozilla::WidgetGUIEvent* aEvent,
-                                    bool aUseAttachedEvents);
+                                    bool aUseAttachedEvents)
+  {
+    return nsEventStatus_eIgnore;
+  }
 };
 
 #endif
--- a/widget/qt/nsWindow.cpp
+++ b/widget/qt/nsWindow.cpp
@@ -2803,24 +2803,16 @@ nsWindow::GetDPI()
     if (heightInches < 0.25) {
         // Something's broken, but we'd better not crash.
         return 96.0f;
     }
 
     return float(rootWindow->height()/heightInches);
 }
 
-nsEventStatus
-nsWindow::DispatchEvent(WidgetGUIEvent* aEvent)
-{
-    nsEventStatus status;
-    DispatchEvent(aEvent, status);
-    return status;
-}
-
 void
 nsWindow::DispatchActivateEvent(void)
 {
     if (mWidgetListener)
       mWidgetListener->WindowActivated();
 }
 
 void
@@ -3173,42 +3165,8 @@ nsWindow::GetGLFrameBufferFormat()
 {
     if (mLayerManager &&
         mLayerManager->GetBackendType() == mozilla::layers::LAYERS_OPENGL) {
         return MozQGLWidgetWrapper::isRGBAContext() ? LOCAL_GL_RGBA : LOCAL_GL_RGB;
     }
     return LOCAL_GL_NONE;
 }
 
-void
-nsWindow::ProcessMotionEvent()
-{
-    if (mPinchEvent.needDispatch) {
-        double distance = DistanceBetweenPoints(mPinchEvent.centerPoint,
-                                                mPinchEvent.touchPoint);
-        distance *= 2;
-        mPinchEvent.delta = distance - mPinchEvent.prevDistance;
-        nsIntPoint centerPoint(mPinchEvent.centerPoint.x(),
-                               mPinchEvent.centerPoint.y());
-        DispatchGestureEvent(NS_SIMPLE_GESTURE_MAGNIFY_UPDATE,
-                             0, mPinchEvent.delta, centerPoint);
-        mPinchEvent.prevDistance = distance;
-    }
-    if (mMoveEvent.needDispatch) {
-        WidgetMouseEvent event(true, NS_MOUSE_MOVE, this,
-                               WidgetMouseEvent::eReal);
-
-        event.refPoint.x = nscoord(mMoveEvent.pos.x());
-        event.refPoint.y = nscoord(mMoveEvent.pos.y());
-
-        event.InitBasicModifiers(mMoveEvent.modifiers & Qt::ControlModifier,
-                                 mMoveEvent.modifiers & Qt::AltModifier,
-                                 mMoveEvent.modifiers & Qt::ShiftModifier,
-                                 mMoveEvent.modifiers & Qt::MetaModifier);
-        event.clickCount      = 0;
-
-        DispatchEvent(&event);
-        mMoveEvent.needDispatch = false;
-    }
-
-    mTimerStarted = false;
-}
-
--- a/widget/qt/nsWindow.h
+++ b/widget/qt/nsWindow.h
@@ -11,17 +11,17 @@
 #include <QKeyEvent>
 #include <QGestureEvent>
 #include <qgraphicswidget.h>
 #include <QTime>
 
 #include "nsAutoPtr.h"
 
 #include "nsBaseWidget.h"
-#include "mozilla/EventForwards.h"
+#include "mozilla/MouseEvents.h"
 
 #include "nsWeakReference.h"
 
 #include "nsGkAtoms.h"
 #include "nsIIdleServiceInternal.h"
 #include "nsIRunnable.h"
 #include "nsThreadUtils.h"
 
@@ -178,17 +178,22 @@ public:
     // event handling code
 
     void DispatchActivateEvent(void);
     void DispatchDeactivateEvent(void);
     void DispatchActivateEventOnTopLevelWindow(void);
     void DispatchDeactivateEventOnTopLevelWindow(void);
     void DispatchResizeEvent(nsIntRect &aRect, nsEventStatus &aStatus);
 
-    nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent);
+    nsEventStatus DispatchEvent(mozilla::WidgetGUIEvent* aEvent)
+    {
+        nsEventStatus status;
+        DispatchEvent(aEvent, status);
+        return status;
+    }
 
     // Some of the nsIWidget methods
     virtual bool IsEnabled() const;
 
     // called when we are destroyed
     void OnDestroy(void);
 
     // called to check and see if a widget's dimensions are sane
@@ -368,17 +373,45 @@ private:
         *flag &= ~mask;
     }
     int32_t mQCursor;
 
     // Call this function when the users activity is the direct cause of an
     // event (like a keypress or mouse click).
     void UserActivity();
 
-    inline void ProcessMotionEvent();
+    inline void ProcessMotionEvent() {
+        if (mPinchEvent.needDispatch) {
+            double distance = DistanceBetweenPoints(mPinchEvent.centerPoint, mPinchEvent.touchPoint);
+            distance *= 2;
+            mPinchEvent.delta = distance - mPinchEvent.prevDistance;
+            nsIntPoint centerPoint(mPinchEvent.centerPoint.x(), mPinchEvent.centerPoint.y());
+            DispatchGestureEvent(NS_SIMPLE_GESTURE_MAGNIFY_UPDATE,
+                                 0, mPinchEvent.delta, centerPoint);
+            mPinchEvent.prevDistance = distance;
+        }
+        if (mMoveEvent.needDispatch) {
+            WidgetMouseEvent event(true, NS_MOUSE_MOVE, this,
+                                   WidgetMouseEvent::eReal);
+
+            event.refPoint.x = nscoord(mMoveEvent.pos.x());
+            event.refPoint.y = nscoord(mMoveEvent.pos.y());
+
+            event.InitBasicModifiers(mMoveEvent.modifiers & Qt::ControlModifier,
+                                     mMoveEvent.modifiers & Qt::AltModifier,
+                                     mMoveEvent.modifiers & Qt::ShiftModifier,
+                                     mMoveEvent.modifiers & Qt::MetaModifier);
+            event.clickCount      = 0;
+
+            DispatchEvent(&event);
+            mMoveEvent.needDispatch = false;
+        }
+
+        mTimerStarted = false;
+    }
 
     void DispatchMotionToMainThread() {
         if (!mTimerStarted) {
             nsCOMPtr<nsIRunnable> event =
                 NS_NewRunnableMethod(this, &nsWindow::ProcessMotionEvent);
             NS_DispatchToMainThread(event);
             mTimerStarted = true;
         }
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -90,48 +90,16 @@ public:
   PRUnichar GetCompositeChar(PRUnichar aBaseChar) const;
 };
 
 
 /*****************************************************************************
  * mozilla::widget::ModifierKeyState
  *****************************************************************************/
 
-ModifierKeyState::ModifierKeyState()
-{
-  Update();
-}
-
-ModifierKeyState::ModifierKeyState(bool aIsShiftDown,
-                                   bool aIsControlDown,
-                                   bool aIsAltDown)
-{
-  Update();
-  Unset(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_ALTGRAPH);
-  Modifiers modifiers = 0;
-  if (aIsShiftDown) {
-    modifiers |= MODIFIER_SHIFT;
-  }
-  if (aIsControlDown) {
-    modifiers |= MODIFIER_CONTROL;
-  }
-  if (aIsAltDown) {
-    modifiers |= MODIFIER_ALT;
-  }
-  if (modifiers) {
-    Set(modifiers);
-  }
-}
-
-ModifierKeyState::ModifierKeyState(Modifiers aModifiers) :
-  mModifiers(aModifiers)
-{
-  EnsureAltGr();
-}
-
 void
 ModifierKeyState::Update()
 {
   mModifiers = 0;
   if (IS_VK_DOWN(VK_SHIFT)) {
     mModifiers |= MODIFIER_SHIFT;
   }
   if (IS_VK_DOWN(VK_CONTROL)) {
@@ -152,32 +120,16 @@ ModifierKeyState::Update()
   if (::GetKeyState(VK_SCROLL) & 1) {
     mModifiers |= MODIFIER_SCROLLLOCK;
   }
 
   EnsureAltGr();
 }
 
 void
-ModifierKeyState::Unset(Modifiers aRemovingModifiers)
-{
-  mModifiers &= ~aRemovingModifiers;
-  // Note that we don't need to unset AltGr flag here automatically.
-  // For nsEditor, we need to remove Alt and Control flags but AltGr isn't
-  // checked in nsEditor, so, it can be kept.
-}
-
-void
-ModifierKeyState::Set(Modifiers aAddingModifiers)
-{
-  mModifiers |= aAddingModifiers;
-  EnsureAltGr();
-}
-
-void
 ModifierKeyState::InitInputEvent(WidgetInputEvent& aInputEvent) const
 {
   aInputEvent.modifiers = mModifiers;
 
   switch(aInputEvent.eventStructType) {
     case NS_MOUSE_EVENT:
     case NS_MOUSE_SCROLL_EVENT:
     case NS_WHEEL_EVENT:
@@ -213,82 +165,16 @@ ModifierKeyState::InitMouseEvent(WidgetI
   if (::GetKeyState(VK_XBUTTON1) < 0) {
     mouseEvent.buttons |= WidgetMouseEvent::e4thButtonFlag;
   }
   if (::GetKeyState(VK_XBUTTON2) < 0) {
     mouseEvent.buttons |= WidgetMouseEvent::e5thButtonFlag;
   }
 }
 
-bool
-ModifierKeyState::IsShift() const
-{
-  return (mModifiers & MODIFIER_SHIFT) != 0;
-}
-
-bool
-ModifierKeyState::IsControl() const
-{
-  return (mModifiers & MODIFIER_CONTROL) != 0;
-}
-
-bool
-ModifierKeyState::IsAlt() const
-{
-  return (mModifiers & MODIFIER_ALT) != 0;
-}
-
-bool
-ModifierKeyState::IsAltGr() const
-{
-  return IsControl() && IsAlt();
-}
-
-bool
-ModifierKeyState::IsWin() const
-{
-  return (mModifiers & MODIFIER_OS) != 0;
-}
-
-bool
-ModifierKeyState::IsCapsLocked() const
-{
-  return (mModifiers & MODIFIER_CAPSLOCK) != 0;
-}
-
-bool
-ModifierKeyState::IsNumLocked() const
-{
-  return (mModifiers & MODIFIER_NUMLOCK) != 0;
-}
-
-bool
-ModifierKeyState::IsScrollLocked() const
-{
-  return (mModifiers & MODIFIER_SCROLLLOCK) != 0;
-}
-
-Modifiers
-ModifierKeyState::GetModifiers() const
-{
-  return mModifiers;
-}
-
-void
-ModifierKeyState::EnsureAltGr()
-{
-  // If both Control key and Alt key are pressed, it means AltGr is pressed.
-  // Ideally, we should check whether the current keyboard layout has AltGr
-  // or not.  However, setting AltGr flags for keyboard which doesn't have
-  // AltGr must not be serious bug.  So, it should be OK for now.
-  if (IsAltGr()) {
-    mModifiers |= MODIFIER_ALTGRAPH;
-  }
-}
-
 /*****************************************************************************
  * mozilla::widget::UniCharsAndModifiers
  *****************************************************************************/
 
 void
 UniCharsAndModifiers::Append(PRUnichar aUniChar, Modifiers aModifiers)
 {
   MOZ_ASSERT(mLength < 5);
@@ -345,60 +231,16 @@ UniCharsAndModifiers::operator+(const Un
   result += aOther;
   return result;
 }
 
 /*****************************************************************************
  * mozilla::widget::VirtualKey
  *****************************************************************************/
 
-// static
-VirtualKey::ShiftState
-VirtualKey::ModifiersToShiftState(Modifiers aModifiers)
-{
-  ShiftState state = 0;
-  if (aModifiers & MODIFIER_SHIFT) {
-    state |= STATE_SHIFT;
-  }
-  if (aModifiers & MODIFIER_CONTROL) {
-    state |= STATE_CONTROL;
-  }
-  if (aModifiers & MODIFIER_ALT) {
-    state |= STATE_ALT;
-  }
-  if (aModifiers & MODIFIER_CAPSLOCK) {
-    state |= STATE_CAPSLOCK;
-  }
-  return state;
-}
-
-// static
-Modifiers
-VirtualKey::ShiftStateToModifiers(ShiftState aShiftState)
-{
-  Modifiers modifiers = 0;
-  if (aShiftState & STATE_SHIFT) {
-    modifiers |= MODIFIER_SHIFT;
-  }
-  if (aShiftState & STATE_CONTROL) {
-    modifiers |= MODIFIER_CONTROL;
-  }
-  if (aShiftState & STATE_ALT) {
-    modifiers |= MODIFIER_ALT;
-  }
-  if (aShiftState & STATE_CAPSLOCK) {
-    modifiers |= MODIFIER_CAPSLOCK;
-  }
-  if ((modifiers & (MODIFIER_ALT | MODIFIER_CONTROL)) ==
-         (MODIFIER_ALT | MODIFIER_CONTROL)) {
-    modifiers |= MODIFIER_ALTGRAPH;
-  }
-  return modifiers;
-}
-
 inline PRUnichar
 VirtualKey::GetCompositeChar(ShiftState aShiftState, PRUnichar aBaseChar) const
 {
   return mShiftStates[aShiftState].DeadKey.Table->GetCompositeChar(aBaseChar);
 }
 
 const DeadKeyTable*
 VirtualKey::MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
@@ -906,22 +748,16 @@ PRUnichar
 NativeKey::ComputeUnicharFromScanCode() const
 {
   return static_cast<PRUnichar>(
            ::MapVirtualKeyEx(ComputeVirtualKeyCodeFromScanCode(),
                              MAPVK_VK_TO_CHAR, mKeyboardLayout));
 }
 
 void
-NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const
-{
-  InitKeyEvent(aKeyEvent, mModKeyState);
-}
-
-void
 NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                         const ModifierKeyState& aModKeyState) const
 {
   nsIntPoint point(0, 0);
   mWidget->InitEvent(aKeyEvent, &point);
 
   switch (aKeyEvent.message) {
     case NS_KEY_DOWN:
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -6,17 +6,16 @@
 #ifndef KeyboardLayout_h__
 #define KeyboardLayout_h__
 
 #include "nscore.h"
 #include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsWindowBase.h"
 #include "nsWindowDefs.h"
-#include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
 #include <windows.h>
 
 #define NS_NUM_OF_KEYS          70
 
 #define VK_OEM_1                0xBA   // ';:' for US
 #define VK_OEM_PLUS             0xBB   // '+' any country
 #define VK_OEM_COMMA            0xBC
@@ -50,46 +49,94 @@ static const uint32_t sModifierKeyMap[][
   { nsIWidget::CTRL_L,    VK_CONTROL, VK_LCONTROL },
   { nsIWidget::CTRL_R,    VK_CONTROL, VK_RCONTROL },
   { nsIWidget::ALT_L,     VK_MENU,    VK_LMENU },
   { nsIWidget::ALT_R,     VK_MENU,    VK_RMENU }
 };
 
 class KeyboardLayout;
 
-class ModifierKeyState
-{
+class ModifierKeyState {
 public:
-  ModifierKeyState();
-  ModifierKeyState(bool aIsShiftDown, bool aIsControlDown, bool aIsAltDown);
-  ModifierKeyState(Modifiers aModifiers);
+  ModifierKeyState()
+  {
+    Update();
+  }
 
-  MOZ_ALWAYS_INLINE void Update();
+  ModifierKeyState(bool aIsShiftDown, bool aIsControlDown, bool aIsAltDown)
+  {
+    Update();
+    Unset(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_ALTGRAPH);
+    Modifiers modifiers = 0;
+    if (aIsShiftDown) {
+      modifiers |= MODIFIER_SHIFT;
+    }
+    if (aIsControlDown) {
+      modifiers |= MODIFIER_CONTROL;
+    }
+    if (aIsAltDown) {
+      modifiers |= MODIFIER_ALT;
+    }
+    if (modifiers) {
+      Set(modifiers);
+    }
+  }
 
-  MOZ_ALWAYS_INLINE void Unset(Modifiers aRemovingModifiers);
-  MOZ_ALWAYS_INLINE void Set(Modifiers aAddingModifiers);
+  ModifierKeyState(Modifiers aModifiers) :
+    mModifiers(aModifiers)
+  {
+    EnsureAltGr();
+  }
+
+  void Update();
+
+  void Unset(Modifiers aRemovingModifiers)
+  {
+    mModifiers &= ~aRemovingModifiers;
+    // Note that we don't need to unset AltGr flag here automatically.
+    // For nsEditor, we need to remove Alt and Control flags but AltGr isn't
+    // checked in nsEditor, so, it can be kept.
+  }
+
+  void Set(Modifiers aAddingModifiers)
+  {
+    mModifiers |= aAddingModifiers;
+    EnsureAltGr();
+  }
 
   void InitInputEvent(WidgetInputEvent& aInputEvent) const;
 
-  MOZ_ALWAYS_INLINE bool IsShift() const;
-  MOZ_ALWAYS_INLINE bool IsControl() const;
-  MOZ_ALWAYS_INLINE bool IsAlt() const;
-  MOZ_ALWAYS_INLINE bool IsAltGr() const;
-  MOZ_ALWAYS_INLINE bool IsWin() const;
+  bool IsShift() const { return (mModifiers & MODIFIER_SHIFT) != 0; }
+  bool IsControl() const { return (mModifiers & MODIFIER_CONTROL) != 0; }
+  bool IsAlt() const { return (mModifiers & MODIFIER_ALT) != 0; }
+  bool IsAltGr() const { return IsControl() && IsAlt(); }
+  bool IsWin() const { return (mModifiers & MODIFIER_OS) != 0; }
 
-  MOZ_ALWAYS_INLINE bool IsCapsLocked() const;
-  MOZ_ALWAYS_INLINE bool IsNumLocked() const;
-  MOZ_ALWAYS_INLINE bool IsScrollLocked() const;
+  bool IsCapsLocked() const { return (mModifiers & MODIFIER_CAPSLOCK) != 0; }
+  bool IsNumLocked() const { return (mModifiers & MODIFIER_NUMLOCK) != 0; }
+  bool IsScrollLocked() const
+  {
+    return (mModifiers & MODIFIER_SCROLLLOCK) != 0;
+  }
 
-  MOZ_ALWAYS_INLINE Modifiers GetModifiers() const;
+  Modifiers GetModifiers() const { return mModifiers; }
 
 private:
   Modifiers mModifiers;
 
-  MOZ_ALWAYS_INLINE void EnsureAltGr();
+  void EnsureAltGr()
+  {
+    // If both Control key and Alt key are pressed, it means AltGr is pressed.
+    // Ideally, we should check whether the current keyboard layout has AltGr
+    // or not.  However, setting AltGr flags for keyboard which doesn't have
+    // AltGr must not be serious bug.  So, it should be OK for now.
+    if (IsAltGr()) {
+      mModifiers |= MODIFIER_ALTGRAPH;
+    }
+  }
 
   void InitMouseEvent(WidgetInputEvent& aMouseEvent) const;
 };
 
 struct UniCharsAndModifiers
 {
   // Dead-key + up to 4 characters
   PRUnichar mChars[5];
@@ -144,18 +191,55 @@ public:
     STATE_SHIFT    = 0x01,
     STATE_CONTROL  = 0x02,
     STATE_ALT      = 0x04,
     STATE_CAPSLOCK = 0x08
   };
 
   typedef uint8_t ShiftState;
 
-  static ShiftState ModifiersToShiftState(Modifiers aModifiers);
-  static Modifiers ShiftStateToModifiers(ShiftState aShiftState);
+  static ShiftState ModifiersToShiftState(Modifiers aModifiers)
+  {
+    ShiftState state = 0;
+    if (aModifiers & MODIFIER_SHIFT) {
+      state |= STATE_SHIFT;
+    }
+    if (aModifiers & MODIFIER_CONTROL) {
+      state |= STATE_CONTROL;
+    }
+    if (aModifiers & MODIFIER_ALT) {
+      state |= STATE_ALT;
+    }
+    if (aModifiers & MODIFIER_CAPSLOCK) {
+      state |= STATE_CAPSLOCK;
+    }
+    return state;
+  }
+
+  static Modifiers ShiftStateToModifiers(ShiftState aShiftState)
+  {
+    Modifiers modifiers = 0;
+    if (aShiftState & STATE_SHIFT) {
+      modifiers |= MODIFIER_SHIFT;
+    }
+    if (aShiftState & STATE_CONTROL) {
+      modifiers |= MODIFIER_CONTROL;
+    }
+    if (aShiftState & STATE_ALT) {
+      modifiers |= MODIFIER_ALT;
+    }
+    if (aShiftState & STATE_CAPSLOCK) {
+      modifiers |= MODIFIER_CAPSLOCK;
+    }
+    if ((modifiers & (MODIFIER_ALT | MODIFIER_CONTROL)) ==
+           (MODIFIER_ALT | MODIFIER_CONTROL)) {
+      modifiers |= MODIFIER_ALTGRAPH;
+    }
+    return modifiers;
+  }
 
 private:
   union KeyShiftState
   {
     struct
     {
       PRUnichar Chars[4];
     } Normal;
@@ -339,17 +423,20 @@ private:
    */
   PRUnichar ComputeUnicharFromScanCode() const;
 
   /**
    * Initializes the aKeyEvent with the information stored in the instance.
    */
   void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                     const ModifierKeyState& aModKeyState) const;
-  void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const;
+  void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const
+  {
+    InitKeyEvent(aKeyEvent, mModKeyState);
+  }
 
   /**
    * Dispatches the key event.  Returns true if the event is consumed.
    * Otherwise, false.
    */
   bool DispatchKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                         const MSG* aMsgSentToPlugin = nullptr) const;
 
--- a/widget/windows/moz.build
+++ b/widget/windows/moz.build
@@ -56,17 +56,16 @@ CPP_SOURCES += [
     'nsScreenManagerWin.cpp',
     'nsScreenWin.cpp',
     'nsSound.cpp',
     'nsToolkit.cpp',
     'nsUXThemeData.cpp',
     'nsWidgetFactory.cpp',
     'nsWinGesture.cpp',
     'nsWindow.cpp',
-    'nsWindowBase.cpp',
     'nsWindowDbg.cpp',
     'nsWindowGfx.cpp',
 ]
 
 if CONFIG['MOZ_CRASHREPORTER']:
     CPP_SOURCES += [
         'LSPAnnotator.cpp',
     ]
--- a/widget/windows/nsTextStore.h
+++ b/widget/windows/nsTextStore.h
@@ -8,17 +8,17 @@
 
 #include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "nsITimer.h"
 #include "nsIWidget.h"
 #include "nsWindowBase.h"
 #include "mozilla/Attributes.h"
-#include "mozilla/TextRange.h"
+#include "mozilla/TextEvents.h"
 
 #include <msctf.h>
 #include <textstor.h>
 
 // GUID_PROP_INPUTSCOPE is declared in inputscope.h using INIT_GUID.
 // With initguid.h, we get its instance instead of extern declaration.
 #ifdef INPUTSCOPE_INIT_GUID
 #include <initguid.h>
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -167,18 +167,16 @@
 #include "nsCrashOnException.h"
 #include "nsIXULRuntime.h"
 
 #include "nsIContent.h"
 
 #include "mozilla/HangMonitor.h"
 #include "WinIMEHandler.h"
 
-#include "npapi.h"
-
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::layers;
 using namespace mozilla::widget;
 
 /**************************************************************
  **************************************************************
  **
deleted file mode 100644
--- a/widget/windows/nsWindowBase.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsWindowBase.h"
-
-#include "mozilla/MiscEvents.h"
-#include "npapi.h"
-
-using namespace mozilla;
-
-bool
-nsWindowBase::DispatchPluginEvent(const MSG& aMsg)
-{
-  if (!PluginHasFocus()) {
-    return false;
-  }
-  WidgetPluginEvent pluginEvent(true, NS_PLUGIN_INPUT_EVENT, this);
-  nsIntPoint point(0, 0);
-  InitEvent(pluginEvent, &point);
-  NPEvent npEvent;
-  npEvent.event = aMsg.message;
-  npEvent.wParam = aMsg.wParam;
-  npEvent.lParam = aMsg.lParam;
-  pluginEvent.pluginEvent = &npEvent;
-  pluginEvent.retargetToFocusedDocument = true;
-  return DispatchWindowEvent(&pluginEvent);
-}
--- a/widget/windows/nsWindowBase.h
+++ b/widget/windows/nsWindowBase.h
@@ -1,18 +1,19 @@
 /* -*- Mode: C++; tab-width: 4; 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 nsWindowBase_h_
 #define nsWindowBase_h_
 
-#include "mozilla/EventForwards.h"
+#include "mozilla/MiscEvents.h"
 #include "nsBaseWidget.h"
+#include "npapi.h"
 #include <windows.h>
 
 /*
  * nsWindowBase - Base class of common methods other classes need to access
  * in both win32 and winrt window classes.
  */
 class nsWindowBase : public nsBaseWidget
 {
@@ -53,17 +54,32 @@ public:
    * is called by KeyboardLayout to dispatch gecko events.
    * Returns true if it's consumed.  Otherwise, false.
    */
   virtual bool DispatchKeyboardEvent(mozilla::WidgetGUIEvent* aEvent) = 0;
 
   /*
    * Default dispatch of a plugin event.
    */
-  virtual bool DispatchPluginEvent(const MSG& aMsg);
+  virtual bool DispatchPluginEvent(const MSG &aMsg)
+  {
+    if (!PluginHasFocus()) {
+      return false;
+    }
+    mozilla::WidgetPluginEvent pluginEvent(true, NS_PLUGIN_INPUT_EVENT, this);
+    nsIntPoint point(0, 0);
+    InitEvent(pluginEvent, &point);
+    NPEvent npEvent;
+    npEvent.event = aMsg.message;
+    npEvent.wParam = aMsg.wParam;
+    npEvent.lParam = aMsg.lParam;
+    pluginEvent.pluginEvent = (void *)&npEvent;
+    pluginEvent.retargetToFocusedDocument = true;
+    return DispatchWindowEvent(&pluginEvent);
+  }
 
   /*
    * Returns true if a plugin has focus on this widget.  Otherwise, false.
    */
   virtual bool PluginHasFocus() const MOZ_FINAL
   {
     return (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
   }
--- a/widget/xpwidgets/moz.build
+++ b/widget/xpwidgets/moz.build
@@ -24,17 +24,16 @@ CPP_SOURCES += [
     'nsBaseDragService.cpp',
     'nsBaseScreen.cpp',
     'nsBaseWidget.cpp',
     'nsClipboardHelper.cpp',
     'nsClipboardPrivacyHandler.cpp',
     'nsFilePickerProxy.cpp',
     'nsHTMLFormatConverter.cpp',
     'nsIdleService.cpp',
-    'nsIWidgetListener.cpp',
     'nsPrimitiveHelpers.cpp',
     'nsPrintOptionsImpl.cpp',
     'nsPrintSession.cpp',
     'nsPrintSettingsImpl.cpp',
     'nsTransferable.cpp',
     'nsXPLookAndFeel.cpp',
 ]
 
deleted file mode 100644
--- a/widget/xpwidgets/nsIWidgetListener.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsIWidgetListener.h"
-
-#include "nsRegion.h"
-#include "nsView.h"
-#include "nsIPresShell.h"
-#include "nsIWidget.h"
-#include "nsIXULWindow.h"
-
-#include "mozilla/BasicEvents.h"
-
-using namespace mozilla;
-
-nsIXULWindow*
-nsIWidgetListener::GetXULWindow()
-{
-  return nullptr;
-}
-
-nsView*
-nsIWidgetListener::GetView()
-{
-  return nullptr;
-}
-
-nsIPresShell*
-nsIWidgetListener::GetPresShell()
-{
-  return nullptr;
-}
-
-bool
-nsIWidgetListener::WindowMoved(nsIWidget* aWidget,
-                               int32_t aX,
-                               int32_t aY)
-{
-  return false;
-}
-
-bool
-nsIWidgetListener::WindowResized(nsIWidget* aWidget,
-                                 int32_t aWidth,
-                                 int32_t aHeight)
-{
-  return false;
-}
-
-void
-nsIWidgetListener::SizeModeChanged(nsSizeMode aSizeMode)
-{
-}
-
-bool
-nsIWidgetListener::ZLevelChanged(bool aImmediate,
-                                 nsWindowZ* aPlacement,
-                                 nsIWidget* aRequestBelow,
-                                 nsIWidget** aActualBelow)
-{
-  return false;
-}
-
-void
-nsIWidgetListener::WindowActivated()
-{
-}
-
-void
-nsIWidgetListener::WindowDeactivated()
-{
-}
-
-void
-nsIWidgetListener::OSToolbarButtonPressed()
-{
-}
-
-bool
-nsIWidgetListener::RequestWindowClose(nsIWidget* aWidget)
-{
-  return false;
-}
-
-void
-nsIWidgetListener::WillPaintWindow(nsIWidget* aWidget)
-{
-}
-
-bool
-nsIWidgetListener::PaintWindow(nsIWidget* aWidget,
-                               nsIntRegion aRegion)
-{
-  return false;
-}
-
-void
-nsIWidgetListener::DidPaintWindow()
-{
-}
-
-void
-nsIWidgetListener::RequestRepaint()
-{
-}
-
-nsEventStatus
-nsIWidgetListener::HandleEvent(WidgetGUIEvent* aEvent,
-                               bool aUseAttachedEvents)
-{
-  return nsEventStatus_eIgnore;
-}
--- a/xpfe/appshell/src/nsAppShellService.cpp
+++ b/xpfe/appshell/src/nsAppShellService.cpp
@@ -18,19 +18,17 @@
 #include "nsPIWindowWatcher.h"
 #include "nsIDOMWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsWebShellWindow.h"
 
 #include "nsCRT.h"
 #include "prprf.h"
 
-#include "nsWidgetInitData.h"
 #include "nsWidgetsCID.h"
-#include "nsIWidget.h"
 #include "nsIRequestObserver.h"
 
 /* For implementing GetHiddenWindowAndJSContext */
 #include "nsIScriptGlobalObject.h"
 #include "nsIScriptContext.h"
 #include "jsapi.h"
 
 #include "nsAppShellService.h"
--- a/xpfe/appshell/src/nsChromeTreeOwner.cpp
+++ b/xpfe/appshell/src/nsChromeTreeOwner.cpp
@@ -14,17 +14,16 @@
 #include "nsIServiceManager.h"
 #include "nsIDocShellTreeItem.h"
 
 // Interfaces needed to include
 #include "nsIPrompt.h"
 #include "nsIAuthPrompt.h"
 #include "nsIBrowserDOMWindow.h"
 #include "nsIWebProgress.h"
-#include "nsIWidget.h"
 #include "nsIWindowMediator.h"
 #include "nsIDOMChromeWindow.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMXULElement.h"
 #include "nsIXULBrowserWindow.h"
 #include "mozilla/dom/Element.h"
--- a/xpfe/appshell/src/nsContentTreeOwner.cpp
+++ b/xpfe/appshell/src/nsContentTreeOwner.cpp
@@ -29,17 +29,16 @@
 #include "nsIXULBrowserWindow.h"
 #include "nsIPrincipal.h"
 #include "nsIURIFixup.h"
 #include "nsCDefaultURIFixup.h"
 #include "nsIWebNavigation.h"
 #include "nsDocShellCID.h"
 #include "nsIExternalURLHandlerService.h"
 #include "nsIMIMEInfo.h"
-#include "nsIWidget.h"
 #include "mozilla/BrowserElementParent.h"
 
 #include "nsIDOMDocument.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIURI.h"
 #include "nsIDocument.h"
 #if defined(XP_MACOSX)
 #include "nsThreadUtils.h"
--- a/xpfe/appshell/src/nsWebShellWindow.cpp
+++ b/xpfe/appshell/src/nsWebShellWindow.cpp
@@ -21,17 +21,16 @@
 
 #include "nsEscape.h"
 #include "nsPIDOMWindow.h"
 #include "nsIWebNavigation.h"
 #include "nsIWindowWatcher.h"
 
 #include "nsIDOMXULElement.h"
 
-#include "nsWidgetInitData.h"
 #include "nsWidgetsCID.h"
 #include "nsIWidget.h"
 #include "nsIWidgetListener.h"
 
 #include "nsIDOMCharacterData.h"
 #include "nsIDOMNodeList.h"
 
 #include "nsITimer.h"
--- a/xpfe/appshell/src/nsWebShellWindow.h
+++ b/xpfe/appshell/src/nsWebShellWindow.h
@@ -11,18 +11,16 @@
 #include "nsITimer.h"
 #include "nsCOMPtr.h"
 #include "nsXULWindow.h"
 #include "nsIWidgetListener.h"
 
 /* Forward declarations.... */
 class nsIURI;
 
-struct nsWidgetInitData;
-
 namespace mozilla {
 class WebShellWindowTimerCallback;
 } // namespace mozilla
 
 class nsWebShellWindow : public nsXULWindow,
                          public nsIWebProgressListener,
                          public nsIWidgetListener
 {
--- a/xpfe/appshell/src/nsXULWindow.h
+++ b/xpfe/appshell/src/nsXULWindow.h
@@ -12,17 +12,16 @@
 #include "nsContentTreeOwner.h"
 
 // Helper classes
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsWeakReference.h"
 #include "nsCOMArray.h"
-#include "nsRect.h"
 
 // Interfaces needed
 #include "nsIBaseWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIDOMWindow.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"