Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsSMILRepeatCount_h |
michael@0 | 7 | #define nsSMILRepeatCount_h |
michael@0 | 8 | |
michael@0 | 9 | #include "nsDebug.h" |
michael@0 | 10 | #include <math.h> |
michael@0 | 11 | |
michael@0 | 12 | //---------------------------------------------------------------------- |
michael@0 | 13 | // nsSMILRepeatCount |
michael@0 | 14 | // |
michael@0 | 15 | // A tri-state non-negative floating point number for representing the number of |
michael@0 | 16 | // times an animation repeat, i.e. the SMIL repeatCount attribute. |
michael@0 | 17 | // |
michael@0 | 18 | // The three states are: |
michael@0 | 19 | // 1. not-set |
michael@0 | 20 | // 2. set (with non-negative, non-zero count value) |
michael@0 | 21 | // 3. indefinite |
michael@0 | 22 | // |
michael@0 | 23 | class nsSMILRepeatCount |
michael@0 | 24 | { |
michael@0 | 25 | public: |
michael@0 | 26 | nsSMILRepeatCount() : mCount(kNotSet) {} |
michael@0 | 27 | explicit nsSMILRepeatCount(double aCount) |
michael@0 | 28 | : mCount(kNotSet) { SetCount(aCount); } |
michael@0 | 29 | |
michael@0 | 30 | operator double() const { |
michael@0 | 31 | MOZ_ASSERT(IsDefinite(), |
michael@0 | 32 | "Converting indefinite or unset repeat count to double"); |
michael@0 | 33 | return mCount; |
michael@0 | 34 | } |
michael@0 | 35 | bool IsDefinite() const { |
michael@0 | 36 | return mCount != kNotSet && mCount != kIndefinite; |
michael@0 | 37 | } |
michael@0 | 38 | bool IsIndefinite() const { return mCount == kIndefinite; } |
michael@0 | 39 | bool IsSet() const { return mCount != kNotSet; } |
michael@0 | 40 | |
michael@0 | 41 | nsSMILRepeatCount& operator=(double aCount) |
michael@0 | 42 | { |
michael@0 | 43 | SetCount(aCount); |
michael@0 | 44 | return *this; |
michael@0 | 45 | } |
michael@0 | 46 | void SetCount(double aCount) |
michael@0 | 47 | { |
michael@0 | 48 | NS_ASSERTION(aCount > 0.0, "Negative or zero repeat count"); |
michael@0 | 49 | mCount = aCount > 0.0 ? aCount : kNotSet; |
michael@0 | 50 | } |
michael@0 | 51 | void SetIndefinite() { mCount = kIndefinite; } |
michael@0 | 52 | void Unset() { mCount = kNotSet; } |
michael@0 | 53 | |
michael@0 | 54 | private: |
michael@0 | 55 | static const double kNotSet; |
michael@0 | 56 | static const double kIndefinite; |
michael@0 | 57 | |
michael@0 | 58 | double mCount; |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | #endif |