SVGAnimatedBoolean.h (2469B)
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_SVGANIMATEDBOOLEAN_H_ 8 #define DOM_SVG_SVGANIMATEDBOOLEAN_H_ 9 10 #include "mozilla/AlreadyAddRefed.h" 11 #include "mozilla/SMILAttr.h" 12 #include "mozilla/UniquePtr.h" 13 #include "nsError.h" 14 15 class nsAtom; 16 17 namespace mozilla { 18 19 class SMILValue; 20 21 namespace dom { 22 class DOMSVGAnimatedBoolean; 23 class SVGAnimationElement; 24 class SVGElement; 25 } // namespace dom 26 27 class SVGAnimatedBoolean { 28 public: 29 friend class AutoChangeBooleanNotifier; 30 using SVGElement = dom::SVGElement; 31 32 void Init(uint8_t aAttrEnum = 0xff, bool aValue = false) { 33 mAnimVal = mBaseVal = aValue; 34 mAttrEnum = aAttrEnum; 35 mIsAnimated = false; 36 } 37 38 nsresult SetBaseValueAtom(const nsAtom* aValue, SVGElement* aSVGElement); 39 nsAtom* GetBaseValueAtom() const; 40 41 void SetBaseValue(bool aValue, SVGElement* aSVGElement); 42 bool GetBaseValue() const { return mBaseVal; } 43 44 void SetAnimValue(bool aValue, SVGElement* aSVGElement); 45 bool GetAnimValue() const { return mAnimVal; } 46 47 already_AddRefed<dom::DOMSVGAnimatedBoolean> ToDOMAnimatedBoolean( 48 SVGElement* aSVGElement); 49 UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement); 50 51 private: 52 bool mAnimVal; 53 bool mBaseVal; 54 bool mIsAnimated; 55 uint8_t mAttrEnum; // element specified tracking for attribute 56 57 public: 58 struct SMILBool : public SMILAttr { 59 public: 60 SMILBool(SVGAnimatedBoolean* aVal, SVGElement* aSVGElement) 61 : mVal(aVal), mSVGElement(aSVGElement) {} 62 63 // These will stay alive because a SMILAttr only lives as long 64 // as the Compositing step, and DOM elements don't get a chance to 65 // die during that. 66 SVGAnimatedBoolean* mVal; 67 SVGElement* mSVGElement; 68 69 // SMILAttr methods 70 nsresult ValueFromString(const nsAString& aStr, 71 const dom::SVGAnimationElement* aSrcElement, 72 SMILValue& aValue, 73 bool& aPreventCachingOfSandwich) const override; 74 SMILValue GetBaseValue() const override; 75 void ClearAnimValue() override; 76 nsresult SetAnimValue(const SMILValue& aValue) override; 77 }; 78 }; 79 80 } // namespace mozilla 81 82 #endif // DOM_SVG_SVGANIMATEDBOOLEAN_H_