2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007 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.
26 #include "SVGClipPathElement.h"
28 #include "CSSStyleSelector.h"
31 #include "SVGTransformList.h"
32 #include "SVGUnitTypes.h"
36 SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* doc)
37 : SVGStyledTransformableElement(tagName, doc)
40 , SVGExternalResourcesRequired()
41 , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
45 SVGClipPathElement::~SVGClipPathElement()
49 ANIMATED_PROPERTY_DEFINITIONS(SVGClipPathElement, int, Enumeration, enumeration, ClipPathUnits, clipPathUnits, SVGNames::clipPathUnitsAttr.localName(), m_clipPathUnits)
51 void SVGClipPathElement::parseMappedAttribute(MappedAttribute* attr)
53 if (attr->name() == SVGNames::clipPathUnitsAttr) {
54 if (attr->value() == "userSpaceOnUse")
55 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
56 else if (attr->value() == "objectBoundingBox")
57 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
59 if (SVGTests::parseMappedAttribute(attr))
61 if (SVGLangSpace::parseMappedAttribute(attr))
63 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
65 SVGStyledTransformableElement::parseMappedAttribute(attr);
69 SVGResource* SVGClipPathElement::canvasResource()
72 m_clipper = new SVGResourceClipper();
74 m_clipper->resetClipData();
76 bool bbox = clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX;
78 RenderStyle* clipPathStyle = styleForRenderer(parent()->renderer()); // FIXME: Manual style resolution is a hack
79 for (Node* n = firstChild(); n; n = n->nextSibling()) {
80 if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) {
81 SVGStyledTransformableElement* styled = static_cast<SVGStyledTransformableElement*>(n);
82 RenderStyle* pathStyle = document()->styleSelector()->styleForElement(styled, clipPathStyle);
83 Path pathData = styled->toClipPath();
84 // FIXME: How do we know the element has done a layout?
85 pathData.transform(styled->animatedLocalTransform());
86 if (!pathData.isEmpty())
87 m_clipper->addClipData(pathData, pathStyle->svgStyle()->clipRule(), bbox);
88 pathStyle->deref(document()->renderArena());
91 if (m_clipper->clipData().isEmpty() ) {
93 pathData.addRect(FloatRect());
94 m_clipper->addClipData(pathData, RULE_EVENODD, bbox);
96 clipPathStyle->deref(document()->renderArena());
97 return m_clipper.get();
100 void SVGClipPathElement::notifyAttributeChange() const
102 if (!m_clipper || !attached() || document()->parsing())
105 m_clipper->invalidate();
106 m_clipper->repaintClients();
111 #endif // ENABLE(SVG)