- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGFEOffsetElement.cpp
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 "SVGNames.h"
26 #include "core/platform/graphics/filters/FilterEffect.h"
27 #include "core/svg/SVGElementInstance.h"
28 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
29
30 namespace WebCore {
31
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)
36
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
43
44 inline SVGFEOffsetElement::SVGFEOffsetElement(const QualifiedName& tagName, Document& document)
45     : SVGFilterPrimitiveStandardAttributes(tagName, document)
46 {
47     ASSERT(hasTagName(SVGNames::feOffsetTag));
48     ScriptWrappable::init(this);
49     registerAnimatedPropertiesForSVGFEOffsetElement();
50 }
51
52 PassRefPtr<SVGFEOffsetElement> SVGFEOffsetElement::create(const QualifiedName& tagName, Document& document)
53 {
54     return adoptRef(new SVGFEOffsetElement(tagName, document));
55 }
56
57 bool SVGFEOffsetElement::isSupportedAttribute(const QualifiedName& attrName)
58 {
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);
64     }
65     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
66 }
67
68 void SVGFEOffsetElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
69 {
70     if (!isSupportedAttribute(name)) {
71         SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
72         return;
73     }
74
75     if (name == SVGNames::dxAttr) {
76         setDxBaseValue(value.toFloat());
77         return;
78     }
79
80     if (name == SVGNames::dyAttr) {
81         setDyBaseValue(value.toFloat());
82         return;
83     }
84
85     if (name == SVGNames::inAttr) {
86         setIn1BaseValue(value);
87         return;
88     }
89
90     ASSERT_NOT_REACHED();
91 }
92
93 void SVGFEOffsetElement::svgAttributeChanged(const QualifiedName& attrName)
94 {
95     if (!isSupportedAttribute(attrName)) {
96         SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
97         return;
98     }
99
100     SVGElementInstance::InvalidationGuard invalidationGuard(this);
101
102     if (attrName == SVGNames::inAttr || attrName == SVGNames::dxAttr || attrName == SVGNames::dyAttr) {
103         invalidate();
104         return;
105     }
106
107     ASSERT_NOT_REACHED();
108 }
109
110 PassRefPtr<FilterEffect> SVGFEOffsetElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
111 {
112     FilterEffect* input1 = filterBuilder->getEffectById(in1CurrentValue());
113
114     if (!input1)
115         return 0;
116
117     RefPtr<FilterEffect> effect = FEOffset::create(filter, dxCurrentValue(), dyCurrentValue());
118     effect->inputEffects().append(input1);
119     return effect.release();
120 }
121
122 }