Bug 386743 - Set default event bubbling/cancelable flags in the WidgetEvent constructor. r=smaug
authorStone Shih <sshih@mozilla.com>
Wed, 13 Apr 2016 14:16:42 +0800
changeset 335923 dfd6e945e298d956474469d41799fa8cad4abbc7
parent 335922 5b7777972750aa3c57e6f6f6d4e4621072741617
child 335924 e7d6853ddf2f14068e3c5dcd7614c9250b60a4b2
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs386743
milestone49.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 386743 - Set default event bubbling/cancelable flags in the WidgetEvent constructor. r=smaug
widget/BasicEvents.h
widget/ContentEvents.h
widget/MouseEvents.h
widget/TextEvents.h
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -259,54 +259,96 @@ public:
 };
 
 /******************************************************************************
  * mozilla::WidgetEvent
  ******************************************************************************/
 
 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,
               EventClassID aEventClassID)
     : WidgetEventTime()
     , mClass(aEventClassID)
     , mMessage(aMessage)
     , mRefPoint(0, 0)
     , mLastRefPoint(0, 0)
     , mSpecifiedEventType(nullptr)
   {
     MOZ_COUNT_CTOR(WidgetEvent);
     mFlags.Clear();
     mFlags.mIsTrusted = aIsTrusted;
-    mFlags.mCancelable = true;
-    mFlags.mBubbles = true;
+    SetDefaultCancelableAndBubbles();
   }
 
   WidgetEvent()
     : WidgetEventTime()
   {
     MOZ_COUNT_CTOR(WidgetEvent);
   }
 
 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()
   {
     MOZ_COUNT_DTOR(WidgetEvent);
   }
 
   WidgetEvent(const WidgetEvent& aOther)
