1 | /* |
2 | * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
3 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
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 | #include "SVGFEDropShadowElement.h" |
23 | |
24 | #include "RenderStyle.h" |
25 | #include "SVGFilterBuilder.h" |
26 | #include "SVGNames.h" |
27 | #include "SVGParserUtilities.h" |
28 | #include "SVGRenderStyle.h" |
29 | #include <wtf/IsoMallocInlines.h> |
30 | |
31 | namespace WebCore { |
32 | |
33 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGFEDropShadowElement); |
34 | |
35 | inline SVGFEDropShadowElement::SVGFEDropShadowElement(const QualifiedName& tagName, Document& document) |
36 | : SVGFilterPrimitiveStandardAttributes(tagName, document) |
37 | { |
38 | ASSERT(hasTagName(SVGNames::feDropShadowTag)); |
39 | |
40 | static std::once_flag onceFlag; |
41 | std::call_once(onceFlag, [] { |
42 | PropertyRegistry::registerProperty<SVGNames::inAttr, &SVGFEDropShadowElement::m_in1>(); |
43 | PropertyRegistry::registerProperty<SVGNames::dxAttr, &SVGFEDropShadowElement::m_dx>(); |
44 | PropertyRegistry::registerProperty<SVGNames::dyAttr, &SVGFEDropShadowElement::m_dy>(); |
45 | PropertyRegistry::registerProperty<SVGNames::stdDeviationAttr, &SVGFEDropShadowElement::m_stdDeviationX, &SVGFEDropShadowElement::m_stdDeviationY>(); |
46 | }); |
47 | } |
48 | |
49 | Ref<SVGFEDropShadowElement> SVGFEDropShadowElement::create(const QualifiedName& tagName, Document& document) |
50 | { |
51 | return adoptRef(*new SVGFEDropShadowElement(tagName, document)); |
52 | } |
53 | |
54 | void SVGFEDropShadowElement::setStdDeviation(float x, float y) |
55 | { |
56 | m_stdDeviationX->setBaseValInternal(x); |
57 | m_stdDeviationY->setBaseValInternal(y); |
58 | invalidate(); |
59 | } |
60 | |
61 | void SVGFEDropShadowElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
62 | { |
63 | if (name == SVGNames::stdDeviationAttr) { |
64 | float x, y; |
65 | if (parseNumberOptionalNumber(value, x, y)) { |
66 | m_stdDeviationX->setBaseValInternal(x); |
67 | m_stdDeviationY->setBaseValInternal(y); |
68 | } |
69 | return; |
70 | } |
71 | |
72 | if (name == SVGNames::inAttr) { |
73 | m_in1->setBaseValInternal(value); |
74 | return; |
75 | } |
76 | |
77 | if (name == SVGNames::dxAttr) { |
78 | m_dx->setBaseValInternal(value.toFloat()); |
79 | return; |
80 | } |
81 | |
82 | if (name == SVGNames::dyAttr) { |
83 | m_dy->setBaseValInternal(value.toFloat()); |
84 | return; |
85 | } |
86 | |
87 | SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); |
88 | } |
89 | |
90 | void SVGFEDropShadowElement::svgAttributeChanged(const QualifiedName& attrName) |
91 | { |
92 | if (PropertyRegistry::isKnownAttribute(attrName)) { |
93 | InstanceInvalidationGuard guard(*this); |
94 | invalidate(); |
95 | return; |
96 | } |
97 | |
98 | SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); |
99 | } |
100 | |
101 | RefPtr<FilterEffect> SVGFEDropShadowElement::build(SVGFilterBuilder* filterBuilder, Filter& filter) const |
102 | { |
103 | RenderObject* renderer = this->renderer(); |
104 | if (!renderer) |
105 | return nullptr; |
106 | |
107 | if (stdDeviationX() < 0 || stdDeviationY() < 0) |
108 | return nullptr; |
109 | |
110 | const SVGRenderStyle& svgStyle = renderer->style().svgStyle(); |
111 | |
112 | Color color = renderer->style().colorByApplyingColorFilter(svgStyle.floodColor()); |
113 | float opacity = svgStyle.floodOpacity(); |
114 | |
115 | auto input1 = filterBuilder->getEffectById(in1()); |
116 | if (!input1) |
117 | return nullptr; |
118 | |
119 | auto effect = FEDropShadow::create(filter, stdDeviationX(), stdDeviationY(), dx(), dy(), color, opacity); |
120 | effect->inputEffects().append(input1); |
121 | return effect; |
122 | } |
123 | |
124 | } |
125 | |