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 #ifndef DOM_SVG_SVGMOTIONSMILANIMATIONFUNCTION_H_
8 #define DOM_SVG_SVGMOTIONSMILANIMATIONFUNCTION_H_
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/SMILAnimationFunction.h"
13 #include "SVGMotionSMILType.h"
26 class SVGMPathElement
;
29 //----------------------------------------------------------------------
30 // SVGMotionSMILAnimationFunction
32 // Subclass of SMILAnimationFunction to support a few extra features offered
33 // by the <animateMotion> element.
35 class SVGMotionSMILAnimationFunction final
: public SMILAnimationFunction
{
36 using Path
= mozilla::gfx::Path
;
39 SVGMotionSMILAnimationFunction();
40 bool SetAttr(nsAtom
* aAttribute
, const nsAString
& aValue
,
41 nsAttrValue
& aResult
, nsresult
* aParseResult
= nullptr) override
;
42 bool UnsetAttr(nsAtom
* aAttribute
) override
;
44 // Method to allow our owner-element to signal us when our <mpath>
45 // has changed or been added/removed. When that happens, we need to
46 // mark ourselves as changed so we'll get recomposed, and mark our path data
47 // as stale so it'll get regenerated (regardless of mPathSourceType, since
48 // <mpath> trumps all the other sources of path data)
49 void MpathChanged() { mIsPathStale
= mHasChanged
= true; }
53 // NOTE: Ordering matters here. Higher-priority path-descriptors should
54 // have higher enumerated values
55 ePathSourceType_None
, // uninitialized or not applicable
56 ePathSourceType_ByAttr
, // by or from-by animation
57 ePathSourceType_ToAttr
, // to or from-to animation
58 ePathSourceType_ValuesAttr
,
59 ePathSourceType_PathAttr
,
63 SMILCalcMode
GetCalcMode() const override
;
64 virtual nsresult
GetValues(const SMILAttr
& aSMILAttr
,
65 SMILValueArray
& aResult
) override
;
66 void CheckValueListDependentAttrs(uint32_t aNumValues
) override
;
68 bool IsToAnimation() const override
;
70 void CheckKeyPoints();
71 nsresult
SetKeyPoints(const nsAString
& aKeyPoints
, nsAttrValue
& aResult
);
72 void UnsetKeyPoints();
73 nsresult
SetRotate(const nsAString
& aRotate
, nsAttrValue
& aResult
);
76 // Helpers for GetValues
77 void MarkStaleIfAttributeAffectsPath(nsAtom
* aAttribute
);
78 void RebuildPathAndVertices(const nsIContent
* aTargetElement
);
79 void RebuildPathAndVerticesFromMpathElem(dom::SVGMPathElement
* aMpathElem
);
80 void RebuildPathAndVerticesFromPathAttr();
81 void RebuildPathAndVerticesFromBasicAttrs(const nsIContent
* aContextElem
);
82 bool GenerateValuesForPathAndPoints(Path
* aPath
, bool aIsKeyPoints
,
83 FallibleTArray
<double>& aPointDistances
,
84 SMILValueArray
& aResult
);
88 FallibleTArray
<double> mKeyPoints
; // parsed from "keyPoints" attribute.
90 RotateType mRotateType
; // auto, auto-reverse, or explicit.
91 float mRotateAngle
; // the angle value, if explicit.
93 PathSourceType mPathSourceType
; // source of our Path.
94 RefPtr
<Path
> mPath
; // representation of motion path.
95 FallibleTArray
<double> mPathVertices
; // distances of vertices along path.
100 } // namespace mozilla
102 #endif // DOM_SVG_SVGMOTIONSMILANIMATIONFUNCTION_H_