Changeset 70303 in webkit
- Timestamp:
- Oct 22, 2010 6:26:25 AM (13 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r70302 r70303 1 2010-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 1 38 2010-10-22 Sheriff Bot <webkit.review.bot@gmail.com> 2 39 -
trunk/WebCore/svg/properties/SVGAnimatedProperty.h
r70223 r70303 59 59 60 60 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) 62 62 { 63 SVGAnimatedPropertyDescription key(element, attribute Name.localName());63 SVGAnimatedPropertyDescription key(element, attributeIdentifier); 64 64 RefPtr<SVGAnimatedProperty> wrapper = animatedPropertyCache()->get(key); 65 65 if (!wrapper) { … … 72 72 73 73 template<typename TearOffType> 74 static TearOffType* lookupWrapper(SVGElement* element, const QualifiedName& attributeName)74 static TearOffType* lookupWrapper(SVGElement* element, const AtomicString& attributeIdentifier) 75 75 { 76 SVGAnimatedPropertyDescription key(element, attribute Name.localName());76 SVGAnimatedPropertyDescription key(element, attributeIdentifier); 77 77 return static_pointer_cast<TearOffType>(animatedPropertyCache()->get(key)).get(); 78 78 } -
trunk/WebCore/svg/properties/SVGAnimatedPropertyMacros.h
r70223 r70303 27 27 #include "SVGAnimatedPropertySynchronizer.h" 28 28 #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 29 30 #include "SVGPropertyTraits.h" 30 31 … … 58 59 59 60 // 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) \ 61 62 public: \ 62 63 PropertyType& LowerProperty() const \ … … 87 88 { \ 88 89 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); \ 90 91 } \ 91 92 private: \ … … 93 94 94 95 #define DECLARE_ANIMATED_PROPERTY_NEW(OwnerType, DOMAttribute, PropertyType, UpperProperty, LowerProperty) \ 95 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGAnimatedPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty) 96 DECLARE_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) \ 99 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGDOMAttributeIdentifier, SVGAnimatedPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty) 96 100 97 101 #define DECLARE_ANIMATED_LIST_PROPERTY_NEW(OwnerType, DOMAttribute, PropertyType, UpperProperty, LowerProperty) \ 98 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, SVGAnimatedListPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty) \102 DECLARE_ANIMATED_PROPERTY_NEW_SHARED(OwnerType, DOMAttribute, DOMAttribute.localName(), SVGAnimatedListPropertyTearOff<PropertyType>, PropertyType, UpperProperty, LowerProperty) \ 99 103 \ 100 104 void detachAnimated##UpperProperty##ListWrappers(unsigned newListSize) \ 101 105 { \ 102 SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGAnimatedListPropertyTearOff<PropertyType> >(this, DOMAttribute ); \106 SVGAnimatedProperty* wrapper = SVGAnimatedProperty::lookupWrapper<SVGAnimatedListPropertyTearOff<PropertyType> >(this, DOMAttribute.localName()); \ 103 107 if (!wrapper) \ 104 108 return; \ -
trunk/WebCore/svg/properties/SVGAnimatedPropertySynchronizer.h
r70135 r70303 20 20 #ifndef SVGAnimatedPropertySynchronizer_h 21 21 #define SVGAnimatedPropertySynchronizer_h 22 23 #include "DeprecatedSVGAnimatedPropertyTraits.h"24 22 25 23 #if ENABLE(SVG) -
trunk/WebCore/svg/properties/SVGListPropertyTearOff.h
r70223 r70303 42 42 typedef Vector<RefPtr<ListItemTearOff> > ListWrapperCache; 43 43 44 // Used for [SVGAnimatedProperty] types (for example: SVGAnimatedLengthList::baseVal()) 44 45 static PassRefPtr<Self> create(SVGAnimatedProperty* animatedProperty, SVGPropertyRole role, PropertyType& values) 45 46 { … … 48 49 } 49 50 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 50 57 int removeItemFromList(ListItemTearOff* removeItem, bool shouldSynchronizeWrappers) 51 58 { 52 59 // Lookup item in cache and remove its corresponding wrapper. 53 60 unsigned size = m_wrappers.size(); 54 ASSERT(size == m_values .size());61 ASSERT(size == m_values->size()); 55 62 for (unsigned i = 0; i < size; ++i) { 56 63 RefPtr<ListItemTearOff>& item = m_wrappers.at(i); … … 60 67 item->detachWrapper(); 61 68 m_wrappers.remove(i); 62 m_values .remove(i);69 m_values->remove(i); 63 70 64 71 if (shouldSynchronizeWrappers) … … 75 82 // See SVGPropertyTearOff::detachWrapper() for an explaination what's happening here. 76 83 unsigned size = m_wrappers.size(); 77 ASSERT(size == m_values .size());84 ASSERT(size == m_values->size()); 78 85 for (unsigned i = 0; i < size; ++i) { 79 86 RefPtr<ListItemTearOff>& item = m_wrappers.at(i); … … 99 106 100 107 detachListWrappers(0); 101 m_values .clear();108 m_values->clear(); 102 109 } 103 110 104 111 unsigned numberOfItems() const 105 112 { 106 return m_values .size();113 return m_values->size(); 107 114 } 108 115 … … 121 128 122 129 RefPtr<ListItemTearOff> newItem = passNewItem; 123 ASSERT(m_values .size() == m_wrappers.size());130 ASSERT(m_values->size() == m_wrappers.size()); 124 131 125 132 // Spec: If the inserted item is already in a list, it is removed from its previous list before it is inserted into this list. … … 128 135 // Spec: Clears all existing current items from the list and re-initializes the list to hold the single item specified by the parameter. 129 136 detachListWrappers(0); 130 m_values .clear();137 m_values->clear(); 131 138 132 m_values .append(newItem->propertyReference());139 m_values->append(newItem->propertyReference()); 133 140 m_wrappers.append(newItem); 134 141 … … 139 146 PassListItemTearOff getItem(unsigned index, ExceptionCode& ec) 140 147 { 141 if (index >= m_values .size()) {148 if (index >= m_values->size()) { 142 149 ec = INDEX_SIZE_ERR; 143 150 return 0; … … 146 153 // Spec: Returns the specified item from the list. The returned item is the item itself and not a copy. 147 154 // 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()); 149 156 RefPtr<ListItemTearOff> wrapper = m_wrappers.at(index); 150 157 if (!wrapper) { … … 152 159 // It is also associated with our animated property, so it can notify the SVG Element which holds the SVGAnimated*List 153 160 // 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)); 155 162 m_wrappers.at(index) = wrapper; 156 163 } … … 173 180 174 181 // 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(); 177 184 178 185 RefPtr<ListItemTearOff> newItem = passNewItem; 179 ASSERT(m_values .size() == m_wrappers.size());186 ASSERT(m_values->size() == m_wrappers.size()); 180 187 181 188 // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. … … 184 191 // 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 185 192 // 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()); 187 194 188 195 // Store new wrapper at position 'index', change its underlying value, so mutations of newItem, directly affect the item in the list. … … 200 207 } 201 208 202 if (index >= m_values .size()) {209 if (index >= m_values->size()) { 203 210 ec = INDEX_SIZE_ERR; 204 211 return 0; … … 212 219 213 220 RefPtr<ListItemTearOff> newItem = passNewItem; 214 ASSERT(m_values .size() == m_wrappers.size());221 ASSERT(m_values->size() == m_wrappers.size()); 215 222 216 223 // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. … … 224 231 225 232 // 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(); 227 234 m_wrappers.at(index) = newItem; 228 235 … … 238 245 } 239 246 240 if (index >= m_values .size()) {247 if (index >= m_values->size()) { 241 248 ec = INDEX_SIZE_ERR; 242 249 return 0; 243 250 } 244 251 245 ASSERT(m_values .size() == m_wrappers.size());252 ASSERT(m_values->size() == m_wrappers.size()); 246 253 247 254 // Detach the existing wrapper. … … 252 259 } 253 260 254 m_values .remove(index);261 m_values->remove(index); 255 262 256 263 commitChange(); … … 272 279 273 280 RefPtr<ListItemTearOff> newItem = passNewItem; 274 ASSERT(m_values .size() == m_wrappers.size());281 ASSERT(m_values->size() == m_wrappers.size()); 275 282 276 283 // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. … … 278 285 279 286 // Append the value and wrapper at the end of the list. 280 m_values .append(newItem->propertyReference());287 m_values->append(newItem->propertyReference()); 281 288 m_wrappers.append(newItem); 282 289 … … 289 296 : m_animatedProperty(animatedProperty) 290 297 , 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. 293 303 if (!values.isEmpty()) 294 304 m_wrappers.fill(0, values.size()); 295 305 } 296 306 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 297 321 void commitChange() 298 322 { 299 323 // Update existing wrappers, as the index in the m_values list has changed. 300 324 unsigned size = m_wrappers.size(); 301 ASSERT(size == m_values .size());325 ASSERT(size == m_values->size()); 302 326 for (unsigned i = 0; i < size; ++i) { 303 327 RefPtr<ListItemTearOff>& item = m_wrappers.at(i); … … 305 329 continue; 306 330 item->setAnimatedProperty(m_animatedProperty.get()); 307 item->setValue(m_values .at(i));331 item->setValue(m_values->at(i)); 308 332 } 309 333 … … 348 372 349 373 // 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; 351 376 352 377 // A list of wrappers, which is always in sync between m_values. -
trunk/WebCore/svg/properties/SVGPropertyTearOff.h
r70223 r70303 22 22 23 23 #if ENABLE(SVG) 24 #include "SVGAnimatedProperty.h" 24 25 #include "SVGElement.h" 25 26 #include "SVGProperty.h" 26 27 27 28 namespace WebCore { 28 29 class SVGAnimatedProperty;30 29 31 30 template<typename PropertyType> … … 42 41 } 43 42 44 // Used for [SVGLiveProperty] types (for example: SVGSVGElement::createSVGLength()).43 // Used for non-animated POD types (for example: SVGLength). 45 44 static PassRefPtr<Self> create(const PropertyType& initialValue) 46 45 { -
trunk/WebCore/svg/properties/SVGPropertyTraits.h
r70223 r70303 23 23 24 24 #if ENABLE(SVG) 25 #include "FloatRect.h" 26 #include "SVGAngle.h" 25 27 #include "SVGLength.h" 26 28 #include "SVGLengthList.h" 29 #include "SVGPreserveAspectRatio.h" 30 #include <wtf/text/StringBuilder.h> 27 31 28 32 namespace WebCore { … … 31 35 struct SVGPropertyTraits { }; 32 36 33 // SVGAnimatedLength 37 template<> 38 struct SVGPropertyTraits<SVGAngle> { 39 static SVGAngle initialValue() { return SVGAngle(); } 40 static String toString(const SVGAngle& type) { return type.valueAsString(); } 41 }; 42 43 template<> 44 struct SVGPropertyTraits<bool> { 45 static bool initialValue() { return false; } 46 static String toString(bool type) { return type ? "true" : "false"; } 47 }; 48 49 template<> 50 struct SVGPropertyTraits<int> { 51 static int initialValue() { return 0; } 52 static String toString(int type) { return String::number(type); } 53 }; 54 55 template<> 56 struct SVGPropertyTraits<long> { 57 static long initialValue() { return 0; } 58 static String toString(long type) { return String::number(type); } 59 }; 60 34 61 template<> 35 62 struct 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(); } 43 64 static String toString(const SVGLength& type) { return type.valueAsString(); } 44 65 }; 45 66 46 // SVGAnimatedLengthList47 67 template<> 48 68 struct SVGPropertyTraits<SVGLengthList> { 49 69 typedef SVGLength ListItemType; 50 70 51 static SVGLengthList& initialValue() 71 static SVGLengthList initialValue() { return SVGLengthList(); } 72 static String toString(const SVGLengthList& type) { return type.valueAsString(); } 73 }; 74 75 template<> 76 struct SVGPropertyTraits<float> { 77 static float initialValue() { return 0; } 78 static String toString(float type) { return String::number(type); } 79 }; 80 81 template<> 82 struct SVGPropertyTraits<SVGPreserveAspectRatio> { 83 static SVGPreserveAspectRatio initialValue() { return SVGPreserveAspectRatio(); } 84 static String toString(const SVGPreserveAspectRatio& type) { return type.valueAsString(); } 85 }; 86 87 template<> 88 struct SVGPropertyTraits<FloatRect> { 89 static FloatRect initialValue() { return FloatRect(); } 90 static String toString(const FloatRect& type) 52 91 { 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(); 56 102 } 103 }; 57 104 58 static String toString(const SVGLengthList& type) { return type.valueAsString(); } 105 template<> 106 struct SVGPropertyTraits<String> { 107 static String initialValue() { return String(); } 108 static String toString(const String& type) { return type; } 59 109 }; 60 110
Note: See TracChangeset
for help on using the changeset viewer.