Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/nsSVGEnum.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 __NS_SVGENUM_H__
8
#define __NS_SVGENUM_H__
9
10
#include "nsCycleCollectionParticipant.h"
11
#include "nsError.h"
12
#include "nsISMILAttr.h"
13
#include "nsSVGElement.h"
14
#include "mozilla/Attributes.h"
15
#include "mozilla/dom/SVGAnimatedEnumeration.h"
16
#include "mozilla/UniquePtr.h"
17
18
class nsAtom;
19
class nsSMILValue;
20
21
namespace mozilla {
22
namespace dom {
23
class SVGAnimationElement;
24
} // namespace dom
25
} // namespace mozilla
26
27
typedef uint8_t nsSVGEnumValue;
28
29
struct nsSVGEnumMapping {
30
  nsStaticAtom** mKey;
31
  nsSVGEnumValue mVal;
32
};
33
34
class nsSVGEnum
35
{
36
public:
37
0
  void Init(uint8_t aAttrEnum, uint16_t aValue) {
38
0
    mAnimVal = mBaseVal = uint8_t(aValue);
39
0
    mAttrEnum = aAttrEnum;
40
0
    mIsAnimated = false;
41
0
    mIsBaseSet = false;
42
0
  }
43
44
  nsresult SetBaseValueAtom(const nsAtom* aValue, nsSVGElement *aSVGElement);
45
  nsAtom* GetBaseValueAtom(nsSVGElement *aSVGElement);
46
  nsresult SetBaseValue(uint16_t aValue,
47
                        nsSVGElement *aSVGElement);
48
  uint16_t GetBaseValue() const
49
0
    { return mBaseVal; }
50
51
  void SetAnimValue(uint16_t aValue, nsSVGElement *aSVGElement);
52
  uint16_t GetAnimValue() const
53
0
    { return mAnimVal; }
54
  bool IsExplicitlySet() const
55
0
    { return mIsAnimated || mIsBaseSet; }
56
57
  already_AddRefed<mozilla::dom::SVGAnimatedEnumeration>
58
  ToDOMAnimatedEnum(nsSVGElement* aSVGElement);
59
60
  mozilla::UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
61
62
private:
63
  nsSVGEnumValue mAnimVal;
64
  nsSVGEnumValue mBaseVal;
65
  uint8_t mAttrEnum; // element specified tracking for attribute
66
  bool mIsAnimated;
67
  bool mIsBaseSet;
68
69
  nsSVGEnumMapping *GetMapping(nsSVGElement *aSVGElement);
70
71
public:
72
  struct DOMAnimatedEnum final : public mozilla::dom::SVGAnimatedEnumeration
73
  {
74
    DOMAnimatedEnum(nsSVGEnum* aVal, nsSVGElement *aSVGElement)
75
      : mozilla::dom::SVGAnimatedEnumeration(aSVGElement)
76
      , mVal(aVal)
77
0
    {}
78
    virtual ~DOMAnimatedEnum();
79
80
    nsSVGEnum *mVal; // kept alive because it belongs to content
81
82
    using mozilla::dom::SVGAnimatedEnumeration::SetBaseVal;
83
    virtual uint16_t BaseVal() override
84
0
    {
85
0
      return mVal->GetBaseValue();
86
0
    }
87
    virtual void SetBaseVal(uint16_t aBaseVal,
88
                            mozilla::ErrorResult& aRv) override
89
0
    {
90
0
      aRv = mVal->SetBaseValue(aBaseVal, mSVGElement);
91
0
    }
92
    virtual uint16_t AnimVal() override
93
0
    {
94
0
      // Script may have modified animation parameters or timeline -- DOM
95
0
      // getters need to flush any resample requests to reflect these
96
0
      // modifications.
97
0
      mSVGElement->FlushAnimations();
98
0
      return mVal->GetAnimValue();
99
0
    }
100
  };
101
102
  struct SMILEnum : public nsISMILAttr
103
  {
104
  public:
105
    SMILEnum(nsSVGEnum* aVal, nsSVGElement* aSVGElement)
106
0
      : mVal(aVal), mSVGElement(aSVGElement) {}
107
108
    // These will stay alive because a nsISMILAttr only lives as long
109
    // as the Compositing step, and DOM elements don't get a chance to
110
    // die during that.
111
    nsSVGEnum* mVal;
112
    nsSVGElement* mSVGElement;
113
114
    // nsISMILAttr methods
115
    virtual nsresult ValueFromString(const nsAString& aStr,
116
                                     const mozilla::dom::SVGAnimationElement* aSrcElement,
117
                                     nsSMILValue& aValue,
118
                                     bool& aPreventCachingOfSandwich) const override;
119
    virtual nsSMILValue GetBaseValue() const override;
120
    virtual void ClearAnimValue() override;
121
    virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
122
  };
123
};
124
125
#endif //__NS_SVGENUM_H__