/src/mozilla-central/dom/smil/nsSMILTimeValue.h
Line | Count | Source (jump to first uncovered line) |
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 NS_SMILTIMEVALUE_H_ |
8 | | #define NS_SMILTIMEVALUE_H_ |
9 | | |
10 | | #include "nsSMILTypes.h" |
11 | | #include "nsDebug.h" |
12 | | |
13 | | /*---------------------------------------------------------------------- |
14 | | * nsSMILTimeValue class |
15 | | * |
16 | | * A tri-state time value. |
17 | | * |
18 | | * First a quick overview of the SMIL time data types: |
19 | | * |
20 | | * nsSMILTime -- a timestamp in milliseconds. |
21 | | * nsSMILTimeValue -- (this class) a timestamp that can take the additional |
22 | | * states 'indefinite' and 'unresolved' |
23 | | * nsSMILInstanceTime -- an nsSMILTimeValue used for constructing intervals. It |
24 | | * contains additional fields to govern reset behavior |
25 | | * and track timing dependencies (e.g. syncbase timing). |
26 | | * nsSMILInterval -- a pair of nsSMILInstanceTimes that defines a begin and |
27 | | * an end time for animation. |
28 | | * nsSMILTimeValueSpec -- a component of a begin or end attribute, such as the |
29 | | * '5s' or 'a.end+2m' in begin="5s; a.end+2m". Acts as |
30 | | * a broker between an nsSMILTimedElement and its |
31 | | * nsSMILInstanceTimes by generating new instance times |
32 | | * and handling changes to existing times. |
33 | | * |
34 | | * Objects of this class may be in one of three states: |
35 | | * |
36 | | * 1) The time is resolved and has a definite millisecond value |
37 | | * 2) The time is resolved and indefinite |
38 | | * 3) The time is unresolved |
39 | | * |
40 | | * In summary: |
41 | | * |
42 | | * State | GetMillis | IsDefinite | IsIndefinite | IsResolved |
43 | | * -----------+-----------------+------------+--------------+------------ |
44 | | * Definite | nsSMILTimeValue | true | false | true |
45 | | * -----------+-----------------+------------+--------------+------------ |
46 | | * Indefinite | -- | false | true | true |
47 | | * -----------+-----------------+------------+--------------+------------ |
48 | | * Unresolved | -- | false | false | false |
49 | | * |
50 | | */ |
51 | | |
52 | | class nsSMILTimeValue |
53 | | { |
54 | | public: |
55 | | // Creates an unresolved time value |
56 | | nsSMILTimeValue() |
57 | | : mMilliseconds(kUnresolvedMillis), |
58 | | mState(STATE_UNRESOLVED) |
59 | 0 | { } |
60 | | |
61 | | // Creates a resolved time value |
62 | | explicit nsSMILTimeValue(nsSMILTime aMillis) |
63 | | : mMilliseconds(aMillis), |
64 | | mState(STATE_DEFINITE) |
65 | 0 | { } |
66 | | |
67 | | // Named constructor to create an indefinite time value |
68 | | static nsSMILTimeValue Indefinite() |
69 | 0 | { |
70 | 0 | nsSMILTimeValue value; |
71 | 0 | value.SetIndefinite(); |
72 | 0 | return value; |
73 | 0 | } |
74 | | |
75 | 0 | bool IsIndefinite() const { return mState == STATE_INDEFINITE; } |
76 | | void SetIndefinite() |
77 | 0 | { |
78 | 0 | mState = STATE_INDEFINITE; |
79 | 0 | mMilliseconds = kUnresolvedMillis; |
80 | 0 | } |
81 | | |
82 | 0 | bool IsResolved() const { return mState != STATE_UNRESOLVED; } |
83 | | void SetUnresolved() |
84 | 0 | { |
85 | 0 | mState = STATE_UNRESOLVED; |
86 | 0 | mMilliseconds = kUnresolvedMillis; |
87 | 0 | } |
88 | | |
89 | 0 | bool IsDefinite() const { return mState == STATE_DEFINITE; } |
90 | | nsSMILTime GetMillis() const |
91 | 0 | { |
92 | 0 | MOZ_ASSERT(mState == STATE_DEFINITE, |
93 | 0 | "GetMillis() called for unresolved or indefinite time"); |
94 | 0 |
|
95 | 0 | return mState == STATE_DEFINITE ? mMilliseconds : kUnresolvedMillis; |
96 | 0 | } |
97 | | |
98 | | void SetMillis(nsSMILTime aMillis) |
99 | 0 | { |
100 | 0 | mState = STATE_DEFINITE; |
101 | 0 | mMilliseconds = aMillis; |
102 | 0 | } |
103 | | |
104 | | int8_t CompareTo(const nsSMILTimeValue& aOther) const; |
105 | | |
106 | | bool operator==(const nsSMILTimeValue& aOther) const |
107 | 0 | { return CompareTo(aOther) == 0; } |
108 | | |
109 | | bool operator!=(const nsSMILTimeValue& aOther) const |
110 | 0 | { return CompareTo(aOther) != 0; } |
111 | | |
112 | | bool operator<(const nsSMILTimeValue& aOther) const |
113 | 0 | { return CompareTo(aOther) < 0; } |
114 | | |
115 | | bool operator>(const nsSMILTimeValue& aOther) const |
116 | 0 | { return CompareTo(aOther) > 0; } |
117 | | |
118 | | bool operator<=(const nsSMILTimeValue& aOther) const |
119 | 0 | { return CompareTo(aOther) <= 0; } |
120 | | |
121 | | bool operator>=(const nsSMILTimeValue& aOther) const |
122 | 0 | { return CompareTo(aOther) >= 0; } |
123 | | |
124 | | private: |
125 | | static const nsSMILTime kUnresolvedMillis; |
126 | | |
127 | | nsSMILTime mMilliseconds; |
128 | | enum { |
129 | | STATE_DEFINITE, |
130 | | STATE_INDEFINITE, |
131 | | STATE_UNRESOLVED |
132 | | } mState; |
133 | | }; |
134 | | |
135 | | #endif // NS_SMILTIMEVALUE_H_ |