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) 2007
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 __NS_SVGENUM_H__
38 : #define __NS_SVGENUM_H__
39 :
40 : #include "nsAutoPtr.h"
41 : #include "nsCycleCollectionParticipant.h"
42 : #include "nsError.h"
43 : #include "nsIDOMSVGAnimatedEnum.h"
44 : #include "nsISMILAttr.h"
45 : #include "nsSVGElement.h"
46 :
47 : class nsIAtom;
48 : class nsISMILAnimationElement;
49 : class nsSMILValue;
50 :
51 : typedef PRUint8 nsSVGEnumValue;
52 :
53 : struct nsSVGEnumMapping {
54 : nsIAtom **mKey;
55 : nsSVGEnumValue mVal;
56 : };
57 :
58 : class nsSVGEnum
59 : {
60 : public:
61 0 : void Init(PRUint8 aAttrEnum, PRUint16 aValue) {
62 0 : mAnimVal = mBaseVal = PRUint8(aValue);
63 0 : mAttrEnum = aAttrEnum;
64 0 : mIsAnimated = false;
65 0 : mIsBaseSet = false;
66 0 : }
67 :
68 : nsresult SetBaseValueAtom(const nsIAtom* aValue, nsSVGElement *aSVGElement);
69 : nsIAtom* GetBaseValueAtom(nsSVGElement *aSVGElement);
70 : nsresult SetBaseValue(PRUint16 aValue,
71 : nsSVGElement *aSVGElement);
72 0 : PRUint16 GetBaseValue() const
73 0 : { return mBaseVal; }
74 :
75 : void SetAnimValue(PRUint16 aValue, nsSVGElement *aSVGElement);
76 0 : PRUint16 GetAnimValue() const
77 0 : { return mAnimVal; }
78 0 : bool IsExplicitlySet() const
79 0 : { return mIsAnimated || mIsBaseSet; }
80 :
81 : nsresult ToDOMAnimatedEnum(nsIDOMSVGAnimatedEnumeration **aResult,
82 : nsSVGElement* aSVGElement);
83 : // Returns a new nsISMILAttr object that the caller must delete
84 : nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
85 :
86 : private:
87 : nsSVGEnumValue mAnimVal;
88 : nsSVGEnumValue mBaseVal;
89 : PRUint8 mAttrEnum; // element specified tracking for attribute
90 : bool mIsAnimated;
91 : bool mIsBaseSet;
92 :
93 : nsSVGEnumMapping *GetMapping(nsSVGElement *aSVGElement);
94 :
95 : public:
96 : struct DOMAnimatedEnum : public nsIDOMSVGAnimatedEnumeration
97 0 : {
98 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
99 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedEnum)
100 :
101 0 : DOMAnimatedEnum(nsSVGEnum* aVal, nsSVGElement *aSVGElement)
102 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
103 :
104 : nsSVGEnum *mVal; // kept alive because it belongs to content
105 : nsRefPtr<nsSVGElement> mSVGElement;
106 :
107 0 : NS_IMETHOD GetBaseVal(PRUint16* aResult)
108 0 : { *aResult = mVal->GetBaseValue(); return NS_OK; }
109 0 : NS_IMETHOD SetBaseVal(PRUint16 aValue)
110 0 : { return mVal->SetBaseValue(aValue, mSVGElement); }
111 :
112 : // Script may have modified animation parameters or timeline -- DOM getters
113 : // need to flush any resample requests to reflect these modifications.
114 0 : NS_IMETHOD GetAnimVal(PRUint16* aResult)
115 : {
116 0 : mSVGElement->FlushAnimations();
117 0 : *aResult = mVal->GetAnimValue();
118 0 : return NS_OK;
119 : }
120 : };
121 :
122 : struct SMILEnum : public nsISMILAttr
123 0 : {
124 : public:
125 0 : SMILEnum(nsSVGEnum* aVal, nsSVGElement* aSVGElement)
126 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
127 :
128 : // These will stay alive because a nsISMILAttr only lives as long
129 : // as the Compositing step, and DOM elements don't get a chance to
130 : // die during that.
131 : nsSVGEnum* mVal;
132 : nsSVGElement* mSVGElement;
133 :
134 : // nsISMILAttr methods
135 : virtual nsresult ValueFromString(const nsAString& aStr,
136 : const nsISMILAnimationElement* aSrcElement,
137 : nsSMILValue& aValue,
138 : bool& aPreventCachingOfSandwich) const;
139 : virtual nsSMILValue GetBaseValue() const;
140 : virtual void ClearAnimValue();
141 : virtual nsresult SetAnimValue(const nsSMILValue& aValue);
142 : };
143 : };
144 :
145 : #endif //__NS_SVGENUM_H__
|