Line data Source code
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/. */
6 :
7 : #ifndef MOZILLA_SVGTRANSFORMLIST_H__
8 : #define MOZILLA_SVGTRANSFORMLIST_H__
9 :
10 : #include "gfxMatrix.h"
11 : #include "nsDebug.h"
12 : #include "nsTArray.h"
13 : #include "nsSVGTransform.h"
14 :
15 : namespace mozilla {
16 :
17 : namespace dom {
18 : class SVGTransform;
19 : } // namespace dom
20 :
21 : /**
22 : * ATTENTION! WARNING! WATCH OUT!!
23 : *
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
26 : * locked down.
27 : *
28 : * The DOM wrapper class for this class is DOMSVGTransformList.
29 : */
30 : class SVGTransformList
31 : {
32 : friend class nsSVGAnimatedTransformList;
33 : friend class DOMSVGTransformList;
34 : friend class dom::SVGTransform;
35 :
36 : public:
37 14 : SVGTransformList() {}
38 7 : ~SVGTransformList() {}
39 :
40 : // Only methods that don't make/permit modification to this list are public.
41 : // Only our friend classes can access methods that may change us.
42 :
43 : /// This may return an incomplete string on OOM, but that's acceptable.
44 : void GetValueAsString(nsAString& aValue) const;
45 :
46 337 : bool IsEmpty() const {
47 337 : return mItems.IsEmpty();
48 : }
49 :
50 0 : uint32_t Length() const {
51 0 : return mItems.Length();
52 : }
53 :
54 0 : const nsSVGTransform& operator[](uint32_t aIndex) const {
55 0 : return mItems[aIndex];
56 : }
57 :
58 : bool operator==(const SVGTransformList& rhs) const {
59 : return mItems == rhs.mItems;
60 : }
61 :
62 0 : bool SetCapacity(uint32_t size) {
63 0 : return mItems.SetCapacity(size, fallible);
64 : }
65 :
66 : void Compact() {
67 : mItems.Compact();
68 : }
69 :
70 : gfxMatrix GetConsolidationMatrix() const;
71 :
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 : // SVGAnimatedTransformList and having that class act as an intermediary so it
77 : // can take care of keeping DOM wrappers in sync.
78 :
79 : protected:
80 :
81 : /**
82 : * These may fail on OOM if the internal capacity needs to be increased, in
83 : * which case the list will be left unmodified.
84 : */
85 : nsresult CopyFrom(const SVGTransformList& rhs);
86 : nsresult CopyFrom(const nsTArray<nsSVGTransform>& aTransformArray);
87 :
88 0 : nsSVGTransform& operator[](uint32_t aIndex) {
89 0 : return mItems[aIndex];
90 : }
91 :
92 : /**
93 : * This may fail (return false) on OOM if the internal capacity is being
94 : * increased, in which case the list will be left unmodified.
95 : */
96 : bool SetLength(uint32_t aNumberOfItems) {
97 : return mItems.SetLength(aNumberOfItems, fallible);
98 : }
99 :
100 : private:
101 :
102 : // Marking the following private only serves to show which methods are only
103 : // used by our friend classes (as opposed to our subclasses) - it doesn't
104 : // really provide additional safety.
105 :
106 : nsresult SetValueFromString(const nsAString& aValue);
107 :
108 0 : void Clear() {
109 0 : mItems.Clear();
110 0 : }
111 :
112 0 : bool InsertItem(uint32_t aIndex, const nsSVGTransform& aTransform) {
113 0 : if (aIndex >= mItems.Length()) {
114 0 : aIndex = mItems.Length();
115 : }
116 0 : return !!mItems.InsertElementAt(aIndex, aTransform, fallible);
117 : }
118 :
119 : void ReplaceItem(uint32_t aIndex, const nsSVGTransform& aTransform) {
120 : MOZ_ASSERT(aIndex < mItems.Length(),
121 : "DOM wrapper caller should have raised INDEX_SIZE_ERR");
122 : mItems[aIndex] = aTransform;
123 : }
124 :
125 0 : void RemoveItem(uint32_t aIndex) {
126 0 : MOZ_ASSERT(aIndex < mItems.Length(),
127 : "DOM wrapper caller should have raised INDEX_SIZE_ERR");
128 0 : mItems.RemoveElementAt(aIndex);
129 0 : }
130 :
131 : bool AppendItem(const nsSVGTransform& aTransform) {
132 : return !!mItems.AppendElement(aTransform, fallible);
133 : }
134 :
135 : protected:
136 : /*
137 : * See SVGLengthList for the rationale for using FallibleTArray<nsSVGTransform>
138 : * instead of FallibleTArray<nsSVGTransform, 1>.
139 : */
140 : FallibleTArray<nsSVGTransform> mItems;
141 : };
142 :
143 : } // namespace mozilla
144 :
145 : #endif // MOZILLA_SVGTRANSFORMLIST_H__
|