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"
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
const nsString& aAnimationName,
|
2013-05-05 06:22:29 -07:00
|
|
|
uint32_t aMessage, mozilla::TimeDuration aElapsedTime,
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data about all of the animations running on an element.
|
|
|
|
*/
|
2012-12-11 13:12:43 -08:00
|
|
|
struct ElementAnimations MOZ_FINAL
|
|
|
|
: public mozilla::css::CommonElementAnimationData
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
|
|
|
typedef mozilla::TimeStamp TimeStamp;
|
|
|
|
typedef mozilla::TimeDuration TimeDuration;
|
|
|
|
|
|
|
|
ElementAnimations(mozilla::dom::Element *aElement, nsIAtom *aElementProperty,
|
2013-10-22 05:14:41 -07:00
|
|
|
nsAnimationManager *aAnimationManager, TimeStamp aNow);
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2014-05-28 00:51:48 -07:00
|
|
|
void GetEventsAt(TimeStamp aRefreshTime, EventArray &aEventsToDispatch);
|
2012-07-31 10:28:21 -07:00
|
|
|
|
|
|
|
bool IsForElement() const { // rather than for a pseudo-element
|
|
|
|
return mElementProperty == nsGkAtoms::animationsProperty;
|
|
|
|
}
|
|
|
|
|
2013-05-05 06:22:29 -07:00
|
|
|
nsString PseudoElement()
|
|
|
|
{
|
|
|
|
return mElementProperty == nsGkAtoms::animationsProperty ?
|
|
|
|
EmptyString() :
|
|
|
|
mElementProperty == nsGkAtoms::animationsOfBeforeProperty ?
|
|
|
|
NS_LITERAL_STRING("::before") :
|
|
|
|
NS_LITERAL_STRING("::after");
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
void PostRestyleForAnimation(nsPresContext *aPresContext) {
|
|
|
|
nsRestyleHint styleHint = IsForElement() ? eRestyle_Self : eRestyle_Subtree;
|
|
|
|
aPresContext->PresShell()->RestyleForAnimation(mElement, styleHint);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-25 01:58:46 -07:00
|
|
|
class nsAnimationManager MOZ_FINAL
|
|
|
|
: public mozilla::css::CommonAnimationManager
|
2011-04-11 23:18:44 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAnimationManager(nsPresContext *aPresContext)
|
2012-07-31 10:28:21 -07:00
|
|
|
: mozilla::css::CommonAnimationManager(aPresContext)
|
2013-06-25 01:58:46 -07:00
|
|
|
, mObservingRefreshDriver(false)
|
2011-04-11 23:18:44 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-19 20:39:25 -07:00
|
|
|
static mozilla::css::CommonElementAnimationData*
|
|
|
|
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
|
|
|
|
2012-12-11 13:12:43 -08: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-06-19 20:39:25 -07:00
|
|
|
void UpdateStyleAndEvents(ElementAnimations* aEA,
|
|
|
|
TimeStamp aRefreshTime,
|
|
|
|
mozilla::EnsureStyleRuleFlags aFlags);
|
2012-12-11 13:12:43 -08:00
|
|
|
|
2011-04-11 23:18:44 -07:00
|
|
|
// nsIStyleRuleProcessor (parts)
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void RulesMatching(ElementRuleProcessorData* aData) MOZ_OVERRIDE;
|
|
|
|
virtual void RulesMatching(PseudoElementRuleProcessorData* aData) MOZ_OVERRIDE;
|
|
|
|
virtual void RulesMatching(AnonBoxRuleProcessorData* aData) MOZ_OVERRIDE;
|
2011-04-11 23:18:44 -07:00
|
|
|
#ifdef MOZ_XUL
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
|
2011-04-11 23:18:44 -07:00
|
|
|
#endif
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2013-03-23 19:14:43 -07:00
|
|
|
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2013-03-23 19:14:43 -07:00
|
|
|
const MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2011-04-11 23:18:44 -07:00
|
|
|
|
|
|
|
// nsARefreshObserver
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_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
|
|
|
|
2011-04-11 23:18:44 -07:00
|
|
|
ElementAnimations* GetElementAnimations(mozilla::dom::Element *aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCreateIfNeeded);
|
2012-12-11 13:12:43 -08:00
|
|
|
|
2013-10-22 05:14:41 -07:00
|
|
|
// Updates styles on throttled animations. See note on nsTransitionManager
|
|
|
|
void UpdateAllThrottledStyles();
|
|
|
|
|
2013-06-25 01:58:46 -07:00
|
|
|
protected:
|
|
|
|
virtual void ElementDataRemoved() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
CheckNeedsRefresh();
|
|
|
|
}
|
|
|
|
virtual void AddElementData(mozilla::css::CommonElementAnimationData* aData) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if we should stop or start observing the refresh driver
|
|
|
|
*/
|
|
|
|
void CheckNeedsRefresh();
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
private:
|
2011-04-11 23:18:44 -07:00
|
|
|
void BuildAnimations(nsStyleContext* aStyleContext,
|
2014-05-14 16:38:37 -07:00
|
|
|
mozilla::ElementAnimationPtrArray& aAnimations);
|
2014-04-02 22:57:28 -07:00
|
|
|
bool BuildSegment(InfallibleTArray<mozilla::AnimationPropertySegment>&
|
2014-04-02 22:57:28 -07:00
|
|
|
aSegments,
|
2011-04-22 18:36:23 -07:00
|
|
|
nsCSSProperty aProperty, const nsAnimation& 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
|
|
|
nsIStyleRule* GetAnimationRule(mozilla::dom::Element* aElement,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType);
|
|
|
|
|
2013-10-22 05:14:41 -07:00
|
|
|
// Update the animated styles of an element and its descendants.
|
|
|
|
// If the element has an animation, it is flushed back to its primary frame.
|
|
|
|
// If the element does not have an animation, then its style is reparented.
|
|
|
|
void UpdateThrottledStylesForSubtree(nsIContent* aContent,
|
|
|
|
nsStyleContext* aParentStyle,
|
|
|
|
nsStyleChangeList &aChangeList);
|
|
|
|
void UpdateAllThrottledStylesInternal();
|
|
|
|
|
2011-12-14 20:42:15 -08:00
|
|
|
// The guts of DispatchEvents
|
|
|
|
void DoDispatchEvents();
|
|
|
|
|
2011-04-11 23:18:44 -07:00
|
|
|
EventArray mPendingEvents;
|
2013-06-25 01:58:46 -07:00
|
|
|
|
|
|
|
bool mObservingRefreshDriver;
|
2011-04-11 23:18:44 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsAnimationManager_h_) */
|