Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis (at) 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) && ENABLE(FILTERS)
     24 #include "SVGFEGaussianBlurElement.h"
     25 
     26 #include "Attribute.h"
     27 #include "FilterEffect.h"
     28 #include "SVGFilterBuilder.h"
     29 #include "SVGNames.h"
     30 #include "SVGParserUtilities.h"
     31 
     32 namespace WebCore {
     33 
     34 // Animated property definitions
     35 DEFINE_ANIMATED_STRING(SVGFEGaussianBlurElement, SVGNames::inAttr, In1, in1)
     36 DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationXIdentifier(), StdDeviationX, stdDeviationX)
     37 DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFEGaussianBlurElement, SVGNames::stdDeviationAttr, stdDeviationYIdentifier(), StdDeviationY, stdDeviationY)
     38 
     39 inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(const QualifiedName& tagName, Document* document)
     40     : SVGFilterPrimitiveStandardAttributes(tagName, document)
     41 {
     42 }
     43 
     44 PassRefPtr<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(const QualifiedName& tagName, Document* document)
     45 {
     46     return adoptRef(new SVGFEGaussianBlurElement(tagName, document));
     47 }
     48 
     49 const AtomicString& SVGFEGaussianBlurElement::stdDeviationXIdentifier()
     50 {
     51     DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationX"));
     52     return s_identifier;
     53 }
     54 
     55 const AtomicString& SVGFEGaussianBlurElement::stdDeviationYIdentifier()
     56 {
     57     DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGStdDeviationY"));
     58     return s_identifier;
     59 }
     60 
     61 void SVGFEGaussianBlurElement::setStdDeviation(float x, float y)
     62 {
     63     setStdDeviationXBaseValue(x);
     64     setStdDeviationYBaseValue(y);
     65     invalidate();
     66 }
     67 
     68 void SVGFEGaussianBlurElement::parseMappedAttribute(Attribute* attr)
     69 {
     70     const String& value = attr->value();
     71     if (attr->name() == SVGNames::stdDeviationAttr) {
     72         float x, y;
     73         if (parseNumberOptionalNumber(value, x, y)) {
     74             setStdDeviationXBaseValue(x);
     75             setStdDeviationYBaseValue(y);
     76         }
     77     } else if (attr->name() == SVGNames::inAttr)
     78         setIn1BaseValue(value);
     79     else
     80         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
     81 }
     82 
     83 void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName)
     84 {
     85     SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
     86 
     87     if (attrName == SVGNames::inAttr
     88         || attrName == SVGNames::stdDeviationAttr)
     89         invalidate();
     90 }
     91 
     92 void SVGFEGaussianBlurElement::synchronizeProperty(const QualifiedName& attrName)
     93 {
     94     SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
     95 
     96     if (attrName == anyQName()) {
     97         synchronizeStdDeviationX();
     98         synchronizeStdDeviationY();
     99         synchronizeIn1();
    100         return;
    101     }
    102 
    103     if (attrName == SVGNames::stdDeviationAttr) {
    104         synchronizeStdDeviationX();
    105         synchronizeStdDeviationY();
    106     } else if (attrName == SVGNames::inAttr)
    107         synchronizeIn1();
    108 }
    109 
    110 AttributeToPropertyTypeMap& SVGFEGaussianBlurElement::attributeToPropertyTypeMap()
    111 {
    112     DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
    113     return s_attributeToPropertyTypeMap;
    114 }
    115 
    116 void SVGFEGaussianBlurElement::fillAttributeToPropertyTypeMap()
    117 {
    118     AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
    119 
    120     SVGFilterPrimitiveStandardAttributes::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
    121     attributeToPropertyTypeMap.set(SVGNames::inAttr, AnimatedString);
    122     attributeToPropertyTypeMap.set(SVGNames::stdDeviationAttr, AnimatedNumberOptionalNumber);
    123 }
    124 
    125 PassRefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
    126 {
    127     FilterEffect* input1 = filterBuilder->getEffectById(in1());
    128 
    129     if (!input1)
    130         return 0;
    131 
    132     RefPtr<FilterEffect> effect = FEGaussianBlur::create(filter, stdDeviationX(), stdDeviationY());
    133     effect->inputEffects().append(input1);
    134     return effect.release();
    135 }
    136 
    137 }
    138 
    139 #endif // ENABLE(SVG)
    140