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 SVGFEColorMatrixElement_h
22#define SVGFEColorMatrixElement_h
23
24#if ENABLE(SVG) && ENABLE(FILTERS)
25#include "FEColorMatrix.h"
26#include "SVGAnimatedEnumeration.h"
27#include "SVGAnimatedNumberList.h"
28#include "SVGFilterPrimitiveStandardAttributes.h"
29
30namespace WebCore {
31
32template<>
33struct SVGPropertyTraits<ColorMatrixType> {
34    static unsigned highestEnumValue() { return FECOLORMATRIX_TYPE_LUMINANCETOALPHA; }
35
36    static String toString(ColorMatrixType type)
37    {
38        switch (type) {
39        case FECOLORMATRIX_TYPE_UNKNOWN:
40            return emptyString();
41        case FECOLORMATRIX_TYPE_MATRIX:
42            return "matrix";
43        case FECOLORMATRIX_TYPE_SATURATE:
44            return "saturate";
45        case FECOLORMATRIX_TYPE_HUEROTATE:
46            return "hueRotate";
47        case FECOLORMATRIX_TYPE_LUMINANCETOALPHA:
48            return "luminanceToAlpha";
49        }
50
51        ASSERT_NOT_REACHED();
52        return emptyString();
53    }
54
55    static ColorMatrixType fromString(const String& value)
56    {
57        if (value == "matrix")
58            return FECOLORMATRIX_TYPE_MATRIX;
59        if (value == "saturate")
60            return FECOLORMATRIX_TYPE_SATURATE;
61        if (value == "hueRotate")
62            return FECOLORMATRIX_TYPE_HUEROTATE;
63        if (value == "luminanceToAlpha")
64            return FECOLORMATRIX_TYPE_LUMINANCETOALPHA;
65        return FECOLORMATRIX_TYPE_UNKNOWN;
66    }
67};
68
69class SVGFEColorMatrixElement FINAL : public SVGFilterPrimitiveStandardAttributes {
70public:
71    static PassRefPtr<SVGFEColorMatrixElement> create(const QualifiedName&, Document*);
72
73private:
74    SVGFEColorMatrixElement(const QualifiedName&, Document*);
75
76    bool isSupportedAttribute(const QualifiedName&);
77    virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
78    virtual bool setFilterEffectAttribute(FilterEffect*, const QualifiedName&);
79    virtual void svgAttributeChanged(const QualifiedName&);
80    virtual PassRefPtr<FilterEffect> build(SVGFilterBuilder*, Filter*);
81
82    BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGFEColorMatrixElement)
83        DECLARE_ANIMATED_STRING(In1, in1)
84        DECLARE_ANIMATED_ENUMERATION(Type, type, ColorMatrixType)
85        DECLARE_ANIMATED_NUMBER_LIST(Values, values)
86    END_DECLARE_ANIMATED_PROPERTIES
87};
88
89} // namespace WebCore
90
91#endif // ENABLE(SVG)
92#endif
93