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 Brian Birtles.
18 : * Portions created by the Initial Developer are Copyright (C) 2006
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Brian Birtles <birtles@gmail.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef SVGTRANSFORMLISTSMILTYPE_H_
39 : #define SVGTRANSFORMLISTSMILTYPE_H_
40 :
41 : #include "nsISMILType.h"
42 : #include "nsTArray.h"
43 :
44 : class nsSMILValue;
45 :
46 : namespace mozilla {
47 :
48 : class SVGTransform;
49 : class SVGTransformList;
50 : class SVGTransformSMILData;
51 :
52 : ////////////////////////////////////////////////////////////////////////
53 : // SVGTransformListSMILType
54 : //
55 : // Operations for animating an nsSVGTransformList.
56 : //
57 : // This class is confused somewhat by the fact that:
58 : // (i) An <animateTransform> element animates an SVGTransformList
59 : // (ii) BUT <animateTransform> only allows the user to specify animation values
60 : // for an SVGTransform
61 : //
62 : // This may be rectified in a future edition of SVG but for now it means that
63 : // the underlying value of an animation may be something of the form:
64 : //
65 : // rotate(90) scale(2) skewX(50)
66 : //
67 : // BUT the animation values can only ever be SINGLE transform operations such as
68 : //
69 : // rotate(90)
70 : //
71 : // (actually the syntax here is:
72 : // <animateTransform type="rotate" from="0" to="90"...
73 : // OR maybe
74 : // <animateTransform type="rotate" values="0; 90; 30; 50"...
75 : // OR even (with a rotation centre)
76 : // <animateTransform type="rotate" values="0 50 20; 30 50 20; 70 0 0"...)
77 : //
78 : // This has many implications for the number of elements we expect in the
79 : // transform array supplied for each operation.
80 : //
81 : // For example, Add() only ever operates on the values specified on an
82 : // <animateTransform> element and so these values can only ever contain 0 or
83 : // 1 TRANSFORM elements as the syntax doesn't allow more. (A "value" here is
84 : // a single element in the values array such as "0 50 20" above.)
85 : //
86 : // Likewise ComputeDistance() only ever operates within the values specified on
87 : // an <animateTransform> element so similar conditions hold.
88 : //
89 : // However, SandwichAdd() combines with a base value which may contain 0..n
90 : // transforms either because the base value of the attribute specifies a series
91 : // of transforms, e.g.
92 : //
93 : // <circle transform="translate(30) rotate(50)"... >
94 : // <animateTransform.../>
95 : // </circle>
96 : //
97 : // or because several animations target the same attribute and are additive and
98 : // so are simply appended on to the transformation array, e.g.
99 : //
100 : // <circle transform="translate(30)"... >
101 : // <animateTransform type="rotate" additive="sum".../>
102 : // <animateTransform type="scale" additive="sum".../>
103 : // <animateTransform type="skewX" additive="sum".../>
104 : // </circle>
105 : //
106 : // Similar conditions hold for Interpolate() which in cases such as to-animation
107 : // may have use a start-value the base value of the target attribute (which as
108 : // we have seen above can contain 0..n elements) whilst the end-value comes from
109 : // the <animateTransform> and so can only hold 1 transform.
110 : //
111 : class SVGTransformListSMILType : public nsISMILType
112 : {
113 : public:
114 : // Singleton for nsSMILValue objects to hold onto.
115 : static SVGTransformListSMILType sSingleton;
116 :
117 : protected:
118 : // nsISMILType Methods
119 : // -------------------
120 : virtual void Init(nsSMILValue& aValue) const;
121 : virtual void Destroy(nsSMILValue& aValue) const;
122 : virtual nsresult Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const;
123 : virtual bool IsEqual(const nsSMILValue& aLeft,
124 : const nsSMILValue& aRight) const;
125 : virtual nsresult Add(nsSMILValue& aDest,
126 : const nsSMILValue& aValueToAdd,
127 : PRUint32 aCount) const;
128 : virtual nsresult SandwichAdd(nsSMILValue& aDest,
129 : const nsSMILValue& aValueToAdd) const;
130 : virtual nsresult ComputeDistance(const nsSMILValue& aFrom,
131 : const nsSMILValue& aTo,
132 : double& aDistance) const;
133 : virtual nsresult Interpolate(const nsSMILValue& aStartVal,
134 : const nsSMILValue& aEndVal,
135 : double aUnitDistance,
136 : nsSMILValue& aResult) const;
137 :
138 : public:
139 : // Transform array accessors
140 : // -------------------------
141 : static nsresult AppendTransform(const SVGTransformSMILData& aTransform,
142 : nsSMILValue& aValue);
143 : static bool AppendTransforms(const SVGTransformList& aList,
144 : nsSMILValue& aValue);
145 : static bool GetTransforms(const nsSMILValue& aValue,
146 : nsTArray<SVGTransform>& aTransforms);
147 :
148 :
149 : private:
150 : // Private constructor & destructor: prevent instances beyond my singleton,
151 : // and prevent others from deleting my singleton.
152 1464 : SVGTransformListSMILType() {}
153 1487 : ~SVGTransformListSMILType() {}
154 : };
155 :
156 : } // end namespace mozilla
157 :
158 : #endif // SVGLISTTRANSFORMSMILTYPE_H_
|