24 #include "wtf/Platform.h"
29 #include "css/cssstyleselector.h"
37 SVGClipPathElement::SVGClipPathElement(
const QualifiedName& tagName, Document* doc)
38 : SVGStyledTransformableElement(tagName, doc)
41 , SVGExternalResourcesRequired()
42 , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
46 SVGClipPathElement::~SVGClipPathElement()
50 ANIMATED_PROPERTY_DEFINITIONS(SVGClipPathElement,
int, Enumeration, enumeration, ClipPathUnits, clipPathUnits,
SVGNames::clipPathUnitsAttr, m_clipPathUnits)
52 void SVGClipPathElement::parseMappedAttribute(MappedAttribute* attr)
55 if (attr->value() ==
"userSpaceOnUse")
56 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
57 else if (attr->value() ==
"objectBoundingBox")
58 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
60 if (SVGTests::parseMappedAttribute(attr))
62 if (SVGLangSpace::parseMappedAttribute(attr))
64 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
66 SVGStyledTransformableElement::parseMappedAttribute(attr);
70 void SVGClipPathElement::svgAttributeChanged(
const QualifiedName& attrName)
72 SVGStyledTransformableElement::svgAttributeChanged(attrName);
78 SVGTests::isKnownAttribute(attrName) ||
79 SVGLangSpace::isKnownAttribute(attrName) ||
80 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
81 SVGStyledTransformableElement::isKnownAttribute(attrName))
82 m_clipper->invalidate();
85 void SVGClipPathElement::childrenChanged(
bool changedByParser, Node* beforeChange, Node* afterChange,
int childCountDelta)
87 SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
92 m_clipper->invalidate();
95 SVGResource* SVGClipPathElement::canvasResource()
98 m_clipper = SVGResourceClipper::create();
100 m_clipper->resetClipData();
102 bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
104 RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer());
105 for (Node* n = firstChild(); n; n = n->nextSibling()) {
106 if (n->isSVGElement() &&
static_cast<SVGElement*
>(n)->isStyledTransformable()) {
107 SVGStyledTransformableElement* styled =
static_cast<SVGStyledTransformableElement*
>(n);
108 RenderStyle* pathStyle = document()->styleSelector()->styleForElement(styled);
109 if (pathStyle->display() != NONE) {
110 Path pathData = styled->toClipPath();
112 pathData.
transform(styled->animatedLocalTransform());
113 if (!pathData.isEmpty())
114 m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox);
119 if (m_clipper->clipData().isEmpty()) {
122 m_clipper->addClipData(pathData, RULE_EVENODD, bbox);
125 return m_clipper.get();
130 #endif // ENABLE(SVG)
void transform(const AffineTransform &)
void addRect(const FloatRect &)
DOM::QualifiedName clipPathUnitsAttr