dom/smil/nsSMILRepeatCount.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/nsSMILRepeatCount.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsSMILRepeatCount_h
    1.10 +#define nsSMILRepeatCount_h
    1.11 +
    1.12 +#include "nsDebug.h"
    1.13 +#include <math.h>
    1.14 +
    1.15 +//----------------------------------------------------------------------
    1.16 +// nsSMILRepeatCount
    1.17 +//
    1.18 +// A tri-state non-negative floating point number for representing the number of
    1.19 +// times an animation repeat, i.e. the SMIL repeatCount attribute.
    1.20 +//
    1.21 +// The three states are:
    1.22 +//  1. not-set
    1.23 +//  2. set (with non-negative, non-zero count value)
    1.24 +//  3. indefinite
    1.25 +//
    1.26 +class nsSMILRepeatCount
    1.27 +{
    1.28 +public:
    1.29 +  nsSMILRepeatCount() : mCount(kNotSet) {}
    1.30 +  explicit nsSMILRepeatCount(double aCount)
    1.31 +    : mCount(kNotSet) { SetCount(aCount); }
    1.32 +
    1.33 +  operator double() const {
    1.34 +    MOZ_ASSERT(IsDefinite(),
    1.35 +      "Converting indefinite or unset repeat count to double");
    1.36 +    return mCount;
    1.37 +  }
    1.38 +  bool IsDefinite() const {
    1.39 +    return mCount != kNotSet && mCount != kIndefinite;
    1.40 +  }
    1.41 +  bool IsIndefinite() const { return mCount == kIndefinite; }
    1.42 +  bool IsSet() const { return mCount != kNotSet; }
    1.43 +
    1.44 +  nsSMILRepeatCount& operator=(double aCount)
    1.45 +  {
    1.46 +    SetCount(aCount);
    1.47 +    return *this;
    1.48 +  }
    1.49 +  void SetCount(double aCount)
    1.50 +  {
    1.51 +    NS_ASSERTION(aCount > 0.0, "Negative or zero repeat count");
    1.52 +    mCount = aCount > 0.0 ? aCount : kNotSet;
    1.53 +  }
    1.54 +  void SetIndefinite() { mCount = kIndefinite; }
    1.55 +  void Unset() { mCount = kNotSet; }
    1.56 +
    1.57 +private:
    1.58 +  static const double kNotSet;
    1.59 +  static const double kIndefinite;
    1.60 +
    1.61 +  double  mCount;
    1.62 +};
    1.63 +
    1.64 +#endif

mercurial