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_SVGANIMATEDORIENT_H_
8 #define DOM_SVG_SVGANIMATEDORIENT_H_
10 #include "DOMSVGAnimatedEnumeration.h"
12 #include "SVGAnimatedEnumeration.h"
13 #include "mozilla/AlreadyAddRefed.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/SMILAttr.h"
16 #include "mozilla/dom/SVGAngleBinding.h"
17 #include "mozilla/dom/SVGMarkerElementBinding.h"
18 #include "mozilla/UniquePtr.h"
28 class DOMSVGAnimatedAngle
;
29 class SVGAnimationElement
;
33 class SVGAnimatedOrient
{
34 friend class AutoChangeOrientNotifier
;
35 friend class dom::DOMSVGAngle
;
36 friend class dom::DOMSVGAnimatedAngle
;
37 using SVGElement
= dom::SVGElement
;
41 mAnimVal
= mBaseVal
= .0f
;
42 mAnimType
= mBaseType
=
43 dom::SVGMarkerElement_Binding::SVG_MARKER_ORIENT_ANGLE
;
44 mAnimValUnit
= mBaseValUnit
=
45 dom::SVGAngle_Binding::SVG_ANGLETYPE_UNSPECIFIED
;
49 nsresult
SetBaseValueString(const nsAString
& aValue
, SVGElement
* aSVGElement
,
51 void GetBaseValueString(nsAString
& aValue
) const;
52 void GetBaseAngleValueString(nsAString
& aValue
) const;
53 void GetAnimAngleValueString(nsAString
& aValue
) const;
55 float GetBaseValue() const {
56 return mBaseVal
* GetDegreesPerUnit(mBaseValUnit
);
58 float GetAnimValue() const {
59 return mAnimVal
* GetDegreesPerUnit(mAnimValUnit
);
61 SVGEnumValue
GetAnimType() const { return mAnimType
; }
63 void SetBaseValue(float aValue
, uint8_t aUnit
, SVGElement
* aSVGElement
,
65 void SetBaseType(SVGEnumValue aValue
, SVGElement
* aSVGElement
,
67 void SetAnimValue(float aValue
, uint8_t aUnit
, SVGElement
* aSVGElement
);
68 void SetAnimType(SVGEnumValue aValue
, SVGElement
* aSVGElement
);
70 uint8_t GetBaseValueUnit() const { return mBaseValUnit
; }
71 uint8_t GetAnimValueUnit() const { return mAnimValUnit
; }
72 float GetBaseValInSpecifiedUnits() const { return mBaseVal
; }
73 float GetAnimValInSpecifiedUnits() const { return mAnimVal
; }
75 static nsresult
ToDOMSVGAngle(nsISupports
** aResult
);
76 already_AddRefed
<dom::DOMSVGAnimatedAngle
> ToDOMAnimatedAngle(
77 SVGElement
* aSVGElement
);
78 already_AddRefed
<dom::DOMSVGAnimatedEnumeration
> ToDOMAnimatedEnum(
79 SVGElement
* aSVGElement
);
80 UniquePtr
<SMILAttr
> ToSMILAttr(SVGElement
* aSVGElement
);
82 static bool GetValueFromString(const nsAString
& aString
, float& aValue
,
84 static float GetDegreesPerUnit(uint8_t aUnit
);
95 void SetBaseValueInSpecifiedUnits(float aValue
, SVGElement
* aSVGElement
);
96 nsresult
NewValueSpecifiedUnits(uint16_t aUnitType
,
97 float aValueInSpecifiedUnits
,
98 SVGElement
* aSVGElement
);
99 nsresult
ConvertToSpecifiedUnits(uint16_t aUnitType
, SVGElement
* aSVGElement
);
100 already_AddRefed
<dom::DOMSVGAngle
> ToDOMBaseVal(SVGElement
* aSVGElement
);
101 already_AddRefed
<dom::DOMSVGAngle
> ToDOMAnimVal(SVGElement
* aSVGElement
);
104 // DOM wrapper class for the (DOM)SVGAnimatedEnumeration interface where the
105 // wrapped class is SVGAnimatedOrient.
106 struct DOMAnimatedEnum final
: public dom::DOMSVGAnimatedEnumeration
{
107 DOMAnimatedEnum(SVGAnimatedOrient
* aVal
, SVGElement
* aSVGElement
)
108 : DOMSVGAnimatedEnumeration(aSVGElement
), mVal(aVal
) {}
111 SVGAnimatedOrient
* mVal
; // kept alive because it belongs to content
113 using dom::DOMSVGAnimatedEnumeration::SetBaseVal
;
114 uint16_t BaseVal() override
{ return mVal
->mBaseType
; }
115 void SetBaseVal(uint16_t aBaseVal
, ErrorResult
& aRv
) override
{
116 mVal
->SetBaseType(aBaseVal
, mSVGElement
, aRv
);
118 uint16_t AnimVal() override
{
119 // Script may have modified animation parameters or timeline -- DOM
120 // getters need to flush any resample requests to reflect these
122 mSVGElement
->FlushAnimations();
123 return mVal
->mAnimType
;
127 struct SMILOrient final
: public SMILAttr
{
129 SMILOrient(SVGAnimatedOrient
* aOrient
, SVGElement
* aSVGElement
)
130 : mOrient(aOrient
), mSVGElement(aSVGElement
) {}
132 // These will stay alive because a SMILAttr only lives as long
133 // as the Compositing step, and DOM elements don't get a chance to
135 SVGAnimatedOrient
* mOrient
;
136 SVGElement
* mSVGElement
;
139 virtual nsresult
ValueFromString(
140 const nsAString
& aStr
, const dom::SVGAnimationElement
* aSrcElement
,
141 SMILValue
& aValue
, bool& aPreventCachingOfSandwich
) const override
;
142 virtual SMILValue
GetBaseValue() const override
;
143 virtual void ClearAnimValue() override
;
144 virtual nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
148 } // namespace mozilla
150 #endif // DOM_SVG_SVGANIMATEDORIENT_H_