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) 2014 Adobe Systems Incorporated. All rights reserved. |
5 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
6 | * |
7 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. |
11 | * |
12 | * This library is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Library General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU Library General Public License |
18 | * along with this library; see the file COPYING.LIB. If not, write to |
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | * Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | #pragma once |
24 | |
25 | #include "GraphicsTypes.h" |
26 | #include "SVGFilterPrimitiveStandardAttributes.h" |
27 | |
28 | namespace WebCore { |
29 | |
30 | template<> |
31 | struct SVGPropertyTraits<BlendMode> { |
32 | static unsigned highestEnumValue() { return static_cast<unsigned>(BlendMode::Luminosity); } |
33 | |
34 | static BlendMode fromString(const String& string) |
35 | { |
36 | BlendMode mode = BlendMode::Normal; |
37 | parseBlendMode(string, mode); |
38 | return mode; |
39 | } |
40 | |
41 | static String toString(BlendMode type) |
42 | { |
43 | if (type < BlendMode::PlusDarker) |
44 | return blendModeName(type); |
45 | |
46 | return emptyString(); |
47 | } |
48 | }; |
49 | |
50 | class SVGFEBlendElement final : public SVGFilterPrimitiveStandardAttributes { |
51 | WTF_MAKE_ISO_ALLOCATED(SVGFEBlendElement); |
52 | public: |
53 | static Ref<SVGFEBlendElement> create(const QualifiedName&, Document&); |
54 | |
55 | String in1() const { return m_in1->currentValue(); } |
56 | String in2() const { return m_in2->currentValue(); } |
57 | BlendMode mode() const { return m_mode->currentValue<BlendMode>(); } |
58 | |
59 | SVGAnimatedString& in1Animated() { return m_in1; } |
60 | SVGAnimatedString& in2Animated() { return m_in2; } |
61 | SVGAnimatedEnumeration& modeAnimated() { return m_mode; } |
62 | |
63 | private: |
64 | SVGFEBlendElement(const QualifiedName&, Document&); |
65 | |
66 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGFEBlendElement, SVGFilterPrimitiveStandardAttributes>; |
67 | const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; } |
68 | |
69 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
70 | void svgAttributeChanged(const QualifiedName&) override; |
71 | |
72 | RefPtr<FilterEffect> build(SVGFilterBuilder*, Filter&) const override; |
73 | bool setFilterEffectAttribute(FilterEffect*, const QualifiedName& attrName) override; |
74 | |
75 | PropertyRegistry m_propertyRegistry { *this }; |
76 | Ref<SVGAnimatedString> m_in1 { SVGAnimatedString::create(this) }; |
77 | Ref<SVGAnimatedString> m_in2 { SVGAnimatedString::create(this) }; |
78 | Ref<SVGAnimatedEnumeration> m_mode { SVGAnimatedEnumeration::create(this, BlendMode::Normal) }; |
79 | }; |
80 | |
81 | } // namespace WebCore |
82 | |