Bug 1045978 Create InternalSVGZoomEvent class and InternalSMILTimeEvent class r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 31 Jul 2014 02:16:57 +0900
changeset 218511 917b5e49c7f4c9bef65214ff140dedf0db7381a5
parent 218510 aef0101ff775f84afd261825a6c6b7b92055e858
child 218512 477ba7091557c5b16aa19bf57c38c59aa87f85fa
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1045978
milestone34.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 1045978 Create InternalSVGZoomEvent class and InternalSMILTimeEvent class r=smaug
content/svg/content/src/SVGSVGElement.cpp
content/svg/content/src/SVGZoomEvent.cpp
content/svg/content/src/SVGZoomEvent.h
dom/events/EventDispatcher.cpp
dom/interfaces/events/nsIDOMEvent.idl
dom/smil/TimeEvent.cpp
dom/smil/TimeEvent.h
dom/smil/nsSMILTimedElement.cpp
widget/BasicEvents.h
widget/ContentEvents.h
widget/EventClassList.h
--- a/content/svg/content/src/SVGSVGElement.cpp
+++ b/content/svg/content/src/SVGSVGElement.cpp
@@ -1,16 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 <stdint.h>
 #include "mozilla/ArrayUtils.h"
-#include "mozilla/BasicEvents.h"
+#include "mozilla/ContentEvents.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/Likely.h"
 
 #include "nsGkAtoms.h"
 #include "nsLayoutUtils.h"
 #include "nsLayoutStylesheetCache.h"
 #include "DOMSVGNumber.h"
 #include "DOMSVGLength.h"