--- a/widget/ContentEvents.h
+++ b/widget/ContentEvents.h
@@ -239,17 +239,16 @@ public:
   {
     return this;
   }
 
   InternalTransitionEvent(bool aIsTrusted, EventMessage aMessage)
     : WidgetEvent(aIsTrusted, aMessage, eTransitionEventClass)
     , mElapsedTime(0.0)
   {
-    mFlags.mCancelable = false;
   }
 
   virtual WidgetEvent* Duplicate() const override
   {
     MOZ_ASSERT(mClass == eTransitionEventClass,
                "Duplicate() must be overridden by sub class");
     InternalTransitionEvent* result =
       new InternalTransitionEvent(false, mMessage);
@@ -284,17 +283,16 @@ public:
   {
     return this;
   }
 
   InternalAnimationEvent(bool aIsTrusted, EventMessage aMessage)
     : WidgetEvent(aIsTrusted, aMessage, eAnimationEventClass)
     , mElapsedTime(0.0)
   {
-    mFlags.mCancelable = false;
   }
 
   virtual WidgetEvent* Duplicate() const override
   {
     MOZ_ASSERT(mClass == eAnimationEventClass,
                "Duplicate() must be overridden by sub class");
     InternalAnimationEvent* result =
       new InternalAnimationEvent(false, mMessage);
@@ -325,17 +323,16 @@ public:
 class InternalSVGZoomEvent : public WidgetGUIEvent
 {
 public:
   virtual InternalSVGZoomEvent* AsSVGZoomEvent() override { return this; }
 
   InternalSVGZoomEvent(bool aIsTrusted, EventMessage aMessage)
     : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, eSVGZoomEventClass)
   {
-    mFlags.mCancelable = false;
   }
 
   virtual WidgetEvent* Duplicate() const override
   {
     MOZ_ASSERT(mClass == eSVGZoomEventClass,
                "Duplicate() must be overridden by sub class");
     // Not copying widget, it is a weak reference.
     InternalSVGZoomEvent* result = new InternalSVGZoomEvent(false, mMessage);
@@ -361,18 +358,16 @@ public:
   virtual InternalSMILTimeEvent* AsSMILTimeEvent() override
   {
     return this;
   }
 
   InternalSMILTimeEvent(bool aIsTrusted, EventMessage aMessage)
     : InternalUIEvent(aIsTrusted, aMessage, eSMILTimeEventClass)
   {
-    mFlags.mBubbles = false;
-    mFlags.mCancelable = false;
   }
 
   virtual WidgetEvent* Duplicate() const override
   {
     MOZ_ASSERT(mClass == eSMILTimeEventClass,
                "Duplicate() must be overridden by sub class");
     InternalSMILTimeEvent* result = new InternalSMILTimeEvent(false, mMessage);
     result->AssignSMILTimeEventData(*this, true);
--- a/widget/MouseEvents.h
+++ b/widget/MouseEvents.h
@@ -212,47 +212,29 @@ protected:
     : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aEventClassID)
     , acceptActivation(false)
     , ignoreRootScrollFrame(false)
     , reason(aReason)
     , context(eNormal)
     , exit(eChild)
     , clickCount(0)
   {
-    switch (aMessage) {
-      case eMouseEnter:
-      case eMouseLeave:
-        mFlags.mBubbles = false;
-        mFlags.mCancelable = false;
-        break;
-      default:
-        break;
-    }
   }
 
 public:
   virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
 
   WidgetMouseEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
                    reasonType aReason, contextType aContext = eNormal) :
     WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, eMouseEventClass),
     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;
     }
   }
 
 #ifdef DEBUG
   virtual ~WidgetMouseEvent()
   {
     NS_WARN_IF_FALSE(mMessage != eContextMenu ||
                      button ==
@@ -332,18 +314,16 @@ protected:
 public:
   virtual WidgetDragEvent* AsDragEvent() override { return this; }
 
   WidgetDragEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget)
     : WidgetMouseEvent(aIsTrusted, aMessage, aWidget, eDragEventClass, eReal)
     , mUserCancelled(false)
     , mDefaultPreventedOnContent(false)
   {
-    mFlags.mCancelable =
-      (aMessage != eDragExit && aMessage != eDragLeave && aMessage != eDragEnd);
   }
 
   virtual WidgetEvent* Duplicate() const override
   {
     MOZ_ASSERT(mClass == eDragEventClass,
                "Duplicate() must be overridden by sub class");
     // Not copying widget, it is a weak reference.
     WidgetDragEvent* result = new WidgetDragEvent(false, mMessage, nullptr);
@@ -670,45 +650,25 @@ public:
   virtual WidgetPointerEvent* AsPointerEvent() override { return this; }
 
   WidgetPointerEvent(bool aIsTrusted, EventMessage aMsg, nsIWidget* w)
     : WidgetMouseEvent(aIsTrusted, aMsg, w, ePointerEventClass, eReal)
     , width(0)
     , height(0)
     , isPrimary(true)
   {
-    UpdateFlags();
   }
 
   explicit WidgetPointerEvent(const WidgetMouseEvent& aEvent)
     : WidgetMouseEvent(aEvent)
     , width(0)
     , height(0)
     , 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
   {
     MOZ_ASSERT(mClass == ePointerEventClass,
                "Duplicate() must be overridden by sub class");
     // Not copying widget, it is a weak reference.
     WidgetPointerEvent* result =
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -493,20 +493,16 @@ public:
   }
 
   WidgetCompositionEvent(bool aIsTrusted, EventMessage aMessage,
                          nsIWidget* aWidget)
     : WidgetGUIEvent(aIsTrusted, aMessage, aWidget, eCompositionEventClass)
     , 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
   {
     MOZ_ASSERT(mClass == eCompositionEventClass,
                "Duplicate() must be overridden by sub class");
     // Not copying widget, it is a weak reference.
     WidgetCompositionEvent* result =
@@ -849,24 +845,16 @@ public:
     return this;
   }
 
   InternalEditorInputEvent(bool aIsTrusted, EventMessage aMessage,
                            nsIWidget* aWidget)
     : 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
   {
     MOZ_ASSERT(mClass == eEditorInputEventClass,
                "Duplicate() must be overridden by sub class");
     // Not copying widget, it is a weak reference.
     InternalEditorInputEvent* result =