2007-01-01 Eric Seidel <eric@eseidel.com>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Jan 2007 17:53:40 +0000 (17:53 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Jan 2007 17:53:40 +0000 (17:53 +0000)
        Reviewed by mitz.

        More clean-up to animation code.

        * ksvg2/svg/SVGAnimateColorElement.cpp:
        (WebCore::SVGAnimateColorElement::handleTimerEvent):
        * ksvg2/svg/SVGAnimateTransformElement.cpp:
        (WebCore::SVGAnimateTransformElement::handleTimerEvent):
        (WebCore::SVGAnimateTransformElement::parseTransformValue):
        (WebCore::SVGAnimateTransformElement::calculateRotationFromMatrix):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@18503 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/ksvg2/svg/SVGAnimateColorElement.cpp
WebCore/ksvg2/svg/SVGAnimateTransformElement.cpp

index 5b45002..5576ff2 100644 (file)
@@ -1,3 +1,16 @@
+2007-01-01  Eric Seidel  <eric@eseidel.com>
+
+        Reviewed by mitz.
+
+        More clean-up to animation code.
+
+        * ksvg2/svg/SVGAnimateColorElement.cpp:
+        (WebCore::SVGAnimateColorElement::handleTimerEvent):
+        * ksvg2/svg/SVGAnimateTransformElement.cpp:
+        (WebCore::SVGAnimateTransformElement::handleTimerEvent):
+        (WebCore::SVGAnimateTransformElement::parseTransformValue):
+        (WebCore::SVGAnimateTransformElement::calculateRotationFromMatrix):
+
 2007-01-01  Eric Seidel  <eric@webkit.org>
 
         Reviewed by olliej.
index ba3ddf9..5b122b5 100644 (file)
@@ -61,66 +61,36 @@ void SVGAnimateColorElement::handleTimerEvent(double timePercentage)
     // Start condition.
     if (!m_connected) {
         // Save initial color... (needed for fill="remove" or additve="sum")
-        RefPtr<SVGColor> temp = new SVGColor();
-        temp->setRGBColor(targetAttribute());
+        RefPtr<SVGColor> initialColor = new SVGColor();
+        initialColor->setRGBColor(targetAttribute());
 
-        m_initialColor = temp->color();
+        m_initialColor = initialColor->color();
 
-        // Animation mode handling
         switch (detectAnimationMode()) {
             case TO_ANIMATION:
             case FROM_TO_ANIMATION:
             {
-                String toColorString(m_to);
-                m_toColor->setRGBColor(toColorString);
-    
-                String fromColorString;
+                m_toColor->setRGBColor(m_to);
                 if (!m_from.isEmpty()) // from-to animation
-                    fromColorString = m_from;
+                    m_fromColor->setRGBColor(m_from);
                 else // to animation
-                    fromColorString = m_initialColor.name();
-    
-                m_fromColor->setRGBColor(fromColorString);    
-
-                // Calculate color differences, once.
-                Color qTo = m_toColor->color();
-                Color qFrom = m_fromColor->color();
+                    m_fromColor->setRGBColor(m_initialColor.name());
     
-                m_redDiff = qTo.red() - qFrom.red();
-                m_greenDiff = qTo.green() - qFrom.green();
-                m_blueDiff = qTo.blue() - qFrom.blue();
-                
+                calculateColorDifference(m_toColor->color(), m_fromColor->color(), m_redDiff, m_greenDiff, m_blueDiff);
                 break;
             }
             case BY_ANIMATION:
             case FROM_BY_ANIMATION:
             {
-                String byColorString(m_by);
-                m_toColor->setRGBColor(byColorString);
-
-                String fromColorString;
-            
                 if (!m_from.isEmpty()) // from-by animation
-                    fromColorString = m_from;
+                    m_fromColor->setRGBColor(m_from);
                 else // by animation
-                    fromColorString = m_initialColor.name();
-
-                m_fromColor->setRGBColor(fromColorString);
-
-                Color qBy = m_toColor->color();
-                Color qFrom = m_fromColor->color();
-
-                // Calculate 'm_toColor' using relative values
-                int r = qFrom.red() + qBy.red();
-                int g = qFrom.green() + qBy.green();
-                int b = qFrom.blue() + qBy.blue();
-
-                Color qTo = clampColor(r, g, b);
-            
-                String toColorString(qTo.name());
-                m_toColor->setRGBColor(toColorString);
+                    m_fromColor->setRGBColor(m_initialColor.name());
+                
+                m_toColor->setRGBColor(m_by);
+                m_toColor->setRGBColor(addColorsAndClamp(m_fromColor->color(), m_toColor->color()).name());
                 
-                calculateColorDifference(qTo, qFrom, m_redDiff, m_greenDiff, m_blueDiff);
+                calculateColorDifference(m_toColor->color(), m_fromColor->color(), m_redDiff, m_greenDiff, m_blueDiff);
                 break;
             }
             case VALUES_ANIMATION:
index 24118fd..228e75d 100644 (file)
@@ -83,7 +83,7 @@ void SVGAnimateTransformElement::handleTimerEvent(double timePercentage)
             if (transformList) {
                 ExceptionCode ec = 0;
                 for (unsigned long i = 0; i < transformList->numberOfItems(); i++) {
-                    SVGTransform* value = transformList->getItem(i, ec).get();;
+                    SVGTransform* value = transformList->getItem(i, ec).get();
                     if (!value)
                         continue;
                         
@@ -242,19 +242,11 @@ void SVGAnimateTransformElement::handleTimerEvent(double timePercentage)
             calculateRotationFromMatrix(qToMatrix, toAngle, toCx, toCy);
             calculateRotationFromMatrix(qFromMatrix, fromAngle, fromCx, fromCy);
 
-            if (m_toRotateSpecialCase) {
-                if (lround(toAngle) == 1)
-                    toAngle = 0.0;
-                else
-                    toAngle = 360.0;
-            }
+            if (m_toRotateSpecialCase)
+                toAngle = (lround(toAngle) == 1) ? 0.0 : 360.0;
 
-            if (m_fromRotateSpecialCase) {
-                if (lround(fromAngle) == 1)
-                    fromAngle = 0.0;
-                else
-                    fromAngle = 360.0;
-            }
+            if (m_fromRotateSpecialCase)
+                fromAngle = (lround(fromAngle) == 1) ? 0.0 : 360.0;
                     
             double angle = ((toAngle - fromAngle) * useTimePercentage) + fromAngle;
             double cx = (toCx - fromCx) * useTimePercentage + fromCx;
@@ -286,10 +278,8 @@ void SVGAnimateTransformElement::handleTimerEvent(double timePercentage)
     }
 
     // End condition.
-    if (timePercentage == 1.0)
-    {
-        if ((m_repeatCount > 0 && m_repeations < m_repeatCount - 1) || isIndefinite(m_repeatCount))
-        {
+    if (timePercentage == 1.0) {
+        if ((m_repeatCount > 0 && m_repeations < m_repeatCount - 1) || isIndefinite(m_repeatCount)) {
             m_lastMatrix.reset();
 
             if (!m_transformMatrix.isIdentity())
@@ -331,7 +321,7 @@ void SVGAnimateTransformElement::applyAnimationToValue(SVGTransformList* targetT
 
 RefPtr<SVGTransform> SVGAnimateTransformElement::parseTransformValue(const String& data) const
 {
-    DeprecatedString parse = data.deprecatedString().stripWhiteSpace();
+    String parse = data.stripWhiteSpace();
     if (parse.isEmpty())
         return 0;
     
@@ -344,20 +334,20 @@ RefPtr<SVGTransform> SVGAnimateTransformElement::parseTransformValue(const Strin
         {
             double tx = 0.0, ty = 0.0;
             if (commaPos != - 1) {
-                tx = parse.mid(0, commaPos).toDouble();
-                ty = parse.mid(commaPos + 1).toDouble();
+                tx = parse.substring(0, commaPos).toDouble();
+                ty = parse.substring(commaPos + 1).toDouble();
             } else 
                 tx = parse.toDouble();
 
             parsedTransform->setTranslate(tx, ty);
-            break;    
+            break;
         }
         case SVGTransform::SVG_TRANSFORM_SCALE:
         {
             double sx = 1.0, sy = 1.0;
             if (commaPos != - 1) {
-                sx = parse.mid(0, commaPos).toDouble();
-                sy = parse.mid(commaPos + 1).toDouble();
+                sx = parse.substring(0, commaPos).toDouble();
+                sy = parse.substring(commaPos + 1).toDouble();
             } else {
                 sx = parse.toDouble();
                 sy = sx;
@@ -370,12 +360,12 @@ RefPtr<SVGTransform> SVGAnimateTransformElement::parseTransformValue(const Strin
         {
             double angle = 0, cx = 0, cy = 0;
             if (commaPos != - 1) {
-                angle = parse.mid(0, commaPos).toDouble(); // TODO: probably needs it's own 'angle' parser
+                angle = parse.substring(0, commaPos).toDouble(); // TODO: probably needs it's own 'angle' parser
     
                 int commaPosTwo = parse.find(',', commaPos + 1); // In case three values are passed...
                 if (commaPosTwo != -1) {
-                    cx = parse.mid(commaPos + 1, commaPosTwo - commaPos - 1).toDouble();
-                    cy = parse.mid(commaPosTwo + 1).toDouble();
+                    cx = parse.substring(commaPos + 1, commaPosTwo - commaPos - 1).toDouble();
+                    cy = parse.substring(commaPosTwo + 1).toDouble();
                 }
             }
             else 
@@ -423,8 +413,7 @@ void SVGAnimateTransformElement::calculateRotationFromMatrix(const AffineTransfo
     double cosa = matrix.a();
     double sina = -matrix.c();
 
-    if (cosa != 1.0)
-    {
+    if (cosa != 1.0) {
         // Calculate the angle via magic ;)
         double temp = SVGAngle::todeg(asin(sina));
         angle = SVGAngle::todeg(acos(cosa));