dom/smil/nsSMILTimeValue.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial