| 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 "CSSPropertyNames.h" |
| 33 | #include "Document.h" |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | class RenderElement; |
| 38 | |
| 39 | // An ImplicitAnimation tracks the state of a transition of a specific CSS property |
| 40 | // for a single RenderElement. |
| 41 | class ImplicitAnimation : public AnimationBase { |
| 42 | public: |
| 43 | static Ref<ImplicitAnimation> create(const Animation& animation, CSSPropertyID animatingProperty, Element& element, CompositeAnimation& compositeAnimation, const RenderStyle& fromStyle) |
| 44 | { |
| 45 | return adoptRef(*new ImplicitAnimation(animation, animatingProperty, element, compositeAnimation, fromStyle)); |
| 46 | }; |
| 47 | |
| 48 | CSSPropertyID transitionProperty() const { return m_transitionProperty; } |
| 49 | CSSPropertyID animatingProperty() const { return m_animatingProperty; } |
| 50 | |
| 51 | void onAnimationEnd(double elapsedTime) override; |
| 52 | bool startAnimation(double timeOffset) override; |
| 53 | void pauseAnimation(double timeOffset) override; |
| 54 | void endAnimation(bool fillingForwards = false) override; |
| 55 | |
| 56 | OptionSet<AnimateChange> animate(CompositeAnimation&, const RenderStyle& targetStyle, std::unique_ptr<RenderStyle>& animatedStyle); |
| 57 | void getAnimatedStyle(std::unique_ptr<RenderStyle>& animatedStyle) override; |
| 58 | void reset(const RenderStyle& to, CompositeAnimation&); |
| 59 | |
| 60 | bool computeExtentOfTransformAnimation(LayoutRect&) const override; |
| 61 | |
| 62 | bool affectsAcceleratedProperty() const; |
| 63 | |
| 64 | void setOverridden(bool); |
| 65 | bool overridden() const override { return m_overridden; } |
| 66 | |
| 67 | bool affectsProperty(CSSPropertyID) const override; |
| 68 | |
| 69 | bool hasStyle() const { return m_fromStyle && m_toStyle; } |
| 70 | |
| 71 | bool isTargetPropertyEqual(CSSPropertyID, const RenderStyle*); |
| 72 | |
| 73 | void blendPropertyValueInStyle(CSSPropertyID, RenderStyle*); |
| 74 | |
| 75 | Optional<Seconds> timeToNextService() override; |
| 76 | |
| 77 | bool active() const { return m_active; } |
| 78 | void setActive(bool b) { m_active = b; } |
| 79 | |
| 80 | const RenderStyle& unanimatedStyle() const override { return *m_fromStyle; } |
| 81 | |
| 82 | void clear() override; |
| 83 | |
| 84 | protected: |
| 85 | bool shouldSendEventForListener(Document::ListenerType) const; |
| 86 | bool sendTransitionEvent(const AtomicString&, double elapsedTime); |
| 87 | |
| 88 | void validateTransformFunctionList(); |
| 89 | void checkForMatchingFilterFunctionLists(); |
| 90 | #if ENABLE(FILTERS_LEVEL_2) |
| 91 | void checkForMatchingBackdropFilterFunctionLists(); |
| 92 | #endif |
| 93 | void checkForMatchingColorFilterFunctionLists(); |
| 94 | |
| 95 | private: |
| 96 | ImplicitAnimation(const Animation&, CSSPropertyID, Element&, CompositeAnimation&, const RenderStyle&); |
| 97 | virtual ~ImplicitAnimation(); |
| 98 | |
| 99 | // The two styles that we are blending. |
| 100 | std::unique_ptr<RenderStyle> m_fromStyle; |
| 101 | std::unique_ptr<RenderStyle> m_toStyle; |
| 102 | |
| 103 | CSSPropertyID m_transitionProperty; // Transition property as specified in the RenderStyle. |
| 104 | CSSPropertyID m_animatingProperty; // Specific property for this ImplicitAnimation |
| 105 | |
| 106 | bool m_active { true }; // Used for culling the list of transitions. |
| 107 | bool m_overridden { false }; // True when there is a keyframe animation that overrides the transitioning property |
| 108 | }; |
| 109 | |
| 110 | } // namespace WebCore |
| 111 | |