1/*
2 * Copyright (C) 2007 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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#pragma once
30
31#include "AnimationBase.h"
32#include "Document.h"
33#include "KeyframeList.h"
34
35namespace WebCore {
36
37class FilterOperations;
38class RenderStyle;
39
40// A KeyframeAnimation tracks the state of an explicit animation for a single RenderElement.
41class KeyframeAnimation final : public AnimationBase {
42public:
43 static Ref<KeyframeAnimation> create(const Animation& animation, Element& element, CompositeAnimation& compositeAnimation, const RenderStyle& unanimatedStyle)
44 {
45 return adoptRef(*new KeyframeAnimation(animation, element, compositeAnimation, unanimatedStyle));
46 }
47
48 OptionSet<AnimateChange> animate(CompositeAnimation&, const RenderStyle& targetStyle, std::unique_ptr<RenderStyle>& animatedStyle);
49 void getAnimatedStyle(std::unique_ptr<RenderStyle>&) override;
50
51 bool computeExtentOfTransformAnimation(LayoutRect&) const override;
52
53 const KeyframeList& keyframes() const { return m_keyframes; }
54
55 const AtomString& name() const { return m_keyframes.animationName(); }
56
57 bool hasAnimationForProperty(CSSPropertyID) const;
58
59 bool triggersStackingContext() const { return m_triggersStackingContext; }
60 bool dependsOnLayout() const { return m_dependsOnLayout; }
61 bool affectsAcceleratedProperty() const { return m_hasAcceleratedProperty; }
62
63 void setUnanimatedStyle(std::unique_ptr<RenderStyle> style) { m_unanimatedStyle = WTFMove(style); }
64 const RenderStyle& unanimatedStyle() const override { return *m_unanimatedStyle; }
65
66 Optional<Seconds> timeToNextService() override;
67
68protected:
69 void onAnimationStart(double elapsedTime) override;
70 void onAnimationIteration(double elapsedTime) override;
71 void onAnimationEnd(double elapsedTime) override;
72 bool startAnimation(double timeOffset) override;
73 void pauseAnimation(double timeOffset) override;
74 void endAnimation(bool fillingForwards = false) override;
75
76 void overrideAnimations() override;
77 void resumeOverriddenAnimations() override;
78
79 bool shouldSendEventForListener(Document::ListenerType inListenerType) const;
80 bool sendAnimationEvent(const AtomString&, double elapsedTime);
81
82 bool affectsProperty(CSSPropertyID) const override;
83
84 bool computeExtentOfAnimationForMatrixAnimation(const FloatRect& rendererBox, LayoutRect&) const;
85
86 bool computeExtentOfAnimationForMatchingTransformLists(const FloatRect& rendererBox, LayoutRect&) const;
87
88 void computeLayoutDependency();
89 void resolveKeyframeStyles();
90 void validateTransformFunctionList();
91 void checkForMatchingFilterFunctionLists();
92#if ENABLE(FILTERS_LEVEL_2)
93 void checkForMatchingBackdropFilterFunctionLists();
94#endif
95 void checkForMatchingColorFilterFunctionLists();
96 bool checkForMatchingFilterFunctionLists(CSSPropertyID, const std::function<const FilterOperations& (const RenderStyle&)>&) const;
97
98private:
99 KeyframeAnimation(const Animation&, Element&, CompositeAnimation&, const RenderStyle& unanimatedStyle);
100 virtual ~KeyframeAnimation();
101
102 // Get the styles for the given property surrounding the current animation time and the progress between them.
103 void fetchIntervalEndpointsForProperty(CSSPropertyID, const RenderStyle*& fromStyle, const RenderStyle*& toStyle, double& progress) const;
104
105 KeyframeList m_keyframes;
106 std::unique_ptr<RenderStyle> m_unanimatedStyle; // The style just before we started animation
107
108 bool m_startEventDispatched { false };
109 bool m_triggersStackingContext { false };
110 bool m_hasAcceleratedProperty { false };
111 bool m_dependsOnLayout { false };
112};
113
114} // namespace WebCore
115