Changeset 70303 in webkit


Ignore:
Timestamp:
Oct 22, 2010 6:26:25 AM (13 years ago)
Author:
Nikolas Zimmermann
Message:

2010-10-22 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.

Further preparations to deploy the new SVGAnimatedProperty concept for the rest of the SVG datatypes
https://bugs.webkit.org/show_bug.cgi?id=48125

Model SVGListPropertyTearOff similar to SVGPropertyTearOff, allow it to be used for SVGXXXList datatypes, that are not animated. (SVGStringList)
Recognize all SVG primitive datatypes in SVGPropertyTraits.
Add a new - temporary - macro to support multiple animated properties that map to a single DOM attribute (kernelUnitLength attribute vs. kernelUnitLengthX/Y properties).
These macros will all be removed and expanded by their content, as soon as the transition to the new SVGAnimatedProperty concept is done.

Doesn't affect any tests yet, as the code is still unused.

  • svg/properties/SVGAnimatedProperty.h: (WebCore::SVGAnimatedProperty::lookupOrCreateWrapper): (WebCore::SVGAnimatedProperty::lookupWrapper):
  • svg/properties/SVGAnimatedPropertyMacros.h:
  • svg/properties/SVGAnimatedPropertySynchronizer.h:
  • svg/properties/SVGListPropertyTearOff.h: (WebCore::SVGListPropertyTearOff::create): (WebCore::SVGListPropertyTearOff::removeItemFromList): (WebCore::SVGListPropertyTearOff::detachListWrappers): (WebCore::SVGListPropertyTearOff::clear): (WebCore::SVGListPropertyTearOff::numberOfItems): (WebCore::SVGListPropertyTearOff::initialize): (WebCore::SVGListPropertyTearOff::getItem): (WebCore::SVGListPropertyTearOff::insertItemBefore): (WebCore::SVGListPropertyTearOff::replaceItem): (WebCore::SVGListPropertyTearOff::removeItem): (WebCore::SVGListPropertyTearOff::appendItem): (WebCore::SVGListPropertyTearOff::SVGListPropertyTearOff): (WebCore::SVGListPropertyTearOff::~SVGListPropertyTearOff): (WebCore::SVGListPropertyTearOff::commitChange):
  • svg/properties/SVGPropertyTearOff.h:
  • svg/properties/SVGPropertyTraits.h:
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r70302 r70303  
     12010-10-22  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        Further preparations to deploy the new SVGAnimatedProperty concept for the rest of the SVG datatypes
     6        https://bugs.webkit.org/show_bug.cgi?id=48125
     7
     8        Model SVGListPropertyTearOff similar to SVGPropertyTearOff, allow it to be used for SVGXXXList datatypes, that are not animated. (SVGStringList)
     9        Recognize all SVG primitive datatypes in SVGPropertyTraits.
     10        Add a new - temporary - macro to support multiple animated properties that map to a single DOM attribute (kernelUnitLength attribute vs. kernelUnitLengthX/Y properties).
     11        These macros will all be removed and expanded by their content, as soon as the transition to the new SVGAnimatedProperty concept is done.
     12
     13        Doesn't affect any tests yet, as the code is still unused.
     14
     15        * svg/properties/SVGAnimatedProperty.h:
     16        (WebCore::SVGAnimatedProperty::lookupOrCreateWrapper):
     17        (WebCore::SVGAnimatedProperty::lookupWrapper):
     18        * svg/properties/SVGAnimatedPropertyMacros.h:
     19        * svg/properties/SVGAnimatedPropertySynchronizer.h:
     20        * svg/properties/SVGListPropertyTearOff.h:
     21        (WebCore::SVGListPropertyTearOff::create):
     22        (WebCore::SVGListPropertyTearOff::removeItemFromList):
     23        (WebCore::SVGListPropertyTearOff::detachListWrappers):
     24        (WebCore::SVGListPropertyTearOff::clear):
     25        (WebCore::SVGListPropertyTearOff::numberOfItems):
     26        (WebCore::SVGListPropertyTearOff::initialize):
     27        (WebCore::SVGListPropertyTearOff::getItem):
     28        (WebCore::SVGListPropertyTearOff::insertItemBefore):
     29        (WebCore::SVGListPropertyTearOff::replaceItem):
     30        (WebCore::SVGListPropertyTearOff::removeItem):
     31        (WebCore::SVGListPropertyTearOff::appendItem):
     32        (WebCore::SVGListPropertyTearOff::SVGListPropertyTearOff):
     33        (WebCore::SVGListPropertyTearOff::~SVGListPropertyTearOff):
     34        (WebCore::SVGListPropertyTearOff::commitChange):
     35        * svg/properties/SVGPropertyTearOff.h:
     36        * svg/properties/SVGPropertyTraits.h:
     37
    1382010-10-22  Sheriff Bot  <webkit.review.bot@gmail.com>
    239
  • trunk/WebCore/svg/properties/SVGAnimatedProperty.h

    r70223 r70303  
    5959
    6060    template<typename TearOffType, typename PropertyType>
    61     static PassRefPtr<TearOffType> lookupOrCreateWrapper(SVGElement* element, const QualifiedName& attributeName, PropertyType& property)
     61    static PassRefPtr<TearOffType> lookupOrCreateWrapper(SVGElement* element, const QualifiedName& attributeName, const AtomicString& attributeIdentifier, PropertyType& property)
    6262    {
    63         SVGAnimatedPropertyDescription key(element, attributeName.localName());
     63        SVGAnimatedPropertyDescription key(element, attributeIdentifier);
    6464        RefPtr<SVGAnimatedProperty> wrapper = animatedPropertyCache()->get(key);
    6565        if (!wrapper) {
     
    7272
    7373    template<typename TearOffType>
    74     static TearOffType* lookupWrapper(SVGElement* element, const QualifiedName& attributeName)
     74    static TearOffType* lookupWrapper(SVGElement* element, const AtomicString& attributeIdentifier)
    7575    {
    76         SVGAnimatedPropertyDescription key(element, attributeName.localName());
     76        SVGAnimatedPropertyDescription key(element, attributeIdentifier);
    7777        return static_pointer_cast<TearOffType>(animatedPropertyCache()->get(key)).get();
    7878    }
  • trunk/WebCore/svg/properties/SVGAnimatedPropertyMacros.h

    r70223 r70303  
    2727#include "SVGAnimatedPropertySynchronizer.h"
    2828#include "SVGAnimatedPropertyTearOff.h"
     29#include "SVGNames.h" // FIXME: Temporary hack, until we expand the macros in all files, so we don't need a global SVGNames.h include
    2930#include "SVGPropertyTraits.h"
    3031
     
    5859
    5960// FIXME: These macros should be removed, after the transition to the new SVGAnimatedProperty concept is finished.
    60 #define DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, TearOffType, PropertyType, UpperProperty, LowerProperty) \
     61#define DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, TearOffType, PropertyType, UpperProperty, LowerProperty) \
    6162public: \
    6263PropertyType& LowerProperty() const \
     
    8788{ \
    8889    m_##LowerProperty.shouldSynchronize = true; \
    89     return SVGAnimatedProperty::lookupOrCreateWrapper<TearOffType, PropertyType>(this, DOMAttribute, m_##LowerProperty.value); \
     90    return SVGAnimatedProperty::lookupOrCreateWrapper<TearOffType, PropertyType>(this, DOMAttribute, SVGDOMAttributeIdentifier, m_##LowerProperty.value); \
    9091} \
    9192private: \
     
    9394
    9495#define DECLARE_ANIMATED_PROPERTY_NEW(OwnerType, DOMAttribute, PropertyType, UpperProperty, LowerProperty) \
    95 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGAnimatedPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty)
     96DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty)
     97
     98#define DECLARE_ANIMATED_PROPERTY_NEW_MULTIPLE_WRAPPERS(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, PropertyType, UpperProperty, LowerProperty) \
     99DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty)
    96100
    97101#define DECLARE_ANIMATED_LIST_PROPERTY_NEW(OwnerType, DOMAttribute, PropertyType, UpperProperty, LowerProperty) \
    98 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGAnimatedListPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty) \
     102DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedListPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty) \
    99103\
    100104void detachAnimated##UpperProperty##ListWrappers(unsigned newListSize) \
    101105{ \
    102     SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGAnimatedListPropertyTearOff<PropertyType> >(this, DOMAttribute); \
     106    SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGAnimatedListPropertyTearOff<PropertyType> >(this, DOMAttribute.localName()); \
    103107    if (!wrapper) \
    104108        return; \
  • trunk/WebCore/svg/properties/SVGAnimatedPropertySynchronizer.h

    r70135 r70303  
    2020#ifndef SVGAnimatedPropertySynchronizer_h
    2121#define SVGAnimatedPropertySynchronizer_h
    22 
    23 #include "DeprecatedSVGAnimatedPropertyTraits.h"
    2422
    2523#if ENABLE(SVG)
  • trunk/WebCore/svg/properties/SVGListPropertyTearOff.h

    r70223 r70303  
    4242    typedef Vector<RefPtr<ListItemTearOff> > ListWrapperCache;
    4343
     44    // Used for [SVGAnimatedProperty] types (for example: SVGAnimatedLengthList::baseVal())
    4445    static PassRefPtr<Self> create(SVGAnimatedProperty* animatedProperty, SVGPropertyRole role, PropertyType& values)
    4546    {
     
    4849    }
    4950
     51    // Used for non-animated POD types (for example: SVGStringList).
     52    static PassRefPtr<Self> create(const PropertyType& initialValue)
     53    {
     54        return adoptRef(new Self(initialValue));
     55    }
     56
    5057    int removeItemFromList(ListItemTearOff* removeItem, bool shouldSynchronizeWrappers)
    5158    {
    5259        // Lookup item in cache and remove its corresponding wrapper.
    5360        unsigned size = m_wrappers.size();
    54         ASSERT(size == m_values.size());
     61        ASSERT(size == m_values->size());
    5562        for (unsigned i = 0; i < size; ++i) {
    5663            RefPtr<ListItemTearOff>& item = m_wrappers.at(i);
     
    6067            item->detachWrapper();
    6168            m_wrappers.remove(i);
    62             m_values.remove(i);
     69            m_values->remove(i);
    6370
    6471            if (shouldSynchronizeWrappers)
     
    7582        // See SVGPropertyTearOff::detachWrapper() for an explaination what's happening here.
    7683        unsigned size = m_wrappers.size();
    77         ASSERT(size == m_values.size());
     84        ASSERT(size == m_values->size());
    7885        for (unsigned i = 0; i < size; ++i) {
    7986            RefPtr<ListItemTearOff>& item = m_wrappers.at(i);
     
    99106
    100107        detachListWrappers(0);
    101         m_values.clear();
     108        m_values->clear();
    102109    }
    103110
    104111    unsigned numberOfItems() const
    105112    {
    106         return m_values.size();
     113        return m_values->size();
    107114    }
    108115
     
    121128
    122129        RefPtr<ListItemTearOff> newItem = passNewItem;
    123         ASSERT(m_values.size() == m_wrappers.size());
     130        ASSERT(m_values->size() == m_wrappers.size());
    124131
    125132        // Spec: If the inserted item is already in a list, it is removed from its previous list before it is inserted into this list.
     
    128135        // Spec: Clears all existing current items from the list and re-initializes the list to hold the single item specified by the parameter.
    129136        detachListWrappers(0);
    130         m_values.clear();
     137        m_values->clear();
    131138       
    132         m_values.append(newItem->propertyReference());
     139        m_values->append(newItem->propertyReference());
    133140        m_wrappers.append(newItem);
    134141
     
    139146    PassListItemTearOff getItem(unsigned index, ExceptionCode& ec)
    140147    {
    141         if (index >= m_values.size()) {
     148        if (index >= m_values->size()) {
    142149            ec = INDEX_SIZE_ERR;
    143150            return 0;
     
    146153        // Spec: Returns the specified item from the list. The returned item is the item itself and not a copy.
    147154        // Any changes made to the item are immediately reflected in the list.
    148         ASSERT(m_values.size() == m_wrappers.size());
     155        ASSERT(m_values->size() == m_wrappers.size());
    149156        RefPtr<ListItemTearOff> wrapper = m_wrappers.at(index);
    150157        if (!wrapper) {
     
    152159            // It is also associated with our animated property, so it can notify the SVG Element which holds the SVGAnimated*List
    153160            // that it has been modified (and thus can call svgAttributeChanged(associatedAttributeName)).
    154             wrapper = ListItemTearOff::create(m_animatedProperty.get(), UndefinedRole, m_values.at(index));
     161            wrapper = ListItemTearOff::create(m_animatedProperty.get(), UndefinedRole, m_values->at(index));
    155162            m_wrappers.at(index) = wrapper;
    156163        }
     
    173180
    174181        // Spec: If the index is greater than or equal to numberOfItems, then the new item is appended to the end of the list.
    175         if (index > m_values.size())
    176              index = m_values.size();
     182        if (index > m_values->size())
     183             index = m_values->size();
    177184
    178185        RefPtr<ListItemTearOff> newItem = passNewItem;
    179         ASSERT(m_values.size() == m_wrappers.size());
     186        ASSERT(m_values->size() == m_wrappers.size());
    180187
    181188        // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list.
     
    184191        // Spec: Inserts a new item into the list at the specified position. The index of the item before which the new item is to be
    185192        // inserted. The first item is number 0. If the index is equal to 0, then the new item is inserted at the front of the list.
    186         m_values.insert(index, newItem->propertyReference());
     193        m_values->insert(index, newItem->propertyReference());
    187194
    188195        // Store new wrapper at position 'index', change its underlying value, so mutations of newItem, directly affect the item in the list.
     
    200207        }
    201208
    202         if (index >= m_values.size()) {
     209        if (index >= m_values->size()) {
    203210            ec = INDEX_SIZE_ERR;
    204211            return 0;
     
    212219
    213220        RefPtr<ListItemTearOff> newItem = passNewItem;
    214         ASSERT(m_values.size() == m_wrappers.size());
     221        ASSERT(m_values->size() == m_wrappers.size());
    215222
    216223        // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list.
     
    224231
    225232        // Update the value and the wrapper at the desired position 'index'.
    226         m_values.at(index) = newItem->propertyReference();
     233        m_values->at(index) = newItem->propertyReference();
    227234        m_wrappers.at(index) = newItem;
    228235
     
    238245        }
    239246
    240         if (index >= m_values.size()) {
     247        if (index >= m_values->size()) {
    241248            ec = INDEX_SIZE_ERR;
    242249            return 0;
    243250        }
    244251
    245         ASSERT(m_values.size() == m_wrappers.size());
     252        ASSERT(m_values->size() == m_wrappers.size());
    246253
    247254        // Detach the existing wrapper.
     
    252259        }
    253260
    254         m_values.remove(index);
     261        m_values->remove(index);
    255262
    256263        commitChange();
     
    272279
    273280        RefPtr<ListItemTearOff> newItem = passNewItem;
    274         ASSERT(m_values.size() == m_wrappers.size());
     281        ASSERT(m_values->size() == m_wrappers.size());
    275282
    276283        // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list.
     
    278285
    279286        // Append the value and wrapper at the end of the list.
    280         m_values.append(newItem->propertyReference());
     287        m_values->append(newItem->propertyReference());
    281288        m_wrappers.append(newItem);
    282289
     
    289296        : m_animatedProperty(animatedProperty)
    290297        , m_role(role)
    291         , m_values(values)
    292     {
     298        , m_values(&values)
     299        , m_valuesIsCopy(false)
     300    {
     301        // Using operator & is completly fine, as SVGAnimatedProperty owns this reference,
     302        // and we're guaranteed to live as long as SVGAnimatedProperty does.
    293303        if (!values.isEmpty())
    294304            m_wrappers.fill(0, values.size());
    295305    }
    296306
     307    SVGListPropertyTearOff(const PropertyType& initialValue)
     308        : m_animatedProperty(0)
     309        , m_role(UndefinedRole)
     310        , m_values(new PropertyType(initialValue))
     311        , m_valuesIsCopy(true)
     312    {
     313    }
     314
     315    virtual ~SVGListPropertyTearOff()
     316    {
     317        if (m_valuesIsCopy)
     318            delete m_values;
     319    }
     320
    297321    void commitChange()
    298322    {
    299323        // Update existing wrappers, as the index in the m_values list has changed.
    300324        unsigned size = m_wrappers.size();
    301         ASSERT(size == m_values.size());
     325        ASSERT(size == m_values->size());
    302326        for (unsigned i = 0; i < size; ++i) {
    303327            RefPtr<ListItemTearOff>& item = m_wrappers.at(i);
     
    305329                continue;
    306330            item->setAnimatedProperty(m_animatedProperty.get());
    307             item->setValue(m_values.at(i));
     331            item->setValue(m_values->at(i));
    308332        }
    309333
     
    348372
    349373    // For the example above (text.x.baseVal): A reference to the SVGLengthList& stored in the SVGTextElement, which we can directly modify
    350     PropertyType& m_values;
     374    PropertyType* m_values;
     375    bool m_valuesIsCopy : 1;
    351376
    352377    // A list of wrappers, which is always in sync between m_values.
  • trunk/WebCore/svg/properties/SVGPropertyTearOff.h

    r70223 r70303  
    2222
    2323#if ENABLE(SVG)
     24#include "SVGAnimatedProperty.h"
    2425#include "SVGElement.h"
    2526#include "SVGProperty.h"
    2627
    2728namespace WebCore {
    28 
    29 class SVGAnimatedProperty;
    3029
    3130template<typename PropertyType>
     
    4241    }
    4342
    44     // Used for [SVGLiveProperty] types (for example: SVGSVGElement::createSVGLength()).
     43    // Used for non-animated POD types (for example: SVGLength).
    4544    static PassRefPtr<Self> create(const PropertyType& initialValue)
    4645    {
  • trunk/WebCore/svg/properties/SVGPropertyTraits.h

    r70223 r70303  
    2323
    2424#if ENABLE(SVG)
     25#include "FloatRect.h"
     26#include "SVGAngle.h"
    2527#include "SVGLength.h"
    2628#include "SVGLengthList.h"
     29#include "SVGPreserveAspectRatio.h"
     30#include <wtf/text/StringBuilder.h>
    2731
    2832namespace WebCore {
     
    3135struct SVGPropertyTraits { };
    3236
    33 // SVGAnimatedLength
     37template<>
     38struct SVGPropertyTraits<SVGAngle> {
     39    static SVGAngle initialValue() { return SVGAngle(); }
     40    static String toString(const SVGAngle& type) { return type.valueAsString(); }
     41};
     42
     43template<>
     44struct SVGPropertyTraits<bool> {
     45    static bool initialValue() { return false; }
     46    static String toString(bool type) { return type ? "true" : "false"; }
     47};
     48
     49template<>
     50struct SVGPropertyTraits<int> {
     51    static int initialValue() { return 0; }
     52    static String toString(int type) { return String::number(type); }
     53};
     54
     55template<>
     56struct SVGPropertyTraits<long> {
     57    static long initialValue() { return 0; }
     58    static String toString(long type) { return String::number(type); }
     59};
     60
    3461template<>
    3562struct SVGPropertyTraits<SVGLength> {
    36     static SVGLength& initialValue()
    37     {
    38         DEFINE_STATIC_LOCAL(SVGLength, s_initialValue, ());
    39         s_initialValue = SVGLength();
    40         return s_initialValue;
    41     }
    42 
     63    static SVGLength initialValue() { return SVGLength(); }
    4364    static String toString(const SVGLength& type) { return type.valueAsString(); }
    4465};
    4566
    46 // SVGAnimatedLengthList
    4767template<>
    4868struct SVGPropertyTraits<SVGLengthList> {
    4969    typedef SVGLength ListItemType;
    5070
    51     static SVGLengthList& initialValue()
     71    static SVGLengthList initialValue() { return SVGLengthList(); }
     72    static String toString(const SVGLengthList& type) { return type.valueAsString(); }
     73};
     74
     75template<>
     76struct SVGPropertyTraits<float> {
     77    static float initialValue() { return 0; }
     78    static String toString(float type) { return String::number(type); }
     79};
     80
     81template<>
     82struct SVGPropertyTraits<SVGPreserveAspectRatio> {
     83    static SVGPreserveAspectRatio initialValue() { return SVGPreserveAspectRatio(); }
     84    static String toString(const SVGPreserveAspectRatio& type) { return type.valueAsString(); }
     85};
     86
     87template<>
     88struct SVGPropertyTraits<FloatRect> {
     89    static FloatRect initialValue() { return FloatRect(); }
     90    static String toString(const FloatRect& type)
    5291    {
    53         DEFINE_STATIC_LOCAL(SVGLengthList, s_initialValue, ());
    54         s_initialValue = SVGLengthList();
    55         return s_initialValue;
     92        StringBuilder builder;
     93        builder.append(String::number(type.x()));
     94        builder.append(' ');
     95        builder.append(String::number(type.y()));
     96        builder.append(' ');
     97        builder.append(String::number(type.width()));
     98        builder.append(' ');
     99        builder.append(String::number(type.height()));
     100        builder.append(' ');
     101        return builder.toString();
    56102    }
     103};
    57104
    58     static String toString(const SVGLengthList& type) { return type.valueAsString(); }
     105template<>
     106struct SVGPropertyTraits<String> {
     107    static String initialValue() { return String(); }
     108    static String toString(const String& type) { return type; }
    59109};
    60110
Note: See TracChangeset for help on using the changeset viewer.