Bug 1436508 part 6. Switch layout/xul from nsIDOMKeyEvent to KeyboardEvent. r=masayuki
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 09 Feb 2018 11:17:09 -0500
changeset 403178 f1f2b10c62e7
parent 403177 4e2f9290346a
child 403179 ee44459b72f6
push id33416
push userarchaeopteryx@coole-files.de
push date2018-02-09 22:32 +0000
treeherdermozilla-central@c2cddb0cbb20 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1436508
milestone60.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 1436508 part 6. Switch layout/xul from nsIDOMKeyEvent to KeyboardEvent. r=masayuki MozReview-Commit-ID: Cp4krHgxXzQ
layout/xul/MenuBoxObject.cpp
layout/xul/nsMenuBarFrame.cpp
layout/xul/nsMenuBarFrame.h
layout/xul/nsMenuBarListener.cpp
layout/xul/nsMenuBarListener.h
layout/xul/nsMenuFrame.cpp
layout/xul/nsMenuPopupFrame.cpp
layout/xul/nsMenuPopupFrame.h
layout/xul/nsXULPopupManager.cpp
layout/xul/nsXULPopupManager.h
--- a/layout/xul/MenuBoxObject.cpp
+++ b/layout/xul/MenuBoxObject.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/MenuBoxObject.h"
 #include "mozilla/dom/MenuBoxObjectBinding.h"
 
 #include "mozilla/dom/KeyboardEvent.h"
 #include "mozilla/dom/Element.h"
-#include "nsIDOMKeyEvent.h"
 #include "nsIFrame.h"
 #include "nsMenuBarFrame.h"
 #include "nsMenuBarListener.h"
 #include "nsMenuFrame.h"
 #include "nsMenuPopupFrame.h"
 
 namespace mozilla {
 namespace dom {
--- a/layout/xul/nsMenuBarFrame.cpp
+++ b/layout/xul/nsMenuBarFrame.cpp
@@ -23,18 +23,20 @@
 #ifdef XP_WIN
 #include "nsISound.h"
 #include "nsWidgetsCID.h"
 #endif
 #include "nsContentUtils.h"
 #include "nsUTF8Utils.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/Event.h"
+#include "mozilla/dom/KeyboardEvent.h"
 
 using namespace mozilla;
+using mozilla::dom::KeyboardEvent;
 
 //
 // NS_NewMenuBarFrame
 //
 // Wrapper for creating a new menu Bar container
 //
 nsIFrame*
 NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
@@ -139,24 +141,23 @@ nsMenuBarFrame::ToggleMenuActiveState()
       mCurrentMenu = firstFrame;
     }
   }
 
   return nullptr;
 }
 
 nsMenuFrame*
-nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, bool aPeek)
+nsMenuBarFrame::FindMenuWithShortcut(KeyboardEvent* aKeyEvent, bool aPeek)
 {
-  uint32_t charCode;
-  aKeyEvent->GetCharCode(&charCode);
+  uint32_t charCode = aKeyEvent->CharCode();
 
   AutoTArray<uint32_t, 10> accessKeys;
   WidgetKeyboardEvent* nativeKeyEvent =
-    aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
+    aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
   if (nativeKeyEvent) {
     nativeKeyEvent->GetAccessKeyCandidates(accessKeys);
   }
   if (accessKeys.IsEmpty() && charCode)
     accessKeys.AppendElement(charCode);
 
   if (accessKeys.IsEmpty())
     return nullptr; // no character was pressed so just return
--- a/layout/xul/nsMenuBarFrame.h
+++ b/layout/xul/nsMenuBarFrame.h
@@ -16,16 +16,22 @@
 #include "nsCOMPtr.h"
 #include "nsBoxFrame.h"
 #include "nsMenuFrame.h"
 #include "nsMenuBarListener.h"
 #include "nsMenuParent.h"
 
 class nsIContent;
 
+namespace mozilla {
+namespace dom {
+class KeyboardEvent;
+} // namespace dom
+} // namespace mozilla
+
 nsIFrame* NS_NewMenuBarFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
 
 class nsMenuBarFrame final : public nsBoxFrame, public nsMenuParent
 {
 public:
   NS_DECL_QUERYFRAME
   NS_DECL_FRAMEARENA_HELPERS(nsMenuBarFrame)
 
@@ -80,17 +86,18 @@ public:
   // may deselect the menuitem.
   virtual bool MenuClosed() override;
 
   // Called when Enter is pressed while the menubar is focused. If the current
   // menu is open, let the child handle the key.
   nsMenuFrame* Enter(mozilla::WidgetGUIEvent* aEvent);
 
   // Used to handle ALT+key combos
-  nsMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, bool aPeek);
+  nsMenuFrame* FindMenuWithShortcut(mozilla::dom::KeyboardEvent* aKeyEvent,
+                                    bool aPeek);
 
   virtual bool IsFrameOfType(uint32_t aFlags) const override
   {
     // Override bogus IsFrameOfType in nsBoxFrame.
     if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
       return false;
     return nsBoxFrame::IsFrameOfType(aFlags);
   }
--- a/layout/xul/nsMenuBarListener.cpp
+++ b/layout/xul/nsMenuBarListener.cpp
@@ -9,27 +9,28 @@
 #include "nsMenuPopupFrame.h"
 #include "nsIDOMEvent.h"
 #include "nsPIWindowRoot.h"
 
 // Drag & Drop, Clipboard
 #include "nsIServiceManager.h"
 #include "nsWidgetsCID.h"
 #include "nsCOMPtr.h"
-#include "nsIDOMKeyEvent.h"
 #include "nsIContent.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMElement.h"
 
 #include "nsContentUtils.h"
 #include "mozilla/BasicEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TextEvents.h"
+#include "mozilla/dom/KeyboardEvent.h"
 
 using namespace mozilla;
+using mozilla::dom::KeyboardEvent;
 
 /*
  * nsMenuBarListener implementation
  */
 
 NS_IMPL_ISUPPORTS(nsMenuBarListener, nsIDOMEventListener)
 
 ////////////////////////////////////////////////////////////////////////
@@ -176,41 +177,37 @@ nsMenuBarListener::ToggleMenuActiveState
       pm->HidePopup(popupFrame->GetContent(), false, false, true, false);
   }
 }
 
 ////////////////////////////////////////////////////////////////////////
 nsresult
 nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent)
 {
-  nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
+  RefPtr<KeyboardEvent> keyEvent =
+    aKeyEvent->InternalDOMEvent()->AsKeyboardEvent();
   if (!keyEvent) {
     return NS_OK;
   }
 
   InitAccessKey();
 
   //handlers shouldn't be triggered by non-trusted events.
-  bool trustedEvent = false;
-  aKeyEvent->GetIsTrusted(&trustedEvent);
-
-  if (!trustedEvent) {
+  if (!keyEvent->IsTrusted()) {
     return NS_OK;
   }
 
   if (mAccessKey && mAccessKeyFocuses)
   {
-    bool defaultPrevented = false;
-    aKeyEvent->GetDefaultPrevented(&defaultPrevented);
+    bool defaultPrevented = keyEvent->DefaultPrevented();
 
     // On a press of the ALT key by itself, we toggle the menu's
     // active/inactive state.
     // Get the ascii key code.
-    uint32_t theChar;
-    keyEvent->GetKeyCode(&theChar);
+    uint32_t theChar = keyEvent->KeyCode();
 
     if (!defaultPrevented && mAccessKeyDown && !mAccessKeyDownCanceled &&
         (int32_t)theChar == mAccessKey)
     {
       // The access key was down and is now up, and no other
       // keys were pressed in between.
       bool toggleMenuActiveState = true;
       if (!mMenuBarFrame->IsActive()) {
@@ -232,18 +229,18 @@ nsMenuBarListener::KeyUp(nsIDOMEvent* aK
         ToggleMenuActiveState();
       }
     }
     mAccessKeyDown = false;
     mAccessKeyDownCanceled = false;
 
     bool active = !Destroyed() && mMenuBarFrame->IsActive();
     if (active) {
-      aKeyEvent->StopPropagation();
-      aKeyEvent->PreventDefault();
+      keyEvent->StopPropagation();
+      keyEvent->PreventDefault();
       return NS_OK; // I am consuming event
     }
   }
 
   return NS_OK; // means I am NOT consuming event
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -276,19 +273,19 @@ nsMenuBarListener::KeyPress(nsIDOMEvent*
     // If accesskey handling was forwarded to a child process, wait for
     // the mozaccesskeynotfound event before handling accesskeys.
     WidgetKeyboardEvent* nativeKeyEvent =
       aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
     if (!nativeKeyEvent) {
       return NS_OK;
     }
 
-    nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
-    uint32_t keyCode;
-    keyEvent->GetKeyCode(&keyCode);
+    RefPtr<KeyboardEvent> keyEvent =
+      aKeyEvent->InternalDOMEvent()->AsKeyboardEvent();
+    uint32_t keyCode = keyEvent->KeyCode();
 
     // Cancel the access key flag unless we are pressing the access key.
     if (keyCode != (uint32_t)mAccessKey) {
       mAccessKeyDownCanceled = true;
     }
 
 #ifndef XP_MACOSX
     // Need to handle F10 specially on Non-Mac platform.
@@ -352,53 +349,52 @@ nsMenuBarListener::KeyPress(nsIDOMEvent*
     aKeyEvent->StopPropagation();
     aKeyEvent->PreventDefault();
   }
 
   return NS_OK;
 }
 
 bool
-nsMenuBarListener::IsAccessKeyPressed(nsIDOMKeyEvent* aKeyEvent)
+nsMenuBarListener::IsAccessKeyPressed(KeyboardEvent* aKeyEvent)
 {
   InitAccessKey();
   // No other modifiers are allowed to be down except for Shift.
   uint32_t modifiers = GetModifiersForAccessKey(aKeyEvent);
 
   return (mAccessKeyMask != MODIFIER_SHIFT &&
           (modifiers & mAccessKeyMask) &&
           (modifiers & ~(mAccessKeyMask | MODIFIER_SHIFT)) == 0);
 }
 
 Modifiers
-nsMenuBarListener::GetModifiersForAccessKey(nsIDOMKeyEvent* aKeyEvent)
+nsMenuBarListener::GetModifiersForAccessKey(KeyboardEvent* aKeyEvent)
 {
   WidgetInputEvent* inputEvent =
-    aKeyEvent->AsEvent()->WidgetEventPtr()->AsInputEvent();
+    aKeyEvent->WidgetEventPtr()->AsInputEvent();
   MOZ_ASSERT(inputEvent);
 
   static const Modifiers kPossibleModifiersForAccessKey =
     (MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META |
      MODIFIER_OS);
   return (inputEvent->mModifiers & kPossibleModifiersForAccessKey);
 }
 
 nsMenuFrame*
-nsMenuBarListener::GetMenuForKeyEvent(nsIDOMKeyEvent* aKeyEvent, bool aPeek)
+nsMenuBarListener::GetMenuForKeyEvent(KeyboardEvent* aKeyEvent, bool aPeek)
 {
   if (!IsAccessKeyPressed(aKeyEvent)) {
     return nullptr;
   }
 
-  uint32_t charCode;
-  aKeyEvent->GetCharCode(&charCode);
+  uint32_t charCode = aKeyEvent->CharCode();
   bool hasAccessKeyCandidates = charCode != 0;
   if (!hasAccessKeyCandidates) {
     WidgetKeyboardEvent* nativeKeyEvent =
-      aKeyEvent->AsEvent()->WidgetEventPtr()->AsKeyboardEvent();
+      aKeyEvent->WidgetEventPtr()->AsKeyboardEvent();
 
     AutoTArray<uint32_t, 10> keys;
     nativeKeyEvent->GetAccessKeyCandidates(keys);
     hasAccessKeyCandidates = !keys.IsEmpty();
   }
 
   if (hasAccessKeyCandidates) {
     // Do shortcut navigation.
@@ -431,26 +427,25 @@ nsMenuBarListener::KeyDown(nsIDOMEvent* 
   if (aKeyEvent) {
     aKeyEvent->GetIsTrusted(&trustedEvent);
   }
 
   if (!trustedEvent) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
+  RefPtr<KeyboardEvent> keyEvent =
+    aKeyEvent->InternalDOMEvent()->AsKeyboardEvent();
   if (!keyEvent) {
     return NS_OK;
   }
 
-  uint32_t theChar;
-  keyEvent->GetKeyCode(&theChar);
+  uint32_t theChar = keyEvent->KeyCode();
 
-  uint16_t eventPhase;
-  aKeyEvent->GetEventPhase(&eventPhase);
+  uint16_t eventPhase = keyEvent->EventPhase();
   bool capturing = (eventPhase == nsIDOMEvent::CAPTURING_PHASE);
 
 #ifndef XP_MACOSX
   if (capturing && !mAccessKeyDown && theChar == NS_VK_F10 &&
       (GetModifiersForAccessKey(keyEvent) & ~MODIFIER_CONTROL) == 0) {
     ReserveKeyIfNeeded(aKeyEvent);
   }
 #endif
--- a/layout/xul/nsMenuBarListener.h
+++ b/layout/xul/nsMenuBarListener.h
@@ -12,21 +12,21 @@
 
 // X.h defines KeyPress
 #ifdef KeyPress
 #undef KeyPress
 #endif
 
 class nsMenuFrame;
 class nsMenuBarFrame;
-class nsIDOMKeyEvent;
 
 namespace mozilla {
 namespace dom {
 class EventTarget;
+class KeyboardEvent;
 } // namespace dom
 } // namespace mozilla
 
 /**
  * EventListener implementation for menubar.
  */
 class nsMenuBarListener final : public nsIDOMEventListener
 {
@@ -53,39 +53,40 @@ public:
    * used for accesskey.  Returns 0 if the platform doesn't support access key.
    */
   static nsresult GetMenuAccessKey(int32_t* aAccessKey);
 
   /**
    * IsAccessKeyPressed() returns true if the modifier state of aEvent matches
    * the modifier state of access key.
    */
-  static bool IsAccessKeyPressed(nsIDOMKeyEvent* aEvent);
+  static bool IsAccessKeyPressed(mozilla::dom::KeyboardEvent* aEvent);
 
 protected:
   virtual ~nsMenuBarListener();
 
   nsresult KeyUp(nsIDOMEvent* aMouseEvent);
   nsresult KeyDown(nsIDOMEvent* aMouseEvent);
   nsresult KeyPress(nsIDOMEvent* aMouseEvent);
   nsresult Blur(nsIDOMEvent* aEvent);
   nsresult OnWindowDeactivated(nsIDOMEvent* aEvent);
   nsresult MouseDown(nsIDOMEvent* aMouseEvent);
   nsresult Fullscreen(nsIDOMEvent* aEvent);
 
   static void InitAccessKey();
 
-  static mozilla::Modifiers GetModifiersForAccessKey(nsIDOMKeyEvent* event);
+  static mozilla::Modifiers
+    GetModifiersForAccessKey(mozilla::dom::KeyboardEvent* event);
 
   /**
    * Given a key event for an Alt+shortcut combination,
    * return the menu, if any, that would be opened. If aPeek
    * is false, then play a beep and deactivate the menubar on Windows.
    */
-  nsMenuFrame* GetMenuForKeyEvent(nsIDOMKeyEvent* aKeyEvent, bool aPeek);
+  nsMenuFrame* GetMenuForKeyEvent(mozilla::dom::KeyboardEvent* aKeyEvent, bool aPeek);
 
   /**
    * Call MarkAsReservedByChrome if the user's preferences indicate that
    * the key should be chrome-only.
    */
   void ReserveKeyIfNeeded(nsIDOMEvent* aKeyEvent);
 
   // This should only be called by the nsMenuBarListener during event dispatch,
--- a/layout/xul/nsMenuFrame.cpp
+++ b/layout/xul/nsMenuFrame.cpp
@@ -20,17 +20,16 @@
 #include "nsIDocument.h"
 #include "nsIDOMElement.h"
 #include "nsIComponentManager.h"
 #include "nsBoxLayoutState.h"
 #include "nsIScrollableFrame.h"
 #include "nsBindingManager.h"
 #include "nsIServiceManager.h"
 #include "nsCSSFrameConstructor.h"
-#include "nsIDOMKeyEvent.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIStringBundle.h"
 #include "nsContentUtils.h"
 #include "nsDisplayList.h"
 #include "nsIReflowCallback.h"
 #include "nsISound.h"
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -14,17 +14,16 @@
 #include "nsNameSpaceManager.h"
 #include "nsViewManager.h"
 #include "nsWidgetsCID.h"
 #include "nsMenuFrame.h"
 #include "nsMenuBarFrame.h"
 #include "nsPopupSetFrame.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMEvent.h"
-#include "nsIDOMKeyEvent.h"
 #include "nsIDOMScreen.h"
 #include "nsIDOMXULMenuListElement.h"
 #include "nsIPresShell.h"
 #include "nsFrameManager.h"
 #include "nsIDocument.h"
 #include "nsRect.h"
 #include "nsIComponentManager.h"
 #include "nsBoxLayoutState.h"
@@ -51,21 +50,23 @@
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/EventStates.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
+#include "mozilla/dom/KeyboardEvent.h"
 #include "mozilla/dom/PopupBoxObject.h"
 #include <algorithm>
 
 using namespace mozilla;
 using mozilla::dom::PopupBoxObject;
+using mozilla::dom::KeyboardEvent;
 
 int8_t nsMenuPopupFrame::sDefaultLevelIsTop = -1;
 
 DOMTimeStamp nsMenuPopupFrame::sLastKeyTime = 0;
 
 // XXX, kyle.yuan@sun.com, there are 4 definitions for the same purpose:
 //  nsMenuPopupFrame.h, nsListControlFrame.cpp, listbox.xml, tree.xml
 //  need to find a good place to put them together.
@@ -2076,21 +2077,20 @@ nsMenuPopupFrame::Enter(WidgetGUIEvent* 
   // Give it to the child.
   if (mCurrentMenu)
     return mCurrentMenu->Enter(aEvent);
 
   return nullptr;
 }
 
 nsMenuFrame*
-nsMenuPopupFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, bool& doAction)
+nsMenuPopupFrame::FindMenuWithShortcut(KeyboardEvent* aKeyEvent, bool& doAction)
 {
-  uint32_t charCode, keyCode;
-  aKeyEvent->GetCharCode(&charCode);
-  aKeyEvent->GetKeyCode(&keyCode);
+  uint32_t charCode = aKeyEvent->CharCode();
+  uint32_t keyCode = aKeyEvent->KeyCode();
 
   doAction = false;
 
   // Enumerate over our list of frames.
   nsContainerFrame* immediateParent =
     nsXULPopupManager::ImmediateParentFrame(this);
   uint32_t matchCount = 0, matchShortcutCount = 0;
   bool foundActive = false;
@@ -2098,18 +2098,17 @@ nsMenuPopupFrame::FindMenuWithShortcut(n
   nsMenuFrame* frameAfter = nullptr;
   nsMenuFrame* frameShortcut = nullptr;
 
   nsIContent* parentContent = mContent->GetParent();
 
   bool isMenu = parentContent &&
                   !parentContent->NodeInfo()->Equals(nsGkAtoms::menulist, kNameSpaceID_XUL);
 
-  DOMTimeStamp keyTime;
-  aKeyEvent->AsEvent()->GetTimeStamp(&keyTime);
+  DOMTimeStamp keyTime = aKeyEvent->TimeStamp();
 
   if (charCode == 0) {
     if (keyCode == nsIDOMKeyEvent::DOM_VK_BACK_SPACE) {
       if (!isMenu && !mIncrementalString.IsEmpty()) {
         mIncrementalString.SetLength(mIncrementalString.Length() - 1);
         return nullptr;
       }
       else {
--- a/layout/xul/nsMenuPopupFrame.h
+++ b/layout/xul/nsMenuPopupFrame.h
@@ -22,16 +22,22 @@
 #include "nsMenuParent.h"
 
 #include "nsITimer.h"
 
 #include "Units.h"
 
 class nsIWidget;
 
+namespace mozilla {
+namespace dom {
+class KeyboardEvent;
+} // namespace dom
+} // namespace mozilla
+
 // XUL popups can be in several different states. When opening a popup, the
 // state changes as follows:
 //   ePopupClosed - initial state
 //   ePopupShowing - during the period when the popupshowing event fires
 //   ePopupOpening - between the popupshowing event and being visible. Creation
 //                   of the child frames, layout and reflow occurs in this
 //                   state. The popup is stored in the popup manager's list of
 //                   open popups during this state.
@@ -334,17 +340,18 @@ public:
   void HidePopup(bool aDeselectMenu, nsPopupState aNewState);
 
   // locate and return the menu frame that should be activated for the
   // supplied key event. If doAction is set to true by this method,
   // then the menu's action should be carried out, as if the user had pressed
   // the Enter key. If doAction is false, the menu should just be highlighted.
   // This method also handles incremental searching in menus so the user can
   // type the first few letters of an item/s name to select it.
-  nsMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, bool& doAction);
+  nsMenuFrame* FindMenuWithShortcut(mozilla::dom::KeyboardEvent* aKeyEvent,
+                                    bool& doAction);
 
   void ClearIncrementalString() { mIncrementalString.Truncate(); }
   static bool IsWithinIncrementalTime(DOMTimeStamp time) {
     return !sTimeoutOfIncrementalSearch || time - sLastKeyTime <= sTimeoutOfIncrementalSearch;
   }
 
 #ifdef DEBUG_FRAME_DUMP
   virtual nsresult GetFrameName(nsAString& aResult) const override
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -22,26 +22,26 @@
 #include "nsViewManager.h"
 #include "nsIComponentManager.h"
 #include "nsITimer.h"
 #include "nsFocusManager.h"
 #include "nsIDocShell.h"
 #include "nsPIDOMWindow.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIBaseWindow.h"
-#include "nsIDOMKeyEvent.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsCaret.h"
 #include "nsIDocument.h"
 #include "nsPIWindowRoot.h"
 #include "nsFrameManager.h"
 #include "nsIObserverService.h"
 #include "XULDocument.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
+#include "mozilla/dom/KeyboardEvent.h"
 #include "mozilla/dom/UIEvent.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/Services.h"
 #include "mozilla/widget/nsAutoRollup.h"
 
@@ -2098,38 +2098,38 @@ nsXULPopupManager::CancelMenuTimer(nsMen
   if (mCloseTimer && mTimerMenu == aMenuParent) {
     mCloseTimer->Cancel();
     mCloseTimer = nullptr;
     mTimerMenu = nullptr;
   }
 }
 
 bool
-nsXULPopupManager::HandleShortcutNavigation(nsIDOMKeyEvent* aKeyEvent,
+nsXULPopupManager::HandleShortcutNavigation(KeyboardEvent* aKeyEvent,
                                             nsMenuPopupFrame* aFrame)
 {
   // On Windows, don't check shortcuts when the accelerator key is down.
 #ifdef XP_WIN
-  WidgetInputEvent* evt = aKeyEvent->AsEvent()->WidgetEventPtr()->AsInputEvent();
+  WidgetInputEvent* evt = aKeyEvent->WidgetEventPtr()->AsInputEvent();
   if (evt && evt->IsAccel()) {
     return false;
   }
 #endif
 
   nsMenuChainItem* item = GetTopVisibleMenu();
   if (!aFrame && item)
     aFrame = item->Frame();
 
   if (aFrame) {
     bool action;
     nsMenuFrame* result = aFrame->FindMenuWithShortcut(aKeyEvent, action);
     if (result) {
       aFrame->ChangeMenuItem(result, false, true);
       if (action) {
-        WidgetGUIEvent* evt = aKeyEvent->AsEvent()->WidgetEventPtr()->AsGUIEvent();
+        WidgetGUIEvent* evt = aKeyEvent->WidgetEventPtr()->AsGUIEvent();
         nsMenuFrame* menuToOpen = result->Enter(evt);
         if (menuToOpen) {
           nsCOMPtr<nsIContent> content = menuToOpen->GetContent();
           ShowMenu(content, true, false);
         }
       }
       return true;
     }
@@ -2324,43 +2324,42 @@ nsXULPopupManager::HandleKeyboardNavigat
     }
   }
 
   return false;
 }
 
 bool
 nsXULPopupManager::HandleKeyboardEventWithKeyCode(
-                        nsIDOMKeyEvent* aKeyEvent,
+                        KeyboardEvent* aKeyEvent,
                         nsMenuChainItem* aTopVisibleMenuItem)
 {
-  uint32_t keyCode;
-  aKeyEvent->GetKeyCode(&keyCode);
+  uint32_t keyCode = aKeyEvent->KeyCode();
 
   // Escape should close panels, but the other keys should have no effect.
   if (aTopVisibleMenuItem &&
       aTopVisibleMenuItem->PopupType() != ePopupTypeMenu) {
     if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE) {
       HidePopup(aTopVisibleMenuItem->Content(), false, false, false, true);
-      aKeyEvent->AsEvent()->StopPropagation();
-      aKeyEvent->AsEvent()->StopCrossProcessForwarding();
-      aKeyEvent->AsEvent()->PreventDefault();
+      aKeyEvent->StopPropagation();
+      aKeyEvent->StopCrossProcessForwarding();
+      aKeyEvent->PreventDefault();
     }
     return true;
   }
 
   bool consume = (aTopVisibleMenuItem || mActiveMenuBar);
   switch (keyCode) {
     case nsIDOMKeyEvent::DOM_VK_UP:
     case nsIDOMKeyEvent::DOM_VK_DOWN:
 #ifndef XP_MACOSX
       // roll up the popup when alt+up/down are pressed within a menulist.
-      bool alt;
-      aKeyEvent->GetAltKey(&alt);
-      if (alt && aTopVisibleMenuItem && aTopVisibleMenuItem->Frame()->IsMenuList()) {
+      if (aKeyEvent->AltKey() &&
+          aTopVisibleMenuItem &&
+          aTopVisibleMenuItem->Frame()->IsMenuList()) {
         Rollup(0, false, nullptr, nullptr);
         break;
       }
       MOZ_FALLTHROUGH;
 #endif
 
     case nsIDOMKeyEvent::DOM_VK_LEFT:
     case nsIDOMKeyEvent::DOM_VK_RIGHT:
@@ -2406,18 +2405,17 @@ nsXULPopupManager::HandleKeyboardEventWi
       // Intentional fall-through to RETURN case
       MOZ_FALLTHROUGH;
 
     case nsIDOMKeyEvent::DOM_VK_RETURN: {
       // If there is a popup open, check if the current item needs to be opened.
       // Otherwise, tell the active menubar, if any, to activate the menu. The
       // Enter method will return a menu if one needs to be opened as a result.
       nsMenuFrame* menuToOpen = nullptr;
-      WidgetGUIEvent* GUIEvent = aKeyEvent->AsEvent()->
-        WidgetEventPtr()->AsGUIEvent();
+      WidgetGUIEvent* GUIEvent = aKeyEvent->WidgetEventPtr()->AsGUIEvent();
 
       if (aTopVisibleMenuItem) {
         menuToOpen = aTopVisibleMenuItem->Frame()->Enter(GUIEvent);
       } else if (mActiveMenuBar) {
         menuToOpen = mActiveMenuBar->Enter(GUIEvent);
       }
       if (menuToOpen) {
         nsCOMPtr<nsIContent> content = menuToOpen->GetContent();
@@ -2426,19 +2424,19 @@ nsXULPopupManager::HandleKeyboardEventWi
       break;
     }
 
     default:
       return false;
   }
 
   if (consume) {
-    aKeyEvent->AsEvent()->StopPropagation();
-    aKeyEvent->AsEvent()->StopCrossProcessForwarding();
-    aKeyEvent->AsEvent()->PreventDefault();
+    aKeyEvent->StopPropagation();
+    aKeyEvent->StopCrossProcessForwarding();
+    aKeyEvent->PreventDefault();
   }
   return true;
 }
 
 nsContainerFrame*
 nsXULPopupManager::ImmediateParentFrame(nsContainerFrame* aFrame)
 {
   MOZ_ASSERT(aFrame && aFrame->GetContent());
@@ -2608,28 +2606,27 @@ nsXULPopupManager::IsValidMenuItem(nsICo
     aContent->IsElement() &&
     aContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
                                        nsGkAtoms::_true, eCaseMatters));
 }
 
 nsresult
 nsXULPopupManager::HandleEvent(nsIDOMEvent* aEvent)
 {
-  nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
+  RefPtr<KeyboardEvent> keyEvent =
+    aEvent->InternalDOMEvent()->AsKeyboardEvent();
   NS_ENSURE_TRUE(keyEvent, NS_ERROR_UNEXPECTED);
 
   //handlers shouldn't be triggered by non-trusted events.
-  bool trustedEvent = false;
-  aEvent->GetIsTrusted(&trustedEvent);
-  if (!trustedEvent) {
+  if (!keyEvent->IsTrusted()) {
     return NS_OK;
   }
 
   nsAutoString eventType;
-  aEvent->GetType(eventType);
+  keyEvent->GetType(eventType);
   if (eventType.EqualsLiteral("keyup")) {
     return KeyUp(keyEvent);
   }
   if (eventType.EqualsLiteral("keydown")) {
     return KeyDown(keyEvent);
   }
   if (eventType.EqualsLiteral("keypress")) {
     return KeyPress(keyEvent);
@@ -2646,136 +2643,129 @@ nsXULPopupManager::UpdateIgnoreKeys(bool
   if (item) {
     item->SetIgnoreKeys(aIgnoreKeys ? eIgnoreKeys_True : eIgnoreKeys_Shortcuts);
   }
   UpdateKeyboardListeners();
   return NS_OK;
 }
 
 nsresult
-nsXULPopupManager::KeyUp(nsIDOMKeyEvent* aKeyEvent)
+nsXULPopupManager::KeyUp(KeyboardEvent* aKeyEvent)
 {
   // don't do anything if a menu isn't open or a menubar isn't active
   if (!mActiveMenuBar) {
     nsMenuChainItem* item = GetTopVisibleMenu();
     if (!item || item->PopupType() != ePopupTypeMenu)
       return NS_OK;
 
     if (item->IgnoreKeys() == eIgnoreKeys_Shortcuts) {
-      aKeyEvent->AsEvent()->StopCrossProcessForwarding();
+      aKeyEvent->StopCrossProcessForwarding();
       return NS_OK;
     }
   }
 
-  aKeyEvent->AsEvent()->StopPropagation();
-  aKeyEvent->AsEvent()->StopCrossProcessForwarding();
-  aKeyEvent->AsEvent()->PreventDefault();
+  aKeyEvent->StopPropagation();
+  aKeyEvent->StopCrossProcessForwarding();
+  aKeyEvent->PreventDefault();
 
   return NS_OK; // I am consuming event
 }
 
 nsresult
-nsXULPopupManager::KeyDown(nsIDOMKeyEvent* aKeyEvent)
+nsXULPopupManager::KeyDown(KeyboardEvent* aKeyEvent)
 {
   nsMenuChainItem* item = GetTopVisibleMenu();
   if (item && item->Frame()->IsMenuLocked())
     return NS_OK;
 
   if (HandleKeyboardEventWithKeyCode(aKeyEvent, item)) {
     return NS_OK;
   }
 
   // don't do anything if a menu isn't open or a menubar isn't active
   if (!mActiveMenuBar && (!item || item->PopupType() != ePopupTypeMenu))
     return NS_OK;
 
   // Since a menu was open, stop propagation of the event to keep other event
   // listeners from becoming confused.
   if (!item || item->IgnoreKeys() != eIgnoreKeys_Shortcuts) {
-    aKeyEvent->AsEvent()->StopPropagation();
+    aKeyEvent->StopPropagation();
   }
 
   int32_t menuAccessKey = -1;
 
   // If the key just pressed is the access key (usually Alt),
   // dismiss and unfocus the menu.
 
   nsMenuBarListener::GetMenuAccessKey(&menuAccessKey);
   if (menuAccessKey) {
-    uint32_t theChar;
-    aKeyEvent->GetKeyCode(&theChar);
+    uint32_t theChar = aKeyEvent->KeyCode();
 
     if (theChar == (uint32_t)menuAccessKey) {
-      bool ctrl = false;
-      if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_CONTROL)
-        aKeyEvent->GetCtrlKey(&ctrl);
-      bool alt=false;
-      if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_ALT)
-        aKeyEvent->GetAltKey(&alt);
-      bool shift=false;
-      if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_SHIFT)
-        aKeyEvent->GetShiftKey(&shift);
-      bool meta=false;
-      if (menuAccessKey != nsIDOMKeyEvent::DOM_VK_META)
-        aKeyEvent->GetMetaKey(&meta);
+      bool ctrl = (menuAccessKey != nsIDOMKeyEvent::DOM_VK_CONTROL &&
+                   aKeyEvent->CtrlKey());
+      bool alt = (menuAccessKey != nsIDOMKeyEvent::DOM_VK_ALT &&
+                  aKeyEvent->AltKey());
+      bool shift = (menuAccessKey != nsIDOMKeyEvent::DOM_VK_SHIFT &&
+                    aKeyEvent->ShiftKey());
+      bool meta = (menuAccessKey != nsIDOMKeyEvent::DOM_VK_META &&
+                   aKeyEvent->MetaKey());
       if (!(ctrl || alt || shift || meta)) {
         // The access key just went down and no other
         // modifiers are already down.
         nsMenuChainItem* item = GetTopVisibleMenu();
         if (item && !item->Frame()->IsMenuList()) {
           Rollup(0, false, nullptr, nullptr);
         } else if (mActiveMenuBar) {
           mActiveMenuBar->MenuClosed();
         }
 
         // Clear the item to avoid bugs as it may have been deleted during rollup.
         item = nullptr;
       }
-      aKeyEvent->AsEvent()->StopPropagation();
-      aKeyEvent->AsEvent()->PreventDefault();
+      aKeyEvent->StopPropagation();
+      aKeyEvent->PreventDefault();
     }
   }
 
   aKeyEvent->AsEvent()->StopCrossProcessForwarding();
   return NS_OK;
 }
 
 nsresult
-nsXULPopupManager::KeyPress(nsIDOMKeyEvent* aKeyEvent)
+nsXULPopupManager::KeyPress(KeyboardEvent* aKeyEvent)
 {
   // Don't check prevent default flag -- menus always get first shot at key events.
 
   nsMenuChainItem* item = GetTopVisibleMenu();
   if (item &&
       (item->Frame()->IsMenuLocked() || item->PopupType() != ePopupTypeMenu)) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
-  NS_ENSURE_TRUE(keyEvent, NS_ERROR_UNEXPECTED);
   // if a menu is open or a menubar is active, it consumes the key event
   bool consume = (item || mActiveMenuBar);
 
-  WidgetInputEvent* evt = aKeyEvent->AsEvent()->WidgetEventPtr()->AsInputEvent();
+  WidgetInputEvent* evt = aKeyEvent->WidgetEventPtr()->AsInputEvent();
   bool isAccel = evt && evt->IsAccel();
 
   // When ignorekeys="shortcuts" is used, we don't call preventDefault on the
   // key event when the accelerator key is pressed. This allows another
   // listener to handle keys. For instance, this allows global shortcuts to
   // still apply while a menu is open.
   if (item && item->IgnoreKeys() == eIgnoreKeys_Shortcuts && isAccel) {
     consume = false;
   }
 
-  HandleShortcutNavigation(keyEvent, nullptr);
-
-  aKeyEvent->AsEvent()->StopCrossProcessForwarding();
+  HandleShortcutNavigation(aKeyEvent, nullptr);
+
+  aKeyEvent->StopCrossProcessForwarding();
   if (consume) {
-    aKeyEvent->AsEvent()->StopPropagation();
-    aKeyEvent->AsEvent()->PreventDefault();
+    aKeyEvent->StopPropagation();
+    aKeyEvent->PreventDefault();
   }
 
   return NS_OK; // I am consuming event
 }
 
 NS_IMETHODIMP
 nsXULPopupShowingEvent::Run()
 {
--- a/layout/xul/nsXULPopupManager.h
+++ b/layout/xul/nsXULPopupManager.h
@@ -47,21 +47,26 @@
  * calling Rollup.
  */
 
 class nsContainerFrame;
 class nsMenuFrame;
 class nsMenuPopupFrame;
 class nsMenuBarFrame;
 class nsMenuParent;
-class nsIDOMKeyEvent;
 class nsIDocShellTreeItem;
 class nsPIDOMWindowOuter;
 class nsRefreshDriver;
 
+namespace mozilla {
+namespace dom {
+class KeyboardEvent;
+} // namespace dom
+} // namespace mozilla
+
 // when a menu command is executed, the closemenu attribute may be used
 // to define how the menu should be closed up
 enum CloseMenuMode {
   CloseMenuMode_Auto, // close up the chain of menus, default value
   CloseMenuMode_None, // don't close up any menus
   CloseMenuMode_Single // close up only the menu the command is inside
 };
 
@@ -665,17 +670,17 @@ public:
    */
   void CancelMenuTimer(nsMenuParent* aMenuParent);
 
   /**
    * Handles navigation for menu accelkeys. If aFrame is specified, then the
    * key is handled by that popup, otherwise if aFrame is null, the key is
    * handled by the active popup or menubar.
    */
-  bool HandleShortcutNavigation(nsIDOMKeyEvent* aKeyEvent,
+  bool HandleShortcutNavigation(mozilla::dom::KeyboardEvent* aKeyEvent,
                                 nsMenuPopupFrame* aFrame);
 
   /**
    * Handles cursor navigation within a menu. Returns true if the key has
    * been handled.
    */
   bool HandleKeyboardNavigation(uint32_t aKeyCode);
 
@@ -689,25 +694,25 @@ public:
   {
     return HandleKeyboardNavigationInPopup(nullptr, aFrame, aDir);
   }
 
   /**
    * Handles the keyboard event with keyCode value. Returns true if the event
    * has been handled.
    */
-  bool HandleKeyboardEventWithKeyCode(nsIDOMKeyEvent* aKeyEvent,
+  bool HandleKeyboardEventWithKeyCode(mozilla::dom::KeyboardEvent* aKeyEvent,
                                       nsMenuChainItem* aTopVisibleMenuItem);
 
   // Sets mIgnoreKeys of the Top Visible Menu Item
   nsresult UpdateIgnoreKeys(bool aIgnoreKeys);
 
-  nsresult KeyUp(nsIDOMKeyEvent* aKeyEvent);
-  nsresult KeyDown(nsIDOMKeyEvent* aKeyEvent);
-  nsresult KeyPress(nsIDOMKeyEvent* aKeyEvent);
+  nsresult KeyUp(mozilla::dom::KeyboardEvent* aKeyEvent);
+  nsresult KeyDown(mozilla::dom::KeyboardEvent* aKeyEvent);
+  nsresult KeyPress(mozilla::dom::KeyboardEvent* aKeyEvent);
 
 protected:
   nsXULPopupManager();
   ~nsXULPopupManager();
 
   // get the nsMenuPopupFrame, if any, for the given content node
   nsMenuPopupFrame* GetPopupFrameForContent(nsIContent* aContent, bool aShouldFlush);