dom/smil/nsSMILTimeValue.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef NS_SMILTIMEVALUE_H_
     7 #define NS_SMILTIMEVALUE_H_
     9 #include "nsSMILTypes.h"
    10 #include "nsDebug.h"
    12 /*----------------------------------------------------------------------
    13  * nsSMILTimeValue class
    14  *
    15  * A tri-state time value.
    16  *
    17  * First a quick overview of the SMIL time data types:
    18  *
    19  * nsSMILTime          -- a timestamp in milliseconds.
    20  * nsSMILTimeValue     -- (this class) a timestamp that can take the additional
    21  *                        states 'indefinite' and 'unresolved'
    22  * nsSMILInstanceTime  -- an nsSMILTimeValue used for constructing intervals. It
    23  *                        contains additional fields to govern reset behavior
    24  *                        and track timing dependencies (e.g. syncbase timing).
    25  * nsSMILInterval      -- a pair of nsSMILInstanceTimes that defines a begin and
    26  *                        an end time for animation.
    27  * nsSMILTimeValueSpec -- a component of a begin or end attribute, such as the
    28  *                        '5s' or 'a.end+2m' in begin="5s; a.end+2m". Acts as
    29  *                        a broker between an nsSMILTimedElement and its
    30  *                        nsSMILInstanceTimes by generating new instance times
    31  *                        and handling changes to existing times.
    32  *
    33  * Objects of this class may be in one of three states:
    34  *
    35  * 1) The time is resolved and has a definite millisecond value
    36  * 2) The time is resolved and indefinite
    37  * 3) The time is unresolved
    38  *
    39  * In summary:
    40  *
    41  * State      | GetMillis       | IsDefinite | IsIndefinite | IsResolved
    42  * -----------+-----------------+------------+--------------+------------
    43  * Definite   | nsSMILTimeValue | true       | false        | true
    44  * -----------+-----------------+------------+--------------+------------
    45  * Indefinite | --              | false      | true         | true
    46  * -----------+-----------------+------------+--------------+------------
    47  * Unresolved | --              | false      | false        | false
    48  *
    49  */
    51 class nsSMILTimeValue
    52 {
    53 public:
    54   // Creates an unresolved time value
    55   nsSMILTimeValue()
    56   : mMilliseconds(kUnresolvedMillis),
    57     mState(STATE_UNRESOLVED)
    58   { }
    60   // Creates a resolved time value
    61   explicit nsSMILTimeValue(nsSMILTime aMillis)
    62   : mMilliseconds(aMillis),
    63     mState(STATE_DEFINITE)
    64   { }
    66   // Named constructor to create an indefinite time value
    67   static nsSMILTimeValue Indefinite()
    68   {
    69     nsSMILTimeValue value;
    70     value.SetIndefinite();
    71     return value;
    72   }
    74   bool IsIndefinite() const { return mState == STATE_INDEFINITE; }
    75   void SetIndefinite()
    76   {
    77     mState = STATE_INDEFINITE;
    78     mMilliseconds = kUnresolvedMillis;
    79   }
    81   bool IsResolved() const { return mState != STATE_UNRESOLVED; }
    82   void SetUnresolved()
    83   {
    84     mState = STATE_UNRESOLVED;
    85     mMilliseconds = kUnresolvedMillis;
    86   }
    88   bool IsDefinite() const { return mState == STATE_DEFINITE; }
    89   nsSMILTime GetMillis() const
    90   {
    91     NS_ABORT_IF_FALSE(mState == STATE_DEFINITE,
    92        "GetMillis() called for unresolved or indefinite time");
    94     return mState == STATE_DEFINITE ? mMilliseconds : kUnresolvedMillis;
    95   }
    97   void SetMillis(nsSMILTime aMillis)
    98   {
    99     mState = STATE_DEFINITE;
   100     mMilliseconds = aMillis;
   101   }
   103   int8_t CompareTo(const nsSMILTimeValue& aOther) const;
   105   bool operator==(const nsSMILTimeValue& aOther) const
   106   { return CompareTo(aOther) == 0; }
   108   bool operator!=(const nsSMILTimeValue& aOther) const
   109   { return CompareTo(aOther) != 0; }
   111   bool operator<(const nsSMILTimeValue& aOther) const
   112   { return CompareTo(aOther) < 0; }
   114   bool operator>(const nsSMILTimeValue& aOther) const
   115   { return CompareTo(aOther) > 0; }
   117   bool operator<=(const nsSMILTimeValue& aOther) const
   118   { return CompareTo(aOther) <= 0; }
   120   bool operator>=(const nsSMILTimeValue& aOther) const
   121   { return CompareTo(aOther) >= 0; }
   123 private:
   124   static nsSMILTime kUnresolvedMillis;
   126   nsSMILTime mMilliseconds;
   127   enum {
   128     STATE_DEFINITE,
   129     STATE_INDEFINITE,
   130     STATE_UNRESOLVED
   131   } mState;
   132 };
   134 #endif // NS_SMILTIMEVALUE_H_

mercurial