Bug 1078122 part 5 - Move CSSAnimationPlayer to nsAnimationManager; r=dholbert
authorBrian Birtles <birtles@gmail.com>
Mon, 20 Oct 2014 13:55:46 +0900
changeset 211179 4d628be8f7d031c0514df23fb7b1caec4f335410
parent 211178 93c56f764bc31ea07df24baa8f6fa6e83df79658
child 211180 082d6d6cf6acc5ddf442784cf425da0f68efd20e
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersdholbert
bugs1078122
milestone36.0a1
Bug 1078122 part 5 - Move CSSAnimationPlayer to nsAnimationManager; r=dholbert This patch takes the CSSAnimationPlayer object, currently defined in dom/animation/AnimationPlayer.{cpp,h}, and moves it to layout/style/nsAnimationManager.{cpp,h} where the rest of the CSS Animations-specific code lives. At the same time it extends the scope of the mozilla namespace block in nsAnimationManager.h to also include the AnimationEventInfo and EventArray types since these classes, which don't have an ns* prefix, probably should be in the mozilla namespace anyway.
dom/animation/AnimationPlayer.cpp
dom/animation/AnimationPlayer.h
layout/style/nsAnimationManager.cpp
layout/style/nsAnimationManager.h
--- a/dom/animation/AnimationPlayer.cpp
+++ b/dom/animation/AnimationPlayer.cpp
@@ -257,45 +257,9 @@ AnimationPlayer::SourceContentEnd() cons
     return StickyTimeDuration(0);
   }
 
   return mSource->Timing().mDelay
          + mSource->GetComputedTiming().mActiveDuration;
 }
 
 } // namespace dom
-
-void
-CSSAnimationPlayer::Play(UpdateFlags aUpdateFlags)
-{
-  mPauseShouldStick = false;
-  AnimationPlayer::Play(aUpdateFlags);
-}
-
-void
-CSSAnimationPlayer::Pause(UpdateFlags aUpdateFlags)
-{
-  mPauseShouldStick = true;
-  AnimationPlayer::Pause(aUpdateFlags);
-}
-
-void
-CSSAnimationPlayer::PlayFromStyle()
-{
-  mIsStylePaused = false;
-  if (!mPauseShouldStick) {
-    AnimationPlayer::Play(eNoUpdate);
-  }
-}
-
-void
-CSSAnimationPlayer::PauseFromStyle()
-{
-  // Check if the pause state is being overridden
-  if (mIsStylePaused) {
-    return;
-  }
-
-  mIsStylePaused = true;
-  AnimationPlayer::Pause(eNoUpdate);
-}
-
 } // namespace mozilla
--- a/dom/animation/AnimationPlayer.h
+++ b/dom/animation/AnimationPlayer.h
@@ -126,89 +126,11 @@ protected:
   nsRefPtr<AnimationTimeline> mTimeline;
   nsRefPtr<Animation> mSource;
   Nullable<TimeDuration> mHoldTime;  // Player timescale
   bool mIsPaused;
   bool mIsRunningOnCompositor;
 };
 
 } // namespace dom
