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 "DOMSVGAngle.h"
8 #include "SVGAnimatedOrient.h"
9 #include "mozilla/dom/SVGAngleBinding.h"
10 #include "mozilla/dom/SVGSVGElement.h"
15 NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGAngle
, mSVGElement
)
17 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMSVGAngle
, AddRef
)
18 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMSVGAngle
, Release
)
20 DOMSVGAngle::DOMSVGAngle(SVGSVGElement
* aSVGElement
)
21 : mSVGElement(aSVGElement
), mType(DOMSVGAngle::CreatedValue
) {
22 mVal
= new SVGAnimatedOrient();
26 JSObject
* DOMSVGAngle::WrapObject(JSContext
* aCx
,
27 JS::Handle
<JSObject
*> aGivenProto
) {
28 return SVGAngle_Binding::Wrap(aCx
, this, aGivenProto
);
31 uint16_t DOMSVGAngle::UnitType() const {
32 if (mType
== AnimValue
) {
33 mSVGElement
->FlushAnimations();
34 return mVal
->mAnimValUnit
;
36 return mVal
->mBaseValUnit
;
39 float DOMSVGAngle::Value() const {
40 if (mType
== AnimValue
) {
41 mSVGElement
->FlushAnimations();
42 return mVal
->GetAnimValue();
44 return mVal
->GetBaseValue();
47 void DOMSVGAngle::SetValue(float aValue
, ErrorResult
& rv
) {
48 if (mType
== AnimValue
) {
49 rv
.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR
);
52 bool isBaseVal
= mType
== BaseValue
;
53 mVal
->SetBaseValue(aValue
, mVal
->mBaseValUnit
,
54 isBaseVal
? mSVGElement
.get() : nullptr, isBaseVal
);
57 float DOMSVGAngle::ValueInSpecifiedUnits() const {
58 if (mType
== AnimValue
) {
59 return mVal
->mAnimVal
;
61 return mVal
->mBaseVal
;
64 void DOMSVGAngle::SetValueInSpecifiedUnits(float aValue
, ErrorResult
& rv
) {
65 if (mType
== AnimValue
) {
66 rv
.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR
);
69 if (mType
== BaseValue
) {
70 mVal
->SetBaseValueInSpecifiedUnits(aValue
, mSVGElement
);
72 mVal
->mBaseVal
= aValue
;
76 void DOMSVGAngle::NewValueSpecifiedUnits(uint16_t unitType
,
77 float valueInSpecifiedUnits
,
79 if (mType
== AnimValue
) {
80 rv
.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR
);
83 rv
= mVal
->NewValueSpecifiedUnits(
84 unitType
, valueInSpecifiedUnits
,
85 mType
== BaseValue
? mSVGElement
.get() : nullptr);
88 void DOMSVGAngle::ConvertToSpecifiedUnits(uint16_t unitType
, ErrorResult
& rv
) {
89 if (mType
== AnimValue
) {
90 rv
.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR
);
93 rv
= mVal
->ConvertToSpecifiedUnits(
94 unitType
, mType
== BaseValue
? mSVGElement
.get() : nullptr);
97 void DOMSVGAngle::SetValueAsString(const nsAString
& aValue
, ErrorResult
& rv
) {
98 if (mType
== AnimValue
) {
99 rv
.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR
);
102 bool isBaseVal
= mType
== BaseValue
;
103 rv
= mVal
->SetBaseValueString(aValue
, isBaseVal
? mSVGElement
.get() : nullptr,
107 void DOMSVGAngle::GetValueAsString(nsAString
& aValue
) {
108 if (mType
== AnimValue
) {
109 mSVGElement
->FlushAnimations();
110 mVal
->GetAnimAngleValueString(aValue
);
112 mVal
->GetBaseAngleValueString(aValue
);
117 } // namespace mozilla