2011-04-11 23:18:44 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 04:12:37 -07: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-11 23:18:44 -07:00
|
|
|
#ifndef nsAnimationManager_h_
|
|
|
|
#define nsAnimationManager_h_
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2011-04-11 23:18:44 -07:00
|
|
|
#include "AnimationCommon.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
2014-10-19 21:55:46 -07:00
|
|
|
#include "mozilla/dom/AnimationPlayer.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-04-11 23:18:44 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2011-04-11 23:18:44 -07:00
|
|
|
|
|
|
|
class nsCSSKeyframesRule;
|
2013-09-15 18:06:52 -07:00
|
|
|
class nsStyleContext;
|
2011-04-11 23:18:44 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
class Declaration;
|
2014-10-19 21:55:46 -07:00
|
|
|
} /* namespace css */
|
2014-12-17 15:42:41 -08:00
|
|
|
namespace dom {
|
|
|
|
class Promise;
|
|
|
|
} /* namespace dom */
|
2011-04-11 23:18:44 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
struct AnimationEventInfo {
|
|
|
|
nsRefPtr<mozilla::dom::Element> mElement;
|
2013-09-26 23:20:54 -07:00
|
|
|
mozilla::InternalAnimationEvent mEvent;
|
2012-07-31 10:28:21 -07:00
|
|
|
|
|
|
|
AnimationEventInfo(mozilla::dom::Element *aElement,
|
2014-08-22 05:42:48 -07:00
|
|
|
const nsSubstring& aAnimationName,
|
2014-09-24 22:25:50 -07:00
|
|
|
uint32_t aMessage,
|
|
|
|
const mozilla::StickyTimeDuration& aElapsedTime,
|
2013-05-05 06:22:29 -07:00
|
|
|
const nsAString& aPseudoElement)
|
2014-02-10 21:35:25 -08:00
|
|
|
: mElement(aElement), mEvent(true, aMessage)
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
2014-02-10 21:35:25 -08:00
|
|
|
// XXX Looks like nobody initialize WidgetEvent::time
|
|
|
|
mEvent.animationName = aAnimationName;
|
|
|
|
mEvent.elapsedTime = aElapsedTime.ToSeconds();
|
|
|
|
mEvent.pseudoElement = aPseudoElement;
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
|
|
|
|
2013-09-26 23:20:54 -07:00
|
|
|
// InternalAnimationEvent doesn't support copy-construction, so we need
|
2012-07-31 10:28:21 -07:00
|
|
|
// to ourselves in order to work with nsTArray
|
|
|
|
AnimationEventInfo(const AnimationEventInfo &aOther)
|
2014-02-10 21:35:25 -08:00
|
|
|
: mElement(aOther.mElement), mEvent(true, aOther.mEvent.message)
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
2014-02-10 21:35:25 -08:00
|
|
|
mEvent.AssignAnimationEventData(aOther.mEvent, false);
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef InfallibleTArray<AnimationEventInfo> EventArray;
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class CSSAnimationPlayer final : public dom::AnimationPlayer
|
2014-10-19 21:55:46 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit CSSAnimationPlayer(dom::AnimationTimeline* aTimeline)
|
|
|
|
: dom::AnimationPlayer(aTimeline)
|
|
|
|
, mIsStylePaused(false)
|
|
|
|
, mPauseShouldStick(false)
|
2015-02-13 07:58:33 -08:00
|
|
|
, mPreviousPhaseOrIteration(PREVIOUS_PHASE_BEFORE)
|
2014-10-19 21:55:46 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual CSSAnimationPlayer*
|
2015-03-21 09:28:04 -07:00
|
|
|
AsCSSAnimationPlayer() override { return this; }
|
2014-10-19 21:55:46 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual dom::Promise* GetReady(ErrorResult& aRv) override;
|
|
|
|
virtual void Play() override;
|
|
|
|
virtual void Pause() override;
|
2014-10-19 21:55:46 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual dom::AnimationPlayState PlayStateFromJS() const override;
|
|
|
|
virtual void PlayFromJS() override;
|
2014-11-16 20:45:58 -08:00
|
|
|
|
2014-10-19 21:55:46 -07:00
|
|
|
void PlayFromStyle();
|
|
|
|
void PauseFromStyle();
|
|
|
|
|
|
|
|
bool IsStylePaused() const { return mIsStylePaused; }
|
|
|
|
|
2014-10-19 21:55:47 -07:00
|
|
|
void QueueEvents(EventArray& aEventsToDispatch);
|
|
|
|
|
2014-10-19 21:55:46 -07:00
|
|
|
protected:
|
|
|
|
virtual ~CSSAnimationPlayer() { }
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual css::CommonAnimationManager* GetAnimationManager() const override;
|
2014-10-19 21:55:46 -07:00
|
|
|
|
2014-10-19 21:55:47 -07:00
|
|
|
static nsString PseudoTypeAsString(nsCSSPseudoElements::Type aPseudoType);
|
|
|
|
|
2014-10-19 21:55:46 -07:00
|
|
|
// 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;
|
2014-10-19 21:55:47 -07:00
|
|
|
|
|
|
|
enum {
|
2015-02-13 07:58:33 -08:00
|
|
|
PREVIOUS_PHASE_BEFORE = uint64_t(-1),
|
|
|
|
PREVIOUS_PHASE_AFTER = uint64_t(-2)
|
2014-10-19 21:55:47 -07:00
|
|
|
};
|
2015-02-13 07:58:33 -08:00
|
|
|
// One of the PREVIOUS_PHASE_* constants, or an integer for the iteration
|
2014-10-19 21:55:47 -07:00
|
|
|
// whose start we last notified on.
|
2015-02-13 07:58:33 -08:00
|
|
|
uint64_t mPreviousPhaseOrIteration;
|
2014-10-19 21:55:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class nsAnimationManager final
|
2013-06-25 01:58:46 -07:00
|
|
|
: public mozilla::css::CommonAnimationManager
|
2011-04-11 23:18:44 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-08-19 21:58:22 -07:00
|
|
|
explicit nsAnimationManager(nsPresContext *aPresContext)
|
2012-07-31 10:28:21 -07:00
|
|
|
: mozilla::css::CommonAnimationManager(aPresContext)
|
2011-04-11 23:18:44 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-10 00:06:46 -07:00
|
|
|
static mozilla::AnimationPlayerCollection*
|
2014-06-19 20:39:25 -07:00
|
|
|
GetAnimationsForCompositor(nsIContent* aContent, nsCSSProperty aProperty)
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
2014-06-19 20:39:25 -07:00
|
|
|
return mozilla::css::CommonAnimationManager::GetAnimationsForCompositor(
|
|
|
|
aContent, nsGkAtoms::animationsProperty, aProperty);
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
2011-04-11 23:18:44 -07:00
|
|
|
|
2014-08-10 00:06:46 -07:00
|
|
|
void UpdateStyleAndEvents(mozilla::AnimationPlayerCollection* aEA,
|
2014-06-22 13:23:59 -07:00
|
|
|
mozilla::TimeStamp aRefreshTime,
|
2014-06-19 20:39:25 -07:00
|
|
|
mozilla::EnsureStyleRuleFlags aFlags);
|
2014-10-19 21:55:47 -07:00
|
|
|
void QueueEvents(mozilla::AnimationPlayerCollection* aEA,
|
|
|
|
mozilla::EventArray &aEventsToDispatch);
|
2012-12-11 13:12:43 -08:00
|
|
|
|
2011-04-11 23:18:44 -07:00
|
|
|
// nsIStyleRuleProcessor (parts)
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2015-03-21 09:28:04 -07:00
|
|
|
const MOZ_MUST_OVERRIDE override;
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2015-03-21 09:28:04 -07:00
|
|
|
const MOZ_MUST_OVERRIDE override;
|
2011-04-11 23:18:44 -07:00
|
|
|
|
|
|
|
// nsARefreshObserver
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) override;
|
2011-04-11 23:18:44 -07:00
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
void FlushAnimations(FlushFlags aFlags);
|
|
|
|
|
2011-04-11 23:18:44 -07: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-11 23:18:44 -07: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-14 20:42:15 -08:00
|
|
|
void DispatchEvents() {
|
|
|
|
// Fast-path the common case: no events
|
|
|
|
if (!mPendingEvents.IsEmpty()) {
|
|
|
|
DoDispatchEvents();
|
|
|
|
}
|
|
|
|
}
|
2011-04-11 23:18:44 -07:00
|
|
|
|
2014-11-19 18:48:41 -08:00
|
|
|
protected:
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* GetAnimationsAtom() override {
|
2014-11-19 18:48:41 -08:00
|
|
|
return nsGkAtoms::animationsProperty;
|
|
|
|
}
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* GetAnimationsBeforeAtom() override {
|
2014-11-19 18:48:41 -08:00
|
|
|
return nsGkAtoms::animationsOfBeforeProperty;
|
|
|
|
}
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* GetAnimationsAfterAtom() override {
|
2014-11-19 18:48:41 -08:00
|
|
|
return nsGkAtoms::animationsOfAfterProperty;
|
|
|
|
}
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool IsAnimationManager() override {
|
2014-11-19 18:48:41 -08:00
|
|
|
return true;
|
|
|
|
}
|
2012-12-11 13:12:43 -08:00
|
|
|
|
|
|
|
private:
|
2011-04-11 23:18:44 -07:00
|
|
|
void BuildAnimations(nsStyleContext* aStyleContext,
|
2014-10-01 23:14:15 -07:00
|
|
|
mozilla::dom::Element* aTarget,
|
2014-07-15 17:02:30 -07:00
|
|
|
mozilla::dom::AnimationTimeline* aTimeline,
|
2014-08-10 00:06:46 -07:00
|
|
|
mozilla::AnimationPlayerPtrArray& aAnimations);
|
2014-04-02 22:57:28 -07:00
|
|
|
bool BuildSegment(InfallibleTArray<mozilla::AnimationPropertySegment>&
|
2014-04-02 22:57:28 -07:00
|
|
|
aSegments,
|
2014-06-26 16:57:11 -07:00
|
|
|
nsCSSProperty aProperty,
|
|
|
|
const mozilla::StyleAnimation& aAnimation,
|
2011-04-11 23:18:44 -07:00
|
|
|
float aFromKey, nsStyleContext* aFromContext,
|
|
|
|
mozilla::css::Declaration* aFromDeclaration,
|
2011-04-22 18:36:23 -07:00
|
|
|
float aToKey, nsStyleContext* aToContext);
|
2011-04-11 23:18:44 -07:00
|
|
|
|
2011-12-14 20:42:15 -08:00
|
|
|
// The guts of DispatchEvents
|
|
|
|
void DoDispatchEvents();
|
|
|
|
|
2014-10-19 21:55:46 -07:00
|
|
|
mozilla::EventArray mPendingEvents;
|
2011-04-11 23:18:44 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsAnimationManager_h_) */
|