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: SMILMilestone(SMILTime aTime,bool aIsEnd)41 SMILMilestone(SMILTime aTime, bool aIsEnd) : mTime(aTime), mIsEnd(aIsEnd) {} 42 SMILMilestone()43 SMILMilestone() : mTime(0), mIsEnd(false) {} 44 45 bool operator==(const SMILMilestone& aOther) const { 46 return mTime == aOther.mTime && mIsEnd == aOther.mIsEnd; 47 } 48 49 bool operator!=(const SMILMilestone& aOther) const { 50 return !(*this == aOther); 51 } 52 53 bool operator<(const SMILMilestone& aOther) const { 54 // Earlier times sort first, and for equal times end milestones sort first 55 return mTime < aOther.mTime || 56 (mTime == aOther.mTime && mIsEnd && !aOther.mIsEnd); 57 } 58 59 bool operator<=(const SMILMilestone& aOther) const { 60 return *this == aOther || *this < aOther; 61 } 62 63 bool operator>=(const SMILMilestone& aOther) const { 64 return !(*this < aOther); 65 } 66 67 SMILTime mTime; // The milestone time. This may be in container time or 68 // parent container time depending on where it is used. 69 bool mIsEnd; // true if this milestone corresponds to an interval 70 // end, false otherwise. 71 }; 72 73 } // namespace mozilla 74 75 #endif // DOM_SMIL_SMILMILESTONE_H_ 76