SVGPathSegListPropertyTearOff.cpp [plain text]
#include "config.h"
#include "SVGPathSegListPropertyTearOff.h"
#include "SVGAnimatedPathSegListPropertyTearOff.h"
#include "SVGNames.h"
#include "SVGPathElement.h"
#include "SVGPathSegWithContext.h"
namespace WebCore {
void SVGPathSegListPropertyTearOff::clearContextAndRoles()
{
ASSERT(m_values);
for (auto& item : *m_values) {
static_cast<SVGPathSegWithContext*>(item.get())->setContextAndRole(0, PathSegUndefinedRole);
}
}
void SVGPathSegListPropertyTearOff::clear(ExceptionCode& ec)
{
ASSERT(m_values);
if (m_values->isEmpty())
return;
clearContextAndRoles();
SVGPathSegListPropertyTearOff::Base::clearValues(ec);
}
SVGPathSegListPropertyTearOff::PtrListItemType SVGPathSegListPropertyTearOff::getItem(unsigned index, ExceptionCode& ec)
{
ListItemType returnedItem = Base::getItemValues(index, ec);
if (returnedItem) {
ASSERT(static_cast<SVGPathSegWithContext*>(returnedItem.get())->contextElement() == contextElement());
ASSERT(static_cast<SVGPathSegWithContext*>(returnedItem.get())->role() == m_pathSegRole);
}
return returnedItem;
}
SVGPathSegListPropertyTearOff::PtrListItemType SVGPathSegListPropertyTearOff::replaceItem(PtrListItemType newItem, unsigned index, ExceptionCode& ec)
{
if (!newItem) {
ec = SVGException::SVG_WRONG_TYPE_ERR;
return 0;
}
if (index < m_values->size()) {
ListItemType replacedItem = m_values->at(index);
ASSERT(replacedItem);
static_cast<SVGPathSegWithContext*>(replacedItem.get())->setContextAndRole(0, PathSegUndefinedRole);
}
return Base::replaceItemValues(newItem, index, ec);
}
SVGPathSegListPropertyTearOff::PtrListItemType SVGPathSegListPropertyTearOff::removeItem(unsigned index, ExceptionCode& ec)
{
SVGPathSegListPropertyTearOff::ListItemType removedItem = SVGPathSegListPropertyTearOff::Base::removeItemValues(index, ec);
if (removedItem)
static_cast<SVGPathSegWithContext*>(removedItem.get())->setContextAndRole(0, PathSegUndefinedRole);
return removedItem;
}
SVGPathElement* SVGPathSegListPropertyTearOff::contextElement() const
{
SVGElement* contextElement = m_animatedProperty->contextElement();
ASSERT(contextElement);
return downcast<SVGPathElement>(contextElement);
}
bool SVGPathSegListPropertyTearOff::processIncomingListItemValue(const ListItemType& newItem, unsigned* indexToModify)
{
SVGPathSegWithContext* newItemWithContext = static_cast<SVGPathSegWithContext*>(newItem.get());
SVGAnimatedProperty* animatedPropertyOfItem = newItemWithContext->animatedProperty();
newItemWithContext->setContextAndRole(contextElement(), m_pathSegRole);
if (!animatedPropertyOfItem)
return true;
if (!animatedPropertyOfItem->isAnimatedListTearOff())
return true;
bool livesInOtherList = animatedPropertyOfItem != m_animatedProperty;
SVGAnimatedPathSegListPropertyTearOff* propertyTearOff = static_cast<SVGAnimatedPathSegListPropertyTearOff*>(animatedPropertyOfItem);
int indexToRemove = propertyTearOff->findItem(newItem.get());
ASSERT(indexToRemove != -1);
if (!livesInOtherList && indexToModify && static_cast<unsigned>(indexToRemove) == *indexToModify)
return false;
propertyTearOff->removeItemFromList(indexToRemove, livesInOtherList);
if (!indexToModify)
return true;
if (!livesInOtherList) {
unsigned& index = *indexToModify;
if (static_cast<unsigned>(indexToRemove) < index)
--index;
}
return true;
}
}