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 #include "core/svg/SVGFEBlendElement.h"
26 #include "platform/graphics/filters/FilterEffect.h"
27 #include "core/svg/SVGElementInstance.h"
28 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
32 // Animated property definitions
33 DEFINE_ANIMATED_ENUMERATION(SVGFEBlendElement, SVGNames::modeAttr, Mode, mode, BlendModeType)
35 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEBlendElement)
36 REGISTER_LOCAL_ANIMATED_PROPERTY(mode)
37 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
38 END_REGISTER_ANIMATED_PROPERTIES
40 inline SVGFEBlendElement::SVGFEBlendElement(Document& document)
41 : SVGFilterPrimitiveStandardAttributes(SVGNames::feBlendTag, document)
42 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create()))
43 , m_in2(SVGAnimatedString::create(this, SVGNames::in2Attr, SVGString::create()))
44 , m_mode(FEBLEND_MODE_NORMAL)
46 ScriptWrappable::init(this);
47 addToPropertyMap(m_in1);
48 addToPropertyMap(m_in2);
49 registerAnimatedPropertiesForSVGFEBlendElement();
52 PassRefPtr<SVGFEBlendElement> SVGFEBlendElement::create(Document& document)
54 return adoptRef(new SVGFEBlendElement(document));
57 bool SVGFEBlendElement::isSupportedAttribute(const QualifiedName& attrName)
59 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
60 if (supportedAttributes.isEmpty()) {
61 supportedAttributes.add(SVGNames::modeAttr);
62 supportedAttributes.add(SVGNames::inAttr);
63 supportedAttributes.add(SVGNames::in2Attr);
65 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
68 void SVGFEBlendElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
70 if (!isSupportedAttribute(name)) {
71 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
75 if (name == SVGNames::modeAttr) {
76 BlendModeType propertyValue = SVGPropertyTraits<BlendModeType>::fromString(value);
77 if (propertyValue > 0)
78 setModeBaseValue(propertyValue);
82 SVGParsingError parseError = NoError;
84 if (name == SVGNames::inAttr)
85 m_in1->setBaseValueAsString(value, parseError);
86 else if (name == SVGNames::in2Attr)
87 m_in2->setBaseValueAsString(value, parseError);
91 reportAttributeParsingError(parseError, name, value);
94 bool SVGFEBlendElement::setFilterEffectAttribute(FilterEffect* effect, const QualifiedName& attrName)
96 FEBlend* blend = static_cast<FEBlend*>(effect);
97 if (attrName == SVGNames::modeAttr)
98 return blend->setBlendMode(modeCurrentValue());
100 ASSERT_NOT_REACHED();
104 void SVGFEBlendElement::svgAttributeChanged(const QualifiedName& attrName)
106 if (!isSupportedAttribute(attrName)) {
107 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
111 SVGElementInstance::InvalidationGuard invalidationGuard(this);
113 if (attrName == SVGNames::modeAttr) {
114 primitiveAttributeChanged(attrName);
118 if (attrName == SVGNames::inAttr || attrName == SVGNames::in2Attr) {
123 ASSERT_NOT_REACHED();
126 PassRefPtr<FilterEffect> SVGFEBlendElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
128 FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value()));
129 FilterEffect* input2 = filterBuilder->getEffectById(AtomicString(m_in2->currentValue()->value()));
131 if (!input1 || !input2)
134 RefPtr<FilterEffect> effect = FEBlend::create(filter, modeCurrentValue());
135 FilterEffectVector& inputEffects = effect->inputEffects();
136 inputEffects.reserveCapacity(2);
137 inputEffects.append(input1);
138 inputEffects.append(input2);
139 return effect.release();