1/*
2 * Copyright (C) 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 "GenericEventQueue.h"
31#include "WebAnimation.h"
32#include <wtf/Ref.h>
33
34namespace WebCore {
35
36class Animation;
37class Element;
38class RenderStyle;
39
40class DeclarativeAnimation : public WebAnimation {
41 WTF_MAKE_ISO_ALLOCATED(DeclarativeAnimation);
42public:
43 ~DeclarativeAnimation();
44
45 bool isDeclarativeAnimation() const final { return true; }
46
47 Element* owningElement() const { return m_owningElement; }
48 const Animation& backingAnimation() const { return m_backingAnimation; }
49 void setBackingAnimation(const Animation&);
50 void cancelFromStyle();
51
52 Optional<double> startTime() const final;
53 void setStartTime(Optional<double>) final;
54 Optional<double> bindingsCurrentTime() const final;
55 ExceptionOr<void> setBindingsCurrentTime(Optional<double>) final;
56 WebAnimation::PlayState bindingsPlayState() const final;
57 bool bindingsPending() const final;
58 WebAnimation::ReadyPromise& bindingsReady() final;
59 WebAnimation::FinishedPromise& bindingsFinished() final;
60 ExceptionOr<void> bindingsPlay() override;
61 ExceptionOr<void> bindingsPause() override;
62
63 void setTimeline(RefPtr<AnimationTimeline>&&) final;
64 void cancel() final;
65
66 bool needsTick() const override;
67 void tick() override;
68
69protected:
70 DeclarativeAnimation(Element&, const Animation&);
71
72 virtual void initialize(const RenderStyle* oldStyle, const RenderStyle& newStyle);
73 virtual void syncPropertiesWithBackingAnimation();
74 void invalidateDOMEvents(Seconds elapsedTime = 0_s);
75
76private:
77 void disassociateFromOwningElement();
78 void flushPendingStyleChanges() const;
79 AnimationEffectPhase phaseWithoutEffect() const;
80 void enqueueDOMEvent(const AtomicString&, Seconds);
81 void remove() final;
82
83 // ActiveDOMObject.
84 void suspend(ReasonForSuspension) final;
85 void resume() final;
86 void stop() final;
87
88 bool m_wasPending { false };
89 AnimationEffectPhase m_previousPhase { AnimationEffectPhase::Idle };
90
91 GenericEventQueue m_eventQueue;
92
93 Element* m_owningElement;
94 Ref<Animation> m_backingAnimation;
95 double m_previousIteration;
96};
97
98} // namespace WebCore
99
100SPECIALIZE_TYPE_TRAITS_WEB_ANIMATION(DeclarativeAnimation, isDeclarativeAnimation())
101