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