Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis (at) 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 #include "core/svg/SVGComponentTransferFunctionElement.h"
     24 
     25 #include "SVGNames.h"
     26 #include "core/dom/Attribute.h"
     27 #include "core/svg/SVGElementInstance.h"
     28 #include "core/svg/SVGFEComponentTransferElement.h"
     29 #include "core/svg/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     ScriptWrappable::init(this);
     60     registerAnimatedPropertiesForSVGComponentTransferFunctionElement();
     61 }
     62 
     63 bool SVGComponentTransferFunctionElement::isSupportedAttribute(const QualifiedName& attrName)
     64 {
     65     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
     66     if (supportedAttributes.isEmpty()) {
     67         supportedAttributes.add(SVGNames::typeAttr);
     68         supportedAttributes.add(SVGNames::tableValuesAttr);
     69         supportedAttributes.add(SVGNames::slopeAttr);
     70         supportedAttributes.add(SVGNames::interceptAttr);
     71         supportedAttributes.add(SVGNames::amplitudeAttr);
     72         supportedAttributes.add(SVGNames::exponentAttr);
     73         supportedAttributes.add(SVGNames::offsetAttr);
     74     }
     75     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
     76 }
     77 
     78 void SVGComponentTransferFunctionElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
     79 {
     80     if (!isSupportedAttribute(name)) {
     81         SVGElement::parseAttribute(name, value);
     82         return;
     83     }
     84 
     85     if (name == SVGNames::typeAttr) {
     86         ComponentTransferType propertyValue = SVGPropertyTraits<ComponentTransferType>::fromString(value);
     87         if (propertyValue > 0)
     88             setTypeBaseValue(propertyValue);
     89         return;
     90     }
     91 
     92     if (name == SVGNames::tableValuesAttr) {
     93         SVGNumberList newList;
     94         newList.parse(value);
     95         detachAnimatedTableValuesListWrappers(newList.size());
     96         setTableValuesBaseValue(newList);
     97         return;
     98     }
     99 
    100     if (name == SVGNames::slopeAttr) {
    101         setSlopeBaseValue(value.toFloat());
    102         return;
    103     }
    104 
    105     if (name == SVGNames::interceptAttr) {
    106         setInterceptBaseValue(value.toFloat());
    107         return;
    108     }
    109 
    110     if (name == SVGNames::amplitudeAttr) {
    111         setAmplitudeBaseValue(value.toFloat());
    112         return;
    113     }
    114 
    115     if (name == SVGNames::exponentAttr) {
    116         setExponentBaseValue(value.toFloat());
    117         return;
    118     }
    119 
    120     if (name == SVGNames::offsetAttr) {
    121         setOffsetBaseValue(value.toFloat());
    122         return;
    123     }
    124 
    125     ASSERT_NOT_REACHED();
    126 }
    127 
    128 void SVGComponentTransferFunctionElement::svgAttributeChanged(const QualifiedName& attrName)
    129 {
    130     if (!isSupportedAttribute(attrName)) {
    131         SVGElement::svgAttributeChanged(attrName);
    132         return;
    133     }
    134 
    135     SVGElementInstance::InvalidationGuard invalidationGuard(this);
    136 
    137     invalidateFilterPrimitiveParent(this);
    138 }
    139 
    140 ComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const
    141 {
    142     ComponentTransferFunction func;
    143     func.type = typeCurrentValue();
    144     func.slope = slopeCurrentValue();
    145     func.intercept = interceptCurrentValue();
    146     func.amplitude = amplitudeCurrentValue();
    147     func.exponent = exponentCurrentValue();
    148     func.offset = offsetCurrentValue();
    149     func.tableValues = tableValuesCurrentValue().toFloatVector();
    150     return func;
    151 }
    152 
    153 }
    154