Bug 683040: Override new method IsToAnimation instead of old method TreatSingleValueAsStatic, to handle "to animation" for animateMotion. r=birtles
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 06 Sep 2011 16:50:49 -0700
changeset 77935 12507ee12f19167560ed7ea655fe3cea47e4aee4
parent 77934 bc627f4c6daa981a61c77885b14cfa0b819827be
child 77936 3ae9b2a742df99f77c0f978eeb35f308088bcceb
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs683040
milestone9.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 683040: Override new method IsToAnimation instead of old method TreatSingleValueAsStatic, to handle "to animation" for animateMotion. r=birtles
content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
content/svg/content/src/SVGMotionSMILAnimationFunction.h
layout/reftests/svg/smil/motion/animateMotion-to-overridden-1.svg
layout/reftests/svg/smil/motion/reftest.list
--- a/content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
+++ b/content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
@@ -378,16 +378,28 @@ SVGMotionSMILAnimationFunction::
 {
   // Call superclass method.
   nsSMILAnimationFunction::CheckValueListDependentAttrs(aNumValues);
 
   // Added behavior: Do checks specific to keyPoints.
   CheckKeyPoints();
 }
 
+PRBool
+SVGMotionSMILAnimationFunction::IsToAnimation() const
+{
+  // Rely on inherited method, but not if we have an <mpath> child or a |path|
+  // attribute, because they'll override any 'to' attr we might have.
+  // NOTE: We can't rely on mPathSourceType, because it might not have been
+  // set to a useful value yet (or it might be stale).
+  return !GetFirstMpathChild(&mAnimationElement->AsElement()) &&
+    !HasAttr(nsGkAtoms::path) &&
+    nsSMILAnimationFunction::IsToAnimation();
+}
+
 void
 SVGMotionSMILAnimationFunction::CheckKeyPoints()
 {
   if (!HasAttr(nsGkAtoms::keyPoints))
     return;
 
   // attribute is ignored for calcMode="paced" (even if it's got errors)
   if (GetCalcMode() == CALC_PACED) {
@@ -480,20 +492,9 @@ SVGMotionSMILAnimationFunction::SetRotat
 void
 SVGMotionSMILAnimationFunction::UnsetRotate()
 {
   mRotateAngle = 0.0f; // default value
   mRotateType = eRotateType_Explicit;
   mHasChanged = PR_TRUE;
 }
 
-PRBool
-SVGMotionSMILAnimationFunction::TreatSingleValueAsStatic() const
-{
-  // <animateMotion> has two more ways that we could be just sampling a single
-  // value -- via path attribute and the <mpath> element, with a path
-  // description that just includes a single "move" command.
-  return (mPathSourceType == ePathSourceType_ValuesAttr ||
-          mPathSourceType == ePathSourceType_PathAttr ||
-          mPathSourceType == ePathSourceType_Mpath);
-}
-
 } // namespace mozilla
--- a/content/svg/content/src/SVGMotionSMILAnimationFunction.h
+++ b/content/svg/content/src/SVGMotionSMILAnimationFunction.h
@@ -80,17 +80,18 @@ protected:
     ePathSourceType_PathAttr,
     ePathSourceType_Mpath
   };
 
   NS_OVERRIDE virtual nsSMILCalcMode GetCalcMode() const;
   NS_OVERRIDE virtual nsresult GetValues(const nsISMILAttr& aSMILAttr,
                                          nsSMILValueArray& aResult);
   NS_OVERRIDE virtual void CheckValueListDependentAttrs(PRUint32 aNumValues);
