SVGPathSegList.cpp [plain text]
#include "config.h"
#include "SVGPathSegList.h"
#include "SVGAnimatedPathSegListPropertyTearOff.h"
#include "SVGPathElement.h"
#include "SVGPathSegWithContext.h"
namespace WebCore {
ExceptionOr<void> SVGPathSegList::clear()
{
ASSERT(m_values);
if (m_values->isEmpty())
return { };
return Base::clearValues();
}
ExceptionOr<RefPtr<SVGPathSeg>> SVGPathSegList::getItem(unsigned index)
{
return Base::getItemValues(index);
}
ExceptionOr<RefPtr<SVGPathSeg>> SVGPathSegList::replaceItem(Ref<SVGPathSeg>&& newItem, unsigned index)
{
if (index < m_values->size())
m_values->clearItemContextAndRole(index);
return Base::replaceItemValues(WTFMove(newItem), index);
}
ExceptionOr<RefPtr<SVGPathSeg>> SVGPathSegList::removeItem(unsigned index)
{
if (index < m_values->size())
m_values->clearItemContextAndRole(index);
auto result = Base::removeItemValues(index);
if (result.hasException())
return result;
return result.releaseReturnValue();
}
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;
}
}