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