OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // See SVGPropertyTearOff::detachWrapper() for an explanation about what
's happening here. | 57 // See SVGPropertyTearOff::detachWrapper() for an explanation about what
's happening here. |
58 ASSERT(wrappers); | 58 ASSERT(wrappers); |
59 unsigned size = wrappers->size(); | 59 unsigned size = wrappers->size(); |
60 for (unsigned i = 0; i < size; ++i) { | 60 for (unsigned i = 0; i < size; ++i) { |
61 if (ListItemTearOff* item = wrappers->at(i).get()) | 61 if (ListItemTearOff* item = wrappers->at(i).get()) |
62 item->detachWrapper(); | 62 item->detachWrapper(); |
63 } | 63 } |
64 | 64 |
65 // Reinitialize the wrapper cache to be equal to the new values size, af
ter the XML DOM changed the list. | 65 // Reinitialize the wrapper cache to be equal to the new values size, af
ter the XML DOM changed the list. |
66 if (newListSize) | 66 if (newListSize) |
67 wrappers->fill(0, newListSize); | 67 wrappers->fill(nullptr, newListSize); |
68 else | 68 else |
69 wrappers->clear(); | 69 wrappers->clear(); |
70 } | 70 } |
71 | 71 |
72 void detachListWrappers(unsigned newListSize) | 72 void detachListWrappers(unsigned newListSize) |
73 { | 73 { |
74 detachListWrappersAndResize(m_wrappers, newListSize); | 74 detachListWrappersAndResize(m_wrappers, newListSize); |
75 } | 75 } |
76 | 76 |
77 void setValuesAndWrappers(PropertyType* values, ListWrapperCache* wrappers,
bool shouldOwnValues) | 77 void setValuesAndWrappers(PropertyType* values, ListWrapperCache* wrappers,
bool shouldOwnValues) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 m_values->append(newItem); | 129 m_values->append(newItem); |
130 | 130 |
131 commitChange(); | 131 commitChange(); |
132 return newItem; | 132 return newItem; |
133 } | 133 } |
134 | 134 |
135 PassListItemTearOff initializeValuesAndWrappers(PassListItemTearOff passNewI
tem, ExceptionState& exceptionState) | 135 PassListItemTearOff initializeValuesAndWrappers(PassListItemTearOff passNewI
tem, ExceptionState& exceptionState) |
136 { | 136 { |
137 ASSERT(m_wrappers); | 137 ASSERT(m_wrappers); |
138 if (!canAlterList(exceptionState)) | 138 if (!canAlterList(exceptionState)) |
139 return 0; | 139 return nullptr; |
140 | 140 |
141 // Not specified, but FF/Opera do it this way, and it's just sane. | 141 // Not specified, but FF/Opera do it this way, and it's just sane. |
142 if (!passNewItem) { | 142 if (!passNewItem) { |
143 exceptionState.throwTypeError("The PassListItemType provided is inva
lid."); | 143 exceptionState.throwTypeError("The PassListItemType provided is inva
lid."); |
144 return 0; | 144 return nullptr; |
145 } | 145 } |
146 | 146 |
147 RefPtr<ListItemTearOff> newItem = passNewItem; | 147 RefPtr<ListItemTearOff> newItem = passNewItem; |
148 ASSERT(m_values->size() == m_wrappers->size()); | 148 ASSERT(m_values->size() == m_wrappers->size()); |
149 | 149 |
150 // Spec: If the inserted item is already in a list, it is removed from i
ts previous list before it is inserted into this list. | 150 // Spec: If the inserted item is already in a list, it is removed from i
ts previous list before it is inserted into this list. |
151 processIncomingListItemWrapper(newItem, 0); | 151 processIncomingListItemWrapper(newItem, 0); |
152 | 152 |
153 // Spec: Clears all existing current items from the list and re-initiali
zes the list to hold the single item specified by the parameter. | 153 // Spec: Clears all existing current items from the list and re-initiali
zes the list to hold the single item specified by the parameter. |
154 detachListWrappers(0); | 154 detachListWrappers(0); |
(...skipping 23 matching lines...) Expand all Loading... |
178 return ListItemType(); | 178 return ListItemType(); |
179 | 179 |
180 // Spec: Returns the specified item from the list. The returned item is
the item itself and not a copy. | 180 // Spec: Returns the specified item from the list. The returned item is
the item itself and not a copy. |
181 return m_values->at(index); | 181 return m_values->at(index); |
182 } | 182 } |
183 | 183 |
184 PassListItemTearOff getItemValuesAndWrappers(AnimatedListPropertyTearOff* an
imatedList, unsigned index, ExceptionState& exceptionState) | 184 PassListItemTearOff getItemValuesAndWrappers(AnimatedListPropertyTearOff* an
imatedList, unsigned index, ExceptionState& exceptionState) |
185 { | 185 { |
186 ASSERT(m_wrappers); | 186 ASSERT(m_wrappers); |
187 if (!canGetItem(index, exceptionState)) | 187 if (!canGetItem(index, exceptionState)) |
188 return 0; | 188 return nullptr; |
189 | 189 |
190 // Spec: Returns the specified item from the list. The returned item is
the item itself and not a copy. | 190 // Spec: Returns the specified item from the list. The returned item is
the item itself and not a copy. |
191 // Any changes made to the item are immediately reflected in the list. | 191 // Any changes made to the item are immediately reflected in the list. |
192 ASSERT(m_values->size() == m_wrappers->size()); | 192 ASSERT(m_values->size() == m_wrappers->size()); |
193 RefPtr<ListItemTearOff> wrapper = m_wrappers->at(index); | 193 RefPtr<ListItemTearOff> wrapper = m_wrappers->at(index); |
194 if (!wrapper) { | 194 if (!wrapper) { |
195 // Create new wrapper, which is allowed to directly modify the item
in the list, w/o copying and cache the wrapper in our map. | 195 // Create new wrapper, which is allowed to directly modify the item
in the list, w/o copying and cache the wrapper in our map. |
196 // It is also associated with our animated property, so it can notif
y the SVG Element which holds the SVGAnimated*List | 196 // It is also associated with our animated property, so it can notif
y the SVG Element which holds the SVGAnimated*List |
197 // that it has been modified (and thus can call svgAttributeChanged(
associatedAttributeName)). | 197 // that it has been modified (and thus can call svgAttributeChanged(
associatedAttributeName)). |
198 wrapper = ListItemTearOff::create(animatedList, UndefinedRole, m_val
ues->at(index)); | 198 wrapper = ListItemTearOff::create(animatedList, UndefinedRole, m_val
ues->at(index)); |
(...skipping 24 matching lines...) Expand all Loading... |
223 m_values->insert(index, newItem); | 223 m_values->insert(index, newItem); |
224 | 224 |
225 commitChange(); | 225 commitChange(); |
226 return newItem; | 226 return newItem; |
227 } | 227 } |
228 | 228 |
229 PassListItemTearOff insertItemBeforeValuesAndWrappers(PassListItemTearOff pa
ssNewItem, unsigned index, ExceptionState& exceptionState) | 229 PassListItemTearOff insertItemBeforeValuesAndWrappers(PassListItemTearOff pa
ssNewItem, unsigned index, ExceptionState& exceptionState) |
230 { | 230 { |
231 ASSERT(m_wrappers); | 231 ASSERT(m_wrappers); |
232 if (!canAlterList(exceptionState)) | 232 if (!canAlterList(exceptionState)) |
233 return 0; | 233 return nullptr; |
234 | 234 |
235 // Not specified, but FF/Opera do it this way, and it's just sane. | 235 // Not specified, but FF/Opera do it this way, and it's just sane. |
236 if (!passNewItem) { | 236 if (!passNewItem) { |
237 exceptionState.throwTypeError("The PassListItemType provided is inva
lid."); | 237 exceptionState.throwTypeError("The PassListItemType provided is inva
lid."); |
238 return 0; | 238 return nullptr; |
239 } | 239 } |
240 | 240 |
241 // Spec: If the index is greater than or equal to numberOfItems, then th
e new item is appended to the end of the list. | 241 // Spec: If the index is greater than or equal to numberOfItems, then th
e new item is appended to the end of the list. |
242 if (index > m_values->size()) | 242 if (index > m_values->size()) |
243 index = m_values->size(); | 243 index = m_values->size(); |
244 | 244 |
245 RefPtr<ListItemTearOff> newItem = passNewItem; | 245 RefPtr<ListItemTearOff> newItem = passNewItem; |
246 ASSERT(m_values->size() == m_wrappers->size()); | 246 ASSERT(m_values->size() == m_wrappers->size()); |
247 | 247 |
248 // Spec: If newItem is already in a list, it is removed from its previou
s list before it is inserted into this list. | 248 // Spec: If newItem is already in a list, it is removed from its previou
s list before it is inserted into this list. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 m_values->at(index) = newItem; | 296 m_values->at(index) = newItem; |
297 | 297 |
298 commitChange(); | 298 commitChange(); |
299 return newItem; | 299 return newItem; |
300 } | 300 } |
301 | 301 |
302 PassListItemTearOff replaceItemValuesAndWrappers(PassListItemTearOff passNew
Item, unsigned index, ExceptionState& exceptionState) | 302 PassListItemTearOff replaceItemValuesAndWrappers(PassListItemTearOff passNew
Item, unsigned index, ExceptionState& exceptionState) |
303 { | 303 { |
304 ASSERT(m_wrappers); | 304 ASSERT(m_wrappers); |
305 if (!canReplaceItem(index, exceptionState)) | 305 if (!canReplaceItem(index, exceptionState)) |
306 return 0; | 306 return nullptr; |
307 | 307 |
308 // Not specified, but FF/Opera do it this way, and it's just sane. | 308 // Not specified, but FF/Opera do it this way, and it's just sane. |
309 if (!passNewItem) { | 309 if (!passNewItem) { |
310 exceptionState.throwTypeError("The PassListItemType provided is inva
lid."); | 310 exceptionState.throwTypeError("The PassListItemType provided is inva
lid."); |
311 return 0; | 311 return nullptr; |
312 } | 312 } |
313 | 313 |
314 ASSERT(m_values->size() == m_wrappers->size()); | 314 ASSERT(m_values->size() == m_wrappers->size()); |
315 RefPtr<ListItemTearOff> newItem = passNewItem; | 315 RefPtr<ListItemTearOff> newItem = passNewItem; |
316 | 316 |
317 // Spec: If newItem is already in a list, it is removed from its previou
s list before it is inserted into this list. | 317 // Spec: If newItem is already in a list, it is removed from its previou
s list before it is inserted into this list. |
318 // Spec: If the item is already in this list, note that the index of the
item to replace is before the removal of the item. | 318 // Spec: If the item is already in this list, note that the index of the
item to replace is before the removal of the item. |
319 if (!processIncomingListItemWrapper(newItem, &index)) | 319 if (!processIncomingListItemWrapper(newItem, &index)) |
320 return newItem.release(); | 320 return newItem.release(); |
321 | 321 |
322 if (m_values->isEmpty()) { | 322 if (m_values->isEmpty()) { |
323 ASSERT(m_wrappers->isEmpty()); | 323 ASSERT(m_wrappers->isEmpty()); |
324 // 'passNewItem' already lived in our list, we removed it, and now w
e're empty, which means there's nothing to replace. | 324 // 'passNewItem' already lived in our list, we removed it, and now w
e're empty, which means there's nothing to replace. |
325 exceptionState.throwDOMException(IndexSizeError, "The new item lived
in this list, and has been removed."); | 325 exceptionState.throwDOMException(IndexSizeError, "The new item lived
in this list, and has been removed."); |
326 return 0; | 326 return nullptr; |
327 } | 327 } |
328 | 328 |
329 // Detach the existing wrapper. | 329 // Detach the existing wrapper. |
330 RefPtr<ListItemTearOff> oldItem = m_wrappers->at(index); | 330 RefPtr<ListItemTearOff> oldItem = m_wrappers->at(index); |
331 if (oldItem) | 331 if (oldItem) |
332 oldItem->detachWrapper(); | 332 oldItem->detachWrapper(); |
333 | 333 |
334 // Update the value and the wrapper at the desired position 'index'. | 334 // Update the value and the wrapper at the desired position 'index'. |
335 m_values->at(index) = newItem->propertyReference(); | 335 m_values->at(index) = newItem->propertyReference(); |
336 m_wrappers->at(index) = newItem; | 336 m_wrappers->at(index) = newItem; |
(...skipping 25 matching lines...) Expand all Loading... |
362 m_values->remove(index); | 362 m_values->remove(index); |
363 | 363 |
364 commitChange(); | 364 commitChange(); |
365 return oldItem; | 365 return oldItem; |
366 } | 366 } |
367 | 367 |
368 PassListItemTearOff removeItemValuesAndWrappers(AnimatedListPropertyTearOff*
animatedList, unsigned index, ExceptionState& exceptionState) | 368 PassListItemTearOff removeItemValuesAndWrappers(AnimatedListPropertyTearOff*
animatedList, unsigned index, ExceptionState& exceptionState) |
369 { | 369 { |
370 ASSERT(m_wrappers); | 370 ASSERT(m_wrappers); |
371 if (!canRemoveItem(index, exceptionState)) | 371 if (!canRemoveItem(index, exceptionState)) |
372 return 0; | 372 return nullptr; |
373 | 373 |
374 ASSERT(m_values->size() == m_wrappers->size()); | 374 ASSERT(m_values->size() == m_wrappers->size()); |
375 | 375 |
376 // Detach the existing wrapper. | 376 // Detach the existing wrapper. |
377 RefPtr<ListItemTearOff> oldItem = m_wrappers->at(index); | 377 RefPtr<ListItemTearOff> oldItem = m_wrappers->at(index); |
378 if (!oldItem) | 378 if (!oldItem) |
379 oldItem = ListItemTearOff::create(animatedList, UndefinedRole, m_val
ues->at(index)); | 379 oldItem = ListItemTearOff::create(animatedList, UndefinedRole, m_val
ues->at(index)); |
380 | 380 |
381 oldItem->detachWrapper(); | 381 oldItem->detachWrapper(); |
382 m_wrappers->remove(index); | 382 m_wrappers->remove(index); |
(...skipping 16 matching lines...) Expand all Loading... |
399 m_values->append(newItem); | 399 m_values->append(newItem); |
400 | 400 |
401 commitChange(ListModificationAppend); | 401 commitChange(ListModificationAppend); |
402 return newItem; | 402 return newItem; |
403 } | 403 } |
404 | 404 |
405 PassListItemTearOff appendItemValuesAndWrappers(PassListItemTearOff passNewI
tem, ExceptionState& exceptionState) | 405 PassListItemTearOff appendItemValuesAndWrappers(PassListItemTearOff passNewI
tem, ExceptionState& exceptionState) |
406 { | 406 { |
407 ASSERT(m_wrappers); | 407 ASSERT(m_wrappers); |
408 if (!canAlterList(exceptionState)) | 408 if (!canAlterList(exceptionState)) |
409 return 0; | 409 return nullptr; |
410 | 410 |
411 // Not specified, but FF/Opera do it this way, and it's just sane. | 411 // Not specified, but FF/Opera do it this way, and it's just sane. |
412 if (!passNewItem) { | 412 if (!passNewItem) { |
413 exceptionState.throwTypeError("The PassListItemType provided is inva
lid."); | 413 exceptionState.throwTypeError("The PassListItemType provided is inva
lid."); |
414 return 0; | 414 return nullptr; |
415 } | 415 } |
416 | 416 |
417 RefPtr<ListItemTearOff> newItem = passNewItem; | 417 RefPtr<ListItemTearOff> newItem = passNewItem; |
418 ASSERT(m_values->size() == m_wrappers->size()); | 418 ASSERT(m_values->size() == m_wrappers->size()); |
419 | 419 |
420 // Spec: If newItem is already in a list, it is removed from its previou
s list before it is inserted into this list. | 420 // Spec: If newItem is already in a list, it is removed from its previou
s list before it is inserted into this list. |
421 processIncomingListItemWrapper(newItem, 0); | 421 processIncomingListItemWrapper(newItem, 0); |
422 | 422 |
423 // Append the value and wrapper at the end of the list. | 423 // Append the value and wrapper at the end of the list. |
424 m_values->append(newItem->propertyReference()); | 424 m_values->append(newItem->propertyReference()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 466 |
467 SVGPropertyRole m_role; | 467 SVGPropertyRole m_role; |
468 bool m_ownsValues; | 468 bool m_ownsValues; |
469 PropertyType* m_values; | 469 PropertyType* m_values; |
470 ListWrapperCache* m_wrappers; | 470 ListWrapperCache* m_wrappers; |
471 }; | 471 }; |
472 | 472 |
473 } | 473 } |
474 | 474 |
475 #endif // SVGListProperty_h | 475 #endif // SVGListProperty_h |
OLD | NEW |