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/SVGFEGaussianBlurElement.h"
26 #include "platform/graphics/filters/FilterEffect.h"
27 #include "core/svg/SVGElementInstance.h"
28 #include "core/svg/SVGParserUtilities.h"
29 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
33 inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(Document& document)
34 : SVGFilterPrimitiveStandardAttributes(SVGNames::feGaussianBlurTag, document)
35 , m_stdDeviation(SVGAnimatedNumberOptionalNumber::create(this, SVGNames::stdDeviationAttr, 0, 0))
36 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create()))
38 ScriptWrappable::init(this);
40 addToPropertyMap(m_stdDeviation);
41 addToPropertyMap(m_in1);
44 PassRefPtr<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(Document& document)
46 return adoptRef(new SVGFEGaussianBlurElement(document));
49 void SVGFEGaussianBlurElement::setStdDeviation(float x, float y)
51 stdDeviationX()->baseValue()->setValue(x);
52 stdDeviationY()->baseValue()->setValue(y);
56 bool SVGFEGaussianBlurElement::isSupportedAttribute(const QualifiedName& attrName)
58 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
59 if (supportedAttributes.isEmpty()) {
60 supportedAttributes.add(SVGNames::inAttr);
61 supportedAttributes.add(SVGNames::stdDeviationAttr);
63 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
66 void SVGFEGaussianBlurElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
68 if (!isSupportedAttribute(name)) {
69 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
73 SVGParsingError parseError = NoError;
75 if (name == SVGNames::inAttr)
76 m_in1->setBaseValueAsString(value, parseError);
77 else if (name == SVGNames::stdDeviationAttr)
78 m_stdDeviation->setBaseValueAsString(value, parseError);
82 reportAttributeParsingError(parseError, name, value);
85 void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName)
87 if (!isSupportedAttribute(attrName)) {
88 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
92 SVGElement::InvalidationGuard invalidationGuard(this);
94 if (attrName == SVGNames::inAttr || attrName == SVGNames::stdDeviationAttr) {
102 PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
104 FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value()));
109 if (stdDeviationX()->currentValue()->value() < 0 || stdDeviationY()->currentValue()->value() < 0)
112 RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationX()->currentValue()->value(), stdDeviationY()->currentValue()->value());
113 effect->inputEffects().append(input1);
114 return effect.release();