/src/mozilla-central/dom/svg/SVGPatternElement.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/ArrayUtils.h" |
8 | | |
9 | | #include "nsCOMPtr.h" |
10 | | #include "nsGkAtoms.h" |
11 | | #include "mozilla/dom/SVGAnimatedTransformList.h" |
12 | | #include "mozilla/dom/SVGLengthBinding.h" |
13 | | #include "mozilla/dom/SVGPatternElement.h" |
14 | | #include "mozilla/dom/SVGPatternElementBinding.h" |
15 | | #include "mozilla/dom/SVGUnitTypesBinding.h" |
16 | | |
17 | | NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Pattern) |
18 | | |
19 | | namespace mozilla { |
20 | | namespace dom { |
21 | | |
22 | | using namespace SVGUnitTypes_Binding; |
23 | | |
24 | | JSObject* |
25 | | SVGPatternElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) |
26 | 0 | { |
27 | 0 | return SVGPatternElement_Binding::Wrap(aCx, this, aGivenProto); |
28 | 0 | } |
29 | | |
30 | | //--------------------- Patterns ------------------------ |
31 | | |
32 | | nsSVGElement::LengthInfo SVGPatternElement::sLengthInfo[4] = |
33 | | { |
34 | | { &nsGkAtoms::x, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X }, |
35 | | { &nsGkAtoms::y, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y }, |
36 | | { &nsGkAtoms::width, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X }, |
37 | | { &nsGkAtoms::height, 0, SVGLength_Binding::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y }, |
38 | | }; |
39 | | |
40 | | nsSVGElement::EnumInfo SVGPatternElement::sEnumInfo[2] = |
41 | | { |
42 | | { &nsGkAtoms::patternUnits, |
43 | | sSVGUnitTypesMap, |
44 | | SVG_UNIT_TYPE_OBJECTBOUNDINGBOX |
45 | | }, |
46 | | { &nsGkAtoms::patternContentUnits, |
47 | | sSVGUnitTypesMap, |
48 | | SVG_UNIT_TYPE_USERSPACEONUSE |
49 | | } |
50 | | }; |
51 | | |
52 | | nsSVGElement::StringInfo SVGPatternElement::sStringInfo[2] = |
53 | | { |
54 | | { &nsGkAtoms::href, kNameSpaceID_None, true }, |
55 | | { &nsGkAtoms::href, kNameSpaceID_XLink, true } |
56 | | }; |
57 | | |
58 | | //---------------------------------------------------------------------- |
59 | | // Implementation |
60 | | |
61 | | SVGPatternElement::SVGPatternElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) |
62 | | : SVGPatternElementBase(std::move(aNodeInfo)) |
63 | 0 | { |
64 | 0 | } |
65 | | |
66 | | //---------------------------------------------------------------------- |
67 | | // nsINode method |
68 | | |
69 | | NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPatternElement) |
70 | | |
71 | | //---------------------------------------------------------------------- |
72 | | |
73 | | already_AddRefed<SVGAnimatedRect> |
74 | | SVGPatternElement::ViewBox() |
75 | 0 | { |
76 | 0 | return mViewBox.ToSVGAnimatedRect(this); |
77 | 0 | } |
78 | | |
79 | | already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> |
80 | | SVGPatternElement::PreserveAspectRatio() |
81 | 0 | { |
82 | 0 | return mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(this); |
83 | 0 | } |
84 | | |
85 | | //---------------------------------------------------------------------- |
86 | | |
87 | | already_AddRefed<SVGAnimatedEnumeration> |
88 | | SVGPatternElement::PatternUnits() |
89 | 0 | { |
90 | 0 | return mEnumAttributes[PATTERNUNITS].ToDOMAnimatedEnum(this); |
91 | 0 | } |
92 | | |
93 | | already_AddRefed<SVGAnimatedEnumeration> |
94 | | SVGPatternElement::PatternContentUnits() |
95 | 0 | { |
96 | 0 | return mEnumAttributes[PATTERNCONTENTUNITS].ToDOMAnimatedEnum(this); |
97 | 0 | } |
98 | | |
99 | | already_AddRefed<SVGAnimatedTransformList> |
100 | | SVGPatternElement::PatternTransform() |
101 | 0 | { |
102 | 0 | // We're creating a DOM wrapper, so we must tell GetAnimatedTransformList |
103 | 0 | // to allocate the SVGAnimatedTransformList if it hasn't already done so: |
104 | 0 | return SVGAnimatedTransformList::GetDOMWrapper( |
105 | 0 | GetAnimatedTransformList(DO_ALLOCATE), this); |
106 | 0 | } |
107 | | |
108 | | already_AddRefed<SVGAnimatedLength> |
109 | | SVGPatternElement::X() |
110 | 0 | { |
111 | 0 | return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this); |
112 | 0 | } |
113 | | |
114 | | already_AddRefed<SVGAnimatedLength> |
115 | | SVGPatternElement::Y() |
116 | 0 | { |
117 | 0 | return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this); |
118 | 0 | } |
119 | | |
120 | | already_AddRefed<SVGAnimatedLength> |
121 | | SVGPatternElement::Width() |
122 | 0 | { |
123 | 0 | return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this); |
124 | 0 | } |
125 | | |
126 | | already_AddRefed<SVGAnimatedLength> |
127 | | SVGPatternElement::Height() |
128 | 0 | { |
129 | 0 | return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this); |
130 | 0 | } |
131 | | |
132 | | already_AddRefed<SVGAnimatedString> |
133 | | SVGPatternElement::Href() |
134 | 0 | { |
135 | 0 | return mStringAttributes[HREF].IsExplicitlySet() |
136 | 0 | ? mStringAttributes[HREF].ToDOMAnimatedString(this) |
137 | 0 | : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this); |
138 | 0 | } |
139 | | |
140 | | //---------------------------------------------------------------------- |
141 | | // nsIContent methods |
142 | | |
143 | | NS_IMETHODIMP_(bool) |
144 | | SVGPatternElement::IsAttributeMapped(const nsAtom* name) const |
145 | 0 | { |
146 | 0 | static const MappedAttributeEntry* const map[] = { |
147 | 0 | sColorMap, |
148 | 0 | sFEFloodMap, |
149 | 0 | sFillStrokeMap, |
150 | 0 | sFiltersMap, |
151 | 0 | sFontSpecificationMap, |
152 | 0 | sGradientStopMap, |
153 | 0 | sGraphicsMap, |
154 | 0 | sLightingEffectsMap, |
155 | 0 | sMarkersMap, |
156 | 0 | sTextContentElementsMap, |
157 | 0 | sViewportsMap |
158 | 0 | }; |
159 | 0 |
|
160 | 0 | return FindAttributeDependence(name, map) || |
161 | 0 | SVGPatternElementBase::IsAttributeMapped(name); |
162 | 0 | } |
163 | | |
164 | | //---------------------------------------------------------------------- |
165 | | // nsSVGElement methods |
166 | | |
167 | | nsSVGAnimatedTransformList* |
168 | | SVGPatternElement::GetAnimatedTransformList(uint32_t aFlags) |
169 | 0 | { |
170 | 0 | if (!mPatternTransform && (aFlags & DO_ALLOCATE)) { |
171 | 0 | mPatternTransform = new nsSVGAnimatedTransformList(); |
172 | 0 | } |
173 | 0 | return mPatternTransform; |
174 | 0 | } |
175 | | |
176 | | /* virtual */ bool |
177 | | SVGPatternElement::HasValidDimensions() const |
178 | 0 | { |
179 | 0 | return mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() && |
180 | 0 | mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0 && |
181 | 0 | mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() && |
182 | 0 | mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0; |
183 | 0 | } |
184 | | |
185 | | nsSVGElement::LengthAttributesInfo |
186 | | SVGPatternElement::GetLengthInfo() |
187 | 0 | { |
188 | 0 | return LengthAttributesInfo(mLengthAttributes, sLengthInfo, |
189 | 0 | ArrayLength(sLengthInfo)); |
190 | 0 | } |
191 | | |
192 | | nsSVGElement::EnumAttributesInfo |
193 | | SVGPatternElement::GetEnumInfo() |
194 | 0 | { |
195 | 0 | return EnumAttributesInfo(mEnumAttributes, sEnumInfo, |
196 | 0 | ArrayLength(sEnumInfo)); |
197 | 0 | } |
198 | | |
199 | | nsSVGViewBox * |
200 | | SVGPatternElement::GetViewBox() |
201 | 0 | { |
202 | 0 | return &mViewBox; |
203 | 0 | } |
204 | | |
205 | | SVGAnimatedPreserveAspectRatio * |
206 | | SVGPatternElement::GetPreserveAspectRatio() |
207 | 0 | { |
208 | 0 | return &mPreserveAspectRatio; |
209 | 0 | } |
210 | | |
211 | | nsSVGElement::StringAttributesInfo |
212 | | SVGPatternElement::GetStringInfo() |
213 | 0 | { |
214 | 0 | return StringAttributesInfo(mStringAttributes, sStringInfo, |
215 | 0 | ArrayLength(sStringInfo)); |
216 | 0 | } |
217 | | |
218 | | } // namespace dom |
219 | | } // namespace mozilla |