Bug 1941128 - Turn off network.dns.native_https_query on Mac again
[gecko.git] / dom / svg / SVGAnimatedOrient.h
blobe03f9f18c5df4442c47f73844aaa3c0a1dd071d0
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"
11 #include "nsError.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"
20 class nsISupports;
22 namespace mozilla {
24 class SMILValue;
26 namespace dom {
27 class DOMSVGAngle;
28 class DOMSVGAnimatedAngle;
29 class SVGAnimationElement;
30 class SVGElement;
31 } // namespace dom
33 class SVGAnimatedOrient {
34 friend class AutoChangeOrientNotifier;
35 friend class dom::DOMSVGAngle;
36 friend class dom::DOMSVGAnimatedAngle;
37 using SVGElement = dom::SVGElement;
39 public:
40 void Init() {
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;
46 mIsAnimated = false;
49 nsresult SetBaseValueString(const nsAString& aValue, SVGElement* aSVGElement,
50 bool aDoSetAttr);
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,
64 bool aDoSetAttr);
65 void SetBaseType(SVGEnumValue aValue, SVGElement* aSVGElement,
66 ErrorResult& aRv);
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 IsValidUnitType(uint16_t aUnitType);
84 static bool GetValueFromString(const nsAString& aString, float& aValue,
85 uint16_t* aUnitType);
86 static float GetDegreesPerUnit(uint8_t aUnit);
88 private:
89 float mAnimVal;
90 float mBaseVal;
91 uint8_t mAnimType;
92 uint8_t mBaseType;
93 uint8_t mAnimValUnit;
94 uint8_t mBaseValUnit;
95 bool mIsAnimated;
97 void SetBaseValueInSpecifiedUnits(float aValue, SVGElement* aSVGElement);
98 nsresult NewValueSpecifiedUnits(uint16_t aUnitType,
99 float aValueInSpecifiedUnits,
100 SVGElement* aSVGElement);
101 nsresult ConvertToSpecifiedUnits(uint16_t aUnitType, SVGElement* aSVGElement);
102 already_AddRefed<dom::DOMSVGAngle> ToDOMBaseVal(SVGElement* aSVGElement);
103 already_AddRefed<dom::DOMSVGAngle> ToDOMAnimVal(SVGElement* aSVGElement);
105 public:
106 // DOM wrapper class for the (DOM)SVGAnimatedEnumeration interface where the
107 // wrapped class is SVGAnimatedOrient.
108 struct DOMAnimatedEnum final : public dom::DOMSVGAnimatedEnumeration {
109 DOMAnimatedEnum(SVGAnimatedOrient* aVal, SVGElement* aSVGElement)
110 : DOMSVGAnimatedEnumeration(aSVGElement), mVal(aVal) {}
111 ~DOMAnimatedEnum();
113 SVGAnimatedOrient* mVal; // kept alive because it belongs to content
115 using dom::DOMSVGAnimatedEnumeration::SetBaseVal;
116 uint16_t BaseVal() override { return mVal->mBaseType; }
117 void SetBaseVal(uint16_t aBaseVal, ErrorResult& aRv) override {
118 mVal->SetBaseType(aBaseVal, mSVGElement, aRv);
120 uint16_t AnimVal() override {
121 // Script may have modified animation parameters or timeline -- DOM
122 // getters need to flush any resample requests to reflect these
123 // modifications.
124 mSVGElement->FlushAnimations();
125 return mVal->mAnimType;
129 struct SMILOrient final : public SMILAttr {
130 public:
131 SMILOrient(SVGAnimatedOrient* aOrient, SVGElement* aSVGElement)
132 : mOrient(aOrient), mSVGElement(aSVGElement) {}
134 // These will stay alive because a SMILAttr only lives as long
135 // as the Compositing step, and DOM elements don't get a chance to
136 // die during that.
137 SVGAnimatedOrient* mOrient;
138 SVGElement* mSVGElement;
140 // SMILAttr methods
141 nsresult ValueFromString(const nsAString& aStr,
142 const dom::SVGAnimationElement* aSrcElement,
143 SMILValue& aValue,
144 bool& aPreventCachingOfSandwich) const override;
145 SMILValue GetBaseValue() const override;
146 void ClearAnimValue() override;
147 nsresult SetAnimValue(const SMILValue& aValue) override;
151 } // namespace mozilla
153 #endif // DOM_SVG_SVGANIMATEDORIENT_H_