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 Mozilla SVG Project code.
16 : *
17 : * The Initial Developer of the Original Code is the Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2010
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 MOZILLA_SVGANIMATEDPOINTLIST_H__
38 : #define MOZILLA_SVGANIMATEDPOINTLIST_H__
39 :
40 : #include "nsAutoPtr.h"
41 : #include "nsISMILAttr.h"
42 : #include "SVGPointList.h"
43 :
44 : class nsISMILAnimationElement;
45 : class nsSMILValue;
46 : class nsSVGElement;
47 :
48 : namespace mozilla {
49 :
50 : /**
51 : * Class SVGAnimatedPointList
52 : *
53 : * Despite the fact that no SVGAnimatedPointList interface or objects exist
54 : * in the SVG specification (unlike e.g. SVGAnimated*Length*List), we
55 : * nevertheless have this internal class. (Note that there is an
56 : * SVGAnimatedPoints interface, but that's quite different to
57 : * SVGAnimatedLengthList since it is inherited by elements, as opposed to
58 : * elements having members of that type.) The reason that we have this class is
59 : * to provide a single locked down point of entry to the SVGPointList objects,
60 : * which helps ensure that the DOM wrappers for SVGPointList objects' are
61 : * always kept in sync. This is vitally important (see the comment in
62 : * DOMSVGPointList::InternalListWillChangeTo) and frees consumers from having
63 : * to know or worry about wrappers (or forget about them!) for the most part.
64 : */
65 : class SVGAnimatedPointList
66 0 : {
67 : // friends so that they can get write access to mBaseVal and mAnimVal
68 : friend class DOMSVGPoint;
69 : friend class DOMSVGPointList;
70 :
71 : public:
72 0 : SVGAnimatedPointList() {}
73 :
74 : /**
75 : * Because it's so important that mBaseVal and its DOMSVGPointList wrapper
76 : * (if any) be kept in sync (see the comment in
77 : * DOMSVGPointList::InternalListWillChangeTo), this method returns a const
78 : * reference. Only our friend classes may get mutable references to mBaseVal.
79 : */
80 0 : const SVGPointList& GetBaseValue() const {
81 0 : return mBaseVal;
82 : }
83 :
84 : nsresult SetBaseValueString(const nsAString& aValue);
85 :
86 : void ClearBaseValue();
87 :
88 : /**
89 : * const! See comment for GetBaseValue!
90 : */
91 0 : const SVGPointList& GetAnimValue() const {
92 0 : return mAnimVal ? *mAnimVal : mBaseVal;
93 : }
94 :
95 : nsresult SetAnimValue(const SVGPointList& aValue,
96 : nsSVGElement *aElement);
97 :
98 : void ClearAnimValue(nsSVGElement *aElement);
99 :
100 : /**
101 : * Needed for correct DOM wrapper construction since GetAnimValue may
102 : * actually return the baseVal!
103 : */
104 0 : void *GetBaseValKey() const {
105 0 : return (void*)&mBaseVal;
106 : }
107 0 : void *GetAnimValKey() const {
108 0 : return (void*)&mAnimVal;
109 : }
110 :
111 0 : bool IsAnimating() const {
112 0 : return !!mAnimVal;
113 : }
114 :
115 : /// Callers own the returned nsISMILAttr
116 : nsISMILAttr* ToSMILAttr(nsSVGElement* aElement);
117 :
118 : private:
119 :
120 : // mAnimVal is a pointer to allow us to determine if we're being animated or
121 : // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
122 : // if we're animating is not an option, since that would break animation *to*
123 : // the empty string (<set to="">).
124 :
125 : SVGPointList mBaseVal;
126 : nsAutoPtr<SVGPointList> mAnimVal;
127 :
128 : struct SMILAnimatedPointList : public nsISMILAttr
129 0 : {
130 : public:
131 0 : SMILAnimatedPointList(SVGAnimatedPointList* aVal,
132 : nsSVGElement* aElement)
133 : : mVal(aVal)
134 0 : , mElement(aElement)
135 0 : {}
136 :
137 : // These will stay alive because a nsISMILAttr only lives as long
138 : // as the Compositing step, and DOM elements don't get a chance to
139 : // die during that.
140 : SVGAnimatedPointList *mVal;
141 : nsSVGElement *mElement;
142 :
143 : // nsISMILAttr methods
144 : virtual nsresult ValueFromString(const nsAString& aStr,
145 : const nsISMILAnimationElement* aSrcElement,
146 : nsSMILValue& aValue,
147 : bool& aPreventCachingOfSandwich) const;
148 : virtual nsSMILValue GetBaseValue() const;
149 : virtual void ClearAnimValue();
150 : virtual nsresult SetAnimValue(const nsSMILValue& aValue);
151 : };
152 : };
153 :
154 : } // namespace mozilla
155 :
156 : #endif // MOZILLA_SVGANIMATEDPOINTLIST_H__
|