1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/nsSMILFloatType.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsSMILFloatType.h" 1.10 +#include "nsSMILValue.h" 1.11 +#include "nsDebug.h" 1.12 +#include <math.h> 1.13 + 1.14 +void 1.15 +nsSMILFloatType::Init(nsSMILValue& aValue) const 1.16 +{ 1.17 + NS_PRECONDITION(aValue.IsNull(), "Unexpected value type"); 1.18 + aValue.mU.mDouble = 0.0; 1.19 + aValue.mType = this; 1.20 +} 1.21 + 1.22 +void 1.23 +nsSMILFloatType::Destroy(nsSMILValue& aValue) const 1.24 +{ 1.25 + NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); 1.26 + aValue.mU.mDouble = 0.0; 1.27 + aValue.mType = nsSMILNullType::Singleton(); 1.28 +} 1.29 + 1.30 +nsresult 1.31 +nsSMILFloatType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const 1.32 +{ 1.33 + NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types"); 1.34 + NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value"); 1.35 + aDest.mU.mDouble = aSrc.mU.mDouble; 1.36 + return NS_OK; 1.37 +} 1.38 + 1.39 +bool 1.40 +nsSMILFloatType::IsEqual(const nsSMILValue& aLeft, 1.41 + const nsSMILValue& aRight) const 1.42 +{ 1.43 + NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types"); 1.44 + NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value"); 1.45 + 1.46 + return aLeft.mU.mDouble == aRight.mU.mDouble; 1.47 +} 1.48 + 1.49 +nsresult 1.50 +nsSMILFloatType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd, 1.51 + uint32_t aCount) const 1.52 +{ 1.53 + NS_PRECONDITION(aValueToAdd.mType == aDest.mType, 1.54 + "Trying to add invalid types"); 1.55 + NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type"); 1.56 + aDest.mU.mDouble += aValueToAdd.mU.mDouble * aCount; 1.57 + return NS_OK; 1.58 +} 1.59 + 1.60 +nsresult 1.61 +nsSMILFloatType::ComputeDistance(const nsSMILValue& aFrom, 1.62 + const nsSMILValue& aTo, 1.63 + double& aDistance) const 1.64 +{ 1.65 + NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types"); 1.66 + NS_PRECONDITION(aFrom.mType == this, "Unexpected source type"); 1.67 + 1.68 + const double &from = aFrom.mU.mDouble; 1.69 + const double &to = aTo.mU.mDouble; 1.70 + 1.71 + aDistance = fabs(to - from); 1.72 + 1.73 + return NS_OK; 1.74 +} 1.75 + 1.76 +nsresult 1.77 +nsSMILFloatType::Interpolate(const nsSMILValue& aStartVal, 1.78 + const nsSMILValue& aEndVal, 1.79 + double aUnitDistance, 1.80 + nsSMILValue& aResult) const 1.81 +{ 1.82 + NS_PRECONDITION(aStartVal.mType == aEndVal.mType, 1.83 + "Trying to interpolate different types"); 1.84 + NS_PRECONDITION(aStartVal.mType == this, 1.85 + "Unexpected types for interpolation"); 1.86 + NS_PRECONDITION(aResult.mType == this, "Unexpected result type"); 1.87 + 1.88 + const double &startVal = aStartVal.mU.mDouble; 1.89 + const double &endVal = aEndVal.mU.mDouble; 1.90 + 1.91 + aResult.mU.mDouble = (startVal + (endVal - startVal) * aUnitDistance); 1.92 + 1.93 + return NS_OK; 1.94 +}