Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/PendingAnimationTracker.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_PendingAnimationTracker_h
8
#define mozilla_dom_PendingAnimationTracker_h
9
10
#include "mozilla/dom/Animation.h"
11
#include "nsCycleCollectionParticipant.h"
12
#include "nsIDocument.h"
13
#include "nsTHashtable.h"
14
15
class nsIFrame;
16
17
namespace mozilla {
18
19
class PendingAnimationTracker final
20
{
21
public:
22
  explicit PendingAnimationTracker(nsIDocument* aDocument)
23
    : mDocument(aDocument)
24
0
  { }
25
26
  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PendingAnimationTracker)
27
  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(PendingAnimationTracker)
28
29
  void AddPlayPending(dom::Animation& aAnimation)
30
0
  {
31
0
    // We'd like to assert here that IsWaitingToPause(aAnimation) is false but
32
0
    // if |aAnimation| was tracked here as a pause-pending animation when it was
33
0
    // removed from |mDocument|, then re-attached to |mDocument|, and then
34
0
    // played again, we could end up here with IsWaitingToPause returning true.
35
0
    //
36
0
    // However, that should be harmless since all it means is that we'll call
37
0
    // Animation::TriggerOnNextTick or Animation::TriggerNow twice, both of
38
0
    // which will handle the redundant call gracefully.
39
0
    AddPending(aAnimation, mPlayPendingSet);
40
0
    mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
41
0
  }
42
  void RemovePlayPending(dom::Animation& aAnimation)
43
0
  {
44
0
    RemovePending(aAnimation, mPlayPendingSet);
45
0
    mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
46
0
  }
47
  bool IsWaitingToPlay(const dom::Animation& aAnimation) const
48
0
  {
49
0
    return IsWaiting(aAnimation, mPlayPendingSet);
50
0
  }
51
52
  void AddPausePending(dom::Animation& aAnimation)
53
0
  {
54
0
    // As with AddPausePending, we'd like to assert that
55
0
    // IsWaitingToPlay(aAnimation) is false but there are some circumstances
56
0
    // where this can be true. Fortunately adding the animation to both pending
57
0
    // sets should be harmless.
58
0
    AddPending(aAnimation, mPausePendingSet);
59
0
  }
60
  void RemovePausePending(dom::Animation& aAnimation)
61
0
  {
62
0
    RemovePending(aAnimation, mPausePendingSet);
63
0
  }
64
  bool IsWaitingToPause(const dom::Animation& aAnimation) const
65
0
  {
66
0
    return IsWaiting(aAnimation, mPausePendingSet);
67
0
  }
68
69
  void TriggerPendingAnimationsOnNextTick(const TimeStamp& aReadyTime);
70
  void TriggerPendingAnimationsNow();
71
0
  bool HasPendingAnimations() const {
72
0
    return mPlayPendingSet.Count() > 0 || mPausePendingSet.Count() > 0;
73
0
  }
74
75
  /**
76
   * Looks amongst the set of play-pending animations, and, if there are
77
   * animations that affect geometric properties, notifies all play-pending
78
   * animations so that they can be synchronized, if needed.
79
   */
80
  void MarkAnimationsThatMightNeedSynchronization();
81
82
private:
83
0
  ~PendingAnimationTracker() { }
84
85
  bool HasPlayPendingGeometricAnimations();
86
  void EnsurePaintIsScheduled();
87
88
  typedef nsTHashtable<nsRefPtrHashKey<dom::Animation>> AnimationSet;
89
90
  void AddPending(dom::Animation& aAnimation, AnimationSet& aSet);
91
  void RemovePending(dom::Animation& aAnimation, AnimationSet& aSet);
92
  bool IsWaiting(const dom::Animation& aAnimation,
93
                 const AnimationSet& aSet) const;
94
95
  AnimationSet mPlayPendingSet;
96
  AnimationSet mPausePendingSet;
97
  nsCOMPtr<nsIDocument> mDocument;
98
99
  enum class CheckState {
100
    Indeterminate,
101
    Absent,
102
    Present
103
  };
104
  CheckState mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
105
};
106
107
} // namespace mozilla
108
109
#endif // mozilla_dom_PendingAnimationTracker_h