SVGTextPathElement.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/dom/SVGTextPathElement.h"
  6. #include "mozilla/dom/SVGTextPathElementBinding.h"
  7. #include "nsSVGElement.h"
  8. #include "nsGkAtoms.h"
  9. #include "nsError.h"
  10. NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(TextPath)
  11. namespace mozilla {
  12. namespace dom {
  13. class SVGAnimatedLength;
  14. JSObject*
  15. SVGTextPathElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
  16. {
  17. return SVGTextPathElementBinding::Wrap(aCx, this, aGivenProto);
  18. }
  19. nsSVGElement::LengthInfo SVGTextPathElement::sLengthInfo[2] =
  20. {
  21. // from SVGTextContentElement:
  22. { &nsGkAtoms::textLength, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::XY },
  23. // from SVGTextPathElement:
  24. { &nsGkAtoms::startOffset, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X }
  25. };
  26. nsSVGEnumMapping SVGTextPathElement::sMethodMap[] = {
  27. {&nsGkAtoms::align, TEXTPATH_METHODTYPE_ALIGN},
  28. {&nsGkAtoms::stretch, TEXTPATH_METHODTYPE_STRETCH},
  29. {nullptr, 0}
  30. };
  31. nsSVGEnumMapping SVGTextPathElement::sSpacingMap[] = {
  32. {&nsGkAtoms::_auto, TEXTPATH_SPACINGTYPE_AUTO},
  33. {&nsGkAtoms::exact, TEXTPATH_SPACINGTYPE_EXACT},
  34. {nullptr, 0}
  35. };
  36. nsSVGElement::EnumInfo SVGTextPathElement::sEnumInfo[3] =
  37. {
  38. // from SVGTextContentElement:
  39. { &nsGkAtoms::lengthAdjust,
  40. sLengthAdjustMap,
  41. SVG_LENGTHADJUST_SPACING
  42. },
  43. // from SVGTextPathElement:
  44. { &nsGkAtoms::method,
  45. sMethodMap,
  46. TEXTPATH_METHODTYPE_ALIGN
  47. },
  48. { &nsGkAtoms::spacing,
  49. sSpacingMap,
  50. TEXTPATH_SPACINGTYPE_EXACT
  51. }
  52. };
  53. nsSVGElement::StringInfo SVGTextPathElement::sStringInfo[2] =
  54. {
  55. { &nsGkAtoms::href, kNameSpaceID_None, true },
  56. { &nsGkAtoms::href, kNameSpaceID_XLink, true }
  57. };
  58. //----------------------------------------------------------------------
  59. // Implementation
  60. SVGTextPathElement::SVGTextPathElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
  61. : SVGTextPathElementBase(aNodeInfo)
  62. {
  63. }
  64. //----------------------------------------------------------------------
  65. // nsIDOMNode methods
  66. NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTextPathElement)
  67. already_AddRefed<SVGAnimatedString>
  68. SVGTextPathElement::Href()
  69. {
  70. return mStringAttributes[HREF].IsExplicitlySet()
  71. ? mStringAttributes[HREF].ToDOMAnimatedString(this)
  72. : mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
  73. }
  74. //----------------------------------------------------------------------
  75. already_AddRefed<SVGAnimatedLength>
  76. SVGTextPathElement::StartOffset()
  77. {
  78. return mLengthAttributes[STARTOFFSET].ToDOMAnimatedLength(this);
  79. }
  80. already_AddRefed<SVGAnimatedEnumeration>
  81. SVGTextPathElement::Method()
  82. {
  83. return mEnumAttributes[METHOD].ToDOMAnimatedEnum(this);
  84. }
  85. already_AddRefed<SVGAnimatedEnumeration>
  86. SVGTextPathElement::Spacing()
  87. {
  88. return mEnumAttributes[SPACING].ToDOMAnimatedEnum(this);
  89. }
  90. //----------------------------------------------------------------------
  91. // nsIContent methods
  92. NS_IMETHODIMP_(bool)
  93. SVGTextPathElement::IsAttributeMapped(const nsIAtom* name) const
  94. {
  95. static const MappedAttributeEntry* const map[] = {
  96. sColorMap,
  97. sFillStrokeMap,
  98. sFontSpecificationMap,
  99. sGraphicsMap,
  100. sTextContentElementsMap
  101. };
  102. return FindAttributeDependence(name, map) ||
  103. SVGTextPathElementBase::IsAttributeMapped(name);
  104. }
  105. //----------------------------------------------------------------------
  106. // nsSVGElement overrides
  107. nsSVGElement::LengthAttributesInfo
  108. SVGTextPathElement::GetLengthInfo()
  109. {
  110. return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
  111. ArrayLength(sLengthInfo));
  112. }
  113. nsSVGElement::EnumAttributesInfo
  114. SVGTextPathElement::GetEnumInfo()
  115. {
  116. return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
  117. ArrayLength(sEnumInfo));
  118. }
  119. nsSVGElement::StringAttributesInfo
  120. SVGTextPathElement::GetStringInfo()
  121. {
  122. return StringAttributesInfo(mStringAttributes, sStringInfo,
  123. ArrayLength(sStringInfo));
  124. }
  125. } // namespace dom
  126. } // namespace mozilla