Bug 920377 part.17 Get rid of nsKeyEvent r=roc
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 01 Oct 2013 16:22:58 +0900
changeset 164193 d2f6e4dd2f91616436be308f81309a9f69eff073
parent 164192 4665d96e7f1a75a7830c8ccd2cc22a4dfa21b0e2
child 164194 f94d70152968eafb220ca09cd6196458e36a94a1
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)
reviewersroc
bugs920377
milestone27.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 920377 part.17 Get rid of nsKeyEvent r=roc
content/base/public/nsContentUtils.h
content/base/src/Element.cpp
content/base/src/nsContentUtils.cpp
content/events/src/nsDOMEvent.cpp
content/events/src/nsDOMKeyboardEvent.cpp
content/events/src/nsDOMKeyboardEvent.h
content/events/src/nsDOMUIEvent.cpp
content/events/src/nsEventDispatcher.cpp
content/events/src/nsEventStateManager.cpp
content/events/src/nsEventStateManager.h
content/html/content/src/HTMLButtonElement.cpp
content/html/content/src/HTMLInputElement.cpp
content/html/content/src/nsTextEditorState.cpp
content/xbl/src/nsXBLWindowKeyHandler.cpp
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/events/nsIDOMEvent.idl
dom/ipc/PBrowser.ipdl
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
dom/plugins/base/nsPluginInstanceOwner.cpp
dom/plugins/ipc/PPluginInstance.ipdl
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditor.h
editor/libeditor/html/nsHTMLEditor.cpp
editor/libeditor/text/nsPlaintextEditor.cpp
layout/base/nsPresShell.cpp
layout/base/nsPresShell.h
layout/forms/nsListControlFrame.cpp
layout/xul/base/src/nsButtonBoxFrame.cpp
layout/xul/base/src/nsMenuBarFrame.cpp
layout/xul/base/src/nsMenuBarListener.cpp
layout/xul/base/src/nsMenuFrame.cpp
widget/EventForwards.h
widget/TextEvents.h
widget/android/nsWindow.cpp
widget/android/nsWindow.h
widget/cocoa/NativeKeyBindings.h
widget/cocoa/NativeKeyBindings.mm
widget/cocoa/TextInputHandler.h
widget/cocoa/TextInputHandler.mm
widget/cocoa/nsChildView.mm
widget/gonk/nsAppShell.cpp
widget/gtk/nsGtkKeyUtils.cpp
widget/gtk/nsGtkKeyUtils.h
widget/gtk/nsNativeKeyBindings.cpp
widget/gtk/nsNativeKeyBindings.h
widget/gtk/nsWindow.cpp
widget/nsGUIEventIPC.h
widget/nsINativeKeyBindings.h
widget/os2/nsWindow.cpp
widget/qt/nsWindow.cpp
widget/windows/KeyboardLayout.cpp
widget/windows/KeyboardLayout.h
widget/windows/winrt/MetroWidget.cpp
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -1386,18 +1386,19 @@ public:
 
   /**
    * Get the candidates for accesskeys for aNativeKeyEvent.
    *
    * @param aNativeKeyEvent [in] the key event for accesskey handling.
    * @param aCandidates [out] the candidate access key list.
    *                          the first item is most preferred.
    */
-  static void GetAccessKeyCandidates(nsKeyEvent* aNativeKeyEvent,
-                                     nsTArray<uint32_t>& aCandidates);
+  static void GetAccessKeyCandidates(
+                mozilla::WidgetKeyboardEvent* aNativeKeyEvent,
+                nsTArray<uint32_t>& aCandidates);
 
   /**
    * Hide any XUL popups associated with aDocument, including any documents
    * displayed in child frames. Does nothing if aDocument is null.
    */
   static void HidePopupsInDocument(nsIDocument* aDocument);
 
   /**
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -2250,17 +2250,18 @@ Element::PostHandleEventForLinks(nsEvent
         aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
       }
     }
     break;
 
   case NS_KEY_PRESS:
     {
       if (aVisitor.mEvent->eventStructType == NS_KEY_EVENT) {
-        nsKeyEvent* keyEvent = static_cast<nsKeyEvent*>(aVisitor.mEvent);
+        WidgetKeyboardEvent* keyEvent =
+          static_cast<WidgetKeyboardEvent*>(aVisitor.mEvent);
         if (keyEvent->keyCode == NS_VK_RETURN) {
           nsEventStatus status = nsEventStatus_eIgnore;
           rv = DispatchClickEvent(aVisitor.mPresContext, keyEvent, this,
                                   false, nullptr, &status);
           if (NS_SUCCEEDED(rv)) {
             aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
           }
         }
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -4594,18 +4594,18 @@ nsContentUtils::GetAccelKeyCandidates(ns
   NS_PRECONDITION(aCandidates.IsEmpty(), "aCandidates must be empty");
 
   nsAutoString eventType;
   aDOMKeyEvent->GetType(eventType);
   // Don't process if aDOMKeyEvent is not a keypress event.
   if (!eventType.EqualsLiteral("keypress"))
     return;
 
-  nsKeyEvent* nativeKeyEvent =
-    static_cast<nsKeyEvent*>(GetNativeEvent(aDOMKeyEvent));
+  WidgetKeyboardEvent* nativeKeyEvent =
+    static_cast<WidgetKeyboardEvent*>(GetNativeEvent(aDOMKeyEvent));
   if (nativeKeyEvent) {
     NS_ASSERTION(nativeKeyEvent->eventStructType == NS_KEY_EVENT,
                  "wrong type of native event");
     // nsShortcutCandidate::mCharCode is a candidate charCode.
     // nsShoftcutCandidate::mIgnoreShift means the mCharCode should be tried to
     // execute a command with/without shift key state. If this is TRUE, the
     // shifted key state should be ignored. Otherwise, don't ignore the state.
     // the priority of the charCodes are (shift key is not pressed):
@@ -4686,17 +4686,17 @@ nsContentUtils::GetAccelKeyCandidates(ns
       nsShortcutCandidate key(charCode, false);
       aCandidates.AppendElement(key);
     }
   }
 }
 
 /* static */
 void
