void DOMSVGPointList::MaybeRemoveItemFromAnimValListAt(uint32_t aIndex) { MOZ_ASSERT(!IsAnimValList(), "call from baseVal to animVal"); if (!AnimListMirrorsBaseList()) { return; } // This needs to be a strong reference; otherwise, the RemovingFromList call // below might drop the last reference to animVal before we're done with it. RefPtr<DOMSVGPointList> animVal = GetDOMWrapperIfExists(InternalAList().GetAnimValKey()); MOZ_ASSERT(animVal, "AnimListMirrorsBaseList() promised a non-null animVal"); MOZ_ASSERT(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); if (animVal->mItems[aIndex]) { animVal->mItems[aIndex]->RemovingFromList(); } animVal->mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(animVal->mItems, aIndex); }
void DOMSVGPointList::MaybeRemoveItemFromAnimValListAt(PRUint32 aIndex) { NS_ABORT_IF_FALSE(!IsAnimValList(), "call from baseVal to animVal"); if (AttrIsAnimating()) { // animVal not a clone of baseVal return; } DOMSVGPointList *animVal = GetDOMWrapperIfExists(InternalAList().GetAnimValKey()); if (!animVal) { // No animVal list wrapper return; } NS_ABORT_IF_FALSE(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); if (animVal->mItems[aIndex]) { animVal->mItems[aIndex]->RemovingFromList(); } animVal->mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(animVal->mItems, aIndex); }
void DOMSVGPointList::MaybeInsertNullInAnimValListAt(uint32_t aIndex) { MOZ_ASSERT(!IsAnimValList(), "call from baseVal to animVal"); if (AttrIsAnimating()) { // animVal not a clone of baseVal return; } // The anim val list is in sync with the base val list DOMSVGPointList *animVal = GetDOMWrapperIfExists(InternalAList().GetAnimValKey()); if (!animVal) { // No animVal list wrapper return; } MOZ_ASSERT(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); MOZ_ALWAYS_TRUE(animVal->mItems.InsertElementAt(aIndex, nullptr, fallible)); UpdateListIndicesFromIndex(animVal->mItems, aIndex + 1); }
void DOMSVGPointList::MaybeInsertNullInAnimValListAt(uint32_t aIndex) { NS_ABORT_IF_FALSE(!IsAnimValList(), "call from baseVal to animVal"); if (AttrIsAnimating()) { // animVal not a clone of baseVal return; } // The anim val list is in sync with the base val list DOMSVGPointList *animVal = GetDOMWrapperIfExists(InternalAList().GetAnimValKey()); if (!animVal) { // No animVal list wrapper return; } NS_ABORT_IF_FALSE(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); animVal->mItems.InsertElementAt(aIndex, static_cast<nsISVGPoint*>(nullptr)); UpdateListIndicesFromIndex(animVal->mItems, aIndex + 1); }
void DOMSVGPointList::MaybeRemoveItemFromAnimValListAt(uint32_t aIndex) { NS_ABORT_IF_FALSE(!IsAnimValList(), "call from baseVal to animVal"); if (AttrIsAnimating()) { // animVal not a clone of baseVal return; } // This needs to be a strong reference; otherwise, the RemovingFromList call // below might drop the last reference to animVal before we're done with it. nsRefPtr<DOMSVGPointList> animVal = GetDOMWrapperIfExists(InternalAList().GetAnimValKey()); if (!animVal) { // No animVal list wrapper return; } NS_ABORT_IF_FALSE(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); if (animVal->mItems[aIndex]) { animVal->mItems[aIndex]->RemovingFromList(); } animVal->mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(animVal->mItems, aIndex); }
NS_IMETHODIMP DOMSVGPathSegList::InsertItemBefore(nsIDOMSVGPathSeg *aNewItem, PRUint32 aIndex, nsIDOMSVGPathSeg **_retval) { *_retval = nsnull; if (IsAnimValList()) { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; } PRUint32 internalIndex; if (aIndex < Length()) { internalIndex = mItems[aIndex].mInternalDataIndex; } else { aIndex = Length(); internalIndex = InternalList().mData.Length(); } if (aIndex >= DOMSVGPathSeg::MaxListIndex()) { return NS_ERROR_DOM_INDEX_SIZE_ERR; } nsCOMPtr<DOMSVGPathSeg> domItem = do_QueryInterface(aNewItem); if (!domItem) { return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR; } if (domItem->HasOwner()) { domItem = domItem->Clone(); // must do this before changing anything! } PRUint32 argCount = SVGPathSegUtils::ArgCountForType(domItem->Type()); // Ensure we have enough memory so we can avoid complex error handling below: if (!mItems.SetCapacity(mItems.Length() + 1) || !InternalList().mData.SetCapacity(InternalList().mData.Length() + 1 + argCount)) { return NS_ERROR_OUT_OF_MEMORY; } // Now that we know we're inserting, keep animVal list in sync as necessary. MaybeInsertNullInAnimValListAt(aIndex, internalIndex, argCount); float segAsRaw[1 + NS_SVG_PATH_SEG_MAX_ARGS]; domItem->ToSVGPathSegEncodedData(segAsRaw); InternalList().mData.InsertElementsAt(internalIndex, segAsRaw, 1 + argCount); mItems.InsertElementAt(aIndex, ItemProxy(domItem.get(), internalIndex)); // This MUST come after the insertion into InternalList(), or else under the // insertion into InternalList() the values read from domItem would be bad // data from InternalList() itself!: domItem->InsertingIntoList(this, aIndex, IsAnimValList()); UpdateListIndicesFromIndex(aIndex + 1, argCount + 1); Element()->DidChangePathSegList(true); if (AttrIsAnimating()) { Element()->AnimationNeedsResample(); } *_retval = domItem.forget().get(); return NS_OK; }
already_AddRefed<nsISVGPoint> DOMSVGPointList::RemoveItem(uint32_t aIndex, ErrorResult& aError) { if (IsAnimValList()) { aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return nullptr; } if (aIndex >= LengthNoFlush()) { aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return nullptr; } AutoChangePointListNotifier notifier(this); // Now that we know we're removing, keep animVal list in sync as necessary. // Do this *before* touching InternalList() so the removed item can get its // internal value. MaybeRemoveItemFromAnimValListAt(aIndex); // We have to return the removed item, so get it, creating it if necessary: RefPtr<nsISVGPoint> result = GetItemAt(aIndex); // Notify the DOM item of removal *before* modifying the lists so that the // DOM item can copy its *old* value: mItems[aIndex]->RemovingFromList(); InternalList().RemoveItem(aIndex); mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(mItems, aIndex); return result.forget(); }
already_AddRefed<DOMSVGPathSeg> DOMSVGPathSegList::InsertItemBefore(DOMSVGPathSeg& aNewItem, uint32_t aIndex, ErrorResult& aError) { if (IsAnimValList()) { aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return nullptr; } uint32_t internalIndex; if (aIndex < LengthNoFlush()) { internalIndex = mItems[aIndex].mInternalDataIndex; } else { aIndex = LengthNoFlush(); internalIndex = InternalList().mData.Length(); } if (aIndex >= DOMSVGPathSeg::MaxListIndex()) { aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return nullptr; } nsRefPtr<DOMSVGPathSeg> domItem = &aNewItem; if (domItem->HasOwner()) { domItem = domItem->Clone(); // must do this before changing anything! } uint32_t argCount = SVGPathSegUtils::ArgCountForType(domItem->Type()); // Ensure we have enough memory so we can avoid complex error handling below: if (!mItems.SetCapacity(mItems.Length() + 1) || !InternalList().mData.SetCapacity(InternalList().mData.Length() + 1 + argCount)) { aError.Throw(NS_ERROR_OUT_OF_MEMORY); return nullptr; } nsAttrValue emptyOrOldValue = Element()->WillChangePathSegList(); // Now that we know we're inserting, keep animVal list in sync as necessary. MaybeInsertNullInAnimValListAt(aIndex, internalIndex, argCount); float segAsRaw[1 + NS_SVG_PATH_SEG_MAX_ARGS]; domItem->ToSVGPathSegEncodedData(segAsRaw); InternalList().mData.InsertElementsAt(internalIndex, segAsRaw, 1 + argCount); mItems.InsertElementAt(aIndex, ItemProxy(domItem.get(), internalIndex)); // This MUST come after the insertion into InternalList(), or else under the // insertion into InternalList() the values read from domItem would be bad // data from InternalList() itself!: domItem->InsertingIntoList(this, aIndex, IsAnimValList()); UpdateListIndicesFromIndex(aIndex + 1, argCount + 1); Element()->DidChangePathSegList(emptyOrOldValue); if (AttrIsAnimating()) { Element()->AnimationNeedsResample(); } return domItem.forget(); }
already_AddRefed<nsISVGPoint> DOMSVGPointList::InsertItemBefore(nsISVGPoint& aNewItem, uint32_t aIndex, ErrorResult& aError) { if (IsAnimValList()) { aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return nullptr; } aIndex = std::min(aIndex, LengthNoFlush()); if (aIndex >= nsISVGPoint::MaxListIndex()) { aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return nullptr; } nsCOMPtr<nsISVGPoint> domItem = &aNewItem; if (domItem->HasOwner() || domItem->IsReadonly() || domItem->IsTranslatePoint()) { domItem = domItem->Copy(); // must do this before changing anything! } // Ensure we have enough memory so we can avoid complex error handling below: if (!mItems.SetCapacity(mItems.Length() + 1, fallible) || !InternalList().SetCapacity(InternalList().Length() + 1)) { aError.Throw(NS_ERROR_OUT_OF_MEMORY); return nullptr; } if (AnimListMirrorsBaseList()) { DOMSVGPointList *animVal = GetDOMWrapperIfExists(InternalAList().GetAnimValKey()); MOZ_ASSERT(animVal, "animVal must be a valid pointer"); if (!animVal->mItems.SetCapacity( animVal->mItems.Length() + 1, fallible)) { aError.Throw(NS_ERROR_OUT_OF_MEMORY); return nullptr; } } AutoChangePointListNotifier notifier(this); // Now that we know we're inserting, keep animVal list in sync as necessary. MaybeInsertNullInAnimValListAt(aIndex); InternalList().InsertItem(aIndex, domItem->ToSVGPoint()); MOZ_ALWAYS_TRUE(mItems.InsertElementAt(aIndex, domItem, fallible)); // This MUST come after the insertion into InternalList(), or else under the // insertion into InternalList() the values read from domItem would be bad // data from InternalList() itself!: domItem->InsertingIntoList(this, aIndex, IsAnimValList()); UpdateListIndicesFromIndex(mItems, aIndex + 1); return domItem.forget(); }
NS_IMETHODIMP DOMSVGNumberList::InsertItemBefore(nsIDOMSVGNumber *newItem, PRUint32 index, nsIDOMSVGNumber **_retval) { *_retval = nsnull; if (IsAnimValList()) { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; } index = NS_MIN(index, Length()); if (index >= DOMSVGNumber::MaxListIndex()) { return NS_ERROR_DOM_INDEX_SIZE_ERR; } nsCOMPtr<DOMSVGNumber> domItem = do_QueryInterface(newItem); if (!domItem) { return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR; } if (domItem->HasOwner()) { domItem = domItem->Clone(); // must do this before changing anything! } // Ensure we have enough memory so we can avoid complex error handling below: if (!mItems.SetCapacity(mItems.Length() + 1) || !InternalList().SetCapacity(InternalList().Length() + 1)) { return NS_ERROR_OUT_OF_MEMORY; } // Now that we know we're inserting, keep animVal list in sync as necessary. MaybeInsertNullInAnimValListAt(index); InternalList().InsertItem(index, domItem->ToSVGNumber()); mItems.InsertElementAt(index, domItem.get()); // This MUST come after the insertion into InternalList(), or else under the // insertion into InternalList() the values read from domItem would be bad // data from InternalList() itself!: domItem->InsertingIntoList(this, AttrEnum(), index, IsAnimValList()); UpdateListIndicesFromIndex(mItems, index + 1); Element()->DidChangeNumberList(AttrEnum(), PR_TRUE); #ifdef MOZ_SMIL if (mAList->IsAnimating()) { Element()->AnimationNeedsResample(); } #endif *_retval = domItem.forget().get(); return NS_OK; }
already_AddRefed<nsIDOMSVGPoint> DOMSVGPointList::InsertItemBefore(nsIDOMSVGPoint *aNewItem, uint32_t aIndex, ErrorResult& aError) { if (IsAnimValList()) { aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return nullptr; } aIndex = NS_MIN(aIndex, LengthNoFlush()); if (aIndex >= DOMSVGPoint::MaxListIndex()) { aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return nullptr; } nsCOMPtr<DOMSVGPoint> domItem = do_QueryInterface(aNewItem); if (!domItem) { aError.Throw(NS_ERROR_DOM_SVG_WRONG_TYPE_ERR); return nullptr; } if (domItem->HasOwner() || domItem->IsReadonly()) { domItem = domItem->Clone(); // must do this before changing anything! } // Ensure we have enough memory so we can avoid complex error handling below: if (!mItems.SetCapacity(mItems.Length() + 1) || !InternalList().SetCapacity(InternalList().Length() + 1)) { aError.Throw(NS_ERROR_OUT_OF_MEMORY); return nullptr; } nsAttrValue emptyOrOldValue = Element()->WillChangePointList(); // Now that we know we're inserting, keep animVal list in sync as necessary. MaybeInsertNullInAnimValListAt(aIndex); InternalList().InsertItem(aIndex, domItem->ToSVGPoint()); mItems.InsertElementAt(aIndex, domItem.get()); // This MUST come after the insertion into InternalList(), or else under the // insertion into InternalList() the values read from domItem would be bad // data from InternalList() itself!: domItem->InsertingIntoList(this, aIndex, IsAnimValList()); UpdateListIndicesFromIndex(mItems, aIndex + 1); Element()->DidChangePointList(emptyOrOldValue); if (AttrIsAnimating()) { Element()->AnimationNeedsResample(); } return domItem.forget(); }
already_AddRefed<SVGTransform> DOMSVGTransformList::InsertItemBefore(SVGTransform& newItem, uint32_t index, ErrorResult& error) { if (IsAnimValList()) { error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return nullptr; } index = std::min(index, LengthNoFlush()); if (index >= SVGTransform::MaxListIndex()) { error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return nullptr; } nsRefPtr<SVGTransform> domItem = &newItem; if (newItem.HasOwner()) { domItem = newItem.Clone(); // must do this before changing anything! } // Ensure we have enough memory so we can avoid complex error handling below: if (!mItems.SetCapacity(mItems.Length() + 1) || !InternalList().SetCapacity(InternalList().Length() + 1)) { error.Throw(NS_ERROR_OUT_OF_MEMORY); return nullptr; } nsAttrValue emptyOrOldValue = Element()->WillChangeTransformList(); // Now that we know we're inserting, keep animVal list in sync as necessary. MaybeInsertNullInAnimValListAt(index); InternalList().InsertItem(index, domItem->ToSVGTransform()); mItems.InsertElementAt(index, domItem.get()); // This MUST come after the insertion into InternalList(), or else under the // insertion into InternalList() the values read from domItem would be bad // data from InternalList() itself!: domItem->InsertingIntoList(this, index, IsAnimValList()); UpdateListIndicesFromIndex(mItems, index + 1); Element()->DidChangeTransformList(emptyOrOldValue); if (mAList->IsAnimating()) { Element()->AnimationNeedsResample(); } return domItem.forget(); }
already_AddRefed<DOMSVGPathSeg> DOMSVGPathSegList::RemoveItem(uint32_t aIndex, ErrorResult& aError) { if (IsAnimValList()) { aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return nullptr; } if (aIndex >= LengthNoFlush()) { aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return nullptr; } // We have to return the removed item, so make sure it exists: EnsureItemAt(aIndex); nsAttrValue emptyOrOldValue = Element()->WillChangePathSegList(); // Notify the DOM item of removal *before* modifying the lists so that the // DOM item can copy its *old* value: ItemAt(aIndex)->RemovingFromList(); nsRefPtr<DOMSVGPathSeg> result = ItemAt(aIndex); uint32_t internalIndex = mItems[aIndex].mInternalDataIndex; uint32_t segType = SVGPathSegUtils::DecodeType(InternalList().mData[internalIndex]); // NOTE: ArgCountForType returns a (small) unsigned value, but we're // intentionally putting it in a signed value, because we're going to // negate it, and you can't negate an unsigned value. int32_t argCount = SVGPathSegUtils::ArgCountForType(segType); // Now that we know we're removing, keep animVal list in sync as necessary. // Do this *before* touching InternalList() so the removed item can get its // internal value. MaybeRemoveItemFromAnimValListAt(aIndex, argCount); InternalList().mData.RemoveElementsAt(internalIndex, 1 + argCount); mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(aIndex, -(argCount + 1)); Element()->DidChangePathSegList(emptyOrOldValue); if (AttrIsAnimating()) { Element()->AnimationNeedsResample(); } return result.forget(); }
void DOMSVGLengthList::MaybeInsertNullInAnimValListAt(PRUint32 aIndex) { NS_ABORT_IF_FALSE(!IsAnimValList(), "call from baseVal to animVal"); DOMSVGLengthList* animVal = mAList->mAnimVal; if (!animVal || mAList->IsAnimating()) { // No animVal list wrapper, or animVal not a clone of baseVal return; } NS_ABORT_IF_FALSE(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); animVal->mItems.InsertElementAt(aIndex, static_cast<DOMSVGLength*>(nsnull)); UpdateListIndicesFromIndex(animVal->mItems, aIndex + 1); }
void DOMSVGTransformList::MaybeInsertNullInAnimValListAt(uint32_t aIndex) { MOZ_ASSERT(!IsAnimValList(), "call from baseVal to animVal"); DOMSVGTransformList* animVal = mAList->mAnimVal; if (!animVal || mAList->IsAnimating()) { // No animVal list wrapper, or animVal not a clone of baseVal return; } MOZ_ASSERT(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); MOZ_ALWAYS_TRUE(animVal->mItems.InsertElementAt(aIndex, nullptr, fallible)); UpdateListIndicesFromIndex(animVal->mItems, aIndex + 1); }
NS_IMETHODIMP DOMSVGPathSegList::RemoveItem(PRUint32 aIndex, nsIDOMSVGPathSeg **_retval) { *_retval = nsnull; if (IsAnimValList()) { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; } if (aIndex >= Length()) { return NS_ERROR_DOM_INDEX_SIZE_ERR; } // We have to return the removed item, so make sure it exists: EnsureItemAt(aIndex); // Notify the DOM item of removal *before* modifying the lists so that the // DOM item can copy its *old* value: ItemAt(aIndex)->RemovingFromList(); NS_ADDREF(*_retval = ItemAt(aIndex)); PRUint32 internalIndex = mItems[aIndex].mInternalDataIndex; PRUint32 segType = SVGPathSegUtils::DecodeType(InternalList().mData[internalIndex]); PRUint32 argCount = SVGPathSegUtils::ArgCountForType(segType); // Now that we know we're removing, keep animVal list in sync as necessary. // Do this *before* touching InternalList() so the removed item can get its // internal value. MaybeRemoveItemFromAnimValListAt(aIndex, argCount); InternalList().mData.RemoveElementsAt(internalIndex, 1 + argCount); mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(aIndex, -(argCount + 1)); Element()->DidChangePathSegList(PR_TRUE); #ifdef MOZ_SMIL if (AttrIsAnimating()) { Element()->AnimationNeedsResample(); } #endif return NS_OK; }
void DOMSVGPointList::MaybeInsertNullInAnimValListAt(uint32_t aIndex) { MOZ_ASSERT(!IsAnimValList(), "call from baseVal to animVal"); if (!AnimListMirrorsBaseList()) { return; } // The anim val list is in sync with the base val list DOMSVGPointList *animVal = GetDOMWrapperIfExists(InternalAList().GetAnimValKey()); MOZ_ASSERT(animVal, "AnimListMirrorsBaseList() promised a non-null animVal"); MOZ_ASSERT(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); MOZ_ALWAYS_TRUE(animVal->mItems.InsertElementAt(aIndex, nullptr, fallible)); UpdateListIndicesFromIndex(animVal->mItems, aIndex + 1); }
NS_IMETHODIMP DOMSVGNumberList::RemoveItem(PRUint32 index, nsIDOMSVGNumber **_retval) { *_retval = nsnull; if (IsAnimValList()) { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; } if (index >= Length()) { return NS_ERROR_DOM_INDEX_SIZE_ERR; } // Now that we know we're removing, keep animVal list in sync as necessary. // Do this *before* touching InternalList() so the removed item can get its // internal value. MaybeRemoveItemFromAnimValListAt(index); // We have to return the removed item, so make sure it exists: EnsureItemAt(index); // Notify the DOM item of removal *before* modifying the lists so that the // DOM item can copy its *old* value: mItems[index]->RemovingFromList(); NS_ADDREF(*_retval = mItems[index]); InternalList().RemoveItem(index); mItems.RemoveElementAt(index); UpdateListIndicesFromIndex(mItems, index); Element()->DidChangeNumberList(AttrEnum(), PR_TRUE); #ifdef MOZ_SMIL if (mAList->IsAnimating()) { Element()->AnimationNeedsResample(); } #endif return NS_OK; }
NS_IMETHODIMP DOMSVGPointList::RemoveItem(PRUint32 aIndex, nsIDOMSVGPoint **_retval) { *_retval = nsnull; if (IsAnimValList()) { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; } if (aIndex >= Length()) { return NS_ERROR_DOM_INDEX_SIZE_ERR; } nsAttrValue emptyOrOldValue = Element()->WillChangePointList(); // Now that we know we're removing, keep animVal list in sync as necessary. // Do this *before* touching InternalList() so the removed item can get its // internal value. MaybeRemoveItemFromAnimValListAt(aIndex); // We have to return the removed item, so make sure it exists: EnsureItemAt(aIndex); // Notify the DOM item of removal *before* modifying the lists so that the // DOM item can copy its *old* value: mItems[aIndex]->RemovingFromList(); NS_ADDREF(*_retval = mItems[aIndex]); InternalList().RemoveItem(aIndex); mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(mItems, aIndex); Element()->DidChangePointList(emptyOrOldValue); if (AttrIsAnimating()) { Element()->AnimationNeedsResample(); } return NS_OK; }
already_AddRefed<nsISVGPoint> DOMSVGPointList::RemoveItem(uint32_t aIndex, ErrorResult& aError) { if (IsAnimValList()) { aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return nullptr; } if (aIndex >= LengthNoFlush()) { aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return nullptr; } nsAttrValue emptyOrOldValue = Element()->WillChangePointList(); // Now that we know we're removing, keep animVal list in sync as necessary. // Do this *before* touching InternalList() so the removed item can get its // internal value. MaybeRemoveItemFromAnimValListAt(aIndex); // We have to return the removed item, so make sure it exists: EnsureItemAt(aIndex); // Notify the DOM item of removal *before* modifying the lists so that the // DOM item can copy its *old* value: mItems[aIndex]->RemovingFromList(); nsCOMPtr<nsISVGPoint> result = mItems[aIndex]; InternalList().RemoveItem(aIndex); mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(mItems, aIndex); Element()->DidChangePointList(emptyOrOldValue); if (AttrIsAnimating()) { Element()->AnimationNeedsResample(); } return result.forget(); }
already_AddRefed<SVGTransform> DOMSVGTransformList::RemoveItem(uint32_t index, ErrorResult& error) { if (IsAnimValList()) { error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR); return nullptr; } if (index >= LengthNoFlush()) { error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); return nullptr; } nsAttrValue emptyOrOldValue = Element()->WillChangeTransformList(); // Now that we know we're removing, keep animVal list in sync as necessary. // Do this *before* touching InternalList() so the removed item can get its // internal value. MaybeRemoveItemFromAnimValListAt(index); // We have to return the removed item, so get it, creating it if necessary: nsRefPtr<SVGTransform> result = GetItemAt(index); // Notify the DOM item of removal *before* modifying the lists so that the // DOM item can copy its *old* value: result->RemovingFromList(); InternalList().RemoveItem(index); mItems.RemoveElementAt(index); UpdateListIndicesFromIndex(mItems, index); Element()->DidChangeTransformList(emptyOrOldValue); if (mAList->IsAnimating()) { Element()->AnimationNeedsResample(); } return result.forget(); }
void DOMSVGLengthList::MaybeRemoveItemFromAnimValListAt(PRUint32 aIndex) { NS_ABORT_IF_FALSE(!IsAnimValList(), "call from baseVal to animVal"); // This needs to be a strong reference; otherwise, the RemovingFromList call // below might drop the last reference to animVal before we're done with it. nsRefPtr<DOMSVGLengthList> animVal = mAList->mAnimVal; if (!animVal || mAList->IsAnimating()) { // No animVal list wrapper, or animVal not a clone of baseVal return; } NS_ABORT_IF_FALSE(animVal->mItems.Length() == mItems.Length(), "animVal list not in sync!"); if (animVal->mItems[aIndex]) { animVal->mItems[aIndex]->RemovingFromList(); } animVal->mItems.RemoveElementAt(aIndex); UpdateListIndicesFromIndex(animVal->mItems, aIndex); }