SVGAnimatedPointList.h (4307B)
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_SVGANIMATEDPOINTLIST_H_ 8 #define DOM_SVG_SVGANIMATEDPOINTLIST_H_ 9 10 #include "SVGPointList.h" 11 #include "mozilla/SMILAttr.h" 12 #include "mozilla/UniquePtr.h" 13 14 namespace mozilla { 15 16 class SMILValue; 17 18 namespace dom { 19 class DOMSVGPoint; 20 class DOMSVGPointList; 21 class SVGAnimationElement; 22 class SVGElement; 23 } // namespace dom 24 25 /** 26 * Class SVGAnimatedPointList 27 * 28 * Despite the fact that no SVGAnimatedPointList interface or objects exist 29 * in the SVG specification (unlike e.g. SVGAnimated*Length*List), we 30 * nevertheless have this internal class. (Note that there is an 31 * SVGAnimatedPoints interface, but that's quite different to 32 * SVGAnimatedLengthList since it is inherited by elements, as opposed to 33 * elements having members of that type.) The reason that we have this class is 34 * to provide a single locked down point of entry to the SVGPointList objects, 35 * which helps ensure that the DOM wrappers for SVGPointList objects' are 36 * always kept in sync. This is vitally important (see the comment in 37 * DOMSVGPointList::InternalListWillChangeTo) and frees consumers from having 38 * to know or worry about wrappers (or forget about them!) for the most part. 39 */ 40 class SVGAnimatedPointList { 41 // friends so that they can get write access to mBaseVal and mAnimVal 42 friend class dom::DOMSVGPoint; 43 friend class dom::DOMSVGPointList; 44 45 public: 46 SVGAnimatedPointList() = default; 47 48 SVGAnimatedPointList& operator=(const SVGAnimatedPointList& aOther) { 49 mBaseVal = aOther.mBaseVal; 50 if (aOther.mAnimVal) { 51 mAnimVal = MakeUnique<SVGPointList>(*aOther.mAnimVal); 52 } 53 return *this; 54 } 55 56 /** 57 * Because it's so important that mBaseVal and its DOMSVGPointList wrapper 58 * (if any) be kept in sync (see the comment in 59 * DOMSVGPointList::InternalListWillChangeTo), this method returns a const 60 * reference. Only our friend classes may get mutable references to mBaseVal. 61 */ 62 const SVGPointList& GetBaseValue() const { return mBaseVal; } 63 64 nsresult SetBaseValueString(const nsAString& aValue); 65 66 void ClearBaseValue(); 67 68 /** 69 * const! See comment for GetBaseValue! 70 */ 71 const SVGPointList& GetAnimValue() const { 72 return mAnimVal ? *mAnimVal : mBaseVal; 73 } 74 75 nsresult SetAnimValue(const SVGPointList& aNewAnimValue, 76 dom::SVGElement* aElement); 77 78 void ClearAnimValue(dom::SVGElement* aElement); 79 80 /** 81 * Needed for correct DOM wrapper construction since GetAnimValue may 82 * actually return the baseVal! 83 */ 84 void* GetBaseValKey() const { return (void*)&mBaseVal; } 85 void* GetAnimValKey() const { return (void*)&mAnimVal; } 86 87 bool IsAnimating() const { return !!mAnimVal; } 88 89 UniquePtr<SMILAttr> ToSMILAttr(dom::SVGElement* aElement); 90 91 private: 92 // mAnimVal is a pointer to allow us to determine if we're being animated or 93 // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check 94 // if we're animating is not an option, since that would break animation *to* 95 // the empty string (<set to="">). 96 97 SVGPointList mBaseVal; 98 UniquePtr<SVGPointList> mAnimVal; 99 100 struct SMILAnimatedPointList : public SMILAttr { 101 public: 102 SMILAnimatedPointList(SVGAnimatedPointList* aVal, dom::SVGElement* aElement) 103 : mVal(aVal), mElement(aElement) {} 104 105 // These will stay alive because a SMILAttr only lives as long 106 // as the Compositing step, and DOM elements don't get a chance to 107 // die during that. 108 SVGAnimatedPointList* mVal; 109 dom::SVGElement* mElement; 110 111 // SMILAttr methods 112 nsresult ValueFromString(const nsAString& aStr, 113 const dom::SVGAnimationElement* aSrcElement, 114 SMILValue& aValue, 115 bool& aPreventCachingOfSandwich) const override; 116 SMILValue GetBaseValue() const override; 117 void ClearAnimValue() override; 118 nsresult SetAnimValue(const SMILValue& aValue) override; 119 }; 120 }; 121 122 } // namespace mozilla 123 124 #endif // DOM_SVG_SVGANIMATEDPOINTLIST_H_