SVGAngle.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "SVGAngle.h"
  6. #include "nsSVGAngle.h"
  7. #include "mozilla/dom/SVGAngleBinding.h"
  8. using namespace mozilla;
  9. using namespace mozilla::dom;
  10. NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(SVGAngle, mSVGElement)
  11. NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(SVGAngle, AddRef)
  12. NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(SVGAngle, Release)
  13. JSObject*
  14. SVGAngle::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  15. {
  16. return SVGAngleBinding::Wrap(aCx, this, aGivenProto);
  17. }
  18. uint16_t
  19. SVGAngle::UnitType() const
  20. {
  21. if (mType == AnimValue) {
  22. return mVal->mAnimValUnit;
  23. }
  24. return mVal->mBaseValUnit;
  25. }
  26. float
  27. SVGAngle::Value() const
  28. {
  29. if (mType == AnimValue) {
  30. return mVal->GetAnimValue();
  31. }
  32. return mVal->GetBaseValue();
  33. }
  34. void
  35. SVGAngle::SetValue(float aValue, ErrorResult& rv)
  36. {
  37. if (mType == AnimValue) {
  38. rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
  39. return;
  40. }
  41. bool isBaseVal = mType == BaseValue;
  42. mVal->SetBaseValue(aValue, isBaseVal ? mSVGElement.get() : nullptr,
  43. isBaseVal);
  44. }
  45. float
  46. SVGAngle::ValueInSpecifiedUnits() const
  47. {
  48. if (mType == AnimValue) {
  49. return mVal->mAnimVal;
  50. }
  51. return mVal->mBaseVal;
  52. }
  53. void
  54. SVGAngle::SetValueInSpecifiedUnits(float aValue, ErrorResult& rv)
  55. {
  56. if (mType == AnimValue) {
  57. rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
  58. return;
  59. } else if (mType == BaseValue) {
  60. mVal->SetBaseValueInSpecifiedUnits(aValue, mSVGElement);
  61. } else {
  62. mVal->mBaseVal = aValue;
  63. }
  64. }
  65. void
  66. SVGAngle::NewValueSpecifiedUnits(uint16_t unitType,
  67. float valueInSpecifiedUnits,
  68. ErrorResult& rv)
  69. {
  70. if (mType == AnimValue) {
  71. rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
  72. return;
  73. }
  74. rv = mVal->NewValueSpecifiedUnits(unitType, valueInSpecifiedUnits,
  75. mType == BaseValue ? mSVGElement.get()
  76. : nullptr);
  77. }
  78. void
  79. SVGAngle::ConvertToSpecifiedUnits(uint16_t unitType, ErrorResult& rv)
  80. {
  81. if (mType == AnimValue) {
  82. rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
  83. return;
  84. }
  85. rv = mVal->ConvertToSpecifiedUnits(unitType, mType == BaseValue ?
  86. mSVGElement.get() : nullptr);
  87. }
  88. void
  89. SVGAngle::SetValueAsString(const nsAString& aValue, ErrorResult& rv)
  90. {
  91. if (mType == AnimValue) {
  92. rv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
  93. return;
  94. }
  95. bool isBaseVal = mType == BaseValue;
  96. rv = mVal->SetBaseValueString(aValue, isBaseVal ? mSVGElement.get() : nullptr,
  97. isBaseVal);
  98. }
  99. void
  100. SVGAngle::GetValueAsString(nsAString& aValue)
  101. {
  102. if (mType == AnimValue) {
  103. mVal->GetAnimValueString(aValue);
  104. } else {
  105. mVal->GetBaseValueString(aValue);
  106. }
  107. }