Bug 1635304 [wpt PR 23392] - Remove erroneous named properties object test, a=testonly
[gecko.git] / dom / svg / SVGAnimatedNumber.h
blobb287ef153296bc121bdcf6a16e36e8461758f56d
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/. */
7 #ifndef mozilla_SVGAnimatedNumber_h
8 #define mozilla_SVGAnimatedNumber_h
10 #include "DOMSVGAnimatedNumber.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsError.h"
13 #include "nsMathUtils.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/FloatingPoint.h"
16 #include "mozilla/SMILAttr.h"
17 #include "mozilla/UniquePtr.h"
18 #include "mozilla/dom/SVGElement.h"
20 namespace mozilla {
22 class SMILValue;
24 namespace dom {
25 class SVGAnimationElement;
26 } // namespace dom
28 class SVGAnimatedNumber {
29 public:
30 typedef mozilla::SMILAttr SMILAttr;
31 typedef mozilla::SMILValue SMILValue;
32 typedef mozilla::dom::SVGElement SVGElement;
34 void Init(uint8_t aAttrEnum = 0xff, float aValue = 0) {
35 mAnimVal = mBaseVal = aValue;
36 mAttrEnum = aAttrEnum;
37 mIsAnimated = false;
38 mIsBaseSet = false;
41 nsresult SetBaseValueString(const nsAString& aValue, SVGElement* aSVGElement);
42 void GetBaseValueString(nsAString& aValue);
44 void SetBaseValue(float aValue, SVGElement* aSVGElement);
45 float GetBaseValue() const { return mBaseVal; }
46 void SetAnimValue(float aValue, SVGElement* aSVGElement);
47 float GetAnimValue() const { return mAnimVal; }
49 // Returns true if the animated value of this number has been explicitly
50 // set (either by animation, or by taking on the base value which has been
51 // explicitly set by markup or a DOM call), false otherwise.
52 // If this returns false, the animated value is still valid, that is,
53 // usable, and represents the default base value of the attribute.
54 bool IsExplicitlySet() const { return mIsAnimated || mIsBaseSet; }
56 already_AddRefed<mozilla::dom::DOMSVGAnimatedNumber> ToDOMAnimatedNumber(
57 SVGElement* aSVGElement);
58 mozilla::UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement);
60 private:
61 float mAnimVal;
62 float mBaseVal;
63 uint8_t mAttrEnum; // element specified tracking for attribute
64 bool mIsAnimated;
65 bool mIsBaseSet;
67 public:
68 // DOM wrapper class for the (DOM)SVGAnimatedNumber interface where the
69 // wrapped class is SVGAnimatedNumber.
70 struct DOMAnimatedNumber final : public mozilla::dom::DOMSVGAnimatedNumber {
71 DOMAnimatedNumber(SVGAnimatedNumber* aVal, SVGElement* aSVGElement)
72 : mozilla::dom::DOMSVGAnimatedNumber(aSVGElement), mVal(aVal) {}
73 virtual ~DOMAnimatedNumber();
75 SVGAnimatedNumber* mVal; // kept alive because it belongs to content
77 virtual float BaseVal() override { return mVal->GetBaseValue(); }
78 virtual void SetBaseVal(float aValue) override {
79 MOZ_ASSERT(mozilla::IsFinite(aValue));
80 mVal->SetBaseValue(aValue, mSVGElement);
83 // Script may have modified animation parameters or timeline -- DOM getters
84 // need to flush any resample requests to reflect these modifications.
85 virtual float AnimVal() override {
86 mSVGElement->FlushAnimations();
87 return mVal->GetAnimValue();
91 struct SMILNumber : public SMILAttr {
92 public:
93 SMILNumber(SVGAnimatedNumber* aVal, SVGElement* aSVGElement)
94 : mVal(aVal), mSVGElement(aSVGElement) {}
96 // These will stay alive because a SMILAttr only lives as long
97 // as the Compositing step, and DOM elements don't get a chance to
98 // die during that.
99 SVGAnimatedNumber* mVal;
100 SVGElement* mSVGElement;
102 // SMILAttr methods
103 virtual nsresult ValueFromString(
104 const nsAString& aStr,
105 const mozilla::dom::SVGAnimationElement* aSrcElement, SMILValue& aValue,
106 bool& aPreventCachingOfSandwich) const override;
107 virtual SMILValue GetBaseValue() const override;
108 virtual void ClearAnimValue() override;
109 virtual nsresult SetAnimValue(const SMILValue& aValue) override;
113 } // namespace mozilla
115 #endif // mozilla_SVGAnimatedNumber_h