Bug 920425 part.27 Use mozilla::WidgetEvent::AsInputEvent() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 18 Oct 2013 15:10:26 +0900
changeset 151323 bc72b42bcf7644385188e115b123fd7a2d345b37
parent 151322 42dda6ce6ec875b488ad88b9193b3a585d733c8f
child 151324 9ba162545a939b738d909e31ae3afab10fb5cb76
push id25484
push userryanvm@gmail.com
push dateFri, 18 Oct 2013 19:14:25 +0000
treeherdermozilla-central@3daff401c7ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs920425
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 920425 part.27 Use mozilla::WidgetEvent::AsInputEvent() r=smaug
content/base/src/Element.cpp
content/events/src/nsDOMEvent.cpp
content/events/src/nsDOMKeyboardEvent.cpp
content/events/src/nsDOMKeyboardEvent.h
content/events/src/nsDOMMouseEvent.cpp
content/events/src/nsDOMMouseEvent.h
content/events/src/nsDOMTouchEvent.cpp
content/events/src/nsDOMTouchEvent.h
content/events/src/nsDOMUIEvent.cpp
content/events/src/nsDOMXULCommandEvent.cpp
content/events/src/nsDOMXULCommandEvent.h
content/html/content/src/HTMLInputElement.cpp
content/html/content/src/HTMLLabelElement.cpp
content/xbl/src/nsXBLPrototypeHandler.cpp
content/xul/content/src/nsXULElement.cpp
layout/generic/nsFrame.cpp
layout/xul/base/src/nsButtonBoxFrame.cpp
layout/xul/base/src/nsMenuBarListener.cpp
layout/xul/base/src/nsMenuFrame.cpp
layout/xul/base/src/nsXULPopupManager.cpp
widget/cocoa/TextInputHandler.mm
widget/windows/winrt/MetroWidget.cpp
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -2244,18 +2244,17 @@ Element::PostHandleEventForLinks(nsEvent
             aVisitor.mPresContext->EventStateManager(), this);
         }
       }
     }
     break;
 
   case NS_MOUSE_CLICK:
     if (aVisitor.mEvent->IsLeftClickEvent()) {
-      WidgetInputEvent* inputEvent =
-        static_cast<WidgetInputEvent*>(aVisitor.mEvent);
+      WidgetInputEvent* inputEvent = aVisitor.mEvent->AsInputEvent();
       if (inputEvent->IsControl() || inputEvent->IsMeta() ||
           inputEvent->IsAlt() ||inputEvent->IsShift()) {
         break;
       }
 
       // The default action is simply to dispatch DOMActivate
       nsCOMPtr<nsIPresShell> shell = aVisitor.mPresContext->GetPresShell();
       if (shell) {
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -521,17 +521,17 @@ nsDOMEvent::DuplicatePrivateData()
       // Not copying widget, it is a weak reference.
       WidgetGUIEvent* guiEvent = new WidgetGUIEvent(false, msg, nullptr);
       guiEvent->AssignGUIEventData(*oldGUIEvent, true);
       newEvent = guiEvent;
       break;
     }
     case NS_INPUT_EVENT:
     {
-      WidgetInputEvent* oldInputEvent = static_cast<WidgetInputEvent*>(mEvent);
+      WidgetInputEvent* oldInputEvent = mEvent->AsInputEvent();
       WidgetInputEvent* inputEvent = new WidgetInputEvent(false, msg, nullptr);
       inputEvent->AssignInputEventData(*oldInputEvent, true);
       newEvent = inputEvent;
       break;
     }
     case NS_KEY_EVENT:
     {
       WidgetKeyboardEvent* oldKeyEvent = mEvent->AsKeyboardEvent();
--- a/content/events/src/nsDOMKeyboardEvent.cpp
+++ b/content/events/src/nsDOMKeyboardEvent.cpp
@@ -28,40 +28,64 @@ nsDOMKeyboardEvent::nsDOMKeyboardEvent(m
 
 NS_IMPL_ADDREF_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent)
 NS_IMPL_RELEASE_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent)
 
 NS_INTERFACE_MAP_BEGIN(nsDOMKeyboardEvent)
   NS_INTERFACE_MAP_ENTRY(nsIDOMKeyEvent)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
 
+bool
+nsDOMKeyboardEvent::AltKey()
+{
+  return mEvent->AsKeyboardEvent()->IsAlt();
+}
+
 NS_IMETHODIMP
 nsDOMKeyboardEvent::GetAltKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = AltKey();
   return NS_OK;
 }
 
