Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/DOMSVGStringList.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_DOMSVGSTRINGLIST_H__
8
#define MOZILLA_DOMSVGSTRINGLIST_H__
9
10
#include "nsCOMPtr.h"
11
#include "nsCycleCollectionParticipant.h"
12
#include "nsSVGElement.h"
13
#include "mozilla/Attributes.h"
14
15
namespace mozilla {
16
17
class ErrorResult;
18
class SVGStringList;
19
20
/**
21
 * Class DOMSVGStringList
22
 *
23
 * This class is used to create the DOM tearoff objects that wrap internal
24
 * SVGPathData objects.
25
 *
26
 * See the architecture comment in DOMSVGAnimatedLengthList.h first (that's
27
 * LENGTH list), then continue reading the remainder of this comment.
28
 *
29
 * The architecture of this class is similar to that of DOMSVGLengthList
30
 * except for two important aspects:
31
 *
32
 * First, since there is no nsIDOMSVGAnimatedStringList interface in SVG, we
33
 * have no parent DOMSVGAnimatedStringList (unlike DOMSVGLengthList which has
34
 * a parent DOMSVGAnimatedLengthList class). As a consequence, much of the
35
 * logic that would otherwise be in DOMSVGAnimatedStringList (and is in
36
 * DOMSVGAnimatedLengthList) is contained in this class.
37
 *
38
 * Second, since there is no nsIDOMSVGString interface in SVG, we have no
39
 * DOMSVGString items to maintain. As far as script is concerned, objects
40
 * of this class contain a list of strings, not a list of mutable objects
41
 * like the other SVG list types. As a result, unlike the other SVG list
42
 * types, this class does not create its items lazily on demand and store
43
 * them so it can return the same objects each time. It simply returns a new
44
 * string each time any given item is requested.
45
 */
46
class DOMSVGStringList final : public nsISupports
47
                             , public nsWrapperCache
48
{
49
  friend class AutoChangeStringListNotifier;
50
51
public:
52
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
53
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGStringList)
54
55
  nsSVGElement* GetParentObject() const
56
0
  {
57
0
    return mElement;
58
0
  }
59
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
60
61
  uint32_t NumberOfItems() const;
62
  uint32_t Length() const;
63
  void Clear();
64
  void Initialize(const nsAString& aNewItem, nsAString& aRetval,
65
                  ErrorResult& aRv);
66
  void GetItem(uint32_t aIndex, nsAString& aRetval, ErrorResult& aRv);
67
  void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aRetval);
68
  void InsertItemBefore(const nsAString& aNewItem, uint32_t aIndex,
69
                        nsAString& aRetval, ErrorResult& aRv);
70
  void ReplaceItem(const nsAString& aNewItem, uint32_t aIndex,
71
                   nsAString& aRetval, ErrorResult& aRv);
72
  void RemoveItem(uint32_t aIndex, nsAString& aRetval, ErrorResult& aRv);
73
  void AppendItem(const nsAString& aNewItem, nsAString& aRetval,
74
                  ErrorResult& aRv);
75
76
  /**
77
   * Factory method to create and return a DOMSVGStringList wrapper
78
   * for a given internal SVGStringList object. The factory takes care
79
   * of caching the object that it returns so that the same object can be
80
   * returned for the given SVGStringList each time it is requested.
81
   * The cached object is only removed from the cache when it is destroyed due
82
   * to there being no more references to it. If that happens, any subsequent
83
   * call requesting the DOM wrapper for the SVGStringList will naturally
84
   * result in a new DOMSVGStringList being returned.
85
   */
86
  static already_AddRefed<DOMSVGStringList>
87
    GetDOMWrapper(SVGStringList *aList,
88
                  nsSVGElement *aElement,
89
                  bool aIsConditionalProcessingAttribute,
90
                  uint8_t aAttrEnum);
91
92
private:
93
  /**
94
   * Only our static GetDOMWrapper() factory method may create objects of our
95
   * type.
96
   */
97
  DOMSVGStringList(nsSVGElement *aElement,
98
                   bool aIsConditionalProcessingAttribute, uint8_t aAttrEnum)
99
    : mElement(aElement)
100
    , mAttrEnum(aAttrEnum)
101
    , mIsConditionalProcessingAttribute(aIsConditionalProcessingAttribute)
102
0
  {
103
0
  }
104
105
  ~DOMSVGStringList();
106
107
  SVGStringList &InternalList() const;
108
109
  // Strong ref to our element to keep it alive.
110
  RefPtr<nsSVGElement> mElement;
111
112
  uint8_t mAttrEnum;
113
114
  bool    mIsConditionalProcessingAttribute;
115
};
116
117
} // namespace mozilla
118
119
#endif // MOZILLA_DOMSVGSTRINGLIST_H__