SMILEnumType.cpp (2724B)
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 "SMILEnumType.h" 8 9 #include <math.h> 10 11 #include "mozilla/SMILValue.h" 12 #include "nsDebug.h" 13 14 namespace mozilla { 15 16 void SMILEnumType::InitValue(SMILValue& aValue) const { 17 MOZ_ASSERT(aValue.IsNull(), "Unexpected value type"); 18 aValue.mU.mUint = 0; 19 aValue.mType = this; 20 } 21 22 void SMILEnumType::DestroyValue(SMILValue& aValue) const { 23 MOZ_ASSERT(aValue.mType == this, "Unexpected SMIL value"); 24 aValue.mU.mUint = 0; 25 aValue.mType = SMILNullType::Singleton(); 26 } 27 28 nsresult SMILEnumType::Assign(SMILValue& aDest, const SMILValue& aSrc) const { 29 MOZ_ASSERT(aDest.mType == aSrc.mType, "Incompatible SMIL types"); 30 MOZ_ASSERT(aDest.mType == this, "Unexpected SMIL value"); 31 aDest.mU.mUint = aSrc.mU.mUint; 32 return NS_OK; 33 } 34 35 bool SMILEnumType::IsEqual(const SMILValue& aLeft, 36 const SMILValue& aRight) const { 37 MOZ_ASSERT(aLeft.mType == aRight.mType, "Incompatible SMIL types"); 38 MOZ_ASSERT(aLeft.mType == this, "Unexpected type for SMIL value"); 39 40 return aLeft.mU.mUint == aRight.mU.mUint; 41 } 42 43 nsresult SMILEnumType::Add(SMILValue& aDest, const SMILValue& aValueToAdd, 44 uint32_t aCount) const { 45 MOZ_ASSERT(aValueToAdd.mType == aDest.mType, "Trying to add invalid types"); 46 MOZ_ASSERT(aValueToAdd.mType == this, "Unexpected source type"); 47 return NS_ERROR_FAILURE; // enum values can't be added to each other 48 } 49 50 nsresult SMILEnumType::ComputeDistance(const SMILValue& aFrom, 51 const SMILValue& aTo, 52 double& aDistance) const { 53 MOZ_ASSERT(aFrom.mType == aTo.mType, "Trying to compare different types"); 54 MOZ_ASSERT(aFrom.mType == this, "Unexpected source type"); 55 return NS_ERROR_FAILURE; // there is no concept of distance between enum 56 // values 57 } 58 59 nsresult SMILEnumType::Interpolate(const SMILValue& aStartVal, 60 const SMILValue& aEndVal, 61 double aUnitDistance, 62 SMILValue& aResult) const { 63 MOZ_ASSERT(aStartVal.mType == aEndVal.mType, 64 "Trying to interpolate different types"); 65 MOZ_ASSERT(aStartVal.mType == this, "Unexpected types for interpolation"); 66 MOZ_ASSERT(aResult.mType == this, "Unexpected result type"); 67 return NS_ERROR_FAILURE; // enum values do not interpolate 68 } 69 70 } // namespace mozilla