Bug 589556. Make SVGMotionSMILPathUtils::PathGenerator use SVGLength, not nsSVGLength2. r=longsonr, a=roc.
authorJonathan Watt <jwatt@jwatt.org>
Sat, 04 Dec 2010 12:26:45 +0000
changeset 58611 17fddebefbf055f9d98de3fbaa3c0219ee64f87e
parent 58610 3cfa2011c8318c0b92e44cc3168fb7e3139aa0a5
child 58612 4da141a1fbffea2d362a41e1b6b2a1392e855eb5
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewerslongsonr, roc
bugs589556
milestone2.0b8pre
Bug 589556. Make SVGMotionSMILPathUtils::PathGenerator use SVGLength, not nsSVGLength2. r=longsonr, a=roc.
content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
content/svg/content/src/SVGMotionSMILPathUtils.cpp
content/svg/content/src/SVGMotionSMILPathUtils.h
--- a/content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
+++ b/content/svg/content/src/SVGMotionSMILAnimationFunction.cpp
@@ -179,22 +179,18 @@ SVGMotionSMILAnimationFunction::
   NS_ABORT_IF_FALSE(mPathVertices.IsEmpty(),
                     "regenerating when we already have vertices");
 
   if (aContextElem->GetNameSpaceID() != kNameSpaceID_SVG) {
     NS_ERROR("Uh oh, SVG animateMotion element targeting a non-SVG node");
     return;
   }
 
-  // NOTE: We have to cast away constness on context node, since the
-  // nsSVGLength2 methods that need it for unit-conversion
-  // (e.g. nsSVGLength2::GetBaseValue) aren't const-correct.
-  nsSVGElement* svgCtx =
-    static_cast<nsSVGElement*>(const_cast<nsIContent*>(aContextElem));
-  SVGMotionSMILPathUtils::PathGenerator pathGenerator(svgCtx);
+  SVGMotionSMILPathUtils::PathGenerator
+    pathGenerator(static_cast<const nsSVGElement*>(aContextElem));
 
   PRBool success = PR_FALSE;
   if (HasAttr(nsGkAtoms::values)) {
     // Generate path based on our values array
     mPathSourceType = ePathSourceType_ValuesAttr;
     const nsAString& valuesStr = GetAttr(nsGkAtoms::values)->GetStringValue();
     SVGMotionSMILPathUtils::MotionValueParser parser(&pathGenerator,
                                                      &mPathVertices);
--- a/content/svg/content/src/SVGMotionSMILPathUtils.cpp
+++ b/content/svg/content/src/SVGMotionSMILPathUtils.cpp
@@ -32,17 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "SVGMotionSMILPathUtils.h"
 #include "nsSVGElement.h"
-#include "nsSVGLength2.h"
+#include "SVGLength.h"
 #include "nsContentCreatorFunctions.h" // For NS_NewSVGElement
 #include "nsCharSeparatedTokenizer.h"
 
 namespace mozilla {
 
 //----------------------------------------------------------------------
 // PathGenerator methods
 
@@ -121,41 +121,40 @@ PRBool
 SVGMotionSMILPathUtils::PathGenerator::
   ParseCoordinatePair(const nsAString& aCoordPairStr,
                       float& aXVal, float& aYVal)
 {
   nsCharSeparatedTokenizer
     tokenizer(aCoordPairStr, ',',
               nsCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
 
-  nsSVGLength2 x, y;
-  nsresult rv;
+  SVGLength x, y;
 
-  if (!tokenizer.hasMoreTokens()) { // No 1st token
-    return PR_FALSE;
-  }
-  // Parse X value
-  x.Init();
-  rv = x.SetBaseValueString(tokenizer.nextToken(), nsnull, PR_FALSE);
-  if (NS_FAILED(rv) ||                // 1st token failed to parse.
-      !tokenizer.hasMoreTokens()) {   // No 2nd token.
+  if (!tokenizer.hasMoreTokens() ||
+      !x.SetValueFromString(tokenizer.nextToken())) {
     return PR_FALSE;
   }
 
-  // Parse Y value
-  y.Init();
-  rv = y.SetBaseValueString(tokenizer.nextToken(), nsnull, PR_FALSE);
-  if (NS_FAILED(rv) ||                           // 2nd token failed to parse.
-      tokenizer.lastTokenEndedWithSeparator() || // Trailing comma.
+  if (!tokenizer.hasMoreTokens() ||
+      !y.SetValueFromString(tokenizer.nextToken())) { 
+    return PR_FALSE;
+  }
+
+  if (tokenizer.lastTokenEndedWithSeparator() || // Trailing comma.
       tokenizer.hasMoreTokens()) {               // More text remains
     return PR_FALSE;
   }
 
-  aXVal = x.GetBaseValue(mSVGElement);
-  aYVal = y.GetBaseValue(mSVGElement);
+  float xRes = x.GetValueInUserUnits(mSVGElement, nsSVGUtils::X);
+  float yRes = y.GetValueInUserUnits(mSVGElement, nsSVGUtils::Y);
+
+  NS_ENSURE_FINITE2(xRes, yRes, PR_FALSE);
+
+  aXVal = xRes;
+  aYVal = yRes;
   return PR_TRUE;
 }
 
 //----------------------------------------------------------------------
 // MotionValueParser methods
 nsresult
 SVGMotionSMILPathUtils::MotionValueParser::
   Parse(const nsAString& aValueStr)
--- a/content/svg/content/src/SVGMotionSMILPathUtils.h
+++ b/content/svg/content/src/SVGMotionSMILPathUtils.h
@@ -57,17 +57,17 @@ class nsAString;
 namespace mozilla {
 
 class SVGMotionSMILPathUtils {
 public:
   // Class to assist in generating a gfxFlattenedPath, based on
   // coordinates in the <animateMotion> from/by/to/values attributes.
   class PathGenerator {
   public:
-    PathGenerator(nsSVGElement* aSVGElement)
+    PathGenerator(const nsSVGElement* aSVGElement)
       : mSVGElement(aSVGElement),
         mGfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()),
         mHaveReceivedCommands(PR_FALSE)
     {}
 
     // Methods for adding various path commands to output path.
     // Note: aCoordPairStr is expected to be a whitespace and/or
     // comma-separated x,y coordinate-pair -- see description of
@@ -86,17 +86,17 @@ public:
     already_AddRefed<gfxFlattenedPath> GetResultingPath();
 
   protected:
     // Helper methods
     PRBool ParseCoordinatePair(const nsAString& aStr,
                                float& aXVal, float& aYVal);
 
     // Member data
-    nsSVGElement* mSVGElement; // context for converting out of relative units
+    const nsSVGElement* mSVGElement; // context for converting to user units
     gfxContext    mGfxContext;
     PRPackedBool  mHaveReceivedCommands;
   };
 
   // Class to assist in passing each subcomponent of a |values| attribute to
   // a PathGenerator, for generating a corresponding gfxFlattenedPath.
   class MotionValueParser : public nsSMILParserUtils::GenericValueParser
   {