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#include "core/svg/SVGFEOffsetElement.h" 24 25#include "core/SVGNames.h" 26#include "platform/graphics/filters/FilterEffect.h" 27#include "core/svg/graphics/filters/SVGFilterBuilder.h" 28 29namespace WebCore { 30 31inline SVGFEOffsetElement::SVGFEOffsetElement(Document& document) 32 : SVGFilterPrimitiveStandardAttributes(SVGNames::feOffsetTag, document) 33 , m_dx(SVGAnimatedNumber::create(this, SVGNames::dxAttr, SVGNumber::create())) 34 , m_dy(SVGAnimatedNumber::create(this, SVGNames::dyAttr, SVGNumber::create())) 35 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create())) 36{ 37 ScriptWrappable::init(this); 38 39 addToPropertyMap(m_dx); 40 addToPropertyMap(m_dy); 41 addToPropertyMap(m_in1); 42} 43 44DEFINE_NODE_FACTORY(SVGFEOffsetElement) 45 46bool SVGFEOffsetElement::isSupportedAttribute(const QualifiedName& attrName) 47{ 48 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 49 if (supportedAttributes.isEmpty()) { 50 supportedAttributes.add(SVGNames::inAttr); 51 supportedAttributes.add(SVGNames::dxAttr); 52 supportedAttributes.add(SVGNames::dyAttr); 53 } 54 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 55} 56 57void SVGFEOffsetElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 58{ 59 if (!isSupportedAttribute(name)) { 60 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); 61 return; 62 } 63 64 SVGParsingError parseError = NoError; 65 66 if (name == SVGNames::inAttr) 67 m_in1->setBaseValueAsString(value, parseError); 68 else if (name == SVGNames::dxAttr) 69 m_dx->setBaseValueAsString(value, parseError); 70 else if (name == SVGNames::dyAttr) 71 m_dy->setBaseValueAsString(value, parseError); 72 else 73 ASSERT_NOT_REACHED(); 74 75 reportAttributeParsingError(parseError, name, value); 76} 77 78void SVGFEOffsetElement::svgAttributeChanged(const QualifiedName& attrName) 79{ 80 if (!isSupportedAttribute(attrName)) { 81 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); 82 return; 83 } 84 85 SVGElement::InvalidationGuard invalidationGuard(this); 86 87 if (attrName == SVGNames::inAttr || attrName == SVGNames::dxAttr || attrName == SVGNames::dyAttr) { 88 invalidate(); 89 return; 90 } 91 92 ASSERT_NOT_REACHED(); 93} 94 95PassRefPtr<FilterEffect> SVGFEOffsetElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) 96{ 97 FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value())); 98 99 if (!input1) 100 return nullptr; 101 102 RefPtr<FilterEffect> effect = FEOffset::create(filter, m_dx->currentValue()->value(), m_dy->currentValue()->value()); 103 effect->inputEffects().append(input1); 104 return effect.release(); 105} 106 107} 108