Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / svg / SVGFEDiffuseLightingElement.cpp
blobed6e3538509cef9ebf5f5383089636c2b60f579e
1 /*
2 Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "config.h"
22 #if ENABLE(SVG) && ENABLE(FILTERS)
23 #include "SVGFEDiffuseLightingElement.h"
25 #include "Attr.h"
26 #include "MappedAttribute.h"
27 #include "RenderObject.h"
28 #include "SVGColor.h"
29 #include "SVGFEDiffuseLighting.h"
30 #include "SVGFELightElement.h"
31 #include "SVGNames.h"
32 #include "SVGParserUtilities.h"
33 #include "SVGRenderStyle.h"
34 #include "SVGResourceFilter.h"
36 namespace WebCore {
38 char SVGKernelUnitLengthXIdentifier[] = "SVGKernelUnitLengthX";
39 char SVGKernelUnitLengthYIdentifier[] = "SVGKernelUnitLengthY";
41 SVGFEDiffuseLightingElement::SVGFEDiffuseLightingElement(const QualifiedName& tagName, Document* doc)
42 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
43 , m_in1(this, SVGNames::inAttr)
44 , m_diffuseConstant(this, SVGNames::diffuseConstantAttr, 1.0f)
45 , m_surfaceScale(this, SVGNames::surfaceScaleAttr, 1.0f)
46 , m_kernelUnitLengthX(this, SVGNames::kernelUnitLengthAttr)
47 , m_kernelUnitLengthY(this, SVGNames::kernelUnitLengthAttr)
51 SVGFEDiffuseLightingElement::~SVGFEDiffuseLightingElement()
55 void SVGFEDiffuseLightingElement::parseMappedAttribute(MappedAttribute *attr)
57 const String& value = attr->value();
58 if (attr->name() == SVGNames::inAttr)
59 setIn1BaseValue(value);
60 else if (attr->name() == SVGNames::surfaceScaleAttr)
61 setSurfaceScaleBaseValue(value.toFloat());
62 else if (attr->name() == SVGNames::diffuseConstantAttr)
63 setDiffuseConstantBaseValue(value.toInt());
64 else if (attr->name() == SVGNames::kernelUnitLengthAttr) {
65 float x, y;
66 if (parseNumberOptionalNumber(value, x, y)) {
67 setKernelUnitLengthXBaseValue(x);
68 setKernelUnitLengthYBaseValue(y);
70 } else
71 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
74 bool SVGFEDiffuseLightingElement::build(SVGResourceFilter* filterResource)
76 FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
78 if (!input1)
79 return false;
81 RefPtr<RenderStyle> filterStyle = styleForRenderer();
82 Color color = filterStyle->svgStyle()->lightingColor();
84 RefPtr<FilterEffect> effect = FEDiffuseLighting::create(input1, color, surfaceScale(), diffuseConstant(),
85 kernelUnitLengthX(), kernelUnitLengthY(), findLights());
86 filterResource->addFilterEffect(this, effect.release());
88 return true;
91 PassRefPtr<LightSource> SVGFEDiffuseLightingElement::findLights() const
93 for (Node* n = firstChild(); n; n = n->nextSibling()) {
94 if (n->hasTagName(SVGNames::feDistantLightTag) ||
95 n->hasTagName(SVGNames::fePointLightTag) ||
96 n->hasTagName(SVGNames::feSpotLightTag)) {
97 SVGFELightElement* lightNode = static_cast<SVGFELightElement*>(n);
98 return lightNode->lightSource();
102 return 0;
107 #endif // ENABLE(SVG)