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 "FEMorphology.h" |
24 | #include "SVGFilterPrimitiveStandardAttributes.h" |
25 | |
26 | namespace WebCore { |
27 | |
28 | template<> |
29 | struct SVGPropertyTraits<MorphologyOperatorType> { |
30 | static unsigned highestEnumValue() { return FEMORPHOLOGY_OPERATOR_DILATE; } |
31 | |
32 | static String toString(MorphologyOperatorType type) |
33 | { |
34 | switch (type) { |
35 | case FEMORPHOLOGY_OPERATOR_UNKNOWN: |
36 | return emptyString(); |
37 | case FEMORPHOLOGY_OPERATOR_ERODE: |
38 | return "erode"_s ; |
39 | case FEMORPHOLOGY_OPERATOR_DILATE: |
40 | return "dilate"_s ; |
41 | } |
42 | |
43 | ASSERT_NOT_REACHED(); |
44 | return emptyString(); |
45 | } |
46 | |
47 | static MorphologyOperatorType fromString(const String& value) |
48 | { |
49 | if (value == "erode" ) |
50 | return FEMORPHOLOGY_OPERATOR_ERODE; |
51 | if (value == "dilate" ) |
52 | return FEMORPHOLOGY_OPERATOR_DILATE; |
53 | return FEMORPHOLOGY_OPERATOR_UNKNOWN; |
54 | } |
55 | }; |
56 | |
57 | class SVGFEMorphologyElement final : public SVGFilterPrimitiveStandardAttributes { |
58 | WTF_MAKE_ISO_ALLOCATED(SVGFEMorphologyElement); |
59 | public: |
60 | static Ref<SVGFEMorphologyElement> create(const QualifiedName&, Document&); |
61 | |
62 | void setRadius(float radiusX, float radiusY); |
63 | |
64 | String in1() const { return m_in1->currentValue(); } |
65 | MorphologyOperatorType svgOperator() const { return m_svgOperator->currentValue<MorphologyOperatorType>(); } |
66 | float radiusX() const { return m_radiusX->currentValue(); } |
67 | float radiusY() const { return m_radiusY->currentValue(); } |
68 | |
69 | SVGAnimatedString& in1Animated() { return m_in1; } |
70 | SVGAnimatedEnumeration& svgOperatorAnimated() { return m_svgOperator; } |
71 | SVGAnimatedNumber& radiusXAnimated() { return m_radiusX; } |
72 | SVGAnimatedNumber& radiusYAnimated() { return m_radiusY; } |
73 | |
74 | private: |
75 | SVGFEMorphologyElement(const QualifiedName&, Document&); |
76 | |
77 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGFEMorphologyElement, SVGFilterPrimitiveStandardAttributes>; |
78 | const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; } |
79 | |
80 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
81 | void svgAttributeChanged(const QualifiedName&) override; |
82 | |
83 | bool setFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; |
84 | RefPtr<FilterEffect> build(SVGFilterBuilder*, Filter&) const override; |
85 | |
86 | PropertyRegistry m_propertyRegistry { *this }; |
87 | Ref<SVGAnimatedString> m_in1 { SVGAnimatedString::create(this) }; |
88 | Ref<SVGAnimatedEnumeration> m_svgOperator { SVGAnimatedEnumeration::create(this, FEMORPHOLOGY_OPERATOR_ERODE) }; |
89 | Ref<SVGAnimatedNumber> m_radiusX { SVGAnimatedNumber::create(this) }; |
90 | Ref<SVGAnimatedNumber> m_radiusY { SVGAnimatedNumber::create(this) }; |
91 | }; |
92 | |
93 | } // namespace WebCore |
94 | |