SVGGeometryElement.cpp [plain text]
#include "config.h"
#include "SVGGeometryElement.h"
#include "DOMPoint.h"
#include "RenderSVGResource.h"
#include "RenderSVGShape.h"
#include "SVGDocumentExtensions.h"
#include "SVGPathUtilities.h"
#include "SVGPoint.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(SVGGeometryElement);
SVGGeometryElement::SVGGeometryElement(const QualifiedName& tagName, Document& document)
: SVGGraphicsElement(tagName, document)
{
static std::once_flag onceFlag;
std::call_once(onceFlag, [] {
PropertyRegistry::registerProperty<SVGNames::pathLengthAttr, &SVGGeometryElement::m_pathLength>();
});
}
float SVGGeometryElement::getTotalLength() const
{
document().updateLayoutIgnorePendingStylesheets();
auto* renderer = downcast<RenderSVGShape>(this->renderer());
if (!renderer)
return 0;
return renderer->getTotalLength();
}
ExceptionOr<Ref<SVGPoint>> SVGGeometryElement::getPointAtLength(float distance) const
{
document().updateLayoutIgnorePendingStylesheets();
auto* renderer = downcast<RenderSVGShape>(this->renderer());
if (!renderer)
return Exception { InvalidStateError };
distance = clampTo<float>(distance, 0, getTotalLength());
return SVGPoint::create(renderer->getPointAtLength(distance));
}
bool SVGGeometryElement::isPointInFill(DOMPointInit&& pointInit)
{
document().updateLayoutIgnorePendingStylesheets();
auto* renderer = downcast<RenderSVGShape>(this->renderer());
if (!renderer)
return false;
FloatPoint point {static_cast<float>(pointInit.x), static_cast<float>(pointInit.y)};
return renderer->isPointInFill(point);
}
bool SVGGeometryElement::isPointInStroke(DOMPointInit&& pointInit)
{
document().updateLayoutIgnorePendingStylesheets();
auto* renderer = downcast<RenderSVGShape>(this->renderer());
if (!renderer)
return false;
FloatPoint point {static_cast<float>(pointInit.x), static_cast<float>(pointInit.y)};
return renderer->isPointInStroke(point);
}
void SVGGeometryElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == SVGNames::pathLengthAttr) {
m_pathLength->setBaseValInternal(value.toFloat());
if (m_pathLength->baseVal() < 0)
document().accessSVGExtensions().reportError("A negative value for path attribute <pathLength> is not allowed");
return;
}
SVGGraphicsElement::parseAttribute(name, value);
}
void SVGGeometryElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (attrName == SVGNames::pathLengthAttr) {
InstanceInvalidationGuard guard(*this);
if (auto* renderer = this->renderer())
RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
return;
}
SVGGraphicsElement::svgAttributeChanged(attrName);
}
}