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 #ifndef DOM_SVG_SVGTRANSFORMLIST_H_
8 #define DOM_SVG_SVGTRANSFORMLIST_H_
10 #include "gfxMatrix.h"
11 #include "mozilla/dom/SVGTransform.h"
17 class DOMSVGTransform
;
18 class DOMSVGTransformList
;
22 * ATTENTION! WARNING! WATCH OUT!!
24 * Consumers that modify objects of this type absolutely MUST keep the DOM
25 * wrappers for those lists (if any) in sync!! That's why this class is so
28 * The DOM wrapper class for this class is DOMSVGTransformList.
30 class SVGTransformList
{
31 friend class SVGAnimatedTransformList
;
32 friend class dom::DOMSVGTransform
;
33 friend class dom::DOMSVGTransformList
;
36 SVGTransformList() = default;
37 ~SVGTransformList() = default;
39 SVGTransformList
& operator=(const SVGTransformList
& aOther
) {
40 mItems
.ClearAndRetainStorage();
41 // Best-effort, really.
42 Unused
<< mItems
.AppendElements(aOther
.mItems
, fallible
);
46 SVGTransformList(const SVGTransformList
& aOther
) { *this = aOther
; }
48 // Only methods that don't make/permit modification to this list are public.
49 // Only our friend classes can access methods that may change us.
51 /// This may return an incomplete string on OOM, but that's acceptable.
52 void GetValueAsString(nsAString
& aValue
) const;
54 bool IsEmpty() const { return mItems
.IsEmpty(); }
56 uint32_t Length() const { return mItems
.Length(); }
58 const SVGTransform
& operator[](uint32_t aIndex
) const {
59 return mItems
[aIndex
];
62 bool operator==(const SVGTransformList
& rhs
) const {
63 return mItems
== rhs
.mItems
;
66 bool SetCapacity(uint32_t size
) { return mItems
.SetCapacity(size
, fallible
); }
68 void Compact() { mItems
.Compact(); }
70 gfxMatrix
GetConsolidationMatrix() const;
72 // Access to methods that can modify objects of this type is deliberately
73 // limited. This is to reduce the chances of someone modifying objects of
74 // this type without taking the necessary steps to keep DOM wrappers in sync.
75 // If you need wider access to these methods, consider adding a method to
76 // DOMSVGAnimatedTransformList and having that class act as an intermediary so
77 // it can take care of keeping DOM wrappers in sync.
81 * These may fail on OOM if the internal capacity needs to be increased, in
82 * which case the list will be left unmodified.
84 nsresult
CopyFrom(const SVGTransformList
& rhs
);
85 nsresult
CopyFrom(const nsTArray
<SVGTransform
>& aTransformArray
);
87 SVGTransform
& operator[](uint32_t aIndex
) { return mItems
[aIndex
]; }
90 * This may fail (return false) on OOM if the internal capacity is being
91 * increased, in which case the list will be left unmodified.
93 bool SetLength(uint32_t aNumberOfItems
) {
94 return mItems
.SetLength(aNumberOfItems
, fallible
);
98 // Marking the following private only serves to show which methods are only
99 // used by our friend classes (as opposed to our subclasses) - it doesn't
100 // really provide additional safety.
102 nsresult
SetValueFromString(const nsAString
& aValue
);
104 void Clear() { mItems
.Clear(); }
106 bool InsertItem(uint32_t aIndex
, const SVGTransform
& aTransform
) {
107 if (aIndex
>= mItems
.Length()) {
108 aIndex
= mItems
.Length();
110 return !!mItems
.InsertElementAt(aIndex
, aTransform
, fallible
);
113 void ReplaceItem(uint32_t aIndex
, const SVGTransform
& aTransform
) {
114 MOZ_ASSERT(aIndex
< mItems
.Length(),
115 "DOM wrapper caller should have raised INDEX_SIZE_ERR");
116 mItems
[aIndex
] = aTransform
;
119 void RemoveItem(uint32_t aIndex
) {
120 MOZ_ASSERT(aIndex
< mItems
.Length(),
121 "DOM wrapper caller should have raised INDEX_SIZE_ERR");
122 mItems
.RemoveElementAt(aIndex
);
125 bool AppendItem(const SVGTransform
& aTransform
) {
126 return !!mItems
.AppendElement(aTransform
, fallible
);
131 * See SVGLengthList for the rationale for using
132 * FallibleTArray<SVGTransform> instead of FallibleTArray<SVGTransform,
135 FallibleTArray
<SVGTransform
> mItems
;
138 } // namespace mozilla
140 #endif // DOM_SVG_SVGTRANSFORMLIST_H_