1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "SMILStringType.h"
7 #include "nsSMILValue.h"
14 SMILStringType::Init(nsSMILValue
& aValue
) const
16 NS_PRECONDITION(aValue
.IsNull(), "Unexpected value type");
17 aValue
.mU
.mPtr
= new nsString();
22 SMILStringType::Destroy(nsSMILValue
& aValue
) const
24 NS_PRECONDITION(aValue
.mType
== this, "Unexpected SMIL value");
25 delete static_cast<nsAString
*>(aValue
.mU
.mPtr
);
26 aValue
.mU
.mPtr
= nullptr;
27 aValue
.mType
= nsSMILNullType::Singleton();
31 SMILStringType::Assign(nsSMILValue
& aDest
, const nsSMILValue
& aSrc
) const
33 NS_PRECONDITION(aDest
.mType
== aSrc
.mType
, "Incompatible SMIL types");
34 NS_PRECONDITION(aDest
.mType
== this, "Unexpected SMIL value");
36 const nsAString
* src
= static_cast<const nsAString
*>(aSrc
.mU
.mPtr
);
37 nsAString
* dst
= static_cast<nsAString
*>(aDest
.mU
.mPtr
);
43 SMILStringType::IsEqual(const nsSMILValue
& aLeft
,
44 const nsSMILValue
& aRight
) const
46 NS_PRECONDITION(aLeft
.mType
== aRight
.mType
, "Incompatible SMIL types");
47 NS_PRECONDITION(aLeft
.mType
== this, "Unexpected type for SMIL value");
49 const nsAString
* leftString
=
50 static_cast<const nsAString
*>(aLeft
.mU
.mPtr
);
51 const nsAString
* rightString
=
52 static_cast<nsAString
*>(aRight
.mU
.mPtr
);
53 return *leftString
== *rightString
;
57 SMILStringType::Add(nsSMILValue
& aDest
, const nsSMILValue
& aValueToAdd
,
58 uint32_t aCount
) const
60 NS_PRECONDITION(aValueToAdd
.mType
== aDest
.mType
,
61 "Trying to add invalid types");
62 NS_PRECONDITION(aValueToAdd
.mType
== this, "Unexpected source type");
63 return NS_ERROR_FAILURE
; // string values can't be added to each other
67 SMILStringType::ComputeDistance(const nsSMILValue
& aFrom
,
68 const nsSMILValue
& aTo
,
69 double& aDistance
) const
71 NS_PRECONDITION(aFrom
.mType
== aTo
.mType
,"Trying to compare different types");
72 NS_PRECONDITION(aFrom
.mType
== this, "Unexpected source type");
73 return NS_ERROR_FAILURE
; // there is no concept of distance between string values
77 SMILStringType::Interpolate(const nsSMILValue
& aStartVal
,
78 const nsSMILValue
& aEndVal
,
80 nsSMILValue
& aResult
) const
82 NS_PRECONDITION(aStartVal
.mType
== aEndVal
.mType
,
83 "Trying to interpolate different types");
84 NS_PRECONDITION(aStartVal
.mType
== this,
85 "Unexpected types for interpolation");
86 NS_PRECONDITION(aResult
.mType
== this, "Unexpected result type");
87 return NS_ERROR_FAILURE
; // string values do not interpolate
90 } // namespace mozilla