michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NS_SMILTIMEVALUE_H_ michael@0: #define NS_SMILTIMEVALUE_H_ michael@0: michael@0: #include "nsSMILTypes.h" michael@0: #include "nsDebug.h" michael@0: michael@0: /*---------------------------------------------------------------------- michael@0: * nsSMILTimeValue class michael@0: * michael@0: * A tri-state time value. michael@0: * michael@0: * First a quick overview of the SMIL time data types: michael@0: * michael@0: * nsSMILTime -- a timestamp in milliseconds. michael@0: * nsSMILTimeValue -- (this class) a timestamp that can take the additional michael@0: * states 'indefinite' and 'unresolved' michael@0: * nsSMILInstanceTime -- an nsSMILTimeValue used for constructing intervals. It michael@0: * contains additional fields to govern reset behavior michael@0: * and track timing dependencies (e.g. syncbase timing). michael@0: * nsSMILInterval -- a pair of nsSMILInstanceTimes that defines a begin and michael@0: * an end time for animation. michael@0: * nsSMILTimeValueSpec -- a component of a begin or end attribute, such as the michael@0: * '5s' or 'a.end+2m' in begin="5s; a.end+2m". Acts as michael@0: * a broker between an nsSMILTimedElement and its michael@0: * nsSMILInstanceTimes by generating new instance times michael@0: * and handling changes to existing times. michael@0: * michael@0: * Objects of this class may be in one of three states: michael@0: * michael@0: * 1) The time is resolved and has a definite millisecond value michael@0: * 2) The time is resolved and indefinite michael@0: * 3) The time is unresolved michael@0: * michael@0: * In summary: michael@0: * michael@0: * State | GetMillis | IsDefinite | IsIndefinite | IsResolved michael@0: * -----------+-----------------+------------+--------------+------------ michael@0: * Definite | nsSMILTimeValue | true | false | true michael@0: * -----------+-----------------+------------+--------------+------------ michael@0: * Indefinite | -- | false | true | true michael@0: * -----------+-----------------+------------+--------------+------------ michael@0: * Unresolved | -- | false | false | false michael@0: * michael@0: */ michael@0: michael@0: class nsSMILTimeValue michael@0: { michael@0: public: michael@0: // Creates an unresolved time value michael@0: nsSMILTimeValue() michael@0: : mMilliseconds(kUnresolvedMillis), michael@0: mState(STATE_UNRESOLVED) michael@0: { } michael@0: michael@0: // Creates a resolved time value michael@0: explicit nsSMILTimeValue(nsSMILTime aMillis) michael@0: : mMilliseconds(aMillis), michael@0: mState(STATE_DEFINITE) michael@0: { } michael@0: michael@0: // Named constructor to create an indefinite time value michael@0: static nsSMILTimeValue Indefinite() michael@0: { michael@0: nsSMILTimeValue value; michael@0: value.SetIndefinite(); michael@0: return value; michael@0: } michael@0: michael@0: bool IsIndefinite() const { return mState == STATE_INDEFINITE; } michael@0: void SetIndefinite() michael@0: { michael@0: mState = STATE_INDEFINITE; michael@0: mMilliseconds = kUnresolvedMillis; michael@0: } michael@0: michael@0: bool IsResolved() const { return mState != STATE_UNRESOLVED; } michael@0: void SetUnresolved() michael@0: { michael@0: mState = STATE_UNRESOLVED; michael@0: mMilliseconds = kUnresolvedMillis; michael@0: } michael@0: michael@0: bool IsDefinite() const { return mState == STATE_DEFINITE; } michael@0: nsSMILTime GetMillis() const michael@0: { michael@0: NS_ABORT_IF_FALSE(mState == STATE_DEFINITE, michael@0: "GetMillis() called for unresolved or indefinite time"); michael@0: michael@0: return mState == STATE_DEFINITE ? mMilliseconds : kUnresolvedMillis; michael@0: } michael@0: michael@0: void SetMillis(nsSMILTime aMillis) michael@0: { michael@0: mState = STATE_DEFINITE; michael@0: mMilliseconds = aMillis; michael@0: } michael@0: michael@0: int8_t CompareTo(const nsSMILTimeValue& aOther) const; michael@0: michael@0: bool operator==(const nsSMILTimeValue& aOther) const michael@0: { return CompareTo(aOther) == 0; } michael@0: michael@0: bool operator!=(const nsSMILTimeValue& aOther) const michael@0: { return CompareTo(aOther) != 0; } michael@0: michael@0: bool operator<(const nsSMILTimeValue& aOther) const michael@0: { return CompareTo(aOther) < 0; } michael@0: michael@0: bool operator>(const nsSMILTimeValue& aOther) const michael@0: { return CompareTo(aOther) > 0; } michael@0: michael@0: bool operator<=(const nsSMILTimeValue& aOther) const michael@0: { return CompareTo(aOther) <= 0; } michael@0: michael@0: bool operator>=(const nsSMILTimeValue& aOther) const michael@0: { return CompareTo(aOther) >= 0; } michael@0: michael@0: private: michael@0: static nsSMILTime kUnresolvedMillis; michael@0: michael@0: nsSMILTime mMilliseconds; michael@0: enum { michael@0: STATE_DEFINITE, michael@0: STATE_INDEFINITE, michael@0: STATE_UNRESOLVED michael@0: } mState; michael@0: }; michael@0: michael@0: #endif // NS_SMILTIMEVALUE_H_