Changeset 56795 in webkit


Ignore:
Timestamp:
Mar 30, 2010 9:40:50 AM (14 years ago)
Author:
krit@webkit.org
Message:

2010-03-30 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

Cannot animate "points" attribute for <svg:polygon>
https://bugs.webkit.org/show_bug.cgi?id=21371

Add animation support for 'points' on polygons in SVG.

Test: svg/animations/animate-points.html

  • svg/SVGAnimateElement.cpp: (WebCore::SVGAnimateElement::determinePropertyType): (WebCore::SVGAnimateElement::calculateAnimatedValue): (WebCore::SVGAnimateElement::calculateFromAndToValues): (WebCore::SVGAnimateElement::resetToBaseValue): (WebCore::SVGAnimateElement::applyResultsToTarget):
  • svg/SVGAnimateElement.h: (WebCore::SVGAnimateElement::): added PropertyType PointsProperty
  • svg/SVGPointList.cpp: (WebCore::blendFunc): (WebCore::SVGPointList::createAnimated): calculates animated PointList
  • svg/SVGPointList.h:

2010-03-30 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

Cannot animate "points" attribute for <svg:polygon>
https://bugs.webkit.org/show_bug.cgi?id=21371

Tests if points of a polygon are animateable.

  • svg/animations/animate-points-expected.txt: Added.
  • svg/animations/animate-points.html: Added.
  • svg/animations/script-tests/animate-points.js: Added. (sample1): (sample2): (sample3): (executeTest):
