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