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_SVGANIMATEDVIEWBOX_H_
8 #define DOM_SVG_SVGANIMATEDVIEWBOX_H_
10 #include "nsCycleCollectionParticipant.h"
12 #include "SVGAttrTearoffTable.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/SMILAttr.h"
15 #include "mozilla/UniquePtr.h"
16 #include "mozilla/dom/SVGAnimatedRect.h"
24 class SVGAnimationElement
;
33 SVGViewBox() : x(0.0), y(0.0), width(0.0), height(0.0), none(true) {}
34 SVGViewBox(float aX
, float aY
, float aWidth
, float aHeight
)
35 : x(aX
), y(aY
), width(aWidth
), height(aHeight
), none(false) {}
36 bool operator==(const SVGViewBox
& aOther
) const;
38 static nsresult
FromString(const nsAString
& aStr
, SVGViewBox
* aViewBox
);
41 class SVGAnimatedViewBox
{
43 friend class AutoChangeViewBoxNotifier
;
44 using SVGElement
= dom::SVGElement
;
46 SVGAnimatedViewBox
& operator=(const SVGAnimatedViewBox
& aOther
) {
47 mBaseVal
= aOther
.mBaseVal
;
48 if (aOther
.mAnimVal
) {
49 mAnimVal
= MakeUnique
<SVGViewBox
>(*aOther
.mAnimVal
);
51 mHasBaseVal
= aOther
.mHasBaseVal
;
58 * Returns true if the corresponding "viewBox" attribute defined a rectangle
59 * with finite values and nonnegative width/height.
60 * Returns false if the viewBox was set to an invalid
61 * string, or if any of the four rect values were too big to store in a
62 * float, or the width/height are negative.
67 * Returns true if the corresponding "viewBox" attribute either defined a
68 * rectangle with finite values or the special "none" value.
70 bool IsExplicitlySet() const {
71 if (mAnimVal
|| mHasBaseVal
) {
72 const SVGViewBox
& rect
= GetAnimValue();
73 return rect
.none
|| (rect
.width
>= 0 && rect
.height
>= 0);
78 const SVGViewBox
& GetBaseValue() const { return mBaseVal
; }
79 void SetBaseValue(const SVGViewBox
& aRect
, SVGElement
* aSVGElement
);
80 const SVGViewBox
& GetAnimValue() const {
81 return mAnimVal
? *mAnimVal
: mBaseVal
;
83 void SetAnimValue(const SVGViewBox
& aRect
, SVGElement
* aSVGElement
);
85 nsresult
SetBaseValueString(const nsAString
& aValue
, SVGElement
* aSVGElement
,
87 void GetBaseValueString(nsAString
& aValue
) const;
89 already_AddRefed
<dom::SVGAnimatedRect
> ToSVGAnimatedRect(
90 SVGElement
* aSVGElement
);
92 already_AddRefed
<dom::SVGRect
> ToDOMBaseVal(SVGElement
* aSVGElement
);
94 already_AddRefed
<dom::SVGRect
> ToDOMAnimVal(SVGElement
* aSVGElement
);
96 UniquePtr
<SMILAttr
> ToSMILAttr(SVGElement
* aSVGElement
);
100 UniquePtr
<SVGViewBox
> mAnimVal
;
104 struct SMILViewBox
: public SMILAttr
{
106 SMILViewBox(SVGAnimatedViewBox
* aVal
, SVGElement
* aSVGElement
)
107 : mVal(aVal
), mSVGElement(aSVGElement
) {}
109 // These will stay alive because a SMILAttr only lives as long
110 // as the Compositing step, and DOM elements don't get a chance to
112 SVGAnimatedViewBox
* mVal
;
113 SVGElement
* mSVGElement
;
116 nsresult
ValueFromString(const nsAString
& aStr
,
117 const dom::SVGAnimationElement
* aSrcElement
,
119 bool& aPreventCachingOfSandwich
) const override
;
120 SMILValue
GetBaseValue() const override
;
121 void ClearAnimValue() override
;
122 nsresult
SetAnimValue(const SMILValue
& aValue
) override
;
125 static SVGAttrTearoffTable
<SVGAnimatedViewBox
, dom::SVGAnimatedRect
>
126 sSVGAnimatedRectTearoffTable
;
129 } // namespace mozilla
131 #endif // DOM_SVG_SVGANIMATEDVIEWBOX_H_