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/SVGFETileElement.h"
24
25#include "SVGNames.h"
26#include "platform/graphics/filters/FilterEffect.h"
27#include "core/svg/SVGElementInstance.h"
28#include "core/svg/graphics/filters/SVGFilterBuilder.h"
29
30namespace WebCore {
31
32// Animated property definitions
33DEFINE_ANIMATED_STRING(SVGFETileElement, SVGNames::inAttr, In1, in1)
34
35BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFETileElement)
36    REGISTER_LOCAL_ANIMATED_PROPERTY(in1)
37    REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
38END_REGISTER_ANIMATED_PROPERTIES
39
40inline SVGFETileElement::SVGFETileElement(Document& document)
41    : SVGFilterPrimitiveStandardAttributes(SVGNames::feTileTag, document)
42{
43    ScriptWrappable::init(this);
44    registerAnimatedPropertiesForSVGFETileElement();
45}
46
47PassRefPtr<SVGFETileElement> SVGFETileElement::create(Document& document)
48{
49    return adoptRef(new SVGFETileElement(document));
50}
51
52bool SVGFETileElement::isSupportedAttribute(const QualifiedName& attrName)
53{
54    DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
55    if (supportedAttributes.isEmpty())
56        supportedAttributes.add(SVGNames::inAttr);
57    return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
58}
59
60void SVGFETileElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
61{
62    if (!isSupportedAttribute(name)) {
63        SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
64        return;
65    }
66
67    if (name == SVGNames::inAttr) {
68        setIn1BaseValue(value);
69        return;
70    }
71
72    ASSERT_NOT_REACHED();
73}
74
75void SVGFETileElement::svgAttributeChanged(const QualifiedName& attrName)
76{
77    if (!isSupportedAttribute(attrName)) {
78        SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
79        return;
80    }
81
82    SVGElementInstance::InvalidationGuard invalidationGuard(this);
83
84    if (attrName == SVGNames::inAttr) {
85        invalidate();
86        return;
87    }
88
89    ASSERT_NOT_REACHED();
90}
91
92PassRefPtr<FilterEffect> SVGFETileElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
93{
94    FilterEffect* input1 = filterBuilder->getEffectById(in1CurrentValue());
95
96    if (!input1)
97        return 0;
98
99    RefPtr<FilterEffect> effect = FETile::create(filter);
100    effect->inputEffects().append(input1);
101    return effect.release();
102}
103
104}
105