Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / dom / svg / SVGTextPathElement.cpp
blob05b87f0e68281e86fef4ed82e3e3cb37b2baf1f3
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 #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 "SVGElement.h"
12 #include "nsGkAtoms.h"
13 #include "nsError.h"
15 NS_IMPL_NS_NEW_SVG_ELEMENT(TextPath)
17 namespace mozilla::dom {
19 using namespace SVGTextContentElement_Binding;
20 using namespace SVGTextPathElement_Binding;
22 class DOMSVGAnimatedLength;
24 JSObject* SVGTextPathElement::WrapNode(JSContext* aCx,
25 JS::Handle<JSObject*> aGivenProto) {
26 return SVGTextPathElement_Binding::Wrap(aCx, this, aGivenProto);
29 SVGElement::LengthInfo SVGTextPathElement::sLengthInfo[2] = {
30 // from SVGTextContentElement:
31 {nsGkAtoms::textLength, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
32 SVGContentUtils::XY},
33 // from SVGTextPathElement:
34 {nsGkAtoms::startOffset, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
35 SVGContentUtils::X}};
37 SVGEnumMapping SVGTextPathElement::sMethodMap[] = {
38 {nsGkAtoms::align, TEXTPATH_METHODTYPE_ALIGN},
39 {nsGkAtoms::stretch, TEXTPATH_METHODTYPE_STRETCH},
40 {nullptr, 0}};
42 SVGEnumMapping SVGTextPathElement::sSpacingMap[] = {
43 {nsGkAtoms::_auto, TEXTPATH_SPACINGTYPE_AUTO},
44 {nsGkAtoms::exact, TEXTPATH_SPACINGTYPE_EXACT},
45 {nullptr, 0}};
47 SVGEnumMapping SVGTextPathElement::sSideMap[] = {
48 {nsGkAtoms::left, TEXTPATH_SIDETYPE_LEFT},
49 {nsGkAtoms::right, TEXTPATH_SIDETYPE_RIGHT},
50 {nullptr, 0}};
52 SVGElement::EnumInfo SVGTextPathElement::sEnumInfo[4] = {
53 // from SVGTextContentElement:
54 {nsGkAtoms::lengthAdjust, sLengthAdjustMap, LENGTHADJUST_SPACING},
55 // from SVGTextPathElement:
56 {nsGkAtoms::method, sMethodMap, TEXTPATH_METHODTYPE_ALIGN},
57 {nsGkAtoms::spacing, sSpacingMap, TEXTPATH_SPACINGTYPE_EXACT},
58 {nsGkAtoms::side_, sSideMap, TEXTPATH_SIDETYPE_LEFT}};
60 SVGElement::StringInfo SVGTextPathElement::sStringInfo[2] = {
61 {nsGkAtoms::href, kNameSpaceID_None, true},
62 {nsGkAtoms::href, kNameSpaceID_XLink, true}};
64 //----------------------------------------------------------------------
65 // Implementation
67 SVGTextPathElement::SVGTextPathElement(
68 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
69 : SVGTextPathElementBase(std::move(aNodeInfo)) {}
71 void SVGTextPathElement::HrefAsString(nsAString& aHref) {
72 if (mStringAttributes[SVGTextPathElement::HREF].IsExplicitlySet()) {
73 mStringAttributes[SVGTextPathElement::HREF].GetAnimValue(aHref, this);
74 } else {
75 mStringAttributes[SVGTextPathElement::XLINK_HREF].GetAnimValue(aHref, this);
79 //----------------------------------------------------------------------
80 // nsINode methods
82 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTextPathElement)
84 already_AddRefed<DOMSVGAnimatedString> SVGTextPathElement::Href() {
85 return mStringAttributes[HREF].IsExplicitlySet()
86 ? mStringAttributes[HREF].ToDOMAnimatedString(this)
87 : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
90 //----------------------------------------------------------------------
92 already_AddRefed<DOMSVGAnimatedLength> SVGTextPathElement::StartOffset() {
93 return mLengthAttributes[STARTOFFSET].ToDOMAnimatedLength(this);
96 already_AddRefed<DOMSVGAnimatedEnumeration> SVGTextPathElement::Method() {
97 return mEnumAttributes[METHOD].ToDOMAnimatedEnum(this);
100 already_AddRefed<DOMSVGAnimatedEnumeration> SVGTextPathElement::Spacing() {
101 return mEnumAttributes[SPACING].ToDOMAnimatedEnum(this);
104 already_AddRefed<DOMSVGAnimatedEnumeration> SVGTextPathElement::Side() {
105 return mEnumAttributes[SIDE].ToDOMAnimatedEnum(this);
108 //----------------------------------------------------------------------
109 // SVGElement overrides
111 SVGElement::LengthAttributesInfo SVGTextPathElement::GetLengthInfo() {
112 return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
113 ArrayLength(sLengthInfo));
116 SVGElement::EnumAttributesInfo SVGTextPathElement::GetEnumInfo() {
117 return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
120 SVGElement::StringAttributesInfo SVGTextPathElement::GetStringInfo() {
121 return StringAttributesInfo(mStringAttributes, sStringInfo,
122 ArrayLength(sStringInfo));
125 } // namespace mozilla::dom