/src/mozilla-central/dom/svg/SVGGradientElement.cpp
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 | | #include "mozilla/dom/SVGGradientElement.h" |
8 | | |
9 | | #include "mozilla/ArrayUtils.h" |
10 | | #include "mozilla/dom/SVGAnimatedTransformList.h" |
11 | | #include "mozilla/dom/SVGGradientElementBinding.h" |
12 | | #include "mozilla/dom/SVGRadialGradientElementBinding.h" |
13 | | #include "mozilla/dom/SVGLengthBinding.h" |
14 | | #include "mozilla/dom/SVGLinearGradientElementBinding.h" |
15 | | #include "mozilla/dom/SVGUnitTypesBinding.h" |
16 | | #include "nsCOMPtr.h" |
17 | | #include "nsGkAtoms.h" |
18 | | #include "nsSVGElement.h" |
19 | | |
20 | | NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(LinearGradient) |
21 | | NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(RadialGradient) |
22 | | |
23 | | namespace mozilla { |
24 | | namespace dom { |
25 | | |
26 | | using namespace SVGGradientElement_Binding; |
27 | | using namespace SVGUnitTypes_Binding; |
28 | | |
29 | | //--------------------- Gradients------------------------ |
30 | | |
31 | | nsSVGEnumMapping SVGGradientElement::sSpreadMethodMap[] = { |
32 | | {&nsGkAtoms::pad, SVG_SPREADMETHOD_PAD}, |
33 | | {&nsGkAtoms::reflect, SVG_SPREADMETHOD_REFLECT}, |
34 | | {&nsGkAtoms::repeat, SVG_SPREADMETHOD_REPEAT}, |
35 | | {nullptr, 0} |
36 | | }; |
37 | | |
38 | | nsSVGElement::EnumInfo SVGGradientElement::sEnumInfo[2] = |
39 | | { |
40 | | { &nsGkAtoms::gradientUnits, |
41 | | sSVGUnitTypesMap, |
42 | | SVG_UNIT_TYPE_OBJECTBOUNDINGBOX |
43 | | }, |
44 | | { &nsGkAtoms::spreadMethod, |
45 | | sSpreadMethodMap, |
46 | | SVG_SPREADMETHOD_PAD |
47 | | } |
48 | | }; |
49 | | |
50 | | nsSVGElement::StringInfo SVGGradientElement::sStringInfo[2] = |
51 | | { |
52 | | { &nsGkAtoms::href, kNameSpaceID_None, true }, |
53 | | { &nsGkAtoms::href, kNameSpaceID_XLink, true } |
54 | | }; |
55 | | |
56 | | //---------------------------------------------------------------------- |
57 | | // Implementation |
58 | | |
59 | | SVGGradientElement::SVGGradientElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) |
60 | | : SVGGradientElementBase(std::move(aNodeInfo)) |
61 | 0 | { |
62 | 0 | } |
63 | | |
64 | | //---------------------------------------------------------------------- |
65 | | // nsSVGElement methods |
66 | | |
67 | | nsSVGElement::EnumAttributesInfo |
68 | | SVGGradientElement::GetEnumInfo() |
69 | 0 | { |
70 | 0 | return EnumAttributesInfo(mEnumAttributes, sEnumInfo, |
71 | 0 | ArrayLength(sEnumInfo)); |
72 | 0 | } |
73 | | |
74 | | nsSVGElement::StringAttributesInfo |
75 | | SVGGradientElement::GetStringInfo() |
76 | 0 | { |
77 | 0 | return StringAttributesInfo(mStringAttributes, sStringInfo, |
78 | 0 | ArrayLength(sStringInfo)); |
79 | 0 | } |
80 | | |
81 | | already_AddRefed<SVGAnimatedEnumeration> |
82 | | SVGGradientElement::GradientUnits() |
83 | 0 | { |
84 | 0 | return mEnumAttributes[GRADIENTUNITS].ToDOMAnimatedEnum(this); |
85 | 0 | } |
86 | | |
87 | | already_AddRefed<SVGAnimatedTransformList> |
88 | | SVGGradientElement::GradientTransform() |
89 | 0 | { |
90 | 0 | // We're creating a DOM wrapper, so we must tell GetAnimatedTransformList |
91 | 0 | // to allocate the SVGAnimatedTransformList if it hasn't already done so: |
92 | 0 | return SVGAnimatedTransformList::GetDOMWrapper( |
93 | 0 | GetAnimatedTransformList(DO_ALLOCATE), this); |
94 | 0 | } |
95 | | |
96 | | already_AddRefed<SVGAnimatedEnumeration> |
97 | | SVGGradientElement::SpreadMethod() |
98 | 0 | { |
99 | 0 | return mEnumAttributes[SPREADMETHOD].ToDOMAnimatedEnum(this); |
100 | 0 | } |
101 | | |
102 | | already_AddRefed<SVGAnimatedString> |
103 | | SVGGradientElement::Href() |
104 | 0 | { |
105 | 0 | return mStringAttributes[HREF].IsExplicitlySet() |
106 | 0 | ? mStringAttributes[HREF].ToDOMAnimatedString(this) |
107 | 0 | : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this); |
108 | 0 | } |
109 | | |
110 | | //---------------------------------------------------------------------- |
111 | | // nsIContent methods |
112 | | |
113 | | NS_IMETHODIMP_(bool) |
114 | | SVGGradientElement::IsAttributeMapped(const nsAtom* name) const |
115 | 0 | { |
116 | 0 | static const MappedAttributeEntry* const map[] = { |
117 | 0 | sColorMap, |
118 | 0 | sGradientStopMap |
119 | 0 | }; |
120 | 0 |
|
121 | 0 | return FindAttributeDependence(name, map) || |
122 | 0 | SVGGradientElementBase::IsAttributeMapped(name); |
123 | 0 | } |
124 | | |
125 | | //---------------------Linear Gradients------------------------ |
126 | | |
127 | | JSObject* |
128 | | SVGLinearGradientElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
129 | 0 | { |
130 | 0 | return SVGLinearGradientElement_Binding::Wrap(aCx, this, aGivenProto); |
131 | 0 | } |
132 | | |
133 | | nsSVGElement::LengthInfo SVGLinearGradientElement::sLengthInfo[4] = |
134 | | { |
135 | | { &nsGkAtoms::x1, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X }, |
136 | | { &nsGkAtoms::y1, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y }, |
137 | | { &nsGkAtoms::x2, 100, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X }, |
138 | | { &nsGkAtoms::y2, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y }, |
139 | | }; |
140 | | |
141 | | //---------------------------------------------------------------------- |
142 | | // Implementation |
143 | | |
144 | | SVGLinearGradientElement::SVGLinearGradientElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) |
145 | | : SVGLinearGradientElementBase(std::move(aNodeInfo)) |
146 | 0 | { |
147 | 0 | } |
148 | | |
149 | | //---------------------------------------------------------------------- |
150 | | // nsINode methods |
151 | | |
152 | | NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGLinearGradientElement) |
153 | | |
154 | | //---------------------------------------------------------------------- |
155 | | |
156 | | already_AddRefed<SVGAnimatedLength> |
157 | | SVGLinearGradientElement::X1() |
158 | 0 | { |
159 | 0 | return mLengthAttributes[ATTR_X1].ToDOMAnimatedLength(this); |
160 | 0 | } |
161 | | |
162 | | already_AddRefed<SVGAnimatedLength> |
163 | | SVGLinearGradientElement::Y1() |
164 | 0 | { |
165 | 0 | return mLengthAttributes[ATTR_Y1].ToDOMAnimatedLength(this); |
166 | 0 | } |
167 | | |
168 | | already_AddRefed<SVGAnimatedLength> |
169 | | SVGLinearGradientElement::X2() |
170 | 0 | { |
171 | 0 | return mLengthAttributes[ATTR_X2].ToDOMAnimatedLength(this); |
172 | 0 | } |
173 | | |
174 | | already_AddRefed<SVGAnimatedLength> |
175 | | SVGLinearGradientElement::Y2() |
176 | 0 | { |
177 | 0 | return mLengthAttributes[ATTR_Y2].ToDOMAnimatedLength(this); |
178 | 0 | } |
179 | | |
180 | | //---------------------------------------------------------------------- |
181 | | // nsSVGElement methods |
182 | | |
183 | | nsSVGAnimatedTransformList* |
184 | | SVGGradientElement::GetAnimatedTransformList(uint32_t aFlags) |
185 | 0 | { |
186 | 0 | if (!mGradientTransform && (aFlags & DO_ALLOCATE)) { |
187 | 0 | mGradientTransform = new nsSVGAnimatedTransformList(); |
188 | 0 | } |
189 | 0 | return mGradientTransform; |
190 | 0 | } |
191 | | |
192 | | nsSVGElement::LengthAttributesInfo |
193 | | SVGLinearGradientElement::GetLengthInfo() |
194 | 0 | { |
195 | 0 | return LengthAttributesInfo(mLengthAttributes, sLengthInfo, |
196 | 0 | ArrayLength(sLengthInfo)); |
197 | 0 | } |
198 | | |
199 | | //-------------------------- Radial Gradients ---------------------------- |
200 | | |
201 | | JSObject* |
202 | | SVGRadialGradientElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
203 | 0 | { |
204 | 0 | return SVGRadialGradientElement_Binding::Wrap(aCx, this, aGivenProto); |
205 | 0 | } |
206 | | |
207 | | nsSVGElement::LengthInfo SVGRadialGradientElement::sLengthInfo[6] = |
208 | | { |
209 | | { &nsGkAtoms::cx, 50, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X }, |
210 | | { &nsGkAtoms::cy, 50, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y }, |
211 | | { &nsGkAtoms::r, 50, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::XY }, |
212 | | { &nsGkAtoms::fx, 50, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X }, |
213 | | { &nsGkAtoms::fy, 50, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y }, |
214 | | { &nsGkAtoms::fr, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::XY }, |
215 | | }; |
216 | | |
217 | | //---------------------------------------------------------------------- |
218 | | // Implementation |
219 | | |
220 | | SVGRadialGradientElement::SVGRadialGradientElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) |
221 | | : SVGRadialGradientElementBase(std::move(aNodeInfo)) |
222 | 0 | { |
223 | 0 | } |
224 | | |
225 | | //---------------------------------------------------------------------- |
226 | | // nsINode methods |
227 | | |
228 | | NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGRadialGradientElement) |
229 | | |
230 | | //---------------------------------------------------------------------- |
231 | | |
232 | | already_AddRefed<SVGAnimatedLength> |
233 | | SVGRadialGradientElement::Cx() |
234 | 0 | { |
235 | 0 | return mLengthAttributes[ATTR_CX].ToDOMAnimatedLength(this); |
236 | 0 | } |
237 | | |
238 | | already_AddRefed<SVGAnimatedLength> |
239 | | SVGRadialGradientElement::Cy() |
240 | 0 | { |
241 | 0 | return mLengthAttributes[ATTR_CY].ToDOMAnimatedLength(this); |
242 | 0 | } |
243 | | |
244 | | already_AddRefed<SVGAnimatedLength> |
245 | | SVGRadialGradientElement::R() |
246 | 0 | { |
247 | 0 | return mLengthAttributes[ATTR_R].ToDOMAnimatedLength(this); |
248 | 0 | } |
249 | | |
250 | | already_AddRefed<SVGAnimatedLength> |
251 | | SVGRadialGradientElement::Fx() |
252 | 0 | { |
253 | 0 | return mLengthAttributes[ATTR_FX].ToDOMAnimatedLength(this); |
254 | 0 | } |
255 | | |
256 | | already_AddRefed<SVGAnimatedLength> |
257 | | SVGRadialGradientElement::Fy() |
258 | 0 | { |
259 | 0 | return mLengthAttributes[ATTR_FY].ToDOMAnimatedLength(this); |
260 | 0 | } |
261 | | |
262 | | already_AddRefed<SVGAnimatedLength> |
263 | | SVGRadialGradientElement::Fr() |
264 | 0 | { |
265 | 0 | return mLengthAttributes[ATTR_FR].ToDOMAnimatedLength(this); |
266 | 0 | } |
267 | | |
268 | | //---------------------------------------------------------------------- |
269 | | // nsSVGElement methods |
270 | | |
271 | | nsSVGElement::LengthAttributesInfo |
272 | | SVGRadialGradientElement::GetLengthInfo() |
273 | 0 | { |
274 | 0 | return LengthAttributesInfo(mLengthAttributes, sLengthInfo, |
275 | 0 | ArrayLength(sLengthInfo)); |
276 | 0 | } |
277 | | |
278 | | } // namespace dom |
279 | | } // namespace mozilla |