Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGAnimatedPreserveAspectRatio.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_SVGANIMATEDPRESERVEASPECTRATIO_H__
8
#define MOZILLA_SVGANIMATEDPRESERVEASPECTRATIO_H__
9
10
#include "nsCycleCollectionParticipant.h"
11
#include "nsError.h"
12
#include "nsISMILAttr.h"
13
#include "nsSVGElement.h"
14
#include "SVGPreserveAspectRatio.h"
15
#include "mozilla/Attributes.h"
16
#include "mozilla/UniquePtr.h"
17
18
class nsSMILValue;
19
20
namespace mozilla {
21
namespace dom {
22
class DOMSVGAnimatedPreserveAspectRatio;
23
class SVGAnimationElement;
24
} // namespace dom
25
26
class SVGAnimatedPreserveAspectRatio final
27
{
28
public:
29
0
  void Init() {
30
0
    mBaseVal.mAlign =
31
0
      dom::SVGPreserveAspectRatio_Binding::SVG_PRESERVEASPECTRATIO_XMIDYMID;
32
0
    mBaseVal.mMeetOrSlice =
33
0
      dom::SVGPreserveAspectRatio_Binding::SVG_MEETORSLICE_MEET;
34
0
    mAnimVal = mBaseVal;
35
0
    mIsAnimated = false;
36
0
    mIsBaseSet = false;
37
0
  }
38
39
  nsresult SetBaseValueString(const nsAString& aValue,
40
                              nsSVGElement *aSVGElement,
41
                              bool aDoSetAttr);
42
  void GetBaseValueString(nsAString& aValue) const;
43
44
  void SetBaseValue(const SVGPreserveAspectRatio &aValue,
45
                    nsSVGElement *aSVGElement);
46
0
  nsresult SetBaseAlign(uint16_t aAlign, nsSVGElement *aSVGElement) {
47
0
    if (aAlign < SVG_ALIGN_MIN_VALID || aAlign > SVG_ALIGN_MAX_VALID) {
48
0
      return NS_ERROR_FAILURE;
49
0
    }
50
0
    SetBaseValue(SVGPreserveAspectRatio(aAlign, mBaseVal.GetMeetOrSlice()),
51
0
                 aSVGElement);
52
0
    return NS_OK;
53
0
  }
54
0
  nsresult SetBaseMeetOrSlice(uint16_t aMeetOrSlice, nsSVGElement *aSVGElement) {
55
0
    if (aMeetOrSlice < SVG_MEETORSLICE_MIN_VALID ||
56
0
        aMeetOrSlice > SVG_MEETORSLICE_MAX_VALID) {
57
0
      return NS_ERROR_FAILURE;
58
0
    }
59
0
    SetBaseValue(SVGPreserveAspectRatio(mBaseVal.GetAlign(), aMeetOrSlice),
60
0
                 aSVGElement);
61
0
    return NS_OK;
62
0
  }
63
  void SetAnimValue(uint64_t aPackedValue, nsSVGElement *aSVGElement);
64
65
  const SVGPreserveAspectRatio &GetBaseValue() const
66
0
    { return mBaseVal; }
67
  const SVGPreserveAspectRatio &GetAnimValue() const
68
0
    { return mAnimVal; }
69
  bool IsAnimated() const
70
0
    { return mIsAnimated; }
71
  bool IsExplicitlySet() const
72
0
    { return mIsAnimated || mIsBaseSet; }
73
74
  already_AddRefed<mozilla::dom::DOMSVGAnimatedPreserveAspectRatio>
75
  ToDOMAnimatedPreserveAspectRatio(nsSVGElement* aSVGElement);
76
  UniquePtr<nsISMILAttr> ToSMILAttr(nsSVGElement* aSVGElement);
77
78
private:
79
80
  SVGPreserveAspectRatio mAnimVal;
81
  SVGPreserveAspectRatio mBaseVal;
82
  bool mIsAnimated;
83
  bool mIsBaseSet;
84
85
public:
86
  struct SMILPreserveAspectRatio final : public nsISMILAttr
87
  {
88
  public:
89
    SMILPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
90
                            nsSVGElement* aSVGElement)
91
0
      : mVal(aVal), mSVGElement(aSVGElement) {}
92
93
    // These will stay alive because a nsISMILAttr only lives as long
94
    // as the Compositing step, and DOM elements don't get a chance to
95
    // die during that.
96
    SVGAnimatedPreserveAspectRatio* mVal;
97
    nsSVGElement* mSVGElement;
98
99
    // nsISMILAttr methods
100
    virtual nsresult ValueFromString(const nsAString& aStr,
101
                                     const dom::SVGAnimationElement* aSrcElement,
102
                                     nsSMILValue& aValue,
103
                                     bool& aPreventCachingOfSandwich) const override;
104
    virtual nsSMILValue GetBaseValue() const override;
105
    virtual void ClearAnimValue() override;
106
    virtual nsresult SetAnimValue(const nsSMILValue& aValue) override;
107
  };
108
};
109
110
namespace dom {
111
class DOMSVGAnimatedPreserveAspectRatio final : public nsISupports,
112
                                                public nsWrapperCache
113
{
114
  ~DOMSVGAnimatedPreserveAspectRatio();
115
116
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
117
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMSVGAnimatedPreserveAspectRatio)
118
119
  DOMSVGAnimatedPreserveAspectRatio(SVGAnimatedPreserveAspectRatio* aVal,
120
                                    nsSVGElement *aSVGElement)
121
    : mVal(aVal), mSVGElement(aSVGElement)
122
0
  {
123
0
  }
124
125
  // WebIDL
126
0
  nsSVGElement* GetParentObject() const { return mSVGElement; }
127
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
128
129
  // These aren't weak refs because new objects are returned each time
130
  already_AddRefed<DOMSVGPreserveAspectRatio> BaseVal();
131
  already_AddRefed<DOMSVGPreserveAspectRatio> AnimVal();
132
133
protected:
134
  // kept alive because it belongs to content:
135
  SVGAnimatedPreserveAspectRatio* mVal;
136
  RefPtr<nsSVGElement> mSVGElement;
137
};
138
139
} // namespace dom
140
} // namespace mozilla
141
142
#endif // MOZILLA_SVGANIMATEDPRESERVEASPECTRATIO_H__