Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGStringList.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_SVGSTRINGLIST_H__
8
#define MOZILLA_SVGSTRINGLIST_H__
9
10
#include "nsDebug.h"
11
#include "nsTArray.h"
12
#include "nsString.h" // IWYU pragma: keep
13
14
namespace mozilla {
15
16
/**
17
 *
18
 * The DOM wrapper class for this class is DOMSVGStringList.
19
 */
20
class SVGStringList
21
{
22
  friend class DOMSVGStringList;
23
24
public:
25
26
0
  SVGStringList() : mIsSet(false), mIsCommaSeparated(false) {}
27
0
  ~SVGStringList(){}
28
29
0
  void SetIsCommaSeparated(bool aIsCommaSeparated) {
30
0
    mIsCommaSeparated = aIsCommaSeparated;
31
0
  }
32
  nsresult SetValue(const nsAString& aValue);
33
34
0
  void Clear() {
35
0
    mStrings.Clear();
36
0
    mIsSet = false;
37
0
  }
38
39
  /// This may return an incomplete string on OOM, but that's acceptable.
40
  void GetValue(nsAString& aValue) const;
41
42
0
  bool IsEmpty() const {
43
0
    return mStrings.IsEmpty();
44
0
  }
45
46
0
  uint32_t Length() const {
47
0
    return mStrings.Length();
48
0
  }
49
50
0
  const nsAString& operator[](uint32_t aIndex) const {
51
0
    return mStrings[aIndex];
52
0
  }
53
54
  bool operator==(const SVGStringList& rhs) const {
55
    return mStrings == rhs.mStrings;
56
  }
57
58
0
  bool SetCapacity(uint32_t size) {
59
0
    return mStrings.SetCapacity(size, fallible);
60
0
  }
61
62
  void Compact() {
63
    mStrings.Compact();
64
  }
65
66
  // Returns true if the value of this stringlist has been explicitly
67
  // set by markup or a DOM call, false otherwise.
68
  bool IsExplicitlySet() const
69
0
    { return mIsSet; }
70
71
  // Access to methods that can modify objects of this type is deliberately
72
  // limited. This is to reduce the chances of someone modifying objects of
73
  // this type without taking the necessary steps to keep DOM wrappers in sync.
74
  // If you need wider access to these methods, consider adding a method to
75
  // SVGAnimatedStringList and having that class act as an intermediary so it
76
  // can take care of keeping DOM wrappers in sync.
77
78
protected:
79
80
  /**
81
   * This may fail on OOM if the internal capacity needs to be increased, in
82
   * which case the list will be left unmodified.
83
   */
84
  nsresult CopyFrom(const SVGStringList& rhs);
85
86
0
  nsAString& operator[](uint32_t aIndex) {
87
0
    return mStrings[aIndex];
88
0
  }
89
90
  /**
91
   * This may fail (return false) on OOM if the internal capacity is being
92
   * increased, in which case the list will be left unmodified.
93
   */
94
  bool SetLength(uint32_t aStringOfItems) {
95
    return mStrings.SetLength(aStringOfItems, fallible);
96
  }
97
98
private:
99
100
  // Marking the following private only serves to show which methods are only
101
  // used by our friend classes (as opposed to our subclasses) - it doesn't
102
  // really provide additional safety.
103
104
0
  bool InsertItem(uint32_t aIndex, const nsAString &aString) {
105
0
    if (aIndex >= mStrings.Length()) {
106
0
      aIndex = mStrings.Length();
107
0
    }
108
0
    if (mStrings.InsertElementAt(aIndex, aString, fallible)) {
109
0
      mIsSet = true;
110
0
      return true;
111
0
    }
112
0
    return false;
113
0
  }
114
115
0
  void ReplaceItem(uint32_t aIndex, const nsAString &aString) {
116
0
    MOZ_ASSERT(aIndex < mStrings.Length(),
117
0
               "DOM wrapper caller should have raised INDEX_SIZE_ERR");
118
0
    mStrings[aIndex] = aString;
119
0
  }
120
121
0
  void RemoveItem(uint32_t aIndex) {
122
0
    MOZ_ASSERT(aIndex < mStrings.Length(),
123
0
               "DOM wrapper caller should have raised INDEX_SIZE_ERR");
124
0
    mStrings.RemoveElementAt(aIndex);
125
0
  }
126
127
0
  bool AppendItem(const nsAString &aString) {
128
0
    if (mStrings.AppendElement(aString, fallible)) {
129
0
      mIsSet = true;
130
0
      return true;
131
0
    }
132
0
    return false;
133
0
  }
134
135
protected:
136
137
  /* See SVGLengthList for the rationale for using FallibleTArray<float> instead
138
   * of FallibleTArray<float, 1>.
139
   */
140
  FallibleTArray<nsString> mStrings;
141
  bool mIsSet;
142
  bool mIsCommaSeparated;
143
};
144
145
} // namespace mozilla
146
147
#endif // MOZILLA_SVGSTRINGLIST_H__