diff --git a/content/base/src/Element.cpp b/content/base/src/Element.cpp index b2f37e74ac3a..722bb8334394 100644 --- a/content/base/src/Element.cpp +++ b/content/base/src/Element.cpp @@ -2249,8 +2249,7 @@ Element::PostHandleEventForLinks(nsEventChainPostVisitor& aVisitor) case NS_MOUSE_CLICK: if (aVisitor.mEvent->IsLeftClickEvent()) { - WidgetInputEvent* inputEvent = - static_cast(aVisitor.mEvent); + WidgetInputEvent* inputEvent = aVisitor.mEvent->AsInputEvent(); if (inputEvent->IsControl() || inputEvent->IsMeta() || inputEvent->IsAlt() ||inputEvent->IsShift()) { break; diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index a2cf9229726d..30395fd668b0 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -526,7 +526,7 @@ nsDOMEvent::DuplicatePrivateData() } case NS_INPUT_EVENT: { - WidgetInputEvent* oldInputEvent = static_cast(mEvent); + WidgetInputEvent* oldInputEvent = mEvent->AsInputEvent(); WidgetInputEvent* inputEvent = new WidgetInputEvent(false, msg, nullptr); inputEvent->AssignInputEventData(*oldInputEvent, true); newEvent = inputEvent; diff --git a/content/events/src/nsDOMKeyboardEvent.cpp b/content/events/src/nsDOMKeyboardEvent.cpp index c42c3f2a10ae..379ecb114337 100644 --- a/content/events/src/nsDOMKeyboardEvent.cpp +++ b/content/events/src/nsDOMKeyboardEvent.cpp @@ -33,6 +33,12 @@ 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) { @@ -41,6 +47,12 @@ nsDOMKeyboardEvent::GetAltKey(bool* aIsDown) return NS_OK; } +bool +nsDOMKeyboardEvent::CtrlKey() +{ + return mEvent->AsKeyboardEvent()->IsControl(); +} + NS_IMETHODIMP nsDOMKeyboardEvent::GetCtrlKey(bool* aIsDown) { @@ -49,6 +61,12 @@ nsDOMKeyboardEvent::GetCtrlKey(bool* aIsDown) return NS_OK; } +bool +nsDOMKeyboardEvent::ShiftKey() +{ + return mEvent->AsKeyboardEvent()->IsShift(); +} + NS_IMETHODIMP nsDOMKeyboardEvent::GetShiftKey(bool* aIsDown) { @@ -57,6 +75,12 @@ nsDOMKeyboardEvent::GetShiftKey(bool* aIsDown) return NS_OK; } +bool +nsDOMKeyboardEvent::MetaKey() +{ + return mEvent->AsKeyboardEvent()->IsMeta(); +} + NS_IMETHODIMP nsDOMKeyboardEvent::GetMetaKey(bool* aIsDown) { diff --git a/content/events/src/nsDOMKeyboardEvent.h b/content/events/src/nsDOMKeyboardEvent.h index 354d5821bc23..20d5df18621f 100644 --- a/content/events/src/nsDOMKeyboardEvent.h +++ b/content/events/src/nsDOMKeyboardEvent.h @@ -10,7 +10,6 @@ #include "nsDOMUIEvent.h" #include "mozilla/EventForwards.h" #include "mozilla/dom/KeyboardEventBinding.h" -#include "mozilla/BasicEvents.h" class nsDOMKeyboardEvent : public nsDOMUIEvent, public nsIDOMKeyEvent @@ -34,25 +33,10 @@ public: return mozilla::dom::KeyboardEventBinding::Wrap(aCx, aScope, this); } - bool AltKey() - { - return static_cast(mEvent)->IsAlt(); - } - - bool CtrlKey() - { - return static_cast(mEvent)->IsControl(); - } - - bool ShiftKey() - { - return static_cast(mEvent)->IsShift(); - } - - bool MetaKey() - { - return static_cast(mEvent)->IsMeta(); - } + bool AltKey(); + bool CtrlKey(); + bool ShiftKey(); + bool MetaKey(); bool GetModifierState(const nsAString& aKey) { diff --git a/content/events/src/nsDOMMouseEvent.cpp b/content/events/src/nsDOMMouseEvent.cpp index c310d8453b7d..62116e75e6c8 100644 --- a/content/events/src/nsDOMMouseEvent.cpp +++ b/content/events/src/nsDOMMouseEvent.cpp @@ -122,7 +122,7 @@ nsDOMMouseEvent::InitMouseEvent(const nsAString& aType, case NS_WHEEL_EVENT: case NS_DRAG_EVENT: case NS_SIMPLE_GESTURE_EVENT: - static_cast(mEvent)->modifiers = modifiers; + mEvent->AsInputEvent()->modifiers = modifiers; return NS_OK; default: MOZ_CRASH("There is no space to store the modifiers"); @@ -354,6 +354,12 @@ nsDOMMouseEvent::ClientY() mClientPoint).y; } +bool +nsDOMMouseEvent::AltKey() +{ + return mEvent->AsInputEvent()->IsAlt(); +} + NS_IMETHODIMP nsDOMMouseEvent::GetAltKey(bool* aIsDown) { @@ -362,6 +368,12 @@ nsDOMMouseEvent::GetAltKey(bool* aIsDown) return NS_OK; } +bool +nsDOMMouseEvent::CtrlKey() +{ + return mEvent->AsInputEvent()->IsControl(); +} + NS_IMETHODIMP nsDOMMouseEvent::GetCtrlKey(bool* aIsDown) { @@ -370,6 +382,12 @@ nsDOMMouseEvent::GetCtrlKey(bool* aIsDown) return NS_OK; } +bool +nsDOMMouseEvent::ShiftKey() +{ + return mEvent->AsInputEvent()->IsShift(); +} + NS_IMETHODIMP nsDOMMouseEvent::GetShiftKey(bool* aIsDown) { @@ -378,6 +396,12 @@ nsDOMMouseEvent::GetShiftKey(bool* aIsDown) return NS_OK; } +bool +nsDOMMouseEvent::MetaKey() +{ + return mEvent->AsInputEvent()->IsMeta(); +} + NS_IMETHODIMP nsDOMMouseEvent::GetMetaKey(bool* aIsDown) { diff --git a/content/events/src/nsDOMMouseEvent.h b/content/events/src/nsDOMMouseEvent.h index e84498cd35b9..4c6b179f1827 100644 --- a/content/events/src/nsDOMMouseEvent.h +++ b/content/events/src/nsDOMMouseEvent.h @@ -9,7 +9,7 @@ #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 @@ -43,22 +43,10 @@ public: int32_t ScreenY(); int32_t ClientX(); int32_t ClientY(); - bool CtrlKey() - { - return static_cast(mEvent)->IsControl(); - } - bool ShiftKey() - { - return static_cast(mEvent)->IsShift(); - } - bool AltKey() - { - return static_cast(mEvent)->IsAlt(); - } - bool MetaKey() - { - return static_cast(mEvent)->IsMeta(); - } + bool CtrlKey(); + bool ShiftKey(); + bool AltKey(); + bool MetaKey(); uint16_t Button(); uint16_t Buttons(); already_AddRefed GetRelatedTarget(); diff --git a/content/events/src/nsDOMTouchEvent.cpp b/content/events/src/nsDOMTouchEvent.cpp index c774a5b31793..9e2daf3678d7 100644 --- a/content/events/src/nsDOMTouchEvent.cpp +++ b/content/events/src/nsDOMTouchEvent.cpp @@ -107,8 +107,8 @@ nsDOMTouchEvent::InitTouchEvent(const nsAString& aType, return; } - static_cast(mEvent)-> - InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey); + mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey, + aShiftKey, aMetaKey); mTouches = aTouches; mTargetTouches = aTargetTouches; mChangedTouches = aChangedTouches; @@ -213,6 +213,30 @@ nsDOMTouchEvent::PrefEnabled() 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, diff --git a/content/events/src/nsDOMTouchEvent.h b/content/events/src/nsDOMTouchEvent.h index 02e6084c7847..2b28789d1071 100644 --- a/content/events/src/nsDOMTouchEvent.h +++ b/content/events/src/nsDOMTouchEvent.h @@ -8,8 +8,9 @@ #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" @@ -98,25 +99,10 @@ public: nsDOMTouchList* TargetTouches(); nsDOMTouchList* ChangedTouches(); - bool AltKey() - { - return static_cast(mEvent)->IsAlt(); - } - - bool MetaKey() - { - return static_cast(mEvent)->IsMeta(); - } - - bool CtrlKey() - { - return static_cast(mEvent)->IsControl(); - } - - bool ShiftKey() - { - return static_cast(mEvent)->IsShift(); - } + bool AltKey(); + bool MetaKey(); + bool CtrlKey(); + bool ShiftKey(); void InitTouchEvent(const nsAString& aType, bool aCanBubble, diff --git a/content/events/src/nsDOMUIEvent.cpp b/content/events/src/nsDOMUIEvent.cpp index b00fe263ae5c..136441d9f8e7 100644 --- a/content/events/src/nsDOMUIEvent.cpp +++ b/content/events/src/nsDOMUIEvent.cpp @@ -456,10 +456,8 @@ nsDOMUIEvent::ComputeModifierState(const nsAString& aModifiersList) bool nsDOMUIEvent::GetModifierStateInternal(const nsAString& aKey) { - if (!mEvent->IsInputDerivedEvent()) { - MOZ_CRASH("mEvent must be WidgetInputEvent or derived class"); - } - WidgetInputEvent* inputEvent = static_cast(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(); } diff --git a/content/events/src/nsDOMXULCommandEvent.cpp b/content/events/src/nsDOMXULCommandEvent.cpp index f2233e61a7bd..ed10a4221d94 100644 --- a/content/events/src/nsDOMXULCommandEvent.cpp +++ b/content/events/src/nsDOMXULCommandEvent.cpp @@ -34,6 +34,12 @@ 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) { @@ -42,6 +48,12 @@ nsDOMXULCommandEvent::GetAltKey(bool* aIsDown) return NS_OK; } +bool +nsDOMXULCommandEvent::CtrlKey() +{ + return mEvent->AsInputEvent()->IsControl(); +} + NS_IMETHODIMP nsDOMXULCommandEvent::GetCtrlKey(bool* aIsDown) { @@ -50,6 +62,12 @@ nsDOMXULCommandEvent::GetCtrlKey(bool* aIsDown) return NS_OK; } +bool +nsDOMXULCommandEvent::ShiftKey() +{ + return mEvent->AsInputEvent()->IsShift(); +} + NS_IMETHODIMP nsDOMXULCommandEvent::GetShiftKey(bool* aIsDown) { @@ -58,6 +76,12 @@ nsDOMXULCommandEvent::GetShiftKey(bool* aIsDown) return NS_OK; } +bool +nsDOMXULCommandEvent::MetaKey() +{ + return mEvent->AsInputEvent()->IsMeta(); +} + NS_IMETHODIMP nsDOMXULCommandEvent::GetMetaKey(bool* aIsDown) { @@ -87,7 +111,8 @@ nsDOMXULCommandEvent::InitCommandEvent(const nsAString& aType, 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; diff --git a/content/events/src/nsDOMXULCommandEvent.h b/content/events/src/nsDOMXULCommandEvent.h index 52f40f943caa..888d62d815e7 100644 --- a/content/events/src/nsDOMXULCommandEvent.h +++ b/content/events/src/nsDOMXULCommandEvent.h @@ -34,25 +34,10 @@ public: 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 GetSourceEvent() { @@ -76,11 +61,6 @@ public: } protected: - // Convenience accessor for the event - mozilla::WidgetInputEvent* Event() { - return static_cast(mEvent); - } - nsCOMPtr mSourceEvent; }; diff --git a/content/html/content/src/HTMLInputElement.cpp b/content/html/content/src/HTMLInputElement.cpp index c993fd171d11..f518f516e6e5 100644 --- a/content/html/content/src/HTMLInputElement.cpp +++ b/content/html/content/src/HTMLInputElement.cpp @@ -3789,8 +3789,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(nsEventChainPostVisitor& aVisitor if (nsIPresShell::GetCapturingContent()) { break; // don't start drag if someone else is already capturing } - WidgetInputEvent* inputEvent = - static_cast(aVisitor.mEvent); + WidgetInputEvent* inputEvent = aVisitor.mEvent->AsInputEvent(); if (inputEvent->IsShift() || inputEvent->IsControl() || inputEvent->IsAlt() || inputEvent->IsMeta() || inputEvent->IsAltGraph() || inputEvent->IsFn() || @@ -3826,8 +3825,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(nsEventChainPostVisitor& aVisitor break; } SetValueOfRangeForUserEvent( - rangeFrame->GetValueAtEventPoint( - static_cast(aVisitor.mEvent))); + rangeFrame->GetValueAtEventPoint(aVisitor.mEvent->AsInputEvent())); aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true; break; @@ -3840,7 +3838,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(nsEventChainPostVisitor& aVisitor // 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(aVisitor.mEvent)); + FinishRangeThumbDrag(aVisitor.mEvent->AsInputEvent()); aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true; break; diff --git a/content/html/content/src/HTMLLabelElement.cpp b/content/html/content/src/HTMLLabelElement.cpp index f6693bb2a85f..56ff3ae6df96 100644 --- a/content/html/content/src/HTMLLabelElement.cpp +++ b/content/html/content/src/HTMLLabelElement.cpp @@ -197,7 +197,7 @@ HTMLLabelElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) EventFlags eventFlags; eventFlags.mMultipleActionsPrevented = true; DispatchClickEvent(aVisitor.mPresContext, - static_cast(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