2011-04-12 10:18:44 +04:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-04-12 10:18:44 +04:00
|
|
|
#ifndef nsAnimationManager_h_
|
|
|
|
#define nsAnimationManager_h_
|
|
|
|
|
2012-09-14 20:10:08 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
#include "AnimationCommon.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
2014-10-20 08:55:46 +04:00
|
|
|
#include "mozilla/dom/AnimationPlayer.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2011-04-12 10:18:44 +04:00
|
|
|
|
|
|
|
class nsCSSKeyframesRule;
|
2013-09-16 05:06:52 +04:00
|
|
|
class nsStyleContext;
|
2011-04-12 10:18:44 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
class Declaration;
|
2014-10-20 08:55:46 +04:00
|
|
|
} /* namespace css */
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2012-07-31 21:28:21 +04:00
|
|
|
struct AnimationEventInfo {
|
|
|
|
nsRefPtr<mozilla::dom::Element> mElement;
|
2013-09-27 10:20:54 +04:00
|
|
|
mozilla::InternalAnimationEvent mEvent;
|
2012-07-31 21:28:21 +04:00
|
|
|
|
|
|
|
AnimationEventInfo(mozilla::dom::Element *aElement,
|
2014-08-22 16:42:48 +04:00
|
|
|
const nsSubstring& aAnimationName,
|
2014-09-25 09:25:50 +04:00
|
|
|
uint32_t aMessage,
|
|
|
|
const mozilla::StickyTimeDuration& aElapsedTime,
|
2013-05-05 17:22:29 +04:00
|
|
|
const nsAString& aPseudoElement)
|
2014-02-11 09:35:25 +04:00
|
|
|
: mElement(aElement), mEvent(true, aMessage)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
2014-02-11 09:35:25 +04:00
|
|
|
// XXX Looks like nobody initialize WidgetEvent::time
|
|
|
|
mEvent.animationName = aAnimationName;
|
|
|
|
mEvent.elapsedTime = aElapsedTime.ToSeconds();
|
|
|
|
mEvent.pseudoElement = aPseudoElement;
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
|
2013-09-27 10:20:54 +04:00
|
|
|
// InternalAnimationEvent doesn't support copy-construction, so we need
|
2012-07-31 21:28:21 +04:00
|
|
|
// to ourselves in order to work with nsTArray
|
|
|
|
AnimationEventInfo(const AnimationEventInfo &aOther)
|
2014-02-11 09:35:25 +04:00
|
|
|
: mElement(aOther.mElement), mEvent(true, aOther.mEvent.message)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
2014-02-11 09:35:25 +04:00
|
|
|
mEvent.AssignAnimationEventData(aOther.mEvent, false);
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef InfallibleTArray<AnimationEventInfo> EventArray;
|
|
|
|
|
2014-10-20 08:55:46 +04:00
|
|
|
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 */
|
|
|
|
|
2013-06-25 12:58:46 +04:00
|
|
|
class nsAnimationManager MOZ_FINAL
|
|
|
|
: public mozilla::css::CommonAnimationManager
|
2011-04-12 10:18:44 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-08-20 08:58:22 +04:00
|
|
|
explicit nsAnimationManager(nsPresContext *aPresContext)
|
2012-07-31 21:28:21 +04:00
|
|
|
: mozilla::css::CommonAnimationManager(aPresContext)
|
2013-06-25 12:58:46 +04:00
|
|
|
, mObservingRefreshDriver(false)
|
2011-04-12 10:18:44 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:46 +04:00
|
|
|
static mozilla::AnimationPlayerCollection*
|
2014-06-20 07:39:25 +04:00
|
|
|
GetAnimationsForCompositor(nsIContent* aContent, nsCSSProperty aProperty)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
2014-06-20 07:39:25 +04:00
|
|
|
return mozilla::css::CommonAnimationManager::GetAnimationsForCompositor(
|
|
|
|
aContent, nsGkAtoms::animationsProperty, aProperty);
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
// Returns true if aContent or any of its ancestors has an animation.
|
|
|
|
static bool ContentOrAncestorHasAnimation(nsIContent* aContent) {
|
|
|
|
do {
|
|
|
|
if (aContent->GetProperty(nsGkAtoms::animationsProperty)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} while ((aContent = aContent->GetParent()));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:46 +04:00
|
|
|
void UpdateStyleAndEvents(mozilla::AnimationPlayerCollection* aEA,
|
2014-06-23 00:23:59 +04:00
|
|
|
mozilla::TimeStamp aRefreshTime,
|
2014-06-20 07:39:25 +04:00
|
|
|
mozilla::EnsureStyleRuleFlags aFlags);
|
2014-08-10 11:06:46 +04:00
|
|
|
void GetEventsForCurrentTime(mozilla::AnimationPlayerCollection* aEA,
|
2014-10-20 08:55:46 +04:00
|
|
|
mozilla::EventArray &aEventsToDispatch);
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
// nsIStyleRuleProcessor (parts)
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE;
|
|
|
|
virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE;
|
|
|
|
virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE;
|
2011-04-12 10:18:44 +04:00
|
|
|
#ifdef MOZ_XUL
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
|
2011-04-12 10:18:44 +04:00
|
|
|
#endif
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2013-03-24 06:14:43 +04:00
|
|
|
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2013-06-23 16:03:39 +04:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2013-03-24 06:14:43 +04:00
|
|
|
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2011-04-12 10:18:44 +04:00
|
|
|
|
|
|
|
// nsARefreshObserver
|
2012-09-14 20:10:08 +04:00
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE;
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
void FlushAnimations(FlushFlags aFlags);
|
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
/**
|
|
|
|
* Return the style rule that RulesMatching should add for
|
|
|
|
* aStyleContext. This might be different from what RulesMatching
|
|
|
|
* actually added during aStyleContext's construction because the
|
|
|
|
* element's animation-name may have changed. (However, this does
|
|
|
|
* return null during the non-animation restyling phase, as
|
|
|
|
* RulesMatching does.)
|
|
|
|
*
|
|
|
|
* aStyleContext may be a style context for aElement or for its
|
|
|
|
* :before or :after pseudo-element.
|
|
|
|
*/
|
|
|
|
nsIStyleRule* CheckAnimationRule(nsStyleContext* aStyleContext,
|
|
|
|
mozilla::dom::Element* aElement);
|
|
|
|
|
2011-04-12 10:18:44 +04:00
|
|
|
/**
|
|
|
|
* Dispatch any pending events. We accumulate animationend and
|
|
|
|
* animationiteration events only during refresh driver notifications
|
|
|
|
* (and dispatch them at the end of such notifications), but we
|
|
|
|
* accumulate animationstart events at other points when style
|
|
|
|
* contexts are created.
|
|
|
|
*/
|
2011-12-15 08:42:15 +04:00
|
|
|
void DispatchEvents() {
|
|
|
|
// Fast-path the common case: no events
|
|
|
|
if (!mPendingEvents.IsEmpty()) {
|
|
|
|
DoDispatchEvents();
|
|
|
|
}
|
|
|
|
}
|
2011-04-12 10:18:44 +04:00
|
|
|
|
2014-08-10 11:06:46 +04:00
|
|
|
mozilla::AnimationPlayerCollection*
|
|
|
|
GetAnimationPlayers(mozilla::dom::Element *aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
|
|
|
bool aCreateIfNeeded);
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2013-06-25 12:58:46 +04:00
|
|
|
protected:
|
2014-06-27 03:57:13 +04:00
|
|
|
virtual void ElementCollectionRemoved() MOZ_OVERRIDE
|
2013-06-25 12:58:46 +04:00
|
|
|
{
|
|
|
|
CheckNeedsRefresh();
|
|
|
|
}
|
2014-06-27 03:57:12 +04:00
|
|
|
virtual void
|
2014-08-10 11:06:46 +04:00
|
|
|
AddElementCollection(mozilla::AnimationPlayerCollection* aData) MOZ_OVERRIDE;
|
2013-06-25 12:58:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if we should stop or start observing the refresh driver
|
|
|
|
*/
|
|
|
|
void CheckNeedsRefresh();
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
private:
|
2011-04-12 10:18:44 +04:00
|
|
|
void BuildAnimations(nsStyleContext* aStyleContext,
|
2014-10-02 10:14:15 +04:00
|
|
|
mozilla::dom::Element* aTarget,
|
2014-07-16 04:02:30 +04:00
|
|
|
mozilla::dom::AnimationTimeline* aTimeline,
|
2014-08-10 11:06:46 +04:00
|
|
|
mozilla::AnimationPlayerPtrArray& aAnimations);
|
2014-04-03 09:57:28 +04:00
|
|
|
bool BuildSegment(InfallibleTArray<mozilla::AnimationPropertySegment>&
|
2014-04-03 09:57:28 +04:00
|
|
|
aSegments,
|
2014-06-27 03:57:11 +04:00
|
|
|
nsCSSProperty aProperty,
|
|
|
|
const mozilla::StyleAnimation& aAnimation,
|
2011-04-12 10:18:44 +04:00
|
|
|
float aFromKey, nsStyleContext* aFromContext,
|
|
|
|
mozilla::css::Declaration* aFromDeclaration,
|
2011-04-23 05:36:23 +04:00
|
|
|
float aToKey, nsStyleContext* aToContext);
|
2011-04-12 10:18:44 +04:00
|
|
|
nsIStyleRule* GetAnimationRule(mozilla::dom::Element* aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType);
|
|
|
|
|
2011-12-15 08:42:15 +04:00
|
|
|
// The guts of DispatchEvents
|
|
|
|
void DoDispatchEvents();
|
|
|
|
|
2014-10-20 08:55:46 +04:00
|
|
|
mozilla::EventArray mPendingEvents;
|
2013-06-25 12:58:46 +04:00
|
|
|
|
|
|
|
bool mObservingRefreshDriver;
|
2011-04-12 10:18:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsAnimationManager_h_) */
|