Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/nsSVGInteger.cpp
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
#include "nsError.h"
8
#include "nsSVGAttrTearoffTable.h"
9
#include "nsSVGInteger.h"
10
#include "nsSMILValue.h"
11
#include "SMILIntegerType.h"
12
#include "SVGContentUtils.h"
13
14
using namespace mozilla;
15
using namespace mozilla::dom;
16
17
/* Implementation */
18
19
static nsSVGAttrTearoffTable<nsSVGInteger, nsSVGInteger::DOMAnimatedInteger>
20
  sSVGAnimatedIntegerTearoffTable;
21
22
nsresult
23
nsSVGInteger::SetBaseValueString(const nsAString &aValueAsString,
24
                                 nsSVGElement *aSVGElement)
25
0
{
26
0
  int32_t value;
27
0
28
0
  if (!SVGContentUtils::ParseInteger(aValueAsString, value)) {
29
0
    return NS_ERROR_DOM_SYNTAX_ERR;
30
0
  }
31
0
32
0
  mIsBaseSet = true;
33
0
  mBaseVal = value;
34
0
  if (!mIsAnimated) {
35
0
    mAnimVal = mBaseVal;
36
0
  }
37
0
  else {
38
0
    aSVGElement->AnimationNeedsResample();
39
0
  }
40
0
  return NS_OK;
41
0
}
42
43
void
44
nsSVGInteger::GetBaseValueString(nsAString & aValueAsString)
45
0
{
46
0
  aValueAsString.Truncate();
47
0
  aValueAsString.AppendInt(mBaseVal);
48
0
}
49
50
void
51
nsSVGInteger::SetBaseValue(int aValue, nsSVGElement *aSVGElement)
52
0
{
53
0
  // We can't just rely on SetParsedAttrValue (as called by DidChangeInteger)
54
0
  // detecting redundant changes since it will compare false if the existing
55
0
  // attribute value has an associated serialized version (a string value) even
56
0
  // if the integers match due to the way integers are stored in nsAttrValue.
57
0
  if (aValue == mBaseVal && mIsBaseSet) {
58
0
    return;
59
0
  }
60
0
61
0
  mBaseVal = aValue;
62
0
  mIsBaseSet = true;
63
0
  if (!mIsAnimated) {
64
0
    mAnimVal = mBaseVal;
65
0
  }
66
0
  else {
67
0
    aSVGElement->AnimationNeedsResample();
68
0
  }
69
0
  aSVGElement->DidChangeInteger(mAttrEnum);
70
0
}
71
72
void
73
nsSVGInteger::SetAnimValue(int aValue, nsSVGElement *aSVGElement)
74
0
{
75
0
  if (mIsAnimated && aValue == mAnimVal) {
76
0
    return;
77
0
  }
78
0
  mAnimVal = aValue;
79
0
  mIsAnimated = true;
80
0
  aSVGElement->DidAnimateInteger(mAttrEnum);
81
0
}
82
83
already_AddRefed<SVGAnimatedInteger>
84
nsSVGInteger::ToDOMAnimatedInteger(nsSVGElement *aSVGElement)
85
0
{
86
0
  RefPtr<DOMAnimatedInteger> domAnimatedInteger =
87
0
    sSVGAnimatedIntegerTearoffTable.GetTearoff(this);
88
0
  if (!domAnimatedInteger) {
89
0
    domAnimatedInteger = new DOMAnimatedInteger(this, aSVGElement);
90
0
    sSVGAnimatedIntegerTearoffTable.AddTearoff(this, domAnimatedInteger);
91
0
  }
92
0
93
0
  return domAnimatedInteger.forget();
94
0
}
95
96
nsSVGInteger::DOMAnimatedInteger::~DOMAnimatedInteger()
97
0
{
98
0
  sSVGAnimatedIntegerTearoffTable.RemoveTearoff(mVal);
99
0
}
100
101
UniquePtr<nsISMILAttr>
102
nsSVGInteger::ToSMILAttr(nsSVGElement *aSVGElement)
103
0
{
104
0
  return MakeUnique<SMILInteger>(this, aSVGElement);
105
0
}
106
107
nsresult
108
nsSVGInteger::SMILInteger::ValueFromString(const nsAString& aStr,
109
                                           const dom::SVGAnimationElement* /*aSrcElement*/,
110
                                           nsSMILValue& aValue,
111
                                           bool& aPreventCachingOfSandwich) const
112
0
{
113
0
  int32_t val;
114
0
115
0
  if (!SVGContentUtils::ParseInteger(aStr, val)) {
116
0
    return NS_ERROR_DOM_SYNTAX_ERR;
117
0
  }
118
0
119
0
  nsSMILValue smilVal(SMILIntegerType::Singleton());
120
0
  smilVal.mU.mInt = val;
121
0
  aValue = smilVal;
122
0
  aPreventCachingOfSandwich = false;
123
0
  return NS_OK;
124
0
}
125
126
nsSMILValue
127
nsSVGInteger::SMILInteger::GetBaseValue() const
128
0
{
129
0
  nsSMILValue val(SMILIntegerType::Singleton());
130
0
  val.mU.mInt = mVal->mBaseVal;
131
0
  return val;
132
0
}
133
134
void
135
nsSVGInteger::SMILInteger::ClearAnimValue()
136
0
{
137
0
  if (mVal->mIsAnimated) {
138
0
    mVal->mIsAnimated = false;
139
0
    mVal->mAnimVal = mVal->mBaseVal;
140
0
    mSVGElement->DidAnimateInteger(mVal->mAttrEnum);
141
0
  }
142
0
}
143
144
nsresult
145
nsSVGInteger::SMILInteger::SetAnimValue(const nsSMILValue& aValue)
146
0
{
147
0
  NS_ASSERTION(aValue.mType == SMILIntegerType::Singleton(),
148
0
               "Unexpected type to assign animated value");
149
0
  if (aValue.mType == SMILIntegerType::Singleton()) {
150
0
    mVal->SetAnimValue(int(aValue.mU.mInt), mSVGElement);
151
0
  }
152
0
  return NS_OK;
153
0
}