nsISVGPoint.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "nsISVGPoint.h"
  6. #include "DOMSVGPointList.h"
  7. #include "SVGPoint.h"
  8. #include "nsSVGElement.h"
  9. #include "nsError.h"
  10. #include "mozilla/dom/SVGPointBinding.h"
  11. // See the architecture comment in DOMSVGPointList.h.
  12. using namespace mozilla;
  13. // We could use NS_IMPL_CYCLE_COLLECTION(, except that in Unlink() we need to
  14. // clear our list's weak ref to us to be safe. (The other option would be to
  15. // not unlink and rely on the breaking of the other edges in the cycle, as
  16. // NS_SVG_VAL_IMPL_CYCLE_COLLECTION does.)
  17. NS_IMPL_CYCLE_COLLECTION_CLASS(nsISVGPoint)
  18. NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsISVGPoint)
  19. // We may not belong to a list, so we must null check tmp->mList.
  20. if (tmp->mList) {
  21. tmp->mList->mItems[tmp->mListIndex] = nullptr;
  22. }
  23. NS_IMPL_CYCLE_COLLECTION_UNLINK(mList)
  24. NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
  25. NS_IMPL_CYCLE_COLLECTION_UNLINK_END
  26. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsISVGPoint)
  27. NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mList)
  28. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
  29. NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsISVGPoint)
  30. NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
  31. NS_IMPL_CYCLE_COLLECTION_TRACE_END
  32. NS_IMPL_CYCLE_COLLECTING_ADDREF(nsISVGPoint)
  33. NS_IMPL_CYCLE_COLLECTING_RELEASE(nsISVGPoint)
  34. NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsISVGPoint)
  35. NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
  36. NS_INTERFACE_MAP_ENTRY(nsISVGPoint)
  37. NS_INTERFACE_MAP_ENTRY(nsISupports)
  38. NS_INTERFACE_MAP_END
  39. void
  40. nsISVGPoint::InsertingIntoList(DOMSVGPointList *aList,
  41. uint32_t aListIndex,
  42. bool aIsAnimValItem)
  43. {
  44. MOZ_ASSERT(!HasOwner(), "Inserting item that already has an owner");
  45. mList = aList;
  46. mListIndex = aListIndex;
  47. mIsReadonly = false;
  48. mIsAnimValItem = aIsAnimValItem;
  49. MOZ_ASSERT(IndexIsValid(), "Bad index for DOMSVGPoint!");
  50. }
  51. void
  52. nsISVGPoint::RemovingFromList()
  53. {
  54. mPt = InternalItem();
  55. mList = nullptr;
  56. MOZ_ASSERT(!mIsReadonly, "mIsReadonly set for list");
  57. mIsAnimValItem = false;
  58. }
  59. SVGPoint&
  60. nsISVGPoint::InternalItem()
  61. {
  62. return mList->InternalList().mItems[mListIndex];
  63. }
  64. #ifdef DEBUG
  65. bool
  66. nsISVGPoint::IndexIsValid()
  67. {
  68. return mListIndex < mList->InternalList().Length();
  69. }
  70. #endif