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 "core/platform/graphics/filters/FilterEffect.h"
27 #include "core/svg/SVGElementInstance.h"
28 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
32 // Animated property definitions
33 DEFINE_ANIMATED_STRING(SVGFEOffsetElement, SVGNames::inAttr, In1, in1)
34 DEFINE_ANIMATED_NUMBER(SVGFEOffsetElement, SVGNames::dxAttr, Dx, dx)
35 DEFINE_ANIMATED_NUMBER(SVGFEOffsetElement, SVGNames::dyAttr, Dy, dy)
37 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEOffsetElement)
38 REGISTER_LOCAL_ANIMATED_PROPERTY(in1)
39 REGISTER_LOCAL_ANIMATED_PROPERTY(dx)
40 REGISTER_LOCAL_ANIMATED_PROPERTY(dy)
41 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
42 END_REGISTER_ANIMATED_PROPERTIES
44 inline SVGFEOffsetElement::SVGFEOffsetElement(const QualifiedName& tagName, Document& document)
45 : SVGFilterPrimitiveStandardAttributes(tagName, document)
47 ASSERT(hasTagName(SVGNames::feOffsetTag));
48 ScriptWrappable::init(this);
49 registerAnimatedPropertiesForSVGFEOffsetElement();
52 PassRefPtr<SVGFEOffsetElement> SVGFEOffsetElement::create(const QualifiedName& tagName, Document& document)
54 return adoptRef(new SVGFEOffsetElement(tagName, 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 if (name == SVGNames::dxAttr) {
76 setDxBaseValue(value.toFloat());
80 if (name == SVGNames::dyAttr) {
81 setDyBaseValue(value.toFloat());
85 if (name == SVGNames::inAttr) {
86 setIn1BaseValue(value);
93 void SVGFEOffsetElement::svgAttributeChanged(const QualifiedName& attrName)
95 if (!isSupportedAttribute(attrName)) {
96 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
100 SVGElementInstance::InvalidationGuard invalidationGuard(this);
102 if (attrName == SVGNames::inAttr || attrName == SVGNames::dxAttr || attrName == SVGNames::dyAttr) {
107 ASSERT_NOT_REACHED();
110 PassRefPtr<FilterEffect> SVGFEOffsetElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
112 FilterEffect* input1 = filterBuilder->getEffectById(in1CurrentValue());
117 RefPtr<FilterEffect> effect = FEOffset::create(filter, dxCurrentValue(), dyCurrentValue());
118 effect->inputEffects().append(input1);
119 return effect.release();