@@ -513,21 +513,24 @@ SVGSVGElement::SetCurrentScaleTranslate(
   mCurrentScale = s;
   mCurrentTranslate = SVGPoint(x, y);
 
   // now dispatch the appropriate event if we are the root element
   nsIDocument* doc = GetCurrentDoc();
   if (doc) {
     nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
     if (presShell && IsRoot()) {
-      bool scaling = (mPreviousScale != mCurrentScale);
       nsEventStatus status = nsEventStatus_eIgnore;
-      WidgetGUIEvent event(true, scaling ? NS_SVG_ZOOM : NS_SVG_SCROLL, 0);
-      event.eventStructType = scaling ? NS_SVGZOOM_EVENT : NS_EVENT;
-      presShell->HandleDOMEventWithTarget(this, &event, &status);
+      if (mPreviousScale != mCurrentScale) {
+        InternalSVGZoomEvent svgZoomEvent(true, NS_SVG_ZOOM);
+        presShell->HandleDOMEventWithTarget(this, &svgZoomEvent, &status);
+      } else {
+        WidgetEvent svgScrollEvent(true, NS_SVG_SCROLL);
+        presShell->HandleDOMEventWithTarget(this, &svgScrollEvent, &status);
+      }
       InvalidateTransformNotifyFrame();
     }
   }
 }
 
 void
 SVGSVGElement::SetCurrentTranslate(float x, float y)
 {
--- a/content/svg/content/src/SVGZoomEvent.cpp
+++ b/content/svg/content/src/SVGZoomEvent.cpp
@@ -1,19 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/SVGZoomEvent.h"
 #include "DOMSVGPoint.h"
+#include "mozilla/ContentEvents.h"
+#include "mozilla/dom/Element.h"
 #include "mozilla/dom/SVGSVGElement.h"
-#include "nsIPresShell.h"
+#include "mozilla/dom/SVGZoomEvent.h"
 #include "nsIDocument.h"
-#include "mozilla/dom/Element.h"
+#include "nsIPresShell.h"
 #include "prtime.h"
 
 namespace mozilla {
 namespace dom {
 
 //----------------------------------------------------------------------
 // Implementation
 
@@ -22,33 +23,30 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGZo
 NS_IMPL_ADDREF_INHERITED(SVGZoomEvent, UIEvent)
 NS_IMPL_RELEASE_INHERITED(SVGZoomEvent, UIEvent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGZoomEvent)
 NS_INTERFACE_MAP_END_INHERITING(UIEvent)
 
 SVGZoomEvent::SVGZoomEvent(EventTarget* aOwner,
                            nsPresContext* aPresContext,
-                           WidgetGUIEvent* aEvent)
+                           InternalSVGZoomEvent* aEvent)
   : UIEvent(aOwner, aPresContext,
-            aEvent ? aEvent : new WidgetGUIEvent(false, NS_SVG_ZOOM, 0))
+            aEvent ? aEvent : new InternalSVGZoomEvent(false, NS_SVG_ZOOM))
   , mPreviousScale(0)
   , mNewScale(0)
 {
   if (aEvent) {
     mEventIsInternal = false;
   }
   else {
     mEventIsInternal = true;
-    mEvent->eventStructType = NS_SVGZOOM_EVENT;
     mEvent->time = PR_Now();
   }
 
-  mEvent->mFlags.mCancelable = false;
-
   // We must store the "Previous" and "New" values before this event is
   // dispatched. Reading the values from the root 'svg' element after we've
   // been dispatched is not an option since event handler code may change
   // currentScale and currentTranslate in response to this event.
   nsIPresShell *presShell;
   if (mPresContext && (presShell = mPresContext->GetPresShell())) {
     nsIDocument *doc = presShell->GetDocument();
     if (doc) {
@@ -90,14 +88,14 @@ SVGZoomEvent::~SVGZoomEvent()
 
 ////////////////////////////////////////////////////////////////////////
 // Exported creation functions:
 
 nsresult
 NS_NewDOMSVGZoomEvent(nsIDOMEvent** aInstancePtrResult,
                       mozilla::dom::EventTarget* aOwner,
                       nsPresContext* aPresContext,
-                      mozilla::WidgetGUIEvent* aEvent)
+                      mozilla::InternalSVGZoomEvent* aEvent)
 {
   mozilla::dom::SVGZoomEvent* it =
     new mozilla::dom::SVGZoomEvent(aOwner, aPresContext, aEvent);
   return CallQueryInterface(it, aInstancePtrResult);
 }
--- a/content/svg/content/src/SVGZoomEvent.h
+++ b/content/svg/content/src/SVGZoomEvent.h
@@ -23,17 +23,17 @@ namespace dom {
 class SVGZoomEvent MOZ_FINAL : public UIEvent
 {
 public:
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGZoomEvent, UIEvent)
   NS_DECL_ISUPPORTS_INHERITED
 
   SVGZoomEvent(EventTarget* aOwner, nsPresContext* aPresContext,
-               WidgetGUIEvent* aEvent);
+               InternalSVGZoomEvent* aEvent);
 
   // Forward to base class
   NS_FORWARD_TO_UIEVENT
 
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
   {
     return SVGZoomEventBinding::Wrap(aCx, this);
   }
--- a/dom/events/EventDispatcher.cpp
+++ b/dom/events/EventDispatcher.cpp
@@ -724,20 +724,20 @@ EventDispatcher::CreateEvent(EventTarget
     case NS_TEXT_EVENT:
       return NS_NewDOMUIEvent(aDOMEvent, aOwner, aPresContext,
                               aEvent->AsTextEvent());
     case NS_CLIPBOARD_EVENT:
       return NS_NewDOMClipboardEvent(aDOMEvent, aOwner, aPresContext,
                                      aEvent->AsClipboardEvent());
     case NS_SVGZOOM_EVENT:
       return NS_NewDOMSVGZoomEvent(aDOMEvent, aOwner, aPresContext,
-                                   aEvent->AsGUIEvent());
+                                   aEvent->AsSVGZoomEvent());
     case NS_SMIL_TIME_EVENT:
-      return NS_NewDOMTimeEvent(aDOMEvent, aOwner, aPresContext, aEvent);
-
+      return NS_NewDOMTimeEvent(aDOMEvent, aOwner, aPresContext,
+                                aEvent->AsSMILTimeEvent());
     case NS_COMMAND_EVENT:
       return NS_NewDOMCommandEvent(aDOMEvent, aOwner, aPresContext,
                                    aEvent->AsCommandEvent());
     case NS_SIMPLE_GESTURE_EVENT:
       return NS_NewDOMSimpleGestureEvent(aDOMEvent, aOwner, aPresContext,
                                          aEvent->AsSimpleGestureEvent());
     case NS_POINTER_EVENT:
       return NS_NewDOMPointerEvent(aDOMEvent, aOwner, aPresContext,
--- a/dom/interfaces/events/nsIDOMEvent.idl
+++ b/dom/interfaces/events/nsIDOMEvent.idl
@@ -301,22 +301,22 @@ nsresult
 NS_NewDOMSVGEvent(nsIDOMEvent** aResult,
                   mozilla::dom::EventTarget* aOwner,
                   nsPresContext* aPresContext,
                   mozilla::WidgetEvent* aEvent);
 nsresult
 NS_NewDOMSVGZoomEvent(nsIDOMEvent** aResult,
                       mozilla::dom::EventTarget* aOwner,
                       nsPresContext* aPresContext,
-                      mozilla::WidgetGUIEvent* aEvent);
+                      mozilla::InternalSVGZoomEvent* aEvent);
 nsresult
 NS_NewDOMTimeEvent(nsIDOMEvent** aResult,
                    mozilla::dom::EventTarget* aOwner,
                    nsPresContext* aPresContext,
-                   mozilla::WidgetEvent* aEvent);
+                   mozilla::InternalSMILTimeEvent* aEvent);
 nsresult
 NS_NewDOMXULCommandEvent(nsIDOMEvent** aResult,
                          mozilla::dom::EventTarget* aOwner,
                          nsPresContext* aPresContext,
                          mozilla::WidgetInputEvent* aEvent);
 nsresult
 NS_NewDOMCommandEvent(nsIDOMEvent** aInstancePtrResult,
                       mozilla::dom::EventTarget* aOwner,
--- a/dom/smil/TimeEvent.cpp
+++ b/dom/smil/TimeEvent.cpp
@@ -1,44 +1,36 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/ContentEvents.h"
 #include "mozilla/dom/TimeEvent.h"
-#include "mozilla/BasicEvents.h"
 #include "nsIDocShell.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsPresContext.h"
 
 namespace mozilla {
 namespace dom {
 
 TimeEvent::TimeEvent(EventTarget* aOwner,
                      nsPresContext* aPresContext,
-                     WidgetEvent* aEvent)
+                     InternalSMILTimeEvent* aEvent)
   : Event(aOwner, aPresContext,
-          aEvent ? aEvent : new InternalUIEvent(false, 0))
-  , mDetail(0)
+          aEvent ? aEvent : new InternalSMILTimeEvent(false, 0))
+  , mDetail(mEvent->AsSMILTimeEvent()->detail)
 {
   SetIsDOMBinding();
   if (aEvent) {
     mEventIsInternal = false;
   } else {
     mEventIsInternal = true;
-    mEvent->eventStructType = NS_SMIL_TIME_EVENT;
   }
 
-  if (mEvent->eventStructType == NS_SMIL_TIME_EVENT) {
-    mDetail = mEvent->AsUIEvent()->detail;
-  }
-
-  mEvent->mFlags.mBubbles = false;
-  mEvent->mFlags.mCancelable = false;
-
   if (mPresContext) {
     nsCOMPtr<nsIDocShell> docShell = mPresContext->GetDocShell();
     if (docShell) {
       mView = docShell->GetWindow();
     }
   }
 }
 
@@ -87,15 +79,15 @@ TimeEvent::InitTimeEvent(const nsAString
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsresult
 NS_NewDOMTimeEvent(nsIDOMEvent** aInstancePtrResult,
                    EventTarget* aOwner,
                    nsPresContext* aPresContext,
-                   WidgetEvent* aEvent)
+                   InternalSMILTimeEvent* aEvent)
 {
   TimeEvent* it = new TimeEvent(aOwner, aPresContext, aEvent);
   NS_ADDREF(it);
   *aInstancePtrResult = static_cast<Event*>(it);
   return NS_OK;
 }
--- a/dom/smil/TimeEvent.h
+++ b/dom/smil/TimeEvent.h
@@ -14,17 +14,17 @@ namespace mozilla {
 namespace dom {
 
 class TimeEvent MOZ_FINAL : public Event,
                             public nsIDOMTimeEvent
 {
 public:
   TimeEvent(EventTarget* aOwner,
             nsPresContext* aPresContext,
-            WidgetEvent* aEvent);
+            InternalSMILTimeEvent* aEvent);
 
   // nsISupports interface:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TimeEvent, Event)
 
   // nsIDOMTimeEvent interface:
   NS_DECL_NSIDOMTIMEEVENT
 
--- a/dom/smil/nsSMILTimedElement.cpp
+++ b/dom/smil/nsSMILTimedElement.cpp
@@ -1,16 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/DebugOnly.h"
 
-#include "mozilla/BasicEvents.h"
+#include "mozilla/ContentEvents.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/dom/SVGAnimationElement.h"
 #include "nsSMILTimedElement.h"
 #include "nsAttrValueInlines.h"
 #include "nsSMILAnimationFunction.h"
 #include "nsSMILTimeValue.h"
 #include "nsSMILTimeValueSpec.h"
 #include "nsSMILInstanceTime.h"
@@ -87,18 +87,17 @@ namespace
   public:
     AsyncTimeEventRunner(nsIContent* aTarget, uint32_t aMsg, int32_t aDetail)
       : mTarget(aTarget), mMsg(aMsg), mDetail(aDetail)
     {
     }
 
     NS_IMETHOD Run()
     {
-      InternalUIEvent event(true, mMsg);
-      event.eventStructType = NS_SMIL_TIME_EVENT;
+      InternalSMILTimeEvent event(true, mMsg);
       event.detail = mDetail;
 
       nsPresContext* context = nullptr;
       nsIDocument* doc = mTarget->GetCurrentDoc();
       if (doc) {
         nsCOMPtr<nsIPresShell> shell = doc->GetShell();
         if (shell) {
           context = shell->GetPresContext();
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -53,30 +53,26 @@ enum nsEventStructType
   // ContentEvents.h
   NS_SCROLLPORT_EVENT,               // InternalScrollPortEvent
   NS_SCROLLAREA_EVENT,               // InternalScrollAreaEvent
   NS_FORM_EVENT,                     // InternalFormEvent
   NS_FOCUS_EVENT,                    // InternalFocusEvent
   NS_CLIPBOARD_EVENT,                // InternalClipboardEvent
   NS_TRANSITION_EVENT,               // InternalTransitionEvent
   NS_ANIMATION_EVENT,                // InternalAnimationEvent
+  NS_SVGZOOM_EVENT,                  // InternalSVGZoomEvent
+  NS_SMIL_TIME_EVENT,                // InternalSMILTimeEvent
 
   // MiscEvents.h
   NS_COMMAND_EVENT,                  // WidgetCommandEvent
   NS_CONTENT_COMMAND_EVENT,          // WidgetContentCommandEvent
   NS_PLUGIN_EVENT,                   // WidgetPluginEvent
 
   // InternalMutationEvent.h (dom/events)
-  NS_MUTATION_EVENT,                 // InternalMutationEvent
-
-  // Follwoing struct type values are ugly.  They indicate other struct type
-  // actually.  However, they are used for distinguishing which DOM event
-  // should be created for the event.
-  NS_SVGZOOM_EVENT,                  // WidgetGUIEvent
-  NS_SMIL_TIME_EVENT                 // InternalUIEvent
+  NS_MUTATION_EVENT                  // InternalMutationEvent
 };
 
 /******************************************************************************
  * Messages
  *
  * TODO: Make them enum.
  ******************************************************************************/
 
@@ -857,18 +853,17 @@ public:
   WidgetGUIEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
     WidgetEvent(aIsTrusted, aMessage, NS_GUI_EVENT),
     widget(aWidget)
   {
   }
 
   virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   {
-    MOZ_ASSERT(eventStructType == NS_GUI_EVENT ||
-                 eventStructType == NS_SVGZOOM_EVENT,
+    MOZ_ASSERT(eventStructType == NS_GUI_EVENT,
                "Duplicate() must be overridden by sub class");
     // Not copying widget, it is a weak reference.
     WidgetGUIEvent* result = new WidgetGUIEvent(false, message, nullptr);
     result->AssignGUIEventData(*this, true);
     result->mFlags = mFlags;
     return result;
   }
 
@@ -1170,18 +1165,17 @@ public:
   InternalUIEvent(bool aIsTrusted, uint32_t aMessage)
     : WidgetGUIEvent(aIsTrusted, aMessage, nullptr, NS_UI_EVENT)
     , detail(0)
   {
   }
 
   virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   {
-    MOZ_ASSERT(eventStructType == NS_UI_EVENT ||
-                 eventStructType == NS_SMIL_TIME_EVENT,
+    MOZ_ASSERT(eventStructType == NS_UI_EVENT,
                "Duplicate() must be overridden by sub class");
     InternalUIEvent* result = new InternalUIEvent(false, message);
     result->AssignUIEventData(*this, true);
     result->mFlags = mFlags;
     return result;
   }
 
   int32_t detail;
--- a/widget/ContentEvents.h
+++ b/widget/ContentEvents.h
@@ -310,11 +310,81 @@ public:
     AssignEventData(aEvent, aCopyTargets);
 
     animationName = aEvent.animationName;
     elapsedTime = aEvent.elapsedTime;
     pseudoElement = aEvent.pseudoElement;
   }
 };
 
+/******************************************************************************
+ * mozilla::InternalSVGZoomEvent
+ ******************************************************************************/
+
+class InternalSVGZoomEvent : public WidgetGUIEvent
+{
+public:
+  virtual InternalSVGZoomEvent* AsSVGZoomEvent() MOZ_OVERRIDE { return this; }
+
+  InternalSVGZoomEvent(bool aIsTrusted, uint32_t aMessage) :
+    WidgetGUIEvent(aIsTrusted, aMessage, nullptr, NS_SVGZOOM_EVENT)
+  {
+    mFlags.mCancelable = false;
+  }
+
+  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
+  {
+    MOZ_ASSERT(eventStructType == NS_SVGZOOM_EVENT,
+               "Duplicate() must be overridden by sub class");
+    // Not copying widget, it is a weak reference.
+    InternalSVGZoomEvent* result = new InternalSVGZoomEvent(false, message);
+    result->AssignSVGZoomEventData(*this, true);
+    result->mFlags = mFlags;
+    return result;
+  }
+
+  void AssignSVGZoomEventData(const InternalSVGZoomEvent& aEvent,
+                              bool aCopyTargets)
+  {
+    AssignGUIEventData(aEvent, aCopyTargets);
+  }
+};
+
+/******************************************************************************
+ * mozilla::InternalSMILTimeEvent
+ ******************************************************************************/
+
+class InternalSMILTimeEvent : public InternalUIEvent
+{
+public:
+  virtual InternalSMILTimeEvent* AsSMILTimeEvent() MOZ_OVERRIDE
+  {
+    return this;
+  }
+
+  InternalSMILTimeEvent(bool aIsTrusted, uint32_t aMessage) :
+    InternalUIEvent(aIsTrusted, aMessage, NS_SMIL_TIME_EVENT)
+  {
+    mFlags.mBubbles = false;
+    mFlags.mCancelable = false;
+  }
+
+  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
+  {
+    MOZ_ASSERT(eventStructType == NS_SMIL_TIME_EVENT,
+               "Duplicate() must be overridden by sub class");
+    InternalSMILTimeEvent* result = new InternalSMILTimeEvent(false, message);
+    result->AssignSMILTimeEventData(*this, true);
+    result->mFlags = mFlags;
+    return result;
+  }
+
+  void AssignSMILTimeEventData(const InternalSMILTimeEvent& aEvent,
+                               bool aCopyTargets)
+  {
+    AssignUIEventData(aEvent, aCopyTargets);
+  }
+};
+
+
 } // namespace mozilla
 
 #endif // mozilla_ContentEvents_h__
--- a/widget/EventClassList.h
+++ b/widget/EventClassList.h
@@ -44,16 +44,18 @@ NS_EVENT_CLASS(Widget, TouchEvent)
 // ContentEvents.h
 NS_EVENT_CLASS(Internal, ScrollPortEvent)
 NS_EVENT_CLASS(Internal, ScrollAreaEvent)
 NS_EVENT_CLASS(Internal, FormEvent)
 NS_EVENT_CLASS(Internal, ClipboardEvent)
 NS_EVENT_CLASS(Internal, FocusEvent)
 NS_EVENT_CLASS(Internal, TransitionEvent)
 NS_EVENT_CLASS(Internal, AnimationEvent)
+NS_EVENT_CLASS(Internal, SVGZoomEvent)
+NS_EVENT_CLASS(Internal, SMILTimeEvent)
 
 // MiscEvents.h
 NS_EVENT_CLASS(Widget, CommandEvent)
 NS_EVENT_CLASS(Widget, ContentCommandEvent)
 NS_EVENT_CLASS(Widget, PluginEvent)
 
 // InternalMutationEvent.h (dom/events)
 NS_EVENT_CLASS(Internal, MutationEvent)