2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 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.
23 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGFEBlendElement.h"
26 #include "Attribute.h"
27 #include "FilterEffect.h"
28 #include "SVGElementInstance.h"
29 #include "SVGFilterBuilder.h"
34 // Animated property definitions
35 DEFINE_ANIMATED_STRING(SVGFEBlendElement, SVGNames::inAttr, In1, in1)
36 DEFINE_ANIMATED_STRING(SVGFEBlendElement, SVGNames::in2Attr, In2, in2)
37 DEFINE_ANIMATED_ENUMERATION(SVGFEBlendElement, SVGNames::modeAttr, Mode, mode, BlendModeType)
39 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEBlendElement)
40 REGISTER_LOCAL_ANIMATED_PROPERTY(in1)
41 REGISTER_LOCAL_ANIMATED_PROPERTY(in2)
42 REGISTER_LOCAL_ANIMATED_PROPERTY(mode)
43 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
44 END_REGISTER_ANIMATED_PROPERTIES
46 inline SVGFEBlendElement::SVGFEBlendElement(const QualifiedName& tagName, Document* document)
47 : SVGFilterPrimitiveStandardAttributes(tagName, document)
48 , m_mode(FEBLEND_MODE_NORMAL)
50 ASSERT(hasTagName(SVGNames::feBlendTag));
51 registerAnimatedPropertiesForSVGFEBlendElement();
54 PassRefPtr<SVGFEBlendElement> SVGFEBlendElement::create(const QualifiedName& tagName, Document* document)
56 return adoptRef(new SVGFEBlendElement(tagName, document));
59 bool SVGFEBlendElement::isSupportedAttribute(const QualifiedName& attrName)
61 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
62 if (supportedAttributes.isEmpty()) {
63 supportedAttributes.add(SVGNames::modeAttr);
64 supportedAttributes.add(SVGNames::inAttr);
65 supportedAttributes.add(SVGNames::in2Attr);
67 return supportedAttributes.contains(attrName);
70 void SVGFEBlendElement::parseMappedAttribute(Attribute* attr)
72 if (!isSupportedAttribute(attr->name())) {
73 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
77 const AtomicString& value = attr->value();
78 if (attr->name() == SVGNames::modeAttr) {
79 BlendModeType propertyValue = SVGPropertyTraits<BlendModeType>::fromString(value);
80 if (propertyValue > 0)
81 setModeBaseValue(propertyValue);
85 if (attr->name() == SVGNames::inAttr) {
86 setIn1BaseValue(value);
90 if (attr->name() == SVGNames::in2Attr) {
91 setIn2BaseValue(value);
98 bool SVGFEBlendElement::setFilterEffectAttribute(FilterEffect* effect, const QualifiedName& attrName)
100 FEBlend* blend = static_cast<FEBlend*>(effect);
101 if (attrName == SVGNames::modeAttr)
102 return blend->setBlendMode(mode());
104 ASSERT_NOT_REACHED();
108 void SVGFEBlendElement::svgAttributeChanged(const QualifiedName& attrName)
110 if (!isSupportedAttribute(attrName)) {
111 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
115 SVGElementInstance::InvalidationGuard invalidationGuard(this);
117 if (attrName == SVGNames::modeAttr) {
118 primitiveAttributeChanged(attrName);
122 if (attrName == SVGNames::inAttr || attrName == SVGNames::in2Attr) {
127 ASSERT_NOT_REACHED();
130 PassRefPtr<FilterEffect> SVGFEBlendElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
132 FilterEffect* input1 = filterBuilder->getEffectById(in1());
133 FilterEffect* input2 = filterBuilder->getEffectById(in2());
135 if (!input1 || !input2)
138 RefPtr<FilterEffect> effect = FEBlend::create(filter, mode());
139 FilterEffectVector& inputEffects = effect->inputEffects();
140 inputEffects.reserveCapacity(2);
141 inputEffects.append(input1);
142 inputEffects.append(input2);
143 return effect.release();
148 #endif // ENABLE(SVG)