blob: 75cadffb04f1935f5636351a067ee758060fb8fc [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)a854de02013-12-18 16:25:25 +000026#include "platform/graphics/filters/FilterEffect.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010027#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
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000045inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(Document& document)
46 : SVGFilterPrimitiveStandardAttributes(SVGNames::feGaussianBlurTag, document)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010047{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010048 ScriptWrappable::init(this);
49 registerAnimatedPropertiesForSVGFEGaussianBlurElement();
50}
51
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000052PassRefPtr<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(Document& document)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010053{
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000054 return adoptRef(new SVGFEGaussianBlurElement(document));
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010055}
56
57const AtomicString& SVGFEGaussianBlurElement::stdDeviationXIdentifier()
58{
59 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationX", AtomicString::ConstructFromLiteral));
60 return s_identifier;
61}
62
63const AtomicString& SVGFEGaussianBlurElement::stdDeviationYIdentifier()
64{
65 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationY", AtomicString::ConstructFromLiteral));
66 return s_identifier;
67}
68
69void SVGFEGaussianBlurElement::setStdDeviation(float x, float y)
70{
71 setStdDeviationXBaseValue(x);
72 setStdDeviationYBaseValue(y);
73 invalidate();
74}
75
76bool SVGFEGaussianBlurElement::isSupportedAttribute(const QualifiedName& attrName)
77{
78 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
79 if (supportedAttributes.isEmpty()) {
80 supportedAttributes.add(SVGNames::inAttr);
81 supportedAttributes.add(SVGNames::stdDeviationAttr);
82 }
Ben Murdoch591b9582013-07-10 11:41:44 +010083 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010084}
85
86void SVGFEGaussianBlurElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
87{
88 if (!isSupportedAttribute(name)) {
89 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
90 return;
91 }
92
93 if (name == SVGNames::stdDeviationAttr) {
94 float x, y;
95 if (parseNumberOptionalNumber(value, x, y)) {
96 setStdDeviationXBaseValue(x);
97 setStdDeviationYBaseValue(y);
98 }
99 return;
100 }
101
102 if (name == SVGNames::inAttr) {
103 setIn1BaseValue(value);
104 return;
105 }
106
107 ASSERT_NOT_REACHED();
108}
109
110void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName)
111{
112 if (!isSupportedAttribute(attrName)) {
113 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
114 return;
115 }
116
117 SVGElementInstance::InvalidationGuard invalidationGuard(this);
Ben Murdoch02772c62013-07-26 10:21:05 +0100118
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100119 if (attrName == SVGNames::inAttr || attrName == SVGNames::stdDeviationAttr) {
120 invalidate();
121 return;
122 }
123
124 ASSERT_NOT_REACHED();
125}
126
127PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
128{
Ben Murdoche69819b2013-07-17 14:56:49 +0100129 FilterEffect* input1 = filterBuilder->getEffectById(in1CurrentValue());
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100130
131 if (!input1)
132 return 0;
133
Ben Murdoche69819b2013-07-17 14:56:49 +0100134 if (stdDeviationXCurrentValue() < 0 || stdDeviationYCurrentValue() < 0)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100135 return 0;
136
Ben Murdoche69819b2013-07-17 14:56:49 +0100137 RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationXCurrentValue(), stdDeviationYCurrentValue());
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100138 effect->inputEffects().append(input1);
139 return effect.release();
140}
141
142}