2009-10-07 20:22:42 -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/. */
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
/* Code to start and animate CSS transitions. */
|
|
|
|
|
|
|
|
#ifndef nsTransitionManager_h_
|
|
|
|
#define nsTransitionManager_h_
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-04-11 23:18:43 -07:00
|
|
|
#include "AnimationCommon.h"
|
2009-12-10 23:37:40 -08:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
class nsStyleContext;
|
|
|
|
class nsPresContext;
|
|
|
|
class nsCSSPropertySet;
|
|
|
|
struct nsTransition;
|
2012-11-14 11:09:01 -08:00
|
|
|
struct ElementDependentRuleProcessorData;
|
2012-07-31 10:28:21 -07:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Per-Element data *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
struct ElementPropertyTransition
|
|
|
|
{
|
2012-12-22 20:52:13 -08:00
|
|
|
ElementPropertyTransition()
|
|
|
|
: mIsRunningOnCompositor(false)
|
|
|
|
{}
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
nsCSSProperty mProperty;
|
|
|
|
nsStyleAnimation::Value mStartValue, mEndValue;
|
|
|
|
mozilla::TimeStamp mStartTime; // actual start plus transition delay
|
|
|
|
|
|
|
|
// data from the relevant nsTransition
|
|
|
|
mozilla::TimeDuration mDuration;
|
|
|
|
mozilla::css::ComputedTimingFunction mTimingFunction;
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
// This is the start value to be used for a check for whether a
|
|
|
|
// transition is being reversed. Normally the same as mStartValue,
|
|
|
|
// except when this transition started as the reversal of another
|
|
|
|
// in-progress transition. Needed so we can handle two reverses in a
|
|
|
|
// row.
|
|
|
|
nsStyleAnimation::Value mStartForReversingTest;
|
|
|
|
// Likewise, the portion (in value space) of the "full" reversed
|
|
|
|
// transition that we're actually covering. For example, if a :hover
|
|
|
|
// effect has a transition that moves the element 10px to the right
|
|
|
|
// (by changing 'left' from 0px to 10px), and the mouse moves in to
|
|
|
|
// the element (starting the transition) but then moves out after the
|
|
|
|
// transition has advanced 4px, the second transition (from 10px/4px
|
|
|
|
// to 0px) will have mReversePortion of 0.4. (If the mouse then moves
|
|
|
|
// in again when the transition is back to 2px, the mReversePortion
|
|
|
|
// for the third transition (from 0px/2px to 10px) will be 0.8.
|
|
|
|
double mReversePortion;
|
2012-12-22 20:52:13 -08:00
|
|
|
// true when the transition is running on the compositor. In particular,
|
|
|
|
// mIsRunningOnCompositor will be false if the transition has a delay and we
|
|
|
|
// are not yet at mStartTime, so there is no animation on the layer.
|
|
|
|
bool mIsRunningOnCompositor;
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
// Compute the portion of the *value* space that we should be through
|
|
|
|
// at the given time. (The input to the transition timing function
|
|
|
|
// has time units, the output has value units.)
|
|
|
|
double ValuePortionFor(mozilla::TimeStamp aRefreshTime) const;
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
bool IsRemovedSentinel() const
|
|
|
|
{
|
|
|
|
return mStartTime.IsNull();
|
|
|
|
}
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
void SetRemovedSentinel()
|
|
|
|
{
|
|
|
|
// assign the null time stamp
|
|
|
|
mStartTime = mozilla::TimeStamp();
|
|
|
|
}
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-08-21 18:48:47 -07:00
|
|
|
bool IsRunningAt(mozilla::TimeStamp aTime) const;
|
2012-07-31 10:28:21 -07:00
|
|
|
};
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
struct ElementTransitions MOZ_FINAL
|
|
|
|
: public mozilla::css::CommonElementAnimationData
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
|
|
|
ElementTransitions(mozilla::dom::Element *aElement, nsIAtom *aElementProperty,
|
2012-12-11 13:12:43 -08:00
|
|
|
nsTransitionManager *aTransitionManager,
|
|
|
|
mozilla::TimeStamp aNow);
|
2012-07-31 10:28:21 -07:00
|
|
|
|
|
|
|
void EnsureStyleRuleFor(mozilla::TimeStamp aRefreshTime);
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
virtual bool HasAnimationOfProperty(nsCSSProperty aProperty) const MOZ_OVERRIDE;
|
|
|
|
virtual bool CanPerformOnCompositorThread(CanAnimateFlags aFlags) const MOZ_OVERRIDE;
|
2012-07-31 10:28:22 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
// Either zero or one for each CSS property:
|
|
|
|
nsTArray<ElementPropertyTransition> mPropertyTransitions;
|
2012-12-11 13:12:43 -08:00
|
|
|
|
|
|
|
// Generation counter for flushes of throttled transitions.
|
|
|
|
// Used to prevent updating the styles twice for a given element during
|
|
|
|
// UpdateAllThrottledStyles.
|
|
|
|
mozilla::TimeStamp mFlushGeneration;
|
2012-07-31 10:28:21 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
class nsTransitionManager : public mozilla::css::CommonAnimationManager
|
|
|
|
{
|
2009-10-07 20:22:42 -07:00
|
|
|
public:
|
2011-04-11 23:18:43 -07:00
|
|
|
nsTransitionManager(nsPresContext *aPresContext)
|
|
|
|
: mozilla::css::CommonAnimationManager(aPresContext)
|
|
|
|
{
|
|
|
|
}
|
2009-12-23 11:10:31 -08:00
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
static ElementTransitions* GetTransitions(nsIContent* aContent) {
|
|
|
|
return static_cast<ElementTransitions*>
|
|
|
|
(aContent->GetProperty(nsGkAtoms::transitionsProperty));
|
|
|
|
}
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
// Returns true if aContent or any of its ancestors has a transition.
|
|
|
|
static bool ContentOrAncestorHasTransition(nsIContent* aContent) {
|
|
|
|
do {
|
|
|
|
if (GetTransitions(aContent)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} while ((aContent = aContent->GetParent()));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef mozilla::css::CommonElementAnimationData CommonElementAnimationData;
|
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
static ElementTransitions*
|
|
|
|
GetTransitionsForCompositor(nsIContent* aContent,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
2012-12-11 13:12:43 -08:00
|
|
|
if (!aContent->MayHaveAnimations()) {
|
2012-07-31 10:28:22 -07:00
|
|
|
return nullptr;
|
2012-12-11 13:12:43 -08:00
|
|
|
}
|
2012-07-31 10:28:22 -07:00
|
|
|
ElementTransitions* transitions = GetTransitions(aContent);
|
|
|
|
if (!transitions ||
|
2012-12-11 13:12:43 -08:00
|
|
|
!transitions->HasAnimationOfProperty(aProperty) ||
|
|
|
|
!transitions->CanPerformOnCompositorThread(
|
|
|
|
CommonElementAnimationData::CanAnimate_AllowPartial)) {
|
2012-07-31 10:28:22 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return transitions;
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
/**
|
2012-07-31 10:28:22 -07:00
|
|
|
* StyleContextChanged
|
2009-10-07 20:22:42 -07:00
|
|
|
*
|
|
|
|
* To be called from nsFrameManager::ReResolveStyleContext when the
|
2010-06-30 18:54:29 -07:00
|
|
|
* style of an element has changed, to initiate transitions from
|
|
|
|
* that style change. For style contexts with :before and :after
|
|
|
|
* pseudos, aElement is expected to be the generated before/after
|
|
|
|
* element.
|
2009-10-07 20:22:42 -07:00
|
|
|
*
|
|
|
|
* It may return a "cover rule" (see CoverTransitionStartStyleRule) to
|
|
|
|
* cover up some of the changes for the duration of the restyling of
|
|
|
|
* descendants. If it does, this function will take care of causing
|
|
|
|
* the necessary restyle afterwards, but the caller must restyle the
|
|
|
|
* element *again* with the original sequence of rules plus the
|
|
|
|
* returned cover rule as the most specific rule.
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIStyleRule>
|
2010-05-14 10:04:51 -07:00
|
|
|
StyleContextChanged(mozilla::dom::Element *aElement,
|
2009-10-07 20:22:42 -07:00
|
|
|
nsStyleContext *aOldStyleContext,
|
|
|
|
nsStyleContext *aNewStyleContext);
|
|
|
|
|
2011-04-11 23:18:43 -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;
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void RulesMatching(XULTreeRuleProcessorData* aData) MOZ_OVERRIDE;
|
2009-12-10 23:37:40 -08:00
|
|
|
#endif
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2013-03-23 19:14:43 -07:00
|
|
|
MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2013-06-23 05:03:39 -07:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2013-03-23 19:14:43 -07:00
|
|
|
MOZ_MUST_OVERRIDE MOZ_OVERRIDE;
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
// nsARefreshObserver
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime) MOZ_OVERRIDE;
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
void FlushTransitions(FlushFlags aFlags);
|
|
|
|
|
2012-12-22 20:52:13 -08:00
|
|
|
// Performs a 'mini-flush' to make styles from throttled transitions
|
|
|
|
// up-to-date prior to processing an unrelated style change, so that
|
|
|
|
// any transitions triggered by that style change produce correct
|
|
|
|
// results.
|
|
|
|
//
|
|
|
|
// In more detail: when we're able to run animations on the
|
|
|
|
// compositor, we sometimes "throttle" these animations by skipping
|
|
|
|
// updating style data on the main thread. However, whenever we
|
|
|
|
// process a normal (non-animation) style change, any changes in
|
|
|
|
// computed style on elements that have transition-* properties set
|
|
|
|
// may need to trigger new transitions; this process requires knowing
|
|
|
|
// both the old and new values of the property. To do this correctly,
|
|
|
|
// we need to have an up-to-date *old* value of the property on the
|
|
|
|
// primary frame. So the purpose of the mini-flush is to update the
|
|
|
|
// style for all throttled transitions and animations to the current
|
|
|
|
// animation state without making any other updates, so that when we
|
|
|
|
// process the queued style updates we'll have correct old data to
|
|
|
|
// compare against. When we do this, we don't bother touching frames
|
2012-12-11 13:12:43 -08:00
|
|
|
// other than primary frames.
|
|
|
|
void UpdateAllThrottledStyles();
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
private:
|
|
|
|
void ConsiderStartingTransition(nsCSSProperty aProperty,
|
|
|
|
const nsTransition& aTransition,
|
2010-05-14 10:04:51 -07:00
|
|
|
mozilla::dom::Element *aElement,
|
2009-10-07 20:22:42 -07:00
|
|
|
ElementTransitions *&aElementTransitions,
|
|
|
|
nsStyleContext *aOldStyleContext,
|
|
|
|
nsStyleContext *aNewStyleContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *aStartedAny,
|
2009-10-07 20:22:42 -07:00
|
|
|
nsCSSPropertySet *aWhichStarted);
|
2010-05-14 10:04:51 -07:00
|
|
|
ElementTransitions* GetElementTransitions(mozilla::dom::Element *aElement,
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCreateIfNeeded);
|
2012-11-14 11:09:01 -08:00
|
|
|
void WalkTransitionRule(ElementDependentRuleProcessorData* aData,
|
2010-07-18 14:20:40 -07:00
|
|
|
nsCSSPseudoElements::Type aPseudoType);
|
2012-12-11 13:12:43 -08:00
|
|
|
|
|
|
|
// Update the animated styles of an element and its descendants.
|
|
|
|
// If the element has a transition, it is flushed back to its primary frame.
|
|
|
|
// If the element does not have a transition, then its style is reparented.
|
|
|
|
void UpdateThrottledStylesForSubtree(nsIContent* aContent,
|
2013-01-08 20:37:29 -08:00
|
|
|
nsStyleContext* aParentStyle,
|
|
|
|
nsStyleChangeList &aChangeList);
|
2012-12-11 13:12:43 -08:00
|
|
|
// Update the style on aElement from the transition stored in this manager and
|
|
|
|
// the new parent style - aParentStyle. aElement must be transitioning or
|
|
|
|
// animated. Returns the updated style.
|
|
|
|
nsStyleContext* UpdateThrottledStyle(mozilla::dom::Element* aElement,
|
2013-01-08 20:37:29 -08:00
|
|
|
nsStyleContext* aParentStyle,
|
|
|
|
nsStyleChangeList &aChangeList);
|
2009-10-07 20:22:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsTransitionManager_h_) */
|