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