| 1 | /* |
| 2 | * Copyright (C) Canon Inc. 2016 |
| 3 | * Copyright (C) 2017 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 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 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #pragma once |
| 28 | |
| 29 | #include "CSSValue.h" |
| 30 | #include "ComputedEffectTiming.h" |
| 31 | #include "RenderStyle.h" |
| 32 | #include "WebAnimation.h" |
| 33 | #include <wtf/Forward.h> |
| 34 | #include <wtf/HashMap.h> |
| 35 | #include <wtf/ListHashSet.h> |
| 36 | #include <wtf/Markable.h> |
| 37 | #include <wtf/Optional.h> |
| 38 | #include <wtf/Ref.h> |
| 39 | #include <wtf/RefCounted.h> |
| 40 | #include <wtf/Seconds.h> |
| 41 | |
| 42 | namespace WebCore { |
| 43 | |
| 44 | class CSSAnimation; |
| 45 | class CSSTransition; |
| 46 | class DeclarativeAnimation; |
| 47 | class Element; |
| 48 | |
| 49 | class AnimationTimeline : public RefCounted<AnimationTimeline> { |
| 50 | public: |
| 51 | virtual bool isDocumentTimeline() const { return false; } |
| 52 | |
| 53 | void forgetAnimation(WebAnimation*); |
| 54 | virtual void animationTimingDidChange(WebAnimation&); |
| 55 | virtual void removeAnimation(WebAnimation&); |
| 56 | |
| 57 | Optional<double> bindingsCurrentTime(); |
| 58 | virtual Optional<Seconds> currentTime() { return m_currentTime; } |
| 59 | |
| 60 | enum class Ordering : uint8_t { Sorted, Unsorted }; |
| 61 | Vector<RefPtr<WebAnimation>> animationsForElement(Element&, Ordering ordering = Ordering::Unsorted) const; |
| 62 | void elementWasRemoved(Element&); |
| 63 | void removeAnimationsForElement(Element&); |
| 64 | void cancelDeclarativeAnimationsForElement(Element&); |
| 65 | virtual void animationWasAddedToElement(WebAnimation&, Element&); |
| 66 | virtual void animationWasRemovedFromElement(WebAnimation&, Element&); |
| 67 | void removeDeclarativeAnimationFromListsForOwningElement(WebAnimation&, Element&); |
| 68 | |
| 69 | void updateCSSAnimationsForElement(Element&, const RenderStyle* currentStyle, const RenderStyle& afterChangeStyle); |
| 70 | void updateCSSTransitionsForElement(Element&, const RenderStyle& currentStyle, const RenderStyle& afterChangeStyle); |
| 71 | |
| 72 | using ElementToAnimationsMap = HashMap<Element*, ListHashSet<RefPtr<WebAnimation>>>; |
| 73 | using PropertyToTransitionMap = HashMap<CSSPropertyID, RefPtr<CSSTransition>>; |
| 74 | |
| 75 | virtual ~AnimationTimeline(); |
| 76 | |
| 77 | protected: |
| 78 | explicit AnimationTimeline(); |
| 79 | |
| 80 | Vector<WeakPtr<WebAnimation>> m_allAnimations; |
| 81 | ListHashSet<RefPtr<WebAnimation>> m_animations; |
| 82 | HashMap<Element*, PropertyToTransitionMap> m_elementToCompletedCSSTransitionByCSSPropertyID; |
| 83 | |
| 84 | private: |
| 85 | RefPtr<WebAnimation> cssAnimationForElementAndProperty(Element&, CSSPropertyID); |
| 86 | PropertyToTransitionMap& ensureRunningTransitionsByProperty(Element&); |
| 87 | void cancelDeclarativeAnimation(DeclarativeAnimation&); |
| 88 | |
| 89 | ElementToAnimationsMap m_elementToAnimationsMap; |
| 90 | ElementToAnimationsMap m_elementToCSSAnimationsMap; |
| 91 | ElementToAnimationsMap m_elementToCSSTransitionsMap; |
| 92 | HashMap<Element*, HashMap<String, RefPtr<CSSAnimation>>> m_elementToCSSAnimationByName; |
| 93 | HashMap<Element*, PropertyToTransitionMap> m_elementToRunningCSSTransitionByCSSPropertyID; |
| 94 | |
| 95 | Markable<Seconds, Seconds::MarkableTraits> m_currentTime; |
| 96 | }; |
| 97 | |
| 98 | } // namespace WebCore |
| 99 | |
| 100 | #define SPECIALIZE_TYPE_TRAITS_ANIMATION_TIMELINE(ToValueTypeName, predicate) \ |
| 101 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \ |
| 102 | static bool isType(const WebCore::AnimationTimeline& value) { return value.predicate; } \ |
| 103 | SPECIALIZE_TYPE_TRAITS_END() |
| 104 | |