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 "SVGPathSegListSMILType.h"
9 #include "mozilla/DebugOnly.h"
10 #include "mozilla/SMILValue.h"
11 #include "SVGPathData.h"
12 #include "SVGPathSegUtils.h"
16 //----------------------------------------------------------------------
17 // nsISMILType implementation
19 void SVGPathSegListSMILType::Init(SMILValue
& aValue
) const {
20 MOZ_ASSERT(aValue
.IsNull(), "Unexpected value type");
21 aValue
.mU
.mPtr
= new SVGPathDataAndInfo();
25 void SVGPathSegListSMILType::Destroy(SMILValue
& aValue
) const {
26 MOZ_ASSERT(aValue
.mType
== this, "Unexpected SMIL value type");
27 delete static_cast<SVGPathDataAndInfo
*>(aValue
.mU
.mPtr
);
28 aValue
.mU
.mPtr
= nullptr;
29 aValue
.mType
= SMILNullType::Singleton();
32 nsresult
SVGPathSegListSMILType::Assign(SMILValue
& aDest
,
33 const SMILValue
& aSrc
) const {
34 MOZ_ASSERT(aDest
.mType
== aSrc
.mType
, "Incompatible SMIL types");
35 MOZ_ASSERT(aDest
.mType
== this, "Unexpected SMIL value");
37 const SVGPathDataAndInfo
* src
=
38 static_cast<const SVGPathDataAndInfo
*>(aSrc
.mU
.mPtr
);
39 SVGPathDataAndInfo
* dest
= static_cast<SVGPathDataAndInfo
*>(aDest
.mU
.mPtr
);
44 bool SVGPathSegListSMILType::IsEqual(const SMILValue
& aLeft
,
45 const SMILValue
& aRight
) const {
46 MOZ_ASSERT(aLeft
.mType
== aRight
.mType
, "Incompatible SMIL types");
47 MOZ_ASSERT(aLeft
.mType
== this, "Unexpected type for SMIL value");
49 return *static_cast<const SVGPathDataAndInfo
*>(aLeft
.mU
.mPtr
) ==
50 *static_cast<const SVGPathDataAndInfo
*>(aRight
.mU
.mPtr
);
53 nsresult
SVGPathSegListSMILType::Add(SMILValue
& aDest
,
54 const SMILValue
& aValueToAdd
,
55 uint32_t aCount
) const {
56 MOZ_ASSERT(aDest
.mType
== this, "Unexpected SMIL type");
57 MOZ_ASSERT(aValueToAdd
.mType
== this, "Incompatible SMIL type");
59 SVGPathDataAndInfo
& dest
= *static_cast<SVGPathDataAndInfo
*>(aDest
.mU
.mPtr
);
60 const SVGPathDataAndInfo
& valueToAdd
=
61 *static_cast<const SVGPathDataAndInfo
*>(aValueToAdd
.mU
.mPtr
);
63 if (valueToAdd
.IsIdentity()) { // Adding identity value - no-op
67 if (dest
.IsIdentity()) {
68 dest
.CopyFrom(valueToAdd
);
73 !Servo_SVGPathData_Add(&dest
.RawData(), &valueToAdd
.RawData(), aCount
)) {
74 // SVGContentUtils::ReportToConsole - can't add path segment lists with
75 // different numbers of segments, with arcs that have different flag
76 // values, or with incompatible segment types.
77 return NS_ERROR_FAILURE
;
82 nsresult
SVGPathSegListSMILType::ComputeDistance(const SMILValue
& aFrom
,
84 double& aDistance
) const {
85 MOZ_ASSERT(aFrom
.mType
== this, "Unexpected SMIL type");
86 MOZ_ASSERT(aTo
.mType
== this, "Incompatible SMIL type");
88 // See https://bugzilla.mozilla.org/show_bug.cgi?id=522306#c18
90 // SVGContentUtils::ReportToConsole
91 return NS_ERROR_NOT_IMPLEMENTED
;
94 nsresult
SVGPathSegListSMILType::Interpolate(const SMILValue
& aStartVal
,
95 const SMILValue
& aEndVal
,
97 SMILValue
& aResult
) const {
98 MOZ_ASSERT(aStartVal
.mType
== aEndVal
.mType
,
99 "Trying to interpolate different types");
100 MOZ_ASSERT(aStartVal
.mType
== this, "Unexpected types for interpolation");
101 MOZ_ASSERT(aResult
.mType
== this, "Unexpected result type");
103 const SVGPathDataAndInfo
& start
=
104 *static_cast<const SVGPathDataAndInfo
*>(aStartVal
.mU
.mPtr
);
105 const SVGPathDataAndInfo
& end
=
106 *static_cast<const SVGPathDataAndInfo
*>(aEndVal
.mU
.mPtr
);
107 SVGPathDataAndInfo
& result
=
108 *static_cast<SVGPathDataAndInfo
*>(aResult
.mU
.mPtr
);
109 MOZ_ASSERT(result
.IsIdentity(),
110 "expecting outparam to start out as identity");
111 result
.SetElement(end
.Element());
112 if (!Servo_SVGPathData_Interpolate(
113 start
.IsIdentity() ? nullptr : &start
.RawData(), &end
.RawData(),
114 aUnitDistance
, &result
.RawData())) {
115 return NS_ERROR_FAILURE
;
120 } // namespace mozilla