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#ifndef SVGFETurbulenceElement_h
22#define SVGFETurbulenceElement_h
23
24#include "core/svg/SVGAnimatedEnumeration.h"
25#include "core/svg/SVGAnimatedInteger.h"
26#include "core/svg/SVGAnimatedNumber.h"
27#include "core/svg/SVGFilterPrimitiveStandardAttributes.h"
28#include "platform/graphics/filters/FETurbulence.h"
29
30namespace WebCore {
31
32enum SVGStitchOptions {
33    SVG_STITCHTYPE_UNKNOWN  = 0,
34    SVG_STITCHTYPE_STITCH   = 1,
35    SVG_STITCHTYPE_NOSTITCH = 2
36};
37
38template<>
39struct SVGPropertyTraits<SVGStitchOptions> {
40    static unsigned highestEnumValue() { return SVG_STITCHTYPE_NOSTITCH; }
41
42    static String toString(SVGStitchOptions type)
43    {
44        switch (type) {
45        case SVG_STITCHTYPE_UNKNOWN:
46            return emptyString();
47        case SVG_STITCHTYPE_STITCH:
48            return "stitch";
49        case SVG_STITCHTYPE_NOSTITCH:
50            return "noStitch";
51        }
52
53        ASSERT_NOT_REACHED();
54        return emptyString();
55    }
56
57    static SVGStitchOptions fromString(const String& value)
58    {
59        if (value == "stitch")
60            return SVG_STITCHTYPE_STITCH;
61        if (value == "noStitch")
62            return SVG_STITCHTYPE_NOSTITCH;
63        return SVG_STITCHTYPE_UNKNOWN;
64    }
65};
66
67template<>
68struct SVGPropertyTraits<TurbulenceType> {
69    static unsigned highestEnumValue() { return FETURBULENCE_TYPE_TURBULENCE; }
70
71    static String toString(TurbulenceType type)
72    {
73        switch (type) {
74        case FETURBULENCE_TYPE_UNKNOWN:
75            return emptyString();
76        case FETURBULENCE_TYPE_FRACTALNOISE:
77            return "fractalNoise";
78        case FETURBULENCE_TYPE_TURBULENCE:
79            return "turbulence";
80        }
81
82        ASSERT_NOT_REACHED();
83        return emptyString();
84    }
85
86    static TurbulenceType fromString(const String& value)
87    {
88        if (value == "fractalNoise")
89            return FETURBULENCE_TYPE_FRACTALNOISE;
90        if (value == "turbulence")
91            return FETURBULENCE_TYPE_TURBULENCE;
92        return FETURBULENCE_TYPE_UNKNOWN;
93    }
94};
95
96class SVGFETurbulenceElement FINAL : public SVGFilterPrimitiveStandardAttributes {
97public:
98    static PassRefPtr<SVGFETurbulenceElement> create(Document&);
99
100private:
101    explicit SVGFETurbulenceElement(Document&);
102
103    bool isSupportedAttribute(const QualifiedName&);
104    virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
105    virtual bool setFilterEffectAttribute(FilterEffect*, const QualifiedName& attrName);
106    virtual void svgAttributeChanged(const QualifiedName&);
107    virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*);
108
109    static const AtomicString& baseFrequencyXIdentifier();
110    static const AtomicString& baseFrequencyYIdentifier();
111
112    BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGFETurbulenceElement)
113        DECLARE_ANIMATED_NUMBER(BaseFrequencyX, baseFrequencyX)
114        DECLARE_ANIMATED_NUMBER(BaseFrequencyY, baseFrequencyY)
115        DECLARE_ANIMATED_INTEGER(NumOctaves, numOctaves)
116        DECLARE_ANIMATED_NUMBER(Seed, seed)
117        DECLARE_ANIMATED_ENUMERATION(StitchTiles, stitchTiles, SVGStitchOptions)
118        DECLARE_ANIMATED_ENUMERATION(Type, type, TurbulenceType)
119    END_DECLARE_ANIMATED_PROPERTIES
120};
121
122} // namespace WebCore
123
124#endif
125