Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGAnimatedNumberList.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_SVGANIMATEDNUMBERLIST_H__
8
#define MOZILLA_SVGANIMATEDNUMBERLIST_H__
9
10
#include "mozilla/Attributes.h"
11
#include "mozilla/UniquePtr.h"
12
#include "nsAutoPtr.h"
13
#include "nsISMILAttr.h"
14
#include "SVGNumberList.h"
15
16
class nsSMILValue;
17
class nsSVGElement;
18
19
namespace mozilla {
20
21
namespace dom {
22
class SVGAnimationElement;
23
} // namespace dom
24
25
/**
26
 * Class SVGAnimatedNumberList
27
 *
28
 * This class is very different to the SVG DOM interface of the same name found
29
 * in the SVG specification. This is a lightweight internal class - see
30
 * DOMSVGAnimatedNumberList for the heavier DOM class that wraps instances of
31
 * this class and implements the SVG specification's SVGAnimatedNumberList DOM
32
 * interface.
33
 *
34
 * Except where noted otherwise, this class' methods take care of keeping the
35
 * appropriate DOM wrappers in sync (see the comment in
36
 * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo) so that their
37
 * consumers don't need to concern themselves with that.
38
 */
39
class SVGAnimatedNumberList
40
{
41
  // friends so that they can get write access to mBaseVal
42
  friend class DOMSVGNumber;
43
  friend class DOMSVGNumberList;
44
45
public:
46
  SVGAnimatedNumberList()
47
    : mIsBaseSet(false)
48
0
  {}
49
50
  /**
51
   * Because it's so important that mBaseVal and its DOMSVGNumberList wrapper
52
   * (if any) be kept in sync (see the comment in
53
   * DOMSVGAnimatedNumberList::InternalBaseValListWillChangeTo), this method
54
   * returns a const reference. Only our friend classes may get mutable
55
   * references to mBaseVal.
56
   */
57
0
  const SVGNumberList& GetBaseValue() const {
58
0
    return mBaseVal;
59
0
  }
60
61
  nsresult SetBaseValueString(const nsAString& aValue);
62
63
  void ClearBaseValue(uint32_t aAttrEnum);
64
65
0
  const SVGNumberList& GetAnimValue() const {
66
0
    return mAnimVal ? *mAnimVal : mBaseVal;
67
0
  }
68
69
  nsresult SetAnimValue(const SVGNumberList& aValue,
70
                        nsSVGElement *aElement,
71
                        uint32_t aAttrEnum);
72
73
  void ClearAnimValue(nsSVGElement *aElement,
74
                      uint32_t aAttrEnum);
75
76
  // Returns true if the animated value of this list has been explicitly
77
  // set (either by animation, or by taking on the base value which has been
78
  // explicitly set by markup or a DOM call), false otherwise.
79
  // If this returns false, the animated value is still valid, that is,
80
  // usable, and represents the default base value of the attribute.
81
  bool IsExplicitlySet() const
82
0
    { return !!mAnimVal || mIsBaseSet; }
83
84
0
  bool IsAnimating() const {
85
0
    return !!mAnimVal;
86
0
  }
87
88
  UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement,
89
                                    uint8_t aAttrEnum);
90
91
private:
92
93
  // mAnimVal is a pointer to allow us to determine if we're being animated or
94
  // not. Making it a non-pointer member and using mAnimVal.IsEmpty() to check
95
  // if we're animating is not an option, since that would break animation *to*
96
  // the empty string (<set to="">).
97
98
  SVGNumberList mBaseVal;
99
  nsAutoPtr<SVGNumberList> mAnimVal;
100
  bool mIsBaseSet;
101
102
  struct SMILAnimatedNumberList : public nsISMILAttr
103
  {
104
  public:
105
    SMILAnimatedNumberList(SVGAnimatedNumberList* aVal,
106
                           nsSVGElement* aSVGElement,
107
                           uint8_t aAttrEnum)
108
      : mVal(aVal)
109
      , mElement(aSVGElement)
110
      , mAttrEnum(aAttrEnum)
111
0
    {}
112
113
    // These will stay alive because a nsISMILAttr only lives as long
114
    // as the Compositing step, and DOM elements don't get a chance to
115
    // die during that.
116
    SVGAnimatedNumberList* mVal;
117
    nsSVGElement* mElement;
118
    uint8_t mAttrEnum;
119
120
    // nsISMILAttr methods
121
    virtual nsresult ValueFromString(const nsAString& aStr,
122
                                     const dom::SVGAnimationElement* aSrcElement,
123
                                     nsSMILValue& aValue,
124
                                     bool& aPreventCachingOfSandwich) const override;
125
    virtual nsSMILValue GetBaseValue() const override;
126
    virtual void ClearAnimValue() override;
127
    virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
128
  };
129
};
130
131
} // namespace mozilla
132
133
#endif // MOZILLA_SVGANIMATEDNUMBERLIST_H__