SVGMaskElement.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/SVGMaskElement.h"
  9. #include "mozilla/dom/SVGMaskElementBinding.h"
  10. NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Mask)
  11. namespace mozilla {
  12. namespace dom {
  13. JSObject*
  14. SVGMaskElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
  15. {
  16. return SVGMaskElementBinding::Wrap(aCx, this, aGivenProto);
  17. }
  18. //--------------------- Masks ------------------------
  19. nsSVGElement::LengthInfo SVGMaskElement::sLengthInfo[4] =
  20. {
  21. { &nsGkAtoms::x, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
  22. { &nsGkAtoms::y, -10, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
  23. { &nsGkAtoms::width, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::X },
  24. { &nsGkAtoms::height, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, SVGContentUtils::Y },
  25. };
  26. nsSVGElement::EnumInfo SVGMaskElement::sEnumInfo[2] =
  27. {
  28. { &nsGkAtoms::maskUnits,
  29. sSVGUnitTypesMap,
  30. SVG_UNIT_TYPE_OBJECTBOUNDINGBOX
  31. },
  32. { &nsGkAtoms::maskContentUnits,
  33. sSVGUnitTypesMap,
  34. SVG_UNIT_TYPE_USERSPACEONUSE
  35. }
  36. };
  37. //----------------------------------------------------------------------
  38. // Implementation
  39. SVGMaskElement::SVGMaskElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
  40. : SVGMaskElementBase(aNodeInfo)
  41. {
  42. }
  43. //----------------------------------------------------------------------
  44. // nsIDOMNode method
  45. NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGMaskElement)
  46. //----------------------------------------------------------------------
  47. already_AddRefed<SVGAnimatedEnumeration>
  48. SVGMaskElement::MaskUnits()
  49. {
  50. return mEnumAttributes[MASKUNITS].ToDOMAnimatedEnum(this);
  51. }
  52. already_AddRefed<SVGAnimatedEnumeration>
  53. SVGMaskElement::MaskContentUnits()
  54. {
  55. return mEnumAttributes[MASKCONTENTUNITS].ToDOMAnimatedEnum(this);
  56. }
  57. already_AddRefed<SVGAnimatedLength>
  58. SVGMaskElement::X()
  59. {
  60. return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
  61. }
  62. already_AddRefed<SVGAnimatedLength>
  63. SVGMaskElement::Y()
  64. {
  65. return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
  66. }
  67. already_AddRefed<SVGAnimatedLength>
  68. SVGMaskElement::Width()
  69. {
  70. return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
  71. }
  72. already_AddRefed<SVGAnimatedLength>
  73. SVGMaskElement::Height()
  74. {
  75. return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
  76. }
  77. //----------------------------------------------------------------------
  78. // nsSVGElement methods
  79. /* virtual */ bool
  80. SVGMaskElement::HasValidDimensions() const
  81. {
  82. return (!mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() ||
  83. mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0) &&
  84. (!mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() ||
  85. mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0);
  86. }
  87. nsSVGElement::LengthAttributesInfo
  88. SVGMaskElement::GetLengthInfo()
  89. {
  90. return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
  91. ArrayLength(sLengthInfo));
  92. }
  93. nsSVGElement::EnumAttributesInfo
  94. SVGMaskElement::GetEnumInfo()
  95. {
  96. return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
  97. ArrayLength(sEnumInfo));
  98. }
  99. //----------------------------------------------------------------------
  100. // nsIContent methods
  101. NS_IMETHODIMP_(bool)
  102. SVGMaskElement::IsAttributeMapped(const nsIAtom* name) const
  103. {
  104. static const MappedAttributeEntry* const map[] = {
  105. sColorMap,
  106. sFEFloodMap,
  107. sFillStrokeMap,
  108. sFiltersMap,
  109. sFontSpecificationMap,
  110. sGradientStopMap,
  111. sGraphicsMap,
  112. sMarkersMap,
  113. sMaskMap,
  114. sTextContentElementsMap,
  115. sViewportsMap
  116. };
  117. return FindAttributeDependence(name, map) ||
  118. SVGMaskElementBase::IsAttributeMapped(name);
  119. }
  120. } // namespace dom
  121. } // namespace mozilla