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
18 : * Jonathan Watt.
19 : * Portions created by the Initial Developer are Copyright (C) 2004
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Craig Topper <craig.topper@gmail.com> (original author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef __NS_SVGVIEWBOX_H__
40 : #define __NS_SVGVIEWBOX_H__
41 :
42 : #include "nsAutoPtr.h"
43 : #include "nsCycleCollectionParticipant.h"
44 : #include "nsDOMError.h"
45 : #include "nsError.h"
46 : #include "nsIDOMSVGAnimatedRect.h"
47 : #include "nsIDOMSVGRect.h"
48 : #include "nsISMILAttr.h"
49 : #include "nsSVGElement.h"
50 :
51 : class nsISMILAnimationElement;
52 : class nsSMILValue;
53 :
54 : struct nsSVGViewBoxRect
55 : {
56 : float x, y;
57 : float width, height;
58 :
59 0 : nsSVGViewBoxRect() : x(0), y(0), width(0), height(0) {}
60 0 : nsSVGViewBoxRect(float aX, float aY, float aWidth, float aHeight) :
61 0 : x(aX), y(aY), width(aWidth), height(aHeight) {}
62 0 : nsSVGViewBoxRect(const nsSVGViewBoxRect& rhs) :
63 0 : x(rhs.x), y(rhs.y), width(rhs.width), height(rhs.height) {}
64 : bool operator==(const nsSVGViewBoxRect& aOther) const;
65 : };
66 :
67 : class nsSVGViewBox
68 0 : {
69 :
70 : public:
71 :
72 : void Init();
73 :
74 : // Used by element to tell if viewBox is defined
75 0 : bool IsValid() const
76 0 : { return (mHasBaseVal || mAnimVal); }
77 :
78 0 : const nsSVGViewBoxRect& GetBaseValue() const
79 0 : { return mBaseVal; }
80 : void SetBaseValue(float aX, float aY, float aWidth, float aHeight,
81 : nsSVGElement *aSVGElement);
82 :
83 0 : const nsSVGViewBoxRect& GetAnimValue() const
84 0 : { return mAnimVal ? *mAnimVal : mBaseVal; }
85 : void SetAnimValue(float aX, float aY, float aWidth, float aHeight,
86 : nsSVGElement *aSVGElement);
87 :
88 : nsresult SetBaseValueString(const nsAString& aValue,
89 : nsSVGElement *aSVGElement);
90 : void GetBaseValueString(nsAString& aValue) const;
91 :
92 : nsresult ToDOMAnimatedRect(nsIDOMSVGAnimatedRect **aResult,
93 : nsSVGElement *aSVGElement);
94 : // Returns a new nsISMILAttr object that the caller must delete
95 : nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
96 :
97 : private:
98 :
99 : nsSVGViewBoxRect mBaseVal;
100 : nsAutoPtr<nsSVGViewBoxRect> mAnimVal;
101 : bool mHasBaseVal;
102 :
103 : struct DOMBaseVal : public nsIDOMSVGRect
104 0 : {
105 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
106 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMBaseVal)
107 :
108 0 : DOMBaseVal(nsSVGViewBox *aVal, nsSVGElement *aSVGElement)
109 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
110 :
111 : nsSVGViewBox* mVal; // kept alive because it belongs to content
112 : nsRefPtr<nsSVGElement> mSVGElement;
113 :
114 0 : NS_IMETHOD GetX(float *aX)
115 0 : { *aX = mVal->GetBaseValue().x; return NS_OK; }
116 0 : NS_IMETHOD GetY(float *aY)
117 0 : { *aY = mVal->GetBaseValue().y; return NS_OK; }
118 0 : NS_IMETHOD GetWidth(float *aWidth)
119 0 : { *aWidth = mVal->GetBaseValue().width; return NS_OK; }
120 0 : NS_IMETHOD GetHeight(float *aHeight)
121 0 : { *aHeight = mVal->GetBaseValue().height; return NS_OK; }
122 :
123 : NS_IMETHOD SetX(float aX);
124 : NS_IMETHOD SetY(float aY);
125 : NS_IMETHOD SetWidth(float aWidth);
126 : NS_IMETHOD SetHeight(float aHeight);
127 : };
128 :
129 : struct DOMAnimVal : public nsIDOMSVGRect
130 0 : {
131 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
132 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimVal)
133 :
134 0 : DOMAnimVal(nsSVGViewBox *aVal, nsSVGElement *aSVGElement)
135 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
136 :
137 : nsSVGViewBox* mVal; // kept alive because it belongs to content
138 : nsRefPtr<nsSVGElement> mSVGElement;
139 :
140 : // Script may have modified animation parameters or timeline -- DOM getters
141 : // need to flush any resample requests to reflect these modifications.
142 0 : NS_IMETHOD GetX(float *aX)
143 : {
144 0 : mSVGElement->FlushAnimations();
145 0 : *aX = mVal->GetAnimValue().x;
146 0 : return NS_OK;
147 : }
148 0 : NS_IMETHOD GetY(float *aY)
149 : {
150 0 : mSVGElement->FlushAnimations();
151 0 : *aY = mVal->GetAnimValue().y;
152 0 : return NS_OK;
153 : }
154 0 : NS_IMETHOD GetWidth(float *aWidth)
155 : {
156 0 : mSVGElement->FlushAnimations();
157 0 : *aWidth = mVal->GetAnimValue().width;
158 0 : return NS_OK;
159 : }
160 0 : NS_IMETHOD GetHeight(float *aHeight)
161 : {
162 0 : mSVGElement->FlushAnimations();
163 0 : *aHeight = mVal->GetAnimValue().height;
164 0 : return NS_OK;
165 : }
166 :
167 0 : NS_IMETHOD SetX(float aX)
168 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
169 0 : NS_IMETHOD SetY(float aY)
170 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
171 0 : NS_IMETHOD SetWidth(float aWidth)
172 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
173 0 : NS_IMETHOD SetHeight(float aHeight)
174 0 : { return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; }
175 : };
176 :
177 : public:
178 : struct DOMAnimatedRect : public nsIDOMSVGAnimatedRect
179 0 : {
180 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
181 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedRect)
182 :
183 0 : DOMAnimatedRect(nsSVGViewBox *aVal, nsSVGElement *aSVGElement)
184 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
185 :
186 : nsSVGViewBox* mVal; // kept alive because it belongs to content
187 : nsRefPtr<nsSVGElement> mSVGElement;
188 :
189 : NS_IMETHOD GetBaseVal(nsIDOMSVGRect **aResult);
190 : NS_IMETHOD GetAnimVal(nsIDOMSVGRect **aResult);
191 : };
192 :
193 : struct SMILViewBox : public nsISMILAttr
194 0 : {
195 : public:
196 0 : SMILViewBox(nsSVGViewBox* aVal, nsSVGElement* aSVGElement)
197 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
198 :
199 : // These will stay alive because a nsISMILAttr only lives as long
200 : // as the Compositing step, and DOM elements don't get a chance to
201 : // die during that.
202 : nsSVGViewBox* mVal;
203 : nsSVGElement* mSVGElement;
204 :
205 : // nsISMILAttr methods
206 : virtual nsresult ValueFromString(const nsAString& aStr,
207 : const nsISMILAnimationElement* aSrcElement,
208 : nsSMILValue& aValue,
209 : bool& aPreventCachingOfSandwich) const;
210 : virtual nsSMILValue GetBaseValue() const;
211 : virtual void ClearAnimValue();
212 : virtual nsresult SetAnimValue(const nsSMILValue& aValue);
213 : };
214 : };
215 :
216 : #endif // __NS_SVGVIEWBOX_H__
|