1/*
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#include "config.h"
23#include "SVGFEOffsetElement.h"
24
25#include "FEOffset.h"
26#include "FilterEffect.h"
27#include "SVGFilterBuilder.h"
28#include "SVGNames.h"
29#include <wtf/IsoMallocInlines.h>
30
31namespace WebCore {
32
33WTF_MAKE_ISO_ALLOCATED_IMPL(SVGFEOffsetElement);
34
35inline SVGFEOffsetElement::SVGFEOffsetElement(const QualifiedName& tagName, Document& document)
36 : SVGFilterPrimitiveStandardAttributes(tagName, document)
37{
38 ASSERT(hasTagName(SVGNames::feOffsetTag));
39
40 static std::once_flag onceFlag;
41 std::call_once(onceFlag, [] {
42 PropertyRegistry::registerProperty<SVGNames::inAttr, &SVGFEOffsetElement::m_in1>();
43 PropertyRegistry::registerProperty<SVGNames::dxAttr, &SVGFEOffsetElement::m_dx>();
44 PropertyRegistry::registerProperty<SVGNames::dyAttr, &SVGFEOffsetElement::m_dy>();
45 });
46}
47
48Ref<SVGFEOffsetElement> SVGFEOffsetElement::create(const QualifiedName& tagName, Document& document)
49{
50 return adoptRef(*new SVGFEOffsetElement(tagName, document));
51}
52
53void SVGFEOffsetElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
54{
55 if (name == SVGNames::dxAttr) {
56 m_dx->setBaseValInternal(value.toFloat());
57 return;
58 }
59
60 if (name == SVGNames::dyAttr) {
61 m_dy->setBaseValInternal(value.toFloat());
62 return;
63 }
64
65 if (name == SVGNames::inAttr) {
66 m_in1->setBaseValInternal(value);
67 return;
68 }
69
70 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
71}
72
73void SVGFEOffsetElement::svgAttributeChanged(const QualifiedName& attrName)
74{
75 if (PropertyRegistry::isKnownAttribute(attrName)) {
76 InstanceInvalidationGuard guard(*this);
77 invalidate();
78 return;
79 }
80
81 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
82}
83
84RefPtr<FilterEffect> SVGFEOffsetElement::build(SVGFilterBuilder* filterBuilder, Filter& filter) const
85{
86 auto input1 = filterBuilder->getEffectById(in1());
87
88 if (!input1)
89 return nullptr;
90
91 auto effect = FEOffset::create(filter, dx(), dy());
92 effect->inputEffects().append(input1);
93 return effect;
94}
95
96}
97