Location:
trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r56793 r56795  
     12010-03-30  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Cannot animate "points" attribute for <svg:polygon>
     6        https://bugs.webkit.org/show_bug.cgi?id=21371
     7
     8        Tests if points of a polygon are animateable.
     9
     10        * svg/animations/animate-points-expected.txt: Added.
     11        * svg/animations/animate-points.html: Added.
     12        * svg/animations/script-tests/animate-points.js: Added.
     13        (sample1):
     14        (sample2):
     15        (sample3):
     16        (executeTest):
     17
    1182010-03-30  Pavel Feldman  <pfeldman@chromium.org>
    219
  • trunk/WebCore/ChangeLog

    r56792 r56795  
     12010-03-30  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Cannot animate "points" attribute for <svg:polygon>
     6        https://bugs.webkit.org/show_bug.cgi?id=21371
     7
     8        Add animation support for 'points' on polygons in SVG.
     9
     10        Test: svg/animations/animate-points.html
     11
     12        * svg/SVGAnimateElement.cpp:
     13        (WebCore::SVGAnimateElement::determinePropertyType):
     14        (WebCore::SVGAnimateElement::calculateAnimatedValue):
     15        (WebCore::SVGAnimateElement::calculateFromAndToValues):
     16        (WebCore::SVGAnimateElement::resetToBaseValue):
     17        (WebCore::SVGAnimateElement::applyResultsToTarget):
     18        * svg/SVGAnimateElement.h:
     19        (WebCore::SVGAnimateElement::): added PropertyType PointsProperty
     20        * svg/SVGPointList.cpp:
     21        (WebCore::blendFunc):
     22        (WebCore::SVGPointList::createAnimated): calculates animated PointList
     23        * svg/SVGPointList.h:
     24
    1252010-03-30  Alexander Pavlov  <apavlov@chromium.org>
    226
  • trunk/WebCore/svg/SVGAnimateElement.cpp

    r50675 r56795  
    2929#include "SVGParserUtilities.h"
    3030#include "SVGPathSegList.h"
     31#include "SVGPointList.h"
    3132#include <math.h>
    3233
     
    8182    if (attribute == "d")
    8283        return PathProperty;
     84    if (attribute == "points")
     85        return PointsProperty;
    8386    if (attribute == "color" || attribute == "fill" || attribute == "stroke")
    8487        return ColorProperty;
     
    143146        }
    144147        return;
     148    } else if (m_propertyType == PointsProperty) {
     149        if (percentage == 0)
     150            results->m_animatedPoints = m_fromPoints;
     151        else if (percentage == 1.f)
     152            results->m_animatedPoints = m_toPoints;
     153        else {
     154            if (m_fromPoints && m_toPoints)
     155                results->m_animatedPoints = SVGPointList::createAnimated(m_fromPoints.get(), m_toPoints.get(), percentage);
     156            else
     157                results->m_animatedPoints.clear();
     158            // Fall back to discrete animation if the points are not compatible
     159            if (!results->m_animatedPoints)
     160                results->m_animatedPoints = ((animationMode == FromToAnimation && percentage > 0.5f) || animationMode == ToAnimation || percentage == 1.0f)
     161                    ? m_toPoints : m_fromPoints;
     162        }
     163        return;
    145164    }
    146165    ASSERT(animationMode == FromToAnimation || animationMode == ToAnimation || animationMode == ValuesAnimation);
     
    178197        m_fromPath.clear();
    179198        m_toPath.clear();
     199    } else if (m_propertyType == PointsProperty) {
     200        m_fromPoints = SVGPointList::create(SVGNames::pointsAttr);
     201        if (pointsListFromSVGData(m_fromPoints.get(), fromString)) {
     202            m_toPoints = SVGPointList::create(SVGNames::pointsAttr);
     203            if (pointsListFromSVGData(m_toPoints.get(), toString))
     204                return true;
     205        }
     206        m_fromPoints.clear();
     207        m_toPoints.clear();
    180208    }
    181209    m_fromString = fromString;
     
    224252    } else if (m_propertyType == PathProperty) {
    225253        m_animatedPath.clear();
     254        return;
     255    } else if (m_propertyType == PointsProperty) {
     256        m_animatedPoints.clear();
    226257        return;
    227258    }
     
    251282            }
    252283        }
     284    } else if (m_propertyType == PointsProperty) {
     285        if (!m_animatedPoints || !m_animatedPoints->numberOfItems())
     286            valueToApply = m_animatedString;
     287        else
     288            valueToApply = m_animatedPoints->valueAsString();
    253289    } else
    254290        valueToApply = m_animatedString;
  • trunk/WebCore/svg/SVGAnimateElement.h

    r50583 r56795  
    3030namespace WebCore {
    3131    class SVGPathSegList;
     32    class SVGPointList;
    3233
    3334    class SVGAnimateElement : public SVGAnimationElement {
     
    4546
    4647    private:
    47         enum PropertyType { NumberProperty, ColorProperty, StringProperty, PathProperty };
     48        enum PropertyType { NumberProperty, ColorProperty, StringProperty, PathProperty, PointsProperty };
    4849        PropertyType determinePropertyType(const String& attribute) const;
    4950        PropertyType m_propertyType;
     
    6263        RefPtr<SVGPathSegList> m_toPath;
    6364        RefPtr<SVGPathSegList> m_animatedPath;
     65        RefPtr<SVGPointList> m_fromPoints;
     66        RefPtr<SVGPointList> m_toPoints;
     67        RefPtr<SVGPointList> m_animatedPoints;
    6468    };
    6569
  • trunk/WebCore/svg/SVGPathSegList.cpp

    r51627 r56795  
    145145}
    146146   
    147 static inline float blendFunc(float from, float to, float progress)
     147float adjustAnimatedValue(float from, float to, float progress)
    148148{
    149149    return (to - from) * progress + from;
     
    151151   
    152152#define BLENDPATHSEG1(class, attr1) \
    153     class::create(blendFunc(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress))
     153    class::create(adjustAnimatedValue(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress))
    154154   
    155155#define BLENDPATHSEG2(class, attr1, attr2) \
    156     class::create(blendFunc(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress), \
    157                     blendFunc(static_cast<class*>(from)->attr2(), static_cast<class*>(to)->attr2(), progress))
     156    class::create(adjustAnimatedValue(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress), \
     157                    adjustAnimatedValue(static_cast<class*>(from)->attr2(), static_cast<class*>(to)->attr2(), progress))
    158158   
    159159#define BLENDPATHSEG4(class, attr1, attr2, attr3, attr4) \
    160     class::create(blendFunc(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress), \
    161                 blendFunc(static_cast<class*>(from)->attr2(), static_cast<class*>(to)->attr2(), progress), \
    162                 blendFunc(static_cast<class*>(from)->attr3(), static_cast<class*>(to)->attr3(), progress), \
    163                 blendFunc(static_cast<class*>(from)->attr4(), static_cast<class*>(to)->attr4(), progress))
     160    class::create(adjustAnimatedValue(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress), \
     161                adjustAnimatedValue(static_cast<class*>(from)->attr2(), static_cast<class*>(to)->attr2(), progress), \
     162                adjustAnimatedValue(static_cast<class*>(from)->attr3(), static_cast<class*>(to)->attr3(), progress), \
     163                adjustAnimatedValue(static_cast<class*>(from)->attr4(), static_cast<class*>(to)->attr4(), progress))
    164164   
    165165#define BLENDPATHSEG6(class, attr1, attr2, attr3, attr4, attr5, attr6) \
    166     class::create(blendFunc(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress), \
    167                 blendFunc(static_cast<class*>(from)->attr2(), static_cast<class*>(to)->attr2(), progress), \
    168                 blendFunc(static_cast<class*>(from)->attr3(), static_cast<class*>(to)->attr3(), progress), \
    169                 blendFunc(static_cast<class*>(from)->attr4(), static_cast<class*>(to)->attr4(), progress), \
    170                 blendFunc(static_cast<class*>(from)->attr5(), static_cast<class*>(to)->attr5(), progress), \
    171                 blendFunc(static_cast<class*>(from)->attr6(), static_cast<class*>(to)->attr6(), progress))
     166    class::create(adjustAnimatedValue(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress), \
     167                adjustAnimatedValue(static_cast<class*>(from)->attr2(), static_cast<class*>(to)->attr2(), progress), \
     168                adjustAnimatedValue(static_cast<class*>(from)->attr3(), static_cast<class*>(to)->attr3(), progress), \
     169                adjustAnimatedValue(static_cast<class*>(from)->attr4(), static_cast<class*>(to)->attr4(), progress), \
     170                adjustAnimatedValue(static_cast<class*>(from)->attr5(), static_cast<class*>(to)->attr5(), progress), \
     171                adjustAnimatedValue(static_cast<class*>(from)->attr6(), static_cast<class*>(to)->attr6(), progress))
    172172
    173173#define BLENDPATHSEG7(class, attr1, attr2, attr3, attr4, attr5, bool1, bool2) \
    174     class::create(blendFunc(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress), \
    175                 blendFunc(static_cast<class*>(from)->attr2(), static_cast<class*>(to)->attr2(), progress), \
    176                 blendFunc(static_cast<class*>(from)->attr3(), static_cast<class*>(to)->attr3(), progress), \
    177                 blendFunc(static_cast<class*>(from)->attr4(), static_cast<class*>(to)->attr4(), progress), \
    178                 blendFunc(static_cast<class*>(from)->attr5(), static_cast<class*>(to)->attr5(), progress), \
    179                 static_cast<bool>(blendFunc(static_cast<class*>(from)->bool1(), static_cast<class*>(to)->bool1(), progress)), \
    180                 static_cast<bool>(blendFunc(static_cast<class*>(from)->bool2(), static_cast<class*>(to)->bool2(), progress)))
     174    class::create(adjustAnimatedValue(static_cast<class*>(from)->attr1(), static_cast<class*>(to)->attr1(), progress), \
     175                adjustAnimatedValue(static_cast<class*>(from)->attr2(), static_cast<class*>(to)->attr2(), progress), \
     176                adjustAnimatedValue(static_cast<class*>(from)->attr3(), static_cast<class*>(to)->attr3(), progress), \
     177                adjustAnimatedValue(static_cast<class*>(from)->attr4(), static_cast<class*>(to)->attr4(), progress), \
     178                adjustAnimatedValue(static_cast<class*>(from)->attr5(), static_cast<class*>(to)->attr5(), progress), \
     179                static_cast<bool>(adjustAnimatedValue(static_cast<class*>(from)->bool1(), static_cast<class*>(to)->bool1(), progress)), \
     180                static_cast<bool>(adjustAnimatedValue(static_cast<class*>(from)->bool2(), static_cast<class*>(to)->bool2(), progress)))
    181181
    182182PassRefPtr<SVGPathSegList> SVGPathSegList::createAnimated(const SVGPathSegList* fromList, const SVGPathSegList* toList, float progress)
  • trunk/WebCore/svg/SVGPathSegList.h

    r51627 r56795  
    4646    };
    4747
     48    float adjustAnimatedValue(float from, float to, float progress);
     49
    4850} // namespace WebCore
    4951
  • trunk/WebCore/svg/SVGPointList.cpp

    r50583 r56795  
    2323#if ENABLE(SVG)
    2424#include "SVGPointList.h"
     25#include "SVGPathSegList.h"
    2526#include "PlatformString.h"
    2627
     
    5455}
    5556
     57PassRefPtr<SVGPointList> SVGPointList::createAnimated(const SVGPointList* fromList, const SVGPointList* toList, float progress)
     58{
     59    unsigned itemCount = fromList->numberOfItems();
     60    if (!itemCount || itemCount != toList->numberOfItems())
     61        return 0;
     62    RefPtr<SVGPointList> result = create(fromList->associatedAttributeName());
     63    ExceptionCode ec = 0;
     64    for (unsigned n = 0; n < itemCount; ++n) {
     65        FloatPoint from = fromList->getItem(n, ec);
     66        if (ec)
     67            return 0;
     68        FloatPoint to = toList->getItem(n, ec);
     69        if (ec)
     70            return 0;
     71        FloatPoint segment = FloatPoint(adjustAnimatedValue(from.x(), to.x(), progress),
     72                                        adjustAnimatedValue(from.y(), to.y(), progress));
     73        result->appendItem(segment, ec);
     74        if (ec)
     75            return 0;
     76    }
     77    return result.release();
     78}
     79
    5680}
    5781
  • trunk/WebCore/svg/SVGPointList.h

    r50583 r56795  
    3838        String valueAsString() const;
    3939
     40        static PassRefPtr<SVGPointList> createAnimated(const SVGPointList* fromList, const SVGPointList* toList, float progress);
     41
    4042    private:
    4143        SVGPointList(const QualifiedName&);
Note: See TracChangeset for help on using the changeset viewer.