SVGFilterPrimitiveStandardAttributes.cpp [plain text]
#include "config.h"
#include "SVGFilterPrimitiveStandardAttributes.h"
#include "FilterEffect.h"
#include "RenderSVGResourceFilterPrimitive.h"
#include "SVGFilterBuilder.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/NeverDestroyed.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(SVGFilterPrimitiveStandardAttributes);
SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document& document)
: SVGElement(tagName, document)
{
registerAttributes();
}
void SVGFilterPrimitiveStandardAttributes::registerAttributes()
{
auto& registry = attributeRegistry();
if (!registry.isEmpty())
return;
registry.registerAttribute<SVGNames::xAttr, &SVGFilterPrimitiveStandardAttributes::m_x>();
registry.registerAttribute<SVGNames::yAttr, &SVGFilterPrimitiveStandardAttributes::m_y>();
registry.registerAttribute<SVGNames::widthAttr, &SVGFilterPrimitiveStandardAttributes::m_width>();
registry.registerAttribute<SVGNames::heightAttr, &SVGFilterPrimitiveStandardAttributes::m_height>();
registry.registerAttribute<SVGNames::resultAttr, &SVGFilterPrimitiveStandardAttributes::m_result>();
}
void SVGFilterPrimitiveStandardAttributes::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
SVGParsingError parseError = NoError;
if (name == SVGNames::xAttr)
m_x.setValue(SVGLengthValue::construct(LengthModeWidth, value, parseError));
else if (name == SVGNames::yAttr)
m_y.setValue(SVGLengthValue::construct(LengthModeHeight, value, parseError));
else if (name == SVGNames::widthAttr)
m_width.setValue(SVGLengthValue::construct(LengthModeWidth, value, parseError));
else if (name == SVGNames::heightAttr)
m_height.setValue(SVGLengthValue::construct(LengthModeHeight, value, parseError));
else if (name == SVGNames::resultAttr)
m_result.setValue(value);
reportAttributeParsingError(parseError, name, value);
SVGElement::parseAttribute(name, value);
}
bool SVGFilterPrimitiveStandardAttributes::setFilterEffectAttribute(FilterEffect*, const QualifiedName&)
{
ASSERT_NOT_REACHED();
return false;
}
void SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(const QualifiedName& attrName)
{
if (isKnownAttribute(attrName)) {
InstanceInvalidationGuard guard(*this);
invalidate();
return;
}
SVGElement::svgAttributeChanged(attrName);
}
void SVGFilterPrimitiveStandardAttributes::childrenChanged(const ChildChange& change)
{
SVGElement::childrenChanged(change);
if (change.source == ChildChangeSource::Parser)
return;
invalidate();
}
void SVGFilterPrimitiveStandardAttributes::setStandardAttributes(FilterEffect* filterEffect) const
{
ASSERT(filterEffect);
if (!filterEffect)
return;
if (hasAttribute(SVGNames::xAttr))
filterEffect->setHasX(true);
if (hasAttribute(SVGNames::yAttr))
filterEffect->setHasY(true);
if (hasAttribute(SVGNames::widthAttr))
filterEffect->setHasWidth(true);
if (hasAttribute(SVGNames::heightAttr))
filterEffect->setHasHeight(true);
}
RenderPtr<RenderElement> SVGFilterPrimitiveStandardAttributes::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
{
return createRenderer<RenderSVGResourceFilterPrimitive>(*this, WTFMove(style));
}
bool SVGFilterPrimitiveStandardAttributes::rendererIsNeeded(const RenderStyle& style)
{
if (parentNode() && (parentNode()->hasTagName(SVGNames::filterTag)))
return SVGElement::rendererIsNeeded(style);
return false;
}
void invalidateFilterPrimitiveParent(SVGElement* element)
{
if (!element)
return;
auto parent = makeRefPtr(element->parentNode());
if (!parent)
return;
RenderElement* renderer = parent->renderer();
if (!renderer || !renderer->isSVGResourceFilterPrimitive())
return;
RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer, false);
}
}