don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGFESpecularLightingElement.cpp
blob26a50bf3180fbee922085455ac52d59e8fc02ad5
1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 2005 Oliver Hunt <oliver@nerget.com>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include "config.h"
24 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
25 #include "SVGFESpecularLightingElement.h"
27 #include "RenderObject.h"
28 #include "SVGColor.h"
29 #include "SVGNames.h"
30 #include "SVGFELightElement.h"
31 #include "SVGParserUtilities.h"
32 #include "SVGResourceFilter.h"
34 namespace WebCore {
36 SVGFESpecularLightingElement::SVGFESpecularLightingElement(const QualifiedName& tagName, Document* doc)
37 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
38 , m_specularConstant(1.0f)
39 , m_specularExponent(1.0f)
40 , m_surfaceScale(1.0f)
41 , m_kernelUnitLengthX(0.0f)
42 , m_kernelUnitLengthY(0.0f)
43 , m_filterEffect(0)
47 SVGFESpecularLightingElement::~SVGFESpecularLightingElement()
49 delete m_filterEffect;
52 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1)
53 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SpecularConstant, specularConstant, SVGNames::specularConstantAttr, m_specularConstant)
54 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SpecularExponent, specularExponent, SVGNames::specularExponentAttr, m_specularExponent)
55 ANIMATED_PROPERTY_DEFINITIONS(SVGFESpecularLightingElement, float, Number, number, SurfaceScale, surfaceScale, SVGNames::surfaceScaleAttr, m_surfaceScale)
56 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFESpecularLightingElement, float, Number, number, KernelUnitLengthX, kernelUnitLengthX, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthX", m_kernelUnitLengthX)
57 ANIMATED_PROPERTY_DEFINITIONS_WITH_CUSTOM_IDENTIFIER(SVGFESpecularLightingElement, float, Number, number, KernelUnitLengthY, kernelUnitLengthY, SVGNames::kernelUnitLengthAttr, "kernelUnitLengthY", m_kernelUnitLengthY)
59 void SVGFESpecularLightingElement::parseMappedAttribute(MappedAttribute* attr)
61 const String& value = attr->value();
62 if (attr->name() == SVGNames::inAttr)
63 setIn1BaseValue(value);
64 else if (attr->name() == SVGNames::surfaceScaleAttr)
65 setSurfaceScaleBaseValue(value.toFloat());
66 else if (attr->name() == SVGNames::specularConstantAttr)
67 setSpecularConstantBaseValue(value.toFloat());
68 else if (attr->name() == SVGNames::specularExponentAttr)
69 setSpecularExponentBaseValue(value.toFloat());
70 else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
71 float x, y;
72 if (parseNumberOptionalNumber(value, x, y)) {
73 setKernelUnitLengthXBaseValue(x);
74 setKernelUnitLengthYBaseValue(y);
76 } else
77 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
80 SVGFESpecularLighting* SVGFESpecularLightingElement::filterEffect(SVGResourceFilter* filter) const
82 if (!m_filterEffect)
83 m_filterEffect = new SVGFESpecularLighting(filter);
85 m_filterEffect->setIn(in1());
86 m_filterEffect->setSpecularConstant((specularConstant()));
87 m_filterEffect->setSpecularExponent((specularExponent()));
88 m_filterEffect->setSurfaceScale((surfaceScale()));
89 m_filterEffect->setKernelUnitLengthX((kernelUnitLengthX()));
90 m_filterEffect->setKernelUnitLengthY((kernelUnitLengthY()));
92 SVGFESpecularLightingElement* nonConstThis = const_cast<SVGFESpecularLightingElement*>(this);
94 RenderStyle* parentStyle = nonConstThis->styleForRenderer(parent()->renderer());
95 RenderStyle* filterStyle = nonConstThis->resolveStyle(parentStyle);
97 m_filterEffect->setLightingColor(filterStyle->svgStyle()->lightingColor());
99 parentStyle->deref(document()->renderArena());
100 filterStyle->deref(document()->renderArena());
102 setStandardAttributes(m_filterEffect);
104 updateLights();
105 return m_filterEffect;
108 void SVGFESpecularLightingElement::updateLights() const
110 if (!m_filterEffect)
111 return;
113 SVGLightSource* light = 0;
114 for (Node* n = firstChild(); n; n = n->nextSibling()) {
115 if (n->hasTagName(SVGNames::feDistantLightTag) ||
116 n->hasTagName(SVGNames::fePointLightTag) ||
117 n->hasTagName(SVGNames::feSpotLightTag)) {
118 SVGFELightElement* lightNode = static_cast<SVGFELightElement*>(n);
119 light = lightNode->lightSource();
120 break;
124 m_filterEffect->setLightSource(light);
129 #endif // ENABLE(SVG)
131 // vim:ts=4:noet