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_SVGSTRINGLIST_H_
8 #define DOM_SVG_SVGSTRINGLIST_H_
12 #include "nsString.h" // IWYU pragma: keep
17 class DOMSVGStringList
;
22 * The DOM wrapper class for this class is DOMSVGStringList.
25 friend class dom::DOMSVGStringList
;
28 SVGStringList() : mIsSet(false), mIsCommaSeparated(false) {}
29 ~SVGStringList() = default;
31 void SetIsCommaSeparated(bool aIsCommaSeparated
) {
32 mIsCommaSeparated
= aIsCommaSeparated
;
34 nsresult
SetValue(const nsAString
& aValue
);
41 /// This may return an incomplete string on OOM, but that's acceptable.
42 void GetValue(nsAString
& aValue
) const;
44 bool IsEmpty() const { return mStrings
.IsEmpty(); }
46 uint32_t Length() const { return mStrings
.Length(); }
48 const nsAString
& operator[](uint32_t aIndex
) const {
49 return mStrings
[aIndex
];
52 bool operator==(const SVGStringList
& rhs
) const {
53 return mStrings
== rhs
.mStrings
;
56 bool SetCapacity(uint32_t size
) {
57 return mStrings
.SetCapacity(size
, fallible
);
60 void Compact() { mStrings
.Compact(); }
62 // Returns true if the value of this stringlist has been explicitly
63 // set by markup or a DOM call, false otherwise.
64 bool IsExplicitlySet() const { return mIsSet
; }
66 // Access to methods that can modify objects of this type is deliberately
67 // limited. This is to reduce the chances of someone modifying objects of
68 // this type without taking the necessary steps to keep DOM wrappers in sync.
69 // If you need wider access to these methods, consider adding a method to
70 // DOMSVGAnimatedStringList and having that class act as an intermediary so it
71 // can take care of keeping DOM wrappers in sync.
75 * This may fail on OOM if the internal capacity needs to be increased, in
76 * which case the list will be left unmodified.
78 nsresult
CopyFrom(const SVGStringList
& rhs
);
80 nsAString
& operator[](uint32_t aIndex
) { return mStrings
[aIndex
]; }
83 * This may fail (return false) on OOM if the internal capacity is being
84 * increased, in which case the list will be left unmodified.
86 bool SetLength(uint32_t aStringOfItems
) {
87 return mStrings
.SetLength(aStringOfItems
, fallible
);
91 // Marking the following private only serves to show which methods are only
92 // used by our friend classes (as opposed to our subclasses) - it doesn't
93 // really provide additional safety.
95 bool InsertItem(uint32_t aIndex
, const nsAString
& aString
) {
96 if (aIndex
>= mStrings
.Length()) {
97 aIndex
= mStrings
.Length();
99 if (mStrings
.InsertElementAt(aIndex
, aString
, fallible
)) {
106 void ReplaceItem(uint32_t aIndex
, const nsAString
& aString
) {
107 MOZ_ASSERT(aIndex
< mStrings
.Length(),
108 "DOM wrapper caller should have raised INDEX_SIZE_ERR");
109 mStrings
[aIndex
] = aString
;
112 void RemoveItem(uint32_t aIndex
) {
113 MOZ_ASSERT(aIndex
< mStrings
.Length(),
114 "DOM wrapper caller should have raised INDEX_SIZE_ERR");
115 mStrings
.RemoveElementAt(aIndex
);
118 bool AppendItem(const nsAString
& aString
) {
119 if (mStrings
.AppendElement(aString
, fallible
)) {
127 /* See SVGLengthList for the rationale for using FallibleTArray<float> instead
128 * of FallibleTArray<float, 1>.
130 FallibleTArray
<nsString
> mStrings
;
132 bool mIsCommaSeparated
;
135 } // namespace mozilla
137 #endif // DOM_SVG_SVGSTRINGLIST_H_