This source file includes following definitions.
- m_result
- isSupportedAttribute
- parseAttribute
- setFilterEffectAttribute
- svgAttributeChanged
- childrenChanged
- setStandardAttributes
- createRenderer
- rendererIsNeeded
- primitiveAttributeChanged
- invalidateFilterPrimitiveParent
#include "config.h"
#include "core/svg/SVGFilterPrimitiveStandardAttributes.h"
#include "SVGNames.h"
#include "platform/graphics/filters/FilterEffect.h"
#include "core/rendering/svg/RenderSVGResourceFilterPrimitive.h"
#include "core/svg/SVGElementInstance.h"
#include "core/svg/SVGLength.h"
namespace WebCore {
SVGFilterPrimitiveStandardAttributes::SVGFilterPrimitiveStandardAttributes(const QualifiedName& tagName, Document& document)
: SVGElement(tagName, document)
, m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(LengthModeWidth), AllowNegativeLengths))
, m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(LengthModeHeight), AllowNegativeLengths))
, m_width(SVGAnimatedLength::create(this, SVGNames::widthAttr, SVGLength::create(LengthModeWidth), ForbidNegativeLengths))
, m_height(SVGAnimatedLength::create(this, SVGNames::heightAttr, SVGLength::create(LengthModeHeight), ForbidNegativeLengths))
, m_result(SVGAnimatedString::create(this, SVGNames::resultAttr, SVGString::create()))
{
m_x->setDefaultValueAsString("0%");
m_y->setDefaultValueAsString("0%");
m_width->setDefaultValueAsString("100%");
m_height->setDefaultValueAsString("100%");
addToPropertyMap(m_x);
addToPropertyMap(m_y);
addToPropertyMap(m_width);
addToPropertyMap(m_height);
addToPropertyMap(m_result);
}
bool SVGFilterPrimitiveStandardAttributes::isSupportedAttribute(const QualifiedName& attrName)
{
DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
if (supportedAttributes.isEmpty()) {
supportedAttributes.add(SVGNames::xAttr);
supportedAttributes.add(SVGNames::yAttr);
supportedAttributes.add(SVGNames::widthAttr);
supportedAttributes.add(SVGNames::heightAttr);
supportedAttributes.add(SVGNames::resultAttr);
}
return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
}
void SVGFilterPrimitiveStandardAttributes::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
SVGParsingError parseError = NoError;
if (!isSupportedAttribute(name))
SVGElement::parseAttribute(name, value);
else if (name == SVGNames::xAttr)
m_x->setBaseValueAsString(value, parseError);
else if (name == SVGNames::yAttr)
m_y->setBaseValueAsString(value, parseError);
else if (name == SVGNames::widthAttr)
m_width->setBaseValueAsString(value, parseError);
else if (name == SVGNames::heightAttr)
m_height->setBaseValueAsString(value, parseError);
else if (name == SVGNames::resultAttr)
m_result->setBaseValueAsString(value, parseError);
else
ASSERT_NOT_REACHED();
reportAttributeParsingError(parseError, name, value);
}
bool SVGFilterPrimitiveStandardAttributes::setFilterEffectAttribute(FilterEffect*, const QualifiedName&)
{
ASSERT_NOT_REACHED();
return false;
}
void SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(const QualifiedName& attrName)
{
if (!isSupportedAttribute(attrName)) {
SVGElement::svgAttributeChanged(attrName);
return;
}
SVGElementInstance::InvalidationGuard invalidationGuard(this);
invalidate();
}
void SVGFilterPrimitiveStandardAttributes::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
if (!changedByParser)
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);
}
RenderObject* SVGFilterPrimitiveStandardAttributes::createRenderer(RenderStyle*)
{
return new RenderSVGResourceFilterPrimitive(this);
}
bool SVGFilterPrimitiveStandardAttributes::rendererIsNeeded(const RenderStyle& style)
{
if (isSVGFilterElement(parentNode()))
return SVGElement::rendererIsNeeded(style);
return false;
}
void SVGFilterPrimitiveStandardAttributes::primitiveAttributeChanged(const QualifiedName& attribute)
{
if (RenderObject* primitiveRenderer = renderer())
static_cast<RenderSVGResourceFilterPrimitive*>(primitiveRenderer)->primitiveAttributeChanged(attribute);
}
void invalidateFilterPrimitiveParent(SVGElement* element)
{
if (!element)
return;
ContainerNode* parent = element->parentNode();
if (!parent)
return;
RenderObject* renderer = parent->renderer();
if (!renderer || !renderer->isSVGResourceFilterPrimitive())
return;
RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer, false);
}
}