OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "wtf/TypeTraits.h" | 37 #include "wtf/TypeTraits.h" |
38 | 38 |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 template<typename ItemProperty> | 41 template<typename ItemProperty> |
42 class ListItemPropertyTraits { | 42 class ListItemPropertyTraits { |
43 public: | 43 public: |
44 typedef ItemProperty ItemPropertyType; | 44 typedef ItemProperty ItemPropertyType; |
45 typedef typename ItemPropertyType::TearOffType ItemTearOffType; | 45 typedef typename ItemPropertyType::TearOffType ItemTearOffType; |
46 | 46 |
47 static PassRefPtr<ItemPropertyType> getValueForInsertionFromTearOff(PassRefP
tr<ItemTearOffType> passNewItem) | 47 static PassRefPtr<ItemPropertyType> getValueForInsertionFromTearOff(PassRefP
tr<ItemTearOffType> passNewItem, SVGElement* contextElement, const QualifiedName
& attributeName) |
48 { | 48 { |
49 RefPtr<ItemTearOffType> newItem = passNewItem; | 49 RefPtr<ItemTearOffType> newItem = passNewItem; |
50 | 50 |
51 // |newItem| is immutable, OR | 51 // |newItem| is immutable, OR |
52 // |newItem| belongs to a SVGElement, but it does not belong to an anima
ted list | 52 // |newItem| belongs to a SVGElement, but it does not belong to an anima
ted list |
53 // (for example: "textElement.x.baseVal.appendItem(rectElement.width.bas
eVal)") | 53 // (for example: "textElement.x.baseVal.appendItem(rectElement.width.bas
eVal)") |
54 if (newItem->isImmutable() | 54 if (newItem->isImmutable() |
55 || (newItem->contextElement() && !newItem->target()->ownerList())) { | 55 || (newItem->contextElement() && !newItem->target()->ownerList())) { |
56 // We have to copy the incoming |newItem|, | 56 // We have to copy the incoming |newItem|, |
57 // Otherwise we'll end up having two tearoffs that operate on the sa
me SVGProperty. Consider the example above: | 57 // Otherwise we'll end up having two tearoffs that operate on the sa
me SVGProperty. Consider the example below: |
58 // SVGRectElements SVGAnimatedLength 'width' property baseVal points
to the same tear off object | 58 // SVGRectElements SVGAnimatedLength 'width' property baseVal points
to the same tear off object |
59 // that's inserted into SVGTextElements SVGAnimatedLengthList 'x'. t
extElement.x.baseVal.getItem(0).value += 150 would | 59 // that's inserted into SVGTextElements SVGAnimatedLengthList 'x'. t
extElement.x.baseVal.getItem(0).value += 150 would |
60 // mutate the rectElement width _and_ the textElement x list. That's
obviously wrong, take care of that. | 60 // mutate the rectElement width _and_ the textElement x list. That's
obviously wrong, take care of that. |
61 return newItem->target()->clone(); | 61 return newItem->target()->clone(); |
62 } | 62 } |
63 | 63 |
| 64 newItem->attachToSVGElementAttribute(contextElement, attributeName); |
64 return newItem->target(); | 65 return newItem->target(); |
65 } | 66 } |
66 | 67 |
67 static PassRefPtr<ItemTearOffType> createTearOff(PassRefPtr<ItemPropertyType
> value, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, co
nst QualifiedName& attributeName) | 68 static PassRefPtr<ItemTearOffType> createTearOff(PassRefPtr<ItemPropertyType
> value, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, co
nst QualifiedName& attributeName) |
68 { | 69 { |
69 return ItemTearOffType::create(value, contextElement, propertyIsAnimVal,
attributeName); | 70 return ItemTearOffType::create(value, contextElement, propertyIsAnimVal,
attributeName); |
70 } | 71 } |
71 }; | 72 }; |
72 | 73 |
73 template<typename Derived, typename ListProperty> | 74 template<typename Derived, typename ListProperty> |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 196 |
196 return createItemTearOff(value.release()); | 197 return createItemTearOff(value.release()); |
197 } | 198 } |
198 | 199 |
199 protected: | 200 protected: |
200 SVGListPropertyTearOffHelper(PassRefPtr<ListPropertyType> target, SVGElement
* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName&
attributeName = nullQName()) | 201 SVGListPropertyTearOffHelper(PassRefPtr<ListPropertyType> target, SVGElement
* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName&
attributeName = nullQName()) |
201 : SVGPropertyTearOff<ListPropertyType>(target, contextElement, propertyI
sAnimVal, attributeName) | 202 : SVGPropertyTearOff<ListPropertyType>(target, contextElement, propertyI
sAnimVal, attributeName) |
202 { | 203 { |
203 } | 204 } |
204 | 205 |
205 static PassRefPtr<ItemPropertyType> getValueForInsertionFromTearOff(PassRefP
tr<ItemTearOffType> passNewItem) | 206 PassRefPtr<ItemPropertyType> getValueForInsertionFromTearOff(PassRefPtr<Item
TearOffType> passNewItem) |
206 { | 207 { |
207 return ItemTraits::getValueForInsertionFromTearOff(passNewItem); | 208 return ItemTraits::getValueForInsertionFromTearOff(passNewItem, toDerive
d()->contextElement(), toDerived()->attributeName()); |
208 } | 209 } |
209 | 210 |
210 PassRefPtr<ItemTearOffType> createItemTearOff(PassRefPtr<ItemPropertyType> v
alue) | 211 PassRefPtr<ItemTearOffType> createItemTearOff(PassRefPtr<ItemPropertyType> v
alue) |
211 { | 212 { |
212 if (!value) | 213 if (!value) |
213 return nullptr; | 214 return nullptr; |
214 | 215 |
215 return ItemTraits::createTearOff(value, toDerived()->contextElement(), t
oDerived()->propertyIsAnimVal(), toDerived()->attributeName()); | 216 if (value->ownerList() == toDerived()->target()) |
| 217 return ItemTraits::createTearOff(value, toDerived()->contextElement(
), toDerived()->propertyIsAnimVal(), toDerived()->attributeName()); |
| 218 |
| 219 return ItemTraits::createTearOff(value, 0, PropertyIsNotAnimVal, nullQNa
me()); |
216 } | 220 } |
217 | 221 |
218 private: | 222 private: |
219 Derived* toDerived() { return static_cast<Derived*>(this); } | 223 Derived* toDerived() { return static_cast<Derived*>(this); } |
220 }; | 224 }; |
221 | 225 |
222 } | 226 } |
223 | 227 |
224 #endif // SVGListPropertyTearOffHelper_h | 228 #endif // SVGListPropertyTearOffHelper_h |
OLD | NEW |