-nsContentUtils::GetAccessKeyCandidates(nsKeyEvent* aNativeKeyEvent,
+nsContentUtils::GetAccessKeyCandidates(WidgetKeyboardEvent* aNativeKeyEvent,
                                        nsTArray<uint32_t>& aCandidates)
 {
   NS_PRECONDITION(aCandidates.IsEmpty(), "aCandidates must be empty");
 
   // return the lower cased charCode candidates for access keys.
   // the priority of the charCodes are:
   //   0: charCode, 1: unshiftedCharCodes[0], 2: shiftedCharCodes[0]
   //   3: unshiftedCharCodes[1], 4: shiftedCharCodes[1],...
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -533,18 +533,20 @@ nsDOMEvent::DuplicatePrivateData()
       nsInputEvent* oldInputEvent = static_cast<nsInputEvent*>(mEvent);
       nsInputEvent* inputEvent = new nsInputEvent(false, msg, nullptr);
       inputEvent->AssignInputEventData(*oldInputEvent, true);
       newEvent = inputEvent;
       break;
     }
     case NS_KEY_EVENT:
     {
-      nsKeyEvent* oldKeyEvent = static_cast<nsKeyEvent*>(mEvent);
-      nsKeyEvent* keyEvent = new nsKeyEvent(false, msg, nullptr);
+      WidgetKeyboardEvent* oldKeyEvent =
+        static_cast<WidgetKeyboardEvent*>(mEvent);
+      WidgetKeyboardEvent* keyEvent =
+        new WidgetKeyboardEvent(false, msg, nullptr);
       keyEvent->AssignKeyEventData(*oldKeyEvent, true);
       newEvent = keyEvent;
       break;
     }
     case NS_MOUSE_EVENT:
     {
       nsMouseEvent* oldMouseEvent = static_cast<nsMouseEvent*>(mEvent);
       nsMouseEvent* mouseEvent =
@@ -890,17 +892,17 @@ nsDOMEvent::GetEventPopupControlState(ns
       case NS_XUL_COMMAND:
         abuse = openControlled;
         break;
       }
     }
     break;
   case NS_KEY_EVENT :
     if (aEvent->mFlags.mIsTrusted) {
-      uint32_t key = static_cast<nsKeyEvent *>(aEvent)->keyCode;
+      uint32_t key = static_cast<WidgetKeyboardEvent*>(aEvent)->keyCode;
       switch(aEvent->message) {
       case NS_KEY_PRESS :
         // return key on focused button. see note at NS_MOUSE_CLICK.
         if (key == nsIDOMKeyEvent::DOM_VK_RETURN)
           abuse = openAllowed;
         else if (::PopupAllowedForEvent("keypress"))
           abuse = openControlled;
         break;
--- a/content/events/src/nsDOMKeyboardEvent.cpp
+++ b/content/events/src/nsDOMKeyboardEvent.cpp
@@ -2,37 +2,39 @@
 /* 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 "nsDOMKeyboardEvent.h"
 #include "prtime.h"
 #include "mozilla/TextEvents.h"
 
+using namespace mozilla;
+
 nsDOMKeyboardEvent::nsDOMKeyboardEvent(mozilla::dom::EventTarget* aOwner,
                                        nsPresContext* aPresContext,
-                                       nsKeyEvent* aEvent)
+                                       WidgetKeyboardEvent* aEvent)
   : nsDOMUIEvent(aOwner, aPresContext, aEvent ? aEvent :
-                 new nsKeyEvent(false, 0, nullptr))
+                 new WidgetKeyboardEvent(false, 0, nullptr))
 {
   NS_ASSERTION(mEvent->eventStructType == NS_KEY_EVENT, "event type mismatch");
 
   if (aEvent) {
     mEventIsInternal = false;
   }
   else {
     mEventIsInternal = true;
     mEvent->time = PR_Now();
   }
 }
 
 nsDOMKeyboardEvent::~nsDOMKeyboardEvent()
 {
   if (mEventIsInternal) {
-    delete static_cast<nsKeyEvent*>(mEvent);
+    delete static_cast<WidgetKeyboardEvent*>(mEvent);
     mEvent = nullptr;
   }
 }
 
 NS_IMPL_ADDREF_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent)
 NS_IMPL_RELEASE_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent)
 
 NS_INTERFACE_MAP_BEGIN(nsDOMKeyboardEvent)
@@ -80,17 +82,17 @@ nsDOMKeyboardEvent::GetModifierState(con
   *aState = GetModifierState(aKey);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMKeyboardEvent::GetKey(nsAString& aKeyName)
 {
   if (!mEventIsInternal) {
-    static_cast<nsKeyEvent*>(mEvent)->GetDOMKeyName(aKeyName);
+    static_cast<WidgetKeyboardEvent*>(mEvent)->GetDOMKeyName(aKeyName);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMKeyboardEvent::GetCharCode(uint32_t* aCharCode)
 {
   NS_ENSURE_ARG_POINTER(aCharCode);
@@ -101,17 +103,17 @@ nsDOMKeyboardEvent::GetCharCode(uint32_t
 uint32_t
 nsDOMKeyboardEvent::CharCode()
 {
   switch (mEvent->message) {
   case NS_KEY_UP:
   case NS_KEY_DOWN:
     return 0;
   case NS_KEY_PRESS:
-    return static_cast<nsKeyEvent*>(mEvent)->charCode;
+    return static_cast<WidgetKeyboardEvent*>(mEvent)->charCode;
   }
   return 0;
 }
 
 NS_IMETHODIMP
 nsDOMKeyboardEvent::GetKeyCode(uint32_t* aKeyCode)
 {
   NS_ENSURE_ARG_POINTER(aKeyCode);
@@ -121,33 +123,33 @@ nsDOMKeyboardEvent::GetKeyCode(uint32_t*
 
 uint32_t
 nsDOMKeyboardEvent::KeyCode()
 {
   switch (mEvent->message) {
   case NS_KEY_UP:
   case NS_KEY_PRESS:
   case NS_KEY_DOWN:
-    return static_cast<nsKeyEvent*>(mEvent)->keyCode;
+    return static_cast<WidgetKeyboardEvent*>(mEvent)->keyCode;
   }
   return 0;
 }
 
 uint32_t
 nsDOMKeyboardEvent::Which()
 {
   switch (mEvent->message) {
     case NS_KEY_UP:
     case NS_KEY_DOWN:
       return KeyCode();
     case NS_KEY_PRESS:
       //Special case for 4xp bug 62878.  Try to make value of which
       //more closely mirror the values that 4.x gave for RETURN and BACKSPACE
       {
-        uint32_t keyCode = ((nsKeyEvent*)mEvent)->keyCode;
+        uint32_t keyCode = static_cast<WidgetKeyboardEvent*>(mEvent)->keyCode;
         if (keyCode == NS_VK_RETURN || keyCode == NS_VK_BACK) {
           return keyCode;
         }
         return CharCode();
       }
   }
 
   return 0;
@@ -166,24 +168,24 @@ NS_IMETHODIMP
 nsDOMKeyboardEvent::InitKeyEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
                                  nsIDOMWindow* aView, bool aCtrlKey, bool aAltKey,
                                  bool aShiftKey, bool aMetaKey,
                                  uint32_t aKeyCode, uint32_t aCharCode)
 {
   nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsKeyEvent* keyEvent = static_cast<nsKeyEvent*>(mEvent);
+  WidgetKeyboardEvent* keyEvent = static_cast<WidgetKeyboardEvent*>(mEvent);
   keyEvent->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
   keyEvent->keyCode = aKeyCode;
   keyEvent->charCode = aCharCode;
 
   return NS_OK;
 }
 
 nsresult NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult,
                                 mozilla::dom::EventTarget* aOwner,
                                 nsPresContext* aPresContext,
-                                nsKeyEvent *aEvent)
+                                WidgetKeyboardEvent* aEvent)
 {
   nsDOMKeyboardEvent* it = new nsDOMKeyboardEvent(aOwner, aPresContext, aEvent);
   return CallQueryInterface(it, aInstancePtrResult);
 }
--- a/content/events/src/nsDOMKeyboardEvent.h
+++ b/content/events/src/nsDOMKeyboardEvent.h
@@ -12,17 +12,18 @@
 #include "mozilla/dom/KeyboardEventBinding.h"
 #include "mozilla/TextEvents.h"
 
 class nsDOMKeyboardEvent : public nsDOMUIEvent,
                            public nsIDOMKeyEvent
 {
 public:
   nsDOMKeyboardEvent(mozilla::dom::EventTarget* aOwner,
-                     nsPresContext* aPresContext, nsKeyEvent* aEvent);
+                     nsPresContext* aPresContext,
+                     mozilla::WidgetKeyboardEvent* aEvent);
   virtual ~nsDOMKeyboardEvent();
 
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMKeyEvent Interface
   NS_DECL_NSIDOMKEYEVENT
 
   // Forward to base class
@@ -60,17 +61,17 @@ public:
   }
 
   uint32_t CharCode();
   uint32_t KeyCode();
   virtual uint32_t Which() MOZ_OVERRIDE;
 
   uint32_t Location()
   {
-    return static_cast<nsKeyEvent*>(mEvent)->location;
+    return static_cast<mozilla::WidgetKeyboardEvent*>(mEvent)->location;
   }
 
   void InitKeyEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
                     nsIDOMWindow* aView, bool aCtrlKey, bool aAltKey,
                     bool aShiftKey, bool aMetaKey,
                     uint32_t aKeyCode, uint32_t aCharCode,
                     mozilla::ErrorResult& aRv)
   {
--- a/content/events/src/nsDOMUIEvent.cpp
+++ b/content/events/src/nsDOMUIEvent.cpp
@@ -344,17 +344,17 @@ nsDOMUIEvent::GetIsChar(bool* aIsChar)
 }
 
 bool
 nsDOMUIEvent::IsChar() const
 {
   switch (mEvent->eventStructType)
   {
     case NS_KEY_EVENT:
-      return static_cast<nsKeyEvent*>(mEvent)->isChar;
+      return static_cast<WidgetKeyboardEvent*>(mEvent)->isChar;
     case NS_TEXT_EVENT:
       return static_cast<nsTextEvent*>(mEvent)->isChar;
     default:
       return false;
   }
   MOZ_CRASH("Switch handles all cases.");
 }
 
--- a/content/events/src/nsEventDispatcher.cpp
+++ b/content/events/src/nsEventDispatcher.cpp
@@ -698,17 +698,17 @@ nsEventDispatcher::CreateEvent(mozilla::
     case NS_UI_EVENT:
       return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext,
                               static_cast<nsGUIEvent*>(aEvent));
     case NS_SCROLLAREA_EVENT:
       return NS_NewDOMScrollAreaEvent(aDOMEvent, aOwner, aPresContext,
                static_cast<InternalScrollAreaEvent*>(aEvent));
     case NS_KEY_EVENT:
       return NS_NewDOMKeyboardEvent(aDOMEvent, aOwner, aPresContext,
-                                    static_cast<nsKeyEvent*>(aEvent));
+                                    static_cast<WidgetKeyboardEvent*>(aEvent));
     case NS_COMPOSITION_EVENT:
       return NS_NewDOMCompositionEvent(
         aDOMEvent, aOwner,
         aPresContext, static_cast<nsCompositionEvent*>(aEvent));
     case NS_MOUSE_EVENT:
       return NS_NewDOMMouseEvent(aDOMEvent, aOwner, aPresContext,
                                  static_cast<nsInputEvent*>(aEvent));
     case NS_FOCUS_EVENT:
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -930,17 +930,17 @@ nsEventStateManager::PreHandleEvent(nsPr
     // NS_DRAGDROP_DROP is fired before NS_DRAGDROP_DRAGDROP so send
     // the enter/exit events before NS_DRAGDROP_DROP.
     GenerateDragDropEnterExit(aPresContext, (nsGUIEvent*)aEvent);
     break;
 
   case NS_KEY_PRESS:
     {
 
-      nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
+      WidgetKeyboardEvent* keyEvent = static_cast<WidgetKeyboardEvent*>(aEvent);
 
       int32_t modifierMask = 0;
       if (keyEvent->IsShift())
         modifierMask |= NS_MODIFIER_SHIFT;
       if (keyEvent->IsControl())
         modifierMask |= NS_MODIFIER_CONTROL;
       if (keyEvent->IsAlt())
         modifierMask |= NS_MODIFIER_ALT;
@@ -1273,17 +1273,17 @@ nsEventStateManager::GetAccessKeyLabelPr
     nsContentUtils::GetShiftText(modifierText);
     aPrefix.Append(modifierText + separator);
   }
   return !aPrefix.IsEmpty();
 }
 
 void
 nsEventStateManager::HandleAccessKey(nsPresContext* aPresContext,
-                                     nsKeyEvent *aEvent,
+                                     WidgetKeyboardEvent* aEvent,
                                      nsEventStatus* aStatus,
                                      nsIDocShellTreeItem* aBubbledFrom,
                                      ProcessingAccessKeyState aAccessKeyState,
                                      int32_t aModifierMask)
 {
   nsCOMPtr<nsISupports> pcContainer = aPresContext->GetContainer();
 
   // Alt or other accesskey modifier is down, we may need to do an accesskey
@@ -1383,17 +1383,17 @@ nsEventStateManager::DispatchCrossProces
   }
 
   switch (aEvent->eventStructType) {
   case NS_MOUSE_EVENT: {
     nsMouseEvent* mouseEvent = static_cast<nsMouseEvent*>(aEvent);
     return remote->SendRealMouseEvent(*mouseEvent);
   }
   case NS_KEY_EVENT: {
-    nsKeyEvent* keyEvent = static_cast<nsKeyEvent*>(aEvent);
+    WidgetKeyboardEvent* keyEvent = static_cast<WidgetKeyboardEvent*>(aEvent);
     return remote->SendRealKeyEvent(*keyEvent);
   }
   case NS_WHEEL_EVENT: {
     WheelEvent* wheelEvent = static_cast<WheelEvent*>(aEvent);
     return remote->SendMouseWheelEvent(*wheelEvent);
   }
   case NS_TOUCH_EVENT: {
     // Let the child process synthesize a mouse event if needed, and
@@ -3375,17 +3375,17 @@ nsEventStateManager::PostHandleEvent(nsP
     GenerateDragDropEnterExit(presContext, (nsGUIEvent*)aEvent);
     break;
 
   case NS_KEY_UP:
     break;
 
   case NS_KEY_PRESS:
     if (nsEventStatus_eConsumeNoDefault != *aStatus) {
-      nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
+      WidgetKeyboardEvent* keyEvent = static_cast<WidgetKeyboardEvent*>(aEvent);
       //This is to prevent keyboard scrolling while alt modifier in use.
       if (!keyEvent->IsAlt()) {
         switch(keyEvent->keyCode) {
           case NS_VK_TAB:
           case NS_VK_F6:
             // Handling the tab event after it was sent to content is bad,
             // because to the FocusManager the remote-browser looks like one
             // element, so we would just move the focus to the next element
--- a/content/events/src/nsEventStateManager.h
+++ b/content/events/src/nsEventStateManager.h
@@ -323,17 +323,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,
-                       nsKeyEvent* aEvent,
+                       mozilla::WidgetKeyboardEvent* aEvent,
                        nsEventStatus* aStatus,
                        nsIDocShellTreeItem* aBubbledFrom,
                        ProcessingAccessKeyState aAccessKeyState,
                        int32_t aModifierMask);
 
   bool ExecuteAccessKey(nsTArray<uint32_t>& aAccessCharCodes,
                           bool aIsTrustedEvent);
 
--- a/content/html/content/src/HTMLButtonElement.cpp
+++ b/content/html/content/src/HTMLButtonElement.cpp
@@ -254,17 +254,18 @@ HTMLButtonElement::PostHandleEvent(nsEve
 
   if (nsEventStatus_eIgnore == aVisitor.mEventStatus) {
     switch (aVisitor.mEvent->message) {
       case NS_KEY_PRESS:
       case NS_KEY_UP:
         {
           // For backwards compat, trigger buttons with space or enter
           // (bug 25300)
-          nsKeyEvent * keyEvent = (nsKeyEvent *)aVisitor.mEvent;
+          WidgetKeyboardEvent* keyEvent =
+            static_cast<WidgetKeyboardEvent*>(aVisitor.mEvent);
           if ((keyEvent->keyCode == NS_VK_RETURN &&
                NS_KEY_PRESS == aVisitor.mEvent->message) ||
               (keyEvent->keyCode == NS_VK_SPACE &&
                NS_KEY_UP == aVisitor.mEvent->message)) {
             nsEventStatus status = nsEventStatus_eIgnore;
 
             nsMouseEvent event(aVisitor.mEvent->mFlags.mIsTrusted,
                                NS_MOUSE_CLICK, nullptr,
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -3411,17 +3411,18 @@ HTMLInputElement::PostHandleEvent(nsEven
           break;
         }
 
         case NS_KEY_PRESS:
         case NS_KEY_UP:
         {
           // For backwards compat, trigger checks/radios/buttons with
           // space or enter (bug 25300)
-          nsKeyEvent* keyEvent = (nsKeyEvent*)aVisitor.mEvent;
+          WidgetKeyboardEvent* keyEvent =
+            static_cast<WidgetKeyboardEvent*>(aVisitor.mEvent);
 
           if ((aVisitor.mEvent->message == NS_KEY_PRESS &&
                keyEvent->keyCode == NS_VK_RETURN) ||
               (aVisitor.mEvent->message == NS_KEY_UP &&
                keyEvent->keyCode == NS_VK_SPACE)) {
             switch(mType) {
               case NS_FORM_INPUT_CHECKBOX:
               case NS_FORM_INPUT_RADIO:
@@ -3745,17 +3746,18 @@ HTMLInputElement::PostHandleEventForRang
       // the drag and set our final value (unless someone has called
       // preventDefault() and prevents us getting here).
       FinishRangeThumbDrag(static_cast<nsInputEvent*>(aVisitor.mEvent));
       aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
       break;
 
     case NS_KEY_PRESS:
       if (mIsDraggingRange &&
-          static_cast<nsKeyEvent*>(aVisitor.mEvent)->keyCode == NS_VK_ESCAPE) {
+          static_cast<WidgetKeyboardEvent*>(aVisitor.mEvent)->keyCode ==
+            NS_VK_ESCAPE) {
         CancelRangeThumbDrag();
       }
       break;
 
     case NS_TOUCH_CANCEL:
       if (mIsDraggingRange) {
         CancelRangeThumbDrag();
       }
--- a/content/html/content/src/nsTextEditorState.cpp
+++ b/content/html/content/src/nsTextEditorState.cpp
@@ -847,18 +847,18 @@ nsTextInputListener::HandleEvent(nsIDOME
 
   bool isTrusted = false;
   rv = aEvent->GetIsTrusted(&isTrusted);
   NS_ENSURE_SUCCESS(rv, rv);
   if (!isTrusted) {
     return NS_OK;
   }
 
-  nsKeyEvent* keyEvent =
-    static_cast<nsKeyEvent*>(aEvent->GetInternalNSEvent());
+  WidgetKeyboardEvent* keyEvent =
+    static_cast<WidgetKeyboardEvent*>(aEvent->GetInternalNSEvent());
   if (keyEvent->eventStructType != NS_KEY_EVENT) {
     return NS_ERROR_UNEXPECTED;
   }
 
   nsINativeKeyBindings *bindings = GetKeyBindings();
   if (bindings) {
     bool handled = false;
     switch (keyEvent->message) {
--- a/content/xbl/src/nsXBLWindowKeyHandler.cpp
+++ b/content/xbl/src/nsXBLWindowKeyHandler.cpp
@@ -355,20 +355,20 @@ nsXBLWindowKeyHandler::WalkHandlers(nsID
   if (isEditor && GetEditorKeyBindings()) {
     // get the DOM window we're attached to
     nsCOMPtr<nsIControllers> controllers;
     nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(mTarget);
     if (root) {
       root->GetControllers(getter_AddRefs(controllers));
     }
 
-    nsKeyEvent* keyEvent =
-      static_cast<nsKeyEvent*>(aKeyEvent->GetInternalNSEvent());
+    WidgetKeyboardEvent* keyEvent =
+      static_cast<WidgetKeyboardEvent*>(aKeyEvent->GetInternalNSEvent());
     MOZ_ASSERT(keyEvent->eventStructType == NS_KEY_EVENT,
-               "DOM key event's internal event must be nsKeyEvent");
+               "DOM key event's internal event must be WidgetKeyboardEvent");
 
     bool handled = false;
     switch (keyEvent->message) {
       case NS_KEY_PRESS:
         handled = sNativeEditorBindings->KeyPress(*keyEvent,
                                                   DoCommandCallback,
                                                   controllers);
         break;
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -926,17 +926,17 @@ nsDOMWindowUtils::SendKeyEvent(const nsA
     msg = NS_KEY_DOWN;
   else if (aType.EqualsLiteral("keyup"))
     msg = NS_KEY_UP;
   else if (aType.EqualsLiteral("keypress"))
     msg = NS_KEY_PRESS;
   else
     return NS_ERROR_FAILURE;
 
-  nsKeyEvent event(true, msg, widget);
+  WidgetKeyboardEvent event(true, msg, widget);
   event.modifiers = GetWidgetModifiers(aModifiers);
 
   if (msg == NS_KEY_PRESS) {
     event.keyCode = aCharCode ? 0 : aKeyCode;
     event.charCode = aCharCode;
   } else {
     event.keyCode = aKeyCode;
     event.charCode = 0;
--- a/dom/interfaces/events/nsIDOMEvent.idl
+++ b/dom/interfaces/events/nsIDOMEvent.idl
@@ -268,17 +268,17 @@ NS_NewDOMClipboardEvent(nsIDOMEvent** aI
                         mozilla::dom::EventTarget* aOwner,
                         nsPresContext* aPresContext,
                         mozilla::InternalClipboardEvent* aEvent);
 
 nsresult
 NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult,
                        mozilla::dom::EventTarget* aOwner,
                        nsPresContext* aPresContext,
-                       nsKeyEvent* aEvent);
+                       mozilla::WidgetKeyboardEvent* aEvent);
 nsresult
 NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult,
                           mozilla::dom::EventTarget* aOwner,
                           nsPresContext* aPresContext,
                           nsCompositionEvent* aEvent);
 nsresult
 NS_NewDOMMutationEvent(nsIDOMEvent** aResult,
                        mozilla::dom::EventTarget* aOwner,
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -36,17 +36,17 @@ using mozilla::layout::ScrollingBehavior
 using mozilla::void_t;
 using mozilla::WindowsHandle;
 using nscolor;
 using nsCompositionEvent;
 using nsIMEUpdatePreference;
 using nsIntPoint;
 using nsIntRect;
 using nsIntSize;
-using nsKeyEvent;
+using mozilla::WidgetKeyboardEvent;
 using nsMouseEvent;
 using nsMouseScrollEvent;
 using mozilla::WheelEvent;
 using nsQueryContentEvent;
 using nsRect;
 using nsSelectionEvent;
 using nsTextEvent;
 using mozilla::WidgetTouchEvent;
@@ -360,17 +360,17 @@ child:
                float aX,
                float aY,
                int32_t aButton,
                int32_t aClickCount,
                int32_t aModifiers,
                bool aIgnoreRootScrollFrame);
 
     RealMouseEvent(nsMouseEvent event);
-    RealKeyEvent(nsKeyEvent event);
+    RealKeyEvent(WidgetKeyboardEvent event);
     MouseWheelEvent(WheelEvent event);
     RealTouchEvent(WidgetTouchEvent event);
     // We use a separate message for touchmove events only to apply
     // compression to them.
     RealTouchMoveEvent(WidgetTouchEvent event) compress;
 
     /**
      * @see nsIDOMWindowUtils sendKeyEvent.
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -1854,19 +1854,19 @@ TabChild::RecvRealTouchEvent(const Widge
 
 bool
 TabChild::RecvRealTouchMoveEvent(const WidgetTouchEvent& aEvent)
 {
   return RecvRealTouchEvent(aEvent);
 }
 
 bool
-TabChild::RecvRealKeyEvent(const nsKeyEvent& event)
+TabChild::RecvRealKeyEvent(const WidgetKeyboardEvent& event)
 {
-  nsKeyEvent localEvent(event);
+  WidgetKeyboardEvent localEvent(event);
   DispatchWidgetEvent(localEvent);
   return true;
 }
 
 bool
 TabChild::RecvKeyEvent(const nsString& aType,
                        const int32_t& aKeyCode,
                        const int32_t& aCharCode,
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -211,17 +211,17 @@ public:
     virtual bool RecvMouseEvent(const nsString& aType,
                                 const float&    aX,
                                 const float&    aY,
                                 const int32_t&  aButton,
                                 const int32_t&  aClickCount,
                                 const int32_t&  aModifiers,
                                 const bool&     aIgnoreRootScrollFrame);
     virtual bool RecvRealMouseEvent(const nsMouseEvent& event);
-    virtual bool RecvRealKeyEvent(const nsKeyEvent& event);
+    virtual bool RecvRealKeyEvent(const mozilla::WidgetKeyboardEvent& event);
     virtual bool RecvMouseWheelEvent(const mozilla::WheelEvent& event);
     virtual bool RecvRealTouchEvent(const WidgetTouchEvent& event);
     virtual bool RecvRealTouchMoveEvent(const WidgetTouchEvent& event);
     virtual bool RecvKeyEvent(const nsString& aType,
                               const int32_t&  aKeyCode,
                               const int32_t&  aCharCode,
                               const int32_t&  aModifiers,
                               const bool&     aPreventDefault);
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -655,22 +655,22 @@ bool TabParent::SendMouseWheelEvent(Whee
   WheelEvent e(event);
   MaybeForwardEventToRenderFrame(event, &e);
   if (!MapEventCoordinatesForChildProcess(&e)) {
     return false;
   }
   return PBrowserParent::SendMouseWheelEvent(event);
 }
 
-bool TabParent::SendRealKeyEvent(nsKeyEvent& event)
+bool TabParent::SendRealKeyEvent(WidgetKeyboardEvent& event)
 {
   if (mIsDestroyed) {
     return false;
   }
-  nsKeyEvent e(event);
+  WidgetKeyboardEvent e(event);
   MaybeForwardEventToRenderFrame(event, &e);
   if (!MapEventCoordinatesForChildProcess(&e)) {
     return false;
   }
   return PBrowserParent::SendRealKeyEvent(e);
 }
 
 bool TabParent::SendRealTouchEvent(WidgetTouchEvent& event)
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -190,17 +190,17 @@ public:
     void SendMouseEvent(const nsAString& aType, float aX, float aY,
                         int32_t aButton, int32_t aClickCount,
                         int32_t aModifiers, bool aIgnoreRootScrollFrame);
     void SendKeyEvent(const nsAString& aType, int32_t aKeyCode,
                       int32_t aCharCode, int32_t aModifiers,
                       bool aPreventDefault);
     bool SendRealMouseEvent(nsMouseEvent& event);
     bool SendMouseWheelEvent(mozilla::WheelEvent& event);
-    bool SendRealKeyEvent(nsKeyEvent& event);
+    bool SendRealKeyEvent(mozilla::WidgetKeyboardEvent& event);
     bool SendRealTouchEvent(WidgetTouchEvent& event);
 
     virtual PDocumentRendererParent*
     AllocPDocumentRendererParent(const nsRect& documentRect, const gfxMatrix& transform,
                                  const nsString& bgcolor,
                                  const uint32_t& renderFlags, const bool& flushLayout,
                                  const nsIntSize& renderSize);
     virtual bool DeallocPDocumentRendererParent(PDocumentRendererParent* actor);
--- a/dom/plugins/base/nsPluginInstanceOwner.cpp
+++ b/dom/plugins/base/nsPluginInstanceOwner.cpp
@@ -2326,17 +2326,18 @@ nsEventStatus nsPluginInstanceOwner::Pro
               break;
             case NS_KEY_UP:
               event.type = KeyRelease;
               break;
             }
 #endif
 
 #ifdef MOZ_WIDGET_QT
-          const nsKeyEvent& keyEvent = static_cast<const nsKeyEvent&>(anEvent);
+          const WidgetKeyboardEvent& keyEvent =
+            static_cast<const WidgetKeyboardEvent&>(anEvent);
 
           memset( &event, 0, sizeof(event) );
           event.time = anEvent.time;
 
           QWidget* qWidget = static_cast<QWidget*>(widget->GetNativeData(NS_NATIVE_WINDOW));
 
           if (qWidget)
 #if defined(Q_WS_X11)
@@ -2487,17 +2488,18 @@ nsEventStatus nsPluginInstanceOwner::Pro
             }
             break;
           }
       }
       break;
 
     case NS_KEY_EVENT:
      {
-       const nsKeyEvent& keyEvent = static_cast<const nsKeyEvent&>(anEvent);
+       const WidgetKeyboardEvent& keyEvent =
+         static_cast<const WidgetKeyboardEvent&>(anEvent);
        LOG("Firing NS_KEY_EVENT %d %d\n", keyEvent.keyCode, keyEvent.charCode);
        // pluginEvent is initialized by nsWindow::InitKeyEvent().
        ANPEvent* pluginEvent = reinterpret_cast<ANPEvent*>(keyEvent.pluginEvent);
        if (pluginEvent) {
          MOZ_ASSERT(pluginEvent->inSize == sizeof(ANPEvent));
          MOZ_ASSERT(pluginEvent->eventType == kKey_ANPEventType);
          mInstance->HandleEvent(pluginEvent, nullptr, NS_PLUGIN_CALL_SAFE_TO_REENTER_GECKO);
        }
--- a/dom/plugins/ipc/PPluginInstance.ipdl
+++ b/dom/plugins/ipc/PPluginInstance.ipdl
@@ -28,17 +28,16 @@ using gfxSurfaceType;
 using gfxIntSize;
 using mozilla::null_t;
 using mozilla::plugins::WindowsSharedMemoryHandle;
 using mozilla::plugins::DXGISharedSurfaceHandle;
 using mozilla::CrossProcessMutexHandle;
 using SurfaceDescriptorX11;
 using nsIntRect;
 using nsTextEvent;
-using nsKeyEvent;
 
 namespace mozilla {
 namespace plugins {
 
 struct IOSurfaceDescriptor {
   uint32_t surfaceId;
   double contentsScaleFactor;
 };
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -4804,17 +4804,17 @@ nsEditor::HandleKeyPressEvent(nsIDOMKeyE
 {
   // NOTE: When you change this method, you should also change:
   //   * editor/libeditor/text/tests/test_texteditor_keyevent_handling.html
   //   * editor/libeditor/html/tests/test_htmleditor_keyevent_handling.html
   //
   // And also when you add new key handling, you need to change the subclass's
   // HandleKeyPressEvent()'s switch statement.
 
-  nsKeyEvent* nativeKeyEvent = GetNativeKeyEvent(aKeyEvent);
+  WidgetKeyboardEvent* nativeKeyEvent = GetNativeKeyEvent(aKeyEvent);
   NS_ENSURE_TRUE(nativeKeyEvent, NS_ERROR_UNEXPECTED);
   NS_ASSERTION(nativeKeyEvent->message == NS_KEY_PRESS,
                "HandleKeyPressEvent gets non-keypress event");
 
   // if we are readonly or disabled, then do nothing.
   if (IsReadonly() || IsDisabled()) {
     // consume backspace for disabled and readonly textfields, to prevent
     // back in history, which could be confusing to users
@@ -5157,24 +5157,24 @@ nsEditor::IsModifiableNode(nsIDOMNode *a
 }
 
 bool
 nsEditor::IsModifiableNode(nsINode *aNode)
 {
   return true;
 }
 
-nsKeyEvent*
+WidgetKeyboardEvent*
 nsEditor::GetNativeKeyEvent(nsIDOMKeyEvent* aDOMKeyEvent)
 {
   NS_ENSURE_TRUE(aDOMKeyEvent, nullptr);
   nsEvent* nativeEvent = aDOMKeyEvent->GetInternalNSEvent();
   NS_ENSURE_TRUE(nativeEvent, nullptr);
   NS_ENSURE_TRUE(nativeEvent->eventStructType == NS_KEY_EVENT, nullptr);
-  return static_cast<nsKeyEvent*>(nativeEvent);
+  return static_cast<WidgetKeyboardEvent*>(nativeEvent);
 }
 
 already_AddRefed<nsIContent>
 nsEditor::GetFocusedContent()
 {
   nsCOMPtr<nsIDOMEventTarget> piTarget = GetDOMEventTarget();
   if (!piTarget) {
     return nullptr;
--- a/editor/libeditor/base/nsEditor.h
+++ b/editor/libeditor/base/nsEditor.h
@@ -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/. */
 
 #ifndef __editor_h__
 #define __editor_h__
 
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc.
-#include "mozilla/EventForwards.h"      // for nsKeyEvent
+#include "mozilla/EventForwards.h"      // for WidgetKeyboardEvent
 #include "mozilla/TypedEnum.h"          // for MOZ_BEGIN_ENUM_CLASS, etc.
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsCOMArray.h"                 // for nsCOMArray
 #include "nsCOMPtr.h"                   // for already_AddRefed, nsCOMPtr
 #include "nsCycleCollectionParticipant.h"
 #include "nsEditProperty.h"             // for nsEditProperty, etc
 #include "nsIEditor.h"                  // for nsIEditor::EDirection, etc
 #include "nsIEditorIMESupport.h"        // for NS_DECL_NSIEDITORIMESUPPORT, etc
@@ -400,17 +400,17 @@ protected:
   // unregister and release our event listeners
   virtual void RemoveEventListeners();
 
   /**
    * Return true if spellchecking should be enabled for this editor.
    */
   bool GetDesiredSpellCheckState();
 
-  nsKeyEvent* GetNativeKeyEvent(nsIDOMKeyEvent* aDOMKeyEvent);
+  mozilla::WidgetKeyboardEvent* GetNativeKeyEvent(nsIDOMKeyEvent* aDOMKeyEvent);
 
   bool CanEnableSpellCheck()
   {
     // Check for password/readonly/disabled, which are not spellchecked
     // regardless of DOM. Also, check to see if spell check should be skipped or not.
     return !IsPasswordEditor() && !IsReadonly() && !IsDisabled() && !ShouldSkipSpellCheck();
   }
 
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -586,17 +586,17 @@ nsHTMLEditor::HandleKeyPressEvent(nsIDOM
   //   * editor/libeditor/html/tests/test_htmleditor_keyevent_handling.html
 
   if (IsReadonly() || IsDisabled()) {
     // When we're not editable, the events are handled on nsEditor, so, we can
     // bypass nsPlaintextEditor.
     return nsEditor::HandleKeyPressEvent(aKeyEvent);
   }
 
-  nsKeyEvent* nativeKeyEvent = GetNativeKeyEvent(aKeyEvent);
+  WidgetKeyboardEvent* nativeKeyEvent = GetNativeKeyEvent(aKeyEvent);
   NS_ENSURE_TRUE(nativeKeyEvent, NS_ERROR_UNEXPECTED);
   NS_ASSERTION(nativeKeyEvent->message == NS_KEY_PRESS,
                "HandleKeyPressEvent gets non-keypress event");
 
   switch (nativeKeyEvent->keyCode) {
     case nsIDOMKeyEvent::DOM_VK_META:
     case nsIDOMKeyEvent::DOM_VK_WIN:
     case nsIDOMKeyEvent::DOM_VK_SHIFT:
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -350,17 +350,17 @@ nsPlaintextEditor::HandleKeyPressEvent(n
   // And also when you add new key handling, you need to change the subclass's
   // HandleKeyPressEvent()'s switch statement.
 
   if (IsReadonly() || IsDisabled()) {
     // When we're not editable, the events handled on nsEditor.
     return nsEditor::HandleKeyPressEvent(aKeyEvent);
   }
 
-  nsKeyEvent* nativeKeyEvent = GetNativeKeyEvent(aKeyEvent);
+  WidgetKeyboardEvent* nativeKeyEvent = GetNativeKeyEvent(aKeyEvent);
   NS_ENSURE_TRUE(nativeKeyEvent, NS_ERROR_UNEXPECTED);
   NS_ASSERTION(nativeKeyEvent->message == NS_KEY_PRESS,
                "HandleKeyPressEvent gets non-keypress event");
 
   switch (nativeKeyEvent->keyCode) {
     case nsIDOMKeyEvent::DOM_VK_META:
     case nsIDOMKeyEvent::DOM_VK_WIN:
     case nsIDOMKeyEvent::DOM_VK_SHIFT:
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -6088,17 +6088,17 @@ PresShell::HandleEvent(nsIFrame        *
   }
 
   if (aEvent->eventStructType == NS_KEY_EVENT &&
       mDocument && mDocument->EventHandlingSuppressed()) {
     if (aEvent->message == NS_KEY_DOWN) {
       mNoDelayedKeyEvents = true;
     } else if (!mNoDelayedKeyEvents) {
       nsDelayedEvent* event =
-        new nsDelayedKeyEvent(static_cast<nsKeyEvent*>(aEvent));
+        new nsDelayedKeyEvent(static_cast<WidgetKeyboardEvent*>(aEvent));
       if (!mDelayedEvents.AppendElement(event)) {
         delete event;
       }
     }
     return NS_OK;
   }
 
   nsIFrame* frame = aFrame;
@@ -6673,17 +6673,18 @@ PresShell::HandleEventInternal(nsEvent* 
     if (aEvent->mFlags.mIsTrusted) {
       switch (aEvent->message) {
       case NS_KEY_PRESS:
       case NS_KEY_DOWN:
       case NS_KEY_UP: {
         nsIDocument* doc = GetCurrentEventContent() ?
                            mCurrentEventContent->OwnerDoc() : nullptr;
         nsIDocument* fullscreenAncestor = nullptr;
-        if (static_cast<const nsKeyEvent*>(aEvent)->keyCode == NS_VK_ESCAPE) {
+        if (static_cast<const WidgetKeyboardEvent*>(aEvent)->keyCode ==
+              NS_VK_ESCAPE) {
           if ((fullscreenAncestor = nsContentUtils::GetFullscreenAncestor(doc))) {
             // Prevent default action on ESC key press when exiting
             // DOM fullscreen mode. This prevents the browser ESC key
             // handler from stopping all loads in the document, which
             // would cause <video> loads to stop.
             aEvent->mFlags.mDefaultPrevented = true;
             aEvent->mFlags.mOnlyChromeDispatch = true;
 
--- a/layout/base/nsPresShell.h
+++ b/layout/base/nsPresShell.h
@@ -583,27 +583,29 @@ protected:
     {
       delete static_cast<nsMouseEvent*>(mEvent);
     }
   };
 
   class nsDelayedKeyEvent : public nsDelayedInputEvent
   {
   public:
-    nsDelayedKeyEvent(nsKeyEvent* aEvent) : nsDelayedInputEvent()
+    nsDelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent) :
+      nsDelayedInputEvent()
     {
-      mEvent = new nsKeyEvent(aEvent->mFlags.mIsTrusted,
-                              aEvent->message,
-                              aEvent->widget);
-      static_cast<nsKeyEvent*>(mEvent)->AssignKeyEventData(*aEvent, false);
+      mEvent = new mozilla::WidgetKeyboardEvent(aEvent->mFlags.mIsTrusted,
+                                                aEvent->message,
+                                                aEvent->widget);
+      static_cast<mozilla::WidgetKeyboardEvent*>(mEvent)->
+        AssignKeyEventData(*aEvent, false);
     }
 
     virtual ~nsDelayedKeyEvent()
     {
-      delete static_cast<nsKeyEvent*>(mEvent);
+      delete static_cast<mozilla::WidgetKeyboardEvent*>(mEvent);
     }
   };
 
   // Check if aEvent is a mouse event and record the mouse location for later
   // synth mouse moves.
   void RecordMouseLocation(nsGUIEvent* aEvent);
   class nsSynthMouseMoveEvent MOZ_FINAL : public nsARefreshObserver {
   public:
--- a/layout/forms/nsListControlFrame.cpp
+++ b/layout/forms/nsListControlFrame.cpp
@@ -2073,21 +2073,21 @@ nsListControlFrame::KeyDown(nsIDOMEvent*
   nsEventStates eventStates = mContent->AsElement()->State();
   if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
     return NS_OK;
   }
 
   // Don't check defaultPrevented value because other browsers don't prevent
   // the key navigation of list control even if preventDefault() is called.
 
-  const nsKeyEvent* keyEvent =
-    static_cast<nsKeyEvent*>(aKeyEvent->GetInternalNSEvent());
+  const WidgetKeyboardEvent* keyEvent =
+    static_cast<WidgetKeyboardEvent*>(aKeyEvent->GetInternalNSEvent());
   MOZ_ASSERT(keyEvent, "DOM event must have internal event");
   MOZ_ASSERT(keyEvent->eventStructType == NS_KEY_EVENT,
-             "The keydown event's internal event struct must be nsKeyEvent");
+    "The keydown event's internal event struct must be WidgetKeyboardEvent");
 
   if (keyEvent->IsAlt()) {
     if (keyEvent->keyCode == NS_VK_UP || keyEvent->keyCode == NS_VK_DOWN) {
       DropDownToggleKey(aKeyEvent);
     }
     return NS_OK;
   }
 
@@ -2214,21 +2214,21 @@ nsListControlFrame::KeyPress(nsIDOMEvent
 {
   MOZ_ASSERT(aKeyEvent, "aKeyEvent is null.");
 
   nsEventStates eventStates = mContent->AsElement()->State();
   if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
     return NS_OK;
   }
 
-  const nsKeyEvent* keyEvent =
-    static_cast<nsKeyEvent*>(aKeyEvent->GetInternalNSEvent());
+  const WidgetKeyboardEvent* keyEvent =
+    static_cast<WidgetKeyboardEvent*>(aKeyEvent->GetInternalNSEvent());
   MOZ_ASSERT(keyEvent, "DOM event must have internal event");
   MOZ_ASSERT(keyEvent->eventStructType == NS_KEY_EVENT,
-             "The keydown event's internal event struct must be nsKeyEvent");
+    "The keydown event's internal event struct must be WidgetKeyboardEvent");
 
   // Select option with this as the first character
   // XXX Not I18N compliant
 
   // Don't do incremental search if the key event has already consumed.
   if (keyEvent->mFlags.mDefaultPrevented) {
     return NS_OK;
   }
--- a/layout/xul/base/src/nsButtonBoxFrame.cpp
+++ b/layout/xul/base/src/nsButtonBoxFrame.cpp
@@ -13,16 +13,17 @@
 #include "nsIPresShell.h"
 #include "nsEventStateManager.h"
 #include "nsIDOMElement.h"
 #include "nsDisplayList.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/TextEvents.h"
 
+using namespace mozilla;
 
 //
 // NS_NewXULButtonFrame
 //
 // Creates a new Button frame and returns it
 //
 nsIFrame*
 NS_NewButtonBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
@@ -51,45 +52,48 @@ nsButtonBoxFrame::HandleEvent(nsPresCont
   NS_ENSURE_ARG_POINTER(aEventStatus);
   if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
     return NS_OK;
   }
 
   switch (aEvent->message) {
     case NS_KEY_DOWN:
       if (NS_KEY_EVENT == aEvent->eventStructType) {
-        nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
+        WidgetKeyboardEvent* keyEvent =
+          static_cast<WidgetKeyboardEvent*>(aEvent);
         if (NS_VK_SPACE == keyEvent->keyCode) {
           nsEventStateManager *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 defualt button, not the focused one.
 #ifndef XP_MACOSX
     case NS_KEY_PRESS:
       if (NS_KEY_EVENT == aEvent->eventStructType) {
-        nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
+        WidgetKeyboardEvent* keyEvent =
+          static_cast<WidgetKeyboardEvent*>(aEvent);
         if (NS_VK_RETURN == keyEvent->keyCode) {
           nsCOMPtr<nsIDOMXULButtonElement> buttonEl(do_QueryInterface(mContent));
           if (buttonEl) {
             MouseClicked(aPresContext, aEvent);
             *aEventStatus = nsEventStatus_eConsumeNoDefault;
           }
         }
       }
       break;
 #endif
 
     case NS_KEY_UP:
       if (NS_KEY_EVENT == aEvent->eventStructType) {
-        nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
+        WidgetKeyboardEvent* keyEvent =
+          static_cast<WidgetKeyboardEvent*>(aEvent);
         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();
--- a/layout/xul/base/src/nsMenuBarFrame.cpp
+++ b/layout/xul/base/src/nsMenuBarFrame.cpp
@@ -22,16 +22,17 @@
 #ifdef XP_WIN
 #include "nsISound.h"
 #include "nsWidgetsCID.h"
 #endif
 #include "nsContentUtils.h"
 #include "nsUTF8Utils.h"
 #include "mozilla/TextEvents.h"
 
+using namespace mozilla;
 
 //
 // NS_NewMenuBarFrame
 //
 // Wrapper for creating a new menu Bar container
 //
 nsIFrame*
 NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
@@ -177,17 +178,18 @@ GetInsertionPoint(nsIPresShell* aShell, 
 nsMenuFrame*
 nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent)
 {
   uint32_t charCode;
   aKeyEvent->GetCharCode(&charCode);
 
   nsAutoTArray<uint32_t, 10> accessKeys;
   nsEvent* nativeEvent = nsContentUtils::GetNativeEvent(aKeyEvent);
-  nsKeyEvent* nativeKeyEvent = static_cast<nsKeyEvent*>(nativeEvent);
+  WidgetKeyboardEvent* nativeKeyEvent =
+    static_cast<WidgetKeyboardEvent*>(nativeEvent);
   if (nativeKeyEvent)
     nsContentUtils::GetAccessKeyCandidates(nativeKeyEvent, accessKeys);
   if (accessKeys.IsEmpty() && charCode)
     accessKeys.AppendElement(charCode);
 
   if (accessKeys.IsEmpty())
     return nullptr; // no character was pressed so just return
 
--- a/layout/xul/base/src/nsMenuBarListener.cpp
+++ b/layout/xul/base/src/nsMenuBarListener.cpp
@@ -193,17 +193,18 @@ nsMenuBarListener::KeyPress(nsIDOMEvent*
       nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
       uint32_t keyCode, charCode;
       keyEvent->GetKeyCode(&keyCode);
       keyEvent->GetCharCode(&charCode);
 
       bool hasAccessKeyCandidates = charCode != 0;
       if (!hasAccessKeyCandidates) {
         nsEvent* nativeEvent = nsContentUtils::GetNativeEvent(aKeyEvent);
-        nsKeyEvent* nativeKeyEvent = static_cast<nsKeyEvent*>(nativeEvent);
+        WidgetKeyboardEvent* nativeKeyEvent =
+          static_cast<WidgetKeyboardEvent*>(nativeEvent);
         if (nativeKeyEvent) {
           nsAutoTArray<uint32_t, 10> keys;
           nsContentUtils::GetAccessKeyCandidates(nativeKeyEvent, keys);
           hasAccessKeyCandidates = !keys.IsEmpty();
         }
       }
 
       // Cancel the access key flag unless we are pressing the access key.
--- a/layout/xul/base/src/nsMenuFrame.cpp
+++ b/layout/xul/base/src/nsMenuFrame.cpp
@@ -402,17 +402,17 @@ nsMenuFrame::HandleEvent(nsPresContext* 
 
   nsWeakFrame weakFrame(this);
   if (*aEventStatus == nsEventStatus_eIgnore)
     *aEventStatus = nsEventStatus_eConsumeDoDefault;
 
   bool onmenu = IsOnMenu();
 
   if (aEvent->message == NS_KEY_PRESS && !IsDisabled()) {
-    nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
+    WidgetKeyboardEvent* keyEvent = static_cast<WidgetKeyboardEvent*>(aEvent);
     uint32_t keyCode = keyEvent->keyCode;
 #ifdef XP_MACOSX
     // On mac, open menulist on either up/down arrow or space (w/o Cmd pressed)
     if (!IsOpen() && ((keyEvent->charCode == NS_VK_SPACE && !keyEvent->IsMeta()) ||
         (keyCode == NS_VK_UP || keyCode == NS_VK_DOWN))) {
       *aEventStatus = nsEventStatus_eConsumeNoDefault;
       OpenMenu(false);
     }
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -102,17 +102,16 @@ class WidgetPluginEvent;
 class InternalMutationEvent;
 } // namespace mozilla
 
 // TODO: Remove following typedefs
 typedef mozilla::WidgetEvent               nsEvent;
 typedef mozilla::WidgetGUIEvent            nsGUIEvent;
 typedef mozilla::WidgetInputEvent          nsInputEvent;
 typedef mozilla::InternalUIEvent           nsUIEvent;
-typedef mozilla::WidgetKeyboardEvent       nsKeyEvent;
 typedef mozilla::TextRangeStyle            nsTextRangeStyle;
 typedef mozilla::TextRange                 nsTextRange;
 typedef mozilla::TextRangeArray            nsTextRangeArray;
 typedef mozilla::WidgetTextEvent           nsTextEvent;
 typedef mozilla::WidgetCompositionEvent    nsCompositionEvent;
 typedef mozilla::WidgetQueryContentEvent   nsQueryContentEvent;
 typedef mozilla::WidgetSelectionEvent      nsSelectionEvent;
 typedef mozilla::WidgetMouseEventBase      nsMouseEvent_base;
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -529,17 +529,16 @@ public:
   bool mExpandToClusterBoundary;
   // true if setting selection succeeded.
   bool mSucceeded;
 };
 
 } // namespace mozilla
 
 // TODO: Remove following typedefs
-typedef mozilla::WidgetKeyboardEvent     nsKeyEvent;
 typedef mozilla::TextRangeStyle          nsTextRangeStyle;
 typedef mozilla::TextRange               nsTextRange;
 typedef mozilla::TextRangeArray          nsTextRangeArray;
 typedef mozilla::WidgetTextEvent         nsTextEvent;
 typedef mozilla::WidgetCompositionEvent  nsCompositionEvent;
 typedef mozilla::WidgetQueryContentEvent nsQueryContentEvent;
 typedef mozilla::WidgetSelectionEvent    nsSelectionEvent;
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -1599,17 +1599,17 @@ static void InitPluginEvent(ANPEvent* pl
     pluginEvent->data.key.nativeCode = androidKeyCode;
     pluginEvent->data.key.virtualCode = domKeyCode;
     pluginEvent->data.key.unichar = key.UnicodeChar();
     pluginEvent->data.key.modifiers = modifiers;
     pluginEvent->data.key.repeatCount = key.RepeatCount();
 }
 
 void
-nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key,
+nsWindow::InitKeyEvent(WidgetKeyboardEvent& event, AndroidGeckoEvent& key,
                        ANPEvent* pluginEvent)
 {
     int androidKeyCode = key.KeyCode();
     event.mKeyNameIndex = ConvertAndroidKeyCodeToKeyNameIndex(androidKeyCode);
     uint32_t domKeyCode = ConvertAndroidKeyCodeToDOMKeyCode(androidKeyCode);
 
     if (event.message == NS_KEY_PRESS) {
         // Android gives us \n, so filter out some control characters.
@@ -1680,17 +1680,17 @@ nsWindow::HandleSpecialKey(AndroidGeckoE
                 gMenu = true;
                 gMenuConsumed = isLongPress;
                 break;
         }
     } else {
         switch (keyCode) {
             case AKEYCODE_BACK: {
                 // XXX Where is the keydown event for this??
-                nsKeyEvent pressEvent(true, NS_KEY_PRESS, this);
+                WidgetKeyboardEvent pressEvent(true, NS_KEY_PRESS, this);
                 ANPEvent pluginEvent;
                 InitKeyEvent(pressEvent, *ae, &pluginEvent);
                 DispatchEvent(&pressEvent);
                 return;
             }
             case AKEYCODE_MENU:
                 gMenu = false;
                 if (!gMenuConsumed) {
@@ -1752,28 +1752,28 @@ nsWindow::OnKeyEvent(AndroidGeckoEvent *
     case AKEYCODE_BACK:
     case AKEYCODE_MENU:
     case AKEYCODE_SEARCH:
         HandleSpecialKey(ae);
         return;
     }
 
     nsEventStatus status;
-    nsKeyEvent event(true, msg, this);
+    WidgetKeyboardEvent event(true, msg, this);
     ANPEvent pluginEvent;
     InitKeyEvent(event, *ae, &pluginEvent);
     DispatchEvent(&event, status);
 
     if (Destroyed())
         return;
     if (!firePress || status == nsEventStatus_eConsumeNoDefault) {
         return;
     }
 
-    nsKeyEvent pressEvent(true, NS_KEY_PRESS, this);
+    WidgetKeyboardEvent pressEvent(true, NS_KEY_PRESS, this);
     InitKeyEvent(pressEvent, *ae, &pluginEvent);
 #ifdef DEBUG_ANDROID_WIDGET
     __android_log_print(ANDROID_LOG_INFO, "Gecko", "Dispatching key pressEvent with keyCode %d charCode %d shift %d alt %d sym/ctrl %d metamask %d", pressEvent.keyCode, pressEvent.charCode, pressEvent.IsShift(), pressEvent.IsAlt(), pressEvent.IsControl(), ae->MetaState());
 #endif
     DispatchEvent(&pressEvent);
 }
 
 #ifdef DEBUG_ANDROID_IME
--- a/widget/android/nsWindow.h
+++ b/widget/android/nsWindow.h
@@ -216,17 +216,18 @@ protected:
 
     InputContext mInputContext;
 
     static void DumpWindows();
     static void DumpWindows(const nsTArray<nsWindow*>& wins, int indent = 0);
     static void LogWindow(nsWindow *win, int index, int indent);
 
 private:
-    void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key,
+    void InitKeyEvent(mozilla::WidgetKeyboardEvent& event,
+                      mozilla::AndroidGeckoEvent& key,
                       ANPEvent* pluginEvent);
     void DispatchMotionEvent(nsInputEvent &event,
                              mozilla::AndroidGeckoEvent *ae,
                              const nsIntPoint &refPoint);
     void DispatchGestureEvent(uint32_t msg, uint32_t direction, double delta,
                               const nsIntPoint &refPoint, uint64_t time);
     void HandleSpecialKey(mozilla::AndroidGeckoEvent *ae);
     void CreateLayerManager(int aCompositorWidth, int aCompositorHeight);
--- a/widget/cocoa/NativeKeyBindings.h
+++ b/widget/cocoa/NativeKeyBindings.h
@@ -46,25 +46,25 @@ class NativeKeyBindings MOZ_FINAL : publ
 public:
   NativeKeyBindings();
 
   NS_DECL_ISUPPORTS
 
   NS_IMETHOD Init(NativeKeyBindingsType aType);
 
   // nsINativeKeyBindings
-  NS_IMETHOD_(bool) KeyDown(const nsKeyEvent& aEvent,
+  NS_IMETHOD_(bool) KeyDown(const WidgetKeyboardEvent& aEvent,
                             DoCommandCallback aCallback,
                             void* aCallbackData);
 
-  NS_IMETHOD_(bool) KeyPress(const nsKeyEvent& aEvent,
+  NS_IMETHOD_(bool) KeyPress(const WidgetKeyboardEvent& aEvent,
                              DoCommandCallback aCallback,
                              void* aCallbackData);
 
-  NS_IMETHOD_(bool) KeyUp(const nsKeyEvent& aEvent,
+  NS_IMETHOD_(bool) KeyUp(const WidgetKeyboardEvent& aEvent,
                           DoCommandCallback aCallback,
                           void* aCallbackData);
 
 private:
   SelectorCommandHashtable mSelectorToCommand;
 }; // NativeKeyBindings
 
 } // namespace widget
--- a/widget/cocoa/NativeKeyBindings.mm
+++ b/widget/cocoa/NativeKeyBindings.mm
@@ -162,24 +162,24 @@ NativeKeyBindings::Init(NativeKeyBinding
   return NS_OK;
 }
 
 #undef SEL_TO_COMMAND
 
 NS_IMPL_ISUPPORTS1(NativeKeyBindings, nsINativeKeyBindings)
 
 NS_IMETHODIMP_(bool)
-NativeKeyBindings::KeyDown(const nsKeyEvent& aEvent,
+NativeKeyBindings::KeyDown(const WidgetKeyboardEvent& aEvent,
                            DoCommandCallback aCallback, void* aCallbackData)
 {
   return false;
 }
 
 NS_IMETHODIMP_(bool)
-NativeKeyBindings::KeyPress(const nsKeyEvent& aEvent,
+NativeKeyBindings::KeyPress(const WidgetKeyboardEvent& aEvent,
                             DoCommandCallback aCallback, void* aCallbackData)
 {
   PR_LOG(gNativeKeyBindingsLog, PR_LOG_ALWAYS,
     ("%p NativeKeyBindings::KeyPress", this));
 
   // Recover the current event, which should always be the key down we are
   // responding to.
 
@@ -260,13 +260,13 @@ NativeKeyBindings::KeyPress(const nsKeyE
 
   PR_LOG(gNativeKeyBindingsLog, PR_LOG_ALWAYS,
     ("%p NativeKeyBindings::KeyPress, handled=true", this));
 
   return true;
 }
 
 NS_IMETHODIMP_(bool)
-NativeKeyBindings::KeyUp(const nsKeyEvent& aEvent,
+NativeKeyBindings::KeyUp(const WidgetKeyboardEvent& aEvent,
                          DoCommandCallback aCallback, void* aCallbackData)
 {
   return false;
 }
--- a/widget/cocoa/TextInputHandler.h
+++ b/widget/cocoa/TextInputHandler.h
@@ -209,17 +209,17 @@ public:
    *                              from the native key event.
    * @param aInsertString         If caller expects that the event will cause
    *                              a character to be input (say in an editor),
    *                              the caller should set this.  Otherwise,
    *                              if caller sets null to this, this method will
    *                              compute the character to be input from
    *                              characters of aNativeKeyEvent.
    */
-  void InitKeyEvent(NSEvent *aNativeKeyEvent, nsKeyEvent& aKeyEvent,
+  void InitKeyEvent(NSEvent *aNativeKeyEvent, WidgetKeyboardEvent& aKeyEvent,
                     const nsAString *aInsertString = nullptr);
 
   /**
    * ComputeGeckoKeyCode() returns Gecko keycode for aNativeKeyCode on current
    * keyboard layout.
    *
    * @param aNativeKeyCode        A native keycode.
    * @param aKbType               A native Keyboard Type value.  Typically,
@@ -280,17 +280,17 @@ protected:
    * @param aKeyEvent             The result -- a Gecko key event initialized
    *                              from the native key event.  This must be
    *                              NS_KEY_PRESS event.
    * @param aKbType               A native Keyboard Type value.  Typically,
    *                              this is a result of ::LMGetKbdType().
    */
   void InitKeyPressEvent(NSEvent *aNativeKeyEvent,
                          PRUnichar aInsertChar,
-                         nsKeyEvent& aKeyEvent,
+                         WidgetKeyboardEvent& aKeyEvent,
                          UInt32 aKbType);
 
   bool GetBoolProperty(const CFStringRef aKey);
   bool GetStringProperty(const CFStringRef aKey, CFStringRef &aStr);
   bool GetStringProperty(const CFStringRef aKey, nsAString &aStr);
 
   TISInputSourceRef mInputSource;
   TISInputSourceRef mKeyboardLayout;
@@ -358,17 +358,17 @@ public:
    *                              from the native key event.
    * @param aInsertString         If caller expects that the event will cause
    *                              a character to be input (say in an editor),
    *                              the caller should set this.  Otherwise,
    *                              if caller sets null to this, this method will
    *                              compute the character to be input from
    *                              characters of aNativeKeyEvent.
    */
-  void InitKeyEvent(NSEvent *aNativeKeyEvent, nsKeyEvent& aKeyEvent,
+  void InitKeyEvent(NSEvent *aNativeKeyEvent, WidgetKeyboardEvent& aKeyEvent,
                     const nsAString *aInsertString = nullptr);
 
   /**
    * SynthesizeNativeKeyEvent() is an implementation of
    * nsIWidget::SynthesizeNativeKeyEvent().  See the document in nsIWidget.h
    * for the detail.
    */
   nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
@@ -379,17 +379,17 @@ public:
 
   /**
    * Utility method intended for testing. Attempts to construct a native key
    * event that would have been generated during an actual key press. This
    * *does not dispatch* the native event. Instead, it is attached to the
    * |mNativeKeyEvent| field of the Gecko event that is passed in.
    * @param aKeyEvent  Gecko key event to attach the native event to
    */
-  NS_IMETHOD AttachNativeKeyEvent(nsKeyEvent& aKeyEvent);
+  NS_IMETHOD AttachNativeKeyEvent(WidgetKeyboardEvent& aKeyEvent);
 
   /**
    * GetWindowLevel() returns the window level of current focused (in Gecko)
    * window.  E.g., if an <input> element in XUL panel has focus, this returns
    * the XUL panel's window level.
    */
   NSInteger GetWindowLevel();
 
@@ -631,17 +631,17 @@ protected:
 
   /**
    * IsNormalCharInputtingEvent() checks whether aKeyEvent causes text input.
    *
    * @param aKeyEvent             A key event.
    * @return                      TRUE if the key event causes text input.
    *                              Otherwise, FALSE.
    */
-  static bool IsNormalCharInputtingEvent(const nsKeyEvent& aKeyEvent);
+  static bool IsNormalCharInputtingEvent(const WidgetKeyboardEvent& aKeyEvent);
 
   /**
    * IsModifierKey() checks whether the native keyCode is for a modifier key.
    *
    * @param aNativeKeyCode        A native keyCode.
    * @return                      TRUE if aNativeKeyCode is for a modifier key.
    *                              Otherwise, FALSE.
    */
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -762,17 +762,17 @@ TISInputSourceWrapper::Clear()
   mKeyboardLayout = nullptr;
   mIsRTL = -1;
   mUCKeyboardLayout = nullptr;
   mOverrideKeyboard = false;
 }
 
 void
 TISInputSourceWrapper::InitKeyEvent(NSEvent *aNativeKeyEvent,
-                                    nsKeyEvent& aKeyEvent,
+                                    WidgetKeyboardEvent& aKeyEvent,
                                     const nsAString *aInsertString)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   PR_LOG(gLog, PR_LOG_ALWAYS,
     ("%p TISInputSourceWrapper::InitKeyEvent, aNativeKeyEvent=%p, "
      "aKeyEvent.message=%s, aInsertString=%p",
      this, aNativeKeyEvent, GetGeckoKeyEventType(aKeyEvent), aInsertString));
@@ -973,17 +973,17 @@ TISInputSourceWrapper::InitKeyEvent(NSEv
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK
 }
 
 void
 TISInputSourceWrapper::InitKeyPressEvent(NSEvent *aNativeKeyEvent,
                                          PRUnichar aInsertChar,
-                                         nsKeyEvent& aKeyEvent,
+                                         WidgetKeyboardEvent& aKeyEvent,
                                          UInt32 aKbType)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   NS_ASSERTION(aKeyEvent.message == NS_KEY_PRESS,
                "aKeyEvent must be NS_KEY_PRESS event");
 
 #ifdef PR_LOGGING
@@ -1436,17 +1436,17 @@ TextInputHandler::HandleKeyDownEvent(NSE
   nsRefPtr<nsChildView> kungFuDeathGrip(mWidget);
 
   KeyEventState* currentKeyEvent = PushKeyEvent(aNativeEvent);
   AutoKeyEventStateCleaner remover(this);
 
   if (!IsIMEComposing()) {
     NSResponder* firstResponder = [[mView window] firstResponder];
 
-    nsKeyEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
+    WidgetKeyboardEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
     InitKeyEvent(aNativeEvent, keydownEvent);
 
     currentKeyEvent->mKeyDownHandled = DispatchEvent(keydownEvent);
     if (Destroyed()) {
       PR_LOG(gLog, PR_LOG_ALWAYS,
         ("%p TextInputHandler::HandleKeyDownEvent, "
          "widget was destroyed by keydown event", this));
       return currentKeyEvent->IsDefaultPrevented();
@@ -1514,17 +1514,17 @@ TextInputHandler::HandleKeyDownEvent(NSE
 
   PR_LOG(gLog, PR_LOG_ALWAYS,
     ("%p TextInputHandler::HandleKeyDownEvent, wasComposing=%s, "
      "IsIMEComposing()=%s",
      this, TrueOrFalse(wasComposing), TrueOrFalse(IsIMEComposing())));
 
   if (currentKeyEvent->CanDispatchKeyPressEvent() &&
       !wasComposing && !IsIMEComposing()) {
-    nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
+    WidgetKeyboardEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
     InitKeyEvent(aNativeEvent, keypressEvent);
 
     // If we called interpretKeyEvents and this isn't normal character input
     // then IME probably ate the event for some reason. We do not want to
     // send a key press event in that case.
     // TODO:
     // There are some other cases which IME eats the current event.
     // 1. If key events were nested during calling interpretKeyEvents, it means
@@ -1584,17 +1584,17 @@ TextInputHandler::HandleKeyUpEvent(NSEve
     return;
   }
 
   // if we don't have any characters we can't generate a keyUp event
   if (IsIMEComposing()) {
     return;
   }
 
-  nsKeyEvent keyupEvent(true, NS_KEY_UP, mWidget);
+  WidgetKeyboardEvent keyupEvent(true, NS_KEY_UP, mWidget);
   InitKeyEvent(aNativeEvent, keyupEvent);
 
   DispatchEvent(keyupEvent);
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 void
@@ -1933,17 +1933,17 @@ TextInputHandler::DispatchKeyEventForFla
     return;
   }
 
   uint32_t message = aDispatchKeyDown ? NS_KEY_DOWN : NS_KEY_UP;
 
   NPCocoaEvent cocoaEvent;
 
   // Fire a key event.
-  nsKeyEvent keyEvent(true, message, mWidget);
+  WidgetKeyboardEvent keyEvent(true, message, mWidget);
   InitKeyEvent(aNativeEvent, keyEvent);
 
   // create event for use by plugins
   if ([mView isPluginView]) {
     if ([mView pluginEventModel] == NPEventModelCocoa) {
       ConvertCocoaKeyEventToNPCocoaEvent(aNativeEvent, cocoaEvent);
       keyEvent.pluginEvent = &cocoaEvent;
     }
@@ -2052,17 +2052,17 @@ TextInputHandler::InsertText(NSAttribute
   // selection will be replaced by the later keypress event.
   if (isEditable &&
       aReplacementRange && aReplacementRange->location != NSNotFound &&
       !NSEqualRanges(selectedRange, *aReplacementRange)) {
     NS_ENSURE_TRUE_VOID(SetSelection(*aReplacementRange));
   }
 
   // Dispatch keypress event with char instead of textEvent
-  nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
+  WidgetKeyboardEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
   keypressEvent.isChar = IsPrintableChar(str.CharAt(0));
 
   // Don't set other modifiers from the current event, because here in
   // -insertText: they've already been taken into account in creating
   // the input string.
 
   if (currentKeyEvent) {
     NSEvent* keyEvent = currentKeyEvent->mKeyEvent;
@@ -2115,17 +2115,17 @@ TextInputHandler::DoCommandBySelector(co
      currentKeyEvent ?
        TrueOrFalse(currentKeyEvent->mKeyDownHandled) : "N/A",
      currentKeyEvent ?
        TrueOrFalse(currentKeyEvent->mKeyPressHandled) : "N/A",
      currentKeyEvent ?
        TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A"));
 
   if (currentKeyEvent && currentKeyEvent->CanDispatchKeyPressEvent()) {
-    nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
+    WidgetKeyboardEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
     InitKeyEvent(currentKeyEvent->mKeyEvent, keypressEvent);
     currentKeyEvent->mKeyPressHandled = DispatchEvent(keypressEvent);
     currentKeyEvent->mKeyPressDispatched = true;
     PR_LOG(gLog, PR_LOG_ALWAYS,
       ("%p TextInputHandler::DoCommandBySelector, keypress event "
        "dispatched, Destroyed()=%s, keypressHandled=%s",
        this, TrueOrFalse(Destroyed()),
        TrueOrFalse(currentKeyEvent->mKeyPressHandled)));
@@ -3792,17 +3792,17 @@ PluginTextInputHandler::HandleCarbonPlug
   EventRef cloneEvent = ::CopyEvent(aKeyEvent);
   for (uint32_t i = 0; i < numCharCodes; ++i) {
     status = ::SetEventParameter(cloneEvent, kEventParamKeyMacCharCodes,
                                  typeChar, 1, charCodes.Elements() + i);
     NS_ENSURE_TRUE(status == noErr, );
 
     EventRecord eventRec;
     if (::ConvertEventRefToEventRecord(cloneEvent, &eventRec)) {
-      nsKeyEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
+      WidgetKeyboardEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
       nsCocoaUtils::InitInputEvent(keydownEvent, cocoaModifiers);
 
       uint32_t keyCode =
         currentInputSource.ComputeGeckoKeyCode(macKeyCode, ::LMGetKbdType(),
                                                keydownEvent.IsMeta());
       uint32_t charCode(charCodes.ElementAt(i));
 
       keydownEvent.time = PR_IntervalNow();
@@ -3986,17 +3986,17 @@ PluginTextInputHandler::HandleKeyUpEvent
 
   NPEventModel eventModel = [mView pluginEventModel];
   if (eventModel == NPEventModelCocoa) {
     // Don't send key up events to Cocoa plugins during composition.
     if (IsInPluginComposition()) {
       return;
     }
 
-    nsKeyEvent keyupEvent(true, NS_KEY_UP, mWidget);
+    WidgetKeyboardEvent keyupEvent(true, NS_KEY_UP, mWidget);
     InitKeyEvent(aNativeKeyEvent, keyupEvent);
     NPCocoaEvent pluginEvent;
     ConvertCocoaKeyEventToNPCocoaEvent(aNativeKeyEvent, pluginEvent);
     keyupEvent.pluginEvent = &pluginEvent;
     DispatchEvent(keyupEvent);
     return;
   }
 }
@@ -4185,17 +4185,17 @@ TextInputHandlerBase::DispatchEvent(nsGU
       [NSCursor setHiddenUntilMouseMoves:YES];
     }
   }
   return mWidget->DispatchWindowEvent(aEvent);
 }
 
 void
 TextInputHandlerBase::InitKeyEvent(NSEvent *aNativeKeyEvent,
-                                   nsKeyEvent& aKeyEvent,
+                                   WidgetKeyboardEvent& aKeyEvent,
                                    const nsAString* aInsertString)
 {
   NS_ASSERTION(aNativeKeyEvent, "aNativeKeyEvent must not be NULL");
 
   if (mKeyboardOverride.mOverrideEnabled) {
     TISInputSourceWrapper tis;
     tis.InitByLayoutID(mKeyboardOverride.mKeyboardLayout, true);
     tis.InitKeyEvent(aNativeKeyEvent, aKeyEvent, aInsertString);
@@ -4298,17 +4298,17 @@ TextInputHandlerBase::GetWindowLevel()
      this, GetWindowLevelName(windowLevel), windowLevel));
 
   return windowLevel;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSNormalWindowLevel);
 }
 
 NS_IMETHODIMP
-TextInputHandlerBase::AttachNativeKeyEvent(nsKeyEvent& aKeyEvent)
+TextInputHandlerBase::AttachNativeKeyEvent(WidgetKeyboardEvent& aKeyEvent)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   // Don't try to replace a native event if one already exists.
   // OS X doesn't have an OS modifier, can't make a native event.
   if (aKeyEvent.mNativeKeyEvent || aKeyEvent.modifiers & MODIFIER_OS) {
     return NS_OK;
   }
@@ -4456,17 +4456,18 @@ TextInputHandlerBase::IsSpecialGeckoKey(
     case kVK_ANSI_KeypadEnter:
     case kVK_Powerbook_KeypadEnter:
       return true;
   }
   return false;
 }
 
 /* static */ bool
-TextInputHandlerBase::IsNormalCharInputtingEvent(const nsKeyEvent& aKeyEvent)
+TextInputHandlerBase::IsNormalCharInputtingEvent(
+                        const WidgetKeyboardEvent& aKeyEvent)
 {
   // this is not character inputting event, simply.
   if (!aKeyEvent.isChar || !aKeyEvent.charCode || aKeyEvent.IsMeta()) {
     return false;
   }
   // if this is unicode char inputting event, we don't need to check
   // ctrl/alt/command keys
   if (aKeyEvent.charCode > 0x7F) {
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1593,17 +1593,17 @@ NS_IMETHODIMP nsChildView::DispatchEvent
   debug_DumpEvent(stdout, event->widget, event, nsAutoCString("something"), 0);
 #endif
 
   NS_ASSERTION(!(mTextInputHandler && mTextInputHandler->IsIMEComposing() &&
                  event->HasKeyEventMessage()),
     "Any key events should not be fired during IME composing");
 
   if (event->mFlags.mIsSynthesizedForTests && event->HasKeyEventMessage()) {
-    nsKeyEvent* keyEvent = reinterpret_cast<nsKeyEvent*>(event);
+    WidgetKeyboardEvent* keyEvent = static_cast<WidgetKeyboardEvent*>(event);
     nsresult rv = mTextInputHandler->AttachNativeKeyEvent(*keyEvent);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   aStatus = nsEventStatus_eIgnore;
 
   nsIWidgetListener* listener = mWidgetListener;
 
--- a/widget/gonk/nsAppShell.cpp
+++ b/widget/gonk/nsAppShell.cpp
@@ -216,17 +216,17 @@ sendTouchEvent(UserInputData& data, bool
 }
 
 static nsEventStatus
 sendKeyEventWithMsg(uint32_t keyCode,
                     KeyNameIndex keyNameIndex,
                     uint32_t msg,
                     uint64_t timeMs)
 {
-    nsKeyEvent event(true, msg, NULL);
+    WidgetKeyboardEvent event(true, msg, NULL);
     event.keyCode = keyCode;
     event.mKeyNameIndex = keyNameIndex;
     event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
     event.time = timeMs;
     return nsWindow::DispatchInputEvent(event);
 }
 
 static void
--- a/widget/gtk/nsGtkKeyUtils.cpp
+++ b/widget/gtk/nsGtkKeyUtils.cpp
@@ -746,17 +746,17 @@ KeymapWrapper::ComputeDOMKeyNameIndex(co
             break;
     }
 
     uint32_t ch = GetCharCodeFor(aGdkKeyEvent);
     return ch ? KEY_NAME_INDEX_PrintableKey : KEY_NAME_INDEX_Unidentified;
 }
 
 /* static */ void
-KeymapWrapper::InitKeyEvent(nsKeyEvent& aKeyEvent,
+KeymapWrapper::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                             GdkEventKey* aGdkKeyEvent)
 {
     KeymapWrapper* keymapWrapper = GetInstance();
 
     aKeyEvent.mKeyNameIndex =
         keymapWrapper->ComputeDOMKeyNameIndex(aGdkKeyEvent);
     aKeyEvent.keyCode = ComputeDOMKeyCode(aGdkKeyEvent);
 
@@ -1160,17 +1160,17 @@ KeymapWrapper::GetDOMKeyCodeFromKeyPairs
         case 0x1005ff10:                return NS_VK_F11;
         // Sun F12 key generates SunF37(0x1005ff11) keysym
         case 0x1005ff11:                return NS_VK_F12;
         default:                        return 0;
     }
 }
 
 void
-KeymapWrapper::InitKeypressEvent(nsKeyEvent& aKeyEvent,
+KeymapWrapper::InitKeypressEvent(WidgetKeyboardEvent& aKeyEvent,
                                  GdkEventKey* aGdkKeyEvent)
 {
     NS_ENSURE_TRUE_VOID(aKeyEvent.message == NS_KEY_PRESS);
 
     aKeyEvent.charCode = GetCharCodeFor(aGdkKeyEvent);
     if (!aKeyEvent.charCode) {
         PR_LOG(gKeymapWrapperLog, PR_LOG_ALWAYS,
             ("KeymapWrapper(%p): InitKeypressEvent, "
--- a/widget/gtk/nsGtkKeyUtils.h
+++ b/widget/gtk/nsGtkKeyUtils.h
@@ -104,21 +104,22 @@ public:
      */
     static void InitInputEvent(nsInputEvent& aInputEvent,
                                guint aModifierState);
 
     /**
      * InitKeyEvent() intializes aKeyEvent's modifier key related members
      * and keycode related values.
      *
-     * @param aKeyEvent         It's an nsKeyEvent which needs to be
+     * @param aKeyEvent         It's an WidgetKeyboardEvent which needs to be
      *                          initialized.
      * @param aGdkKeyEvent      A native GDK key event.
      */
-    static void InitKeyEvent(nsKeyEvent& aKeyEvent, GdkEventKey* aGdkKeyEvent);
+    static void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
+                             GdkEventKey* aGdkKeyEvent);
 
     /**
      * IsKeyPressEventNecessary() returns TRUE when aGdkKeyEvent should cause
      * a DOM keypress event.  Otherwise, FALSE.
      */
     static bool IsKeyPressEventNecessary(GdkEventKey* aGdkKeyEvent);
 
 protected:
@@ -287,15 +288,16 @@ protected:
      * alternativeCharCodes of keypress event.
      *
      * @param aKeyEvent         An NS_KEY_PRESS event, must not be NULL.
      *                          The modifier related members and keyCode must
      *                          be initialized already.
      * @param aGdkKeyEvent      A native key event which causes dispatching
      *                          aKeyEvent.
      */
-    void InitKeypressEvent(nsKeyEvent& aKeyEvent, GdkEventKey* aGdkKeyEvent);
+    void InitKeypressEvent(WidgetKeyboardEvent& aKeyEvent,
+                           GdkEventKey* aGdkKeyEvent);
 };
 
 } // namespace widget
 } // namespace mozilla
 
 #endif /* __nsGdkKeyUtils_h__ */
--- a/widget/gtk/nsNativeKeyBindings.cpp
+++ b/widget/gtk/nsNativeKeyBindings.cpp
@@ -231,24 +231,24 @@ nsNativeKeyBindings::~nsNativeKeyBinding
 {
   gtk_widget_destroy(mNativeTarget);
   g_object_unref(mNativeTarget);
 }
 
 NS_IMPL_ISUPPORTS1(nsNativeKeyBindings, nsINativeKeyBindings)
 
 bool
-nsNativeKeyBindings::KeyDown(const nsKeyEvent& aEvent,
+nsNativeKeyBindings::KeyDown(const WidgetKeyboardEvent& aEvent,
                              DoCommandCallback aCallback, void *aCallbackData)
 {
   return false;
 }
 
 bool
-nsNativeKeyBindings::KeyPress(const nsKeyEvent& aEvent,
+nsNativeKeyBindings::KeyPress(const WidgetKeyboardEvent& aEvent,
                               DoCommandCallback aCallback, void *aCallbackData)
 {
   // If the native key event is set, it must be synthesized for tests.
   // We just ignore such events because this behavior depends on system
   // settings.
   if (!aEvent.mNativeKeyEvent) {
     // It must be synthesized event or dispatched DOM event from chrome.
     return false;
@@ -292,17 +292,17 @@ Code, which should be used after fixing 
   gtk_bindings_activate_event(GTK_OBJECT(mNativeTarget),
     static_cast<GdkEventKey*>(aEvent.mNativeKeyEvent));
 */
 
   return false;
 }
 
 bool
-nsNativeKeyBindings::KeyPressInternal(const nsKeyEvent& aEvent,
+nsNativeKeyBindings::KeyPressInternal(const WidgetKeyboardEvent& aEvent,
                                       DoCommandCallback aCallback,
                                       void *aCallbackData,
                                       guint aKeyval)
 {
   guint modifiers =
     static_cast<GdkEventKey*>(aEvent.mNativeKeyEvent)->state;
 
   gCurrentCallback = aCallback;
@@ -319,13 +319,13 @@ nsNativeKeyBindings::KeyPressInternal(co
 
   gCurrentCallback = nullptr;
   gCurrentCallbackData = nullptr;
 
   return gHandled;
 }
 
 bool
-nsNativeKeyBindings::KeyUp(const nsKeyEvent& aEvent,
+nsNativeKeyBindings::KeyUp(const WidgetKeyboardEvent& aEvent,
                            DoCommandCallback aCallback, void *aCallbackData)
 {
   return false;
 }
--- a/widget/gtk/nsNativeKeyBindings.h
+++ b/widget/gtk/nsNativeKeyBindings.h
@@ -33,32 +33,32 @@ enum NativeKeyBindingsType {
 class nsNativeKeyBindings MOZ_FINAL : public nsINativeKeyBindings
 {
 public:
   NS_HIDDEN_(void) Init(NativeKeyBindingsType aType);
 
   NS_DECL_ISUPPORTS
 
   // nsINativeKeyBindings
-  virtual NS_HIDDEN_(bool) KeyDown(const nsKeyEvent& aEvent,
+  virtual NS_HIDDEN_(bool) KeyDown(const mozilla::WidgetKeyboardEvent& aEvent,
                                    DoCommandCallback aCallback,
                                    void *aCallbackData);
 
-  virtual NS_HIDDEN_(bool) KeyPress(const nsKeyEvent& aEvent,
+  virtual NS_HIDDEN_(bool) KeyPress(const mozilla::WidgetKeyboardEvent& aEvent,
                                     DoCommandCallback aCallback,
                                     void *aCallbackData);
 
-  virtual NS_HIDDEN_(bool) KeyUp(const nsKeyEvent& aEvent,
+  virtual NS_HIDDEN_(bool) KeyUp(const mozilla::WidgetKeyboardEvent& aEvent,
                                  DoCommandCallback aCallback,
                                  void *aCallbackData);
 
 private:
   ~nsNativeKeyBindings() NS_HIDDEN;
 
-  bool KeyPressInternal(const nsKeyEvent& aEvent,
+  bool KeyPressInternal(const mozilla::WidgetKeyboardEvent& aEvent,
                         DoCommandCallback aCallback,
                         void *aCallbackData,
                         guint aKeyval);
 
   GtkWidget *mNativeTarget;
 };
 
 #endif
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -146,17 +146,17 @@ static nsWindow  *get_window_for_gtk_wid
 static nsWindow  *get_window_for_gdk_window(GdkWindow *window);
 static GtkWidget *get_gtk_widget_for_gdk_window(GdkWindow *window);
 static GdkCursor *get_gtk_cursor(nsCursor aCursor);
 
 static GdkWindow *get_inner_gdk_window (GdkWindow *aWindow,
                                         gint x, gint y,
                                         gint *retx, gint *rety);
 
-static inline bool is_context_menu_key(const nsKeyEvent& inKeyEvent);
+static inline bool is_context_menu_key(const WidgetKeyboardEvent& inKeyEvent);
 
 static int    is_parent_ungrab_enter(GdkEventCrossing *aEvent);
 static int    is_parent_grab_leave(GdkEventCrossing *aEvent);
 
 static void GetBrandName(nsXPIDLString& brandName);
 
 /* callbacks from widgets */
 #if (MOZ_WIDGET_GTK == 2)
@@ -2913,17 +2913,17 @@ nsWindow::DispatchKeyDownEvent(GdkEventK
     *aCancelled = false;
 
     if (IsCtrlAltTab(aEvent)) {
         return false;
     }
 
     // send the key down event
     nsEventStatus status;
-    nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
+    WidgetKeyboardEvent downEvent(true, NS_KEY_DOWN, this);
     KeymapWrapper::InitKeyEvent(downEvent, aEvent);
     DispatchEvent(&downEvent, status);
     *aCancelled = (status == nsEventStatus_eConsumeNoDefault);
     return true;
 }
 
 gboolean
 nsWindow::OnKeyPressEvent(GdkEventKey *aEvent)
@@ -3011,17 +3011,17 @@ nsWindow::OnKeyPressEvent(GdkEventKey *a
             return DispatchContentCommandEvent(NS_CONTENT_COMMAND_REDO);
         case GDK_Undo:
         case GDK_F14:
             return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
     }
 #endif /* ! AIX */
 #endif /* MOZ_X11 */
 
-    nsKeyEvent event(true, NS_KEY_PRESS, this);
+    WidgetKeyboardEvent event(true, NS_KEY_PRESS, this);
     KeymapWrapper::InitKeyEvent(event, aEvent);
 
     // before we dispatch a key, check if it's the context menu key.
     // If so, send a context menu key event instead.
     if (is_context_menu_key(event)) {
         nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU, this,
                                       nsMouseEvent::eReal,
                                       nsMouseEvent::eContextMenuKey);
@@ -3063,17 +3063,17 @@ nsWindow::OnKeyReleaseEvent(GdkEventKey 
 {
     LOGFOCUS(("OnKeyReleaseEvent [%p]\n", (void *)this));
 
     if (mIMModule && mIMModule->OnKeyEvent(this, aEvent)) {
         return TRUE;
     }
 
     // send the key event as a key up event
-    nsKeyEvent event(true, NS_KEY_UP, this);
+    WidgetKeyboardEvent event(true, NS_KEY_UP, this);
     KeymapWrapper::InitKeyEvent(event, aEvent);
 
     nsEventStatus status;
     DispatchEvent(&event, status);
 
     // If the event was consumed, return.
     if (status == nsEventStatus_eConsumeNoDefault) {
         return TRUE;
@@ -5727,17 +5727,17 @@ get_inner_gdk_window (GdkWindow *aWindow
         }
     }
     *retx = x;
     *rety = y;
     return aWindow;
 }
 
 static inline bool
-is_context_menu_key(const nsKeyEvent& aKeyEvent)
+is_context_menu_key(const WidgetKeyboardEvent& aKeyEvent)
 {
     return ((aKeyEvent.keyCode == NS_VK_F10 && aKeyEvent.IsShift() &&
              !aKeyEvent.IsControl() && !aKeyEvent.IsMeta() &&
              !aKeyEvent.IsAlt()) ||
             (aKeyEvent.keyCode == NS_VK_CONTEXT_MENU && !aKeyEvent.IsShift() &&
              !aKeyEvent.IsControl() && !aKeyEvent.IsMeta() &&
              !aKeyEvent.IsAlt()));
 }
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -247,19 +247,19 @@ struct ParamTraits<mozilla::WidgetTouchE
             identifier, mozilla::LayoutDeviceIntPoint::ToUntyped(refPoint),
             radius, rotationAngle, force));
     }
     return true;
   }
 };
 
 template<>
-struct ParamTraits<nsKeyEvent>
+struct ParamTraits<mozilla::WidgetKeyboardEvent>
 {
-  typedef nsKeyEvent paramType;
+  typedef mozilla::WidgetKeyboardEvent paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
     WriteParam(aMsg, static_cast<uint32_t>(aParam.mKeyNameIndex));
     WriteParam(aMsg, aParam.keyCode);
     WriteParam(aMsg, aParam.charCode);
     WriteParam(aMsg, aParam.isChar);
--- a/widget/nsINativeKeyBindings.h
+++ b/widget/nsINativeKeyBindings.h
@@ -26,24 +26,24 @@ NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "
 
 class nsINativeKeyBindings : public nsISupports
 {
  public:
   typedef void (*DoCommandCallback)(const char *, void*);
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_INATIVEKEYBINDINGS_IID)
 
-  virtual NS_HIDDEN_(bool) KeyDown(const nsKeyEvent& aEvent,
+  virtual NS_HIDDEN_(bool) KeyDown(const mozilla::WidgetKeyboardEvent& aEvent,
                                    DoCommandCallback aCallback,
                                    void *aCallbackData) = 0;
 
-  virtual NS_HIDDEN_(bool) KeyPress(const nsKeyEvent& aEvent,
+  virtual NS_HIDDEN_(bool) KeyPress(const mozilla::WidgetKeyboardEvent& aEvent,
                                     DoCommandCallback aCallback,
                                     void *aCallbackData) = 0;
 
-  virtual NS_HIDDEN_(bool) KeyUp(const nsKeyEvent& aEvent,
+  virtual NS_HIDDEN_(bool) KeyUp(const mozilla::WidgetKeyboardEvent& aEvent,
                                  DoCommandCallback aCallback,
                                  void *aCallbackData) = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsINativeKeyBindings, NS_INATIVEKEYBINDINGS_IID)
 
 #endif
--- a/widget/os2/nsWindow.cpp
+++ b/widget/os2/nsWindow.cpp
@@ -2154,17 +2154,17 @@ bool nsWindow::OnMouseChord(MPARAM mp1, 
         (WinQuerySysValue(HWND_DESKTOP, SV_CXMOTIONSTART) / 2) ||
       abs(YFROMMP(mp1) - sLastButton1Down.y) >
         (WinQuerySysValue(HWND_DESKTOP, SV_CYMOTIONSTART) / 2)) {
     isCopy = true;
   }
 
   // XXX Using keypress event here is wrong approach, this should be replaced
   //     with content command event.
-  nsKeyEvent event(true, NS_KEY_PRESS, this);
+  WidgetKeyboardEvent event(true, NS_KEY_PRESS, this);
   nsIntPoint point(0,0);
   InitEvent(event, &point);
 
   event.keyCode     = NS_VK_INSERT;
   if (isCopy) {
     event.modifiers = MODIFIER_CONTROL;
   } else {
     event.modifiers = MODIFIER_SHIFT;
@@ -2727,17 +2727,17 @@ NS_IMETHODIMP_(InputContext) nsWindow::G
 // see other platforms for best results of how things are supposed to work.
 //
 // Perhaps more importantly, the main man listening to these events
 // (besides random bits of javascript) is ender -- see
 // mozilla/editor/base/nsEditorEventListeners.cpp.
 
 bool nsWindow::DispatchKeyEvent(MPARAM mp1, MPARAM mp2)
 {
-  nsKeyEvent pressEvent(true, 0, nullptr);
+  WidgetKeyboardEvent pressEvent(true, 0, nullptr);
   USHORT fsFlags = SHORT1FROMMP(mp1);
   USHORT usVKey = SHORT2FROMMP(mp2);
   USHORT usChar = SHORT1FROMMP(mp2);
   UCHAR uchScan = CHAR4FROMMP(mp1);
 
   // It appears we're not supposed to transmit shift,
   // control, & alt events to gecko.
   if (fsFlags & KC_VIRTUALKEY && !(fsFlags & KC_KEYUP) &&
@@ -2755,18 +2755,19 @@ bool nsWindow::DispatchKeyEvent(MPARAM m
    // Now check if it's a dead-key
   if (fsFlags & KC_DEADKEY) {
     return true;
   }
 
   // Now dispatch a keyup/keydown event.  This one is *not* meant to
   // have the unicode charcode in.
   nsIntPoint point(0,0);
-  nsKeyEvent event(true, (fsFlags & KC_KEYUP) ? NS_KEY_UP : NS_KEY_DOWN,
-                   this);
+  WidgetKeyboardEvent event(true,
+                            (fsFlags & KC_KEYUP) ? NS_KEY_UP : NS_KEY_DOWN,
+                            this);
   InitEvent(event, &point);
   event.keyCode   = WMChar2KeyCode(mp1, mp2);
   event.InitBasicModifiers(fsFlags & KC_CTRL, fsFlags & KC_ALT,
                            fsFlags & KC_SHIFT, false);
   event.charCode  = 0;
 
   // Check for a scroll mouse event vs. a keyboard event.  The way we know
   // this is that the repeat count is 0 and the key is not physically down.
--- a/widget/qt/nsWindow.cpp
+++ b/widget/qt/nsWindow.cpp
@@ -158,17 +158,17 @@ isContextMenuKeyEvent(const QKeyEvent *q
         return false;
 
     bool isShift = qe->modifiers() & Qt::ShiftModifier;
     return (kc == NS_VK_F10 && isShift) ||
         (kc == NS_VK_CONTEXT_MENU && !isShift);
 }
 
 static void
-InitKeyEvent(nsKeyEvent &aEvent, QKeyEvent *aQEvent)
+InitKeyEvent(WidgetKeyboardEvent &aEvent, QKeyEvent *aQEvent)
 {
     aEvent.InitBasicModifiers(aQEvent->modifiers() & Qt::ControlModifier,
                               aQEvent->modifiers() & Qt::AltModifier,
                               aQEvent->modifiers() & Qt::ShiftModifier,
                               aQEvent->modifiers() & Qt::MetaModifier);
     aEvent.time = 0;
 
     if (sAltGrModifier) {
@@ -1575,17 +1575,17 @@ nsWindow::OnKeyPressEvent(QKeyEvent *aEv
                       QtKeyCodeToDOMKeyNameIndex(aEvent->key());
 
     // If the key isn't autorepeat, we need to send the initial down event
     if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) {
         // send the key down event
 
         SetKeyDownFlag(domKeyCode);
 
-        nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
+        WidgetKeyboardEvent downEvent(true, NS_KEY_DOWN, this);
         InitKeyEvent(downEvent, aEvent);
 
         downEvent.keyCode = domKeyCode;
         downEvent.mKeyNameIndex = keyNameIndex;
 
         nsEventStatus status = DispatchEvent(&downEvent);
 
         // DispatchEvent can Destroy us (bug 378273)
@@ -1647,17 +1647,17 @@ nsWindow::OnKeyPressEvent(QKeyEvent *aEv
     // Qt::Key_Redo and Qt::Key_Undo are not available yet.
     if (aEvent->nativeVirtualKey() == 0xff66) {
         return DispatchContentCommandEvent(NS_CONTENT_COMMAND_REDO);
     }
     if (aEvent->nativeVirtualKey() == 0xff65) {
         return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
     }
 
-    nsKeyEvent event(true, NS_KEY_PRESS, this);
+    WidgetKeyboardEvent event(true, NS_KEY_PRESS, this);
     InitKeyEvent(event, aEvent);
 
     // If there is no charcode attainable from the text, try to
     // generate it from the keycode. Check shift state for case
     // Also replace the charcode if ControlModifier is the only
     // pressed Modifier
     if ((!domCharCode) &&
         (QApplication::keyboardModifiers() &
@@ -1817,31 +1817,31 @@ nsWindow::OnKeyPressEvent(QKeyEvent *aEv
                       QtKeyCodeToDOMKeyNameIndex(aEvent->key());
 
     // If the key isn't autorepeat, we need to send the initial down event
     if (!aEvent->isAutoRepeat() && !IsKeyDown(domKeyCode)) {
         // send the key down event
 
         SetKeyDownFlag(domKeyCode);
 
-        nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
+        WidgetKeyboardEvent downEvent(true, NS_KEY_DOWN, this);
         InitKeyEvent(downEvent, aEvent);
 
         downEvent.keyCode = domKeyCode;
         downEvent.mKeyNameIndex = keyNameIndex;
 
         nsEventStatus status = DispatchEvent(&downEvent);
 
         // If prevent default on keydown, don't dispatch keypress event
         if (status == nsEventStatus_eConsumeNoDefault) {
             return nsEventStatus_eConsumeNoDefault;
         }
     }
 
-    nsKeyEvent event(true, NS_KEY_PRESS, this);
+    WidgetKeyboardEvent event(true, NS_KEY_PRESS, this);
     InitKeyEvent(event, aEvent);
 
     event.charCode = domCharCode;
 
     event.keyCode = domCharCode ? 0 : domKeyCode;
     event.mKeyNameIndex = keyNameIndex;
 
     // send the key press event
@@ -1883,17 +1883,17 @@ nsWindow::OnKeyReleaseEvent(QKeyEvent *a
 
         if (xkeymap) {
             XFree(xkeymap);
         }
     }
 #endif // MOZ_X11
 
     // send the key event as a key up event
-    nsKeyEvent event(true, NS_KEY_UP, this);
+    WidgetKeyboardEvent event(true, NS_KEY_UP, this);
     InitKeyEvent(event, aEvent);
 
     if (aEvent->key() == Qt::Key_AltGr) {
         sAltGrModifier = false;
     }
 
     event.keyCode = domKeyCode;
     event.mKeyNameIndex =
@@ -2527,17 +2527,17 @@ nsWindow::InitDragEvent(nsMouseEvent &aE
 nsresult
 initialize_prefs(void)
 {
     // check to see if we should set our raise pref
     return NS_OK;
 }
 
 inline bool
-is_context_menu_key(const nsKeyEvent& aKeyEvent)
+is_context_menu_key(const WidgetKeyboardEvent& aKeyEvent)
 {
     return ((aKeyEvent.keyCode == NS_VK_F10 && aKeyEvent.IsShift() &&
              !aKeyEvent.IsControl() && !aKeyEvent.IsMeta() &&
              !aKeyEvent.IsAlt()) ||
             (aKeyEvent.keyCode == NS_VK_CONTEXT_MENU && !aKeyEvent.IsShift() &&
              !aKeyEvent.IsControl() && !aKeyEvent.IsMeta() &&
              !aKeyEvent.IsAlt()));
 }
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -748,17 +748,17 @@ PRUnichar
 NativeKey::ComputeUnicharFromScanCode() const
 {
   return static_cast<PRUnichar>(
            ::MapVirtualKeyEx(ComputeVirtualKeyCodeFromScanCode(),
                              MAPVK_VK_TO_CHAR, mKeyboardLayout));
 }
 
 void
-NativeKey::InitKeyEvent(nsKeyEvent& aKeyEvent,
+NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                         const ModifierKeyState& aModKeyState) const
 {
   nsIntPoint point(0, 0);
   mWidget->InitEvent(aKeyEvent, &point);
 
   switch (aKeyEvent.message) {
     case NS_KEY_DOWN:
       aKeyEvent.keyCode = mDOMKeyCode;
@@ -784,17 +784,17 @@ NativeKey::InitKeyEvent(nsKeyEvent& aKey
   }
 
   aKeyEvent.mKeyNameIndex = mKeyNameIndex;
   aKeyEvent.location = GetKeyLocation();
   aModKeyState.InitInputEvent(aKeyEvent);
 }
 
 bool
-NativeKey::DispatchKeyEvent(nsKeyEvent& aKeyEvent,
+NativeKey::DispatchKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                             const MSG* aMsgSentToPlugin) const
 {
   if (mWidget->Destroyed()) {
     MOZ_CRASH("NativeKey tries to dispatch a key event on destroyed widget");
   }
 
   KeyboardLayout::NotifyIdleServiceOfUserActivity();
 
@@ -824,17 +824,17 @@ NativeKey::HandleKeyDownMessage(bool* aE
       !RedirectedKeyDownMessageManager::IsRedirectedMessage(mMsg)) {
     // Ignore [shift+]alt+space so the OS can handle it.
     if (mModKeyState.IsAlt() && !mModKeyState.IsControl() &&
         mVirtualKeyCode == VK_SPACE) {
       return false;
     }
 
     bool isIMEEnabled = WinUtils::IsIMEEnabled(mWidget->GetInputContext());
-    nsKeyEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
+    WidgetKeyboardEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
     InitKeyEvent(keydownEvent, mModKeyState);
     if (aEventDispatched) {
       *aEventDispatched = true;
     }
     defaultPrevented = DispatchKeyEvent(keydownEvent, &mMsg);
 
     if (mWidget->Destroyed()) {
       return true;
@@ -964,17 +964,17 @@ NativeKey::HandleCharMessage(const MSG& 
   static const PRUnichar U_SPACE = 0x20;
   static const PRUnichar U_EQUAL = 0x3D;
 
   // First, handle normal text input or non-printable key case here.
   if ((!mModKeyState.IsAlt() && !mModKeyState.IsControl()) ||
       mModKeyState.IsAltGr() ||
       (mOriginalVirtualKeyCode &&
        !KeyboardLayout::IsPrintableCharKey(mOriginalVirtualKeyCode))) {
-    nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
+    WidgetKeyboardEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
     if (aCharMsg.wParam >= U_SPACE) {
       keypressEvent.charCode = static_cast<uint32_t>(aCharMsg.wParam);
     } else {
       keypressEvent.keyCode = mDOMKeyCode;
     }
     // When AltGr (Alt+Ctrl) is pressed, that causes normal text input.
     // At this time, if either alt or ctrl flag is set, nsEditor ignores the
     // keypress event.  For avoiding this issue, we should remove ctrl and alt
@@ -1029,17 +1029,17 @@ NativeKey::HandleCharMessage(const MSG& 
   // Bug 285161 and Bug 295095: They were caused by the initial fix for
   // bug 178110.  When pressing (alt|ctrl)+char, the char must be lowercase
   // unless shift is pressed too.
   if (!mModKeyState.IsShift() &&
       (mModKeyState.IsAlt() || mModKeyState.IsControl())) {
     uniChar = towlower(uniChar);
   }
 
-  nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
+  WidgetKeyboardEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
   keypressEvent.charCode = uniChar;
   if (!keypressEvent.charCode) {
     keypressEvent.keyCode = mDOMKeyCode;
   }
   InitKeyEvent(keypressEvent, mModKeyState);
   if (aEventDispatched) {
     *aEventDispatched = true;
   }
@@ -1056,17 +1056,17 @@ NativeKey::HandleKeyUpMessage(bool* aEve
   }
 
   // Ignore [shift+]alt+space so the OS can handle it.
   if (mModKeyState.IsAlt() && !mModKeyState.IsControl() &&
       mVirtualKeyCode == VK_SPACE) {
     return false;
   }
 
-  nsKeyEvent keyupEvent(true, NS_KEY_UP, mWidget);
+  WidgetKeyboardEvent keyupEvent(true, NS_KEY_UP, mWidget);
   InitKeyEvent(keyupEvent, mModKeyState);
   if (aEventDispatched) {
     *aEventDispatched = true;
   }
   return DispatchKeyEvent(keyupEvent, &mMsg);
 }
 
 bool
@@ -1270,17 +1270,17 @@ NativeKey::DispatchKeyPressEventsWithKey
         inputtingChars.Clear();
         inputtingChars.Append(ch, mModKeyState.GetModifiers());
       }
     }
   }
 
   if (inputtingChars.IsEmpty() &&
       shiftedChars.IsEmpty() && unshiftedChars.IsEmpty()) {
-    nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
+    WidgetKeyboardEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
     keypressEvent.keyCode = mDOMKeyCode;
     InitKeyEvent(keypressEvent, mModKeyState);
     return DispatchKeyEvent(keypressEvent);
   }
 
   uint32_t longestLength =
     std::max(inputtingChars.mLength,
              std::max(shiftedChars.mLength, unshiftedChars.mLength));
@@ -1341,17 +1341,17 @@ NativeKey::DispatchKeyPressEventsWithKey
           charForOEMKeyCode != shiftedChars.mChars[0] &&
           charForOEMKeyCode != unshiftedLatinChar &&
           charForOEMKeyCode != shiftedLatinChar) {
         AlternativeCharCode OEMChars(charForOEMKeyCode, charForOEMKeyCode);
         altArray.AppendElement(OEMChars);
       }
     }
 
-    nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
+    WidgetKeyboardEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
     keypressEvent.charCode = uniChar;
     keypressEvent.alternativeCharCodes.AppendElements(altArray);
     InitKeyEvent(keypressEvent, modKeyState);
     defaultPrevented = (DispatchKeyEvent(keypressEvent) || defaultPrevented);
     if (mWidget->Destroyed()) {
       return true;
     }
   }
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -421,28 +421,28 @@ private:
   /**
    * Wraps MapVirtualKeyEx() with MAPVK_VSC_TO_VK and MAPVK_VK_TO_CHAR.
    */
   PRUnichar ComputeUnicharFromScanCode() const;
 
   /**
    * Initializes the aKeyEvent with the information stored in the instance.
    */
-  void InitKeyEvent(nsKeyEvent& aKeyEvent,
+  void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                     const ModifierKeyState& aModKeyState) const;
-  void InitKeyEvent(nsKeyEvent& 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(nsKeyEvent& aKeyEvent,
+  bool DispatchKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                         const MSG* aMsgSentToPlugin = nullptr) const;
 
   /**
    * DispatchKeyPressEventsWithKeyboardLayout() dispatches keypress event(s)
    * with the information provided by KeyboardLayout class.
    */
   bool DispatchKeyPressEventsWithKeyboardLayout() const;
 
--- a/widget/windows/winrt/MetroWidget.cpp
+++ b/widget/windows/winrt/MetroWidget.cpp
@@ -628,19 +628,20 @@ MetroWidget::DeliverNextScrollEvent()
   delete msg;
 }
 
 // defined in nsWiondowBase, called from shared module KeyboardLayout.
 bool
 MetroWidget::DispatchKeyboardEvent(nsGUIEvent* aEvent)
 {
   MOZ_ASSERT(aEvent);
-  nsKeyEvent* oldKeyEvent = static_cast<nsKeyEvent*>(aEvent);
-  nsKeyEvent* keyEvent =
-    new nsKeyEvent(oldKeyEvent->mFlags.mIsTrusted, oldKeyEvent->message, oldKeyEvent->widget);
+  WidgetKeyboardEvent* oldKeyEvent = static_cast<WidgetKeyboardEvent*>(aEvent);
+  WidgetKeyboardEvent* keyEvent =
+    new WidgetKeyboardEvent(oldKeyEvent->mFlags.mIsTrusted,
+                            oldKeyEvent->message, oldKeyEvent->widget);
   // XXX note this leaves pluginEvent null, which is fine for now.
   keyEvent->AssignKeyEventData(*oldKeyEvent, true);
   mKeyEventQueue.Push(keyEvent);
   nsCOMPtr<nsIRunnable> runnable =
     NS_NewRunnableMethod(this, &MetroWidget::DeliverNextKeyboardEvent);
   NS_DispatchToCurrentThread(runnable);
   return false;
 }
@@ -649,30 +650,31 @@ MetroWidget::DispatchKeyboardEvent(nsGUI
 // that should not be delivered due to the return result of the
 // preceeding keydown.
 class KeyQueryIdAndCancel : public nsDequeFunctor {
 public:
   KeyQueryIdAndCancel(uint32_t aIdToCancel) :
     mId(aIdToCancel) {
   }
   virtual void* operator() (void* aObject) {
-    nsKeyEvent* event = static_cast<nsKeyEvent*>(aObject);
+    WidgetKeyboardEvent* event = static_cast<WidgetKeyboardEvent*>(aObject);
     if (event->mUniqueId == mId) {
       event->mFlags.mPropagationStopped = true;
     }
     return nullptr;
   }
 protected:
   uint32_t mId;
 };
 
 void
 MetroWidget::DeliverNextKeyboardEvent()
 {
-  nsKeyEvent* event = static_cast<nsKeyEvent*>(mKeyEventQueue.PopFront());
+  WidgetKeyboardEvent* event =
+    static_cast<WidgetKeyboardEvent*>(mKeyEventQueue.PopFront());
   if (event->mFlags.mPropagationStopped) {
     // This can happen if a keypress was previously cancelled.
     delete event;
     return;
   }
   
   if (DispatchWindowEvent(event) && event->message == NS_KEY_DOWN) {
     // keydown events may be followed by multiple keypress events which