tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SMILRepeatCount.h (1820B)


      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 DOM_SMIL_SMILREPEATCOUNT_H_
      8 #define DOM_SMIL_SMILREPEATCOUNT_H_
      9 
     10 #include <math.h>
     11 
     12 #include "nsDebug.h"
     13 
     14 namespace mozilla {
     15 
     16 //----------------------------------------------------------------------
     17 // SMILRepeatCount
     18 //
     19 // A tri-state non-negative floating point number for representing the number of
     20 // times an animation repeat, i.e. the SMIL repeatCount attribute.
     21 //
     22 // The three states are:
     23 //  1. not-set
     24 //  2. set (with non-negative, non-zero count value)
     25 //  3. indefinite
     26 //
     27 class SMILRepeatCount {
     28 public:
     29  SMILRepeatCount() : mCount(kNotSet) {}
     30  explicit SMILRepeatCount(double aCount) : mCount(kNotSet) {
     31    SetCount(aCount);
     32  }
     33 
     34  operator double() const {
     35    MOZ_ASSERT(IsDefinite(),
     36               "Converting indefinite or unset repeat count to double");
     37    return mCount;
     38  }
     39  bool IsDefinite() const { return mCount != kNotSet && mCount != kIndefinite; }
     40  bool IsIndefinite() const { return mCount == kIndefinite; }
     41  bool IsSet() const { return mCount != kNotSet; }
     42 
     43  SMILRepeatCount& operator=(double aCount) {
     44    SetCount(aCount);
     45    return *this;
     46  }
     47  void SetCount(double aCount) {
     48    NS_ASSERTION(aCount > 0.0, "Negative or zero repeat count");
     49    mCount = aCount > 0.0 ? aCount : kNotSet;
     50  }
     51  void SetIndefinite() { mCount = kIndefinite; }
     52  void Unset() { mCount = kNotSet; }
     53 
     54 private:
     55  static const double kNotSet;
     56  static const double kIndefinite;
     57 
     58  double mCount;
     59 };
     60 
     61 }  // namespace mozilla
     62 
     63 #endif  // DOM_SMIL_SMILREPEATCOUNT_H_