nsSVGInteger.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_SVGINTEGER_H__
  6. #define __NS_SVGINTEGER_H__
  7. #include "nsCycleCollectionParticipant.h"
  8. #include "nsError.h"
  9. #include "SVGAnimatedInteger.h"
  10. #include "nsISMILAttr.h"
  11. #include "nsSVGElement.h"
  12. #include "mozilla/Attributes.h"
  13. class nsSMILValue;
  14. namespace mozilla {
  15. namespace dom {
  16. class SVGAnimationElement;
  17. } // namespace dom
  18. } // namespace mozilla
  19. class nsSVGInteger
  20. {
  21. public:
  22. void Init(uint8_t aAttrEnum = 0xff, int32_t aValue = 0) {
  23. mAnimVal = mBaseVal = aValue;
  24. mAttrEnum = aAttrEnum;
  25. mIsAnimated = false;
  26. mIsBaseSet = false;
  27. }
  28. nsresult SetBaseValueString(const nsAString& aValue,
  29. nsSVGElement *aSVGElement);
  30. void GetBaseValueString(nsAString& aValue);
  31. void SetBaseValue(int32_t aValue, nsSVGElement *aSVGElement);
  32. int32_t GetBaseValue() const
  33. { return mBaseVal; }
  34. void SetAnimValue(int aValue, nsSVGElement *aSVGElement);
  35. int GetAnimValue() const
  36. { return mAnimVal; }
  37. // Returns true if the animated value of this integer has been explicitly
  38. // set (either by animation, or by taking on the base value which has been
  39. // explicitly set by markup or a DOM call), false otherwise.
  40. // If this returns false, the animated value is still valid, that is,
  41. // useable, and represents the default base value of the attribute.
  42. bool IsExplicitlySet() const
  43. { return mIsAnimated || mIsBaseSet; }
  44. already_AddRefed<mozilla::dom::SVGAnimatedInteger>
  45. ToDOMAnimatedInteger(nsSVGElement* aSVGElement);
  46. // Returns a new nsISMILAttr object that the caller must delete
  47. nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
  48. private:
  49. int32_t mAnimVal;
  50. int32_t mBaseVal;
  51. uint8_t mAttrEnum; // element specified tracking for attribute
  52. bool mIsAnimated;
  53. bool mIsBaseSet;
  54. public:
  55. struct DOMAnimatedInteger final : public mozilla::dom::SVGAnimatedInteger
  56. {
  57. DOMAnimatedInteger(nsSVGInteger* aVal, nsSVGElement* aSVGElement)
  58. : mozilla::dom::SVGAnimatedInteger(aSVGElement)
  59. , mVal(aVal)
  60. {}
  61. virtual ~DOMAnimatedInteger();
  62. nsSVGInteger* mVal; // kept alive because it belongs to content
  63. virtual int32_t BaseVal() override
  64. {
  65. return mVal->GetBaseValue();
  66. }
  67. virtual void SetBaseVal(int32_t aValue) override
  68. {
  69. mVal->SetBaseValue(aValue, mSVGElement);
  70. }
  71. // Script may have modified animation parameters or timeline -- DOM getters
  72. // need to flush any resample requests to reflect these modifications.
  73. virtual int32_t AnimVal() override
  74. {
  75. mSVGElement->FlushAnimations();
  76. return mVal->GetAnimValue();
  77. }
  78. };
  79. struct SMILInteger : public nsISMILAttr
  80. {
  81. public:
  82. SMILInteger(nsSVGInteger* aVal, nsSVGElement* aSVGElement)
  83. : mVal(aVal), mSVGElement(aSVGElement) {}
  84. // These will stay alive because a nsISMILAttr only lives as long
  85. // as the Compositing step, and DOM elements don't get a chance to
  86. // die during that.
  87. nsSVGInteger* mVal;
  88. nsSVGElement* mSVGElement;
  89. // nsISMILAttr methods
  90. virtual nsresult ValueFromString(const nsAString& aStr,
  91. const mozilla::dom::SVGAnimationElement* aSrcElement,
  92. nsSMILValue& aValue,
  93. bool& aPreventCachingOfSandwich) const override;
  94. virtual nsSMILValue GetBaseValue() const override;
  95. virtual void ClearAnimValue() override;
  96. virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
  97. };
  98. };
  99. #endif //__NS_SVGINTEGER_H__