Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGAnimatedString.h
bloba86e4dec1992a87611c4ba9452674988774756bd
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_SVGANIMATEDSTRING_H_
8 #define DOM_SVG_SVGANIMATEDSTRING_H_
10 #include "nsError.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/SMILAttr.h"
13 #include "mozilla/SVGAnimatedClassOrString.h"
14 #include "mozilla/dom/SVGElement.h"
15 #include "mozilla/UniquePtr.h"
17 namespace mozilla {
19 class SMILValue;
21 namespace dom {
22 class SVGElement;
25 class SVGAnimatedString final : public SVGAnimatedClassOrString {
26 public:
27 using SVGElement = dom::SVGElement;
29 void Init(uint8_t aAttrEnum) {
30 mAnimVal = nullptr;
31 mAttrEnum = aAttrEnum;
32 mIsBaseSet = false;
35 void SetBaseValue(const nsAString& aValue, SVGElement* aSVGElement,
36 bool aDoSetAttr) override;
37 void GetBaseValue(nsAString& aValue,
38 const SVGElement* aSVGElement) const override {
39 aSVGElement->GetStringBaseValue(mAttrEnum, aValue);
42 void SetAnimValue(const nsAString& aValue, SVGElement* aSVGElement);
43 void GetAnimValue(nsAString& aResult,
44 const SVGElement* aSVGElement) const override;
46 // Returns true if the animated value of this string has been explicitly
47 // set (either by animation, or by taking on the base value which has been
48 // explicitly set by markup or a DOM call), false otherwise.
49 // If this returns false, the animated value is still valid, that is,
50 // usable, and represents the default base value of the attribute.
51 bool IsExplicitlySet() const { return !!mAnimVal || mIsBaseSet; }
53 UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement);
55 SVGAnimatedString() = default;
57 SVGAnimatedString& operator=(const SVGAnimatedString& aOther) {
58 mAttrEnum = aOther.mAttrEnum;
59 mIsBaseSet = aOther.mIsBaseSet;
60 if (aOther.mAnimVal) {
61 mAnimVal = MakeUnique<nsString>(*aOther.mAnimVal);
63 return *this;
66 SVGAnimatedString(const SVGAnimatedString& aOther) : SVGAnimatedString() {
67 *this = aOther;
70 private:
71 // FIXME: Should probably use void string rather than UniquePtr<nsString>.
72 UniquePtr<nsString> mAnimVal;
73 uint8_t mAttrEnum = 0; // element specified tracking for attribute
74 bool mIsBaseSet = false;
76 public:
77 struct SMILString : public SMILAttr {
78 public:
79 SMILString(SVGAnimatedString* aVal, SVGElement* aSVGElement)
80 : mVal(aVal), mSVGElement(aSVGElement) {}
82 // These will stay alive because a SMILAttr only lives as long
83 // as the Compositing step, and DOM elements don't get a chance to
84 // die during that.
85 SVGAnimatedString* mVal;
86 SVGElement* mSVGElement;
88 // SMILAttr methods
89 nsresult ValueFromString(const nsAString& aStr,
90 const dom::SVGAnimationElement* aSrcElement,
91 SMILValue& aValue,
92 bool& aPreventCachingOfSandwich) const override;
93 SMILValue GetBaseValue() const override;
94 void ClearAnimValue() override;
95 nsresult SetAnimValue(const SMILValue& aValue) override;
99 } // namespace mozilla
101 #endif // DOM_SVG_SVGANIMATEDSTRING_H_