1 | /* |
2 | * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
3 | * Copyright (C) 2004, 2005, 2006 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 "SVGFEGaussianBlurElement.h" |
24 | |
25 | #include "FilterEffect.h" |
26 | #include "SVGFilterBuilder.h" |
27 | #include "SVGNames.h" |
28 | #include "SVGParserUtilities.h" |
29 | #include <wtf/IsoMallocInlines.h> |
30 | |
31 | namespace WebCore { |
32 | |
33 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGFEGaussianBlurElement); |
34 | |
35 | inline SVGFEGaussianBlurElement::SVGFEGaussianBlurElement(const QualifiedName& tagName, Document& document) |
36 | : SVGFilterPrimitiveStandardAttributes(tagName, document) |
37 | { |
38 | ASSERT(hasTagName(SVGNames::feGaussianBlurTag)); |
39 | |
40 | static std::once_flag onceFlag; |
41 | std::call_once(onceFlag, [] { |
42 | PropertyRegistry::registerProperty<SVGNames::inAttr, &SVGFEGaussianBlurElement::m_in1>(); |
43 | PropertyRegistry::registerProperty<SVGNames::stdDeviationAttr, &SVGFEGaussianBlurElement::m_stdDeviationX, &SVGFEGaussianBlurElement::m_stdDeviationY>(); |
44 | PropertyRegistry::registerProperty<SVGNames::edgeModeAttr, EdgeModeType, &SVGFEGaussianBlurElement::m_edgeMode>(); |
45 | }); |
46 | } |
47 | |
48 | Ref<SVGFEGaussianBlurElement> SVGFEGaussianBlurElement::create(const QualifiedName& tagName, Document& document) |
49 | { |
50 | return adoptRef(*new SVGFEGaussianBlurElement(tagName, document)); |
51 | } |
52 | |
53 | void SVGFEGaussianBlurElement::setStdDeviation(float x, float y) |
54 | { |
55 | m_stdDeviationX->setBaseValInternal(x); |
56 | m_stdDeviationY->setBaseValInternal(y); |
57 | invalidate(); |
58 | } |
59 | |
60 | void SVGFEGaussianBlurElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
61 | { |
62 | if (name == SVGNames::stdDeviationAttr) { |
63 | float x, y; |
64 | if (parseNumberOptionalNumber(value, x, y)) { |
65 | m_stdDeviationX->setBaseValInternal(x); |
66 | m_stdDeviationY->setBaseValInternal(y); |
67 | } |
68 | return; |
69 | } |
70 | |
71 | if (name == SVGNames::inAttr) { |
72 | m_in1->setBaseValInternal(value); |
73 | return; |
74 | } |
75 | |
76 | if (name == SVGNames::edgeModeAttr) { |
77 | auto propertyValue = SVGPropertyTraits<EdgeModeType>::fromString(value); |
78 | if (propertyValue > 0) |
79 | m_edgeMode->setBaseValInternal<EdgeModeType>(propertyValue); |
80 | else |
81 | document().accessSVGExtensions().reportWarning("feGaussianBlur: problem parsing edgeMode=\"" + value + "\". Filtered element will not be displayed." ); |
82 | return; |
83 | } |
84 | |
85 | SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); |
86 | } |
87 | |
88 | void SVGFEGaussianBlurElement::svgAttributeChanged(const QualifiedName& attrName) |
89 | { |
90 | if (PropertyRegistry::isKnownAttribute(attrName)) { |
91 | InstanceInvalidationGuard guard(*this); |
92 | invalidate(); |
93 | return; |
94 | } |
95 | |
96 | SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); |
97 | } |
98 | |
99 | RefPtr<FilterEffect> SVGFEGaussianBlurElement::build(SVGFilterBuilder* filterBuilder, Filter& filter) const |
100 | { |
101 | auto input1 = filterBuilder->getEffectById(in1()); |
102 | |
103 | if (!input1) |
104 | return nullptr; |
105 | |
106 | if (stdDeviationX() < 0 || stdDeviationY() < 0) |
107 | return nullptr; |
108 | |
109 | auto effect = FEGaussianBlur::create(filter, stdDeviationX(), stdDeviationY(), edgeMode()); |
110 | effect->inputEffects().append(input1); |
111 | return effect; |
112 | } |
113 | |
114 | } |
115 | |