Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGAnimatedNumberList.h
blob2bc0438ad512563888aace7dd4346a0f86ddcbb9
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_SVGANIMATEDNUMBERLIST_H_
8 #define DOM_SVG_SVGANIMATEDNUMBERLIST_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/SMILAttr.h"
12 #include "mozilla/UniquePtr.h"
13 #include "SVGNumberList.h"
15 namespace mozilla {
17 class SMILValue;
19 namespace dom {
20 class SVGAnimationElement;
21 class SVGElement;
22 } // namespace dom
24 /**
25 * Class SVGAnimatedNumberList
27 * This class is very different to the SVG DOM interface of the same name found
28 * in the SVG specification. This is a lightweight internal class - see
29 * DOMSVGAnimatedNumberList for the heavier DOM class that wraps instances of
30 * this class and implements the SVG specification's SVGAnimatedNumberList DOM
31 * interface.
33 * Except where noted otherwise, this class' methods take care of keeping the
34 * appropriate DOM wrappers in sync (see the comment in
35 * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo) so that their
36 * consumers don't need to concern themselves with that.
38 class SVGAnimatedNumberList {
39 // friends so that they can get write access to mBaseVal
40 friend class dom::DOMSVGNumber;
41 friend class dom::DOMSVGNumberList;
43 public:
44 SVGAnimatedNumberList() = default;
46 SVGAnimatedNumberList& operator=(const SVGAnimatedNumberList& aOther) {
47 mIsBaseSet = aOther.mIsBaseSet;
48 mBaseVal = aOther.mBaseVal;
49 if (aOther.mAnimVal) {
50 mAnimVal = MakeUnique<SVGNumberList>(*aOther.mAnimVal);
52 return *this;
55 /**
56 * Because it's so important that mBaseVal and its DOMSVGNumberList wrapper
57 * (if any) be kept in sync (see the comment in
58 * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo), this method
59 * returns a const reference. Only our friend classes may get mutable
60 * references to mBaseVal.
62 const SVGNumberList& GetBaseValue() const { return mBaseVal; }
64 nsresult SetBaseValueString(const nsAString& aValue);
66 void ClearBaseValue(uint32_t aAttrEnum);
68 const SVGNumberList& GetAnimValue() const {
69 return mAnimVal ? *mAnimVal : mBaseVal;
72 nsresult SetAnimValue(const SVGNumberList& aNewAnimValue,
73 dom::SVGElement* aElement, uint32_t aAttrEnum);
75 void ClearAnimValue(dom::SVGElement* aElement, uint32_t aAttrEnum);
77 // Returns true if the animated value of this list has been explicitly
78 // set (either by animation, or by taking on the base value which has been
79 // explicitly set by markup or a DOM call), false otherwise.
80 // If this returns false, the animated value is still valid, that is,
81 // usable, and represents the default base value of the attribute.
82 bool IsExplicitlySet() const { return !!mAnimVal || mIsBaseSet; }
84 bool IsAnimating() const { return !!mAnimVal; }
86 UniquePtr<SMILAttr> ToSMILAttr(dom::SVGElement* aSVGElement,
87 uint8_t aAttrEnum);
89 private:
90 // mAnimVal is a pointer to allow us to determine if we're being animated or
91 // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
92 // if we're animating is not an option, since that would break animation *to*
93 // the empty string (<set to="">).
95 SVGNumberList mBaseVal;
96 UniquePtr<SVGNumberList> mAnimVal;
97 bool mIsBaseSet = false;
99 struct SMILAnimatedNumberList : public SMILAttr {
100 public:
101 SMILAnimatedNumberList(SVGAnimatedNumberList* aVal,
102 dom::SVGElement* aSVGElement, uint8_t aAttrEnum)
103 : mVal(aVal), mElement(aSVGElement), mAttrEnum(aAttrEnum) {}
105 // These will stay alive because a SMILAttr only lives as long
106 // as the Compositing step, and DOM elements don't get a chance to
107 // die during that.
108 SVGAnimatedNumberList* mVal;
109 dom::SVGElement* mElement;
110 uint8_t mAttrEnum;
112 // SMILAttr methods
113 nsresult ValueFromString(const nsAString& aStr,
114 const dom::SVGAnimationElement* aSrcElement,
115 SMILValue& aValue,
116 bool& aPreventCachingOfSandwich) const override;
117 SMILValue GetBaseValue() const override;
118 void ClearAnimValue() override;
119 nsresult SetAnimValue(const SMILValue& aValue) override;
123 } // namespace mozilla
125 #endif // DOM_SVG_SVGANIMATEDNUMBERLIST_H_