1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla SVG Project code.
16 : *
17 : * The Initial Developer of the Original Code is the Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2010
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 2 or later (the "GPL"), or
25 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : #ifndef MOZILLA_SVGANIMATEDLENGTHLIST_H__
38 : #define MOZILLA_SVGANIMATEDLENGTHLIST_H__
39 :
40 : #include "nsAutoPtr.h"
41 : #include "nsISMILAttr.h"
42 : #include "SVGLengthList.h"
43 :
44 : class nsISMILAnimationElement;
45 : class nsSMILValue;
46 : class nsSVGElement;
47 :
48 : namespace mozilla {
49 :
50 : /**
51 : * Class SVGAnimatedLengthList
52 : *
53 : * This class is very different to the SVG DOM interface of the same name found
54 : * in the SVG specification. This is a lightweight internal class - see
55 : * DOMSVGAnimatedLengthList for the heavier DOM class that wraps instances of
56 : * this class and implements the SVG specification's SVGAnimatedLengthList DOM
57 : * interface.
58 : *
59 : * Except where noted otherwise, this class' methods take care of keeping the
60 : * appropriate DOM wrappers in sync (see the comment in
61 : * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo) so that their
62 : * consumers don't need to concern themselves with that.
63 : */
64 : class SVGAnimatedLengthList
65 0 : {
66 : // friends so that they can get write access to mBaseVal
67 : friend class DOMSVGLength;
68 : friend class DOMSVGLengthList;
69 :
70 : public:
71 0 : SVGAnimatedLengthList() {}
72 :
73 : /**
74 : * Because it's so important that mBaseVal and its DOMSVGLengthList wrapper
75 : * (if any) be kept in sync (see the comment in
76 : * DOMSVGAnimatedLengthList::InternalBaseValListWillChangeTo), this method
77 : * returns a const reference. Only our friend classes may get mutable
78 : * references to mBaseVal.
79 : */
80 0 : const SVGLengthList& GetBaseValue() const {
81 0 : return mBaseVal;
82 : }
83 :
84 : nsresult SetBaseValueString(const nsAString& aValue);
85 :
86 : void ClearBaseValue(PRUint32 aAttrEnum);
87 :
88 0 : const SVGLengthList& GetAnimValue() const {
89 0 : return mAnimVal ? *mAnimVal : mBaseVal;
90 : }
91 :
92 : nsresult SetAnimValue(const SVGLengthList& aValue,
93 : nsSVGElement *aElement,
94 : PRUint32 aAttrEnum);
95 :
96 : void ClearAnimValue(nsSVGElement *aElement,
97 : PRUint32 aAttrEnum);
98 :
99 0 : bool IsAnimating() const {
100 0 : return !!mAnimVal;
101 : }
102 :
103 : /// Callers own the returned nsISMILAttr
104 : nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement, PRUint8 aAttrEnum,
105 : PRUint8 aAxis, bool aCanZeroPadList);
106 :
107 : private:
108 :
109 : // mAnimVal is a pointer to allow us to determine if we're being animated or
110 : // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
111 : // if we're animating is not an option, since that would break animation *to*
112 : // the empty string (<set to="">).
113 :
114 : SVGLengthList mBaseVal;
115 : nsAutoPtr<SVGLengthList> mAnimVal;
116 :
117 : struct SMILAnimatedLengthList : public nsISMILAttr
118 0 : {
119 : public:
120 0 : SMILAnimatedLengthList(SVGAnimatedLengthList* aVal,
121 : nsSVGElement* aSVGElement,
122 : PRUint8 aAttrEnum,
123 : PRUint8 aAxis,
124 : bool aCanZeroPadList)
125 : : mVal(aVal)
126 : , mElement(aSVGElement)
127 : , mAttrEnum(aAttrEnum)
128 : , mAxis(aAxis)
129 0 : , mCanZeroPadList(aCanZeroPadList)
130 0 : {}
131 :
132 : // These will stay alive because a nsISMILAttr only lives as long
133 : // as the Compositing step, and DOM elements don't get a chance to
134 : // die during that.
135 : SVGAnimatedLengthList* mVal;
136 : nsSVGElement* mElement;
137 : PRUint8 mAttrEnum;
138 : PRUint8 mAxis;
139 : bool mCanZeroPadList; // See SVGLengthListAndInfo::CanZeroPadList
140 :
141 : // nsISMILAttr methods
142 : virtual nsresult ValueFromString(const nsAString& aStr,
143 : const nsISMILAnimationElement* aSrcElement,
144 : nsSMILValue& aValue,
145 : bool& aPreventCachingOfSandwich) const;
146 : virtual nsSMILValue GetBaseValue() const;
147 : virtual void ClearAnimValue();
148 : virtual nsresult SetAnimValue(const nsSMILValue& aValue);
149 : };
150 : };
151 :
152 : } // namespace mozilla
153 :
154 : #endif // MOZILLA_SVGANIMATEDLENGTHLIST_H__
|