blob: 30883f8375b1d517b6441ce1879d8b2544e712c1 [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 *
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.
9 *
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.
14 *
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.
19 */
20
21#include "config.h"
22
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010023#include "core/svg/SVGFEGaussianBlurElement.h"
24
25#include "SVGNames.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010026#include "core/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"
30
31namespace WebCore {
32
33// Animated property definitions
34DEFINE_ANIMATED_STRING(SVGFEGaussianBlurElement, SVGNames::inAttr, In1, in1)
35DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationXIdentifier(), StdDeviationX, stdDeviationX)
36DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationYIdentifier(), StdDeviationY, stdDeviationY)
37
38BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEGaussianBlurElement)
39 REGISTER_LOCAL_ANIMATED_PROPERTY(in1)
40 REGISTER_LOCAL_ANIMATED_PROPERTY(stdDeviationX)
41 REGISTER_LOCAL_ANIMATED_PROPERTY(stdDeviationY)
42 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
43END_REGISTER_ANIMATED_PROPERTIES
44
45inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(const QualifiedName& tagName, Document* document)
46 : SVGFilterPrimitiveStandardAttributes(tagName, document)
47{
48 ASSERT(hasTagName(SVGNames::feGaussianBlurTag));
49 ScriptWrappable::init(this);
50 registerAnimatedPropertiesForSVGFEGaussianBlurElement();
51}
52
53PassRefPtr<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(const QualifiedName& tagName, Document* document)
54{
55 return adoptRef(new SVGFEGaussianBlurElement(tagName, document));
56}
57
58const AtomicString& SVGFEGaussianBlurElement::stdDeviationXIdentifier()
59{
60 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationX", AtomicString::ConstructFromLiteral));
61 return s_identifier;
62}
63
64const AtomicString& SVGFEGaussianBlurElement::stdDeviationYIdentifier()
65{
66 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationY", AtomicString::ConstructFromLiteral));
67 return s_identifier;
68}
69
70void SVGFEGaussianBlurElement::setStdDeviation(float x, float y)
71{
72 setStdDeviationXBaseValue(x);
73 setStdDeviationYBaseValue(y);
74 invalidate();
75}
76
77bool SVGFEGaussianBlurElement::isSupportedAttribute(const QualifiedName& attrName)
78{
79 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
80 if (supportedAttributes.isEmpty()) {
81 supportedAttributes.add(SVGNames::inAttr);
82 supportedAttributes.add(SVGNames::stdDeviationAttr);
83 }
Ben Murdoch591b9582013-07-10 11:41:44 +010084 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010085}
86
87void SVGFEGaussianBlurElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
88{
89 if (!isSupportedAttribute(name)) {
90 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
91 return;
92 }
93
94 if (name == SVGNames::stdDeviationAttr) {
95 float x, y;
96 if (parseNumberOptionalNumber(value, x, y)) {
97 setStdDeviationXBaseValue(x);
98 setStdDeviationYBaseValue(y);
99 }
100 return;
101 }
102
103 if (name == SVGNames::inAttr) {
104 setIn1BaseValue(value);
105 return;
106 }
107
108 ASSERT_NOT_REACHED();
109}
110
111void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName)
112{
113 if (!isSupportedAttribute(attrName)) {
114 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
115 return;
116 }
117
118 SVGElementInstance::InvalidationGuard invalidationGuard(this);
119
120 if (attrName == SVGNames::inAttr || attrName == SVGNames::stdDeviationAttr) {
121 invalidate();
122 return;
123 }
124
125 ASSERT_NOT_REACHED();
126}
127
128PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
129{
130 FilterEffect* input1 = filterBuilder->getEffectById(in1());
131
132 if (!input1)
133 return 0;
134
135 if (stdDeviationX() < 0 || stdDeviationY() < 0)
136 return 0;
137
138 RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationX(), stdDeviationY());
139 effect->inputEffects().append(input1);
140 return effect.release();
141}
142
143}