SMILTimeValue.cpp (1572B)
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/. */ 6 7 #include "SMILTimeValue.h" 8 9 #include "nsMathUtils.h" 10 11 namespace mozilla { 12 13 const SMILTime SMILTimeValue::kUnresolvedMillis = 14 std::numeric_limits<SMILTime>::max(); 15 16 //---------------------------------------------------------------------- 17 // SMILTimeValue methods: 18 19 static inline int8_t Cmp(int64_t aA, int64_t aB) { 20 return aA == aB ? 0 : (aA > aB ? 1 : -1); 21 } 22 23 int8_t SMILTimeValue::CompareTo(const SMILTimeValue& aOther) const { 24 int8_t result; 25 26 if (mState == STATE_DEFINITE) { 27 result = (aOther.mState == STATE_DEFINITE) 28 ? Cmp(mMilliseconds, aOther.mMilliseconds) 29 : -1; 30 } else if (mState == STATE_INDEFINITE) { 31 if (aOther.mState == STATE_DEFINITE) 32 result = 1; 33 else if (aOther.mState == STATE_INDEFINITE) 34 result = 0; 35 else 36 result = -1; 37 } else { 38 result = (aOther.mState != STATE_UNRESOLVED) ? 1 : 0; 39 } 40 41 return result; 42 } 43 44 void SMILTimeValue::SetMillis(double aMillis, Rounding aRounding) { 45 mState = STATE_DEFINITE; 46 mMilliseconds = NS_round(aMillis); 47 if (aRounding == Rounding::EnsureNonZero && !mMilliseconds && aMillis) { 48 // Ensure we don't round small values to zero. 49 mMilliseconds = std::copysign(1.0, aMillis); 50 } 51 } 52 53 } // namespace mozilla