void
nsSVGPathSegList::AppendElement(nsSVGPathSeg* aElement)
{
  WillModify();
  // XXX: we should only remove an item from its current list if we
  // successfully added it to this list
  RemoveFromCurrentList(aElement);
  mSegments.AppendObject(aElement);
  aElement->SetCurrentList(this);
  DidModify();
}
Example #2
0
void
nsSVGPathSegList::InsertElementAt(nsSVGPathSeg* aElement, PRInt32 index)
{
  WillModify();
  // XXX: we should only remove an item from its current list if we
  // successfully added it to this list
  RemoveFromCurrentList(aElement);
  mSegments.InsertObjectAt(aElement, index);
  aElement->SetCurrentList(this);
  DidModify();
}
/* nsIDOMSVGPathSeg replaceItem (in nsIDOMSVGPathSeg newItem, in unsigned long index); */
NS_IMETHODIMP nsSVGPathSegList::ReplaceItem(nsIDOMSVGPathSeg *newItem,
                                            PRUint32 index,
                                            nsIDOMSVGPathSeg **_retval)
{
  NS_ENSURE_NATIVE_PATH_SEG(newItem, _retval);

  // immediately remove the new item from its current list
  nsSVGPathSeg* newItemSeg = static_cast<nsSVGPathSeg*>(newItem);
  RemoveFromCurrentList(newItemSeg);

  if (index >= static_cast<PRUint32>(mSegments.Count())) {
    return NS_ERROR_DOM_INDEX_SIZE_ERR;
  }

  // NOTE: the new item can never be the item we will be replacing now that we removed it from its current list beforehand
  InsertElementAt(newItemSeg, index);
  RemoveFromCurrentList(static_cast<nsSVGPathSeg*>(mSegments.ObjectAt(index+1)));
  NS_ADDREF(*_retval = newItem);

  return NS_OK;
}