/src/mozilla-central/dom/svg/SVGTextPathElement.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/SVGTextPathElement.h" |
8 | | #include "mozilla/dom/SVGLengthBinding.h" |
9 | | #include "mozilla/dom/SVGTextContentElementBinding.h" |
10 | | #include "mozilla/dom/SVGTextPathElementBinding.h" |
11 | | #include "nsSVGElement.h" |
12 | | #include "nsGkAtoms.h" |
13 | | #include "nsError.h" |
14 | | |
15 | | NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(TextPath) |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | | using namespace SVGTextContentElement_Binding; |
21 | | using namespace SVGTextPathElement_Binding; |
22 | | |
23 | | class SVGAnimatedLength; |
24 | | |
25 | | JSObject* |
26 | | SVGTextPathElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) |
27 | 0 | { |
28 | 0 | return SVGTextPathElement_Binding::Wrap(aCx, this, aGivenProto); |
29 | 0 | } |
30 | | |
31 | | nsSVGElement::LengthInfo SVGTextPathElement::sLengthInfo[2] = |
32 | | { |
33 | | // from SVGTextContentElement: |
34 | | { &nsGkAtoms::textLength, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::XY }, |
35 | | // from SVGTextPathElement: |
36 | | { &nsGkAtoms::startOffset, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X } |
37 | | }; |
38 | | |
39 | | nsSVGEnumMapping SVGTextPathElement::sMethodMap[] = { |
40 | | {&nsGkAtoms::align, TEXTPATH_METHODTYPE_ALIGN}, |
41 | | {&nsGkAtoms::stretch, TEXTPATH_METHODTYPE_STRETCH}, |
42 | | {nullptr, 0} |
43 | | }; |
44 | | |
45 | | nsSVGEnumMapping SVGTextPathElement::sSpacingMap[] = { |
46 | | {&nsGkAtoms::_auto, TEXTPATH_SPACINGTYPE_AUTO}, |
47 | | {&nsGkAtoms::exact, TEXTPATH_SPACINGTYPE_EXACT}, |
48 | | {nullptr, 0} |
49 | | }; |
50 | | |
51 | | nsSVGEnumMapping SVGTextPathElement::sSideMap[] = { |
52 | | {&nsGkAtoms::left, TEXTPATH_SIDETYPE_LEFT}, |
53 | | {&nsGkAtoms::right, TEXTPATH_SIDETYPE_RIGHT}, |
54 | | {nullptr, 0} |
55 | | }; |
56 | | |
57 | | nsSVGElement::EnumInfo SVGTextPathElement::sEnumInfo[4] = |
58 | | { |
59 | | // from SVGTextContentElement: |
60 | | { &nsGkAtoms::lengthAdjust, |
61 | | sLengthAdjustMap, |
62 | | LENGTHADJUST_SPACING |
63 | | }, |
64 | | // from SVGTextPathElement: |
65 | | { &nsGkAtoms::method, |
66 | | sMethodMap, |
67 | | TEXTPATH_METHODTYPE_ALIGN |
68 | | }, |
69 | | { &nsGkAtoms::spacing, |
70 | | sSpacingMap, |
71 | | TEXTPATH_SPACINGTYPE_EXACT |
72 | | }, |
73 | | { &nsGkAtoms::side_, |
74 | | sSideMap, |
75 | | TEXTPATH_SIDETYPE_LEFT |
76 | | } |
77 | | }; |
78 | | |
79 | | nsSVGElement::StringInfo SVGTextPathElement::sStringInfo[2] = |
80 | | { |
81 | | { &nsGkAtoms::href, kNameSpaceID_None, true }, |
82 | | { &nsGkAtoms::href, kNameSpaceID_XLink, true } |
83 | | }; |
84 | | |
85 | | //---------------------------------------------------------------------- |
86 | | // Implementation |
87 | | |
88 | | SVGTextPathElement::SVGTextPathElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) |
89 | | : SVGTextPathElementBase(std::move(aNodeInfo)) |
90 | 0 | { |
91 | 0 | } |
92 | | |
93 | | void |
94 | | SVGTextPathElement::HrefAsString(nsAString& aHref) |
95 | 0 | { |
96 | 0 | if (mStringAttributes[SVGTextPathElement::HREF].IsExplicitlySet()) { |
97 | 0 | mStringAttributes[SVGTextPathElement::HREF] |
98 | 0 | .GetAnimValue(aHref, this); |
99 | 0 | } else { |
100 | 0 | mStringAttributes[SVGTextPathElement::XLINK_HREF] |
101 | 0 | .GetAnimValue(aHref, this); |
102 | 0 | } |
103 | 0 | } |
104 | | |
105 | | //---------------------------------------------------------------------- |
106 | | // nsINode methods |
107 | | |
108 | | NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTextPathElement) |
109 | | |
110 | | already_AddRefed<SVGAnimatedString> |
111 | | SVGTextPathElement::Href() |
112 | 0 | { |
113 | 0 | return mStringAttributes[HREF].IsExplicitlySet() |
114 | 0 | ? mStringAttributes[HREF].ToDOMAnimatedString(this) |
115 | 0 | : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this); |
116 | 0 | } |
117 | | |
118 | | //---------------------------------------------------------------------- |
119 | | |
120 | | already_AddRefed<SVGAnimatedLength> |
121 | | SVGTextPathElement::StartOffset() |
122 | 0 | { |
123 | 0 | return mLengthAttributes[STARTOFFSET].ToDOMAnimatedLength(this); |
124 | 0 | } |
125 | | |
126 | | already_AddRefed<SVGAnimatedEnumeration> |
127 | | SVGTextPathElement::Method() |
128 | 0 | { |
129 | 0 | return mEnumAttributes[METHOD].ToDOMAnimatedEnum(this); |
130 | 0 | } |
131 | | |
132 | | already_AddRefed<SVGAnimatedEnumeration> |
133 | | SVGTextPathElement::Spacing() |
134 | 0 | { |
135 | 0 | return mEnumAttributes[SPACING].ToDOMAnimatedEnum(this); |
136 | 0 | } |
137 | | |
138 | | already_AddRefed<SVGAnimatedEnumeration> |
139 | | SVGTextPathElement::Side() |
140 | 0 | { |
141 | 0 | return mEnumAttributes[SIDE].ToDOMAnimatedEnum(this); |
142 | 0 | } |
143 | | |
144 | | //---------------------------------------------------------------------- |
145 | | // nsIContent methods |
146 | | |
147 | | NS_IMETHODIMP_(bool) |
148 | | SVGTextPathElement::IsAttributeMapped(const nsAtom* name) const |
149 | 0 | { |
150 | 0 | static const MappedAttributeEntry* const map[] = { |
151 | 0 | sColorMap, |
152 | 0 | sFillStrokeMap, |
153 | 0 | sFontSpecificationMap, |
154 | 0 | sGraphicsMap, |
155 | 0 | sTextContentElementsMap |
156 | 0 | }; |
157 | 0 |
|
158 | 0 | return FindAttributeDependence(name, map) || |
159 | 0 | SVGTextPathElementBase::IsAttributeMapped(name); |
160 | 0 | } |
161 | | |
162 | | //---------------------------------------------------------------------- |
163 | | // nsSVGElement overrides |
164 | | |
165 | | nsSVGElement::LengthAttributesInfo |
166 | | SVGTextPathElement::GetLengthInfo() |
167 | 0 | { |
168 | 0 | return LengthAttributesInfo(mLengthAttributes, sLengthInfo, |
169 | 0 | ArrayLength(sLengthInfo)); |
170 | 0 | } |
171 | | |
172 | | nsSVGElement::EnumAttributesInfo |
173 | | SVGTextPathElement::GetEnumInfo() |
174 | 0 | { |
175 | 0 | return EnumAttributesInfo(mEnumAttributes, sEnumInfo, |
176 | 0 | ArrayLength(sEnumInfo)); |
177 | 0 | } |
178 | | |
179 | | nsSVGElement::StringAttributesInfo |
180 | | SVGTextPathElement::GetStringInfo() |
181 | 0 | { |
182 | 0 | return StringAttributesInfo(mStringAttributes, sStringInfo, |
183 | 0 | ArrayLength(sStringInfo)); |
184 | 0 | } |
185 | | |
186 | | } // namespace dom |
187 | | } // namespace mozilla |