blob: 9ce1f7fd7da0bd8bda698d839e8d16d2cdb3646c [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
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000033inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(Document& document)
34 : SVGFilterPrimitiveStandardAttributes(SVGNames::feGaussianBlurTag, document)
Torne (Richard Coles)09380292014-02-21 12:17:33 +000035 , m_stdDeviation(SVGAnimatedNumberOptionalNumber::create(this, SVGNames::stdDeviationAttr, 0, 0))
36 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create()))
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010037{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010038 ScriptWrappable::init(this);
Torne (Richard Coles)09380292014-02-21 12:17:33 +000039
40 addToPropertyMap(m_stdDeviation);
41 addToPropertyMap(m_in1);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010042}
43
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000044PassRefPtr<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(Document& document)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010045{
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000046 return adoptRef(new SVGFEGaussianBlurElement(document));
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010047}
48
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010049void SVGFEGaussianBlurElement::setStdDeviation(float x, float y)
50{
Torne (Richard Coles)09380292014-02-21 12:17:33 +000051 stdDeviationX()->baseValue()->setValue(x);
52 stdDeviationY()->baseValue()->setValue(y);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010053 invalidate();
54}
55
56bool SVGFEGaussianBlurElement::isSupportedAttribute(const QualifiedName& attrName)
57{
58 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
59 if (supportedAttributes.isEmpty()) {
60 supportedAttributes.add(SVGNames::inAttr);
61 supportedAttributes.add(SVGNames::stdDeviationAttr);
62 }
Ben Murdoch591b9582013-07-10 11:41:44 +010063 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010064}
65
66void SVGFEGaussianBlurElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
67{
68 if (!isSupportedAttribute(name)) {
69 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
70 return;
71 }
72
Torne (Richard Coles)09380292014-02-21 12:17:33 +000073 SVGParsingError parseError = NoError;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010074
Torne (Richard Coles)09380292014-02-21 12:17:33 +000075 if (name == SVGNames::inAttr)
76 m_in1->setBaseValueAsString(value, parseError);
77 else if (name == SVGNames::stdDeviationAttr)
78 m_stdDeviation->setBaseValueAsString(value, parseError);
79 else
80 ASSERT_NOT_REACHED();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010081
Torne (Richard Coles)09380292014-02-21 12:17:33 +000082 reportAttributeParsingError(parseError, name, value);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010083}
84
85void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName)
86{
87 if (!isSupportedAttribute(attrName)) {
88 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
89 return;
90 }
91
Torne (Richard Coles)32348042014-05-14 12:12:57 +010092 SVGElement::InvalidationGuard invalidationGuard(this);
Ben Murdoch02772c62013-07-26 10:21:05 +010093
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010094 if (attrName == SVGNames::inAttr || attrName == SVGNames::stdDeviationAttr) {
95 invalidate();
96 return;
97 }
98
99 ASSERT_NOT_REACHED();
100}
101
102PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
103{
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000104 FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value()));
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100105
106 if (!input1)
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000107 return nullptr;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100108
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000109 if (stdDeviationX()->currentValue()->value() < 0 || stdDeviationY()->currentValue()->value() < 0)
Torne (Richard Coles)d5428f32014-03-18 10:21:16 +0000110 return nullptr;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100111
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000112 RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationX()->currentValue()->value(), stdDeviationY()->currentValue()->value());
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100113 effect->inputEffects().append(input1);
114 return effect.release();
115}
116
117}