• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005 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) && ENABLE(FILTERS)
24 #include "SVGFEOffsetElement.h"
25 
26 #include "Attribute.h"
27 #include "FilterEffect.h"
28 #include "SVGFilterBuilder.h"
29 #include "SVGNames.h"
30 
31 namespace WebCore {
32 
33 // Animated property definitions
DEFINE_ANIMATED_STRING(SVGFEOffsetElement,SVGNames::inAttr,In1,in1)34 DEFINE_ANIMATED_STRING(SVGFEOffsetElement, SVGNames::inAttr, In1, in1)
35 DEFINE_ANIMATED_NUMBER(SVGFEOffsetElement, SVGNames::dxAttr, Dx, dx)
36 DEFINE_ANIMATED_NUMBER(SVGFEOffsetElement, SVGNames::dyAttr, Dy, dy)
37 
38 inline SVGFEOffsetElement::SVGFEOffsetElement(const QualifiedName& tagName, Document* document)
39     : SVGFilterPrimitiveStandardAttributes(tagName, document)
40 {
41 }
42 
create(const QualifiedName & tagName,Document * document)43 PassRefPtr<SVGFEOffsetElement> SVGFEOffsetElement::create(const QualifiedName& tagName, Document* document)
44 {
45     return adoptRef(new SVGFEOffsetElement(tagName, document));
46 }
47 
parseMappedAttribute(Attribute * attr)48 void SVGFEOffsetElement::parseMappedAttribute(Attribute* attr)
49 {
50     const String& value = attr->value();
51     if (attr->name() == SVGNames::dxAttr)
52         setDxBaseValue(value.toFloat());
53     else if (attr->name() == SVGNames::dyAttr)
54         setDyBaseValue(value.toFloat());
55     else if (attr->name() == SVGNames::inAttr)
56         setIn1BaseValue(value);
57     else
58         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
59 }
60 
svgAttributeChanged(const QualifiedName & attrName)61 void SVGFEOffsetElement::svgAttributeChanged(const QualifiedName& attrName)
62 {
63     SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
64 
65     if (attrName == SVGNames::inAttr
66         || attrName == SVGNames::dxAttr
67         || attrName == SVGNames::dyAttr)
68         invalidate();
69 }
70 
synchronizeProperty(const QualifiedName & attrName)71 void SVGFEOffsetElement::synchronizeProperty(const QualifiedName& attrName)
72 {
73     SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
74 
75     if (attrName == anyQName()) {
76         synchronizeDx();
77         synchronizeDy();
78         synchronizeIn1();
79         return;
80     }
81 
82     if (attrName == SVGNames::dxAttr)
83         synchronizeDx();
84     else if (attrName == SVGNames::dyAttr)
85         synchronizeDy();
86     else if (attrName == SVGNames::inAttr)
87         synchronizeIn1();
88 }
89 
attributeToPropertyTypeMap()90 AttributeToPropertyTypeMap& SVGFEOffsetElement::attributeToPropertyTypeMap()
91 {
92     DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
93     return s_attributeToPropertyTypeMap;
94 }
95 
fillAttributeToPropertyTypeMap()96 void SVGFEOffsetElement::fillAttributeToPropertyTypeMap()
97 {
98     AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
99 
100     SVGFilterPrimitiveStandardAttributes::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
101     attributeToPropertyTypeMap.set(SVGNames::inAttr, AnimatedString);
102     attributeToPropertyTypeMap.set(SVGNames::dxAttr, AnimatedNumber);
103     attributeToPropertyTypeMap.set(SVGNames::dyAttr, AnimatedNumber);
104 }
105 
build(SVGFilterBuilder * filterBuilder,Filter * filter)106 PassRefPtr<FilterEffect> SVGFEOffsetElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
107 {
108     FilterEffect* input1 = filterBuilder->getEffectById(in1());
109 
110     if (!input1)
111         return 0;
112 
113     RefPtr<FilterEffect> effect = FEOffset::create(filter, dx(), dy());
114     effect->inputEffects().append(input1);
115     return effect.release();
116 }
117 
118 }
119 
120 #endif // ENABLE(SVG)
121