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 Robert Longson.
18 : * Portions created by the Initial Developer are Copyright (C) 2011
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_SVGINTEGERPAIR_H__
38 : #define __NS_SVGINTEGERPAIR_H__
39 :
40 : #include "nsAutoPtr.h"
41 : #include "nsCycleCollectionParticipant.h"
42 : #include "nsError.h"
43 : #include "nsIDOMSVGAnimatedInteger.h"
44 : #include "nsISMILAttr.h"
45 : #include "nsSVGElement.h"
46 :
47 : class nsISMILAnimationElement;
48 : class nsSMILValue;
49 :
50 : class nsSVGIntegerPair
51 : {
52 :
53 : public:
54 : enum PairIndex {
55 : eFirst,
56 : eSecond
57 : };
58 :
59 0 : void Init(PRUint8 aAttrEnum = 0xff, PRInt32 aValue1 = 0, PRInt32 aValue2 = 0) {
60 0 : mAnimVal[0] = mBaseVal[0] = aValue1;
61 0 : mAnimVal[1] = mBaseVal[1] = aValue2;
62 0 : mAttrEnum = aAttrEnum;
63 0 : mIsAnimated = false;
64 0 : mIsBaseSet = false;
65 0 : }
66 :
67 : nsresult SetBaseValueString(const nsAString& aValue,
68 : nsSVGElement *aSVGElement);
69 : void GetBaseValueString(nsAString& aValue) const;
70 :
71 : void SetBaseValue(PRInt32 aValue, PairIndex aIndex, nsSVGElement *aSVGElement);
72 : void SetBaseValues(PRInt32 aValue1, PRInt32 aValue2, nsSVGElement *aSVGElement);
73 0 : PRInt32 GetBaseValue(PairIndex aIndex) const
74 0 : { return mBaseVal[aIndex == eFirst ? 0 : 1]; }
75 : void SetAnimValue(const PRInt32 aValue[2], nsSVGElement *aSVGElement);
76 0 : PRInt32 GetAnimValue(PairIndex aIndex) const
77 0 : { return mAnimVal[aIndex == eFirst ? 0 : 1]; }
78 :
79 : // Returns true if the animated value of this integer has been explicitly
80 : // set (either by animation, or by taking on the base value which has been
81 : // explicitly set by markup or a DOM call), false otherwise.
82 : // If this returns false, the animated value is still valid, that is,
83 : // useable, and represents the default base value of the attribute.
84 0 : bool IsExplicitlySet() const
85 0 : { return mIsAnimated || mIsBaseSet; }
86 :
87 : nsresult ToDOMAnimatedInteger(nsIDOMSVGAnimatedInteger **aResult,
88 : PairIndex aIndex,
89 : nsSVGElement* aSVGElement);
90 : // Returns a new nsISMILAttr object that the caller must delete
91 : nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
92 :
93 : private:
94 :
95 : PRInt32 mAnimVal[2];
96 : PRInt32 mBaseVal[2];
97 : PRUint8 mAttrEnum; // element specified tracking for attribute
98 : bool mIsAnimated;
99 : bool mIsBaseSet;
100 :
101 : public:
102 : struct DOMAnimatedInteger : public nsIDOMSVGAnimatedInteger
103 0 : {
104 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
105 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedInteger)
106 :
107 0 : DOMAnimatedInteger(nsSVGIntegerPair* aVal, PairIndex aIndex, nsSVGElement *aSVGElement)
108 0 : : mVal(aVal), mSVGElement(aSVGElement), mIndex(aIndex) {}
109 :
110 : nsSVGIntegerPair* mVal; // kept alive because it belongs to content
111 : nsRefPtr<nsSVGElement> mSVGElement;
112 : PairIndex mIndex; // are we the first or second integer
113 :
114 0 : NS_IMETHOD GetBaseVal(PRInt32* aResult)
115 0 : { *aResult = mVal->GetBaseValue(mIndex); return NS_OK; }
116 0 : NS_IMETHOD SetBaseVal(PRInt32 aValue)
117 : {
118 0 : mVal->SetBaseValue(aValue, mIndex, mSVGElement);
119 0 : return NS_OK;
120 : }
121 :
122 : // Script may have modified animation parameters or timeline -- DOM getters
123 : // need to flush any resample requests to reflect these modifications.
124 0 : NS_IMETHOD GetAnimVal(PRInt32* aResult)
125 : {
126 0 : mSVGElement->FlushAnimations();
127 0 : *aResult = mVal->GetAnimValue(mIndex);
128 0 : return NS_OK;
129 : }
130 : };
131 :
132 : struct SMILIntegerPair : public nsISMILAttr
133 0 : {
134 : public:
135 0 : SMILIntegerPair(nsSVGIntegerPair* aVal, nsSVGElement* aSVGElement)
136 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
137 :
138 : // These will stay alive because a nsISMILAttr only lives as long
139 : // as the Compositing step, and DOM elements don't get a chance to
140 : // die during that.
141 : nsSVGIntegerPair* mVal;
142 : nsSVGElement* mSVGElement;
143 :
144 : // nsISMILAttr methods
145 : virtual nsresult ValueFromString(const nsAString& aStr,
146 : const nsISMILAnimationElement* aSrcElement,
147 : nsSMILValue& aValue,
148 : bool& aPreventCachingOfSandwich) const;
149 : virtual nsSMILValue GetBaseValue() const;
150 : virtual void ClearAnimValue();
151 : virtual nsresult SetAnimValue(const nsSMILValue& aValue);
152 : };
153 : };
154 :
155 : #endif //__NS_SVGINTEGERPAIR_H__
|