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/. */
7 #include "SMILTimeValue.h"
8 #include "nsMathUtils.h"
12 const SMILTime
SMILTimeValue::kUnresolvedMillis
=
13 std::numeric_limits
<SMILTime
>::max();
15 //----------------------------------------------------------------------
16 // SMILTimeValue methods:
18 static inline int8_t Cmp(int64_t aA
, int64_t aB
) {
19 return aA
== aB
? 0 : (aA
> aB
? 1 : -1);
22 int8_t SMILTimeValue::CompareTo(const SMILTimeValue
& aOther
) const {
25 if (mState
== STATE_DEFINITE
) {
26 result
= (aOther
.mState
== STATE_DEFINITE
)
27 ? Cmp(mMilliseconds
, aOther
.mMilliseconds
)
29 } else if (mState
== STATE_INDEFINITE
) {
30 if (aOther
.mState
== STATE_DEFINITE
)
32 else if (aOther
.mState
== STATE_INDEFINITE
)
37 result
= (aOther
.mState
!= STATE_UNRESOLVED
) ? 1 : 0;
43 void SMILTimeValue::SetMillis(double aMillis
, Rounding aRounding
) {
44 mState
= STATE_DEFINITE
;
45 mMilliseconds
= NS_round(aMillis
);
46 if (aRounding
== Rounding::EnsureNonZero
&& !mMilliseconds
&& aMillis
) {
47 // Ensure we don't round small values to zero.
48 mMilliseconds
= std::copysign(1.0, aMillis
);
52 } // namespace mozilla