2007-01-01 Eric Seidel <eric@webkit.org>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Jan 2007 20:48:30 +0000 (20:48 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 1 Jan 2007 20:48:30 +0000 (20:48 +0000)
        Reviewed by andersca.

        Begin pushing code down into SVGAnimateElement

        * ksvg2/svg/SVGAnimateColorElement.cpp:
        (WebCore::SVGAnimateColorElement::handleStartCondition):
        * ksvg2/svg/SVGAnimateColorElement.h:
        * ksvg2/svg/SVGAnimateElement.h:
        (WebCore::SVGAnimateElement::updateCurrentValue):
        (WebCore::SVGAnimateElement::handleStartCondition):
        (WebCore::SVGAnimateElement::handleEndCondition):
        * ksvg2/svg/SVGAnimateTransformElement.cpp:
        (WebCore::SVGAnimateTransformElement::handleStartCondition):
        * ksvg2/svg/SVGAnimateTransformElement.h:
        * ksvg2/svg/SVGAnimationElement.cpp:
        (WebCore::SVGAnimationElement::handleTimerEvent):
        * ksvg2/svg/SVGAnimationElement.h:
        * ksvg2/svg/SVGSetElement.cpp:
        (WebCore::SVGSetElement::updateCurrentValue):
        (WebCore::SVGSetElement::handleStartCondition):
        (WebCore::SVGSetElement::handleEndCondition):
        * ksvg2/svg/SVGSetElement.h:

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

WebCore/ChangeLog
WebCore/ksvg2/svg/SVGAnimateColorElement.cpp
WebCore/ksvg2/svg/SVGAnimateColorElement.h
WebCore/ksvg2/svg/SVGAnimateElement.h
WebCore/ksvg2/svg/SVGAnimateTransformElement.cpp
WebCore/ksvg2/svg/SVGAnimateTransformElement.h
WebCore/ksvg2/svg/SVGAnimationElement.cpp
WebCore/ksvg2/svg/SVGAnimationElement.h
WebCore/ksvg2/svg/SVGSetElement.cpp
WebCore/ksvg2/svg/SVGSetElement.h

index 0716a5f..0888bdb 100644 (file)
@@ -2,6 +2,31 @@
 
         Reviewed by andersca.
 
+        Begin pushing code down into SVGAnimateElement
+
+        * ksvg2/svg/SVGAnimateColorElement.cpp:
+        (WebCore::SVGAnimateColorElement::handleStartCondition):
+        * ksvg2/svg/SVGAnimateColorElement.h:
+        * ksvg2/svg/SVGAnimateElement.h:
+        (WebCore::SVGAnimateElement::updateCurrentValue):
+        (WebCore::SVGAnimateElement::handleStartCondition):
+        (WebCore::SVGAnimateElement::handleEndCondition):
+        * ksvg2/svg/SVGAnimateTransformElement.cpp:
+        (WebCore::SVGAnimateTransformElement::handleStartCondition):
+        * ksvg2/svg/SVGAnimateTransformElement.h:
+        * ksvg2/svg/SVGAnimationElement.cpp:
+        (WebCore::SVGAnimationElement::handleTimerEvent):
+        * ksvg2/svg/SVGAnimationElement.h:
+        * ksvg2/svg/SVGSetElement.cpp:
+        (WebCore::SVGSetElement::updateCurrentValue):
+        (WebCore::SVGSetElement::handleStartCondition):
+        (WebCore::SVGSetElement::handleEndCondition):
+        * ksvg2/svg/SVGSetElement.h:
+
+2007-01-01  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by andersca.
+
         Add static function SVGColor::colorFromRGBColorString to allow parsing Colors from SVG color strings w/o creating an SVGColor object.
 
         * ksvg2/svg/SVGAnimateColorElement.cpp:
index 60ac96f..dab6209 100644 (file)
@@ -129,51 +129,46 @@ bool SVGAnimateColorElement::updateCurrentValue(double timePercentage)
     return true;
 }
 