-  NS_OVERRIDE virtual PRBool TreatSingleValueAsStatic() const;
+
+  NS_OVERRIDE virtual PRBool IsToAnimation() const;
 
   void     CheckKeyPoints();
   nsresult SetKeyPoints(const nsAString& aKeyPoints, nsAttrValue& aResult);
   void     UnsetKeyPoints();
   nsresult SetRotate(const nsAString& aRotate, nsAttrValue& aResult);
   void     UnsetRotate();
 
   // Helpers for GetValues
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/smil/motion/animateMotion-to-overridden-1.svg
@@ -0,0 +1,61 @@
+<svg xmlns="http://www.w3.org/2000/svg"
+     xmlns:xlink="http://www.w3.org/1999/xlink"
+     class="reftest-wait">
+  <script xlink:href="../smil-util.js" type="text/javascript"/>
+  <script type="text/javascript">
+    function doTest() {
+      setTimeAndSnapshot(1, true);
+    }
+    window.addEventListener("MozReftestInvalidate", doTest, false);
+  </script>
+
+  <!-- Big green background to match lime.svg -->
+  <rect fill="lime" width="100%" height="100%" />
+
+  <!-- In the following pairs of rects, the only pairwise differences are the
+       fill-color and the presence of the "to" attribute on the animateMotion
+       element.  "to" shouldn't have any effect in these cases, since it has
+       lower priority than "values," "path," and "mpath". So in each case, the
+       lime rect should cover up the red rect at all times. -->
+
+  <!-- Single-point path specified with "values" attribute: -->
+  <g transform="translate(0,0)">
+    <rect width="20" height="20" fill="red">
+      <animateMotion values="20,0" dur="2"/>
+    </rect>
+    <rect width="20" height="20" fill="lime">
+      <animateMotion values="20,0" dur="2" to="-50,0"/>
+    </rect>
+  </g>
+
+  <!-- Multi-point path specified with "values" attribute: -->
+  <g transform="translate(0,30)">
+    <rect width="20" height="20" fill="red">
+      <animateMotion values="20,0; 80,0" dur="2"/>
+    </rect>
+    <rect width="20" height="20" fill="lime">
+      <animateMotion values="20,0; 80,0" dur="2" to="-50,0"/>
+    </rect>
+  </g>
+
+  <!-- Path specified with "path" attribute: -->
+  <g transform="translate(0,60)">
+    <rect width="20" height="20" fill="red">
+      <animateMotion path="m0,0 h100" dur="2"/>
+    </rect>
+    <rect width="20" height="20" fill="lime">
+      <animateMotion path="m0,0 h100" dur="2" to="-50,0"/>
+    </rect>
+  </g>
+
+  <!-- Path specified with "mpath" subelement: -->
+  <path id="p" d="m0,0 h100"/>
+  <g transform="translate(0,90)">
+    <rect width="20" height="20" fill="red">
+      <animateMotion dur="2"><mpath xlink:href="#p"/></animateMotion>
+    </rect>
+    <rect width="20" height="20" fill="lime">
+      <animateMotion dur="2" to="-50,0"><mpath xlink:href="#p"/></animateMotion>
+    </rect>
+  </g>
+</svg>
--- a/layout/reftests/svg/smil/motion/reftest.list
+++ b/layout/reftests/svg/smil/motion/reftest.list
@@ -1,16 +1,17 @@
 # Tests related to SVG Animation (using SMIL), focusing on the animateMotion
 # element.
 
 == animateMotion-by-1.svg      lime.svg
 == animateMotion-from-to-1.svg lime.svg
 == animateMotion-rotate-1a.svg lime.svg
 == animateMotion-rotate-1b.svg lime.svg
 == animateMotion-rotate-2.svg  lime.svg
+== animateMotion-to-overridden-1.svg lime.svg
 == animateMotion-values-linear-1.svg animateMotion-values-linear-1-ref.svg
 == animateMotion-values-paced-1a.svg animateMotion-values-paced-1-ref.svg
 == animateMotion-values-paced-1b.svg animateMotion-values-paced-1-ref.svg
 
 # Tests involving <mpath> sub-element
 == animateMotion-mpath-pathLength-1.svg lime.svg
 == animateMotion-mpath-targetChange-1.svg lime.svg
 == animateMotion-mpath-target-transform-1.svg lime.svg