Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGAnimatedPathSegList.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_SVGANIMATEDPATHSEGLIST_H__
8
#define MOZILLA_SVGANIMATEDPATHSEGLIST_H__
9
10
#include "mozilla/Attributes.h"
11
#include "mozilla/MemoryReporting.h"
12
#include "mozilla/UniquePtr.h"
13
#include "nsAutoPtr.h"
14
#include "nsISMILAttr.h"
15
#include "SVGPathData.h"
16
17
class nsSMILValue;
18
class nsSVGElement;
19
20
namespace mozilla {
21
22
namespace dom {
23
class SVGAnimationElement;
24
} // namespace dom
25
26
/**
27
 * Class SVGAnimatedPathSegList
28
 *
29
 * Despite the fact that no SVGAnimatedPathSegList interface or objects exist
30
 * in the SVG specification (unlike e.g. SVGAnimated*Length*List), we
31
 * nevertheless have this internal class. (Note that there is an
32
 * SVGAnimatedPathData interface, but that's quite different to
33
 * SVGAnimatedLengthList since it is inherited by elements, as opposed to
34
 * elements having members of that type.) The reason that we have this class is
35
 * to provide a single locked down point of entry to the SVGPathData objects,
36
 * which helps ensure that the DOM wrappers for SVGPathData objects' are always
37
 * kept in sync. This is vitally important (see the comment in
38
 * DOMSVGPathSegList::InternalListWillChangeTo) and frees consumers from having
39
 * to know or worry about wrappers (or forget about them!) for the most part.
40
 */
41
class SVGAnimatedPathSegList final
42
{
43
  // friends so that they can get write access to mBaseVal and mAnimVal
44
  friend class DOMSVGPathSeg;
45
  friend class DOMSVGPathSegList;
46
47
public:
48
  SVGAnimatedPathSegList() {}
49
50
  /**
51
   * Because it's so important that mBaseVal and its DOMSVGPathSegList wrapper
52
   * (if any) be kept in sync (see the comment in
53
   * DOMSVGPathSegList::InternalListWillChangeTo), this method returns a const
54
   * reference. Only our friend classes may get mutable references to mBaseVal.
55
   */
56
0
  const SVGPathData& GetBaseValue() const {
57
0
    return mBaseVal;
58
0
  }
59
60
  nsresult SetBaseValueString(const nsAString& aValue);
61
62
  void ClearBaseValue();
63
64
  /**
65
   * const! See comment for GetBaseValue!
66
   */
67
  const SVGPathData& GetAnimValue() const {
68
    return mAnimVal ? *mAnimVal : mBaseVal;
69
  }
70
71
  nsresult SetAnimValue(const SVGPathData& aValue,
72
                        nsSVGElement *aElement);
73
74
  void ClearAnimValue(nsSVGElement *aElement);
75
76
  /**
77
   * Empty paths are not rendered.
78
   */
79
  bool IsRendered() const;
80
81
  /**
82
   * Needed for correct DOM wrapper construction since GetAnimValue may
83
   * actually return the baseVal!
84
   */
85
0
  void *GetBaseValKey() const {
86
0
    return (void*)&mBaseVal;
87
0
  }
88
0
  void *GetAnimValKey() const {
89
0
    return (void*)&mAnimVal;
90
0
  }
91
92
0
  bool IsAnimating() const {
93
0
    return !!mAnimVal;
94
0
  }
95
96
  UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aElement);
97
98
  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
99
100
private:
101
102
  // mAnimVal is a pointer to allow us to determine if we're being animated or
103
  // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
104
  // if we're animating is not an option, since that would break animation *to*
105
  // the empty string (<set to="">).
106
107
  SVGPathData mBaseVal;
108
  nsAutoPtr<SVGPathData> mAnimVal;
109
110
  struct SMILAnimatedPathSegList : public nsISMILAttr
111
  {
112
  public:
113
    SMILAnimatedPathSegList(SVGAnimatedPathSegList* aVal,
114
                            nsSVGElement* aElement)
115
      : mVal(aVal)
116
      , mElement(aElement)
117
0
    {}
118
119
    // These will stay alive because a nsISMILAttr only lives as long
120
    // as the Compositing step, and DOM elements don't get a chance to
121
    // die during that.
122
    SVGAnimatedPathSegList *mVal;
123
    nsSVGElement *mElement;
124
125
    // nsISMILAttr methods
126
    virtual nsresult ValueFromString(const nsAString& aStr,
127
                                     const dom::SVGAnimationElement* aSrcElement,
128
                                     nsSMILValue& aValue,
129
                                     bool& aPreventCachingOfSandwich) const override;
130
    virtual nsSMILValue GetBaseValue() const override;
131
    virtual void ClearAnimValue() override;
132
    virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
133
  };
134
};
135
136
} // namespace mozilla
137
138
#endif // MOZILLA_SVGANIMATEDPATHSEGLIST_H__