|
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/. */ |
|
5 |
|
6 #ifndef NS_SMILINSTANCETIME_H_ |
|
7 #define NS_SMILINSTANCETIME_H_ |
|
8 |
|
9 #include "nsSMILTimeValue.h" |
|
10 #include "nsAutoPtr.h" |
|
11 |
|
12 class nsSMILInterval; |
|
13 class nsSMILTimeContainer; |
|
14 class nsSMILTimeValueSpec; |
|
15 |
|
16 //---------------------------------------------------------------------- |
|
17 // nsSMILInstanceTime |
|
18 // |
|
19 // An instant in document simple time that may be used in creating a new |
|
20 // interval. |
|
21 // |
|
22 // For an overview of how this class is related to other SMIL time classes see |
|
23 // the documentation in nsSMILTimeValue.h |
|
24 // |
|
25 // These objects are owned by an nsSMILTimedElement but MAY also be referenced |
|
26 // by: |
|
27 // |
|
28 // a) nsSMILIntervals that belong to the same nsSMILTimedElement and which refer |
|
29 // to the nsSMILInstanceTimes which form the interval endpoints; and/or |
|
30 // b) nsSMILIntervals that belong to other nsSMILTimedElements but which need to |
|
31 // update dependent instance times when they change or are deleted. |
|
32 // E.g. for begin='a.begin', 'a' needs to inform dependent |
|
33 // nsSMILInstanceTimes if its begin time changes. This notification is |
|
34 // performed by the nsSMILInterval. |
|
35 |
|
36 class nsSMILInstanceTime MOZ_FINAL |
|
37 { |
|
38 public: |
|
39 // Instance time source. Times generated by events, syncbase relationships, |
|
40 // and DOM calls behave differently in some circumstances such as when a timed |
|
41 // element is reset. |
|
42 enum nsSMILInstanceTimeSource { |
|
43 // No particularly significant source, e.g. offset time, 'indefinite' |
|
44 SOURCE_NONE, |
|
45 // Generated by a DOM call such as beginElement |
|
46 SOURCE_DOM, |
|
47 // Generated by a syncbase relationship |
|
48 SOURCE_SYNCBASE, |
|
49 // Generated by an event |
|
50 SOURCE_EVENT |
|
51 }; |
|
52 |
|
53 nsSMILInstanceTime(const nsSMILTimeValue& aTime, |
|
54 nsSMILInstanceTimeSource aSource = SOURCE_NONE, |
|
55 nsSMILTimeValueSpec* aCreator = nullptr, |
|
56 nsSMILInterval* aBaseInterval = nullptr); |
|
57 |
|
58 void Unlink(); |
|
59 void HandleChangedInterval(const nsSMILTimeContainer* aSrcContainer, |
|
60 bool aBeginObjectChanged, |
|
61 bool aEndObjectChanged); |
|
62 void HandleDeletedInterval(); |
|
63 void HandleFilteredInterval(); |
|
64 |
|
65 const nsSMILTimeValue& Time() const { return mTime; } |
|
66 const nsSMILTimeValueSpec* GetCreator() const { return mCreator; } |
|
67 |
|
68 bool IsDynamic() const { return !!(mFlags & kDynamic); } |
|
69 bool IsFixedTime() const { return !(mFlags & kMayUpdate); } |
|
70 bool FromDOM() const { return !!(mFlags & kFromDOM); } |
|
71 |
|
72 bool ShouldPreserve() const; |
|
73 void UnmarkShouldPreserve(); |
|
74 |
|
75 void AddRefFixedEndpoint(); |
|
76 void ReleaseFixedEndpoint(); |
|
77 |
|
78 void DependentUpdate(const nsSMILTimeValue& aNewTime) |
|
79 { |
|
80 NS_ABORT_IF_FALSE(!IsFixedTime(), |
|
81 "Updating an instance time that is not expected to be updated"); |
|
82 mTime = aNewTime; |
|
83 } |
|
84 |
|
85 bool IsDependent() const { return !!mBaseInterval; } |
|
86 bool IsDependentOn(const nsSMILInstanceTime& aOther) const; |
|
87 const nsSMILInterval* GetBaseInterval() const { return mBaseInterval; } |
|
88 const nsSMILInstanceTime* GetBaseTime() const; |
|
89 |
|
90 bool SameTimeAndBase(const nsSMILInstanceTime& aOther) const |
|
91 { |
|
92 return mTime == aOther.mTime && GetBaseTime() == aOther.GetBaseTime(); |
|
93 } |
|
94 |
|
95 // Get and set a serial number which may be used by a containing class to |
|
96 // control the sort order of otherwise similar instance times. |
|
97 uint32_t Serial() const { return mSerial; } |
|
98 void SetSerial(uint32_t aIndex) { mSerial = aIndex; } |
|
99 |
|
100 NS_INLINE_DECL_REFCOUNTING(nsSMILInstanceTime) |
|
101 |
|
102 private: |
|
103 // Private destructor, to discourage deletion outside of Release(): |
|
104 ~nsSMILInstanceTime(); |
|
105 |
|
106 void SetBaseInterval(nsSMILInterval* aBaseInterval); |
|
107 |
|
108 nsSMILTimeValue mTime; |
|
109 |
|
110 // Internal flags used to represent the behaviour of different instance times |
|
111 enum { |
|
112 // Indicates that this instance time was generated by an event or a DOM |
|
113 // call. Such instance times require special handling when (i) the owning |
|
114 // element is reset, (ii) when they are to be added as a new end instance |
|
115 // times (as per SMIL's event sensitivity contraints), and (iii) when |
|
116 // a backwards seek is performed and the timing model is reconstructed. |
|
117 kDynamic = 1, |
|
118 |
|
119 // Indicates that this instance time is referred to by an |
|
120 // nsSMILTimeValueSpec and as such may be updated. Such instance time should |
|
121 // not be filtered out by the nsSMILTimedElement even if they appear to be |
|
122 // in the past as they may be updated to a future time. |
|
123 kMayUpdate = 2, |
|
124 |
|
125 // Indicates that this instance time was generated from the DOM as opposed |
|
126 // to an nsSMILTimeValueSpec. When a 'begin' or 'end' attribute is set or |
|
127 // reset we should clear all the instance times that have been generated by |
|
128 // that attribute (and hence an nsSMILTimeValueSpec), but not those from the |
|
129 // DOM. |
|
130 kFromDOM = 4, |
|
131 |
|
132 // Indicates that this instance time was used as the endpoint of an interval |
|
133 // that has been filtered or removed. However, since it is a dynamic time it |
|
134 // should be preserved and not filtered. |
|
135 kWasDynamicEndpoint = 8 |
|
136 }; |
|
137 uint8_t mFlags; // Combination of kDynamic, kMayUpdate, etc. |
|
138 mutable bool mVisited; // Cycle tracking |
|
139 |
|
140 // Additional reference count to determine if this instance time is currently |
|
141 // used as a fixed endpoint in any intervals. Instance times that are used in |
|
142 // this way should not be removed when the owning nsSMILTimedElement removes |
|
143 // instance times in response to a restart or in an attempt to free up memory |
|
144 // by filtering out old instance times. |
|
145 // |
|
146 // Instance times are only shared in a few cases, namely: |
|
147 // a) early ends, |
|
148 // b) zero-duration intervals, |
|
149 // c) momentarily whilst establishing new intervals and updating the current |
|
150 // interval, and |
|
151 // d) trimmed intervals |
|
152 // Hence the limited range of a uint16_t should be more than adequate. |
|
153 uint16_t mFixedEndpointRefCnt; |
|
154 |
|
155 uint32_t mSerial; // A serial number used by the containing class to |
|
156 // specify the sort order for instance times with the |
|
157 // same mTime. |
|
158 |
|
159 nsSMILTimeValueSpec* mCreator; // The nsSMILTimeValueSpec object that created |
|
160 // us. (currently only needed for syncbase |
|
161 // instance times.) |
|
162 nsSMILInterval* mBaseInterval; // Interval from which this time is derived |
|
163 // (only used for syncbase instance times) |
|
164 }; |
|
165 |
|
166 #endif // NS_SMILINSTANCETIME_H_ |