Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / DOMSVGAngle.cpp
blobe22b62c1e9e709f44207162de840294a5a815201
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"
12 namespace mozilla::dom {
14 NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGAngle, mSVGElement)
16 DOMSVGAngle::DOMSVGAngle(SVGSVGElement* aSVGElement)
17 : mSVGElement(aSVGElement), mType(AngleType::CreatedValue) {
18 mVal = new SVGAnimatedOrient();
19 mVal->Init();
22 JSObject* DOMSVGAngle::WrapObject(JSContext* aCx,
23 JS::Handle<JSObject*> aGivenProto) {
24 return SVGAngle_Binding::Wrap(aCx, this, aGivenProto);
27 uint16_t DOMSVGAngle::UnitType() const {
28 uint16_t unitType;
29 if (mType == AngleType::AnimValue) {
30 mSVGElement->FlushAnimations();
31 unitType = mVal->mAnimValUnit;
32 } else {
33 unitType = mVal->mBaseValUnit;
35 return SVGAnimatedOrient::IsValidUnitType(unitType)
36 ? unitType
37 : SVGAngle_Binding::SVG_ANGLETYPE_UNKNOWN;
40 float DOMSVGAngle::Value() const {
41 if (mType == AngleType::AnimValue) {
42 mSVGElement->FlushAnimations();
43 return mVal->GetAnimValue();
45 return mVal->GetBaseValue();
48 void DOMSVGAngle::SetValue(float aValue, ErrorResult& rv) {
49 if (mType == AngleType::AnimValue) {
50 rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
51 return;
53 bool isBaseVal = mType == AngleType::BaseValue;
54 mVal->SetBaseValue(aValue, mVal->mBaseValUnit,
55 isBaseVal ? mSVGElement.get() : nullptr, isBaseVal);
58 float DOMSVGAngle::ValueInSpecifiedUnits() const {
59 if (mType == AngleType::AnimValue) {
60 return mVal->mAnimVal;
62 return mVal->mBaseVal;
65 void DOMSVGAngle::SetValueInSpecifiedUnits(float aValue, ErrorResult& rv) {
66 if (mType == AngleType::AnimValue) {
67 rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
68 return;
70 if (mType == AngleType::BaseValue) {
71 mVal->SetBaseValueInSpecifiedUnits(aValue, mSVGElement);
72 } else {
73 mVal->mBaseVal = aValue;
77 void DOMSVGAngle::NewValueSpecifiedUnits(uint16_t unitType,
78 float valueInSpecifiedUnits,
79 ErrorResult& rv) {
80 if (mType == AngleType::AnimValue) {
81 rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
82 return;
84 rv = mVal->NewValueSpecifiedUnits(
85 unitType, valueInSpecifiedUnits,
86 mType == AngleType::BaseValue ? mSVGElement.get() : nullptr);
89 void DOMSVGAngle::ConvertToSpecifiedUnits(uint16_t unitType, ErrorResult& rv) {
90 if (mType == AngleType::AnimValue) {
91 rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
92 return;
94 rv = mVal->ConvertToSpecifiedUnits(
95 unitType, mType == AngleType::BaseValue ? mSVGElement.get() : nullptr);
98 void DOMSVGAngle::SetValueAsString(const nsAString& aValue, ErrorResult& rv) {
99 if (mType == AngleType::AnimValue) {
100 rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
101 return;
103 bool isBaseVal = mType == AngleType::BaseValue;
104 rv = mVal->SetBaseValueString(aValue, isBaseVal ? mSVGElement.get() : nullptr,
105 isBaseVal);
108 void DOMSVGAngle::GetValueAsString(nsAString& aValue) {
109 if (mType == AngleType::AnimValue) {
110 mSVGElement->FlushAnimations();
111 mVal->GetAnimAngleValueString(aValue);
112 } else {
113 mVal->GetBaseAngleValueString(aValue);
117 } // namespace mozilla::dom