-
-class CSSAnimationPlayer MOZ_FINAL : public dom::AnimationPlayer
-{
-public:
- explicit CSSAnimationPlayer(dom::AnimationTimeline* aTimeline)
-    : dom::AnimationPlayer(aTimeline)
-    , mIsStylePaused(false)
-    , mPauseShouldStick(false)
-  {
-  }
-
-  virtual CSSAnimationPlayer*
-  AsCSSAnimationPlayer() MOZ_OVERRIDE { return this; }
-
-  virtual void Play(UpdateFlags aUpdateFlags) MOZ_OVERRIDE;
-  virtual void Pause(UpdateFlags aUpdateFlags) MOZ_OVERRIDE;
-
-  void PlayFromStyle();
-  void PauseFromStyle();
-
-  bool IsStylePaused() const { return mIsStylePaused; }
-
-protected:
-  virtual ~CSSAnimationPlayer() { }
-
-  // When combining animation-play-state with play() / pause() the following
-  // behavior applies:
-  // 1. pause() is sticky and always overrides the underlying
-  //    animation-play-state
-  // 2. If animation-play-state is 'paused', play() will temporarily override
-  //    it until animation-play-state next becomes 'running'.
-  // 3. Calls to play() trigger finishing behavior but setting the
-  //    animation-play-state to 'running' does not.
-  //
-  // This leads to five distinct states:
-  //
-  // A. Running
-  // B. Running and temporarily overriding animation-play-state: paused
-  // C. Paused and sticky overriding animation-play-state: running
-  // D. Paused and sticky overriding animation-play-state: paused
-  // E. Paused by animation-play-state
-  //
-  // C and D may seem redundant but they differ in how to respond to the
-  // sequence: call play(), set animation-play-state: paused.
-  //
-  // C will transition to A then E leaving the animation paused.
-  // D will transition to B then B leaving the animation running.
-  //
-  // A state transition chart is as follows:
-  //
-  //             A | B | C | D | E
-  //   ---------------------------
-  //   play()    A | B | A | B | B
-  //   pause()   C | D | C | D | D
-  //   'running' A | A | C | C | A
-  //   'paused'  E | B | D | D | E
-  //
-  // The base class, AnimationPlayer already provides a boolean value,
-  // mIsPaused which gives us two states. To this we add a further two booleans
-  // to represent the states as follows.
-  //
-  // A. Running
-  //    (!mIsPaused; !mIsStylePaused; !mPauseShouldStick)
-  // B. Running and temporarily overriding animation-play-state: paused
-  //    (!mIsPaused; mIsStylePaused; !mPauseShouldStick)
-  // C. Paused and sticky overriding animation-play-state: running
-  //    (mIsPaused; !mIsStylePaused; mPauseShouldStick)
-  // D. Paused and sticky overriding animation-play-state: paused
-  //    (mIsPaused; mIsStylePaused; mPauseShouldStick)
-  // E. Paused by animation-play-state
-  //    (mIsPaused; mIsStylePaused; !mPauseShouldStick)
-  //
-  // (That leaves 3 combinations of the boolean values that we never set because
-  // they don't represent valid states.)
-  bool mIsStylePaused;
-  bool mPauseShouldStick;
-};
-
 } // namespace mozilla
 
 #endif // mozilla_dom_AnimationPlayer_h
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsAnimationManager.h"
 #include "nsTransitionManager.h"
 
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/StyleAnimationValue.h"
-#include "mozilla/dom/AnimationPlayer.h"
 
 #include "nsPresContext.h"
 #include "nsRuleProcessorData.h"
 #include "nsStyleSet.h"
 #include "nsStyleChangeList.h"
 #include "nsCSSRules.h"
 #include "RestyleManager.h"
 #include "nsLayoutUtils.h"
@@ -24,16 +23,51 @@
 
 using namespace mozilla;
 using namespace mozilla::css;
 using mozilla::dom::Animation;
 using mozilla::dom::AnimationPlayer;
 using mozilla::CSSAnimationPlayer;
 
 void
