nsSVGAngle.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef __NS_SVGANGLE_H__
  6. #define __NS_SVGANGLE_H__
  7. #include "nsCOMPtr.h"
  8. #include "nsError.h"
  9. #include "nsISMILAttr.h"
  10. #include "mozilla/Attributes.h"
  11. class nsISupports;
  12. class nsSMILValue;
  13. class nsSVGElement;
  14. namespace mozilla {
  15. // Angle Unit Types
  16. static const unsigned short SVG_ANGLETYPE_UNKNOWN = 0;
  17. static const unsigned short SVG_ANGLETYPE_UNSPECIFIED = 1;
  18. static const unsigned short SVG_ANGLETYPE_DEG = 2;
  19. static const unsigned short SVG_ANGLETYPE_RAD = 3;
  20. static const unsigned short SVG_ANGLETYPE_GRAD = 4;
  21. namespace dom {
  22. class nsSVGOrientType;
  23. class SVGAngle;
  24. class SVGAnimatedAngle;
  25. class SVGAnimationElement;
  26. } // namespace dom
  27. } // namespace mozilla
  28. class nsSVGAngle
  29. {
  30. friend class mozilla::dom::SVGAngle;
  31. friend class mozilla::dom::SVGAnimatedAngle;
  32. public:
  33. void Init(uint8_t aAttrEnum = 0xff,
  34. float aValue = 0,
  35. uint8_t aUnitType = mozilla::SVG_ANGLETYPE_UNSPECIFIED) {
  36. mAnimVal = mBaseVal = aValue;
  37. mAnimValUnit = mBaseValUnit = aUnitType;
  38. mAttrEnum = aAttrEnum;
  39. mIsAnimated = false;
  40. }
  41. nsresult SetBaseValueString(const nsAString& aValue,
  42. nsSVGElement *aSVGElement,
  43. bool aDoSetAttr);
  44. void GetBaseValueString(nsAString& aValue) const;
  45. void GetAnimValueString(nsAString& aValue) const;
  46. float GetBaseValue() const
  47. { return mBaseVal * GetDegreesPerUnit(mBaseValUnit); }
  48. float GetAnimValue() const
  49. { return mAnimVal * GetDegreesPerUnit(mAnimValUnit); }
  50. void SetBaseValue(float aValue, nsSVGElement *aSVGElement, bool aDoSetAttr);
  51. void SetAnimValue(float aValue, uint8_t aUnit, nsSVGElement *aSVGElement);
  52. uint8_t GetBaseValueUnit() const { return mBaseValUnit; }
  53. uint8_t GetAnimValueUnit() const { return mAnimValUnit; }
  54. float GetBaseValInSpecifiedUnits() const { return mBaseVal; }
  55. float GetAnimValInSpecifiedUnits() const { return mAnimVal; }
  56. static nsresult ToDOMSVGAngle(nsISupports **aResult);
  57. already_AddRefed<mozilla::dom::SVGAnimatedAngle>
  58. ToDOMAnimatedAngle(nsSVGElement* aSVGElement);
  59. // Returns a new nsISMILAttr object that the caller must delete
  60. nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
  61. static float GetDegreesPerUnit(uint8_t aUnit);
  62. private:
  63. float mAnimVal;
  64. float mBaseVal;
  65. uint8_t mAnimValUnit;
  66. uint8_t mBaseValUnit;
  67. uint8_t mAttrEnum; // element specified tracking for attribute
  68. bool mIsAnimated;
  69. void SetBaseValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement);
  70. nsresult NewValueSpecifiedUnits(uint16_t aUnitType, float aValue,
  71. nsSVGElement *aSVGElement);
  72. nsresult ConvertToSpecifiedUnits(uint16_t aUnitType, nsSVGElement *aSVGElement);
  73. already_AddRefed<mozilla::dom::SVGAngle> ToDOMBaseVal(nsSVGElement* aSVGElement);
  74. already_AddRefed<mozilla::dom::SVGAngle> ToDOMAnimVal(nsSVGElement* aSVGElement);
  75. public:
  76. // We do not currently implemente a SMILAngle struct because in SVG 1.1 the
  77. // only *animatable* attribute that takes an <angle> is 'orient', on the
  78. // 'marker' element, and 'orient' must be special cased since it can also
  79. // take the value 'auto', making it a more complex type.
  80. struct SMILOrient final : public nsISMILAttr
  81. {
  82. public:
  83. SMILOrient(mozilla::dom::nsSVGOrientType* aOrientType,
  84. nsSVGAngle* aAngle,
  85. nsSVGElement* aSVGElement)
  86. : mOrientType(aOrientType)
  87. , mAngle(aAngle)
  88. , mSVGElement(aSVGElement)
  89. {}
  90. // These will stay alive because a nsISMILAttr only lives as long
  91. // as the Compositing step, and DOM elements don't get a chance to
  92. // die during that.
  93. mozilla::dom::nsSVGOrientType* mOrientType;
  94. nsSVGAngle* mAngle;
  95. nsSVGElement* mSVGElement;
  96. // nsISMILAttr methods
  97. virtual nsresult ValueFromString(const nsAString& aStr,
  98. const mozilla::dom::SVGAnimationElement* aSrcElement,
  99. nsSMILValue& aValue,
  100. bool& aPreventCachingOfSandwich) const override;
  101. virtual nsSMILValue GetBaseValue() const override;
  102. virtual void ClearAnimValue() override;
  103. virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
  104. };
  105. };
  106. #endif //__NS_SVGANGLE_H__