LCOV - code coverage report
Current view: top level - dom/animation - AnimationTimeline.h (source / functions) Hit Total Coverage
Test: output.info Lines: 9 14 64.3 %
Date: 2017-07-14 16:53:18 Functions: 4 13 30.8 %
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_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             : namespace mozilla {
      27             : namespace dom {
      28             : 
      29             : class Animation;
      30             : 
      31             : class AnimationTimeline
      32             :   : public nsISupports
      33             :   , public nsWrapperCache
      34             : {
      35             : public:
      36          22 :   explicit AnimationTimeline(nsIGlobalObject* aWindow)
      37          22 :     : mWindow(aWindow)
      38             :   {
      39          22 :     MOZ_ASSERT(mWindow);
      40          22 :   }
      41             : 
      42             : protected:
      43           0 :   virtual ~AnimationTimeline()
      44           0 :   {
      45           0 :     mAnimationOrder.clear();
      46           0 :   }
      47             : 
      48             : public:
      49             :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      50          63 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AnimationTimeline)
      51             : 
      52           0 :   nsIGlobalObject* GetParentObject() const { return mWindow; }
      53             : 
      54             :   // AnimationTimeline methods
      55             :   virtual Nullable<TimeDuration> GetCurrentTime() const = 0;
      56             : 
      57             :   // Wrapper functions for AnimationTimeline DOM methods when called from
      58             :   // script.
      59           2 :   Nullable<double> GetCurrentTimeAsDouble() const {
      60           2 :     return AnimationUtils::TimeDurationToDouble(GetCurrentTime());
      61             :   }
      62             : 
      63             :   /**
      64             :    * Returns true if the times returned by GetCurrentTime() are convertible
      65             :    * to and from wallclock-based TimeStamp (e.g. from TimeStamp::Now()) values
      66             :    * using ToTimelineTime() and ToTimeStamp().
      67             :    *
      68             :    * Typically this is true, but it will be false in the case when this
      69             :    * timeline has no refresh driver or is tied to a refresh driver under test
      70             :    * control.
      71             :    */
      72             :   virtual bool TracksWallclockTime() const = 0;
      73             : 
      74             :   /**
      75             :    * Converts a TimeStamp to the equivalent value in timeline time.
      76             :    * Note that when TracksWallclockTime() is false, there is no correspondence
      77             :    * between timeline time and wallclock time. In such a case, passing a
      78             :    * timestamp from TimeStamp::Now() to this method will not return a
      79             :    * meaningful result.
      80             :    */
      81             :   virtual Nullable<TimeDuration> ToTimelineTime(const TimeStamp&
      82             :                                                   aTimeStamp) const = 0;
      83             : 
      84             :   virtual TimeStamp ToTimeStamp(const TimeDuration& aTimelineTime) const = 0;
      85             : 
      86             :   /**
      87             :    * Inform this timeline that |aAnimation| which is or was observing the
      88             :    * timeline, has been updated. This serves as both the means to associate
      89             :    * AND disassociate animations with a timeline. The timeline itself will
      90             :    * determine if it needs to begin, continue or stop tracking this animation.
      91             :    */
      92             :   virtual void NotifyAnimationUpdated(Animation& aAnimation);
      93             : 
      94             :   /**
      95             :    * Returns true if any CSS animations, CSS transitions or Web animations are
      96             :    * currently associated with this timeline.  As soon as an animation is
      97             :    * applied to an element it is associated with the timeline even if it has a
      98             :    * delayed start, so this includes animations that may not be active for some
      99             :    * time.
     100             :    */
     101          21 :   bool HasAnimations() const {
     102          21 :     return !mAnimations.IsEmpty();
     103             :   }
     104             : 
     105             :   virtual void RemoveAnimation(Animation* aAnimation);
     106             : 
     107             : protected:
     108             :   nsCOMPtr<nsIGlobalObject> mWindow;
     109             : 
     110             :   // Animations observing this timeline
     111             :   //
     112             :   // We store them in (a) a hashset for quick lookup, and (b) an array
     113             :   // to maintain a fixed sampling order.
     114             :   //
     115             :   // The hashset keeps a strong reference to each animation since
     116             :   // dealing with addref/release with LinkedList is difficult.
     117             :   typedef nsTHashtable<nsRefPtrHashKey<dom::Animation>> AnimationSet;
     118             :   AnimationSet mAnimations;
     119             :   LinkedList<dom::Animation> mAnimationOrder;
     120             : };
     121             : 
     122             : } // namespace dom
     123             : } // namespace mozilla
     124             : 
     125             : #endif // mozilla_dom_AnimationTimeline_h

Generated by: LCOV version 1.13