1/* 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005 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 "SVGFEOffsetElement.h" 25 26#include "Attribute.h" 27#include "FilterEffect.h" 28#include "SVGElementInstance.h" 29#include "SVGFilterBuilder.h" 30#include "SVGNames.h" 31 32namespace WebCore { 33 34// Animated property definitions 35DEFINE_ANIMATED_STRING(SVGFEOffsetElement, SVGNames::inAttr, In1, in1) 36DEFINE_ANIMATED_NUMBER(SVGFEOffsetElement, SVGNames::dxAttr, Dx, dx) 37DEFINE_ANIMATED_NUMBER(SVGFEOffsetElement, SVGNames::dyAttr, Dy, dy) 38 39BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEOffsetElement) 40 REGISTER_LOCAL_ANIMATED_PROPERTY(in1) 41 REGISTER_LOCAL_ANIMATED_PROPERTY(dx) 42 REGISTER_LOCAL_ANIMATED_PROPERTY(dy) 43 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes) 44END_REGISTER_ANIMATED_PROPERTIES 45 46inline SVGFEOffsetElement::SVGFEOffsetElement(const QualifiedName& tagName, Document* document) 47 : SVGFilterPrimitiveStandardAttributes(tagName, document) 48{ 49 ASSERT(hasTagName(SVGNames::feOffsetTag)); 50 registerAnimatedPropertiesForSVGFEOffsetElement(); 51} 52 53PassRefPtr<SVGFEOffsetElement> SVGFEOffsetElement::create(const QualifiedName& tagName, Document* document) 54{ 55 return adoptRef(new SVGFEOffsetElement(tagName, document)); 56} 57 58bool SVGFEOffsetElement::isSupportedAttribute(const QualifiedName& attrName) 59{ 60 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 61 if (supportedAttributes.isEmpty()) { 62 supportedAttributes.add(SVGNames::inAttr); 63 supportedAttributes.add(SVGNames::dxAttr); 64 supportedAttributes.add(SVGNames::dyAttr); 65 } 66 return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName); 67} 68 69void SVGFEOffsetElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 70{ 71 if (!isSupportedAttribute(name)) { 72 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); 73 return; 74 } 75 76 if (name == SVGNames::dxAttr) { 77 setDxBaseValue(value.toFloat()); 78 return; 79 } 80 81 if (name == SVGNames::dyAttr) { 82 setDyBaseValue(value.toFloat()); 83 return; 84 } 85 86 if (name == SVGNames::inAttr) { 87 setIn1BaseValue(value); 88 return; 89 } 90 91 ASSERT_NOT_REACHED(); 92} 93 94void SVGFEOffsetElement::svgAttributeChanged(const QualifiedName& attrName) 95{ 96 if (!isSupportedAttribute(attrName)) { 97 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); 98 return; 99 } 100 101 SVGElementInstance::InvalidationGuard invalidationGuard(this); 102 103 if (attrName == SVGNames::inAttr || attrName == SVGNames::dxAttr || attrName == SVGNames::dyAttr) { 104 invalidate(); 105 return; 106 } 107 108 ASSERT_NOT_REACHED(); 109} 110 111PassRefPtr<FilterEffect> SVGFEOffsetElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) 112{ 113 FilterEffect* input1 = filterBuilder->getEffectById(in1()); 114 115 if (!input1) 116 return 0; 117 118 RefPtr<FilterEffect> effect = FEOffset::create(filter, dx(), dy()); 119 effect->inputEffects().append(input1); 120 return effect.release(); 121} 122 123} 124 125#endif // ENABLE(SVG) 126