nsSVGClass.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_SVGCLASS_H__
  6. #define __NS_SVGCLASS_H__
  7. #include "nsAutoPtr.h"
  8. #include "nsCycleCollectionParticipant.h"
  9. #include "nsError.h"
  10. #include "nsISMILAttr.h"
  11. #include "nsString.h"
  12. #include "mozilla/Attributes.h"
  13. class nsSVGElement;
  14. namespace mozilla {
  15. namespace dom {
  16. class SVGAnimatedString;
  17. } // namespace dom
  18. } // namespace mozilla
  19. class nsSVGClass
  20. {
  21. public:
  22. void Init() {
  23. mAnimVal = nullptr;
  24. }
  25. void SetBaseValue(const nsAString& aValue,
  26. nsSVGElement *aSVGElement,
  27. bool aDoSetAttr);
  28. void GetBaseValue(nsAString& aValue, const nsSVGElement *aSVGElement) const;
  29. void SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement);
  30. void GetAnimValue(nsAString& aValue, const nsSVGElement *aSVGElement) const;
  31. bool IsAnimated() const
  32. { return !!mAnimVal; }
  33. already_AddRefed<mozilla::dom::SVGAnimatedString>
  34. ToDOMAnimatedString(nsSVGElement* aSVGElement);
  35. // Returns a new nsISMILAttr object that the caller must delete
  36. nsISMILAttr* ToSMILAttr(nsSVGElement *aSVGElement);
  37. private:
  38. nsAutoPtr<nsString> mAnimVal;
  39. public:
  40. struct SMILString : public nsISMILAttr
  41. {
  42. public:
  43. SMILString(nsSVGClass *aVal, nsSVGElement *aSVGElement)
  44. : mVal(aVal), mSVGElement(aSVGElement) {}
  45. // These will stay alive because a nsISMILAttr only lives as long
  46. // as the Compositing step, and DOM elements don't get a chance to
  47. // die during that.
  48. nsSVGClass* mVal;
  49. nsSVGElement* mSVGElement;
  50. // nsISMILAttr methods
  51. virtual nsresult ValueFromString(const nsAString& aStr,
  52. const mozilla::dom::SVGAnimationElement *aSrcElement,
  53. nsSMILValue& aValue,
  54. bool& aPreventCachingOfSandwich) const override;
  55. virtual nsSMILValue GetBaseValue() const override;
  56. virtual void ClearAnimValue() override;
  57. virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
  58. };
  59. };
  60. #endif //__NS_SVGCLASS_H__