gecko/content/smil/nsSMILRepeatCount.h
Brian Birtles 096d486b89 Bug 948245 part 1 - Rework and test repeat duration calculation; r=dholbert
In order to implement the min attribute properly we need to distinguish between
cases where the repeat duration is less than the active duration so we can apply
the fill mode in the 'gap'. Currently the repeat duration calculation is mostly
contained in GetRepeatDuration (but is hard to make sense of) and partly
contained in the call site CalcActiveEnd. Furthermore, it does not have thorough
tests (there were some unit tests but they were never converted to mochitests).

This patch reworks the repeat duration calculation so it is contained in one
place, easier to read, and thoroughly tested.
2013-12-13 13:41:47 +09:00

62 lines
1.7 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsSMILRepeatCount_h
#define nsSMILRepeatCount_h
#include "nsDebug.h"
#include <math.h>
//----------------------------------------------------------------------
// nsSMILRepeatCount
//
// A tri-state non-negative floating point number for representing the number of
// times an animation repeat, i.e. the SMIL repeatCount attribute.
//
// The three states are:
// 1. not-set
// 2. set (with non-negative, non-zero count value)
// 3. indefinite
//
class nsSMILRepeatCount
{
public:
nsSMILRepeatCount() : mCount(kNotSet) {}
explicit nsSMILRepeatCount(double aCount)
: mCount(kNotSet) { SetCount(aCount); }
operator double() const {
MOZ_ASSERT(IsDefinite(),
"Converting indefinite or unset repeat count to double");
return mCount;
}
bool IsDefinite() const {
return mCount != kNotSet && mCount != kIndefinite;
}
bool IsIndefinite() const { return mCount == kIndefinite; }
bool IsSet() const { return mCount != kNotSet; }
nsSMILRepeatCount& operator=(double aCount)
{
SetCount(aCount);
return *this;
}
void SetCount(double aCount)
{
NS_ASSERTION(aCount > 0.0, "Negative or zero repeat count");
mCount = aCount > 0.0 ? aCount : kNotSet;
}
void SetIndefinite() { mCount = kIndefinite; }
void Unset() { mCount = kNotSet; }
private:
static const double kNotSet;
static const double kIndefinite;
double mCount;
};
#endif