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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 // WebIDL requires "unsigned long" type instead of size_t. | 49 // WebIDL requires "unsigned long" type instead of size_t. |
50 unsigned long numberOfItems() | 50 unsigned long numberOfItems() |
51 { | 51 { |
52 return toDerived()->target()->numberOfItems(); | 52 return toDerived()->target()->numberOfItems(); |
53 } | 53 } |
54 | 54 |
55 void clear(ExceptionState& exceptionState) | 55 void clear(ExceptionState& exceptionState) |
56 { | 56 { |
57 if (toDerived()->isImmutable()) { | 57 if (toDerived()->isImmutable()) { |
58 exceptionState.throwDOMException(NoModificationAllowedError, Excepti
onMessages::failedToExecute("clear", Derived::propertyTypeName(), "The object is
read-only.")); | 58 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
59 return; | 59 return; |
60 } | 60 } |
61 | 61 |
62 toDerived()->target()->clear(); | 62 toDerived()->target()->clear(); |
63 } | 63 } |
64 | 64 |
65 PassRefPtr<ItemTearOffType> initialize(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) | 65 PassRefPtr<ItemTearOffType> initialize(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) |
66 { | 66 { |
67 RefPtr<ItemTearOffType> item = passItem; | 67 RefPtr<ItemTearOffType> item = passItem; |
68 | 68 |
69 if (toDerived()->isImmutable()) { | 69 if (toDerived()->isImmutable()) { |
70 exceptionState.throwDOMException(NoModificationAllowedError, Excepti
onMessages::failedToExecute("initialize", Derived::propertyTypeName(), "The obje
ct is read-only.")); | 70 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
71 return 0; | 71 return 0; |
72 } | 72 } |
73 | 73 |
74 if (!item) { | 74 if (!item) { |
75 exceptionState.throwTypeError("Lists must be initialized with a vali
d item."); | 75 exceptionState.throwTypeError("Lists must be initialized with a vali
d item."); |
76 return 0; | 76 return 0; |
77 } | 77 } |
78 | 78 |
79 item = cloneIfNeeded(item); | 79 item = cloneIfNeeded(item); |
80 | 80 |
81 RefPtr<ListPropertyType> ownerList; | 81 RefPtr<ListPropertyType> ownerList; |
82 if (item->ownerList()) | 82 if (item->ownerList()) |
83 ownerList = Derived::upcastFrom(item->ownerList())->target(); | 83 ownerList = Derived::upcastFrom(item->ownerList())->target(); |
84 | 84 |
85 RefPtr<ItemPropertyType> value = toDerived()->target()->initialize(item-
>target(), ownerList); | 85 RefPtr<ItemPropertyType> value = toDerived()->target()->initialize(item-
>target(), ownerList); |
| 86 item->setOwnerList(this); |
86 toDerived()->commitChange(); | 87 toDerived()->commitChange(); |
87 | 88 |
88 return createItemTearOff(value.release()); | 89 return createItemTearOff(value.release()); |
89 } | 90 } |
90 | 91 |
91 PassRefPtr<ItemTearOffType> getItem(unsigned long index, ExceptionState& exc
eptionState) | 92 PassRefPtr<ItemTearOffType> getItem(unsigned long index, ExceptionState& exc
eptionState) |
92 { | 93 { |
93 RefPtr<ItemPropertyType> value = toDerived()->target()->getItem(index, e
xceptionState); | 94 RefPtr<ItemPropertyType> value = toDerived()->target()->getItem(index, e
xceptionState); |
94 return createItemTearOff(value.release()); | 95 return createItemTearOff(value.release()); |
95 } | 96 } |
96 | 97 |
97 PassRefPtr<ItemTearOffType> insertItemBefore(PassRefPtr<ItemTearOffType> pas
sItem, unsigned long index, ExceptionState& exceptionState) | 98 PassRefPtr<ItemTearOffType> insertItemBefore(PassRefPtr<ItemTearOffType> pas
sItem, unsigned long index, ExceptionState& exceptionState) |
98 { | 99 { |
99 RefPtr<ItemTearOffType> item = passItem; | 100 RefPtr<ItemTearOffType> item = passItem; |
100 | 101 |
101 if (toDerived()->isImmutable()) { | 102 if (toDerived()->isImmutable()) { |
102 exceptionState.throwDOMException(NoModificationAllowedError, Excepti
onMessages::failedToExecute("insertItemBefore", Derived::propertyTypeName(), "Th
e object is read-only.")); | 103 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
103 return 0; | 104 return 0; |
104 } | 105 } |
105 | 106 |
106 if (!item) { | 107 if (!item) { |
107 exceptionState.throwTypeError(ExceptionMessages::failedToExecute("in
sertItemBefore", Derived::propertyTypeName(), "An invalid item cannot be inserte
d to a list.")); | 108 exceptionState.throwTypeError("An invalid item cannot be inserted to
a list."); |
108 return 0; | 109 return 0; |
109 } | 110 } |
110 | 111 |
111 item = cloneIfNeeded(item); | 112 item = cloneIfNeeded(item); |
112 | 113 |
113 RefPtr<ListPropertyType> ownerList; | 114 RefPtr<ListPropertyType> ownerList; |
114 if (item->ownerList()) | 115 if (item->ownerList()) |
115 ownerList = Derived::upcastFrom(item->ownerList())->target(); | 116 ownerList = Derived::upcastFrom(item->ownerList())->target(); |
116 | 117 |
117 RefPtr<ItemPropertyType> value = toDerived()->target()->insertItemBefore
(item->target(), ownerList, index); | 118 RefPtr<ItemPropertyType> value = toDerived()->target()->insertItemBefore
(item->target(), ownerList, index); |
| 119 item->setOwnerList(this); |
118 toDerived()->commitChange(); | 120 toDerived()->commitChange(); |
119 | 121 |
120 return createItemTearOff(value.release()); | 122 return createItemTearOff(value.release()); |
121 } | 123 } |
122 | 124 |
123 PassRefPtr<ItemTearOffType> replaceItem(PassRefPtr<ItemTearOffType> passItem
, unsigned long index, ExceptionState& exceptionState) | 125 PassRefPtr<ItemTearOffType> replaceItem(PassRefPtr<ItemTearOffType> passItem
, unsigned long index, ExceptionState& exceptionState) |
124 { | 126 { |
125 RefPtr<ItemTearOffType> item = passItem; | 127 RefPtr<ItemTearOffType> item = passItem; |
126 | 128 |
127 if (toDerived()->isImmutable()) { | 129 if (toDerived()->isImmutable()) { |
128 exceptionState.throwDOMException(NoModificationAllowedError, Excepti
onMessages::failedToExecute("replaceItem", Derived::propertyTypeName(), "The obj
ect is read-only.")); | 130 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
129 return 0; | 131 return 0; |
130 } | 132 } |
131 | 133 |
132 if (!item) { | 134 if (!item) { |
133 exceptionState.throwTypeError(ExceptionMessages::failedToExecute("re
placeItem", Derived::propertyTypeName(), "An invalid item cannot be replaced wit
h an existing list item.")); | 135 exceptionState.throwTypeError("An invalid item cannot be replaced wi
th an existing list item."); |
134 return 0; | 136 return 0; |
135 } | 137 } |
136 | 138 |
137 item = cloneIfNeeded(item); | 139 item = cloneIfNeeded(item); |
138 | 140 |
139 RefPtr<ListPropertyType> ownerList; | 141 RefPtr<ListPropertyType> ownerList; |
140 if (item->ownerList()) | 142 if (item->ownerList()) |
141 ownerList = Derived::upcastFrom(item->ownerList())->target(); | 143 ownerList = Derived::upcastFrom(item->ownerList())->target(); |
142 | 144 |
143 RefPtr<ItemPropertyType> value = toDerived()->target()->replaceItem(item
->target(), ownerList, index, exceptionState); | 145 RefPtr<ItemPropertyType> value = toDerived()->target()->replaceItem(item
->target(), ownerList, index, exceptionState); |
| 146 item->setOwnerList(this); |
144 toDerived()->commitChange(); | 147 toDerived()->commitChange(); |
145 | 148 |
146 return createItemTearOff(value.release()); | 149 return createItemTearOff(value.release()); |
147 } | 150 } |
148 | 151 |
149 PassRefPtr<ItemTearOffType> removeItem(unsigned long index, ExceptionState&
exceptionState) | 152 PassRefPtr<ItemTearOffType> removeItem(unsigned long index, ExceptionState&
exceptionState) |
150 { | 153 { |
151 RefPtr<ItemPropertyType> value = toDerived()->target()->removeItem(index
, exceptionState); | 154 RefPtr<ItemPropertyType> value = toDerived()->target()->removeItem(index
, exceptionState); |
152 toDerived()->commitChange(); | 155 toDerived()->commitChange(); |
153 | 156 |
154 return createItemTearOff(value.release()); | 157 return createItemTearOff(value.release(), false); |
155 } | 158 } |
156 | 159 |
157 PassRefPtr<ItemTearOffType> appendItem(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) | 160 PassRefPtr<ItemTearOffType> appendItem(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) |
158 { | 161 { |
159 RefPtr<ItemTearOffType> item = passItem; | 162 RefPtr<ItemTearOffType> item = passItem; |
160 | 163 |
161 if (toDerived()->isImmutable()) { | 164 if (toDerived()->isImmutable()) { |
162 exceptionState.throwDOMException(NoModificationAllowedError, Excepti
onMessages::failedToExecute("appendItem", Derived::propertyTypeName(), "The obje
ct is read-only.")); | 165 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
163 return 0; | 166 return 0; |
164 } | 167 } |
165 | 168 |
166 if (!item) { | 169 if (!item) { |
167 exceptionState.throwTypeError(ExceptionMessages::failedToExecute("ap
pendItem", Derived::propertyTypeName(), "An invalid item cannot be appended to a
list.")); | 170 exceptionState.throwTypeError("An invalid item cannot be appended to
a list."); |
168 return 0; | 171 return 0; |
169 } | 172 } |
170 | 173 |
171 item = cloneIfNeeded(item); | 174 item = cloneIfNeeded(item); |
172 | 175 |
173 RefPtr<ListPropertyType> ownerList; | 176 RefPtr<ListPropertyType> ownerList; |
174 if (item->ownerList()) | 177 if (item->ownerList()) |
175 ownerList = Derived::upcastFrom(item->ownerList())->target(); | 178 ownerList = Derived::upcastFrom(item->ownerList())->target(); |
176 | 179 |
177 RefPtr<ItemPropertyType> value = toDerived()->target()->appendItem(item-
>target(), ownerList); | 180 RefPtr<ItemPropertyType> value = toDerived()->target()->appendItem(item-
>target(), ownerList); |
| 181 item->setOwnerList(this); |
178 toDerived()->commitChange(); | 182 toDerived()->commitChange(); |
179 | 183 |
180 return createItemTearOff(value.release()); | 184 return createItemTearOff(value.release()); |
181 } | 185 } |
182 | 186 |
183 protected: | 187 protected: |
184 NewSVGListPropertyTearOffHelper(PassRefPtr<ListPropertyType> target, SVGElem
ent* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedNam
e& attributeName = nullQName()) | 188 NewSVGListPropertyTearOffHelper(PassRefPtr<ListPropertyType> target, SVGElem
ent* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedNam
e& attributeName = nullQName()) |
185 : NewSVGPropertyTearOff<ListPropertyType>(target, contextElement, proper
tyIsAnimVal, attributeName) | 189 : NewSVGPropertyTearOff<ListPropertyType>(target, contextElement, proper
tyIsAnimVal, attributeName) |
186 { | 190 { |
187 } | 191 } |
(...skipping 11 matching lines...) Expand all Loading... |
199 // Otherwise we'll end up having two tearoffs that operate on the sa
me SVGProperty. Consider the example above: | 203 // Otherwise we'll end up having two tearoffs that operate on the sa
me SVGProperty. Consider the example above: |
200 // SVGRectElements SVGAnimatedLength 'width' property baseVal points
to the same tear off object | 204 // SVGRectElements SVGAnimatedLength 'width' property baseVal points
to the same tear off object |
201 // that's inserted into SVGTextElements SVGAnimatedLengthList 'x'. t
extElement.x.baseVal.getItem(0).value += 150 would | 205 // that's inserted into SVGTextElements SVGAnimatedLengthList 'x'. t
extElement.x.baseVal.getItem(0).value += 150 would |
202 // mutate the rectElement width _and_ the textElement x list. That's
obviously wrong, take care of that. | 206 // mutate the rectElement width _and_ the textElement x list. That's
obviously wrong, take care of that. |
203 return ItemTearOffType::create(newItem->target()->clone(), toDerived
()->contextElement(), toDerived()->propertyIsAnimVal(), toDerived()->attributeNa
me()); | 207 return ItemTearOffType::create(newItem->target()->clone(), toDerived
()->contextElement(), toDerived()->propertyIsAnimVal(), toDerived()->attributeNa
me()); |
204 } | 208 } |
205 | 209 |
206 return newItem.release(); | 210 return newItem.release(); |
207 } | 211 } |
208 | 212 |
209 PassRefPtr<ItemTearOffType> createItemTearOff(PassRefPtr<ItemPropertyType> v
alue) | 213 PassRefPtr<ItemTearOffType> createItemTearOff(PassRefPtr<ItemPropertyType> v
alue, bool setOwnerList = true) |
210 { | 214 { |
211 if (!value) | 215 if (!value) |
212 return 0; | 216 return 0; |
213 | 217 |
214 RefPtr<ItemTearOffType> tearoff = ItemTearOffType::create(value, toDeriv
ed()->contextElement(), toDerived()->propertyIsAnimVal(), toDerived()->attribute
Name()); | 218 RefPtr<ItemTearOffType> tearoff = ItemTearOffType::create(value, toDeriv
ed()->contextElement(), toDerived()->propertyIsAnimVal(), toDerived()->attribute
Name()); |
215 tearoff->setBelongingList(this); | 219 if (setOwnerList) |
| 220 tearoff->setOwnerList(this); |
216 return tearoff.release(); | 221 return tearoff.release(); |
217 } | 222 } |
218 | 223 |
219 private: | 224 private: |
220 Derived* toDerived() { return static_cast<Derived*>(this); } | 225 Derived* toDerived() { return static_cast<Derived*>(this); } |
| 226 |
| 227 static PassRefPtr<Derived> upcastFrom(PassRefPtr<NewSVGPropertyTearOffBase>
passBase) |
| 228 { |
| 229 RefPtr<NewSVGPropertyTearOffBase> base = passBase; |
| 230 ASSERT(base->type() == ListPropertyType::classType()); |
| 231 return static_pointer_cast<Derived>(base.release()); |
| 232 } |
221 }; | 233 }; |
222 | 234 |
223 } | 235 } |
224 | 236 |
225 #endif // NewSVGListPropertyTearOffHelper_h | 237 #endif // NewSVGListPropertyTearOffHelper_h |
OLD | NEW |