1 | /* |
2 | * Copyright (C) 2017-2018 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 "AnimationEffect.h" |
29 | #include "AnimationEffectPhase.h" |
30 | #include "BasicEffectTiming.h" |
31 | #include "ComputedEffectTiming.h" |
32 | #include "ExceptionOr.h" |
33 | #include "FillMode.h" |
34 | #include "KeyframeEffectOptions.h" |
35 | #include "OptionalEffectTiming.h" |
36 | #include "PlaybackDirection.h" |
37 | #include "TimingFunction.h" |
38 | #include "WebAnimation.h" |
39 | #include "WebAnimationUtilities.h" |
40 | #include <wtf/Forward.h> |
41 | #include <wtf/Ref.h> |
42 | #include <wtf/RefCounted.h> |
43 | #include <wtf/RefPtr.h> |
44 | #include <wtf/Seconds.h> |
45 | #include <wtf/Variant.h> |
46 | #include <wtf/WeakPtr.h> |
47 | |
48 | namespace WebCore { |
49 | |
50 | class AnimationEffect : public RefCounted<AnimationEffect> { |
51 | public: |
52 | virtual ~AnimationEffect(); |
53 | |
54 | virtual bool isKeyframeEffect() const { return false; } |
55 | |
56 | EffectTiming getTiming() const; |
57 | BasicEffectTiming getBasicTiming() const; |
58 | ComputedEffectTiming getComputedTiming() const; |
59 | ExceptionOr<void> updateTiming(Optional<OptionalEffectTiming>); |
60 | |
61 | virtual void apply(RenderStyle&) = 0; |
62 | virtual void invalidate() = 0; |
63 | virtual void animationDidSeek() = 0; |
64 | virtual void animationSuspensionStateDidChange(bool) = 0; |
65 | |
66 | WebAnimation* animation() const { return m_animation.get(); } |
67 | void setAnimation(WebAnimation* animation) { m_animation = makeWeakPtr(animation); } |
68 | |
69 | Seconds delay() const { return m_delay; } |
70 | void setDelay(const Seconds&); |
71 | |
72 | Seconds endDelay() const { return m_endDelay; } |
73 | void setEndDelay(const Seconds&); |
74 | |
75 | FillMode fill() const { return m_fill; } |
76 | void setFill(FillMode); |
77 | |
78 | double iterationStart() const { return m_iterationStart; } |
79 | ExceptionOr<void> setIterationStart(double); |
80 | |
81 | double iterations() const { return m_iterations; } |
82 | ExceptionOr<void> setIterations(double); |
83 | |
84 | Seconds iterationDuration() const { return m_iterationDuration; } |
85 | void setIterationDuration(const Seconds&); |
86 | |
87 | PlaybackDirection direction() const { return m_direction; } |
88 | void setDirection(PlaybackDirection); |
89 | |
90 | TimingFunction* timingFunction() const { return m_timingFunction.get(); } |
91 | void setTimingFunction(const RefPtr<TimingFunction>&); |
92 | |
93 | protected: |
94 | explicit AnimationEffect(); |
95 | |
96 | private: |
97 | enum class ComputedDirection : uint8_t { Forwards, Reverse }; |
98 | |
99 | FillMode m_fill { FillMode::Auto }; |
100 | PlaybackDirection m_direction { PlaybackDirection::Normal }; |
101 | |
102 | WeakPtr<WebAnimation> m_animation; |
103 | RefPtr<TimingFunction> m_timingFunction; |
104 | |
105 | double m_iterationStart { 0 }; |
106 | double m_iterations { 1 }; |
107 | |
108 | Seconds m_delay { 0_s }; |
109 | Seconds m_endDelay { 0_s }; |
110 | Seconds m_iterationDuration { 0_s }; |
111 | }; |
112 | |
113 | } // namespace WebCore |
114 | |
115 | #define SPECIALIZE_TYPE_TRAITS_ANIMATION_EFFECT(ToValueTypeName, predicate) \ |
116 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \ |
117 | static bool isType(const WebCore::AnimationEffect& value) { return value.predicate; } \ |
118 | SPECIALIZE_TYPE_TRAITS_END() |
119 | |