diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/smil/SMILTimeValue.h | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/smil/SMILTimeValue.h')
-rw-r--r-- | dom/smil/SMILTimeValue.h | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/dom/smil/SMILTimeValue.h b/dom/smil/SMILTimeValue.h new file mode 100644 index 0000000000..0fbe7d3b36 --- /dev/null +++ b/dom/smil/SMILTimeValue.h @@ -0,0 +1,131 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ + +#ifndef DOM_SMIL_SMILTIMEVALUE_H_ +#define DOM_SMIL_SMILTIMEVALUE_H_ + +#include "mozilla/SMILTypes.h" +#include "nsDebug.h" + +namespace mozilla { + +/*---------------------------------------------------------------------- + * SMILTimeValue class + * + * A tri-state time value. + * + * First a quick overview of the SMIL time data types: + * + * SMILTime -- a timestamp in milliseconds. + * 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. + * + * Objects of this class may be in one of three states: + * + * 1) The time is resolved and has a definite millisecond value + * 2) The time is resolved and indefinite + * 3) The time is unresolved + * + * In summary: + * + * State | GetMillis | IsDefinite | IsIndefinite | IsResolved + * -----------+---------------+------------+--------------+------------ + * Definite | SMILTimeValue | true | false | true + * -----------+---------------+------------+--------------+------------ + * Indefinite | -- | false | true | true + * -----------+---------------+------------+--------------+------------ + * Unresolved | -- | false | false | false + * + */ + +class SMILTimeValue { + public: + // Creates an unresolved time value + SMILTimeValue() + : mMilliseconds(kUnresolvedMillis), mState(STATE_UNRESOLVED) {} + + // Creates a resolved time value + explicit SMILTimeValue(SMILTime aMillis) + : mMilliseconds(aMillis), mState(STATE_DEFINITE) {} + + // Named constructor to create an indefinite time value + static SMILTimeValue Indefinite() { + SMILTimeValue value; + value.SetIndefinite(); + return value; + } + + bool IsIndefinite() const { return mState == STATE_INDEFINITE; } + void SetIndefinite() { + mState = STATE_INDEFINITE; + mMilliseconds = kUnresolvedMillis; + } + + bool IsResolved() const { return mState != STATE_UNRESOLVED; } + void SetUnresolved() { + mState = STATE_UNRESOLVED; + mMilliseconds = kUnresolvedMillis; + } + + bool IsDefinite() const { return mState == STATE_DEFINITE; } + SMILTime GetMillis() const { + MOZ_ASSERT(mState == STATE_DEFINITE, + "GetMillis() called for unresolved or indefinite time"); + + return mState == STATE_DEFINITE ? mMilliseconds : kUnresolvedMillis; + } + + void SetMillis(SMILTime aMillis) { + mState = STATE_DEFINITE; + mMilliseconds = aMillis; + } + + int8_t CompareTo(const SMILTimeValue& aOther) const; + + bool operator==(const SMILTimeValue& aOther) const { + return CompareTo(aOther) == 0; + } + + bool operator!=(const SMILTimeValue& aOther) const { + return CompareTo(aOther) != 0; + } + + bool operator<(const SMILTimeValue& aOther) const { + return CompareTo(aOther) < 0; + } + + bool operator>(const SMILTimeValue& aOther) const { + return CompareTo(aOther) > 0; + } + + bool operator<=(const SMILTimeValue& aOther) const { + return CompareTo(aOther) <= 0; + } + + bool operator>=(const SMILTimeValue& aOther) const { + return CompareTo(aOther) >= 0; + } + + private: + static const SMILTime kUnresolvedMillis; + + SMILTime mMilliseconds; + enum { STATE_DEFINITE, STATE_INDEFINITE, STATE_UNRESOLVED } mState; +}; + +} // namespace mozilla + +#endif // DOM_SMIL_SMILTIMEVALUE_H_ |