Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGAnimatedIntegerPair.h
blob41c368cd8c4b5dfd2e9352383342582c6a51afca
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 DOM_SVG_SVGANIMATEDINTEGERPAIR_H_
8 #define DOM_SVG_SVGANIMATEDINTEGERPAIR_H_
10 #include "DOMSVGAnimatedInteger.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsError.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/SMILAttr.h"
15 #include "mozilla/UniquePtr.h"
17 namespace mozilla {
19 class SMILValue;
21 namespace dom {
22 class SVGAnimationElement;
23 class SVGElement;
24 } // namespace dom
26 class SVGAnimatedIntegerPair {
27 public:
28 friend class AutoChangeIntegerPairNotifier;
29 using SVGElement = dom::SVGElement;
31 enum PairIndex { eFirst, eSecond };
33 void Init(uint8_t aAttrEnum = 0xff, int32_t aValue1 = 0,
34 int32_t aValue2 = 0) {
35 mAnimVal[0] = mBaseVal[0] = aValue1;
36 mAnimVal[1] = mBaseVal[1] = aValue2;
37 mAttrEnum = aAttrEnum;
38 mIsAnimated = false;
39 mIsBaseSet = false;
42 nsresult SetBaseValueString(const nsAString& aValue, SVGElement* aSVGElement);
43 void GetBaseValueString(nsAString& aValue) const;
45 void SetBaseValue(int32_t aValue, PairIndex aPairIndex,
46 SVGElement* aSVGElement);
47 void SetBaseValues(int32_t aValue1, int32_t aValue2, SVGElement* aSVGElement);
48 int32_t GetBaseValue(PairIndex aIndex) const {
49 return mBaseVal[aIndex == eFirst ? 0 : 1];
51 void SetAnimValue(const int32_t aValue[2], SVGElement* aSVGElement);
52 int32_t GetAnimValue(PairIndex aIndex) const {
53 return mAnimVal[aIndex == eFirst ? 0 : 1];
56 // Returns true if the animated value of this integer has been explicitly
57 // set (either by animation, or by taking on the base value which has been
58 // explicitly set by markup or a DOM call), false otherwise.
59 // If this returns false, the animated value is still valid, that is,
60 // usable, and represents the default base value of the attribute.
61 bool IsExplicitlySet() const { return mIsAnimated || mIsBaseSet; }
63 already_AddRefed<dom::DOMSVGAnimatedInteger> ToDOMAnimatedInteger(
64 PairIndex aIndex, SVGElement* aSVGElement);
65 UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement);
67 private:
68 int32_t mAnimVal[2];
69 int32_t mBaseVal[2];
70 uint8_t mAttrEnum; // element specified tracking for attribute
71 bool mIsAnimated;
72 bool mIsBaseSet;
74 public:
75 struct DOMAnimatedInteger final : public dom::DOMSVGAnimatedInteger {
76 DOMAnimatedInteger(SVGAnimatedIntegerPair* aVal, PairIndex aIndex,
77 SVGElement* aSVGElement)
78 : dom::DOMSVGAnimatedInteger(aSVGElement), mVal(aVal), mIndex(aIndex) {}
79 virtual ~DOMAnimatedInteger();
81 SVGAnimatedIntegerPair* mVal; // kept alive because it belongs to content
82 PairIndex mIndex; // are we the first or second integer
84 int32_t BaseVal() override { return mVal->GetBaseValue(mIndex); }
85 void SetBaseVal(int32_t aValue) override {
86 mVal->SetBaseValue(aValue, mIndex, mSVGElement);
89 // Script may have modified animation parameters or timeline -- DOM getters
90 // need to flush any resample requests to reflect these modifications.
91 int32_t AnimVal() override {
92 mSVGElement->FlushAnimations();
93 return mVal->GetAnimValue(mIndex);
97 struct SMILIntegerPair : public SMILAttr {
98 public:
99 SMILIntegerPair(SVGAnimatedIntegerPair* aVal, SVGElement* aSVGElement)
100 : mVal(aVal), mSVGElement(aSVGElement) {}
102 // These will stay alive because a SMILAttr only lives as long
103 // as the Compositing step, and DOM elements don't get a chance to
104 // die during that.
105 SVGAnimatedIntegerPair* mVal;
106 SVGElement* mSVGElement;
108 // SMILAttr methods
109 nsresult ValueFromString(const nsAString& aStr,
110 const dom::SVGAnimationElement* aSrcElement,
111 SMILValue& aValue,
112 bool& aPreventCachingOfSandwich) const override;
113 SMILValue GetBaseValue() const override;
114 void ClearAnimValue() override;
115 nsresult SetAnimValue(const SMILValue& aValue) override;
119 } // namespace mozilla
121 #endif // DOM_SVG_SVGANIMATEDINTEGERPAIR_H_