2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
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.
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.
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.
23 #include "core/svg/SVGFEOffsetElement.h"
26 #include "platform/graphics/filters/FilterEffect.h"
27 #include "core/svg/SVGElementInstance.h"
28 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
32 // Animated property definitions
34 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEOffsetElement)
35 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
36 END_REGISTER_ANIMATED_PROPERTIES
38 inline SVGFEOffsetElement::SVGFEOffsetElement(Document& document)
39 : SVGFilterPrimitiveStandardAttributes(SVGNames::feOffsetTag, document)
40 , m_dx(SVGAnimatedNumber::create(this, SVGNames::dxAttr, SVGNumber::create()))
41 , m_dy(SVGAnimatedNumber::create(this, SVGNames::dyAttr, SVGNumber::create()))
42 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create()))
44 ScriptWrappable::init(this);
46 addToPropertyMap(m_dx);
47 addToPropertyMap(m_dy);
48 addToPropertyMap(m_in1);
49 registerAnimatedPropertiesForSVGFEOffsetElement();
52 PassRefPtr<SVGFEOffsetElement> SVGFEOffsetElement::create(Document& document)
54 return adoptRef(new SVGFEOffsetElement(document));
57 bool SVGFEOffsetElement::isSupportedAttribute(const QualifiedName& attrName)
59 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
60 if (supportedAttributes.isEmpty()) {
61 supportedAttributes.add(SVGNames::inAttr);
62 supportedAttributes.add(SVGNames::dxAttr);
63 supportedAttributes.add(SVGNames::dyAttr);
65 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
68 void SVGFEOffsetElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
70 if (!isSupportedAttribute(name)) {
71 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
75 SVGParsingError parseError = NoError;
77 if (name == SVGNames::inAttr)
78 m_in1->setBaseValueAsString(value, parseError);
79 else if (name == SVGNames::dxAttr)
80 m_dx->setBaseValueAsString(value, parseError);
81 else if (name == SVGNames::dyAttr)
82 m_dy->setBaseValueAsString(value, parseError);
86 reportAttributeParsingError(parseError, name, value);
89 void SVGFEOffsetElement::svgAttributeChanged(const QualifiedName& attrName)
91 if (!isSupportedAttribute(attrName)) {
92 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
96 SVGElementInstance::InvalidationGuard invalidationGuard(this);
98 if (attrName == SVGNames::inAttr || attrName == SVGNames::dxAttr || attrName == SVGNames::dyAttr) {
103 ASSERT_NOT_REACHED();
106 PassRefPtr<FilterEffect> SVGFEOffsetElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
108 FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value()));
113 RefPtr<FilterEffect> effect = FEOffset::create(filter, m_dx->currentValue()->value(), m_dy->currentValue()->value());
114 effect->inputEffects().append(input1);
115 return effect.release();