michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef NS_SMILINSTANCETIME_H_ michael@0: #define NS_SMILINSTANCETIME_H_ michael@0: michael@0: #include "nsSMILTimeValue.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: class nsSMILInterval; michael@0: class nsSMILTimeContainer; michael@0: class nsSMILTimeValueSpec; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // nsSMILInstanceTime michael@0: // michael@0: // An instant in document simple time that may be used in creating a new michael@0: // interval. michael@0: // michael@0: // For an overview of how this class is related to other SMIL time classes see michael@0: // the documentation in nsSMILTimeValue.h michael@0: // michael@0: // These objects are owned by an nsSMILTimedElement but MAY also be referenced michael@0: // by: michael@0: // michael@0: // a) nsSMILIntervals that belong to the same nsSMILTimedElement and which refer michael@0: // to the nsSMILInstanceTimes which form the interval endpoints; and/or michael@0: // b) nsSMILIntervals that belong to other nsSMILTimedElements but which need to michael@0: // update dependent instance times when they change or are deleted. michael@0: // E.g. for begin='a.begin', 'a' needs to inform dependent michael@0: // nsSMILInstanceTimes if its begin time changes. This notification is michael@0: // performed by the nsSMILInterval. michael@0: michael@0: class nsSMILInstanceTime MOZ_FINAL michael@0: { michael@0: public: michael@0: // Instance time source. Times generated by events, syncbase relationships, michael@0: // and DOM calls behave differently in some circumstances such as when a timed michael@0: // element is reset. michael@0: enum nsSMILInstanceTimeSource { michael@0: // No particularly significant source, e.g. offset time, 'indefinite' michael@0: SOURCE_NONE, michael@0: // Generated by a DOM call such as beginElement michael@0: SOURCE_DOM, michael@0: // Generated by a syncbase relationship michael@0: SOURCE_SYNCBASE, michael@0: // Generated by an event michael@0: SOURCE_EVENT michael@0: }; michael@0: michael@0: nsSMILInstanceTime(const nsSMILTimeValue& aTime, michael@0: nsSMILInstanceTimeSource aSource = SOURCE_NONE, michael@0: nsSMILTimeValueSpec* aCreator = nullptr, michael@0: nsSMILInterval* aBaseInterval = nullptr); michael@0: michael@0: void Unlink(); michael@0: void HandleChangedInterval(const nsSMILTimeContainer* aSrcContainer, michael@0: bool aBeginObjectChanged, michael@0: bool aEndObjectChanged); michael@0: void HandleDeletedInterval(); michael@0: void HandleFilteredInterval(); michael@0: michael@0: const nsSMILTimeValue& Time() const { return mTime; } michael@0: const nsSMILTimeValueSpec* GetCreator() const { return mCreator; } michael@0: michael@0: bool IsDynamic() const { return !!(mFlags & kDynamic); } michael@0: bool IsFixedTime() const { return !(mFlags & kMayUpdate); } michael@0: bool FromDOM() const { return !!(mFlags & kFromDOM); } michael@0: michael@0: bool ShouldPreserve() const; michael@0: void UnmarkShouldPreserve(); michael@0: michael@0: void AddRefFixedEndpoint(); michael@0: void ReleaseFixedEndpoint(); michael@0: michael@0: void DependentUpdate(const nsSMILTimeValue& aNewTime) michael@0: { michael@0: NS_ABORT_IF_FALSE(!IsFixedTime(), michael@0: "Updating an instance time that is not expected to be updated"); michael@0: mTime = aNewTime; michael@0: } michael@0: michael@0: bool IsDependent() const { return !!mBaseInterval; } michael@0: bool IsDependentOn(const nsSMILInstanceTime& aOther) const; michael@0: const nsSMILInterval* GetBaseInterval() const { return mBaseInterval; } michael@0: const nsSMILInstanceTime* GetBaseTime() const; michael@0: michael@0: bool SameTimeAndBase(const nsSMILInstanceTime& aOther) const michael@0: { michael@0: return mTime == aOther.mTime && GetBaseTime() == aOther.GetBaseTime(); michael@0: } michael@0: michael@0: // Get and set a serial number which may be used by a containing class to michael@0: // control the sort order of otherwise similar instance times. michael@0: uint32_t Serial() const { return mSerial; } michael@0: void SetSerial(uint32_t aIndex) { mSerial = aIndex; } michael@0: michael@0: NS_INLINE_DECL_REFCOUNTING(nsSMILInstanceTime) michael@0: michael@0: private: michael@0: // Private destructor, to discourage deletion outside of Release(): michael@0: ~nsSMILInstanceTime(); michael@0: michael@0: void SetBaseInterval(nsSMILInterval* aBaseInterval); michael@0: michael@0: nsSMILTimeValue mTime; michael@0: michael@0: // Internal flags used to represent the behaviour of different instance times michael@0: enum { michael@0: // Indicates that this instance time was generated by an event or a DOM michael@0: // call. Such instance times require special handling when (i) the owning michael@0: // element is reset, (ii) when they are to be added as a new end instance michael@0: // times (as per SMIL's event sensitivity contraints), and (iii) when michael@0: // a backwards seek is performed and the timing model is reconstructed. michael@0: kDynamic = 1, michael@0: michael@0: // Indicates that this instance time is referred to by an michael@0: // nsSMILTimeValueSpec and as such may be updated. Such instance time should michael@0: // not be filtered out by the nsSMILTimedElement even if they appear to be michael@0: // in the past as they may be updated to a future time. michael@0: kMayUpdate = 2, michael@0: michael@0: // Indicates that this instance time was generated from the DOM as opposed michael@0: // to an nsSMILTimeValueSpec. When a 'begin' or 'end' attribute is set or michael@0: // reset we should clear all the instance times that have been generated by michael@0: // that attribute (and hence an nsSMILTimeValueSpec), but not those from the michael@0: // DOM. michael@0: kFromDOM = 4, michael@0: michael@0: // Indicates that this instance time was used as the endpoint of an interval michael@0: // that has been filtered or removed. However, since it is a dynamic time it michael@0: // should be preserved and not filtered. michael@0: kWasDynamicEndpoint = 8 michael@0: }; michael@0: uint8_t mFlags; // Combination of kDynamic, kMayUpdate, etc. michael@0: mutable bool mVisited; // Cycle tracking michael@0: michael@0: // Additional reference count to determine if this instance time is currently michael@0: // used as a fixed endpoint in any intervals. Instance times that are used in michael@0: // this way should not be removed when the owning nsSMILTimedElement removes michael@0: // instance times in response to a restart or in an attempt to free up memory michael@0: // by filtering out old instance times. michael@0: // michael@0: // Instance times are only shared in a few cases, namely: michael@0: // a) early ends, michael@0: // b) zero-duration intervals, michael@0: // c) momentarily whilst establishing new intervals and updating the current michael@0: // interval, and michael@0: // d) trimmed intervals michael@0: // Hence the limited range of a uint16_t should be more than adequate. michael@0: uint16_t mFixedEndpointRefCnt; michael@0: michael@0: uint32_t mSerial; // A serial number used by the containing class to michael@0: // specify the sort order for instance times with the michael@0: // same mTime. michael@0: michael@0: nsSMILTimeValueSpec* mCreator; // The nsSMILTimeValueSpec object that created michael@0: // us. (currently only needed for syncbase michael@0: // instance times.) michael@0: nsSMILInterval* mBaseInterval; // Interval from which this time is derived michael@0: // (only used for syncbase instance times) michael@0: }; michael@0: michael@0: #endif // NS_SMILINSTANCETIME_H_