+bool
+nsDOMKeyboardEvent::CtrlKey()
+{
+  return mEvent->AsKeyboardEvent()->IsControl();
+}
+
 NS_IMETHODIMP
 nsDOMKeyboardEvent::GetCtrlKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = CtrlKey();
   return NS_OK;
 }
 
+bool
+nsDOMKeyboardEvent::ShiftKey()
+{
+  return mEvent->AsKeyboardEvent()->IsShift();
+}
+
 NS_IMETHODIMP
 nsDOMKeyboardEvent::GetShiftKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = ShiftKey();
   return NS_OK;
 }
 
+bool
+nsDOMKeyboardEvent::MetaKey()
+{
+  return mEvent->AsKeyboardEvent()->IsMeta();
+}
+
 NS_IMETHODIMP
 nsDOMKeyboardEvent::GetMetaKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = MetaKey();
   return NS_OK;
 }
 
--- a/content/events/src/nsDOMKeyboardEvent.h
+++ b/content/events/src/nsDOMKeyboardEvent.h
@@ -5,17 +5,16 @@
 
 #ifndef nsDOMKeyboardEvent_h__
 #define nsDOMKeyboardEvent_h__
 
 #include "nsIDOMKeyEvent.h"
 #include "nsDOMUIEvent.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/dom/KeyboardEventBinding.h"
-#include "mozilla/BasicEvents.h"
 
 class nsDOMKeyboardEvent : public nsDOMUIEvent,
                            public nsIDOMKeyEvent
 {
 public:
   nsDOMKeyboardEvent(mozilla::dom::EventTarget* aOwner,
                      nsPresContext* aPresContext,
                      mozilla::WidgetKeyboardEvent* aEvent);
@@ -29,35 +28,20 @@ public:
   NS_FORWARD_TO_NSDOMUIEVENT
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
   {
     return mozilla::dom::KeyboardEventBinding::Wrap(aCx, aScope, this);
   }
 
-  bool AltKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsAlt();
-  }
-
-  bool CtrlKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsControl();
-  }
-
-  bool ShiftKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsShift();
-  }
-
-  bool MetaKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsMeta();
-  }
+  bool AltKey();
+  bool CtrlKey();
+  bool ShiftKey();
+  bool MetaKey();
 
   bool GetModifierState(const nsAString& aKey)
   {
     return GetModifierStateInternal(aKey);
   }
 
   uint32_t CharCode();
   uint32_t KeyCode();
--- a/content/events/src/nsDOMMouseEvent.cpp
+++ b/content/events/src/nsDOMMouseEvent.cpp
@@ -117,17 +117,17 @@ nsDOMMouseEvent::InitMouseEvent(const ns
   NS_ENSURE_SUCCESS(rv, rv);
 
   switch(mEvent->eventStructType) {
     case NS_MOUSE_EVENT:
     case NS_MOUSE_SCROLL_EVENT:
     case NS_WHEEL_EVENT:
     case NS_DRAG_EVENT:
     case NS_SIMPLE_GESTURE_EVENT:
-      static_cast<WidgetInputEvent*>(mEvent)->modifiers = modifiers;
+      mEvent->AsInputEvent()->modifiers = modifiers;
       return NS_OK;
     default:
       MOZ_CRASH("There is no space to store the modifiers");
   }
 }
 
 already_AddRefed<nsDOMMouseEvent>
 nsDOMMouseEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal,
@@ -349,40 +349,64 @@ int32_t
 nsDOMMouseEvent::ClientY()
 {
   return nsDOMEvent::GetClientCoords(mPresContext,
                                      mEvent,
                                      mEvent->refPoint,
                                      mClientPoint).y;
 }
 
+bool
+nsDOMMouseEvent::AltKey()
+{
+  return mEvent->AsInputEvent()->IsAlt();
+}
+
 NS_IMETHODIMP
 nsDOMMouseEvent::GetAltKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = AltKey();
   return NS_OK;
 }
 
+bool
+nsDOMMouseEvent::CtrlKey()
+{
+  return mEvent->AsInputEvent()->IsControl();
+}
+
 NS_IMETHODIMP
 nsDOMMouseEvent::GetCtrlKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = CtrlKey();
   return NS_OK;
 }
 
