Bug 1698238 return default dictionary from GetUserMediaRequest#getConstraints() if...
[gecko.git] / dom / svg / SVGAnimatedPreserveAspectRatio.h
blobb8801fc72cebedbc7a5cc5cc51a978f8acb4620c
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_SVGANIMATEDPRESERVEASPECTRATIO_H_
8 #define DOM_SVG_SVGANIMATEDPRESERVEASPECTRATIO_H_
10 #include "nsCycleCollectionParticipant.h"
11 #include "nsError.h"
12 #include "SVGPreserveAspectRatio.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/SMILAttr.h"
15 #include "mozilla/UniquePtr.h"
16 #include "mozilla/dom/SVGElement.h"
18 namespace mozilla {
20 class SMILValue;
22 namespace dom {
23 class DOMSVGAnimatedPreserveAspectRatio;
24 class SVGAnimationElement;
25 } // namespace dom
27 class SVGAnimatedPreserveAspectRatio final {
28 friend class AutoChangePreserveAspectRatioNotifier;
30 public:
31 void Init() {
32 mBaseVal.mAlign =
33 dom::SVGPreserveAspectRatio_Binding::SVG_PRESERVEASPECTRATIO_XMIDYMID;
34 mBaseVal.mMeetOrSlice =
35 dom::SVGPreserveAspectRatio_Binding::SVG_MEETORSLICE_MEET;
36 mAnimVal = mBaseVal;
37 mIsAnimated = false;
38 mIsBaseSet = false;
41 nsresult SetBaseValueString(const nsAString& aValue,
42 dom::SVGElement* aSVGElement, bool aDoSetAttr);
43 void GetBaseValueString(nsAString& aValue) const;
45 void SetBaseValue(const SVGPreserveAspectRatio& aValue,
46 dom::SVGElement* aSVGElement);
47 nsresult SetBaseAlign(uint16_t aAlign, dom::SVGElement* aSVGElement) {
48 if (aAlign < SVG_ALIGN_MIN_VALID || aAlign > SVG_ALIGN_MAX_VALID) {
49 return NS_ERROR_FAILURE;
51 SetBaseValue(SVGPreserveAspectRatio(static_cast<uint8_t>(aAlign),
52 mBaseVal.GetMeetOrSlice()),
53 aSVGElement);
54 return NS_OK;
56 nsresult SetBaseMeetOrSlice(uint16_t aMeetOrSlice,
57 dom::SVGElement* aSVGElement) {
58 if (aMeetOrSlice < SVG_MEETORSLICE_MIN_VALID ||
59 aMeetOrSlice > SVG_MEETORSLICE_MAX_VALID) {
60 return NS_ERROR_FAILURE;
62 SetBaseValue(SVGPreserveAspectRatio(mBaseVal.GetAlign(),
63 static_cast<uint8_t>(aMeetOrSlice)),
64 aSVGElement);
65 return NS_OK;
67 void SetAnimValue(uint64_t aPackedValue, dom::SVGElement* aSVGElement);
69 const SVGPreserveAspectRatio& GetBaseValue() const { return mBaseVal; }
70 const SVGPreserveAspectRatio& GetAnimValue() const { return mAnimVal; }
71 bool IsAnimated() const { return mIsAnimated; }
72 bool IsExplicitlySet() const { return mIsAnimated || mIsBaseSet; }
74 already_AddRefed<dom::DOMSVGAnimatedPreserveAspectRatio>
75 ToDOMAnimatedPreserveAspectRatio(dom::SVGElement* aSVGElement);
76 UniquePtr<SMILAttr> ToSMILAttr(dom::SVGElement* aSVGElement);
78 private:
79 SVGPreserveAspectRatio mAnimVal;
80 SVGPreserveAspectRatio mBaseVal;
81 bool mIsAnimated;
82 bool mIsBaseSet;
84 public:
85 struct SMILPreserveAspectRatio final : public SMILAttr {
86 public:
87 SMILPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
88 dom::SVGElement* aSVGElement)
89 : mVal(aVal), mSVGElement(aSVGElement) {}
91 // These will stay alive because a SMILAttr only lives as long
92 // as the Compositing step, and DOM elements don't get a chance to
93 // die during that.
94 SVGAnimatedPreserveAspectRatio* mVal;
95 dom::SVGElement* mSVGElement;
97 // SMILAttr methods
98 virtual nsresult ValueFromString(
99 const nsAString& aStr, const dom::SVGAnimationElement* aSrcElement,
100 SMILValue& aValue, bool& aPreventCachingOfSandwich) const override;
101 virtual SMILValue GetBaseValue() const override;
102 virtual void ClearAnimValue() override;
103 virtual nsresult SetAnimValue(const SMILValue& aValue) override;
107 namespace dom {
108 class DOMSVGAnimatedPreserveAspectRatio final : public nsWrapperCache {
109 ~DOMSVGAnimatedPreserveAspectRatio();
111 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(
112 DOMSVGAnimatedPreserveAspectRatio)
113 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(
114 DOMSVGAnimatedPreserveAspectRatio)
116 DOMSVGAnimatedPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
117 dom::SVGElement* aSVGElement)
118 : mVal(aVal), mSVGElement(aSVGElement) {}
120 // WebIDL
121 dom::SVGElement* GetParentObject() const { return mSVGElement; }
122 virtual JSObject* WrapObject(JSContext* aCx,
123 JS::Handle<JSObject*> aGivenProto) override;
125 // These aren't weak refs because new objects are returned each time
126 already_AddRefed<DOMSVGPreserveAspectRatio> BaseVal();
127 already_AddRefed<DOMSVGPreserveAspectRatio> AnimVal();
129 protected:
130 // kept alive because it belongs to content:
131 SVGAnimatedPreserveAspectRatio* mVal;
132 RefPtr<dom::SVGElement> mSVGElement;
135 } // namespace dom
136 } // namespace mozilla
138 #endif // DOM_SVG_SVGANIMATEDPRESERVEASPECTRATIO_H_