1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla SVG Project code.
17 : *
18 : * The Initial Developer of the Original Code is the Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2011
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Brian Birtles <birtles@gmail.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * 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 MOZILLA_SVGANIMATEDTRANSFORMLIST_H__
40 : #define MOZILLA_SVGANIMATEDTRANSFORMLIST_H__
41 :
42 : #include "nsAutoPtr.h"
43 : #include "nsISMILAttr.h"
44 : #include "SVGTransformList.h"
45 :
46 : class nsIAtom;
47 : class nsISMILAnimationElement;
48 : class nsSMILValue;
49 : class nsSVGElement;
50 :
51 : namespace mozilla {
52 :
53 : /**
54 : * Class SVGAnimatedTransformList
55 : *
56 : * This class is very different to the SVG DOM interface of the same name found
57 : * in the SVG specification. This is a lightweight internal class - see
58 : * DOMSVGAnimatedTransformList for the heavier DOM class that wraps instances of
59 : * this class and implements the SVG specification's SVGAnimatedTransformList
60 : * DOM interface.
61 : *
62 : * Except where noted otherwise, this class' methods take care of keeping the
63 : * appropriate DOM wrappers in sync (see the comment in
64 : * DOMSVGAnimatedTransformList::InternalBaseValListWillChangeTo) so that their
65 : * consumers don't need to concern themselves with that.
66 : */
67 : class SVGAnimatedTransformList
68 0 : {
69 : // friends so that they can get write access to mBaseVal
70 : friend class DOMSVGTransform;
71 : friend class DOMSVGTransformList;
72 :
73 : public:
74 0 : SVGAnimatedTransformList() : mIsAttrSet(false) { }
75 :
76 : /**
77 : * Because it's so important that mBaseVal and its DOMSVGTransformList wrapper
78 : * (if any) be kept in sync (see the comment in
79 : * DOMSVGAnimatedTransformList::InternalBaseValListWillChangeTo), this method
80 : * returns a const reference. Only our friend classes may get mutable
81 : * references to mBaseVal.
82 : */
83 0 : const SVGTransformList& GetBaseValue() const {
84 0 : return mBaseVal;
85 : }
86 :
87 : nsresult SetBaseValueString(const nsAString& aValue);
88 :
89 : void ClearBaseValue();
90 :
91 0 : const SVGTransformList& GetAnimValue() const {
92 0 : return mAnimVal ? *mAnimVal : mBaseVal;
93 : }
94 :
95 : nsresult SetAnimValue(const SVGTransformList& aNewAnimValue,
96 : nsSVGElement *aElement);
97 :
98 : void ClearAnimValue(nsSVGElement *aElement);
99 :
100 : bool IsExplicitlySet() const;
101 :
102 0 : bool IsAnimating() const {
103 0 : return !!mAnimVal;
104 : }
105 :
106 : /// Callers own the returned nsISMILAttr
107 : nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);
108 :
109 : private:
110 :
111 : // mAnimVal is a pointer to allow us to determine if we're being animated or
112 : // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
113 : // if we're animating is not an option, since that would break animation *to*
114 : // the empty string (<set to="">).
115 :
116 : SVGTransformList mBaseVal;
117 : nsAutoPtr<SVGTransformList> mAnimVal;
118 : bool mIsAttrSet;
119 :
120 : struct SMILAnimatedTransformList : public nsISMILAttr
121 0 : {
122 : public:
123 0 : SMILAnimatedTransformList(SVGAnimatedTransformList* aVal,
124 : nsSVGElement* aSVGElement)
125 : : mVal(aVal)
126 0 : , mElement(aSVGElement)
127 0 : {}
128 :
129 : // nsISMILAttr methods
130 : virtual nsresult ValueFromString(const nsAString& aStr,
131 : const nsISMILAnimationElement* aSrcElement,
132 : nsSMILValue& aValue,
133 : bool& aPreventCachingOfSandwich) const;
134 : virtual nsSMILValue GetBaseValue() const;
135 : virtual void ClearAnimValue();
136 : virtual nsresult SetAnimValue(const nsSMILValue& aValue);
137 :
138 : protected:
139 : static void ParseValue(const nsAString& aSpec,
140 : const nsIAtom* aTransformType,
141 : nsSMILValue& aResult);
142 : static PRInt32 ParseParameterList(const nsAString& aSpec, float* aVars,
143 : PRInt32 aNVars);
144 :
145 : // These will stay alive because a nsISMILAttr only lives as long
146 : // as the Compositing step, and DOM elements don't get a chance to
147 : // die during that.
148 : SVGAnimatedTransformList* mVal;
149 : nsSVGElement* mElement;
150 : };
151 : };
152 :
153 : } // namespace mozilla
154 :
155 : #endif // MOZILLA_SVGANIMATEDTRANSFORMLIST_H__
|