DOMSVGPoint.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #ifndef MOZILLA_DOMSVGPOINT_H__
  6. #define MOZILLA_DOMSVGPOINT_H__
  7. #include "DOMSVGPointList.h"
  8. #include "mozilla/gfx/2D.h"
  9. #include "nsDebug.h"
  10. #include "nsISVGPoint.h"
  11. #include "SVGPoint.h"
  12. #include "mozilla/Attributes.h"
  13. #include "mozilla/FloatingPoint.h"
  14. class nsSVGElement;
  15. namespace mozilla {
  16. namespace dom {
  17. class SVGMatrix;
  18. } // namespace dom
  19. /**
  20. * Class DOMSVGPoint
  21. *
  22. * This class creates the DOM objects that wrap internal SVGPoint objects that
  23. * are in an SVGPointList. It is also used to create the objects returned by
  24. * SVGSVGElement.createSVGPoint() and other functions that return DOM SVGPoint
  25. * objects.
  26. *
  27. * See the architecture comment in DOMSVGPointList.h for an overview of the
  28. * important points regarding these DOM wrapper structures.
  29. *
  30. * See the architecture comment in DOMSVGLength.h (yes, LENGTH) for an overview
  31. * of the important points regarding how this specific class works.
  32. */
  33. class DOMSVGPoint final : public nsISVGPoint
  34. {
  35. friend class AutoChangePointNotifier;
  36. typedef mozilla::gfx::Point Point;
  37. public:
  38. /**
  39. * Generic ctor for DOMSVGPoint objects that are created for an attribute.
  40. */
  41. DOMSVGPoint(DOMSVGPointList *aList,
  42. uint32_t aListIndex,
  43. bool aIsAnimValItem)
  44. : nsISVGPoint()
  45. {
  46. mList = aList;
  47. mListIndex = aListIndex;
  48. mIsAnimValItem = aIsAnimValItem;
  49. // These shifts are in sync with the members.
  50. MOZ_ASSERT(aList && aListIndex <= MaxListIndex(), "bad arg");
  51. MOZ_ASSERT(IndexIsValid(), "Bad index for DOMSVGPoint!");
  52. }
  53. explicit DOMSVGPoint(const DOMSVGPoint *aPt = nullptr)
  54. : nsISVGPoint()
  55. {
  56. if (aPt) {
  57. mPt = aPt->ToSVGPoint();
  58. }
  59. }
  60. DOMSVGPoint(float aX, float aY)
  61. : nsISVGPoint()
  62. {
  63. mPt.mX = aX;
  64. mPt.mY = aY;
  65. }
  66. explicit DOMSVGPoint(const Point& aPt)
  67. : nsISVGPoint()
  68. {
  69. mPt.mX = aPt.x;
  70. mPt.mY = aPt.y;
  71. NS_ASSERTION(IsFinite(mPt.mX) && IsFinite(mPt.mX),
  72. "DOMSVGPoint coords are not finite");
  73. }
  74. // WebIDL
  75. virtual float X() override;
  76. virtual void SetX(float aX, ErrorResult& rv) override;
  77. virtual float Y() override;
  78. virtual void SetY(float aY, ErrorResult& rv) override;
  79. virtual already_AddRefed<nsISVGPoint> MatrixTransform(dom::SVGMatrix& matrix) override;
  80. nsISupports* GetParentObject() override {
  81. return mList;
  82. }
  83. virtual DOMSVGPoint* Copy() override {
  84. return new DOMSVGPoint(this);
  85. }
  86. protected:
  87. nsSVGElement* Element() {
  88. return mList->Element();
  89. }
  90. };
  91. } // namespace mozilla
  92. #endif // MOZILLA_DOMSVGPOINT_H__