Chromium Code Reviews| Index: Source/core/svg/properties/SVGListPropertyHelper.h |
| diff --git a/Source/core/svg/properties/SVGListPropertyHelper.h b/Source/core/svg/properties/SVGListPropertyHelper.h |
| index a6fd4d713bc2ef6d9031351b66ccb2211cea05ee..41331ba5b17a7d51ff4c095caf488e11493d9443 100644 |
| --- a/Source/core/svg/properties/SVGListPropertyHelper.h |
| +++ b/Source/core/svg/properties/SVGListPropertyHelper.h |
| @@ -171,7 +171,6 @@ protected: |
| private: |
| inline bool checkIndexBound(size_t, ExceptionState&); |
| - bool removeFromOldOwnerListAndAdjustIndex(PassRefPtrWillBeRawPtr<ItemPropertyType>, size_t* indexToModify); |
| size_t findItem(PassRefPtrWillBeRawPtr<ItemPropertyType>); |
| WillBeHeapVector<RefPtrWillBeMember<ItemPropertyType>> m_values; |
| @@ -221,8 +220,10 @@ PassRefPtrWillBeRawPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty |
| { |
| RefPtrWillBeRawPtr<ItemPropertyType> newItem = passNewItem; |
| - // Spec: If the inserted item is already in a list, it is removed from its previous list before it is inserted into this list. |
| - removeFromOldOwnerListAndAdjustIndex(newItem, 0); |
| + // SVG2-Draft Spec: If newItem is already in a list, then a new object is created with the same values as newItem and this item is inserted into the list. |
| + // Otherwise, newItem itself is inserted into the list. |
| + if (newItem->ownerList()) |
| + newItem = newItem->clone(); |
|
fs
2015/06/17 16:02:05
Should we handle this in the generic ListItemPrope
Shanmuga Pandi
2015/06/18 11:30:45
Done
|
| // Spec: Clears all existing current items from the list and re-initializes the list to hold the single item specified by the parameter. |
| clear(); |
| @@ -250,11 +251,10 @@ PassRefPtrWillBeRawPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty |
| RefPtrWillBeRawPtr<ItemPropertyType> newItem = passNewItem; |
| - // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. |
| - if (!removeFromOldOwnerListAndAdjustIndex(newItem, &index)) { |
| - // Inserting the item before itself is a no-op. |
| - return newItem.release(); |
| - } |
| + // SVG2-Draft Spec: If newItem is already in a list, then a new object is created with the same values as newItem and this item is inserted into the list. |
| + // Otherwise, newItem itself is inserted into the list. |
| + if (newItem->ownerList()) |
| + newItem = newItem->clone(); |
| // Spec: Inserts a new item into the list at the specified position. The index of the item before which the new item is to be |
| // inserted. The first item is number 0. If the index is equal to 0, then the new item is inserted at the front of the list. |
| @@ -283,8 +283,10 @@ PassRefPtrWillBeRawPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty |
| { |
| RefPtrWillBeRawPtr<ItemPropertyType> newItem = passNewItem; |
| - // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. |
| - removeFromOldOwnerListAndAdjustIndex(newItem, 0); |
| + // SVG2-Draft Spec: If newItem is already in a list, then a new object is created with the same values as newItem and this item is inserted into the list. |
| + // Otherwise, newItem itself is inserted into the list. |
| + if (newItem->ownerList()) |
| + newItem = newItem->clone(); |
| // Append the value and wrapper at the end of the list. |
| append(newItem); |
| @@ -300,12 +302,10 @@ PassRefPtrWillBeRawPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty |
| RefPtrWillBeRawPtr<ItemPropertyType> newItem = passNewItem; |
| - // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. |
| - // 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. |
| - if (!removeFromOldOwnerListAndAdjustIndex(newItem, &index)) { |
| - // Replacing the item with itself is a no-op. |
| - return newItem.release(); |
| - } |
| + // SVG2-Draft Spec: If newItem is already in a list, then a new object is created with the same values as newItem and this item is inserted into the list. |
| + // Otherwise, newItem itself is inserted into the list. |
| + if (newItem->ownerList()) |
| + newItem = newItem->clone(); |
| if (m_values.isEmpty()) { |
| // 'newItem' already lived in our list, we removed it, and now we're empty, which means there's nothing to replace. |
| @@ -335,41 +335,6 @@ bool SVGListPropertyHelper<Derived, ItemProperty>::checkIndexBound(size_t index, |
| } |
| template<typename Derived, typename ItemProperty> |
| -bool SVGListPropertyHelper<Derived, ItemProperty>::removeFromOldOwnerListAndAdjustIndex(PassRefPtrWillBeRawPtr<ItemPropertyType> passItem, size_t* indexToModify) |
| -{ |
| - RefPtrWillBeRawPtr<ItemPropertyType> item = passItem; |
| - ASSERT(item); |
| - RefPtrWillBeRawPtr<Derived> ownerList = toDerived(item->ownerList()); |
| - if (!ownerList) |
| - return true; |
| - |
| - // Spec: If newItem is already in a list, it is removed from its previous list before it is inserted into this list. |
| - // 'newItem' is already living in another list. If it's not our list, synchronize the other lists wrappers after the removal. |
| - bool livesInOtherList = ownerList.get() != this; |
| - size_t indexToRemove = ownerList->findItem(item); |
| - ASSERT(indexToRemove != WTF::kNotFound); |
| - |
| - // Do not remove newItem if already in this list at the target index. |
| - if (!livesInOtherList && indexToModify && indexToRemove == *indexToModify) |
| - return false; |
| - |
| - ownerList->removeItem(indexToRemove, ASSERT_NO_EXCEPTION); |
| - |
| - if (!indexToModify) |
| - return true; |
| - |
| - // If the item lived in our list, adjust the insertion index. |
| - if (!livesInOtherList) { |
| - size_t& index = *indexToModify; |
| - // Spec: If the item is already in this list, note that the index of the item to (replace|insert before) is before the removal of the item. |
| - if (static_cast<size_t>(indexToRemove) < index) |
| - --index; |
| - } |
| - |
| - return true; |
| -} |
| - |
| -template<typename Derived, typename ItemProperty> |
| size_t SVGListPropertyHelper<Derived, ItemProperty>::findItem(PassRefPtrWillBeRawPtr<ItemPropertyType> item) |
| { |
| return m_values.find(item); |