1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef NS_SMILTIMEVALUE_H_
7 #define NS_SMILTIMEVALUE_H_
9 #include "nsSMILTypes.h"
12 /*----------------------------------------------------------------------
13 * nsSMILTimeValue class
15 * A tri-state time value.
17 * First a quick overview of the SMIL time data types:
19 * nsSMILTime -- a timestamp in milliseconds.
20 * nsSMILTimeValue -- (this class) a timestamp that can take the additional
21 * states 'indefinite' and 'unresolved'
22 * nsSMILInstanceTime -- an nsSMILTimeValue used for constructing intervals. It
23 * contains additional fields to govern reset behavior
24 * and track timing dependencies (e.g. syncbase timing).
25 * nsSMILInterval -- a pair of nsSMILInstanceTimes that defines a begin and
26 * an end time for animation.
27 * nsSMILTimeValueSpec -- a component of a begin or end attribute, such as the
28 * '5s' or 'a.end+2m' in begin="5s; a.end+2m". Acts as
29 * a broker between an nsSMILTimedElement and its
30 * nsSMILInstanceTimes by generating new instance times
31 * and handling changes to existing times.
33 * Objects of this class may be in one of three states:
35 * 1) The time is resolved and has a definite millisecond value
36 * 2) The time is resolved and indefinite
37 * 3) The time is unresolved
41 * State | GetMillis | IsDefinite | IsIndefinite | IsResolved
42 * -----------+-----------------+------------+--------------+------------
43 * Definite | nsSMILTimeValue | true | false | true
44 * -----------+-----------------+------------+--------------+------------
45 * Indefinite | -- | false | true | true
46 * -----------+-----------------+------------+--------------+------------
47 * Unresolved | -- | false | false | false
54 // Creates an unresolved time value
56 : mMilliseconds(kUnresolvedMillis
),
57 mState(STATE_UNRESOLVED
)
60 // Creates a resolved time value
61 explicit nsSMILTimeValue(nsSMILTime aMillis
)
62 : mMilliseconds(aMillis
),
63 mState(STATE_DEFINITE
)
66 // Named constructor to create an indefinite time value
67 static nsSMILTimeValue
Indefinite()
69 nsSMILTimeValue value
;
70 value
.SetIndefinite();
74 bool IsIndefinite() const { return mState
== STATE_INDEFINITE
; }
77 mState
= STATE_INDEFINITE
;
78 mMilliseconds
= kUnresolvedMillis
;
81 bool IsResolved() const { return mState
!= STATE_UNRESOLVED
; }
84 mState
= STATE_UNRESOLVED
;
85 mMilliseconds
= kUnresolvedMillis
;
88 bool IsDefinite() const { return mState
== STATE_DEFINITE
; }
89 nsSMILTime
GetMillis() const
91 NS_ABORT_IF_FALSE(mState
== STATE_DEFINITE
,
92 "GetMillis() called for unresolved or indefinite time");
94 return mState
== STATE_DEFINITE
? mMilliseconds
: kUnresolvedMillis
;
97 void SetMillis(nsSMILTime aMillis
)
99 mState
= STATE_DEFINITE
;
100 mMilliseconds
= aMillis
;
103 int8_t CompareTo(const nsSMILTimeValue
& aOther
) const;
105 bool operator==(const nsSMILTimeValue
& aOther
) const
106 { return CompareTo(aOther
) == 0; }
108 bool operator!=(const nsSMILTimeValue
& aOther
) const
109 { return CompareTo(aOther
) != 0; }
111 bool operator<(const nsSMILTimeValue
& aOther
) const
112 { return CompareTo(aOther
) < 0; }
114 bool operator>(const nsSMILTimeValue
& aOther
) const
115 { return CompareTo(aOther
) > 0; }
117 bool operator<=(const nsSMILTimeValue
& aOther
) const
118 { return CompareTo(aOther
) <= 0; }
120 bool operator>=(const nsSMILTimeValue
& aOther
) const
121 { return CompareTo(aOther
) >= 0; }
124 static nsSMILTime kUnresolvedMillis
;
126 nsSMILTime mMilliseconds
;
134 #endif // NS_SMILTIMEVALUE_H_