2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
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.
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.
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.
23 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGFETurbulenceElement.h"
26 #include "Attribute.h"
27 #include "SVGElementInstance.h"
29 #include "SVGParserUtilities.h"
33 // Animated property definitions
34 DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFETurbulenceElement, SVGNames::baseFrequencyAttr, baseFrequencyXIdentifier(), BaseFrequencyX, baseFrequencyX)
35 DEFINE_ANIMATED_NUMBER_MULTIPLE_WRAPPERS(SVGFETurbulenceElement, SVGNames::baseFrequencyAttr, baseFrequencyYIdentifier(), BaseFrequencyY, baseFrequencyY)
36 DEFINE_ANIMATED_INTEGER(SVGFETurbulenceElement, SVGNames::numOctavesAttr, NumOctaves, numOctaves)
37 DEFINE_ANIMATED_NUMBER(SVGFETurbulenceElement, SVGNames::seedAttr, Seed, seed)
38 DEFINE_ANIMATED_ENUMERATION(SVGFETurbulenceElement, SVGNames::stitchTilesAttr, StitchTiles, stitchTiles, SVGStitchOptions)
39 DEFINE_ANIMATED_ENUMERATION(SVGFETurbulenceElement, SVGNames::typeAttr, Type, type, TurbulenceType)
41 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFETurbulenceElement)
42 REGISTER_LOCAL_ANIMATED_PROPERTY(baseFrequencyX)
43 REGISTER_LOCAL_ANIMATED_PROPERTY(baseFrequencyY)
44 REGISTER_LOCAL_ANIMATED_PROPERTY(numOctaves)
45 REGISTER_LOCAL_ANIMATED_PROPERTY(seed)
46 REGISTER_LOCAL_ANIMATED_PROPERTY(stitchTiles)
47 REGISTER_LOCAL_ANIMATED_PROPERTY(type)
48 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
49 END_REGISTER_ANIMATED_PROPERTIES
51 inline SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName& tagName, Document* document)
52 : SVGFilterPrimitiveStandardAttributes(tagName, document)
54 , m_stitchTiles(SVG_STITCHTYPE_NOSTITCH)
55 , m_type(FETURBULENCE_TYPE_TURBULENCE)
57 ASSERT(hasTagName(SVGNames::feTurbulenceTag));
58 registerAnimatedPropertiesForSVGFETurbulenceElement();
61 PassRefPtr<SVGFETurbulenceElement> SVGFETurbulenceElement::create(const QualifiedName& tagName, Document* document)
63 return adoptRef(new SVGFETurbulenceElement(tagName, document));
66 const AtomicString& SVGFETurbulenceElement::baseFrequencyXIdentifier()
68 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyX"));
72 const AtomicString& SVGFETurbulenceElement::baseFrequencyYIdentifier()
74 DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyY"));
78 bool SVGFETurbulenceElement::isSupportedAttribute(const QualifiedName& attrName)
80 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
81 if (supportedAttributes.isEmpty()) {
82 supportedAttributes.add(SVGNames::baseFrequencyAttr);
83 supportedAttributes.add(SVGNames::numOctavesAttr);
84 supportedAttributes.add(SVGNames::seedAttr);
85 supportedAttributes.add(SVGNames::stitchTilesAttr);
86 supportedAttributes.add(SVGNames::typeAttr);
88 return supportedAttributes.contains(attrName);
91 void SVGFETurbulenceElement::parseMappedAttribute(Attribute* attr)
93 if (!isSupportedAttribute(attr->name())) {
94 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
98 const AtomicString& value = attr->value();
99 if (attr->name() == SVGNames::typeAttr) {
100 TurbulenceType propertyValue = SVGPropertyTraits<TurbulenceType>::fromString(value);
101 if (propertyValue > 0)
102 setTypeBaseValue(propertyValue);
106 if (attr->name() == SVGNames::stitchTilesAttr) {
107 SVGStitchOptions propertyValue = SVGPropertyTraits<SVGStitchOptions>::fromString(value);
108 if (propertyValue > 0)
109 setStitchTilesBaseValue(propertyValue);
113 if (attr->name() == SVGNames::baseFrequencyAttr) {
115 if (parseNumberOptionalNumber(value, x, y)) {
116 setBaseFrequencyXBaseValue(x);
117 setBaseFrequencyYBaseValue(y);
122 if (attr->name() == SVGNames::seedAttr) {
123 setSeedBaseValue(value.toFloat());
127 if (attr->name() == SVGNames::numOctavesAttr) {
128 setNumOctavesBaseValue(value.string().toUIntStrict());
132 ASSERT_NOT_REACHED();
135 bool SVGFETurbulenceElement::setFilterEffectAttribute(FilterEffect* effect, const QualifiedName& attrName)
137 FETurbulence* turbulence = static_cast<FETurbulence*>(effect);
138 if (attrName == SVGNames::typeAttr)
139 return turbulence->setType(type());
140 if (attrName == SVGNames::stitchTilesAttr)
141 return turbulence->setStitchTiles(stitchTiles());
142 if (attrName == SVGNames::baseFrequencyAttr)
143 return (turbulence->setBaseFrequencyX(baseFrequencyX()) || turbulence->setBaseFrequencyY(baseFrequencyY()));
144 if (attrName == SVGNames::seedAttr)
145 return turbulence->setSeed(seed());
146 if (attrName == SVGNames::numOctavesAttr)
147 return turbulence->setNumOctaves(numOctaves());
149 ASSERT_NOT_REACHED();
153 void SVGFETurbulenceElement::svgAttributeChanged(const QualifiedName& attrName)
155 if (!isSupportedAttribute(attrName)) {
156 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
160 SVGElementInstance::InvalidationGuard invalidationGuard(this);
162 if (attrName == SVGNames::baseFrequencyAttr
163 || attrName == SVGNames::numOctavesAttr
164 || attrName == SVGNames::seedAttr
165 || attrName == SVGNames::stitchTilesAttr
166 || attrName == SVGNames::typeAttr) {
167 primitiveAttributeChanged(attrName);
171 ASSERT_NOT_REACHED();
174 PassRefPtr<FilterEffect> SVGFETurbulenceElement::build(SVGFilterBuilder*, Filter* filter)
176 if (baseFrequencyX() < 0 || baseFrequencyY() < 0)
178 return FETurbulence::create(filter, type(), baseFrequencyX(), baseFrequencyY(), numOctaves(), seed(), stitchTiles() == SVG_STITCHTYPE_STITCH);
183 #endif // ENABLE(SVG)