Bumping manifests a=b2g-bump
[gecko.git] / dom / animation / AnimationTimeline.h
blob77f154664b415887102beef8bf2019cbb74f2c73
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_AnimationTimeline_h
7 #define mozilla_dom_AnimationTimeline_h
9 #include "nsWrapperCache.h"
10 #include "nsCycleCollectionParticipant.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/TimeStamp.h"
13 #include "js/TypeDecls.h"
14 #include "nsIDocument.h"
15 #include "nsRefreshDriver.h"
17 struct JSContext;
19 namespace mozilla {
20 namespace dom {
22 class AnimationTimeline MOZ_FINAL : public nsWrapperCache
24 public:
25 explicit AnimationTimeline(nsIDocument* aDocument)
26 : mDocument(aDocument)
30 protected:
31 virtual ~AnimationTimeline() { }
33 public:
34 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AnimationTimeline)
35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AnimationTimeline)
37 nsIGlobalObject* GetParentObject() const
39 return mDocument->GetParentObject();
41 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
43 // AnimationTimeline methods
44 Nullable<TimeDuration> GetCurrentTime() const;
46 // Wrapper functions for AnimationTimeline DOM methods when called from
47 // script.
48 Nullable<double> GetCurrentTimeAsDouble() const;
50 // Converts a TimeStamp to the equivalent value in timeline time.
51 // Note that when IsUnderTestControl() is true, there is no correspondence
52 // between timeline time and wallclock time. In such a case, passing a
53 // timestamp from TimeStamp::Now() to this method will not return a
54 // meaningful result.
55 Nullable<TimeDuration> ToTimelineTime(const TimeStamp& aTimeStamp) const;
56 TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const;
58 nsRefreshDriver* GetRefreshDriver() const;
59 // Returns true if this timeline is driven by a refresh driver that is
60 // under test control. In such a case, there is no correspondence between
61 // TimeStamp values returned by the refresh driver and wallclock time.
62 // As a result, passing a value from TimeStamp::Now() to ToTimelineTime()
63 // would not return a meaningful result.
64 bool IsUnderTestControl() const
66 nsRefreshDriver* refreshDriver = GetRefreshDriver();
67 return refreshDriver && refreshDriver->IsTestControllingRefreshesEnabled();
70 protected:
71 TimeStamp GetCurrentTimeStamp() const;
73 nsCOMPtr<nsIDocument> mDocument;
75 // The most recently used refresh driver time. This is used in cases where
76 // we don't have a refresh driver (e.g. because we are in a display:none
77 // iframe).
78 mutable TimeStamp mLastRefreshDriverTime;
81 } // namespace dom
82 } // namespace mozilla
84 #endif // mozilla_dom_AnimationTimeline_h