LCOV - code coverage report
Current view: top level - dom/animation - PendingAnimationTracker.h (source / functions) Hit Total Coverage
Test: output.info Lines: 16 28 57.1 %
Date: 2017-07-14 16:53:18 Functions: 7 15 46.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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           1 :   explicit PendingAnimationTracker(nsIDocument* aDocument)
      23           1 :     : mDocument(aDocument)
      24           1 :   { }
      25             : 
      26           1 :   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PendingAnimationTracker)
      27          16 :   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(PendingAnimationTracker)
      28             : 
      29           2 :   void AddPlayPending(dom::Animation& aAnimation)
      30             :   {
      31           2 :     MOZ_ASSERT(!IsWaitingToPause(aAnimation),
      32             :                "Animation is already waiting to pause");
      33           2 :     AddPending(aAnimation, mPlayPendingSet);
      34           2 :     mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
      35           2 :   }
      36           0 :   void RemovePlayPending(dom::Animation& aAnimation)
      37             :   {
      38           0 :     RemovePending(aAnimation, mPlayPendingSet);
      39           0 :     mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
      40           0 :   }
      41          18 :   bool IsWaitingToPlay(const dom::Animation& aAnimation) const
      42             :   {
      43          18 :     return IsWaiting(aAnimation, mPlayPendingSet);
      44             :   }
      45             : 
      46           0 :   void AddPausePending(dom::Animation& aAnimation)
      47             :   {
      48           0 :     MOZ_ASSERT(!IsWaitingToPlay(aAnimation),
      49             :                "Animation is already waiting to play");
      50           0 :     AddPending(aAnimation, mPausePendingSet);
      51           0 :   }
      52           0 :   void RemovePausePending(dom::Animation& aAnimation)
      53             :   {
      54           0 :     RemovePending(aAnimation, mPausePendingSet);
      55           0 :   }
      56           2 :   bool IsWaitingToPause(const dom::Animation& aAnimation) const
      57             :   {
      58           2 :     return IsWaiting(aAnimation, mPausePendingSet);
      59             :   }
      60             : 
      61             :   void TriggerPendingAnimationsOnNextTick(const TimeStamp& aReadyTime);
      62             :   void TriggerPendingAnimationsNow();
      63          19 :   bool HasPendingAnimations() const {
      64          19 :     return mPlayPendingSet.Count() > 0 || mPausePendingSet.Count() > 0;
      65             :   }
      66             : 
      67             :   /**
      68             :    * Looks amongst the set of play-pending animations, and, if there are
      69             :    * animations that affect geometric properties, notifies all play-pending
      70             :    * animations so that they can be synchronized, if needed.
      71             :    */
      72             :   void MarkAnimationsThatMightNeedSynchronization();
      73             : 
      74             : private:
      75           0 :   ~PendingAnimationTracker() { }
      76             : 
      77             :   bool HasPlayPendingGeometricAnimations();
      78             :   void EnsurePaintIsScheduled();
      79             : 
      80             :   typedef nsTHashtable<nsRefPtrHashKey<dom::Animation>> AnimationSet;
      81             : 
      82             :   void AddPending(dom::Animation& aAnimation, AnimationSet& aSet);
      83             :   void RemovePending(dom::Animation& aAnimation, AnimationSet& aSet);
      84             :   bool IsWaiting(const dom::Animation& aAnimation,
      85             :                  const AnimationSet& aSet) const;
      86             : 
      87             :   AnimationSet mPlayPendingSet;
      88             :   AnimationSet mPausePendingSet;
      89             :   nsCOMPtr<nsIDocument> mDocument;
      90             : 
      91             :   enum class CheckState {
      92             :     Indeterminate,
      93             :     Absent,
      94             :     Present
      95             :   };
      96             :   CheckState mHasPlayPendingGeometricAnimations = CheckState::Indeterminate;
      97             : };
      98             : 
      99             : } // namespace mozilla
     100             : 
     101             : #endif // mozilla_dom_PendingAnimationTracker_h

Generated by: LCOV version 1.13