Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / svg / SVGFEBlendElement.cpp
blob03c5795340c5304b96c8a4ae1aa6d3883c573136
1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "config.h"
23 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGFEBlendElement.h"
26 #include "MappedAttribute.h"
27 #include "SVGResourceFilter.h"
29 namespace WebCore {
31 SVGFEBlendElement::SVGFEBlendElement(const QualifiedName& tagName, Document* doc)
32 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
33 , m_in1(this, SVGNames::inAttr)
34 , m_in2(this, SVGNames::in2Attr)
35 , m_mode(this, SVGNames::modeAttr, FEBLEND_MODE_NORMAL)
39 SVGFEBlendElement::~SVGFEBlendElement()
43 void SVGFEBlendElement::parseMappedAttribute(MappedAttribute* attr)
45 const String& value = attr->value();
46 if (attr->name() == SVGNames::modeAttr) {
47 if (value == "normal")
48 setModeBaseValue(FEBLEND_MODE_NORMAL);
49 else if (value == "multiply")
50 setModeBaseValue(FEBLEND_MODE_MULTIPLY);
51 else if (value == "screen")
52 setModeBaseValue(FEBLEND_MODE_SCREEN);
53 else if (value == "darken")
54 setModeBaseValue(FEBLEND_MODE_DARKEN);
55 else if (value == "lighten")
56 setModeBaseValue(FEBLEND_MODE_LIGHTEN);
57 } else if (attr->name() == SVGNames::inAttr)
58 setIn1BaseValue(value);
59 else if (attr->name() == SVGNames::in2Attr)
60 setIn2BaseValue(value);
61 else
62 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
65 bool SVGFEBlendElement::build(SVGResourceFilter* filterResource)
67 FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
68 FilterEffect* input2 = filterResource->builder()->getEffectById(in2());
70 if (!input1 || !input2)
71 return false;
73 RefPtr<FilterEffect> effect = FEBlend::create(input1, input2, static_cast<BlendModeType>(mode()));
74 filterResource->addFilterEffect(this, effect.release());
76 return true;
81 #endif // ENABLE(SVG)
83 // vim:ts=4:noet