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 | #pragma once |
23 | |
24 | #include "FEComposite.h" |
25 | #include "SVGFilterPrimitiveStandardAttributes.h" |
26 | |
27 | namespace WebCore { |
28 | |
29 | template<> |
30 | inline unsigned SVGIDLEnumLimits<CompositeOperationType>::highestExposedEnumValue() { return FECOMPOSITE_OPERATOR_ARITHMETIC; } |
31 | |
32 | template<> |
33 | struct SVGPropertyTraits<CompositeOperationType> { |
34 | static unsigned highestEnumValue() { return FECOMPOSITE_OPERATOR_LIGHTER; } |
35 | |
36 | static String toString(CompositeOperationType type) |
37 | { |
38 | switch (type) { |
39 | case FECOMPOSITE_OPERATOR_UNKNOWN: |
40 | return emptyString(); |
41 | case FECOMPOSITE_OPERATOR_OVER: |
42 | return "over"_s ; |
43 | case FECOMPOSITE_OPERATOR_IN: |
44 | return "in"_s ; |
45 | case FECOMPOSITE_OPERATOR_OUT: |
46 | return "out"_s ; |
47 | case FECOMPOSITE_OPERATOR_ATOP: |
48 | return "atop"_s ; |
49 | case FECOMPOSITE_OPERATOR_XOR: |
50 | return "xor"_s ; |
51 | case FECOMPOSITE_OPERATOR_ARITHMETIC: |
52 | return "arithmetic"_s ; |
53 | case FECOMPOSITE_OPERATOR_LIGHTER: |
54 | return "lighter"_s ; |
55 | } |
56 | |
57 | ASSERT_NOT_REACHED(); |
58 | return emptyString(); |
59 | } |
60 | |
61 | static CompositeOperationType fromString(const String& value) |
62 | { |
63 | if (value == "over" ) |
64 | return FECOMPOSITE_OPERATOR_OVER; |
65 | if (value == "in" ) |
66 | return FECOMPOSITE_OPERATOR_IN; |
67 | if (value == "out" ) |
68 | return FECOMPOSITE_OPERATOR_OUT; |
69 | if (value == "atop" ) |
70 | return FECOMPOSITE_OPERATOR_ATOP; |
71 | if (value == "xor" ) |
72 | return FECOMPOSITE_OPERATOR_XOR; |
73 | if (value == "arithmetic" ) |
74 | return FECOMPOSITE_OPERATOR_ARITHMETIC; |
75 | if (value == "lighter" ) |
76 | return FECOMPOSITE_OPERATOR_LIGHTER; |
77 | return FECOMPOSITE_OPERATOR_UNKNOWN; |
78 | } |
79 | }; |
80 | |
81 | class SVGFECompositeElement final : public SVGFilterPrimitiveStandardAttributes { |
82 | WTF_MAKE_ISO_ALLOCATED(SVGFECompositeElement); |
83 | public: |
84 | static Ref<SVGFECompositeElement> create(const QualifiedName&, Document&); |
85 | |
86 | String in1() const { return m_in1->currentValue(); } |
87 | String in2() const { return m_in2->currentValue(); } |
88 | CompositeOperationType svgOperator() const { return m_svgOperator->currentValue<CompositeOperationType>(); } |
89 | float k1() const { return m_k1->currentValue(); } |
90 | float k2() const { return m_k2->currentValue(); } |
91 | float k3() const { return m_k3->currentValue(); } |
92 | float k4() const { return m_k4->currentValue(); } |
93 | |
94 | SVGAnimatedString& in1Animated() { return m_in1; } |
95 | SVGAnimatedString& in2Animated() { return m_in2; } |
96 | SVGAnimatedEnumeration& svgOperatorAnimated() { return m_svgOperator; } |
97 | SVGAnimatedNumber& k1Animated() { return m_k1; } |
98 | SVGAnimatedNumber& k2Animated() { return m_k2; } |
99 | SVGAnimatedNumber& k3Animated() { return m_k3; } |
100 | SVGAnimatedNumber& k4Animated() { return m_k4; } |
101 | |
102 | private: |
103 | SVGFECompositeElement(const QualifiedName&, Document&); |
104 | |
105 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGFECompositeElement, SVGFilterPrimitiveStandardAttributes>; |
106 | const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; } |
107 | |
108 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
109 | void svgAttributeChanged(const QualifiedName&) override; |
110 | |
111 | bool setFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; |
112 | RefPtr<FilterEffect> build(SVGFilterBuilder*, Filter&) const override; |
113 | |
114 | PropertyRegistry m_propertyRegistry { *this }; |
115 | Ref<SVGAnimatedString> m_in1 { SVGAnimatedString::create(this) }; |
116 | Ref<SVGAnimatedString> m_in2 { SVGAnimatedString::create(this) }; |
117 | Ref<SVGAnimatedEnumeration> m_svgOperator { SVGAnimatedEnumeration::create(this, FECOMPOSITE_OPERATOR_OVER) }; |
118 | Ref<SVGAnimatedNumber> m_k1 { SVGAnimatedNumber::create(this) }; |
119 | Ref<SVGAnimatedNumber> m_k2 { SVGAnimatedNumber::create(this) }; |
120 | Ref<SVGAnimatedNumber> m_k3 { SVGAnimatedNumber::create(this) }; |
121 | Ref<SVGAnimatedNumber> m_k4 { SVGAnimatedNumber::create(this) }; |
122 | }; |
123 | |
124 | } // namespace WebCore |
125 | |