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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 toDerived()->target()->clear(); | 96 toDerived()->target()->clear(); |
97 } | 97 } |
98 | 98 |
99 PassRefPtr<ItemTearOffType> initialize(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) | 99 PassRefPtr<ItemTearOffType> initialize(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) |
100 { | 100 { |
101 RefPtr<ItemTearOffType> item = passItem; | 101 RefPtr<ItemTearOffType> item = passItem; |
102 | 102 |
103 if (toDerived()->isImmutable()) { | 103 if (toDerived()->isImmutable()) { |
104 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 104 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
105 return 0; | 105 return nullptr; |
106 } | 106 } |
107 | 107 |
108 if (!item) { | 108 if (!item) { |
109 exceptionState.throwTypeError("Lists must be initialized with a vali
d item."); | 109 exceptionState.throwTypeError("Lists must be initialized with a vali
d item."); |
110 return 0; | 110 return nullptr; |
111 } | 111 } |
112 | 112 |
113 RefPtr<ItemPropertyType> value = toDerived()->target()->initialize(getVa
lueForInsertionFromTearOff(item)); | 113 RefPtr<ItemPropertyType> value = toDerived()->target()->initialize(getVa
lueForInsertionFromTearOff(item)); |
114 toDerived()->commitChange(); | 114 toDerived()->commitChange(); |
115 | 115 |
116 return createItemTearOff(value.release()); | 116 return createItemTearOff(value.release()); |
117 } | 117 } |
118 | 118 |
119 PassRefPtr<ItemTearOffType> getItem(unsigned long index, ExceptionState& exc
eptionState) | 119 PassRefPtr<ItemTearOffType> getItem(unsigned long index, ExceptionState& exc
eptionState) |
120 { | 120 { |
121 RefPtr<ItemPropertyType> value = toDerived()->target()->getItem(index, e
xceptionState); | 121 RefPtr<ItemPropertyType> value = toDerived()->target()->getItem(index, e
xceptionState); |
122 return createItemTearOff(value.release()); | 122 return createItemTearOff(value.release()); |
123 } | 123 } |
124 | 124 |
125 PassRefPtr<ItemTearOffType> insertItemBefore(PassRefPtr<ItemTearOffType> pas
sItem, unsigned long index, ExceptionState& exceptionState) | 125 PassRefPtr<ItemTearOffType> insertItemBefore(PassRefPtr<ItemTearOffType> pas
sItem, unsigned long index, ExceptionState& exceptionState) |
126 { | 126 { |
127 RefPtr<ItemTearOffType> item = passItem; | 127 RefPtr<ItemTearOffType> item = passItem; |
128 | 128 |
129 if (toDerived()->isImmutable()) { | 129 if (toDerived()->isImmutable()) { |
130 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 130 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
131 return 0; | 131 return nullptr; |
132 } | 132 } |
133 | 133 |
134 if (!item) { | 134 if (!item) { |
135 exceptionState.throwTypeError("An invalid item cannot be inserted to
a list."); | 135 exceptionState.throwTypeError("An invalid item cannot be inserted to
a list."); |
136 return 0; | 136 return nullptr; |
137 } | 137 } |
138 | 138 |
139 RefPtr<ItemPropertyType> value = toDerived()->target()->insertItemBefore
(getValueForInsertionFromTearOff(item), index); | 139 RefPtr<ItemPropertyType> value = toDerived()->target()->insertItemBefore
(getValueForInsertionFromTearOff(item), index); |
140 toDerived()->commitChange(); | 140 toDerived()->commitChange(); |
141 | 141 |
142 return createItemTearOff(value.release()); | 142 return createItemTearOff(value.release()); |
143 } | 143 } |
144 | 144 |
145 PassRefPtr<ItemTearOffType> replaceItem(PassRefPtr<ItemTearOffType> passItem
, unsigned long index, ExceptionState& exceptionState) | 145 PassRefPtr<ItemTearOffType> replaceItem(PassRefPtr<ItemTearOffType> passItem
, unsigned long index, ExceptionState& exceptionState) |
146 { | 146 { |
147 RefPtr<ItemTearOffType> item = passItem; | 147 RefPtr<ItemTearOffType> item = passItem; |
148 | 148 |
149 if (toDerived()->isImmutable()) { | 149 if (toDerived()->isImmutable()) { |
150 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 150 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
151 return 0; | 151 return nullptr; |
152 } | 152 } |
153 | 153 |
154 if (!item) { | 154 if (!item) { |
155 exceptionState.throwTypeError("An invalid item cannot be replaced wi
th an existing list item."); | 155 exceptionState.throwTypeError("An invalid item cannot be replaced wi
th an existing list item."); |
156 return 0; | 156 return nullptr; |
157 } | 157 } |
158 | 158 |
159 RefPtr<ItemPropertyType> value = toDerived()->target()->replaceItem(getV
alueForInsertionFromTearOff(item), index, exceptionState); | 159 RefPtr<ItemPropertyType> value = toDerived()->target()->replaceItem(getV
alueForInsertionFromTearOff(item), index, exceptionState); |
160 toDerived()->commitChange(); | 160 toDerived()->commitChange(); |
161 | 161 |
162 return createItemTearOff(value.release()); | 162 return createItemTearOff(value.release()); |
163 } | 163 } |
164 | 164 |
165 PassRefPtr<ItemTearOffType> removeItem(unsigned long index, ExceptionState&
exceptionState) | 165 PassRefPtr<ItemTearOffType> removeItem(unsigned long index, ExceptionState&
exceptionState) |
166 { | 166 { |
167 RefPtr<ItemPropertyType> value = toDerived()->target()->removeItem(index
, exceptionState); | 167 RefPtr<ItemPropertyType> value = toDerived()->target()->removeItem(index
, exceptionState); |
168 toDerived()->commitChange(); | 168 toDerived()->commitChange(); |
169 | 169 |
170 return createItemTearOff(value.release()); | 170 return createItemTearOff(value.release()); |
171 } | 171 } |
172 | 172 |
173 PassRefPtr<ItemTearOffType> appendItem(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) | 173 PassRefPtr<ItemTearOffType> appendItem(PassRefPtr<ItemTearOffType> passItem,
ExceptionState& exceptionState) |
174 { | 174 { |
175 RefPtr<ItemTearOffType> item = passItem; | 175 RefPtr<ItemTearOffType> item = passItem; |
176 | 176 |
177 if (toDerived()->isImmutable()) { | 177 if (toDerived()->isImmutable()) { |
178 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); | 178 exceptionState.throwDOMException(NoModificationAllowedError, "The ob
ject is read-only."); |
179 return 0; | 179 return nullptr; |
180 } | 180 } |
181 | 181 |
182 if (!item) { | 182 if (!item) { |
183 exceptionState.throwTypeError("An invalid item cannot be appended to
a list."); | 183 exceptionState.throwTypeError("An invalid item cannot be appended to
a list."); |
184 return 0; | 184 return nullptr; |
185 } | 185 } |
186 | 186 |
187 RefPtr<ItemPropertyType> value = toDerived()->target()->appendItem(getVa
lueForInsertionFromTearOff(item)); | 187 RefPtr<ItemPropertyType> value = toDerived()->target()->appendItem(getVa
lueForInsertionFromTearOff(item)); |
188 toDerived()->commitChange(); | 188 toDerived()->commitChange(); |
189 | 189 |
190 return createItemTearOff(value.release()); | 190 return createItemTearOff(value.release()); |
191 } | 191 } |
192 | 192 |
193 protected: | 193 protected: |
194 NewSVGListPropertyTearOffHelper(PassRefPtr<ListPropertyType> target, SVGElem
ent* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedNam
e& attributeName = nullQName()) | 194 NewSVGListPropertyTearOffHelper(PassRefPtr<ListPropertyType> target, SVGElem
ent* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedNam
e& attributeName = nullQName()) |
195 : NewSVGPropertyTearOff<ListPropertyType>(target, contextElement, proper
tyIsAnimVal, attributeName) | 195 : NewSVGPropertyTearOff<ListPropertyType>(target, contextElement, proper
tyIsAnimVal, attributeName) |
196 { | 196 { |
197 } | 197 } |
198 | 198 |
199 static PassRefPtr<ItemPropertyType> getValueForInsertionFromTearOff(PassRefP
tr<ItemTearOffType> passNewItem) | 199 static PassRefPtr<ItemPropertyType> getValueForInsertionFromTearOff(PassRefP
tr<ItemTearOffType> passNewItem) |
200 { | 200 { |
201 return ItemTraits::getValueForInsertionFromTearOff(passNewItem); | 201 return ItemTraits::getValueForInsertionFromTearOff(passNewItem); |
202 } | 202 } |
203 | 203 |
204 PassRefPtr<ItemTearOffType> createItemTearOff(PassRefPtr<ItemPropertyType> v
alue) | 204 PassRefPtr<ItemTearOffType> createItemTearOff(PassRefPtr<ItemPropertyType> v
alue) |
205 { | 205 { |
206 if (!value) | 206 if (!value) |
207 return 0; | 207 return nullptr; |
208 | 208 |
209 return ItemTraits::createTearOff(value, toDerived()->contextElement(), t
oDerived()->propertyIsAnimVal(), toDerived()->attributeName()); | 209 return ItemTraits::createTearOff(value, toDerived()->contextElement(), t
oDerived()->propertyIsAnimVal(), toDerived()->attributeName()); |
210 } | 210 } |
211 | 211 |
212 private: | 212 private: |
213 Derived* toDerived() { return static_cast<Derived*>(this); } | 213 Derived* toDerived() { return static_cast<Derived*>(this); } |
214 }; | 214 }; |
215 | 215 |
216 } | 216 } |
217 | 217 |
218 #endif // NewSVGListPropertyTearOffHelper_h | 218 #endif // NewSVGListPropertyTearOffHelper_h |
OLD | NEW |