SVGAnimatedLengthList.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 MOZILLA_SVGANIMATEDLENGTHLIST_H__
  6. #define MOZILLA_SVGANIMATEDLENGTHLIST_H__
  7. #include "mozilla/Attributes.h"
  8. #include "nsAutoPtr.h"
  9. #include "nsISMILAttr.h"
  10. #include "SVGLengthList.h"
  11. class nsSMILValue;
  12. class nsSVGElement;
  13. namespace mozilla {
  14. namespace dom {
  15. class SVGAnimationElement;
  16. } // namespace dom
  17. /**
  18. * Class SVGAnimatedLengthList
  19. *
  20. * This class is very different to the SVG DOM interface of the same name found
  21. * in the SVG specification. This is a lightweight internal class - see
  22. * DOMSVGAnimatedLengthList for the heavier DOM class that wraps instances of
  23. * this class and implements the SVG specification's SVGAnimatedLengthList DOM
  24. * interface.
  25. *
  26. * Except where noted otherwise, this class' methods take care of keeping the
  27. * appropriate DOM wrappers in sync (see the comment in
  28. * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo) so that their
  29. * consumers don't need to concern themselves with that.
  30. */
  31. class SVGAnimatedLengthList
  32. {
  33. // friends so that they can get write access to mBaseVal
  34. friend class DOMSVGLength;
  35. friend class DOMSVGLengthList;
  36. public:
  37. SVGAnimatedLengthList() {}
  38. /**
  39. * Because it's so important that mBaseVal and its DOMSVGLengthList wrapper
  40. * (if any) be kept in sync (see the comment in
  41. * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo), this method
  42. * returns a const reference. Only our friend classes may get mutable
  43. * references to mBaseVal.
  44. */
  45. const SVGLengthList& GetBaseValue() const {
  46. return mBaseVal;
  47. }
  48. nsresult SetBaseValueString(const nsAString& aValue);
  49. void ClearBaseValue(uint32_t aAttrEnum);
  50. const SVGLengthList& GetAnimValue() const {
  51. return mAnimVal ? *mAnimVal : mBaseVal;
  52. }
  53. nsresult SetAnimValue(const SVGLengthList& aValue,
  54. nsSVGElement *aElement,
  55. uint32_t aAttrEnum);
  56. void ClearAnimValue(nsSVGElement *aElement,
  57. uint32_t aAttrEnum);
  58. bool IsAnimating() const {
  59. return !!mAnimVal;
  60. }
  61. /// Callers own the returned nsISMILAttr
  62. nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement, uint8_t aAttrEnum,
  63. uint8_t aAxis, bool aCanZeroPadList);
  64. private:
  65. // mAnimVal is a pointer to allow us to determine if we're being animated or
  66. // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
  67. // if we're animating is not an option, since that would break animation *to*
  68. // the empty string (<set to="">).
  69. SVGLengthList mBaseVal;
  70. nsAutoPtr<SVGLengthList> mAnimVal;
  71. struct SMILAnimatedLengthList : public nsISMILAttr
  72. {
  73. public:
  74. SMILAnimatedLengthList(SVGAnimatedLengthList* aVal,
  75. nsSVGElement* aSVGElement,
  76. uint8_t aAttrEnum,
  77. uint8_t aAxis,
  78. bool aCanZeroPadList)
  79. : mVal(aVal)
  80. , mElement(aSVGElement)
  81. , mAttrEnum(aAttrEnum)
  82. , mAxis(aAxis)
  83. , mCanZeroPadList(aCanZeroPadList)
  84. {}
  85. // These will stay alive because a nsISMILAttr only lives as long
  86. // as the Compositing step, and DOM elements don't get a chance to
  87. // die during that.
  88. SVGAnimatedLengthList* mVal;
  89. nsSVGElement* mElement;
  90. uint8_t mAttrEnum;
  91. uint8_t mAxis;
  92. bool mCanZeroPadList; // See SVGLengthListAndInfo::CanZeroPadList
  93. // nsISMILAttr methods
  94. virtual nsresult ValueFromString(const nsAString& aStr,
  95. const dom::SVGAnimationElement* aSrcElement,
  96. nsSMILValue& aValue,
  97. bool& aPreventCachingOfSandwich) const override;
  98. virtual nsSMILValue GetBaseValue() const override;
  99. virtual void ClearAnimValue() override;
  100. virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
  101. };
  102. };
  103. } // namespace mozilla
  104. #endif // MOZILLA_SVGANIMATEDLENGTHLIST_H__