+bool
+nsDOMMouseEvent::ShiftKey()
+{
+  return mEvent->AsInputEvent()->IsShift();
+}
+
 NS_IMETHODIMP
 nsDOMMouseEvent::GetShiftKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = ShiftKey();
   return NS_OK;
 }
 
+bool
+nsDOMMouseEvent::MetaKey()
+{
+  return mEvent->AsInputEvent()->IsMeta();
+}
+
 NS_IMETHODIMP
 nsDOMMouseEvent::GetMetaKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = MetaKey();
   return NS_OK;
 }
 
--- a/content/events/src/nsDOMMouseEvent.h
+++ b/content/events/src/nsDOMMouseEvent.h
@@ -4,17 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsDOMMouseEvent_h__
 #define nsDOMMouseEvent_h__
 
 #include "nsIDOMMouseEvent.h"
 #include "nsDOMUIEvent.h"
 #include "mozilla/dom/MouseEventBinding.h"
-#include "mozilla/BasicEvents.h"
+#include "mozilla/EventForwards.h"
 
 class nsDOMMouseEvent : public nsDOMUIEvent,
                         public nsIDOMMouseEvent
 {
 public:
   nsDOMMouseEvent(mozilla::dom::EventTarget* aOwner,
                   nsPresContext* aPresContext,
                   mozilla::WidgetMouseEventBase* aEvent);
@@ -38,32 +38,20 @@ public:
   {
     return Button() + 1;
   }
 
   int32_t ScreenX();
   int32_t ScreenY();
   int32_t ClientX();
   int32_t ClientY();
-  bool CtrlKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsControl();
-  }
-  bool ShiftKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsShift();
-  }
-  bool AltKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsAlt();
-  }
-  bool MetaKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsMeta();
-  }
+  bool CtrlKey();
+  bool ShiftKey();
+  bool AltKey();
+  bool MetaKey();
   uint16_t Button();
   uint16_t Buttons();
   already_AddRefed<mozilla::dom::EventTarget> GetRelatedTarget();
   void InitMouseEvent(const nsAString & aType, bool aCanBubble, bool aCancelable,
                       nsIDOMWindow* aView, int32_t aDetail, int32_t aScreenX,
                       int32_t aScreenY, int32_t aClientX, int32_t aClientY,
                       bool aCtrlKey, bool aAltKey, bool aShiftKey,
                       bool aMetaKey, uint16_t aButton,
--- a/content/events/src/nsDOMTouchEvent.cpp
+++ b/content/events/src/nsDOMTouchEvent.cpp
@@ -102,18 +102,18 @@ nsDOMTouchEvent::InitTouchEvent(const ns
                                   aCanBubble,
                                   aCancelable,
                                   aView,
                                   aDetail);
   if (aRv.Failed()) {
     return;
   }
 
-  static_cast<WidgetInputEvent*>(mEvent)->
-    InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
+  mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey,
+                                             aShiftKey, aMetaKey);
   mTouches = aTouches;
   mTargetTouches = aTargetTouches;
   mChangedTouches = aChangedTouches;
 }
 
 nsDOMTouchList*
 nsDOMTouchEvent::Touches()
 {
@@ -208,16 +208,40 @@ nsDOMTouchEvent::PrefEnabled()
     }
   }
   if (prefValue) {
     nsContentUtils::InitializeTouchEventTable();
   }
   return prefValue;
 }
 