-bool SVGAnimateColorElement::startIfNecessary()
+bool SVGAnimateColorElement::handleStartCondition()
 {
-    if (!connectedToTimer()) {
-        storeInitialValue();
-        
-        switch (detectAnimationMode()) {
-            case TO_ANIMATION:
-            case FROM_TO_ANIMATION:
-            {
-                m_toColor->setRGBColor(m_to);
-                if (!m_from.isEmpty()) // from-to animation
-                    m_fromColor->setRGBColor(m_from);
-                else // to animation
-                    m_fromColor->setRGBColor(m_initialColor.name());
-                
-                calculateColorDifference(m_toColor->color(), m_fromColor->color(), m_redDiff, m_greenDiff, m_blueDiff);
-                break;
-            }
-            case BY_ANIMATION:
-            case FROM_BY_ANIMATION:
-            {
-                if (!m_from.isEmpty()) // from-by animation
-                    m_fromColor->setRGBColor(m_from);
-                else // by animation
-                    m_fromColor->setRGBColor(m_initialColor.name());
-                
-                m_toColor->setRGBColor(addColorsAndClamp(m_fromColor->color(), SVGColor::colorFromRGBColorString(m_by)).name());
-                
-                calculateColorDifference(m_toColor->color(), m_fromColor->color(), m_redDiff, m_greenDiff, m_blueDiff);
-                break;
-            }
-            case VALUES_ANIMATION:
-                break;
-            default:
-            {
-                //kdError() << k_funcinfo << " Unable to detect animation mode! Aborting creation!" << endl;
-                return true;
-            }
+    storeInitialValue();
+    
+    switch (detectAnimationMode()) {
+        case TO_ANIMATION:
+        case FROM_TO_ANIMATION:
+        {
+            m_toColor->setRGBColor(m_to);
+            if (!m_from.isEmpty()) // from-to animation
+                m_fromColor->setRGBColor(m_from);
+            else // to animation
+                m_fromColor->setRGBColor(m_initialColor.name());
+            
+            calculateColorDifference(m_toColor->color(), m_fromColor->color(), m_redDiff, m_greenDiff, m_blueDiff);
+            break;
+        }
+        case BY_ANIMATION:
+        case FROM_BY_ANIMATION:
+        {
+            if (!m_from.isEmpty()) // from-by animation
+                m_fromColor->setRGBColor(m_from);
+            else // by animation
+                m_fromColor->setRGBColor(m_initialColor.name());
+            
+            m_toColor->setRGBColor(addColorsAndClamp(m_fromColor->color(), SVGColor::colorFromRGBColorString(m_by)).name());
+            
+            calculateColorDifference(m_toColor->color(), m_fromColor->color(), m_redDiff, m_greenDiff, m_blueDiff);
+            break;
+        }
+        case VALUES_ANIMATION:
+            break;
+        default:
+        {
+            //kdError() << k_funcinfo << " Unable to detect animation mode! Aborting creation!" << endl;
+            return false;
         }
-        
-        connectTimer();
-        return true;
     }
     
-    return false;
+    return true;
 }
 
 void SVGAnimateColorElement::handleEndCondition()
@@ -188,20 +183,6 @@ void SVGAnimateColorElement::handleEndCondition()
     resetValues();
 }
 
-void SVGAnimateColorElement::handleTimerEvent(double timePercentage)
-{
-    // Start condition.
-    if (!startIfNecessary())
-        return;
-
-    if (!updateCurrentValue(timePercentage))
-        return;
-    
-    // End condition.
-    if (timePercentage == 1.0)
-        handleEndCondition();
-}
-
 void SVGAnimateColorElement::applyAnimationToValue(Color& currentColor)
 {
     if (isAdditive())
index 0c0690c..f8ec61b 100644 (file)
@@ -37,7 +37,6 @@ namespace WebCore {
         virtual ~SVGAnimateColorElement();
 
         void applyAnimationToValue(Color& currentColor);
-        virtual void handleTimerEvent(double timePercentage);
 
         // Helper
         Color addColorsAndClamp(const Color&, const Color&);
@@ -51,9 +50,10 @@ namespace WebCore {
         virtual const SVGElement* contextElement() const { return this; }
         void storeInitialValue();
         void resetValues();
-        bool updateCurrentValue(double timePercentage);
-        bool startIfNecessary();
-        void handleEndCondition();
+        
+        virtual bool updateCurrentValue(double timePercentage);
+        virtual bool handleStartCondition();
+        virtual void handleEndCondition();
 
     private:
         Color m_lastColor;
index 819c57f..f80856b 100644 (file)
@@ -32,11 +32,13 @@ namespace WebCore {
     public:
         SVGAnimateElement(const QualifiedName&, Document*);
         virtual ~SVGAnimateElement();
-
-        virtual void handleTimerEvent(double timePercentage) { }
     
     protected:
         virtual const SVGElement* contextElement() const { return this; }
+        
+        virtual bool updateCurrentValue(double timePercentage) { return false; }
+        virtual bool handleStartCondition() { return false; }
+        virtual void handleEndCondition() { }
 
     private:
         int m_currentItem;
index 496ab99..a843449 100644 (file)
@@ -224,68 +224,63 @@ bool SVGAnimateTransformElement::updateCurrentValue(double timePercentage)
     return true;
 }
 
-bool SVGAnimateTransformElement::startIfNecessary()
+bool SVGAnimateTransformElement::handleStartCondition()
 {
-    if (!connectedToTimer()) {
-        storeInitialValue();
-        
-        switch (detectAnimationMode()) {
-            case TO_ANIMATION:
-            case FROM_TO_ANIMATION:
-            {        
-                m_toTransform = parseTransformValue(m_to);
-                m_toRotateSpecialCase = m_rotateSpecialCase;
-                
-                if (!m_from.isEmpty()) { // from-to animation
-                    m_fromTransform = parseTransformValue(m_from);
-                    m_fromRotateSpecialCase = m_rotateSpecialCase;
-                } else { // to animation
-                    m_fromTransform = m_initialTransform;
-                    m_fromRotateSpecialCase = false;
-                }
-                
-                if (!m_fromTransform)
-                    m_fromTransform = new SVGTransform();
-                
-                break;
-            }
-            case BY_ANIMATION:
-            case FROM_BY_ANIMATION:
-            {
-                m_toTransform = parseTransformValue(m_by);
-                m_toRotateSpecialCase = m_rotateSpecialCase;
-                
-                if (!m_from.isEmpty()) { // from-by animation
-                    m_fromTransform = parseTransformValue(m_from);
-                    m_fromRotateSpecialCase = m_rotateSpecialCase;
-                } else { // by animation
-                    m_fromTransform = m_initialTransform;
-                    m_fromRotateSpecialCase = false;
-                }
-                
-                if (!m_fromTransform)
-                    m_fromTransform = new SVGTransform();
-                
-                AffineTransform byMatrix = m_toTransform->matrix();
-                AffineTransform fromMatrix = m_fromTransform->matrix();
-                
-                byMatrix *= fromMatrix;
-                
-                break;
+    storeInitialValue();
+    
+    switch (detectAnimationMode()) {
+        case TO_ANIMATION:
+        case FROM_TO_ANIMATION:
+        {        
+            m_toTransform = parseTransformValue(m_to);
+            m_toRotateSpecialCase = m_rotateSpecialCase;
+            
+            if (!m_from.isEmpty()) { // from-to animation
+                m_fromTransform = parseTransformValue(m_from);
+                m_fromRotateSpecialCase = m_rotateSpecialCase;
+            } else { // to animation
+                m_fromTransform = m_initialTransform;
+                m_fromRotateSpecialCase = false;
             }
-            case VALUES_ANIMATION:
-                break;
-            default:
-            {
-                //kdError() << k_funcinfo << " Unable to detect animation mode! Aborting creation!" << endl;
-                return true;
+            
+            if (!m_fromTransform)
+                m_fromTransform = new SVGTransform();
+            
+            break;
+        }
+        case BY_ANIMATION:
+        case FROM_BY_ANIMATION:
+        {
+            m_toTransform = parseTransformValue(m_by);
+            m_toRotateSpecialCase = m_rotateSpecialCase;
+            
+            if (!m_from.isEmpty()) { // from-by animation
+                m_fromTransform = parseTransformValue(m_from);
+                m_fromRotateSpecialCase = m_rotateSpecialCase;
+            } else { // by animation
+                m_fromTransform = m_initialTransform;
+                m_fromRotateSpecialCase = false;
             }
+            
+            if (!m_fromTransform)
+                m_fromTransform = new SVGTransform();
+            
+            AffineTransform byMatrix = m_toTransform->matrix();
+            AffineTransform fromMatrix = m_fromTransform->matrix();
+            
+            byMatrix *= fromMatrix;
+            
+            break;
+        }
+        case VALUES_ANIMATION:
+            break;
+        default:
+        {
+            //kdError() << k_funcinfo << " Unable to detect animation mode! Aborting creation!" << endl;
+            return false;
         }
-        
-        connectTimer();
-        return true;
     }
-    return false;
+    return true;
 }
 
 void SVGAnimateTransformElement::handleEndCondition()
@@ -312,18 +307,6 @@ void SVGAnimateTransformElement::handleEndCondition()
     }
 }
 
-void SVGAnimateTransformElement::handleTimerEvent(double timePercentage)
-{
-    if (startIfNecessary())
-        return;
-    
-    if (!updateCurrentValue(timePercentage))
-        return;
-
-    if (timePercentage == 1.0)
-        handleEndCondition();
-}
-
 void SVGAnimateTransformElement::applyAnimationToValue(SVGTransformList* targetTransforms)
 {
     ExceptionCode ec;
index c4bc0f1..c8ecc68 100644 (file)
@@ -38,7 +38,6 @@ namespace WebCore {
 
         virtual void parseMappedAttribute(MappedAttribute*);
 
-        virtual void handleTimerEvent(double timePercentage);
         void applyAnimationToValue(SVGTransformList*);
 
         // Helpers
@@ -51,10 +50,11 @@ namespace WebCore {
     protected:
         virtual const SVGElement* contextElement() const { return this; }
         void storeInitialValue();
-        bool updateCurrentValue(double timePercentage);
         void resetValues();
-        bool startIfNecessary();
-        void handleEndCondition();
+        
+        virtual bool updateCurrentValue(double timePercentage);
+        virtual bool handleStartCondition();
+        virtual void handleEndCondition();
 
     private:
         int m_currentItem;
index 7a44c79..f5b2a36 100644 (file)
@@ -544,6 +544,21 @@ static double calculateTimePercentage(double elapsedSeconds, double start, doubl
     return percentage;
 }
 
+void SVGAnimationElement::handleTimerEvent(double timePercentage)
+{
+    if (!connectedToTimer()) {
+        connectTimer();
+        handleStartCondition(); // Check bool if adding anything after this call
+        return;
+    }
+    
+    if (!updateCurrentValue(timePercentage))
+        return;
+    
+    if (timePercentage == 1.0)
+        handleEndCondition();
+}
+
 bool SVGAnimationElement::updateForElapsedSeconds(double elapsedSeconds)
 {
     // Validate animation timing settings:
index 15dcba1..8d3d6c3 100644 (file)
@@ -99,7 +99,7 @@ namespace WebCore {
 
         // Helpers
         bool updateForElapsedSeconds(double);
-        virtual void handleTimerEvent(double timePercentage) = 0;
+        void handleTimerEvent(double timePercentage);
 
         double parseClockValue(const String&) const;
 
@@ -129,6 +129,10 @@ namespace WebCore {
         
         void connectTimer();
         void disconnectTimer();
+        
+        virtual bool updateCurrentValue(double timePercentage) = 0;
+        virtual bool handleStartCondition() = 0;
+        virtual void handleEndCondition() = 0;
 
         ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGExternalResourcesRequired, bool, ExternalResourcesRequired, externalResourcesRequired)
 
index 61e1ab6..74253a1 100644 (file)
@@ -39,29 +39,28 @@ SVGSetElement::~SVGSetElement()
 {
 }
 
-void SVGSetElement::handleTimerEvent(double timePercentage)
+bool SVGSetElement::updateCurrentValue(double timePercentage)
 {
-    // Start condition.
-    if (!connectedToTimer()) {
-        connectTimer();
-        return;
-    }
-    
-    // Commit change now...
     if (m_savedTo.isEmpty()) {
         m_savedTo = targetAttribute();
         setTargetAttribute(m_to);
     }
+    return false;
+}
 
-    // End condition.
-    if (timePercentage == 1.0) {
-        disconnectTimer();
-
-        if (!isFrozen())
-            setTargetAttribute(m_savedTo);
+bool SVGSetElement::handleStartCondition()
+{
+    return true;
+}
 
-        m_savedTo = String();
-    }
+void SVGSetElement::handleEndCondition()
+{
+    disconnectTimer();
+    
+    if (!isFrozen())
+        setTargetAttribute(m_savedTo);
+    
+    m_savedTo = String();
 }
 
 }
index d6418cd..3d9075a 100644 (file)
@@ -34,10 +34,12 @@ namespace WebCore
         SVGSetElement(const QualifiedName&, Document*);
         virtual ~SVGSetElement();
 
-        virtual void handleTimerEvent(double timePercentage);
-
     protected:
         virtual const SVGElement* contextElement() const { return this; }
+        
+        virtual bool updateCurrentValue(double timePercentage);
+        virtual bool handleStartCondition();
+        virtual void handleEndCondition();
 
     private:
         String m_savedTo;