+CSSAnimationPlayer::Play(UpdateFlags aUpdateFlags)
+{
+  mPauseShouldStick = false;
+  AnimationPlayer::Play(aUpdateFlags);
+}
+
+void
+CSSAnimationPlayer::Pause(UpdateFlags aUpdateFlags)
+{
+  mPauseShouldStick = true;
+  AnimationPlayer::Pause(aUpdateFlags);
+}
+
+void
+CSSAnimationPlayer::PlayFromStyle()
+{
+  mIsStylePaused = false;
+  if (!mPauseShouldStick) {
+    AnimationPlayer::Play(eNoUpdate);
+  }
+}
+
+void
+CSSAnimationPlayer::PauseFromStyle()
+{
+  // Check if the pause state is being overridden
+  if (mIsStylePaused) {
+    return;
+  }
+
+  mIsStylePaused = true;
+  AnimationPlayer::Pause(eNoUpdate);
+}
+
+void
 nsAnimationManager::UpdateStyleAndEvents(AnimationPlayerCollection*
                                            aCollection,
                                          TimeStamp aRefreshTime,
                                          EnsureStyleRuleFlags aFlags)
 {
   aCollection->EnsureStyleRuleFor(aRefreshTime, aFlags);
   GetEventsForCurrentTime(aCollection, mPendingEvents);
   CheckNeedsRefresh();
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -4,27 +4,27 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #ifndef nsAnimationManager_h_
 #define nsAnimationManager_h_
 
 #include "mozilla/Attributes.h"
 #include "mozilla/ContentEvents.h"
 #include "AnimationCommon.h"
 #include "nsCSSPseudoElements.h"
+#include "mozilla/dom/AnimationPlayer.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/TimeStamp.h"
 
 class nsCSSKeyframesRule;
 class nsStyleContext;
 
 namespace mozilla {
 namespace css {
 class Declaration;
-}
-}
+} /* namespace css */
 
 struct AnimationEventInfo {
   nsRefPtr<mozilla::dom::Element> mElement;
   mozilla::InternalAnimationEvent mEvent;
 
   AnimationEventInfo(mozilla::dom::Element *aElement,
                      const nsSubstring& aAnimationName,
                      uint32_t aMessage,
@@ -44,16 +44,95 @@ struct AnimationEventInfo {
     : mElement(aOther.mElement), mEvent(true, aOther.mEvent.message)
   {
     mEvent.AssignAnimationEventData(aOther.mEvent, false);
   }
 };
 
 typedef InfallibleTArray<AnimationEventInfo> EventArray;
 
+class CSSAnimationPlayer MOZ_FINAL : public dom::AnimationPlayer
+{
+public:
+ explicit CSSAnimationPlayer(dom::AnimationTimeline* aTimeline)
+    : dom::AnimationPlayer(aTimeline)
+    , mIsStylePaused(false)
+    , mPauseShouldStick(false)
+  {
+  }
+
+  virtual CSSAnimationPlayer*
+  AsCSSAnimationPlayer() MOZ_OVERRIDE { return this; }
+
+  virtual void Play(UpdateFlags aUpdateFlags) MOZ_OVERRIDE;
+  virtual void Pause(UpdateFlags aUpdateFlags) MOZ_OVERRIDE;
+
+  void PlayFromStyle();
+  void PauseFromStyle();
+
+  bool IsStylePaused() const { return mIsStylePaused; }
+
+protected:
+  virtual ~CSSAnimationPlayer() { }
+
+  // When combining animation-play-state with play() / pause() the following
+  // behavior applies:
+  // 1. pause() is sticky and always overrides the underlying
+  //    animation-play-state
+  // 2. If animation-play-state is 'paused', play() will temporarily override
+  //    it until animation-play-state next becomes 'running'.
+  // 3. Calls to play() trigger finishing behavior but setting the
+  //    animation-play-state to 'running' does not.
+  //
+  // This leads to five distinct states:
+  //
+  // A. Running
+  // B. Running and temporarily overriding animation-play-state: paused
+  // C. Paused and sticky overriding animation-play-state: running
+  // D. Paused and sticky overriding animation-play-state: paused
+  // E. Paused by animation-play-state
+  //
+  // C and D may seem redundant but they differ in how to respond to the
+  // sequence: call play(), set animation-play-state: paused.
+  //
+  // C will transition to A then E leaving the animation paused.
+  // D will transition to B then B leaving the animation running.
+  //
+  // A state transition chart is as follows:
+  //
+  //             A | B | C | D | E
+  //   ---------------------------
+  //   play()    A | B | A | B | B
+  //   pause()   C | D | C | D | D
+  //   'running' A | A | C | C | A
+  //   'paused'  E | B | D | D | E
+  //
+  // The base class, AnimationPlayer already provides a boolean value,
+  // mIsPaused which gives us two states. To this we add a further two booleans
+  // to represent the states as follows.
+  //
+  // A. Running
+  //    (!mIsPaused; !mIsStylePaused; !mPauseShouldStick)
+  // B. Running and temporarily overriding animation-play-state: paused
+  //    (!mIsPaused; mIsStylePaused; !mPauseShouldStick)
+  // C. Paused and sticky overriding animation-play-state: running
+  //    (mIsPaused; !mIsStylePaused; mPauseShouldStick)
+  // D. Paused and sticky overriding animation-play-state: paused
+  //    (mIsPaused; mIsStylePaused; mPauseShouldStick)
+  // E. Paused by animation-play-state
+  //    (mIsPaused; mIsStylePaused; !mPauseShouldStick)
+  //
+  // (That leaves 3 combinations of the boolean values that we never set because
+  // they don't represent valid states.)
+  bool mIsStylePaused;
+  bool mPauseShouldStick;
+};
+
+} /* namespace mozilla */
+
 class nsAnimationManager MOZ_FINAL
   : public mozilla::css::CommonAnimationManager
 {
 public:
   explicit nsAnimationManager(nsPresContext *aPresContext)
     : mozilla::css::CommonAnimationManager(aPresContext)
     , mObservingRefreshDriver(false)
   {
@@ -76,17 +155,17 @@ public:
 
     return false;
   }
 
   void UpdateStyleAndEvents(mozilla::AnimationPlayerCollection* aEA,
                             mozilla::TimeStamp aRefreshTime,
                             mozilla::EnsureStyleRuleFlags aFlags);
   void GetEventsForCurrentTime(mozilla::AnimationPlayerCollection* aEA,
-                               EventArray &aEventsToDispatch);
+                               mozilla::EventArray &aEventsToDispatch);
 
   // nsIStyleRuleProcessor (parts)
   virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE;
   virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE;
   virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE;
 #ifdef MOZ_XUL
   virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
 #endif
@@ -159,14 +238,14 @@ private:
                     mozilla::css::Declaration* aFromDeclaration,
                     float aToKey, nsStyleContext* aToContext);
   nsIStyleRule* GetAnimationRule(mozilla::dom::Element* aElement,
                                  nsCSSPseudoElements::Type aPseudoType);
 
   // The guts of DispatchEvents
   void DoDispatchEvents();
 
-  EventArray mPendingEvents;
+  mozilla::EventArray mPendingEvents;
 
   bool mObservingRefreshDriver;
 };
 
 #endif /* !defined(nsAnimationManager_h_) */