ComputedTiming.h (2675B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_ComputedTiming_h 8 #define mozilla_ComputedTiming_h 9 10 #include "mozilla/StickyTimeDuration.h" 11 #include "mozilla/dom/AnimationEffectBinding.h" // FillMode 12 #include "mozilla/dom/Nullable.h" 13 14 namespace mozilla { 15 16 /** 17 * Stores the results of calculating the timing properties of an animation 18 * at a given sample time. 19 */ 20 struct ComputedTiming { 21 // The total duration of the animation including all iterations. 22 // Will equal StickyTimeDuration::Forever() if the animation repeats 23 // indefinitely. 24 StickyTimeDuration mActiveDuration; 25 // The time within the active interval. 26 StickyTimeDuration mActiveTime; 27 // The effect end time in local time (i.e. an offset from the effect's 28 // start time). Will equal StickyTimeDuration::Forever() if the animation 29 // plays indefinitely. 30 StickyTimeDuration mEndTime; 31 // Progress towards the end of the current iteration. If the effect is 32 // being sampled backwards, this will go from 1.0 to 0.0. 33 // Will be null if the animation is neither animating nor 34 // filling at the sampled time. 35 dom::Nullable<double> mProgress; 36 // Zero-based iteration index (meaningless if mProgress is null). 37 uint64_t mCurrentIteration = 0; 38 // Unlike TimingParams::mIterations, this value is 39 // guaranteed to be in the range [0, Infinity]. 40 double mIterations = 1.0; 41 double mIterationStart = 0.0; 42 StickyTimeDuration mDuration; 43 44 // This is the computed fill mode so it is never auto 45 dom::FillMode mFill = dom::FillMode::None; 46 bool FillsForwards() const { 47 MOZ_ASSERT(mFill != dom::FillMode::Auto, 48 "mFill should not be Auto in ComputedTiming."); 49 return mFill == dom::FillMode::Both || mFill == dom::FillMode::Forwards; 50 } 51 bool FillsBackwards() const { 52 MOZ_ASSERT(mFill != dom::FillMode::Auto, 53 "mFill should not be Auto in ComputedTiming."); 54 return mFill == dom::FillMode::Both || mFill == dom::FillMode::Backwards; 55 } 56 57 enum class AnimationPhase { 58 Idle, // Not sampled (null sample time) 59 Before, // Sampled prior to the start of the active interval 60 Active, // Sampled within the active interval 61 After // Sampled after (or at) the end of the active interval 62 }; 63 AnimationPhase mPhase = AnimationPhase::Idle; 64 65 bool mBeforeFlag = false; 66 }; 67 68 } // namespace mozilla 69 70 #endif // mozilla_ComputedTiming_h