SVGPathSegList.cpp [plain text]
#include "config.h"
#include "SVGPathSegList.h"
#include "SVGAnimatedPathSegListPropertyTearOff.h"
#include "SVGPathElement.h"
#include "SVGPathSegWithContext.h"
namespace WebCore {
void SVGPathSegList::clearContextAndRoles()
{
ASSERT(m_values);
for (auto& item : *m_values)
static_cast<SVGPathSegWithContext*>(item.get())->setContextAndRole(nullptr, PathSegUndefinedRole);
}
ExceptionOr<void> SVGPathSegList::clear()
{
ASSERT(m_values);
if (m_values->isEmpty())
return { };
clearContextAndRoles();
return Base::clearValues();
}
ExceptionOr<SVGPathSegList::PtrListItemType> SVGPathSegList::getItem(unsigned index)
{
return Base::getItemValues(index);
}
ExceptionOr<SVGPathSegList::PtrListItemType> SVGPathSegList::replaceItem(PtrListItemType newItem, unsigned index)
{
if (!newItem)
return Exception { SVGException::SVG_WRONG_TYPE_ERR };
if (index < m_values->size()) {
ListItemType replacedItem = m_values->at(index);
ASSERT(replacedItem);
static_cast<SVGPathSegWithContext*>(replacedItem.get())->setContextAndRole(nullptr, PathSegUndefinedRole);
}
return Base::replaceItemValues(newItem, index);
}
ExceptionOr<SVGPathSegList::PtrListItemType> SVGPathSegList::removeItem(unsigned index)
{
auto result = Base::removeItemValues(index);
if (result.hasException())
return result;
auto removedItem = result.releaseReturnValue();
if (removedItem)
static_cast<SVGPathSegWithContext&>(*removedItem).setContextAndRole(nullptr, PathSegUndefinedRole);
return WTFMove(removedItem);
}
SVGPathElement* SVGPathSegList::contextElement() const
{
SVGElement* contextElement = m_animatedProperty->contextElement();
ASSERT(contextElement);
return downcast<SVGPathElement>(contextElement);
}
bool SVGPathSegList::processIncomingListItemValue(const ListItemType& newItem, unsigned* indexToModify)
{
SVGPathSegWithContext* newItemWithContext = static_cast<SVGPathSegWithContext*>(newItem.get());
RefPtr<SVGAnimatedProperty> animatedPropertyOfItem = newItemWithContext->animatedProperty();
newItemWithContext->setContextAndRole(contextElement(), m_pathSegRole);
if (!animatedPropertyOfItem)
return true;
if (!animatedPropertyOfItem->isAnimatedListTearOff())
return true;
bool livesInOtherList = animatedPropertyOfItem != m_animatedProperty;
RefPtr<SVGAnimatedPathSegListPropertyTearOff> propertyTearOff = static_pointer_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;
}
}