SVGPatternElement.cpp 5.8 KB

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