KHTML
SVGClipPathElement.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #include "wtf/Platform.h"
00025
00026 #if ENABLE(SVG)
00027 #include "SVGClipPathElement.h"
00028
00029 #include "css/cssstyleselector.h"
00030 #include "Document.h"
00031 #include "SVGNames.h"
00032 #include "SVGTransformList.h"
00033 #include "SVGUnitTypes.h"
00034
00035 namespace WebCore {
00036
00037 SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* doc)
00038 : SVGStyledTransformableElement(tagName, doc)
00039 , SVGTests()
00040 , SVGLangSpace()
00041 , SVGExternalResourcesRequired()
00042 , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
00043 {
00044 }
00045
00046 SVGClipPathElement::~SVGClipPathElement()
00047 {
00048 }
00049
00050 ANIMATED_PROPERTY_DEFINITIONS(SVGClipPathElement, int, Enumeration, enumeration, ClipPathUnits, clipPathUnits, SVGNames::clipPathUnitsAttr, m_clipPathUnits)
00051
00052 void SVGClipPathElement::parseMappedAttribute(MappedAttribute* attr)
00053 {
00054 if (attr->name() == SVGNames::clipPathUnitsAttr) {
00055 if (attr->value() == "userSpaceOnUse")
00056 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
00057 else if (attr->value() == "objectBoundingBox")
00058 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
00059 } else {
00060 if (SVGTests::parseMappedAttribute(attr))
00061 return;
00062 if (SVGLangSpace::parseMappedAttribute(attr))
00063 return;
00064 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
00065 return;
00066 SVGStyledTransformableElement::parseMappedAttribute(attr);
00067 }
00068 }
00069
00070 void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName)
00071 {
00072 SVGStyledTransformableElement::svgAttributeChanged(attrName);
00073
00074 if (!m_clipper)
00075 return;
00076
00077 if (attrName == SVGNames::clipPathUnitsAttr ||
00078 SVGTests::isKnownAttribute(attrName) ||
00079 SVGLangSpace::isKnownAttribute(attrName) ||
00080 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
00081 SVGStyledTransformableElement::isKnownAttribute(attrName))
00082 m_clipper->invalidate();
00083 }
00084
00085 void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
00086 {
00087 SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
00088
00089 if (!m_clipper)
00090 return;
00091
00092 m_clipper->invalidate();
00093 }
00094
00095 SVGResource* SVGClipPathElement::canvasResource()
00096 {
00097 if (!m_clipper)
00098 m_clipper = SVGResourceClipper::create();
00099 else
00100 m_clipper->resetClipData();
00101
00102 bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
00103
00104 RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer());
00105 for (Node* n = firstChild(); n; n = n->nextSibling()) {
00106 if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) {
00107 SVGStyledTransformableElement* styled = static_cast<SVGStyledTransformableElement*>(n);
00108 RenderStyle* pathStyle = document()->styleSelector()->styleForElement(styled);
00109 if (pathStyle->display() != NONE) {
00110 Path pathData = styled->toClipPath();
00111
00112 pathData.transform(styled->animatedLocalTransform());
00113 if (!pathData.isEmpty())
00114 m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox);
00115 }
00116
00117 }
00118 }
00119 if (m_clipper->clipData().isEmpty()) {
00120 Path pathData;
00121 pathData.addRect(FloatRect());
00122 m_clipper->addClipData(pathData, RULE_EVENODD, bbox);
00123 }
00124
00125 return m_clipper.get();
00126 }
00127
00128 }
00129
00130 #endif // ENABLE(SVG)