/src/mozilla-central/dom/svg/nsSVGString.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 __NS_SVGSTRING_H__ |
8 | | #define __NS_SVGSTRING_H__ |
9 | | |
10 | | #include "nsAutoPtr.h" |
11 | | #include "nsError.h" |
12 | | #include "nsSVGElement.h" |
13 | | #include "mozilla/Attributes.h" |
14 | | #include "mozilla/dom/SVGAnimatedString.h" |
15 | | #include "mozilla/UniquePtr.h" |
16 | | |
17 | | class nsSVGString |
18 | | { |
19 | | |
20 | | public: |
21 | 0 | void Init(uint8_t aAttrEnum) { |
22 | 0 | mAnimVal = nullptr; |
23 | 0 | mAttrEnum = aAttrEnum; |
24 | 0 | mIsBaseSet = false; |
25 | 0 | } |
26 | | |
27 | | void SetBaseValue(const nsAString& aValue, |
28 | | nsSVGElement *aSVGElement, |
29 | | bool aDoSetAttr); |
30 | | void GetBaseValue(nsAString& aValue, const nsSVGElement *aSVGElement) const |
31 | 0 | { aSVGElement->GetStringBaseValue(mAttrEnum, aValue); } |
32 | | |
33 | | void SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement); |
34 | | void GetAnimValue(nsAString& aValue, const nsSVGElement *aSVGElement) const; |
35 | | |
36 | | // Returns true if the animated value of this string has been explicitly |
37 | | // set (either by animation, or by taking on the base value which has been |
38 | | // explicitly set by markup or a DOM call), false otherwise. |
39 | | // If this returns false, the animated value is still valid, that is, |
40 | | // usable, and represents the default base value of the attribute. |
41 | | bool IsExplicitlySet() const |
42 | 0 | { return !!mAnimVal || mIsBaseSet; } |
43 | | |
44 | | already_AddRefed<mozilla::dom::SVGAnimatedString> |
45 | | ToDOMAnimatedString(nsSVGElement* aSVGElement); |
46 | | |
47 | | mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement *aSVGElement); |
48 | | |
49 | | private: |
50 | | nsAutoPtr<nsString> mAnimVal; |
51 | | uint8_t mAttrEnum; // element specified tracking for attribute |
52 | | bool mIsBaseSet; |
53 | | |
54 | | public: |
55 | | struct DOMAnimatedString final : public mozilla::dom::SVGAnimatedString |
56 | | { |
57 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
58 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMAnimatedString) |
59 | | |
60 | | DOMAnimatedString(nsSVGString* aVal, nsSVGElement* aSVGElement) |
61 | | : mozilla::dom::SVGAnimatedString(aSVGElement) |
62 | | , mVal(aVal) |
63 | 0 | {} |
64 | | |
65 | | nsSVGString* mVal; // kept alive because it belongs to content |
66 | | |
67 | | void GetBaseVal(nsAString & aResult) override |
68 | 0 | { |
69 | 0 | mVal->GetBaseValue(aResult, mSVGElement); |
70 | 0 | } |
71 | | |
72 | | void SetBaseVal(const nsAString & aValue) override |
73 | 0 | { |
74 | 0 | mVal->SetBaseValue(aValue, mSVGElement, true); |
75 | 0 | } |
76 | | |
77 | | void GetAnimVal(nsAString & aResult) override |
78 | 0 | { |
79 | 0 | mSVGElement->FlushAnimations(); |
80 | 0 | mVal->GetAnimValue(aResult, mSVGElement); |
81 | 0 | } |
82 | | |
83 | | private: |
84 | | virtual ~DOMAnimatedString(); |
85 | | }; |
86 | | struct SMILString : public nsISMILAttr |
87 | | { |
88 | | public: |
89 | | SMILString(nsSVGString *aVal, nsSVGElement *aSVGElement) |
90 | 0 | : mVal(aVal), mSVGElement(aSVGElement) {} |
91 | | |
92 | | // These will stay alive because a nsISMILAttr only lives as long |
93 | | // as the Compositing step, and DOM elements don't get a chance to |
94 | | // die during that. |
95 | | nsSVGString* mVal; |
96 | | nsSVGElement* mSVGElement; |
97 | | |
98 | | // nsISMILAttr methods |
99 | | virtual nsresult ValueFromString(const nsAString& aStr, |
100 | | const mozilla::dom::SVGAnimationElement *aSrcElement, |
101 | | nsSMILValue& aValue, |
102 | | bool& aPreventCachingOfSandwich) const override; |
103 | | virtual nsSMILValue GetBaseValue() const override; |
104 | | virtual void ClearAnimValue() override; |
105 | | virtual nsresult SetAnimValue(const nsSMILValue& aValue) override; |
106 | | }; |
107 | | }; |
108 | | #endif //__NS_SVGSTRING_H__ |