+bool
+nsDOMTouchEvent::AltKey()
+{
+  return mEvent->AsTouchEvent()->IsAlt();
+}
+
+bool
+nsDOMTouchEvent::MetaKey()
+{
+  return mEvent->AsTouchEvent()->IsMeta();
+}
+
+bool
+nsDOMTouchEvent::CtrlKey()
+{
+  return mEvent->AsTouchEvent()->IsControl();
+}
+
+bool
+nsDOMTouchEvent::ShiftKey()
+{
+  return mEvent->AsTouchEvent()->IsShift();
+}
+
 nsresult
 NS_NewDOMTouchEvent(nsIDOMEvent** aInstancePtrResult,
                     mozilla::dom::EventTarget* aOwner,
                     nsPresContext* aPresContext,
                     WidgetTouchEvent* aEvent)
 {
   nsDOMTouchEvent* it = new nsDOMTouchEvent(aOwner, aPresContext, aEvent);
   return CallQueryInterface(it, aInstancePtrResult);
--- a/content/events/src/nsDOMTouchEvent.h
+++ b/content/events/src/nsDOMTouchEvent.h
@@ -3,18 +3,19 @@
  * 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 nsDOMTouchEvent_h_
 #define nsDOMTouchEvent_h_
 
 #include "nsDOMUIEvent.h"
 #include "nsTArray.h"
 #include "mozilla/Attributes.h"
-#include "mozilla/TouchEvents.h"
+#include "mozilla/EventForwards.h"
 #include "nsJSEnvironment.h"
+#include "mozilla/dom/Touch.h"
 #include "mozilla/dom/TouchEventBinding.h"
 #include "nsWrapperCache.h"
 
 
 class nsAString;
 
 class nsDOMTouchList MOZ_FINAL : public nsISupports
                                , public nsWrapperCache
@@ -93,35 +94,20 @@ public:
   {
     return mozilla::dom::TouchEventBinding::Wrap(aCx, aScope, this);
   }
 
   nsDOMTouchList* Touches();
   nsDOMTouchList* TargetTouches();
   nsDOMTouchList* ChangedTouches();
 
-  bool AltKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsAlt();
-  }
-
-  bool MetaKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsMeta();
-  }
-
-  bool CtrlKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsControl();
-  }
-
-  bool ShiftKey()
-  {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsShift();
-  }
+  bool AltKey();
+  bool MetaKey();
+  bool CtrlKey();
+  bool ShiftKey();
 
   void InitTouchEvent(const nsAString& aType,
                       bool aCanBubble,
                       bool aCancelable,
                       nsIDOMWindow* aView,
                       int32_t aDetail,
                       bool aCtrlKey,
                       bool aAltKey,
--- a/content/events/src/nsDOMUIEvent.cpp
+++ b/content/events/src/nsDOMUIEvent.cpp
@@ -451,20 +451,18 @@ nsDOMUIEvent::ComputeModifierState(const
   }
 
   return modifiers;
 }
 
 bool
 nsDOMUIEvent::GetModifierStateInternal(const nsAString& aKey)
 {
-  if (!mEvent->IsInputDerivedEvent()) {
-    MOZ_CRASH("mEvent must be WidgetInputEvent or derived class");
-  }
-  WidgetInputEvent* inputEvent = static_cast<WidgetInputEvent*>(mEvent);
+  WidgetInputEvent* inputEvent = mEvent->AsInputEvent();
+  MOZ_ASSERT(inputEvent, "mEvent must be WidgetInputEvent or derived class");
   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_SHIFT)) {
     return inputEvent->IsShift();
   }
   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_CONTROL)) {
     return inputEvent->IsControl();
   }
   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_META)) {
     return inputEvent->IsMeta();
--- a/content/events/src/nsDOMXULCommandEvent.cpp
+++ b/content/events/src/nsDOMXULCommandEvent.cpp
@@ -29,40 +29,64 @@ NS_IMPL_RELEASE_INHERITED(nsDOMXULComman
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED_1(nsDOMXULCommandEvent, nsDOMUIEvent,
                                      mSourceEvent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMXULCommandEvent)
   NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandEvent)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
 
+bool
+nsDOMXULCommandEvent::AltKey()
+{
+  return mEvent->AsInputEvent()->IsAlt();
+}
+
 NS_IMETHODIMP
 nsDOMXULCommandEvent::GetAltKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = AltKey();
   return NS_OK;
 }
 
+bool
+nsDOMXULCommandEvent::CtrlKey()
+{
+  return mEvent->AsInputEvent()->IsControl();
+}
+
 NS_IMETHODIMP
 nsDOMXULCommandEvent::GetCtrlKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = CtrlKey();
   return NS_OK;
 }
 
+bool
+nsDOMXULCommandEvent::ShiftKey()
+{
+  return mEvent->AsInputEvent()->IsShift();
+}
+
 NS_IMETHODIMP
 nsDOMXULCommandEvent::GetShiftKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = ShiftKey();
   return NS_OK;
 }
 
