tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AnimationEffect.h (4273B)


      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_AnimationEffect_h
      8 #define mozilla_dom_AnimationEffect_h
      9 
     10 #include "mozilla/ComputedTiming.h"
     11 #include "mozilla/TimeStamp.h"
     12 #include "mozilla/TimingParams.h"
     13 #include "mozilla/dom/Animation.h"
     14 #include "mozilla/dom/Nullable.h"
     15 #include "mozilla/dom/ScrollTimeline.h"
     16 #include "nsCycleCollectionParticipant.h"
     17 #include "nsWrapperCache.h"
     18 
     19 namespace mozilla {
     20 class ErrorResult;
     21 
     22 namespace dom {
     23 
     24 class KeyframeEffect;
     25 struct ComputedEffectTiming;
     26 struct EffectTiming;
     27 struct OptionalEffectTiming;
     28 class Document;
     29 
     30 class AnimationEffect : public nsISupports, public nsWrapperCache {
     31 public:
     32  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     33  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(AnimationEffect)
     34 
     35  AnimationEffect(Document* aDocument, TimingParams&& aTiming);
     36 
     37  virtual KeyframeEffect* AsKeyframeEffect() { return nullptr; }
     38 
     39  nsISupports* GetParentObject() const;
     40 
     41  bool IsCurrent() const;
     42  bool IsInEffect() const;
     43  bool HasFiniteActiveDuration() const {
     44    return NormalizedTiming().ActiveDuration() != TimeDuration::Forever();
     45  }
     46 
     47  // AnimationEffect interface
     48  virtual void GetTiming(EffectTiming& aRetVal) const;
     49  virtual void GetComputedTimingAsDict(ComputedEffectTiming& aRetVal) const;
     50  virtual void UpdateTiming(const OptionalEffectTiming& aTiming,
     51                            ErrorResult& aRv);
     52 
     53  const TimingParams& SpecifiedTiming() const { return mTiming; }
     54  void SetSpecifiedTiming(TimingParams&& aTiming);
     55 
     56  const TimingParams& NormalizedTiming() const {
     57    MOZ_ASSERT((mAnimation && mAnimation->UsingScrollTimeline() &&
     58                mNormalizedTiming) ||
     59                   !mNormalizedTiming,
     60               "We do normalization only for progress-based timeline");
     61    return mNormalizedTiming ? *mNormalizedTiming : mTiming;
     62  }
     63 
     64  // There are 3 conditions where we have to update the normalized timing:
     65  // 1. mAnimation is changed, or
     66  // 2. the timeline of mAnimation is changed, or
     67  // 3. mTiming is changed.
     68  void UpdateNormalizedTiming();
     69 
     70  // This function takes as input the timing parameters of an animation and
     71  // returns the computed timing at the specified local time.
     72  //
     73  // The local time may be null in which case only static parameters such as the
     74  // active duration are calculated. All other members of the returned object
     75  // are given a null/initial value.
     76  //
     77  // This function returns a null mProgress member of the return value
     78  // if the animation should not be run
     79  // (because it is not currently active and is not filling at this time).
     80  static ComputedTiming GetComputedTimingAt(
     81      const Nullable<TimeDuration>& aLocalTime, const TimingParams& aTiming,
     82      double aPlaybackRate,
     83      Animation::ProgressTimelinePosition aProgressTimelinePosition,
     84      EndpointBehavior aEndpointBehavior = EndpointBehavior::Exclusive);
     85  // Shortcut that gets the computed timing using the current local time as
     86  // calculated from the timeline time.
     87  ComputedTiming GetComputedTiming(
     88      const TimingParams* aTiming = nullptr,
     89      EndpointBehavior aEndpointBehavior = EndpointBehavior::Exclusive) const;
     90 
     91  virtual void SetAnimation(Animation* aAnimation) = 0;
     92  Animation* GetAnimation() const { return mAnimation; };
     93 
     94  /**
     95   * Returns true if this effect animates one of the properties we consider
     96   * geometric properties, e.g. properties such as 'width' or 'margin-left'
     97   * that we try to synchronize with transform animations, on a valid target
     98   * element.
     99   */
    100  virtual bool AffectsGeometry() const = 0;
    101 
    102 protected:
    103  virtual ~AnimationEffect();
    104 
    105  Nullable<TimeDuration> GetLocalTime() const;
    106 
    107 protected:
    108  RefPtr<Document> mDocument;
    109  RefPtr<Animation> mAnimation;
    110  TimingParams mTiming;
    111  Maybe<TimingParams> mNormalizedTiming;
    112 
    113  // Whether the Animation is System, ResistFingerprinting, or neither
    114  enum RTPCallerType mRTPCallerType;
    115 };
    116 
    117 }  // namespace dom
    118 }  // namespace mozilla
    119 
    120 #endif  // mozilla_dom_AnimationEffect_h