SVGPathSegListPropertyTearOff.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "SVGPathSegListPropertyTearOff.h"
#include "SVGAnimatedPathSegListPropertyTearOff.h"
#include "SVGNames.h"
#include "SVGPathElement.h"
#include "SVGPathSegWithContext.h"
namespace WebCore {
void SVGPathSegListPropertyTearOff::clear(ExceptionCode& ec)
{
ASSERT(m_values);
if (m_values->isEmpty())
return;
unsigned size = m_values->size();
for (unsigned i = 0; i < size; ++i) {
ListItemType item = m_values->at(i);
static_cast<SVGPathSegWithContext*>(item.get())->setContextAndRole(0, PathSegUndefinedRole);
}
SVGPathSegListPropertyTearOff::Base::clearValues(ec);
}
SVGPathSegListPropertyTearOff::PassListItemType 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.release();
}
SVGPathSegListPropertyTearOff::PassListItemType 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.release();
}
SVGPathElement* SVGPathSegListPropertyTearOff::contextElement() const
{
SVGElement* contextElement = m_animatedProperty->contextElement();
ASSERT(contextElement);
ASSERT(contextElement->hasTagName(SVGNames::pathTag));
return static_cast<SVGPathElement*>(contextElement);
}
void 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;
if (!animatedPropertyOfItem->isAnimatedListTearOff())
return;
bool livesInOtherList = animatedPropertyOfItem != m_animatedProperty;
int removedIndex = static_cast<SVGAnimatedPathSegListPropertyTearOff*>(animatedPropertyOfItem)->removeItemFromList(newItem.get(), livesInOtherList);
ASSERT(removedIndex != -1);
if (!indexToModify)
return;
if (!livesInOtherList) {
unsigned& index = *indexToModify;
if (static_cast<unsigned>(removedIndex) < index)
--index;
}
}
}
#endif // ENABLE(SVG)