+bool
+nsDOMXULCommandEvent::MetaKey()
+{
+  return mEvent->AsInputEvent()->IsMeta();
+}
+
 NS_IMETHODIMP
 nsDOMXULCommandEvent::GetMetaKey(bool* aIsDown)
 {
   NS_ENSURE_ARG_POINTER(aIsDown);
   *aIsDown = MetaKey();
   return NS_OK;
 }
 
@@ -82,17 +106,18 @@ nsDOMXULCommandEvent::InitCommandEvent(c
                                        bool aCtrlKey, bool aAltKey,
                                        bool aShiftKey, bool aMetaKey,
                                        nsIDOMEvent* aSourceEvent)
 {
   nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable,
                                           aView, aDetail);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  Event()->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
+  mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey,
+                                             aShiftKey, aMetaKey);
   mSourceEvent = aSourceEvent;
 
   return NS_OK;
 }
 
 
 nsresult NS_NewDOMXULCommandEvent(nsIDOMEvent** aInstancePtrResult,
                                   mozilla::dom::EventTarget* aOwner,
--- a/content/events/src/nsDOMXULCommandEvent.h
+++ b/content/events/src/nsDOMXULCommandEvent.h
@@ -29,35 +29,20 @@ public:
   NS_FORWARD_TO_NSDOMUIEVENT
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
   {
     return mozilla::dom::XULCommandEventBinding::Wrap(aCx, aScope, this);
   }
 
-  bool AltKey()
-  {
-    return Event()->IsAlt();
-  }
-
-  bool CtrlKey()
-  {
-    return Event()->IsControl();
-  }
-
-  bool ShiftKey()
-  {
-    return Event()->IsShift();
-  }
-
-  bool MetaKey()
-  {
-    return Event()->IsMeta();
-  }
+  bool AltKey();
+  bool CtrlKey();
+  bool ShiftKey();
+  bool MetaKey();
 
   already_AddRefed<nsDOMEvent> GetSourceEvent()
   {
     nsRefPtr<nsDOMEvent> e =
       mSourceEvent ? mSourceEvent->InternalDOMEvent() : nullptr;
     return e.forget();
   }
 
@@ -71,17 +56,12 @@ public:
                         mozilla::ErrorResult& aRv)
   {
     aRv = InitCommandEvent(aType, aCanBubble, aCancelable, aView, aDetail,
                            aCtrlKey, aAltKey, aShiftKey, aMetaKey,
                            aSourceEvent);
   }
 
 protected:
-  // Convenience accessor for the event
-  mozilla::WidgetInputEvent* Event() {
-    return static_cast<mozilla::WidgetInputEvent*>(mEvent);
-  }
-
   nsCOMPtr<nsIDOMEvent> mSourceEvent;
 };
 
 #endif  // nsDOMXULCommandEvent_h_
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -3784,18 +3784,17 @@ HTMLInputElement::PostHandleEventForRang
     case NS_MOUSE_BUTTON_DOWN:
     case NS_TOUCH_START: {
       if (mIsDraggingRange) {
         break;
       }
       if (nsIPresShell::GetCapturingContent()) {
         break; // don't start drag if someone else is already capturing
       }
-      WidgetInputEvent* inputEvent =
-        static_cast<WidgetInputEvent*>(aVisitor.mEvent);
+      WidgetInputEvent* inputEvent = aVisitor.mEvent->AsInputEvent();
       if (inputEvent->IsShift() || inputEvent->IsControl() ||
           inputEvent->IsAlt() || inputEvent->IsMeta() ||
           inputEvent->IsAltGraph() || inputEvent->IsFn() ||
           inputEvent->IsOS()) {
         break; // ignore
       }
       if (aVisitor.mEvent->message == NS_MOUSE_BUTTON_DOWN) {
         WidgetMouseEvent* mouseEvent =
@@ -3821,31 +3820,30 @@ HTMLInputElement::PostHandleEventForRang
         break;
       }
       if (nsIPresShell::GetCapturingContent() != this) {
         // Someone else grabbed capture.
         CancelRangeThumbDrag();
         break;
       }
       SetValueOfRangeForUserEvent(
-        rangeFrame->GetValueAtEventPoint(
-          static_cast<WidgetInputEvent*>(aVisitor.mEvent)));
+        rangeFrame->GetValueAtEventPoint(aVisitor.mEvent->AsInputEvent()));
       aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
       break;
 
     case NS_MOUSE_BUTTON_UP:
     case NS_TOUCH_END:
       if (!mIsDraggingRange) {
         break;
       }
       // We don't check to see whether we are the capturing content here and
       // call CancelRangeThumbDrag() if that is the case. We just finish off
       // the drag and set our final value (unless someone has called
       // preventDefault() and prevents us getting here).
