Line data Source code
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_SVGANIMATEDNUMBERLIST_H__
8 : #define MOZILLA_SVGANIMATEDNUMBERLIST_H__
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/UniquePtr.h"
12 : #include "nsAutoPtr.h"
13 : #include "nsISMILAttr.h"
14 : #include "SVGNumberList.h"
15 :
16 : class nsSMILValue;
17 : class nsSVGElement;
18 :
19 : namespace mozilla {
20 :
21 : namespace dom {
22 : class SVGAnimationElement;
23 : } // namespace dom
24 :
25 : /**
26 : * Class SVGAnimatedNumberList
27 : *
28 : * This class is very different to the SVG DOM interface of the same name found
29 : * in the SVG specification. This is a lightweight internal class - see
30 : * DOMSVGAnimatedNumberList for the heavier DOM class that wraps instances of
31 : * this class and implements the SVG specification's SVGAnimatedNumberList DOM
32 : * interface.
33 : *
34 : * Except where noted otherwise, this class' methods take care of keeping the
35 : * appropriate DOM wrappers in sync (see the comment in
36 : * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo) so that their
37 : * consumers don't need to concern themselves with that.
38 : */
39 0 : class SVGAnimatedNumberList
40 : {
41 : // friends so that they can get write access to mBaseVal
42 : friend class DOMSVGNumber;
43 : friend class DOMSVGNumberList;
44 :
45 : public:
46 0 : SVGAnimatedNumberList() {}
47 :
48 : /**
49 : * Because it's so important that mBaseVal and its DOMSVGNumberList wrapper
50 : * (if any) be kept in sync (see the comment in
51 : * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo), this method
52 : * returns a const reference. Only our friend classes may get mutable
53 : * references to mBaseVal.
54 : */
55 0 : const SVGNumberList& GetBaseValue() const {
56 0 : return mBaseVal;
57 : }
58 :
59 : nsresult SetBaseValueString(const nsAString& aValue);
60 :
61 : void ClearBaseValue(uint32_t aAttrEnum);
62 :
63 0 : const SVGNumberList& GetAnimValue() const {
64 0 : return mAnimVal ? *mAnimVal : mBaseVal;
65 : }
66 :
67 : nsresult SetAnimValue(const SVGNumberList& aValue,
68 : nsSVGElement *aElement,
69 : uint32_t aAttrEnum);
70 :
71 : void ClearAnimValue(nsSVGElement *aElement,
72 : uint32_t aAttrEnum);
73 :
74 : // Returns true if the animated value of this list has been explicitly
75 : // set (either by animation, or by taking on the base value which has been
76 : // explicitly set by markup or a DOM call), false otherwise.
77 : // If this returns false, the animated value is still valid, that is,
78 : // useable, and represents the default base value of the attribute.
79 0 : bool IsExplicitlySet() const
80 0 : { return !!mAnimVal || mIsBaseSet; }
81 :
82 0 : bool IsAnimating() const {
83 0 : return !!mAnimVal;
84 : }
85 :
86 : UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement,
87 : uint8_t aAttrEnum);
88 :
89 : private:
90 :
91 : // mAnimVal is a pointer to allow us to determine if we're being animated or
92 : // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
93 : // if we're animating is not an option, since that would break animation *to*
94 : // the empty string (<set to="">).
95 :
96 : SVGNumberList mBaseVal;
97 : nsAutoPtr<SVGNumberList> mAnimVal;
98 : bool mIsBaseSet;
99 :
100 0 : struct SMILAnimatedNumberList : public nsISMILAttr
101 : {
102 : public:
103 0 : SMILAnimatedNumberList(SVGAnimatedNumberList* aVal,
104 : nsSVGElement* aSVGElement,
105 : uint8_t aAttrEnum)
106 0 : : mVal(aVal)
107 : , mElement(aSVGElement)
108 0 : , mAttrEnum(aAttrEnum)
109 0 : {}
110 :
111 : // These will stay alive because a nsISMILAttr only lives as long
112 : // as the Compositing step, and DOM elements don't get a chance to
113 : // die during that.
114 : SVGAnimatedNumberList* mVal;
115 : nsSVGElement* mElement;
116 : uint8_t mAttrEnum;
117 :
118 : // nsISMILAttr methods
119 : virtual nsresult ValueFromString(const nsAString& aStr,
120 : const dom::SVGAnimationElement* aSrcElement,
121 : nsSMILValue& aValue,
122 : bool& aPreventCachingOfSandwich) const override;
123 : virtual nsSMILValue GetBaseValue() const override;
124 : virtual void ClearAnimValue() override;
125 : virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
126 : };
127 : };
128 :
129 : } // namespace mozilla
130 :
131 : #endif // MOZILLA_SVGANIMATEDNUMBERLIST_H__
|