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_
|
|
|
|
|
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-07-31 10:28:21 -07:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Per-Element data *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
struct ElementPropertyTransition
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
bool IsRemovedSentinel() const
|
|
|
|
{
|
|
|
|
return mStartTime.IsNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetRemovedSentinel()
|
|
|
|
{
|
|
|
|
// assign the null time stamp
|
|
|
|
mStartTime = mozilla::TimeStamp();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ElementTransitions : public mozilla::css::CommonElementAnimationData
|
|
|
|
{
|
|
|
|
ElementTransitions(mozilla::dom::Element *aElement, nsIAtom *aElementProperty,
|
|
|
|
nsTransitionManager *aTransitionManager);
|
|
|
|
|
|
|
|
void EnsureStyleRuleFor(mozilla::TimeStamp aRefreshTime);
|
|
|
|
|
|
|
|
// True if this animation can be performed on the compositor thread.
|
|
|
|
// virtual CanPerformOnCompositorThread() const;
|
|
|
|
// Either zero or one for each CSS property:
|
|
|
|
nsTArray<ElementPropertyTransition> mPropertyTransitions;
|
|
|
|
|
|
|
|
// This style rule overrides style data with the currently
|
|
|
|
// transitioning value for an element that is executing a transition.
|
|
|
|
// It only matches when styling with animation. When we style without
|
|
|
|
// animation, we need to not use it so that we can detect any new
|
|
|
|
// changes; if necessary we restyle immediately afterwards with
|
|
|
|
// animation.
|
|
|
|
nsRefPtr<mozilla::css::AnimValuesStyleRule> mStyleRule;
|
|
|
|
// The refresh time associated with mStyleRule.
|
|
|
|
mozilla::TimeStamp mStyleRuleRefreshTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
/**
|
2012-07-30 11:36:12 -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)
|
2010-07-18 14:20:40 -07:00
|
|
|
virtual void RulesMatching(ElementRuleProcessorData* aData);
|
|
|
|
virtual void RulesMatching(PseudoElementRuleProcessorData* aData);
|
|
|
|
virtual void RulesMatching(AnonBoxRuleProcessorData* aData);
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-18 14:20:40 -07:00
|
|
|
virtual void RulesMatching(XULTreeRuleProcessorData* aData);
|
2009-12-10 23:37:40 -08:00
|
|
|
#endif
|
2011-12-08 21:01:52 -08:00
|
|
|
virtual NS_MUST_OVERRIDE size_t
|
|
|
|
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
|
|
|
|
virtual NS_MUST_OVERRIDE size_t
|
|
|
|
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
// nsARefreshObserver
|
|
|
|
virtual void WillRefresh(mozilla::TimeStamp aTime);
|
|
|
|
|
|
|
|
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);
|
2010-07-18 14:20:40 -07:00
|
|
|
void WalkTransitionRule(RuleProcessorData* aData,
|
|
|
|
nsCSSPseudoElements::Type aPseudoType);
|
2009-10-07 20:22:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* !defined(nsTransitionManager_h_) */
|