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.
22 #include "SVGFEGaussianBlurElement.h"
24 #include "Attribute.h"
25 #include "FilterEffect.h"
26 #include "SVGElementInstance.h"
27 #include "SVGFilterBuilder.h"
29 #include "SVGParserUtilities.h"
30 #include <wtf/NeverDestroyed.h>
34 // Animated property definitions
35 DEFINE_ANIMATED_STRING(SVGFEGaussianBlurElement, SVGNames::inAttr, In1, in1)
36 DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationXIdentifier(), StdDeviationX, stdDeviationX)
37 DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationYIdentifier(), StdDeviationY, stdDeviationY)
38 DEFINE_ANIMATED_ENUMERATION(SVGFEGaussianBlurElement, SVGNames::edgeModeAttr, EdgeMode, edgeMode, EdgeModeType)
40 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEGaussianBlurElement)
41 REGISTER_LOCAL_ANIMATED_PROPERTY(in1)
42 REGISTER_LOCAL_ANIMATED_PROPERTY(stdDeviationX)
43 REGISTER_LOCAL_ANIMATED_PROPERTY(stdDeviationY)
44 REGISTER_LOCAL_ANIMATED_PROPERTY(edgeMode)
45 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
46 END_REGISTER_ANIMATED_PROPERTIES
48 inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(const QualifiedName& tagName, Document& document)
49 : SVGFilterPrimitiveStandardAttributes(tagName, document)
50 , m_edgeMode(EDGEMODE_NONE)
52 ASSERT(hasTagName(SVGNames::feGaussianBlurTag));
53 registerAnimatedPropertiesForSVGFEGaussianBlurElement();
56 PassRefPtr<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(const QualifiedName& tagName, Document& document)
58 return adoptRef(new SVGFEGaussianBlurElement(tagName, document));
61 const AtomicString& SVGFEGaussianBlurElement::stdDeviationXIdentifier()
63 DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationX", AtomicString::ConstructFromLiteral));
67 const AtomicString& SVGFEGaussianBlurElement::stdDeviationYIdentifier()
69 DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationY", AtomicString::ConstructFromLiteral));
73 void SVGFEGaussianBlurElement::setStdDeviation(float x, float y)
75 setStdDeviationXBaseValue(x);
76 setStdDeviationYBaseValue(y);
80 bool SVGFEGaussianBlurElement::isSupportedAttribute(const QualifiedName& attrName)
82 static NeverDestroyed<HashSet<QualifiedName>> supportedAttributes;
83 if (supportedAttributes.get().isEmpty()) {
84 supportedAttributes.get().add(SVGNames::inAttr);
85 supportedAttributes.get().add(SVGNames::stdDeviationAttr);
86 supportedAttributes.get().add(SVGNames::edgeModeAttr);
88 return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName);
91 void SVGFEGaussianBlurElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
93 if (!isSupportedAttribute(name)) {
94 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
98 if (name == SVGNames::stdDeviationAttr) {
100 if (parseNumberOptionalNumber(value, x, y)) {
101 setStdDeviationXBaseValue(x);
102 setStdDeviationYBaseValue(y);
107 if (name == SVGNames::inAttr) {
108 setIn1BaseValue(value);
112 if (name == SVGNames::edgeModeAttr) {
113 EdgeModeType propertyValue = SVGPropertyTraits<EdgeModeType>::fromString(value);
114 if (propertyValue > 0)
115 setEdgeModeBaseValue(propertyValue);
117 document().accessSVGExtensions().reportWarning(
118 "feGaussianBlur: problem parsing edgeMode=\"" + value
119 + "\". Filtered element will not be displayed.");
123 ASSERT_NOT_REACHED();
126 void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName)
128 if (!isSupportedAttribute(attrName)) {
129 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
133 SVGElementInstance::InvalidationGuard invalidationGuard(this);
135 if (attrName == SVGNames::inAttr
136 || attrName == SVGNames::stdDeviationAttr
137 || attrName == SVGNames::edgeModeAttr) {
142 ASSERT_NOT_REACHED();
145 PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
147 FilterEffect* input1 = filterBuilder->getEffectById(in1());
152 if (stdDeviationX() < 0 || stdDeviationY() < 0)
155 RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationX(), stdDeviationY(), edgeMode());
156 effect->inputEffects().append(input1);
157 return effect.release();