diff --git a/widget/BasicEvents.h b/widget/BasicEvents.h index 97ea284e1578..cb3bab111f24 100644 --- a/widget/BasicEvents.h +++ b/widget/BasicEvents.h @@ -264,6 +264,59 @@ public: class WidgetEvent : public WidgetEventTime { +private: + void SetDefaultCancelableAndBubbles() + { + switch (mClass) { + case eEditorInputEventClass: + mFlags.mCancelable = false; + mFlags.mBubbles = mFlags.mIsTrusted; + break; + case eMouseEventClass: + mFlags.mCancelable = (mMessage != eMouseEnter && + mMessage != eMouseLeave); + mFlags.mBubbles = (mMessage != eMouseEnter && + mMessage != eMouseLeave); + break; + case ePointerEventClass: + mFlags.mCancelable = (mMessage != ePointerEnter && + mMessage != ePointerLeave && + mMessage != ePointerCancel && + mMessage != ePointerGotCapture && + mMessage != ePointerLostCapture); + mFlags.mBubbles = (mMessage != ePointerEnter && + mMessage != ePointerLeave); + break; + case eDragEventClass: + mFlags.mCancelable = (mMessage != eDragExit && + mMessage != eDragLeave && + mMessage != eDragEnd); + mFlags.mBubbles = true; + break; + case eSMILTimeEventClass: + mFlags.mCancelable = false; + mFlags.mBubbles = false; + break; + case eTransitionEventClass: + case eAnimationEventClass: + case eSVGZoomEventClass: + mFlags.mCancelable = false; + mFlags.mBubbles = true; + break; + case eCompositionEventClass: + // XXX compositionstart is cancelable in draft of DOM3 Events. + // However, it doesn't make sense for us, we cannot cancel + // composition when we send compositionstart event. + mFlags.mCancelable = false; + mFlags.mBubbles = true; + break; + default: + mFlags.mCancelable = true; + mFlags.mBubbles = true; + break; + } + } + protected: WidgetEvent(bool aIsTrusted, EventMessage aMessage, @@ -278,8 +331,7 @@ protected: MOZ_COUNT_CTOR(WidgetEvent); mFlags.Clear(); mFlags.mIsTrusted = aIsTrusted; - mFlags.mCancelable = true; - mFlags.mBubbles = true; + SetDefaultCancelableAndBubbles(); } WidgetEvent() @@ -290,18 +342,8 @@ protected: public: WidgetEvent(bool aIsTrusted, EventMessage aMessage) - : WidgetEventTime() - , mClass(eBasicEventClass) - , mMessage(aMessage) - , mRefPoint(0, 0) - , mLastRefPoint(0, 0) - , mSpecifiedEventType(nullptr) + : WidgetEvent(aIsTrusted, aMessage, eBasicEventClass) { - MOZ_COUNT_CTOR(WidgetEvent); - mFlags.Clear(); - mFlags.mIsTrusted = aIsTrusted; - mFlags.mCancelable = true; - mFlags.mBubbles = true; } virtual ~WidgetEvent() diff --git a/widget/ContentEvents.h b/widget/ContentEvents.h index fe979c7c73e4..fc83aaa057c9 100644 --- a/widget/ContentEvents.h +++ b/widget/ContentEvents.h @@ -244,7 +244,6 @@ public: : WidgetEvent(aIsTrusted, aMessage, eTransitionEventClass) , mElapsedTime(0.0) { - mFlags.mCancelable = false; } virtual WidgetEvent* Duplicate() const override @@ -289,7 +288,6 @@ public: : WidgetEvent(aIsTrusted, aMessage, eAnimationEventClass) , mElapsedTime(0.0) { - mFlags.mCancelable = false; } virtual WidgetEvent* Duplicate() const override @@ -330,7 +328,6 @@ public: InternalSVGZoomEvent(bool aIsTrusted, EventMessage aMessage) : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, eSVGZoomEventClass) { - mFlags.mCancelable = false; } virtual WidgetEvent* Duplicate() const override @@ -366,8 +363,6 @@ public: InternalSMILTimeEvent(bool aIsTrusted, EventMessage aMessage) : InternalUIEvent(aIsTrusted, aMessage, eSMILTimeEventClass) { - mFlags.mBubbles = false; - mFlags.mCancelable = false; } virtual WidgetEvent* Duplicate() const override diff --git a/widget/MouseEvents.h b/widget/MouseEvents.h index d3b580432475..b96a57254eb0 100644 --- a/widget/MouseEvents.h +++ b/widget/MouseEvents.h @@ -217,15 +217,6 @@ protected: , exit(eChild) , clickCount(0) { - switch (aMessage) { - case eMouseEnter: - case eMouseLeave: - mFlags.mBubbles = false; - mFlags.mCancelable = false; - break; - default: - break; - } } public: @@ -237,17 +228,8 @@ public: acceptActivation(false), ignoreRootScrollFrame(false), reason(aReason), context(aContext), exit(eChild), clickCount(0) { - switch (aMessage) { - case eMouseEnter: - case eMouseLeave: - mFlags.mBubbles = false; - mFlags.mCancelable = false; - break; - case eContextMenu: - button = (context == eNormal) ? eRightButton : eLeftButton; - break; - default: - break; + if (aMessage == eContextMenu) { + button = (context == eNormal) ? eRightButton : eLeftButton; } } @@ -337,8 +319,6 @@ public: , mUserCancelled(false) , mDefaultPreventedOnContent(false) { - mFlags.mCancelable = - (aMessage != eDragExit && aMessage != eDragLeave && aMessage != eDragEnd); } virtual WidgetEvent* Duplicate() const override @@ -675,7 +655,6 @@ public: , height(0) , isPrimary(true) { - UpdateFlags(); } explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent) @@ -685,25 +664,6 @@ public: , isPrimary(true) { mClass = ePointerEventClass; - UpdateFlags(); - } - - void UpdateFlags() - { - switch (mMessage) { - case ePointerEnter: - case ePointerLeave: - mFlags.mBubbles = false; - mFlags.mCancelable = false; - break; - case ePointerCancel: - case ePointerGotCapture: - case ePointerLostCapture: - mFlags.mCancelable = false; - break; - default: - break; - } } virtual WidgetEvent* Duplicate() const override diff --git a/widget/TextEvents.h b/widget/TextEvents.h index db54f757c688..42fe75eb904b 100644 --- a/widget/TextEvents.h +++ b/widget/TextEvents.h @@ -498,10 +498,6 @@ public: , mNativeIMEContext(aWidget) , mOriginalMessage(eVoidEvent) { - // XXX compositionstart is cancelable in draft of DOM3 Events. - // However, it doesn't make sense for us, we cannot cancel composition - // when we send compositionstart event. - mFlags.mCancelable = false; } virtual WidgetEvent* Duplicate() const override @@ -854,14 +850,6 @@ public: : InternalUIEvent(aIsTrusted, aMessage, aWidget, eEditorInputEventClass) , mIsComposing(false) { - if (!aIsTrusted) { - mFlags.mBubbles = false; - mFlags.mCancelable = false; - return; - } - - mFlags.mBubbles = true; - mFlags.mCancelable = false; } virtual WidgetEvent* Duplicate() const override