/src/mozilla-central/dom/svg/SVGTransformList.h
Line | Count | Source (jump to first uncovered line) |
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 | 0 | SVGTransformList() {} |
38 | 0 | ~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 | 0 | bool IsEmpty() const { |
47 | 0 | return mItems.IsEmpty(); |
48 | 0 | } |
49 | | |
50 | 0 | uint32_t Length() const { |
51 | 0 | return mItems.Length(); |
52 | 0 | } |
53 | | |
54 | 0 | const nsSVGTransform& operator[](uint32_t aIndex) const { |
55 | 0 | return mItems[aIndex]; |
56 | 0 | } |
57 | | |
58 | 0 | bool operator==(const SVGTransformList& rhs) const { |
59 | 0 | return mItems == rhs.mItems; |
60 | 0 | } |
61 | | |
62 | 0 | bool SetCapacity(uint32_t size) { |
63 | 0 | return mItems.SetCapacity(size, fallible); |
64 | 0 | } |
65 | | |
66 | 0 | void Compact() { |
67 | 0 | mItems.Compact(); |
68 | 0 | } |
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 | 0 | } |
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 | 0 | bool SetLength(uint32_t aNumberOfItems) { |
97 | 0 | return mItems.SetLength(aNumberOfItems, fallible); |
98 | 0 | } |
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 | 0 | } |
116 | 0 | return !!mItems.InsertElementAt(aIndex, aTransform, fallible); |
117 | 0 | } |
118 | | |
119 | 0 | void ReplaceItem(uint32_t aIndex, const nsSVGTransform& aTransform) { |
120 | 0 | MOZ_ASSERT(aIndex < mItems.Length(), |
121 | 0 | "DOM wrapper caller should have raised INDEX_SIZE_ERR"); |
122 | 0 | mItems[aIndex] = aTransform; |
123 | 0 | } |
124 | | |
125 | 0 | void RemoveItem(uint32_t aIndex) { |
126 | 0 | MOZ_ASSERT(aIndex < mItems.Length(), |
127 | 0 | "DOM wrapper caller should have raised INDEX_SIZE_ERR"); |
128 | 0 | mItems.RemoveElementAt(aIndex); |
129 | 0 | } |
130 | | |
131 | 0 | bool AppendItem(const nsSVGTransform& aTransform) { |
132 | 0 | return !!mItems.AppendElement(aTransform, fallible); |
133 | 0 | } |
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__ |