2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SMIL_SMILTIMEVALUE_H_
|
|
|
|
#define DOM_SMIL_SMILTIMEVALUE_H_
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2019-01-23 16:48:08 +03:00
|
|
|
#include "mozilla/SMILTypes.h"
|
2010-01-12 23:00:49 +03:00
|
|
|
#include "nsDebug.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
/*----------------------------------------------------------------------
|
2019-01-22 10:28:40 +03:00
|
|
|
* SMILTimeValue class
|
2009-01-15 07:38:07 +03:00
|
|
|
*
|
|
|
|
* A tri-state time value.
|
|
|
|
*
|
|
|
|
* First a quick overview of the SMIL time data types:
|
|
|
|
*
|
2019-01-25 06:24:01 +03:00
|
|
|
* SMILTime -- a timestamp in milliseconds.
|
2019-01-22 10:28:40 +03:00
|
|
|
* SMILTimeValue -- (this class) a timestamp that can take the additional
|
|
|
|
* states 'indefinite' and 'unresolved'
|
|
|
|
* SMILInstanceTime -- an SMILTimeValue used for constructing intervals. It
|
|
|
|
* contains additional fields to govern reset behavior
|
|
|
|
* and track timing dependencies (e.g. syncbase timing).
|
|
|
|
* SMILInterval -- a pair of SMILInstanceTimes that defines a begin and
|
|
|
|
* an end time for animation.
|
|
|
|
* SMILTimeValueSpec -- a component of a begin or end attribute, such as the
|
|
|
|
* '5s' or 'a.end+2m' in begin="5s; a.end+2m". Acts as
|
|
|
|
* a broker between an SMILTimedElement and its
|
|
|
|
* SMILInstanceTimes by generating new instance times
|
|
|
|
* and handling changes to existing times.
|
2009-01-15 07:38:07 +03:00
|
|
|
*
|
|
|
|
* Objects of this class may be in one of three states:
|
|
|
|
*
|
2011-09-07 04:20:40 +04:00
|
|
|
* 1) The time is resolved and has a definite millisecond value
|
|
|
|
* 2) The time is resolved and indefinite
|
|
|
|
* 3) The time is unresolved
|
2011-09-07 04:20:40 +04:00
|
|
|
*
|
|
|
|
* In summary:
|
|
|
|
*
|
2019-01-22 10:28:40 +03:00
|
|
|
* State | GetMillis | IsDefinite | IsIndefinite | IsResolved
|
|
|
|
* -----------+---------------+------------+--------------+------------
|
|
|
|
* Definite | SMILTimeValue | true | false | true
|
|
|
|
* -----------+---------------+------------+--------------+------------
|
|
|
|
* Indefinite | -- | false | true | true
|
|
|
|
* -----------+---------------+------------+--------------+------------
|
|
|
|
* Unresolved | -- | false | false | false
|
2011-09-07 04:20:40 +04:00
|
|
|
*
|
2009-01-15 07:38:07 +03:00
|
|
|
*/
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
class SMILTimeValue {
|
2009-01-15 07:38:07 +03:00
|
|
|
public:
|
|
|
|
// Creates an unresolved time value
|
2019-01-22 10:28:40 +03:00
|
|
|
SMILTimeValue()
|
2010-01-12 23:00:49 +03:00
|
|
|
: mMilliseconds(kUnresolvedMillis), mState(STATE_UNRESOLVED) {}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
// Creates a resolved time value
|
2019-01-25 06:24:01 +03:00
|
|
|
explicit SMILTimeValue(SMILTime aMillis)
|
2010-01-12 23:00:49 +03:00
|
|
|
: mMilliseconds(aMillis), mState(STATE_DEFINITE) {}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
// Named constructor to create an indefinite time value
|
2019-01-22 10:28:40 +03:00
|
|
|
static SMILTimeValue Indefinite() {
|
|
|
|
SMILTimeValue value;
|
2010-01-12 23:00:49 +03:00
|
|
|
value.SetIndefinite();
|
|
|
|
return value;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsIndefinite() const { return mState == STATE_INDEFINITE; }
|
2010-01-12 23:00:49 +03:00
|
|
|
void SetIndefinite() {
|
|
|
|
mState = STATE_INDEFINITE;
|
|
|
|
mMilliseconds = kUnresolvedMillis;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsResolved() const { return mState != STATE_UNRESOLVED; }
|
2010-01-12 23:00:49 +03:00
|
|
|
void SetUnresolved() {
|
|
|
|
mState = STATE_UNRESOLVED;
|
|
|
|
mMilliseconds = kUnresolvedMillis;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsDefinite() const { return mState == STATE_DEFINITE; }
|
2019-01-25 06:24:01 +03:00
|
|
|
SMILTime GetMillis() const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mState == STATE_DEFINITE,
|
|
|
|
"GetMillis() called for unresolved or indefinite time");
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2011-09-07 04:20:40 +04:00
|
|
|
return mState == STATE_DEFINITE ? mMilliseconds : kUnresolvedMillis;
|
2010-01-12 23:00:49 +03:00
|
|
|
}
|
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
void SetMillis(SMILTime aMillis) {
|
2011-09-07 04:20:40 +04:00
|
|
|
mState = STATE_DEFINITE;
|
2010-01-12 23:00:49 +03:00
|
|
|
mMilliseconds = aMillis;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
int8_t CompareTo(const SMILTimeValue& aOther) const;
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
bool operator==(const SMILTimeValue& aOther) const {
|
2010-01-12 23:00:49 +03:00
|
|
|
return CompareTo(aOther) == 0;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
bool operator!=(const SMILTimeValue& aOther) const {
|
2010-01-12 23:00:49 +03:00
|
|
|
return CompareTo(aOther) != 0;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
bool operator<(const SMILTimeValue& aOther) const {
|
2010-01-12 23:00:49 +03:00
|
|
|
return CompareTo(aOther) < 0;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
bool operator>(const SMILTimeValue& aOther) const {
|
2010-01-12 23:00:49 +03:00
|
|
|
return CompareTo(aOther) > 0;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
bool operator<=(const SMILTimeValue& aOther) const {
|
2010-01-12 23:00:49 +03:00
|
|
|
return CompareTo(aOther) <= 0;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
bool operator>=(const SMILTimeValue& aOther) const {
|
2010-01-12 23:00:49 +03:00
|
|
|
return CompareTo(aOther) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-01-25 06:24:01 +03:00
|
|
|
static const SMILTime kUnresolvedMillis;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2019-01-25 06:24:01 +03:00
|
|
|
SMILTime mMilliseconds;
|
2009-01-15 07:38:07 +03:00
|
|
|
enum { STATE_DEFINITE, STATE_INDEFINITE, STATE_UNRESOLVED } mState;
|
|
|
|
};
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SMIL_SMILTIMEVALUE_H_
|