SVGAnimatedClass.h (2265B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_SVG_SVGANIMATEDCLASS_H_ 8 #define DOM_SVG_SVGANIMATEDCLASS_H_ 9 10 #include "mozilla/SMILAttr.h" 11 #include "mozilla/SVGAnimatedClassOrString.h" 12 #include "mozilla/UniquePtr.h" 13 #include "nsCycleCollectionParticipant.h" 14 15 namespace mozilla { 16 17 class SMILValue; 18 19 namespace dom { 20 class DOMSVGAnimatedString; 21 class SVGElement; 22 } // namespace dom 23 24 class SVGAnimatedClass final : public SVGAnimatedClassOrString { 25 public: 26 using SVGElement = dom::SVGElement; 27 28 void Init() { mAnimVal = nullptr; } 29 30 void SetBaseValue(const nsAString& aValue, SVGElement* aSVGElement, 31 bool aDoSetAttr) override; 32 void GetBaseValue(nsAString& aValue, 33 const SVGElement* aSVGElement) const override; 34 35 void SetAnimValue(const nsAString& aValue, SVGElement* aSVGElement); 36 void GetAnimValue(nsAString& aResult, 37 const SVGElement* aSVGElement) const override; 38 bool IsAnimated() const { return !!mAnimVal; } 39 40 UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement); 41 42 private: 43 UniquePtr<nsString> mAnimVal; 44 45 public: 46 struct SMILString : public SMILAttr { 47 public: 48 SMILString(SVGAnimatedClass* aVal, SVGElement* aSVGElement) 49 : mVal(aVal), mSVGElement(aSVGElement) {} 50 51 // These will stay alive because a SMILAttr only lives as long 52 // as the Compositing step, and DOM elements don't get a chance to 53 // die during that. 54 SVGAnimatedClass* mVal; 55 SVGElement* mSVGElement; 56 57 // SMILAttr methods 58 nsresult ValueFromString(const nsAString& aStr, 59 const dom::SVGAnimationElement* aSrcElement, 60 SMILValue& aValue, 61 bool& aPreventCachingOfSandwich) const override; 62 SMILValue GetBaseValue() const override; 63 void ClearAnimValue() override; 64 nsresult SetAnimValue(const SMILValue& aValue) override; 65 }; 66 }; 67 68 } // namespace mozilla 69 70 #endif // DOM_SVG_SVGANIMATEDCLASS_H_