dom/smil/nsSMILTimeValue.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/nsSMILTimeValue.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     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 NS_SMILTIMEVALUE_H_
    1.10 +#define NS_SMILTIMEVALUE_H_
    1.11 +
    1.12 +#include "nsSMILTypes.h"
    1.13 +#include "nsDebug.h"
    1.14 +
    1.15 +/*----------------------------------------------------------------------
    1.16 + * nsSMILTimeValue class
    1.17 + *
    1.18 + * A tri-state time value.
    1.19 + *
    1.20 + * First a quick overview of the SMIL time data types:
    1.21 + *
    1.22 + * nsSMILTime          -- a timestamp in milliseconds.
    1.23 + * nsSMILTimeValue     -- (this class) a timestamp that can take the additional
    1.24 + *                        states 'indefinite' and 'unresolved'
    1.25 + * nsSMILInstanceTime  -- an nsSMILTimeValue used for constructing intervals. It
    1.26 + *                        contains additional fields to govern reset behavior
    1.27 + *                        and track timing dependencies (e.g. syncbase timing).
    1.28 + * nsSMILInterval      -- a pair of nsSMILInstanceTimes that defines a begin and
    1.29 + *                        an end time for animation.
    1.30 + * nsSMILTimeValueSpec -- a component of a begin or end attribute, such as the
    1.31 + *                        '5s' or 'a.end+2m' in begin="5s; a.end+2m". Acts as
    1.32 + *                        a broker between an nsSMILTimedElement and its
    1.33 + *                        nsSMILInstanceTimes by generating new instance times
    1.34 + *                        and handling changes to existing times.
    1.35 + *
    1.36 + * Objects of this class may be in one of three states:
    1.37 + *
    1.38 + * 1) The time is resolved and has a definite millisecond value
    1.39 + * 2) The time is resolved and indefinite
    1.40 + * 3) The time is unresolved
    1.41 + *
    1.42 + * In summary:
    1.43 + *
    1.44 + * State      | GetMillis       | IsDefinite | IsIndefinite | IsResolved
    1.45 + * -----------+-----------------+------------+--------------+------------
    1.46 + * Definite   | nsSMILTimeValue | true       | false        | true
    1.47 + * -----------+-----------------+------------+--------------+------------
    1.48 + * Indefinite | --              | false      | true         | true
    1.49 + * -----------+-----------------+------------+--------------+------------
    1.50 + * Unresolved | --              | false      | false        | false
    1.51 + *
    1.52 + */
    1.53 +
    1.54 +class nsSMILTimeValue
    1.55 +{
    1.56 +public:
    1.57 +  // Creates an unresolved time value
    1.58 +  nsSMILTimeValue()
    1.59 +  : mMilliseconds(kUnresolvedMillis),
    1.60 +    mState(STATE_UNRESOLVED)
    1.61 +  { }
    1.62 +
    1.63 +  // Creates a resolved time value
    1.64 +  explicit nsSMILTimeValue(nsSMILTime aMillis)
    1.65 +  : mMilliseconds(aMillis),
    1.66 +    mState(STATE_DEFINITE)
    1.67 +  { }
    1.68 +
    1.69 +  // Named constructor to create an indefinite time value
    1.70 +  static nsSMILTimeValue Indefinite()
    1.71 +  {
    1.72 +    nsSMILTimeValue value;
    1.73 +    value.SetIndefinite();
    1.74 +    return value;
    1.75 +  }
    1.76 +
    1.77 +  bool IsIndefinite() const { return mState == STATE_INDEFINITE; }
    1.78 +  void SetIndefinite()
    1.79 +  {
    1.80 +    mState = STATE_INDEFINITE;
    1.81 +    mMilliseconds = kUnresolvedMillis;
    1.82 +  }
    1.83 +
    1.84 +  bool IsResolved() const { return mState != STATE_UNRESOLVED; }
    1.85 +  void SetUnresolved()
    1.86 +  {
    1.87 +    mState = STATE_UNRESOLVED;
    1.88 +    mMilliseconds = kUnresolvedMillis;
    1.89 +  }
    1.90 +
    1.91 +  bool IsDefinite() const { return mState == STATE_DEFINITE; }
    1.92 +  nsSMILTime GetMillis() const
    1.93 +  {
    1.94 +    NS_ABORT_IF_FALSE(mState == STATE_DEFINITE,
    1.95 +       "GetMillis() called for unresolved or indefinite time");
    1.96 +
    1.97 +    return mState == STATE_DEFINITE ? mMilliseconds : kUnresolvedMillis;
    1.98 +  }
    1.99 +
   1.100 +  void SetMillis(nsSMILTime aMillis)
   1.101 +  {
   1.102 +    mState = STATE_DEFINITE;
   1.103 +    mMilliseconds = aMillis;
   1.104 +  }
   1.105 +
   1.106 +  int8_t CompareTo(const nsSMILTimeValue& aOther) const;
   1.107 +
   1.108 +  bool operator==(const nsSMILTimeValue& aOther) const
   1.109 +  { return CompareTo(aOther) == 0; }
   1.110 +
   1.111 +  bool operator!=(const nsSMILTimeValue& aOther) const
   1.112 +  { return CompareTo(aOther) != 0; }
   1.113 +
   1.114 +  bool operator<(const nsSMILTimeValue& aOther) const
   1.115 +  { return CompareTo(aOther) < 0; }
   1.116 +
   1.117 +  bool operator>(const nsSMILTimeValue& aOther) const
   1.118 +  { return CompareTo(aOther) > 0; }
   1.119 +
   1.120 +  bool operator<=(const nsSMILTimeValue& aOther) const
   1.121 +  { return CompareTo(aOther) <= 0; }
   1.122 +
   1.123 +  bool operator>=(const nsSMILTimeValue& aOther) const
   1.124 +  { return CompareTo(aOther) >= 0; }
   1.125 +
   1.126 +private:
   1.127 +  static nsSMILTime kUnresolvedMillis;
   1.128 +
   1.129 +  nsSMILTime mMilliseconds;
   1.130 +  enum {
   1.131 +    STATE_DEFINITE,
   1.132 +    STATE_INDEFINITE,
   1.133 +    STATE_UNRESOLVED
   1.134 +  } mState;
   1.135 +};
   1.136 +
   1.137 +#endif // NS_SMILTIMEVALUE_H_

mercurial