1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla SVG Project code.
17 : *
18 : * The Initial Developer of the Original Code is the Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2011
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Brian Birtles <birtles@gmail.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef MOZILLA_SVGTRANSFORMLIST_H__
40 : #define MOZILLA_SVGTRANSFORMLIST_H__
41 :
42 : #include "gfxMatrix.h"
43 : #include "nsDebug.h"
44 : #include "nsTArray.h"
45 : #include "SVGTransform.h"
46 :
47 : namespace mozilla {
48 :
49 : /**
50 : * ATTENTION! WARNING! WATCH OUT!!
51 : *
52 : * Consumers that modify objects of this type absolutely MUST keep the DOM
53 : * wrappers for those lists (if any) in sync!! That's why this class is so
54 : * locked down.
55 : *
56 : * The DOM wrapper class for this class is DOMSVGTransformList.
57 : */
58 : class SVGTransformList
59 : {
60 : friend class SVGAnimatedTransformList;
61 : friend class DOMSVGTransformList;
62 : friend class DOMSVGTransform;
63 :
64 : public:
65 0 : SVGTransformList() {}
66 0 : ~SVGTransformList() {}
67 :
68 : // Only methods that don't make/permit modification to this list are public.
69 : // Only our friend classes can access methods that may change us.
70 :
71 : /// This may return an incomplete string on OOM, but that's acceptable.
72 : void GetValueAsString(nsAString& aValue) const;
73 :
74 0 : bool IsEmpty() const {
75 0 : return mItems.IsEmpty();
76 : }
77 :
78 0 : PRUint32 Length() const {
79 0 : return mItems.Length();
80 : }
81 :
82 0 : const SVGTransform& operator[](PRUint32 aIndex) const {
83 0 : return mItems[aIndex];
84 : }
85 :
86 : bool operator==(const SVGTransformList& rhs) const {
87 : return mItems == rhs.mItems;
88 : }
89 :
90 0 : bool SetCapacity(PRUint32 size) {
91 0 : return mItems.SetCapacity(size);
92 : }
93 :
94 : void Compact() {
95 : mItems.Compact();
96 : }
97 :
98 : gfxMatrix GetConsolidationMatrix() const;
99 :
100 : // Access to methods that can modify objects of this type is deliberately
101 : // limited. This is to reduce the chances of someone modifying objects of
102 : // this type without taking the necessary steps to keep DOM wrappers in sync.
103 : // If you need wider access to these methods, consider adding a method to
104 : // SVGAnimatedTransformList and having that class act as an intermediary so it
105 : // can take care of keeping DOM wrappers in sync.
106 :
107 : protected:
108 :
109 : /**
110 : * These may fail on OOM if the internal capacity needs to be increased, in
111 : * which case the list will be left unmodified.
112 : */
113 : nsresult CopyFrom(const SVGTransformList& rhs);
114 : nsresult CopyFrom(const nsTArray<SVGTransform>& aTransformArray);
115 :
116 0 : SVGTransform& operator[](PRUint32 aIndex) {
117 0 : return mItems[aIndex];
118 : }
119 :
120 : /**
121 : * This may fail (return false) on OOM if the internal capacity is being
122 : * increased, in which case the list will be left unmodified.
123 : */
124 : bool SetLength(PRUint32 aNumberOfItems) {
125 : return mItems.SetLength(aNumberOfItems);
126 : }
127 :
128 : private:
129 :
130 : // Marking the following private only serves to show which methods are only
131 : // used by our friend classes (as opposed to our subclasses) - it doesn't
132 : // really provide additional safety.
133 :
134 : nsresult SetValueFromString(const nsAString& aValue);
135 :
136 0 : void Clear() {
137 0 : mItems.Clear();
138 0 : }
139 :
140 0 : bool InsertItem(PRUint32 aIndex, const SVGTransform& aTransform) {
141 0 : if (aIndex >= mItems.Length()) {
142 0 : aIndex = mItems.Length();
143 : }
144 0 : return !!mItems.InsertElementAt(aIndex, aTransform);
145 : }
146 :
147 : void ReplaceItem(PRUint32 aIndex, const SVGTransform& aTransform) {
148 : NS_ABORT_IF_FALSE(aIndex < mItems.Length(),
149 : "DOM wrapper caller should have raised INDEX_SIZE_ERR");
150 : mItems[aIndex] = aTransform;
151 : }
152 :
153 0 : void RemoveItem(PRUint32 aIndex) {
154 0 : NS_ABORT_IF_FALSE(aIndex < mItems.Length(),
155 : "DOM wrapper caller should have raised INDEX_SIZE_ERR");
156 0 : mItems.RemoveElementAt(aIndex);
157 0 : }
158 :
159 : bool AppendItem(const SVGTransform& aTransform) {
160 : return !!mItems.AppendElement(aTransform);
161 : }
162 :
163 : protected:
164 : /*
165 : * See SVGLengthList for the rationale for using nsTArray<SVGTransform>
166 : * instead of nsTArray<SVGTransform, 1>.
167 : */
168 : nsTArray<SVGTransform> mItems;
169 : };
170 :
171 : } // namespace mozilla
172 :
173 : #endif // MOZILLA_SVGTRANSFORMLIST_H__
|