1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is the Mozilla SMIL module.
16 : *
17 : * The Initial Developer of the Original Code is Brian Birtles.
18 : * Portions created by the Initial Developer are Copyright (C) 2005
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Brian Birtles <birtles@gmail.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef NS_SMILTIMEVALUE_H_
39 : #define NS_SMILTIMEVALUE_H_
40 :
41 : #include "prtypes.h"
42 : #include "prlong.h"
43 : #include "nsSMILTypes.h"
44 : #include "nsDebug.h"
45 :
46 : /*----------------------------------------------------------------------
47 : * nsSMILTimeValue class
48 : *
49 : * A tri-state time value.
50 : *
51 : * First a quick overview of the SMIL time data types:
52 : *
53 : * nsSMILTime -- a timestamp in milliseconds.
54 : * nsSMILTimeValue -- (this class) a timestamp that can take the additional
55 : * states 'indefinite' and 'unresolved'
56 : * nsSMILInstanceTime -- an nsSMILTimeValue used for constructing intervals. It
57 : * contains additional fields to govern reset behavior
58 : * and track timing dependencies (e.g. syncbase timing).
59 : * nsSMILInterval -- a pair of nsSMILInstanceTimes that defines a begin and
60 : * an end time for animation.
61 : * nsSMILTimeValueSpec -- a component of a begin or end attribute, such as the
62 : * '5s' or 'a.end+2m' in begin="5s; a.end+2m". Acts as
63 : * a broker between an nsSMILTimedElement and its
64 : * nsSMILInstanceTimes by generating new instance times
65 : * and handling changes to existing times.
66 : *
67 : * Objects of this class may be in one of three states:
68 : *
69 : * 1) The time is resolved and has a definite millisecond value
70 : * 2) The time is resolved and indefinite
71 : * 3) The time is unresolved
72 : *
73 : * In summary:
74 : *
75 : * State | GetMillis | IsDefinite | IsIndefinite | IsResolved
76 : * -----------+-----------------+------------+--------------+------------
77 : * Definite | nsSMILTimeValue | true | false | true
78 : * -----------+-----------------+------------+--------------+------------
79 : * Indefinite | -- | false | true | true
80 : * -----------+-----------------+------------+--------------+------------
81 : * Unresolved | -- | false | false | false
82 : *
83 : */
84 :
85 : class nsSMILTimeValue
86 : {
87 : public:
88 : // Creates an unresolved time value
89 0 : nsSMILTimeValue()
90 : : mMilliseconds(kUnresolvedMillis),
91 0 : mState(STATE_UNRESOLVED)
92 0 : { }
93 :
94 : // Creates a resolved time value
95 0 : explicit nsSMILTimeValue(nsSMILTime aMillis)
96 : : mMilliseconds(aMillis),
97 0 : mState(STATE_DEFINITE)
98 0 : { }
99 :
100 : // Named constructor to create an indefinite time value
101 0 : static nsSMILTimeValue Indefinite()
102 : {
103 0 : nsSMILTimeValue value;
104 0 : value.SetIndefinite();
105 : return value;
106 : }
107 :
108 0 : bool IsIndefinite() const { return mState == STATE_INDEFINITE; }
109 0 : void SetIndefinite()
110 : {
111 0 : mState = STATE_INDEFINITE;
112 0 : mMilliseconds = kUnresolvedMillis;
113 0 : }
114 :
115 0 : bool IsResolved() const { return mState != STATE_UNRESOLVED; }
116 0 : void SetUnresolved()
117 : {
118 0 : mState = STATE_UNRESOLVED;
119 0 : mMilliseconds = kUnresolvedMillis;
120 0 : }
121 :
122 0 : bool IsDefinite() const { return mState == STATE_DEFINITE; }
123 0 : nsSMILTime GetMillis() const
124 : {
125 0 : NS_ABORT_IF_FALSE(mState == STATE_DEFINITE,
126 : "GetMillis() called for unresolved or indefinite time");
127 :
128 0 : return mState == STATE_DEFINITE ? mMilliseconds : kUnresolvedMillis;
129 : }
130 :
131 0 : void SetMillis(nsSMILTime aMillis)
132 : {
133 0 : mState = STATE_DEFINITE;
134 0 : mMilliseconds = aMillis;
135 0 : }
136 :
137 : PRInt8 CompareTo(const nsSMILTimeValue& aOther) const;
138 :
139 0 : bool operator==(const nsSMILTimeValue& aOther) const
140 0 : { return CompareTo(aOther) == 0; }
141 :
142 0 : bool operator!=(const nsSMILTimeValue& aOther) const
143 0 : { return CompareTo(aOther) != 0; }
144 :
145 0 : bool operator<(const nsSMILTimeValue& aOther) const
146 0 : { return CompareTo(aOther) < 0; }
147 :
148 0 : bool operator>(const nsSMILTimeValue& aOther) const
149 0 : { return CompareTo(aOther) > 0; }
150 :
151 0 : bool operator<=(const nsSMILTimeValue& aOther) const
152 0 : { return CompareTo(aOther) <= 0; }
153 :
154 0 : bool operator>=(const nsSMILTimeValue& aOther) const
155 0 : { return CompareTo(aOther) >= 0; }
156 :
157 : private:
158 : static nsSMILTime kUnresolvedMillis;
159 :
160 : nsSMILTime mMilliseconds;
161 : enum {
162 : STATE_DEFINITE,
163 : STATE_INDEFINITE,
164 : STATE_UNRESOLVED
165 : } mState;
166 : };
167 :
168 : #endif // NS_SMILTIMEVALUE_H_
|