dom/smil/nsSMILTimeContainer.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef NS_SMILTIMECONTAINER_H_
michael@0 7 #define NS_SMILTIMECONTAINER_H_
michael@0 8
michael@0 9 #include "mozilla/dom/SVGAnimationElement.h"
michael@0 10 #include "nscore.h"
michael@0 11 #include "nsSMILTypes.h"
michael@0 12 #include "nsTPriorityQueue.h"
michael@0 13 #include "nsAutoPtr.h"
michael@0 14 #include "nsSMILMilestone.h"
michael@0 15
michael@0 16 class nsSMILTimeValue;
michael@0 17
michael@0 18 //----------------------------------------------------------------------
michael@0 19 // nsSMILTimeContainer
michael@0 20 //
michael@0 21 // Common base class for a time base that can be paused, resumed, and sampled.
michael@0 22 //
michael@0 23 class nsSMILTimeContainer
michael@0 24 {
michael@0 25 public:
michael@0 26 nsSMILTimeContainer();
michael@0 27 virtual ~nsSMILTimeContainer();
michael@0 28
michael@0 29 /*
michael@0 30 * Pause request types.
michael@0 31 */
michael@0 32 enum {
michael@0 33 PAUSE_BEGIN = 1, // Paused because timeline has yet to begin.
michael@0 34 PAUSE_SCRIPT = 2, // Paused by script.
michael@0 35 PAUSE_PAGEHIDE = 4, // Paused because our doc is hidden.
michael@0 36 PAUSE_USERPREF = 8, // Paused because animations are disabled in prefs.
michael@0 37 PAUSE_IMAGE = 16 // Paused becuase we're in an image that's suspended.
michael@0 38 };
michael@0 39
michael@0 40 /*
michael@0 41 * Cause the time container to record its begin time.
michael@0 42 */
michael@0 43 void Begin();
michael@0 44
michael@0 45 /*
michael@0 46 * Pause this time container
michael@0 47 *
michael@0 48 * @param aType The source of the pause request. Successive calls to Pause
michael@0 49 * with the same aType will be ignored. The container will remain paused until
michael@0 50 * each call to Pause of a given aType has been matched by at least one call
michael@0 51 * to Resume with the same aType.
michael@0 52 */
michael@0 53 virtual void Pause(uint32_t aType);
michael@0 54
michael@0 55 /*
michael@0 56 * Resume this time container
michael@0 57 *
michael@0 58 * param @aType The source of the resume request. Clears the pause flag for
michael@0 59 * this particular type of pause request. When all pause flags have been
michael@0 60 * cleared the time container will be resumed.
michael@0 61 */
michael@0 62 virtual void Resume(uint32_t aType);
michael@0 63
michael@0 64 /**
michael@0 65 * Returns true if this time container is paused by the specified type.
michael@0 66 * Note that the time container may also be paused by other types; this method
michael@0 67 * does not test if aType is the exclusive pause source.
michael@0 68 *
michael@0 69 * @param @aType The pause source to test for.
michael@0 70 * @return true if this container is paused by aType.
michael@0 71 */
michael@0 72 bool IsPausedByType(uint32_t aType) const { return mPauseState & aType; }
michael@0 73
michael@0 74 /**
michael@0 75 * Returns true if this time container is paused.
michael@0 76 * Generally you should test for a specific type of pausing using
michael@0 77 * IsPausedByType.
michael@0 78 *
michael@0 79 * @return true if this container is paused, false otherwise.
michael@0 80 */
michael@0 81 bool IsPaused() const { return mPauseState != 0; }
michael@0 82
michael@0 83 /*
michael@0 84 * Return the time elapsed since this time container's begin time (expressed
michael@0 85 * in parent time) minus any accumulated offset from pausing.
michael@0 86 */
michael@0 87 nsSMILTime GetCurrentTime() const;
michael@0 88
michael@0 89 /*
michael@0 90 * Seek the document timeline to the specified time.
michael@0 91 *
michael@0 92 * @param aSeekTo The time to seek to, expressed in this time container's time
michael@0 93 * base (i.e. the same units as GetCurrentTime).
michael@0 94 */
michael@0 95 void SetCurrentTime(nsSMILTime aSeekTo);
michael@0 96
michael@0 97 /*
michael@0 98 * Return the current time for the parent time container if any.
michael@0 99 */
michael@0 100 virtual nsSMILTime GetParentTime() const;
michael@0 101
michael@0 102 /*
michael@0 103 * Convert container time to parent time.
michael@0 104 *
michael@0 105 * @param aContainerTime The container time to convert.
michael@0 106 * @return The equivalent parent time or indefinite if the container is
michael@0 107 * paused and the time is in the future.
michael@0 108 */
michael@0 109 nsSMILTimeValue ContainerToParentTime(nsSMILTime aContainerTime) const;
michael@0 110
michael@0 111 /*
michael@0 112 * Convert from parent time to container time.
michael@0 113 *
michael@0 114 * @param aParentTime The parent time to convert.
michael@0 115 * @return The equivalent container time or indefinite if the container is
michael@0 116 * paused and aParentTime is after the time when the pause began.
michael@0 117 */
michael@0 118 nsSMILTimeValue ParentToContainerTime(nsSMILTime aParentTime) const;
michael@0 119
michael@0 120 /*
michael@0 121 * If the container is paused, causes the pause time to be updated to the
michael@0 122 * current parent time. This should be called before updating
michael@0 123 * cross-container dependencies that will call ContainerToParentTime in order
michael@0 124 * to provide more intuitive results.
michael@0 125 */
michael@0 126 void SyncPauseTime();
michael@0 127
michael@0 128 /*
michael@0 129 * Updates the current time of this time container and calls DoSample to
michael@0 130 * perform any sample-operations.
michael@0 131 */
michael@0 132 void Sample();
michael@0 133
michael@0 134 /*
michael@0 135 * Return if this time container should be sampled or can be skipped.
michael@0 136 *
michael@0 137 * This is most useful as an optimisation for skipping time containers that
michael@0 138 * don't require a sample.
michael@0 139 */
michael@0 140 bool NeedsSample() const { return !mPauseState || mNeedsPauseSample; }
michael@0 141
michael@0 142 /*
michael@0 143 * Indicates if the elements of this time container need to be rewound.
michael@0 144 * This occurs during a backwards seek.
michael@0 145 */
michael@0 146 bool NeedsRewind() const { return mNeedsRewind; }
michael@0 147 void ClearNeedsRewind() { mNeedsRewind = false; }
michael@0 148
michael@0 149 /*
michael@0 150 * Indicates the time container is currently processing a SetCurrentTime
michael@0 151 * request and appropriate seek behaviour should be applied by child elements
michael@0 152 * (e.g. not firing time events).
michael@0 153 */
michael@0 154 bool IsSeeking() const { return mIsSeeking; }
michael@0 155 void MarkSeekFinished() { mIsSeeking = false; }
michael@0 156
michael@0 157 /*
michael@0 158 * Sets the parent time container.
michael@0 159 *
michael@0 160 * The callee still retains ownership of the time container.
michael@0 161 */
michael@0 162 nsresult SetParent(nsSMILTimeContainer* aParent);
michael@0 163
michael@0 164 /*
michael@0 165 * Registers an element for a sample at the given time.
michael@0 166 *
michael@0 167 * @param aMilestone The milestone to register in container time.
michael@0 168 * @param aElement The timebase element that needs a sample at
michael@0 169 * aMilestone.
michael@0 170 * @return true if the element was successfully added, false otherwise.
michael@0 171 */
michael@0 172 bool AddMilestone(const nsSMILMilestone& aMilestone,
michael@0 173 mozilla::dom::SVGAnimationElement& aElement);
michael@0 174
michael@0 175 /*
michael@0 176 * Resets the list of milestones.
michael@0 177 */
michael@0 178 void ClearMilestones();
michael@0 179
michael@0 180 /*
michael@0 181 * Returns the next significant transition from amongst the registered
michael@0 182 * milestones.
michael@0 183 *
michael@0 184 * @param[out] aNextMilestone The next milestone with time in parent time.
michael@0 185 *
michael@0 186 * @return true if there exists another milestone, false otherwise in
michael@0 187 * which case aNextMilestone will be unmodified.
michael@0 188 */
michael@0 189 bool GetNextMilestoneInParentTime(nsSMILMilestone& aNextMilestone) const;
michael@0 190
michael@0 191 typedef nsTArray<nsRefPtr<mozilla::dom::SVGAnimationElement> > AnimElemArray;
michael@0 192
michael@0 193 /*
michael@0 194 * Removes and returns the timebase elements from the start of the list of
michael@0 195 * timebase elements that match the given time.
michael@0 196 *
michael@0 197 * @param aMilestone The milestone time to match in parent time. This
michael@0 198 * must be <= GetNextMilestoneInParentTime.
michael@0 199 * @param[out] aMatchedElements The array to which matching elements will be
michael@0 200 * appended.
michael@0 201 * @return true if one or more elements match, false otherwise.
michael@0 202 */
michael@0 203 bool PopMilestoneElementsAtMilestone(const nsSMILMilestone& aMilestone,
michael@0 204 AnimElemArray& aMatchedElements);
michael@0 205
michael@0 206 // Cycle-collection support
michael@0 207 void Traverse(nsCycleCollectionTraversalCallback* aCallback);
michael@0 208 void Unlink();
michael@0 209
michael@0 210 protected:
michael@0 211 /*
michael@0 212 * Per-sample operations to be performed whenever Sample() is called and
michael@0 213 * NeedsSample() is true. Called after updating mCurrentTime;
michael@0 214 */
michael@0 215 virtual void DoSample() { }
michael@0 216
michael@0 217 /*
michael@0 218 * Adding and removing child containers is not implemented in the base class
michael@0 219 * because not all subclasses need this.
michael@0 220 */
michael@0 221
michael@0 222 /*
michael@0 223 * Adds a child time container.
michael@0 224 */
michael@0 225 virtual nsresult AddChild(nsSMILTimeContainer& aChild)
michael@0 226 {
michael@0 227 return NS_ERROR_FAILURE;
michael@0 228 }
michael@0 229
michael@0 230 /*
michael@0 231 * Removes a child time container.
michael@0 232 */
michael@0 233 virtual void RemoveChild(nsSMILTimeContainer& aChild) { }
michael@0 234
michael@0 235 /*
michael@0 236 * Implementation helper to update the current time.
michael@0 237 */
michael@0 238 void UpdateCurrentTime();
michael@0 239
michael@0 240 /*
michael@0 241 * Implementation helper to notify timed elements with dependencies that the
michael@0 242 * container time has changed with respect to the document time.
michael@0 243 */
michael@0 244 void NotifyTimeChange();
michael@0 245
michael@0 246 // The parent time container, if any
michael@0 247 nsSMILTimeContainer* mParent;
michael@0 248
michael@0 249 // The current time established at the last call to Sample()
michael@0 250 nsSMILTime mCurrentTime;
michael@0 251
michael@0 252 // The number of milliseconds for which the container has been paused
michael@0 253 // (excluding the current pause interval if the container is currently
michael@0 254 // paused).
michael@0 255 //
michael@0 256 // Current time = parent time - mParentOffset
michael@0 257 //
michael@0 258 nsSMILTime mParentOffset;
michael@0 259
michael@0 260 // The timestamp in parent time when the container was paused
michael@0 261 nsSMILTime mPauseStart;
michael@0 262
michael@0 263 // Whether or not a pause sample is required
michael@0 264 bool mNeedsPauseSample;
michael@0 265
michael@0 266 bool mNeedsRewind; // Backwards seek performed
michael@0 267 bool mIsSeeking; // Currently in the middle of a seek operation
michael@0 268
michael@0 269 // A bitfield of the pause state for all pause requests
michael@0 270 uint32_t mPauseState;
michael@0 271
michael@0 272 struct MilestoneEntry
michael@0 273 {
michael@0 274 MilestoneEntry(nsSMILMilestone aMilestone,
michael@0 275 mozilla::dom::SVGAnimationElement& aElement)
michael@0 276 : mMilestone(aMilestone), mTimebase(&aElement)
michael@0 277 { }
michael@0 278
michael@0 279 bool operator<(const MilestoneEntry& aOther) const
michael@0 280 {
michael@0 281 return mMilestone < aOther.mMilestone;
michael@0 282 }
michael@0 283
michael@0 284 nsSMILMilestone mMilestone; // In container time.
michael@0 285 nsRefPtr<mozilla::dom::SVGAnimationElement> mTimebase;
michael@0 286 };
michael@0 287
michael@0 288 // Queue of elements with registered milestones. Used to update the model with
michael@0 289 // significant transitions that occur between two samples. Since timed element
michael@0 290 // re-register their milestones when they're sampled this is reset once we've
michael@0 291 // taken care of the milestones before the current sample time but before we
michael@0 292 // actually do the full sample.
michael@0 293 nsTPriorityQueue<MilestoneEntry> mMilestoneEntries;
michael@0 294 };
michael@0 295
michael@0 296 #endif // NS_SMILTIMECONTAINER_H_

mercurial