1/*
2 * Copyright (C) 2004, 2005, 2008 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 "FEComponentTransfer.h"
25#include "SVGElement.h"
26
27namespace WebCore {
28
29template<>
30struct SVGPropertyTraits<ComponentTransferType> {
31 static unsigned highestEnumValue() { return FECOMPONENTTRANSFER_TYPE_GAMMA; }
32
33 static String toString(ComponentTransferType type)
34 {
35 switch (type) {
36 case FECOMPONENTTRANSFER_TYPE_UNKNOWN:
37 return emptyString();
38 case FECOMPONENTTRANSFER_TYPE_IDENTITY:
39 return "identity"_s;
40 case FECOMPONENTTRANSFER_TYPE_TABLE:
41 return "table"_s;
42 case FECOMPONENTTRANSFER_TYPE_DISCRETE:
43 return "discrete"_s;
44 case FECOMPONENTTRANSFER_TYPE_LINEAR:
45 return "linear"_s;
46 case FECOMPONENTTRANSFER_TYPE_GAMMA:
47 return "gamma"_s;
48 }
49
50 ASSERT_NOT_REACHED();
51 return emptyString();
52 }
53
54 static ComponentTransferType fromString(const String& value)
55 {
56 if (value == "identity")
57 return FECOMPONENTTRANSFER_TYPE_IDENTITY;
58 if (value == "table")
59 return FECOMPONENTTRANSFER_TYPE_TABLE;
60 if (value == "discrete")
61 return FECOMPONENTTRANSFER_TYPE_DISCRETE;
62 if (value == "linear")
63 return FECOMPONENTTRANSFER_TYPE_LINEAR;
64 if (value == "gamma")
65 return FECOMPONENTTRANSFER_TYPE_GAMMA;
66 return FECOMPONENTTRANSFER_TYPE_UNKNOWN;
67 }
68};
69
70class SVGComponentTransferFunctionElement : public SVGElement {
71 WTF_MAKE_ISO_ALLOCATED(SVGComponentTransferFunctionElement);
72public:
73 ComponentTransferFunction transferFunction() const;
74
75 ComponentTransferType type() const { return m_type->currentValue<ComponentTransferType>(); }
76 const SVGNumberList& tableValues() const { return m_tableValues->currentValue(); }
77 float slope() const { return m_slope->currentValue(); }
78 float intercept() const { return m_intercept->currentValue(); }
79 float amplitude() const { return m_amplitude->currentValue(); }
80 float exponent() const { return m_exponent->currentValue(); }
81 float offset() const { return m_offset->currentValue(); }
82
83 SVGAnimatedEnumeration& typeAnimated() { return m_type; }
84 SVGAnimatedNumberList& tableValuesAnimated() { return m_tableValues; }
85 SVGAnimatedNumber& slopeAnimated() { return m_slope; }
86 SVGAnimatedNumber& interceptAnimated() { return m_intercept; }
87 SVGAnimatedNumber& amplitudeAnimated() { return m_amplitude; }
88 SVGAnimatedNumber& exponentAnimated() { return m_exponent; }
89 SVGAnimatedNumber& offsetAnimated() { return m_offset; }
90
91protected:
92 SVGComponentTransferFunctionElement(const QualifiedName&, Document&);
93
94 using PropertyRegistry = SVGPropertyOwnerRegistry<SVGComponentTransferFunctionElement, SVGElement>;
95 const SVGPropertyRegistry& propertyRegistry() const override { return m_propertyRegistry; }
96
97 void parseAttribute(const QualifiedName&, const AtomicString&) override;
98 void svgAttributeChanged(const QualifiedName&) override;
99
100 bool rendererIsNeeded(const RenderStyle&) override { return false; }
101
102private:
103 PropertyRegistry m_propertyRegistry { *this };
104 Ref<SVGAnimatedEnumeration> m_type { SVGAnimatedEnumeration::create(this, FECOMPONENTTRANSFER_TYPE_IDENTITY) };
105 Ref<SVGAnimatedNumberList> m_tableValues { SVGAnimatedNumberList::create(this) };
106 Ref<SVGAnimatedNumber> m_slope { SVGAnimatedNumber::create(this, 1) };
107 Ref<SVGAnimatedNumber> m_intercept { SVGAnimatedNumber::create(this) };
108 Ref<SVGAnimatedNumber> m_amplitude { SVGAnimatedNumber::create(this, 1) };
109 Ref<SVGAnimatedNumber> m_exponent { SVGAnimatedNumber::create(this, 1) };
110 Ref<SVGAnimatedNumber> m_offset { SVGAnimatedNumber::create(this) };
111};
112
113} // namespace WebCore
114