1 | /* |
2 | * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
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 | #pragma once |
22 | |
23 | #include "FEConvolveMatrix.h" |
24 | #include "SVGFilterPrimitiveStandardAttributes.h" |
25 | |
26 | namespace WebCore { |
27 | |
28 | template<> |
29 | struct SVGPropertyTraits<EdgeModeType> { |
30 | static unsigned highestEnumValue() { return EDGEMODE_NONE; } |
31 | static EdgeModeType initialValue() { return EDGEMODE_NONE; } |
32 | |
33 | static String toString(EdgeModeType type) |
34 | { |
35 | switch (type) { |
36 | case EDGEMODE_UNKNOWN: |
37 | return emptyString(); |
38 | case EDGEMODE_DUPLICATE: |
39 | return "duplicate"_s ; |
40 | case EDGEMODE_WRAP: |
41 | return "wrap"_s ; |
42 | case EDGEMODE_NONE: |
43 | return "none"_s ; |
44 | } |
45 | |
46 | ASSERT_NOT_REACHED(); |
47 | return emptyString(); |
48 | } |
49 | |
50 | static EdgeModeType fromString(const String& value) |
51 | { |
52 | if (value == "duplicate" ) |
53 | return EDGEMODE_DUPLICATE; |
54 | if (value == "wrap" ) |
55 | return EDGEMODE_WRAP; |
56 | if (value == "none" ) |
57 | return EDGEMODE_NONE; |
58 | return EDGEMODE_UNKNOWN; |
59 | } |
60 | }; |
61 | |
62 | class SVGFEConvolveMatrixElement final : public SVGFilterPrimitiveStandardAttributes { |
63 | WTF_MAKE_ISO_ALLOCATED(SVGFEConvolveMatrixElement); |
64 | public: |
65 | static Ref<SVGFEConvolveMatrixElement> create(const QualifiedName&, Document&); |
66 | |
67 | void setOrder(float orderX, float orderY); |
68 | void setKernelUnitLength(float kernelUnitLengthX, float kernelUnitLengthY); |
69 | |
70 | String in1() const { return m_in1->currentValue(); } |
71 | int orderX() const { return m_orderX->currentValue(); } |
72 | int orderY() const { return m_orderY->currentValue(); } |
73 | const SVGNumberList& kernelMatrix() const { return m_kernelMatrix->currentValue(); } |
74 | float divisor() const { return m_divisor->currentValue(); } |
75 | float bias() const { return m_bias->currentValue(); } |
76 | int targetX() const { return m_targetX->currentValue(); } |
77 | int targetY() const { return m_targetY->currentValue(); } |
78 | EdgeModeType edgeMode() const { return m_edgeMode->currentValue<EdgeModeType>(); } |
79 | float kernelUnitLengthX() const { return m_kernelUnitLengthX->currentValue(); } |
80 | float kernelUnitLengthY() const { return m_kernelUnitLengthY->currentValue(); } |
81 | bool preserveAlpha() const { return m_preserveAlpha->currentValue(); } |
82 | |
83 | SVGAnimatedString& in1Animated() { return m_in1; } |
84 | SVGAnimatedInteger& orderXAnimated() { return m_orderX; } |
85 | SVGAnimatedInteger& orderYAnimated() { return m_orderY; } |
86 | SVGAnimatedNumberList& kernelMatrixAnimated() { return m_kernelMatrix; } |
87 | SVGAnimatedNumber& divisorAnimated() { return m_divisor; } |
88 | SVGAnimatedNumber& biasAnimated() { return m_bias; } |
89 | SVGAnimatedInteger& targetXAnimated() { return m_targetX; } |
90 | SVGAnimatedInteger& targetYAnimated() { return m_targetY; } |
91 | SVGAnimatedEnumeration& edgeModeAnimated() { return m_edgeMode; } |
92 | SVGAnimatedNumber& kernelUnitLengthXAnimated() { return m_kernelUnitLengthX; } |
93 | SVGAnimatedNumber& kernelUnitLengthYAnimated() { return m_kernelUnitLengthY; } |
94 | SVGAnimatedBoolean& preserveAlphaAnimated() { return m_preserveAlpha; } |
95 | |
96 | private: |
97 | SVGFEConvolveMatrixElement(const QualifiedName&, Document&); |
98 | |
99 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGFEConvolveMatrixElement, SVGFilterPrimitiveStandardAttributes>; |
100 | const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; } |
101 | |
102 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
103 | void svgAttributeChanged(const QualifiedName&) override; |
104 | |
105 | bool setFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; |
106 | RefPtr<FilterEffect> build(SVGFilterBuilder*, Filter&) const override; |
107 | |
108 | PropertyRegistry m_propertyRegistry { *this }; |
109 | Ref<SVGAnimatedString> m_in1 { SVGAnimatedString::create(this) }; |
110 | Ref<SVGAnimatedInteger> m_orderX { SVGAnimatedInteger::create(this) }; |
111 | Ref<SVGAnimatedInteger> m_orderY { SVGAnimatedInteger::create(this) }; |
112 | Ref<SVGAnimatedNumberList> m_kernelMatrix { SVGAnimatedNumberList::create(this) }; |
113 | Ref<SVGAnimatedNumber> m_divisor { SVGAnimatedNumber::create(this) }; |
114 | Ref<SVGAnimatedNumber> m_bias { SVGAnimatedNumber::create(this) }; |
115 | Ref<SVGAnimatedInteger> m_targetX { SVGAnimatedInteger::create(this) }; |
116 | Ref<SVGAnimatedInteger> m_targetY { SVGAnimatedInteger::create(this) }; |
117 | Ref<SVGAnimatedEnumeration> m_edgeMode { SVGAnimatedEnumeration::create(this, EDGEMODE_DUPLICATE) }; |
118 | Ref<SVGAnimatedNumber> m_kernelUnitLengthX { SVGAnimatedNumber::create(this) }; |
119 | Ref<SVGAnimatedNumber> m_kernelUnitLengthY { SVGAnimatedNumber::create(this) }; |
120 | Ref<SVGAnimatedBoolean> m_preserveAlpha { SVGAnimatedBoolean::create(this) }; |
121 | }; |
122 | |
123 | } // namespace WebCore |
124 | |