-      FinishRangeThumbDrag(static_cast<WidgetInputEvent*>(aVisitor.mEvent));
+      FinishRangeThumbDrag(aVisitor.mEvent->AsInputEvent());
       aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
       break;
 
     case NS_KEY_PRESS:
       if (mIsDraggingRange &&
           aVisitor.mEvent->AsKeyboardEvent()->keyCode == NS_VK_ESCAPE) {
         CancelRangeThumbDrag();
       }
--- a/content/html/content/src/HTMLLabelElement.cpp
+++ b/content/html/content/src/HTMLLabelElement.cpp
@@ -192,17 +192,17 @@ HTMLLabelElement::PostHandleEvent(nsEven
           //    sensible, we might send more events through like
           //    this.)  See bug 7554, bug 49897, and bug 96813.
           nsEventStatus status = aVisitor.mEventStatus;
           // Ok to use aVisitor.mEvent as parameter because DispatchClickEvent
           // will actually create a new event.
           EventFlags eventFlags;
           eventFlags.mMultipleActionsPrevented = true;
           DispatchClickEvent(aVisitor.mPresContext,
-                             static_cast<WidgetInputEvent*>(aVisitor.mEvent),
+                             aVisitor.mEvent->AsInputEvent(),
                              content, false, &eventFlags, &status);
           // Do we care about the status this returned?  I don't think we do...
           // Don't run another <label> off of this click
           aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
         }
         break;
     }
     mHandlingEvent = false;
