Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/animation/AnimationTimeline.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_AnimationTimeline_h
8
#define mozilla_dom_AnimationTimeline_h
9
10
#include "nsISupports.h"
11
#include "nsWrapperCache.h"
12
#include "nsCycleCollectionParticipant.h"
13
#include "js/TypeDecls.h"
14
#include "mozilla/AnimationUtils.h"
15
#include "mozilla/Attributes.h"
16
#include "nsHashKeys.h"
17
#include "nsIGlobalObject.h"
18
#include "nsTHashtable.h"
19
20
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
21
// GetTickCount().
22
#ifdef GetCurrentTime
23
#undef GetCurrentTime
24
#endif
25
26
class nsIDocument;
27
28
namespace mozilla {
29
namespace dom {
30
31
class Animation;
32
33
class AnimationTimeline
34
  : public nsISupports
35
  , public nsWrapperCache
36
{
37
public:
38
  explicit AnimationTimeline(nsIGlobalObject* aWindow)
39
    : mWindow(aWindow)
40
0
  {
41
0
    MOZ_ASSERT(mWindow);
42
0
  }
43
44
protected:
45
  virtual ~AnimationTimeline()
46
0
  {
47
0
    mAnimationOrder.clear();
48
0
  }
49
50
public:
51
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
52
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AnimationTimeline)
53
54
  nsIGlobalObject* GetParentObject() const { return mWindow; }
55
56
  // AnimationTimeline methods
57
  virtual Nullable<TimeDuration> GetCurrentTime() const = 0;
58
59
  // Wrapper functions for AnimationTimeline DOM methods when called from
60
  // script.
61
0
  Nullable<double> GetCurrentTimeAsDouble() const {
62
0
    return AnimationUtils::TimeDurationToDouble(GetCurrentTime());
63
0
  }
64
65
0
  TimeStamp GetCurrentTimeAsTimeStamp() const {
66
0
    Nullable<TimeDuration> currentTime = GetCurrentTime();
67
0
    return !currentTime.IsNull()
68
0
      ? ToTimeStamp(currentTime.Value())
69
0
      : TimeStamp();
70
0
  }
71
72
  /**
73
   * Returns true if the times returned by GetCurrentTime() are convertible
74
   * to and from wallclock-based TimeStamp (e.g. from TimeStamp::Now()) values
75
   * using ToTimelineTime() and ToTimeStamp().
76
   *
77
   * Typically this is true, but it will be false in the case when this
78
   * timeline has no refresh driver or is tied to a refresh driver under test
79
   * control.
80
   */
81
  virtual bool TracksWallclockTime() const = 0;
82
83
  /**
84
   * Converts a TimeStamp to the equivalent value in timeline time.
85
   * Note that when TracksWallclockTime() is false, there is no correspondence
86
   * between timeline time and wallclock time. In such a case, passing a
87
   * timestamp from TimeStamp::Now() to this method will not return a
88
   * meaningful result.
89
   */
90
  virtual Nullable<TimeDuration> ToTimelineTime(const TimeStamp&
91
                                                  aTimeStamp) const = 0;
92
93
  virtual TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const = 0;
94
95
  /**
96
   * Inform this timeline that |aAnimation| which is or was observing the
97
   * timeline, has been updated. This serves as both the means to associate
98
   * AND disassociate animations with a timeline. The timeline itself will
99
   * determine if it needs to begin, continue or stop tracking this animation.
100
   */
101
  virtual void NotifyAnimationUpdated(Animation& aAnimation);
102
103
  /**
104
   * Returns true if any CSS animations, CSS transitions or Web animations are
105
   * currently associated with this timeline.  As soon as an animation is
106
   * applied to an element it is associated with the timeline even if it has a
107
   * delayed start, so this includes animations that may not be active for some
108
   * time.
109
   */
110
  bool HasAnimations() const {
111
    return !mAnimations.IsEmpty();
112
  }
113
114
  virtual void RemoveAnimation(Animation* aAnimation);
115
116
  virtual nsIDocument* GetDocument() const = 0;
117
118
protected:
119
  nsCOMPtr<nsIGlobalObject> mWindow;
120
121
  // Animations observing this timeline
122
  //
123
  // We store them in (a) a hashset for quick lookup, and (b) an array
124
  // to maintain a fixed sampling order.
125
  //
126
  // The hashset keeps a strong reference to each animation since
127
  // dealing with addref/release with LinkedList is difficult.
128
  typedef nsTHashtable<nsRefPtrHashKey<dom::Animation>> AnimationSet;
129
  AnimationSet mAnimations;
130
  LinkedList<dom::Animation> mAnimationOrder;
131
};
132
133
} // namespace dom
134
} // namespace mozilla
135
136
#endif // mozilla_dom_AnimationTimeline_h