don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGClipPathElement.cpp
bloba64db9450f3f521bd5548e555496d8681a3d9f2a
1 /*
2 Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 #include "config.h"
24 #include "wtf/Platform.h"
26 #if ENABLE(SVG)
27 #include "SVGClipPathElement.h"
29 #include "CSSStyleSelector.h"
30 #include "Document.h"
31 #include "SVGNames.h"
32 #include "SVGTransformList.h"
33 #include "SVGUnitTypes.h"
35 namespace WebCore {
37 SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* doc)
38 : SVGStyledTransformableElement(tagName, doc)
39 , SVGTests()
40 , SVGLangSpace()
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)
54 if (attr->name() == SVGNames::clipPathUnitsAttr) {
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);
59 } else {
60 if (SVGTests::parseMappedAttribute(attr))
61 return;
62 if (SVGLangSpace::parseMappedAttribute(attr))
63 return;
64 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
65 return;
66 SVGStyledTransformableElement::parseMappedAttribute(attr);
70 void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName)
72 SVGStyledTransformableElement::svgAttributeChanged(attrName);
74 if (!m_clipper)
75 return;
77 if (attrName == SVGNames::clipPathUnitsAttr ||
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);
89 if (!m_clipper)
90 return;
92 m_clipper->invalidate();
95 SVGResource* SVGClipPathElement::canvasResource()
97 if (!m_clipper)
98 m_clipper = SVGResourceClipper::create();
99 else
100 m_clipper->resetClipData();
102 bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
104 RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer()); // FIXME: Manual style resolution is a hack
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/*khtml, clipPathStyle*/);
109 if (pathStyle->display() != NONE) {
110 Path pathData = styled->toClipPath();
111 // FIXME: How do we know the element has done a layout?
112 pathData.transform(styled->animatedLocalTransform());
113 if (!pathData.isEmpty())
114 m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox);
116 //khtml pathStyle->deref(document()->renderArena());
119 if (m_clipper->clipData().isEmpty()) {
120 Path pathData;
121 pathData.addRect(FloatRect());
122 m_clipper->addClipData(pathData, RULE_EVENODD, bbox);
124 //khtml clipPathStyle->deref(document()->renderArena());
125 return m_clipper.get();
130 #endif // ENABLE(SVG)