| 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 blink { | 39 namespace blink { |
| 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, SVGElement* contextElement, const QualifiedName
& attributeName) | 47 static PassRefPtrWillBeRawPtr<ItemPropertyType> getValueForInsertionFromTear
Off(PassRefPtrWillBeRawPtr<ItemTearOffType> passNewItem, SVGElement* contextElem
ent, const QualifiedName& attributeName) |
| 48 { | 48 { |
| 49 RefPtr<ItemTearOffType> newItem = passNewItem; | 49 RefPtrWillBeRawPtr<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 below: | 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 newItem->attachToSVGElementAttribute(contextElement, attributeName); |
| 65 return newItem->target(); | 65 return newItem->target(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 static PassRefPtr<ItemTearOffType> createTearOff(PassRefPtr<ItemPropertyType
> value, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, co
nst QualifiedName& attributeName) | 68 static PassRefPtrWillBeRawPtr<ItemTearOffType> createTearOff(PassRefPtrWillB
eRawPtr<ItemPropertyType> value, SVGElement* contextElement, PropertyIsAnimValTy
pe propertyIsAnimVal, const QualifiedName& attributeName) |
| 69 { | 69 { |
| 70 return ItemTearOffType::create(value, contextElement, propertyIsAnimVal,
attributeName); | 70 return ItemTearOffType::create(value, contextElement, propertyIsAnimVal,
attributeName); |
| 71 } | 71 } |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 template<typename Derived, typename ListProperty> | 74 template<typename Derived, typename ListProperty> |
| 75 class SVGListPropertyTearOffHelper : public SVGPropertyTearOff<ListProperty> { | 75 class SVGListPropertyTearOffHelper : public SVGPropertyTearOff<ListProperty> { |
| 76 public: | 76 public: |
| 77 typedef ListProperty ListPropertyType; | 77 typedef ListProperty ListPropertyType; |
| 78 typedef typename ListPropertyType::ItemPropertyType ItemPropertyType; | 78 typedef typename ListPropertyType::ItemPropertyType ItemPropertyType; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 void clear(ExceptionState& exceptionState) | 90 void clear(ExceptionState& exceptionState) |
| 91 { | 91 { |
| 92 if (toDerived()->isImmutable()) { | 92 if (toDerived()->isImmutable()) { |
| 93 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 93 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 | 96 |
| 97 toDerived()->target()->clear(); | 97 toDerived()->target()->clear(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 PassRefPtr<ItemTearOffType> initialize(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) | 100 PassRefPtrWillBeRawPtr<ItemTearOffType> initialize(PassRefPtrWillBeRawPtr<It
emTearOffType> passItem, ExceptionState& exceptionState) |
| 101 { | 101 { |
| 102 RefPtr<ItemTearOffType> item = passItem; | 102 RefPtrWillBeRawPtr<ItemTearOffType> item = passItem; |
| 103 | 103 |
| 104 if (toDerived()->isImmutable()) { | 104 if (toDerived()->isImmutable()) { |
| 105 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 105 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
| 106 return nullptr; | 106 return nullptr; |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (!item) { | 109 if (!item) { |
| 110 exceptionState.throwTypeError("Lists must be initialized with a vali
d item."); | 110 exceptionState.throwTypeError("Lists must be initialized with a vali
d item."); |
| 111 return nullptr; | 111 return nullptr; |
| 112 } | 112 } |
| 113 | 113 |
| 114 RefPtr<ItemPropertyType> value = toDerived()->target()->initialize(getVa
lueForInsertionFromTearOff(item)); | 114 RefPtrWillBeRawPtr<ItemPropertyType> value = toDerived()->target()->init
ialize(getValueForInsertionFromTearOff(item)); |
| 115 toDerived()->commitChange(); | 115 toDerived()->commitChange(); |
| 116 | 116 |
| 117 return createItemTearOff(value.release()); | 117 return createItemTearOff(value.release()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 PassRefPtr<ItemTearOffType> getItem(unsigned long index, ExceptionState& exc
eptionState) | 120 PassRefPtrWillBeRawPtr<ItemTearOffType> getItem(unsigned long index, Excepti
onState& exceptionState) |
| 121 { | 121 { |
| 122 RefPtr<ItemPropertyType> value = toDerived()->target()->getItem(index, e
xceptionState); | 122 RefPtrWillBeRawPtr<ItemPropertyType> value = toDerived()->target()->getI
tem(index, exceptionState); |
| 123 return createItemTearOff(value.release()); | 123 return createItemTearOff(value.release()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 PassRefPtr<ItemTearOffType> insertItemBefore(PassRefPtr<ItemTearOffType> pas
sItem, unsigned long index, ExceptionState& exceptionState) | 126 PassRefPtrWillBeRawPtr<ItemTearOffType> insertItemBefore(PassRefPtrWillBeRaw
Ptr<ItemTearOffType> passItem, unsigned long index, ExceptionState& exceptionSta
te) |
| 127 { | 127 { |
| 128 RefPtr<ItemTearOffType> item = passItem; | 128 RefPtrWillBeRawPtr<ItemTearOffType> item = passItem; |
| 129 | 129 |
| 130 if (toDerived()->isImmutable()) { | 130 if (toDerived()->isImmutable()) { |
| 131 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 131 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
| 132 return nullptr; | 132 return nullptr; |
| 133 } | 133 } |
| 134 | 134 |
| 135 if (!item) { | 135 if (!item) { |
| 136 exceptionState.throwTypeError("An invalid item cannot be inserted to
a list."); | 136 exceptionState.throwTypeError("An invalid item cannot be inserted to
a list."); |
| 137 return nullptr; | 137 return nullptr; |
| 138 } | 138 } |
| 139 | 139 |
| 140 RefPtr<ItemPropertyType> value = toDerived()->target()->insertItemBefore
(getValueForInsertionFromTearOff(item), index); | 140 RefPtrWillBeRawPtr<ItemPropertyType> value = toDerived()->target()->inse
rtItemBefore(getValueForInsertionFromTearOff(item), index); |
| 141 toDerived()->commitChange(); | 141 toDerived()->commitChange(); |
| 142 | 142 |
| 143 return createItemTearOff(value.release()); | 143 return createItemTearOff(value.release()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 PassRefPtr<ItemTearOffType> replaceItem(PassRefPtr<ItemTearOffType> passItem
, unsigned long index, ExceptionState& exceptionState) | 146 PassRefPtrWillBeRawPtr<ItemTearOffType> replaceItem(PassRefPtrWillBeRawPtr<I
temTearOffType> passItem, unsigned long index, ExceptionState& exceptionState) |
| 147 { | 147 { |
| 148 RefPtr<ItemTearOffType> item = passItem; | 148 RefPtrWillBeRawPtr<ItemTearOffType> item = passItem; |
| 149 | 149 |
| 150 if (toDerived()->isImmutable()) { | 150 if (toDerived()->isImmutable()) { |
| 151 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 151 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
| 152 return nullptr; | 152 return nullptr; |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (!item) { | 155 if (!item) { |
| 156 exceptionState.throwTypeError("An invalid item cannot be replaced wi
th an existing list item."); | 156 exceptionState.throwTypeError("An invalid item cannot be replaced wi
th an existing list item."); |
| 157 return nullptr; | 157 return nullptr; |
| 158 } | 158 } |
| 159 | 159 |
| 160 RefPtr<ItemPropertyType> value = toDerived()->target()->replaceItem(getV
alueForInsertionFromTearOff(item), index, exceptionState); | 160 RefPtrWillBeRawPtr<ItemPropertyType> value = toDerived()->target()->repl
aceItem(getValueForInsertionFromTearOff(item), index, exceptionState); |
| 161 toDerived()->commitChange(); | 161 toDerived()->commitChange(); |
| 162 | 162 |
| 163 return createItemTearOff(value.release()); | 163 return createItemTearOff(value.release()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 bool anonymousIndexedSetter(unsigned index, PassRefPtr<ItemTearOffType> pass
Item, ExceptionState& exceptionState) | 166 bool anonymousIndexedSetter(unsigned index, PassRefPtrWillBeRawPtr<ItemTearO
ffType> passItem, ExceptionState& exceptionState) |
| 167 { | 167 { |
| 168 replaceItem(passItem, index, exceptionState); | 168 replaceItem(passItem, index, exceptionState); |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 | 171 |
| 172 PassRefPtr<ItemTearOffType> removeItem(unsigned long index, ExceptionState&
exceptionState) | 172 PassRefPtrWillBeRawPtr<ItemTearOffType> removeItem(unsigned long index, Exce
ptionState& exceptionState) |
| 173 { | 173 { |
| 174 RefPtr<ItemPropertyType> value = toDerived()->target()->removeItem(index
, exceptionState); | 174 RefPtrWillBeRawPtr<ItemPropertyType> value = toDerived()->target()->remo
veItem(index, exceptionState); |
| 175 toDerived()->commitChange(); | 175 toDerived()->commitChange(); |
| 176 | 176 |
| 177 return createItemTearOff(value.release()); | 177 return createItemTearOff(value.release()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 PassRefPtr<ItemTearOffType> appendItem(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) | 180 PassRefPtrWillBeRawPtr<ItemTearOffType> appendItem(PassRefPtrWillBeRawPtr<It
emTearOffType> passItem, ExceptionState& exceptionState) |
| 181 { | 181 { |
| 182 RefPtr<ItemTearOffType> item = passItem; | 182 RefPtrWillBeRawPtr<ItemTearOffType> item = passItem; |
| 183 | 183 |
| 184 if (toDerived()->isImmutable()) { | 184 if (toDerived()->isImmutable()) { |
| 185 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 185 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
| 186 return nullptr; | 186 return nullptr; |
| 187 } | 187 } |
| 188 | 188 |
| 189 if (!item) { | 189 if (!item) { |
| 190 exceptionState.throwTypeError("An invalid item cannot be appended to
a list."); | 190 exceptionState.throwTypeError("An invalid item cannot be appended to
a list."); |
| 191 return nullptr; | 191 return nullptr; |
| 192 } | 192 } |
| 193 | 193 |
| 194 RefPtr<ItemPropertyType> value = toDerived()->target()->appendItem(getVa
lueForInsertionFromTearOff(item)); | 194 RefPtrWillBeRawPtr<ItemPropertyType> value = toDerived()->target()->appe
ndItem(getValueForInsertionFromTearOff(item)); |
| 195 toDerived()->commitChange(); | 195 toDerived()->commitChange(); |
| 196 | 196 |
| 197 return createItemTearOff(value.release()); | 197 return createItemTearOff(value.release()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 protected: | 200 protected: |
| 201 SVGListPropertyTearOffHelper(PassRefPtr<ListPropertyType> target, SVGElement
* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName&
attributeName = QualifiedName::null()) | 201 SVGListPropertyTearOffHelper(PassRefPtrWillBeRawPtr<ListPropertyType> target
, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qua
lifiedName& attributeName = QualifiedName::null()) |
| 202 : SVGPropertyTearOff<ListPropertyType>(target, contextElement, propertyI
sAnimVal, attributeName) | 202 : SVGPropertyTearOff<ListPropertyType>(target, contextElement, propertyI
sAnimVal, attributeName) |
| 203 { | 203 { |
| 204 } | 204 } |
| 205 | 205 |
| 206 PassRefPtr<ItemPropertyType> getValueForInsertionFromTearOff(PassRefPtr<Item
TearOffType> passNewItem) | 206 PassRefPtrWillBeRawPtr<ItemPropertyType> getValueForInsertionFromTearOff(Pas
sRefPtrWillBeRawPtr<ItemTearOffType> passNewItem) |
| 207 { | 207 { |
| 208 return ItemTraits::getValueForInsertionFromTearOff(passNewItem, toDerive
d()->contextElement(), toDerived()->attributeName()); | 208 return ItemTraits::getValueForInsertionFromTearOff(passNewItem, toDerive
d()->contextElement(), toDerived()->attributeName()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 PassRefPtr<ItemTearOffType> createItemTearOff(PassRefPtr<ItemPropertyType> v
alue) | 211 PassRefPtrWillBeRawPtr<ItemTearOffType> createItemTearOff(PassRefPtrWillBeRa
wPtr<ItemPropertyType> value) |
| 212 { | 212 { |
| 213 if (!value) | 213 if (!value) |
| 214 return nullptr; | 214 return nullptr; |
| 215 | 215 |
| 216 if (value->ownerList() == toDerived()->target()) | 216 if (value->ownerList() == toDerived()->target()) |
| 217 return ItemTraits::createTearOff(value, toDerived()->contextElement(
), toDerived()->propertyIsAnimVal(), toDerived()->attributeName()); | 217 return ItemTraits::createTearOff(value, toDerived()->contextElement(
), toDerived()->propertyIsAnimVal(), toDerived()->attributeName()); |
| 218 | 218 |
| 219 return ItemTraits::createTearOff(value, 0, PropertyIsNotAnimVal, Qualifi
edName::null()); | 219 return ItemTraits::createTearOff(value, 0, PropertyIsNotAnimVal, Qualifi
edName::null()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 private: | 222 private: |
| 223 Derived* toDerived() { return static_cast<Derived*>(this); } | 223 Derived* toDerived() { return static_cast<Derived*>(this); } |
| 224 }; | 224 }; |
| 225 | 225 |
| 226 } | 226 } |
| 227 | 227 |
| 228 #endif // SVGListPropertyTearOffHelper_h | 228 #endif // SVGListPropertyTearOffHelper_h |
| OLD | NEW |