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 | |
| 23 | #if ENABLE(SVG) |
| 24 | #include "core/svg/SVGFEGaussianBlurElement.h" |
| 25 | |
| 26 | #include "SVGNames.h" |
| 27 | #include "core/dom/Attribute.h" |
| 28 | #include "core/platform/graphics/filters/FilterEffect.h" |
| 29 | #include "core/svg/SVGElementInstance.h" |
| 30 | #include "core/svg/SVGParserUtilities.h" |
| 31 | #include "core/svg/graphics/filters/SVGFilterBuilder.h" |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | // Animated property definitions |
| 36 | DEFINE_ANIMATED_STRING(SVGFEGaussianBlurElement, SVGNames::inAttr, In1, in1) |
| 37 | DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationXIdentifier(), StdDeviationX, stdDeviationX) |
| 38 | DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationYIdentifier(), StdDeviationY, stdDeviationY) |
| 39 | |
| 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_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes) |
| 45 | END_REGISTER_ANIMATED_PROPERTIES |
| 46 | |
| 47 | inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(const QualifiedName& tagName, Document* document) |
| 48 | : SVGFilterPrimitiveStandardAttributes(tagName, document) |
| 49 | { |
| 50 | ASSERT(hasTagName(SVGNames::feGaussianBlurTag)); |
| 51 | ScriptWrappable::init(this); |
| 52 | registerAnimatedPropertiesForSVGFEGaussianBlurElement(); |
| 53 | } |
| 54 | |
| 55 | PassRefPtr<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(const QualifiedName& tagName, Document* document) |
| 56 | { |
| 57 | return adoptRef(new SVGFEGaussianBlurElement(tagName, document)); |
| 58 | } |
| 59 | |
| 60 | const AtomicString& SVGFEGaussianBlurElement::stdDeviationXIdentifier() |
| 61 | { |
| 62 | DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationX", AtomicString::ConstructFromLiteral)); |
| 63 | return s_identifier; |
| 64 | } |
| 65 | |
| 66 | const AtomicString& SVGFEGaussianBlurElement::stdDeviationYIdentifier() |
| 67 | { |
| 68 | DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationY", AtomicString::ConstructFromLiteral)); |
| 69 | return s_identifier; |
| 70 | } |
| 71 | |
| 72 | void SVGFEGaussianBlurElement::setStdDeviation(float x, float y) |
| 73 | { |
| 74 | setStdDeviationXBaseValue(x); |
| 75 | setStdDeviationYBaseValue(y); |
| 76 | invalidate(); |
| 77 | } |
| 78 | |
| 79 | bool SVGFEGaussianBlurElement::isSupportedAttribute(const QualifiedName& attrName) |
| 80 | { |
| 81 | DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); |
| 82 | if (supportedAttributes.isEmpty()) { |
| 83 | supportedAttributes.add(SVGNames::inAttr); |
| 84 | supportedAttributes.add(SVGNames::stdDeviationAttr); |
| 85 | } |
| 86 | return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName); |
| 87 | } |
| 88 | |
| 89 | void SVGFEGaussianBlurElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 90 | { |
| 91 | if (!isSupportedAttribute(name)) { |
| 92 | SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | if (name == SVGNames::stdDeviationAttr) { |
| 97 | float x, y; |
| 98 | if (parseNumberOptionalNumber(value, x, y)) { |
| 99 | setStdDeviationXBaseValue(x); |
| 100 | setStdDeviationYBaseValue(y); |
| 101 | } |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | if (name == SVGNames::inAttr) { |
| 106 | setIn1BaseValue(value); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | ASSERT_NOT_REACHED(); |
| 111 | } |
| 112 | |
| 113 | void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName) |
| 114 | { |
| 115 | if (!isSupportedAttribute(attrName)) { |
| 116 | SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | SVGElementInstance::InvalidationGuard invalidationGuard(this); |
| 121 | |
| 122 | if (attrName == SVGNames::inAttr || attrName == SVGNames::stdDeviationAttr) { |
| 123 | invalidate(); |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | ASSERT_NOT_REACHED(); |
| 128 | } |
| 129 | |
| 130 | PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) |
| 131 | { |
| 132 | FilterEffect* input1 = filterBuilder->getEffectById(in1()); |
| 133 | |
| 134 | if (!input1) |
| 135 | return 0; |
| 136 | |
| 137 | if (stdDeviationX() < 0 || stdDeviationY() < 0) |
| 138 | return 0; |
| 139 | |
| 140 | RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationX(), stdDeviationY()); |
| 141 | effect->inputEffects().append(input1); |
| 142 | return effect.release(); |
| 143 | } |
| 144 | |
| 145 | } |
| 146 | |
| 147 | #endif // ENABLE(SVG) |