OSDN Git Service

Merge Webkit at r70949: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / svg / SVGFETurbulenceElement.cpp
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) && ENABLE(FILTERS)
24 #include "SVGFETurbulenceElement.h"
25
26 #include "Attribute.h"
27 #include "SVGParserUtilities.h"
28
29 namespace WebCore {
30
31 inline SVGFETurbulenceElement::SVGFETurbulenceElement(const QualifiedName& tagName, Document* document)
32     : SVGFilterPrimitiveStandardAttributes(tagName, document)
33     , m_numOctaves(1)
34     , m_stitchTiles(SVG_STITCHTYPE_NOSTITCH)
35     , m_type(FETURBULENCE_TYPE_TURBULENCE)
36 {
37 }
38
39 PassRefPtr<SVGFETurbulenceElement> SVGFETurbulenceElement::create(const QualifiedName& tagName, Document* document)
40 {
41     return adoptRef(new SVGFETurbulenceElement(tagName, document));
42 }
43
44 const AtomicString& SVGFETurbulenceElement::baseFrequencyXIdentifier()
45 {
46     DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyX"));
47     return s_identifier;    
48 }
49
50 const AtomicString& SVGFETurbulenceElement::baseFrequencyYIdentifier()
51 {
52     DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGBaseFrequencyY"));
53     return s_identifier;    
54 }
55
56 void SVGFETurbulenceElement::parseMappedAttribute(Attribute* attr)
57 {
58     const String& value = attr->value();
59     if (attr->name() == SVGNames::typeAttr) {
60         if (value == "fractalNoise")
61             setTypeBaseValue(FETURBULENCE_TYPE_FRACTALNOISE);
62         else if (value == "turbulence")
63             setTypeBaseValue(FETURBULENCE_TYPE_TURBULENCE);
64     } else if (attr->name() == SVGNames::stitchTilesAttr) {
65         if (value == "stitch")
66             setStitchTilesBaseValue(SVG_STITCHTYPE_STITCH);
67         else if (value == "noStitch")
68             setStitchTilesBaseValue(SVG_STITCHTYPE_NOSTITCH);
69     } else if (attr->name() == SVGNames::baseFrequencyAttr) {
70         float x, y;
71         if (parseNumberOptionalNumber(value, x, y)) {
72             setBaseFrequencyXBaseValue(x);
73             setBaseFrequencyYBaseValue(y);
74         }
75     } else if (attr->name() == SVGNames::seedAttr)
76         setSeedBaseValue(value.toFloat());
77     else if (attr->name() == SVGNames::numOctavesAttr)
78         setNumOctavesBaseValue(value.toUIntStrict());
79     else
80         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
81 }
82
83 void SVGFETurbulenceElement::svgAttributeChanged(const QualifiedName& attrName)
84 {
85     SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
86     
87     if (attrName == SVGNames::baseFrequencyAttr
88         || attrName == SVGNames::numOctavesAttr
89         || attrName == SVGNames::seedAttr
90         || attrName == SVGNames::stitchTilesAttr
91         || attrName == SVGNames::typeAttr)
92         invalidate();
93 }
94
95 void SVGFETurbulenceElement::synchronizeProperty(const QualifiedName& attrName)
96 {
97     SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
98
99     if (attrName == anyQName()) {
100         synchronizeType();
101         synchronizeStitchTiles();
102         synchronizeBaseFrequencyX();
103         synchronizeBaseFrequencyY();
104         synchronizeSeed();
105         synchronizeNumOctaves();
106         return;
107     }
108
109     if (attrName == SVGNames::typeAttr)
110         synchronizeType();
111     else if (attrName == SVGNames::stitchTilesAttr)
112         synchronizeStitchTiles();
113     else if (attrName == SVGNames::baseFrequencyAttr) {
114         synchronizeBaseFrequencyX();
115         synchronizeBaseFrequencyY();
116     } else if (attrName == SVGNames::seedAttr)
117         synchronizeSeed();
118     else if (attrName == SVGNames::numOctavesAttr)
119         synchronizeNumOctaves();
120 }
121
122 PassRefPtr<FilterEffect> SVGFETurbulenceElement::build(SVGFilterBuilder*)
123 {
124     if (baseFrequencyX() < 0 || baseFrequencyY() < 0)
125         return 0;
126
127     return FETurbulence::create(static_cast<TurbulanceType>(type()), baseFrequencyX(), 
128                 baseFrequencyY(), numOctaves(), seed(), stitchTiles() == SVG_STITCHTYPE_STITCH);
129 }
130
131 }
132
133 #endif // ENABLE(SVG)