no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / smil / SMILTimeValue.h
blob19fd67b53613e16a07b59c94aff240ae11d661cd
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/. */
7 #ifndef DOM_SMIL_SMILTIMEVALUE_H_
8 #define DOM_SMIL_SMILTIMEVALUE_H_
10 #include "mozilla/SMILTypes.h"
11 #include "nsDebug.h"
13 namespace mozilla {
15 /*----------------------------------------------------------------------
16 * SMILTimeValue class
18 * A tri-state time value.
20 * First a quick overview of the SMIL time data types:
22 * SMILTime -- a timestamp in milliseconds.
23 * SMILTimeValue -- (this class) a timestamp that can take the additional
24 * states 'indefinite' and 'unresolved'
25 * SMILInstanceTime -- an SMILTimeValue used for constructing intervals. It
26 * contains additional fields to govern reset behavior
27 * and track timing dependencies (e.g. syncbase timing).
28 * SMILInterval -- a pair of SMILInstanceTimes that defines a begin and
29 * an end time for animation.
30 * SMILTimeValueSpec -- a component of a begin or end attribute, such as the
31 * '5s' or 'a.end+2m' in begin="5s; a.end+2m". Acts as
32 * a broker between an SMILTimedElement and its
33 * SMILInstanceTimes by generating new instance times
34 * and handling changes to existing times.
36 * Objects of this class may be in one of three states:
38 * 1) The time is resolved and has a definite millisecond value
39 * 2) The time is resolved and indefinite
40 * 3) The time is unresolved
42 * In summary:
44 * State | GetMillis | IsDefinite | IsIndefinite | IsResolved
45 * -----------+---------------+------------+--------------+------------
46 * Definite | SMILTimeValue | true | false | true
47 * -----------+---------------+------------+--------------+------------
48 * Indefinite | -- | false | true | true
49 * -----------+---------------+------------+--------------+------------
50 * Unresolved | -- | false | false | false
54 class SMILTimeValue {
55 public:
56 // Creates an unresolved time value
57 SMILTimeValue()
58 : mMilliseconds(kUnresolvedMillis), mState(STATE_UNRESOLVED) {}
60 // Creates a resolved time value
61 explicit SMILTimeValue(SMILTime aMillis)
62 : mMilliseconds(aMillis), mState(STATE_DEFINITE) {}
64 // Named constructor to create an indefinite time value
65 static SMILTimeValue Indefinite() {
66 SMILTimeValue value;
67 value.SetIndefinite();
68 return value;
71 static SMILTimeValue Zero() { return SMILTimeValue(SMILTime(0L)); }
73 bool IsIndefinite() const { return mState == STATE_INDEFINITE; }
74 void SetIndefinite() {
75 mState = STATE_INDEFINITE;
76 mMilliseconds = kUnresolvedMillis;
79 bool IsResolved() const { return mState != STATE_UNRESOLVED; }
80 void SetUnresolved() {
81 mState = STATE_UNRESOLVED;
82 mMilliseconds = kUnresolvedMillis;
85 bool IsDefinite() const { return mState == STATE_DEFINITE; }
86 SMILTime GetMillis() const {
87 MOZ_ASSERT(mState == STATE_DEFINITE,
88 "GetMillis() called for unresolved or indefinite time");
90 return mState == STATE_DEFINITE ? mMilliseconds : kUnresolvedMillis;
93 bool IsZero() const {
94 return mState == STATE_DEFINITE ? mMilliseconds == 0 : false;
97 void SetMillis(SMILTime aMillis) {
98 mState = STATE_DEFINITE;
99 mMilliseconds = aMillis;
103 * EnsureNonZero ensures values such as 0.0001s are not represented as 0
104 * for values where 0 is invalid.
106 enum class Rounding : uint8_t { EnsureNonZero, Nearest };
108 void SetMillis(double aMillis, Rounding aRounding);
110 int8_t CompareTo(const SMILTimeValue& aOther) const;
112 bool operator==(const SMILTimeValue& aOther) const {
113 return CompareTo(aOther) == 0;
116 bool operator!=(const SMILTimeValue& aOther) const {
117 return CompareTo(aOther) != 0;
120 bool operator<(const SMILTimeValue& aOther) const {
121 return CompareTo(aOther) < 0;
124 bool operator>(const SMILTimeValue& aOther) const {
125 return CompareTo(aOther) > 0;
128 bool operator<=(const SMILTimeValue& aOther) const {
129 return CompareTo(aOther) <= 0;
132 bool operator>=(const SMILTimeValue& aOther) const {
133 return CompareTo(aOther) >= 0;
136 private:
137 static const SMILTime kUnresolvedMillis;
139 SMILTime mMilliseconds;
140 enum { STATE_DEFINITE, STATE_INDEFINITE, STATE_UNRESOLVED } mState;
143 } // namespace mozilla
145 #endif // DOM_SMIL_SMILTIMEVALUE_H_