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 the Mozilla SVG project.
16 : *
17 : * The Initial Developer of the Original Code is IBM Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 2004
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 of the GNU General Public License Version 2 or later (the "GPL"),
25 : * or 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 __NS_SVGANGLE_H__
38 : #define __NS_SVGANGLE_H__
39 :
40 : #include "nsAutoPtr.h"
41 : #include "nsCycleCollectionParticipant.h"
42 : #include "nsDOMError.h"
43 : #include "nsError.h"
44 : #include "nsIDOMSVGAngle.h"
45 : #include "nsIDOMSVGAnimatedAngle.h"
46 : #include "nsISMILAttr.h"
47 : #include "nsSVGElement.h"
48 :
49 : class nsISMILAnimationElement;
50 : class nsSMILValue;
51 : class nsSVGOrientType;
52 :
53 : class nsSVGAngle
54 : {
55 : friend class DOMSVGAngle;
56 :
57 : public:
58 0 : void Init(PRUint8 aAttrEnum = 0xff,
59 : float aValue = 0,
60 : PRUint8 aUnitType = nsIDOMSVGAngle::SVG_ANGLETYPE_UNSPECIFIED) {
61 0 : mAnimVal = mBaseVal = aValue;
62 0 : mAnimValUnit = mBaseValUnit = aUnitType;
63 0 : mAttrEnum = aAttrEnum;
64 0 : mIsAnimated = false;
65 0 : }
66 :
67 : nsresult SetBaseValueString(const nsAString& aValue,
68 : nsSVGElement *aSVGElement,
69 : bool aDoSetAttr);
70 : void GetBaseValueString(nsAString& aValue) const;
71 : void GetAnimValueString(nsAString& aValue) const;
72 :
73 0 : float GetBaseValue() const
74 0 : { return mBaseVal * GetDegreesPerUnit(mBaseValUnit); }
75 0 : float GetAnimValue() const
76 0 : { return mAnimVal * GetDegreesPerUnit(mAnimValUnit); }
77 :
78 : void SetBaseValue(float aValue, nsSVGElement *aSVGElement, bool aDoSetAttr);
79 : void SetAnimValue(float aValue, PRUint8 aUnit, nsSVGElement *aSVGElement);
80 :
81 0 : PRUint8 GetBaseValueUnit() const { return mBaseValUnit; }
82 : PRUint8 GetAnimValueUnit() const { return mAnimValUnit; }
83 0 : float GetBaseValInSpecifiedUnits() const { return mBaseVal; }
84 : float GetAnimValInSpecifiedUnits() const { return mAnimVal; }
85 :
86 : static nsresult ToDOMSVGAngle(nsIDOMSVGAngle **aResult);
87 : nsresult ToDOMAnimatedAngle(nsIDOMSVGAnimatedAngle **aResult,
88 : nsSVGElement* aSVGElement);
89 : // Returns a new nsISMILAttr object that the caller must delete
90 : nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
91 :
92 : static float GetDegreesPerUnit(PRUint8 aUnit);
93 :
94 : private:
95 :
96 : float mAnimVal;
97 : float mBaseVal;
98 : PRUint8 mAnimValUnit;
99 : PRUint8 mBaseValUnit;
100 : PRUint8 mAttrEnum; // element specified tracking for attribute
101 : bool mIsAnimated;
102 :
103 : void SetBaseValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement);
104 : nsresult NewValueSpecifiedUnits(PRUint16 aUnitType, float aValue,
105 : nsSVGElement *aSVGElement);
106 : nsresult ConvertToSpecifiedUnits(PRUint16 aUnitType, nsSVGElement *aSVGElement);
107 : nsresult ToDOMBaseVal(nsIDOMSVGAngle **aResult, nsSVGElement* aSVGElement);
108 : nsresult ToDOMAnimVal(nsIDOMSVGAngle **aResult, nsSVGElement* aSVGElement);
109 :
110 : public:
111 : struct DOMBaseVal : public nsIDOMSVGAngle
112 0 : {
113 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
114 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMBaseVal)
115 :
116 0 : DOMBaseVal(nsSVGAngle* aVal, nsSVGElement *aSVGElement)
117 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
118 :
119 : nsSVGAngle* mVal; // kept alive because it belongs to mSVGElement
120 : nsRefPtr<nsSVGElement> mSVGElement;
121 :
122 0 : NS_IMETHOD GetUnitType(PRUint16* aResult)
123 0 : { *aResult = mVal->mBaseValUnit; return NS_OK; }
124 :
125 0 : NS_IMETHOD GetValue(float* aResult)
126 0 : { *aResult = mVal->GetBaseValue(); return NS_OK; }
127 0 : NS_IMETHOD SetValue(float aValue)
128 0 : { mVal->SetBaseValue(aValue, mSVGElement, true); return NS_OK; }
129 :
130 0 : NS_IMETHOD GetValueInSpecifiedUnits(float* aResult)
131 0 : { *aResult = mVal->mBaseVal; return NS_OK; }
132 0 : NS_IMETHOD SetValueInSpecifiedUnits(float aValue)
133 0 : { mVal->SetBaseValueInSpecifiedUnits(aValue, mSVGElement);
134 0 : return NS_OK; }
135 :
136 0 : NS_IMETHOD SetValueAsString(const nsAString& aValue)
137 0 : { return mVal->SetBaseValueString(aValue, mSVGElement, true); }
138 0 : NS_IMETHOD GetValueAsString(nsAString& aValue)
139 0 : { mVal->GetBaseValueString(aValue); return NS_OK; }
140 :
141 0 : NS_IMETHOD NewValueSpecifiedUnits(PRUint16 unitType,
142 : float valueInSpecifiedUnits)
143 : { return mVal->NewValueSpecifiedUnits(unitType, valueInSpecifiedUnits,
144 0 : mSVGElement); }
145 :
146 0 : NS_IMETHOD ConvertToSpecifiedUnits(PRUint16 unitType)
147 0 : { return mVal->ConvertToSpecifiedUnits(unitType, mSVGElement); }
148 : };
149 :
150 : struct DOMAnimVal : public nsIDOMSVGAngle
151 0 : {
152 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
153 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimVal)
154 :
155 0 : DOMAnimVal(nsSVGAngle* aVal, nsSVGElement *aSVGElement)
156 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
157 :
158 : nsSVGAngle* mVal; // kept alive because it belongs to mSVGElement
159 : nsRefPtr<nsSVGElement> mSVGElement;
160 :
161 0 : NS_IMETHOD GetUnitType(PRUint16* aResult)
162 0 : { *aResult = mVal->mAnimValUnit; return NS_OK; }
163 :
164 0 : NS_IMETHOD GetValue(float* aResult)
165 0 : { *aResult = mVal->GetAnimValue(); return NS_OK; }
166 0 : NS_IMETHOD SetValue(float aValue)
167 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
168 :
169 0 : NS_IMETHOD GetValueInSpecifiedUnits(float* aResult)
170 0 : { *aResult = mVal->mAnimVal; return NS_OK; }
171 0 : NS_IMETHOD SetValueInSpecifiedUnits(float aValue)
172 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
173 :
174 0 : NS_IMETHOD SetValueAsString(const nsAString& aValue)
175 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
176 0 : NS_IMETHOD GetValueAsString(nsAString& aValue)
177 0 : { mVal->GetAnimValueString(aValue); return NS_OK; }
178 :
179 0 : NS_IMETHOD NewValueSpecifiedUnits(PRUint16 unitType,
180 : float valueInSpecifiedUnits)
181 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
182 :
183 0 : NS_IMETHOD ConvertToSpecifiedUnits(PRUint16 unitType)
184 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
185 : };
186 :
187 : struct DOMAnimatedAngle : public nsIDOMSVGAnimatedAngle
188 0 : {
189 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
190 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedAngle)
191 :
192 0 : DOMAnimatedAngle(nsSVGAngle* aVal, nsSVGElement *aSVGElement)
193 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
194 :
195 : nsSVGAngle* mVal; // kept alive because it belongs to content
196 : nsRefPtr<nsSVGElement> mSVGElement;
197 :
198 0 : NS_IMETHOD GetBaseVal(nsIDOMSVGAngle **aBaseVal)
199 0 : { return mVal->ToDOMBaseVal(aBaseVal, mSVGElement); }
200 :
201 0 : NS_IMETHOD GetAnimVal(nsIDOMSVGAngle **aAnimVal)
202 0 : { return mVal->ToDOMAnimVal(aAnimVal, mSVGElement); }
203 : };
204 :
205 : // We do not currently implemente a SMILAngle struct because in SVG 1.1 the
206 : // only *animatable* attribute that takes an <angle> is 'orient', on the
207 : // 'marker' element, and 'orient' must be special cased since it can also
208 : // take the value 'auto', making it a more complex type.
209 :
210 : struct SMILOrient : public nsISMILAttr
211 0 : {
212 : public:
213 0 : SMILOrient(nsSVGOrientType* aOrientType,
214 : nsSVGAngle* aAngle,
215 : nsSVGElement* aSVGElement)
216 : : mOrientType(aOrientType)
217 : , mAngle(aAngle)
218 0 : , mSVGElement(aSVGElement)
219 0 : {}
220 :
221 : // These will stay alive because a nsISMILAttr only lives as long
222 : // as the Compositing step, and DOM elements don't get a chance to
223 : // die during that.
224 : nsSVGOrientType* mOrientType;
225 : nsSVGAngle* mAngle;
226 : nsSVGElement* mSVGElement;
227 :
228 : // nsISMILAttr methods
229 : virtual nsresult ValueFromString(const nsAString& aStr,
230 : const nsISMILAnimationElement* aSrcElement,
231 : nsSMILValue& aValue,
232 : bool& aPreventCachingOfSandwich) const;
233 : virtual nsSMILValue GetBaseValue() const;
234 : virtual void ClearAnimValue();
235 : virtual nsresult SetAnimValue(const nsSMILValue& aValue);
236 : };
237 : };
238 :
239 : nsresult
240 : NS_NewDOMSVGAngle(nsIDOMSVGAngle** result);
241 :
242 : #endif //__NS_SVGANGLE_H__
|