SMILMilestone.h (3028B)
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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_SMIL_SMILMILESTONE_H_ 8 #define DOM_SMIL_SMILMILESTONE_H_ 9 10 #include "mozilla/SMILTypes.h" 11 12 namespace mozilla { 13 14 /* 15 * A significant moment in an SMILTimedElement's lifetime where a sample is 16 * required. 17 * 18 * Animations register the next milestone in their lifetime with the time 19 * container that they belong to. When the animation controller goes to run 20 * a sample it first visits all the animations that have a registered milestone 21 * in order of their milestone times. This allows interdependencies between 22 * animations to be correctly resolved and events to fire in the proper order. 23 * 24 * A distinction is made between a milestone representing the end of an interval 25 * and any other milestone. This is because if animation A ends at time t, and 26 * animation B begins at the same time t (or has some other significant moment 27 * such as firing a repeat event), SMIL's endpoint-exclusive timing model 28 * implies that the interval end occurs first. In fact, interval ends can be 29 * thought of as ending an infinitesimally small time before t. Therefore, 30 * A should be sampled before B. 31 * 32 * Furthermore, this distinction between sampling the end of an interval and 33 * a regular sample is used within the timing model (specifically in 34 * SMILTimedElement) to ensure that all intervals ending at time t are sampled 35 * before any new intervals are entered so that we have a fully up-to-date set 36 * of instance times available before committing to a new interval. Once an 37 * interval is entered, the begin time is fixed. 38 */ 39 class SMILMilestone { 40 public: 41 constexpr SMILMilestone(SMILTime aTime, bool aIsEnd) 42 : mTime(aTime), mIsEnd(aIsEnd) {} 43 44 constexpr SMILMilestone() : mTime(0), mIsEnd(false) {} 45 46 bool operator==(const SMILMilestone& aOther) const { 47 return mTime == aOther.mTime && mIsEnd == aOther.mIsEnd; 48 } 49 50 bool operator!=(const SMILMilestone& aOther) const { 51 return !(*this == aOther); 52 } 53 54 bool operator<(const SMILMilestone& aOther) const { 55 // Earlier times sort first, and for equal times end milestones sort first 56 return mTime < aOther.mTime || 57 (mTime == aOther.mTime && mIsEnd && !aOther.mIsEnd); 58 } 59 60 bool operator<=(const SMILMilestone& aOther) const { 61 return *this == aOther || *this < aOther; 62 } 63 64 bool operator>=(const SMILMilestone& aOther) const { 65 return !(*this < aOther); 66 } 67 68 SMILTime mTime; // The milestone time. This may be in container time or 69 // parent container time depending on where it is used. 70 bool mIsEnd; // true if this milestone corresponds to an interval 71 // end, false otherwise. 72 }; 73 74 } // namespace mozilla 75 76 #endif // DOM_SMIL_SMILMILESTONE_H_