SVGFESpotLightElement.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/SVGFESpotLightElement.h"
  6. #include "mozilla/dom/SVGFESpotLightElementBinding.h"
  7. #include "nsSVGFilterInstance.h"
  8. NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FESpotLight)
  9. using namespace mozilla::gfx;
  10. namespace mozilla {
  11. namespace dom {
  12. JSObject*
  13. SVGFESpotLightElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  14. {
  15. return SVGFESpotLightElementBinding::Wrap(aCx, this, aGivenProto);
  16. }
  17. nsSVGElement::NumberInfo SVGFESpotLightElement::sNumberInfo[8] =
  18. {
  19. { &nsGkAtoms::x, 0, false },
  20. { &nsGkAtoms::y, 0, false },
  21. { &nsGkAtoms::z, 0, false },
  22. { &nsGkAtoms::pointsAtX, 0, false },
  23. { &nsGkAtoms::pointsAtY, 0, false },
  24. { &nsGkAtoms::pointsAtZ, 0, false },
  25. { &nsGkAtoms::specularExponent, 1, false },
  26. { &nsGkAtoms::limitingConeAngle, 0, false }
  27. };
  28. //----------------------------------------------------------------------
  29. // nsIDOMNode methods
  30. NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFESpotLightElement)
  31. //----------------------------------------------------------------------
  32. // nsFEUnstyledElement methods
  33. bool
  34. SVGFESpotLightElement::AttributeAffectsRendering(int32_t aNameSpaceID,
  35. nsIAtom* aAttribute) const
  36. {
  37. return aNameSpaceID == kNameSpaceID_None &&
  38. (aAttribute == nsGkAtoms::x ||
  39. aAttribute == nsGkAtoms::y ||
  40. aAttribute == nsGkAtoms::z ||
  41. aAttribute == nsGkAtoms::pointsAtX ||
  42. aAttribute == nsGkAtoms::pointsAtY ||
  43. aAttribute == nsGkAtoms::pointsAtZ ||
  44. aAttribute == nsGkAtoms::specularExponent ||
  45. aAttribute == nsGkAtoms::limitingConeAngle);
  46. }
  47. //----------------------------------------------------------------------
  48. AttributeMap
  49. SVGFESpotLightElement::ComputeLightAttributes(nsSVGFilterInstance* aInstance)
  50. {
  51. Point3D lightPos, pointsAt;
  52. float specularExponent, limitingConeAngle;
  53. GetAnimatedNumberValues(&lightPos.x, &lightPos.y, &lightPos.z,
  54. &pointsAt.x, &pointsAt.y, &pointsAt.z,
  55. &specularExponent, &limitingConeAngle,
  56. nullptr);
  57. if (!mNumberAttributes[SVGFESpotLightElement::LIMITING_CONE_ANGLE].IsExplicitlySet()) {
  58. limitingConeAngle = 90;
  59. }
  60. AttributeMap map;
  61. map.Set(eLightType, (uint32_t)eLightTypeSpot);
  62. map.Set(eSpotLightPosition, aInstance->ConvertLocation(lightPos));
  63. map.Set(eSpotLightPointsAt, aInstance->ConvertLocation(pointsAt));
  64. map.Set(eSpotLightFocus, specularExponent);
  65. map.Set(eSpotLightLimitingConeAngle, limitingConeAngle);
  66. return map;
  67. }
  68. already_AddRefed<SVGAnimatedNumber>
  69. SVGFESpotLightElement::X()
  70. {
  71. return mNumberAttributes[ATTR_X].ToDOMAnimatedNumber(this);
  72. }
  73. already_AddRefed<SVGAnimatedNumber>
  74. SVGFESpotLightElement::Y()
  75. {
  76. return mNumberAttributes[ATTR_Y].ToDOMAnimatedNumber(this);
  77. }
  78. already_AddRefed<SVGAnimatedNumber>
  79. SVGFESpotLightElement::Z()
  80. {
  81. return mNumberAttributes[ATTR_Z].ToDOMAnimatedNumber(this);
  82. }
  83. already_AddRefed<SVGAnimatedNumber>
  84. SVGFESpotLightElement::PointsAtX()
  85. {
  86. return mNumberAttributes[POINTS_AT_X].ToDOMAnimatedNumber(this);
  87. }
  88. already_AddRefed<SVGAnimatedNumber>
  89. SVGFESpotLightElement::PointsAtY()
  90. {
  91. return mNumberAttributes[POINTS_AT_Y].ToDOMAnimatedNumber(this);
  92. }
  93. already_AddRefed<SVGAnimatedNumber>
  94. SVGFESpotLightElement::PointsAtZ()
  95. {
  96. return mNumberAttributes[POINTS_AT_Z].ToDOMAnimatedNumber(this);
  97. }
  98. already_AddRefed<SVGAnimatedNumber>
  99. SVGFESpotLightElement::SpecularExponent()
  100. {
  101. return mNumberAttributes[SPECULAR_EXPONENT].ToDOMAnimatedNumber(this);
  102. }
  103. already_AddRefed<SVGAnimatedNumber>
  104. SVGFESpotLightElement::LimitingConeAngle()
  105. {
  106. return mNumberAttributes[LIMITING_CONE_ANGLE].ToDOMAnimatedNumber(this);
  107. }
  108. //----------------------------------------------------------------------
  109. // nsSVGElement methods
  110. nsSVGElement::NumberAttributesInfo
  111. SVGFESpotLightElement::GetNumberInfo()
  112. {
  113. return NumberAttributesInfo(mNumberAttributes, sNumberInfo,
  114. ArrayLength(sNumberInfo));
  115. }
  116. } // namespace dom
  117. } // namespace mozilla