blob: aa91df38b36298f121a1411c4d0ae5ecd58665d3 [file] [log] [blame]
darinb9481ed2006-03-20 02:57:59 +00001/*
zimmermann@webkit.org711245f2010-08-03 19:39:01 +00002 * Copyright (C) 2006 Oliver Hunt <oliver@nerget.com>
commit-queue@webkit.orgfcb4bb12019-03-18 23:33:10 +00003 * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
zimmermann@webkit.org711245f2010-08-03 19:39:01 +00004 *
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.
darinb9481ed2006-03-20 02:57:59 +000019 */
20
commit-queue@webkit.org46c0f522016-11-13 10:05:43 +000021#pragma once
darinb9481ed2006-03-20 02:57:59 +000022
krit@webkit.orga64eca02010-09-22 07:42:12 +000023#include "FEDisplacementMap.h"
rwlbuis79983122006-10-09 07:40:41 +000024#include "SVGFilterPrimitiveStandardAttributes.h"
darinb9481ed2006-03-20 02:57:59 +000025
darind18e72a2006-03-21 01:15:36 +000026namespace WebCore {
zimmermann@webkit.orge1c7c582011-07-07 14:18:01 +000027
zimmermann@webkit.org94630af2011-05-18 15:35:36 +000028template<>
29struct SVGPropertyTraits<ChannelSelectorType> {
zimmermann@webkit.orgf941d3c2012-04-03 11:26:50 +000030 static unsigned highestEnumValue() { return CHANNEL_A; }
zimmermann@webkit.org94630af2011-05-18 15:35:36 +000031
32 static String toString(ChannelSelectorType type)
33 {
34 switch (type) {
35 case CHANNEL_UNKNOWN:
36 return emptyString();
37 case CHANNEL_R:
utatane.tea@gmail.com84077632018-06-23 08:39:34 +000038 return "R"_s;
zimmermann@webkit.org94630af2011-05-18 15:35:36 +000039 case CHANNEL_G:
utatane.tea@gmail.com84077632018-06-23 08:39:34 +000040 return "G"_s;
zimmermann@webkit.org94630af2011-05-18 15:35:36 +000041 case CHANNEL_B:
utatane.tea@gmail.com84077632018-06-23 08:39:34 +000042 return "B"_s;
zimmermann@webkit.org94630af2011-05-18 15:35:36 +000043 case CHANNEL_A:
utatane.tea@gmail.com84077632018-06-23 08:39:34 +000044 return "A"_s;
zimmermann@webkit.org94630af2011-05-18 15:35:36 +000045 }
46
47 ASSERT_NOT_REACHED();
48 return emptyString();
49 }
50
51 static ChannelSelectorType fromString(const String& value)
52 {
53 if (value == "R")
54 return CHANNEL_R;
55 if (value == "G")
56 return CHANNEL_G;
57 if (value == "B")
58 return CHANNEL_B;
59 if (value == "A")
60 return CHANNEL_A;
61 return CHANNEL_UNKNOWN;
62 }
63};
64
andersca@apple.com16d2dd42014-01-16 23:08:24 +000065class SVGFEDisplacementMapElement final : public SVGFilterPrimitiveStandardAttributes {
fpizlo@apple.com197cd322018-03-17 06:11:00 +000066 WTF_MAKE_ISO_ALLOCATED(SVGFEDisplacementMapElement);
zimmermann@webkit.orge1c7c582011-07-07 14:18:01 +000067public:
weinig@apple.com10923572015-01-07 20:56:24 +000068 static Ref<SVGFEDisplacementMapElement> create(const QualifiedName&, Document&);
zimmermann@webkit.orge1c7c582011-07-07 14:18:01 +000069
70 static ChannelSelectorType stringToChannel(const String&);
commit-queue@webkit.orgea3eb582018-08-06 21:08:53 +000071
said@apple.com7f843242019-03-21 21:46:39 +000072 String in1() const { return m_in1->currentValue(); }
73 String in2() const { return m_in2->currentValue(); }
commit-queue@webkit.org30faed42019-03-26 01:26:11 +000074 ChannelSelectorType xChannelSelector() const { return m_xChannelSelector->currentValue<ChannelSelectorType>(); }
75 ChannelSelectorType yChannelSelector() const { return m_yChannelSelector->currentValue<ChannelSelectorType>(); }
said@apple.comf9426b32019-03-21 00:35:50 +000076 float scale() const { return m_scale->currentValue(); }
commit-queue@webkit.orgea3eb582018-08-06 21:08:53 +000077
said@apple.com7f843242019-03-21 21:46:39 +000078 SVGAnimatedString& in1Animated() { return m_in1; }
79 SVGAnimatedString& in2Animated() { return m_in2; }
commit-queue@webkit.org30faed42019-03-26 01:26:11 +000080 SVGAnimatedEnumeration& xChannelSelectorAnimated() { return m_xChannelSelector; }
81 SVGAnimatedEnumeration& yChannelSelectorAnimated() { return m_yChannelSelector; }
said@apple.comf9426b32019-03-21 00:35:50 +000082 SVGAnimatedNumber& scaleAnimated() { return m_scale; }
commit-queue@webkit.orgea3eb582018-08-06 21:08:53 +000083
zimmermann@webkit.orge1c7c582011-07-07 14:18:01 +000084private:
weinig@apple.com52e786e2013-09-15 18:06:06 +000085 SVGFEDisplacementMapElement(const QualifiedName& tagName, Document&);
commit-queue@webkit.orgea3eb582018-08-06 21:08:53 +000086
commit-queue@webkit.orgfcb4bb12019-03-18 23:33:10 +000087 using PropertyRegistry = SVGPropertyOwnerRegistry<SVGFEDisplacementMapElement, SVGFilterPrimitiveStandardAttributes>;
88 const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; }
89
darin@apple.com0ce67df2019-06-17 01:48:13 +000090 void parseAttribute(const QualifiedName&, const AtomString&) override;
darin@apple.com11ff47c2016-03-04 16:47:55 +000091 void svgAttributeChanged(const QualifiedName&) override;
commit-queue@webkit.orgea3eb582018-08-06 21:08:53 +000092
93 bool setFilterEffectAttribute(FilterEffect*, const QualifiedName& attrName) override;
commit-queue@webkit.orga43a6e82019-03-20 01:49:29 +000094 RefPtr<FilterEffect> build(SVGFilterBuilder*, Filter&) const override;
zimmermann@webkit.orge1c7c582011-07-07 14:18:01 +000095
commit-queue@webkit.orgfcb4bb12019-03-18 23:33:10 +000096 PropertyRegistry m_propertyRegistry { *this };
said@apple.com7f843242019-03-21 21:46:39 +000097 Ref<SVGAnimatedString> m_in1 { SVGAnimatedString::create(this) };
98 Ref<SVGAnimatedString> m_in2 { SVGAnimatedString::create(this) };
commit-queue@webkit.org30faed42019-03-26 01:26:11 +000099 Ref<SVGAnimatedEnumeration> m_xChannelSelector { SVGAnimatedEnumeration::create(this, CHANNEL_A) };
100 Ref<SVGAnimatedEnumeration> m_yChannelSelector { SVGAnimatedEnumeration::create(this, CHANNEL_A) };
said@apple.comf9426b32019-03-21 00:35:50 +0000101 Ref<SVGAnimatedNumber> m_scale { SVGAnimatedNumber::create(this) };
zimmermann@webkit.orge1c7c582011-07-07 14:18:01 +0000102};
103
weinigab5f09e2006-07-29 23:15:25 +0000104} // namespace WebCore