Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 1 | /* |
| 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) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 23 | #include "core/svg/SVGFEGaussianBlurElement.h" |
| 24 | |
Torne (Richard Coles) | 5d92fed | 2014-06-20 14:52:37 +0100 | [diff] [blame] | 25 | #include "core/SVGNames.h" |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 26 | #include "platform/graphics/filters/FilterEffect.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 27 | #include "core/svg/SVGParserUtilities.h" |
| 28 | #include "core/svg/graphics/filters/SVGFilterBuilder.h" |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
Torne (Richard Coles) | 5d92fed | 2014-06-20 14:52:37 +0100 | [diff] [blame] | 32 | inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(Document& document) |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 33 | : SVGFilterPrimitiveStandardAttributes(SVGNames::feGaussianBlurTag, document) |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 34 | , m_stdDeviation(SVGAnimatedNumberOptionalNumber::create(this, SVGNames::stdDeviationAttr, 0, 0)) |
| 35 | , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create())) |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 36 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 37 | ScriptWrappable::init(this); |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 38 | |
| 39 | addToPropertyMap(m_stdDeviation); |
| 40 | addToPropertyMap(m_in1); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 41 | } |
| 42 | |
Torne (Richard Coles) | 5d92fed | 2014-06-20 14:52:37 +0100 | [diff] [blame] | 43 | DEFINE_NODE_FACTORY(SVGFEGaussianBlurElement) |
| 44 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 45 | void SVGFEGaussianBlurElement::setStdDeviation(float x, float y) |
| 46 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 47 | stdDeviationX()->baseValue()->setValue(x); |
| 48 | stdDeviationY()->baseValue()->setValue(y); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 49 | invalidate(); |
| 50 | } |
| 51 | |
| 52 | bool SVGFEGaussianBlurElement::isSupportedAttribute(const QualifiedName& attrName) |
| 53 | { |
| 54 | DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); |
| 55 | if (supportedAttributes.isEmpty()) { |
| 56 | supportedAttributes.add(SVGNames::inAttr); |
| 57 | supportedAttributes.add(SVGNames::stdDeviationAttr); |
| 58 | } |
Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 59 | return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void SVGFEGaussianBlurElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 63 | { |
| 64 | if (!isSupportedAttribute(name)) { |
| 65 | SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); |
| 66 | return; |
| 67 | } |
| 68 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 69 | SVGParsingError parseError = NoError; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 70 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 71 | if (name == SVGNames::inAttr) |
| 72 | m_in1->setBaseValueAsString(value, parseError); |
| 73 | else if (name == SVGNames::stdDeviationAttr) |
| 74 | m_stdDeviation->setBaseValueAsString(value, parseError); |
| 75 | else |
| 76 | ASSERT_NOT_REACHED(); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 77 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 78 | reportAttributeParsingError(parseError, name, value); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName) |
| 82 | { |
| 83 | if (!isSupportedAttribute(attrName)) { |
| 84 | SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); |
| 85 | return; |
| 86 | } |
| 87 | |
Torne (Richard Coles) | 3234804 | 2014-05-14 12:12:57 +0100 | [diff] [blame] | 88 | SVGElement::InvalidationGuard invalidationGuard(this); |
Ben Murdoch | 02772c6 | 2013-07-26 10:21:05 +0100 | [diff] [blame] | 89 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 90 | if (attrName == SVGNames::inAttr || attrName == SVGNames::stdDeviationAttr) { |
| 91 | invalidate(); |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | ASSERT_NOT_REACHED(); |
| 96 | } |
| 97 | |
| 98 | PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) |
| 99 | { |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 100 | FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value())); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 101 | |
| 102 | if (!input1) |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 103 | return nullptr; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 104 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 105 | if (stdDeviationX()->currentValue()->value() < 0 || stdDeviationY()->currentValue()->value() < 0) |
Torne (Richard Coles) | d5428f3 | 2014-03-18 10:21:16 +0000 | [diff] [blame] | 106 | return nullptr; |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 107 | |
Torne (Richard Coles) | 0938029 | 2014-02-21 12:17:33 +0000 | [diff] [blame] | 108 | RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationX()->currentValue()->value(), stdDeviationY()->currentValue()->value()); |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 109 | effect->inputEffects().append(input1); |
| 110 | return effect.release(); |
| 111 | } |
| 112 | |
| 113 | } |