Bug 1889091 - Part 6: Remove "scratch" register parameter from emitPushArguments...
[gecko.git] / dom / smil / SMILTimeValue.cpp
blob67676a329f949177b2f19c69f8d7f486fc80a779
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"
10 namespace mozilla {
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 {
23 int8_t result;
25 if (mState == STATE_DEFINITE) {
26 result = (aOther.mState == STATE_DEFINITE)
27 ? Cmp(mMilliseconds, aOther.mMilliseconds)
28 : -1;
29 } else if (mState == STATE_INDEFINITE) {
30 if (aOther.mState == STATE_DEFINITE)
31 result = 1;
32 else if (aOther.mState == STATE_INDEFINITE)
33 result = 0;
34 else
35 result = -1;
36 } else {
37 result = (aOther.mState != STATE_UNRESOLVED) ? 1 : 0;
40 return result;
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