--- a/content/xbl/src/nsXBLPrototypeHandler.cpp
+++ b/content/xbl/src/nsXBLPrototypeHandler.cpp
@@ -905,19 +905,18 @@ nsXBLPrototypeHandler::ReportKeyConflict
                                   params, ArrayLength(params),
                                   nullptr, EmptyString(), mLineNumber);
 }
 
 bool
 nsXBLPrototypeHandler::ModifiersMatchMask(nsIDOMUIEvent* aEvent,
                                           bool aIgnoreShiftKey)
 {
-  WidgetEvent* event = aEvent->GetInternalNSEvent();
-  NS_ENSURE_TRUE(event && event->IsInputDerivedEvent(), false);
-  WidgetInputEvent* inputEvent = static_cast<WidgetInputEvent*>(event);
+  WidgetInputEvent* inputEvent = aEvent->GetInternalNSEvent()->AsInputEvent();
+  NS_ENSURE_TRUE(inputEvent, false);
 
   if (mKeyMask & cMetaMask) {
     if (inputEvent->IsMeta() != ((mKeyMask & cMeta) != 0)) {
       return false;
     }
   }
 
   if (mKeyMask & cOSMask) {
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -1185,18 +1185,17 @@ nsXULElement::PreHandleEvent(nsEventChai
                         do_QueryInterface(domEvent);
                     if (commandEvent) {
                         commandEvent->GetSourceEvent(getter_AddRefs(domEvent));
                     } else {
                         domEvent = nullptr;
                     }
                 }
 
-                WidgetInputEvent* orig =
-                    static_cast<WidgetInputEvent*>(aVisitor.mEvent);
+                WidgetInputEvent* orig = aVisitor.mEvent->AsInputEvent();
                 nsContentUtils::DispatchXULCommand(
                   commandContent,
                   aVisitor.mEvent->mFlags.mIsTrusted,
                   aVisitor.mDOMEvent,
                   nullptr,
                   orig->IsControl(),
                   orig->IsAlt(),
                   orig->IsShift(),
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -2580,18 +2580,17 @@ nsFrame::HandlePress(nsPresContext* aPre
 
   // if we are in Navigator and the click is in a draggable node, we don't want
   // to start selection because we don't want to interfere with a potential
   // drag of said node and steal all its glory.
   int16_t isEditor = shell->GetSelectionFlags();
   //weaaak. only the editor can display frame selection not just text and images
   isEditor = isEditor == nsISelectionDisplay::DISPLAY_ALL;
 
-  WidgetInputEvent* keyEvent = static_cast<WidgetInputEvent*>(aEvent);
-  if (!keyEvent->IsAlt()) {
+  if (!aEvent->AsInputEvent()->IsAlt()) {
     for (nsIContent* content = mContent; content;
          content = content->GetParent()) {
       if (nsContentUtils::ContentIsDraggable(content) &&
           !content->IsEditable()) {
         // coordinate stuff is the fix for bug #55921
         if ((mRect - GetPosition()).Contains(
                nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this)))
           return NS_OK;
--- a/layout/xul/base/src/nsButtonBoxFrame.cpp
+++ b/layout/xul/base/src/nsButtonBoxFrame.cpp
@@ -127,20 +127,21 @@ nsButtonBoxFrame::DoMouseClick(WidgetGUI
     return;
 
   // Execute the oncommand event handler.
   bool isShift = false;
   bool isControl = false;
   bool isAlt = false;
   bool isMeta = false;
   if(aEvent) {
-    isShift = static_cast<WidgetInputEvent*>(aEvent)->IsShift();
-    isControl = static_cast<WidgetInputEvent*>(aEvent)->IsControl();
-    isAlt = static_cast<WidgetInputEvent*>(aEvent)->IsAlt();
-    isMeta = static_cast<WidgetInputEvent*>(aEvent)->IsMeta();
+    WidgetInputEvent* inputEvent = aEvent->AsInputEvent();
+    isShift = inputEvent->IsShift();
+    isControl = inputEvent->IsControl();
+    isAlt = inputEvent->IsAlt();
+    isMeta = inputEvent->IsMeta();
   }
 
   // Have the content handle the event, propagating it according to normal DOM rules.
   nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
   if (shell) {
     nsContentUtils::DispatchXULCommand(mContent,
                                        aEvent ?
                                          aEvent->mFlags.mIsTrusted : aTrustEvent,
--- a/layout/xul/base/src/nsMenuBarListener.cpp
+++ b/layout/xul/base/src/nsMenuBarListener.cpp
@@ -265,17 +265,17 @@ nsMenuBarListener::IsAccessKeyPressed(ns
           (modifiers & ~(mAccessKeyMask | MODIFIER_SHIFT)) == 0);
 }
 
 uint32_t
 nsMenuBarListener::GetModifiers(nsIDOMKeyEvent* aKeyEvent)
 {
   uint32_t modifiers = 0;
   WidgetInputEvent* inputEvent =
-    static_cast<WidgetInputEvent*>(aKeyEvent->GetInternalNSEvent());
+    aKeyEvent->GetInternalNSEvent()->AsInputEvent();
   MOZ_ASSERT(inputEvent);
 
   if (inputEvent->IsShift()) {
     modifiers |= MODIFIER_SHIFT;
   }
 
   if (inputEvent->IsControl()) {
     modifiers |= MODIFIER_CONTROL;
--- a/layout/xul/base/src/nsMenuFrame.cpp
+++ b/layout/xul/base/src/nsMenuFrame.cpp
@@ -1243,22 +1243,22 @@ nsMenuFrame::CreateMenuCommandEvent(Widg
 {
   // Create a trusted event if the triggering event was trusted, or if
   // we're called from chrome code (since at least one of our caller
   // passes in a null event).
   bool isTrusted = aEvent ? aEvent->mFlags.mIsTrusted :
                               nsContentUtils::IsCallerChrome();
 
   bool shift = false, control = false, alt = false, meta = false;
-  if (aEvent && (aEvent->eventStructType == NS_MOUSE_EVENT ||
-                 aEvent->eventStructType == NS_KEY_EVENT)) {
-    shift = static_cast<WidgetInputEvent*>(aEvent)->IsShift();
-    control = static_cast<WidgetInputEvent*>(aEvent)->IsControl();
-    alt = static_cast<WidgetInputEvent*>(aEvent)->IsAlt();
-    meta = static_cast<WidgetInputEvent*>(aEvent)->IsMeta();
+  WidgetInputEvent* inputEvent = aEvent ? aEvent->AsInputEvent() : nullptr;
+  if (inputEvent) {
+    shift = inputEvent->IsShift();
+    control = inputEvent->IsControl();
+    alt = inputEvent->IsAlt();
+    meta = inputEvent->IsMeta();
   }
 
   // Because the command event is firing asynchronously, a flag is needed to
   // indicate whether user input is being handled. This ensures that a popup
   // window won't get blocked.
   bool userinput = nsEventStateManager::IsHandlingUserInput();
 
   mDelayedMenuCommandEvent =
--- a/layout/xul/base/src/nsXULPopupManager.cpp
+++ b/layout/xul/base/src/nsXULPopupManager.cpp
@@ -475,19 +475,19 @@ nsXULPopupManager::InitTriggerEvent(nsID
     uiEvent->GetRangeParent(getter_AddRefs(mRangeParent));
     uiEvent->GetRangeOffset(&mRangeOffset);
 
     // get the event coordinates relative to the root frame of the document
     // containing the popup.
     NS_ASSERTION(aPopup, "Expected a popup node");
     WidgetEvent* event = aEvent->GetInternalNSEvent();
     if (event) {
-      if (event->eventStructType == NS_MOUSE_EVENT ||
-          event->eventStructType == NS_KEY_EVENT) {
-        mCachedModifiers = static_cast<WidgetInputEvent*>(event)->modifiers;
+      WidgetInputEvent* inputEvent = event->AsInputEvent();
+      if (inputEvent) {
+        mCachedModifiers = inputEvent->modifiers;
       }
       nsIDocument* doc = aPopup->GetCurrentDoc();
       if (doc) {
         nsIPresShell* presShell = doc->GetShell();
         nsPresContext* presContext;
         if (presShell && (presContext = presShell->GetPresContext())) {
           nsPresContext* rootDocPresContext =
             presContext->GetRootPresContext();
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -4174,17 +4174,17 @@ TextInputHandlerBase::OnDestroyWidget(ns
   mWidget = nullptr;
   return true;
 }
 
 bool
 TextInputHandlerBase::DispatchEvent(WidgetGUIEvent& aEvent)
 {
   if (aEvent.message == NS_KEY_PRESS) {
-    WidgetInputEvent& inputEvent = static_cast<WidgetInputEvent&>(aEvent);
+    WidgetInputEvent& inputEvent = *aEvent.AsInputEvent();
     if (!inputEvent.IsMeta()) {
       PR_LOG(gLog, PR_LOG_ALWAYS,
         ("%p TextInputHandlerBase::DispatchEvent, hiding mouse cursor", this));
       [NSCursor setHiddenUntilMouseMoves:YES];
     }
   }
   return mWidget->DispatchWindowEvent(aEvent);
 }
--- a/widget/windows/winrt/MetroWidget.cpp
+++ b/widget/windows/winrt/MetroWidget.cpp
@@ -1015,32 +1015,31 @@ MetroWidget::HitTestAPZC(ScreenPoint& pt
 nsEventStatus
 MetroWidget::ApzReceiveInputEvent(WidgetInputEvent* aEvent)
 {
   MOZ_ASSERT(aEvent);
 
   if (!MetroWidget::sAPZC) {
     return nsEventStatus_eIgnore;
   }
-  WidgetInputEvent& event = static_cast<WidgetInputEvent&>(*aEvent);
-  return MetroWidget::sAPZC->ReceiveInputEvent(event);
+  return MetroWidget::sAPZC->ReceiveInputEvent(*aEvent->AsInputEvent());
 }
 
 nsEventStatus
 MetroWidget::ApzReceiveInputEvent(WidgetInputEvent* aInEvent,
                                   WidgetInputEvent* aOutEvent)
 {
   MOZ_ASSERT(aInEvent);
   MOZ_ASSERT(aOutEvent);
 
   if (!MetroWidget::sAPZC) {
     return nsEventStatus_eIgnore;
   }
-  WidgetInputEvent& event = static_cast<WidgetInputEvent&>(*aInEvent);
-  return MetroWidget::sAPZC->ReceiveInputEvent(event, aOutEvent);
+  return MetroWidget::sAPZC->ReceiveInputEvent(*aInEvent->AsInputEvent(),
+                                               aOutEvent);
 }
 
 LayerManager*
 MetroWidget::GetLayerManager(PLayerTransactionChild* aShadowManager,
                              LayersBackend aBackendHint,
                              LayerManagerPersistence aPersistence,
                              bool* aAllowRetaining)
 {