/src/mozilla-central/dom/svg/SVGPreserveAspectRatio.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef MOZILLA_CONTENT_SVGPRESERVEASPECTRATIO_H_ |
8 | | #define MOZILLA_CONTENT_SVGPRESERVEASPECTRATIO_H_ |
9 | | |
10 | | #include "mozilla/dom/SVGPreserveAspectRatioBinding.h" |
11 | | #include "mozilla/HashFunctions.h" // for HashGeneric |
12 | | |
13 | | #include "nsWrapperCache.h" |
14 | | #include "nsCycleCollectionParticipant.h" |
15 | | #include "mozilla/ErrorResult.h" |
16 | | #include "nsSVGElement.h" |
17 | | |
18 | | namespace mozilla { |
19 | | |
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; |
26 | | |
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; |
33 | | |
34 | | class SVGAnimatedPreserveAspectRatio; |
35 | | |
36 | | class SVGPreserveAspectRatio final |
37 | | { |
38 | | friend class SVGAnimatedPreserveAspectRatio; |
39 | | public: |
40 | | explicit SVGPreserveAspectRatio() |
41 | | : mAlign(dom::SVGPreserveAspectRatio_Binding::SVG_PRESERVEASPECTRATIO_UNKNOWN) |
42 | | , mMeetOrSlice(dom::SVGPreserveAspectRatio_Binding::SVG_MEETORSLICE_UNKNOWN) |
43 | 0 | {} |
44 | | |
45 | | SVGPreserveAspectRatio(uint16_t aAlign, uint16_t aMeetOrSlice) |
46 | | : mAlign(aAlign) |
47 | | , mMeetOrSlice(aMeetOrSlice) |
48 | 0 | {} |
49 | | |
50 | | static nsresult FromString(const nsAString& aString, |
51 | | SVGPreserveAspectRatio* aValue); |
52 | | void ToString(nsAString& aValueAsString) const; |
53 | | |
54 | | bool operator==(const SVGPreserveAspectRatio& aOther) const; |
55 | | |
56 | 0 | nsresult SetAlign(uint16_t aAlign) { |
57 | 0 | if (aAlign < SVG_ALIGN_MIN_VALID || aAlign > SVG_ALIGN_MAX_VALID) |
58 | 0 | return NS_ERROR_FAILURE; |
59 | 0 | mAlign = static_cast<uint8_t>(aAlign); |
60 | 0 | return NS_OK; |
61 | 0 | } |
62 | | |
63 | 0 | uint16_t GetAlign() const { |
64 | 0 | return mAlign; |
65 | 0 | } |
66 | | |
67 | 0 | nsresult SetMeetOrSlice(uint16_t aMeetOrSlice) { |
68 | 0 | if (aMeetOrSlice < SVG_MEETORSLICE_MIN_VALID || |
69 | 0 | aMeetOrSlice > SVG_MEETORSLICE_MAX_VALID) |
70 | 0 | return NS_ERROR_FAILURE; |
71 | 0 | mMeetOrSlice = static_cast<uint8_t>(aMeetOrSlice); |
72 | 0 | return NS_OK; |
73 | 0 | } |
74 | | |
75 | 0 | uint16_t GetMeetOrSlice() const { |
76 | 0 | return mMeetOrSlice; |
77 | 0 | } |
78 | | |
79 | 0 | PLDHashNumber Hash() const { |
80 | 0 | return HashGeneric(mAlign, mMeetOrSlice); |
81 | 0 | } |
82 | | |
83 | | private: |
84 | | // We can't use enum types here because some compilers fail to pack them. |
85 | | uint8_t mAlign; |
86 | | uint8_t mMeetOrSlice; |
87 | | }; |
88 | | |
89 | | namespace dom { |
90 | | |
91 | | class DOMSVGPreserveAspectRatio final : public nsISupports, |
92 | | public nsWrapperCache |
93 | | { |
94 | | public: |
95 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
96 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGPreserveAspectRatio) |
97 | | |
98 | | DOMSVGPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal, |
99 | | nsSVGElement *aSVGElement, |
100 | | bool aIsBaseValue) |
101 | | : mVal(aVal), mSVGElement(aSVGElement), mIsBaseValue(aIsBaseValue) |
102 | 0 | { |
103 | 0 | } |
104 | | |
105 | | // WebIDL |
106 | | nsSVGElement* GetParentObject() const { return mSVGElement; } |
107 | | virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
108 | | |
109 | | uint16_t Align(); |
110 | | void SetAlign(uint16_t aAlign, ErrorResult& rv); |
111 | | uint16_t MeetOrSlice(); |
112 | | void SetMeetOrSlice(uint16_t aMeetOrSlice, ErrorResult& rv); |
113 | | |
114 | | protected: |
115 | | ~DOMSVGPreserveAspectRatio(); |
116 | | |
117 | | SVGAnimatedPreserveAspectRatio* mVal; // kept alive because it belongs to mSVGElement |
118 | | RefPtr<nsSVGElement> mSVGElement; |
119 | | const bool mIsBaseValue; |
120 | | }; |
121 | | |
122 | | } //namespace dom |
123 | | } //namespace mozilla |
124 | | |
125 | | #endif // MOZILLA_CONTENT_SVGPRESERVEASPECTRATIO_H_ |