initial import
[vuplus_webkit] / Source / WebCore / svg / SVGComponentTransferFunctionElement.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 "SVGComponentTransferFunctionElement.h"
25
26 #include "Attribute.h"
27 #include "SVGFEComponentTransferElement.h"
28 #include "SVGNames.h"
29 #include "SVGNumberList.h"
30
31 namespace WebCore {
32
33 // Animated property definitions
34 DEFINE_ANIMATED_ENUMERATION(SVGComponentTransferFunctionElement, SVGNames::typeAttr, Type, type, ComponentTransferType)
35 DEFINE_ANIMATED_NUMBER_LIST(SVGComponentTransferFunctionElement, SVGNames::tableValuesAttr, TableValues, tableValues)
36 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::slopeAttr, Slope, slope)
37 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::interceptAttr, Intercept, intercept)
38 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::amplitudeAttr, Amplitude, amplitude)
39 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::exponentAttr, Exponent, exponent)
40 DEFINE_ANIMATED_NUMBER(SVGComponentTransferFunctionElement, SVGNames::offsetAttr, Offset, offset)
41
42 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGComponentTransferFunctionElement)
43     REGISTER_LOCAL_ANIMATED_PROPERTY(type)
44     REGISTER_LOCAL_ANIMATED_PROPERTY(tableValues)
45     REGISTER_LOCAL_ANIMATED_PROPERTY(slope)
46     REGISTER_LOCAL_ANIMATED_PROPERTY(intercept)
47     REGISTER_LOCAL_ANIMATED_PROPERTY(amplitude)
48     REGISTER_LOCAL_ANIMATED_PROPERTY(exponent)
49     REGISTER_LOCAL_ANIMATED_PROPERTY(offset)
50 END_REGISTER_ANIMATED_PROPERTIES
51
52 SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName& tagName, Document* document)
53     : SVGElement(tagName, document)
54     , m_type(FECOMPONENTTRANSFER_TYPE_IDENTITY)
55     , m_slope(1)
56     , m_amplitude(1)
57     , m_exponent(1)
58 {
59     registerAnimatedPropertiesForSVGComponentTransferFunctionElement();
60 }
61
62 bool SVGComponentTransferFunctionElement::isSupportedAttribute(const QualifiedName& attrName)
63 {
64     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
65     if (supportedAttributes.isEmpty()) {
66         supportedAttributes.add(SVGNames::typeAttr);
67         supportedAttributes.add(SVGNames::tableValuesAttr);
68         supportedAttributes.add(SVGNames::slopeAttr);
69         supportedAttributes.add(SVGNames::interceptAttr);
70         supportedAttributes.add(SVGNames::amplitudeAttr);
71         supportedAttributes.add(SVGNames::exponentAttr);
72         supportedAttributes.add(SVGNames::offsetAttr);
73     }
74     return supportedAttributes.contains(attrName);
75 }
76
77 void SVGComponentTransferFunctionElement::parseMappedAttribute(Attribute* attr)
78 {
79     if (!isSupportedAttribute(attr->name())) {
80         SVGElement::parseMappedAttribute(attr);
81         return;
82     }
83
84     const AtomicString& value = attr->value();
85     if (attr->name() == SVGNames::typeAttr) {
86         ComponentTransferType propertyValue = SVGPropertyTraits<ComponentTransferType>::fromString(value);
87         if (propertyValue > 0)
88             setTypeBaseValue(propertyValue);
89         return;
90     }
91
92     if (attr->name() == SVGNames::tableValuesAttr) {
93         SVGNumberList newList;
94         newList.parse(value);
95         detachAnimatedTableValuesListWrappers(newList.size());
96         setTableValuesBaseValue(newList);
97         return;
98     }
99
100     if (attr->name() == SVGNames::slopeAttr) {
101         setSlopeBaseValue(value.toFloat());
102         return;
103     }
104
105     if (attr->name() == SVGNames::interceptAttr) {
106         setInterceptBaseValue(value.toFloat());
107         return;
108     }
109
110     if (attr->name() == SVGNames::amplitudeAttr) {
111         setAmplitudeBaseValue(value.toFloat());
112         return;
113     }
114
115     if (attr->name() == SVGNames::exponentAttr) {
116         setExponentBaseValue(value.toFloat());
117         return;
118     }
119
120     if (attr->name() == SVGNames::offsetAttr) {
121         setOffsetBaseValue(value.toFloat());
122         return;
123     }
124
125     ASSERT_NOT_REACHED();
126 }
127
128 ComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const
129 {
130     ComponentTransferFunction func;
131     func.type = type();
132     func.slope = slope();
133     func.intercept = intercept();
134     func.amplitude = amplitude();
135     func.exponent = exponent();
136     func.offset = offset();
137     func.tableValues = tableValues();
138     return func;
139 }
140
141 }
142
143 #endif // ENABLE(SVG)