1/*
2 * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "SVGAnimatedPropertyAccessorImpl.h"
29#include "SVGAnimatedPropertyAnimatorImpl.h"
30#include "SVGAnimatedPropertyImpl.h"
31#include "SVGAnimatedPropertyPairAccessor.h"
32#include "SVGAnimatedPropertyPairAnimatorImpl.h"
33#include "SVGNames.h"
34
35namespace WebCore {
36
37template<typename OwnerType>
38class SVGAnimatedAngleOrientAccessor final : public SVGAnimatedPropertyPairAccessor<OwnerType, SVGAnimatedAngleAccessor<OwnerType>, SVGAnimatedOrientTypeAccessor<OwnerType>> {
39 using Base = SVGAnimatedPropertyPairAccessor<OwnerType, SVGAnimatedAngleAccessor<OwnerType>, SVGAnimatedOrientTypeAccessor<OwnerType>>;
40 using Base::property1;
41 using Base::property2;
42
43public:
44 using Base::Base;
45 template<Ref<SVGAnimatedAngle> OwnerType::*property1, Ref<SVGAnimatedOrientType> OwnerType::*property2>
46 constexpr static const SVGMemberAccessor<OwnerType>& singleton() { return Base::template singleton<SVGAnimatedAngleOrientAccessor, property1, property2>(); }
47
48private:
49 Optional<String> synchronize(const OwnerType& owner) const final
50 {
51 bool dirty1 = property1(owner)->isDirty();
52 bool dirty2 = property2(owner)->isDirty();
53 if (!(dirty1 || dirty2))
54 return WTF::nullopt;
55
56 auto type = property2(owner)->baseVal();
57
58 String string1 = dirty1 ? *property1(owner)->synchronize() : property1(owner)->baseValAsString();
59 String string2 = dirty2 ? *property2(owner)->synchronize() : property2(owner)->baseValAsString();
60 return type == SVGMarkerOrientAuto || type == SVGMarkerOrientAutoStartReverse ? string2 : string1;
61 }
62
63 std::unique_ptr<SVGAttributeAnimator> createAnimator(OwnerType& owner, const QualifiedName& attributeName, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) const final
64 {
65 return SVGAnimatedAngleOrientAnimator::create(attributeName, property1(owner), property2(owner), animationMode, calcMode, isAccumulated, isAdditive);
66 }
67
68 void appendAnimatedInstance(OwnerType& owner, SVGAttributeAnimator& animator) const final
69 {
70 static_cast<SVGAnimatedAngleOrientAnimator&>(animator).appendAnimatedInstance(property1(owner), property2(owner));
71 }
72};
73
74template<typename OwnerType>
75class SVGAnimatedIntegerPairAccessor final : public SVGAnimatedPropertyPairAccessor<OwnerType, SVGAnimatedIntegerAccessor<OwnerType>, SVGAnimatedIntegerAccessor<OwnerType>> {
76 using Base = SVGAnimatedPropertyPairAccessor<OwnerType, SVGAnimatedIntegerAccessor<OwnerType>, SVGAnimatedIntegerAccessor<OwnerType>>;
77 using Base::property1;
78 using Base::property2;
79
80public:
81 using Base::Base;
82 template<Ref<SVGAnimatedInteger> OwnerType::*property1, Ref<SVGAnimatedInteger> OwnerType::*property2>
83 constexpr static const SVGMemberAccessor<OwnerType>& singleton() { return Base::template singleton<SVGAnimatedIntegerPairAccessor, property1, property2>(); }
84
85private:
86 Optional<String> synchronize(const OwnerType& owner) const final
87 {
88 bool dirty1 = property1(owner)->isDirty();
89 bool dirty2 = property2(owner)->isDirty();
90 if (!(dirty1 || dirty2))
91 return WTF::nullopt;
92
93 String string1 = dirty1 ? *property1(owner)->synchronize() : property1(owner)->baseValAsString();
94 String string2 = dirty2 ? *property2(owner)->synchronize() : property2(owner)->baseValAsString();
95 return string1 == string2 ? string1 : string1 + ", " + string2;
96 }
97
98 std::unique_ptr<SVGAttributeAnimator> createAnimator(OwnerType& owner, const QualifiedName& attributeName, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) const final
99 {
100 return SVGAnimatedIntegerPairAnimator::create(attributeName, property1(owner), property2(owner), animationMode, calcMode, isAccumulated, isAdditive);
101 }
102
103 void appendAnimatedInstance(OwnerType& owner, SVGAttributeAnimator& animator) const final
104 {
105 static_cast<SVGAnimatedIntegerPairAnimator&>(animator).appendAnimatedInstance(property1(owner), property2(owner));
106 }
107};
108
109template<typename OwnerType>
110class SVGAnimatedNumberPairAccessor final : public SVGAnimatedPropertyPairAccessor<OwnerType, SVGAnimatedNumberAccessor<OwnerType>, SVGAnimatedNumberAccessor<OwnerType>> {
111 using Base = SVGAnimatedPropertyPairAccessor<OwnerType, SVGAnimatedNumberAccessor<OwnerType>, SVGAnimatedNumberAccessor<OwnerType>>;
112 using Base::property1;
113 using Base::property2;
114
115public:
116 using Base::Base;
117 template<Ref<SVGAnimatedNumber> OwnerType::*property1, Ref<SVGAnimatedNumber> OwnerType::*property2 >
118 constexpr static const SVGMemberAccessor<OwnerType>& singleton() { return Base::template singleton<SVGAnimatedNumberPairAccessor, property1, property2>(); }
119
120private:
121 Optional<String> synchronize(const OwnerType& owner) const final
122 {
123 bool dirty1 = property1(owner)->isDirty();
124 bool dirty2 = property2(owner)->isDirty();
125 if (!(dirty1 || dirty2))
126 return WTF::nullopt;
127
128 String string1 = dirty1 ? *property1(owner)->synchronize() : property1(owner)->baseValAsString();
129 String string2 = dirty2 ? *property2(owner)->synchronize() : property2(owner)->baseValAsString();
130 return string1 == string2 ? string1 : string1 + ", " + string2;
131 }
132
133 std::unique_ptr<SVGAttributeAnimator> createAnimator(OwnerType& owner, const QualifiedName& attributeName, AnimationMode animationMode, CalcMode calcMode, bool isAccumulated, bool isAdditive) const final
134 {
135 return SVGAnimatedNumberPairAnimator::create(attributeName, property1(owner), property2(owner), animationMode, calcMode, isAccumulated, isAdditive);
136 }
137
138 void appendAnimatedInstance(OwnerType& owner, SVGAttributeAnimator& animator) const final
139 {
140 static_cast<SVGAnimatedNumberPairAnimator&>(animator).appendAnimatedInstance(property1(owner), property2(owner));
141 }
142};
143
144}
145