Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / svg / SVGPreserveAspectRatio.h
blob7bcc724e072ef559731eae13bd78f6497cfd20b2
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_SVGPRESERVEASPECTRATIO_H_
8 #define DOM_SVG_SVGPRESERVEASPECTRATIO_H_
10 #include "mozilla/dom/SVGPreserveAspectRatioBinding.h"
11 #include "mozilla/HashFunctions.h" // for HashGeneric
13 #include "nsWrapperCache.h"
14 #include "nsCycleCollectionParticipant.h"
15 #include "mozilla/dom/SVGElement.h"
17 namespace mozilla {
18 class ErrorResult;
20 // These constants represent the range of valid enum values for the <align>
21 // parameter. They exclude the sentinel _UNKNOWN value.
22 const uint16_t SVG_ALIGN_MIN_VALID =
23 dom::SVGPreserveAspectRatio_Binding::SVG_PRESERVEASPECTRATIO_NONE;
24 const uint16_t SVG_ALIGN_MAX_VALID =
25 dom::SVGPreserveAspectRatio_Binding::SVG_PRESERVEASPECTRATIO_XMAXYMAX;
27 // These constants represent the range of valid enum values for the
28 // <meetOrSlice> parameter. They exclude the sentinel _UNKNOWN value.
29 const uint16_t SVG_MEETORSLICE_MIN_VALID =
30 dom::SVGPreserveAspectRatio_Binding::SVG_MEETORSLICE_MEET;
31 const uint16_t SVG_MEETORSLICE_MAX_VALID =
32 dom::SVGPreserveAspectRatio_Binding::SVG_MEETORSLICE_SLICE;
34 class SVGAnimatedPreserveAspectRatio;
36 class SVGPreserveAspectRatio final {
37 friend class SVGAnimatedPreserveAspectRatio;
39 public:
40 explicit SVGPreserveAspectRatio()
41 : mAlign(dom::SVGPreserveAspectRatio_Binding::
42 SVG_PRESERVEASPECTRATIO_UNKNOWN),
43 mMeetOrSlice(
44 dom::SVGPreserveAspectRatio_Binding::SVG_MEETORSLICE_UNKNOWN) {}
46 SVGPreserveAspectRatio(uint8_t aAlign, uint8_t aMeetOrSlice)
47 : mAlign(aAlign), mMeetOrSlice(aMeetOrSlice) {}
49 static nsresult FromString(const nsAString& aString,
50 SVGPreserveAspectRatio* aValue);
51 void ToString(nsAString& aValueAsString) const;
53 bool operator==(const SVGPreserveAspectRatio& aOther) const;
55 nsresult SetAlign(uint16_t aAlign) {
56 if (aAlign < SVG_ALIGN_MIN_VALID || aAlign > SVG_ALIGN_MAX_VALID)
57 return NS_ERROR_FAILURE;
58 mAlign = static_cast<uint8_t>(aAlign);
59 return NS_OK;
62 auto GetAlign() const { return mAlign; }
64 nsresult SetMeetOrSlice(uint16_t aMeetOrSlice) {
65 if (aMeetOrSlice < SVG_MEETORSLICE_MIN_VALID ||
66 aMeetOrSlice > SVG_MEETORSLICE_MAX_VALID)
67 return NS_ERROR_FAILURE;
68 mMeetOrSlice = static_cast<uint8_t>(aMeetOrSlice);
69 return NS_OK;
72 auto GetMeetOrSlice() const { return mMeetOrSlice; }
74 PLDHashNumber Hash() const { return HashGeneric(mAlign, mMeetOrSlice); }
76 private:
77 // We can't use enum types here because some compilers fail to pack them.
78 uint8_t mAlign;
79 uint8_t mMeetOrSlice;
82 namespace dom {
84 class DOMSVGPreserveAspectRatio final : public nsWrapperCache {
85 public:
86 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMSVGPreserveAspectRatio)
87 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMSVGPreserveAspectRatio)
89 DOMSVGPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
90 SVGElement* aSVGElement, bool aIsBaseValue)
91 : mVal(aVal), mSVGElement(aSVGElement), mIsBaseValue(aIsBaseValue) {}
93 // WebIDL
94 SVGElement* GetParentObject() const { return mSVGElement; }
95 JSObject* WrapObject(JSContext* aCx,
96 JS::Handle<JSObject*> aGivenProto) override;
98 uint16_t Align();
99 void SetAlign(uint16_t aAlign, ErrorResult& rv);
100 uint16_t MeetOrSlice();
101 void SetMeetOrSlice(uint16_t aMeetOrSlice, ErrorResult& rv);
103 protected:
104 ~DOMSVGPreserveAspectRatio();
106 SVGAnimatedPreserveAspectRatio*
107 mVal; // kept alive because it belongs to mSVGElement
108 RefPtr<SVGElement> mSVGElement;
109 const bool mIsBaseValue;
112 } // namespace dom
113 } // namespace mozilla
115 #endif // DOM_SVG_SVGPRESERVEASPECTRATIO_H_