dom/smil/nsSMILInstanceTime.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/nsSMILInstanceTime.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,166 @@
     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_SMILINSTANCETIME_H_
    1.10 +#define NS_SMILINSTANCETIME_H_
    1.11 +
    1.12 +#include "nsSMILTimeValue.h"
    1.13 +#include "nsAutoPtr.h"
    1.14 +
    1.15 +class nsSMILInterval;
    1.16 +class nsSMILTimeContainer;
    1.17 +class nsSMILTimeValueSpec;
    1.18 +
    1.19 +//----------------------------------------------------------------------
    1.20 +// nsSMILInstanceTime
    1.21 +//
    1.22 +// An instant in document simple time that may be used in creating a new
    1.23 +// interval.
    1.24 +//
    1.25 +// For an overview of how this class is related to other SMIL time classes see
    1.26 +// the documentation in nsSMILTimeValue.h
    1.27 +//
    1.28 +// These objects are owned by an nsSMILTimedElement but MAY also be referenced
    1.29 +// by:
    1.30 +//
    1.31 +// a) nsSMILIntervals that belong to the same nsSMILTimedElement and which refer
    1.32 +//    to the nsSMILInstanceTimes which form the interval endpoints; and/or
    1.33 +// b) nsSMILIntervals that belong to other nsSMILTimedElements but which need to
    1.34 +//    update dependent instance times when they change or are deleted.
    1.35 +//    E.g. for begin='a.begin', 'a' needs to inform dependent
    1.36 +//    nsSMILInstanceTimes if its begin time changes. This notification is
    1.37 +//    performed by the nsSMILInterval.
    1.38 +
    1.39 +class nsSMILInstanceTime MOZ_FINAL
    1.40 +{
    1.41 +public:
    1.42 +  // Instance time source. Times generated by events, syncbase relationships,
    1.43 +  // and DOM calls behave differently in some circumstances such as when a timed
    1.44 +  // element is reset.
    1.45 +  enum nsSMILInstanceTimeSource {
    1.46 +    // No particularly significant source, e.g. offset time, 'indefinite'
    1.47 +    SOURCE_NONE,
    1.48 +    // Generated by a DOM call such as beginElement
    1.49 +    SOURCE_DOM,
    1.50 +    // Generated by a syncbase relationship
    1.51 +    SOURCE_SYNCBASE,
    1.52 +    // Generated by an event
    1.53 +    SOURCE_EVENT
    1.54 +  };
    1.55 +
    1.56 +  nsSMILInstanceTime(const nsSMILTimeValue& aTime,
    1.57 +                     nsSMILInstanceTimeSource aSource = SOURCE_NONE,
    1.58 +                     nsSMILTimeValueSpec* aCreator = nullptr,
    1.59 +                     nsSMILInterval* aBaseInterval = nullptr);
    1.60 +
    1.61 +  void Unlink();
    1.62 +  void HandleChangedInterval(const nsSMILTimeContainer* aSrcContainer,
    1.63 +                             bool aBeginObjectChanged,
    1.64 +                             bool aEndObjectChanged);
    1.65 +  void HandleDeletedInterval();
    1.66 +  void HandleFilteredInterval();
    1.67 +
    1.68 +  const nsSMILTimeValue& Time() const { return mTime; }
    1.69 +  const nsSMILTimeValueSpec* GetCreator() const { return mCreator; }
    1.70 +
    1.71 +  bool IsDynamic() const { return !!(mFlags & kDynamic); }
    1.72 +  bool IsFixedTime() const { return !(mFlags & kMayUpdate); }
    1.73 +  bool FromDOM() const { return !!(mFlags & kFromDOM); }
    1.74 +
    1.75 +  bool ShouldPreserve() const;
    1.76 +  void   UnmarkShouldPreserve();
    1.77 +
    1.78 +  void AddRefFixedEndpoint();
    1.79 +  void ReleaseFixedEndpoint();
    1.80 +
    1.81 +  void DependentUpdate(const nsSMILTimeValue& aNewTime)
    1.82 +  {
    1.83 +    NS_ABORT_IF_FALSE(!IsFixedTime(),
    1.84 +        "Updating an instance time that is not expected to be updated");
    1.85 +    mTime = aNewTime;
    1.86 +  }
    1.87 +
    1.88 +  bool IsDependent() const { return !!mBaseInterval; }
    1.89 +  bool IsDependentOn(const nsSMILInstanceTime& aOther) const;
    1.90 +  const nsSMILInterval* GetBaseInterval() const { return mBaseInterval; }
    1.91 +  const nsSMILInstanceTime* GetBaseTime() const;
    1.92 +
    1.93 +  bool SameTimeAndBase(const nsSMILInstanceTime& aOther) const
    1.94 +  {
    1.95 +    return mTime == aOther.mTime && GetBaseTime() == aOther.GetBaseTime();
    1.96 +  }
    1.97 +
    1.98 +  // Get and set a serial number which may be used by a containing class to
    1.99 +  // control the sort order of otherwise similar instance times.
   1.100 +  uint32_t Serial() const { return mSerial; }
   1.101 +  void SetSerial(uint32_t aIndex) { mSerial = aIndex; }
   1.102 +
   1.103 +  NS_INLINE_DECL_REFCOUNTING(nsSMILInstanceTime)
   1.104 +
   1.105 +private:
   1.106 +  // Private destructor, to discourage deletion outside of Release():
   1.107 +  ~nsSMILInstanceTime();
   1.108 +
   1.109 +  void SetBaseInterval(nsSMILInterval* aBaseInterval);
   1.110 +
   1.111 +  nsSMILTimeValue mTime;
   1.112 +
   1.113 +  // Internal flags used to represent the behaviour of different instance times
   1.114 +  enum {
   1.115 +    // Indicates that this instance time was generated by an event or a DOM
   1.116 +    // call. Such instance times require special handling when (i) the owning
   1.117 +    // element is reset, (ii) when they are to be added as a new end instance
   1.118 +    // times (as per SMIL's event sensitivity contraints), and (iii) when
   1.119 +    // a backwards seek is performed and the timing model is reconstructed.
   1.120 +    kDynamic = 1,
   1.121 +
   1.122 +    // Indicates that this instance time is referred to by an
   1.123 +    // nsSMILTimeValueSpec and as such may be updated. Such instance time should
   1.124 +    // not be filtered out by the nsSMILTimedElement even if they appear to be
   1.125 +    // in the past as they may be updated to a future time.
   1.126 +    kMayUpdate = 2,
   1.127 +
   1.128 +    // Indicates that this instance time was generated from the DOM as opposed
   1.129 +    // to an nsSMILTimeValueSpec. When a 'begin' or 'end' attribute is set or
   1.130 +    // reset we should clear all the instance times that have been generated by
   1.131 +    // that attribute (and hence an nsSMILTimeValueSpec), but not those from the
   1.132 +    // DOM.
   1.133 +    kFromDOM = 4,
   1.134 +
   1.135 +    // Indicates that this instance time was used as the endpoint of an interval
   1.136 +    // that has been filtered or removed. However, since it is a dynamic time it
   1.137 +    // should be preserved and not filtered.
   1.138 +    kWasDynamicEndpoint = 8
   1.139 +  };
   1.140 +  uint8_t       mFlags;   // Combination of kDynamic, kMayUpdate, etc.
   1.141 +  mutable bool  mVisited; // Cycle tracking
   1.142 +
   1.143 +  // Additional reference count to determine if this instance time is currently
   1.144 +  // used as a fixed endpoint in any intervals. Instance times that are used in
   1.145 +  // this way should not be removed when the owning nsSMILTimedElement removes
   1.146 +  // instance times in response to a restart or in an attempt to free up memory
   1.147 +  // by filtering out old instance times.
   1.148 +  //
   1.149 +  // Instance times are only shared in a few cases, namely:
   1.150 +  // a) early ends,
   1.151 +  // b) zero-duration intervals,
   1.152 +  // c) momentarily whilst establishing new intervals and updating the current
   1.153 +  //    interval, and
   1.154 +  // d) trimmed intervals
   1.155 +  // Hence the limited range of a uint16_t should be more than adequate.
   1.156 +  uint16_t      mFixedEndpointRefCnt;
   1.157 +
   1.158 +  uint32_t      mSerial; // A serial number used by the containing class to
   1.159 +                         // specify the sort order for instance times with the
   1.160 +                         // same mTime.
   1.161 +
   1.162 +  nsSMILTimeValueSpec* mCreator; // The nsSMILTimeValueSpec object that created
   1.163 +                                 // us. (currently only needed for syncbase
   1.164 +                                 // instance times.)
   1.165 +  nsSMILInterval* mBaseInterval; // Interval from which this time is derived
   1.166 +                                 // (only used for syncbase instance times)
   1.167 +};
   1.168 +
   1.169 +#endif // NS_SMILINSTANCETIME_H_

mercurial