Line data Source code
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 MOZILLA_SVGANIMATEDLENGTHLIST_H__
8 : #define MOZILLA_SVGANIMATEDLENGTHLIST_H__
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/UniquePtr.h"
12 : #include "nsAutoPtr.h"
13 : #include "nsISMILAttr.h"
14 : #include "SVGLengthList.h"
15 :
16 : class nsSMILValue;
17 : class nsSVGElement;
18 :
19 : namespace mozilla {
20 :
21 : namespace dom {
22 : class SVGAnimationElement;
23 : } // namespace dom
24 :
25 : /**
26 : * Class SVGAnimatedLengthList
27 : *
28 : * This class is very different to the SVG DOM interface of the same name found
29 : * in the SVG specification. This is a lightweight internal class - see
30 : * DOMSVGAnimatedLengthList for the heavier DOM class that wraps instances of
31 : * this class and implements the SVG specification's SVGAnimatedLengthList DOM
32 : * interface.
33 : *
34 : * Except where noted otherwise, this class' methods take care of keeping the
35 : * appropriate DOM wrappers in sync (see the comment in
36 : * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo) so that their
37 : * consumers don't need to concern themselves with that.
38 : */
39 0 : class SVGAnimatedLengthList
40 : {
41 : // friends so that they can get write access to mBaseVal
42 : friend class DOMSVGLength;
43 : friend class DOMSVGLengthList;
44 :
45 : public:
46 0 : SVGAnimatedLengthList() {}
47 :
48 : /**
49 : * Because it's so important that mBaseVal and its DOMSVGLengthList wrapper
50 : * (if any) be kept in sync (see the comment in
51 : * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo), this method
52 : * returns a const reference. Only our friend classes may get mutable
53 : * references to mBaseVal.
54 : */
55 0 : const SVGLengthList& GetBaseValue() const {
56 0 : return mBaseVal;
57 : }
58 :
59 : nsresult SetBaseValueString(const nsAString& aValue);
60 :
61 : void ClearBaseValue(uint32_t aAttrEnum);
62 :
63 0 : const SVGLengthList& GetAnimValue() const {
64 0 : return mAnimVal ? *mAnimVal : mBaseVal;
65 : }
66 :
67 : nsresult SetAnimValue(const SVGLengthList& aValue,
68 : nsSVGElement *aElement,
69 : uint32_t aAttrEnum);
70 :
71 : void ClearAnimValue(nsSVGElement *aElement,
72 : uint32_t aAttrEnum);
73 :
74 0 : bool IsAnimating() const {
75 0 : return !!mAnimVal;
76 : }
77 :
78 : UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement,
79 : uint8_t aAttrEnum, uint8_t aAxis,
80 : bool aCanZeroPadList);
81 :
82 : private:
83 :
84 : // mAnimVal is a pointer to allow us to determine if we're being animated or
85 : // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
86 : // if we're animating is not an option, since that would break animation *to*
87 : // the empty string (<set to="">).
88 :
89 : SVGLengthList mBaseVal;
90 : nsAutoPtr<SVGLengthList> mAnimVal;
91 :
92 0 : struct SMILAnimatedLengthList : public nsISMILAttr
93 : {
94 : public:
95 0 : SMILAnimatedLengthList(SVGAnimatedLengthList* aVal,
96 : nsSVGElement* aSVGElement,
97 : uint8_t aAttrEnum,
98 : uint8_t aAxis,
99 : bool aCanZeroPadList)
100 0 : : mVal(aVal)
101 : , mElement(aSVGElement)
102 : , mAttrEnum(aAttrEnum)
103 : , mAxis(aAxis)
104 0 : , mCanZeroPadList(aCanZeroPadList)
105 0 : {}
106 :
107 : // These will stay alive because a nsISMILAttr only lives as long
108 : // as the Compositing step, and DOM elements don't get a chance to
109 : // die during that.
110 : SVGAnimatedLengthList* mVal;
111 : nsSVGElement* mElement;
112 : uint8_t mAttrEnum;
113 : uint8_t mAxis;
114 : bool mCanZeroPadList; // See SVGLengthListAndInfo::CanZeroPadList
115 :
116 : // nsISMILAttr methods
117 : virtual nsresult ValueFromString(const nsAString& aStr,
118 : const dom::SVGAnimationElement* aSrcElement,
119 : nsSMILValue& aValue,
120 : bool& aPreventCachingOfSandwich) const override;
121 : virtual nsSMILValue GetBaseValue() const override;
122 : virtual void ClearAnimValue() override;
123 : virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
124 : };
125 : };
126 :
127 : } // namespace mozilla
128 :
129 : #endif // MOZILLA_SVGANIMATEDLENGTHLIST_H__
|