SVGClipPathElement.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "SVGClipPathElement.h"
#include "CSSStyleSelector.h"
#include "Document.h"
#include "SVGNames.h"
#include "SVGTransformList.h"
#include "SVGUnitTypes.h"
namespace WebCore {
SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* doc)
: SVGStyledTransformableElement(tagName, doc)
, SVGTests()
, SVGLangSpace()
, SVGExternalResourcesRequired()
, m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
{
}
SVGClipPathElement::~SVGClipPathElement()
{
}
ANIMATED_PROPERTY_DEFINITIONS(SVGClipPathElement, int, Enumeration, enumeration, ClipPathUnits, clipPathUnits, SVGNames::clipPathUnitsAttr, m_clipPathUnits)
void SVGClipPathElement::parseMappedAttribute(MappedAttribute* attr)
{
if (attr->name() == SVGNames::clipPathUnitsAttr) {
if (attr->value() == "userSpaceOnUse")
setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
else if (attr->value() == "objectBoundingBox")
setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
} else {
if (SVGTests::parseMappedAttribute(attr))
return;
if (SVGLangSpace::parseMappedAttribute(attr))
return;
if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
return;
SVGStyledTransformableElement::parseMappedAttribute(attr);
}
}
void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName)
{
SVGStyledTransformableElement::svgAttributeChanged(attrName);
if (!m_clipper)
return;
if (attrName == SVGNames::clipPathUnitsAttr ||
SVGTests::isKnownAttribute(attrName) ||
SVGLangSpace::isKnownAttribute(attrName) ||
SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
SVGStyledTransformableElement::isKnownAttribute(attrName))
m_clipper->invalidate();
}
void SVGClipPathElement::childrenChanged(bool changedByParser)
{
SVGStyledTransformableElement::childrenChanged(changedByParser);
if (!m_clipper)
return;
m_clipper->invalidate();
}
SVGResource* SVGClipPathElement::canvasResource()
{
if (!m_clipper)
m_clipper = new SVGResourceClipper();
else
m_clipper->resetClipData();
bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer()); for (Node* n = firstChild(); n; n = n->nextSibling()) {
if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) {
SVGStyledTransformableElement* styled = static_cast<SVGStyledTransformableElement*>(n);
RenderStyle* pathStyle = document()->styleSelector()->styleForElement(styled, clipPathStyle);
Path pathData = styled->toClipPath();
pathData.transform(styled->animatedLocalTransform());
if (!pathData.isEmpty())
m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox);
pathStyle->deref(document()->renderArena());
}
}
if (m_clipper->clipData().isEmpty()) {
Path pathData;
pathData.addRect(FloatRect());
m_clipper->addClipData(pathData, RULE_EVENODD, bbox);
}
clipPathStyle->deref(document()->renderArena());
return m_clipper.get();
}
}
#endif // ENABLE(SVG)