/src/mozilla-central/dom/svg/nsSVGAnimatedTransformList.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_SVGANIMATEDTRANSFORMLIST_H__ |
8 | | #define MOZILLA_SVGANIMATEDTRANSFORMLIST_H__ |
9 | | |
10 | | #include "mozilla/Attributes.h" |
11 | | #include "mozilla/UniquePtr.h" |
12 | | #include "nsAutoPtr.h" |
13 | | #include "nsISMILAttr.h" |
14 | | #include "SVGTransformList.h" |
15 | | |
16 | | class nsAtom; |
17 | | class nsSMILValue; |
18 | | class nsSVGElement; |
19 | | |
20 | | namespace mozilla { |
21 | | |
22 | | namespace dom { |
23 | | class SVGAnimationElement; |
24 | | class SVGTransform; |
25 | | } // namespace dom |
26 | | |
27 | | /** |
28 | | * Class nsSVGAnimatedTransformList |
29 | | * |
30 | | * This class is very different to the SVG DOM interface of the same name found |
31 | | * in the SVG specification. This is a lightweight internal class - see |
32 | | * SVGAnimatedTransformList for the heavier DOM class that wraps instances of |
33 | | * this class and implements the SVG specification's SVGAnimatedTransformList |
34 | | * DOM interface. |
35 | | * |
36 | | * Except where noted otherwise, this class' methods take care of keeping the |
37 | | * appropriate DOM wrappers in sync (see the comment in |
38 | | * SVGAnimatedTransformList::InternalBaseValListWillChangeTo) so that their |
39 | | * consumers don't need to concern themselves with that. |
40 | | */ |
41 | | class nsSVGAnimatedTransformList |
42 | | { |
43 | | // friends so that they can get write access to mBaseVal |
44 | | friend class dom::SVGTransform; |
45 | | friend class DOMSVGTransformList; |
46 | | |
47 | | public: |
48 | | nsSVGAnimatedTransformList() |
49 | | : mIsAttrSet(false), |
50 | 0 | mRequiresFrameReconstruction(true) { } |
51 | | |
52 | | /** |
53 | | * Because it's so important that mBaseVal and its DOMSVGTransformList wrapper |
54 | | * (if any) be kept in sync (see the comment in |
55 | | * SVGAnimatedTransformList::InternalBaseValListWillChangeTo), this method |
56 | | * returns a const reference. Only our friend classes may get mutable |
57 | | * references to mBaseVal. |
58 | | */ |
59 | | const SVGTransformList& GetBaseValue() const { |
60 | | return mBaseVal; |
61 | | } |
62 | | |
63 | | nsresult SetBaseValue(const SVGTransformList& aValue, |
64 | | nsSVGElement* aSVGElement); |
65 | | |
66 | | nsresult SetBaseValueString(const nsAString& aValue, |
67 | | nsSVGElement* aSVGElement); |
68 | | |
69 | | void ClearBaseValue(); |
70 | | |
71 | | const SVGTransformList& GetAnimValue() const { |
72 | | return mAnimVal ? *mAnimVal : mBaseVal; |
73 | | } |
74 | | |
75 | | nsresult SetAnimValue(const SVGTransformList& aNewAnimValue, |
76 | | nsSVGElement *aElement); |
77 | | |
78 | | void ClearAnimValue(nsSVGElement *aElement); |
79 | | |
80 | | /** |
81 | | * Returns true if the corresponding transform attribute is set (or animated) |
82 | | * to a valid value. Unlike HasTransform it will return true for an empty |
83 | | * transform. |
84 | | */ |
85 | | bool IsExplicitlySet() const; |
86 | | |
87 | | /** |
88 | | * Returns true if the corresponding transform attribute is set (or animated) |
89 | | * to a valid value, such that we have at least one transform in our list. |
90 | | * Returns false otherwise (e.g. if the transform attribute is missing or empty |
91 | | * or invalid). |
92 | | */ |
93 | | bool HasTransform() const |
94 | 0 | { return (mAnimVal && !mAnimVal->IsEmpty()) || !mBaseVal.IsEmpty(); } |
95 | | |
96 | | bool IsAnimating() const { |
97 | | return !!mAnimVal; |
98 | | } |
99 | | |
100 | | /** |
101 | | * Returns true if we need to reconstruct the frame of the element associated |
102 | | * with this transform list because the stacking context has changed. |
103 | | * |
104 | | * (This is used as part of an optimization in |
105 | | * SVGTransformableElement::GetAttributeChangeHint. That function reports an |
106 | | * inexpensive nsChangeHint when a transform has just modified -- but this |
107 | | * accessor lets it detect cases where the "modification" is actually adding |
108 | | * a transform where we previously had none. These cases require a more |
109 | | * thorough nsChangeHint.) |
110 | | */ |
111 | 0 | bool RequiresFrameReconstruction() const { |
112 | 0 | return mRequiresFrameReconstruction; |
113 | 0 | } |
114 | | |
115 | | mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement); |
116 | | |
117 | | private: |
118 | | |
119 | | // mAnimVal is a pointer to allow us to determine if we're being animated or |
120 | | // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check |
121 | | // if we're animating is not an option, since that would break animation *to* |
122 | | // the empty string (<set to="">). |
123 | | |
124 | | SVGTransformList mBaseVal; |
125 | | nsAutoPtr<SVGTransformList> mAnimVal; |
126 | | bool mIsAttrSet; |
127 | | // (See documentation for accessor, RequiresFrameReconstruction.) |
128 | | bool mRequiresFrameReconstruction; |
129 | | |
130 | | struct SMILAnimatedTransformList : public nsISMILAttr |
131 | | { |
132 | | public: |
133 | | SMILAnimatedTransformList(nsSVGAnimatedTransformList* aVal, |
134 | | nsSVGElement* aSVGElement) |
135 | | : mVal(aVal) |
136 | | , mElement(aSVGElement) |
137 | 0 | {} |
138 | | |
139 | | // nsISMILAttr methods |
140 | | virtual nsresult ValueFromString(const nsAString& aStr, |
141 | | const dom::SVGAnimationElement* aSrcElement, |
142 | | nsSMILValue& aValue, |
143 | | bool& aPreventCachingOfSandwich) const override; |
144 | | virtual nsSMILValue GetBaseValue() const override; |
145 | | virtual void ClearAnimValue() override; |
146 | | virtual nsresult SetAnimValue(const nsSMILValue& aValue) override; |
147 | | |
148 | | protected: |
149 | | static void ParseValue(const nsAString& aSpec, |
150 | | const nsAtom* aTransformType, |
151 | | nsSMILValue& aResult); |
152 | | static int32_t ParseParameterList(const nsAString& aSpec, float* aVars, |
153 | | int32_t aNVars); |
154 | | |
155 | | // These will stay alive because a nsISMILAttr only lives as long |
156 | | // as the Compositing step, and DOM elements don't get a chance to |
157 | | // die during that. |
158 | | nsSVGAnimatedTransformList* mVal; |
159 | | nsSVGElement* mElement; |
160 | | }; |
161 | | }; |
162 | | |
163 | | } // namespace mozilla |
164 | | |
165 | | #endif // MOZILLA_SVGANIMATEDTRANSFORMLIST_H__ |