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/. */
7 #include "SMILStringType.h"
9 #include "mozilla/SMILValue.h"
15 void SMILStringType::Init(SMILValue
& aValue
) const {
16 MOZ_ASSERT(aValue
.IsNull(), "Unexpected value type");
17 aValue
.mU
.mPtr
= new nsString();
21 void SMILStringType::Destroy(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();
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");
32 const nsAString
* src
= static_cast<const nsAString
*>(aSrc
.mU
.mPtr
);
33 nsAString
* dst
= static_cast<nsAString
*>(aDest
.mU
.mPtr
);
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");
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
;
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
55 nsresult
SMILStringType::ComputeDistance(const SMILValue
& aFrom
,
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
64 nsresult
SMILStringType::Interpolate(const SMILValue
& aStartVal
,
65 const SMILValue
& aEndVal
,
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
75 } // namespace mozilla