SVGPathElement.cpp [plain text]
#include "config.h"
#include "SVGPathElement.h"
#include "RenderSVGPath.h"
#include "RenderSVGResource.h"
#include "SVGDocumentExtensions.h"
#include "SVGMPathElement.h"
#include "SVGNames.h"
#include "SVGPathUtilities.h"
#include "SVGPoint.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(SVGPathElement);
inline SVGPathElement::SVGPathElement(const QualifiedName& tagName, Document& document)
: SVGGeometryElement(tagName, document)
{
ASSERT(hasTagName(SVGNames::pathTag));
static std::once_flag onceFlag;
std::call_once(onceFlag, [] {
PropertyRegistry::registerProperty<SVGNames::dAttr, &SVGPathElement::m_pathSegList>();
});
}
Ref<SVGPathElement> SVGPathElement::create(const QualifiedName& tagName, Document& document)
{
return adoptRef(*new SVGPathElement(tagName, document));
}
void SVGPathElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == SVGNames::dAttr) {
if (!m_pathSegList->baseVal()->parse(value))
document().accessSVGExtensions().reportError("Problem parsing d=\"" + value + "\"");
return;
}
SVGGeometryElement::parseAttribute(name, value);
}
void SVGPathElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (attrName == SVGNames::dAttr) {
InstanceInvalidationGuard guard(*this);
invalidateMPathDependencies();
if (auto* renderer = downcast<RenderSVGPath>(this->renderer())) {
renderer->setNeedsShapeUpdate();
RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
}
return;
}
SVGGeometryElement::svgAttributeChanged(attrName);
}
void SVGPathElement::invalidateMPathDependencies()
{
if (HashSet<SVGElement*>* dependencies = document().accessSVGExtensions().setOfElementsReferencingTarget(*this)) {
for (auto* element : *dependencies) {
if (is<SVGMPathElement>(*element))
downcast<SVGMPathElement>(*element).targetPathChanged();
}
}
}
Node::InsertedIntoAncestorResult SVGPathElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree)
{
SVGGeometryElement::insertedIntoAncestor(insertionType, parentOfInsertedTree);
invalidateMPathDependencies();
return InsertedIntoAncestorResult::Done;
}
void SVGPathElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
{
SVGGeometryElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
invalidateMPathDependencies();
}
float SVGPathElement::getTotalLength() const
{
return getTotalLengthOfSVGPathByteStream(pathByteStream());
}
ExceptionOr<Ref<SVGPoint>> SVGPathElement::getPointAtLength(float distance) const
{
distance = clampTo<float>(distance, 0, getTotalLength());
return SVGPoint::create(getPointAtLengthOfSVGPathByteStream(pathByteStream(), distance));
}
unsigned SVGPathElement::getPathSegAtLength(float length) const
{
return getSVGPathSegAtLengthFromSVGPathByteStream(pathByteStream(), length);
}
FloatRect SVGPathElement::getBBox(StyleUpdateStrategy styleUpdateStrategy)
{
if (styleUpdateStrategy == AllowStyleUpdate)
document().updateLayoutIgnorePendingStylesheets();
RenderSVGPath* renderer = downcast<RenderSVGPath>(this->renderer());
if (!renderer || !renderer->hasPath())
return { };
return renderer->path().boundingRect();
}
RenderPtr<RenderElement> SVGPathElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
{
return createRenderer<RenderSVGPath>(*this, WTFMove(style));
}
}