1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "DOMSVGAnimatedTransformList.h"
9 #include "DOMSVGTransformList.h"
10 #include "SVGAnimatedTransformList.h"
11 #include "SVGAttrTearoffTable.h"
12 #include "mozilla/dom/SVGAnimatedTransformListBinding.h"
14 namespace mozilla::dom
{
16 MOZ_CONSTINIT
static SVGAttrTearoffTable
<SVGAnimatedTransformList
,
17 DOMSVGAnimatedTransformList
>
18 sSVGAnimatedTransformListTearoffTable
;
20 NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGAnimatedTransformList
,
23 JSObject
* DOMSVGAnimatedTransformList::WrapObject(
24 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
25 return SVGAnimatedTransformList_Binding::Wrap(aCx
, this, aGivenProto
);
28 //----------------------------------------------------------------------
29 already_AddRefed
<DOMSVGTransformList
> DOMSVGAnimatedTransformList::BaseVal() {
31 mBaseVal
= new DOMSVGTransformList(this, InternalAList().GetBaseValue());
33 RefPtr
<DOMSVGTransformList
> baseVal
= mBaseVal
;
34 return baseVal
.forget();
37 already_AddRefed
<DOMSVGTransformList
> DOMSVGAnimatedTransformList::AnimVal() {
39 mAnimVal
= new DOMSVGTransformList(this, InternalAList().GetAnimValue());
41 RefPtr
<DOMSVGTransformList
> animVal
= mAnimVal
;
42 return animVal
.forget();
46 already_AddRefed
<DOMSVGAnimatedTransformList
>
47 DOMSVGAnimatedTransformList::GetDOMWrapper(SVGAnimatedTransformList
* aList
,
48 SVGElement
* aElement
) {
49 RefPtr
<DOMSVGAnimatedTransformList
> wrapper
=
50 sSVGAnimatedTransformListTearoffTable
.GetTearoff(aList
);
52 wrapper
= new DOMSVGAnimatedTransformList(aElement
);
53 sSVGAnimatedTransformListTearoffTable
.AddTearoff(aList
, wrapper
);
55 return wrapper
.forget();
59 DOMSVGAnimatedTransformList
* DOMSVGAnimatedTransformList::GetDOMWrapperIfExists(
60 SVGAnimatedTransformList
* aList
) {
61 return sSVGAnimatedTransformListTearoffTable
.GetTearoff(aList
);
64 DOMSVGAnimatedTransformList::~DOMSVGAnimatedTransformList() {
65 // Script no longer has any references to us, to our base/animVal objects, or
66 // to any of their list items.
67 sSVGAnimatedTransformListTearoffTable
.RemoveTearoff(&InternalAList());
70 void DOMSVGAnimatedTransformList::InternalBaseValListWillChangeLengthTo(
71 uint32_t aNewLength
) {
72 // When the number of items in our internal counterpart's baseVal changes,
73 // we MUST keep our baseVal in sync. If we don't, script will either see a
74 // list that is too short and be unable to access indexes that should be
75 // valid, or else, MUCH WORSE, script will see a list that is too long and be
76 // able to access "items" at indexes that are out of bounds (read/write to
79 RefPtr
<DOMSVGAnimatedTransformList
> kungFuDeathGrip
;
81 if (aNewLength
< mBaseVal
->LengthNoFlush()) {
82 // InternalListLengthWillChange might clear last reference to |this|.
83 // Retain a temporary reference to keep from dying before returning.
84 kungFuDeathGrip
= this;
86 mBaseVal
->InternalListLengthWillChange(aNewLength
);
89 // If our attribute is not animating, then our animVal mirrors our baseVal
90 // and we must sync its length too. (If our attribute is animating, then the
91 // SMIL engine takes care of calling InternalAnimValListWillChangeLengthTo()
95 InternalAnimValListWillChangeLengthTo(aNewLength
);
99 void DOMSVGAnimatedTransformList::InternalAnimValListWillChangeLengthTo(
100 uint32_t aNewLength
) {
102 mAnimVal
->InternalListLengthWillChange(aNewLength
);
106 bool DOMSVGAnimatedTransformList::IsAnimating() const {
107 return InternalAList().IsAnimating();
110 SVGAnimatedTransformList
& DOMSVGAnimatedTransformList::InternalAList() {
111 return *mElement
->GetAnimatedTransformList();
114 const SVGAnimatedTransformList
& DOMSVGAnimatedTransformList::InternalAList()
116 return *mElement
->GetAnimatedTransformList();
119 } // namespace mozilla::dom